taskswitcher/taskswitcherui/taskswitcherapp/src/tsfastswaparea.cpp
branchRCL_3
changeset 102 ba63c83f4716
parent 93 b01126ce0bec
equal deleted inserted replaced
93:b01126ce0bec 102:ba63c83f4716
    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>
    31 #include <aknlongtapanimation.h>
    34 #include <aknlongtapanimation.h>
    32 #include <aknpointereventsuppressor.h>
       
    33 
    35 
    34 #include "tsfastswaparea.h"
    36 #include "tsfastswaparea.h"
    35 #include "tsfastswapareautils.h"
       
    36 #include "tsapplogging.h"
    37 #include "tsapplogging.h"
    37 #include "tsfswclient.h"
    38 #include "tsfswclient.h"
    38 #include "tsappui.h"
    39 #include "tsappui.h"
    39 #include "tsdatachangeobserver.h"
    40 #include "tsdatachangeobserver.h"
    40 #include "tseventcontroler.h"
    41 #include "tseventcontroler.h"
    55 
    56 
    56 const TInt KAppKeyTypeShort = 1;
    57 const TInt KAppKeyTypeShort = 1;
    57 const TInt KAppKeyTypeLong = 2;
    58 const TInt KAppKeyTypeLong = 2;
    58 
    59 
    59 const TInt KLayoutItemCount = 4;
    60 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;
       
    72 
    69 
    73 const TInt KMaxGranularity = 4;
    70 const TInt KMaxGranularity = 4;
    74 
    71 
    75 const TUid KTsMenuUid = { 0x101f4cd2 };
    72 const TUid KTsMenuUid = { 0x101f4cd2 };
    76 const TUid KTsHomescreenUid = { 0x102750f0 };
    73 const TUid KTsHomescreenUid = { 0x102750f0 };
    77 
       
    78 
       
    79 
    74 
    80 // -----------------------------------------------------------------------------
    75 // -----------------------------------------------------------------------------
    81 // CTsFastSwapArea::NewL
    76 // CTsFastSwapArea::NewL
    82 // -----------------------------------------------------------------------------
    77 // -----------------------------------------------------------------------------
    83 //
    78 //
   112 //
   107 //
   113 CTsFastSwapArea::CTsFastSwapArea(CCoeControl& aParent,
   108 CTsFastSwapArea::CTsFastSwapArea(CCoeControl& aParent,
   114     CTsDeviceState& aDeviceState,
   109     CTsDeviceState& aDeviceState,
   115     CTsEventControler& aEventHandler) :
   110     CTsEventControler& aEventHandler) :
   116     iParent(aParent), iDeviceState(aDeviceState), iEvtHandler(aEventHandler),
   111     iParent(aParent), iDeviceState(aDeviceState), iEvtHandler(aEventHandler),
   117     iGridItemGap(KLayoutItemGap), iIgnoreLayoutSwitch(EFalse), 
   112     iIgnoreLayoutSwitch(EFalse), iWidgetClosingCount(0), iLongTapAnimationRunning(EFalse)
   118     iSupressDrag(EFalse),iWidgetClosingCount(0),
       
   119     iLongTapAnimationRunning(EFalse)
       
   120     {
   113     {
   121     // no implementation required
   114     // no implementation required
   122     }
   115     }
   123 
   116 
   124 // -----------------------------------------------------------------------------
   117 // -----------------------------------------------------------------------------
   136     delete iRedrawTimer;
   129     delete iRedrawTimer;
   137     delete iUpdateGridTimer;
   130     delete iUpdateGridTimer;
   138     delete iOrientationSignalTimer;
   131     delete iOrientationSignalTimer;
   139     delete iLongTapAnimation;
   132     delete iLongTapAnimation;
   140     delete iLongTapAnimationTimer;
   133     delete iLongTapAnimationTimer;
   141     delete iFastSwapExt;
       
   142     iPrevScreenshots.Close();
       
   143     iPrevWgIds.Close();
       
   144     delete iEventSupressor;
       
   145     }
   134     }
   146 
   135 
   147 // -----------------------------------------------------------------------------
   136 // -----------------------------------------------------------------------------
   148 // CTsFastSwapArea::ConstructL
   137 // CTsFastSwapArea::ConstructL
   149 // -----------------------------------------------------------------------------
   138 // -----------------------------------------------------------------------------
   152     {
   141     {
   153     SetContainerWindowL( iParent );
   142     SetContainerWindowL( iParent );
   154 
   143 
   155     SetRect( aRect );
   144     SetRect( aRect );
   156 
   145 
   157     // Create utility class
       
   158     iFastSwapExt = CTsFastSwapAreaExtension::NewL( *this, *iEikonEnv );
       
   159     
       
   160     // setup grid
   146     // setup grid
   161     ReCreateGridL();
   147     ReCreateGridL();
   162 
   148 
   163     // create stylus popup instance
   149     // create stylus popup instance
   164     PreCreatePopupL();
   150     PreCreatePopupL();
   186     iLongTapAnimationTimer = new (ELeave) CTsFastSwapTimer( *this ); 
   172     iLongTapAnimationTimer = new (ELeave) CTsFastSwapTimer( *this ); 
   187     iLongTapAnimationTimer->ConstructL();
   173     iLongTapAnimationTimer->ConstructL();
   188     
   174     
   189     iActivateOnPointerRelease = TPoint();
   175     iActivateOnPointerRelease = TPoint();
   190     iHandlePointerCandidate = EFalse;
   176     iHandlePointerCandidate = EFalse;
   191     
       
   192     iEventSupressor = CAknPointerEventSuppressor::NewL();
       
   193     TSize maxTapMove(KPointerEventSuppressorMaxTapMoveWidth, 
       
   194                      KPointerEventSuppressorMaxTapMoveHeight );
       
   195     iEventSupressor->SetMaxTapMove(maxTapMove);
       
   196     iEventSupressor->SetMaxTapDuration(KPointerEventSuppressorMaxTapDuration);
       
   197     
   177     
   198     ActivateL();
   178     ActivateL();
   199     }
   179     }
   200 
   180 
   201 // -----------------------------------------------------------------------------
   181 // -----------------------------------------------------------------------------
   259 // CTsFastSwapArea::LayoutGridL
   239 // CTsFastSwapArea::LayoutGridL
   260 // --------------------------------------------------------------------------
   240 // --------------------------------------------------------------------------
   261 //
   241 //
   262 void CTsFastSwapArea::LayoutGridL()
   242 void CTsFastSwapArea::LayoutGridL()
   263     {
   243     {
   264     TSLOG_CONTEXT( CTsFastSwapArea::LayoutGridL, TSLOG_LOCAL );
       
   265     TSLOG_IN();
       
   266     
       
   267     RArray<TAknLayoutRect> rects;
   244     RArray<TAknLayoutRect> rects;
   268     CleanupClosePushL(rects);
   245     CleanupClosePushL(rects);
   269     rects.ReserveL(KLayoutItemCount);
   246     rects.ReserveL(KLayoutItemCount);
   270     iFastSwapExt->GetFastSwapAreaRects(rects);
   247     GetFastSwapAreaRects(rects);
   271     TAknLayoutRect gridAppPane = rects[0];
   248     TAknLayoutRect gridAppPane = rects[0];
   272     TAknLayoutRect gridItem = rects[1];
   249     TAknLayoutRect gridItem = rects[1];
   273     TAknLayoutRect gridImage = rects[2];
   250     TAknLayoutRect gridImage = rects[2];
   274 
   251     TAknLayoutRect gridNextItem = rects[3];
   275     CleanupStack::PopAndDestroy(&rects);
   252     CleanupStack::PopAndDestroy(&rects);
   276     
   253     
   277     TPoint position = iFastSwapExt->ItemViewPosition( SelectedIndex() );
   254     iGrid->SetRect(gridAppPane.Rect());
   278     iGrid->SetRect( CountCenteredGridRect( position ) );
       
   279 
       
   280     
       
   281     
       
   282     CTsAppUi* appUi = static_cast<CTsAppUi*>(iEikonEnv->AppUi());
       
   283     
   255     
   284     TInt variety;
   256     TInt variety;
   285     TBool disable = iFastSwapExt->GetVariety(variety);
   257     TBool disable = GetVariety(variety);
   286     if ( disable )
   258     if ( disable )
   287         {
   259         {
   288         TRAP_IGNORE(appUi->RequestPopUpL());
   260         TRAP_IGNORE(static_cast<CTsAppUi*>(iEikonEnv->AppUi())->RequestPopUpL());
   289         }
   261         }
   290     variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0; // double check to avoid layout panic
   262     variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0; // double check to avoid layout panic
   291     TSLOG1( TSLOG_INFO, "variety %d", variety );
       
   292     
   263     
   293     TAknLayoutScalableParameterLimits gridParams = 
   264     TAknLayoutScalableParameterLimits gridParams = 
   294         AknLayoutScalable_Apps::cell_tport_appsw_pane_ParamLimits( variety );
   265         AknLayoutScalable_Apps::cell_tport_appsw_pane_ParamLimits( variety );
   295     TPoint empty( ELayoutEmpty, ELayoutEmpty );
   266     TPoint empty( ELayoutEmpty, ELayoutEmpty );
   296     
   267     
   317     colors.iHighlightedText = highlightTextColor;
   288     colors.iHighlightedText = highlightTextColor;
   318     colors.iHighlightedBack = iGrid->ItemDrawer()->HighlightedBackColor();
   289     colors.iHighlightedBack = iGrid->ItemDrawer()->HighlightedBackColor();
   319     iGrid->ItemDrawer()->FormattedCellData()->SetSubCellColorsL(1, colors);
   290     iGrid->ItemDrawer()->FormattedCellData()->SetSubCellColorsL(1, colors);
   320     iGrid->SetStrokeColors(textColor, highlightTextColor);
   291     iGrid->SetStrokeColors(textColor, highlightTextColor);
   321     
   292     
       
   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         }
   322     iMaxItemsOnScreen = Rect().Width() / gridItem.Rect().Width();
   301     iMaxItemsOnScreen = Rect().Width() / gridItem.Rect().Width();
   323     if ( iMaxItemsOnScreen > 1 )
   302     if ( iMaxItemsOnScreen > 1 )
   324         {
   303         {
   325         TInt widthWithGaps =
   304         TInt widthWithGaps =
   326             (iMaxItemsOnScreen - 1) * iGridItemGap + iMaxItemsOnScreen * gridItem.Rect().Width();
   305             (iMaxItemsOnScreen - 1) * iGridItemGap + iMaxItemsOnScreen * gridItem.Rect().Width();
   328             {
   307             {
   329             iMaxItemsOnScreen--;
   308             iMaxItemsOnScreen--;
   330             }
   309             }
   331         }
   310         }
   332     iGridItemWidth = gridItem.Rect().Width();
   311     iGridItemWidth = gridItem.Rect().Width();
       
   312     
   333     // Update item drawer
   313     // Update item drawer
   334     iGrid->UpdateItemDrawerLayoutDataL();
   314     iGrid->UpdateItemDrawerLayoutDataL();
   335     
   315     
   336     // Update state
   316     // Update state
   337     HandleDeviceStateChanged( EDeviceType );
   317     HandleDeviceStateChanged( EDeviceType );
   338     
   318     
   339     if ( disable )
   319     if ( disable )
   340         {
   320         {
   341         TRAP_IGNORE(appUi->DisablePopUpL());
   321         TRAP_IGNORE(static_cast<CTsAppUi*>(iEikonEnv->AppUi())->DisablePopUpL());
   342         }
   322         }
   343     
       
   344     TSLOG_OUT();
       
   345     }
   323     }
   346 
   324 
   347 
   325 
   348 // --------------------------------------------------------------------------
   326 // --------------------------------------------------------------------------
   349 // CTsFastSwapArea::LayoutGridView
   327 // CTsFastSwapArea::LayoutGridView
   352 void CTsFastSwapArea::LayoutGridViewL( TInt aItemCount )
   330 void CTsFastSwapArea::LayoutGridViewL( TInt aItemCount )
   353     {
   331     {
   354     RArray<TAknLayoutRect> rects;
   332     RArray<TAknLayoutRect> rects;
   355     CleanupClosePushL(rects);
   333     CleanupClosePushL(rects);
   356     rects.ReserveL(KLayoutItemCount);
   334     rects.ReserveL(KLayoutItemCount);
   357     iFastSwapExt->GetFastSwapAreaRects(rects);
   335     GetFastSwapAreaRects(rects);
   358     TAknLayoutRect gridItem = rects[1];
   336     TAknLayoutRect gridItem = rects[1];
   359     CleanupStack::PopAndDestroy(&rects);
   337     CleanupStack::PopAndDestroy(&rects);
   360     if ( aItemCount )
   338     if ( aItemCount )
   361         {
   339         {
   362         iGrid->ItemDrawer()->ColumnData()->SetDrawBackground(EFalse);
   340         iGrid->ItemDrawer()->ColumnData()->SetDrawBackground(EFalse);
   380     if( iGrid->ScrollBarFrame() )
   358     if( iGrid->ScrollBarFrame() )
   381         {
   359         {
   382         iGrid->SetScrollBarFrame(NULL,CEikListBox::EOwnedExternally);
   360         iGrid->SetScrollBarFrame(NULL,CEikListBox::EOwnedExternally);
   383         }
   361         }
   384     }
   362     }
       
   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 
   385 
   405 
   386 // --------------------------------------------------------------------------
   406 // --------------------------------------------------------------------------
   387 // CTsFastSwapArea::Setup
   407 // CTsFastSwapArea::Setup
   388 // --------------------------------------------------------------------------
   408 // --------------------------------------------------------------------------
   389 //
   409 //
   532             {
   552             {
   533             iWidgetClosingCount++;
   553             iWidgetClosingCount++;
   534             }
   554             }
   535         
   555         
   536         // Orientation update
   556         // Orientation update
   537         iPrevScreenOrientation = iFastSwapExt->GetCurrentScreenOrientation();
   557         iPrevScreenOrientation = GetCurrentScreenOrientation();
   538         iOrientationSignalTimer->Cancel();
   558         iOrientationSignalTimer->Cancel();
   539         iOrientationSignalTimer->After(KOrientationSwitchTime);
   559         iOrientationSignalTimer->After(KOrientationSwitchTime);
   540         }
   560         }
   541 
   561 
   542     TSLOG_OUT();
   562     TSLOG_OUT();
   602 //
   622 //
   603 void CTsFastSwapArea::HandleFswContentChanged()
   623 void CTsFastSwapArea::HandleFswContentChanged()
   604     {
   624     {
   605     TSLOG_CONTEXT( HandleFswContentChanged, TSLOG_LOCAL );
   625     TSLOG_CONTEXT( HandleFswContentChanged, TSLOG_LOCAL );
   606     TSLOG_IN();
   626     TSLOG_IN();
   607     
   627 
   608     //prepare grid with current content from fastswap server 
   628     TRAPD( err, HandleFswContentChangedL() );
   609     GetContentForGrid();
   629     if ( err != KErrNone )
   610     // draw
   630         {
   611     UpdateGrid( ETrue, ETrue );
   631         TSLOG1( TSLOG_INFO, "leave occured: %d", err );
   612     // notify observer, if present
   632         }
   613     NotifyChange();
   633 
   614     
       
   615     TSLOG_OUT();
   634     TSLOG_OUT();
   616     }
   635     }
   617 
   636 
   618 // --------------------------------------------------------------------------
   637 // --------------------------------------------------------------------------
   619 // CTsFastSwapArea::GetContentForGrid
   638 // CTsFastSwapArea::HandleFswContentChangedL
   620 // --------------------------------------------------------------------------
   639 // --------------------------------------------------------------------------
   621 //
   640 //
   622 void CTsFastSwapArea::GetContentForGrid()
   641 void CTsFastSwapArea::HandleFswContentChangedL()
   623     {
   642     {
   624     TSLOG_CONTEXT( GetContentForGrid, TSLOG_LOCAL );
   643     TSLOG_CONTEXT( HandleFswContentChangedL, TSLOG_LOCAL );
   625     TSLOG_IN();
   644     TSLOG_IN();
   626     TRAPD( err,
   645 
   627         // get current content from fastswap server
   646     // get current content from fastswap server
   628         GetContentL();
       
   629         // prepare grid content
       
   630         RenderContentL();
       
   631     )
       
   632     if ( err != KErrNone )
       
   633         {
       
   634         TSLOG1( TSLOG_INFO, "leave occured: %d", err );
       
   635         }
       
   636 
       
   637     TSLOG_OUT();
       
   638     }
       
   639 
       
   640 // --------------------------------------------------------------------------
       
   641 // CTsFastSwapArea::GetContentL
       
   642 // --------------------------------------------------------------------------
       
   643 //
       
   644 void CTsFastSwapArea::GetContentL()
       
   645     {
       
   646     TSLOG_CONTEXT( GetContentL, TSLOG_LOCAL );
       
   647     TSLOG_IN();
       
   648     iFSClient->GetContentL( iArray );
   647     iFSClient->GetContentL( iArray );
   649     
   648 
   650     #ifdef _DEBUG
   649 #ifdef _DEBUG
   651     for ( TInt i = 0, ie = iArray.Count(); i != ie; ++i )
   650     for ( TInt i = 0, ie = iArray.Count(); i != ie; ++i )
   652         {
   651         {
   653         CTsFswEntry* e = iArray[i];
   652         CTsFswEntry* e = iArray[i];
   654         const TDesC& name( e->AppName() );
   653         const TDesC& name( e->AppName() );
   655         TSLOG4( TSLOG_INFO, "[%d]: %d %d %S", i, e->WgId(), e->AppUid(), &name );
   654         TSLOG4( TSLOG_INFO, "[%d]: %d %d %S", i, e->WgId(), e->AppUid(), &name );
   656         }
   655         }
   657     #endif
   656 #endif
   658     
   657     
   659     // Update closing widget count if necessary
   658     // Update closing widget count if necessary
   660     if ( iWidgetClosingCount )
   659     if ( iWidgetClosingCount )
   661         {
   660         {
   662         TInt widgetCount(0);
   661         TInt widgetCount(0);
   667                 widgetCount++;
   666                 widgetCount++;
   668                 }
   667                 }
   669             }
   668             }
   670         iWidgetClosingCount = widgetCount;
   669         iWidgetClosingCount = widgetCount;
   671         }
   670         }
       
   671 
       
   672     // draw
       
   673     RenderContentL();
       
   674 
       
   675     // notify observer, if present
       
   676     NotifyChange();
       
   677 
   672     TSLOG_OUT();
   678     TSLOG_OUT();
   673     }
   679     }
   674 
   680 
   675 // --------------------------------------------------------------------------
   681 // --------------------------------------------------------------------------
   676 // CTsFastSwapArea::RenderContentL
   682 // CTsFastSwapArea::RenderContentL
   677 // --------------------------------------------------------------------------
   683 // --------------------------------------------------------------------------
   678 //
   684 //
   679 void CTsFastSwapArea::RenderContentL( )
   685 void CTsFastSwapArea::RenderContentL( TBool aSuppressAnimation )
   680     {
   686     {
   681     TSLOG_CONTEXT( RenderContentL, TSLOG_LOCAL );
   687     TSLOG_CONTEXT( RenderContentL, TSLOG_LOCAL );
   682     TSLOG_IN();
   688     TSLOG_IN();
   683 
   689 
   684     _LIT(KSeparator, "\t");
   690     _LIT(KSeparator, "\t");
   685     
       
   686     // Cancel ongoing scaling
       
   687     iFastSwapExt->CancelScaleTasks();
       
   688     
   691     
   689     CArrayPtr<CGulIcon>* iconArray = new ( ELeave ) CAknIconArray( KMaxGranularity );
   692     CArrayPtr<CGulIcon>* iconArray = new ( ELeave ) CAknIconArray( KMaxGranularity );
   690     CleanupStack::PushL( iconArray );
   693     CleanupStack::PushL( iconArray );
   691     CDesCArrayFlat* textArray = new ( ELeave ) CDesCArrayFlat( KMaxGranularity );
   694     CDesCArrayFlat* textArray = new ( ELeave ) CDesCArrayFlat( KMaxGranularity );
   692     CleanupStack::PushL( textArray );
   695     CleanupStack::PushL( textArray );
   693     RArray<TInt> closeItemArray;
   696     RArray<TInt> closeItemArray;
   694     CleanupClosePushL(closeItemArray);
   697     CleanupClosePushL(closeItemArray);
   695     RArray<TInt> strokeItemArray;
   698     RArray<TInt> strokeItemArray;
   696     CleanupClosePushL(strokeItemArray);
   699     CleanupClosePushL(strokeItemArray);
   697     RArray<TInt> screenshotList;
       
   698     CleanupClosePushL(screenshotList);
       
   699     RArray<TInt> wgIdList;
       
   700     CleanupClosePushL(wgIdList);
       
   701     
   700     
   702     // Update view based on number of items
   701     // Update view based on number of items
   703     LayoutGridViewL( iArray.Count() );
   702     LayoutGridViewL( iArray.Count() );
   704     
       
   705     CArrayPtr<CGulIcon>* oldIconArray =
       
   706         iGrid->ItemDrawer()->FormattedCellData()->IconArray();
       
   707     
   703     
   708     for ( TInt i = 0; i < iArray.Count(); ++i )
   704     for ( TInt i = 0; i < iArray.Count(); ++i )
   709         {
   705         {
   710         const TDesC& appName( iArray[i]->AppName() );
   706         const TDesC& appName( iArray[i]->AppName() );
   711         const TInt formatLen = 3 + 2;
   707         const TInt formatLen = 3 + 2;
   715         formAppName.AppendNum(i);
   711         formAppName.AppendNum(i);
   716         formAppName.Append(KSeparator);
   712         formAppName.Append(KSeparator);
   717         formAppName.Append(appName);
   713         formAppName.Append(appName);
   718         textArray->AppendL(formAppName);
   714         textArray->AppendL(formAppName);
   719         CleanupStack::PopAndDestroy(&formAppName);
   715         CleanupStack::PopAndDestroy(&formAppName);
   720         
   716         TSize sz = PreferredImageSize();
       
   717 
   721         // take the screenshot or appicon+mask and make a copy and scale
   718         // take the screenshot or appicon+mask and make a copy and scale
       
   719         CFbsBitmap* bitmap = 0;
   722         TInt h = iArray[i]->ScreenshotHandle();
   720         TInt h = iArray[i]->ScreenshotHandle();
   723         TSLOG2( TSLOG_INFO, "'%S' screenshot handle %d", &appName, h );
   721         TSLOG2( TSLOG_INFO, "'%S' screenshot handle %d", &appName, h );
   724         TBool isScreenshot( ETrue );
   722         TInt maskh = 0;
       
   723         CFbsBitmap* mask = 0;
   725         if ( !h )
   724         if ( !h )
   726             {
   725             {
   727             // No screenshot, take app icon
   726             // No screenshot, take app icon
   728             h = iArray[i]->AppIconBitmapHandle();
   727             h = iArray[i]->AppIconBitmapHandle();
   729             isScreenshot = EFalse;
   728             maskh = iArray[i]->AppIconMaskHandle();
   730             TSLOG1( TSLOG_INFO, "using appicon, handle = %d", h );
   729             TSLOG1( TSLOG_INFO, "using appicon, handle = %d", h );
   731             }
   730             }
   732         else
   731         else
   733             {
   732             {
   734             // Screenshot exists, mark it for stroke
   733             // Screenshot exists, mark it for stroke
   735             strokeItemArray.AppendL(i);
   734             strokeItemArray.AppendL(i);
   736             }
   735             }
   737         __ASSERT_DEBUG( h, User::Invariant() );
   736         __ASSERT_DEBUG( h, User::Invariant() );
       
   737         bitmap = CopyBitmapL( h, sz );
       
   738         CleanupStack::PushL( bitmap );
       
   739         if ( maskh )
       
   740             {
       
   741             mask = CopyBitmapL( maskh, sz );
       
   742             }
       
   743         CleanupStack::PushL( mask );
       
   744 
       
   745         CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
       
   746         CleanupStack::PushL(icon);
       
   747         iconArray->AppendL(icon);
       
   748         CleanupStack::Pop( 3, bitmap ); // mask, bitmap, icon
   738         
   749         
   739         // check screenshot - if it exists already, use it
       
   740         // so there is no unnecessary scaling performed
       
   741         CGulIcon* icon = CreateItemIconLC( iArray[i], isScreenshot );
       
   742         iconArray->AppendL(icon);
       
   743         CleanupStack::Pop( icon ); //icon
       
   744         
       
   745         screenshotList.AppendL( h );
       
   746         wgIdList.AppendL( iArray[i]->WgId() );
       
   747                 
       
   748         // Check if item can be closed
   750         // Check if item can be closed
   749         if ( CanClose(i) && AknLayoutUtils::PenEnabled() )
   751         if ( CanClose(i) && AknLayoutUtils::PenEnabled() )
   750             {
   752             {
   751             closeItemArray.AppendL(i);
   753             closeItemArray.AppendL(i);
   752             }
   754             }
   753         }
   755         }
   754     // Update screenshot list
       
   755     iPrevScreenshots.Reset();
       
   756     iPrevWgIds.Reset();
       
   757     for ( TInt i = 0; 
       
   758             i < screenshotList.Count() && i < wgIdList.Count(); i++ )
       
   759         {
       
   760         iPrevScreenshots.AppendL( screenshotList[i] );
       
   761         iPrevWgIds.AppendL( wgIdList[i] );
       
   762         }
       
   763     CleanupStack::PopAndDestroy( &wgIdList );
       
   764     CleanupStack::PopAndDestroy( &screenshotList );
       
   765     
       
   766     // Setup grid
   756     // Setup grid
   767     iGrid->Model()->SetItemTextArray(textArray);
   757     iGrid->Model()->SetItemTextArray(textArray);
       
   758     CArrayPtr<CGulIcon>* oldIconArray =
       
   759         iGrid->ItemDrawer()->FormattedCellData()->IconArray();
   768     if(oldIconArray)
   760     if(oldIconArray)
   769         {
   761         {
   770         delete oldIconArray;
   762         delete oldIconArray;
   771         oldIconArray = NULL;
   763         oldIconArray = NULL;
   772         }
   764         }
   791     iEvtHandler.ReInitPhysicsL( GridWorldSize(), ViewSize(), ETrue );
   783     iEvtHandler.ReInitPhysicsL( GridWorldSize(), ViewSize(), ETrue );
   792     if ( SelectedIndex() >= GridItemCount() && GridItemCount() )
   784     if ( SelectedIndex() >= GridItemCount() && GridItemCount() )
   793         {
   785         {
   794         iGrid->SetCurrentDataIndex( GridItemCount() - 1 );
   786         iGrid->SetCurrentDataIndex( GridItemCount() - 1 );
   795         }
   787         }
       
   788     UpdateGrid( ETrue, !aSuppressAnimation );
       
   789     
   796     TSLOG_OUT();
   790     TSLOG_OUT();
   797     }
   791     }
   798 
   792 
   799 // --------------------------------------------------------------------------
   793 // --------------------------------------------------------------------------
   800 // CTsFastSwapArea::CreateItemIconLC
   794 // CTsFastSwapArea::CopyBitmapL
   801 // --------------------------------------------------------------------------
   795 // Copy and scale.
   802 //
   796 // --------------------------------------------------------------------------
   803 CGulIcon* CTsFastSwapArea::CreateItemIconLC( CTsFswEntry* aEntry,
   797 //
   804                 TBool aIsScreenshot )
   798 CFbsBitmap* CTsFastSwapArea::CopyBitmapL( TInt aFbsHandle, TSize aSize )
   805     {
   799     {
   806     TSize sz = iFastSwapExt->PreferredImageSize();
   800     CFbsBitmap* ret = new (ELeave) CFbsBitmap();
   807     CArrayPtr<CGulIcon>* oldIconArray =
   801     CleanupStack::PushL( ret );
   808             iGrid->ItemDrawer()->FormattedCellData()->IconArray();
   802 
   809     
   803     CFbsBitmap* bmp = new (ELeave) CFbsBitmap();
   810     CFbsBitmap* bitmap = NULL;
   804     CleanupStack::PushL( bmp );
   811     CFbsBitmap* mask = NULL;
   805     User::LeaveIfError( bmp->Duplicate( aFbsHandle ) );
   812     
   806 
   813     TInt h = 0;
   807     // do not always use aSize, preserving the aspect ratio is quite
   814     TInt maskh = 0;
   808     // important when showing app icons instead of screenshots
   815     if ( aIsScreenshot )
   809     TSize sz = CalculateSizePreserveRatio( aSize, bmp->SizeInPixels() );
   816         {
   810     User::LeaveIfError( ret->Create( sz, bmp->DisplayMode() ) );
   817         h = aEntry->ScreenshotHandle();
   811 
   818         }
   812     AknIconUtils::ScaleBitmapL( sz, ret, bmp );
   819     else
   813 
   820         {
   814     CleanupStack::PopAndDestroy( bmp );
   821         h = aEntry->AppIconBitmapHandle();
   815     CleanupStack::Pop( ret );
   822         maskh = aEntry->AppIconMaskHandle();
   816 
   823         }
   817     return ret;
   824         
   818     }
   825     TInt idx = iPrevScreenshots.Find( h );
       
   826     TInt wgIdIdx = iPrevWgIds.Find( aEntry->WgId() );
       
   827         
       
   828     if ( idx != KErrNotFound && idx == wgIdIdx 
       
   829             && oldIconArray && idx < oldIconArray->Count() )
       
   830         {
       
   831         CGulIcon* existingIcon = oldIconArray->At( idx );
       
   832         if ( existingIcon->Bitmap() )
       
   833             {
       
   834             bitmap = iFastSwapExt->DuplicateBitmapLC(
       
   835                     existingIcon->Bitmap()->Handle() );
       
   836             if ( existingIcon->Mask() )
       
   837                 {
       
   838                 maskh = existingIcon->Mask()->Handle();
       
   839                 mask = iFastSwapExt->DuplicateBitmapLC( maskh );
       
   840                 }
       
   841             }
       
   842         }
       
   843     else if ( idx == KErrNotFound && wgIdIdx != KErrNotFound
       
   844             && oldIconArray && wgIdIdx < oldIconArray->Count() )
       
   845         {
       
   846         CGulIcon* existingIcon = oldIconArray->At( wgIdIdx );
       
   847         if ( existingIcon->Bitmap() 
       
   848                 && !existingIcon->Mask() )
       
   849             {
       
   850             bitmap = iFastSwapExt->DuplicateBitmapLC(
       
   851                     existingIcon->Bitmap()->Handle() );
       
   852             CFbsBitmap* source = iFastSwapExt->DuplicateBitmapLC( h );
       
   853             iFastSwapExt->ScaleBitmapL( source, bitmap );
       
   854             CleanupStack::Pop( source );
       
   855             }
       
   856         }
       
   857     
       
   858     // create bitmap for grid item
       
   859     if ( !bitmap )
       
   860         {
       
   861         bitmap = iFastSwapExt->CopyBitmapL( h, sz, aIsScreenshot );
       
   862         CleanupStack::PushL( bitmap );
       
   863         }
       
   864     if ( !mask && maskh )
       
   865         {
       
   866         mask = iFastSwapExt->CopyBitmapL( maskh, sz, EFalse );
       
   867         CleanupStack::PushL( mask );
       
   868         }
       
   869     else if ( !mask )
       
   870         {
       
   871         CleanupStack::PushL( mask );
       
   872         }
       
   873     
       
   874     CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
       
   875     CleanupStack::Pop( 2, bitmap );
       
   876     CleanupStack::PushL( icon );
       
   877     return icon;
       
   878     }
       
   879 
       
   880 
   819 
   881 // --------------------------------------------------------------------------
   820 // --------------------------------------------------------------------------
   882 // CTsFastSwapArea::CountComponentControls
   821 // CTsFastSwapArea::CountComponentControls
   883 // --------------------------------------------------------------------------
   822 // --------------------------------------------------------------------------
   884 //
   823 //
   950     else
   889     else
   951         {
   890         {
   952         iGrid->ShowHighlight();
   891         iGrid->ShowHighlight();
   953         }
   892         }
   954     
   893     
   955     //prepare grid with current content from fastswap server
   894     // get the current task list
   956     GetContentForGrid();    
   895     HandleFswContentChanged();
   957     //restore default selection
       
   958     RestoreSelectedIndex();
       
   959     // draw
       
   960     UpdateGrid( ETrue, EFalse );
       
   961     // notify observer, if present
       
   962     NotifyChange();
       
   963     // and then start listening for changes
   896     // and then start listening for changes
   964     iFSClient->Subscribe( *this );
   897     iFSClient->Subscribe( *this );
   965     
   898     
       
   899     RestoreSelectedIndex();
       
   900     UpdateGrid(EFalse, EFalse);
       
   901     
   966     iRedrawTimer->Cancel();
   902     iRedrawTimer->Cancel();
   967     iRedrawTimer->After(KRedrawTime);
   903     iRedrawTimer->After(KRedrawTime);
   968     
   904     
   969     // give feedback
   905     // give feedback
   970     iFastSwapExt->LaunchPopupFeedback();
   906     LaunchPopupFeedback();
   971     
   907     
   972     iPrevAppCount = iArray.Count();
   908     iPrevAppCount = iArray.Count();
   973     
   909     
   974     if ( !appUi->DelayedForegroundLaunched() )
   910     if ( !appUi->DelayedForegroundLaunched() )
   975         {
   911         {
  1111 // CTsFastSwapArea::HandlePointerEventL
  1047 // CTsFastSwapArea::HandlePointerEventL
  1112 // -----------------------------------------------------------------------------
  1048 // -----------------------------------------------------------------------------
  1113 //
  1049 //
  1114 void CTsFastSwapArea::HandlePointerEventL( const TPointerEvent& aPointerEvent )
  1050 void CTsFastSwapArea::HandlePointerEventL( const TPointerEvent& aPointerEvent )
  1115     {
  1051     {
  1116     TBool supressed = iEventSupressor->SuppressPointerEvent( aPointerEvent );
       
  1117     iKeyEvent = EFalse;
  1052     iKeyEvent = EFalse;
  1118     if(aPointerEvent.iType == TPointerEvent::EButton1Down)
  1053     if(aPointerEvent.iType == TPointerEvent::EButton1Down)
  1119         {
  1054         {
  1120         iSupressDrag = EFalse;
       
  1121         iHandlePointerCandidate = ETrue;
  1055         iHandlePointerCandidate = ETrue;
  1122         iTapEvent = aPointerEvent;
  1056         iTapEvent = aPointerEvent;
  1123         iGrid->EnableAknEventHandling(EFalse);
  1057         iGrid->EnableAknEventHandling(EFalse);
  1124         iGrid->HandlePointerEventL(aPointerEvent);
  1058         iGrid->HandlePointerEventL(aPointerEvent);
  1125         iGrid->EnableAknEventHandling(ETrue);
  1059         iGrid->EnableAknEventHandling(ETrue);
  1128             {
  1062             {
  1129             iLongTapAnimationTimer->Cancel();
  1063             iLongTapAnimationTimer->Cancel();
  1130             iLongTapAnimationTimer->After(KLongTapAnimationInitTime);
  1064             iLongTapAnimationTimer->After(KLongTapAnimationInitTime);
  1131             }
  1065             }
  1132         }
  1066         }
  1133     else if( aPointerEvent.iType == TPointerEvent::EDrag )
       
  1134         {
       
  1135         iSupressDrag = supressed;
       
  1136         }
       
  1137     else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
  1067     else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
  1138         {
  1068         {
  1139         CancelLongTapAnimation( EFalse );
  1069         CancelLongTapAnimation( EFalse );
  1140         if( iActivateOnPointerRelease != TPoint() )
  1070         if( iActivateOnPointerRelease != TPoint() )
  1141             {
  1071             {
  1142             iHandlePointerCandidate = ETrue;
  1072             iHandlePointerCandidate = ETrue;
  1143             TapL( iActivateOnPointerRelease );
  1073             TapL(iActivateOnPointerRelease);
  1144             iActivateOnPointerRelease = TPoint();
  1074             iActivateOnPointerRelease = TPoint();
  1145             }
       
  1146         else if( iSupressDrag )
       
  1147             {
       
  1148             iSupressDrag = EFalse;
       
  1149             iHandlePointerCandidate = ETrue;
       
  1150             TapL( iTapEvent.iParentPosition );
       
  1151             }
  1075             }
  1152         }
  1076         }
  1153     }
  1077     }
  1154 
  1078 
  1155 // -----------------------------------------------------------------------------
  1079 // -----------------------------------------------------------------------------
  1275         {
  1199         {
  1276         UpdateGrid(ETrue, ETrue);
  1200         UpdateGrid(ETrue, ETrue);
  1277         }
  1201         }
  1278     else if ( aSource == iOrientationSignalTimer )
  1202     else if ( aSource == iOrientationSignalTimer )
  1279         {
  1203         {
  1280         TInt currentOrientation = iFastSwapExt->GetCurrentScreenOrientation();
  1204         TInt currentOrientation = GetCurrentScreenOrientation();
  1281         if ( currentOrientation != iPrevScreenOrientation )
  1205         if ( currentOrientation != iPrevScreenOrientation )
  1282             {
  1206             {
  1283             // Order layout change
  1207             // Order layout change
  1284             static_cast<CAknAppUi*>(iCoeEnv->AppUi())->HandleResourceChangeL(KEikDynamicLayoutVariantSwitch);
  1208             static_cast<CAknAppUi*>(iCoeEnv->AppUi())->HandleResourceChangeL(KEikDynamicLayoutVariantSwitch);
  1285             iRedrawTimer->Cancel();
  1209             iRedrawTimer->Cancel();
  1349 
  1273 
  1350     if(showPopUp)
  1274     if(showPopUp)
  1351         {
  1275         {
  1352         static_cast<CTsAppUi*>(iEikonEnv->AppUi())->RequestPopUpL();
  1276         static_cast<CTsAppUi*>(iEikonEnv->AppUi())->RequestPopUpL();
  1353         // give feedback
  1277         // give feedback
  1354         iFastSwapExt->LaunchPopupFeedback();
  1278         LaunchPopupFeedback();
  1355         // save index for later use & show popup
  1279         // save index for later use & show popup
  1356         iAppIndexForPopup = aIndex;
  1280         iAppIndexForPopup = aIndex;
  1357         iPopup->SetPosition( aPoint, CAknStylusPopUpMenu::EPositionTypeLeftBottom );
  1281         iPopup->SetPosition( aPoint, CAknStylusPopUpMenu::EPositionTypeLeftBottom );
  1358         iPopup->ShowMenu();
  1282         iPopup->ShowMenu();
  1359         }
  1283         }
  1391         iDcObserver->DataChanged( this, Count() );
  1315         iDcObserver->DataChanged( this, Count() );
  1392         }
  1316         }
  1393     }
  1317     }
  1394     
  1318     
  1395 // -----------------------------------------------------------------------------
  1319 // -----------------------------------------------------------------------------
       
  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 // -----------------------------------------------------------------------------
  1396 // CTsFastSwapArea::GridItemCount
  1338 // CTsFastSwapArea::GridItemCount
  1397 // -----------------------------------------------------------------------------
  1339 // -----------------------------------------------------------------------------
  1398 //
  1340 //
  1399 TInt CTsFastSwapArea::GridItemCount()
  1341 TInt CTsFastSwapArea::GridItemCount()
  1400     {
  1342     {
  1401     return iGrid->Model()->ItemTextArray()->MdcaCount();
  1343     return iGrid->Model()->ItemTextArray()->MdcaCount();
  1402     }
       
  1403 
       
  1404 
       
  1405 // -----------------------------------------------------------------------------
       
  1406 // CTsFastSwapArea::GridItemCount
       
  1407 // -----------------------------------------------------------------------------
       
  1408 //
       
  1409 TInt CTsFastSwapArea::GetGridItemData( TsFastSwapAreaGridData aDataType )
       
  1410     {
       
  1411     TInt retVal;
       
  1412     switch ( aDataType )
       
  1413         {
       
  1414         case EMaxItemsOnScreen:
       
  1415             retVal = iMaxItemsOnScreen;
       
  1416             break;
       
  1417         case EGridItemWidth:
       
  1418             retVal = iGridItemWidth;
       
  1419             break;
       
  1420         case EGridItemGap:
       
  1421             retVal = iGridItemGap;
       
  1422             break;
       
  1423         default:
       
  1424             retVal = KErrArgument;
       
  1425             break;
       
  1426         }
       
  1427     return retVal;
       
  1428     }
  1344     }
  1429 
  1345 
  1430 // -----------------------------------------------------------------------------
  1346 // -----------------------------------------------------------------------------
  1431 // CTsFastSwapArea::HandleListBoxEventL
  1347 // CTsFastSwapArea::HandleListBoxEventL
  1432 // -----------------------------------------------------------------------------
  1348 // -----------------------------------------------------------------------------
  1453                 break;
  1369                 break;
  1454             }
  1370             }
  1455         }
  1371         }
  1456     }
  1372     }
  1457 
  1373 
       
  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     }
  1458 
  1393 
  1459 // --------------------------------------------------------------------------
  1394 // --------------------------------------------------------------------------
  1460 // CTsFastSwapArea::SelectNextItem
  1395 // CTsFastSwapArea::SelectNextItem
  1461 // --------------------------------------------------------------------------
  1396 // --------------------------------------------------------------------------
  1462 //
  1397 //
  1484 //
  1419 //
  1485 void CTsFastSwapArea::CenterItem(TInt aRedrawDelay)
  1420 void CTsFastSwapArea::CenterItem(TInt aRedrawDelay)
  1486     {
  1421     {
  1487     if( iMaxItemsOnScreen < GridItemCount() )
  1422     if( iMaxItemsOnScreen < GridItemCount() )
  1488         {
  1423         {
  1489         TInt visibleItem = iFastSwapExt->ViewToVisibleItem( ViewPos() );
  1424         TInt visibleItem = ViewToVisibleItem( ViewPos() );
  1490         if(iKeyEvent)
  1425         if(iKeyEvent)
  1491             {
  1426             {
  1492             visibleItem = SelectedIndex();
  1427             visibleItem = SelectedIndex();
  1493             }
  1428             }
  1494         if(visibleItem != SelectedIndex())
  1429         if(visibleItem != SelectedIndex())
  1525 // CTsFastSwapArea::UpdateGrid
  1460 // CTsFastSwapArea::UpdateGrid
  1526 // --------------------------------------------------------------------------
  1461 // --------------------------------------------------------------------------
  1527 //
  1462 //
  1528 void CTsFastSwapArea::UpdateGrid( TBool aForceRedraw, TBool aAnimate )
  1463 void CTsFastSwapArea::UpdateGrid( TBool aForceRedraw, TBool aAnimate )
  1529     {
  1464     {
  1530     TPoint targetPoint = iFastSwapExt->ItemViewPosition( SelectedIndex() );
  1465     TPoint targetPoint = ItemViewPosition( SelectedIndex() );
  1531     if ( aForceRedraw || targetPoint.iX != ViewPos().iX )
  1466     if ( aForceRedraw || targetPoint.iX != ViewPos().iX )
  1532         {
  1467         {
  1533         if ( aAnimate )
  1468         if ( aAnimate )
  1534             {
  1469             {
  1535             iEvtHandler.Animate( targetPoint );
  1470             iEvtHandler.Animate( targetPoint );
  1591 		iUpdateGridTimer->After(KUpdateGridTime);
  1526 		iUpdateGridTimer->After(KUpdateGridTime);
  1592     	}
  1527     	}
  1593     
  1528     
  1594     if ( aDrawNow )
  1529     if ( aDrawNow )
  1595         {
  1530         {
  1596         TRect gridViewRect = CountCenteredGridRect( aPoint );
  1531         TInt currentXPos = aPoint.iX;
       
  1532         currentXPos -= Rect().Width() / 2;
       
  1533         TRect gridViewRect = Rect();
       
  1534         gridViewRect.iTl.iX = -currentXPos;
       
  1535         // Take edge offset into account
       
  1536         gridViewRect.iTl.iX += Rect().iTl.iX;
       
  1537         if(GridItemCount() && GridItemCount() <= iMaxItemsOnScreen)
       
  1538             {
       
  1539             // Center view
       
  1540             gridViewRect.iTl.iX += ( Rect().Width() - GridItemCount() * iGridItemWidth ) / 2;
       
  1541             }
  1597         //iParent.DrawDeferred();
  1542         //iParent.DrawDeferred();
  1598         iGrid->DrawDeferred();
  1543         iGrid->DrawDeferred();
  1599         iGrid->SetRect( gridViewRect );
  1544         iGrid->SetRect( gridViewRect );
  1600         iLogicalViewPosOffset = 0;
  1545         iLogicalViewPosOffset = 0;
  1601         }
  1546         }
  1653         iGrid->SetCurrentItemIndex(index);
  1598         iGrid->SetCurrentItemIndex(index);
  1654         SaveSelectedIndex();
  1599         SaveSelectedIndex();
  1655         if ( !ShowPopupL(iSavedSelectedIndex, aPoint) )
  1600         if ( !ShowPopupL(iSavedSelectedIndex, aPoint) )
  1656             {
  1601             {
  1657             iActivateOnPointerRelease = aPoint;
  1602             iActivateOnPointerRelease = aPoint;
  1658             }
       
  1659         else
       
  1660             {
       
  1661             iSupressDrag = EFalse;
       
  1662             }
  1603             }
  1663         iGrid->ShowHighlight();
  1604         iGrid->ShowHighlight();
  1664         DrawNow();
  1605         DrawNow();
  1665         }
  1606         }
  1666 	iHandlePointerCandidate = EFalse;
  1607 	iHandlePointerCandidate = EFalse;
  1703     CenterItem( KUpdateGridTime );
  1644     CenterItem( KUpdateGridTime );
  1704     DrawDeferred();
  1645     DrawDeferred();
  1705     }
  1646     }
  1706 
  1647 
  1707 // -----------------------------------------------------------------------------
  1648 // -----------------------------------------------------------------------------
  1708 // CTsFastSwapArea::ViewPos
  1649 // CTsFastSwapArea::ViewSize
  1709 // -----------------------------------------------------------------------------
  1650 // -----------------------------------------------------------------------------
  1710 //
  1651 //
  1711 TPoint CTsFastSwapArea::ViewPos() const
  1652 TPoint CTsFastSwapArea::ViewPos() const
  1712     {
  1653     {
  1713     TPoint retVal;
  1654     TPoint retVal;
  1721         }
  1662         }
  1722     retVal.iX += iLogicalViewPosOffset;
  1663     retVal.iX += iLogicalViewPosOffset;
  1723     return retVal;
  1664     return retVal;
  1724     }
  1665     }
  1725 
  1666 
       
  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     }
  1726 
  1872 
  1727 // -----------------------------------------------------------------------------
  1873 // -----------------------------------------------------------------------------
  1728 // CTsFastSwapArea::IsAppClosing
  1874 // CTsFastSwapArea::IsAppClosing
  1729 // -----------------------------------------------------------------------------
  1875 // -----------------------------------------------------------------------------
  1730 //
  1876 //
  1776         }
  1922         }
  1777     else if ( aWgId == homescrWgId )
  1923     else if ( aWgId == homescrWgId )
  1778         {
  1924         {
  1779         retVal = ETrue;
  1925         retVal = ETrue;
  1780         }
  1926         }
  1781     
       
  1782     iPrevAppCount = appCount;
  1927     iPrevAppCount = appCount;
  1783     return retVal;
  1928     return retVal;
  1784     }
  1929     }
  1785 
  1930 
  1786 // -----------------------------------------------------------------------------
  1931 // -----------------------------------------------------------------------------
  1821             }
  1966             }
  1822         }
  1967         }
  1823     return EFalse;
  1968     return EFalse;
  1824     }
  1969     }
  1825 
  1970 
  1826 // -----------------------------------------------------------------------------
       
  1827 // CTsFastSwapArea::CountCenteredGridRect
       
  1828 // -----------------------------------------------------------------------------
       
  1829 //
       
  1830 TRect CTsFastSwapArea::CountCenteredGridRect( TPoint aItemPosition)
       
  1831     {
       
  1832     TInt currentXPos = aItemPosition.iX;
       
  1833     currentXPos -= Rect().Width() / 2;
       
  1834     TRect gridViewRect = Rect();
       
  1835     gridViewRect.iTl.iX = -currentXPos;
       
  1836     // Take edge offset into account
       
  1837     gridViewRect.iTl.iX += Rect().iTl.iX;
       
  1838     if(GridItemCount() && GridItemCount() <= iMaxItemsOnScreen)
       
  1839         {
       
  1840         // Center view
       
  1841         gridViewRect.iTl.iX += ( Rect().Width() - GridItemCount() * iGridItemWidth ) / 2;
       
  1842         }
       
  1843     return gridViewRect;
       
  1844     }
       
  1845 
       
  1846 // End of file
  1971 // End of file