taskswitcher/taskswitcherui/taskswitcherapp/src/tsfastswaparea.cpp
branchRCL_3
changeset 35 3321d3e205b6
parent 34 5456b4e8b3a8
equal deleted inserted replaced
34:5456b4e8b3a8 35:3321d3e205b6
    26 #include <StringLoader.h>
    26 #include <StringLoader.h>
    27 #include <taskswitcher.rsg>
    27 #include <taskswitcher.rsg>
    28 #include <aknlayoutscalable_apps.cdl.h>
    28 #include <aknlayoutscalable_apps.cdl.h>
    29 #include <layoutmetadata.cdl.h>
    29 #include <layoutmetadata.cdl.h>
    30 #include <aknlists.h>
    30 #include <aknlists.h>
    31 #include <touchfeedback.h>
       
    32 #include <akntransitionutils.h>
       
    33 #include <akntranseffect.h>
       
    34 #include <aknlongtapanimation.h>
    31 #include <aknlongtapanimation.h>
       
    32 #include <aknpointereventsuppressor.h>
    35 
    33 
    36 #include "tsfastswaparea.h"
    34 #include "tsfastswaparea.h"
       
    35 #include "tsfastswapareautils.h"
    37 #include "tsapplogging.h"
    36 #include "tsapplogging.h"
    38 #include "tsfswclient.h"
    37 #include "tsfswclient.h"
    39 #include "tsappui.h"
    38 #include "tsappui.h"
    40 #include "tsdatachangeobserver.h"
    39 #include "tsdatachangeobserver.h"
    41 #include "tseventcontroler.h"
    40 #include "tseventcontroler.h"
    56 
    55 
    57 const TInt KAppKeyTypeShort = 1;
    56 const TInt KAppKeyTypeShort = 1;
    58 const TInt KAppKeyTypeLong = 2;
    57 const TInt KAppKeyTypeLong = 2;
    59 
    58 
    60 const TInt KLayoutItemCount = 4;
    59 const TInt KLayoutItemCount = 4;
       
    60 const TInt KLayoutItemGap = 0;
    61 
    61 
    62 const TInt KRedrawTime = 250000; // 0.25 sec
    62 const TInt KRedrawTime = 250000; // 0.25 sec
    63 const TInt KRedrawTimeForLayoutSwitch = 700000; // 0.7 sec
    63 const TInt KRedrawTimeForLayoutSwitch = 700000; // 0.7 sec
    64 const TInt KHighlighActivationTime = 100000; // 100 ms
    64 const TInt KHighlighActivationTime = 100000; // 100 ms
    65 const TInt KUpdateGridTime = 0; // imediately
    65 const TInt KUpdateGridTime = 0; // imediately
    66 const TInt KOrientationSwitchTime = 1000000; // 1 sec
    66 const TInt KOrientationSwitchTime = 1000000; // 1 sec
    67 const TInt KLongTapAnimationInitTime = 150000; // 0.15 sec
    67 const TInt KLongTapAnimationInitTime = 150000; // 0.15 sec
    68 const TInt KLongTapAnimationTimeout = 1000000; // 1 sec
    68 const TInt KLongTapAnimationTimeout = 1000000; // 1 sec
       
    69 const TInt KPointerEventSuppressorMaxTapDuration = 400000;	// 0.4 sec
       
    70 const TInt KPointerEventSuppressorMaxTapMoveWidth = 3;
       
    71 const TInt KPointerEventSuppressorMaxTapMoveHeight = 8;
    69 
    72 
    70 const TInt KMaxGranularity = 4;
    73 const TInt KMaxGranularity = 4;
    71 
    74 
    72 const TUid KTsMenuUid = { 0x101f4cd2 };
    75 const TUid KTsMenuUid = { 0x101f4cd2 };
    73 const TUid KTsHomescreenUid = { 0x102750f0 };
    76 const TUid KTsHomescreenUid = { 0x102750f0 };
       
    77 
       
    78 
    74 
    79 
    75 // -----------------------------------------------------------------------------
    80 // -----------------------------------------------------------------------------
    76 // CTsFastSwapArea::NewL
    81 // CTsFastSwapArea::NewL
    77 // -----------------------------------------------------------------------------
    82 // -----------------------------------------------------------------------------
    78 //
    83 //
   107 //
   112 //
   108 CTsFastSwapArea::CTsFastSwapArea(CCoeControl& aParent,
   113 CTsFastSwapArea::CTsFastSwapArea(CCoeControl& aParent,
   109     CTsDeviceState& aDeviceState,
   114     CTsDeviceState& aDeviceState,
   110     CTsEventControler& aEventHandler) :
   115     CTsEventControler& aEventHandler) :
   111     iParent(aParent), iDeviceState(aDeviceState), iEvtHandler(aEventHandler),
   116     iParent(aParent), iDeviceState(aDeviceState), iEvtHandler(aEventHandler),
   112     iIgnoreLayoutSwitch(EFalse), iWidgetClosingCount(0), iLongTapAnimationRunning(EFalse)
   117     iGridItemGap(KLayoutItemGap), iIgnoreLayoutSwitch(EFalse), 
       
   118     iSupressDrag(EFalse),iWidgetClosingCount(0),
       
   119     iLongTapAnimationRunning(EFalse)
   113     {
   120     {
   114     // no implementation required
   121     // no implementation required
   115     }
   122     }
   116 
   123 
   117 // -----------------------------------------------------------------------------
   124 // -----------------------------------------------------------------------------
   129     delete iRedrawTimer;
   136     delete iRedrawTimer;
   130     delete iUpdateGridTimer;
   137     delete iUpdateGridTimer;
   131     delete iOrientationSignalTimer;
   138     delete iOrientationSignalTimer;
   132     delete iLongTapAnimation;
   139     delete iLongTapAnimation;
   133     delete iLongTapAnimationTimer;
   140     delete iLongTapAnimationTimer;
       
   141     delete iFastSwapExt;
       
   142     iPrevScreenshots.Close();
       
   143     delete iEventSupressor;
   134     }
   144     }
   135 
   145 
   136 // -----------------------------------------------------------------------------
   146 // -----------------------------------------------------------------------------
   137 // CTsFastSwapArea::ConstructL
   147 // CTsFastSwapArea::ConstructL
   138 // -----------------------------------------------------------------------------
   148 // -----------------------------------------------------------------------------
   141     {
   151     {
   142     SetContainerWindowL( iParent );
   152     SetContainerWindowL( iParent );
   143 
   153 
   144     SetRect( aRect );
   154     SetRect( aRect );
   145 
   155 
       
   156     // Create utility class
       
   157     iFastSwapExt = CTsFastSwapAreaExtension::NewL( *this, *iEikonEnv );
       
   158     
   146     // setup grid
   159     // setup grid
   147     ReCreateGridL();
   160     ReCreateGridL();
   148 
   161 
   149     // create stylus popup instance
   162     // create stylus popup instance
   150     PreCreatePopupL();
   163     PreCreatePopupL();
   172     iLongTapAnimationTimer = new (ELeave) CTsFastSwapTimer( *this ); 
   185     iLongTapAnimationTimer = new (ELeave) CTsFastSwapTimer( *this ); 
   173     iLongTapAnimationTimer->ConstructL();
   186     iLongTapAnimationTimer->ConstructL();
   174     
   187     
   175     iActivateOnPointerRelease = TPoint();
   188     iActivateOnPointerRelease = TPoint();
   176     iHandlePointerCandidate = EFalse;
   189     iHandlePointerCandidate = EFalse;
       
   190     
       
   191     iEventSupressor = CAknPointerEventSuppressor::NewL();
       
   192     TSize maxTapMove(KPointerEventSuppressorMaxTapMoveWidth, 
       
   193                      KPointerEventSuppressorMaxTapMoveHeight );
       
   194     iEventSupressor->SetMaxTapMove(maxTapMove);
       
   195     iEventSupressor->SetMaxTapDuration(KPointerEventSuppressorMaxTapDuration);
   177     
   196     
   178     ActivateL();
   197     ActivateL();
   179     }
   198     }
   180 
   199 
   181 // -----------------------------------------------------------------------------
   200 // -----------------------------------------------------------------------------
   239 // CTsFastSwapArea::LayoutGridL
   258 // CTsFastSwapArea::LayoutGridL
   240 // --------------------------------------------------------------------------
   259 // --------------------------------------------------------------------------
   241 //
   260 //
   242 void CTsFastSwapArea::LayoutGridL()
   261 void CTsFastSwapArea::LayoutGridL()
   243     {
   262     {
       
   263     TSLOG_CONTEXT( CTsFastSwapArea::LayoutGridL, TSLOG_LOCAL );
       
   264     TSLOG_IN();
       
   265     
   244     RArray<TAknLayoutRect> rects;
   266     RArray<TAknLayoutRect> rects;
   245     CleanupClosePushL(rects);
   267     CleanupClosePushL(rects);
   246     rects.ReserveL(KLayoutItemCount);
   268     rects.ReserveL(KLayoutItemCount);
   247     GetFastSwapAreaRects(rects);
   269     iFastSwapExt->GetFastSwapAreaRects(rects);
   248     TAknLayoutRect gridAppPane = rects[0];
   270     TAknLayoutRect gridAppPane = rects[0];
   249     TAknLayoutRect gridItem = rects[1];
   271     TAknLayoutRect gridItem = rects[1];
   250     TAknLayoutRect gridImage = rects[2];
   272     TAknLayoutRect gridImage = rects[2];
   251     TAknLayoutRect gridNextItem = rects[3];
   273 
   252     CleanupStack::PopAndDestroy(&rects);
   274     CleanupStack::PopAndDestroy(&rects);
   253     
   275     
   254     iGrid->SetRect(gridAppPane.Rect());
   276     iGrid->SetRect(gridAppPane.Rect());
   255     
   277     
       
   278     CTsAppUi* appUi = static_cast<CTsAppUi*>(iEikonEnv->AppUi());
       
   279     
   256     TInt variety;
   280     TInt variety;
   257     TBool disable = GetVariety(variety);
   281     TBool disable = iFastSwapExt->GetVariety(variety);
   258     if ( disable )
   282     if ( disable )
   259         {
   283         {
   260         TRAP_IGNORE(static_cast<CTsAppUi*>(iEikonEnv->AppUi())->RequestPopUpL());
   284         TRAP_IGNORE(appUi->RequestPopUpL());
   261         }
   285         }
   262     variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0; // double check to avoid layout panic
   286     variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0; // double check to avoid layout panic
       
   287     TSLOG1( TSLOG_INFO, "variety %d", variety );
   263     
   288     
   264     TAknLayoutScalableParameterLimits gridParams = 
   289     TAknLayoutScalableParameterLimits gridParams = 
   265         AknLayoutScalable_Apps::cell_tport_appsw_pane_ParamLimits( variety );
   290         AknLayoutScalable_Apps::cell_tport_appsw_pane_ParamLimits( variety );
   266     TPoint empty( ELayoutEmpty, ELayoutEmpty );
   291     TPoint empty( ELayoutEmpty, ELayoutEmpty );
   267     
   292     
   288     colors.iHighlightedText = highlightTextColor;
   313     colors.iHighlightedText = highlightTextColor;
   289     colors.iHighlightedBack = iGrid->ItemDrawer()->HighlightedBackColor();
   314     colors.iHighlightedBack = iGrid->ItemDrawer()->HighlightedBackColor();
   290     iGrid->ItemDrawer()->FormattedCellData()->SetSubCellColorsL(1, colors);
   315     iGrid->ItemDrawer()->FormattedCellData()->SetSubCellColorsL(1, colors);
   291     iGrid->SetStrokeColors(textColor, highlightTextColor);
   316     iGrid->SetStrokeColors(textColor, highlightTextColor);
   292     
   317     
   293     if ( AknLayoutUtils::LayoutMirrored() )
       
   294         {
       
   295         iGridItemGap = gridItem.Rect().iTl.iX - gridNextItem.Rect().iBr.iX;
       
   296         }
       
   297     else
       
   298         {
       
   299         iGridItemGap = gridNextItem.Rect().iTl.iX - gridItem.Rect().iBr.iX;
       
   300         }
       
   301     iMaxItemsOnScreen = Rect().Width() / gridItem.Rect().Width();
   318     iMaxItemsOnScreen = Rect().Width() / gridItem.Rect().Width();
   302     if ( iMaxItemsOnScreen > 1 )
   319     if ( iMaxItemsOnScreen > 1 )
   303         {
   320         {
   304         TInt widthWithGaps =
   321         TInt widthWithGaps =
   305             (iMaxItemsOnScreen - 1) * iGridItemGap + iMaxItemsOnScreen * gridItem.Rect().Width();
   322             (iMaxItemsOnScreen - 1) * iGridItemGap + iMaxItemsOnScreen * gridItem.Rect().Width();
   307             {
   324             {
   308             iMaxItemsOnScreen--;
   325             iMaxItemsOnScreen--;
   309             }
   326             }
   310         }
   327         }
   311     iGridItemWidth = gridItem.Rect().Width();
   328     iGridItemWidth = gridItem.Rect().Width();
   312     
       
   313     // Update item drawer
   329     // Update item drawer
   314     iGrid->UpdateItemDrawerLayoutDataL();
   330     iGrid->UpdateItemDrawerLayoutDataL();
   315     
   331     
   316     // Update state
   332     // Update state
   317     HandleDeviceStateChanged( EDeviceType );
   333     HandleDeviceStateChanged( EDeviceType );
   318     
   334     
   319     if ( disable )
   335     if ( disable )
   320         {
   336         {
   321         TRAP_IGNORE(static_cast<CTsAppUi*>(iEikonEnv->AppUi())->DisablePopUpL());
   337         TRAP_IGNORE(appUi->DisablePopUpL());
   322         }
   338         }
       
   339     
       
   340     TSLOG_OUT();
   323     }
   341     }
   324 
   342 
   325 
   343 
   326 // --------------------------------------------------------------------------
   344 // --------------------------------------------------------------------------
   327 // CTsFastSwapArea::LayoutGridView
   345 // CTsFastSwapArea::LayoutGridView
   330 void CTsFastSwapArea::LayoutGridViewL( TInt aItemCount )
   348 void CTsFastSwapArea::LayoutGridViewL( TInt aItemCount )
   331     {
   349     {
   332     RArray<TAknLayoutRect> rects;
   350     RArray<TAknLayoutRect> rects;
   333     CleanupClosePushL(rects);
   351     CleanupClosePushL(rects);
   334     rects.ReserveL(KLayoutItemCount);
   352     rects.ReserveL(KLayoutItemCount);
   335     GetFastSwapAreaRects(rects);
   353     iFastSwapExt->GetFastSwapAreaRects(rects);
   336     TAknLayoutRect gridItem = rects[1];
   354     TAknLayoutRect gridItem = rects[1];
   337     CleanupStack::PopAndDestroy(&rects);
   355     CleanupStack::PopAndDestroy(&rects);
   338     if ( aItemCount )
   356     if ( aItemCount )
   339         {
   357         {
   340         iGrid->ItemDrawer()->ColumnData()->SetDrawBackground(EFalse);
   358         iGrid->ItemDrawer()->ColumnData()->SetDrawBackground(EFalse);
   358     if( iGrid->ScrollBarFrame() )
   376     if( iGrid->ScrollBarFrame() )
   359         {
   377         {
   360         iGrid->SetScrollBarFrame(NULL,CEikListBox::EOwnedExternally);
   378         iGrid->SetScrollBarFrame(NULL,CEikListBox::EOwnedExternally);
   361         }
   379         }
   362     }
   380     }
   363 
       
   364 
       
   365 // --------------------------------------------------------------------------
       
   366 // CTsFastSwapArea::GetFastSwapAreaRects
       
   367 // --------------------------------------------------------------------------
       
   368 //
       
   369 void CTsFastSwapArea::GetFastSwapAreaRects( RArray<TAknLayoutRect>& aRects )
       
   370     {
       
   371     TAknLayoutRect gridAppPane;
       
   372     TAknLayoutRect gridItem;
       
   373     TAknLayoutRect gridImage;
       
   374     TAknLayoutRect gridNextItem;
       
   375     
       
   376     TInt variety;
       
   377     TBool disable = GetVariety(variety);
       
   378     if ( disable )
       
   379         {
       
   380         TRAP_IGNORE(static_cast<CTsAppUi*>(iEikonEnv->AppUi())->RequestPopUpL());
       
   381         }
       
   382     variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0; // double check to avoid layout panic
       
   383     
       
   384     gridAppPane.LayoutRect( Rect(), 
       
   385             AknLayoutScalable_Apps::tport_appsw_pane( variety ) );
       
   386     aRects.Append(gridAppPane);
       
   387     
       
   388     gridItem.LayoutRect( gridAppPane.Rect(),
       
   389             AknLayoutScalable_Apps::cell_tport_appsw_pane( variety, 0, 0 ) );
       
   390     aRects.Append(gridItem);
       
   391     
       
   392     gridImage.LayoutRect( gridItem.Rect(),
       
   393             AknLayoutScalable_Apps::cell_tport_appsw_pane_g1( variety ) ); 
       
   394     aRects.Append(gridImage);
       
   395     gridNextItem.LayoutRect( gridAppPane.Rect(),
       
   396             AknLayoutScalable_Apps::cell_tport_appsw_pane_cp03( variety ) );
       
   397     aRects.Append(gridNextItem);
       
   398     
       
   399     if ( disable )
       
   400         {
       
   401         TRAP_IGNORE(static_cast<CTsAppUi*>(iEikonEnv->AppUi())->DisablePopUpL());
       
   402         }
       
   403     }
       
   404 
       
   405 
   381 
   406 // --------------------------------------------------------------------------
   382 // --------------------------------------------------------------------------
   407 // CTsFastSwapArea::Setup
   383 // CTsFastSwapArea::Setup
   408 // --------------------------------------------------------------------------
   384 // --------------------------------------------------------------------------
   409 //
   385 //
   552             {
   528             {
   553             iWidgetClosingCount++;
   529             iWidgetClosingCount++;
   554             }
   530             }
   555         
   531         
   556         // Orientation update
   532         // Orientation update
   557         iPrevScreenOrientation = GetCurrentScreenOrientation();
   533         iPrevScreenOrientation = iFastSwapExt->GetCurrentScreenOrientation();
   558         iOrientationSignalTimer->Cancel();
   534         iOrientationSignalTimer->Cancel();
   559         iOrientationSignalTimer->After(KOrientationSwitchTime);
   535         iOrientationSignalTimer->After(KOrientationSwitchTime);
   560         }
   536         }
   561 
   537 
   562     TSLOG_OUT();
   538     TSLOG_OUT();
   622 //
   598 //
   623 void CTsFastSwapArea::HandleFswContentChanged()
   599 void CTsFastSwapArea::HandleFswContentChanged()
   624     {
   600     {
   625     TSLOG_CONTEXT( HandleFswContentChanged, TSLOG_LOCAL );
   601     TSLOG_CONTEXT( HandleFswContentChanged, TSLOG_LOCAL );
   626     TSLOG_IN();
   602     TSLOG_IN();
   627 
   603     
   628     TRAPD( err, HandleFswContentChangedL() );
   604     //prepare grid with current content from fastswap server 
       
   605     GetContentForGrid();
       
   606     // draw
       
   607     UpdateGrid( ETrue, ETrue );
       
   608     // notify observer, if present
       
   609     NotifyChange();
       
   610     
       
   611     TSLOG_OUT();
       
   612     }
       
   613 
       
   614 // --------------------------------------------------------------------------
       
   615 // CTsFastSwapArea::GetContentForGrid
       
   616 // --------------------------------------------------------------------------
       
   617 //
       
   618 void CTsFastSwapArea::GetContentForGrid()
       
   619     {
       
   620     TSLOG_CONTEXT( GetContentForGrid, TSLOG_LOCAL );
       
   621     TSLOG_IN();
       
   622     TRAPD( err,
       
   623         // get current content from fastswap server
       
   624         GetContentL();
       
   625         // prepare grid content
       
   626         RenderContentL();
       
   627     )
   629     if ( err != KErrNone )
   628     if ( err != KErrNone )
   630         {
   629         {
   631         TSLOG1( TSLOG_INFO, "leave occured: %d", err );
   630         TSLOG1( TSLOG_INFO, "leave occured: %d", err );
   632         }
   631         }
   633 
   632 
   634     TSLOG_OUT();
   633     TSLOG_OUT();
   635     }
   634     }
   636 
   635 
   637 // --------------------------------------------------------------------------
   636 // --------------------------------------------------------------------------
   638 // CTsFastSwapArea::HandleFswContentChangedL
   637 // CTsFastSwapArea::GetContentL
   639 // --------------------------------------------------------------------------
   638 // --------------------------------------------------------------------------
   640 //
   639 //
   641 void CTsFastSwapArea::HandleFswContentChangedL()
   640 void CTsFastSwapArea::GetContentL()
   642     {
   641     {
   643     TSLOG_CONTEXT( HandleFswContentChangedL, TSLOG_LOCAL );
   642     TSLOG_CONTEXT( GetContentL, TSLOG_LOCAL );
   644     TSLOG_IN();
   643     TSLOG_IN();
   645 
       
   646     // get current content from fastswap server
       
   647     iFSClient->GetContentL( iArray );
   644     iFSClient->GetContentL( iArray );
   648 
   645     
   649 #ifdef _DEBUG
   646     #ifdef _DEBUG
   650     for ( TInt i = 0, ie = iArray.Count(); i != ie; ++i )
   647     for ( TInt i = 0, ie = iArray.Count(); i != ie; ++i )
   651         {
   648         {
   652         CTsFswEntry* e = iArray[i];
   649         CTsFswEntry* e = iArray[i];
   653         const TDesC& name( e->AppName() );
   650         const TDesC& name( e->AppName() );
   654         TSLOG4( TSLOG_INFO, "[%d]: %d %d %S", i, e->WgId(), e->AppUid(), &name );
   651         TSLOG4( TSLOG_INFO, "[%d]: %d %d %S", i, e->WgId(), e->AppUid(), &name );
   655         }
   652         }
   656 #endif
   653     #endif
   657     
   654     
   658     // Update closing widget count if necessary
   655     // Update closing widget count if necessary
   659     if ( iWidgetClosingCount )
   656     if ( iWidgetClosingCount )
   660         {
   657         {
   661         TInt widgetCount(0);
   658         TInt widgetCount(0);
   666                 widgetCount++;
   663                 widgetCount++;
   667                 }
   664                 }
   668             }
   665             }
   669         iWidgetClosingCount = widgetCount;
   666         iWidgetClosingCount = widgetCount;
   670         }
   667         }
   671 
       
   672     // draw
       
   673     RenderContentL();
       
   674 
       
   675     // notify observer, if present
       
   676     NotifyChange();
       
   677 
       
   678     TSLOG_OUT();
   668     TSLOG_OUT();
   679     }
   669     }
   680 
   670 
   681 // --------------------------------------------------------------------------
   671 // --------------------------------------------------------------------------
   682 // CTsFastSwapArea::RenderContentL
   672 // CTsFastSwapArea::RenderContentL
   683 // --------------------------------------------------------------------------
   673 // --------------------------------------------------------------------------
   684 //
   674 //
   685 void CTsFastSwapArea::RenderContentL( TBool aSuppressAnimation )
   675 void CTsFastSwapArea::RenderContentL( )
   686     {
   676     {
   687     TSLOG_CONTEXT( RenderContentL, TSLOG_LOCAL );
   677     TSLOG_CONTEXT( RenderContentL, TSLOG_LOCAL );
   688     TSLOG_IN();
   678     TSLOG_IN();
   689 
   679 
   690     _LIT(KSeparator, "\t");
   680     _LIT(KSeparator, "\t");
       
   681     
       
   682     // Cancel ongoing scaling
       
   683     iFastSwapExt->CancelScaleTasks();
   691     
   684     
   692     CArrayPtr<CGulIcon>* iconArray = new ( ELeave ) CAknIconArray( KMaxGranularity );
   685     CArrayPtr<CGulIcon>* iconArray = new ( ELeave ) CAknIconArray( KMaxGranularity );
   693     CleanupStack::PushL( iconArray );
   686     CleanupStack::PushL( iconArray );
   694     CDesCArrayFlat* textArray = new ( ELeave ) CDesCArrayFlat( KMaxGranularity );
   687     CDesCArrayFlat* textArray = new ( ELeave ) CDesCArrayFlat( KMaxGranularity );
   695     CleanupStack::PushL( textArray );
   688     CleanupStack::PushL( textArray );
   696     RArray<TInt> closeItemArray;
   689     RArray<TInt> closeItemArray;
   697     CleanupClosePushL(closeItemArray);
   690     CleanupClosePushL(closeItemArray);
   698     RArray<TInt> strokeItemArray;
   691     RArray<TInt> strokeItemArray;
   699     CleanupClosePushL(strokeItemArray);
   692     CleanupClosePushL(strokeItemArray);
       
   693     RArray<TInt> screenshotList;
       
   694     CleanupClosePushL(screenshotList);
   700     
   695     
   701     // Update view based on number of items
   696     // Update view based on number of items
   702     LayoutGridViewL( iArray.Count() );
   697     LayoutGridViewL( iArray.Count() );
       
   698     
       
   699     CArrayPtr<CGulIcon>* oldIconArray =
       
   700         iGrid->ItemDrawer()->FormattedCellData()->IconArray();
   703     
   701     
   704     for ( TInt i = 0; i < iArray.Count(); ++i )
   702     for ( TInt i = 0; i < iArray.Count(); ++i )
   705         {
   703         {
   706         const TDesC& appName( iArray[i]->AppName() );
   704         const TDesC& appName( iArray[i]->AppName() );
   707         const TInt formatLen = 3 + 2;
   705         const TInt formatLen = 3 + 2;
   711         formAppName.AppendNum(i);
   709         formAppName.AppendNum(i);
   712         formAppName.Append(KSeparator);
   710         formAppName.Append(KSeparator);
   713         formAppName.Append(appName);
   711         formAppName.Append(appName);
   714         textArray->AppendL(formAppName);
   712         textArray->AppendL(formAppName);
   715         CleanupStack::PopAndDestroy(&formAppName);
   713         CleanupStack::PopAndDestroy(&formAppName);
   716         TSize sz = PreferredImageSize();
   714         TSize sz = iFastSwapExt->PreferredImageSize();
   717 
   715         
   718         // take the screenshot or appicon+mask and make a copy and scale
   716         // take the screenshot or appicon+mask and make a copy and scale
   719         CFbsBitmap* bitmap = 0;
   717         CFbsBitmap* bitmap = 0;
   720         TInt h = iArray[i]->ScreenshotHandle();
   718         TInt h = iArray[i]->ScreenshotHandle();
   721         TSLOG2( TSLOG_INFO, "'%S' screenshot handle %d", &appName, h );
   719         TSLOG2( TSLOG_INFO, "'%S' screenshot handle %d", &appName, h );
   722         TInt maskh = 0;
   720         TInt maskh = 0;
   723         CFbsBitmap* mask = 0;
   721         CFbsBitmap* mask = 0;
       
   722         TBool isScreenshot( ETrue );
   724         if ( !h )
   723         if ( !h )
   725             {
   724             {
   726             // No screenshot, take app icon
   725             // No screenshot, take app icon
   727             h = iArray[i]->AppIconBitmapHandle();
   726             h = iArray[i]->AppIconBitmapHandle();
   728             maskh = iArray[i]->AppIconMaskHandle();
   727             maskh = iArray[i]->AppIconMaskHandle();
       
   728             isScreenshot = EFalse;
   729             TSLOG1( TSLOG_INFO, "using appicon, handle = %d", h );
   729             TSLOG1( TSLOG_INFO, "using appicon, handle = %d", h );
   730             }
   730             }
   731         else
   731         else
   732             {
   732             {
   733             // Screenshot exists, mark it for stroke
   733             // Screenshot exists, mark it for stroke
   734             strokeItemArray.AppendL(i);
   734             strokeItemArray.AppendL(i);
   735             }
   735             }
   736         __ASSERT_DEBUG( h, User::Invariant() );
   736         __ASSERT_DEBUG( h, User::Invariant() );
   737         bitmap = CopyBitmapL( h, sz );
   737         
       
   738         // check screenshot - if it exists already, use it
       
   739         // so there is no unnecessary scaling performed
       
   740         screenshotList.AppendL( h );
       
   741         TInt idx = iPrevScreenshots.Find( h );
       
   742         if ( idx != KErrNotFound && oldIconArray && idx < oldIconArray->Count() )
       
   743             {
       
   744             CGulIcon* existingIcon = oldIconArray->At( idx );
       
   745             if ( existingIcon->Bitmap() )
       
   746                 {
       
   747                 h = existingIcon->Bitmap()->Handle();
       
   748                 if ( existingIcon->Mask() )
       
   749                     {
       
   750                     maskh = existingIcon->Mask()->Handle();
       
   751                     }
       
   752                 isScreenshot = EFalse;
       
   753                 }
       
   754             }
       
   755         
       
   756         // create bitmap for grid item
       
   757         bitmap = iFastSwapExt->CopyBitmapL( h, sz, isScreenshot );
   738         CleanupStack::PushL( bitmap );
   758         CleanupStack::PushL( bitmap );
   739         if ( maskh )
   759         if ( maskh )
   740             {
   760             {
   741             mask = CopyBitmapL( maskh, sz );
   761             mask = iFastSwapExt->CopyBitmapL( maskh, sz, EFalse );
   742             }
   762             }
   743         CleanupStack::PushL( mask );
   763         CleanupStack::PushL( mask );
   744 
   764 
   745         CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
   765         CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
   746         CleanupStack::PushL(icon);
   766         CleanupStack::PushL(icon);
   751         if ( CanClose(i) && AknLayoutUtils::PenEnabled() )
   771         if ( CanClose(i) && AknLayoutUtils::PenEnabled() )
   752             {
   772             {
   753             closeItemArray.AppendL(i);
   773             closeItemArray.AppendL(i);
   754             }
   774             }
   755         }
   775         }
       
   776     // Update screenshot list
       
   777     iPrevScreenshots.Reset();
       
   778     for ( TInt i = 0; i < screenshotList.Count(); i++ )
       
   779         {
       
   780         iPrevScreenshots.AppendL( screenshotList[i] );
       
   781         }
       
   782     CleanupStack::PopAndDestroy( &screenshotList );
       
   783     
   756     // Setup grid
   784     // Setup grid
   757     iGrid->Model()->SetItemTextArray(textArray);
   785     iGrid->Model()->SetItemTextArray(textArray);
   758     CArrayPtr<CGulIcon>* oldIconArray =
       
   759         iGrid->ItemDrawer()->FormattedCellData()->IconArray();
       
   760     if(oldIconArray)
   786     if(oldIconArray)
   761         {
   787         {
   762         delete oldIconArray;
   788         delete oldIconArray;
   763         oldIconArray = NULL;
   789         oldIconArray = NULL;
   764         }
   790         }
   783     iEvtHandler.ReInitPhysicsL( GridWorldSize(), ViewSize(), ETrue );
   809     iEvtHandler.ReInitPhysicsL( GridWorldSize(), ViewSize(), ETrue );
   784     if ( SelectedIndex() >= GridItemCount() && GridItemCount() )
   810     if ( SelectedIndex() >= GridItemCount() && GridItemCount() )
   785         {
   811         {
   786         iGrid->SetCurrentDataIndex( GridItemCount() - 1 );
   812         iGrid->SetCurrentDataIndex( GridItemCount() - 1 );
   787         }
   813         }
   788     UpdateGrid( ETrue, !aSuppressAnimation );
       
   789     
       
   790     TSLOG_OUT();
   814     TSLOG_OUT();
   791     }
   815     }
   792 
   816 
   793 // --------------------------------------------------------------------------
       
   794 // CTsFastSwapArea::CopyBitmapL
       
   795 // Copy and scale.
       
   796 // --------------------------------------------------------------------------
       
   797 //
       
   798 CFbsBitmap* CTsFastSwapArea::CopyBitmapL( TInt aFbsHandle, TSize aSize )
       
   799     {
       
   800     CFbsBitmap* ret = new (ELeave) CFbsBitmap();
       
   801     CleanupStack::PushL( ret );
       
   802 
       
   803     CFbsBitmap* bmp = new (ELeave) CFbsBitmap();
       
   804     CleanupStack::PushL( bmp );
       
   805     User::LeaveIfError( bmp->Duplicate( aFbsHandle ) );
       
   806 
       
   807     // do not always use aSize, preserving the aspect ratio is quite
       
   808     // important when showing app icons instead of screenshots
       
   809     TSize sz = CalculateSizePreserveRatio( aSize, bmp->SizeInPixels() );
       
   810     User::LeaveIfError( ret->Create( sz, bmp->DisplayMode() ) );
       
   811 
       
   812     AknIconUtils::ScaleBitmapL( sz, ret, bmp );
       
   813 
       
   814     CleanupStack::PopAndDestroy( bmp );
       
   815     CleanupStack::Pop( ret );
       
   816 
       
   817     return ret;
       
   818     }
       
   819 
   817 
   820 // --------------------------------------------------------------------------
   818 // --------------------------------------------------------------------------
   821 // CTsFastSwapArea::CountComponentControls
   819 // CTsFastSwapArea::CountComponentControls
   822 // --------------------------------------------------------------------------
   820 // --------------------------------------------------------------------------
   823 //
   821 //
   889     else
   887     else
   890         {
   888         {
   891         iGrid->ShowHighlight();
   889         iGrid->ShowHighlight();
   892         }
   890         }
   893     
   891     
   894     // get the current task list
   892     //prepare grid with current content from fastswap server
   895     HandleFswContentChanged();
   893     GetContentForGrid();    
       
   894     //restore default selection
       
   895     RestoreSelectedIndex();
       
   896     // draw
       
   897     UpdateGrid( ETrue, EFalse );
       
   898     // notify observer, if present
       
   899     NotifyChange();
   896     // and then start listening for changes
   900     // and then start listening for changes
   897     iFSClient->Subscribe( *this );
   901     iFSClient->Subscribe( *this );
   898     
   902     
   899     RestoreSelectedIndex();
       
   900     UpdateGrid(EFalse, EFalse);
       
   901     
       
   902     iRedrawTimer->Cancel();
   903     iRedrawTimer->Cancel();
   903     iRedrawTimer->After(KRedrawTime);
   904     iRedrawTimer->After(KRedrawTime);
   904     
   905     
   905     // give feedback
   906     // give feedback
   906     LaunchPopupFeedback();
   907     iFastSwapExt->LaunchPopupFeedback();
   907     
   908     
   908     iPrevAppCount = iArray.Count();
   909     iPrevAppCount = iArray.Count();
   909     
   910     
   910     if ( !appUi->DelayedForegroundLaunched() )
   911     if ( !appUi->DelayedForegroundLaunched() )
   911         {
   912         {
  1047 // CTsFastSwapArea::HandlePointerEventL
  1048 // CTsFastSwapArea::HandlePointerEventL
  1048 // -----------------------------------------------------------------------------
  1049 // -----------------------------------------------------------------------------
  1049 //
  1050 //
  1050 void CTsFastSwapArea::HandlePointerEventL( const TPointerEvent& aPointerEvent )
  1051 void CTsFastSwapArea::HandlePointerEventL( const TPointerEvent& aPointerEvent )
  1051     {
  1052     {
       
  1053     TBool supressed = iEventSupressor->SuppressPointerEvent( aPointerEvent );
  1052     iKeyEvent = EFalse;
  1054     iKeyEvent = EFalse;
  1053     if(aPointerEvent.iType == TPointerEvent::EButton1Down)
  1055     if(aPointerEvent.iType == TPointerEvent::EButton1Down)
  1054         {
  1056         {
       
  1057         iSupressDrag = EFalse;
  1055         iHandlePointerCandidate = ETrue;
  1058         iHandlePointerCandidate = ETrue;
  1056         iTapEvent = aPointerEvent;
  1059         iTapEvent = aPointerEvent;
  1057         iGrid->EnableAknEventHandling(EFalse);
  1060         iGrid->EnableAknEventHandling(EFalse);
  1058         iGrid->HandlePointerEventL(aPointerEvent);
  1061         iGrid->HandlePointerEventL(aPointerEvent);
  1059         iGrid->EnableAknEventHandling(ETrue);
  1062         iGrid->EnableAknEventHandling(ETrue);
  1062             {
  1065             {
  1063             iLongTapAnimationTimer->Cancel();
  1066             iLongTapAnimationTimer->Cancel();
  1064             iLongTapAnimationTimer->After(KLongTapAnimationInitTime);
  1067             iLongTapAnimationTimer->After(KLongTapAnimationInitTime);
  1065             }
  1068             }
  1066         }
  1069         }
       
  1070     else if( aPointerEvent.iType == TPointerEvent::EDrag )
       
  1071         {
       
  1072         iSupressDrag = supressed;
       
  1073         }
  1067     else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
  1074     else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
  1068         {
  1075         {
  1069         CancelLongTapAnimation( EFalse );
  1076         CancelLongTapAnimation( EFalse );
  1070         if( iActivateOnPointerRelease != TPoint() )
  1077         if( iActivateOnPointerRelease != TPoint() ||
       
  1078             iSupressDrag)
  1071             {
  1079             {
  1072             iHandlePointerCandidate = ETrue;
  1080             iHandlePointerCandidate = ETrue;
  1073             TapL(iActivateOnPointerRelease);
  1081             TapL(iActivateOnPointerRelease);
  1074             iActivateOnPointerRelease = TPoint();
  1082             iActivateOnPointerRelease = TPoint();
  1075             }
  1083             }
  1199         {
  1207         {
  1200         UpdateGrid(ETrue, ETrue);
  1208         UpdateGrid(ETrue, ETrue);
  1201         }
  1209         }
  1202     else if ( aSource == iOrientationSignalTimer )
  1210     else if ( aSource == iOrientationSignalTimer )
  1203         {
  1211         {
  1204         TInt currentOrientation = GetCurrentScreenOrientation();
  1212         TInt currentOrientation = iFastSwapExt->GetCurrentScreenOrientation();
  1205         if ( currentOrientation != iPrevScreenOrientation )
  1213         if ( currentOrientation != iPrevScreenOrientation )
  1206             {
  1214             {
  1207             // Order layout change
  1215             // Order layout change
  1208             static_cast<CAknAppUi*>(iCoeEnv->AppUi())->HandleResourceChangeL(KEikDynamicLayoutVariantSwitch);
  1216             static_cast<CAknAppUi*>(iCoeEnv->AppUi())->HandleResourceChangeL(KEikDynamicLayoutVariantSwitch);
  1209             iRedrawTimer->Cancel();
  1217             iRedrawTimer->Cancel();
  1273 
  1281 
  1274     if(showPopUp)
  1282     if(showPopUp)
  1275         {
  1283         {
  1276         static_cast<CTsAppUi*>(iEikonEnv->AppUi())->RequestPopUpL();
  1284         static_cast<CTsAppUi*>(iEikonEnv->AppUi())->RequestPopUpL();
  1277         // give feedback
  1285         // give feedback
  1278         LaunchPopupFeedback();
  1286         iFastSwapExt->LaunchPopupFeedback();
  1279         // save index for later use & show popup
  1287         // save index for later use & show popup
  1280         iAppIndexForPopup = aIndex;
  1288         iAppIndexForPopup = aIndex;
  1281         iPopup->SetPosition( aPoint, CAknStylusPopUpMenu::EPositionTypeLeftBottom );
  1289         iPopup->SetPosition( aPoint, CAknStylusPopUpMenu::EPositionTypeLeftBottom );
  1282         iPopup->ShowMenu();
  1290         iPopup->ShowMenu();
  1283         }
  1291         }
  1315         iDcObserver->DataChanged( this, Count() );
  1323         iDcObserver->DataChanged( this, Count() );
  1316         }
  1324         }
  1317     }
  1325     }
  1318     
  1326     
  1319 // -----------------------------------------------------------------------------
  1327 // -----------------------------------------------------------------------------
  1320 // CTsFastSwapArea::PreferredImageSize
       
  1321 // -----------------------------------------------------------------------------
       
  1322 //
       
  1323 TSize CTsFastSwapArea::PreferredImageSize()
       
  1324     {
       
  1325     TAknLayoutRect gridImage;
       
  1326     TRAP_IGNORE(
       
  1327         RArray<TAknLayoutRect> rects;
       
  1328         CleanupClosePushL(rects);
       
  1329         rects.ReserveL(KLayoutItemCount);
       
  1330         GetFastSwapAreaRects(rects);
       
  1331         gridImage = rects[2];
       
  1332         CleanupStack::PopAndDestroy(&rects);
       
  1333         );
       
  1334     return gridImage.Rect().Size();
       
  1335     }
       
  1336     
       
  1337 // -----------------------------------------------------------------------------
       
  1338 // CTsFastSwapArea::GridItemCount
  1328 // CTsFastSwapArea::GridItemCount
  1339 // -----------------------------------------------------------------------------
  1329 // -----------------------------------------------------------------------------
  1340 //
  1330 //
  1341 TInt CTsFastSwapArea::GridItemCount()
  1331 TInt CTsFastSwapArea::GridItemCount()
  1342     {
  1332     {
  1343     return iGrid->Model()->ItemTextArray()->MdcaCount();
  1333     return iGrid->Model()->ItemTextArray()->MdcaCount();
       
  1334     }
       
  1335 
       
  1336 
       
  1337 // -----------------------------------------------------------------------------
       
  1338 // CTsFastSwapArea::GridItemCount
       
  1339 // -----------------------------------------------------------------------------
       
  1340 //
       
  1341 TInt CTsFastSwapArea::GetGridItemData( TsFastSwapAreaGridData aDataType )
       
  1342     {
       
  1343     TInt retVal;
       
  1344     switch ( aDataType )
       
  1345         {
       
  1346         case EMaxItemsOnScreen:
       
  1347             retVal = iMaxItemsOnScreen;
       
  1348             break;
       
  1349         case EGridItemWidth:
       
  1350             retVal = iGridItemWidth;
       
  1351             break;
       
  1352         case EGridItemGap:
       
  1353             retVal = iGridItemGap;
       
  1354             break;
       
  1355         default:
       
  1356             retVal = KErrArgument;
       
  1357             break;
       
  1358         }
       
  1359     return retVal;
  1344     }
  1360     }
  1345 
  1361 
  1346 // -----------------------------------------------------------------------------
  1362 // -----------------------------------------------------------------------------
  1347 // CTsFastSwapArea::HandleListBoxEventL
  1363 // CTsFastSwapArea::HandleListBoxEventL
  1348 // -----------------------------------------------------------------------------
  1364 // -----------------------------------------------------------------------------
  1369                 break;
  1385                 break;
  1370             }
  1386             }
  1371         }
  1387         }
  1372     }
  1388     }
  1373 
  1389 
  1374 // --------------------------------------------------------------------------
       
  1375 // CTsFastSwapArea::CalculateSizePreserveRatio
       
  1376 // --------------------------------------------------------------------------
       
  1377 //
       
  1378 TSize CTsFastSwapArea::CalculateSizePreserveRatio(
       
  1379         const TSize& aTargetAreaSize,
       
  1380         const TSize& aSourceSize )
       
  1381     {
       
  1382     const TReal 
       
  1383       resizedAspectRatio(aTargetAreaSize.iWidth/(TReal)aTargetAreaSize.iHeight);
       
  1384     const TReal 
       
  1385       orginalAspectRatio(aSourceSize.iWidth/(TReal)aSourceSize.iHeight);
       
  1386     //this condition avoid empty margins ( bigger output ). to realy fit area change it
       
  1387     const TReal scaleFactor = 
       
  1388         ( orginalAspectRatio > resizedAspectRatio ) ? 
       
  1389         (aTargetAreaSize.iHeight /(TReal)aSourceSize.iHeight) ://scale by height
       
  1390         (aTargetAreaSize.iWidth /(TReal)aSourceSize.iWidth) ;//scale by width
       
  1391     return TSize(aSourceSize.iWidth * scaleFactor, aSourceSize.iHeight * scaleFactor);
       
  1392     }
       
  1393 
  1390 
  1394 // --------------------------------------------------------------------------
  1391 // --------------------------------------------------------------------------
  1395 // CTsFastSwapArea::SelectNextItem
  1392 // CTsFastSwapArea::SelectNextItem
  1396 // --------------------------------------------------------------------------
  1393 // --------------------------------------------------------------------------
  1397 //
  1394 //
  1419 //
  1416 //
  1420 void CTsFastSwapArea::CenterItem(TInt aRedrawDelay)
  1417 void CTsFastSwapArea::CenterItem(TInt aRedrawDelay)
  1421     {
  1418     {
  1422     if( iMaxItemsOnScreen < GridItemCount() )
  1419     if( iMaxItemsOnScreen < GridItemCount() )
  1423         {
  1420         {
  1424         TInt visibleItem = ViewToVisibleItem( ViewPos() );
  1421         TInt visibleItem = iFastSwapExt->ViewToVisibleItem( ViewPos() );
  1425         if(iKeyEvent)
  1422         if(iKeyEvent)
  1426             {
  1423             {
  1427             visibleItem = SelectedIndex();
  1424             visibleItem = SelectedIndex();
  1428             }
  1425             }
  1429         if(visibleItem != SelectedIndex())
  1426         if(visibleItem != SelectedIndex())
  1460 // CTsFastSwapArea::UpdateGrid
  1457 // CTsFastSwapArea::UpdateGrid
  1461 // --------------------------------------------------------------------------
  1458 // --------------------------------------------------------------------------
  1462 //
  1459 //
  1463 void CTsFastSwapArea::UpdateGrid( TBool aForceRedraw, TBool aAnimate )
  1460 void CTsFastSwapArea::UpdateGrid( TBool aForceRedraw, TBool aAnimate )
  1464     {
  1461     {
  1465     TPoint targetPoint = ItemViewPosition( SelectedIndex() );
  1462     TPoint targetPoint = iFastSwapExt->ItemViewPosition( SelectedIndex() );
  1466     if ( aForceRedraw || targetPoint.iX != ViewPos().iX )
  1463     if ( aForceRedraw || targetPoint.iX != ViewPos().iX )
  1467         {
  1464         {
  1468         if ( aAnimate )
  1465         if ( aAnimate )
  1469             {
  1466             {
  1470             iEvtHandler.Animate( targetPoint );
  1467             iEvtHandler.Animate( targetPoint );
  1644     CenterItem( KUpdateGridTime );
  1641     CenterItem( KUpdateGridTime );
  1645     DrawDeferred();
  1642     DrawDeferred();
  1646     }
  1643     }
  1647 
  1644 
  1648 // -----------------------------------------------------------------------------
  1645 // -----------------------------------------------------------------------------
  1649 // CTsFastSwapArea::ViewSize
  1646 // CTsFastSwapArea::ViewPos
  1650 // -----------------------------------------------------------------------------
  1647 // -----------------------------------------------------------------------------
  1651 //
  1648 //
  1652 TPoint CTsFastSwapArea::ViewPos() const
  1649 TPoint CTsFastSwapArea::ViewPos() const
  1653     {
  1650     {
  1654     TPoint retVal;
  1651     TPoint retVal;
  1662         }
  1659         }
  1663     retVal.iX += iLogicalViewPosOffset;
  1660     retVal.iX += iLogicalViewPosOffset;
  1664     return retVal;
  1661     return retVal;
  1665     }
  1662     }
  1666 
  1663 
  1667 // -----------------------------------------------------------------------------
       
  1668 // CTsFastSwapArea::ItemPosition
       
  1669 // -----------------------------------------------------------------------------
       
  1670 //
       
  1671 TPoint CTsFastSwapArea::ItemViewPosition( TInt aItemIdx )
       
  1672     {
       
  1673     TPoint retVal = Rect().iTl;
       
  1674     if ( aItemIdx < 0 )
       
  1675         {
       
  1676         // No items
       
  1677         retVal.iX = 0;
       
  1678         }
       
  1679     else if ( aItemIdx == 0 )
       
  1680         {
       
  1681         // First item
       
  1682         if( AknLayoutUtils::LayoutMirrored() )
       
  1683             {
       
  1684             if ( GridItemCount() > iMaxItemsOnScreen )
       
  1685                 {
       
  1686                 retVal.iX = GridWorldSize().iWidth - Rect().Width();
       
  1687                 }
       
  1688             else
       
  1689                 {
       
  1690                 retVal.iX = 0;
       
  1691                 }
       
  1692             }
       
  1693         else // normal layout
       
  1694             {
       
  1695             retVal.iX = 0;
       
  1696             }
       
  1697         }
       
  1698     else if ( aItemIdx == GridItemCount() - 1 )
       
  1699         {
       
  1700         // Last item selected
       
  1701         if( AknLayoutUtils::LayoutMirrored() )
       
  1702             {
       
  1703             retVal.iX = 0;
       
  1704             }
       
  1705         else // normal layout
       
  1706             {
       
  1707             if ( GridItemCount() > iMaxItemsOnScreen )
       
  1708                 {
       
  1709                 retVal.iX = GridWorldSize().iWidth - Rect().Width();
       
  1710                 }
       
  1711             else
       
  1712                 {
       
  1713                 retVal.iX = 0;
       
  1714                 }
       
  1715             }
       
  1716         }
       
  1717     else
       
  1718         {
       
  1719         // Middle item
       
  1720         TInt screenMiddleItemOffset = ( Rect().Width() - iGridItemWidth ) / 2;
       
  1721         if( AknLayoutUtils::LayoutMirrored() )
       
  1722             {
       
  1723             retVal.iX = iGridItemWidth * ( GridItemCount() - 1 - aItemIdx ) - screenMiddleItemOffset;
       
  1724             retVal.iX += ( GridItemCount() - 1 - aItemIdx ) * iGridItemGap;
       
  1725             }
       
  1726         else // normal layout
       
  1727             {
       
  1728             retVal.iX = iGridItemWidth * aItemIdx - screenMiddleItemOffset;
       
  1729             retVal.iX += iGridItemGap * aItemIdx;
       
  1730             }
       
  1731         if ( retVal.iX < 0 )
       
  1732             {
       
  1733             retVal.iX = 0;
       
  1734             }
       
  1735         else if ( retVal.iX + Rect().Width() > GridWorldSize().iWidth )
       
  1736             {
       
  1737             retVal.iX = GridWorldSize().iWidth - Rect().Width();
       
  1738             }
       
  1739         }
       
  1740     
       
  1741     // Return middle of the view rectangle
       
  1742     retVal.iX += Rect().Width() / 2;
       
  1743     
       
  1744     return retVal;
       
  1745     }
       
  1746 
       
  1747 // -----------------------------------------------------------------------------
       
  1748 // CTsFastSwapArea::ViewToVisibleItem
       
  1749 // -----------------------------------------------------------------------------
       
  1750 //
       
  1751 TInt CTsFastSwapArea::ViewToVisibleItem( const TPoint aViewPos )
       
  1752     {
       
  1753     TInt retVal(0);
       
  1754     TPoint absViewPos = aViewPos;
       
  1755     absViewPos.iX -= Rect().Width() / 2;
       
  1756     if ( absViewPos.iX < 0 )
       
  1757         {
       
  1758         if ( AknLayoutUtils::LayoutMirrored() )
       
  1759             {
       
  1760             // View crossed left border of grid world rect, last item selected
       
  1761             retVal = GridItemCount() - 1;
       
  1762             }
       
  1763         else // normal layout
       
  1764             {
       
  1765             // View crossed left border of grid world rect, first item selected
       
  1766             retVal = 0;
       
  1767             }
       
  1768         }
       
  1769     else if ( absViewPos.iX + Rect().Width() > GridWorldSize().iWidth )
       
  1770         {
       
  1771         if ( AknLayoutUtils::LayoutMirrored() )
       
  1772             {
       
  1773             // View crossed right border of grid world rect, first item selected
       
  1774             retVal = 0;
       
  1775             }
       
  1776         else // normal layout
       
  1777             {
       
  1778             // View crossed right border of grid world rect, last item selected
       
  1779             retVal = GridItemCount() - 1;
       
  1780             }
       
  1781         }
       
  1782     else
       
  1783         {
       
  1784         TInt retItemPosX(0);
       
  1785         TInt offsetCheck = GridWorldSize().iWidth;
       
  1786         // View inside of grid world rect
       
  1787         for ( TInt i = 0 ; i < GridItemCount(); i++ )
       
  1788             {
       
  1789             TInt itemPosX = ItemViewPosition( i ).iX;
       
  1790             TInt offset = aViewPos.iX - itemPosX;
       
  1791             if ( Abs( offset ) <= offsetCheck )
       
  1792                 {
       
  1793                 offsetCheck = Abs( offset );
       
  1794                 retVal = i;
       
  1795                 retItemPosX = itemPosX;
       
  1796                 }
       
  1797             else
       
  1798                 {
       
  1799                 break;
       
  1800                 }
       
  1801             }
       
  1802         // Check if item is fully visible. If not
       
  1803         // return next one if possible
       
  1804         if ( retItemPosX - iGridItemWidth / 2 < absViewPos.iX &&
       
  1805              retVal + 1 < GridItemCount() )
       
  1806             {
       
  1807             retVal++;
       
  1808             }
       
  1809         }
       
  1810     
       
  1811     return retVal;
       
  1812     }
       
  1813 
       
  1814 
       
  1815 // -----------------------------------------------------------------------------
       
  1816 // CTsFastSwapArea::LaunchPopupFeedback
       
  1817 // -----------------------------------------------------------------------------
       
  1818 //
       
  1819 void CTsFastSwapArea::LaunchPopupFeedback()
       
  1820     {
       
  1821     if ( AknLayoutUtils::PenEnabled() )
       
  1822         {
       
  1823         MTouchFeedback* feedback = MTouchFeedback::Instance();
       
  1824         if ( feedback )
       
  1825             {
       
  1826             TTouchLogicalFeedback fbLogicalType = ETouchFeedbackPopUp;
       
  1827             if ( CAknTransitionUtils::TransitionsEnabled(
       
  1828                  AknTransEffect::EComponentTransitionsOff ) )
       
  1829                 {
       
  1830                 fbLogicalType = ETouchFeedbackIncreasingPopUp;
       
  1831                 }
       
  1832             feedback->InstantFeedback( this,
       
  1833                                        fbLogicalType,
       
  1834                                        ETouchFeedbackVibra,
       
  1835                                        TPointerEvent() );
       
  1836             }
       
  1837         }
       
  1838     }
       
  1839 
       
  1840 
       
  1841 // -----------------------------------------------------------------------------
       
  1842 // CTsFastSwapArea::GetCurrentScreenOrientation
       
  1843 // -----------------------------------------------------------------------------
       
  1844 //
       
  1845 TInt CTsFastSwapArea::GetCurrentScreenOrientation()
       
  1846     {
       
  1847     TPixelsAndRotation availableRect;
       
  1848     iEikonEnv->ScreenDevice()->GetDefaultScreenSizeAndRotation(availableRect);
       
  1849     return availableRect.iPixelSize.iWidth > availableRect.iPixelSize.iHeight;
       
  1850     }
       
  1851 
       
  1852 
       
  1853 // -----------------------------------------------------------------------------
       
  1854 // CTsFastSwapArea::GetVariety
       
  1855 // -----------------------------------------------------------------------------
       
  1856 //
       
  1857 TBool CTsFastSwapArea::GetVariety( TInt& aVariety )
       
  1858     {
       
  1859     aVariety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0;
       
  1860     TBool foreground = static_cast<CTsAppUi*>(iEikonEnv->AppUi())->IsForeground();
       
  1861     if ( foreground )
       
  1862         {
       
  1863         TInt screenOrientation = GetCurrentScreenOrientation();
       
  1864         if ( aVariety != screenOrientation )
       
  1865             {
       
  1866             aVariety = screenOrientation;
       
  1867             return ETrue;
       
  1868             }
       
  1869         }
       
  1870     return EFalse;
       
  1871     }
       
  1872 
  1664 
  1873 // -----------------------------------------------------------------------------
  1665 // -----------------------------------------------------------------------------
  1874 // CTsFastSwapArea::IsAppClosing
  1666 // CTsFastSwapArea::IsAppClosing
  1875 // -----------------------------------------------------------------------------
  1667 // -----------------------------------------------------------------------------
  1876 //
  1668 //
  1922         }
  1714         }
  1923     else if ( aWgId == homescrWgId )
  1715     else if ( aWgId == homescrWgId )
  1924         {
  1716         {
  1925         retVal = ETrue;
  1717         retVal = ETrue;
  1926         }
  1718         }
       
  1719     
  1927     iPrevAppCount = appCount;
  1720     iPrevAppCount = appCount;
  1928     return retVal;
  1721     return retVal;
  1929     }
  1722     }
  1930 
  1723 
  1931 // -----------------------------------------------------------------------------
  1724 // -----------------------------------------------------------------------------