landmarksui/uicontrols/src/CLmkMultiSelectorDialog.cpp
branchRCL_3
changeset 36 1fc85118c3ae
parent 34 8173571d354e
child 37 870918037e16
equal deleted inserted replaced
34:8173571d354e 36:1fc85118c3ae
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    LandmarksUi Content File -
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <featmgr.h>
       
    22 #include <sendnorm.rsg> // R_SENDUI_MENU
       
    23 #include <aknsfld.h>
       
    24 #include <StringLoader.h>
       
    25 #include <lmkui.rsg>
       
    26 #include <lmkerrors.h>
       
    27 
       
    28 #include "CLmkMultiSelectorDialog.h"
       
    29 #include "MLmkDlgMenuObserver.h"
       
    30 #include "MLmkNavigationObserver.h"
       
    31 #include "LmkConsts.h"
       
    32 #include "landmarks.hrh"
       
    33 #include "CLmkSender.h"
       
    34 
       
    35 
       
    36 // CONSTANTS
       
    37 /// Unnamed namespace for local definitions
       
    38 namespace {
       
    39 
       
    40 #if defined(_DEBUG)
       
    41 
       
    42 _LIT( KPanicMsg, "CLmkMultiSelectorDialog" );
       
    43 
       
    44 void Panic( TPanicCode aReason )
       
    45     {
       
    46     User::Panic( KPanicMsg, aReason );
       
    47     }
       
    48 #endif
       
    49 }  // namespace
       
    50 
       
    51 // ============================ MEMBER FUNCTIONS ===============================
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CLmkMultiSelectorDialog::CLmkMultiSelectorDialog
       
    55 // C++ default constructor can NOT contain any code, that
       
    56 // might leave.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CLmkMultiSelectorDialog::CLmkMultiSelectorDialog(
       
    60     TInt& aOpenedItemIndex,
       
    61     CArrayFix<TInt>* aSelectionIndexArray,
       
    62     MDesCArray* aLbModel,
       
    63     TInt aMenuBarResourceId,
       
    64     TInt aOkOptionsMenuResourceId,
       
    65     MEikCommandObserver* aCmdObserver,
       
    66     MLmkDlgMenuObserver* aMenuObserver,
       
    67     MLmkListMemento* aMemento )
       
    68     : CLmkSelectorDialog( aOpenedItemIndex, aLbModel, aCmdObserver,aMemento ),
       
    69       iMenuBarResourceId( aMenuBarResourceId ),
       
    70       iOkOptionsMenuResourceId( aOkOptionsMenuResourceId ),
       
    71       iSendUiMenuPaneResourceId( KZeroResourceId ),
       
    72       iSelectionIndexArray( aSelectionIndexArray ),
       
    73       iMenuObserver( aMenuObserver )
       
    74     {
       
    75     iExited = EFalse;
       
    76     iIsToClearSelection = EFalse;
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CLmkMultiSelectorDialog::NewL
       
    81 // Two-phased constructor.
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 CLmkMultiSelectorDialog* CLmkMultiSelectorDialog::NewL(
       
    85     TInt& aOpenedItemIndex,
       
    86     CArrayFix<TInt>* aSelectionIndexArray,
       
    87     MDesCArray* aLbModel,
       
    88     TInt aMenuBarResourceId,
       
    89     TInt aOkOptionsMenuResourceId,
       
    90     MEikCommandObserver* aCmdObserver,
       
    91     MLmkDlgMenuObserver* aMenuObserver,
       
    92     MLmkListMemento* aMemento )
       
    93     {
       
    94     CLmkMultiSelectorDialog* self =
       
    95         new( ELeave ) CLmkMultiSelectorDialog( aOpenedItemIndex,
       
    96                                                aSelectionIndexArray,
       
    97                                                aLbModel,
       
    98                                                aMenuBarResourceId,
       
    99                                                aOkOptionsMenuResourceId,
       
   100                                                aCmdObserver,
       
   101                                                aMenuObserver,
       
   102                                                aMemento );
       
   103 
       
   104     CleanupStack::PushL( self );
       
   105     self->ConstructL( aMenuBarResourceId );
       
   106     CleanupStack::Pop();
       
   107 
       
   108     return self;
       
   109     }
       
   110 
       
   111 // ----------------------------------------------------
       
   112 // CLmkMultiSelectorDialog::ConstructL
       
   113 // ----------------------------------------------------
       
   114 //
       
   115 void CLmkMultiSelectorDialog::ConstructL(TInt aMenuBarResourceId)
       
   116 	{
       
   117 	CAknSelectionListDialog::ConstructL( aMenuBarResourceId );
       
   118 	}
       
   119 
       
   120 // ----------------------------------------------------
       
   121 // CLmkMultiSelectorDialog::~CLmkMultiSelectorDialog
       
   122 // ----------------------------------------------------
       
   123 //
       
   124 CLmkMultiSelectorDialog::~CLmkMultiSelectorDialog()
       
   125     {
       
   126     }
       
   127 
       
   128 // ----------------------------------------------------
       
   129 // CLmkMultiSelectorDialog::SetupSendMenu
       
   130 // ----------------------------------------------------
       
   131 //
       
   132 void CLmkMultiSelectorDialog::SetupSendMenu(
       
   133     CLmkSender& aSender,
       
   134     TInt aSendUiMenuPaneResource,
       
   135     TInt aMenuTextResource )
       
   136     {
       
   137     iLmkSender = &aSender;
       
   138     iSendUiMenuPaneResourceId = aSendUiMenuPaneResource;
       
   139     iMenuTextResourceId = aMenuTextResource;
       
   140     }
       
   141 
       
   142 // ----------------------------------------------------
       
   143 // CLmkMultiSelectorDialog::HandleListBoxEventL
       
   144 // ----------------------------------------------------
       
   145 //
       
   146 void CLmkMultiSelectorDialog::HandleListBoxEventL(
       
   147     CEikListBox* /*aListBox*/,
       
   148     TListBoxEvent aEventType )
       
   149     {
       
   150     switch( aEventType )
       
   151         {
       
   152         case EEventEnterKeyPressed:
       
   153         case EEventItemDoubleClicked:
       
   154             {
       
   155 	        // Do nothing -- offerkeyevent handles this
       
   156             }
       
   157             break;
       
   158     #ifdef RD_SCALABLE_UI_V2
       
   159         case EEventItemClicked:
       
   160         	{
       
   161         	UpdateMskL();
       
   162         	break;
       
   163         	}
       
   164     #endif//RD_SCALABLE_UI_V2
       
   165         default:
       
   166             {
       
   167             break;
       
   168             }
       
   169         };
       
   170     }
       
   171 
       
   172 
       
   173 // ----------------------------------------------------
       
   174 // CLmkMultiSelectorDialog::SelectionListProcessCommandL
       
   175 // ----------------------------------------------------
       
   176 //
       
   177 void CLmkMultiSelectorDialog::SelectionListProcessCommandL( TInt aCommand )
       
   178     {
       
   179     AknSelectionService::HandleMarkableListProcessCommandL( aCommand,
       
   180                                                             ListBox() );
       
   181     }
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CLmkMultiSelectorDialog::OfferKeyEventL
       
   185 // ?implementation_description
       
   186 // (other items were commented in a header).
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 TKeyResponse CLmkMultiSelectorDialog::OfferKeyEventL(
       
   190                                      const TKeyEvent& aKeyEvent,
       
   191                                      TEventCode aType )
       
   192 	{
       
   193 	// Do not process navigation handling till UI gets from engine
       
   194 	if (!ListBox())
       
   195 		{
       
   196 		return EKeyWasConsumed;
       
   197 		}
       
   198     if (aType == EEventKey &&
       
   199         	(aKeyEvent.iCode == EKeyOK || aKeyEvent.iCode == EKeyEnter || aKeyEvent.iScanCode == EStdKeyEnter) )
       
   200 		{
       
   201 		ListBox()->View()->ToggleItemL(ListBox()->CurrentItemIndex());
       
   202 		return EKeyWasConsumed;
       
   203 		}
       
   204 	if (aKeyEvent.iRepeats == 0)
       
   205         {
       
   206         if (KeyEventForNavigationL(aKeyEvent, aType) == EKeyWasConsumed)
       
   207             {
       
   208             iIsToClearSelection = ETrue;
       
   209             TryExitL(EAknSoftkeyOk);
       
   210             return EKeyWasConsumed;
       
   211             }
       
   212         CAknSearchField* findBox = FindBox();
       
   213         if	(findBox && !(findBox->IsVisible()))
       
   214             {
       
   215             return 	EKeyWasConsumed;
       
   216             }
       
   217         }
       
   218 
       
   219 	TKeyResponse keyResponce;
       
   220 	keyResponce = CAknSelectionListDialog::OfferKeyEventL(aKeyEvent, aType);
       
   221 	//CEikButtonGroupContainer &buttonContainer = *(CEikButtonGroupContainer::Current());//ButtonGroupContainer();
       
   222 	if(!iExited)
       
   223 		{
       
   224 		UpdateMskL();
       
   225 		}
       
   226 	return keyResponce;
       
   227 	}
       
   228 
       
   229 // ----------------------------------------------------
       
   230 // CLmkMultiSelectorDialog::PreLayoutDynInitL
       
   231 // ----------------------------------------------------
       
   232 //
       
   233 void CLmkMultiSelectorDialog::PreLayoutDynInitL()
       
   234     {
       
   235     CLmkSelectorDialog::PreLayoutDynInitL();
       
   236     __ASSERT_DEBUG( iSelectionIndexArray, Panic( KLmkPanicNullMember ) );
       
   237     ListBox()->SetSelectionIndexesL( iSelectionIndexArray );
       
   238     }
       
   239 // ----------------------------------------------------
       
   240 // CLmkMultiSelectorDialog::PostLayoutDynInitL
       
   241 // ----------------------------------------------------
       
   242 
       
   243 void CLmkMultiSelectorDialog::PostLayoutDynInitL()
       
   244 	{
       
   245 	CLmkSelectorDialog::PostLayoutDynInitL();
       
   246 	UpdateMskL();
       
   247 
       
   248 	}
       
   249 // -----------------------------------------------------------------------------
       
   250 // CLmkMultiSelectorDialog::OkToExitL
       
   251 // ?implementation_description
       
   252 // (other items were commented in a header).
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 TBool CLmkMultiSelectorDialog::OkToExitL( TInt aButtonId )
       
   256     {
       
   257     TBool b = CAknSelectionListDialog::OkToExitL( aButtonId );
       
   258     if ( iSelectionIndexArray )
       
   259 	    {
       
   260 	    const CArrayFix<TInt>* array = ListBox()->SelectionIndexes();
       
   261 	    if ( FindBox() )
       
   262 	        {
       
   263             CAknFilteredTextListBoxModel* model =
       
   264 	         static_cast<CAknFilteredTextListBoxModel*>( ListBox()->Model() );
       
   265             model->Filter()->UpdateSelectionIndexesL();
       
   266 	        array = model->Filter()->SelectionIndexes();
       
   267 	        }
       
   268 	    TInt numberOfItems( array->Count() );
       
   269 	    iSelectionIndexArray->Reset();
       
   270 	    for ( TInt i( 0 ); i < numberOfItems; ++i )
       
   271             {
       
   272 	        iSelectionIndexArray->AppendL( array->At( i ) );
       
   273             }
       
   274 	    }
       
   275     if(iIsToClearSelection && iSelectionIndexArray)
       
   276         {
       
   277         iSelectionIndexArray->Reset();
       
   278         }
       
   279     if ( b && iNavigationObserver )
       
   280         {
       
   281         iNavigationObserver->HandleClosingEventL();
       
   282         }
       
   283 
       
   284     iExited = b;
       
   285     return b;
       
   286     }
       
   287 
       
   288 // ----------------------------------------------------
       
   289 // CLmkMultiSelectorDialog::DynInitMenuPaneL
       
   290 // ----------------------------------------------------
       
   291 //
       
   292 void CLmkMultiSelectorDialog::DynInitMenuPaneL(
       
   293     TInt aResourceId,
       
   294     CEikMenuPane* aMenuPane )
       
   295     {
       
   296     AknSelectionService::HandleMarkableListDynInitMenuPane( aResourceId,
       
   297                                                     aMenuPane, ListBox() );
       
   298 
       
   299     if ( iMenuObserver )
       
   300         {
       
   301         iMenuObserver->DynInitDlgMenuPaneL( aResourceId, aMenuPane );
       
   302         }
       
   303 
       
   304     TInt visibleCount = ListBox()->Model()->NumberOfItems();
       
   305 
       
   306     if ( aResourceId == iSendUiMenuPaneResourceId )
       
   307         {
       
   308         if ( iLmkSender )
       
   309             {
       
   310             // Send menu is handled by iLmkSender:
       
   311             if ( FeatureManager::FeatureSupported( KFeatureIdLandmarksConverter ) )
       
   312 				{
       
   313 				aMenuPane->SetItemDimmed(ELmkCmdSendDummy, EFalse);
       
   314 				}
       
   315 			else
       
   316 				{
       
   317 				aMenuPane->SetItemDimmed(ELmkCmdSendDummy, ETrue);
       
   318 				}
       
   319             }
       
   320         }
       
   321     else if ( aResourceId == R_SENDUI_MENU )
       
   322         { // Dynamically created send ui menu
       
   323         // Sender always exists if R_SENDUI_MENU exists:
       
   324         __ASSERT_DEBUG( iLmkSender, Panic( KLmkPanicSenderNotExist ) );
       
   325 
       
   326         if ( FeatureManager::FeatureSupported( KFeatureIdLandmarksConverter ) )
       
   327 	        {
       
   328 	        iLmkSender->DisplaySendCascadeMenuL( *aMenuPane );
       
   329 	        }
       
   330         }
       
   331 
       
   332     CAknSelectionListDialog::DynInitMenuPaneL( aResourceId, aMenuPane );
       
   333     }
       
   334 
       
   335 
       
   336 // ----------------------------------------------------
       
   337 // CLmkMultiSelectorDialog::UpdateMskL
       
   338 // ----------------------------------------------------
       
   339 //
       
   340  void CLmkMultiSelectorDialog::UpdateMskL()
       
   341 	 {
       
   342 
       
   343  	CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
       
   344  	HBufC* mskTxt = NULL;
       
   345  	if (ListBox()->Model()->NumberOfItems() > 0)
       
   346  		{
       
   347  		cba->MakeCommandVisibleByPosition(CEikButtonGroupContainer::EMiddleSoftkeyPosition,ETrue);
       
   348  		cba->MakeCommandVisible(EAknSoftkeyDone, ETrue);
       
   349 		cba->MakeCommandVisible(EAknSoftkeyOk, ETrue);
       
   350  		if(IsCurrentItemMarked())
       
   351 			{
       
   352 			mskTxt = StringLoader::LoadLC( R_LM_MSK_UNMARK, iEikonEnv );
       
   353 			cba->AddCommandToStackL(KMskCommandPos,EAknSoftkeyUnmark,mskTxt->Des());
       
   354 			CleanupStack::PopAndDestroy(mskTxt);
       
   355 
       
   356 			}
       
   357 		else
       
   358 			{
       
   359 			mskTxt = StringLoader::LoadLC( R_LM_MSK_MARK, iEikonEnv );
       
   360 			cba->AddCommandToStackL(KMskCommandPos,EAknSoftkeyMark,mskTxt->Des());
       
   361 			CleanupStack::PopAndDestroy(mskTxt);
       
   362 			}
       
   363  		}
       
   364  	else
       
   365  		{
       
   366  		cba->MakeCommandVisible(EAknSoftkeyDone, EFalse);
       
   367 		cba->MakeCommandVisible(EAknSoftkeyOk, EFalse);
       
   368  		cba->MakeCommandVisibleByPosition(CEikButtonGroupContainer::EMiddleSoftkeyPosition,EFalse);
       
   369  		}
       
   370  	 cba->DrawDeferred();
       
   371 	 }
       
   372 
       
   373 
       
   374 // ----------------------------------------------------
       
   375 // CLmkMultiSelectorDialog::IsCurrentItemMarked
       
   376 // ----------------------------------------------------
       
   377 //
       
   378 TBool CLmkMultiSelectorDialog::IsCurrentItemMarked()
       
   379 	{
       
   380 	TBool ret(EFalse);
       
   381 	TInt itemIndex = ListBox()->View()->CurrentItemIndex();
       
   382 	if (itemIndex != KErrNotFound)
       
   383 		{
       
   384 		 ret = ListBox()->View()->ItemIsSelected(itemIndex);
       
   385 		}
       
   386 	return ret;
       
   387 	}
       
   388 //  End of File