uifw/AknGlobalUI/AknCapServer/src/AknFastswapWindowControl.cpp
changeset 0 2f259fa3e83a
child 4 8ca85d2f0db7
child 14 3320e4e6e8bb
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-2009 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:  Control container for fastswap.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <gulicon.h>
       
    21 #include <eikbtgpc.h>
       
    22 #include <eikmop.h>
       
    23 #include <AknQueryDialog.h>
       
    24 #include <eiksrvui.rsg>
       
    25 #include <StringLoader.h>
       
    26 #include <AknsDrawUtils.h>
       
    27 #include <AknsControlContext.h>
       
    28 #include <avkon.mbg>
       
    29 #include <AknsFrameBackgroundControlContext.h>
       
    30 #include <aknlayoutscalable_avkon.cdl.h>
       
    31 #include <layoutmetadata.cdl.h>
       
    32 #include <AknIconUtils.h>
       
    33 #include <eikfrlbd.h>
       
    34 #include <apgwgnam.h>
       
    35 #include <AknInfoPopupNoteController.h> // tooltip
       
    36 #include <AknBidiTextUtils.h> // method ConvertToVisualAndClipL
       
    37 #include <skinlayout.cdl.h>
       
    38 
       
    39 #include <akntransitionutils.h>
       
    40 #include <akntranseffect.h>
       
    41 #include <gfxtranseffect/gfxtranseffect.h>
       
    42 #include <WidgetRegistryConstants.h>
       
    43 #include <WidgetRegistryData.h>
       
    44 #include <featmgr.h>
       
    45 #include <aknglobalpopupprioritycontroller.h>
       
    46 #include <centralrepository.h>
       
    47 #include <AknTasHook.h>
       
    48 #include <touchfeedback.h>
       
    49 
       
    50 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
    51 #include <aknlistloadertfx.h>
       
    52 #include <aknlistboxtfxinternal.h>
       
    53 #endif // RD_UI_TRANSITION_EFFECTS_LIST
       
    54 
       
    55 #include <aknmemorycardui.rsg>
       
    56 #include <aknlongtapanimation.h>
       
    57 #include <aknstyluspopupmenu.h>
       
    58 #include <aknpointereventsuppressor.h>
       
    59 #include <pslninternalcrkeys.h>
       
    60 #include <AknStatuspaneUtils.h>
       
    61 
       
    62 #include "AknFastswapWindowControl.h"
       
    63 #include "AknFastswapWindowGrid.h"
       
    64 #include "AknCapServerEntry.h"
       
    65 #include "akntrace.h"
       
    66 void InvalidateWindows( CCoeControl* aControl )
       
    67     {
       
    68     if ( aControl )
       
    69         {
       
    70         if ( aControl->OwnsWindow() )
       
    71             {
       
    72             ( (RWindow*) aControl->DrawableWindow() )->ClearRedrawStore();
       
    73             }
       
    74 
       
    75         for ( TInt i = aControl->CountComponentControls() - 1; i >= 0; --i )
       
    76             {
       
    77             InvalidateWindows( aControl->ComponentControl( i ) );
       
    78             }
       
    79         }
       
    80     }
       
    81 
       
    82 const TInt KFSWArrayGranularity = 4;
       
    83 const TInt KMinimumSupportedApps = 20;
       
    84 
       
    85 const TBool KVerticalOrientation = EFalse;
       
    86 const TBool KLeftToRight = ETrue;
       
    87 const TBool KRightToLeft = EFalse;
       
    88 const TBool KTopToBottom = ETrue;
       
    89 
       
    90 const TInt KTooltipTimeBefore = 600;
       
    91 const TInt KTooltipTimeView = 1500;
       
    92 
       
    93 // Values for touch mode tooltip.
       
    94 const TInt KTooltipTimeBeforeTouch = 0;  
       
    95 const TInt KTooltipTimeViewTouch = 0; // Shown until canceled
       
    96 
       
    97 // Always shown applications spesified in the ui specs.
       
    98 const TInt KAlwaysShownAppCount = 3;
       
    99 const TUid KMenuAppUid  = {0x101F4CD2};
       
   100 const TUid KSearchAppUid  = {0x0EFC346A};
       
   101 
       
   102 // new idle from 3.2 onwards, old idle uid is 0x101FD64C
       
   103 const TUid KIdleAppUid  = {0x102750F0}; 
       
   104 
       
   105 const TInt KApplicationWithoutWG = KErrNotFound;
       
   106 
       
   107 const TInt KWidgetWithoutWG = KErrGeneral;
       
   108 // Uid of the Widget application.
       
   109 const TUid KWidgetAppUid  = {0x10282822};
       
   110 
       
   111 // Matrix Menu P&S category 
       
   112 const TUid KFSWMMenuPSCat = {0x101F4CD2};
       
   113 // Key that stores last used - current view (it is text value)
       
   114 const TUint KFSWMMenuLastViewKey = 0x01;
       
   115 // name of folder view
       
   116 _LIT(KFSWMMenuFolderView, "foldersuite");
       
   117 
       
   118 const TInt KTimeDelayBeforeAnimation = 200000;  // 0.2 seconds
       
   119 const TInt KLongTapDelay = 800000;  // 0.8 seconds
       
   120 const TInt KTimeNeverHappenEvent = 100000000; // 100 seconds 
       
   121 const TInt KPressedDownEffectTime = 500000;//0.5 seconds
       
   122 enum TAknCapServerCommands
       
   123     {
       
   124     EAknCapServerCmdOpen = 0x6100, 
       
   125     EAknCapServerCmdClose      
       
   126     };
       
   127 
       
   128 NONSHARABLE_CLASS(CAknFastSwapData) : public CBase, 
       
   129                                       public MAknTransitionUtilsObserver
       
   130   {
       
   131   public:
       
   132       CAknFastSwapData(TInt aKey, CAknInfoPopupNoteController* aTooltip);
       
   133   
       
   134   private:
       
   135       TInt AknTransitionCallback(TInt aEvent, TInt aState = 0,
       
   136                                  const TDesC8* aParams = NULL);
       
   137     
       
   138   private:
       
   139       CAknInfoPopupNoteController* iTooltip;
       
   140       TInt iKey;
       
   141   };
       
   142 
       
   143 CAknFastSwapData::CAknFastSwapData( TInt aKey, 
       
   144                                     CAknInfoPopupNoteController* aTooltip )
       
   145     : iTooltip( aTooltip ), iKey( aKey )
       
   146     {
       
   147     }
       
   148 
       
   149 TInt CAknFastSwapData::AknTransitionCallback(TInt aEvent, TInt /*aState*/,
       
   150                                              const TDesC8* /*aParams*/)
       
   151     {
       
   152     _AKNTRACE_FUNC_ENTER; 
       
   153     iTooltip->ShowInfoPopupNote();
       
   154 
       
   155     CAknTransitionUtils::RemoveObserver( this, aEvent );
       
   156     _AKNTRACE_FUNC_EXIT; 
       
   157     return KErrNone;
       
   158     }
       
   159 
       
   160 NONSHARABLE_CLASS(CAknWidgetList) : public CBase
       
   161     {
       
   162     public:
       
   163         static CAknWidgetList* NewL( CAknFastSwapWindowControl& aParent );
       
   164         /** Destructor */
       
   165         ~CAknWidgetList();
       
   166 
       
   167         /**
       
   168          * Initializes the list that stores widgets.
       
   169          * @return   -
       
   170          */        
       
   171         void InitializeWidgetListL();
       
   172 
       
   173         /**
       
   174          * Check if a uid is the uid of the widget application.
       
   175          * @param    aAppUid The application uid to be checked.
       
   176          * @return   ETrue application uid belongs to widget application - EFalse otherwise.
       
   177          */
       
   178         TBool IsWidgetAppUI( TUid aAppUid );
       
   179 
       
   180         /**
       
   181          * Check if the window group id value refers to widget.
       
   182          * @param aWgId window group id.
       
   183          * @return ETrue if window group id has value that refers to widget.
       
   184          */
       
   185         TBool IsWidget( TInt aWgId );
       
   186 
       
   187         /**
       
   188          * Map tasklist application index to application Uid.
       
   189          *  
       
   190          * @param    aIndex index of tasklist item array.
       
   191          * @param    aAlwaysShownCount number of applications that are always shown on
       
   192                      the active applications list.
       
   193          * @return   application Uid
       
   194          */
       
   195         TUid IndexToAppUid( TInt aIndex, TInt aAlwaysShownCount );
       
   196         
       
   197     private:
       
   198         /** Constructor */
       
   199         CAknWidgetList( CAknFastSwapWindowControl& aParent );
       
   200         void ConstructL();
       
   201         void ResetArrayOfWidgetInfo( RWidgetInfoArray& aWidgetInfoArr );
       
   202         
       
   203         static void CleanupConnect( TAny* aThis );
       
   204 
       
   205     public:
       
   206         /** Contains list of widgets that are currently running */
       
   207         RWidgetInfoArray iRunningWidgets;
       
   208     private:
       
   209         CAknFastSwapWindowControl& iParent;
       
   210         RWidgetRegistryClientSession iWidgetRegistryClientSession;
       
   211     };
       
   212 
       
   213 
       
   214 CAknWidgetList* CAknWidgetList::NewL( CAknFastSwapWindowControl& aParent )
       
   215     {
       
   216     _AKNTRACE_FUNC_ENTER;
       
   217     CAknWidgetList* self = new (ELeave) CAknWidgetList( aParent );
       
   218     CleanupStack::PushL(self);
       
   219     self->ConstructL();
       
   220     CleanupStack::Pop(); //self
       
   221     _AKNTRACE_FUNC_EXIT;
       
   222     return self;
       
   223     }
       
   224     
       
   225 CAknWidgetList::CAknWidgetList( CAknFastSwapWindowControl& aParent ): iParent( aParent )
       
   226     {
       
   227     }
       
   228 
       
   229 CAknWidgetList::~CAknWidgetList()
       
   230     {
       
   231     _AKNTRACE_FUNC_ENTER;    
       
   232     ResetArrayOfWidgetInfo( iRunningWidgets );        
       
   233     iRunningWidgets.Reset();
       
   234     _AKNTRACE_FUNC_EXIT;
       
   235     }
       
   236 
       
   237 void CAknWidgetList::ConstructL()
       
   238     {
       
   239     }
       
   240     
       
   241 void CAknWidgetList::CleanupConnect( TAny* aThis )
       
   242     {
       
   243     _AKNTRACE_FUNC_ENTER;
       
   244      (( CAknWidgetList*)aThis)->iWidgetRegistryClientSession.Disconnect();   
       
   245     _AKNTRACE_FUNC_EXIT;
       
   246     }
       
   247 
       
   248 void CAknWidgetList::InitializeWidgetListL()
       
   249     {
       
   250     _AKNTRACE_FUNC_ENTER;
       
   251     ResetArrayOfWidgetInfo( iRunningWidgets );
       
   252     iRunningWidgets.Reset();
       
   253     User::LeaveIfError( iWidgetRegistryClientSession.Connect() );
       
   254     CleanupStack::PushL( TCleanupItem( CleanupConnect, this) );
       
   255     iWidgetRegistryClientSession.RunningWidgetsL(iRunningWidgets);
       
   256     for ( TInt i = iRunningWidgets.Count() - 1; i > -1; i-- )
       
   257         {
       
   258         if ( !iWidgetRegistryClientSession.IsWidgetInFullView(iRunningWidgets[i]->iUid) )
       
   259             {
       
   260             delete iRunningWidgets[i];
       
   261             iRunningWidgets.Remove(i);
       
   262             }
       
   263         }
       
   264     CleanupStack::Pop(); // clean WidgetRegistryClientSession item
       
   265     iWidgetRegistryClientSession.Disconnect();
       
   266     _AKNTRACE_FUNC_EXIT;
       
   267     }
       
   268     
       
   269 TBool CAknWidgetList::IsWidgetAppUI( TUid aAppUid )
       
   270     {
       
   271     _AKNTRACE( "[%s] aAppUid = %d", 
       
   272 	           __FUNCTION__, aAppUid.iUid );
       
   273     return (aAppUid == KWidgetAppUid);
       
   274     }
       
   275 
       
   276 TBool CAknWidgetList::IsWidget( TInt aWgId )
       
   277     {
       
   278     _AKNTRACE( "[%s] aWgId = %d", 
       
   279 	           __FUNCTION__, aWgId );
       
   280     return (aWgId == KWidgetWithoutWG);
       
   281     }
       
   282 
       
   283 TUid CAknWidgetList::IndexToAppUid( TInt aIndex, TInt aAlwaysShownCount )
       
   284     {
       
   285     _AKNTRACE( "[%s] aIndex = %d aAlwaysShownCount = %d",
       
   286     		   __FUNCTION__, aIndex, aAlwaysShownCount );
       
   287     return iRunningWidgets[aIndex + iRunningWidgets.Count() + 
       
   288         aAlwaysShownCount - iParent.iNumberOfWGs]->iUid;
       
   289     }
       
   290 
       
   291 void CAknWidgetList::ResetArrayOfWidgetInfo( 
       
   292     RWidgetInfoArray& aWidgetInfoArr )
       
   293     {
       
   294     _AKNTRACE_FUNC_ENTER;
       
   295     for ( TInt i = 0; i < aWidgetInfoArr.Count(); i++ )
       
   296         {
       
   297         CWidgetInfo *item = aWidgetInfoArr[i];
       
   298         delete item ; 
       
   299         }
       
   300     _AKNTRACE_FUNC_EXIT;
       
   301     }
       
   302 
       
   303 
       
   304 NONSHARABLE_CLASS(CAknAlwaysShownAppList) : public CBase
       
   305     {
       
   306     public:
       
   307        // always shown application info  
       
   308        // used in the always shown application list
       
   309        struct SAlwaysShownAppInfo
       
   310             {
       
   311             TUid iAppUid;
       
   312             TInt iWgId;
       
   313             };    
       
   314     public:
       
   315         static CAknAlwaysShownAppList* NewL( CAknFastSwapWindowControl& aParent );
       
   316         CAknAlwaysShownAppList( CAknFastSwapWindowControl& aParent );
       
   317         ~CAknAlwaysShownAppList();
       
   318         
       
   319         /**
       
   320         * Initializes the list that stores applications that are always 
       
   321         * shown in the fast swap provided they have been installed
       
   322         * in the phone rom
       
   323         * @return   -
       
   324         */        
       
   325         void InitializeAlwaysShownListL();
       
   326         
       
   327         /**
       
   328         * Add window group id to spesific appication (=uid)
       
   329         * @return   -    
       
   330         * @param    TUid aAppUid the application uid      
       
   331         * @param    TInt aWgId the window group where task resides 
       
   332         */        
       
   333         void AddWgGroupToAlwaysShownList( TUid aAppUid, TInt aWgId ); 
       
   334 
       
   335         /**
       
   336         * If application uid exists in the always shown application list 
       
   337         * @return   ETrue  application uid exists in the list
       
   338         *           EFalse application uid doesn't exist in the list
       
   339         * @param    TUid aAppUid the application uid
       
   340         */        
       
   341         TBool IsAlwaysShownApp( TUid aAppUid );
       
   342 
       
   343         /**
       
   344         * If application window group exists in the always shown application list 
       
   345         * @return   ETrue  wg exists in the list
       
   346         *           EFalse wg doesn't exist in the list
       
   347         * @param    TInt aWgId the application window group      
       
   348         */        
       
   349         TBool IsAlwaysShownApp( TInt aWgId );
       
   350 
       
   351         /**
       
   352         *
       
   353         * Map Tasklist application index to application Uid
       
   354         * @return   TUid application Uid
       
   355         *  
       
   356         * @param    TInt aIndex index of tasklist item arrays
       
   357         */ 
       
   358         TUid IndexToAppUid( TInt aIndex );
       
   359 
       
   360     public:
       
   361         RArray<SAlwaysShownAppInfo>* iAppList;
       
   362     private:
       
   363         void ConstructL();
       
   364     private:
       
   365         // the list of applications always shown in the fsw
       
   366         CAknFastSwapWindowControl& iParent;
       
   367     };
       
   368 
       
   369 // ---------------------------------------------------------
       
   370 // CAknFastSwapWindowControl::NewL
       
   371 // ---------------------------------------------------------
       
   372 //  
       
   373 CAknAlwaysShownAppList* CAknAlwaysShownAppList::NewL( CAknFastSwapWindowControl& aParent )
       
   374     {
       
   375     _AKNTRACE_FUNC_ENTER;    
       
   376     CAknAlwaysShownAppList* self = new (ELeave) CAknAlwaysShownAppList( aParent );
       
   377     CleanupStack::PushL(self);
       
   378     self->ConstructL();
       
   379     CleanupStack::Pop(); //self
       
   380     _AKNTRACE_FUNC_EXIT;    
       
   381     return self;
       
   382     }
       
   383     
       
   384 // ---------------------------------------------------------
       
   385 // CAknFastSwapWindowControl::CAknAlwaysShownAppList
       
   386 // ---------------------------------------------------------
       
   387 //  
       
   388 CAknAlwaysShownAppList::CAknAlwaysShownAppList( CAknFastSwapWindowControl& aParent )
       
   389 : iParent( aParent )
       
   390     {
       
   391     }
       
   392 
       
   393 // ---------------------------------------------------------
       
   394 // CAknFastSwapWindowControl::~CAknAlwaysShownAppList
       
   395 // ---------------------------------------------------------
       
   396 //
       
   397 CAknAlwaysShownAppList::~CAknAlwaysShownAppList()
       
   398     {
       
   399     _AKNTRACE_FUNC_ENTER;
       
   400     if (iAppList)
       
   401         {
       
   402         iAppList->Close();
       
   403         }
       
   404     delete iAppList;
       
   405     _AKNTRACE_FUNC_EXIT;
       
   406     }
       
   407 
       
   408 // ---------------------------------------------------------
       
   409 // CAknFastSwapWindowControl::ConstructL
       
   410 // ---------------------------------------------------------
       
   411 //
       
   412 void CAknAlwaysShownAppList::ConstructL()
       
   413     {
       
   414     // the list for always shown applications in the fast swap
       
   415     iAppList = new (ELeave) RArray<SAlwaysShownAppInfo>();    
       
   416     }
       
   417 
       
   418 // ---------------------------------------------------------
       
   419 // CAknFastSwapWindowControl::InitializeAlwaysShownListL
       
   420 // Applications that are always shown in fast swap are stored 
       
   421 // in different their own list whether they exist
       
   422 // in the phone rom or not
       
   423 // ---------------------------------------------------------
       
   424 //
       
   425 void CAknAlwaysShownAppList::InitializeAlwaysShownListL()
       
   426     {
       
   427     _AKNTRACE_FUNC_ENTER;
       
   428     iAppList->Close();
       
   429     // order of always shown applications
       
   430     TUid uidArray[] = {KMenuAppUid, KSearchAppUid, KIdleAppUid};
       
   431     TApaAppInfo applicationInfo;
       
   432     SAlwaysShownAppInfo fixedAppInfo;
       
   433     for ( TInt index = 0; index < KAlwaysShownAppCount; index++)
       
   434         {
       
   435         // if exists in phone rom
       
   436         if (  iParent.iAppArcSession.GetAppInfo(applicationInfo, uidArray[index]) != KErrNotFound )
       
   437             {
       
   438             fixedAppInfo.iAppUid = uidArray[index];
       
   439             // list is created without known window groups
       
   440             fixedAppInfo.iWgId = KApplicationWithoutWG;
       
   441             iAppList->AppendL( fixedAppInfo );
       
   442             }
       
   443         }
       
   444     _AKNTRACE_FUNC_EXIT;
       
   445     }
       
   446 
       
   447 // ---------------------------------------------------------
       
   448 // CAknFastSwapWindowControl::AddWgGroupToAlwaysShownList
       
   449 // The window groups are stored with the application uids
       
   450 // ---------------------------------------------------------
       
   451 //
       
   452 void CAknAlwaysShownAppList::AddWgGroupToAlwaysShownList( TUid aAppUid, TInt aWgId )
       
   453     {
       
   454     _AKNTRACE_FUNC_ENTER;
       
   455     _AKNTRACE( "[%s] aAppUid = %d aWgId = %d", 
       
   456     		   __FUNCTION__, aAppUid.iUid, aWgId );
       
   457     for ( TInt index = 0; index < iAppList->Count(); index++)
       
   458         {
       
   459         if ( (*iAppList)[index].iAppUid == aAppUid )
       
   460             {
       
   461             (*iAppList)[index].iWgId = aWgId;
       
   462             }
       
   463         }
       
   464     _AKNTRACE_FUNC_EXIT;
       
   465     }
       
   466     
       
   467 // ---------------------------------------------------------
       
   468 // CAknFastSwapWindowControl::IsAlwaysShownApp
       
   469 // If application uid exists in the always shown application list 
       
   470 // ---------------------------------------------------------
       
   471 //
       
   472 TBool CAknAlwaysShownAppList::IsAlwaysShownApp( TUid aAppUid )
       
   473     {
       
   474     _AKNTRACE_FUNC_ENTER;
       
   475     _AKNTRACE( "[%s] aAppUid = %d", __FUNCTION__, aAppUid.iUid );
       
   476     for ( TInt index = 0; index < iAppList->Count(); index++)
       
   477         {
       
   478         if ( (*iAppList)[index].iAppUid == aAppUid )
       
   479             {
       
   480             _AKNTRACE_FUNC_EXIT;
       
   481             return ETrue;
       
   482             }
       
   483         }
       
   484     _AKNTRACE_FUNC_EXIT;
       
   485     return EFalse;
       
   486     }
       
   487 
       
   488 // ---------------------------------------------------------
       
   489 // CAknFastSwapWindowControl::IsAlwaysShownApp
       
   490 // If application window group exists in the always shown application list 
       
   491 // ---------------------------------------------------------
       
   492 //
       
   493 TBool CAknAlwaysShownAppList::IsAlwaysShownApp( TInt aWgId )
       
   494     {
       
   495     _AKNTRACE_FUNC_ENTER;
       
   496     _AKNTRACE( "[%s] aWgId = %d", __FUNCTION__, aWgId );
       
   497     for ( TInt index = 0; index < iAppList->Count(); index++)
       
   498         {
       
   499         if ( (*iAppList)[index].iWgId == aWgId )
       
   500             {
       
   501             _AKNTRACE_FUNC_EXIT;
       
   502             return ETrue;
       
   503             }
       
   504         }
       
   505     _AKNTRACE_FUNC_EXIT;
       
   506     return EFalse;
       
   507     }
       
   508 
       
   509 // ---------------------------------------------------------
       
   510 // CAknFastSwapWindowControl::IndexToAppUid
       
   511 // Map Tasklist application index to application Uid
       
   512 // ---------------------------------------------------------
       
   513 //
       
   514 TUid CAknAlwaysShownAppList::IndexToAppUid( TInt aIndex )
       
   515     {
       
   516     _AKNTRACE( "[%s] aIndex = %d", __FUNCTION__, aIndex );
       
   517     return (*iAppList)[aIndex + iAppList->Count() - iParent.iNumberOfWGs].iAppUid;
       
   518     }
       
   519 
       
   520 
       
   521 CAknGridView::TScrollingType KVerticalScrollingType = CAknGridView::EScrollFollowsItemsAndLoops;
       
   522 CAknGridView::TScrollingType KHorizontalScrollingType = CAknGridView::EScrollFollowsItemsAndLoops;
       
   523 
       
   524 _LIT(KTab,"\t");
       
   525 
       
   526 // ================= MEMBER FUNCTIONS =======================
       
   527 // C++ default constructor can NOT contain any code, that
       
   528 // might leave.
       
   529 //
       
   530 CAknFastSwapWindowControl::CAknFastSwapWindowControl(CAknCapAppServerAppUi& aAppUi)
       
   531 : iAppUi( aAppUi ),iLowMemory( EFalse ), iLowMemIcons( EFalse ), iAppArcSessionInitiated( EFalse ),
       
   532   iWidgetAppUiWgId(-1), iWidgetsSupported( EFalse ),
       
   533   iTooltipModeTouch( EFalse ),iTransparencyEnabled( CAknEnv::Static()->TransparencyEnabled() ), 
       
   534   iIsStylusPopupShow(EFalse), iState( EWaiting )
       
   535     { 
       
   536     AKNTASHOOK_ADD( this, "CAknFastSwapWindowControl" );
       
   537     }
       
   538 
       
   539 // Symbian OS default constructor can leave.
       
   540 void CAknFastSwapWindowControl::ConstructL()
       
   541     {
       
   542     _AKNTRACE_FUNC_ENTER; 
       
   543     GfxTransEffect::Enable();
       
   544    
       
   545     CreateWindowL();
       
   546     SetComponentsToInheritVisibility();
       
   547     Window().SetShadowDisabled( ETrue );
       
   548     Window().SetPointerGrab( ETrue );
       
   549     SetGloballyCapturing( ETrue );
       
   550     
       
   551     if( iTransparencyEnabled )
       
   552         {
       
   553         Window().SetRequiredDisplayMode( EColor16MA );
       
   554         TInt err = Window().SetTransparencyAlphaChannel();
       
   555 
       
   556         if ( err == KErrNone )
       
   557             {
       
   558             Window().SetBackgroundColor(~0);
       
   559             }
       
   560         }
       
   561 
       
   562     if (FeatureManager::FeatureSupported(KFeatureIdWebWidgets))
       
   563         {   
       
   564         iWidgetsSupported = ETrue;     
       
   565         }
       
   566     CreateCbaL();
       
   567     CreateGridL();
       
   568     CreateItemArraysL();
       
   569     CreateTooltipL();
       
   570     CreateLabelL();
       
   571     UpdateHeadingIconL();
       
   572     
       
   573     //create animation
       
   574     iLongTapAnimation = CAknLongTapAnimation::NewL( EFalse );
       
   575     iThemesAppRepository = CRepository::NewL( KCRUidThemes );
       
   576     //create TimeOut
       
   577     iTimeOut = CPeriodic::NewL(CActive::EPriorityStandard); 
       
   578     iToolTipTimer = CPeriodic::NewL(CActive::EPriorityStandard); 
       
   579     
       
   580     CreateComponentArrayL();
       
   581   
       
   582     // create control context
       
   583     TRect nullRect( 0, 0 , 0, 0 );
       
   584     iFrameContext = CAknsFrameBackgroundControlContext::NewL(
       
   585         KAknsIIDQsnFrPopup, nullRect, nullRect, EFalse);
       
   586 
       
   587     // the list for always shown applications in the fast swap
       
   588     iAlwaysShownList = CAknAlwaysShownAppList::NewL( *this );
       
   589 
       
   590     if (iWidgetsSupported)
       
   591         {        
       
   592         iWidgetList = CAknWidgetList::NewL( *this );
       
   593         }
       
   594     MakeVisible( EFalse );
       
   595     _AKNTRACE_FUNC_EXIT; 
       
   596     }
       
   597     
       
   598 // Destructor
       
   599 CAknFastSwapWindowControl::~CAknFastSwapWindowControl()
       
   600     {
       
   601     _AKNTRACE_FUNC_ENTER;
       
   602     AKNTASHOOK_REMOVE();
       
   603     AknGlobalPopupPriorityController::RemovePopupPriority(*this);
       
   604     GfxTransEffect::Deregister( this );
       
   605       
       
   606     iAppArcSession.Close();
       
   607     ClearItemArrays( ETrue ); 
       
   608     if ( iGrid )
       
   609         {
       
   610         AknsUtils::DeregisterControlPosition( iGrid );
       
   611         }
       
   612     delete iAlwaysShownList;
       
   613     delete iWidgetList;
       
   614     FadeBackground( EFalse );
       
   615     delete iFrameContext;
       
   616     delete iGrid; // destroys also iIconArray and scrollbar frame
       
   617     delete iShownWgIds;
       
   618     if ( iAllWgIds )
       
   619         {
       
   620         iAllWgIds->Close();
       
   621         }
       
   622 
       
   623     CAknFastSwapData *data = 
       
   624         (CAknFastSwapData*)CAknTransitionUtils::GetData( (TInt)this );
       
   625     if ( data )
       
   626         {
       
   627         CAknTransitionUtils::RemoveObserver( data,
       
   628             CAknTransitionUtils::EEventControlTransitionFinished );
       
   629         CAknTransitionUtils::RemoveData( (TInt)this );
       
   630         delete data;
       
   631         }
       
   632 
       
   633     delete iItemTextArray;
       
   634     delete iAllWgIds;
       
   635     delete iDefaultAppIcon;
       
   636     delete iCba;
       
   637     delete iConfirmCloseDialog;
       
   638     delete iHeadingIcon;
       
   639     delete iTooltip;
       
   640     delete iLabel;
       
   641     delete iPopupMenu;
       
   642     delete iLongTapAnimation;
       
   643     delete iTimeOut;
       
   644     delete iToolTipTimer;
       
   645     delete iThemesAppRepository;
       
   646     _AKNTRACE_FUNC_EXIT;
       
   647     }
       
   648 
       
   649 // ---------------------------------------------------------
       
   650 // CAknFastSwapWindowControl::RunFastSwapL
       
   651 // Function that is called from CEikServAppUi to launch
       
   652 // task switching. Updates all relevant data (see more detailed
       
   653 // description from the functions called) and brings the
       
   654 // window to foreground
       
   655 // ---------------------------------------------------------
       
   656 //
       
   657 void CAknFastSwapWindowControl::RunFastSwapL()
       
   658     {
       
   659     _AKNTRACE_FUNC_ENTER;
       
   660     if ( iIsDisplayed )
       
   661         {
       
   662         _AKNTRACE_FUNC_EXIT;
       
   663         return;
       
   664         }
       
   665     TInt effectValue( 0 );
       
   666     iThemesAppRepository->Get( KThemesTransitionEffects, effectValue );
       
   667     if ( effectValue == 0 )     /* TAT on */
       
   668         {
       
   669         MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   670         if ( feedback )
       
   671             {
       
   672             feedback->InstantFeedback( ETouchFeedbackIncreasingPopUp );
       
   673             }
       
   674         }
       
   675     
       
   676     GfxTransEffect::Register( this, KGfxTaskSwapperControlUid, EFalse );
       
   677     GfxTransEffect::Abort();
       
   678     
       
   679     TPoint dPoint( iGrid->PositionRelativeToScreen() );
       
   680     TRect dRect( iGrid->Rect() );
       
   681     dRect.Move( dPoint );
       
   682     
       
   683                 
       
   684 
       
   685     SetPointerCapture( ETrue );
       
   686 
       
   687     CleanupStack::PushL( TCleanupItem( CleanupRunFastSwap, this) );
       
   688 
       
   689     iIsDisplayed = ETrue;
       
   690     
       
   691     AknGlobalPopupPriorityController::AddPopupToControlStackL(*this,ECoeStackPriorityDialog,0 );
       
   692     AknGlobalPopupPriorityController::AddPopupToControlStackL(*iCba->ButtonGroup()->AsControl(),
       
   693         ECoeStackPriorityCba, ECoeStackFlagRefusesFocus );
       
   694     AknGlobalPopupPriorityController::ShowPopup(*this, ETrue);
       
   695         
       
   696     TBool areWeInIdleState = CEikStatusPaneBase::Current()->PaneCapabilities(
       
   697         TUid::Uid( EEikStatusPaneUidClock ) ).IsInCurrentLayout();
       
   698          
       
   699     if (areWeInIdleState)
       
   700         { // idle state
       
   701         ( (CEikCba*) iCba->ButtonGroup() )->SetSkinBackgroundId(KAknsIIDQsnBgAreaControlIdle);
       
   702         }
       
   703     else
       
   704         {
       
   705         ( (CEikCba*) iCba->ButtonGroup() )->SetSkinBackgroundId(KAknsIIDQsnBgAreaControl);
       
   706         }
       
   707 
       
   708     iCba->HandleResourceChange(KEikDynamicLayoutVariantSwitch);
       
   709     iCba->MakeVisible( ETrue );
       
   710 
       
   711     
       
   712     SetRect( FastSwapWindowRect() );    // Causes call of SizeChanged()
       
   713 
       
   714     iBackgroundWgId = (*iAllWgIds)[0].iId;  // where to switch if cancel is pressed
       
   715     
       
   716     ActivateL();
       
   717     
       
   718     CleanupStack::Pop();    // clean fast swap cleanup item
       
   719     
       
   720     // if the grid creation failed, fsw closes
       
   721     if ( iGrid->Model()->NumberOfItems() == 0 )
       
   722         {
       
   723         // if memory runs out, FSW uses what it has 
       
   724         // and continues (should never happen)
       
   725         CloseFastSwap(); 
       
   726         }    
       
   727     else 
       
   728         {
       
   729         iGrid->SetTopItemIndex( 0 );
       
   730         iGrid->SetCurrentDataIndex( 0 );
       
   731         UpdateTooltipL();
       
   732         if ( !CAknTransitionUtils::TransitionsEnabled( 
       
   733                 AknTransEffect::EComponentTransitionsOff ) )
       
   734             {
       
   735             iTooltip->ShowInfoPopupNote();
       
   736             }
       
   737         }    
       
   738     CAknTransitionUtils::SetAllParents( this );
       
   739     
       
   740     TBool rsWasEnabled( EFalse );
       
   741 
       
   742     if( !iTransparencyEnabled && Window().IsRedrawStoreEnabled() )
       
   743         {
       
   744         rsWasEnabled = ETrue;
       
   745         // disable redrawstore during transition to avoid
       
   746         // drawing problems behind FSW
       
   747         Window().EnableRedrawStore( EFalse );
       
   748         }
       
   749     
       
   750     GfxTransEffect::Begin( this, KGfxControlAppearAction );   
       
   751     GfxTransEffect::NotifyExternalState(ECaptureComponentsBegin, (const TDesC8*)this);
       
   752 
       
   753     // Temporarily set to nonfading to prevent a faded version
       
   754     // from appearing on screen
       
   755     Window().SetNonFading(ETrue);
       
   756     FadeBackground( ETrue );
       
   757     MakeVisible( ETrue );
       
   758     SetFocus( ETrue );
       
   759 
       
   760     Window().SetNonFading(EFalse);
       
   761     GfxTransEffect::SetDemarcation( this, dRect );
       
   762     CAknTransitionUtils::MakeVisibleSubComponents( this,
       
   763                                         CAknTransitionUtils::EForceVisible );
       
   764 
       
   765     // Delay display of tooltip until the appear animation has finished,
       
   766     // to avoid the fast swap window being drawn on top of the tooltip.
       
   767     CAknFastSwapData *data = 
       
   768         (CAknFastSwapData*)CAknTransitionUtils::GetData( (TInt)this );
       
   769     if ( !data )
       
   770         {
       
   771         data = new (ELeave) CAknFastSwapData( (TInt)this, iTooltip );
       
   772         CAknTransitionUtils::SetData( (TInt)this, data );
       
   773         }
       
   774         
       
   775     if ( CAknTransitionUtils::AddObserver( data, 
       
   776                  CAknTransitionUtils::EEventControlTransitionFinished,
       
   777                  (const TDesC8 *)this ) == KErrNone )
       
   778         {
       
   779         GfxTransEffect::NotifyExternalState(ECaptureComponentsEnd, (const TDesC8*)this);
       
   780         GfxTransEffect::End( this );
       
   781         }
       
   782     else
       
   783         {
       
   784         CAknTransitionUtils::RemoveData( (TInt)this  );
       
   785         delete data;
       
   786         GfxTransEffect::Deregister( this );
       
   787         }
       
   788     
       
   789     if( !iTransparencyEnabled && rsWasEnabled )
       
   790         {
       
   791         // if redrawstore was on before transition,
       
   792         // enable it again
       
   793         Window().EnableRedrawStore( ETrue );
       
   794         }
       
   795     _AKNTRACE_FUNC_EXIT;
       
   796     }
       
   797 
       
   798 // ---------------------------------------------------------
       
   799 // CAknFastSwapWindowControl::HandleChangeInWindowGroupListL
       
   800 // Function that is called from CEikServAppUi when apps list changes.
       
   801 // Resets window size and selection if FSW is displayed.
       
   802 // ---------------------------------------------------------
       
   803 //
       
   804 void CAknFastSwapWindowControl::HandleChangeInWindowGroupListL()
       
   805     {
       
   806     _AKNTRACE_FUNC_ENTER;
       
   807     if ( !iIsDisplayed )
       
   808         {
       
   809         _AKNTRACE_FUNC_EXIT;
       
   810         return;
       
   811         }
       
   812 
       
   813     if ( iNumberOfWGs <= 0 )
       
   814         {
       
   815         CloseFastSwap();
       
   816         _AKNTRACE_FUNC_EXIT;
       
   817         return;
       
   818         }
       
   819         
       
   820     TInt currPos = iGrid->CurrentDataIndex();
       
   821 
       
   822     SetRect( FastSwapWindowRect() );    // Causes call of SizeChanged()  
       
   823 
       
   824     TInt iOrgWgId = iBackgroundWgId;
       
   825 
       
   826     TInt count = iAllWgIds->Count();
       
   827     for ( TInt ii=0; ii<count && !IsWgIdInShownList( iBackgroundWgId); ii++ )
       
   828         {
       
   829         iBackgroundWgId = (*iAllWgIds)[ii].iId;
       
   830         }
       
   831 
       
   832     if ( iBackgroundWgId != iOrgWgId )
       
   833         {
       
   834         // If the current application is closed when hidden
       
   835         // BeginFullScreen is called, we must abort that BeginFullScreen
       
   836         GfxTransEffect::AbortFullScreen();
       
   837         }
       
   838 
       
   839 
       
   840     if ( iConfirmCloseDialog && !IsWgIdInShownList( iConfirmCloseWgId) )
       
   841         {
       
   842         delete iConfirmCloseDialog;
       
   843         iConfirmCloseDialog = NULL;
       
   844         }
       
   845     // if the grid creation failed, fsw closes
       
   846     if ( iGrid->Model()->NumberOfItems() == 0 )
       
   847         {
       
   848         // if memory runs out, FSW uses what it has 
       
   849         // and continues 
       
   850         CloseFastSwap(); 
       
   851         }    
       
   852     else 
       
   853         {
       
   854         if (currPos >= iGrid->Model()->NumberOfItems())
       
   855             {
       
   856             currPos = iGrid->Model()->NumberOfItems()-1;
       
   857             }
       
   858         iGrid->SetCurrentDataIndex(currPos);
       
   859 
       
   860         ShowTooltipTouchL(EFalse);
       
   861         }
       
   862     _AKNTRACE_FUNC_EXIT;
       
   863     }
       
   864 
       
   865 // ---------------------------------------------------------
       
   866 // CAknFastSwapWindowControl::InitializeWindowGroupListL
       
   867 // Accesses the window server for a list of existing window groups
       
   868 // of the standard window group priority (default for an application).
       
   869 // Removes all hidden window groups from the list.
       
   870 // Normally an application does not have more than one window group.
       
   871 // ---------------------------------------------------------
       
   872 //
       
   873 TBool CAknFastSwapWindowControl::InitializeWindowGroupListL( TInt aWaitForWGRemoval )
       
   874     {
       
   875     _AKNTRACE_FUNC_ENTER;
       
   876     _AKNTRACE( "[%s] aWaitForWGRemoval = %d", __FUNCTION__, aWaitForWGRemoval );
       
   877     if (!iAppArcSessionInitiated)
       
   878         {
       
   879         // Creates a session to the apparc server,
       
   880         // connection takes time, so done only once
       
   881         // no need to do it many times 
       
   882         // done here because cannot be done at the startup 
       
   883         User::LeaveIfError( iAppArcSession.Connect() );
       
   884         iAppArcSessionInitiated = ETrue;
       
   885         }
       
   886     iAppArcSession.GetAllApps();
       
   887     // create list for always shown applications    
       
   888     iAlwaysShownList->InitializeAlwaysShownListL();         
       
   889     if (iWidgetsSupported)
       
   890         {        
       
   891         iWidgetList->InitializeWidgetListL();
       
   892         }
       
   893     //Initializes CAknFastSwapWindowControl private data ( iWgIds, iNumberOfWGs )
       
   894     RWsSession& wsSession=iEikonEnv->WsSession();
       
   895     TInt count=wsSession.NumWindowGroups( 0 );
       
   896 
       
   897     RArray<RWsSession::TWindowGroupChainInfo>* allWgIds = new (ELeave)
       
   898         RArray<RWsSession::TWindowGroupChainInfo>( KFSWArrayGranularity );
       
   899         
       
   900     CleanupDeletePushL( allWgIds );
       
   901     CleanupClosePushL( *allWgIds );
       
   902     User::LeaveIfError( wsSession.WindowGroupList( 0, allWgIds) );
       
   903     count = allWgIds->Count();
       
   904 
       
   905     CArrayFixFlat<SWindowGroupInfo>* shownWgIds = new (ELeave)
       
   906         CArrayFixFlat<SWindowGroupInfo>(KFSWArrayGranularity);
       
   907         
       
   908     CleanupStack::PushL(shownWgIds);
       
   909     CApaWindowGroupName* windowName;
       
   910     
       
   911     //
       
   912     // Running application window groups
       
   913     //
       
   914     TInt firstAppWgId = KErrNone;
       
   915     for ( TInt index=0; index < count; index++ )
       
   916         {
       
   917         RWsSession::TWindowGroupChainInfo& info = (*allWgIds)[index];
       
   918         if ( info.iParentId <= 0 )
       
   919             {
       
   920             TInt wgId=info.iId;
       
   921             windowName = CApaWindowGroupName::NewLC(wsSession, wgId);
       
   922             TUid applicationUid = windowName->AppUid();
       
   923             
       
   924             // application screen (0 = main screen, 1 = cover ui )          
       
   925             // the possible error value is omitted 
       
   926             TInt appScreen = -1; 
       
   927             TInt errId = iAppArcSession.GetDefaultScreenNumber( appScreen, applicationUid ); 
       
   928             if (  errId != KErrNone )
       
   929                 {
       
   930                 CleanupStack::PopAndDestroy( windowName );  //windowName
       
   931                 continue;   
       
   932                 }
       
   933 
       
   934             if ( firstAppWgId == KErrNone && ( appScreen == 0 || appScreen == -1 ) )
       
   935                 {
       
   936                 firstAppWgId = wgId;    
       
   937                 }
       
   938             // always shown applications are appended to the end of window group list 
       
   939             if ( iAlwaysShownList->IsAlwaysShownApp( applicationUid ) )
       
   940                 {
       
   941                 iAlwaysShownList->AddWgGroupToAlwaysShownList( applicationUid, wgId );
       
   942                 }
       
   943             else if (iWidgetsSupported && iWidgetList->IsWidgetAppUI(applicationUid))
       
   944                 {
       
   945                 iWidgetAppUiWgId = wgId;
       
   946                 }
       
   947             // could't use windowName->IsAppReady(), because then java and console application
       
   948             // wouldn't be seen in FSW. Now it is possible that some system apps are seen at the
       
   949             // beginning of their start for a while in FSW (even they should be hidden all the time)
       
   950             // temporary solution since application shell is normally hidden from tasklist
       
   951             // and in the new solution it should be shown
       
   952             else if ( !windowName->Hidden() && !iAppUi.HiddenFromFSW(applicationUid.iUid) &&
       
   953                 ( appScreen == 0 || appScreen == -1 ) ) // appScreen == -1 is used for console applications
       
   954                 {
       
   955                 SWindowGroupInfo wgInfo = { wgId, windowName->IsSystem() };
       
   956                 shownWgIds->AppendL(wgInfo);
       
   957                 }
       
   958             CleanupStack::PopAndDestroy();  //windowName
       
   959             }
       
   960         }
       
   961 
       
   962     if (iWidgetsSupported)
       
   963         {        
       
   964         for ( TInt index = 0; index < iWidgetList->iRunningWidgets.Count(); index++)
       
   965             {
       
   966             SWindowGroupInfo wgInfo = { KWidgetWithoutWG, EFalse };
       
   967             shownWgIds->AppendL( wgInfo );
       
   968             }
       
   969         }
       
   970 
       
   971     // always shown applications are appended to the end of window group list 
       
   972     for ( TInt index = 0; index < iAlwaysShownList->iAppList->Count(); index++)
       
   973         {
       
   974         SWindowGroupInfo wgInfo = { (*iAlwaysShownList->iAppList)[index].iWgId, ETrue };
       
   975         shownWgIds->AppendL( wgInfo );
       
   976         }
       
   977    
       
   978     if ( iIsDisplayed && !iIsClosing && shownWgIds->Count() >= iShownWgIds->Count() )
       
   979     {
       
   980     if ( firstAppWgId != KErrNone && firstAppWgId != iFirstAppWgId && firstAppWgId != iBackgroundWgId ) 
       
   981         {
       
   982         CloseFastSwap();   
       
   983         }
       
   984     }
       
   985     iFirstAppWgId = firstAppWgId;  
       
   986 
       
   987     if ( iShownWgIds && iShownWgIds->Count() != shownWgIds->Count() )
       
   988         {
       
   989         iIsClosing = EFalse;    
       
   990         }
       
   991              
       
   992     // check if window group of deleted application has been removed
       
   993     if ( aWaitForWGRemoval && iShownWgIds )
       
   994         {
       
   995         // if not removed
       
   996         if ( shownWgIds->Count() == iShownWgIds->Count() )
       
   997             {
       
   998             // no changes are made
       
   999             TBool needReset = EFalse;
       
  1000             CApaWindowGroupName* appNameInShowList = 
       
  1001                                  CApaWindowGroupName::NewLC(wsSession);
       
  1002             CApaWindowGroupName* appNameInIShowList =
       
  1003                                  CApaWindowGroupName::NewLC(wsSession);
       
  1004             for ( int i = 0; i < shownWgIds->Count(); i++ )
       
  1005                  {
       
  1006                  appNameInShowList->ConstructFromWgIdL(shownWgIds->At(i).iWgId);
       
  1007                  appNameInIShowList->ConstructFromWgIdL(iShownWgIds->At(i).iWgId);
       
  1008                  if ( appNameInShowList->AppUid() != appNameInIShowList->AppUid() )
       
  1009                 	 {
       
  1010                 	 needReset = ETrue;
       
  1011                 	 break;
       
  1012                 	 }
       
  1013                  }
       
  1014             CleanupStack::PopAndDestroy(2);
       
  1015             if( !needReset )
       
  1016             	{
       
  1017                 CleanupStack::PopAndDestroy(shownWgIds);
       
  1018                 CleanupStack::PopAndDestroy();            // pop close allWgIds
       
  1019                 CleanupStack::PopAndDestroy(allWgIds);    // pop delete allWgIds            
       
  1020             
       
  1021                 _AKNTRACE_FUNC_EXIT;
       
  1022                 // EFalse if window group list hasn't been changed
       
  1023                 return EFalse;
       
  1024             	}
       
  1025             }
       
  1026         }
       
  1027 
       
  1028     // changes are made    
       
  1029     if ( iAllWgIds )
       
  1030         {
       
  1031         iAllWgIds->Close();
       
  1032         }
       
  1033     delete iAllWgIds;
       
  1034     iAllWgIds = allWgIds;
       
  1035     delete iShownWgIds;
       
  1036     iShownWgIds=shownWgIds;
       
  1037     iNumberOfWGs=shownWgIds->Count();
       
  1038     
       
  1039     CleanupStack::Pop(shownWgIds);
       
  1040     CleanupStack::Pop();            // pop close allWgIds
       
  1041     CleanupStack::Pop(allWgIds);    // pop delete allWgIds
       
  1042     
       
  1043     _AKNTRACE_FUNC_EXIT;
       
  1044     // ETrue if window group list has changed
       
  1045     return ETrue;
       
  1046     }
       
  1047 
       
  1048 // ---------------------------------------------------------
       
  1049 // CAknFastSwapWindowControl::VisibleWindowGroupsCountL
       
  1050 // Returns the number of visible window groups found in the system
       
  1051 // ---------------------------------------------------------
       
  1052 //
       
  1053 TInt CAknFastSwapWindowControl::VisibleWindowGroupsCountL()
       
  1054     {
       
  1055     InitializeWindowGroupListL( EFalse );
       
  1056     return iNumberOfWGs;
       
  1057     }
       
  1058 
       
  1059 TBool CAknFastSwapWindowControl::IsDisplayed()
       
  1060     {
       
  1061     return iIsDisplayed;
       
  1062     }
       
  1063 
       
  1064 // ---------------------------------------------------------
       
  1065 // CAknFastSwapWindowControl::UpdateGridL
       
  1066 // Modifies grid extent according the parent control rect
       
  1067 // ---------------------------------------------------------
       
  1068 //
       
  1069 void CAknFastSwapWindowControl::UpdateGridL()
       
  1070     {
       
  1071     _AKNTRACE_FUNC_ENTER;
       
  1072     TAknLayoutRect listScrollLayoutRect;
       
  1073     TAknLayoutRect gridLayoutRect;
       
  1074     
       
  1075     listScrollLayoutRect.LayoutRect( 
       
  1076         Rect(), 
       
  1077         AknLayoutScalable_Avkon::listscroll_fast2_pane( ).LayoutLine() );
       
  1078 
       
  1079     // grid
       
  1080     gridLayoutRect.LayoutRect( 
       
  1081         listScrollLayoutRect.Rect(), 
       
  1082         AknLayoutScalable_Avkon::grid_fast2_pane().LayoutLine() );
       
  1083 
       
  1084     TAknLayoutScalableParameterLimits cellLimits = AknLayoutScalable_Avkon::cell_fast2_pane_ParamLimits();
       
  1085     TInt numberOfGridColumns = cellLimits.LastColumn() + 1;
       
  1086 
       
  1087     if ( AknLayoutUtils::LayoutMirrored() ) 
       
  1088         {
       
  1089         iGrid->SetLayoutL( 
       
  1090             KVerticalOrientation, 
       
  1091             KRightToLeft, 
       
  1092             KTopToBottom, 
       
  1093             numberOfGridColumns, 
       
  1094             NumberOfVisibleRows(), 
       
  1095             IconSize() );             
       
  1096         }
       
  1097     else
       
  1098         {          
       
  1099         iGrid->SetLayoutL(  
       
  1100             KVerticalOrientation, 
       
  1101             KLeftToRight, 
       
  1102             KTopToBottom, 
       
  1103             numberOfGridColumns, 
       
  1104             NumberOfVisibleRows(), 
       
  1105             IconSize() );             
       
  1106         }
       
  1107 
       
  1108     iGrid->ScrollBarFrame()->SetScrollBarFrameObserver( iGrid );
       
  1109     
       
  1110     TRect gridArea = gridLayoutRect.Rect();
       
  1111     if ( iGrid->Rect() != gridArea )
       
  1112         {
       
  1113         iGrid->SetRect( gridArea );
       
  1114         }
       
  1115     AknsUtils::RegisterControlPosition( iGrid );    
       
  1116     
       
  1117     // scrollbar
       
  1118     AknLayoutUtils::LayoutVerticalScrollBar( 
       
  1119         iGrid->ScrollBarFrame(), 
       
  1120         listScrollLayoutRect.Rect(), 
       
  1121         AknLayoutScalable_Avkon::scroll_pane_cp26().LayoutLine() );
       
  1122     _AKNTRACE_FUNC_EXIT;
       
  1123     }
       
  1124 
       
  1125 
       
  1126 // ---------------------------------------------------------------------------
       
  1127 // Updates the UI components.
       
  1128 // ---------------------------------------------------------------------------
       
  1129 //
       
  1130 void CAknFastSwapWindowControl::UpdateViewL()
       
  1131     {
       
  1132     _AKNTRACE_FUNC_ENTER;
       
  1133     UpdateItemArraysL();
       
  1134     UpdateGridL();
       
  1135     UpdateControlContext();
       
  1136     iGrid->UpdateScrollBarsL();
       
  1137     UpdateLabelL();
       
  1138     UpdateHeadingIconL();
       
  1139     
       
  1140 
       
  1141     if ( IsVisible() )
       
  1142         {
       
  1143         DrawDeferred();
       
  1144         }
       
  1145 
       
  1146     if ( iIsStylusPopupShow )
       
  1147         {
       
  1148         TPoint pos = PositionRelativeToScreen();
       
  1149         TInt itemIndex = iGrid->CurrentItemIndex();
       
  1150         itemIndex = itemIndex < 0 ? 0 : itemIndex;
       
  1151         TPoint posItem = iGrid->View()->ItemPos( itemIndex );
       
  1152         pos.iY += posItem.iY;
       
  1153         pos.iX += posItem.iX;
       
  1154         if ( AknLayoutUtils::LayoutMirrored() )
       
  1155             {
       
  1156             TInt itemWidth = iGrid->View()->ItemSize( itemIndex ).iWidth;    
       
  1157             pos.iX += itemWidth;
       
  1158             }
       
  1159         if ( iPopupMenu ) 
       
  1160             {
       
  1161             iPopupMenu->SetPosition( pos, CAknStylusPopUpMenu::EPositionTypeLeftBottom );       
       
  1162             }
       
  1163         }
       
  1164     _AKNTRACE_FUNC_EXIT;
       
  1165     }
       
  1166         
       
  1167 // ---------------------------------------------------------
       
  1168 // CAknFastSwapWindowControl::UpdateControlContext
       
  1169 // ---------------------------------------------------------
       
  1170 //
       
  1171 void CAknFastSwapWindowControl::UpdateControlContext()
       
  1172     {
       
  1173     _AKNTRACE_FUNC_ENTER;
       
  1174     TRect rectParent = Rect();
       
  1175     TAknLayoutRect layoutRect;
       
  1176 
       
  1177     layoutRect.LayoutRect( 
       
  1178         rectParent, 
       
  1179         AknLayoutScalable_Avkon::bg_popup_window_pane_cp17().LayoutLine() );
       
  1180         
       
  1181     rectParent = layoutRect.Rect();
       
  1182     
       
  1183     layoutRect.LayoutRect( 
       
  1184         rectParent, 
       
  1185         AknLayoutScalable_Avkon::bg_popup_window_pane_g1(0).LayoutLine() );
       
  1186 
       
  1187     iFrameContext->SetFrame(KAknsIIDQsnFrPopup);
       
  1188     iFrameContext->SetFrameRects(rectParent, layoutRect.Rect());
       
  1189     iFrameContext->SetCenter(KAknsIIDQsnFrPopupCenterFswap);
       
  1190     _AKNTRACE_FUNC_EXIT;
       
  1191     }
       
  1192 
       
  1193 // ---------------------------------------------------------
       
  1194 // CAknFastSwapWindowControl::Draw
       
  1195 // Symbian OS framework drawing function. Draws the window shadows and
       
  1196 // outline frame.
       
  1197 // ---------------------------------------------------------
       
  1198 //
       
  1199 void CAknFastSwapWindowControl::Draw(const TRect& /*aRect*/) const
       
  1200     {
       
  1201     _AKNTRACE_FUNC_ENTER;
       
  1202     if ( iNumberOfWGs < 1 )
       
  1203         {
       
  1204         _AKNTRACE_FUNC_EXIT;
       
  1205         return;
       
  1206         }
       
  1207     CWindowGc& gc = SystemGc();
       
  1208         
       
  1209     if( !iTransparencyEnabled )
       
  1210     {
       
  1211         // Should only clear the background when transparency is not enabled
       
  1212         gc.Clear( Rect() );
       
  1213     }
       
  1214     
       
  1215     if ( iLowMemIcons ) 
       
  1216         {
       
  1217         _AKNTRACE_FUNC_EXIT;
       
  1218         return;
       
  1219         }
       
  1220     
       
  1221     MAknsSkinInstance *skin = AknsUtils::SkinInstance();
       
  1222 
       
  1223     gc.SetPenStyle(CGraphicsContext::ENullPen);
       
  1224         
       
  1225     TAknLayoutRect topLeft;
       
  1226     TAknLayoutRect bottomRight;
       
  1227         
       
  1228     topLeft.LayoutRect( Rect(), SkinLayout::Popup_windows_skin_placing__frame_general__Line_2());
       
  1229     bottomRight.LayoutRect(Rect(), SkinLayout::Popup_windows_skin_placing__frame_general__Line_5());
       
  1230         
       
  1231     TRect innerRect = TRect(topLeft.Rect().iBr, bottomRight.Rect().iTl);
       
  1232 
       
  1233     TAknLayoutRect headingArea;
       
  1234     TAknLayoutRect headingBackground;
       
  1235     TAknLayoutRect headingCenter;
       
  1236     TAknLayoutRect iconArea;
       
  1237     
       
  1238     headingArea.LayoutRect( Rect(), AknLayoutScalable_Avkon::heading_pane_cp2().LayoutLine() );
       
  1239     
       
  1240     headingBackground.LayoutRect( headingArea.Rect(), 
       
  1241         AknLayoutScalable_Avkon::bg_popup_heading_pane(  0 ).LayoutLine() );
       
  1242         
       
  1243     headingCenter.LayoutRect( headingBackground.Rect(), 
       
  1244         AknLayoutScalable_Avkon::bg_popup_heading_pane_g1().LayoutLine() );
       
  1245 
       
  1246     if( iTransparencyEnabled )
       
  1247         {
       
  1248         TRegionFix<1> dontDrawRegion;
       
  1249         TRegionFix<8> drawRegion; // 8 should be enough for grid and heading clipping
       
  1250         dontDrawRegion.AddRect( iGrid->Rect() );
       
  1251         drawRegion.AddRect( Rect() );
       
  1252         drawRegion.SubRegion( dontDrawRegion );
       
  1253         gc.SetClippingRegion( drawRegion );
       
  1254         AknsDrawUtils::DrawFrame( skin, gc, Rect(), innerRect, 
       
  1255             KAknsIIDQsnFrPopup, KAknsIIDQsnFrPopupCenter); //KAknsIIDQsnFrPopupCenterFswap);
       
  1256         gc.CancelClippingRegion();    
       
  1257         }
       
  1258     else
       
  1259         {
       
  1260         AknsDrawUtils::DrawFrame( skin, gc, Rect(), innerRect, 
       
  1261             KAknsIIDQsnFrPopup, KAknsIIDQsnFrPopupCenter); //KAknsIIDQsnFrPopupCenterFswap);
       
  1262         }
       
  1263 
       
  1264     AknsDrawUtils::DrawFrame( skin, gc, headingBackground.Rect(), headingCenter.Rect(),
       
  1265         KAknsIIDQsnFrPopupHeading, KAknsIIDQsnFrPopupHeadingCenter);
       
  1266                                          
       
  1267     if ( iHeadingIcon )
       
  1268         {
       
  1269         iconArea.LayoutRect( 
       
  1270             headingBackground.Rect(), 
       
  1271             AknLayoutScalable_Avkon::heading_pane_g2().LayoutLine() );        
       
  1272         
       
  1273         gc.BitBltMasked( iconArea.Rect().iTl, iHeadingIcon->Bitmap(), iconArea.Rect().Size(), 
       
  1274             iHeadingIcon->Mask(), ETrue );        
       
  1275         }
       
  1276     _AKNTRACE_FUNC_EXIT;
       
  1277     }
       
  1278 
       
  1279 // ---------------------------------------------------------
       
  1280 // CAknFastSwapWindowControl::OfferKeyEventL
       
  1281 // Key handling routine, forwards key events to grid
       
  1282 // ---------------------------------------------------------
       
  1283 //
       
  1284 TKeyResponse CAknFastSwapWindowControl::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
  1285     {
       
  1286     _AKNTRACE_FUNC_ENTER;
       
  1287     _AKNTRACE( "[%s] scancode = %d aType = %d", __FUNCTION__, aKeyEvent.iScanCode, aType );
       
  1288     // if user pressed backspace / clear key the fsw offers 
       
  1289     // to close the selected application
       
  1290     if (aType == EEventKey && aKeyEvent.iCode == EKeyBackspace)
       
  1291         {
       
  1292         TBool isShift(EFalse);
       
  1293 #ifdef __WINSCW__
       
  1294         // secret test mode for emulator: shift-backspace sends a definite exit message
       
  1295         isShift = aKeyEvent.iModifiers & (EModifierLeftShift | EModifierRightShift | EModifierShift);
       
  1296 #endif
       
  1297         TryCloseApplicationL(iGrid->CurrentDataIndex(), isShift);
       
  1298         _AKNTRACE_FUNC_EXIT;
       
  1299         return EKeyWasConsumed;
       
  1300         }
       
  1301 
       
  1302     if ( AknLayoutUtils::PenEnabled() )
       
  1303         {
       
  1304         if ( aType == EEventKeyUp && aKeyEvent.iScanCode == EStdKeyYes )
       
  1305             {
       
  1306             CloseFastSwap();
       
  1307             _AKNTRACE_FUNC_EXIT;
       
  1308             return EKeyWasNotConsumed ;    
       
  1309             }
       
  1310         }
       
  1311     // If user pressed the end key the fastswap will close    
       
  1312     if ( aType == EEventKey && ( aKeyEvent.iCode == EKeyNo || aKeyEvent.iCode == EKeyEnd )
       
  1313         || (aKeyEvent.iCode == EKeyEscape ) )
       
  1314         {
       
  1315         
       
  1316                 
       
  1317         CApaWindowGroupName* wgName = CApaWindowGroupName::NewL( iEikonEnv->WsSession() );
       
  1318         CleanupStack::PushL( wgName );
       
  1319         
       
  1320         wgName->ConstructFromWgIdL( iBackgroundWgId );
       
  1321         
       
  1322         TBool idleIsBelow = wgName->AppUid() == KIdleAppUid;
       
  1323         
       
  1324         CleanupStack::PopAndDestroy( wgName );
       
  1325                         
       
  1326         // with end key show fullscreen effect but no
       
  1327         // FSW component effect, except if the idle app
       
  1328         // is below FSW
       
  1329         
       
  1330         if( !idleIsBelow )
       
  1331             {
       
  1332             GfxTransEffect::BeginFullScreen(5000,
       
  1333             TRect(0,0,0,0),
       
  1334             AknTransEffect::EParameterType,
       
  1335             
       
  1336             AknTransEffect::GfxTransParam(
       
  1337                 iAppUi.Application()->AppDllUid(), 
       
  1338                 AknTransEffect::TParameter::EActivateExplicitContinue));
       
  1339             }
       
  1340                 
       
  1341         if( !idleIsBelow )
       
  1342             {
       
  1343             iDisableFSWEffect = ETrue;    
       
  1344             }
       
  1345         CloseFastSwap();
       
  1346         iDisableFSWEffect = EFalse;
       
  1347         _AKNTRACE_FUNC_EXIT;
       
  1348         return EKeyWasConsumed;
       
  1349         }
       
  1350     TInt index = iGrid->CurrentDataIndex();
       
  1351     TKeyResponse keyresponse = iGrid->OfferKeyEventL(aKeyEvent, aType);
       
  1352     if ( index != iGrid->CurrentDataIndex() )
       
  1353         {
       
  1354         UpdateTooltipL();
       
  1355         iTooltip->ShowInfoPopupNote();
       
  1356         }
       
  1357     _AKNTRACE_FUNC_EXIT;
       
  1358     return keyresponse;
       
  1359     }
       
  1360 
       
  1361 
       
  1362 // ---------------------------------------------------------------------------
       
  1363 // Handles tooltip in touch events and long tapping. 
       
  1364 // CAknGrid handles changing the highlighted item and opening the application
       
  1365 // when tapping on a highlighted item.
       
  1366 // ---------------------------------------------------------------------------
       
  1367 //
       
  1368 void CAknFastSwapWindowControl::HandlePointerEventL(
       
  1369     const TPointerEvent& aPointerEvent )
       
  1370     {
       
  1371     _AKNTRACE_FUNC_ENTER;
       
  1372     _AKNTRACE( "[%s] Type = %d", __FUNCTION__, aPointerEvent.iType );
       
  1373     // FSW does not handle any pointer event when stylus popup
       
  1374     // menu is visible.
       
  1375     if ( iIsStylusPopupShow && aPointerEvent.iType != TPointerEvent::EButton1Up  )
       
  1376         {
       
  1377         _AKNTRACE_FUNC_EXIT;
       
  1378         return;
       
  1379         }
       
  1380     
       
  1381     if ( AknLayoutUtils::PenEnabled() )
       
  1382         {        
       
  1383         if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
  1384             {
       
  1385             PointerEventL( aPointerEvent );    
       
  1386             }
       
  1387         
       
  1388         // Pointer coordinates start from the top left position of the
       
  1389         // window at the coordinates (0,0).
       
  1390         TRect controlArea( NULL, NULL, iSize.iWidth, iSize.iHeight );
       
  1391         TInt touchedIndex = KErrNotFound;
       
  1392         TBool isOverItem =
       
  1393             iGrid->GridView()->XYPosToItemIndex( aPointerEvent.iPosition,
       
  1394                                                  touchedIndex );
       
  1395         if ( isOverItem )
       
  1396             {
       
  1397             touchedIndex = iGrid->GridView()->ActualDataIndex( touchedIndex );
       
  1398             }
       
  1399 
       
  1400         // Cancel touch mode tooltip if pointer is not over an item.
       
  1401         if ( !isOverItem && iTooltipModeTouch )
       
  1402             {
       
  1403             HideTooltip();
       
  1404             iTooltipModeTouch = EFalse;
       
  1405             }
       
  1406         
       
  1407         TBool eventInsideControlArea =
       
  1408             controlArea.Contains( aPointerEvent.iPosition );
       
  1409         TBool eventInsideGrid =
       
  1410             iGrid->Rect().Contains( aPointerEvent.iPosition );
       
  1411 
       
  1412         TInt oldIndex = iGrid->CurrentDataIndex();
       
  1413         
       
  1414         if ( eventInsideControlArea && IsFocused() )
       
  1415             {
       
  1416             // Sends events to the grid and the scrollbar while FSW is focused.
       
  1417             // When tapping a highlight item, the grid sends an
       
  1418             // EEventItemClicked event to FSW, and FSW opens this app.
       
  1419             CCoeControl::HandlePointerEventL( aPointerEvent );
       
  1420             }
       
  1421         else if ( eventInsideControlArea && 
       
  1422                 aPointerEvent.iType == TPointerEvent::EButton1Up )
       
  1423             {
       
  1424             // Up event needs to be always passed to the base class so that
       
  1425             // grid's AknPhysics stays in sync.
       
  1426             CCoeControl::HandlePointerEventL( aPointerEvent );
       
  1427             }
       
  1428 
       
  1429         switch ( aPointerEvent.iType )
       
  1430             {
       
  1431             case TPointerEvent::EButton1Down:
       
  1432                 {
       
  1433                 if ( !eventInsideControlArea )
       
  1434                     {
       
  1435                     // Pointer down was received outside of the FSW.
       
  1436                     iStylusDownIn = EFalse;
       
  1437                     iIsPointerDownOutOfGrid = EFalse;
       
  1438                     }
       
  1439                 else
       
  1440                     {
       
  1441                     // Pointer down was received inside the FSW.
       
  1442                     if ( eventInsideGrid )
       
  1443                         {
       
  1444                         iStylusDownIn = ETrue;
       
  1445                         iIsPointerDownOutOfGrid = EFalse;     
       
  1446                         }
       
  1447                     else
       
  1448                         {
       
  1449                         iStylusDownIn = EFalse;    
       
  1450                         iIsPointerDownOutOfGrid = ETrue; 
       
  1451                         }
       
  1452                     
       
  1453                     if ( isOverItem )
       
  1454                         {
       
  1455                         if ( eventInsideGrid )
       
  1456                             {
       
  1457                             // Start detecting long tap.
       
  1458                             PointerEventL( aPointerEvent );
       
  1459                             }
       
  1460 
       
  1461                         }
       
  1462                     }
       
  1463                 break;
       
  1464                 }
       
  1465             
       
  1466             case TPointerEvent::EDrag:
       
  1467                 {
       
  1468                 if ( !eventInsideControlArea )
       
  1469                     {
       
  1470                     // Drag event was received outside of the FSW.
       
  1471                     if ( iStylusDownIn )
       
  1472                         {
       
  1473                         // Cancel animation when dragging outside of the FSW.
       
  1474                         CancelAnimationAndPressDownEffect();
       
  1475                         
       
  1476                         // Forward the event for scrolling.
       
  1477                         CCoeControl::HandlePointerEventL( aPointerEvent );
       
  1478                         }
       
  1479                     }
       
  1480                 else
       
  1481                     {
       
  1482                     // Drag event was received inside the FSW.
       
  1483                     if ( !iStylusDownIn )
       
  1484                         {
       
  1485                         _AKNTRACE_FUNC_EXIT;
       
  1486                         return;
       
  1487                         }
       
  1488                     
       
  1489                     if ( !iItemHighlighted )
       
  1490                         {
       
  1491                         // Highlight hasn't yet been changed so the item
       
  1492                         // index isn't update yet either.
       
  1493                         oldIndex = touchedIndex;
       
  1494                         }
       
  1495                     
       
  1496                     if ( isOverItem )
       
  1497                         {
       
  1498                         if ( eventInsideGrid )
       
  1499                             {
       
  1500                             // Start detecting long tap.
       
  1501                             PointerEventL( aPointerEvent );
       
  1502                             }
       
  1503                         
       
  1504                         if ( oldIndex != touchedIndex )
       
  1505                             {
       
  1506                             
       
  1507                             // Set this in case the listbox hasn't reported
       
  1508                             // dragging actioned event in order to not to
       
  1509                             // activate item which didn't receive the pointer down.
       
  1510                             iItemDraggingActioned = ETrue;
       
  1511                             }
       
  1512                         }
       
  1513                     else if ( iStylusDownIn )
       
  1514                         {
       
  1515                         CancelAnimationAndPressDownEffect(); 
       
  1516                         }
       
  1517                     }
       
  1518                 break;
       
  1519                 }
       
  1520                 
       
  1521             case TPointerEvent::EButton1Up:
       
  1522                 {
       
  1523                 iItemHighlighted = EFalse;
       
  1524                 
       
  1525                 if ( !eventInsideControlArea )
       
  1526                     {
       
  1527                     // Pointer up was received outside of the FSW.
       
  1528                     if ( !iStylusDownIn && !iIsPointerDownOutOfGrid )
       
  1529                         {
       
  1530                         // The FSW is closed if both the pointer down and
       
  1531                         // pointer up events occur outside the window.
       
  1532                         CloseFastSwap();
       
  1533                         }
       
  1534 
       
  1535                     CCoeControl::HandlePointerEventL( aPointerEvent );
       
  1536                     }
       
  1537                 else
       
  1538                     {
       
  1539                     // Pointer up was received inside the FSW.
       
  1540                     if ( !iStylusDownIn )
       
  1541                         {
       
  1542                         _AKNTRACE_FUNC_EXIT;
       
  1543                         return;
       
  1544                         }
       
  1545                     
       
  1546                     if ( isOverItem ) 
       
  1547                         {
       
  1548                         // The current item is selected if pointer is
       
  1549                         // lifted while in the grid / over a legimate item.
       
  1550                         
       
  1551                         // Cancel touch mode for tooltip.
       
  1552                         iTooltipModeTouch = EFalse;
       
  1553                         
       
  1554                         // Open the application as before, but now change the
       
  1555                         // highlighted item, so need to update tooltip.
       
  1556                         if ( iItemDraggingActioned ) 
       
  1557                             {
       
  1558                             if ( iToolTipTimer->IsActive() )
       
  1559                                 {
       
  1560                                 iToolTipTimer->Cancel();     
       
  1561                                 }
       
  1562     
       
  1563                             // Hide tooltip, otherwise tooltip does
       
  1564                             // not disappear.
       
  1565                             iToolTipTimer->Start(
       
  1566                                 KTooltipTimeView * 1000, 
       
  1567                                 KTimeNeverHappenEvent,
       
  1568                                 TCallBack( ToolTipTimeOutCallBackL, this ) );  
       
  1569                             }
       
  1570                         }
       
  1571                     }
       
  1572                 break;
       
  1573                 }
       
  1574                 
       
  1575             default:
       
  1576                 {
       
  1577                 CCoeControl::HandlePointerEventL( aPointerEvent );
       
  1578                 break;
       
  1579                 }
       
  1580             }
       
  1581         }
       
  1582     _AKNTRACE_FUNC_EXIT;
       
  1583     }
       
  1584 
       
  1585 
       
  1586 // ---------------------------------------------------------
       
  1587 // CAknFastSwapWindowControl::ProcessCommandL
       
  1588 // Softkey event handling
       
  1589 // ---------------------------------------------------------
       
  1590 //
       
  1591 void CAknFastSwapWindowControl::ProcessCommandL(TInt aCommandId)
       
  1592     {
       
  1593     _AKNTRACE_FUNC_ENTER;
       
  1594     _AKNTRACE( "[%s] aCommandId = %d", __FUNCTION__, aCommandId );
       
  1595     switch (aCommandId)
       
  1596         {
       
  1597         case EAknSoftkeyCancel:
       
  1598             SwitchToTask( iBackgroundWgId );
       
  1599             break;
       
  1600         case EAknSoftkeySelect:
       
  1601             HandleListBoxEventL( iGrid, EEventEnterKeyPressed );
       
  1602             break;
       
  1603         case EAknCapServerCmdOpen: 
       
  1604             SetHiddenFlag();
       
  1605             SwitchToApplicationL( iGrid->CurrentDataIndex() );
       
  1606             break;
       
  1607         case EAknCapServerCmdClose:
       
  1608             SetHiddenFlag();
       
  1609             TryCloseApplicationL( iGrid->CurrentDataIndex() );
       
  1610             break;
       
  1611         case KErrCancel:
       
  1612             SetHiddenFlag();
       
  1613             break;    
       
  1614         default:
       
  1615         	_AKNTRACE_FUNC_EXIT;
       
  1616             return;
       
  1617         }
       
  1618     _AKNTRACE_FUNC_EXIT;
       
  1619     }
       
  1620 
       
  1621 
       
  1622 // ---------------------------------------------------------------------------
       
  1623 // Handles item selection in the grid.
       
  1624 // ---------------------------------------------------------------------------
       
  1625 //
       
  1626 void CAknFastSwapWindowControl::HandleListBoxEventL( CEikListBox* /*aListBox*/, 
       
  1627                                                      TListBoxEvent aEventType )
       
  1628     {
       
  1629     _AKNTRACE_FUNC_ENTER;
       
  1630     _AKNTRACE( "[%s] aEventType = %d", __FUNCTION__, aEventType );
       
  1631     switch ( aEventType )
       
  1632         {
       
  1633         case MEikListBoxObserver::EEventPenDownOnItem:
       
  1634             iItemDraggingActioned = EFalse;
       
  1635             iPressDownTime.HomeTime();
       
  1636             break;
       
  1637             
       
  1638         case MEikListBoxObserver::EEventEnterKeyPressed:
       
  1639             SwitchToApplicationL( iGrid->CurrentDataIndex() );    
       
  1640             break;
       
  1641 
       
  1642         case MEikListBoxObserver::EEventItemClicked:
       
  1643             if ( !iItemDraggingActioned && !iIsStylusPopupShow )
       
  1644                 {
       
  1645                 TTime now;
       
  1646                 now.HomeTime();
       
  1647                 TInt64 diffTime = KPressedDownEffectTime - now.MicroSecondsFrom(iPressDownTime).Int64();         
       
  1648                 if( diffTime > 0 )
       
  1649                     {
       
  1650                     // wait for the diffTime 
       
  1651                     User::After( diffTime );     
       
  1652                     }
       
  1653                 SwitchToApplicationL( iGrid->CurrentDataIndex() );
       
  1654                 }
       
  1655             break;
       
  1656 
       
  1657         case MEikListBoxObserver::EEventPanningStarted:
       
  1658         case MEikListBoxObserver::EEventFlickStarted:
       
  1659         case MEikListBoxObserver::EEventItemDraggingActioned:
       
  1660             HideTooltip();
       
  1661             CancelAnimationAndPressDownEffect();
       
  1662             break;
       
  1663 
       
  1664         default:
       
  1665             break;
       
  1666         }
       
  1667     _AKNTRACE_FUNC_EXIT;
       
  1668     }
       
  1669 
       
  1670 // ---------------------------------------------------------------------------
       
  1671 // Handles events from grid 
       
  1672 // ---------------------------------------------------------------------------
       
  1673 //
       
  1674 void CAknFastSwapWindowControl::HandleControlEventL( 
       
  1675     CCoeControl *aControl, TCoeEvent aEventType )
       
  1676     {
       
  1677     _AKNTRACE_FUNC_ENTER;
       
  1678     if ( aControl == iGrid && aEventType == EEventStateChanged && iIsDisplayed )
       
  1679         {
       
  1680         iItemHighlighted = ETrue;
       
  1681         }
       
  1682     _AKNTRACE_FUNC_EXIT;
       
  1683     }
       
  1684 
       
  1685 // ---------------------------------------------------------
       
  1686 // CAknFastSwapWindowControl::FadeBackground
       
  1687 // Fades the underlying window group when fastswap is invoked
       
  1688 // ( if not already faded)
       
  1689 // implementation is similar to Eikon dialogs
       
  1690 // ---------------------------------------------------------
       
  1691 //
       
  1692 void CAknFastSwapWindowControl::FadeBackground(TBool aFade)
       
  1693     {
       
  1694     AknGlobalPopupPriorityController::FadeBehindPopup(*this, iPopupFader, *this, aFade);
       
  1695     }
       
  1696   
       
  1697 // ---------------------------------------------------------
       
  1698 // CAknFastSwapWindowControl::CreateGridL
       
  1699 // Grid construction
       
  1700 // ---------------------------------------------------------
       
  1701 //
       
  1702 void CAknFastSwapWindowControl::CreateGridL()
       
  1703     {
       
  1704     _AKNTRACE_FUNC_ENTER;
       
  1705     ASSERT(!iGrid);
       
  1706     TAknLayoutScalableParameterLimits cellLimits = AknLayoutScalable_Avkon::cell_fast2_pane_ParamLimits();
       
  1707     TInt numberOfGridColumns = cellLimits.LastColumn() + 1;
       
  1708     
       
  1709     iGrid = new (ELeave) CAknFastSwapWindowGrid;
       
  1710     iGrid->ConstructL( this, EAknListBoxSelectionGrid | EAknListBoxScrollBarSizeExcluded );    
       
  1711     iGrid->SetLayoutL( KVerticalOrientation, KLeftToRight,
       
  1712         KTopToBottom, numberOfGridColumns, NumberOfVisibleRows(), IconSize() );
       
  1713     iGrid->SetObserver( this );
       
  1714     
       
  1715     // CAknGrid creates a window owning scroll bar. This causes flickering of
       
  1716     // the scroll bar when fast swap window is opened. Create a non window
       
  1717     // owning scroll bar and install it into the grid.
       
  1718     CEikScrollBarFrame* sbFrame = new(ELeave) CEikScrollBarFrame(
       
  1719         this, iGrid, ETrue);
       
  1720     CleanupStack::PushL(sbFrame);
       
  1721     if (AknLayoutUtils::DefaultScrollBarType(iAvkonAppUi) == CEikScrollBarFrame::EDoubleSpan)
       
  1722         {
       
  1723         sbFrame->CreateDoubleSpanScrollBarsL(EFalse, EFalse, ETrue, EFalse);
       
  1724         }
       
  1725     iGrid->SetScrollBarFrame(sbFrame, CEikListBox::ENotOwnedExternally);
       
  1726     CleanupStack::Pop(); // sbFrame
       
  1727     iGrid->SetPrimaryScrollingType( KHorizontalScrollingType );
       
  1728     iGrid->SetSecondaryScrollingType( KVerticalScrollingType );
       
  1729     iGrid->SetCurrentDataIndex( 0 );        
       
  1730     iGrid->SetRect( TRect( 0, 0, 10, 10 ) ); // avoids grid panic        
       
  1731 
       
  1732     iGrid->SetContainerWindowL(*this);
       
  1733     iGrid->SetListBoxObserver(this);
       
  1734     // Scroll bar should be shown always when fsw visible
       
  1735     iGrid->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, 
       
  1736         CEikScrollBarFrame::EAuto);
       
  1737     if (iTransparencyEnabled)
       
  1738         {
       
  1739         // When fast swap window opens, scroll bar background appears to be
       
  1740         // drawn twice during transition even if it is added into a clipping
       
  1741         // region in CAknFastSwapWindowControl::Draw(). Therefore background
       
  1742         // drawing is disabled in scroll bar and drawn by this control.
       
  1743         iGrid->ScrollBarFrame()->DrawBackground(EFalse, EFalse);
       
  1744         }
       
  1745     _AKNTRACE_FUNC_EXIT;
       
  1746     }
       
  1747     
       
  1748 // ---------------------------------------------------------
       
  1749 // CAknFastSwapWindowControl::CreateGridL
       
  1750 // Creates CCoeControlArray for the child controls
       
  1751 // ---------------------------------------------------------
       
  1752 //
       
  1753 void CAknFastSwapWindowControl::CreateComponentArrayL()
       
  1754     {
       
  1755     _AKNTRACE_FUNC_ENTER;
       
  1756     InitComponentArrayL();
       
  1757     Components().AppendLC( iGrid, 0 );
       
  1758     CleanupStack::Pop();
       
  1759     Components().AppendLC( iLabel, 1 );
       
  1760     CleanupStack::Pop();
       
  1761     CEikScrollBar* scrollBar = iGrid->ScrollBarFrame()->VerticalScrollBar();
       
  1762     if (scrollBar)
       
  1763         {
       
  1764         Components().AppendLC(scrollBar, 2);
       
  1765         CleanupStack::Pop();
       
  1766         }
       
  1767     Components().SetControlsOwnedExternally( ETrue );
       
  1768     _AKNTRACE_FUNC_EXIT;
       
  1769     }
       
  1770 
       
  1771 // ---------------------------------------------------------
       
  1772 // CAknFastSwapWindowControl::CreateTooltipL
       
  1773 // 
       
  1774 // ---------------------------------------------------------
       
  1775 //
       
  1776 void CAknFastSwapWindowControl::CreateTooltipL()
       
  1777     {
       
  1778     _AKNTRACE_FUNC_ENTER;
       
  1779     iTooltip = CAknInfoPopupNoteController::NewL();    
       
  1780     iTooltip->SetTimeDelayBeforeShow( KTooltipTimeBefore );
       
  1781     iTooltip->SetTimePopupInView( KTooltipTimeView );
       
  1782     iTooltip->SetTooltipModeL( ETrue );
       
  1783     iTooltip->HideWhenAppFaded( EFalse );
       
  1784     _AKNTRACE_FUNC_EXIT;
       
  1785     }
       
  1786 
       
  1787 // ---------------------------------------------------------
       
  1788 // CAknFastSwapWindowControl::CreateLabelL
       
  1789 // Creates tooltip that shows application name of highlighted application icon
       
  1790 // ---------------------------------------------------------
       
  1791 //
       
  1792 void CAknFastSwapWindowControl::CreateLabelL()
       
  1793     {
       
  1794     _AKNTRACE_FUNC_ENTER;
       
  1795     // read label from resources qtn_options_task_swapper
       
  1796     HBufC* labelBuffer = CCoeEnv::Static()->AllocReadResourceL( R_QTN_SELEC_TITLE_SWAPPER );
       
  1797     CleanupStack::PushL( labelBuffer );
       
  1798             
       
  1799     // determine the width of the text
       
  1800     // determining the size of the text
       
  1801     TAknLayoutRect headingRect;
       
  1802     headingRect.LayoutRect( FastSwapWindowRect(), 
       
  1803         AknLayoutScalable_Avkon::heading_pane( 0 ).LayoutLine());
       
  1804     TAknLayoutText textLayout; 
       
  1805     textLayout.LayoutText( headingRect.Rect(), 
       
  1806         AknLayoutScalable_Avkon::heading_pane_t1( 2 ).LayoutLine() );
       
  1807     TInt width = textLayout.TextRect().Width();
       
  1808 
       
  1809     // clip the label
       
  1810     TPtr clippedStringPtr = labelBuffer->Des();
       
  1811     AknBidiTextUtils::ConvertToVisualAndClipL(
       
  1812     clippedStringPtr, *textLayout.Font() /**iEikonEnv->NormalFont()*/, width, width );
       
  1813         
       
  1814     // create label        
       
  1815     iLabel = new (ELeave) CEikLabel();
       
  1816     iLabel->SetContainerWindowL( *this );
       
  1817     iLabel->SetTextL( *labelBuffer );
       
  1818     iLabel->UseLogicalToVisualConversion( EFalse );
       
  1819     iLabel->SetBrushStyle( CGraphicsContext::ENullBrush );
       
  1820     CleanupStack::PopAndDestroy(); // labelBuffer
       
  1821     _AKNTRACE_FUNC_EXIT;
       
  1822     }
       
  1823 
       
  1824 void CAknFastSwapWindowControl::UpdateLabelL()
       
  1825     {
       
  1826     _AKNTRACE_FUNC_ENTER;
       
  1827     // layout
       
  1828     TAknLayoutRect headingArea;
       
  1829     TAknLayoutRect textArea;
       
  1830     headingArea.LayoutRect( Rect(), AknLayoutScalable_Avkon::heading_pane_cp2().LayoutLine());
       
  1831     
       
  1832     AknLayoutUtils::LayoutLabel( 
       
  1833         iLabel, 
       
  1834         headingArea.Rect(), 
       
  1835         AknLayoutScalable_Avkon::heading_pane_t1( 2 ).LayoutLine(), 
       
  1836         iEikonEnv->NormalFont());
       
  1837     
       
  1838     // skin
       
  1839     TRgb color;
       
  1840     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
  1841     TInt error = AknsUtils::GetCachedColor( skin, color, KAknsIIDQsnTextColors, 
       
  1842         EAknsCIQsnTextColorsCG19 );
       
  1843         
       
  1844     if (!error)
       
  1845         {
       
  1846         // Ignore error
       
  1847         TRAP_IGNORE( AknLayoutUtils::OverrideControlColorL( *iLabel, EColorLabelText, color ) );
       
  1848         }
       
  1849     _AKNTRACE_FUNC_EXIT;
       
  1850     }   
       
  1851 
       
  1852 
       
  1853 // ---------------------------------------------------------
       
  1854 // CAknFastSwapWindowControl::CreateGridL
       
  1855 // Updates tooltip with right application name andthat shows application name of highlighted 
       
  1856 // application icon
       
  1857 // ---------------------------------------------------------
       
  1858 //
       
  1859 void CAknFastSwapWindowControl::UpdateTooltipL()
       
  1860     {
       
  1861     _AKNTRACE_FUNC_ENTER;
       
  1862     iTooltip->HideInfoPopupNote();
       
  1863     if ( !IsFocused() || IsDimmed() || iGrid->CurrentDataIndex() == KErrNotFound )
       
  1864         {
       
  1865         _AKNTRACE_FUNC_EXIT;
       
  1866         return;
       
  1867         }
       
  1868             
       
  1869     TRect currentItemRect = CurrentGridItemRect();
       
  1870     if ( currentItemRect.iTl.iY < iGrid->View()->ViewRect().iTl.iY )
       
  1871     	{
       
  1872     	currentItemRect.iTl.iY = iGrid->View()->ViewRect().iTl.iY;
       
  1873     	}
       
  1874     TAknLayoutRect rect;
       
  1875     TRect parent;
       
  1876     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EPopupParent, parent );
       
  1877     currentItemRect.Move( FastSwapWindowRect().iTl );
       
  1878     // The tooltip width must be set before calculating the floating point in 
       
  1879     // SetPositionAndAlignment().
       
  1880     iTooltip->SetTextL( CurrentAppName() );
       
  1881     iTooltip->SetPositionByHighlight(currentItemRect); // This method also checks the current layout (European or Arabic)
       
  1882     if( !iTooltipModeTouch )
       
  1883         {
       
  1884         iTooltip->SetTimeDelayBeforeShow(KTooltipTimeBefore);
       
  1885         iTooltip->SetTimePopupInView(KTooltipTimeView);
       
  1886         }
       
  1887     _AKNTRACE_FUNC_EXIT;
       
  1888     }
       
  1889 
       
  1890 // ---------------------------------------------------------
       
  1891 // CAknFastSwapWindowControl::ShowTooltipTouchL
       
  1892 // Handles tooltip when touch input is used.
       
  1893 // ---------------------------------------------------------
       
  1894 //
       
  1895 void CAknFastSwapWindowControl::ShowTooltipTouchL(TBool aPointerOverItem)
       
  1896     {
       
  1897     _AKNTRACE_FUNC_ENTER;
       
  1898     _AKNTRACE( "[%s] aPointerOverItem = %d", __FUNCTION__, aPointerOverItem );
       
  1899     if( !iTooltipModeTouch && aPointerOverItem)
       
  1900         {
       
  1901         iTooltip->SetTimeDelayBeforeShow(KTooltipTimeBeforeTouch);
       
  1902         iTooltip->SetTimePopupInView(KTooltipTimeViewTouch);
       
  1903         iTooltipModeTouch = ETrue;
       
  1904         }
       
  1905     // Show tooltip only when fast swap control has keyboard focus.
       
  1906     if (IsFocused())
       
  1907         {
       
  1908         UpdateTooltipL();
       
  1909         iTooltip->ShowInfoPopupNote();
       
  1910         }
       
  1911     _AKNTRACE_FUNC_EXIT;
       
  1912     }
       
  1913 
       
  1914 // ---------------------------------------------------------
       
  1915 // CAknFastSwapWindowControl::CurrentGridItemRect
       
  1916 // The rect of current highlighted grid item
       
  1917 // ---------------------------------------------------------
       
  1918 //        
       
  1919 TRect CAknFastSwapWindowControl::CurrentGridItemRect()
       
  1920     {
       
  1921     _AKNTRACE_FUNC_ENTER;
       
  1922     // must be item index, not data index as usual
       
  1923     TInt index = iGrid->CurrentItemIndex();
       
  1924     if( index != KErrNotFound )         
       
  1925         {
       
  1926         TRect currentItemRect = TRect( iGrid->View()->ItemPos( index ) /*item pos*/, 
       
  1927             iGrid->View()->ItemSize( 0)  /*item size*/);
       
  1928 
       
  1929         _AKNTRACE_FUNC_EXIT;   
       
  1930         return currentItemRect;
       
  1931         }
       
  1932     _AKNTRACE_FUNC_EXIT;
       
  1933     return TRect( NULL, NULL, NULL, NULL );
       
  1934     }
       
  1935     
       
  1936 // ---------------------------------------------------------
       
  1937 // CAknFastSwapWindowControl::UpdateHeadingIconL
       
  1938 // Resets heading icon with the icon provided by the current skin
       
  1939 // ---------------------------------------------------------
       
  1940 //
       
  1941 void CAknFastSwapWindowControl::UpdateHeadingIconL()
       
  1942     {
       
  1943     _AKNTRACE_FUNC_ENTER;
       
  1944     if ( iLowMemory )
       
  1945     	{
       
  1946     	_AKNTRACE_FUNC_EXIT;
       
  1947         return;
       
  1948     	}
       
  1949     MAknsSkinInstance* skin = AknsUtils::SkinInstance();    
       
  1950     
       
  1951     CGulIcon* headingIcon = AknsUtils::CreateGulIconL( 
       
  1952         skin, KAknsIIDQgnIndiAppOpen, 
       
  1953         AknIconUtils::AvkonIconFileName(),
       
  1954         EMbmAvkonQgn_indi_app_open_add, 
       
  1955         EMbmAvkonQgn_indi_app_open_add_mask);
       
  1956         
       
  1957     CleanupStack::PushL( headingIcon ); // to stack
       
  1958     TAknLayoutRect headingArea;
       
  1959     TAknLayoutRect headingBackground;
       
  1960     TAknLayoutRect iconArea;
       
  1961     headingArea.LayoutRect( Rect(), AknLayoutScalable_Avkon::heading_pane_cp2().LayoutLine() );
       
  1962     
       
  1963     headingBackground.LayoutRect( 
       
  1964         headingArea.Rect(), 
       
  1965         AknLayoutScalable_Avkon::bg_popup_heading_pane(  0 ).LayoutLine() );
       
  1966         
       
  1967     iconArea.LayoutRect( 
       
  1968         headingBackground.Rect(), 
       
  1969         AknLayoutScalable_Avkon::heading_pane_g2().LayoutLine() );
       
  1970         
       
  1971     User::LeaveIfError( AknIconUtils::SetSize( headingIcon->Bitmap(), iconArea.Rect().Size() ) ); 
       
  1972 
       
  1973     delete iHeadingIcon;                                         
       
  1974     iHeadingIcon = headingIcon;
       
  1975     CleanupStack::Pop(); // headingIcon    
       
  1976     _AKNTRACE_FUNC_EXIT;
       
  1977     }
       
  1978 
       
  1979 // ---------------------------------------------------------
       
  1980 // CAknFastSwapWindowControl::CreateCbaL
       
  1981 // Softkey construction (component control of CAknFastswapWindowControl)
       
  1982 // ---------------------------------------------------------
       
  1983 //
       
  1984 void CAknFastSwapWindowControl::CreateCbaL()
       
  1985     {
       
  1986     _AKNTRACE_FUNC_ENTER;
       
  1987     ASSERT(!iCba);
       
  1988     TRect screenRect;
       
  1989     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screenRect );    
       
  1990     
       
  1991     iCba = CEikButtonGroupContainer::NewL(
       
  1992         CEikButtonGroupContainer::ECba,
       
  1993         CEikButtonGroupContainer::EHorizontal,
       
  1994         this, R_AVKON_SOFTKEYS_SELECT_CANCEL__SELECT);
       
  1995         
       
  1996     iCba->MakeVisible( EFalse );
       
  1997     iCba->SetBoundingRect( screenRect );
       
  1998     
       
  1999     iCba->ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition( -1 );   // -1 puts this window at the back
       
  2000         
       
  2001     iAppUi.RemoveFromStack( iCba->ButtonGroup()->AsControl() );
       
  2002     AknGlobalPopupPriorityController::AddSubPopupL(*this, *iCba->ButtonGroup()->AsControl());
       
  2003     _AKNTRACE_FUNC_EXIT; 
       
  2004     }
       
  2005 
       
  2006 // ---------------------------------------------------------
       
  2007 // CAknFastSwapWindowControl::UpdateItemArraysL
       
  2008 // Retrieves the application names and icons via the apparc
       
  2009 // server, and stores them in arrays.
       
  2010 // ---------------------------------------------------------
       
  2011 //
       
  2012 void CAknFastSwapWindowControl::UpdateItemArraysL()
       
  2013     {
       
  2014     _AKNTRACE_FUNC_ENTER;
       
  2015     ClearItemArrays( EFalse );
       
  2016     RWsSession& wsSession = iEikonEnv->WsSession();
       
  2017 
       
  2018     TBuf<2*KMaxFileName+1> name;
       
  2019 
       
  2020     // Set the icon size we wish retrieve
       
  2021     TUid appUid;
       
  2022     TInt wgId;
       
  2023 
       
  2024     for (TInt index=0; index<iNumberOfWGs; index++)
       
  2025         {
       
  2026         wgId=(*iShownWgIds)[index].iWgId;
       
  2027         TApaAppInfo info;
       
  2028         //
       
  2029         // Always shown applications
       
  2030         //
       
  2031         if ( iAlwaysShownList->IsAlwaysShownApp( wgId ) )
       
  2032             {
       
  2033             appUid = iAlwaysShownList->IndexToAppUid( index );
       
  2034             iAppArcSession.GetAppInfo( info, appUid );
       
  2035 
       
  2036             // retrieve the app name
       
  2037             TPtrC caption = info.iShortCaption;
       
  2038             name.Zero();
       
  2039             
       
  2040             // conversion from TInt to TReal, might be a problem in the future
       
  2041             name.AppendNum( index ); 
       
  2042             
       
  2043             name.Append( KTab );
       
  2044             name.Append( caption );
       
  2045             }
       
  2046         else if (iWidgetsSupported && iWidgetList->IsWidget( wgId ))
       
  2047             {
       
  2048             appUid = iWidgetList->IndexToAppUid( index, iAlwaysShownList->iAppList->Count() );
       
  2049             iAppArcSession.GetAppInfo( info, appUid );
       
  2050 
       
  2051             // retrieve the app name
       
  2052             TPtrC caption = info.iShortCaption;
       
  2053             name.Zero();
       
  2054             
       
  2055             // conversion from TInt to TReal, might be a problem in the future
       
  2056             name.AppendNum( index ); 
       
  2057             
       
  2058             name.Append( KTab );
       
  2059             name.Append( caption );            
       
  2060             }            
       
  2061         //
       
  2062         // Running Applications
       
  2063         //
       
  2064         else 
       
  2065             {
       
  2066             CApaWindowGroupName* windowName = CApaWindowGroupName::NewLC( wsSession, wgId );
       
  2067             appUid = windowName->AppUid();
       
  2068             iAppArcSession.GetAppInfo( info, appUid );
       
  2069 
       
  2070             //Retrieve the app name
       
  2071             TPtrC caption = info.iShortCaption;
       
  2072             name.Zero();
       
  2073             
       
  2074             // conversion from TInt to TReal, might be a problem in the future
       
  2075             name.AppendNum( index ); 
       
  2076             
       
  2077             name.Append( KTab );
       
  2078             if ( !( caption.Length() ) ) // if not set - use thread name instead
       
  2079                 {
       
  2080                 if (windowName->Caption().Length() != 0)
       
  2081                     {
       
  2082                     name.Append( windowName->Caption() );
       
  2083                     }
       
  2084                 else
       
  2085                     {
       
  2086                     TThreadId threadId;
       
  2087                     TInt err = wsSession.GetWindowGroupClientThreadId( wgId, threadId );
       
  2088                     if ( err == KErrNone )
       
  2089                         {
       
  2090                         RThread thread;
       
  2091                         err = thread.Open( threadId);
       
  2092                         if ( err==KErrNone )
       
  2093                             {
       
  2094                             name.Append( thread.Name() );
       
  2095                             thread.Close();
       
  2096                             }
       
  2097                         }
       
  2098                     }
       
  2099                 }
       
  2100             else
       
  2101                 {
       
  2102                 name.Append( caption );
       
  2103                 }
       
  2104             CleanupStack::PopAndDestroy();  //windowName
       
  2105             }
       
  2106         // we discontinue if no more items can be added to the icon array
       
  2107         TBool iconAddSuccess = ETrue;
       
  2108         TRAPD(error ,iconAddSuccess = AddIconToArrayL( appUid ));
       
  2109         if (!iconAddSuccess)
       
  2110             {
       
  2111             break;      
       
  2112             }
       
  2113         if( error != KErrNone )
       
  2114            {
       
  2115            if( error == KErrNoMemory )
       
  2116               {
       
  2117               User::LeaveNoMemory();
       
  2118               }
       
  2119            if( error == KErrNotFound )
       
  2120               {
       
  2121               iIconArray->AppendL( iDefaultAppIcon);
       
  2122               }
       
  2123            else
       
  2124               {
       
  2125               User::Leave(error);
       
  2126               }
       
  2127             }            
       
  2128         iItemTextArray->AppendL( name );
       
  2129         }
       
  2130        
       
  2131     // update the grid according the changes made to icon arrays
       
  2132     TInt newCount = iItemTextArray->MdcaCount();
       
  2133     if (newCount >= iOldCount)
       
  2134         iGrid->HandleItemAdditionL();
       
  2135     else
       
  2136         {
       
  2137         iGrid->HandleItemRemovalL();
       
  2138         if ( ( iGrid->Model()->NumberOfItems() % iGrid->GridView()->NumberOfColsInView() ) == 0 )
       
  2139             { 
       
  2140             TInt logicalRow;
       
  2141             TInt logicalColumn;   
       
  2142             TInt topItemIndex; 
       
  2143             
       
  2144             iGrid->GridView()->LogicalPosFromListBoxIndex(  
       
  2145                 iGrid->TopItemIndex(), 
       
  2146                 logicalRow, 
       
  2147                 logicalColumn );
       
  2148                 
       
  2149             logicalRow = Max( 0, logicalRow - 1 ); 
       
  2150             
       
  2151             iGrid->GridView()->ListBoxIndexFromLogicalPos(  
       
  2152                 topItemIndex, 
       
  2153                 logicalRow, 
       
  2154                 logicalColumn );
       
  2155                 
       
  2156             iGrid->SetTopItemIndex( topItemIndex );
       
  2157             }
       
  2158         }
       
  2159     _AKNTRACE_FUNC_EXIT;
       
  2160     }
       
  2161 
       
  2162 // ---------------------------------------------------------
       
  2163 // CAknFastSwapWindowControl::AddIconToArrayL
       
  2164 // Application is added to the AknGrid icon array
       
  2165 // if it can be found and if there is enough memory
       
  2166 // If not, default application icon is used
       
  2167 // ---------------------------------------------------------
       
  2168 //
       
  2169 TBool CAknFastSwapWindowControl::AddIconToArrayL( TUid aAppUid )
       
  2170     {
       
  2171     _AKNTRACE_FUNC_ENTER;
       
  2172     _AKNTRACE( "[%s] aAppUid = %d", __FUNCTION__, aAppUid.iUid );
       
  2173     if ( iLowMemory )
       
  2174         {
       
  2175         // when memory is low, only one prereserved 
       
  2176         // default app icon is used for every grid item
       
  2177         TRAPD( err, iIconArray->AppendL( iDefaultAppIcon) );
       
  2178         if ( err != KErrNone )
       
  2179             {
       
  2180             _AKNTRACE_FUNC_EXIT;
       
  2181             // if memory runs out, FSW uses what it has 
       
  2182             // and continues (should never happen)
       
  2183             return EFalse;
       
  2184             }
       
  2185         iLowMemIcons = ETrue;
       
  2186        
       
  2187         // fsw can only quarantee KMinimumSupportedApps number of apps 
       
  2188         // in low memory conditions, so after KMinimumSupportedApps items
       
  2189         // no more items are added to the memory
       
  2190         if ( iItemTextArray->Count() >= KMinimumSupportedApps )
       
  2191             {
       
  2192             _AKNTRACE_FUNC_EXIT;
       
  2193             return EFalse;
       
  2194             }
       
  2195         }
       
  2196     else
       
  2197         {
       
  2198         CGulIcon* icon;
       
  2199         CFbsBitmap* bitmap;
       
  2200         CFbsBitmap* mask;
       
  2201         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
  2202         // Retrieve the app icon using the Uid
       
  2203         AknsUtils::CreateAppIconLC( skin, aAppUid, EAknsAppIconTypeList,bitmap, mask );
       
  2204         User::LeaveIfError( AknIconUtils::SetSize( bitmap, IconSize() ) );
       
  2205         icon = CGulIcon::NewL( bitmap, mask );    //takes ownership
       
  2206         CleanupStack::PushL( icon );
       
  2207         CleanupStack::Pop( 2 ); // bitmap, mask
       
  2208         iIconArray->AppendL( icon );       //takes ownership
       
  2209         CleanupStack::Pop(); // icon
       
  2210         }
       
  2211     _AKNTRACE_FUNC_EXIT;
       
  2212     return ETrue;
       
  2213     }
       
  2214    
       
  2215 // ---------------------------------------------------------
       
  2216 // CAknFastSwapWindowControl::SwitchToApplicationL
       
  2217 // Either launches an application using method LaunchAppL
       
  2218 // or brings existing task to foreground by calling method SwitchToTask
       
  2219 // ---------------------------------------------------------
       
  2220 //
       
  2221 void CAknFastSwapWindowControl::SwitchToApplicationL( TInt aIndex )
       
  2222     {
       
  2223     _AKNTRACE_FUNC_ENTER;
       
  2224     _AKNTRACE( "[%s] aIndex = %d", __FUNCTION__, aIndex );
       
  2225     // abort FSW transition when item chosen (case when choosing quickly)
       
  2226     GfxTransEffect::Abort();
       
  2227     TInt wgId = (*iShownWgIds)[ aIndex ].iWgId;
       
  2228 
       
  2229     // launches application and closes fastswap
       
  2230     if ( wgId == KApplicationWithoutWG )
       
  2231         {
       
  2232         LaunchAppL( iAlwaysShownList->IndexToAppUid( aIndex ) );
       
  2233         }
       
  2234     else if ( iWidgetsSupported && wgId == KWidgetWithoutWG )
       
  2235         {
       
  2236         LaunchAppL( iWidgetList->IndexToAppUid( aIndex, iAlwaysShownList->iAppList->Count() ) );
       
  2237         }
       
  2238     // brings existing application to foreground and closes fastswap    
       
  2239     else 
       
  2240         {
       
  2241         if ( iAlwaysShownList->IsAlwaysShownApp( wgId ) &&
       
  2242              iAlwaysShownList->IndexToAppUid( aIndex ) == KMenuAppUid )
       
  2243             {     
       
  2244             TBuf<128> viewType;
       
  2245             if ( wgId != iBackgroundWgId || 
       
  2246                  ( RProperty::Get(KFSWMMenuPSCat, KFSWMMenuLastViewKey, viewType) == KErrNone &&
       
  2247                  viewType.Compare(KFSWMMenuFolderView) != 0 ) )
       
  2248                 {
       
  2249                 TApaTask task( iEikonEnv->WsSession() );       
       
  2250                 task.SetWgId( wgId );       
       
  2251                 task.SendMessage(KUidApaMessageSwitchOpenFile, KNullDesC8);                       
       
  2252                 } 
       
  2253             }
       
  2254         SwitchToTask( wgId );
       
  2255         } 
       
  2256     _AKNTRACE_FUNC_EXIT;
       
  2257     }
       
  2258 
       
  2259 // ---------------------------------------------------------
       
  2260 // CAknFastSwapWindowControl::SwitchToTask
       
  2261 // Brings a task associated with the given window group to
       
  2262 // the foreground, and dismissed CAknFastswapWindowControl
       
  2263 // from the screen and removes it from the control stack
       
  2264 // ---------------------------------------------------------
       
  2265 //
       
  2266 void CAknFastSwapWindowControl::SwitchToTask( TInt aWgId )
       
  2267     {
       
  2268     _AKNTRACE_FUNC_ENTER;
       
  2269     _AKNTRACE( "[%s] aWgId = %d", __FUNCTION__, aWgId );
       
  2270     CloseFastSwap();
       
  2271     if( iFirstAppWgId != aWgId && iBackgroundWgId != aWgId )
       
  2272         {
       
  2273         GfxTransEffect::BeginFullScreen(5000,
       
  2274         TRect(0,0,0,0),
       
  2275         AknTransEffect::EParameterType,
       
  2276         
       
  2277         AknTransEffect::GfxTransParam(
       
  2278             iAppUi.Application()->AppDllUid(), 
       
  2279             AknTransEffect::TParameter::EActivateExplicitContinue));
       
  2280         }
       
  2281         
       
  2282     CAknSgcClient::MoveApp(aWgId, ESgcMoveAppToForeground);
       
  2283     _AKNTRACE_FUNC_EXIT;
       
  2284     }
       
  2285 
       
  2286 // ---------------------------------------------------------
       
  2287 // CAknFastSwapWindowControl::SwitchToTask
       
  2288 // Launches an application to the phone memory based on the 
       
  2289 // given application uid and closes the fastswap
       
  2290 // ---------------------------------------------------------
       
  2291 //
       
  2292 void CAknFastSwapWindowControl::LaunchAppL( TUid aAppUid )
       
  2293     {
       
  2294     _AKNTRACE_FUNC_ENTER;
       
  2295     _AKNTRACE( "[%s] aAppUid = %d", __FUNCTION__, aAppUid.iUid );
       
  2296     RApaLsSession ls;                   
       
  2297     User::LeaveIfError(ls.Connect());   
       
  2298     CleanupClosePushL(ls);
       
  2299     CApaCommandLine* cmdLine=CApaCommandLine::NewLC();
       
  2300     cmdLine->SetCommandL(EApaCommandRun); 
       
  2301     TApaAppInfo info; 
       
  2302     iAppArcSession.GetAppInfo( info, aAppUid );
       
  2303     cmdLine->SetExecutableNameL( info.iFullName );
       
  2304     ls.StartApp( *cmdLine ); 
       
  2305     CleanupStack::PopAndDestroy(2); // cmdLine, ls
       
  2306     // informing the system about a transition 
       
  2307     
       
  2308     CloseFastSwap();    
       
  2309     _AKNTRACE_FUNC_EXIT;
       
  2310     }
       
  2311     
       
  2312         
       
  2313 // ---------------------------------------------------------
       
  2314 // CAknFastSwapWindowControl::CloseFastSwap
       
  2315 // Dismisses CAknFastswapWindowControl
       
  2316 // from the screen and removes it from the control stack
       
  2317 // ---------------------------------------------------------
       
  2318 //
       
  2319 void CAknFastSwapWindowControl::CloseFastSwap()
       
  2320     {
       
  2321     _AKNTRACE_FUNC_ENTER;
       
  2322     if ( iIsDisplayed )
       
  2323         {
       
  2324         TInt effectValue( 0 );
       
  2325         iThemesAppRepository->Get( KThemesTransitionEffects, effectValue );
       
  2326         if ( effectValue == 0 ) /* TAT on */
       
  2327             {
       
  2328             MTouchFeedback* feedback = MTouchFeedback::Instance();
       
  2329             if ( feedback )
       
  2330                 {
       
  2331                 feedback->InstantFeedback( ETouchFeedbackDecreasingPopUp );
       
  2332                 }
       
  2333             }
       
  2334         // calculate already here since PositionRelativeToScreen
       
  2335         // causes a flush to WS, which can disturb transition
       
  2336         TPoint dPoint( iGrid->PositionRelativeToScreen() );
       
  2337         TRect dRect( iGrid->Rect() );
       
  2338         dRect.Move( dPoint );
       
  2339         TBool visible = IsVisible();
       
  2340    
       
  2341         TBool rsWasEnabled( EFalse );
       
  2342 
       
  2343         if( !iDisableFSWEffect )
       
  2344             {
       
  2345             if( !iTransparencyEnabled && Window().IsRedrawStoreEnabled() )
       
  2346                 {
       
  2347                 rsWasEnabled = ETrue;
       
  2348                 // disable rsStore during transition
       
  2349                 Window().EnableRedrawStore( EFalse );
       
  2350                 }
       
  2351             // If we never got to the callback after the appear effect, we
       
  2352             // remove the observer here, so that we don't get the callback
       
  2353             // when the disappear effect finishes.
       
  2354             CAknFastSwapData *data = 
       
  2355                 (CAknFastSwapData*)CAknTransitionUtils::GetData( (TInt)this );
       
  2356             CAknTransitionUtils::RemoveObserver( data,
       
  2357                 CAknTransitionUtils::EEventControlTransitionFinished );
       
  2358 
       
  2359             if(visible)
       
  2360                 {   
       
  2361                 GfxTransEffect::Begin( this, KGfxControlDisappearAction );
       
  2362                 GfxTransEffect::NotifyExternalState(ECaptureComponentsBegin, (const TDesC8*)this);
       
  2363                 }
       
  2364             }
       
  2365         delete iConfirmCloseDialog;
       
  2366         iConfirmCloseDialog = NULL;
       
  2367         iTooltip->HideInfoPopupNote();
       
  2368 
       
  2369         if ( iTimeOut->IsActive() )
       
  2370             {
       
  2371             iTimeOut->Cancel();
       
  2372             StopAnimation();
       
  2373             iState = EWaiting;    
       
  2374             iTooltipModeTouch = EFalse;
       
  2375             }
       
  2376         if ( iIsStylusPopupShow )
       
  2377             {
       
  2378             //for Hide popup menu,but CStylusPopupMenu does not export HideMenu method.  
       
  2379             delete iPopupMenu;
       
  2380             iPopupMenu = NULL;
       
  2381             SetHiddenFlag();    
       
  2382             }
       
  2383         
       
  2384          
       
  2385         MakeVisible( EFalse );
       
  2386         if( !iDisableFSWEffect )
       
  2387             {
       
  2388             if(visible)
       
  2389                 {              
       
  2390                 CAknTransitionUtils::MakeVisibleSubComponents( this,
       
  2391                                         CAknTransitionUtils::EForceInvisible );
       
  2392                 GfxTransEffect::SetDemarcation( this, dRect );
       
  2393                 GfxTransEffect::NotifyExternalState(ECaptureComponentsEnd, (const TDesC8*)this);
       
  2394                 GfxTransEffect::End( this );
       
  2395                 }
       
  2396             if( !iTransparencyEnabled && rsWasEnabled )
       
  2397                 {
       
  2398                 Window().EnableRedrawStore( ETrue );
       
  2399                 }
       
  2400             }
       
  2401         GfxTransEffect::Deregister( this );
       
  2402 
       
  2403         FadeBackground( EFalse );
       
  2404 
       
  2405         AknGlobalPopupPriorityController::ShowPopup(*this, EFalse);
       
  2406         
       
  2407         InvalidateWindows(this);
       
  2408             
       
  2409         iCba->MakeVisible( EFalse );
       
  2410         SetFocus( EFalse );
       
  2411         iAppUi.RemoveFromStack( iCba->ButtonGroup()->AsControl() );
       
  2412         iAppUi.RemoveFromStack( this );
       
  2413         
       
  2414         SetPointerCapture( EFalse );
       
  2415         //IgnoreEventsUntilNextPointerUp();
       
  2416 
       
  2417         // Item array data like app names and icons 
       
  2418         // is not preserved when the FSW is not visible
       
  2419         // (to save used heap)
       
  2420         ClearItemArrays( ETrue );
       
  2421         }
       
  2422     iIsDisplayed = EFalse;
       
  2423     _AKNTRACE_FUNC_EXIT;
       
  2424     }
       
  2425 
       
  2426 // ---------------------------------------------------------
       
  2427 // CAknFastSwapWindowControl::CleanupRunFastSwap
       
  2428 // ---------------------------------------------------------
       
  2429 //
       
  2430 void CAknFastSwapWindowControl::CleanupRunFastSwap(TAny* aThis)
       
  2431     {
       
  2432     ( (CAknFastSwapWindowControl*) aThis)->CloseFastSwap();
       
  2433     }
       
  2434 
       
  2435 // ---------------------------------------------------------
       
  2436 // CAknFastSwapWindowControl::HandleShortAppsKeyPressL
       
  2437 // ---------------------------------------------------------
       
  2438 //
       
  2439 void CAknFastSwapWindowControl::HandleShortAppsKeyPressL()
       
  2440     {
       
  2441     _AKNTRACE_FUNC_ENTER;
       
  2442     if ( !iConfirmCloseDialog && IsFocused() )
       
  2443         {
       
  2444         TInt index = ( iGrid->CurrentDataIndex() + 1) % iShownWgIds->Count();
       
  2445         iGrid->SetCurrentDataIndex( index );
       
  2446         iGrid->DrawDeferred();
       
  2447         UpdateTooltipL();
       
  2448         iTooltip->ShowInfoPopupNote();
       
  2449         }
       
  2450     _AKNTRACE_FUNC_EXIT;
       
  2451     }
       
  2452 
       
  2453 // ---------------------------------------------------------
       
  2454 // CAknFastSwapWindowControl::HandleLongAppsKeyPressL
       
  2455 // ---------------------------------------------------------
       
  2456 //
       
  2457 void CAknFastSwapWindowControl::HandleLongAppsKeyPressL()
       
  2458     {
       
  2459     _AKNTRACE_FUNC_ENTER;
       
  2460     if (!iConfirmCloseDialog)
       
  2461         {
       
  2462         HandleListBoxEventL( iGrid, EEventEnterKeyPressed );
       
  2463         }
       
  2464     _AKNTRACE_FUNC_EXIT;
       
  2465     }
       
  2466 
       
  2467 // ---------------------------------------------------------
       
  2468 // CAknFastSwapWindowControl::MopSupplyObject
       
  2469 // ---------------------------------------------------------
       
  2470 //
       
  2471 TTypeUid::Ptr CAknFastSwapWindowControl::MopSupplyObject(TTypeUid aId)
       
  2472     {
       
  2473     if ( aId.iUid == MAknsControlContext::ETypeId )
       
  2474         {
       
  2475         return ( MAknsControlContext::SupplyMopObject( aId, iFrameContext ) ) ;
       
  2476         }
       
  2477 
       
  2478     return SupplyMopObject(aId, iCba);
       
  2479     }
       
  2480 
       
  2481 // ---------------------------------------------------------
       
  2482 // CAknFastSwapWindowControl::FastSwapWindowRect
       
  2483 // ---------------------------------------------------------
       
  2484 //
       
  2485 TRect CAknFastSwapWindowControl::FastSwapWindowRect()
       
  2486     {
       
  2487     _AKNTRACE_FUNC_ENTER;
       
  2488     TRect parent;
       
  2489     TAknLayoutRect rect;  
       
  2490     TRect finalRect;  
       
  2491     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EPopupParent, parent );
       
  2492     AknLayoutUtils::TAknCbaLocation cbaLocation( AknLayoutUtils::CbaLocation() );  
       
  2493     
       
  2494     TInt variety( 0 );
       
  2495     if ( cbaLocation == AknLayoutUtils::EAknCbaLocationRight )
       
  2496         {
       
  2497         variety = 3;
       
  2498         }
       
  2499     else if ( cbaLocation == AknLayoutUtils::EAknCbaLocationLeft )
       
  2500         {
       
  2501         variety = 6;
       
  2502         }
       
  2503     else
       
  2504         {
       
  2505         variety = 0;
       
  2506         }
       
  2507         
       
  2508     if( Layout_Meta_Data::IsLandscapeOrientation() && 
       
  2509         Layout_Meta_Data::IsPenEnabled() &&
       
  2510         cbaLocation == AknLayoutUtils::EAknCbaLocationBottom && 
       
  2511         !AknStatuspaneUtils::FlatLayoutActive() )
       
  2512         {
       
  2513         variety = 3; 
       
  2514         }
       
  2515     rect.LayoutRect( parent, 
       
  2516         AknLayoutScalable_Avkon::popup_fast_swap2_window( 
       
  2517             variety + NumberOfVisibleRows() - 1 ).LayoutLine() );
       
  2518     _AKNTRACE_FUNC_EXIT;
       
  2519     return rect.Rect();        
       
  2520     }
       
  2521     
       
  2522 // ---------------------------------------------------------
       
  2523 // CAknFastSwapWindowControl::CountFadedComponents
       
  2524 // ---------------------------------------------------------
       
  2525 //
       
  2526 TInt CAknFastSwapWindowControl::CountFadedComponents()
       
  2527     {
       
  2528     return 4;
       
  2529     }
       
  2530 
       
  2531 // ---------------------------------------------------------
       
  2532 // CAknFastSwapWindowControl::FadedComponent
       
  2533 // ---------------------------------------------------------
       
  2534 //
       
  2535 CCoeControl* CAknFastSwapWindowControl::FadedComponent(TInt aIndex)
       
  2536     {
       
  2537     _AKNTRACE( "[%s] aIndex = %d", __FUNCTION__, aIndex );
       
  2538     switch (aIndex)
       
  2539         {
       
  2540         case 0:
       
  2541             return this;
       
  2542         case 1:
       
  2543             return iGrid;
       
  2544         case 2:
       
  2545             return iCba;
       
  2546         case 3:
       
  2547             return iLongTapAnimation;
       
  2548         default:
       
  2549             return NULL;
       
  2550         }
       
  2551     }
       
  2552 
       
  2553 // ---------------------------------------------------------
       
  2554 // CAknFastSwapWindowControl::OfferCloseSelectedAppL
       
  2555 // ---------------------------------------------------------
       
  2556 //
       
  2557 TBool CAknFastSwapWindowControl::OfferCloseSelectedAppL(const TDesC& aName)
       
  2558     {
       
  2559     _AKNTRACE_FUNC_ENTER;
       
  2560     HBufC* msg = StringLoader::LoadLC(R_CONFIRM_CLOSE_APP_MESSAGE, aName, iEikonEnv);
       
  2561     delete iConfirmCloseDialog;
       
  2562     iConfirmCloseDialog = NULL;
       
  2563     iConfirmCloseDialog = CAknQueryDialog::NewL( CAknQueryDialog::EConfirmationTone );
       
  2564     iConfirmCloseDialog->SetPromptL( *msg );
       
  2565     CleanupStack::PopAndDestroy(msg);
       
  2566     TBool ok = iConfirmCloseDialog->ExecuteLD(R_CONFIRM_CLOSE_APP_QUERY);
       
  2567     iConfirmCloseDialog = NULL;
       
  2568     _AKNTRACE_FUNC_EXIT;
       
  2569     return ok;
       
  2570     }
       
  2571 
       
  2572 // ---------------------------------------------------------
       
  2573 // CAknFastSwapWindowControl::IsWgIdInShownList
       
  2574 // ---------------------------------------------------------
       
  2575 //
       
  2576 TBool CAknFastSwapWindowControl::IsWgIdInShownList(TInt aWgId)
       
  2577     {
       
  2578     _AKNTRACE_FUNC_ENTER;
       
  2579     _AKNTRACE( "[%s] aWgId = %d", __FUNCTION__, aWgId );
       
  2580     TInt count = iShownWgIds->Count();
       
  2581     for (TInt ii=0; ii<count; ii++)
       
  2582         {
       
  2583         if ( iShownWgIds->At(ii).iWgId == aWgId )
       
  2584             {
       
  2585             _AKNTRACE_FUNC_EXIT;
       
  2586             return ETrue;
       
  2587             }
       
  2588         }
       
  2589     _AKNTRACE_FUNC_EXIT;
       
  2590     return EFalse;
       
  2591     }
       
  2592 
       
  2593 // ---------------------------------------------------------
       
  2594 // CAknFastSwapWindowControl::FocusChanged
       
  2595 // ---------------------------------------------------------
       
  2596 //
       
  2597 void CAknFastSwapWindowControl::FocusChanged(TDrawNow /*aDrawNow*/)
       
  2598     {
       
  2599     _AKNTRACE_FUNC_ENTER;
       
  2600     if( iGrid )
       
  2601         {
       
  2602         iGrid->SetFocus( IsFocused() );
       
  2603         }
       
  2604 
       
  2605     if (!IsFocused() && iTooltip)
       
  2606         {
       
  2607         iTooltip->HideInfoPopupNote();
       
  2608         }
       
  2609     if ( !IsFocused() && iIsStylusPopupShow )
       
  2610         {
       
  2611         delete iPopupMenu;
       
  2612         iPopupMenu = NULL;
       
  2613         SetHiddenFlag();
       
  2614         }
       
  2615     _AKNTRACE_FUNC_EXIT;
       
  2616     }
       
  2617 
       
  2618 // ---------------------------------------------------------
       
  2619 // CAknFastSwapWindowControl::SizeChanged
       
  2620 // ---------------------------------------------------------
       
  2621 //
       
  2622 void CAknFastSwapWindowControl::SizeChanged()
       
  2623     {
       
  2624     _AKNTRACE_FUNC_ENTER;
       
  2625     // FSW tries to update the UI
       
  2626     TRAPD( err, UpdateViewL() );
       
  2627    
       
  2628     // if the creation of the grid wasn't successful,
       
  2629     // FSW creates a grid without reserving new icons       
       
  2630     if ( err != KErrNone )
       
  2631         {
       
  2632         if ( err == KErrNoMemory )
       
  2633             {
       
  2634             // FSW in low memory
       
  2635             iLowMemory = ETrue;
       
  2636             TRAP_IGNORE( UpdateViewL() );
       
  2637             iLowMemory = EFalse;    
       
  2638             // above should always work, because memory is always 
       
  2639             // reserved for default application icon and the minimum of 20 apps
       
  2640             }
       
  2641         }    
       
  2642     _AKNTRACE_FUNC_EXIT;
       
  2643     }
       
  2644 
       
  2645 // ---------------------------------------------------------
       
  2646 // CAknFastSwapWindowControl::HandleResourceChange
       
  2647 // ---------------------------------------------------------
       
  2648 //
       
  2649 void CAknFastSwapWindowControl::HandleResourceChange(TInt aType)
       
  2650     {
       
  2651     _AKNTRACE_FUNC_ENTER;
       
  2652     _AKNTRACE( "[%s] aType = %d", __FUNCTION__, aType );
       
  2653     CCoeControl::HandleResourceChange(aType);
       
  2654     if ( aType == KAknsMessageSkinChange )
       
  2655         {
       
  2656         TRAP_IGNORE( UpdateDefaultAppIconL() );
       
  2657         }
       
  2658     if ( iCba )
       
  2659         {
       
  2660         iCba->HandleResourceChange(aType);
       
  2661         }
       
  2662     if(iGrid && iGrid->ScrollBarFrame() && iGrid->ScrollBarFrame()->VerticalScrollBar())
       
  2663         {
       
  2664         iGrid->ScrollBarFrame()->VerticalScrollBar()->HandleResourceChange(aType);
       
  2665         }
       
  2666     if ( aType == KEikDynamicLayoutVariantSwitch )
       
  2667         {
       
  2668         SetRect( FastSwapWindowRect() );
       
  2669         }
       
  2670     _AKNTRACE_FUNC_EXIT;
       
  2671     }
       
  2672 
       
  2673 // ---------------------------------------------------------
       
  2674 // CAknFastSwapWindowControl::CreateItemArraysL
       
  2675 // During the creation of the grid the used item arrays
       
  2676 // are also created and set in to the grid. Arrays reserve 
       
  2677 // memory so that fsw can be quaranteed to work also in 
       
  2678 // low memory conditions.
       
  2679 // ---------------------------------------------------------
       
  2680 //
       
  2681 void CAknFastSwapWindowControl::CreateItemArraysL()
       
  2682     {
       
  2683     _AKNTRACE_FUNC_ENTER;
       
  2684     // fetch default application icon from the skin
       
  2685     UpdateDefaultAppIconL();
       
  2686     
       
  2687     // FSW reserves memory for icon and item arrays
       
  2688     iIconArray = new (ELeave) CArrayPtrFlat<CGulIcon>(KFSWArrayGranularity);
       
  2689     iItemTextArray = new (ELeave) CDesCArrayFlat(KFSWArrayGranularity);
       
  2690     iIconArray->SetReserveL( KMinimumSupportedApps );
       
  2691     TBuf<2*KMaxFileName+1> name;
       
  2692     for ( TInt count = 0; count < KMinimumSupportedApps; count ++)
       
  2693         {
       
  2694         iItemTextArray->AppendL( name );
       
  2695         }
       
  2696     iItemTextArray->Delete( NULL, iItemTextArray->Count() );  
       
  2697     // without setting this null the automatically created itemtextarray
       
  2698     // wont be freed
       
  2699     iGrid->Model()->SetItemTextArray( NULL );
       
  2700     // grid doesn't take ownership of the arrays
       
  2701     iGrid->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
  2702     // arrays are set into grid
       
  2703     iGrid->Model()->SetItemTextArray( iItemTextArray ); 
       
  2704     iGrid->ItemDrawer()->FormattedCellData()->SetIconArrayL( iIconArray );
       
  2705     _AKNTRACE_FUNC_EXIT;
       
  2706     }
       
  2707 
       
  2708 // ---------------------------------------------------------
       
  2709 // CAknFastSwapWindowControl::SetDefaultAppIconL
       
  2710 // Retrieves the default application icon from the skin,
       
  2711 // icon is to be used when there is no memory to reserve new icons
       
  2712 // ---------------------------------------------------------
       
  2713 //
       
  2714 void CAknFastSwapWindowControl::UpdateDefaultAppIconL()
       
  2715     {
       
  2716     _AKNTRACE_FUNC_ENTER;
       
  2717     CGulIcon* defaultAppIcon = NULL;
       
  2718     TRAPD( error,defaultAppIcon = AknsUtils::CreateGulIconL( 
       
  2719         AknsUtils::SkinInstance(),
       
  2720         KAknsIIDQgnMenuUnknownCxt,
       
  2721         AknIconUtils::AvkonIconFileName(),
       
  2722         EMbmAvkonQgn_menu_unknown_cxt,
       
  2723         EMbmAvkonQgn_menu_unknown_cxt_mask ) );
       
  2724     CleanupStack::PushL( defaultAppIcon );
       
  2725     if ( error != KErrNone )
       
  2726         {
       
  2727         if ( error == KErrNoMemory )
       
  2728             {
       
  2729             _AKNTRACE_FUNC_EXIT;
       
  2730             return;
       
  2731             }
       
  2732         else
       
  2733             {
       
  2734             User::LeaveIfError(error); 
       
  2735             }
       
  2736         }
       
  2737     User::LeaveIfError( AknIconUtils::SetSize( 
       
  2738         defaultAppIcon->Bitmap(),
       
  2739         IconSize() ) );
       
  2740     if ( iIconArray != NULL && iIconArray->Count() > 0)
       
  2741         {
       
  2742         for ( TInt i = 0; i < iIconArray->Count(); i++ )
       
  2743              {
       
  2744              if( iDefaultAppIcon == iIconArray->At(i) )
       
  2745                 {
       
  2746                 iIconArray->At(i) = defaultAppIcon;
       
  2747                 }
       
  2748              }
       
  2749         }
       
  2750     delete iDefaultAppIcon;
       
  2751     iDefaultAppIcon = defaultAppIcon;
       
  2752     CleanupStack::Pop(); // defaultAppIcon 
       
  2753     _AKNTRACE_FUNC_EXIT;
       
  2754     }
       
  2755 
       
  2756 // ---------------------------------------------------------
       
  2757 // CAknFastSwapWindowControl::ClearItemArrays
       
  2758 // The content is deleted from arrays and arrays can be compressed 
       
  2759 // to the reserved size KMinimumSupportedApps
       
  2760 //
       
  2761 // TBool aCompress states whether the arrays are are to be compressed or not
       
  2762 //
       
  2763 // ---------------------------------------------------------
       
  2764 //
       
  2765 void CAknFastSwapWindowControl::ClearItemArrays( TBool aCompress )
       
  2766     {
       
  2767     _AKNTRACE_FUNC_ENTER;
       
  2768     _AKNTRACE( "[%s] aCompress = %d", __FUNCTION__, aCompress );
       
  2769     // Old count is used comparison later when new items are added to array
       
  2770     // if handling of the item addition / removal is needed for the fsw grid
       
  2771     if ( !iIconArray ) 
       
  2772         {
       
  2773         _AKNTRACE_FUNC_EXIT;
       
  2774         return;
       
  2775         }
       
  2776     TInt currentlyReserved = iIconArray->Count();
       
  2777     if ( currentlyReserved > NULL ) 
       
  2778         {
       
  2779         // compression for arrays is done when the closefastswap is called
       
  2780         // when the fsw is updated while visible compression is not very wise
       
  2781         // since the item arrays are probably very close to the 
       
  2782         if ( aCompress ) 
       
  2783             {
       
  2784             // if there have been two many applications running lets 
       
  2785             // try to  compress the arrays to size of KMinimumSupportedApps
       
  2786             if ( iItemTextArray->Count() > KMinimumSupportedApps ) 
       
  2787                 {
       
  2788                 iItemTextArray->Delete(
       
  2789                     KMinimumSupportedApps, 
       
  2790                     iItemTextArray->Count() - KMinimumSupportedApps);
       
  2791                     
       
  2792                 iItemTextArray->Compress();
       
  2793                 }
       
  2794             // arrays are deleted separately, since there exists situations
       
  2795             // when memory allocation has failed and arrays have different 
       
  2796             // number of cells
       
  2797             if ( currentlyReserved > KMinimumSupportedApps )  
       
  2798                 {
       
  2799                 if ( iLowMemIcons ) 
       
  2800                     {
       
  2801                     // resizes to KMinimumSupportedApps, no dynamically loaded icons,
       
  2802                     // every pointer in the icon array points to the same default app icon 
       
  2803                     // (never deleted)
       
  2804                     iIconArray->Delete( 
       
  2805                         KMinimumSupportedApps, 
       
  2806                         currentlyReserved - KMinimumSupportedApps );
       
  2807                     }
       
  2808                 else
       
  2809                     {
       
  2810                     // deletes dynamically loaded icons
       
  2811                     DeleteIcons( 
       
  2812                         KMinimumSupportedApps, 
       
  2813                         currentlyReserved - KMinimumSupportedApps );
       
  2814                     }
       
  2815                 // compresses the array to max KMinimumSupportedApps
       
  2816                 iIconArray->Compress();
       
  2817                 TRAP_IGNORE( iGrid->HandleItemRemovalL() ); 
       
  2818                 }
       
  2819             }
       
  2820             
       
  2821         // if arrays are emptified, fsw needs information 
       
  2822         // how many apps were in the grid before the operation   
       
  2823         iOldCount = iGrid->Model()->ItemTextArray()->MdcaCount();
       
  2824         
       
  2825         // the deletion doesn't free the memory reserved for the array,
       
  2826         // but it emptifies the text array
       
  2827         iItemTextArray->Delete( NULL, iItemTextArray->Count() );
       
  2828     
       
  2829         // if the memory was too low 
       
  2830         // on the previously run, different icon array 
       
  2831         // was used, and also needs to be freed differentely
       
  2832         if ( iLowMemIcons ) 
       
  2833             {
       
  2834             // resizing doesn't free the memory
       
  2835             // array or the used icon reserved
       
  2836             //
       
  2837             // below resize can leave when array is enlarged,
       
  2838             // but in this case size always shrunk to NULL
       
  2839             TRAP_IGNORE( iIconArray->Delete( NULL, iIconArray->Count() ) );
       
  2840             iLowMemIcons = EFalse;
       
  2841             }
       
  2842         else 
       
  2843             {
       
  2844             // icons inside array are deleted from the memory, 
       
  2845             // but the deletion doesn't free the memory 
       
  2846             // reserved for the pointer array
       
  2847             DeleteIcons( NULL, iIconArray->Count() );
       
  2848             }
       
  2849         }
       
  2850     _AKNTRACE_FUNC_EXIT;
       
  2851     }
       
  2852 
       
  2853 // ---------------------------------------------------------
       
  2854 // CAknFastSwapWindowControl::IconSize
       
  2855 // Calculates and returns the icon size used in the fast swap list.
       
  2856 // ---------------------------------------------------------
       
  2857 //      
       
  2858 TSize CAknFastSwapWindowControl::IconSize()
       
  2859     {
       
  2860     _AKNTRACE_FUNC_ENTER;
       
  2861     TRect appWindow;
       
  2862     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EApplicationWindow, appWindow );
       
  2863     TAknLayoutRect rect;
       
  2864     
       
  2865     rect.LayoutRect( 
       
  2866         FastSwapWindowRect(), 
       
  2867         AknLayoutScalable_Avkon::aid_size_cell_fast2().LayoutLine());
       
  2868 
       
  2869     _AKNTRACE_FUNC_EXIT;
       
  2870     return rect.Rect().Size();
       
  2871     }
       
  2872 
       
  2873 // ---------------------------------------------------------
       
  2874 // CAknFastSwapWindowControl::DeleteIcons
       
  2875 // Clears given array slots of dynamically loaded icons
       
  2876 // ---------------------------------------------------------
       
  2877 //
       
  2878 void CAknFastSwapWindowControl::DeleteIcons( TInt aIndex, TInt aCount )
       
  2879     {
       
  2880     _AKNTRACE_FUNC_ENTER;
       
  2881     _AKNTRACE( "[%s] aIndex = %d aCount = %d", __FUNCTION__, aIndex, aCount );
       
  2882     for ( TInt i = 0; i < aCount; i++ ) 
       
  2883         {
       
  2884         if(iDefaultAppIcon != iIconArray->At( aIndex + i ))
       
  2885             {
       
  2886                 delete iIconArray->At( aIndex + i );
       
  2887             }
       
  2888         }
       
  2889     iIconArray->Delete( aIndex, aCount ); 
       
  2890     _AKNTRACE_FUNC_EXIT;
       
  2891     }
       
  2892 
       
  2893 // ---------------------------------------------------------
       
  2894 // CAknFastSwapWindowControl::NumberOfVisibleRows
       
  2895 // How many visible rows are shown in the fast swap grid
       
  2896 // ---------------------------------------------------------
       
  2897 //
       
  2898 TInt CAknFastSwapWindowControl::NumberOfVisibleRows()
       
  2899     {
       
  2900     _AKNTRACE_FUNC_ENTER;
       
  2901     TAknLayoutScalableParameterLimits cellLimits = AknLayoutScalable_Avkon::cell_fast2_pane_ParamLimits();
       
  2902     TInt numberOfGridColumns = cellLimits.LastColumn() + 1;
       
  2903     TInt numberOfGridRows = cellLimits.LastRow() + 1;
       
  2904     
       
  2905     TInt numberOfRows = ( iNumberOfWGs - 1 ) / numberOfGridColumns + 1;
       
  2906     if ( numberOfRows <= numberOfGridRows )
       
  2907         {
       
  2908         _AKNTRACE_FUNC_EXIT;
       
  2909         return numberOfRows;
       
  2910         }
       
  2911     else 
       
  2912         {
       
  2913         _AKNTRACE_FUNC_EXIT;
       
  2914         return numberOfGridRows;
       
  2915         }
       
  2916     }
       
  2917 
       
  2918 // ---------------------------------------------------------
       
  2919 // CAknFastSwapWindowControl::CurrentAppName
       
  2920 // Gives the name of the application with current highlight
       
  2921 // ---------------------------------------------------------
       
  2922 //
       
  2923 TPtrC CAknFastSwapWindowControl::CurrentAppName()
       
  2924     {
       
  2925     _AKNTRACE_FUNC_ENTER;
       
  2926     TPtrC name = iGrid->Model()->ItemText( iGrid->CurrentDataIndex() );
       
  2927     name.Set( name.Mid( name.Find(KTab)+1) );
       
  2928     _AKNTRACE_FUNC_EXIT;
       
  2929     return name;
       
  2930     }        
       
  2931 
       
  2932 // ----------------------------------------------------------------------------
       
  2933 // CAknFastSwapperWindowControl::CreateStylusPopupMenu
       
  2934 // ----------------------------------------------------------------------------
       
  2935 // 
       
  2936 void CAknFastSwapWindowControl::CreateStylusPopupMenuL()
       
  2937     {
       
  2938     _AKNTRACE_FUNC_ENTER;
       
  2939     if ( !iPopupMenu )
       
  2940         {
       
  2941         iPopupMenu = CAknStylusPopUpMenu::NewL( this, Rect().iTl );
       
  2942         HBufC* openText = StringLoader::LoadLC( R_QTN_FSW_STYLUSPOPUPMENU_OPEN );
       
  2943         HBufC* exitText = StringLoader::LoadLC( R_QTN_FSW_STYLUSPOPUPMENU_EXIT );
       
  2944         iPopupMenu->AddMenuItemL( *openText, EAknCapServerCmdOpen );    
       
  2945         iPopupMenu->AddMenuItemL( *exitText, EAknCapServerCmdClose );  
       
  2946         CleanupStack::PopAndDestroy( exitText );
       
  2947         CleanupStack::PopAndDestroy( openText );
       
  2948         }
       
  2949     _AKNTRACE_FUNC_EXIT;
       
  2950     }
       
  2951 
       
  2952 // ----------------------------------------------------------------------------
       
  2953 // CAknFastSwapperWindowControl::ShowPopupMenuL
       
  2954 // ----------------------------------------------------------------------------
       
  2955 //    
       
  2956 void CAknFastSwapWindowControl::ShowPopupMenuL() 
       
  2957     {
       
  2958     _AKNTRACE_FUNC_ENTER; 
       
  2959     if ( !iPopupMenu )
       
  2960         {
       
  2961         CreateStylusPopupMenuL();    
       
  2962         }
       
  2963     
       
  2964     if( iIsStylusPopupShow )
       
  2965         {
       
  2966         _AKNTRACE_FUNC_EXIT;
       
  2967         return;
       
  2968         }
       
  2969     iIsStylusPopupShow = ETrue;
       
  2970 
       
  2971     iTooltipModeTouch = EFalse;
       
  2972     SetPointerCapture( EFalse );
       
  2973     RWindowGroup& rootWin = iCoeEnv->RootWin();
       
  2974        
       
  2975     TInt index = iGrid->CurrentDataIndex();
       
  2976     index = index < 0 ? 0 : index;
       
  2977    
       
  2978     if ((*iShownWgIds)[index].iIsSystemApp)
       
  2979         {            
       
  2980         iPopupMenu->SetItemDimmed( EAknCapServerCmdClose, ETrue );
       
  2981         }
       
  2982     else
       
  2983         {
       
  2984         iPopupMenu->SetItemDimmed( EAknCapServerCmdClose, EFalse );   
       
  2985         }
       
  2986     iTooltip->HideInfoPopupNote();     
       
  2987     TPoint pos = PositionRelativeToScreen();
       
  2988     TInt itemIndex = iGrid->CurrentItemIndex();
       
  2989     itemIndex = itemIndex < 0 ? 0 : itemIndex;
       
  2990     TPoint posItem = iGrid->View()->ItemPos( itemIndex );
       
  2991     if( posItem.iY < iGrid->View()->ViewRect().iTl.iY )
       
  2992        {
       
  2993        posItem.iY = iGrid->View()->ViewRect().iTl.iY;
       
  2994        }
       
  2995     pos.iY += posItem.iY;
       
  2996     pos.iX += posItem.iX;
       
  2997 
       
  2998     if ( AknLayoutUtils::LayoutMirrored() )
       
  2999         {
       
  3000         TInt itemWidth = iGrid->View()->ItemSize( itemIndex ).iWidth;    
       
  3001         pos.iX += itemWidth;
       
  3002         }
       
  3003     iPopupMenu->SetPosition( pos, CAknStylusPopUpMenu::EPositionTypeLeftBottom );
       
  3004     
       
  3005     MTouchFeedback* feedback = MTouchFeedback::Instance();
       
  3006     if ( feedback )
       
  3007         {
       
  3008         // feedback on menu opening
       
  3009         feedback->InstantFeedback( ETouchFeedbackPopUp );
       
  3010         }
       
  3011     iPopupMenu->ShowMenu();
       
  3012     _AKNTRACE_FUNC_EXIT;
       
  3013     }
       
  3014 
       
  3015 // ----------------------------------------------------------------------------
       
  3016 // CAknFastSwapperWindowControl::TryCloseApplicationL
       
  3017 // ----------------------------------------------------------------------------
       
  3018 //    
       
  3019 void CAknFastSwapWindowControl::TryCloseApplicationL( TInt aIndex, TBool aIsShift )
       
  3020     {
       
  3021     _AKNTRACE_FUNC_ENTER;
       
  3022     _AKNTRACE( "[%s] aIndex = %d aIsShift = %d", __FUNCTION__, aIndex, aIsShift );
       
  3023     if ( aIndex == KErrNotFound || (*iShownWgIds)[aIndex].iIsSystemApp)
       
  3024         {    
       
  3025         _AKNTRACE_FUNC_EXIT;
       
  3026         return;
       
  3027         }
       
  3028 
       
  3029     iConfirmCloseWgId = (*iShownWgIds)[aIndex].iWgId;
       
  3030 
       
  3031     // if this leaves, okToClose will be left as ETrue
       
  3032     iTooltip->HideInfoPopupNote();
       
  3033 
       
  3034     iIsClosing = ETrue;
       
  3035     
       
  3036     if (iWidgetsSupported && iWidgetList->IsWidget( iConfirmCloseWgId ))
       
  3037         {
       
  3038         TWsEvent event;
       
  3039         event.SetType(EEventUser);
       
  3040             
       
  3041         TUid widgetUid = iWidgetList->IndexToAppUid(aIndex, iAlwaysShownList->iAppList->Count());
       
  3042 
       
  3043         TInt32 widgetAppUiUidInt = KWidgetAppUid.iUid;
       
  3044         TInt32 widgetUidInt = widgetUid.iUid;
       
  3045         TUint8* eventData = event.EventData();
       
  3046         // Fill bits 0-31 with widget application Uid.
       
  3047         (TUint32&)*eventData = widgetAppUiUidInt;
       
  3048         eventData+=sizeof(TUint32);
       
  3049         // Fill bits 32-63 with uid of the widget that should be closed.
       
  3050         (TUint32&)*eventData = widgetUidInt;
       
  3051         // Send the event to Widget AppUi.
       
  3052         iEikonEnv->WsSession().SendEventToWindowGroup(iWidgetAppUiWgId, event);
       
  3053         }
       
  3054     else if ( aIsShift )
       
  3055         {
       
  3056         TApaTask task( iEikonEnv->WsSession() );
       
  3057         task.SetWgId( iConfirmCloseWgId );
       
  3058         task.SendSystemEvent( EApaSystemEventShutdown);
       
  3059         }
       
  3060     else
       
  3061         {
       
  3062         TWsEvent event;
       
  3063         event.SetTimeNow();
       
  3064         event.SetType(KAknShutOrHideApp); 
       
  3065         iEikonEnv->WsSession().SendEventToWindowGroup(iConfirmCloseWgId, event);
       
  3066         }
       
  3067 
       
  3068     _AKNTRACE_FUNC_EXIT;
       
  3069     }
       
  3070     
       
  3071 // ----------------------------------------------------------------------------
       
  3072 // CAknFastSwapperWindowControl::SetEmphasis
       
  3073 // ----------------------------------------------------------------------------
       
  3074 //    
       
  3075 void CAknFastSwapWindowControl::SetEmphasis(CCoeControl* /* aMenuControl */,TBool /* aEmphasis */)
       
  3076     {
       
  3077     
       
  3078     }
       
  3079     
       
  3080 // ----------------------------------------------------------------------------
       
  3081 // CAknFastSwapperWindowControl::SetHiddenFlag
       
  3082 // ----------------------------------------------------------------------------
       
  3083 //    
       
  3084 void CAknFastSwapWindowControl::SetHiddenFlag()
       
  3085     {
       
  3086     _AKNTRACE_FUNC_ENTER;
       
  3087     if ( iIsStylusPopupShow )
       
  3088         {
       
  3089         SetPointerCapture( ETrue );
       
  3090         iIsStylusPopupShow = EFalse;    
       
  3091         }
       
  3092     _AKNTRACE_FUNC_EXIT;
       
  3093     }
       
  3094     
       
  3095 // ----------------------------------------------------------------------------
       
  3096 // CAknFastSwapperWindowControl::PointerEventL
       
  3097 // ----------------------------------------------------------------------------
       
  3098 //      
       
  3099 void CAknFastSwapWindowControl::PointerEventL( const TPointerEvent& aEvent )
       
  3100     {
       
  3101     _AKNTRACE_FUNC_ENTER;
       
  3102     _AKNTRACE( "[%s] event type = %d", __FUNCTION__, aEvent.iType );
       
  3103     if ( ( iState == EShowingAnimation ||  iState == EWaitingForAnimation ) && 
       
  3104            aEvent.iType == TPointerEvent::EDrag )
       
  3105         {
       
  3106         // Test whether the pointer event is filtered.
       
  3107         TInt offset = AknLayoutScalable_Avkon::aid_value_unit2().LayoutLine().iW * 2 / 5;
       
  3108         TRect dragMaxRect( iAnimationPosition.iX - offset, iAnimationPosition.iY - offset,
       
  3109                            iAnimationPosition.iX + offset, iAnimationPosition.iY + offset );   
       
  3110         if ( dragMaxRect.Contains( aEvent.iParentPosition ) )
       
  3111             {
       
  3112             _AKNTRACE_FUNC_EXIT;
       
  3113             return;  
       
  3114             }
       
  3115         }
       
  3116 
       
  3117     // Whatever happens, cancel the timer and stop animation.
       
  3118     iTimeOut->Cancel();
       
  3119     StopAnimation();
       
  3120     iState = EWaiting;
       
  3121     iAnimationPosition = aEvent.iParentPosition;
       
  3122     
       
  3123     if ( iIsStylusPopupShow )
       
  3124         {
       
  3125         _AKNTRACE_FUNC_EXIT;
       
  3126         // Do not start animation when the stylus popup menu is displayed.  
       
  3127         return;    
       
  3128         }
       
  3129        
       
  3130     if ( aEvent.iType == TPointerEvent::EButton1Down ) 
       
  3131         {
       
  3132         TInt touchedIndex = KErrNotFound;
       
  3133         TBool isOverItem =
       
  3134                             iGrid->GridView()->XYPosToItemIndex( aEvent.iPosition,
       
  3135                             		                             touchedIndex);
       
  3136         if( isOverItem && touchedIndex != iGrid->CurrentItemIndex())
       
  3137            {
       
  3138            iGrid->View()->ItemDrawer()->SetFlags( CListItemDrawer::EPressedDownState );
       
  3139            touchedIndex = iGrid->GridView()->ActualDataIndex( touchedIndex );
       
  3140            iGrid->SetCurrentDataIndex(touchedIndex);
       
  3141            iGrid->DrawDeferred();       	
       
  3142            }
       
  3143         ShowTooltipTouchL( ETrue );
       
  3144         iState = EWaitingForAnimation;
       
  3145         iTimeOut->Start(
       
  3146             KTimeDelayBeforeAnimation, 
       
  3147             KTimeNeverHappenEvent,
       
  3148             TCallBack( TimeOutCallBackL, this ) );
       
  3149         }
       
  3150     _AKNTRACE_FUNC_EXIT;
       
  3151     }
       
  3152     
       
  3153 // ----------------------------------------------------------------------------
       
  3154 // CAknFastSwapperWindowControl::ToolTipTimeOutCallBackL
       
  3155 // ----------------------------------------------------------------------------
       
  3156 //    
       
  3157 TInt CAknFastSwapWindowControl::ToolTipTimeOutCallBackL( TAny* aPtr )  
       
  3158     {
       
  3159     (STATIC_CAST(CAknFastSwapWindowControl*,aPtr))->HideTooltip();
       
  3160     return KErrNone ;      
       
  3161     }
       
  3162     
       
  3163 // ----------------------------------------------------------------------------
       
  3164 // CAknFastSwapperWindowControl::HideTooltip
       
  3165 // ----------------------------------------------------------------------------
       
  3166 //     
       
  3167 void CAknFastSwapWindowControl::HideTooltip()
       
  3168     {
       
  3169     iToolTipTimer->Cancel();
       
  3170     iTooltip->HideInfoPopupNote();     
       
  3171     }
       
  3172     
       
  3173 // ----------------------------------------------------------------------------
       
  3174 // CAknFastSwapperWindowControl::TimeOutCallBackL
       
  3175 // ----------------------------------------------------------------------------
       
  3176 //     
       
  3177 TInt CAknFastSwapWindowControl::TimeOutCallBackL( TAny* aPtr )
       
  3178     {
       
  3179     (STATIC_CAST(CAknFastSwapWindowControl*,aPtr))->ShowAnimationL(); 
       
  3180     return KErrNone ;   
       
  3181     }
       
  3182 
       
  3183 
       
  3184 // ---------------------------------------------------------------------------
       
  3185 // Handles the state changes in the long tap animation.
       
  3186 // ---------------------------------------------------------------------------
       
  3187 //      
       
  3188 void CAknFastSwapWindowControl::ShowAnimationL()
       
  3189     {
       
  3190     _AKNTRACE_FUNC_ENTER;
       
  3191     if ( AknLayoutUtils::PenEnabled() )
       
  3192         {
       
  3193         switch ( iState )
       
  3194             {
       
  3195             case EWaitingForAnimation:
       
  3196                 {
       
  3197                 iState = EShowingAnimation;
       
  3198                 iTimeOut->Cancel();
       
  3199                 StartAnimationL();
       
  3200 
       
  3201                 iTimeOut->Start( KLongTapDelay - KTimeDelayBeforeAnimation, 
       
  3202                                  KTimeNeverHappenEvent,
       
  3203                                  TCallBack( TimeOutCallBackL, this ) );
       
  3204                 break;
       
  3205                 }
       
  3206 
       
  3207             case EShowingAnimation:
       
  3208             case EShowingPressedDownEffect:
       
  3209                 {
       
  3210                 iState = EShowingPressedDownEffect;
       
  3211                 iTimeOut->Cancel();
       
  3212                 StopAnimation();
       
  3213                 ShowPopupMenuL();
       
  3214                 iGrid->View()->ItemDrawer()->ClearFlags( CListItemDrawer::EPressedDownState ); 
       
  3215                 iState = EWaiting;
       
  3216                 break;
       
  3217                 }
       
  3218 
       
  3219             default:
       
  3220                 {
       
  3221                 break;
       
  3222                 }
       
  3223             }
       
  3224         }
       
  3225     _AKNTRACE_FUNC_EXIT;
       
  3226     }
       
  3227 
       
  3228 // ----------------------------------------------------------------------------
       
  3229 // CAknFastSwapperWindowControl::StartAnimationL
       
  3230 // ----------------------------------------------------------------------------
       
  3231 //      
       
  3232 void CAknFastSwapWindowControl::StartAnimationL()
       
  3233     { 
       
  3234     iIsAnimationShowing = ETrue;
       
  3235     iLongTapAnimation->ShowAnimationL( iAnimationPosition.iX,
       
  3236                                        iAnimationPosition.iY );
       
  3237     }
       
  3238 
       
  3239 // ----------------------------------------------------------------------------
       
  3240 // CAknFastSwapperWindowControl::StopAnimationL
       
  3241 // ----------------------------------------------------------------------------
       
  3242 //     
       
  3243 void CAknFastSwapWindowControl::StopAnimation()
       
  3244     {
       
  3245     if ( iLongTapAnimation )
       
  3246         {
       
  3247         if ( iIsAnimationShowing )
       
  3248             {
       
  3249             iIsAnimationShowing = EFalse;    
       
  3250             iLongTapAnimation->HideAnimation();
       
  3251             }
       
  3252         }        
       
  3253     }
       
  3254     
       
  3255 // ---------------------------------------------------------------------------
       
  3256 // CAknFastSwapperWindowControl::CancelAnimationAndPressDownEffect
       
  3257 // ---------------------------------------------------------------------------
       
  3258 //
       
  3259 void CAknFastSwapWindowControl::CancelAnimationAndPressDownEffect()
       
  3260     {
       
  3261     _AKNTRACE_FUNC_ENTER;
       
  3262     iTimeOut->Cancel();
       
  3263     StopAnimation();
       
  3264     iState = EWaiting;
       
  3265 
       
  3266     iItemDraggingActioned = ETrue;
       
  3267 
       
  3268     CListItemDrawer* itemDrawer = iGrid->View()->ItemDrawer();
       
  3269 
       
  3270     if ( itemDrawer->Flags() & CListItemDrawer::EPressedDownState )
       
  3271         {
       
  3272         // Clear the pressed down state from the drawer and draw the
       
  3273         // the normal highlight on the highlighter item.
       
  3274         iGrid->View()->ItemDrawer()->ClearFlags( CListItemDrawer::EPressedDownState ); 
       
  3275         iGrid->DrawItem( iGrid->CurrentItemIndex() );
       
  3276         }
       
  3277      _AKNTRACE_FUNC_EXIT;
       
  3278     }
       
  3279 
       
  3280 //  End of File