menufw/menufwui/mmwidgets/src/mmlistboxitemdrawer.cpp
branchRCL_3
changeset 34 5456b4e8b3a8
child 35 3321d3e205b6
equal deleted inserted replaced
33:5f0182e07bfb 34:5456b4e8b3a8
       
     1 /*
       
     2  * Copyright (c) 2007 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:
       
    15  *
       
    16  */
       
    17 
       
    18 #include <eikfrlb.h>
       
    19 #include <e32math.h>
       
    20 #include "mmwidgetsconstants.h"
       
    21 #include "hnconvutils.h"
       
    22 #include <gdi.h>
       
    23 #include <AknIconArray.h>
       
    24 #include <AknsConstants.h>
       
    25 #include <AknFontAccess.h>
       
    26 #include <aknlistboxtfx.h>
       
    27 #include <layoutmetadata.cdl.h>
       
    28 #include <AknIconUtils.h>
       
    29 #include <AknBidiTextUtils.h>
       
    30 #include <AknDef.hrh>
       
    31 #include <AknLayoutFont.h>
       
    32 #include <avkon.mbg>
       
    33 
       
    34 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
    35 #include <aknlistloadertfx.h>
       
    36 #include <aknlistboxtfxinternal.h>
       
    37 #endif
       
    38 
       
    39 #include <AknsLayeredBackgroundControlContext.h>
       
    40 #include <AknsListBoxBackgroundControlContext.h>
       
    41 #include "bitmaptransforms.h"
       
    42 #include "mmwidgetsconstants.h"
       
    43 #include "mmlistbox.h"
       
    44 #include "mmtemplatelibrary.h"
       
    45 #include "mmlistboxitemdrawer.h"
       
    46 #include "mmlistboxmodel.h"
       
    47 #include "mmdraweranimator.h"
       
    48 #include "mmmarqueeadapter.h"
       
    49 #include "mmfloatingitem.h"
       
    50 #include "mmgridview.h"
       
    51 #include "mmlistboxview.h"
       
    52 #include "mmcacheforitem.h"
       
    53 #include "mmitemsdatacache.h"
       
    54 #include "mmwidgetcontainer.h"
       
    55 #include "hnsuitemodel.h"
       
    56 #include "menudebug.h"
       
    57 #include "hnextbmpiconholder.h"
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CMmListBoxItemDrawer::CMmListBoxItemDrawer(
       
    64         CMmListBoxModel* aMmListBoxModel,
       
    65       const CFont* aFont,
       
    66       CFormattedCellListBoxData* aFormattedCellData,
       
    67       TMmWidgetType aWidgetType,
       
    68       CMmTemplateLibrary* aTemplateLibrary )
       
    69   : CFormattedCellListBoxItemDrawer( aMmListBoxModel , aFont, aFormattedCellData),
       
    70   iFont(aFont), iLeftOverAreaUnderAnimatedItem(EFalse)
       
    71   {
       
    72   iWidgetType = aWidgetType;
       
    73   iTemplateLibrary = aTemplateLibrary;
       
    74   iMmModel = aMmListBoxModel;
       
    75   iRedrawBackground = ETrue;
       
    76   iDrawSeparatorLines = EFalse;
       
    77   iZoomIconIndex = -1;
       
    78   iIconAnimationZoomRatio = 1;
       
    79   // this is needed to get iColors initialized on first use:
       
    80   iLastDrawnItemWasFloating = ETrue;
       
    81     SetFlags( CListItemDrawer::EDisableHighlight );
       
    82     iIsSwapFloating = EFalse;
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 CMmListBoxItemDrawer::~CMmListBoxItemDrawer()
       
    90     {
       
    91     iFloatingItems.Close();
       
    92     delete iItemsDataCache;
       
    93     delete iAnimator;
       
    94     delete iSubcellText;
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void CMmListBoxItemDrawer::EnableCachedDataUse( TBool aEnable )
       
   102     {
       
   103     iUseCache = aEnable;
       
   104     if( aEnable )
       
   105         {
       
   106         RemoveFloatingItems();
       
   107         }
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 TBool CMmListBoxItemDrawer::CachedDataUseIsEnabled() const
       
   115     {
       
   116     return iUseCache;
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 void CMmListBoxItemDrawer::TrimCacheSize( TInt aItemCount )
       
   124     {
       
   125     iItemsDataCache->Trim( aItemCount );
       
   126     }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void CMmListBoxItemDrawer::InvalidateCache()
       
   133     {
       
   134     iItemsDataCache->Invalidate();
       
   135     // this is needed to get iColors initialized on first use:
       
   136     iLastDrawnItemWasFloating = ETrue;
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 CMmListBoxItemDrawer* CMmListBoxItemDrawer::NewLC(
       
   144         CMmListBoxModel* aMmListBoxModel,
       
   145         const CFont* aFont,
       
   146         CFormattedCellListBoxData* aFormattedCellData,
       
   147         TMmWidgetType aWidgetType,
       
   148         CMmTemplateLibrary* aTemplateLibrary )
       
   149     {
       
   150     CMmListBoxItemDrawer* self = new ( ELeave ) CMmListBoxItemDrawer(
       
   151             aMmListBoxModel, aFont, aFormattedCellData, aWidgetType,
       
   152             aTemplateLibrary );
       
   153     CleanupStack::PushL( self );
       
   154     self->ConstructL();
       
   155     return self;
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 CMmListBoxItemDrawer* CMmListBoxItemDrawer::NewL(
       
   163         CMmListBoxModel* aMmListBoxModel,
       
   164       const CFont* aFont,
       
   165       CFormattedCellListBoxData* aFormattedCellData,
       
   166       TMmWidgetType aWidgetType,
       
   167       CMmTemplateLibrary* aTemplateLibrary )
       
   168     {
       
   169     CMmListBoxItemDrawer* self = CMmListBoxItemDrawer::NewLC(
       
   170             aMmListBoxModel, aFont, aFormattedCellData, aWidgetType,
       
   171             aTemplateLibrary );
       
   172     CleanupStack::Pop( self );
       
   173     return self;
       
   174 
       
   175     }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CMmListBoxItemDrawer::SetView( CEikListBox * aView )
       
   182     {
       
   183     iWidget = aView;
       
   184     }
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 CEikListBox* CMmListBoxItemDrawer::Widget() const
       
   191     {
       
   192     return iWidget;
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void CMmListBoxItemDrawer::ConstructL()
       
   200     {
       
   201     iAnimator = CMmDrawerAnimator::NewL( *this );
       
   202     iItemsDataCache = CMmItemsDataCache::NewL();
       
   203     iIsEditMode = EFalse;
       
   204     iHighlightShown = EFalse;
       
   205     iDrawMoveIndicators = ETrue;
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 void CMmListBoxItemDrawer::DrawEmptyItem( TInt aItemIndex,
       
   213         TPoint aItemRectPos, TBool aViewIsDimmed ) const
       
   214     {
       
   215     TRect r( aItemRectPos, iItemCellSize );
       
   216 
       
   217     CFormattedCellListBoxItemDrawer::DrawEmptyItem( aItemIndex, aItemRectPos,
       
   218         aViewIsDimmed );
       
   219 
       
   220     const_cast<CMmListBoxItemDrawer*> ( this )->DrawFloatingItems( r );
       
   221     }
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 TInt CMmListBoxItemDrawer::GetFloatingItemIndex( TMmFloatingItemType aType ) const
       
   228     {
       
   229     TInt ret( KErrNotFound );
       
   230     TInt i( iFloatingItems.Count() - 1 );
       
   231     for( ; i >= 0; i-- )
       
   232         {
       
   233         if( iFloatingItems[i].GetFloatingItemType() == aType )
       
   234             {
       
   235             ret = i;
       
   236             break;
       
   237             }
       
   238         }
       
   239 
       
   240     return ret;
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 TMmFloatingItem& CMmListBoxItemDrawer::GetFloatingItemL(TMmFloatingItemType aType)
       
   248     {
       
   249     TInt index = GetFloatingItemIndex( aType );
       
   250     User::LeaveIfError( index );
       
   251     return iFloatingItems[index];
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 void CMmListBoxItemDrawer::AnimateDragItemTransitionL()
       
   259     {
       
   260     iAnimator->AnimateDragItemTransitionL();
       
   261     iAnimator->Trigger();
       
   262     }
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 // -----------------------------------------------------------------------------
       
   267 //
       
   268 void CMmListBoxItemDrawer::AnimateItemSwapL( TInt aItemFrom, TInt aItemTo )
       
   269     {
       
   270     iAnimator->AnimateItemSwapL( aItemFrom, aItemTo );
       
   271     iAnimator->Trigger();
       
   272     }
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 void CMmListBoxItemDrawer::AnimateItemZoomInL( TInt aItemIndex )
       
   279     {
       
   280     iAnimator->AnimateItemZoomL( aItemIndex, ETrue );
       
   281     iAnimator->Trigger();
       
   282     static_cast<CMmWidgetContainer*> (Widget()->Parent() )->SetAllowMove( EFalse );
       
   283     }
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 //
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 void CMmListBoxItemDrawer::AnimateItemZoomOutL( TInt aItemIndex )
       
   290     {
       
   291     iAnimator->AnimateItemZoomL( aItemIndex, EFalse );
       
   292     iAnimator->Trigger();
       
   293     }
       
   294 
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 // -----------------------------------------------------------------------------
       
   298 //
       
   299 void CMmListBoxItemDrawer::DrawFloatingItems( TRect currentlyDrawnRect )
       
   300     {
       
   301     TBool redrawItemBackground = IsRedrawItemBackgroundEnabled();
       
   302     SetRedrawItemBackground( EFalse );
       
   303     for( TInt i( iFloatingItems.Count() - 1 ); i >= 0; i-- )
       
   304         {
       
   305         TMmFloatingItemType type = iFloatingItems[i].GetFloatingItemType();
       
   306         if( iFloatingItems[i].IsFloatingItemValid() )
       
   307             {
       
   308             TInt drawnItemIndex = iFloatingItems[i].GetDrawnItemIndex();
       
   309             TSize size = iWidget->View()->ItemSize( drawnItemIndex );
       
   310             if ( iWidgetType == EListbox 
       
   311                     && TemplateLibrary()->GetScrollbarVisibility())
       
   312                 {
       
   313                 size.iWidth -= TemplateLibrary()->ScrollbarWidth();
       
   314                 }
       
   315             TRect rect( iFloatingItems[i].GetItemPosition(),
       
   316                     iFloatingItems[i].GetItemPosition() + size);
       
   317 
       
   318             if( rect.Intersects( currentlyDrawnRect ) )
       
   319                 {
       
   320                 TInt tempZoomIconIndex = iZoomIconIndex;
       
   321                 TInt tempZoomRatio = iIconAnimationZoomRatio;
       
   322 
       
   323                 iZoomIconIndex = iFloatingItems[i].GetDrawnItemIndex();
       
   324                 iIconAnimationZoomRatio = iFloatingItems[i].GetCurrentZoomRatio();
       
   325 
       
   326                 if ( ItemHasFloatingType( drawnItemIndex, EDrag)
       
   327                         || ItemHasFloatingType( drawnItemIndex, EDragTransition)
       
   328                         || ItemHasFloatingType( drawnItemIndex, EDragStart ) )
       
   329                     {
       
   330                     ClearFlags( CListItemDrawer::EPressedDownState );
       
   331                     }
       
   332                 type == ESwapTransition ? iIsSwapFloating = ETrue : iIsSwapFloating = EFalse;
       
   333                 if( ( type == EDrag && !ItemHasFloatingType( drawnItemIndex, EDragStart ) )
       
   334                         || ( type != EDragTransition && type != EDrag
       
   335                                 && !ItemHasFloatingType( drawnItemIndex, EDragTransition ) )
       
   336                         || ( type == EDragTransition )
       
   337                     )
       
   338 					{
       
   339                     DrawActualItem( drawnItemIndex, rect, ETrue, EFalse, EFalse, EFalse );
       
   340 					}
       
   341                 iIconAnimationZoomRatio = tempZoomRatio;
       
   342                 iZoomIconIndex = tempZoomIconIndex;
       
   343                 }
       
   344             }
       
   345         else
       
   346             {
       
   347             iFloatingItems.Remove( i );
       
   348             }
       
   349         }
       
   350     SetRedrawItemBackground( redrawItemBackground );
       
   351     }
       
   352 
       
   353 // -----------------------------------------------------------------------------
       
   354 //
       
   355 // -----------------------------------------------------------------------------
       
   356 //
       
   357 TInt CMmListBoxItemDrawer::GetValidFloatingItemCount(TMmFloatingItemType aType)
       
   358     {
       
   359     TInt count( 0 );
       
   360 
       
   361     for( TInt i( iFloatingItems.Count() - 1 ); i >= 0; i-- )
       
   362         {
       
   363         if( iFloatingItems[i].GetFloatingItemType() == aType
       
   364                 && iFloatingItems[i].IsFloatingItemValid() )
       
   365             count++;
       
   366         }
       
   367     return count;
       
   368     }
       
   369 // -----------------------------------------------------------------------------
       
   370 //
       
   371 // -----------------------------------------------------------------------------
       
   372 //
       
   373 void CMmListBoxItemDrawer::DrawItem( TInt aItemIndex, TPoint aItemRectPos,
       
   374         TBool aItemIsSelected, TBool aItemIsCurrent, TBool aViewIsEmphasized,
       
   375         TBool aViewIsDimmed) const
       
   376     {
       
   377     if( !Widget()->View()->RedrawDisabled() )
       
   378         {
       
   379         TBool highlightVisible =
       
   380                 !( Flags() & CListItemDrawer::ESingleClickDisabledHighlight );
       
   381         aItemIsCurrent = aItemIsCurrent && highlightVisible;
       
   382         DoDrawItem( aItemIndex, aItemRectPos, aItemIsSelected,
       
   383                 aItemIsCurrent, aViewIsEmphasized, aViewIsDimmed );
       
   384         }
       
   385     }
       
   386 // -----------------------------------------------------------------------------
       
   387 //
       
   388 // -----------------------------------------------------------------------------
       
   389 //
       
   390 void CMmListBoxItemDrawer::DoDrawItem(TInt aItemIndex, TPoint aItemRectPos,
       
   391         TBool aItemIsSelected, TBool aItemIsCurrent, TBool aViewIsEmphasized,
       
   392         TBool aViewIsDimmed) const
       
   393     {
       
   394     TSize itemCellSize = TSize( GetItemSize( aItemIndex, aItemIsCurrent ) );
       
   395     TRect actualItemRect( aItemRectPos, itemCellSize );
       
   396 
       
   397 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   398     MAknListBoxTfxInternal* transApi = CAknListLoader::TfxApiInternal( iGc );
       
   399     if( transApi )
       
   400         {
       
   401         transApi->StartDrawing( MAknListBoxTfxInternal::EListView );
       
   402         transApi->StopDrawing();
       
   403         transApi->BeginRedraw( MAknListBoxTfxInternal::EListItem,
       
   404                 actualItemRect, aItemIndex );
       
   405         }
       
   406 #endif
       
   407 
       
   408     const_cast<CMmListBoxItemDrawer*>(this)->iLeftOverAreaUnderAnimatedItem = EFalse;
       
   409     for( TInt i( iFloatingItems.Count() - 1 ); i >= 0; i-- )
       
   410         {
       
   411         if( iFloatingItems[i].GetDrawnItemIndex() == aItemIndex
       
   412                 && iFloatingItems[i].IsFloatingItemValid() )
       
   413             {
       
   414             const_cast<CMmListBoxItemDrawer*>(this)->iLeftOverAreaUnderAnimatedItem = ETrue;
       
   415             break;
       
   416             }
       
   417         }
       
   418 
       
   419     iIsSwapFloating = EFalse;
       
   420     DrawActualItem(aItemIndex, actualItemRect, aItemIsCurrent, aViewIsEmphasized,
       
   421             aViewIsDimmed, aItemIsSelected);
       
   422     const_cast<CMmListBoxItemDrawer*>(this)->iLeftOverAreaUnderAnimatedItem = EFalse;
       
   423 
       
   424     const_cast<CMmListBoxItemDrawer*>(this)->DrawFloatingItems(actualItemRect);
       
   425 
       
   426     if( !AknLayoutUtils::PenEnabled() && IsEditMode() )
       
   427         {
       
   428         const_cast<CMmListBoxItemDrawer*> ( this )->DrawActualIndicatorItem(
       
   429                 aItemIndex, actualItemRect );
       
   430         }
       
   431 
       
   432 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   433     if( transApi )
       
   434         {
       
   435       transApi->EndRedraw( MAknListBoxTfxInternal::EListItem, aItemIndex );
       
   436     }
       
   437 #endif
       
   438 
       
   439 
       
   440 
       
   441     }
       
   442 // -----------------------------------------------------------------------------
       
   443 //
       
   444 // -----------------------------------------------------------------------------
       
   445 //
       
   446 void CMmListBoxItemDrawer::DrawItemText( TInt aItemIndex,
       
   447         const TRect &aItemTextRect, TBool aItemIsCurrent,
       
   448         TBool aViewIsEmphasized, TBool aItemIsSelected ) const
       
   449     {
       
   450     TRAP_IGNORE( DoDrawItemTextL( aItemIndex, aItemTextRect, aItemIsCurrent,
       
   451                     aViewIsEmphasized, aItemIsSelected ) );
       
   452     }
       
   453 
       
   454 // -----------------------------------------------------------------------------
       
   455 //
       
   456 // -----------------------------------------------------------------------------
       
   457 //
       
   458 void CMmListBoxItemDrawer::DoDrawItemTextL( TInt aItemIndex, const TRect
       
   459         &aItemTextRect, TBool aItemIsCurrent, TBool aViewIsEmphasized,
       
   460         TBool /* aItemIsSelected */) const
       
   461     {
       
   462     CMmCacheForItem* cache = iItemsDataCache->GetItemCacheL( aItemIndex );
       
   463     cache->InvalidateIfCacheMayNotBeUsed(
       
   464             aItemIsCurrent, iLastSubcellsSetupCode );
       
   465 
       
   466     if( IsRedrawItemBackgroundEnabled() )
       
   467         {
       
   468         DrawBackground( aItemTextRect );
       
   469         }
       
   470 
       
   471     if ( !iUseCache || !cache->IsValid() )
       
   472         {
       
   473         SetupSubCellsL( aItemIsCurrent, aItemIndex );
       
   474         }
       
   475     __ASSERT_DEBUG( cache->IsValid(), User::Invariant() );
       
   476 
       
   477     FormattedCellData()->SetIconArray( cache->GetIconListL() );
       
   478 
       
   479     TBool isFloating = !iUseCache && IsFloating( aItemIndex );
       
   480     if( !!isFloating != !!iLastDrawnItemWasFloating ) // Ex-OR
       
   481         {
       
   482         iLastDrawnItemWasFloating = isFloating;
       
   483         iColors = SetupColors( isFloating );
       
   484         }
       
   485 
       
   486   CFormattedCellListBoxData* data = static_cast<CFormattedCellListBoxData*>(iData);
       
   487     data->EnableMarqueeL( EFalse );
       
   488 
       
   489     TBool highlightShown = ETrue;
       
   490     if( FormattedCellData()->RespectFocus() && !aViewIsEmphasized )
       
   491         {
       
   492 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   493     MAknListBoxTfxInternal *transApi = CAknListLoader::TfxApiInternal( iGc );
       
   494         if( transApi )
       
   495             {
       
   496             transApi->Remove( MAknListBoxTfxInternal::EListHighlight );
       
   497             }
       
   498 #endif
       
   499         highlightShown = EFalse;
       
   500         }
       
   501 
       
   502     data->Draw( Properties(aItemIndex), *iGc, &( cache->GetItemText() ), aItemTextRect,
       
   503             GetHighlightVisibility( aItemIndex, aItemIsCurrent, highlightShown ), iColors );
       
   504 
       
   505 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   506     MAknListBoxTfxInternal *transApi = CAknListLoader::TfxApiInternal( iGc );
       
   507     if( transApi )
       
   508         {
       
   509         transApi->StartDrawing( MAknListBoxTfxInternal::EListItem );
       
   510         }
       
   511 #endif
       
   512 
       
   513     if( iMarqueeAdapter && aItemIsCurrent )
       
   514         {
       
   515         DEBUG(("CMmListBoxItemDrawer::DoDrawItemTextL - DrawMarquee"));
       
   516         iMarqueeAdapter->DrawMarqueeL( *iGc );
       
   517         }
       
   518 
       
   519 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   520     if( transApi )
       
   521         {
       
   522         transApi->StopDrawing();
       
   523         }
       
   524 #endif
       
   525 
       
   526   if( iDrawSeparatorLines && !iIsSwapFloating )
       
   527         {
       
   528         CMmListBoxView* view = static_cast<CMmListBoxView*>( iWidget->View() );
       
   529         if( aItemIndex != ( view->ModelItemsCount() - 1  ))
       
   530             {
       
   531             AknListUtils::DrawSeparator( *iGc, aItemTextRect, iColors.iBack );
       
   532             }
       
   533        }
       
   534     ColumnData()->SetIconArray( NULL );
       
   535 
       
   536     }
       
   537 
       
   538 // -----------------------------------------------------------------------------
       
   539 //
       
   540 // -----------------------------------------------------------------------------
       
   541 //
       
   542 void CMmListBoxItemDrawer::SetRedrawItemBackground( TBool aRedraw )
       
   543     {
       
   544     iRedrawBackground = aRedraw;
       
   545     }
       
   546 
       
   547 // -----------------------------------------------------------------------------
       
   548 //
       
   549 // -----------------------------------------------------------------------------
       
   550 //
       
   551 void CMmListBoxItemDrawer::SetDrawSeparatorLines( TBool aDraw )
       
   552     {
       
   553     iDrawSeparatorLines = aDraw;
       
   554     }
       
   555 
       
   556 // -----------------------------------------------------------------------------
       
   557 //
       
   558 // -----------------------------------------------------------------------------
       
   559 //
       
   560 TBool CMmListBoxItemDrawer::IsRedrawItemBackgroundEnabled() const
       
   561     {
       
   562     return iRedrawBackground;
       
   563     }
       
   564 
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 // -----------------------------------------------------------------------------
       
   568 //
       
   569 void CMmListBoxItemDrawer::DrawBackground( const TRect& aItemTextRect ) const
       
   570     {
       
   571     MAknsSkinInstance *skin = AknsUtils::SkinInstance();
       
   572     CCoeControl* control = FormattedCellData()->Control();
       
   573 
       
   574     if( IsRedrawItemBackgroundEnabled() )
       
   575         {
       
   576 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   577         MAknListBoxTfxInternal *transApi = CAknListLoader::TfxApiInternal( iGc );
       
   578         if( transApi )
       
   579             {
       
   580             transApi->StartDrawing( MAknListBoxTfxInternal::EListView );
       
   581             }
       
   582 #endif
       
   583         TBool bgDrawn( EFalse );
       
   584         if( control )
       
   585             {
       
   586             if( CAknEnv::Static()->TransparencyEnabled() )
       
   587                 {
       
   588                 bgDrawn = AknsDrawUtils::Background(
       
   589                     skin, iBgContext, control, *iGc, aItemTextRect,
       
   590                     KAknsDrawParamNoClearUnderImage );
       
   591                 }
       
   592             else
       
   593                 {
       
   594                 bgDrawn = AknsDrawUtils::Background(
       
   595                     skin, iBgContext, control, *iGc, aItemTextRect,
       
   596                     KAknsDrawParamNoClearUnderImage |
       
   597                     KAknsDrawParamBottomLevelRGBOnly );
       
   598                 }
       
   599             }
       
   600         if( !bgDrawn )
       
   601             {
       
   602             iGc->Clear( aItemTextRect );
       
   603             }
       
   604 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   605         if( transApi )
       
   606             {
       
   607             transApi->StopDrawing();
       
   608             }
       
   609 #endif
       
   610         }
       
   611     }
       
   612 
       
   613 // -----------------------------------------------------------------------------
       
   614 //
       
   615 // -----------------------------------------------------------------------------
       
   616 //
       
   617 void CMmListBoxItemDrawer::AnimateDragItemStartL( TInt aDraggedIndex,
       
   618         TPoint aPoint )
       
   619     {
       
   620     iAnimator->AnimateDragItemStartL( aDraggedIndex, aPoint );
       
   621     iAnimator->Trigger();
       
   622     }
       
   623 
       
   624 // -----------------------------------------------------------------------------
       
   625 //
       
   626 // -----------------------------------------------------------------------------
       
   627 //
       
   628 void CMmListBoxItemDrawer::SetupSubNoCellL( TInt aIndex,
       
   629         TInt aItemIndex ) const
       
   630     {
       
   631     TTemplateChild child;
       
   632     child.iFontId = EAknLogicalFontSecondaryFont;
       
   633     child.iIsImage = EFalse;
       
   634     const_cast<CMmListBoxItemDrawer*>(this)->
       
   635         ReplaceSubCellText( KNullDesC() );
       
   636     SetupSubCellL( child, aIndex, aItemIndex );
       
   637     iLastSubcellsSetupCode.AddSubcellInfo( TMmSubcellsSetupCode::ENoSubcell );
       
   638     }
       
   639 
       
   640 // -----------------------------------------------------------------------------
       
   641 //
       
   642 // -----------------------------------------------------------------------------
       
   643 //
       
   644 void CMmListBoxItemDrawer::SetupSubIcondDragHighlightCellL(
       
   645         TTemplateChild aSubCellTemplate, TInt aIndex, TInt aItemIndex ) const
       
   646     {
       
   647     aSubCellTemplate.iRectAccordingToParent.iBr
       
   648     = TPoint(ItemCellSize().iWidth * iIconAnimationZoomRatio,
       
   649         ItemCellSize().iHeight * iIconAnimationZoomRatio);
       
   650 
       
   651     aSubCellTemplate.iRectAccordingToParent.iTl = TPoint(0, 0);
       
   652     SetupSubCellL( aSubCellTemplate, aIndex, aItemIndex );
       
   653     }
       
   654 
       
   655 // -----------------------------------------------------------------------------
       
   656 //
       
   657 // -----------------------------------------------------------------------------
       
   658 //
       
   659 void CMmListBoxItemDrawer::SetupSubCellL( TTemplateChild aSubCellTemplate,
       
   660         TInt aIndex, TInt aItemIndex ) const
       
   661     {
       
   662     CFormattedCellListBoxData* data = static_cast<CFormattedCellListBoxData*>(iData);
       
   663     TInt width = aSubCellTemplate.iRectAccordingToParent.iBr.iX - aSubCellTemplate.iRectAccordingToParent.iTl.iX;
       
   664     TInt height = aSubCellTemplate.iRectAccordingToParent.iBr.iY - aSubCellTemplate.iRectAccordingToParent.iTl.iY;
       
   665     data->SetTransparentSubCellL( aIndex, ETrue );
       
   666     data->SetSubCellSizeL( aIndex, TSize( width, height ) );
       
   667     data->SetSubCellIconSize( aIndex, TSize( width, height ) );
       
   668     data->SetSubCellPositionL( aIndex, aSubCellTemplate.iRectAccordingToParent.iTl);
       
   669     data->SetGraphicsSubCellL( aIndex, aSubCellTemplate.iIsImage );
       
   670     data->SetSubCellAlignmentL( aIndex, aSubCellTemplate.iTextAlign );
       
   671     const CFont* font = AknLayoutUtils::FontFromId(aSubCellTemplate.iFontId);
       
   672     data->SetSubCellFontL (aIndex, font);
       
   673     data->SetSubCellBaselinePosL( aIndex,
       
   674             CAknLayoutFont::AsCAknLayoutFontOrNull( font )->TextPaneTopToBaseline()
       
   675                     + aSubCellTemplate.iRectAccordingToParent.iTl.iY );
       
   676 
       
   677     //	If some text is clipped then marquee will do the drawing right after the subcell is drawn by ListBoxData.
       
   678     //	Setting the subcell size to zero prevents ListBoxData from drawing the text.
       
   679   if (!aSubCellTemplate.iIsImage
       
   680       && !iIsMarqueeBeingDrawn
       
   681       && ( aItemIndex == iWidget->View()->CurrentItemIndex() )
       
   682       && !IsEditMode()
       
   683       && iWidgetType == EListbox
       
   684       && iSubcellText
       
   685             && iMarqueeAdapter->IsMarqueeEnabled() )
       
   686 
       
   687         {
       
   688     if (iMarqueeAdapter && IsTextClippedL( aSubCellTemplate, *iSubcellText )
       
   689                 && STATIC_CAST(CMmWidgetContainer*,Widget()->Parent())->IsHighlightVisible() )
       
   690             {
       
   691             data->SetSubCellSizeL( aIndex, TSize( 0, 0 ) );
       
   692             const_cast<CMmListBoxItemDrawer*> ( this )->AddSubcellMarqueeElementL(
       
   693                     aSubCellTemplate, aIndex, aItemIndex );
       
   694             }
       
   695         else if( iMarqueeAdapter )
       
   696             {
       
   697             iMarqueeAdapter->StopMarqueeDrawing( aIndex );
       
   698             }
       
   699         }
       
   700 
       
   701     if( iMarqueeAdapter && iIsMarqueeBeingDrawn
       
   702             && iMarqueeAdapter->SubcellMarqueeElementExists( aIndex ) )
       
   703         {
       
   704         if( aItemIndex != iWidget->View()->CurrentItemIndex() )
       
   705             {
       
   706             iMarqueeAdapter->StopMarqueeDrawing( aIndex );
       
   707             }
       
   708         else
       
   709             {
       
   710             data->SetSubCellSizeL( aIndex, TSize( 0, 0 ) );
       
   711             }
       
   712         }
       
   713     }
       
   714 
       
   715 // -----------------------------------------------------------------------------
       
   716 //
       
   717 // -----------------------------------------------------------------------------
       
   718 //
       
   719 CFormattedCellListBoxData::TColors CMmListBoxItemDrawer::SetupColors(  TBool aDragged ) const
       
   720     {
       
   721     CFormattedCellListBoxData::TColors colors;
       
   722     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   723 
       
   724     if( !aDragged )
       
   725         {
       
   726         AknsUtils::GetCachedColor( skin, colors.iText, KAknsIIDQsnTextColors,
       
   727                 EAknsCIQsnTextColorsCG9 );
       
   728         AknsUtils::GetCachedColor( skin, colors.iBack , KAknsIIDQsnTextColors,
       
   729                 EAknsCIQsnOtherColorsCG6 );
       
   730         AknsUtils::GetCachedColor( skin, colors.iHighlightedText,
       
   731                 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG11 );
       
   732         AknsUtils::GetCachedColor( skin, colors.iHighlightedBack,
       
   733                 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6 );
       
   734         }
       
   735     else
       
   736         {
       
   737         AknsUtils::GetCachedColor( skin, colors.iText, KAknsIIDQsnTextColors,
       
   738                 EAknsCIQsnTextColorsCG11 );
       
   739         AknsUtils::GetCachedColor( skin, colors.iBack , KAknsIIDQsnTextColors,
       
   740                 EAknsCIQsnTextColorsCG6 );
       
   741         AknsUtils::GetCachedColor( skin, colors.iHighlightedText,
       
   742                 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG11 );
       
   743         AknsUtils::GetCachedColor( skin, colors.iHighlightedBack,
       
   744                 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6 );
       
   745         }
       
   746 
       
   747     return colors;
       
   748     }
       
   749 
       
   750 // -----------------------------------------------------------------------------
       
   751 //
       
   752 // -----------------------------------------------------------------------------
       
   753 //
       
   754 TInt CMmListBoxItemDrawer::GetItemHeight( TInt aItemIndex, TBool aItemIsCurrent ) const
       
   755     {
       
   756     TSize ret( TInt( 0 ), TInt( 0 ) );
       
   757     ret = GetItemSize( aItemIndex, aItemIsCurrent );
       
   758     return ret.iHeight;
       
   759     }
       
   760 
       
   761 // -----------------------------------------------------------------------------
       
   762 //
       
   763 // -----------------------------------------------------------------------------
       
   764 //
       
   765 TInt CMmListBoxItemDrawer::GetFloatingItemCount()
       
   766     {
       
   767     for( TInt i( iFloatingItems.Count() - 1 ); i >= 0; i-- )
       
   768         {
       
   769         TMmFloatingItem& current = GetFloatingItemAtIndex( i );
       
   770         if( current.GetDrawnItemIndex() == KErrNotFound )
       
   771             {
       
   772             RemoveFloatingItem( i );
       
   773             }
       
   774         }
       
   775 
       
   776     return iFloatingItems.Count();
       
   777     }
       
   778 
       
   779 // -----------------------------------------------------------------------------
       
   780 //
       
   781 // -----------------------------------------------------------------------------
       
   782 //
       
   783 TMmFloatingItem& CMmListBoxItemDrawer::GetFloatingItemAtIndex( TInt aIndex )
       
   784     {
       
   785     return iFloatingItems[aIndex];
       
   786     }
       
   787 
       
   788 // -----------------------------------------------------------------------------
       
   789 //
       
   790 // -----------------------------------------------------------------------------
       
   791 //
       
   792 void CMmListBoxItemDrawer::RemoveFloatingItem( TInt aPosition )
       
   793     {
       
   794     if( aPosition != KErrNotFound )
       
   795         {
       
   796         iFloatingItems.Remove( aPosition );
       
   797         }
       
   798     }
       
   799 
       
   800 // -----------------------------------------------------------------------------
       
   801 //
       
   802 // -----------------------------------------------------------------------------
       
   803 //
       
   804 void CMmListBoxItemDrawer::RemoveFloatingItems()
       
   805     {
       
   806     iFloatingItems.Reset();
       
   807     }
       
   808 
       
   809 // -----------------------------------------------------------------------------
       
   810 //
       
   811 // -----------------------------------------------------------------------------
       
   812 //
       
   813 void CMmListBoxItemDrawer::AddFloatingItemL( TMmFloatingItem& aFloatingItem,
       
   814         TInt aPosition )
       
   815     {
       
   816     EnableCachedDataUse( EFalse );
       
   817     if( aPosition != KErrNotFound )
       
   818         {
       
   819         iFloatingItems.InsertL( aFloatingItem, aPosition );
       
   820         }
       
   821     else
       
   822         {
       
   823         iFloatingItems.AppendL( aFloatingItem );
       
   824         }
       
   825     }
       
   826 
       
   827 // -----------------------------------------------------------------------------
       
   828 //
       
   829 // -----------------------------------------------------------------------------
       
   830 //
       
   831 TSize CMmListBoxItemDrawer::GetItemSize( TInt aItemIndex, TBool aItemIsCurrent ) const
       
   832     {
       
   833     if( aItemIndex < 0 )
       
   834         {
       
   835         return TSize( 1, 1 );
       
   836         }
       
   837 
       
   838     TSize size;
       
   839 
       
   840     CMmCacheForItem* cache = NULL;
       
   841     TRAPD( cacheError, cache = iItemsDataCache->GetItemCacheL( aItemIndex ) );
       
   842     if( cacheError != KErrNone )
       
   843         {
       
   844         cache = NULL;
       
   845         }
       
   846 
       
   847     if( cache )
       
   848         {
       
   849       cache->InvalidateIfCacheMayNotBeUsed(
       
   850               aItemIsCurrent, iLastSubcellsSetupCode );
       
   851       }
       
   852 
       
   853     if( !iUseCache || !cache || !cache->IsValid() )
       
   854         {
       
   855         const TDesC8& mm_template = iMmModel->GetAttributeAsText (aItemIndex,
       
   856                 KMmTemplate8);
       
   857         TRect viewRect = iWidget->View()->ViewRect();
       
   858         TBool landscapeOrientation = Layout_Meta_Data::IsLandscapeOrientation();
       
   859 
       
   860         if( iTemplateLibrary->GetSize( size, iWidgetType, mm_template,
       
   861                 landscapeOrientation, aItemIsCurrent, viewRect )
       
   862                 != KErrNone )
       
   863             {
       
   864             size = TSize( 1, 1 );
       
   865             }
       
   866         if( cache )
       
   867             {
       
   868             cache->SetSize( size );
       
   869             }
       
   870         }
       
   871     else
       
   872         {
       
   873         size = cache->GetSize();
       
   874         }
       
   875     return size;
       
   876     }
       
   877 
       
   878 // -----------------------------------------------------------------------------
       
   879 //
       
   880 // -----------------------------------------------------------------------------
       
   881 //
       
   882 TRect CMmListBoxItemDrawer::GetIndicatorRect() const
       
   883     {
       
   884     TBool landscapeOrientation = Layout_Meta_Data::IsLandscapeOrientation();
       
   885     const TDesC8& mm_template = iMmModel->GetAttributeAsText(
       
   886             iWidget->View()->CurrentItemIndex(), KMmTemplate8 );
       
   887     TRect indicatorRect( iTemplateLibrary->GetMoveIndicatorRect(
       
   888             iWidgetType, mm_template, landscapeOrientation, ETrue ) );
       
   889     return indicatorRect;
       
   890     }
       
   891 
       
   892 // -----------------------------------------------------------------------------
       
   893 //
       
   894 // -----------------------------------------------------------------------------
       
   895 //
       
   896 void CMmListBoxItemDrawer::SetDraggableL( TBool aDraggable )
       
   897     {
       
   898 
       
   899     iDraggable = aDraggable;
       
   900 
       
   901     if( !iDraggable )
       
   902         {
       
   903         for( int i = 0; i < iFloatingItems.Count(); i++ )
       
   904             {
       
   905             if( iFloatingItems[i].GetFloatingItemType() == EZoomTransition
       
   906                     && iFloatingItems[i].GetZoomingStatus() > 0 )
       
   907                 {
       
   908                 AnimateItemZoomOutL( iFloatingItems[i].GetDrawnItemIndex() );
       
   909                 }
       
   910             else if( iFloatingItems[i].GetFloatingItemType() == EDrag
       
   911                     || iFloatingItems[i].IsManualDelete() )
       
   912                 {
       
   913                 iFloatingItems[i].InvalidateFloatingItem();
       
   914                 }
       
   915             }
       
   916         }
       
   917     }
       
   918 
       
   919 // -----------------------------------------------------------------------------
       
   920 //
       
   921 // -----------------------------------------------------------------------------
       
   922 //
       
   923 void CMmListBoxItemDrawer::SetEditModeL( TBool aEditMode )
       
   924     {
       
   925     if( aEditMode )
       
   926         {
       
   927         EnableCachedDataUse( EFalse );
       
   928         }
       
   929 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   930     MAknListBoxTfxInternal *trans = CAknListLoader::TfxApiInternal( iGc );
       
   931     if( trans )
       
   932         {
       
   933         trans->Remove( MAknListBoxTfxInternal::EListEverything );
       
   934         trans->Draw( iViewRect );
       
   935         }
       
   936 #endif
       
   937     iIsEditMode = aEditMode;
       
   938     }
       
   939 
       
   940 // -----------------------------------------------------------------------------
       
   941 //
       
   942 // -----------------------------------------------------------------------------
       
   943 //
       
   944 TBool CMmListBoxItemDrawer::IsEditMode() const
       
   945     {
       
   946     return iIsEditMode;
       
   947     }
       
   948 
       
   949 // -----------------------------------------------------------------------------
       
   950 //
       
   951 // -----------------------------------------------------------------------------
       
   952 //
       
   953 CMmDrawerAnimator* CMmListBoxItemDrawer::GetAnimator()
       
   954     {
       
   955     return iAnimator;
       
   956     }
       
   957 
       
   958 // -----------------------------------------------------------------------------
       
   959 //
       
   960 // -----------------------------------------------------------------------------
       
   961 //
       
   962 void CMmListBoxItemDrawer::SetDraggedPointL( TPoint aPoint )
       
   963     {
       
   964     TInt dragFloatingItem = GetFloatingItemIndex( EDragStart );
       
   965     if( KErrNotFound != dragFloatingItem )
       
   966         {
       
   967         TMmFloatingItem & item = GetFloatingItemAtIndex( dragFloatingItem );
       
   968         TMmFloatingItem postDragRefresh( item.GetDrawnItemIndex(),
       
   969                 item.GetItemPosition(), EPostDragRefreshItem,
       
   970                 MmEffects::KNoAnimationFramesCount, iWidget->View() );
       
   971         if( postDragRefresh.GetItemPosition() != aPoint )
       
   972             {
       
   973             iFloatingItems.Append( postDragRefresh );
       
   974             }
       
   975         }
       
   976 
       
   977     if( dragFloatingItem == KErrNotFound
       
   978             && ( dragFloatingItem = GetFloatingItemIndex( EDrag ) )
       
   979                 != KErrNotFound )
       
   980         {
       
   981         TMmFloatingItem & item = GetFloatingItemAtIndex( dragFloatingItem );
       
   982         TMmFloatingItem floatingItem( item.GetDrawnItemIndex(),
       
   983                 aPoint,	EDrag, MmEffects::KNoAnimationFramesCount, NULL );
       
   984         floatingItem.SetManualDelete( ETrue );
       
   985 
       
   986         TMmFloatingItem postDragRefresh( item.GetDrawnItemIndex(),
       
   987                 item.GetItemPosition(), EPostDragRefreshItem,
       
   988                 MmEffects::KNoAnimationFramesCount, iWidget->View() );
       
   989 
       
   990         iFloatingItems.Remove( dragFloatingItem );
       
   991 
       
   992         if (postDragRefresh.GetItemPosition() != floatingItem.GetItemPosition())
       
   993             {
       
   994             iFloatingItems.Append( postDragRefresh );
       
   995             }
       
   996         iFloatingItems.Insert( floatingItem, 0 );
       
   997         }
       
   998     }
       
   999 
       
  1000 // -----------------------------------------------------------------------------
       
  1001 //
       
  1002 // -----------------------------------------------------------------------------
       
  1003 //
       
  1004 void CMmListBoxItemDrawer::SetDraggedIndexL( TInt aDraggedItemIndex,
       
  1005         TPoint aPoint )
       
  1006     {
       
  1007     TInt dragStartFloatingItem( KErrNotFound );
       
  1008     TInt dragFloatingItem( KErrNotFound );
       
  1009     do
       
  1010         {
       
  1011         dragStartFloatingItem = GetFloatingItemIndex( EDragStart );
       
  1012         dragFloatingItem = GetFloatingItemIndex( EDrag );
       
  1013         if( dragStartFloatingItem == KErrNotFound )
       
  1014             dragStartFloatingItem = dragFloatingItem;
       
  1015         if( dragStartFloatingItem != KErrNotFound )
       
  1016             {
       
  1017             TMmFloatingItem & item = GetFloatingItemAtIndex( dragStartFloatingItem );
       
  1018             TMmFloatingItem postDragRefresh( item.GetDrawnItemIndex(),
       
  1019                     item.GetItemPosition(), EPostDragRefreshItem,
       
  1020                     MmEffects::KNoAnimationFramesCount, iWidget->View() );
       
  1021 
       
  1022             if( postDragRefresh.GetItemPosition() != aPoint )
       
  1023                 {
       
  1024                 iFloatingItems.Append( postDragRefresh );
       
  1025                 }                
       
  1026             }
       
  1027         RemoveFloatingItem( dragFloatingItem );
       
  1028         }
       
  1029     while( dragFloatingItem != KErrNotFound );
       
  1030 
       
  1031     if( aDraggedItemIndex != KErrNotFound )
       
  1032         {
       
  1033         TMmFloatingItem floatingItem( aDraggedItemIndex, aPoint, EDrag,
       
  1034                 MmEffects::KNoAnimationFramesCount, iWidget->View() );
       
  1035         floatingItem.SetManualDelete( ETrue );
       
  1036         AddFloatingItemL( floatingItem, 0 );
       
  1037 
       
  1038         TMmFloatingItem postDragRefresh( aDraggedItemIndex,
       
  1039                 iWidget->View()->ItemPos( aDraggedItemIndex ), EPostDragRefreshItem,
       
  1040                 MmEffects::KNoAnimationFramesCount, iWidget->View() );
       
  1041         AddFloatingItemL( postDragRefresh );
       
  1042 
       
  1043         ClearFlags( CListItemDrawer::EPressedDownState );
       
  1044         }
       
  1045 
       
  1046     iAnimator->Trigger();
       
  1047     }
       
  1048 
       
  1049 // -----------------------------------------------------------------------------
       
  1050 //
       
  1051 // -----------------------------------------------------------------------------
       
  1052 //
       
  1053 TBool CMmListBoxItemDrawer::IsDraggable() const
       
  1054     {
       
  1055     return iDraggable && iWidget->View();
       
  1056     }
       
  1057 
       
  1058 // -----------------------------------------------------------------------------
       
  1059 //
       
  1060 // -----------------------------------------------------------------------------
       
  1061 //
       
  1062 void CMmListBoxItemDrawer::SetBgContext(
       
  1063         CAknsBasicBackgroundControlContext * aBgContext )
       
  1064     {
       
  1065     iBgContext = aBgContext;
       
  1066     }
       
  1067 
       
  1068 // -----------------------------------------------------------------------------
       
  1069 //
       
  1070 // -----------------------------------------------------------------------------
       
  1071 //
       
  1072 void CMmListBoxItemDrawer::SetScrollbarVisibilityL( TBool aIsScrollbarVisible )
       
  1073     {
       
  1074     iTemplateLibrary->SetScrollbarVisibilityL( aIsScrollbarVisible );
       
  1075     }
       
  1076 
       
  1077 // -----------------------------------------------------------------------------
       
  1078 //
       
  1079 // -----------------------------------------------------------------------------
       
  1080 //
       
  1081 TRect CMmListBoxItemDrawer::AdjustItemRect( TInt aItemIndex ) const
       
  1082     {
       
  1083   TSize size = iWidget->View()->ItemSize (iWidget->View()->CurrentItemIndex () );
       
  1084   TRect rect(iWidget->View()->ItemPos (iWidget->View()->CurrentItemIndex () ),
       
  1085       iWidget->View()->ItemPos (iWidget->View()->CurrentItemIndex () ) + size);
       
  1086     if( !AknLayoutUtils::PenEnabled() && iIsIndicatorItem )
       
  1087         {
       
  1088         TBool landscapeOrientation =
       
  1089                 Layout_Meta_Data::IsLandscapeOrientation();
       
  1090     const TDesC8& mm_template = iMmModel->GetAttributeAsText (
       
  1091         0, KMmTemplate8);
       
  1092         TRect relativeToParentRect = TRect( TPoint( 0, 0 ), TPoint( 0, 0 ) );
       
  1093     relativeToParentRect = iTemplateLibrary->GetMoveIndicatorRect(
       
  1094             iWidgetType, mm_template, landscapeOrientation,
       
  1095             aItemIndex == iWidget->View()->CurrentItemIndex () );
       
  1096         rect.Move( relativeToParentRect.iTl );
       
  1097         rect.iBr.iX = rect.iBr.iX + relativeToParentRect.Width();
       
  1098         rect.iBr.iY = rect.iBr.iY + relativeToParentRect.Height();
       
  1099         }
       
  1100     return rect;
       
  1101     }
       
  1102 
       
  1103 // -----------------------------------------------------------------------------
       
  1104 //
       
  1105 // -----------------------------------------------------------------------------
       
  1106 //
       
  1107 void CMmListBoxItemDrawer::DrawActualIndicatorItem( TInt aItemIndex, TRect /*actualItemRect*/ )
       
  1108   {
       
  1109   if ( iDrawMoveIndicators )
       
  1110     {
       
  1111     iIsIndicatorItem = ETrue;
       
  1112     TBool redrawItemBackground =
       
  1113             IsRedrawItemBackgroundEnabled( );
       
  1114     SetRedrawItemBackground( EFalse );
       
  1115 
       
  1116     DrawActualItem( aItemIndex, AdjustItemRect( aItemIndex ) , EFalse, EFalse, EFalse, EFalse);
       
  1117 
       
  1118         SetRedrawItemBackground( redrawItemBackground );
       
  1119         iIsIndicatorItem = EFalse;
       
  1120         }
       
  1121     }
       
  1122 
       
  1123 // -----------------------------------------------------------------------------
       
  1124 //
       
  1125 // -----------------------------------------------------------------------------
       
  1126 //
       
  1127 void CMmListBoxItemDrawer::ReplaceSubCellText( const TDesC& aText )
       
  1128     {
       
  1129     delete iSubcellText;
       
  1130     iSubcellText = NULL;
       
  1131     if( aText.Compare( KNullDesC() ) )
       
  1132         {
       
  1133         iSubcellText = aText.Alloc();
       
  1134         }
       
  1135     }
       
  1136 
       
  1137 // -----------------------------------------------------------------------------
       
  1138 //
       
  1139 // -----------------------------------------------------------------------------
       
  1140 //
       
  1141 void CMmListBoxItemDrawer::AddSubcellMarqueeElementL( TTemplateChild aSubCellTemplate, TInt aIndex, TInt aItemIndex )
       
  1142   {
       
  1143   TRgb textColor;
       
  1144   MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
  1145   AknsUtils::GetCachedColor( skin, textColor, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG10 );
       
  1146   iMarqueeAdapter->AddMarqueeElementL( aSubCellTemplate.iRectAccordingToParent, *iSubcellText,
       
  1147       aSubCellTemplate.iFontId, textColor, aSubCellTemplate.iTextAlign, aIndex,
       
  1148       aSubCellTemplate.iRectAccordingToParent.iTl.iY,
       
  1149       aItemIndex);
       
  1150   }
       
  1151 
       
  1152 // -----------------------------------------------------------------------------
       
  1153 //
       
  1154 // -----------------------------------------------------------------------------
       
  1155 //
       
  1156 void CMmListBoxItemDrawer::SetMarqueeAdapter( CMmMarqueeAdapter* aAdapter )
       
  1157     {
       
  1158     iMarqueeAdapter = aAdapter;
       
  1159     }
       
  1160 
       
  1161 // -----------------------------------------------------------------------------
       
  1162 //
       
  1163 // -----------------------------------------------------------------------------
       
  1164 //
       
  1165 void CMmListBoxItemDrawer::SetMarqueeDrawing( TBool aIsMarqueeBeingDrawn )
       
  1166   {
       
  1167   iIsMarqueeBeingDrawn = aIsMarqueeBeingDrawn;
       
  1168   }
       
  1169 
       
  1170 
       
  1171 // -----------------------------------------------------------------------------
       
  1172 //
       
  1173 // -----------------------------------------------------------------------------
       
  1174 //
       
  1175 TBool CMmListBoxItemDrawer::IsTextClippedL( TTemplateChild aTemplateChild,
       
  1176     const TDesC& aText ) const
       
  1177   {
       
  1178     TBuf< MmMarqueeConstants::KClippingBufLength > clipbuf
       
  1179     = aText.Left( MmMarqueeConstants::KTextTrimmingThreshold);
       
  1180   TInt maxClipWidth = aTemplateChild.iRectAccordingToParent.Width();
       
  1181   const CFont* font = AknLayoutUtils::FontFromId(aTemplateChild.iFontId);
       
  1182     return AknBidiTextUtils::ConvertToVisualAndClipL( clipbuf, *font,
       
  1183             aTemplateChild.iRectAccordingToParent.Width(), maxClipWidth );
       
  1184     }
       
  1185 
       
  1186 // -----------------------------------------------------------------------------
       
  1187 //
       
  1188 // -----------------------------------------------------------------------------
       
  1189 //
       
  1190 void CMmListBoxItemDrawer::SetNumberOfColsInView( TInt aNumberOfColumns )
       
  1191     {
       
  1192     iNumberOfColsInWidget = aNumberOfColumns;
       
  1193     }
       
  1194 
       
  1195 // -----------------------------------------------------------------------------
       
  1196 //
       
  1197 // -----------------------------------------------------------------------------
       
  1198 //
       
  1199 void CMmListBoxItemDrawer::SetupIconSubcellL(
       
  1200     RArray<TTemplateChild>& aTemplateChildArray, TInt aChildIndex, TInt aItemIndex,
       
  1201     RBuf& aItemText, TInt& aSubcellIncrement ) const
       
  1202     {
       
  1203     CGulIcon* icon = NULL;
       
  1204     TTemplateChild child = aTemplateChildArray[aChildIndex];
       
  1205     if ( !IsEditMode() &&
       
  1206             child.iImageVisualId == EImageVisualIdEditMode )
       
  1207         {
       
  1208         child.iIsImage = EFalse;
       
  1209         }
       
  1210 
       
  1211     if( IsEditMode() && IsDraggable() && aItemIndex == iZoomIconIndex )
       
  1212         {
       
  1213         const TReal KNormalZoomRatio = 1.0;
       
  1214         TReal zoomDelta = ( iIconAnimationZoomRatio - KNormalZoomRatio ) / 2.0;
       
  1215         TSize size = child.iRectAccordingToParent.Size();
       
  1216         TSize sizeDelta( size.iWidth * zoomDelta, size.iHeight * zoomDelta );
       
  1217         child.iRectAccordingToParent.Grow( sizeDelta );
       
  1218         TInt targetZoom( KZoomStateZoomRatio * 100 );
       
  1219         Math::Round( zoomDelta, ( zoomDelta * 1000 ), 0);
       
  1220         if( (TInt)zoomDelta == targetZoom )
       
  1221             {
       
  1222             static_cast<CMmWidgetContainer*> (Widget()->Parent())->SetAllowMove( ETrue );
       
  1223             }
       
  1224         }
       
  1225 
       
  1226     TSize targetSize = child.iRectAccordingToParent.Size();
       
  1227 
       
  1228     CHnIconHolder* iconHolder = iMmModel->GetAttributeAsRefCountedGraphics(
       
  1229             aItemIndex, child.iData, &targetSize );
       
  1230     icon = iconHolder ? iconHolder->GetGulIcon() : NULL;
       
  1231     if( icon )
       
  1232         {
       
  1233         CFbsBitmap* bitmap = icon->Bitmap();
       
  1234         ASSERT( bitmap );
       
  1235         TInt errTooBig( KErrNone );
       
  1236         //resize the item if it is a move indicator
       
  1237         if( iIsIndicatorItem )
       
  1238             {
       
  1239             errTooBig = AknIconUtils::SetSize( bitmap,
       
  1240                     child.iRectAccordingToParent.Size(),
       
  1241                     EAspectRatioNotPreserved );
       
  1242             }
       
  1243         else
       
  1244             {
       
  1245             TSize bmpSize = bitmap->SizeInPixels();
       
  1246             TBool setSizeRequired = bitmap->DisplayMode() == ENone;
       
  1247             if ( targetSize.iWidth && targetSize.iHeight &&
       
  1248                     ( setSizeRequired || !BitmapFitsIntoTarget( bmpSize, targetSize ) ) )
       
  1249                 {
       
  1250                 CFbsBitmap* mask = icon->Mask();
       
  1251                 if( mask )
       
  1252                     {
       
  1253                     __ASSERT_DEBUG( bmpSize == mask->SizeInPixels(), User::Invariant() );
       
  1254                     errTooBig = AknIconUtils::SetSize( mask, targetSize,
       
  1255                             EAspectRatioPreservedAndUnusedSpaceRemoved );
       
  1256                     }
       
  1257                 if( !errTooBig )
       
  1258                     errTooBig = AknIconUtils::SetSize( bitmap, targetSize,
       
  1259                         EAspectRatioPreservedAndUnusedSpaceRemoved );
       
  1260                 }
       
  1261             }
       
  1262 
       
  1263         if( errTooBig == KErrTooBig )
       
  1264             {
       
  1265             // If icon is not created, try to create default application icon
       
  1266             MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
  1267             CFbsBitmap* bitmap( NULL );
       
  1268             CFbsBitmap* maskBitmap( NULL );
       
  1269             TRAPD( err,
       
  1270                 {
       
  1271                 AknsUtils::CreateIconLC( skin,
       
  1272                     KAknsIIDQgnMenuUnknownLst, bitmap, maskBitmap,
       
  1273                     AknIconUtils::AvkonIconFileName(),
       
  1274                     EMbmAvkonQgn_menu_unknown_lst,
       
  1275                     EMbmAvkonQgn_menu_unknown_lst_mask );
       
  1276                 CleanupStack::Pop( 2 ); // for trap
       
  1277                 }
       
  1278                 );
       
  1279             if( !err )
       
  1280                 {
       
  1281                 if( maskBitmap)
       
  1282                     AknIconUtils::SetSize( maskBitmap, targetSize,
       
  1283                             EAspectRatioPreservedAndUnusedSpaceRemoved );
       
  1284                 AknIconUtils::SetSize( bitmap, targetSize,
       
  1285                         EAspectRatioPreservedAndUnusedSpaceRemoved );
       
  1286                 static_cast<CHnExtBmpIconHolder*>(iconHolder)->CleanBmpBuffer();
       
  1287                 icon->SetBitmap(bitmap);
       
  1288                 icon->SetMask(maskBitmap);
       
  1289                 icon->SetBitmapsOwnedExternally(EFalse);
       
  1290                 }
       
  1291             }
       
  1292 
       
  1293         TInt iconIndex = iItemsDataCache->GetItemCacheL( aItemIndex )->AppendIconL( iconHolder );
       
  1294 
       
  1295         HBufC8* number = HnConvUtils::NumToStr8LC( iconIndex );
       
  1296         const TInt newLength = aItemText.Length() + number->Length();
       
  1297         if( aItemText.MaxLength() < newLength )
       
  1298             {
       
  1299             aItemText.ReAllocL( newLength );
       
  1300             }
       
  1301         CleanupStack::PopAndDestroy( number );
       
  1302         aItemText.AppendNum( iconIndex );
       
  1303 
       
  1304         SetupSubCellL( child, aSubcellIncrement, aItemIndex );
       
  1305 
       
  1306         if( aChildIndex < aTemplateChildArray.Count() - 1 )
       
  1307             {
       
  1308             const TInt newLength = aItemText.Length() + KTab().Length();
       
  1309             if( aItemText.MaxLength() < newLength )
       
  1310                 {
       
  1311                 aItemText.ReAllocL( newLength );
       
  1312                 }
       
  1313             aItemText.Append( KTab );
       
  1314             }
       
  1315 
       
  1316         aSubcellIncrement++;
       
  1317           iLastSubcellsSetupCode.AddSubcellInfo( TMmSubcellsSetupCode::EGraphicsSubcell );
       
  1318         }
       
  1319     else
       
  1320         {
       
  1321         // Mark the fact that subcell was not set to ensure that TMmSubcellsSetupCode
       
  1322         // works properly.
       
  1323             iLastSubcellsSetupCode.AddSubcellInfo( TMmSubcellsSetupCode::ESkippedSubcell );
       
  1324         }
       
  1325     }
       
  1326 
       
  1327 // -----------------------------------------------------------------------------
       
  1328 //
       
  1329 // -----------------------------------------------------------------------------
       
  1330 //
       
  1331 TBool CMmListBoxItemDrawer::BitmapFitsIntoTarget(
       
  1332         TSize aBmpSize, TSize aTargetSize ) const
       
  1333     {
       
  1334     TBool widthLessOrEqual = aBmpSize.iWidth <= aTargetSize.iWidth;
       
  1335     TBool heightLessOrEqual = aBmpSize.iHeight <= aTargetSize.iHeight;
       
  1336     TBool widthAlmostEqual = Abs( aBmpSize.iWidth - aTargetSize.iWidth ) < 2;
       
  1337     TBool heightAlmostEqual = Abs( aBmpSize.iHeight - aTargetSize.iHeight ) < 2;
       
  1338     return ( widthLessOrEqual && heightAlmostEqual ) ||
       
  1339            ( widthAlmostEqual && heightLessOrEqual );
       
  1340     }
       
  1341 
       
  1342 // -----------------------------------------------------------------------------
       
  1343 //
       
  1344 // -----------------------------------------------------------------------------
       
  1345 //
       
  1346 void CMmListBoxItemDrawer::SetupTextSubcellL(
       
  1347         RArray<TTemplateChild>& aTemplateChildArray, TInt aChildIndex,
       
  1348         TInt aItemIndex, RBuf& aItemText, TInt& aSubcellIncrement ) const
       
  1349     {
       
  1350     TTemplateChild child = aTemplateChildArray[aChildIndex];
       
  1351     RBuf itemChildText;
       
  1352     CleanupClosePushL( itemChildText );
       
  1353     const TDesC8& mmTitleDes8 = iMmModel->GetAttributeAsText( aItemIndex,
       
  1354             child.iData );
       
  1355     itemChildText.Assign( HnConvUtils::Str8ToStr( mmTitleDes8 ) );
       
  1356 
       
  1357     AppendText( aItemText, itemChildText );
       
  1358 
       
  1359     const_cast<CMmListBoxItemDrawer*> ( this )->ReplaceSubCellText(
       
  1360             itemChildText );
       
  1361     CleanupStack::PopAndDestroy( &itemChildText );
       
  1362 
       
  1363     SetupSubCellL( child, aSubcellIncrement, aItemIndex );
       
  1364 
       
  1365     if( aChildIndex < aTemplateChildArray.Count() - 1 )
       
  1366         {
       
  1367         AppendText( aItemText, KTab );
       
  1368         }
       
  1369 
       
  1370     aSubcellIncrement++;
       
  1371       iLastSubcellsSetupCode.AddSubcellInfo( TMmSubcellsSetupCode::ETextSubcell );
       
  1372     }
       
  1373 // -----------------------------------------------------------------------------
       
  1374 //
       
  1375 // -----------------------------------------------------------------------------
       
  1376 //
       
  1377 void CMmListBoxItemDrawer::AppendText( RBuf& aBuffer, const TDesC& aTextToAppend ) const
       
  1378     {
       
  1379     TInt newLength = aBuffer.Length() + aTextToAppend.Length();
       
  1380     TInt error = KErrNone;
       
  1381 
       
  1382     if( aBuffer.MaxLength() < newLength )
       
  1383         {
       
  1384         error = aBuffer.ReAlloc( newLength );
       
  1385         }
       
  1386     if( error == KErrNone )
       
  1387         {
       
  1388         aBuffer.Append( aTextToAppend );
       
  1389         }
       
  1390     }
       
  1391 // -----------------------------------------------------------------------------
       
  1392 //
       
  1393 // -----------------------------------------------------------------------------
       
  1394 //
       
  1395 void CMmListBoxItemDrawer::SetupBackdropSubcellL(
       
  1396         RArray<TTemplateChild>& aTemplateChildArray, TInt aItemIndex,
       
  1397         RBuf& aItemText, TInt& aSubcellIncrement ) const
       
  1398     {
       
  1399     CGulIcon* icon = NULL;
       
  1400     for( TInt i = 0; i < aTemplateChildArray.Count() /*&&
       
  1401      aItemIndex != iWidget->View()->CurrentItemIndex()*/; ++i )
       
  1402         {
       
  1403         TTemplateChild child = aTemplateChildArray[i];
       
  1404         if( child.iImageVisualId == EImageVisualIdEditMode  &&
       
  1405                 child.iIsImage )
       
  1406             {
       
  1407             TSize itemSize = GetItemSize( aItemIndex,
       
  1408                 aItemIndex == iWidget->View()->CurrentItemIndex() );
       
  1409             CHnIconHolder* iconHolder = iMmModel->GetAttributeAsRefCountedGraphics(
       
  1410                     aItemIndex, child.iData, &itemSize );
       
  1411             icon = iconHolder ? iconHolder->GetGulIcon() : NULL;
       
  1412             if( icon )
       
  1413                 {
       
  1414                 CFbsBitmap* bitmap = icon->Bitmap();
       
  1415                 child.iRectAccordingToParent = TRect( TPoint( 0, 0 ),
       
  1416                         TPoint( itemSize.iWidth, itemSize.iHeight ) );
       
  1417                 AknIconUtils::SetSize( bitmap, itemSize,
       
  1418                         EAspectRatioNotPreserved );
       
  1419                 TInt iconIndex = iItemsDataCache->GetItemCacheL( aItemIndex )->
       
  1420                         AppendIconL( iconHolder );
       
  1421 
       
  1422                 HBufC8* number = HnConvUtils::NumToStr8LC( iconIndex );
       
  1423                 TInt newLength = aItemText.Length() + number->Length();
       
  1424                 if( aItemText.MaxLength() < newLength )
       
  1425                     {
       
  1426                     aItemText.ReAllocL( newLength );
       
  1427                     }
       
  1428                 CleanupStack::PopAndDestroy( number );
       
  1429                 aItemText.AppendNum( iconIndex );
       
  1430 
       
  1431                 newLength = aItemText.Length() + KTab().Length();
       
  1432                 if( aItemText.MaxLength() < newLength )
       
  1433                     {
       
  1434                     aItemText.ReAllocL( newLength );
       
  1435                     }
       
  1436                 aItemText.Append( KTab );
       
  1437                 SetupSubCellL( child, aSubcellIncrement, aItemIndex );
       
  1438                 aSubcellIncrement++;
       
  1439                 iLastSubcellsSetupCode.AddSubcellInfo( TMmSubcellsSetupCode::EBackdropSubcell );
       
  1440                 }
       
  1441             }
       
  1442         }
       
  1443     }
       
  1444 
       
  1445 // -----------------------------------------------------------------------------
       
  1446 //
       
  1447 // -----------------------------------------------------------------------------
       
  1448 //
       
  1449 void CMmListBoxItemDrawer::SetupSubCellsL( TBool aItemIsCurrent,
       
  1450         TInt aItemIndex ) const
       
  1451     {
       
  1452     CMmCacheForItem* cache = iItemsDataCache->GetItemCacheL( aItemIndex );
       
  1453     cache->MarkAsInvalid();
       
  1454 
       
  1455     const TDesC8& mmTemplate = iMmModel->GetAttributeAsText( aItemIndex, KMmTemplate8 );
       
  1456     if( !mmTemplate.Compare( KNullDesC8 ) || !mmTemplate.Compare( KEmpty8 ) )
       
  1457         {
       
  1458         User::Leave( KErrNotFound );
       
  1459         }
       
  1460     cache->SetTemplateL( mmTemplate );
       
  1461 
       
  1462     cache->ClearIconArray();
       
  1463     cache->SetCurrent( aItemIsCurrent );
       
  1464 
       
  1465     TBool landscapeOrientation = Layout_Meta_Data::IsLandscapeOrientation();
       
  1466 
       
  1467     RBuf& itemText = cache->GetItemTextForModifications();
       
  1468     itemText.Close();
       
  1469     itemText.CreateL( MmTemplateContants::KItemSubCellsText );
       
  1470 
       
  1471     RArray<TTemplateChild> templateChildArray;
       
  1472     CleanupClosePushL( templateChildArray );
       
  1473     if( !iIsIndicatorItem )
       
  1474         {
       
  1475         iTemplateLibrary->GetChildrenL( iWidgetType, templateChildArray, mmTemplate,
       
  1476         landscapeOrientation, aItemIsCurrent,	IsEditMode() );
       
  1477         }
       
  1478     else if ( !AknLayoutUtils::PenEnabled() )
       
  1479         {
       
  1480         iTemplateLibrary->GetMoveIndicatorChildrenL( iWidgetType, templateChildArray,
       
  1481                 mmTemplate, landscapeOrientation, aItemIsCurrent );
       
  1482         }
       
  1483 
       
  1484     iLastSubcellsSetupCode.Clear();
       
  1485 
       
  1486     //Backdrop icon as first element to draw
       
  1487     TInt subcellIncrement( 0 );
       
  1488     if( ( GetBackdropVisibility( aItemIndex, aItemIsCurrent )
       
  1489                 || ItemHasFloatingType( aItemIndex, ESwapTransition ) )
       
  1490             && !iIsSwapFloating )
       
  1491         {
       
  1492         SetupBackdropSubcellL( templateChildArray, aItemIndex, itemText, subcellIncrement );
       
  1493         iItemHasBackdrop = ETrue;
       
  1494         iIsSwapFloating = EFalse;
       
  1495         }
       
  1496     else
       
  1497         {
       
  1498         iItemHasBackdrop = EFalse;
       
  1499         }
       
  1500 
       
  1501     for ( TInt i( 0 ) ; i < templateChildArray.Count() && !iLeftOverAreaUnderAnimatedItem; i++ )
       
  1502         {
       
  1503         TTemplateChild child = templateChildArray[i];
       
  1504         if ( child.iImageVisualId == EImageVisualIdEditMode && child.iIsImage )
       
  1505             {
       
  1506             continue;
       
  1507             }
       
  1508         else if( !child.iIsImage )
       
  1509             {
       
  1510             SetupTextSubcellL( templateChildArray, i, aItemIndex, itemText, subcellIncrement );
       
  1511             }
       
  1512         else
       
  1513             {
       
  1514             SetupIconSubcellL( templateChildArray, i, aItemIndex, itemText, subcellIncrement );
       
  1515             }
       
  1516         }
       
  1517     TInt subcellsJustSet = subcellIncrement;
       
  1518     iCurrentNumberOfSubcellsSet = Max( iCurrentNumberOfSubcellsSet, subcellsJustSet );
       
  1519     __ASSERT_DEBUG( iCurrentNumberOfSubcellsSet <= MmTemplateContants::KSubCellsCount,
       
  1520             User::Invariant() );
       
  1521 
       
  1522     for( TInt i = subcellIncrement; i < iCurrentNumberOfSubcellsSet; i++ )
       
  1523         {
       
  1524         SetupSubNoCellL( i, aItemIndex );
       
  1525         }
       
  1526 
       
  1527     iLastSubcellsSetupCode.AddTemplateInfo(
       
  1528             iItemsDataCache->GetTemplateIdentifierL( mmTemplate ) );
       
  1529     iLastSubcellsSetupCode.AddIsCurrentInfo( aItemIsCurrent );
       
  1530 
       
  1531     CleanupStack::PopAndDestroy( &templateChildArray );
       
  1532 
       
  1533     cache->SetSubcellsSetupCode( iLastSubcellsSetupCode );
       
  1534     // the line below is here only to make the cached information complete
       
  1535     GetItemSize( aItemIndex, aItemIsCurrent );
       
  1536     cache->MarkAsValidL();
       
  1537     }
       
  1538 
       
  1539 // -----------------------------------------------------------------------------
       
  1540 //
       
  1541 // -----------------------------------------------------------------------------
       
  1542 //
       
  1543 CMmTemplateLibrary* CMmListBoxItemDrawer::TemplateLibrary()
       
  1544     {
       
  1545     return iTemplateLibrary;
       
  1546     }
       
  1547 
       
  1548 // -----------------------------------------------------------------------------
       
  1549 //
       
  1550 // -----------------------------------------------------------------------------
       
  1551 //
       
  1552 void CMmListBoxItemDrawer::SetHighlightShown( TBool aDrawn )
       
  1553     {
       
  1554     iHighlightShown = aDrawn;
       
  1555     iDrawMoveIndicators = aDrawn;
       
  1556     }
       
  1557 
       
  1558 // -----------------------------------------------------------------------------
       
  1559 //
       
  1560 // -----------------------------------------------------------------------------
       
  1561 //
       
  1562 TBool CMmListBoxItemDrawer::IsFloating( TInt aItemIndex ) const
       
  1563     {
       
  1564     TBool isFloating( EFalse );
       
  1565 
       
  1566     TInt index = GetFloatingItemIndex( EDrag );
       
  1567     if( index == KErrNotFound )
       
  1568         {
       
  1569         index = GetFloatingItemIndex( EDragTransition );
       
  1570         }
       
  1571     if( index == KErrNotFound )
       
  1572         {
       
  1573         index = GetFloatingItemIndex( EDragStart );
       
  1574         }
       
  1575 
       
  1576     if( KErrNotFound != index )
       
  1577         {
       
  1578         TMmFloatingItem& current = const_cast<CMmListBoxItemDrawer*>(this)->GetFloatingItemAtIndex( index );
       
  1579         TInt drawnIndex = current.GetDrawnItemIndex();
       
  1580         if( drawnIndex == aItemIndex )
       
  1581             {
       
  1582             isFloating = ETrue;
       
  1583             }
       
  1584         }
       
  1585     return isFloating;
       
  1586     }
       
  1587 
       
  1588 // -----------------------------------------------------------------------------
       
  1589 //
       
  1590 // -----------------------------------------------------------------------------
       
  1591 //
       
  1592 void CMmListBoxItemDrawer::DrawActualItem( TInt aItemIndex,
       
  1593         const TRect& aActualItemRect, TBool aItemIsCurrent,
       
  1594         TBool aViewIsEmphasized, TBool /*aViewIsDimmed*/,
       
  1595         TBool aItemIsSelected ) const
       
  1596     {
       
  1597     if( Properties( aItemIndex ).IsSelectionHidden() )
       
  1598         {
       
  1599         aItemIsSelected = EFalse;
       
  1600         }
       
  1601     DrawItemText( aItemIndex, aActualItemRect, aItemIsCurrent,
       
  1602             aViewIsEmphasized, aItemIsSelected );
       
  1603     }
       
  1604 
       
  1605 // -----------------------------------------------------------------------------
       
  1606 //
       
  1607 // -----------------------------------------------------------------------------
       
  1608 //
       
  1609 TBool CMmListBoxItemDrawer::GetHighlightVisibility( TInt aItemIndex,
       
  1610         TBool aItemIsCurrent, TBool aAllowHighlightForNonDraggedItem ) const
       
  1611     {
       
  1612     TBool highlightVisibility( EFalse );
       
  1613     if( !iItemHasBackdrop && !iLeftOverAreaUnderAnimatedItem ) //never draw highlight when item has backdrop or when left over area under animated item
       
  1614         {
       
  1615         TBool currentlyDraggedItem =
       
  1616                 ItemHasFloatingType( aItemIndex, EDrag )
       
  1617                 || ItemHasFloatingType( aItemIndex, EDragTransition )
       
  1618                 || ItemHasFloatingType( aItemIndex, EDragStart );
       
  1619 
       
  1620         if( ( STATIC_CAST(CMmWidgetContainer*,Widget()->Parent())->IsHighlightVisible()
       
  1621                 && aItemIsCurrent && aAllowHighlightForNonDraggedItem )
       
  1622                 || currentlyDraggedItem )
       
  1623             {
       
  1624             highlightVisibility = ETrue;
       
  1625             }
       
  1626         }
       
  1627     return highlightVisibility;
       
  1628     }
       
  1629 
       
  1630 // -----------------------------------------------------------------------------
       
  1631 //
       
  1632 // -----------------------------------------------------------------------------
       
  1633 //
       
  1634 TBool CMmListBoxItemDrawer::GetBackdropVisibility( TInt aItemIndex,
       
  1635         TBool aItemIsCurrent ) const
       
  1636     {
       
  1637     TBool currentlyDraggedItem =
       
  1638             ItemHasFloatingType( aItemIndex, EDrag )
       
  1639             || ItemHasFloatingType( aItemIndex, EDragTransition )
       
  1640             || ItemHasFloatingType( aItemIndex, EDragStart );
       
  1641 
       
  1642     return 	IsEditMode() /* draw the backdrop only in edit mode */
       
  1643         && !currentlyDraggedItem /* backdrop is disabled for dragged items */
       
  1644         && !iIsIndicatorItem /* in non-touch backdrop is not drawn, just "move indicators" */
       
  1645         && !iLeftOverAreaUnderAnimatedItem /* is the currently drawn item the area left over behind dragged item*/
       
  1646         && !( STATIC_CAST( CMmWidgetContainer*,Widget()->Parent() )->IsHighlightVisible()
       
  1647             && aItemIsCurrent );/*if the timer is active then we want to draw highlight (not backdrop) on the current index*/
       
  1648     }
       
  1649 
       
  1650 // -----------------------------------------------------------------------------
       
  1651 //
       
  1652 // -----------------------------------------------------------------------------
       
  1653 //
       
  1654 TBool CMmListBoxItemDrawer::ItemHasFloatingType( TInt aItemIndex,
       
  1655         TMmFloatingItemType aFloatingType ) const
       
  1656     {
       
  1657     TBool hasFloatingType( EFalse );
       
  1658     for( TInt i = iFloatingItems.Count() - 1; i >= 0; i-- )
       
  1659         {
       
  1660         const TMmFloatingItem& item = iFloatingItems[i];
       
  1661         if( item.GetFloatingItemType() == aFloatingType
       
  1662                 && item.GetDrawnItemIndex() == aItemIndex )
       
  1663             {
       
  1664             hasFloatingType = ETrue;
       
  1665             break;
       
  1666             }
       
  1667         }
       
  1668     return hasFloatingType;
       
  1669     }
       
  1670 // End of file