taskswitcher/taskswitcherui/taskswitcherapp/src/tsfastswapgrid.cpp
branchRCL_3
changeset 83 5456b4e8b3a8
child 88 3321d3e205b6
equal deleted inserted replaced
82:5f0182e07bfb 83:5456b4e8b3a8
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Taskswitcher Fast Swap area UI
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <avkon.mbg>
       
    20 #include <aknlayoutscalable_apps.cdl.h>
       
    21 #include <layoutmetadata.cdl.h>
       
    22 #include <AknsFrameBackgroundControlContext.h>
       
    23 #include <touchfeedback.h>
       
    24 
       
    25 #include "tsfastswapgrid.h"
       
    26 #include "tsapplogging.h"
       
    27 
       
    28  /* ================================================================================
       
    29   * CTsFastSwapGrid
       
    30   * ================================================================================
       
    31   */
       
    32 
       
    33 const TInt KCloseIconRedrawTime = 300000; // 0.3 second
       
    34 
       
    35 const TInt KStrokeThickness = 1;
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CTsFastSwapGrid::CTsFastSwapGrid
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CTsFastSwapGrid::CTsFastSwapGrid()
       
    42 : CAknGrid(),
       
    43   iCloseIconHitIdx( KErrNotFound ),
       
    44   iBehaviour( ETouchOnly ),
       
    45   iHighlightVisible( EFalse ),
       
    46   iAknEventHandlingEnabled(ETrue)
       
    47     {
       
    48     }
       
    49 
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CTsFastSwapGrid::~CTsFastSwapGrid
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CTsFastSwapGrid::~CTsFastSwapGrid()
       
    56     {
       
    57     iCloseItems.Close();
       
    58     delete iCloseIconRedrawTimer;
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CTsFastSwapGrid::ConstructL
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 void CTsFastSwapGrid::ConstructL( const CCoeControl* aParent )
       
    66     {
       
    67     TSLOG_CONTEXT( CTsFastSwapGrid::ConstructL, TSLOG_LOCAL );
       
    68     TSLOG_IN();
       
    69     
       
    70     iParent = aParent;
       
    71     CAknGrid::ConstructL( aParent, EAknListBoxSelectionGrid );
       
    72     SetPrimaryScrollingType(CAknGridView::EScrollFollowsItemsAndLoops);
       
    73     SetSecondaryScrollingType(CAknGridView::EScrollFollowsItemsAndLoops);
       
    74     iCloseIconRedrawTimer = new (ELeave) CTsFastSwapTimer( *this );
       
    75     iCloseIconRedrawTimer->ConstructL();
       
    76     
       
    77     TSLOG_OUT();
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CTsFastSwapGrid::HandlePointerEventL
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CTsFastSwapGrid::HandlePointerEventL( const TPointerEvent &aPointerEvent )
       
    85     {
       
    86     TSLOG_CONTEXT( CTsFastSwapGrid::HandlePointerEventL, TSLOG_LOCAL );
       
    87     TSLOG_IN();
       
    88     
       
    89     TBool eventHandled( EFalse );
       
    90     if ( aPointerEvent.iType == TPointerEvent::EButton1Up ||
       
    91          aPointerEvent.iType == TPointerEvent::EButton1Down )
       
    92         {
       
    93         // Check if close icon has been hit
       
    94         // Find hit item
       
    95         TInt hitItem( KErrNotFound );
       
    96         for ( TInt i = 0; i < Model()->NumberOfItems(); i++ )
       
    97             {
       
    98             if ( GridView()->XYPosToItemIndex( aPointerEvent.iParentPosition, i ) )
       
    99                 {
       
   100                 hitItem = i;
       
   101                 break;
       
   102                 }
       
   103             }
       
   104         if ( hitItem != KErrNotFound && CanCloseItem( hitItem ) )
       
   105             {
       
   106             // Item found, check if close icon has been hit
       
   107             TPoint itemPos = GridView()->ItemPos( hitItem );
       
   108             TSize itemSize = GridView()->ItemSize( hitItem );
       
   109             TRect itemRect( itemPos, itemSize );
       
   110             CTsGridItemDrawer* itemDrawer =
       
   111                 static_cast<CTsGridItemDrawer*>( ItemDrawer() );
       
   112             TRect closeIconRect = itemDrawer->GetCloseButtonRect( itemRect );
       
   113             if ( closeIconRect.Contains( aPointerEvent.iParentPosition ) )
       
   114                 {
       
   115                 // Close icon hit
       
   116                 TInt hitDataIdx(hitItem);
       
   117                 if ( AknLayoutUtils::LayoutMirrored() )
       
   118                     {
       
   119                     // Calculate logical item index
       
   120                     hitDataIdx = Model()->ItemTextArray()->MdcaCount() - 1 - hitItem;
       
   121                     }
       
   122                 iCloseIconHitIdx = hitDataIdx;
       
   123                 eventHandled = ETrue;
       
   124                 
       
   125                 if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   126                     {
       
   127                     // Update current item and redraw grid
       
   128                     SetCurrentItemIndex( hitItem );
       
   129                     DrawNow();
       
   130                     
       
   131                     iCloseIconRedrawTimer->Cancel();
       
   132                     iCloseIconRedrawTimer->After(KCloseIconRedrawTime);
       
   133                     }
       
   134                 else
       
   135                     {
       
   136                     // Pointer up
       
   137                     if ( iFastSwapGridObserver )
       
   138                         {
       
   139                         MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   140                         feedback->InstantFeedback(this,
       
   141                                                   ETouchFeedbackBasicButton, 
       
   142                                                   ETouchFeedbackVibra, 
       
   143                                                   aPointerEvent);
       
   144                         }
       
   145                     if ( GridBehaviour() == EHybrid )
       
   146                         {
       
   147                         ShowHighlight();
       
   148                         }
       
   149                     else
       
   150                         {
       
   151                         Redraw();
       
   152                         }
       
   153                     iFastSwapGridObserver->HandleCloseEventL( hitDataIdx );
       
   154                     ResetCloseHit();
       
   155                     }
       
   156                 }
       
   157             }
       
   158         }
       
   159     
       
   160     if ( !eventHandled )
       
   161         {
       
   162         CTsGridItemDrawer* itemDrawer =
       
   163             static_cast<CTsGridItemDrawer*>( ItemDrawer() );
       
   164         if( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   165             {
       
   166             itemDrawer->SetRedrawBackground( ETrue );
       
   167             }
       
   168         else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   169             {
       
   170             itemDrawer->SetRedrawBackground( EFalse );
       
   171             }
       
   172         if ( iAknEventHandlingEnabled )
       
   173             {
       
   174             CAknGrid::HandlePointerEventL( aPointerEvent );
       
   175             }
       
   176         Redraw();
       
   177         }
       
   178     
       
   179     TSLOG_OUT();
       
   180     }
       
   181 
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CTsFastSwapGrid::HandleDeviceStateChanged
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 void CTsFastSwapGrid::HandleDeviceStateChanged( TChangeType aChangeType )
       
   188     {
       
   189     TSLOG_CONTEXT( CTsFastSwapGrid::HandleDeviceStateChanged, TSLOG_LOCAL );
       
   190     TSLOG_IN();
       
   191     
       
   192     if ( aChangeType == ESkin )
       
   193         {
       
   194         LoadCloseIconAndStrokeParams();
       
   195         }
       
   196     
       
   197     TSLOG_OUT();
       
   198     }
       
   199 
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CTsFastSwapGrid::HandleResourceChange
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 void CTsFastSwapGrid::HandleResourceChange( TInt aType )
       
   206     {
       
   207     TSLOG_CONTEXT( CTsFastSwapGrid::HandleResourceChange, TSLOG_LOCAL );
       
   208     TSLOG_IN();
       
   209     
       
   210     if ( aType != KEikDynamicLayoutVariantSwitch &&
       
   211          Model()->ItemTextArray()->MdcaCount() )
       
   212         {
       
   213         CAknGrid::HandleResourceChange( aType );
       
   214         }
       
   215     
       
   216     TSLOG_OUT();
       
   217     }
       
   218 
       
   219 
       
   220 // -----------------------------------------------------------------------------
       
   221 // CTsFastSwapGrid::SizeChanged
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 void CTsFastSwapGrid::SizeChanged()
       
   225     {
       
   226     }
       
   227 
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CTsFastSwapGrid::Draw
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 void CTsFastSwapGrid::Draw( const TRect& aRect ) const
       
   234     {
       
   235     CAknGrid::Draw(aRect);
       
   236     if ( !Model()->ItemTextArray()->MdcaCount() )
       
   237         {
       
   238         GridView()->DrawEmptyList();
       
   239         }
       
   240     }
       
   241 
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // CTsFastSwapGrid::SetFastSwapGridObserver
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 void CTsFastSwapGrid::SetFastSwapGridObserver( MTsFastSwapGridObserver* aObserver )
       
   248     {
       
   249     iFastSwapGridObserver = aObserver;
       
   250     }
       
   251 
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // CTsFastSwapGrid::CreateItemDrawerL
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 void CTsFastSwapGrid::CreateItemDrawerL()
       
   258     {
       
   259     TSLOG_CONTEXT( CTsFastSwapGrid::CreateItemDrawerL, TSLOG_LOCAL );
       
   260     TSLOG_IN();
       
   261     
       
   262     CFormattedCellGridData* data = CFormattedCellGridData::NewL();
       
   263     CleanupStack::PushL( data );
       
   264     CTsGridItemDrawer* itemDrawer =
       
   265         new ( ELeave ) CTsGridItemDrawer( this, data );
       
   266     iItemDrawer = itemDrawer;
       
   267     CleanupStack::Pop( data );
       
   268     
       
   269     TSLOG_OUT();
       
   270     }
       
   271 
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 // CTsFastSwapGrid::UpdateItemDrawerLayoutDataL
       
   275 // -----------------------------------------------------------------------------
       
   276 //
       
   277 void CTsFastSwapGrid::UpdateItemDrawerLayoutDataL()
       
   278     {
       
   279     CTsGridItemDrawer* itemDrawer =
       
   280         static_cast<CTsGridItemDrawer*>( ItemDrawer() );
       
   281     
       
   282     TPixelsAndRotation screenSize;
       
   283     iEikonEnv->ScreenDevice()->GetDefaultScreenSizeAndRotation(screenSize);
       
   284     TRect availableRect = TRect( TPoint(0,0), screenSize.iPixelSize );
       
   285     itemDrawer->SetScreenRect(availableRect);
       
   286     
       
   287     TAknLayoutRect fastSwapAreaPane;
       
   288     TInt variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0;
       
   289     fastSwapAreaPane.LayoutRect( availableRect,
       
   290             AknLayoutScalable_Apps::tport_appsw_pane( variety ) );
       
   291     const TInt leftOffset = iParent->Rect().iTl.iX;
       
   292     const TInt rightOffset = availableRect.Width() - iParent->Rect().iBr.iX;
       
   293     SetVisibleViewRect(fastSwapAreaPane.Rect());
       
   294     itemDrawer->SetEdgeOffset( leftOffset, rightOffset );
       
   295     
       
   296     LoadCloseIconAndStrokeParams();
       
   297     }
       
   298 
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CTsFastSwapGrid::EnableAknEventHandling
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 void CTsFastSwapGrid::EnableAknEventHandling( TBool aEnable )
       
   305     {
       
   306     iAknEventHandlingEnabled = aEnable;
       
   307     }
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // CTsFastSwapGrid::TimerCompletedL
       
   311 // -----------------------------------------------------------------------------
       
   312 //
       
   313 void CTsFastSwapGrid::TimerCompletedL( CTsFastSwapTimer* aSource )
       
   314     {
       
   315     if ( aSource == iCloseIconRedrawTimer )
       
   316         {
       
   317         ResetCloseHit();
       
   318         }
       
   319     }
       
   320 
       
   321 // -----------------------------------------------------------------------------
       
   322 // CTsFastSwapGrid::SetCloseItemsL
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 void CTsFastSwapGrid::SetCloseItemsL( RArray<TInt>& aItemIndex )
       
   326     {
       
   327     iCloseItems.Close();
       
   328     for ( TInt i = 0; i < aItemIndex.Count(); i++ )
       
   329         {
       
   330         iCloseItems.AppendL( aItemIndex[i] );
       
   331         }
       
   332     }
       
   333 
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // CTsFastSwapGrid::CanCloseItem
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 TBool CTsFastSwapGrid::CanCloseItem( TInt aItemIndex )
       
   340     {
       
   341     return iCloseItems.Find(aItemIndex) != KErrNotFound;
       
   342     }
       
   343 
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // CTsFastSwapGrid::ItemCloseHit
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 TBool CTsFastSwapGrid::IsItemCloseHit( TInt aItemIndex )
       
   350     {
       
   351     return iCloseIconHitIdx == aItemIndex;
       
   352     }
       
   353 
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // CTsFastSwapGrid::ResetCloseHit
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 void CTsFastSwapGrid::ResetCloseHit()
       
   360     {
       
   361     iCloseIconHitIdx = KErrNotFound;
       
   362     }
       
   363 
       
   364 
       
   365 // -----------------------------------------------------------------------------
       
   366 // CTsFastSwapGrid::SetStrokeColor
       
   367 // -----------------------------------------------------------------------------
       
   368 //
       
   369 void CTsFastSwapGrid::SetStrokeColors( TRgb aColor,
       
   370                                        TRgb aHighlightedColor )
       
   371     {
       
   372     static_cast<CTsGridItemDrawer*>(iItemDrawer)->SetStrokeColors(aColor, aHighlightedColor);
       
   373     }
       
   374 
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // CTsFastSwapGrid::SetStrokeItemsL
       
   378 // -----------------------------------------------------------------------------
       
   379 //
       
   380 void CTsFastSwapGrid::SetStrokeItemsL( RArray<TInt>& aItemIndex )
       
   381     {
       
   382     static_cast<CTsGridItemDrawer*>(iItemDrawer)->SetStrokeItemsL(aItemIndex);
       
   383     }
       
   384 
       
   385 
       
   386 // -----------------------------------------------------------------------------
       
   387 // CTsFastSwapGrid::SetBehaviour
       
   388 // -----------------------------------------------------------------------------
       
   389 //
       
   390 void CTsFastSwapGrid::SetGridBehaviour( TFastSwapGridBehaviour aBehaviour )
       
   391     {
       
   392     iBehaviour = aBehaviour;
       
   393     switch ( iBehaviour )
       
   394         {
       
   395         case ETouchOnly:
       
   396             {
       
   397             HideHighlight();
       
   398             }
       
   399             break;
       
   400         default:
       
   401             {
       
   402             ShowHighlight();
       
   403             }
       
   404             break;
       
   405         }
       
   406     }
       
   407 
       
   408 
       
   409 // -----------------------------------------------------------------------------
       
   410 // CTsFastSwapGrid::GridBehaviour
       
   411 // -----------------------------------------------------------------------------
       
   412 //
       
   413 CTsFastSwapGrid::TFastSwapGridBehaviour CTsFastSwapGrid::GridBehaviour()
       
   414     {
       
   415     return iBehaviour;
       
   416     }
       
   417 
       
   418 
       
   419 // -----------------------------------------------------------------------------
       
   420 // CTsFastSwapGrid::ShowHighlight
       
   421 // -----------------------------------------------------------------------------
       
   422 //
       
   423 void CTsFastSwapGrid::ShowHighlight()
       
   424     {
       
   425     if ( !iHighlightVisible )
       
   426         {
       
   427         // Draw highlight
       
   428         iHighlightVisible = ETrue;
       
   429         Redraw();
       
   430         }
       
   431     }
       
   432 
       
   433 
       
   434 // -----------------------------------------------------------------------------
       
   435 // CTsFastSwapGrid::HideHighlight
       
   436 // -----------------------------------------------------------------------------
       
   437 //
       
   438 void CTsFastSwapGrid::HideHighlight()
       
   439     {
       
   440     if ( iHighlightVisible )
       
   441         {
       
   442         iHighlightVisible = EFalse;
       
   443         Redraw();
       
   444         }
       
   445     }
       
   446 
       
   447 
       
   448 // -----------------------------------------------------------------------------
       
   449 // CTsFastSwapGrid::IsHighlightVisible
       
   450 // -----------------------------------------------------------------------------
       
   451 //
       
   452 TBool CTsFastSwapGrid::IsHighlightVisible()
       
   453     {
       
   454     return iHighlightVisible;
       
   455     }
       
   456 
       
   457 
       
   458 // -----------------------------------------------------------------------------
       
   459 // CTsFastSwapGrid::SetVisibleViewRect
       
   460 // -----------------------------------------------------------------------------
       
   461 //
       
   462 void CTsFastSwapGrid::SetVisibleViewRect( const TRect aRect )
       
   463     {
       
   464     iVisibleViewRect = aRect;
       
   465     }
       
   466 
       
   467 
       
   468 // -----------------------------------------------------------------------------
       
   469 // CTsFastSwapGrid::VisibleViewRect
       
   470 // -----------------------------------------------------------------------------
       
   471 //
       
   472 TRect CTsFastSwapGrid::VisibleViewRect()
       
   473     {
       
   474     TRect retVal;
       
   475     TRect emptyRect = TRect( 0, 0, 0, 0 );
       
   476     if ( iVisibleViewRect == emptyRect )
       
   477         {
       
   478         retVal = Rect();
       
   479         }
       
   480     else
       
   481         {
       
   482         retVal = iVisibleViewRect;
       
   483         }
       
   484     return retVal;
       
   485     }
       
   486 
       
   487 
       
   488 // -----------------------------------------------------------------------------
       
   489 // CTsFastSwapGrid::LoadCloseIconAndStrokeParams
       
   490 // -----------------------------------------------------------------------------
       
   491 //
       
   492 void CTsFastSwapGrid::LoadCloseIconAndStrokeParams()
       
   493     {
       
   494     // Load and set close icon
       
   495     CFbsBitmap* icon = NULL;
       
   496     CFbsBitmap* iconMask = NULL;
       
   497     CFbsBitmap* iconPressed = NULL;
       
   498     CFbsBitmap* iconPressedMask = NULL;
       
   499     
       
   500     TRAP_IGNORE(AknsUtils::CreateIconL( AknsUtils::SkinInstance(),
       
   501                 KAknsIIDQgnIndiTsButtonClose,
       
   502                 icon,
       
   503                 iconMask,
       
   504                 KAvkonBitmapFile,
       
   505                 EMbmAvkonQgn_indi_button_preview_close,
       
   506                 EMbmAvkonQgn_indi_button_preview_close_mask
       
   507                 ));
       
   508     
       
   509     TRAP_IGNORE(AknsUtils::CreateIconL( AknsUtils::SkinInstance(),
       
   510                 KAknsIIDQgnIndiTsButtonClosePressed,
       
   511                 iconPressed,
       
   512                 iconPressedMask,
       
   513                 KAvkonBitmapFile,
       
   514                 EMbmAvkonQgn_indi_button_preview_close,
       
   515                 EMbmAvkonQgn_indi_button_preview_close_mask
       
   516                 ));
       
   517 
       
   518     TAknLayoutRect gridAppPane;
       
   519     TAknLayoutRect gridItem;
       
   520     TAknLayoutRect gridImage;
       
   521     TAknLayoutRect gridCloseButton;
       
   522     TAknLayoutRect gridCloseIcon;
       
   523     TInt variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0;
       
   524     TRect source = iParent ? iParent->Rect() : Rect();
       
   525     gridAppPane.LayoutRect( source,
       
   526             AknLayoutScalable_Apps::tport_appsw_pane( variety ) );
       
   527     gridItem.LayoutRect( gridAppPane.Rect(),
       
   528             AknLayoutScalable_Apps::cell_tport_appsw_pane( variety, 0, 0 ) );
       
   529     gridImage.LayoutRect( gridItem.Rect(),
       
   530             AknLayoutScalable_Apps::cell_tport_appsw_pane_g1( variety ) ); 
       
   531     gridCloseButton.LayoutRect( gridItem.Rect(),
       
   532             AknLayoutScalable_Apps::bg_button_pane_cp16( variety, 0, 0 ));
       
   533     gridCloseIcon.LayoutRect( gridItem.Rect(),
       
   534             AknLayoutScalable_Apps::cell_tport_appsw_pane_g3( variety, 0, 0 ));
       
   535     
       
   536     // Set icon size
       
   537     AknIconUtils::SetSize( icon, gridCloseIcon.Rect().Size(), EAspectRatioPreserved );
       
   538     AknIconUtils::SetSize( iconPressed, gridCloseIcon.Rect().Size(), EAspectRatioPreserved );
       
   539     CTsGridItemDrawer* itemDrawer =
       
   540         static_cast<CTsGridItemDrawer*>(iItemDrawer);
       
   541     
       
   542     // Setup close parameters
       
   543     itemDrawer->SetCloseIcon( icon, iconMask, iconPressed, iconPressedMask );
       
   544     TRect relGridCloseButton = TRect( TPoint( gridCloseButton.Rect().iTl.iX - gridItem.Rect().iTl.iX,
       
   545                                               gridCloseButton.Rect().iTl.iY - gridItem.Rect().iTl.iY),
       
   546                                       gridCloseButton.Rect().Size() );
       
   547     TRect relGridCloseIconRect = TRect( TPoint( gridCloseIcon.Rect().iTl.iX - gridItem.Rect().iTl.iX,
       
   548                                                 gridCloseIcon.Rect().iTl.iY - gridItem.Rect().iTl.iY),
       
   549                                         gridCloseIcon.Rect().Size() );
       
   550     itemDrawer->SetCloseIconRect( relGridCloseButton, relGridCloseIconRect );
       
   551     
       
   552     // Setup stroke parameters
       
   553     TPoint strokeOffset;
       
   554     strokeOffset.iX = gridImage.Rect().iTl.iX - gridItem.Rect().iTl.iX - KStrokeThickness;
       
   555     strokeOffset.iY = gridImage.Rect().iTl.iY - gridItem.Rect().iTl.iY - KStrokeThickness;
       
   556     TSize strokeSize = gridImage.Rect().Size();
       
   557     strokeSize.iHeight += KStrokeThickness * 2;
       
   558     strokeSize.iWidth += KStrokeThickness * 2;
       
   559     itemDrawer->SetStrokeOffset( strokeOffset, strokeSize );
       
   560     }
       
   561 
       
   562 
       
   563 // -----------------------------------------------------------------------------
       
   564 // CTsFastSwapGrid::Redraw
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 void CTsFastSwapGrid::Redraw()
       
   568     {
       
   569     DrawDeferred();
       
   570     CCoeControl* ctrlToRedraw = Parent();
       
   571     if ( ctrlToRedraw )
       
   572         {
       
   573         ctrlToRedraw->DrawDeferred();
       
   574         ctrlToRedraw = ctrlToRedraw->Parent();
       
   575         if ( ctrlToRedraw )
       
   576             {
       
   577             ctrlToRedraw->DrawNow();
       
   578             }
       
   579         }
       
   580     }
       
   581 
       
   582 
       
   583 
       
   584 
       
   585 /* ================================================================================
       
   586  * CTsGridItemDrawer
       
   587  * ================================================================================
       
   588  */
       
   589 
       
   590 // -----------------------------------------------------------------------------
       
   591 // CTsGridItemDrawer::CTsGridItemDrawer
       
   592 // -----------------------------------------------------------------------------
       
   593 //
       
   594 CTsGridItemDrawer::CTsGridItemDrawer(
       
   595         CTsFastSwapGrid* aGrid,
       
   596         CFormattedCellListBoxData* aData )
       
   597 : CFormattedCellListBoxItemDrawer( aGrid->Model(),
       
   598         NULL,
       
   599         aData ),
       
   600   iGrid( aGrid ),
       
   601   iStrokeColor( KRgbBlack ),
       
   602   iHighlightStrokeColor( KRgbBlack )
       
   603     {
       
   604     }
       
   605 
       
   606 
       
   607 // -----------------------------------------------------------------------------
       
   608 // CTsGridItemDrawer::~CTsGridItemDrawer
       
   609 // -----------------------------------------------------------------------------
       
   610 //
       
   611 CTsGridItemDrawer::~CTsGridItemDrawer()
       
   612     {
       
   613     delete iCloseIcon;
       
   614     delete iCloseIconMask;
       
   615     delete iCloseIconPressed;
       
   616     delete iCloseIconPressedMask;
       
   617     iStrokeItems.Close();
       
   618     }
       
   619 
       
   620 
       
   621 // -----------------------------------------------------------------------------
       
   622 // CTsGridItemDrawer::SetCloseIcon
       
   623 // -----------------------------------------------------------------------------
       
   624 //
       
   625 void CTsGridItemDrawer::SetCloseIcon( CFbsBitmap* aBmp, CFbsBitmap* aBmpMask,
       
   626                                       CFbsBitmap* aBmpPressed, CFbsBitmap* aBmpPressedMask  )
       
   627     {
       
   628     delete iCloseIcon;
       
   629     iCloseIcon = aBmp;
       
   630     delete iCloseIconMask;
       
   631     iCloseIconMask = aBmpMask;
       
   632     delete iCloseIconPressed;
       
   633     iCloseIconPressed = aBmpPressed;
       
   634     delete iCloseIconPressedMask;
       
   635     iCloseIconPressedMask = aBmpPressedMask;
       
   636     }
       
   637 
       
   638 
       
   639 // -----------------------------------------------------------------------------
       
   640 // CTsGridItemDrawer::SetCloseIconRect
       
   641 // -----------------------------------------------------------------------------
       
   642 //
       
   643 void CTsGridItemDrawer::SetCloseIconRect( const TRect& aButtonRect, const TRect& aIconRect )
       
   644     {
       
   645     iCloseButtonRect = aButtonRect;
       
   646     iCloseIconRect = aIconRect;
       
   647     }
       
   648 
       
   649 
       
   650 // -----------------------------------------------------------------------------
       
   651 // CTsGridItemDrawer::GetCloseButtonRect
       
   652 // -----------------------------------------------------------------------------
       
   653 //
       
   654 TRect CTsGridItemDrawer::GetCloseButtonRect( const TRect& aItemRect ) const
       
   655     {
       
   656     TRect retVal;
       
   657     retVal = TRect( TPoint(aItemRect.iTl.iX + iCloseButtonRect.iTl.iX,
       
   658                            aItemRect.iTl.iY + iCloseButtonRect.iTl.iY),
       
   659                     iCloseButtonRect.Size() );
       
   660     return retVal;
       
   661     }
       
   662 
       
   663 
       
   664 // -----------------------------------------------------------------------------
       
   665 // CTsGridItemDrawer::SetEdgeOffset
       
   666 // -----------------------------------------------------------------------------
       
   667 //
       
   668 void CTsGridItemDrawer::SetEdgeOffset( TInt aLeftOffset, TInt aRightOffset )
       
   669     {
       
   670     iLeftOffset = aLeftOffset;
       
   671     iRightOffset = aRightOffset;
       
   672     }
       
   673 
       
   674 
       
   675 // -----------------------------------------------------------------------------
       
   676 // CTsGridItemDrawer::SetRedrawBackground
       
   677 // -----------------------------------------------------------------------------
       
   678 //
       
   679 void CTsGridItemDrawer::SetRedrawBackground( TBool aEnable )
       
   680     {
       
   681     iRedrawBackground = aEnable;
       
   682     }
       
   683 
       
   684 
       
   685 // -----------------------------------------------------------------------------
       
   686 // CTsGridItemDrawer::SetStrokeColor
       
   687 // -----------------------------------------------------------------------------
       
   688 //
       
   689 void CTsGridItemDrawer::SetStrokeColors( TRgb aColor,
       
   690                                          TRgb aHighlightedColor )
       
   691     {
       
   692     iStrokeColor = aColor;
       
   693     iHighlightStrokeColor = aHighlightedColor;
       
   694     }
       
   695 
       
   696 
       
   697 // -----------------------------------------------------------------------------
       
   698 // CTsGridItemDrawer::SetStrokeItemsL
       
   699 // -----------------------------------------------------------------------------
       
   700 //
       
   701 void CTsGridItemDrawer::SetStrokeItemsL( RArray<TInt>& aItemIndex )
       
   702     {
       
   703     iStrokeItems.Close();
       
   704     for ( TInt i = 0; i < aItemIndex.Count(); i++ )
       
   705         {
       
   706         iStrokeItems.AppendL( aItemIndex[i] );
       
   707         }
       
   708     }
       
   709 
       
   710 
       
   711 // -----------------------------------------------------------------------------
       
   712 // CTsGridItemDrawer::SetStrokeOffset
       
   713 // -----------------------------------------------------------------------------
       
   714 //
       
   715 void CTsGridItemDrawer::SetStrokeOffset( TPoint aStrokeOffset, TSize aStrokeSize )
       
   716     {
       
   717     iStrokeRect = TRect( aStrokeOffset, aStrokeSize );
       
   718     }
       
   719 
       
   720 
       
   721 // -----------------------------------------------------------------------------
       
   722 // CTsGridItemDrawer::SetScreenRect
       
   723 // -----------------------------------------------------------------------------
       
   724 //
       
   725 void CTsGridItemDrawer::SetScreenRect( TRect aRect )
       
   726     {
       
   727     iScreenRect = aRect;
       
   728     }
       
   729 
       
   730 
       
   731 // -----------------------------------------------------------------------------
       
   732 // CTsGridItemDrawer::DrawActualItem
       
   733 // -----------------------------------------------------------------------------
       
   734 //
       
   735  void CTsGridItemDrawer::DrawActualItem( TInt aItemIndex, const TRect& aActualItemRect,
       
   736                                                  TBool aItemIsCurrent, TBool aViewIsEmphasized,
       
   737                                                  TBool aViewIsDimmed, TBool aItemIsSelected ) const
       
   738     {
       
   739     if (IsItemRectVisible(aActualItemRect))
       
   740         {
       
   741         // Calculate offset of the visible rectangle
       
   742         TRect drawRect = aActualItemRect;
       
   743         if ( drawRect.iTl.iX < iLeftOffset )
       
   744             {
       
   745             drawRect.iTl.iX = iLeftOffset;
       
   746             }
       
   747         if ( iScreenRect.Width() - drawRect.iBr.iX < iRightOffset )
       
   748             {
       
   749             drawRect.iBr.iX = iScreenRect.Width() - iRightOffset;
       
   750             }
       
   751         iGc->SetClippingRect(drawRect);
       
   752 			
       
   753         // Check for item highlight
       
   754         TBool itemIsCurrent = !iGrid->IsHighlightVisible() ? EFalse : aItemIsCurrent;
       
   755         
       
   756         // Draw background if necessary
       
   757         if ( iRedrawBackground )
       
   758             {
       
   759             CCoeControl* targetCtrlCtx = iGrid->Parent();
       
   760             if(targetCtrlCtx)
       
   761                 {
       
   762                 MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   763                 MAknsControlContext* cc = AknsDrawUtils::ControlContext( targetCtrlCtx );
       
   764                 AknsDrawUtils::Background( skin,
       
   765                        cc,
       
   766                        targetCtrlCtx,
       
   767                        *iGc,
       
   768                        drawRect );
       
   769                 }
       
   770             }
       
   771         
       
   772         // Draw item
       
   773         CFormattedCellListBoxItemDrawer::DrawActualItem(aItemIndex, aActualItemRect,
       
   774                 itemIsCurrent, aViewIsEmphasized, aViewIsDimmed, aItemIsSelected );
       
   775         
       
   776         // Draw stroke
       
   777         if ( iStrokeItems.Find( aItemIndex ) != KErrNotFound )
       
   778             {
       
   779             TRect strokeRect = iStrokeRect;
       
   780             strokeRect.Move( aActualItemRect.iTl );
       
   781             if ( itemIsCurrent )
       
   782                 {
       
   783                 iGc->SetPenColor( iHighlightStrokeColor );
       
   784                 }
       
   785             else
       
   786                 {
       
   787                 iGc->SetPenColor( iStrokeColor );
       
   788                 }
       
   789             // Thumbnail stroke
       
   790             iGc->DrawRect( strokeRect );
       
   791             }
       
   792         
       
   793         // Draw close button
       
   794         if ( iGrid->CanCloseItem( aItemIndex ) && iCloseIcon && iCloseIconPressed )
       
   795             {
       
   796             TRect closeIconRect = GetCloseButtonRect( aActualItemRect );
       
   797             // Draw frame
       
   798             TRect outerRect = closeIconRect;
       
   799             TRect innerRect = CalculateInnerButtonRect( outerRect );
       
   800             MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   801             if ( iGrid->IsItemCloseHit( aItemIndex ) )
       
   802                 {
       
   803                 TRect sourceRect( TPoint(0,0), iCloseIconPressed->SizeInPixels() );
       
   804                 iGc->DrawBitmapMasked( innerRect,
       
   805                         iCloseIconPressed,
       
   806                         sourceRect,
       
   807                         iCloseIconPressedMask,
       
   808                         ETrue );
       
   809                 }
       
   810             else
       
   811                 {
       
   812                 TRect sourceRect( TPoint(0,0), iCloseIcon->SizeInPixels() );
       
   813                 iGc->DrawBitmapMasked( innerRect,
       
   814                         iCloseIcon,
       
   815                         sourceRect,
       
   816                         iCloseIconMask,
       
   817                         ETrue );
       
   818                 }
       
   819             }
       
   820         }
       
   821     }
       
   822 
       
   823 // -----------------------------------------------------------------------------
       
   824 // CTsGridItemDrawer::DrawActualItem
       
   825 // -----------------------------------------------------------------------------
       
   826 //
       
   827 TBool CTsGridItemDrawer::IsItemRectVisible( const TRect& aItemRect ) const
       
   828     {
       
   829     TBool retVal( EFalse );
       
   830     TRect viewRect = iGrid->VisibleViewRect();
       
   831     if ( viewRect.Intersects( aItemRect ) )
       
   832         {
       
   833         retVal = ETrue;
       
   834         }
       
   835     return retVal;
       
   836     }
       
   837 
       
   838 // -----------------------------------------------------------------------------
       
   839 // CTsGridItemDrawer::IsRectContained
       
   840 // -----------------------------------------------------------------------------
       
   841 //
       
   842 TBool CTsGridItemDrawer::IsRectContained(
       
   843         const TRect& aRectContained, const TRect& aRectContainig) const
       
   844     {
       
   845     TBool retVal(EFalse);
       
   846     TRect intersectionRect(aRectContainig);
       
   847     intersectionRect.Intersection( aRectContained );
       
   848     if( intersectionRect == aRectContained)
       
   849         {
       
   850         retVal = ETrue;
       
   851         }
       
   852     return retVal;
       
   853     }
       
   854 
       
   855 // -----------------------------------------------------------------------------
       
   856 // CTsGridItemDrawer::CalculateInnerButtonRect
       
   857 // -----------------------------------------------------------------------------
       
   858 //
       
   859 TRect CTsGridItemDrawer::CalculateInnerButtonRect( const TRect& aOuterRect ) const
       
   860     {
       
   861     TRect retVal(aOuterRect);
       
   862     retVal.iTl.iX += iCloseIconRect.iTl.iX - iCloseButtonRect.iTl.iX;
       
   863     retVal.iTl.iY += iCloseIconRect.iTl.iY - iCloseButtonRect.iTl.iY;
       
   864     retVal.iBr.iX -= iCloseButtonRect.iBr.iX - iCloseIconRect.iBr.iX;
       
   865     retVal.iBr.iY -= iCloseButtonRect.iBr.iY - iCloseIconRect.iBr.iY;
       
   866     return retVal;
       
   867     }
       
   868  
       
   869  
       
   870  
       
   871  /* ================================================================================
       
   872   * CTsGridHighlightTimer
       
   873   * ================================================================================
       
   874   */
       
   875 
       
   876 // -----------------------------------------------------------------------------
       
   877 // CTsGridHighlightTimer::CTsGridHighlightTimer
       
   878 // -----------------------------------------------------------------------------
       
   879 //
       
   880 CTsFastSwapTimer::CTsFastSwapTimer( MTsFastSwapTimerObserver& aObserver )
       
   881 : CTimer( EPriorityStandard ),
       
   882   iObserver( &aObserver )
       
   883     {
       
   884     }
       
   885 
       
   886 
       
   887 // -----------------------------------------------------------------------------
       
   888 // CTsGridHighlightTimer::CTsGridHighlightTimer
       
   889 // -----------------------------------------------------------------------------
       
   890 //
       
   891 CTsFastSwapTimer::~CTsFastSwapTimer()
       
   892     {
       
   893     Cancel();
       
   894     }
       
   895 
       
   896 
       
   897 // -----------------------------------------------------------------------------
       
   898 // CTsGridHighlightTimer::ConstructL
       
   899 // -----------------------------------------------------------------------------
       
   900 //
       
   901 void CTsFastSwapTimer::ConstructL()
       
   902     {
       
   903     CTimer::ConstructL();
       
   904     CActiveScheduler::Add( this );
       
   905     }
       
   906 
       
   907 
       
   908 // -----------------------------------------------------------------------------
       
   909 // CTsGridHighlightTimer::CTsGridHighlightTimer
       
   910 // -----------------------------------------------------------------------------
       
   911 //
       
   912 void CTsFastSwapTimer::RunL()
       
   913     {
       
   914     iObserver->TimerCompletedL(this);
       
   915     }
       
   916  
       
   917  // End of file