taskswitcher/taskswitcherui/taskswitcherapp/src/tsfastswaparea.cpp
branchRCL_3
changeset 35 3321d3e205b6
parent 34 5456b4e8b3a8
--- a/taskswitcher/taskswitcherui/taskswitcherapp/src/tsfastswaparea.cpp	Wed Sep 01 12:32:46 2010 +0100
+++ b/taskswitcher/taskswitcherui/taskswitcherapp/src/tsfastswaparea.cpp	Tue Sep 14 20:58:58 2010 +0300
@@ -28,12 +28,11 @@
 #include <aknlayoutscalable_apps.cdl.h>
 #include <layoutmetadata.cdl.h>
 #include <aknlists.h>
-#include <touchfeedback.h>
-#include <akntransitionutils.h>
-#include <akntranseffect.h>
 #include <aknlongtapanimation.h>
+#include <aknpointereventsuppressor.h>
 
 #include "tsfastswaparea.h"
+#include "tsfastswapareautils.h"
 #include "tsapplogging.h"
 #include "tsfswclient.h"
 #include "tsappui.h"
@@ -58,6 +57,7 @@
 const TInt KAppKeyTypeLong = 2;
 
 const TInt KLayoutItemCount = 4;
+const TInt KLayoutItemGap = 0;
 
 const TInt KRedrawTime = 250000; // 0.25 sec
 const TInt KRedrawTimeForLayoutSwitch = 700000; // 0.7 sec
@@ -66,12 +66,17 @@
 const TInt KOrientationSwitchTime = 1000000; // 1 sec
 const TInt KLongTapAnimationInitTime = 150000; // 0.15 sec
 const TInt KLongTapAnimationTimeout = 1000000; // 1 sec
+const TInt KPointerEventSuppressorMaxTapDuration = 400000;	// 0.4 sec
+const TInt KPointerEventSuppressorMaxTapMoveWidth = 3;
+const TInt KPointerEventSuppressorMaxTapMoveHeight = 8;
 
 const TInt KMaxGranularity = 4;
 
 const TUid KTsMenuUid = { 0x101f4cd2 };
 const TUid KTsHomescreenUid = { 0x102750f0 };
 
+
+
 // -----------------------------------------------------------------------------
 // CTsFastSwapArea::NewL
 // -----------------------------------------------------------------------------
@@ -109,7 +114,9 @@
     CTsDeviceState& aDeviceState,
     CTsEventControler& aEventHandler) :
     iParent(aParent), iDeviceState(aDeviceState), iEvtHandler(aEventHandler),
-    iIgnoreLayoutSwitch(EFalse), iWidgetClosingCount(0), iLongTapAnimationRunning(EFalse)
+    iGridItemGap(KLayoutItemGap), iIgnoreLayoutSwitch(EFalse), 
+    iSupressDrag(EFalse),iWidgetClosingCount(0),
+    iLongTapAnimationRunning(EFalse)
     {
     // no implementation required
     }
@@ -131,6 +138,9 @@
     delete iOrientationSignalTimer;
     delete iLongTapAnimation;
     delete iLongTapAnimationTimer;
+    delete iFastSwapExt;
+    iPrevScreenshots.Close();
+    delete iEventSupressor;
     }
 
 // -----------------------------------------------------------------------------
@@ -143,6 +153,9 @@
 
     SetRect( aRect );
 
+    // Create utility class
+    iFastSwapExt = CTsFastSwapAreaExtension::NewL( *this, *iEikonEnv );
+    
     // setup grid
     ReCreateGridL();
 
@@ -175,6 +188,12 @@
     iActivateOnPointerRelease = TPoint();
     iHandlePointerCandidate = EFalse;
     
+    iEventSupressor = CAknPointerEventSuppressor::NewL();
+    TSize maxTapMove(KPointerEventSuppressorMaxTapMoveWidth, 
+                     KPointerEventSuppressorMaxTapMoveHeight );
+    iEventSupressor->SetMaxTapMove(maxTapMove);
+    iEventSupressor->SetMaxTapDuration(KPointerEventSuppressorMaxTapDuration);
+    
     ActivateL();
     }
 
@@ -241,25 +260,31 @@
 //
 void CTsFastSwapArea::LayoutGridL()
     {
+    TSLOG_CONTEXT( CTsFastSwapArea::LayoutGridL, TSLOG_LOCAL );
+    TSLOG_IN();
+    
     RArray<TAknLayoutRect> rects;
     CleanupClosePushL(rects);
     rects.ReserveL(KLayoutItemCount);
-    GetFastSwapAreaRects(rects);
+    iFastSwapExt->GetFastSwapAreaRects(rects);
     TAknLayoutRect gridAppPane = rects[0];
     TAknLayoutRect gridItem = rects[1];
     TAknLayoutRect gridImage = rects[2];
-    TAknLayoutRect gridNextItem = rects[3];
+
     CleanupStack::PopAndDestroy(&rects);
     
     iGrid->SetRect(gridAppPane.Rect());
     
+    CTsAppUi* appUi = static_cast<CTsAppUi*>(iEikonEnv->AppUi());
+    
     TInt variety;
-    TBool disable = GetVariety(variety);
+    TBool disable = iFastSwapExt->GetVariety(variety);
     if ( disable )
         {
-        TRAP_IGNORE(static_cast<CTsAppUi*>(iEikonEnv->AppUi())->RequestPopUpL());
+        TRAP_IGNORE(appUi->RequestPopUpL());
         }
     variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0; // double check to avoid layout panic
+    TSLOG1( TSLOG_INFO, "variety %d", variety );
     
     TAknLayoutScalableParameterLimits gridParams = 
         AknLayoutScalable_Apps::cell_tport_appsw_pane_ParamLimits( variety );
@@ -290,14 +315,6 @@
     iGrid->ItemDrawer()->FormattedCellData()->SetSubCellColorsL(1, colors);
     iGrid->SetStrokeColors(textColor, highlightTextColor);
     
-    if ( AknLayoutUtils::LayoutMirrored() )
-        {
-        iGridItemGap = gridItem.Rect().iTl.iX - gridNextItem.Rect().iBr.iX;
-        }
-    else
-        {
-        iGridItemGap = gridNextItem.Rect().iTl.iX - gridItem.Rect().iBr.iX;
-        }
     iMaxItemsOnScreen = Rect().Width() / gridItem.Rect().Width();
     if ( iMaxItemsOnScreen > 1 )
         {
@@ -309,7 +326,6 @@
             }
         }
     iGridItemWidth = gridItem.Rect().Width();
-    
     // Update item drawer
     iGrid->UpdateItemDrawerLayoutDataL();
     
@@ -318,8 +334,10 @@
     
     if ( disable )
         {
-        TRAP_IGNORE(static_cast<CTsAppUi*>(iEikonEnv->AppUi())->DisablePopUpL());
+        TRAP_IGNORE(appUi->DisablePopUpL());
         }
+    
+    TSLOG_OUT();
     }
 
 
@@ -332,7 +350,7 @@
     RArray<TAknLayoutRect> rects;
     CleanupClosePushL(rects);
     rects.ReserveL(KLayoutItemCount);
-    GetFastSwapAreaRects(rects);
+    iFastSwapExt->GetFastSwapAreaRects(rects);
     TAknLayoutRect gridItem = rects[1];
     CleanupStack::PopAndDestroy(&rects);
     if ( aItemCount )
@@ -361,48 +379,6 @@
         }
     }
 
-
-// --------------------------------------------------------------------------
-// CTsFastSwapArea::GetFastSwapAreaRects
-// --------------------------------------------------------------------------
-//
-void CTsFastSwapArea::GetFastSwapAreaRects( RArray<TAknLayoutRect>& aRects )
-    {
-    TAknLayoutRect gridAppPane;
-    TAknLayoutRect gridItem;
-    TAknLayoutRect gridImage;
-    TAknLayoutRect gridNextItem;
-    
-    TInt variety;
-    TBool disable = GetVariety(variety);
-    if ( disable )
-        {
-        TRAP_IGNORE(static_cast<CTsAppUi*>(iEikonEnv->AppUi())->RequestPopUpL());
-        }
-    variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0; // double check to avoid layout panic
-    
-    gridAppPane.LayoutRect( Rect(), 
-            AknLayoutScalable_Apps::tport_appsw_pane( variety ) );
-    aRects.Append(gridAppPane);
-    
-    gridItem.LayoutRect( gridAppPane.Rect(),
-            AknLayoutScalable_Apps::cell_tport_appsw_pane( variety, 0, 0 ) );
-    aRects.Append(gridItem);
-    
-    gridImage.LayoutRect( gridItem.Rect(),
-            AknLayoutScalable_Apps::cell_tport_appsw_pane_g1( variety ) ); 
-    aRects.Append(gridImage);
-    gridNextItem.LayoutRect( gridAppPane.Rect(),
-            AknLayoutScalable_Apps::cell_tport_appsw_pane_cp03( variety ) );
-    aRects.Append(gridNextItem);
-    
-    if ( disable )
-        {
-        TRAP_IGNORE(static_cast<CTsAppUi*>(iEikonEnv->AppUi())->DisablePopUpL());
-        }
-    }
-
-
 // --------------------------------------------------------------------------
 // CTsFastSwapArea::Setup
 // --------------------------------------------------------------------------
@@ -554,7 +530,7 @@
             }
         
         // Orientation update
-        iPrevScreenOrientation = GetCurrentScreenOrientation();
+        iPrevScreenOrientation = iFastSwapExt->GetCurrentScreenOrientation();
         iOrientationSignalTimer->Cancel();
         iOrientationSignalTimer->After(KOrientationSwitchTime);
         }
@@ -624,8 +600,31 @@
     {
     TSLOG_CONTEXT( HandleFswContentChanged, TSLOG_LOCAL );
     TSLOG_IN();
+    
+    //prepare grid with current content from fastswap server 
+    GetContentForGrid();
+    // draw
+    UpdateGrid( ETrue, ETrue );
+    // notify observer, if present
+    NotifyChange();
+    
+    TSLOG_OUT();
+    }
 
-    TRAPD( err, HandleFswContentChangedL() );
+// --------------------------------------------------------------------------
+// CTsFastSwapArea::GetContentForGrid
+// --------------------------------------------------------------------------
+//
+void CTsFastSwapArea::GetContentForGrid()
+    {
+    TSLOG_CONTEXT( GetContentForGrid, TSLOG_LOCAL );
+    TSLOG_IN();
+    TRAPD( err,
+        // get current content from fastswap server
+        GetContentL();
+        // prepare grid content
+        RenderContentL();
+    )
     if ( err != KErrNone )
         {
         TSLOG1( TSLOG_INFO, "leave occured: %d", err );
@@ -635,25 +634,23 @@
     }
 
 // --------------------------------------------------------------------------
-// CTsFastSwapArea::HandleFswContentChangedL
+// CTsFastSwapArea::GetContentL
 // --------------------------------------------------------------------------
 //
-void CTsFastSwapArea::HandleFswContentChangedL()
+void CTsFastSwapArea::GetContentL()
     {
-    TSLOG_CONTEXT( HandleFswContentChangedL, TSLOG_LOCAL );
+    TSLOG_CONTEXT( GetContentL, TSLOG_LOCAL );
     TSLOG_IN();
-
-    // get current content from fastswap server
     iFSClient->GetContentL( iArray );
-
-#ifdef _DEBUG
+    
+    #ifdef _DEBUG
     for ( TInt i = 0, ie = iArray.Count(); i != ie; ++i )
         {
         CTsFswEntry* e = iArray[i];
         const TDesC& name( e->AppName() );
         TSLOG4( TSLOG_INFO, "[%d]: %d %d %S", i, e->WgId(), e->AppUid(), &name );
         }
-#endif
+    #endif
     
     // Update closing widget count if necessary
     if ( iWidgetClosingCount )
@@ -668,13 +665,6 @@
             }
         iWidgetClosingCount = widgetCount;
         }
-
-    // draw
-    RenderContentL();
-
-    // notify observer, if present
-    NotifyChange();
-
     TSLOG_OUT();
     }
 
@@ -682,13 +672,16 @@
 // CTsFastSwapArea::RenderContentL
 // --------------------------------------------------------------------------
 //
-void CTsFastSwapArea::RenderContentL( TBool aSuppressAnimation )
+void CTsFastSwapArea::RenderContentL( )
     {
     TSLOG_CONTEXT( RenderContentL, TSLOG_LOCAL );
     TSLOG_IN();
 
     _LIT(KSeparator, "\t");
     
+    // Cancel ongoing scaling
+    iFastSwapExt->CancelScaleTasks();
+    
     CArrayPtr<CGulIcon>* iconArray = new ( ELeave ) CAknIconArray( KMaxGranularity );
     CleanupStack::PushL( iconArray );
     CDesCArrayFlat* textArray = new ( ELeave ) CDesCArrayFlat( KMaxGranularity );
@@ -697,10 +690,15 @@
     CleanupClosePushL(closeItemArray);
     RArray<TInt> strokeItemArray;
     CleanupClosePushL(strokeItemArray);
+    RArray<TInt> screenshotList;
+    CleanupClosePushL(screenshotList);
     
     // Update view based on number of items
     LayoutGridViewL( iArray.Count() );
     
+    CArrayPtr<CGulIcon>* oldIconArray =
+        iGrid->ItemDrawer()->FormattedCellData()->IconArray();
+    
     for ( TInt i = 0; i < iArray.Count(); ++i )
         {
         const TDesC& appName( iArray[i]->AppName() );
@@ -713,19 +711,21 @@
         formAppName.Append(appName);
         textArray->AppendL(formAppName);
         CleanupStack::PopAndDestroy(&formAppName);
-        TSize sz = PreferredImageSize();
-
+        TSize sz = iFastSwapExt->PreferredImageSize();
+        
         // take the screenshot or appicon+mask and make a copy and scale
         CFbsBitmap* bitmap = 0;
         TInt h = iArray[i]->ScreenshotHandle();
         TSLOG2( TSLOG_INFO, "'%S' screenshot handle %d", &appName, h );
         TInt maskh = 0;
         CFbsBitmap* mask = 0;
+        TBool isScreenshot( ETrue );
         if ( !h )
             {
             // No screenshot, take app icon
             h = iArray[i]->AppIconBitmapHandle();
             maskh = iArray[i]->AppIconMaskHandle();
+            isScreenshot = EFalse;
             TSLOG1( TSLOG_INFO, "using appicon, handle = %d", h );
             }
         else
@@ -734,11 +734,31 @@
             strokeItemArray.AppendL(i);
             }
         __ASSERT_DEBUG( h, User::Invariant() );
-        bitmap = CopyBitmapL( h, sz );
+        
+        // check screenshot - if it exists already, use it
+        // so there is no unnecessary scaling performed
+        screenshotList.AppendL( h );
+        TInt idx = iPrevScreenshots.Find( h );
+        if ( idx != KErrNotFound && oldIconArray && idx < oldIconArray->Count() )
+            {
+            CGulIcon* existingIcon = oldIconArray->At( idx );
+            if ( existingIcon->Bitmap() )
+                {
+                h = existingIcon->Bitmap()->Handle();
+                if ( existingIcon->Mask() )
+                    {
+                    maskh = existingIcon->Mask()->Handle();
+                    }
+                isScreenshot = EFalse;
+                }
+            }
+        
+        // create bitmap for grid item
+        bitmap = iFastSwapExt->CopyBitmapL( h, sz, isScreenshot );
         CleanupStack::PushL( bitmap );
         if ( maskh )
             {
-            mask = CopyBitmapL( maskh, sz );
+            mask = iFastSwapExt->CopyBitmapL( maskh, sz, EFalse );
             }
         CleanupStack::PushL( mask );
 
@@ -753,10 +773,16 @@
             closeItemArray.AppendL(i);
             }
         }
+    // Update screenshot list
+    iPrevScreenshots.Reset();
+    for ( TInt i = 0; i < screenshotList.Count(); i++ )
+        {
+        iPrevScreenshots.AppendL( screenshotList[i] );
+        }
+    CleanupStack::PopAndDestroy( &screenshotList );
+    
     // Setup grid
     iGrid->Model()->SetItemTextArray(textArray);
-    CArrayPtr<CGulIcon>* oldIconArray =
-        iGrid->ItemDrawer()->FormattedCellData()->IconArray();
     if(oldIconArray)
         {
         delete oldIconArray;
@@ -785,37 +811,9 @@
         {
         iGrid->SetCurrentDataIndex( GridItemCount() - 1 );
         }
-    UpdateGrid( ETrue, !aSuppressAnimation );
-    
     TSLOG_OUT();
     }
 
-// --------------------------------------------------------------------------
-// CTsFastSwapArea::CopyBitmapL
-// Copy and scale.
-// --------------------------------------------------------------------------
-//
-CFbsBitmap* CTsFastSwapArea::CopyBitmapL( TInt aFbsHandle, TSize aSize )
-    {
-    CFbsBitmap* ret = new (ELeave) CFbsBitmap();
-    CleanupStack::PushL( ret );
-
-    CFbsBitmap* bmp = new (ELeave) CFbsBitmap();
-    CleanupStack::PushL( bmp );
-    User::LeaveIfError( bmp->Duplicate( aFbsHandle ) );
-
-    // do not always use aSize, preserving the aspect ratio is quite
-    // important when showing app icons instead of screenshots
-    TSize sz = CalculateSizePreserveRatio( aSize, bmp->SizeInPixels() );
-    User::LeaveIfError( ret->Create( sz, bmp->DisplayMode() ) );
-
-    AknIconUtils::ScaleBitmapL( sz, ret, bmp );
-
-    CleanupStack::PopAndDestroy( bmp );
-    CleanupStack::Pop( ret );
-
-    return ret;
-    }
 
 // --------------------------------------------------------------------------
 // CTsFastSwapArea::CountComponentControls
@@ -891,19 +889,22 @@
         iGrid->ShowHighlight();
         }
     
-    // get the current task list
-    HandleFswContentChanged();
+    //prepare grid with current content from fastswap server
+    GetContentForGrid();    
+    //restore default selection
+    RestoreSelectedIndex();
+    // draw
+    UpdateGrid( ETrue, EFalse );
+    // notify observer, if present
+    NotifyChange();
     // and then start listening for changes
     iFSClient->Subscribe( *this );
     
-    RestoreSelectedIndex();
-    UpdateGrid(EFalse, EFalse);
-    
     iRedrawTimer->Cancel();
     iRedrawTimer->After(KRedrawTime);
     
     // give feedback
-    LaunchPopupFeedback();
+    iFastSwapExt->LaunchPopupFeedback();
     
     iPrevAppCount = iArray.Count();
     
@@ -1049,9 +1050,11 @@
 //
 void CTsFastSwapArea::HandlePointerEventL( const TPointerEvent& aPointerEvent )
     {
+    TBool supressed = iEventSupressor->SuppressPointerEvent( aPointerEvent );
     iKeyEvent = EFalse;
     if(aPointerEvent.iType == TPointerEvent::EButton1Down)
         {
+        iSupressDrag = EFalse;
         iHandlePointerCandidate = ETrue;
         iTapEvent = aPointerEvent;
         iGrid->EnableAknEventHandling(EFalse);
@@ -1064,10 +1067,15 @@
             iLongTapAnimationTimer->After(KLongTapAnimationInitTime);
             }
         }
+    else if( aPointerEvent.iType == TPointerEvent::EDrag )
+        {
+        iSupressDrag = supressed;
+        }
     else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
         {
         CancelLongTapAnimation( EFalse );
-        if( iActivateOnPointerRelease != TPoint() )
+        if( iActivateOnPointerRelease != TPoint() ||
+            iSupressDrag)
             {
             iHandlePointerCandidate = ETrue;
             TapL(iActivateOnPointerRelease);
@@ -1201,7 +1209,7 @@
         }
     else if ( aSource == iOrientationSignalTimer )
         {
-        TInt currentOrientation = GetCurrentScreenOrientation();
+        TInt currentOrientation = iFastSwapExt->GetCurrentScreenOrientation();
         if ( currentOrientation != iPrevScreenOrientation )
             {
             // Order layout change
@@ -1275,7 +1283,7 @@
         {
         static_cast<CTsAppUi*>(iEikonEnv->AppUi())->RequestPopUpL();
         // give feedback
-        LaunchPopupFeedback();
+        iFastSwapExt->LaunchPopupFeedback();
         // save index for later use & show popup
         iAppIndexForPopup = aIndex;
         iPopup->SetPosition( aPoint, CAknStylusPopUpMenu::EPositionTypeLeftBottom );
@@ -1317,24 +1325,6 @@
     }
     
 // -----------------------------------------------------------------------------
-// CTsFastSwapArea::PreferredImageSize
-// -----------------------------------------------------------------------------
-//
-TSize CTsFastSwapArea::PreferredImageSize()
-    {
-    TAknLayoutRect gridImage;
-    TRAP_IGNORE(
-        RArray<TAknLayoutRect> rects;
-        CleanupClosePushL(rects);
-        rects.ReserveL(KLayoutItemCount);
-        GetFastSwapAreaRects(rects);
-        gridImage = rects[2];
-        CleanupStack::PopAndDestroy(&rects);
-        );
-    return gridImage.Rect().Size();
-    }
-    
-// -----------------------------------------------------------------------------
 // CTsFastSwapArea::GridItemCount
 // -----------------------------------------------------------------------------
 //
@@ -1343,6 +1333,32 @@
     return iGrid->Model()->ItemTextArray()->MdcaCount();
     }
 
+
+// -----------------------------------------------------------------------------
+// CTsFastSwapArea::GridItemCount
+// -----------------------------------------------------------------------------
+//
+TInt CTsFastSwapArea::GetGridItemData( TsFastSwapAreaGridData aDataType )
+    {
+    TInt retVal;
+    switch ( aDataType )
+        {
+        case EMaxItemsOnScreen:
+            retVal = iMaxItemsOnScreen;
+            break;
+        case EGridItemWidth:
+            retVal = iGridItemWidth;
+            break;
+        case EGridItemGap:
+            retVal = iGridItemGap;
+            break;
+        default:
+            retVal = KErrArgument;
+            break;
+        }
+    return retVal;
+    }
+
 // -----------------------------------------------------------------------------
 // CTsFastSwapArea::HandleListBoxEventL
 // -----------------------------------------------------------------------------
@@ -1371,25 +1387,6 @@
         }
     }
 
-// --------------------------------------------------------------------------
-// CTsFastSwapArea::CalculateSizePreserveRatio
-// --------------------------------------------------------------------------
-//
-TSize CTsFastSwapArea::CalculateSizePreserveRatio(
-        const TSize& aTargetAreaSize,
-        const TSize& aSourceSize )
-    {
-    const TReal 
-      resizedAspectRatio(aTargetAreaSize.iWidth/(TReal)aTargetAreaSize.iHeight);
-    const TReal 
-      orginalAspectRatio(aSourceSize.iWidth/(TReal)aSourceSize.iHeight);
-    //this condition avoid empty margins ( bigger output ). to realy fit area change it
-    const TReal scaleFactor = 
-        ( orginalAspectRatio > resizedAspectRatio ) ? 
-        (aTargetAreaSize.iHeight /(TReal)aSourceSize.iHeight) ://scale by height
-        (aTargetAreaSize.iWidth /(TReal)aSourceSize.iWidth) ;//scale by width
-    return TSize(aSourceSize.iWidth * scaleFactor, aSourceSize.iHeight * scaleFactor);
-    }
 
 // --------------------------------------------------------------------------
 // CTsFastSwapArea::SelectNextItem
@@ -1421,7 +1418,7 @@
     {
     if( iMaxItemsOnScreen < GridItemCount() )
         {
-        TInt visibleItem = ViewToVisibleItem( ViewPos() );
+        TInt visibleItem = iFastSwapExt->ViewToVisibleItem( ViewPos() );
         if(iKeyEvent)
             {
             visibleItem = SelectedIndex();
@@ -1462,7 +1459,7 @@
 //
 void CTsFastSwapArea::UpdateGrid( TBool aForceRedraw, TBool aAnimate )
     {
-    TPoint targetPoint = ItemViewPosition( SelectedIndex() );
+    TPoint targetPoint = iFastSwapExt->ItemViewPosition( SelectedIndex() );
     if ( aForceRedraw || targetPoint.iX != ViewPos().iX )
         {
         if ( aAnimate )
@@ -1646,7 +1643,7 @@
     }
 
 // -----------------------------------------------------------------------------
-// CTsFastSwapArea::ViewSize
+// CTsFastSwapArea::ViewPos
 // -----------------------------------------------------------------------------
 //
 TPoint CTsFastSwapArea::ViewPos() const
@@ -1664,211 +1661,6 @@
     return retVal;
     }
 
-// -----------------------------------------------------------------------------
-// CTsFastSwapArea::ItemPosition
-// -----------------------------------------------------------------------------
-//
-TPoint CTsFastSwapArea::ItemViewPosition( TInt aItemIdx )
-    {
-    TPoint retVal = Rect().iTl;
-    if ( aItemIdx < 0 )
-        {
-        // No items
-        retVal.iX = 0;
-        }
-    else if ( aItemIdx == 0 )
-        {
-        // First item
-        if( AknLayoutUtils::LayoutMirrored() )
-            {
-            if ( GridItemCount() > iMaxItemsOnScreen )
-                {
-                retVal.iX = GridWorldSize().iWidth - Rect().Width();
-                }
-            else
-                {
-                retVal.iX = 0;
-                }
-            }
-        else // normal layout
-            {
-            retVal.iX = 0;
-            }
-        }
-    else if ( aItemIdx == GridItemCount() - 1 )
-        {
-        // Last item selected
-        if( AknLayoutUtils::LayoutMirrored() )
-            {
-            retVal.iX = 0;
-            }
-        else // normal layout
-            {
-            if ( GridItemCount() > iMaxItemsOnScreen )
-                {
-                retVal.iX = GridWorldSize().iWidth - Rect().Width();
-                }
-            else
-                {
-                retVal.iX = 0;
-                }
-            }
-        }
-    else
-        {
-        // Middle item
-        TInt screenMiddleItemOffset = ( Rect().Width() - iGridItemWidth ) / 2;
-        if( AknLayoutUtils::LayoutMirrored() )
-            {
-            retVal.iX = iGridItemWidth * ( GridItemCount() - 1 - aItemIdx ) - screenMiddleItemOffset;
-            retVal.iX += ( GridItemCount() - 1 - aItemIdx ) * iGridItemGap;
-            }
-        else // normal layout
-            {
-            retVal.iX = iGridItemWidth * aItemIdx - screenMiddleItemOffset;
-            retVal.iX += iGridItemGap * aItemIdx;
-            }
-        if ( retVal.iX < 0 )
-            {
-            retVal.iX = 0;
-            }
-        else if ( retVal.iX + Rect().Width() > GridWorldSize().iWidth )
-            {
-            retVal.iX = GridWorldSize().iWidth - Rect().Width();
-            }
-        }
-    
-    // Return middle of the view rectangle
-    retVal.iX += Rect().Width() / 2;
-    
-    return retVal;
-    }
-
-// -----------------------------------------------------------------------------
-// CTsFastSwapArea::ViewToVisibleItem
-// -----------------------------------------------------------------------------
-//
-TInt CTsFastSwapArea::ViewToVisibleItem( const TPoint aViewPos )
-    {
-    TInt retVal(0);
-    TPoint absViewPos = aViewPos;
-    absViewPos.iX -= Rect().Width() / 2;
-    if ( absViewPos.iX < 0 )
-        {
-        if ( AknLayoutUtils::LayoutMirrored() )
-            {
-            // View crossed left border of grid world rect, last item selected
-            retVal = GridItemCount() - 1;
-            }
-        else // normal layout
-            {
-            // View crossed left border of grid world rect, first item selected
-            retVal = 0;
-            }
-        }
-    else if ( absViewPos.iX + Rect().Width() > GridWorldSize().iWidth )
-        {
-        if ( AknLayoutUtils::LayoutMirrored() )
-            {
-            // View crossed right border of grid world rect, first item selected
-            retVal = 0;
-            }
-        else // normal layout
-            {
-            // View crossed right border of grid world rect, last item selected
-            retVal = GridItemCount() - 1;
-            }
-        }
-    else
-        {
-        TInt retItemPosX(0);
-        TInt offsetCheck = GridWorldSize().iWidth;
-        // View inside of grid world rect
-        for ( TInt i = 0 ; i < GridItemCount(); i++ )
-            {
-            TInt itemPosX = ItemViewPosition( i ).iX;
-            TInt offset = aViewPos.iX - itemPosX;
-            if ( Abs( offset ) <= offsetCheck )
-                {
-                offsetCheck = Abs( offset );
-                retVal = i;
-                retItemPosX = itemPosX;
-                }
-            else
-                {
-                break;
-                }
-            }
-        // Check if item is fully visible. If not
-        // return next one if possible
-        if ( retItemPosX - iGridItemWidth / 2 < absViewPos.iX &&
-             retVal + 1 < GridItemCount() )
-            {
-            retVal++;
-            }
-        }
-    
-    return retVal;
-    }
-
-
-// -----------------------------------------------------------------------------
-// CTsFastSwapArea::LaunchPopupFeedback
-// -----------------------------------------------------------------------------
-//
-void CTsFastSwapArea::LaunchPopupFeedback()
-    {
-    if ( AknLayoutUtils::PenEnabled() )
-        {
-        MTouchFeedback* feedback = MTouchFeedback::Instance();
-        if ( feedback )
-            {
-            TTouchLogicalFeedback fbLogicalType = ETouchFeedbackPopUp;
-            if ( CAknTransitionUtils::TransitionsEnabled(
-                 AknTransEffect::EComponentTransitionsOff ) )
-                {
-                fbLogicalType = ETouchFeedbackIncreasingPopUp;
-                }
-            feedback->InstantFeedback( this,
-                                       fbLogicalType,
-                                       ETouchFeedbackVibra,
-                                       TPointerEvent() );
-            }
-        }
-    }
-
-
-// -----------------------------------------------------------------------------
-// CTsFastSwapArea::GetCurrentScreenOrientation
-// -----------------------------------------------------------------------------
-//
-TInt CTsFastSwapArea::GetCurrentScreenOrientation()
-    {
-    TPixelsAndRotation availableRect;
-    iEikonEnv->ScreenDevice()->GetDefaultScreenSizeAndRotation(availableRect);
-    return availableRect.iPixelSize.iWidth > availableRect.iPixelSize.iHeight;
-    }
-
-
-// -----------------------------------------------------------------------------
-// CTsFastSwapArea::GetVariety
-// -----------------------------------------------------------------------------
-//
-TBool CTsFastSwapArea::GetVariety( TInt& aVariety )
-    {
-    aVariety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0;
-    TBool foreground = static_cast<CTsAppUi*>(iEikonEnv->AppUi())->IsForeground();
-    if ( foreground )
-        {
-        TInt screenOrientation = GetCurrentScreenOrientation();
-        if ( aVariety != screenOrientation )
-            {
-            aVariety = screenOrientation;
-            return ETrue;
-            }
-        }
-    return EFalse;
-    }
 
 // -----------------------------------------------------------------------------
 // CTsFastSwapArea::IsAppClosing
@@ -1924,6 +1716,7 @@
         {
         retVal = ETrue;
         }
+    
     iPrevAppCount = appCount;
     return retVal;
     }