menufw/menufwui/matrixmenu/src/mmappui.cpp
branchRCL_3
changeset 34 5456b4e8b3a8
child 35 3321d3e205b6
equal deleted inserted replaced
33:5f0182e07bfb 34:5456b4e8b3a8
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Application UI class
       
    15 *  Version     : %version: MM_176.1.28.1.83 % << Don't touch! Updated by Synergy at check-out.
       
    16 *  Version     : %version: MM_176.1.28.1.83 % << Don't touch! Updated by Synergy at check-out.
       
    17 *
       
    18 */
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <e32cmn.h>
       
    22 #include <avkon.hrh>
       
    23 #include <avkon.rsg>
       
    24 #include <akntitle.h>
       
    25 #include <eikmenub.h>
       
    26 #include <akntoolbar.h>
       
    27 #include <aknbutton.h>
       
    28 #include <e32hashtab.h>
       
    29 #include <layoutmetadata.cdl.h>
       
    30 #include <gulicon.h>
       
    31 #include <fbs.h>
       
    32 #include <eikcmbut.h>
       
    33 #include <hlplch.h>
       
    34 #include <aknlists.h>
       
    35 #include <StringLoader.h>
       
    36 #include <activeidle2domainpskeys.h>
       
    37 #include <UikonInternalPSKeys.h>
       
    38 #include <e32property.h>
       
    39 #include <AknTaskList.h>
       
    40 #include <AknSgcc.h>                           // for transition effects
       
    41 #include <featmgr.h>
       
    42 #include <matrixmenu.rsg>
       
    43 #include <akntabgrp.h>
       
    44 #include <apgcli.h>
       
    45 #include <AknDef.hrh>
       
    46 #include <AknDlgShut.h>
       
    47 #include <mmenuinternalPSkeys.h>
       
    48 #include <aknstyluspopupmenu.h> //stylus popup for long tap event
       
    49 #include <apgwgnam.h>
       
    50 
       
    51 #include "mmgui.hrh"
       
    52 #include "mmguiconstants.h"
       
    53 #include "mmappui.h"
       
    54 #include "menudebug.h"
       
    55 #include "hnengine.h"
       
    56 #include "hnglobals.h"
       
    57 #include "hnsuitemodelcontainer.h"
       
    58 #include "hnmenuitemmodel.h"
       
    59 #include "hntoolbarmodel.h"
       
    60 #include "hnbuttonmodel.h"
       
    61 #include "hnitemmodel.h"
       
    62 #include "hnconvutils.h"
       
    63 #include "hnsuitemodel.h"
       
    64 #include "hnmdbasekey.h"
       
    65 #include "hnmdkeyfactory.h"
       
    66 #include "mmwidgetcontainer.h"
       
    67 #include "mmtemplatelibrary.h"
       
    68 #include "mmextensionmanager.h"
       
    69 #include "hnitemsorder.h"
       
    70 
       
    71 #include "mmnomemory.h"
       
    72 #include "mmappkeyhandler.h"
       
    73 
       
    74 enum TMenuTransEffectContext
       
    75     {
       
    76     EMenuOpenFolderEffect = 1001,
       
    77     EMenuCloseFolderEffect = 1002
       
    78     };
       
    79 
       
    80 #define AI_UID3_AIFW_COMMON 0x102750F0
       
    81 
       
    82 // ============================ MEMBER FUNCTIONS =============================
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 void CMmAppUi::ConstructL()
       
    89     {
       
    90     DEBUG(("_Mm_:CMmAppUi::ConstructL IN"));
       
    91     MMPERF(("Test Logger speed..."));
       
    92     MMPERF(("Test Logger speed - DONE"));
       
    93     MMPERF(("GO!"));
       
    94 
       
    95     //set matrix to be system app
       
    96     iEikonEnv->SetSystem( ETrue );
       
    97 
       
    98     TInt appUiFlags = AknLayoutUtils::PenEnabled() ?
       
    99       EAknEnableSkin | EAknSingleClickCompatible :
       
   100         EAknEnableSkin | EAknEnableMSK;
       
   101     BaseConstructL( appUiFlags );
       
   102     //hide Menu from TS at startup
       
   103     HideApplicationFromFSW( ETrue );
       
   104     isHiddenFromFS = ETrue;
       
   105     FeatureManager::InitializeLibL();
       
   106     iIsKastorEffectStarted = EFalse;
       
   107     StartLayoutSwitchFullScreen( AknTransEffect::EApplicationStart );
       
   108 
       
   109     RefreshUiPanesL( ETrue );
       
   110     Cba()->MakeVisible( EFalse );
       
   111     StatusPane()->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_USUAL );
       
   112 
       
   113     iDummyTemplateLib = CMmTemplateLibrary::NewL();
       
   114     iDummyContainer = CMmWidgetContainer::NewGridContainerL( ClientRect(),
       
   115             this, iDummyTemplateLib );
       
   116     iDummyContainer->SetEmptyTextL( KNullDesC );
       
   117     iDummyContainer->MakeVisible( EFalse );
       
   118     AddToStackL( iDummyContainer, ECoeStackPriorityDefault,
       
   119             ECoeStackFlagRefusesFocus | ECoeStackFlagRefusesAllKeys );
       
   120 
       
   121     iHNInterface = CHnEngine::NewL( *this );
       
   122     iTemplateLibrary = CMmTemplateLibrary::NewL();
       
   123     InitializeL();
       
   124 
       
   125     iMmExtManager = CMMExtensionManager::NewL( *this );
       
   126 
       
   127     iScreenOn = ETrue;
       
   128     iSkinChangeNeeded = EFalse;
       
   129     iSkinChangeInProgress = EFalse;
       
   130     iHasFocus = ETrue;
       
   131 
       
   132     iSkinSrvSession.Connect(this);
       
   133     iAppkeyHandler = CMmAppkeyHandler::NewL();
       
   134 
       
   135     RProperty::Define( KMMenuPSCat, KMMenuLastViewKey, RProperty::EText );
       
   136 
       
   137     MMPERF(("CMmAppUi::ConstructL - HN ready"));
       
   138     DEBUG(("_Mm_:CMmAppUi::ConstructL OUT"));
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 TBool CMmAppUi::IsRootdisplayedL()
       
   146     {
       
   147     TBool ret( EFalse );
       
   148     if( iHNInterface && iHNInterface->GetSuiteModelsCountL() == KModelCountForRoot )
       
   149         {
       
   150         ret = ETrue;
       
   151         }
       
   152     return ret;
       
   153     }
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 CMmAppUi::CMmAppUi()
       
   160     {
       
   161     // No implementation required
       
   162     }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 CMmAppUi::~CMmAppUi()
       
   169     {
       
   170     DEBUG(("_Mm_:CMmAppUi::~CMmAppUi IN"));
       
   171 
       
   172     delete iOutOfMemoryHandler;
       
   173     if (iCurrentSuiteModel)
       
   174         {
       
   175         iCurrentSuiteModel->UnregisterSuiteObserver( this );
       
   176         }
       
   177     delete iToolbar;
       
   178     iCascadeMenuMap.Close();
       
   179     RemoveFromStack( iCurrentContainer );
       
   180     RemoveFromStack( iDummyContainer );
       
   181     iDummyContainer->MakeVisible( EFalse );
       
   182     delete iDummyContainer;
       
   183     ResetContainerMap();
       
   184     iGarbage.ResetAndDestroy();
       
   185     delete iHNInterface;
       
   186     FeatureManager::UnInitializeLib();
       
   187     delete iMmExtManager;
       
   188     delete iTemplateLibrary;
       
   189     delete iDummyTemplateLib;
       
   190     delete iAppkeyHandler;
       
   191     delete iPopupMenu;
       
   192     iSkinSrvSession.Close();
       
   193 
       
   194     MMPERF(("Matrix closed"));
       
   195     DEBUG(("_Mm_:CMmAppUi::~CMmAppUi OUT"));
       
   196 
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 void CMmAppUi::HandleResourceChangeL( TInt aType )
       
   204     {
       
   205     CAknAppUi::HandleResourceChangeL( aType );
       
   206 
       
   207     //we're interested in layout change events
       
   208     //only if container is available
       
   209     if ( aType == KEikDynamicLayoutVariantSwitch &&
       
   210             iCurrentContainer && iCurrentSuiteModel )
       
   211         {
       
   212         MMPERF(("Layout change START"));
       
   213         // Do not call StartLayoutSwitchFullScreen(),
       
   214         // layout switch effect is started automatically
       
   215         iIsKastorEffectStarted = ETrue;
       
   216         TInt lastItemIndex = iCurrentContainer->NumberOfItems() - 1;
       
   217 
       
   218         if ( lastItemIndex >= 0 && iCurrentContainer->ItemIsFullyVisible( lastItemIndex )
       
   219                 && !iCurrentContainer->IsHighlightVisible() )
       
   220             {
       
   221             iCurrentContainer->SetManualHighlightL( lastItemIndex, EFalse );
       
   222             }
       
   223         else if( !iCurrentContainer->IsHighlightVisible()
       
   224                 && iCurrentContainer->Widget()->TopItemIndex() > -1)
       
   225             {
       
   226             iCurrentContainer->SetManualHighlightL(
       
   227                     iCurrentContainer->Widget()->TopItemIndex(), EFalse );
       
   228             }
       
   229 
       
   230         iCurrentContainer->SetRect( ClientRect() );
       
   231         iDummyContainer->SetRect( ClientRect() );
       
   232 
       
   233         THashMapIter< TInt, CMmWidgetContainer* > iterator( iContainerMap );
       
   234         while( iterator.NextKey() )
       
   235             {
       
   236             CMmWidgetContainer* container = *iterator.CurrentValue();
       
   237             if ( container != iCurrentContainer )
       
   238                 {
       
   239                 container->SetRect( ClientRect() );
       
   240                 container->HandleResourceChange( aType );
       
   241                 }
       
   242             }
       
   243         ShowSuiteL();
       
   244         EndFullScreen();
       
   245         MMPERF(("Layout change END"));
       
   246         }
       
   247 
       
   248     if ( aType == KEikMessageFadeAllWindows && iCurrentContainer )
       
   249         {
       
   250         iCurrentContainer->SetIsFaded( ETrue );
       
   251         }
       
   252     else if ( aType == KEikMessageUnfadeWindows && iCurrentContainer )
       
   253         {
       
   254         iCurrentContainer->SetIsFaded( EFalse );
       
   255         }
       
   256     }
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 //
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 TBool CMmAppUi::ProcessCommandParametersL( TApaCommand aCommand,
       
   263                                                 TFileName& aDocumentName,
       
   264                                                 const TDesC8& aTail )
       
   265     {
       
   266     DEBUG(("_Mm_:CMmAppUi::ProcessCommandParametersL IN"));
       
   267     DEBUG8(("\t_Mm_:tail: %S", &aTail));
       
   268 
       
   269     if ( aTail.Length() )
       
   270         {
       
   271         DEBUG(("\t_Mm_:call HandleMessageL"));
       
   272         HandleMessageL( aTail );
       
   273         }
       
   274 
       
   275     TBool result = CEikAppUi::ProcessCommandParametersL( aCommand,
       
   276                                                     aDocumentName,
       
   277                                                     aTail );
       
   278 
       
   279     MMPERF(("Matrix started and ready!"));
       
   280     DEBUG(("_Mm_:CMmAppUi::ProcessCommandParametersL OUT"));
       
   281     return result;
       
   282     }
       
   283 
       
   284 // ---------------------------------------------------------------------------
       
   285 //
       
   286 // ---------------------------------------------------------------------------
       
   287 //
       
   288 void CMmAppUi::ProcessCommandL(TInt aCommand)
       
   289     {
       
   290     TBool ignoreCommand = EFalse;
       
   291 
       
   292     // ignore options click in edit mode and intermediate states for non-touch
       
   293     if ( aCommand == EAknSoftkeyOptions && iEditModeStatus != ENoEditMode &&
       
   294             !AknLayoutUtils::PenEnabled() )
       
   295         {
       
   296         ignoreCommand = ETrue;
       
   297         }
       
   298 
       
   299     // ignore keyselect for non-touch while in edit mode or stopping edit mode
       
   300     if ( aCommand == KKeyIdSelect && !AknLayoutUtils::PenEnabled() &&
       
   301             ( iEditModeStatus == ETransitionFromEditMode || IsEditMode() ) )
       
   302         {
       
   303         ignoreCommand = ETrue;
       
   304         }
       
   305 
       
   306     if ( !ignoreCommand )
       
   307         {
       
   308         CAknAppUi::ProcessCommandL( aCommand );
       
   309         }
       
   310 
       
   311     if ( iCurrentContainer )
       
   312       {
       
   313       iCurrentContainer->EndLongTapL();
       
   314       }
       
   315     }
       
   316 
       
   317 // ---------------------------------------------------------------------------
       
   318 //
       
   319 // ---------------------------------------------------------------------------
       
   320 //
       
   321 void CMmAppUi::ProcessMessageL( TUid /*aUid*/, const TDesC8& aParams )
       
   322     {
       
   323     DEBUG(("_Mm_:CMmAppUi::ProcessMessageL IN"));
       
   324     DEBUG8(("\t_Mm_:params: %S", &aParams));
       
   325     MMPERF(("APA Message Recieved"));
       
   326 
       
   327     // fix for the CR 417-35490
       
   328     // Handle empty message sends by AVKON after app key press or switch
       
   329     // to Menu via task swapper.
       
   330     if( !aParams.Compare( KNullDesC8 ) )
       
   331         {
       
   332         if ( !iAppkeyHandler->IsActive() )
       
   333             {
       
   334             //make dummy container visible when returning
       
   335             //to menu by AppKey
       
   336             if( iDummyContainer && iCurrentContainer )
       
   337                 {
       
   338                 iDummyContainer->MakeVisible( ETrue );
       
   339                 RefreshUiPanesL( ETrue );
       
   340                 iCurrentContainer->MakeVisible( EFalse );
       
   341                 iDummyContainer->DrawNow();
       
   342                 }
       
   343             CleanupForExitL( EExitKeyApplication );
       
   344             User::LeaveIfError( iCoeEnv->WsSession().SetWindowGroupOrdinalPosition(
       
   345             CEikonEnv::Static()->RootWin().Identifier(), 0 ) );
       
   346             iAppkeyHandler->StartL();
       
   347             }
       
   348         }
       
   349 
       
   350     // first refresh model, show afterwords
       
   351     if ( aParams.Length() )
       
   352         {
       
   353         DEBUG(("\t_Mm_:call HandleMessageL"));
       
   354         HandleMessageL( aParams );
       
   355         }
       
   356 
       
   357     MMPERF(("APA Message Processed"));
       
   358     DEBUG(("_Mm_:CMmAppUi::ProcessMessageL OUT"));
       
   359     }
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 //
       
   363 // ---------------------------------------------------------------------------
       
   364 //
       
   365 MCoeMessageObserver::TMessageResponse CMmAppUi::HandleMessageL(
       
   366          TUint32 aClientHandleOfTargetWindowGroup,
       
   367          TUid aMessageUid,
       
   368          const TDesC8& aMessageParameters )
       
   369     {
       
   370     if ( aMessageUid.iUid == KUidApaMessageSwitchOpenFileValue )
       
   371         {
       
   372         ProcessMessageL( aMessageUid, aMessageParameters );
       
   373         return EMessageHandled;
       
   374         }
       
   375     else
       
   376         {
       
   377         return CAknAppUi::HandleMessageL(
       
   378                 aClientHandleOfTargetWindowGroup,
       
   379                 aMessageUid,
       
   380                 aMessageParameters );
       
   381         }
       
   382     }
       
   383 
       
   384 // ---------------------------------------------------------------------------
       
   385 //
       
   386 // ---------------------------------------------------------------------------
       
   387 //
       
   388 void CMmAppUi::HandleCommandL( TInt aCommand )
       
   389     {
       
   390     DEBUG(("_Mm_:CMmAppUi::HandleCommandL IN"));
       
   391     DEBUG(("\t_Mm_:aCommand: %d",aCommand));
       
   392 
       
   393     // in case something has gone wrong
       
   394     ClearTransitionFromEditModeFlag();
       
   395 
       
   396     switch( aCommand )
       
   397         {
       
   398         case EEikCmdExit:
       
   399             {
       
   400             DEBUG(("\t_Mm_:EEikCmdExit"));
       
   401             // Simply exit
       
   402             Exit();
       
   403             }
       
   404             break;
       
   405 
       
   406         case EMmOptionsExit:
       
   407             {
       
   408             MMPERF(("Options->Exit pressed"));
       
   409             DEBUG(("\t_Mm_:EMmOptionsExit"));
       
   410 
       
   411             //Check if it is a folder suite.If Yes really exit.
       
   412             //Otherwise behave like LSK.
       
   413             if( iCurrentSuiteModel &&
       
   414                 iCurrentSuiteModel->SuiteName().Compare( KFolderSuite) )
       
   415                 {
       
   416                 if( iCurrentSuiteModel->ExitMode() == EExitModeHide )
       
   417                     {
       
   418                     // hide and reset menu
       
   419                     TApaTaskList taskList( iCoeEnv->WsSession() );
       
   420                     TApaTask me = taskList.FindApp( KUidMatrixMenuApp );
       
   421                     me.SendToBackground();
       
   422                     CleanupForExitL( EExitKeyApplication );
       
   423                     }
       
   424                 else
       
   425                     {
       
   426                     StartLayoutSwitchFullScreen( EMenuCloseFolderEffect );
       
   427                     HandleBackCommandL();
       
   428                     }
       
   429                 }
       
   430             else
       
   431                 {
       
   432                 ExitMatrix( EExitReally );
       
   433                 }
       
   434             }
       
   435             break;
       
   436 
       
   437         case EAknSoftkeyExit:
       
   438             {
       
   439             MMPERF(("SoftkeyExit pressed"));
       
   440             DEBUG(("\t_Mm_:EAknSoftkeyExit"));
       
   441             ExitMatrix( EExitToPhone );
       
   442             }
       
   443             break;
       
   444 
       
   445         case EAknSoftkeyBack:
       
   446             {
       
   447             StartLayoutSwitchFullScreen( EMenuCloseFolderEffect );
       
   448 
       
   449             if( iCurrentSuiteModel && iCurrentSuiteModel->ExitMode() == EExitModeHide )
       
   450                 {
       
   451                 // hide and reset menu
       
   452                 TApaTaskList taskList( iCoeEnv->WsSession() );
       
   453                 TApaTask me = taskList.FindApp( KUidMatrixMenuApp );
       
   454                 me.SendToBackground();
       
   455                 if ( iCurrentContainer )
       
   456                     {
       
   457                     iCurrentContainer->MakeVisible( EFalse );
       
   458                     }
       
   459                 iDummyContainer->MakeVisible( ETrue );
       
   460                 RefreshCbaL();
       
   461                 iDummyContainer->DrawNow();
       
   462                 CleanupForExitL( EExitKeyApplication );
       
   463                 }
       
   464             else if( iCurrentSuiteModel )
       
   465                 {
       
   466                 HandleBackCommandL();
       
   467                 }
       
   468             }
       
   469             break;
       
   470 
       
   471         case EAknSoftkeyOk:
       
   472         case EAknSoftkeyDone:
       
   473             {
       
   474             ASSERT( IsEditMode() );
       
   475             SetEditModeL( EFalse );
       
   476             }
       
   477             break;
       
   478         default:
       
   479             {
       
   480             ForwardEventToHNL( aCommand );
       
   481             }
       
   482             break;
       
   483         }
       
   484     DEBUG(("_Mm_:CMmAppUi::HandleCommandL OUT"));
       
   485     }
       
   486 
       
   487 // ---------------------------------------------------------------------------
       
   488 //
       
   489 // ---------------------------------------------------------------------------
       
   490 //
       
   491 void CMmAppUi::HandleBackCommandL()
       
   492     {
       
   493     DEBUG(("_Mm_:CMmAppUi::HandleBackCommandL IN"));
       
   494     MMPERF(("CMmAppUi::HandleBackCommandL - START"));
       
   495     DEBUG16(("\t_Mm_:current genre: %S",&iCurrentSuiteModel->SuiteName()));
       
   496 
       
   497     iDummyContainer->MakeVisible( ETrue );
       
   498     RefreshUiPanesL( ETrue );
       
   499     iCurrentContainer->MakeVisible( EFalse );
       
   500     iDummyContainer->DrawNow();
       
   501 
       
   502     iHNInterface->HandleBackEventL( iCurrentSuiteModel->SuiteName() );
       
   503 
       
   504     MMPERF(("CMmAppUi::HandleBackCommandL - DONE"));
       
   505     DEBUG(("_Mm_:CMmAppUi::HandleBackCommandL OUT"));
       
   506     }
       
   507 
       
   508 // ---------------------------------------------------------------------------
       
   509 //
       
   510 // ---------------------------------------------------------------------------
       
   511 //
       
   512 CMmWidgetContainer* CMmAppUi::GetAppropriateContainerToLoadL()
       
   513     {
       
   514     CMmWidgetContainer* retContainer = NULL;
       
   515     if ( iCurrentSuiteModel )
       
   516         {
       
   517         TInt currentSuiteId = iCurrentSuiteModel->GetItemsOrder()->GetSuiteId();
       
   518 
       
   519         CMmWidgetContainer** ret = iContainerMap.Find( currentSuiteId );
       
   520         retContainer = (ret) ? *ret : NULL;
       
   521 
       
   522         if ( ret && (*ret)->WidgetType() != iCurrentSuiteModel->WidgetType() )
       
   523             {
       
   524             iMakeHightlightedItemFullyVisible = ETrue;
       
   525             iGarbage.AppendL( *ret );
       
   526             iContainerMap.Remove(
       
   527                     iCurrentSuiteModel->GetItemsOrder()->GetSuiteId() );
       
   528             retContainer = NULL;
       
   529             }
       
   530         }
       
   531     return retContainer;
       
   532     }
       
   533 
       
   534 // ---------------------------------------------------------------------------
       
   535 //
       
   536 // ---------------------------------------------------------------------------
       
   537 //
       
   538 void CMmAppUi::ShowSuiteL()
       
   539     {
       
   540     DEBUG(("_Mm_:CMmAppUi::ShowSuiteL IN"));
       
   541 //    DEBUG16(("\t_Mm_:current genre: %S", &iCurrentSuiteModel->SuiteName()));
       
   542 
       
   543     if ( iCurrentSuiteModel )
       
   544         {
       
   545         CMmWidgetContainer* containerToLoad = GetAppropriateContainerToLoadL();
       
   546         TBool makeHandlePresentationChange( ETrue );
       
   547 
       
   548         if (!containerToLoad)
       
   549             {
       
   550             makeHandlePresentationChange = CreateNewContainerL(
       
   551                     iCurrentSuiteModel, containerToLoad );
       
   552             }
       
   553 
       
   554         if( makeHandlePresentationChange )
       
   555             {
       
   556             HandlePresentationChangeL( containerToLoad );
       
   557             }
       
   558         }
       
   559 
       
   560     DEBUG(("_Mm_:CMmAppUi::ShowSuiteL OUT"));
       
   561     }
       
   562 
       
   563 // ---------------------------------------------------------------------------
       
   564 //
       
   565 // ---------------------------------------------------------------------------
       
   566 //
       
   567 TBool CMmAppUi::CreateNewContainerL(
       
   568         CHnSuiteModel* aSuiteModel, CMmWidgetContainer*& aContainerToLoad )
       
   569     {
       
   570     TRect rect = ClientRect();
       
   571     switch( aSuiteModel->WidgetType() )
       
   572         {
       
   573         case ECoverFlowWidget :
       
   574         case EGridWidget :
       
   575             aContainerToLoad = CMmWidgetContainer::NewGridContainerL(
       
   576                     rect, this, iTemplateLibrary );
       
   577             break;
       
   578         case EListWidget :
       
   579             aContainerToLoad = CMmWidgetContainer::NewListBoxContainerL(
       
   580                     rect, this, iTemplateLibrary );
       
   581             break;
       
   582         case EUnspecified:
       
   583         default:
       
   584             return EFalse;
       
   585         }
       
   586     aContainerToLoad->SetLongTapObserver(this);
       
   587     aContainerToLoad->HandleItemAdditionL();
       
   588     iContainerMap.InsertL(
       
   589             aSuiteModel->GetItemsOrder()->GetSuiteId(),
       
   590             aContainerToLoad );
       
   591     return ETrue;
       
   592     }
       
   593 
       
   594 // ---------------------------------------------------------------------------
       
   595 //
       
   596 // ---------------------------------------------------------------------------
       
   597 //
       
   598 void CMmAppUi::ForwardEventToHNL( TInt aEvent, TInt aItemId,
       
   599         CLiwGenericParamList* aEventParams )
       
   600     {
       
   601     DEBUG(("\t_Mm_:event ID: %d for item ID %d", aEvent, aItemId));
       
   602 
       
   603     TInt id = iCurrentSuiteModel->IdByIndex( aItemId );
       
   604     if ( id >= 0 )
       
   605         {
       
   606         MMPERF(("Handling event %d for item %d - START",aEvent,aItemId));
       
   607 
       
   608         if( aEvent == KKeyIdSelect )
       
   609             {
       
   610             MMPERF(("This is a 'select' event"));
       
   611 
       
   612             TInt modelId = iCurrentSuiteModel->IdByIndex( aItemId );
       
   613             CHnItemModel* itemModel =
       
   614                 iCurrentSuiteModel->GetItemModel( modelId );
       
   615             TInt effect = GetKastorEffectL( itemModel );
       
   616             TRect rect = GetKastorRectL( itemModel, aItemId );
       
   617             TUid appUid = itemModel->GetItemType() == EItemTypeApplication ?
       
   618                 itemModel->GetItemUid() : KUidMatrixMenuApp;
       
   619 
       
   620             if (iScreenOn && IsForeground() && effect
       
   621                     != AknTransEffect::ENone)
       
   622                 {
       
   623                 DEBUG(("_MM_:CMmAppUi::ForwardEventToHNL Foreground"));
       
   624                 GfxTransEffect::BeginFullScreen(
       
   625                      effect, rect,
       
   626                      AknTransEffect::EParameterType,
       
   627                      AknTransEffect::GfxTransParam( appUid , KUidMatrixMenuApp ) );
       
   628                 }
       
   629             }
       
   630 
       
   631         iHNInterface->TriggerHnEventL( aEvent, id, aEventParams );
       
   632         MMPERF(("Handling event - END"));
       
   633         }
       
   634     }
       
   635 
       
   636 // ---------------------------------------------------------------------------
       
   637 //
       
   638 // ---------------------------------------------------------------------------
       
   639 //
       
   640 TInt CMmAppUi::GetKastorEffectL( CHnItemModel* aItemModel )
       
   641   {
       
   642   TInt effect( AknTransEffect::ENone );
       
   643     if ((IsEditMode() || iEditModeStatus == ETransitionFromEditMode)
       
   644             && !AknLayoutUtils::PenEnabled())
       
   645         {
       
   646         return effect;
       
   647         }
       
   648   switch( aItemModel->GetItemType() )
       
   649     {
       
   650     case EItemTypeApplication:
       
   651       {
       
   652       if( !IsEditMode() && !aItemModel->IsDrmExpired() )
       
   653         {
       
   654         if( aItemModel->IsRunning() )
       
   655           {
       
   656           effect = AknTransEffect::EApplicationStartSwitchRect;
       
   657           }
       
   658         else
       
   659           {
       
   660           effect = AknTransEffect::EApplicationStartRect;
       
   661           }
       
   662         }
       
   663       break;
       
   664       }
       
   665     case EItemTypeSuite:
       
   666       {
       
   667       if( !IsEditMode() )
       
   668         {
       
   669         effect = EMenuOpenFolderEffect;
       
   670         iIsKastorEffectStarted = ETrue;
       
   671         }
       
   672       break;
       
   673       }
       
   674     case EItemTypeParentFolder:
       
   675         {
       
   676             effect = EMenuCloseFolderEffect;
       
   677             iIsKastorEffectStarted = ETrue;
       
   678         break;
       
   679         }
       
   680     case EItemTypeFolder:
       
   681       {
       
   682       if (!(IsEditMode() && aItemModel->IsDeleteLocked()))
       
   683                 {
       
   684                 effect = EMenuOpenFolderEffect;
       
   685                 iIsKastorEffectStarted = ETrue;
       
   686                 }
       
   687       break;
       
   688       }
       
   689     case EItemTypeUnknown:
       
   690     default:
       
   691       {
       
   692       effect = AknTransEffect::ENone;
       
   693       break;
       
   694       }
       
   695     }
       
   696     return effect;
       
   697     }
       
   698 
       
   699 // ---------------------------------------------------------------------------
       
   700 //
       
   701 // ---------------------------------------------------------------------------
       
   702 //
       
   703 TRect CMmAppUi::GetKastorRectL( CHnItemModel* aItemModel, TInt aItemId )
       
   704     {
       
   705     TRect rect = TRect();
       
   706     if( aItemModel->GetItemType() == EItemTypeApplication )
       
   707         {
       
   708         rect = iCurrentContainer->GetItemRectL( aItemId );
       
   709         RRegion region; CleanupClosePushL( region );
       
   710         StatusPane()->GetShapeL( region, true, true );
       
   711         TInt statusPaneHeight = region.BoundingRect().Height();
       
   712         rect.iBr.iY += statusPaneHeight;
       
   713         rect.iTl.iY += statusPaneHeight;
       
   714         CleanupStack::PopAndDestroy( &region );
       
   715         }
       
   716     return rect;
       
   717     }
       
   718 
       
   719 // ---------------------------------------------------------------------------
       
   720 //
       
   721 // ---------------------------------------------------------------------------
       
   722 //
       
   723 void CMmAppUi::ForwardEventToHNL( TInt aEvent )
       
   724     {
       
   725     DEBUG(("_Mm_:CMmAppUi::ForwardEventToHNL IN"));
       
   726     DEBUG(("\t_Mm_:event ID: %d", aEvent));
       
   727 
       
   728     if ( iCurrentContainer )
       
   729         {
       
   730         TBool idByContainer = iCurrentContainer->IsHighlightVisible() &&
       
   731                 iCurrentContainer->GetSuiteModelL()->GetItemModelsCount() > 1;
       
   732         TInt current = idByContainer ?
       
   733              iCurrentContainer->GetHighlight():
       
   734              iCurrentContainer->GetSuiteModelL()->GetSuiteHighlight();
       
   735         ForwardEventToHNL( aEvent, current );
       
   736         }
       
   737 
       
   738     DEBUG(("_Mm_:CMmAppUi::ForwardEventToHNL OUT"));
       
   739     }
       
   740 
       
   741 // ---------------------------------------------------------------------------
       
   742 //
       
   743 // ---------------------------------------------------------------------------
       
   744 //
       
   745 void CMmAppUi::NotifyUiRefreshL( const THnUiRefreshType aRefreshType )
       
   746     {
       
   747     DEBUG(("_Mm_:CMmAppUi::NotifyUiRefreshL IN"));
       
   748     DEBUG(("\t_Mm_:refresh type: %d", aRefreshType));
       
   749 
       
   750     switch (aRefreshType)
       
   751         {
       
   752         case ERefreshSuite:
       
   753             TRAPD( err, ShowSuiteL() );
       
   754             if ( KErrNoMemory == err )
       
   755                 {
       
   756                 HandleOutOfMemoryL();
       
   757                 User::Leave( KErrNoMemory );
       
   758                 }
       
   759             break;
       
   760         case ERefreshToolbar:
       
   761             RefreshToolbarL();
       
   762             break;
       
   763         case EStartEditMode:
       
   764             SetEditModeL( ETrue );
       
   765             break;
       
   766         case EStopEditMode:
       
   767             SetEditModeL( EFalse );
       
   768             break;
       
   769         case EForegroundGain:
       
   770             {
       
   771             DEBUG(("_MM_:CMmAppUi::NotifyUiRefreshL Foreground"));
       
   772             TApaTaskList taskList( iCoeEnv->WsSession() );
       
   773             TApaTask me = taskList.FindApp( KUidMatrixMenuApp );
       
   774             me.BringToForeground();
       
   775             }
       
   776             break;
       
   777         case EBackgroundGain:
       
   778             {
       
   779             DEBUG(("_MM_:CMmAppUi::NotifyUiRefreshL Foreground"));
       
   780             TApaTaskList taskList( iCoeEnv->WsSession() );
       
   781             TApaTask me = taskList.FindApp( KUidMatrixMenuApp );
       
   782             me.SendToBackground();
       
   783             }
       
   784             break;
       
   785         case ELightOn:
       
   786             {
       
   787             DEBUG(("_Mm_:CMmAppUi::NotifyUiRefreshL - ELightOn"));
       
   788             iScreenOn = ETrue;
       
   789             if ( iCurrentContainer )
       
   790                 {
       
   791                 iCurrentContainer->HandleForegroundGainedL();
       
   792                 }
       
   793             }
       
   794             break;
       
   795         case ELightOff:
       
   796             {
       
   797             DEBUG(("_Mm_:CMmAppUi::NotifyUiRefreshL - ELightOff"));
       
   798             iScreenOn = EFalse;
       
   799             if (iCurrentContainer)
       
   800                 {
       
   801                 iCurrentContainer->HandleBackgroundGainedL();
       
   802                 if (IsEditMode() && iCurrentContainer->IsDraggable())
       
   803                     {
       
   804                     iCurrentContainer->CancelDragL(EFalse);
       
   805                     }
       
   806                 }
       
   807             }
       
   808             break;
       
   809         case ERemoveLiwObjects:
       
   810             {
       
   811             THashMapIter< TInt, CMmWidgetContainer* > iterator( iContainerMap );
       
   812             while( iterator.NextKey() )
       
   813                 {
       
   814                 CMmWidgetContainer** container = iterator.CurrentValue();
       
   815                 (*container)->RemoveLiwObjects();
       
   816                 }
       
   817             }
       
   818             break;
       
   819         default:
       
   820             ASSERT( false );
       
   821         }
       
   822     DEBUG(("_Mm_:CMmAppUi::NotifyUiRefreshL OUT"));
       
   823     }
       
   824 
       
   825 // ---------------------------------------------------------------------------
       
   826 //
       
   827 // ---------------------------------------------------------------------------
       
   828 //
       
   829 void CMmAppUi::RefreshToolbarL()
       
   830     {
       
   831     DEBUG(("_Mm_:CMmAppUi::RefreshToolbarL IN"));
       
   832     HandleToolbarVisibilityL();
       
   833     UpdateToolbarL();
       
   834     DEBUG(("_Mm_:CMmAppUi::RefreshToolbarL OUT"));
       
   835     }
       
   836 
       
   837 // ---------------------------------------------------------------------------
       
   838 //
       
   839 // ---------------------------------------------------------------------------
       
   840 //
       
   841 void CMmAppUi::RefreshUiPanesL( TBool aReset )
       
   842     {
       
   843     // refresh status pane
       
   844     CAknTitlePane* titlePane =
       
   845         static_cast<CAknTitlePane*>(
       
   846                 StatusPane()->ControlL(
       
   847                         TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   848 
       
   849     if( aReset )
       
   850         {
       
   851         titlePane->SetTextL( KNullDesC );
       
   852         }
       
   853     else
       
   854         {
       
   855         if ( IsEditMode() && iCurrentSuiteModel )
       
   856             {
       
   857             HBufC* title = NULL;
       
   858             if ( IsRootdisplayedL() )
       
   859                 {
       
   860                 title = StringLoader::LoadLC( R_ORG_ROOT_EDITING_TITLE );
       
   861                 }
       
   862             else
       
   863                 {
       
   864                 title = StringLoader::LoadLC(
       
   865                         R_ORG_FOLDER_EDITING_TITLE,
       
   866                         iCurrentSuiteModel->Title() );
       
   867                 }
       
   868             ASSERT( title );
       
   869             titlePane->SetTextL( title->Des() );
       
   870             CleanupStack::PopAndDestroy( title );
       
   871             }
       
   872         else if ( iCurrentSuiteModel && iCurrentContainer )
       
   873             {
       
   874             // refresh status pane
       
   875             titlePane->SetTextL( iCurrentSuiteModel->Title() );
       
   876 
       
   877             // inform AVKON about current suite to allow proper handling
       
   878             // of AppKey and FSW
       
   879             RProperty::Set( KMMenuPSCat, KMMenuLastViewKey, iCurrentSuiteModel->SuiteName() );
       
   880             }
       
   881         else
       
   882             {
       
   883             titlePane->SetTextL( KNullDesC );
       
   884             }
       
   885         }
       
   886 
       
   887     RefreshCbaL();
       
   888     SetMiddleSoftKeyL();
       
   889 
       
   890     StatusPane()->DrawNow();
       
   891     Cba()->DrawNow();
       
   892     }
       
   893 
       
   894 // ---------------------------------------------------------------------------
       
   895 //
       
   896 // ---------------------------------------------------------------------------
       
   897 //
       
   898 void CMmAppUi::RefreshCbaL()
       
   899     {
       
   900     if ( ( iDummyContainer && iDummyContainer->IsVisible() ) ||
       
   901             !iCurrentSuiteModel )
       
   902         {
       
   903         // R_MENU_SOFTKEYS_EMPTY__EMPTY looks much better than
       
   904         // R_AVKON_SOFTKEYS_EMPTY
       
   905         Cba()->SetCommandSetL( R_MENU_SOFTKEYS_EMPTY__EMPTY );
       
   906         }
       
   907     else
       
   908         {
       
   909         if ( IsEditMode() )
       
   910             {
       
   911             Cba()->SetCommandSetL( AknLayoutUtils::PenEnabled() ?
       
   912                 R_AVKON_SOFTKEYS_OPTIONS_DONE :
       
   913                 R_AVKON_SOFTKEYS_OK_EMPTY__OK );
       
   914             }
       
   915         else if ( IsRootdisplayedL() )
       
   916             {
       
   917             Cba()->SetCommandSetL( AknLayoutUtils::PenEnabled() ?
       
   918                  R_AVKON_SOFTKEYS_OPTIONS_EXIT :
       
   919                  R_AVKON_SOFTKEYS_OPTIONS_EXIT__SELECT );
       
   920             }
       
   921         else if ( iCurrentSuiteModel &&
       
   922                 iCurrentSuiteModel->SuiteName().Compare(KParamFolderSuite) )
       
   923             {
       
   924             Cba()->SetCommandSetL( AknLayoutUtils::PenEnabled() ?
       
   925                  R_MENU_SOFTKEYS_OPTIONS_BEXIT :
       
   926                  R_MENU_SOFTKEYS_OPTIONS_BEXIT__SELECT );
       
   927             }
       
   928         else
       
   929             {
       
   930             Cba()->SetCommandSetL( AknLayoutUtils::PenEnabled() ?
       
   931                 R_AVKON_SOFTKEYS_OPTIONS_BACK :
       
   932                 R_AVKON_SOFTKEYS_OPTIONS_BACK__SELECT );
       
   933             }
       
   934         }
       
   935     }
       
   936 
       
   937 // ---------------------------------------------------------------------------
       
   938 //
       
   939 // ---------------------------------------------------------------------------
       
   940 //
       
   941 TKeyResponse CMmAppUi::HandleKeyPressedL( const TKeyEvent &aKeyEvent,
       
   942             TEventCode aType )
       
   943     {
       
   944     TKeyResponse resp = EKeyWasNotConsumed;
       
   945 
       
   946     // handling enter key - touch & non touch
       
   947     if ( ( aKeyEvent.iScanCode == EStdKeyEnter ||
       
   948             aKeyEvent.iScanCode == EStdKeyNkpEnter ||
       
   949            aKeyEvent.iScanCode == EStdKeyDevice3 ) && aType == EEventKeyDown )
       
   950         {
       
   951         if ( iCurrentContainer->IsHighlightVisible() )
       
   952             {
       
   953             DEBUG(("_Mm_:CMmAppUi::HandleKeyPressedL - enter"));
       
   954             ForwardEventToHNL( KKeyIdSelect );
       
   955             resp = EKeyWasConsumed;
       
   956             }
       
   957         }
       
   958 
       
   959     //handling enter key - non touch / edit mode
       
   960     if ( ( aKeyEvent.iScanCode == EStdKeyEnter ||
       
   961             aKeyEvent.iScanCode == EStdKeyDevice3 ) &&
       
   962             aType == EEventKeyDown &&
       
   963             IsEditMode() && !Layout_Meta_Data::IsPenEnabled() )
       
   964         {
       
   965         DEBUG(("_Mm_:CMmAppUi::HandleKeyPressedL - enter in edit mode"));
       
   966         HandleCommandL( EAknSoftkeyOk );
       
   967         resp = EKeyWasConsumed;
       
   968         }
       
   969 
       
   970     // handle the key exactly as container does (the same conditions)
       
   971     if ( ( aKeyEvent.iRepeats > 0 && aType == EEventKey ) ||
       
   972             ( aKeyEvent.iRepeats == 0 && aType == EEventKeyUp ) )
       
   973         {
       
   974         TBool navigationEvent =
       
   975             aKeyEvent.iScanCode == EStdKeyRightArrow ||
       
   976             aKeyEvent.iScanCode == EStdKeyLeftArrow ||
       
   977             aKeyEvent.iScanCode == EStdKeyUpArrow ||
       
   978             aKeyEvent.iScanCode == EStdKeyDownArrow;
       
   979 
       
   980         if ( navigationEvent )
       
   981             {
       
   982             DEBUG(("_Mm_:CMmAppUi::HandleKeyPressedL - navi event: %d",
       
   983                 aKeyEvent.iScanCode));
       
   984             MMPERF(("Rocker navigation - START"));
       
   985             UpdateToolbarL();
       
   986             SetMiddleSoftKeyL();
       
   987             resp = EKeyWasConsumed;
       
   988             MMPERF(("Rocker navigation - END"));
       
   989             }
       
   990         else if ( aKeyEvent.iScanCode == EStdKeyBackspace )
       
   991             {
       
   992             // handle clear key event
       
   993             DEBUG(("_Mm_:CMmAppUi::HandleKeyPressedL - clear key"));
       
   994             ForwardEventToHNL( KKeyIdClear );
       
   995             resp = EKeyWasConsumed;
       
   996             }
       
   997         }
       
   998 
       
   999     if( aType == EEventUser )
       
  1000         {
       
  1001         if ( aKeyEvent.iScanCode == EStdKeyNull &&
       
  1002                 iCurrentContainer->IsHighlightVisible() )
       
  1003             {
       
  1004             DEBUG(("_Mm_:CMmAppUi::HandleKeyPressedL - User press -> forward key:select to HN"));
       
  1005             UpdateToolbarL();
       
  1006             SetMiddleSoftKeyL();
       
  1007             ForwardEventToHNL( KKeyIdSelect );
       
  1008             resp = EKeyWasConsumed;
       
  1009             }
       
  1010         }
       
  1011 
       
  1012     return resp;
       
  1013     }
       
  1014 
       
  1015 // -----------------------------------------------------------------------------
       
  1016 //
       
  1017 //
       
  1018 // -----------------------------------------------------------------------------
       
  1019 //
       
  1020 void CMmAppUi::HandleDragStartL( TInt aModelItemIndex )
       
  1021     {
       
  1022     MMPERF(("CMmAppUi::HandleDragStartL - START"));
       
  1023 
       
  1024     if ( IsEditMode() )
       
  1025         {
       
  1026 
       
  1027         TInt modelId = iCurrentSuiteModel->IdByIndex( aModelItemIndex );
       
  1028         if (modelId != KErrNotFound)
       
  1029             {
       
  1030             CHnItemModel *itModel = iCurrentSuiteModel->GetItemModel( modelId );
       
  1031             if (itModel->GetItemType() == EItemTypeParentFolder)
       
  1032                 {
       
  1033                 iCurrentContainer->CancelDragL( EFalse );
       
  1034                 }
       
  1035             else
       
  1036                 {
       
  1037                 iItemDragged = aModelItemIndex;
       
  1038                 iIdDragged = iCurrentSuiteModel->IdByIndex( aModelItemIndex );
       
  1039                 }
       
  1040             }
       
  1041         }
       
  1042     MMPERF(("CMmAppUi::HandleDragStartL - STOP"));
       
  1043     }
       
  1044 
       
  1045 // -----------------------------------------------------------------------------
       
  1046 //
       
  1047 //
       
  1048 // -----------------------------------------------------------------------------
       
  1049 //
       
  1050 void CMmAppUi::HandleDragOverL( TInt /* aModelItemIndex */ )
       
  1051     {
       
  1052     MMPERF(("CMmAppUi::HandleDragOverL - START"));
       
  1053 
       
  1054     MMPERF(("CMmAppUi::HandleDragOverL - STOP"));
       
  1055     }
       
  1056 
       
  1057 // -----------------------------------------------------------------------------
       
  1058 //
       
  1059 // -----------------------------------------------------------------------------
       
  1060 //
       
  1061 void CMmAppUi::HandleDraggedIndexUpdatedL( TInt  aModelItemIndex  )
       
  1062     {
       
  1063     MMPERF(("CMmAppUi::HandleDraggedIndexUpdatedL - START"));
       
  1064     iItemDragged = aModelItemIndex;
       
  1065     MMPERF(("CMmAppUi::HandleDraggedIndexUpdatedL - STOP"));
       
  1066     }
       
  1067 
       
  1068 // -----------------------------------------------------------------------------
       
  1069 //
       
  1070 // -----------------------------------------------------------------------------
       
  1071 //
       
  1072 void CMmAppUi::HandleDragStopL( TInt aModelItemIndex )
       
  1073     {
       
  1074     MMPERF(("CMmAppUi::HandleDragStopL - START"));
       
  1075     if( IsEditMode() )
       
  1076         {
       
  1077         TInt itemId = iCurrentSuiteModel->IdByIndex( aModelItemIndex );
       
  1078         TMcsItemType typeCurr =
       
  1079             iCurrentSuiteModel->GetItemType( aModelItemIndex );
       
  1080         TBool isOverFolder = ( AknLayoutUtils::PenEnabled() &&
       
  1081             ( typeCurr == EItemTypeParentFolder || typeCurr == EItemTypeFolder ) );
       
  1082         TBool isDeleteLocked = (itemId != KErrNotFound)
       
  1083                                 ? iCurrentSuiteModel->GetItemModel( itemId )->IsDeleteLocked()
       
  1084                                 : EFalse;
       
  1085 
       
  1086         TBuf8<KMaxLength> beforeCustomId;
       
  1087         beforeCustomId.Num( KErrNotFound );
       
  1088         if( aModelItemIndex + 1 < iCurrentContainer->NumberOfItems() )
       
  1089             {
       
  1090             beforeCustomId.Num( iCurrentSuiteModel->GetItemModel(
       
  1091                     iCurrentSuiteModel->IdByIndex( aModelItemIndex + 1 ) )->CustomId() );
       
  1092             }
       
  1093 
       
  1094         TBuf8<KMaxLength> draggedCustomId;
       
  1095         draggedCustomId.Num( KErrNotFound );
       
  1096         CHnItemModel* draggedModel = iCurrentSuiteModel->GetItemModel( iIdDragged );
       
  1097         if( draggedModel )
       
  1098             {
       
  1099             draggedCustomId.Num( iCurrentSuiteModel->GetItemModel( iIdDragged )->CustomId() );
       
  1100             }
       
  1101 
       
  1102         CLiwGenericParamList* eventParameters = CLiwGenericParamList::NewL();
       
  1103         CleanupStack::PushL( eventParameters );
       
  1104         CHnMdBaseKey* tempKeys = HnMdKeyFactory::CreateL(
       
  1105                 HnEvent::KEventArgNamespace8(), KKeyTypeMap(), KNullDesC8() );
       
  1106         CleanupStack::PushL( tempKeys );
       
  1107 
       
  1108         CHnMdBaseKey* baseKey = HnMdKeyFactory::CreateL(
       
  1109                 HnEvent::KEventArgNamespace8(), KKeyTypeMap(), KNullDesC8() );
       
  1110         CleanupStack::PushL( baseKey );
       
  1111         baseKey->AddSubKeyL( HnMdKeyFactory::CreateL( HnEvent::KDroppedBefore8(),
       
  1112                 KKeyTypeInteger(), beforeCustomId ) );
       
  1113         baseKey->AddSubKeyL( HnMdKeyFactory::CreateL( HnEvent::KDragged8(),
       
  1114                 KKeyTypeInteger(), draggedCustomId ) );
       
  1115         CleanupStack::Pop( baseKey );
       
  1116         tempKeys->AddSubKeyL( baseKey );
       
  1117 
       
  1118         tempKeys->ToGenericParamListL( *eventParameters );
       
  1119         CleanupStack::PopAndDestroy( tempKeys );
       
  1120 
       
  1121         TBool allowMoveInto = iCurrentContainer->AllowMove();
       
  1122 
       
  1123         if( iIdDragged != itemId && isOverFolder && !isDeleteLocked
       
  1124                 && allowMoveInto )
       
  1125             {
       
  1126             iCurrentSuiteModel->RemoveItemL( iIdDragged );
       
  1127             if( iItemDragged < aModelItemIndex )
       
  1128                 {
       
  1129                 // indices of all items after iItemDragged have been
       
  1130                 // decreased when the dragged item got removed from the
       
  1131                 // current suite; prevent highlighted item change
       
  1132                 iCurrentSuiteModel->SetSuiteHighlightL( aModelItemIndex - 1 );
       
  1133                 iCurrentContainer->SetManualHighlightL(
       
  1134                         iCurrentContainer->GetHighlight() - 1, EFalse );
       
  1135                 }
       
  1136 
       
  1137             iCurrentContainer->HandleItemRemovalL();
       
  1138             iCurrentContainer->CancelDragL( EFalse );
       
  1139 
       
  1140             iHNInterface->TriggerHnEventL( KKeyIdMoveInto, itemId, eventParameters );
       
  1141             iMakeHightlightedItemFullyVisible = ETrue;
       
  1142             }
       
  1143         else if( iIdDragged == itemId )
       
  1144             {
       
  1145             iCurrentContainer->CancelDragL( ETrue );
       
  1146             iCurrentContainer->SetTriggerMoveItemL( itemId, eventParameters );
       
  1147             // fix for: edit->move, then LSK->Up->LSK->LSK FAST... (short options show up)
       
  1148             if( !AknLayoutUtils::PenEnabled() )
       
  1149                 {
       
  1150                 CLiwGenericParamList* paramList = CLiwGenericParamList::NewLC();
       
  1151                 TLiwGenericParam command(KHnRequest, TLiwVariant( KEvaluateMdModel));
       
  1152                 paramList->AppendL( command );
       
  1153                 HandleRequestL( *paramList );
       
  1154                 CleanupStack::PopAndDestroy( paramList );
       
  1155                 }
       
  1156             }
       
  1157         else
       
  1158             {
       
  1159             iCurrentContainer->CancelDragL( ETrue );
       
  1160             if( !AknLayoutUtils::PenEnabled() )
       
  1161                 {
       
  1162                 CLiwGenericParamList* paramList = CLiwGenericParamList::NewLC();
       
  1163                 TLiwGenericParam command(KHnRequest, TLiwVariant( KEvaluateMdModel));
       
  1164                 paramList->AppendL( command );
       
  1165                 HandleRequestL( *paramList );
       
  1166                 CleanupStack::PopAndDestroy( paramList );
       
  1167                 }
       
  1168             }
       
  1169 
       
  1170         CleanupStack::PopAndDestroy( eventParameters );
       
  1171         }
       
  1172     MMPERF(("CMmAppUi::HandleDragStopL - STOP"));
       
  1173     }
       
  1174 
       
  1175 // ---------------------------------------------------------------------------
       
  1176 //
       
  1177 // ---------------------------------------------------------------------------
       
  1178 //
       
  1179 void CMmAppUi::HandleEventDraggingActionedL()
       
  1180     {
       
  1181     SetMiddleSoftKeyL();
       
  1182     UpdateToolbarL();
       
  1183     iKeyClickLocked = ETrue;
       
  1184     }
       
  1185 // ---------------------------------------------------------------------------
       
  1186 //
       
  1187 // ---------------------------------------------------------------------------
       
  1188 //
       
  1189 void CMmAppUi::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
  1190         MEikListBoxObserver::TListBoxEvent aEventType )
       
  1191     {
       
  1192     DEBUG(("_Mm_:CMmAppUi::HandleListBoxEventL IN"));
       
  1193     DEBUG(("\t_Mm_: aEventType = %d", (TInt) aEventType ) );
       
  1194 
       
  1195     TInt currentHighlight = iCurrentContainer->GetHighlight();
       
  1196 
       
  1197     DEBUG(("\t_Mm_: CurrentHighlight = %d", currentHighlight ) );
       
  1198 
       
  1199     if ( aEventType == MEikListBoxObserver::EEventItemDraggingActioned )
       
  1200         {
       
  1201         DEBUG8(("\t_Mm_:CMmAppUi::HandleListBoxEventL EEventItemDraggingActioned"));
       
  1202         HandleEventDraggingActionedL();
       
  1203         }
       
  1204     else if ( aEventType == MEikListBoxObserver::EEventPenDownOnItem )
       
  1205         {
       
  1206         DEBUG(("\t_Mm_:CMmAppUi::HandleListBoxEventL EEventItemClicked"));
       
  1207         HandleHighlightItemPenDownL( iCurrentContainer->GetHighlight() );
       
  1208         }
       
  1209     else if ( aEventType == MEikListBoxObserver::EEventItemDoubleClicked )
       
  1210         {
       
  1211         DEBUG(("\t_Mm_:CMmAppUi::HandleListBoxEventL EEventItemDoubleClicked"));
       
  1212         HandleHighlightItemDoubleClickedL( iCurrentContainer->GetHighlight() );
       
  1213         }
       
  1214     else if ( aEventType == MEikListBoxObserver::EEventItemSingleClicked )
       
  1215         {
       
  1216         DEBUG(("\t_Mm_:CMmAppUi::HandleListBoxEventL EEventItemSingleClicked"));
       
  1217         HandleHighlightItemSingleClickedL(  iCurrentContainer->Widget()->CurrentItemIndex() );
       
  1218         }
       
  1219     else if ( aEventType == MEikListBoxObserver::EEventPanningStarted )
       
  1220         {
       
  1221         iKeyClickLocked = ETrue;
       
  1222         }
       
  1223 
       
  1224     DEBUG(("_Mm_:CMmAppUi::HandleListBoxEventL OUT"));
       
  1225     }
       
  1226 
       
  1227 // ---------------------------------------------------------------------------
       
  1228 //
       
  1229 // ---------------------------------------------------------------------------
       
  1230 //
       
  1231 void CMmAppUi::HandleLongTapEventL( const TPoint& aPenEventLocation )
       
  1232     {
       
  1233     TBool popupMenuDisplayed(EFalse);
       
  1234     if (iPopupMenu)
       
  1235         {
       
  1236         delete iPopupMenu;
       
  1237         iPopupMenu = NULL;
       
  1238         }
       
  1239     iPopupMenu = CAknStylusPopUpMenu::NewL(this,aPenEventLocation);
       
  1240 
       
  1241     if ( AknLayoutUtils::LayoutMirrored() )
       
  1242         {
       
  1243         iPopupMenu->SetPosition( aPenEventLocation,
       
  1244                 CAknStylusPopUpMenu::EPositionTypeRightBottom );
       
  1245         }
       
  1246     else
       
  1247         {
       
  1248         iPopupMenu->SetPosition( aPenEventLocation,
       
  1249                 CAknStylusPopUpMenu::EPositionTypeLeftBottom );
       
  1250         }
       
  1251 
       
  1252     if( iCurrentSuiteModel == iHNInterface->GetLastSuiteModelL()
       
  1253             && iCurrentContainer->IsHighlightVisible()
       
  1254             && iCurrentContainer->GetSuiteModelL()->GetItemModelsCount() > 1 )
       
  1255         {
       
  1256         MMPERF(("CMmAppUi::DynInitMenuPaneL - START"));
       
  1257         //fill the main menu structure, look for cascade menus
       
  1258         //reset the helper hash map
       
  1259         iCascadeMenuMap.Close();
       
  1260 
       
  1261         MHnMenuItemModelIterator* menuIterator =
       
  1262                 iCurrentSuiteModel->GetMenuStructureL(
       
  1263                         iCurrentSuiteModel->IdByIndex(
       
  1264                                 iCurrentContainer->GetHighlight() ) );
       
  1265 
       
  1266         // check if there is a menu structure available
       
  1267         // for the specified item
       
  1268         if ( menuIterator )
       
  1269             {
       
  1270             //create item sorting helper objects
       
  1271             RArray<TInt> positionArray;
       
  1272             CleanupClosePushL( positionArray );
       
  1273             RHashMap<TInt, CEikMenuPaneItem::SData> menuItemMap;
       
  1274             CleanupClosePushL( menuItemMap );
       
  1275 
       
  1276             while ( menuIterator->HasNextSpecific() )
       
  1277                 {
       
  1278                 CHnMenuItemModel* childItem = menuIterator->GetNextSpecific();
       
  1279                 CEikMenuPaneItem::SData childData;
       
  1280                 childData.iCommandId = childItem->Command();
       
  1281                 childData.iText = childItem->NameL().
       
  1282                         Left( CEikMenuPaneItem::SData::ENominalTextLength );
       
  1283                 childData.iFlags = 0;
       
  1284                 childData.iCascadeId = 0;
       
  1285 
       
  1286                 positionArray.AppendL( childItem->Position() );
       
  1287                 menuItemMap.InsertL( childItem->Position(), childData );
       
  1288                 }
       
  1289 
       
  1290             positionArray.Sort();
       
  1291 
       
  1292             //add items in correct order
       
  1293             for ( TInt i = 0; i < positionArray.Count(); ++i )
       
  1294                 {
       
  1295                 iPopupMenu->AddMenuItemL(
       
  1296                         menuItemMap.FindL( positionArray[i] ).iText,
       
  1297                         menuItemMap.FindL( positionArray[i] ).iCommandId );
       
  1298                 }
       
  1299 
       
  1300             if (positionArray.Count()>0)
       
  1301                 {
       
  1302                 iPopupMenu->ShowMenu();
       
  1303                 popupMenuDisplayed = ETrue;
       
  1304                 }
       
  1305             CleanupStack::PopAndDestroy( &menuItemMap );
       
  1306             CleanupStack::PopAndDestroy( &positionArray );
       
  1307             }
       
  1308         MMPERF(("CMmAppUi::DynInitMenuPaneL - STOP"));
       
  1309         }
       
  1310 
       
  1311     if ( !popupMenuDisplayed && iCurrentContainer )
       
  1312         {
       
  1313         iCurrentContainer->EndLongTapL( ETrue );
       
  1314         HandleHighlightItemSingleClickedL(
       
  1315                 iCurrentContainer->Widget()->CurrentItemIndex() );
       
  1316         }
       
  1317     }
       
  1318 
       
  1319 // ---------------------------------------------------------------------------
       
  1320 //
       
  1321 // ---------------------------------------------------------------------------
       
  1322 //
       
  1323 void CMmAppUi::HandleHighlightItemDoubleClickedL( TInt aIndex )
       
  1324     {
       
  1325     if ( iKeyClickLocked )
       
  1326       return;
       
  1327 
       
  1328     if ( iCurrentSuiteModel->WidgetType() == EListWidget
       
  1329         && iCurrentContainer->GetPreviousHighlight() == aIndex )
       
  1330         {
       
  1331         ForwardEventToHNL( KKeyIdSelect, aIndex );
       
  1332         }
       
  1333     else if ( iCurrentSuiteModel->WidgetType() == EGridWidget
       
  1334             && IsEditMode() && iCurrentContainer->GetPreviousHighlight() == aIndex
       
  1335             && !iCurrentContainer->IsDraggable())
       
  1336         {
       
  1337         ForwardEventToHNL( KKeyIdSelect, aIndex );
       
  1338         }
       
  1339     }
       
  1340 
       
  1341 // ---------------------------------------------------------------------------
       
  1342 //
       
  1343 // ---------------------------------------------------------------------------
       
  1344 //
       
  1345 void CMmAppUi::HandleHighlightItemPenDownL( TInt /* aIndex */ )
       
  1346     {
       
  1347     DEBUG(("CMmAppUi::HandleHighlightItemPenDownL - IN"));
       
  1348     UpdateToolbarL();
       
  1349     SetMiddleSoftKeyL();
       
  1350     iKeyClickLocked = EFalse;
       
  1351     DEBUG(("CMmAppUi::HandleHighlightItemPenDownL - OUT"));
       
  1352     }
       
  1353 
       
  1354 // ---------------------------------------------------------------------------
       
  1355 //
       
  1356 // ---------------------------------------------------------------------------
       
  1357 //
       
  1358 void CMmAppUi::HandleHighlightItemSingleClickedL( TInt aIndex )
       
  1359     {
       
  1360     if ( !iKeyClickLocked && !IsFaded() )
       
  1361         {
       
  1362         ForwardEventToHNL( KKeyIdSelect, aIndex );
       
  1363         }
       
  1364     }
       
  1365 
       
  1366 // ---------------------------------------------------------------------------
       
  1367 //
       
  1368 // ---------------------------------------------------------------------------
       
  1369 //
       
  1370 void CMmAppUi::ResetContainerMap()
       
  1371     {
       
  1372     THashMapIter< TInt, CMmWidgetContainer* > iterator( iContainerMap );
       
  1373     while( iterator.NextKey() )
       
  1374         {
       
  1375         CMmWidgetContainer** container = iterator.CurrentValue();
       
  1376         delete *container;
       
  1377         iterator.RemoveCurrent();
       
  1378         }
       
  1379     iContainerMap.Close();
       
  1380     }
       
  1381 
       
  1382 // ---------------------------------------------------------------------------
       
  1383 //
       
  1384 // ---------------------------------------------------------------------------
       
  1385 //
       
  1386 void CMmAppUi::ResetContainerMapToRootL()
       
  1387     {
       
  1388     TInt err( KErrNone );
       
  1389     CHnSuiteModel* currentSuite = iHNInterface->GetLastSuiteModelL();
       
  1390 
       
  1391     // there is a loaded suite configuration
       
  1392     if( currentSuite )
       
  1393         {
       
  1394         TInt id( currentSuite->GetItemsOrder()->GetSuiteId() );
       
  1395         TRAP( err, iCurrentContainer = iContainerMap.FindL( id ) );
       
  1396 
       
  1397         // configuration loaded but there is no container
       
  1398         if( err != KErrNone )
       
  1399             {
       
  1400             HandleSuiteModelInitializedL( currentSuite );
       
  1401             }
       
  1402         else if( iContainerMap.Count() > 0 )
       
  1403             {
       
  1404             THashMapIter< TInt, CMmWidgetContainer* > iterator( iContainerMap );
       
  1405             while( iterator.NextKey() )
       
  1406                 {
       
  1407                 CMmWidgetContainer** container = iterator.CurrentValue();
       
  1408                 if( iCurrentContainer != *container )
       
  1409                     {
       
  1410                     RemoveFromStack( *container );
       
  1411                     iGarbage.AppendL( *container );
       
  1412                     iterator.RemoveCurrent();
       
  1413                     }
       
  1414                 }
       
  1415             }
       
  1416         }
       
  1417     else
       
  1418         {
       
  1419         ResetContainerMap();
       
  1420         InitializeL();
       
  1421         }
       
  1422     }
       
  1423 
       
  1424 // ---------------------------------------------------------------------------
       
  1425 //
       
  1426 // ---------------------------------------------------------------------------
       
  1427 //
       
  1428 void CMmAppUi::HandleMessageL( const TDesC8& aMessage )
       
  1429     {
       
  1430     if( iMmExtManager )
       
  1431         {
       
  1432         iMmExtManager->ExecuteActionL(TUid::Null(), KCommandDeleteDialog, NULL );
       
  1433         }
       
  1434     if ( IsEditMode() )
       
  1435         {
       
  1436         SetEditModeL( EFalse );
       
  1437         }
       
  1438     if ( aMessage.Find( KRootWithPref ) != KErrNotFound )
       
  1439         {
       
  1440         RemoveFromStack( iCurrentContainer );
       
  1441         iDummyContainer->MakeVisible( ETrue );
       
  1442         RefreshCbaL();
       
  1443         iGarbage.ResetAndDestroy();
       
  1444         ResetContainerMap();
       
  1445         iCurrentSuiteModel = NULL;
       
  1446         iCurrentContainer = NULL;
       
  1447         }
       
  1448 
       
  1449     TRAPD( err, iHNInterface->LoadSuitesFromUriL( aMessage ) );
       
  1450 
       
  1451     if ( err && iCurrentContainer && ( aMessage.Find( KSetFocusWithPref ) == KErrNotFound ) )
       
  1452         {
       
  1453         HandleSuiteEventL( ESuiteModelInitialized, iHNInterface->GetLastSuiteModelL() );
       
  1454         }
       
  1455     }
       
  1456 
       
  1457 // ---------------------------------------------------------------------------
       
  1458 //
       
  1459 // ---------------------------------------------------------------------------
       
  1460 //
       
  1461 void CMmAppUi::DynInitMenuPaneL( TInt aResourceId,
       
  1462                                  CEikMenuPane* aMenuPane )
       
  1463     {
       
  1464     aMenuPane->EnableMarqueeL( ETrue );
       
  1465     if( iCurrentSuiteModel == iHNInterface->GetLastSuiteModelL() )
       
  1466         {
       
  1467         switch ( aResourceId )
       
  1468             {
       
  1469             case R_MAIN_MENU_PANE:
       
  1470                 {
       
  1471                 MMPERF(("CMmAppUi::DynInitMenuPaneL - START"));
       
  1472                 //fill the main menu structure, look for cascade menus
       
  1473                 //reset the helper hash map
       
  1474                 iCascadeMenuMap.Close();
       
  1475 
       
  1476                 MHnMenuItemModelIterator* menuIterator = NULL;
       
  1477                 TBool ignoreItemSpecific( EFalse );
       
  1478                 if ( iCurrentSuiteModel )
       
  1479                     {
       
  1480                     TInt itemId( KErrNotFound );
       
  1481                     TBool suiteModelHasItems = iCurrentContainer->GetSuiteModelL()->GetItemModelsCount() > 1;
       
  1482                     TBool highlightVisible = iCurrentContainer->IsHighlightVisible();
       
  1483                     if ( !highlightVisible && suiteModelHasItems )
       
  1484                         {
       
  1485 //						if there is no highlight, but there are items, show menuitems for logically
       
  1486 //						current suite highlight fetched from suite model.
       
  1487                         TInt suiteHighlight = iCurrentSuiteModel->GetSuiteHighlight();
       
  1488                         ASSERT( suiteHighlight != KErrNotFound );
       
  1489                         itemId = iCurrentSuiteModel->IdByIndex( suiteHighlight );
       
  1490                         ignoreItemSpecific = ETrue;
       
  1491                         }
       
  1492                     else
       
  1493                         {
       
  1494                         TBool idByContainer = highlightVisible && suiteModelHasItems;
       
  1495                         itemId = idByContainer
       
  1496                                 ? iCurrentSuiteModel->IdByIndex( iCurrentContainer->GetHighlight() )
       
  1497                                 : iCurrentSuiteModel->IdByIndex( KErrNotFound );
       
  1498                         }
       
  1499                     menuIterator = iCurrentSuiteModel->GetMenuStructureL( itemId );
       
  1500                     }
       
  1501 
       
  1502                 // check if there is a menu structure available
       
  1503                 // for the specified item
       
  1504                 if ( menuIterator )
       
  1505                     {
       
  1506                     //create item sorting helper objects
       
  1507                     RArray<TInt> positionArray;
       
  1508                     CleanupClosePushL( positionArray );
       
  1509                     RHashMap<TInt, CEikMenuPaneItem::SData> menuItemMap;
       
  1510                     CleanupClosePushL( menuItemMap );
       
  1511 
       
  1512                     //get original (rss defined) items positions
       
  1513                     for ( TInt i = 0; i < aMenuPane->NumberOfItemsInPane(); ++i )
       
  1514                         {
       
  1515                         //multiply to make space for suite defined entries
       
  1516                         //first item has 100th conceptual position
       
  1517                         positionArray.AppendL( ( i + 1 ) * KMenuPosMultiplier );
       
  1518                         //store items, position as the key
       
  1519                         menuItemMap.InsertL( ( i + 1 ) * KMenuPosMultiplier,
       
  1520                             aMenuPane->
       
  1521                                 ItemData( aMenuPane->MenuItemCommandId( i ) ) );
       
  1522                         }
       
  1523 
       
  1524 
       
  1525                     //get custom menu items and their positions
       
  1526                     while ( menuIterator->HasNext() )
       
  1527                         {
       
  1528                         CHnMenuItemModel* menuItem = menuIterator->GetNext();
       
  1529                         if ( (menuItem->MenuItemType() == CHnMenuItemModel::EItemApplication) || !ignoreItemSpecific )
       
  1530                             {
       
  1531                             CEikMenuPaneItem::SData menuData;
       
  1532                             menuData.iCommandId = menuItem->Command();
       
  1533                             menuData.iText = menuItem->NameL().
       
  1534                                     Left( CEikMenuPaneItem::SData::ENominalTextLength );
       
  1535                             menuData.iFlags = 0;
       
  1536 
       
  1537                             //check for children
       
  1538                             MHnMenuItemModelIterator* childIterator =
       
  1539                                     menuItem->GetMenuStructure();
       
  1540                             if ( childIterator->HasNext() )
       
  1541                                 {
       
  1542                                 //this is a cascade item
       
  1543                                 //one menu item can contain only one cascade menu
       
  1544                                 //check if there are available cascade menu containers
       
  1545                                 TInt freeResource = GetNextCascadeMenuResourceId();
       
  1546                                 if ( freeResource != KErrNotFound )
       
  1547                                     {
       
  1548                                     //error checking
       
  1549                                     if( !iCascadeMenuMap.Insert( freeResource,
       
  1550                                             childIterator ) )
       
  1551                                         {
       
  1552                                         //add item only if there is an
       
  1553                                         //available resource
       
  1554                                         menuData.iCascadeId = freeResource;
       
  1555                                         }
       
  1556                                     }
       
  1557                                 }
       
  1558                             else
       
  1559                                 {
       
  1560                                 //normal entry
       
  1561                                 menuData.iCascadeId = 0;
       
  1562                                 }
       
  1563                             positionArray.AppendL( menuItem->Position() );
       
  1564                             menuItemMap.InsertL( menuItem->Position(), menuData );
       
  1565                             }
       
  1566                         }
       
  1567 
       
  1568                     aMenuPane->Reset();
       
  1569                     positionArray.Sort();
       
  1570 
       
  1571                     //add items in correct order
       
  1572                     for ( TInt i = 0; i < positionArray.Count(); ++i )
       
  1573                         {
       
  1574                         aMenuPane->
       
  1575                             AddMenuItemL(
       
  1576                                 ( menuItemMap.FindL( positionArray[i] ) ) );
       
  1577                         }
       
  1578 
       
  1579                     CleanupStack::PopAndDestroy( &menuItemMap );
       
  1580                     CleanupStack::PopAndDestroy( &positionArray );
       
  1581                     }
       
  1582                 MMPERF(("CMmAppUi::DynInitMenuPaneL - STOP"));
       
  1583                 }
       
  1584                 break;
       
  1585 
       
  1586             case R_CASCADE_MENU_PANE_1:
       
  1587             case R_CASCADE_MENU_PANE_2:
       
  1588             case R_CASCADE_MENU_PANE_3:
       
  1589                 {
       
  1590                 //realod cascade menu map
       
  1591                 ReloadCascadeMenuMapL();
       
  1592                 //fill the cascade menu panes
       
  1593                 MHnMenuItemModelIterator* childIteratorPtr =
       
  1594                     iCascadeMenuMap.FindL( aResourceId );
       
  1595 
       
  1596                 // check if child iterator available
       
  1597                 if ( childIteratorPtr )
       
  1598                     {
       
  1599                     childIteratorPtr->Reset();
       
  1600 
       
  1601                     //create item sorting helper objects
       
  1602                     RArray<TInt> positionArray;
       
  1603                     CleanupClosePushL( positionArray );
       
  1604                     RHashMap<TInt, CEikMenuPaneItem::SData> menuItemMap;
       
  1605                     CleanupClosePushL( menuItemMap );
       
  1606 
       
  1607                     while ( childIteratorPtr->HasNext() )
       
  1608                         {
       
  1609                         CHnMenuItemModel* childItem = childIteratorPtr->GetNext();
       
  1610 
       
  1611                         CEikMenuPaneItem::SData childData;
       
  1612                         childData.iCommandId = childItem->Command();
       
  1613                         childData.iText = childItem->NameL().
       
  1614                             Left( CEikMenuPaneItem::SData::ENominalTextLength );
       
  1615                         childData.iFlags = 0;
       
  1616                         childData.iCascadeId = 0;
       
  1617 
       
  1618                         positionArray.AppendL( childItem->Position() );
       
  1619                         menuItemMap.InsertL( childItem->Position(), childData );
       
  1620                         }
       
  1621 
       
  1622                     positionArray.Sort();
       
  1623                     //add items in correct order
       
  1624                     for ( TInt i = 0; i < positionArray.Count(); ++i )
       
  1625                         {
       
  1626                         aMenuPane->AddMenuItemL(
       
  1627                             ( menuItemMap.FindL( positionArray[i] ) ) );
       
  1628                         }
       
  1629 
       
  1630                     CleanupStack::PopAndDestroy( &menuItemMap );
       
  1631                     CleanupStack::PopAndDestroy( &positionArray );
       
  1632                     }
       
  1633                 }
       
  1634                 break;
       
  1635 
       
  1636             default:
       
  1637                 break;
       
  1638             }
       
  1639         }
       
  1640     else if( aResourceId == R_MAIN_MENU_PANE )
       
  1641         {
       
  1642         aMenuPane->SetItemDimmed( EMmOptionsExit, ETrue );
       
  1643         }
       
  1644     }
       
  1645 
       
  1646 // ---------------------------------------------------------------------------
       
  1647 //
       
  1648 // ---------------------------------------------------------------------------
       
  1649 //
       
  1650 void CMmAppUi::ReloadCascadeMenuMapL()
       
  1651     {
       
  1652     iCascadeMenuMap.Close();
       
  1653     MHnMenuItemModelIterator* menuIterator = NULL;
       
  1654     if ( iCurrentSuiteModel )
       
  1655         {
       
  1656         TBool idByContainer = iCurrentContainer->IsHighlightVisible() &&
       
  1657                 iCurrentContainer->GetSuiteModelL()->GetItemModelsCount() > 1;
       
  1658         TInt itemId = idByContainer ?
       
  1659             iCurrentSuiteModel->IdByIndex( iCurrentContainer->GetHighlight() ) :
       
  1660             iCurrentSuiteModel->IdByIndex( KErrNotFound );
       
  1661         menuIterator = iCurrentSuiteModel->GetMenuStructureL( itemId );
       
  1662         }
       
  1663 
       
  1664     if ( menuIterator )
       
  1665         {
       
  1666         while ( menuIterator->HasNext() )
       
  1667             {
       
  1668             CHnMenuItemModel* menuItem = menuIterator->GetNext();
       
  1669 
       
  1670             MHnMenuItemModelIterator* childIterator =
       
  1671                 menuItem->GetMenuStructure();
       
  1672             if ( childIterator->HasNext() )
       
  1673                 {
       
  1674                 TInt freeResource = GetNextCascadeMenuResourceId();
       
  1675                 if ( freeResource != KErrNotFound )
       
  1676                     {
       
  1677                     iCascadeMenuMap.Insert( freeResource, childIterator );
       
  1678                     }
       
  1679                 }
       
  1680             }
       
  1681         }
       
  1682     }
       
  1683 
       
  1684 // ---------------------------------------------------------------------------
       
  1685 //
       
  1686 // ---------------------------------------------------------------------------
       
  1687 //
       
  1688 TInt CMmAppUi::GetNextCascadeMenuResourceId()
       
  1689     {
       
  1690     //if needed add additional placeholders in matrixmenu.rss
       
  1691     //next add additional cases in this method and the
       
  1692     //CMmAppUi::DynInitMenuPaneL
       
  1693 
       
  1694     TInt freeResource( KErrNotFound );
       
  1695     switch ( iCascadeMenuMap.Count() )
       
  1696         {
       
  1697         case 0:
       
  1698             {
       
  1699             freeResource = R_CASCADE_MENU_PANE_1;
       
  1700             }
       
  1701             break;
       
  1702         case 1:
       
  1703             {
       
  1704             freeResource = R_CASCADE_MENU_PANE_2;
       
  1705             }
       
  1706             break;
       
  1707         case 2:
       
  1708             {
       
  1709             freeResource = R_CASCADE_MENU_PANE_3;
       
  1710             }
       
  1711             break;
       
  1712         default:
       
  1713             break;
       
  1714         }
       
  1715     return freeResource;
       
  1716     }
       
  1717 
       
  1718 // ---------------------------------------------------------------------------
       
  1719 //
       
  1720 // ---------------------------------------------------------------------------
       
  1721 //
       
  1722 void CMmAppUi::HandleWidgetChangeRefreshL(
       
  1723         CMmWidgetContainer* aWidgetContainer )
       
  1724     {
       
  1725     DEBUG(("_Mm_:CMmAppUi::HandleWidgetChangeRefreshL IN"));
       
  1726 
       
  1727     CMmWidgetContainer* previousContainer = iCurrentContainer;
       
  1728     if (previousContainer)
       
  1729         {
       
  1730         previousContainer->SetObserver(NULL);
       
  1731         RemoveFromStack(previousContainer);
       
  1732         }
       
  1733 
       
  1734     iCurrentContainer = aWidgetContainer;
       
  1735     iCurrentContainer->Widget()->View()->SetDisableRedraw(ETrue);
       
  1736     if( isHiddenFromFS )
       
  1737         {
       
  1738         iCurrentContainer->MakeVisible( EFalse );
       
  1739         }
       
  1740     else
       
  1741         {
       
  1742         iDummyContainer->MakeVisible( ETrue );
       
  1743         }
       
  1744 
       
  1745     RefreshCbaL();
       
  1746     iCurrentContainer->SetEditModeL( IsEditMode() );
       
  1747     iCurrentContainer->SetSuiteModelL( iCurrentSuiteModel );
       
  1748     iCurrentContainer->HandleResourceChange( KAknsMessageSkinChange );
       
  1749     iCurrentContainer->HandleResourceChange( KUidValueCoeColorSchemeChangeEvent );
       
  1750     iCurrentContainer->SetEmptyTextL( iCurrentSuiteModel->EmptyText() );
       
  1751     iCurrentContainer->SetHasFocusL( iHasFocus );
       
  1752     iCurrentContainer->SetIsFaded( IsFaded() );
       
  1753     iCurrentContainer->SetObserver( this );
       
  1754 
       
  1755     if ( previousContainer && previousContainer->WidgetType() != iCurrentContainer->WidgetType()
       
  1756             && previousContainer->GetSuiteModelL() == iCurrentContainer->GetSuiteModelL() )
       
  1757         {
       
  1758         iCurrentSuiteModel->SetSuiteHighlightL( KErrNotFound );
       
  1759         }
       
  1760 
       
  1761     AddToStackL( iCurrentContainer );
       
  1762     if ( previousContainer )
       
  1763         {
       
  1764         previousContainer->MakeVisible( EFalse );
       
  1765         }
       
  1766 
       
  1767     DEBUG(("_Mm_:CMmAppUi::HandleWidgetChangeRefreshL OUT"));
       
  1768     }
       
  1769 
       
  1770 // ---------------------------------------------------------------------------
       
  1771 //
       
  1772 // ---------------------------------------------------------------------------
       
  1773 //
       
  1774 void CMmAppUi::HandleNoWidgetChangeRefreshL()
       
  1775     {
       
  1776     if ( iCurrentSuiteModel )
       
  1777         {
       
  1778         iCurrentContainer->Widget()->View()->SetDisableRedraw(ETrue);
       
  1779         iCurrentContainer->SetEditModeL( IsEditMode() );
       
  1780         iCurrentContainer->SetSuiteModelL( iCurrentSuiteModel );
       
  1781         iCurrentContainer->SetEmptyTextL( iCurrentSuiteModel->EmptyText() );
       
  1782         iCurrentContainer->SetHasFocusL( iHasFocus );
       
  1783         iCurrentContainer->SetIsFaded( IsFaded() );
       
  1784         iCurrentContainer->SetObserver(this);
       
  1785         }
       
  1786     }
       
  1787 
       
  1788 // ---------------------------------------------------------------------------
       
  1789 //
       
  1790 // ---------------------------------------------------------------------------
       
  1791 //
       
  1792 TBool CMmAppUi::IsEditMode()
       
  1793     {
       
  1794     return (iEditModeStatus == EEditMode
       
  1795             || iEditModeStatus == ETransitionToEditMode);
       
  1796     }
       
  1797 // ---------------------------------------------------------------------------
       
  1798 //
       
  1799 // ---------------------------------------------------------------------------
       
  1800 //
       
  1801 void CMmAppUi::HandlePresentationChangeL(
       
  1802         CMmWidgetContainer* aWidgetContainer )
       
  1803     {
       
  1804     DEBUG(("_Mm_:CMmAppUi::HandlePresentationChangeL IN"));
       
  1805 
       
  1806     if ( iToolbar && iToolbar->IsShown() )
       
  1807         {
       
  1808         iToolbar->SetToolbarVisibility( EFalse );
       
  1809         }
       
  1810 
       
  1811     TBool scrollView( EFalse );
       
  1812     if( iCurrentContainer != aWidgetContainer )
       
  1813         {
       
  1814         // During open new folder cancel longTap.
       
  1815         if( iCurrentContainer && iCurrentContainer->IsEditMode() )
       
  1816             iCurrentContainer->EnableLongTapAnimation( EFalse );
       
  1817 
       
  1818         // We want a highlight to be visible while switching between
       
  1819         // grid and list views but no highlight should be visible
       
  1820         // after opening a folder.
       
  1821         TBool highlightVisibleBefore =
       
  1822                 iCurrentContainer &&
       
  1823                 aWidgetContainer &&
       
  1824                 iCurrentContainer->IsHighlightVisible() &&
       
  1825                 iCurrentContainer->WidgetType() != aWidgetContainer->WidgetType();
       
  1826 
       
  1827         HandleWidgetChangeRefreshL( aWidgetContainer );
       
  1828 
       
  1829         if ( highlightVisibleBefore )
       
  1830             {
       
  1831             iCurrentContainer->SetHighlightVisibilityL( ETrue );
       
  1832             }
       
  1833         scrollView = ETrue;
       
  1834         }
       
  1835     else
       
  1836         {
       
  1837         HandleNoWidgetChangeRefreshL();
       
  1838         }
       
  1839 
       
  1840     if( iCurrentContainer )
       
  1841         {
       
  1842         iCurrentContainer->SetRect(ClientRect());
       
  1843         iDummyContainer->SetRect(ClientRect());
       
  1844         if( IsForeground() || IsFaded() )
       
  1845             {
       
  1846             // should be called before MakeVisible (and after SetRect or SetupLayout,
       
  1847             // so that default highlight is displayed correctly when zoomed)
       
  1848             ApplyHighlightFromModelL();
       
  1849 
       
  1850             // There is defferences in code because behaviour in non-touch edit mode
       
  1851             // and non-touch edit mode is different.
       
  1852             if (!AknLayoutUtils::PenEnabled())
       
  1853                 {
       
  1854                 // While starting non-touch edit mode we have to scroll view in case when
       
  1855                 // higlighted item is placed on top/bottow row of view and there
       
  1856                 // are more rows over/under one to show all needed indicator arrows.
       
  1857                 // DrawNow() method caused jumping both scrollbar and view to old positions.
       
  1858                 iCurrentContainer->MakeVisible(ETrue);
       
  1859                 iCurrentContainer->Widget()->View()->SetDisableRedraw(EFalse);
       
  1860                 iCurrentContainer->SetEditModeL(IsEditMode());
       
  1861                 iDummyContainer->MakeVisible(EFalse);
       
  1862                 }
       
  1863             else
       
  1864                 {
       
  1865                 // For touch normal mode we have to redraw container in case
       
  1866                 // we back "parent folder" which was edited in edit mode.
       
  1867                 // Thanks to DrawNow() method we avoid drawing items's backdrop icons
       
  1868                 // and switching between edit mode's and normal mode's views
       
  1869                 iCurrentContainer->SetEditModeL(IsEditMode());
       
  1870                 iCurrentContainer->MakeVisible(ETrue);
       
  1871 
       
  1872                 // cache widget position so that we can restore it after DrawNow(), which
       
  1873                 // changes it for no apparent reason when using list view.
       
  1874                 iCurrentContainer->CacheWidgetPosition();
       
  1875 
       
  1876                 // draw container before effects gets snapshot
       
  1877                 iCurrentContainer->DrawNow();
       
  1878                 iCurrentContainer->Widget()->View()->SetDisableRedraw(EFalse);
       
  1879                 iDummyContainer->MakeVisible(EFalse);
       
  1880 
       
  1881                 // restore the correct widget position
       
  1882                 iCurrentContainer->RestoreWidgetPosition();
       
  1883                 // force scroll view to highlighted item in case we've been backing back
       
  1884                 // and change presentation mode (to list view) had been done.
       
  1885                 if( scrollView && iCurrentContainer->WidgetType() == EListWidget
       
  1886                         && iCurrentSuiteModel->GetSuiteHighlight() > KErrNotFound
       
  1887                         && !iCurrentContainer->ItemIsFullyVisible(
       
  1888                                 iCurrentSuiteModel->GetSuiteHighlight() ))
       
  1889                     {
       
  1890                     iCurrentContainer->ScrollToItemL(
       
  1891                             iCurrentSuiteModel->GetSuiteHighlight() );
       
  1892                     }
       
  1893                 }
       
  1894 
       
  1895             // refresh changed items only
       
  1896             iCurrentContainer->DrawView();
       
  1897             RefreshUiPanesL();
       
  1898             RefreshToolbarL();
       
  1899             }
       
  1900         else
       
  1901             {
       
  1902             iCurrentContainer->SetupWidgetLayoutL();
       
  1903             iCurrentContainer->Widget()->View()->SetDisableRedraw( EFalse );
       
  1904             ApplyHighlightFromModelL();
       
  1905             }
       
  1906         }
       
  1907 
       
  1908     MMPERF(("CMmAppUi::HandlePresentationChangeL - model swapped"));
       
  1909     DEBUG(("_Mm_:CMmAppUi::HandlePresentationChangeL OUT"));
       
  1910     }
       
  1911 
       
  1912 // ---------------------------------------------------------------------------
       
  1913 //
       
  1914 // ---------------------------------------------------------------------------
       
  1915 //
       
  1916 void CMmAppUi::OfferToolbarEventL( TInt aCommand )
       
  1917     {
       
  1918     TInt itemId = iCurrentSuiteModel->IdByIndex( iCurrentContainer->GetHighlight() );
       
  1919     CHnItemModel* itemModel = iCurrentSuiteModel->GetItemModel( itemId );
       
  1920     ASSERT( itemModel );
       
  1921     const CHnToolbarModel* toolbarModel = itemModel->GetToolbarModel();
       
  1922     ASSERT( toolbarModel );
       
  1923     const CHnButtonModel* buttonModel = toolbarModel->GetButton( aCommand );
       
  1924     ASSERT( buttonModel );
       
  1925 
       
  1926     ForwardEventToHNL( buttonModel->GetEventId() );
       
  1927     }
       
  1928 // ---------------------------------------------------------------------------
       
  1929 //
       
  1930 // ---------------------------------------------------------------------------
       
  1931 //
       
  1932 TInt CMmAppUi::ExecuteExtensionActionL( const TUid aUid , const TDesC& aCommand,
       
  1933                 CLiwGenericParamList* aEventParamList )
       
  1934     {
       
  1935     iCurrentContainer->SetExDialogOpened( ETrue );
       
  1936     return iMmExtManager->ExecuteActionL( aUid, aCommand, aEventParamList);
       
  1937     }
       
  1938 // ---------------------------------------------------------------------------
       
  1939 //
       
  1940 // ---------------------------------------------------------------------------
       
  1941 //
       
  1942 void CMmAppUi::HandleToolbarVisibilityL()
       
  1943     {
       
  1944     TBool suiteModelHasToolbar =
       
  1945         iCurrentSuiteModel && iCurrentSuiteModel->HasToolbar();
       
  1946 
       
  1947     if ( suiteModelHasToolbar )
       
  1948         {
       
  1949         if ( iToolbar )
       
  1950             {
       
  1951             // could have gotten hidden during view change
       
  1952             iToolbar->SetToolbarVisibility( ETrue );
       
  1953             }
       
  1954         else
       
  1955             {
       
  1956             iToolbar = CAknToolbar::NewL( R_GLOBAL_TOOLBAR );
       
  1957             iToolbar->SetToolbarObserver( this );
       
  1958             iToolbar->SetToolbarVisibility( ETrue );
       
  1959 
       
  1960             // substract the toolbar from display's visible area
       
  1961             TRect remainingArea( ClientRect() );
       
  1962             if ( !Layout_Meta_Data::IsLandscapeOrientation() )
       
  1963                 remainingArea.Resize( 0, -iToolbar->Size().iHeight );
       
  1964             iCurrentContainer->SetRect( remainingArea );
       
  1965             }
       
  1966         }
       
  1967     else if ( !suiteModelHasToolbar && iToolbar )
       
  1968         {
       
  1969         iToolbar->SetToolbarVisibility( EFalse );
       
  1970         delete iToolbar;
       
  1971         iToolbar = NULL;
       
  1972         iCurrentContainer->SetRect( ClientRect() );
       
  1973         }
       
  1974     }
       
  1975 
       
  1976 // ---------------------------------------------------------------------------
       
  1977 //
       
  1978 // ---------------------------------------------------------------------------
       
  1979 //
       
  1980 void CMmAppUi::UpdateToolbarL()
       
  1981     {
       
  1982     // drop toolbar handling if there should be none
       
  1983     if ( iToolbar && iCurrentSuiteModel->HasToolbar() )
       
  1984         {
       
  1985         iToolbar->RemoveItem( EMmToolbarControl1 );
       
  1986         iToolbar->RemoveItem( EMmToolbarControl2 );
       
  1987         iToolbar->RemoveItem( EMmToolbarControl3 );
       
  1988 
       
  1989         TInt itemId = iCurrentSuiteModel->IdByIndex( iCurrentContainer->Widget()->CurrentItemIndex() );
       
  1990         CHnItemModel* itemModel = iCurrentSuiteModel->GetItemModel( itemId );
       
  1991         if ( !itemModel )
       
  1992             {
       
  1993             return;
       
  1994             }
       
  1995         const CHnToolbarModel* toolbarModel = itemModel->GetToolbarModel();
       
  1996 
       
  1997         CAknButton* button( NULL );
       
  1998         for ( TInt i = 0; i < KNumOfButtonsInToolbar; ++i )
       
  1999             {
       
  2000             const CHnButtonModel* buttonModel = toolbarModel->GetButton( i );
       
  2001             // get button icon and help text from model
       
  2002             if ( buttonModel )
       
  2003                 {
       
  2004                 CGulIcon* originalIcon = buttonModel->GetIcon();
       
  2005                 CGulIcon* iconCopy( NULL );
       
  2006                 if ( originalIcon && originalIcon->Bitmap() )
       
  2007                     {
       
  2008                     // create a copy of the icon if exists,
       
  2009                     // CAknButton takes ownership of the icon but we
       
  2010                     // want to reuse it,
       
  2011                     // also duplicate bitmaps for proper scaling
       
  2012                     CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
       
  2013                     CleanupStack::PushL( bitmap );
       
  2014                     bitmap->Duplicate( originalIcon->Bitmap()->Handle() );
       
  2015 
       
  2016                     CFbsBitmap* mask( NULL );
       
  2017                     if ( originalIcon->Mask() )
       
  2018                         {
       
  2019                         mask = new (ELeave) CFbsBitmap;
       
  2020                         CleanupStack::PushL( mask );
       
  2021                         mask->Duplicate( originalIcon->Mask()->Handle() );
       
  2022                         }
       
  2023 
       
  2024                     iconCopy = CGulIcon::NewL( bitmap, mask );
       
  2025                     if ( mask )
       
  2026                         {
       
  2027                         CleanupStack::Pop( mask );
       
  2028                         }
       
  2029                     CleanupStack::Pop( bitmap );
       
  2030                     CleanupStack::PushL( iconCopy );
       
  2031                     }
       
  2032                 button = CAknButton::NewL( iconCopy,
       
  2033                         NULL,
       
  2034                         NULL,
       
  2035                         NULL,
       
  2036                         KNullDesC,
       
  2037                         buttonModel->GetButtonText(),
       
  2038                         0,
       
  2039                         0 );
       
  2040                 if ( iconCopy )
       
  2041                     {
       
  2042                     CleanupStack::Pop( iconCopy );
       
  2043                     }
       
  2044                 CleanupStack::PushL( button );
       
  2045                 button->SetDimmed( buttonModel->GetDimmed() );
       
  2046                 }
       
  2047             else
       
  2048                 {
       
  2049                 button = CAknButton::NewLC();
       
  2050                 }
       
  2051             iToolbar->AddItemL( button,
       
  2052                     EAknCtButton,
       
  2053                     EMmToolbarControl1 + i,
       
  2054                     0 );
       
  2055             CleanupStack::Pop( button );
       
  2056             }
       
  2057         }
       
  2058     }
       
  2059 
       
  2060 // ---------------------------------------------------------------------------
       
  2061 //
       
  2062 // ---------------------------------------------------------------------------
       
  2063 //
       
  2064 void CMmAppUi::SetEditModeL( TBool aIsEditMode )
       
  2065   {
       
  2066   MMPERF(("CMmAppUi::SetEditModeL %d - START",aIsEditMode));
       
  2067     if ( IsEditMode() != aIsEditMode && iCurrentSuiteModel )
       
  2068         {
       
  2069 
       
  2070         // stops moving items. This must be called when leaving non-touch edit mode to save
       
  2071         // the current visible order of the items. In non-touch it is called only once when completing editing
       
  2072 
       
  2073         iHNInterface->SetEditModeL(aIsEditMode);
       
  2074         iCurrentContainer->StopMovingL();
       
  2075 
       
  2076         if ( aIsEditMode )
       
  2077           {
       
  2078           iEditModeStatus = ETransitionToEditMode;
       
  2079           }
       
  2080         else
       
  2081           {
       
  2082           if ( iEditModeStatus == ETransitionToEditMode )
       
  2083             {
       
  2084             iEditModeStatus = EFastTransitionFromEditMode;
       
  2085             }
       
  2086           else
       
  2087             {
       
  2088             iEditModeStatus = ETransitionFromEditMode;
       
  2089             }
       
  2090           }
       
  2091 
       
  2092         HandleHighlightOffsetL( aIsEditMode ? EOffsetNext : EOffsetPrevious );
       
  2093         iCurrentSuiteModel->SetSuiteHighlightL(
       
  2094                 AdjustEditModeHighlightL( iCurrentSuiteModel->GetSuiteHighlight() ) );
       
  2095 
       
  2096         // update the container at the end when highlight is proper,
       
  2097         // this will ensure correct focus/unfocus action handling
       
  2098         iCurrentContainer->CacheWidgetPosition();
       
  2099         iCurrentContainer->SetEditModeL( IsEditMode() );
       
  2100 
       
  2101         if ( iCurrentContainer->IsHighlightVisible() )
       
  2102             {
       
  2103             iMakeHightlightedItemFullyVisible = ETrue;
       
  2104             }
       
  2105 
       
  2106         RefreshUiPanesL();
       
  2107 
       
  2108         //disable redraw so that no redrawing events coming from window server cause redrawing until
       
  2109         //everything is ready to draw. Then iCurrentContainer->DrawNow in HandlePresentationChangeL is called
       
  2110         if (IsEditMode())
       
  2111             {
       
  2112             iCurrentContainer->Widget()->View()->SetDisableRedraw(ETrue);
       
  2113             }
       
  2114         }
       
  2115 
       
  2116     MMPERF(("CMmAppUi::SetEditModeL - STOP"));
       
  2117     }
       
  2118 
       
  2119 // ---------------------------------------------------------------------------
       
  2120 //
       
  2121 // ---------------------------------------------------------------------------
       
  2122 //
       
  2123 void CMmAppUi::HandleWsEventL( const TWsEvent& aEvent,
       
  2124                                CCoeControl* aDestination )
       
  2125     {
       
  2126     DEBUG(("_Mm_:CMmAppUi::HandleWsEventL %d - IN", aEvent.Type()));
       
  2127 
       
  2128     if ( aEvent.Type() == KAknUidValueEndKeyCloseEvent )
       
  2129         {
       
  2130         // return when the red key was pressed
       
  2131         MMPERF(("End key pressed"));
       
  2132         DEBUG(("_Mm_:CMmAppUi::HandleWsEventL - End key"));
       
  2133         ExitMatrix( EExitToIdle );
       
  2134         return;
       
  2135         }
       
  2136 
       
  2137     TEventCode type = static_cast< TEventCode >( aEvent.Type() );
       
  2138 
       
  2139     if ( ( type == EEventFocusLost || type == KAknFullOrPartialForegroundLost )
       
  2140         && iCurrentContainer )
       
  2141         {
       
  2142         iCurrentContainer->CacheWidgetPosition();
       
  2143         }
       
  2144 
       
  2145     // base's HandleWsEventL needs to be called before foreground handling,
       
  2146     // otherwise the screen saver will be turned off
       
  2147     CAknAppUi::HandleWsEventL( aEvent, aDestination );
       
  2148 
       
  2149     // refreshes toolbar when pen down event was invoked
       
  2150     if ( type == EEventPointer )
       
  2151         {
       
  2152         if ( iCurrentSuiteModel )
       
  2153             {
       
  2154             RefreshToolbarL();
       
  2155             }
       
  2156         }
       
  2157     else if ( type == EEventFocusGained )
       
  2158         {
       
  2159         HandleFocusGainedL();
       
  2160         }
       
  2161     else if ( type == EEventFocusLost )
       
  2162         {
       
  2163         HandleFocusLostL();
       
  2164         }
       
  2165     else if ( type == KAknFullOrPartialForegroundGained )
       
  2166         {
       
  2167         HandleFullOrPartialForegroundGainedL();
       
  2168         }
       
  2169     else if( type == KAknFullOrPartialForegroundLost )
       
  2170         {
       
  2171         HandleFullOrPartialForegroundLostL();
       
  2172         }
       
  2173     }
       
  2174 
       
  2175 // ---------------------------------------------------------------------------
       
  2176 //
       
  2177 // ---------------------------------------------------------------------------
       
  2178 //
       
  2179 TErrorHandlerResponse CMmAppUi::HandleError(TInt aError,
       
  2180                                             const SExtendedError& /*aExtErr*/,
       
  2181                                             TDes& /*aErrorText*/,
       
  2182                                             TDes& /*aContextText*/ )
       
  2183     {
       
  2184     if( aError == KErrNoMemory )
       
  2185         {
       
  2186         TRAP_IGNORE( ResetToInitialStateL( ) );
       
  2187         }
       
  2188     return EErrorNotHandled;
       
  2189     }
       
  2190 
       
  2191 // ---------------------------------------------------------------------------
       
  2192 //
       
  2193 // ---------------------------------------------------------------------------
       
  2194 //
       
  2195 void CMmAppUi::HandleSuiteEventL (
       
  2196         THnCustomSuiteEvent aCustomSuiteEvent, CHnSuiteModel* aModel )
       
  2197     {
       
  2198 
       
  2199     DEBUG(("_Mm_:CMmAppUi::HandleSuiteEventL %d - IN",aCustomSuiteEvent));
       
  2200     switch ( aCustomSuiteEvent )
       
  2201         {
       
  2202         case ESuitePushedToStack:
       
  2203             {
       
  2204             aModel->RegisterSuiteObserverL( this, EPriorityMuchLess );
       
  2205             }
       
  2206             break;
       
  2207         case ESuitePoppedFromStack:
       
  2208             {
       
  2209 
       
  2210             }
       
  2211             break;
       
  2212         case ESuiteModelInitialized:
       
  2213             {
       
  2214             HandleSuiteModelInitializedL( aModel );
       
  2215             }
       
  2216             break;
       
  2217         default:
       
  2218             break;
       
  2219         }
       
  2220 
       
  2221     if ( iCurrentSuiteModel == aModel )
       
  2222         {
       
  2223         //We are interested in the following event
       
  2224         //only if they come from the current suite.
       
  2225         TBool redraw = (iScreenOn && IsForeground()) ? ETrue : EFalse;
       
  2226         switch (aCustomSuiteEvent)
       
  2227             {
       
  2228             case ESuiteModelDestroyed:
       
  2229                 {
       
  2230                 iCurrentContainer->PrepareForGarbage();
       
  2231                 iGarbage.AppendL(iCurrentContainer);
       
  2232                 iContainerMap.Remove(
       
  2233                         iCurrentSuiteModel->GetItemsOrder()->GetSuiteId());
       
  2234                 RemoveFromStack(iCurrentContainer);
       
  2235                 iDummyContainer->MakeVisible( ETrue );
       
  2236                 iCurrentContainer->SetObserver(NULL);
       
  2237                 iCurrentSuiteModel = NULL;
       
  2238                 iCurrentContainer = NULL;
       
  2239                 }
       
  2240                 break;
       
  2241             case ESuiteItemsAdded:
       
  2242                 {
       
  2243                 //we need consistent view/state before item is added
       
  2244                 //so draggind should be cancelled
       
  2245                 if( IsEditMode() && iCurrentContainer->IsDraggable() )
       
  2246                     {
       
  2247                     iCurrentContainer->CancelDragL( EFalse );
       
  2248                     iCurrentContainer->DrawNow();
       
  2249                     }
       
  2250                 HandleNumberOfItemsChangedL( EItemsAdded );
       
  2251                 }
       
  2252                 break;
       
  2253             case ESuiteItemsRemoved:
       
  2254                 {
       
  2255                 //we need consistent view/state before item is removed
       
  2256                 //so draggind should be cancelled
       
  2257                 if( IsEditMode() && iCurrentContainer->IsDraggable() )
       
  2258                     {
       
  2259                     iCurrentContainer->CancelDragL( EFalse );
       
  2260                     iCurrentContainer->DrawNow();
       
  2261                     }
       
  2262                 HandleNumberOfItemsChangedL( EItemsRemoved );
       
  2263                 }
       
  2264                 break;
       
  2265             case ESuiteItemsUpdated:
       
  2266                 {
       
  2267                 ClearTransitionFromEditModeFlag();
       
  2268                 iCurrentContainer->DrawView();
       
  2269                 }
       
  2270                 break;
       
  2271             case ESuiteHighlightChanged:
       
  2272                 {
       
  2273                 iCurrentContainer->SetManualHighlightL(
       
  2274                         iCurrentSuiteModel->GetSuiteHighlight(), redraw );
       
  2275                 }
       
  2276                 break;
       
  2277             default:
       
  2278                 break;
       
  2279             }
       
  2280         }
       
  2281     DEBUG(("_Mm_:CMmAppUi::HandleSuiteEventL OUT"));
       
  2282     }
       
  2283 
       
  2284 // ---------------------------------------------------------------------------
       
  2285 //
       
  2286 // ---------------------------------------------------------------------------
       
  2287 //
       
  2288 void CMmAppUi::ClearTransitionFromEditModeFlag()
       
  2289   {
       
  2290   if ( iEditModeStatus == ETransitionFromEditMode ||
       
  2291      iEditModeStatus == EFastTransitionFromEditMode )
       
  2292     {
       
  2293     iEditModeStatus = ENoEditMode;
       
  2294     }
       
  2295   }
       
  2296 
       
  2297 // ---------------------------------------------------------------------------
       
  2298 //
       
  2299 // ---------------------------------------------------------------------------
       
  2300 //
       
  2301 TInt CMmAppUi::AdjustEditModeHighlightL( TInt aOriginalHighlight )
       
  2302     {
       
  2303     if ( AknLayoutUtils::PenEnabled() )
       
  2304         {
       
  2305         if ( !iCurrentContainer->IsHighlightVisible()
       
  2306                 && iEditModeStatus == ETransitionToEditMode )
       
  2307             {
       
  2308             aOriginalHighlight = KErrNotFound ;
       
  2309             }
       
  2310         }
       
  2311     return aOriginalHighlight;
       
  2312     }
       
  2313 
       
  2314 // ---------------------------------------------------------------------------
       
  2315 //
       
  2316 // ---------------------------------------------------------------------------
       
  2317 //
       
  2318 void CMmAppUi::HandleOutOfMemoryL()
       
  2319     {
       
  2320     if( !iOutOfMemoryHandler )
       
  2321         {
       
  2322         iOutOfMemoryHandler = CMmNoMemory::NewL();
       
  2323         }
       
  2324     iOutOfMemoryHandler->Start();
       
  2325     }
       
  2326 
       
  2327 // ---------------------------------------------------------------------------
       
  2328 //
       
  2329 // ---------------------------------------------------------------------------
       
  2330 //
       
  2331 void CMmAppUi::ResetToInitialStateL()
       
  2332     {
       
  2333     iDummyContainer->MakeVisible( ETrue );
       
  2334     iDummyContainer->DrawNow();
       
  2335     RefreshCbaL();
       
  2336 
       
  2337     if (iCurrentSuiteModel)
       
  2338         {
       
  2339         iCurrentSuiteModel->UnregisterSuiteObserver( this );
       
  2340         }
       
  2341     RemoveFromStack( iCurrentContainer );
       
  2342     ResetContainerMap();
       
  2343     iGarbage.ResetAndDestroy();
       
  2344     delete iHNInterface;
       
  2345     iHNInterface = NULL;
       
  2346     delete iMmExtManager;
       
  2347     iMmExtManager = NULL;
       
  2348     delete iTemplateLibrary;
       
  2349     iTemplateLibrary = NULL;
       
  2350 
       
  2351     iCurrentSuiteModel = NULL;
       
  2352     iCurrentContainer = NULL;
       
  2353     iContainerMap.Close();
       
  2354     iEditModeStatus = ENoEditMode;
       
  2355 
       
  2356     GfxTransEffect::AbortFullScreen();
       
  2357     iIsKastorEffectStarted = EFalse;
       
  2358 
       
  2359     RefreshUiPanesL();
       
  2360     Cba()->MakeVisible( EFalse );
       
  2361     StatusPane()->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_USUAL );
       
  2362 
       
  2363     iHNInterface = CHnEngine::NewL( *this );
       
  2364     iTemplateLibrary = CMmTemplateLibrary::NewL();
       
  2365     InitializeL();
       
  2366 
       
  2367     iMmExtManager = CMMExtensionManager::NewL( *this );
       
  2368 
       
  2369     iScreenOn = ETrue;
       
  2370     iSkinChangeNeeded = EFalse;
       
  2371     iSkinChangeInProgress = EFalse;
       
  2372     }
       
  2373 
       
  2374 // ---------------------------------------------------------------------------
       
  2375 //
       
  2376 // ---------------------------------------------------------------------------
       
  2377 //
       
  2378 void CMmAppUi::HandleSuiteModelInitializedL( CHnSuiteModel* aModel )
       
  2379     {
       
  2380 
       
  2381     StatusPane()->MakeVisible( ETrue );
       
  2382     Cba()->MakeVisible( ETrue );
       
  2383     if ( aModel == iHNInterface->GetLastSuiteModelL() )
       
  2384         {
       
  2385         TBool showOpenFolderEffect(iCurrentSuiteModel
       
  2386                 && (iCurrentSuiteModel->CustomId() != aModel->CustomId()
       
  2387                         || iCurrentSuiteModel->WidgetType()
       
  2388                                 != aModel->WidgetType()));
       
  2389         if( showOpenFolderEffect )
       
  2390             {
       
  2391             StartLayoutSwitchFullScreen( EMenuOpenFolderEffect );
       
  2392             }
       
  2393 
       
  2394         iCurrentSuiteModel = aModel;
       
  2395         ShowSuiteL();
       
  2396         iGarbage.ResetAndDestroy();
       
  2397 
       
  2398          if ( iEditModeStatus == ETransitionToEditMode )
       
  2399             {
       
  2400             iEditModeStatus = EEditMode;
       
  2401             }
       
  2402         else if ( iEditModeStatus == ETransitionFromEditMode )
       
  2403             {
       
  2404             iEditModeStatus = ENoEditMode;
       
  2405             }
       
  2406 
       
  2407         HideMenuPaneIfVisibleL();
       
  2408         EndFullScreen();
       
  2409         }
       
  2410     else
       
  2411         {
       
  2412         if( iHNInterface->SuiteModelLoadedL(
       
  2413                 aModel->GetItemsOrder()->GetSuiteId() ) )
       
  2414             {
       
  2415             CMmWidgetContainer* containerToLoad = NULL;
       
  2416             TBool created( CreateNewContainerL( aModel, containerToLoad ) );
       
  2417             if( created )
       
  2418                 {
       
  2419                 containerToLoad->Widget()->View()->SetDisableRedraw( ETrue );
       
  2420                 containerToLoad->SetEditModeL( IsEditMode() );
       
  2421                 containerToLoad->SetSuiteModelL( aModel );
       
  2422                 containerToLoad->SetEmptyTextL( aModel->EmptyText() );
       
  2423                 containerToLoad->SetObserver( this );
       
  2424                 containerToLoad->SetRect( ClientRect() );
       
  2425                 containerToLoad->MakeVisible( EFalse );
       
  2426                 }
       
  2427             }
       
  2428         }
       
  2429     }
       
  2430 
       
  2431 // ---------------------------------------------------------------------------
       
  2432 //
       
  2433 // ---------------------------------------------------------------------------
       
  2434 //
       
  2435 void CMmAppUi::HideMenuPaneIfVisibleL()
       
  2436     {
       
  2437     if ( iEikonEnv->AppUiFactory()->MenuBar()->IsDisplayed() )
       
  2438         {
       
  2439         iEikonEnv->AppUiFactory()->MenuBar()->StopDisplayingMenuBar();
       
  2440         }
       
  2441     }
       
  2442 
       
  2443 // ---------------------------------------------------------------------------
       
  2444 //
       
  2445 // ---------------------------------------------------------------------------
       
  2446 //
       
  2447 void CMmAppUi::ExitMatrix( TExitType aExitType )
       
  2448     {
       
  2449     DEBUG(("_Mm_:CMmAppUi::ExitMatrix - IN"));
       
  2450     DEBUG(("\t_Mm_:Exit type: %d",aExitType));
       
  2451 
       
  2452     if ( aExitType == EExitReally )
       
  2453         {
       
  2454         // Calling PrepareHomescreenForMatrixExitL instead of ShowHomescreenL
       
  2455         // allows for avoiding a bug that would occur if appkey was pressed
       
  2456         // immediately after exiting the menu via Options->Exit.
       
  2457         // The bug would be that on pressing the appkey homescreen would be
       
  2458         // displayed and then the menu would appear again on the screen for
       
  2459         // a fraction of second causing an ugly and confusing flicker effect.
       
  2460         TRAP_IGNORE( PrepareHomescreenForMatrixExitL() );
       
  2461         //ShowHomescreenL( aExitType );
       
  2462         //if we got exit cmd from OS, let's really exit.
       
  2463         Exit();
       
  2464         }
       
  2465     else
       
  2466         {
       
  2467         GfxTransEffect::AbortFullScreen();
       
  2468         iIsKastorEffectStarted = EFalse;
       
  2469         StartLayoutSwitchFullScreen( AknTransEffect::EApplicationExit );
       
  2470 
       
  2471         TRAP_IGNORE( ShowHomescreenL( aExitType ) );
       
  2472         TRAP_IGNORE( CleanupForExitL( EExitKeyRed ) );
       
  2473         }
       
  2474 
       
  2475     DEBUG(("_Mm_:CMmAppUi::ExitMatrix - OUT"));
       
  2476     }
       
  2477 
       
  2478 // ---------------------------------------------------------------------------
       
  2479 //
       
  2480 // ---------------------------------------------------------------------------
       
  2481 //
       
  2482 void CMmAppUi::CleanupForExitL( TExitKeyType aExitKey )
       
  2483     {
       
  2484     DEBUG(("_Mm_:CMmAppUi::CleanupForExitL - IN"));
       
  2485 
       
  2486     // closing all dialogs opened in ui extensions before exit
       
  2487     iMmExtManager->ExecuteActionL( TUid::Null(), KCommandDeleteDialog, NULL );
       
  2488     if( IsDisplayingDialog() )
       
  2489         {
       
  2490         AknDialogShutter::ShutDialogsL( *iEikonEnv );
       
  2491         }
       
  2492 
       
  2493     if ( IsEditMode() && iCurrentContainer )
       
  2494         {
       
  2495         DEBUG(("\t_Mm_:Edit Mode turned off"));
       
  2496         iCurrentContainer->CancelDragL( EFalse );
       
  2497         SetEditModeL( EFalse );
       
  2498         }
       
  2499 
       
  2500     // reset model - revert to root if current view is not a suite view
       
  2501     CHnSuiteModel* model = iHNInterface->GetLastSuiteModelL();
       
  2502     if ( model && aExitKey == EExitKeyApplication )
       
  2503         {
       
  2504         TBool topSuiteIsBeingEvaluated =
       
  2505             !model->GetItemsOrder()->IsSuiteReadyToShow();
       
  2506         TBool topSuiteChanged = ResetToRootL();
       
  2507         model = NULL; // ResetToRootL might have deleted the model
       
  2508         TBool presentationChangeExpected = topSuiteChanged || topSuiteIsBeingEvaluated;
       
  2509 
       
  2510         TBool mustDrawImmediately =
       
  2511             !presentationChangeExpected || !iDummyContainer->IsVisible();
       
  2512 
       
  2513         if ( iCurrentContainer && mustDrawImmediately )
       
  2514             {
       
  2515             DEBUG(("\t_Mm_:Top item index reset"));
       
  2516             iCurrentContainer->ResetWidgetPosition();
       
  2517             iCurrentContainer->Widget()->UpdateScrollBarsL();
       
  2518             iCurrentContainer->MakeVisible( ETrue );
       
  2519             iCurrentContainer->DrawNow();
       
  2520             }
       
  2521         }
       
  2522 
       
  2523     DEBUG(("_Mm_:CMmAppUi::CleanupForExitL - OUT"));
       
  2524     }
       
  2525 
       
  2526 // ---------------------------------------------------------------------------
       
  2527 //
       
  2528 // ---------------------------------------------------------------------------
       
  2529 //
       
  2530 void CMmAppUi::ShowHomescreenL( TExitType  aExitType  )
       
  2531     {
       
  2532     TInt appToShowUid(0);
       
  2533     TInt idleid(0);
       
  2534     switch( aExitType )
       
  2535         {
       
  2536         case EExitToIdle:
       
  2537             {
       
  2538             User::LeaveIfError( RProperty::Get( KPSUidAiInformation,
       
  2539                     KActiveIdleUid, appToShowUid ) );
       
  2540             OpenAppL( TUid::Uid( appToShowUid ) );
       
  2541             }
       
  2542             break;
       
  2543         case EExitToPhone:
       
  2544             {
       
  2545             if( !RProperty::Get( KPSUidUikon, KUikVideoCallTopApp, idleid ) )
       
  2546                 {
       
  2547                 // Possible error code not relevant, as we have valid id anyway
       
  2548                 if( idleid == KVideoCallAppUid )
       
  2549                     {
       
  2550                     CreateActivateViewEventL( TVwsViewId(
       
  2551                             TUid::Uid( idleid ), TUid::Uid( idleid ) ),
       
  2552                             KNullUid, KNullDesC8() );
       
  2553                     break;
       
  2554                     }
       
  2555                 }
       
  2556             CAknTaskList* taskList = CAknTaskList::NewL(
       
  2557                     iCoeEnv->WsSession() );
       
  2558             TApaTask task = taskList->FindRootApp( TUid::Uid( KPhoneAppUid ) );
       
  2559             delete taskList;
       
  2560             if( task.Exists() )
       
  2561                 {
       
  2562                 CApaWindowGroupName* windowName = CApaWindowGroupName::NewLC(
       
  2563                                 iCoeEnv->WsSession(), task.WgId() );
       
  2564                 TBool hidden = windowName->Hidden();
       
  2565                 CleanupStack::PopAndDestroy( windowName );
       
  2566                 if( !hidden )
       
  2567                     {
       
  2568                     OpenAppL( TUid::Uid( KPhoneAppUid ) );
       
  2569                     break;
       
  2570                     }
       
  2571                 }
       
  2572             ShowHomescreenL( EExitToIdle );
       
  2573             }
       
  2574             break;
       
  2575         default:
       
  2576             ShowHomescreenL( EExitToPhone );
       
  2577         }
       
  2578     }
       
  2579 
       
  2580 // ---------------------------------------------------------------------------
       
  2581 //
       
  2582 // ---------------------------------------------------------------------------
       
  2583 //
       
  2584 void CMmAppUi::PrepareHomescreenForMatrixExitL()
       
  2585     {
       
  2586     TBool succeeded( EFalse );
       
  2587 
       
  2588     CAknTaskList* taskList = CAknTaskList::NewL( iCoeEnv->WsSession() );
       
  2589     TApaTask task = taskList->FindRootApp( TUid::Uid( KPhoneAppUid ) );
       
  2590     delete taskList;
       
  2591 
       
  2592     if( task.Exists() )
       
  2593         {
       
  2594         CApaWindowGroupName* windowName = CApaWindowGroupName::NewLC(
       
  2595                 iCoeEnv->WsSession(), task.WgId() );
       
  2596         if( !windowName->Hidden() )
       
  2597             {
       
  2598             succeeded = !iCoeEnv->WsSession().SetWindowGroupOrdinalPosition(
       
  2599                             task.WgId(), 1 );
       
  2600             }
       
  2601         CleanupStack::PopAndDestroy( windowName );
       
  2602         }
       
  2603 
       
  2604     if( !succeeded )
       
  2605         {
       
  2606         ShowHomescreenL( EExitReally );
       
  2607         }
       
  2608     }
       
  2609 
       
  2610 // ---------------------------------------------------------------------------
       
  2611 //
       
  2612 // ---------------------------------------------------------------------------
       
  2613 //
       
  2614 void CMmAppUi::OpenAppL( const TUid aUid )
       
  2615     {
       
  2616     DEBUG(("_Mm_:CMmAppUi::OpenAppL - IN"));
       
  2617     DEBUG(("\t_Mm_:aUid: 0x%x",aUid.iUid));
       
  2618 
       
  2619     // Get the correct application data
       
  2620     CAknTaskList* taskList = CAknTaskList::NewL( iCoeEnv->WsSession() );
       
  2621     TApaTask task = taskList->FindRootApp( aUid );
       
  2622     delete taskList;
       
  2623 
       
  2624     if ( task.Exists() )
       
  2625         {
       
  2626         CAknSgcClient::MoveApp( task.WgId(), ESgcMoveAppToForeground );
       
  2627         }
       
  2628     else
       
  2629         {
       
  2630         // Task doesn't exist, launch a new instance of an application
       
  2631         TApaAppInfo appInfo;
       
  2632         TApaAppCapabilityBuf capabilityBuf;
       
  2633         RApaLsSession lsSession;
       
  2634         User::LeaveIfError( lsSession.Connect() );
       
  2635         CleanupClosePushL( lsSession );
       
  2636         User::LeaveIfError( lsSession.GetAppInfo( appInfo, aUid ) );
       
  2637         User::LeaveIfError(
       
  2638                 lsSession.GetAppCapability( capabilityBuf, aUid ) );
       
  2639 
       
  2640         TApaAppCapability& caps = capabilityBuf();
       
  2641         TFileName appName = appInfo.iFullName;
       
  2642         CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
  2643         cmdLine->SetExecutableNameL( appName );
       
  2644 
       
  2645         if ( caps.iLaunchInBackground )
       
  2646             {
       
  2647             cmdLine->SetCommandL( EApaCommandBackground );
       
  2648             }
       
  2649         else
       
  2650             {
       
  2651             cmdLine->SetCommandL( EApaCommandRun );
       
  2652             }
       
  2653 
       
  2654         User::LeaveIfError( lsSession.StartApp( *cmdLine ) );
       
  2655 
       
  2656         CleanupStack::PopAndDestroy( cmdLine );
       
  2657         CleanupStack::PopAndDestroy( &lsSession );
       
  2658         }
       
  2659 
       
  2660     DEBUG(("_Mm_:CMmAppUi::OpenAppL - OUT"));
       
  2661     }
       
  2662 // ---------------------------------------------------------------------------
       
  2663 //
       
  2664 // ---------------------------------------------------------------------------
       
  2665 //
       
  2666 void CMmAppUi::InitializeL()
       
  2667     {
       
  2668     DEBUG(("_MM_:CMmAppUi::InitializeL IN"));
       
  2669     CLiwGenericParamList* paramList = CLiwGenericParamList::NewLC();
       
  2670     CLiwDefaultMap* map = CLiwDefaultMap::NewLC();
       
  2671 
       
  2672     HBufC* suiteName = StringLoader::LoadLC( R_MENU_TITLE );
       
  2673 
       
  2674     paramList->AppendL( TLiwGenericParam( KParamSuiteName8,
       
  2675             TLiwVariant( KParamFolderSuite ) ) );
       
  2676     map->InsertL( KParamSuiteName8, TLiwVariant( suiteName ) );
       
  2677     map->InsertL( KParamFolderId8, TLiwVariant( KParamFolderId ) );
       
  2678     map->InsertL( KParamRemoveLocked8, TLiwVariant( KParamFalse ) );
       
  2679     map->InsertL( KParentFolderId8, TLiwVariant( KParamFolderId ) );
       
  2680     map->InsertL( KTmpParentFolderId8, TLiwVariant( KParamFolderId ) );
       
  2681     paramList->AppendL( TLiwGenericParam( KParams8, TLiwVariant( map ) ) );
       
  2682 
       
  2683     iHNInterface->InitializeL( *paramList );
       
  2684 
       
  2685     CleanupStack::PopAndDestroy( suiteName );
       
  2686     CleanupStack::PopAndDestroy( map );
       
  2687     CleanupStack::PopAndDestroy( paramList );
       
  2688     DEBUG(("_MM_:CMmAppUi::InitializeL OUT"));
       
  2689     }
       
  2690 
       
  2691 // ---------------------------------------------------------------------------
       
  2692 //
       
  2693 // ---------------------------------------------------------------------------
       
  2694 //
       
  2695 void CMmAppUi::SetMiddleSoftKeyL()
       
  2696     {
       
  2697     DEBUG(("_Mm_:CMmAppUi::SetMiddleSoftKeyL - IN"));
       
  2698     if ( iCurrentSuiteModel && !AknLayoutUtils::PenEnabled() && !IsEditMode() )
       
  2699       {
       
  2700       DEBUG(("\t_Mm_:suite highlight: %d",
       
  2701                   iCurrentSuiteModel->GetSuiteHighlight()));
       
  2702 
       
  2703     TBool idByContainer = iCurrentContainer->IsHighlightVisible() &&
       
  2704         iCurrentContainer->GetSuiteModelL()->GetItemModelsCount() > 1;
       
  2705     TInt itemId = idByContainer ?
       
  2706       iCurrentSuiteModel->IdByIndex( iCurrentContainer->GetHighlight() ) :
       
  2707       iCurrentSuiteModel->IdByIndex( KErrNotFound );
       
  2708     CHnItemModel* itemModel = iCurrentSuiteModel->GetItemModel( itemId );
       
  2709 
       
  2710     CHnButtonModel* mskModel = NULL;
       
  2711 
       
  2712     if ( itemModel )
       
  2713       {
       
  2714       mskModel = itemModel->GetMiddleSoftKey();
       
  2715       }
       
  2716 
       
  2717     if ( mskModel )
       
  2718       {
       
  2719       TInt event = (mskModel->GetEventId() == KErrNotFound) ?
       
  2720           KKeyIdSelect : mskModel->GetEventId();
       
  2721       Cba()->SetCommandL( CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
  2722           event, mskModel->GetButtonText());
       
  2723       }
       
  2724     else
       
  2725       {
       
  2726       // reset to default
       
  2727       RefreshCbaL();
       
  2728       }
       
  2729       }
       
  2730     DEBUG(("_Mm_:CMmAppUi::SetMiddleSoftKeyL - OUT"));
       
  2731     }
       
  2732 
       
  2733 // ---------------------------------------------------------------------------
       
  2734 //
       
  2735 // ---------------------------------------------------------------------------
       
  2736 //
       
  2737 void CMmAppUi::StartLayoutSwitchFullScreen( TInt aKastorEffect )
       
  2738     {
       
  2739     if( ( !iIsKastorEffectStarted && iScreenOn && IsForeground() ) ||
       
  2740             aKastorEffect == AknTransEffect::EApplicationStart ||
       
  2741             aKastorEffect == AknTransEffect::EApplicationExit )
       
  2742         {
       
  2743         DEBUG(("_MM_:CMmAppUi::StartLayoutSwitchFullScreen Foreground"));
       
  2744         TUid uidNext( KUidMatrixMenuApp );
       
  2745         TUid uidPrev( KUidMatrixMenuApp );
       
  2746 
       
  2747         if( aKastorEffect == AknTransEffect::EApplicationExit )
       
  2748             {
       
  2749             uidPrev = TUid::Null();
       
  2750             }
       
  2751         else if( aKastorEffect == AknTransEffect::EApplicationStart )
       
  2752             {
       
  2753             uidPrev = uidPrev.Uid( AI_UID3_AIFW_COMMON );
       
  2754             }
       
  2755 
       
  2756         AknTransEffect::TParamBuffer params = AknTransEffect::GfxTransParam(
       
  2757                 uidNext, uidPrev, AknTransEffect::TParameter::EFlagNone );
       
  2758 
       
  2759         GfxTransEffect::BeginFullScreen( aKastorEffect, TRect(),
       
  2760                 AknTransEffect::EParameterType, params );
       
  2761 
       
  2762         iIsKastorEffectStarted = ETrue;
       
  2763         }
       
  2764     }
       
  2765 
       
  2766 // ---------------------------------------------------------------------------
       
  2767 //
       
  2768 // ---------------------------------------------------------------------------
       
  2769 //
       
  2770 void CMmAppUi::EndFullScreen()
       
  2771     {
       
  2772     if( iIsKastorEffectStarted && iScreenOn )
       
  2773         {
       
  2774         DEBUG(("_MM_:CMmAppUi::EndFullScreen Foreground"));
       
  2775         GfxTransEffect::EndFullScreen();
       
  2776         iIsKastorEffectStarted = EFalse;
       
  2777         }
       
  2778     }
       
  2779 // ---------------------------------------------------------------------------
       
  2780 //
       
  2781 // ---------------------------------------------------------------------------
       
  2782 //
       
  2783 void CMmAppUi::HandleRequestL( const CLiwGenericParamList& aParam,
       
  2784                          CLiwGenericParamList* aOutput )
       
  2785     {
       
  2786     iHNInterface->HandleRequestL( aParam, aOutput );
       
  2787     }
       
  2788 
       
  2789 // ---------------------------------------------------------------------------
       
  2790 //
       
  2791 // ---------------------------------------------------------------------------
       
  2792 //
       
  2793 TBool CMmAppUi::ResetToRootL()
       
  2794     {
       
  2795     TBool resetConsumed( EFalse );
       
  2796     if( iHNInterface && iCurrentSuiteModel &&
       
  2797             !IsRootdisplayedL() )
       
  2798         {
       
  2799         RemoveFromStack( iCurrentContainer );
       
  2800         iDummyContainer->MakeVisible( ETrue );
       
  2801         iHNInterface->HandleBackEventL(
       
  2802                 iCurrentSuiteModel->SuiteName(),
       
  2803                 iHNInterface->GetSuiteModelsCountL() - 1 );
       
  2804         ResetContainerMapToRootL();
       
  2805         if( iCurrentContainer )
       
  2806             {
       
  2807             iCurrentContainer->ResetWidgetPosition();
       
  2808             AddToStackL( iCurrentContainer );
       
  2809             }
       
  2810         RefreshUiPanesL( ETrue );
       
  2811         resetConsumed = ETrue;
       
  2812         }
       
  2813     return resetConsumed;
       
  2814     }
       
  2815 
       
  2816 // ---------------------------------------------------------------------------
       
  2817 //
       
  2818 // ---------------------------------------------------------------------------
       
  2819 //
       
  2820 void CMmAppUi::SkinContentChanged()
       
  2821     {
       
  2822     iSkinChangeNeeded = ETrue;
       
  2823     iSkinChangeInProgress = ETrue;
       
  2824     }
       
  2825 // ---------------------------------------------------------------------------
       
  2826 //
       
  2827 // ---------------------------------------------------------------------------
       
  2828 //
       
  2829 void CMmAppUi::SkinConfigurationChanged(
       
  2830         const TAknsSkinStatusConfigurationChangeReason aReason)
       
  2831     {
       
  2832         DEBUG(("_Mm_:CMmAppUi::SkinConfigurationChanged IN - aReason:%d iSkinChangeNeeded:%d iSkinChangeInProgress:%d", aReason, iSkinChangeNeeded, iSkinChangeInProgress));
       
  2833     switch (aReason)
       
  2834         {
       
  2835         case EAknsSkinStatusConfigurationMerged://      = 1,
       
  2836             {
       
  2837             iSkinChangeNeeded = ETrue;
       
  2838             iSkinChangeInProgress = ETrue;
       
  2839             }
       
  2840             break;
       
  2841         case EAknsSkinStatusConfigurationDeployed://    = 2,
       
  2842             {
       
  2843             iSkinChangeInProgress = EFalse;
       
  2844             if (IsForeground())
       
  2845                 {
       
  2846                 TRAPD( err, RefreshIconsL());
       
  2847                 if (!err)
       
  2848                     {
       
  2849                     iSkinChangeNeeded = ETrue;
       
  2850                     }
       
  2851                 }
       
  2852             }
       
  2853             break;
       
  2854         default:
       
  2855             {
       
  2856 
       
  2857             }
       
  2858         }
       
  2859         DEBUG(("_Mm_:CMmAppUi::SkinConfigurationChanged OUT - aReason:%d iSkinChangeNeeded:%d iSkinChangeInProgress:%d", aReason, iSkinChangeNeeded, iSkinChangeInProgress));
       
  2860     }
       
  2861 
       
  2862 // ---------------------------------------------------------------------------
       
  2863 //
       
  2864 // ---------------------------------------------------------------------------
       
  2865 //
       
  2866 void CMmAppUi::SkinPackageChanged(const TAknsSkinStatusPackageChangeReason /*aReason*/)
       
  2867     {
       
  2868     }
       
  2869 
       
  2870 // ---------------------------------------------------------------------------
       
  2871 //
       
  2872 // ---------------------------------------------------------------------------
       
  2873 //
       
  2874 void CMmAppUi::HandleTriggerMoveItemL( const TInt aRecipientId,
       
  2875         CLiwGenericParamList* aEventParameters)
       
  2876     {
       
  2877     iHNInterface->TriggerHnEventL( KKeyIdMove, aRecipientId, aEventParameters);
       
  2878     }
       
  2879 
       
  2880 // ---------------------------------------------------------------------------
       
  2881 //
       
  2882 // ---------------------------------------------------------------------------
       
  2883 //
       
  2884 void CMmAppUi::RefreshIconsL()
       
  2885     {
       
  2886     iSkinChangeNeeded = EFalse;
       
  2887     CLiwGenericParamList* paramList = CLiwGenericParamList::NewLC();
       
  2888     TLiwGenericParam command(KHnRequest, TLiwVariant( KRefreshIcons));
       
  2889     paramList->AppendL(command);
       
  2890     HandleRequestL(*paramList);
       
  2891     CleanupStack::PopAndDestroy(paramList);
       
  2892     if( iCurrentContainer )
       
  2893         {
       
  2894         iCurrentContainer->HandleResourceChange( KAknsMessageSkinChange );
       
  2895         }
       
  2896     }
       
  2897 
       
  2898 // ---------------------------------------------------------------------------
       
  2899 //
       
  2900 // ---------------------------------------------------------------------------
       
  2901 //
       
  2902 void CMmAppUi::HandleHighlightOffsetL( TInt aOffset )
       
  2903     {
       
  2904     if( AknLayoutUtils::PenEnabled() )
       
  2905         {
       
  2906         iHNInterface->TriggerHnEventL( KKeyIdMoveHighlight, aOffset, NULL );
       
  2907         }
       
  2908     }
       
  2909 
       
  2910 // ---------------------------------------------------------------------------
       
  2911 //
       
  2912 // ---------------------------------------------------------------------------
       
  2913 //
       
  2914 void CMmAppUi::HandleNumberOfItemsChangedL( TItemsChangeType aChange )
       
  2915     {
       
  2916     iCurrentContainer->NumberOfItemsChangedL( aChange );
       
  2917     TBool scrollConsumed( EFalse );
       
  2918     scrollConsumed =
       
  2919         iCurrentContainer->ScrollToItemL( iCurrentSuiteModel->GetSuiteHighlight() );
       
  2920     if ( !scrollConsumed || !AknLayoutUtils::PenEnabled() )
       
  2921         {
       
  2922         iCurrentContainer->DrawNow();
       
  2923         }
       
  2924     RefreshUiPanesL();
       
  2925     }
       
  2926 
       
  2927 // ---------------------------------------------------------------------------
       
  2928 //
       
  2929 // ---------------------------------------------------------------------------
       
  2930 //
       
  2931 void CMmAppUi::ApplyHighlightFromModelL()
       
  2932     {
       
  2933     if ( iCurrentSuiteModel && iCurrentContainer )
       
  2934         {
       
  2935         TInt highlightedItemIndex = iCurrentSuiteModel->GetSuiteHighlight();
       
  2936         iCurrentContainer->RestoreWidgetPosition();
       
  2937 
       
  2938         iCurrentContainer->SetManualHighlightL(
       
  2939                 highlightedItemIndex, EFalse );
       
  2940         if ( iMakeHightlightedItemFullyVisible &&
       
  2941                 !iCurrentContainer->ItemIsFullyVisible( highlightedItemIndex ) )
       
  2942             {
       
  2943             iCurrentContainer->ScrollToItemL( highlightedItemIndex );
       
  2944             }
       
  2945         iCurrentContainer->CacheWidgetPosition();
       
  2946         iMakeHightlightedItemFullyVisible = EFalse;
       
  2947         }
       
  2948     }
       
  2949 
       
  2950 // ---------------------------------------------------------------------------
       
  2951 //
       
  2952 // ---------------------------------------------------------------------------
       
  2953 //
       
  2954 void CMmAppUi::HandleFocusGainedL()
       
  2955     {
       
  2956     DEBUG(("_Mm_:CMmAppUi::HandleWsEventL "
       
  2957       "- EEventFocusGained"));
       
  2958 
       
  2959     iHasFocus = ETrue;
       
  2960 
       
  2961     // Tricky: lack of iCurrentSuiteModel indicates that suite evaluation is in
       
  2962     // progress - do not call HandlePresentationChangeL if evalution has not
       
  2963     // finished.
       
  2964     if ( iCurrentContainer && !iCurrentContainer->IsVisible() &&
       
  2965           iCurrentSuiteModel )
       
  2966         {
       
  2967         HandlePresentationChangeL( iCurrentContainer );
       
  2968         }
       
  2969 
       
  2970     if ( iCurrentSuiteModel && iCurrentContainer )
       
  2971         {
       
  2972         iDummyContainer->MakeVisible( EFalse );
       
  2973         iCurrentContainer->MakeVisible( ETrue );
       
  2974         iCurrentContainer->DrawNow();
       
  2975         }
       
  2976     if( IsForeground() )
       
  2977         {
       
  2978         RefreshUiPanesL();
       
  2979         }
       
  2980     if ( iCurrentContainer )
       
  2981         {
       
  2982         iCurrentContainer->SetHasFocusL( ETrue );
       
  2983         }
       
  2984     }
       
  2985 
       
  2986 // ---------------------------------------------------------------------------
       
  2987 //
       
  2988 // ---------------------------------------------------------------------------
       
  2989 //
       
  2990 void CMmAppUi::HandleFocusLostL()
       
  2991   {
       
  2992   DEBUG(("_Mm_:CMmAppUi::HandleWsEventL "
       
  2993       "- EEventFocusLost"));
       
  2994 
       
  2995   iHasFocus = EFalse;
       
  2996 
       
  2997   if( iCurrentContainer )
       
  2998     {
       
  2999     //This is needed in case some popup is displayed
       
  3000     //while touching item in grid. Highlight
       
  3001     //should be reset to normal then.
       
  3002     if( AknLayoutUtils::PenEnabled() )
       
  3003       {
       
  3004       if( iCurrentContainer->WidgetType() == EGridWidget && !IsEditMode() )
       
  3005         {
       
  3006         iCurrentContainer->Widget()->View()->ItemDrawer()->
       
  3007           SetFlags( CListItemDrawer::EDisableHighlight );
       
  3008         }
       
  3009       iCurrentContainer->Widget()->View()->
       
  3010       ItemDrawer()->ClearFlags( CListItemDrawer::EPressedDownState );
       
  3011       iCurrentContainer->Widget()->View()->DrawItem(
       
  3012                 iCurrentContainer->Widget()->CurrentItemIndex() ) ;
       
  3013       }
       
  3014     if( IsEditMode() && iCurrentContainer->IsDraggable() )
       
  3015       {
       
  3016       HandleDragStopL( iCurrentContainer->GetHighlight() );
       
  3017       iCurrentContainer->DrawNow();
       
  3018       }
       
  3019     iCurrentContainer->SetHasFocusL( EFalse );
       
  3020     }
       
  3021   }
       
  3022 
       
  3023 // ---------------------------------------------------------------------------
       
  3024 //
       
  3025 // ---------------------------------------------------------------------------
       
  3026 //
       
  3027 void CMmAppUi::HandleFullOrPartialForegroundGainedL()
       
  3028   {
       
  3029     DEBUG(("_Mm_:CMmAppUi::HandleWsEventL "
       
  3030             "- KAknFullOrPartialForegroundGained"));
       
  3031     //show Menu in TS when launched for the first time
       
  3032     if( isHiddenFromFS )
       
  3033         {
       
  3034         HideApplicationFromFSW( EFalse );
       
  3035         isHiddenFromFS = EFalse;
       
  3036         }
       
  3037 
       
  3038   if (iCurrentContainer && iCurrentSuiteModel )
       
  3039     {
       
  3040     iCurrentContainer->HandleForegroundGainedL();
       
  3041     iDummyContainer->MakeVisible( EFalse );
       
  3042     iCurrentContainer->MakeVisible( ETrue );
       
  3043     RefreshUiPanesL();
       
  3044     }
       
  3045   if (iSkinChangeNeeded && !iSkinChangeInProgress)
       
  3046     {
       
  3047     MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
       
  3048     if (skinInstance && !skinInstance->IsUpdateInProgress())
       
  3049       {
       
  3050       RefreshIconsL();
       
  3051 
       
  3052       }
       
  3053     }
       
  3054   }
       
  3055 
       
  3056 // ---------------------------------------------------------------------------
       
  3057 //
       
  3058 // ---------------------------------------------------------------------------
       
  3059 //
       
  3060 void CMmAppUi::HandleFullOrPartialForegroundLostL()
       
  3061   {
       
  3062   DEBUG(("_Mm_:CMmAppUi::HandleWsEventL "
       
  3063       "- KAknFullOrPartialForegroundLost"));
       
  3064   if ( iCurrentContainer )
       
  3065     {
       
  3066     iCurrentContainer->HandleBackgroundGainedL();
       
  3067     if ( IsRootdisplayedL() )
       
  3068       {
       
  3069       iCurrentContainer->RestoreWidgetPosition();
       
  3070       iCurrentContainer->CacheWidgetPosition();
       
  3071       }
       
  3072     }
       
  3073   }
       
  3074 
       
  3075 // End of File