phonebookui/Phonebook2/ccapplication/ccacommlauncherplugin/src/ccappcommlaunchercustomlistboxitemdrawer.cpp
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
equal deleted inserted replaced
62:5b6f26637ad3 63:f4a778e096c2
       
     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: CCA customized control. Code has been modified to
       
    15 *       suit CCA requirements. See CFormattedCellListBoxItemDrawer
       
    16 *       in eikfrlb.cpp
       
    17 *       Ensure that this piece of code is in sync with Avkon eikfrlb.cpp(CFormattedCellListBoxItemDrawer) 
       
    18 *
       
    19 */
       
    20 
       
    21 #include <eikfrlb.h>
       
    22 #include <barsread.h>
       
    23 #include <gulicon.h>
       
    24 #include <AknUtils.h>
       
    25 #include <AknsControlContext.h>
       
    26 #include <AknBidiTextUtils.h>
       
    27 #include <aknlists.h>
       
    28 #include <aknlayoutscalable_avkon.cdl.h>
       
    29 #include <AknFontId.h>
       
    30 
       
    31 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
    32 #include <aknlistloadertfx.h>
       
    33 #include <aknlistboxtfxinternal.h>
       
    34 #include <aknlistboxtfx.h>
       
    35 #endif //RD_UI_TRANSITION_EFFECTS_LIST
       
    36 
       
    37 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS
       
    38 #include <akntransitionutils.h>
       
    39 #endif
       
    40 
       
    41 _LIT(KMarkReplacementString, "%S");
       
    42 
       
    43 #include "ccappcommlaunchercustomlistboxdata.h"
       
    44 #include "ccappcommlaunchercustomlistboxitemdrawer.h"
       
    45 
       
    46 CCCAppCommLauncherCustomListBoxItemDrawer::CCCAppCommLauncherCustomListBoxItemDrawer(MTextListBoxModel* aTextListBoxModel, 
       
    47                                  const CFont* aFont, 
       
    48                                  CCCAppCommLauncherCustomListBoxData* aFormattedCellData)
       
    49 						         : CTextListItemDrawer(aTextListBoxModel, aFont)
       
    50     {
       
    51     SetData(aFormattedCellData);
       
    52     }
       
    53 
       
    54 
       
    55 CCCAppCommLauncherCustomListBoxItemDrawer::~CCCAppCommLauncherCustomListBoxItemDrawer()
       
    56     {   
       
    57     delete iPropertyArray;
       
    58     }
       
    59 
       
    60 CCCAppCommLauncherCustomListBoxData* CCCAppCommLauncherCustomListBoxItemDrawer::FormattedCellData() const
       
    61     {
       
    62     return STATIC_CAST(CCCAppCommLauncherCustomListBoxData*,iData);
       
    63     }
       
    64 
       
    65 CCCAppCommLauncherCustomListBoxData* CCCAppCommLauncherCustomListBoxItemDrawer::ColumnData() const
       
    66     {
       
    67     return STATIC_CAST(CCCAppCommLauncherCustomListBoxData*,iData);
       
    68     }
       
    69 
       
    70 void CCCAppCommLauncherCustomListBoxItemDrawer::DrawEmptyItem( TInt /*aItemIndex*/,
       
    71                                                TPoint aItemRectPos,
       
    72                                                TBool /*aViewIsDimmed*/ ) const
       
    73    {
       
    74 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
    75    MAknListBoxTfxInternal* transApi = CAknListLoader::TfxApiInternal( iGc );
       
    76    if ( transApi )
       
    77        {
       
    78        transApi->StartDrawing( MAknListBoxTfxInternal::EListView );
       
    79        }
       
    80 #endif //RD_UI_TRANSITION_EFFECTS_LIST
       
    81    TRect r( aItemRectPos, iItemCellSize );
       
    82    CCoeControl* control = FormattedCellData()->Control();
       
    83    
       
    84     const MCoeControlBackground* backgroundDrawer = control->FindBackground();
       
    85    if ( control )
       
    86        {
       
    87        MAknsControlContext *cc = AknsDrawUtils::ControlContext( control );
       
    88 
       
    89        if ( !cc )
       
    90            {
       
    91            cc = FormattedCellData()->SkinBackgroundContext();
       
    92            }
       
    93         if ( backgroundDrawer )
       
    94             {
       
    95             backgroundDrawer->Draw( *iGc, *control, r );
       
    96             }
       
    97         else if ( CAknEnv::Static()->TransparencyEnabled() )
       
    98            {
       
    99            AknsDrawUtils::Background( AknsUtils::SkinInstance(), cc, control, *iGc, r,
       
   100                                   KAknsDrawParamNoClearUnderImage );
       
   101            }
       
   102        else
       
   103            {
       
   104            AknsDrawUtils::Background( AknsUtils::SkinInstance(), cc, control, *iGc, r,
       
   105                                   KAknsDrawParamNoClearUnderImage |
       
   106                                   KAknsDrawParamBottomLevelRGBOnly );
       
   107            }
       
   108        }
       
   109    else
       
   110        {
       
   111        iGc->Clear( r );
       
   112        }
       
   113 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   114    if ( transApi )
       
   115        {
       
   116        transApi->StopDrawing();
       
   117        }
       
   118 #endif //RD_UI_TRANSITION_EFFECTS_LIST
       
   119    }
       
   120 
       
   121 struct TLafTable;
       
   122 const TLafTable &BgListPaneTable();
       
   123 
       
   124 
       
   125 void CCCAppCommLauncherCustomListBoxItemDrawer::DrawItemText( TInt aItemIndex,
       
   126                                                    const TRect& aItemTextRect,
       
   127                                                    TBool aItemIsCurrent,
       
   128                                                    TBool aViewIsEmphasized, 
       
   129                                                    TBool aItemIsSelected) const
       
   130    {
       
   131 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   132    MAknListBoxTfxInternal* transApi = CAknListLoader::TfxApiInternal( iGc );
       
   133    if ( transApi )
       
   134        {
       
   135        transApi->StartDrawing( MAknListBoxTfxInternal::EListNotSpecified );
       
   136        }
       
   137 #endif //RD_UI_TRANSITION_EFFECTS_LIST
       
   138    iGc->SetPenColor(iTextColor);
       
   139    iGc->SetBrushColor(iBackColor);
       
   140 
       
   141    TPtrC temp=iModel->ItemText(aItemIndex);
       
   142 
       
   143    SetupGc(aItemIndex);
       
   144 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   145    if ( transApi )
       
   146        {
       
   147        transApi->StopDrawing();
       
   148        }
       
   149 #endif //RD_UI_TRANSITION_EFFECTS_LIST
       
   150 
       
   151    TBool removeicon = (!aItemIsSelected && !ItemMarkReverse()) || (aItemIsSelected && ItemMarkReverse());
       
   152 
       
   153    CCCAppCommLauncherCustomListBoxData::TColors colors;
       
   154    colors.iText=iTextColor;
       
   155    colors.iBack=iBackColor;
       
   156    colors.iHighlightedText=iHighlightedTextColor;
       
   157    colors.iHighlightedBack=iHighlightedBackColor;
       
   158    
       
   159    DrawBackgroundAndSeparatorLines( aItemTextRect, 
       
   160             aItemIndex != FormattedCellData()->ListBox()->BottomItemIndex() );
       
   161    
       
   162    TBool highlightShown = ETrue;
       
   163    
       
   164    if (FormattedCellData()->RespectFocus() && !aViewIsEmphasized)
       
   165        {
       
   166 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   167        if ( transApi )
       
   168            {
       
   169            transApi->Remove( MAknListBoxTfxInternal::EListHighlight );
       
   170            }
       
   171 #endif //RD_UI_TRANSITION_EFFECTS_LIST
       
   172 
       
   173        highlightShown = EFalse;
       
   174        }
       
   175        
       
   176    if (FormattedCellData()->IsMarqueeOn() && FormattedCellData()->CurrentMarqueeItemIndex() != aItemIndex && aItemIsCurrent)
       
   177        {
       
   178        FormattedCellData()->ResetMarquee();
       
   179        FormattedCellData()->SetCurrentMarqueeItemIndex(aItemIndex);
       
   180        }
       
   181    
       
   182    if ( aItemIsCurrent )
       
   183        {
       
   184        FormattedCellData()->SetCurrentItemIndex( aItemIndex );
       
   185        }
       
   186        
       
   187    FormattedCellData()->SetCurrentlyDrawnItemIndex( aItemIndex );
       
   188    
       
   189    // drawing with mark icon
       
   190    if ( Flags() & EDrawMarkSelection && ItemMarkPosition() != -1 && removeicon)
       
   191        {
       
   192        // Try to allocate buffer dynamically. If out of memory, just use normal drawing
       
   193        // without mark icon.
       
   194        // (+2 is for the possible 2 additional column separators)
       
   195        TPtrC repl;
       
   196        repl.Set( ItemMarkReplacement() );        
       
   197        TInt size = temp.Length() + repl.Length() + 2;
       
   198        //TBufC<KMaxTotalDataLength> target(KNullDesC);
       
   199        HBufC* buffer = HBufC::New( size );
       
   200 
       
   201        if( buffer )
       
   202            {
       
   203            TPtr des = buffer->Des();
       
   204            TInt markPos = ItemMarkPosition(); // -1 if not set
       
   205            TInt startPos(0);
       
   206            TInt endPos(0);
       
   207            
       
   208            while( endPos < temp.Length() && markPos >= 0 )
       
   209                {
       
   210                if( temp[endPos] == '\t' )
       
   211                    {
       
   212                    markPos--;
       
   213                    if( markPos == 0 )
       
   214                        {
       
   215                        startPos = endPos + 1; // +1 for column separator
       
   216                        }
       
   217                    }
       
   218                endPos++;
       
   219                }
       
   220 
       
   221            if( markPos > 0 ) // mark icon will go somewhere after item string...
       
   222                {
       
   223                startPos = temp.Length();
       
   224                endPos = temp.Length();
       
   225                des.Append( temp.Left( startPos ) ); // first part of string
       
   226                des.Append( '\t' ); // column separator before mark icon was missing                
       
   227                }
       
   228            else
       
   229                {
       
   230                des.Append( temp.Left( startPos ) ); // first part of string
       
   231                }
       
   232 
       
   233            TInt replace = repl.FindF(KMarkReplacementString);
       
   234            if (replace != KErrNotFound) // moving subcell
       
   235                {
       
   236                des.Append( repl.Left( replace ) );
       
   237                // now we have first part of string + mark subcell
       
   238                // then add 1 moved subcell
       
   239                des.Append( temp.Mid( startPos, endPos-startPos ) );
       
   240 
       
   241                // skip second moved subcell and add rest of the string
       
   242                while( endPos < temp.Length() )
       
   243                    {
       
   244                    if( temp[endPos] == '\t' )
       
   245                        {
       
   246                        break;
       
   247                        }
       
   248                    endPos++;
       
   249                    }
       
   250                if( endPos < temp.Length() ) // this cuts off '\t'
       
   251                    {
       
   252                    endPos++;
       
   253                    }
       
   254                des.Append( temp.Mid( endPos ) );
       
   255                
       
   256                //is this needed - currently not used in S60?
       
   257                //buffer.Append(aReplacement->Mid(replace+2)); // 2 == length of %s
       
   258                }
       
   259            else // just replacement
       
   260                {
       
   261                des.Append( repl ); // no '%s' in replacement string
       
   262                des.Append( '\t' );
       
   263                des.Append( temp.Mid( endPos ) );
       
   264                }
       
   265 
       
   266            des.Set( buffer->Des() );
       
   267            FormattedCellData()->Draw( Properties(aItemIndex),
       
   268                                       *iGc,
       
   269                                       &des,
       
   270                                       aItemTextRect,
       
   271                                       aItemIsCurrent && highlightShown,
       
   272                                       colors );
       
   273            delete buffer;
       
   274            return;
       
   275            }
       
   276        }
       
   277 
       
   278    // normal drawing without mark icon
       
   279    FormattedCellData()->Draw( Properties(aItemIndex),
       
   280                               *iGc,
       
   281                               &temp,
       
   282                               aItemTextRect,
       
   283                               aItemIsCurrent && highlightShown,
       
   284                               colors );
       
   285    }
       
   286 
       
   287 TSize CCCAppCommLauncherCustomListBoxItemDrawer::MinimumCellSize() const 
       
   288    {
       
   289    CCCAppCommLauncherCustomListBoxData* data=FormattedCellData();
       
   290    const TInt cells=data->LastSubCell();
       
   291    if (cells==-1)
       
   292        return CTextListItemDrawer::MinimumCellSize();
       
   293    TInt width=0;
       
   294    TInt height=0;
       
   295    for(TInt ii=0;ii<cells;ii++) 
       
   296        {
       
   297        TPoint endpos( data->SubCellPosition(ii) + data->SubCellSize(ii) );
       
   298        if (endpos.iX > width) width = endpos.iX;
       
   299        if (endpos.iY > height) height = endpos.iY;
       
   300        }
       
   301    height+=VerticalInterItemGap();
       
   302    return TSize(width,height);
       
   303    }
       
   304 
       
   305 
       
   306 void CCCAppCommLauncherCustomListBoxItemDrawer::DrawItemMark(TBool /*aItemIsSelected*/, TBool /*aViewIsDimmed*/, const TPoint& /*aMarkPos*/) const
       
   307    {
       
   308    }
       
   309 
       
   310 
       
   311 TInt CCCAppCommLauncherCustomListBoxItemDrawer::ItemWidthInPixels(TInt) const
       
   312    {
       
   313    TInt itemWidth = MinimumCellSize().iWidth;
       
   314    
       
   315    if (iDrawMark)
       
   316        itemWidth += (iMarkColumnWidth + iMarkGutter);
       
   317    return itemWidth;
       
   318    }
       
   319 
       
   320 void CCCAppCommLauncherCustomListBoxItemDrawer::SetItemCellSize(
       
   321    const TSize& aSizeInPixels )
       
   322    {
       
   323    CTextListItemDrawer::SetItemCellSize( aSizeInPixels );
       
   324 
       
   325    // Data needs the cell size to create/reconfigure highlight animations
       
   326    FormattedCellData()->SetItemCellSize( iItemCellSize );
       
   327    }
       
   328 
       
   329 void CCCAppCommLauncherCustomListBoxItemDrawer::SetTopItemIndex(TInt aTop)
       
   330    {
       
   331    iTopItemIndex = aTop;
       
   332    }
       
   333 
       
   334 void CCCAppCommLauncherCustomListBoxItemDrawer::DrawCurrentItemRect(const TRect& aRect) const
       
   335    {
       
   336    iGc->SetClippingRect(iViewRect);
       
   337    iGc->SetBrushStyle(CGraphicsContext::ENullBrush);
       
   338    iGc->SetPenColor(iHighlightedBackColor);
       
   339    iGc->DrawRect(aRect);
       
   340    iGc->CancelClippingRect();
       
   341    }
       
   342 
       
   343 void CCCAppCommLauncherCustomListBoxItemDrawer::ClearAllPropertiesL()
       
   344     {
       
   345     delete iPropertyArray;
       
   346     iPropertyArray = NULL;
       
   347     iPropertyArray = new (ELeave) CArrayFixFlat<SListProperties>(2);    
       
   348     }
       
   349 
       
   350 void CCCAppCommLauncherCustomListBoxItemDrawer::SetPropertiesL(TInt aItemIndex, TListItemProperties aProperty)
       
   351     {
       
   352     if (!iPropertyArray) ClearAllPropertiesL();
       
   353     TInt index;
       
   354     TKeyArrayFix key(0,ECmpTInt);
       
   355     SListProperties prop;
       
   356     prop.iItem = aItemIndex;
       
   357     TInt error = iPropertyArray->FindIsq(prop, key, index);
       
   358     if (error)
       
   359     { // not found, error is nonzero.
       
   360     iPropertyArray->InsertIsqL(prop, key);
       
   361     iPropertyArray->FindIsq(prop, key, index);
       
   362     }
       
   363     iPropertyArray->At(index).iProperties = aProperty;
       
   364     }
       
   365 
       
   366 TListItemProperties CCCAppCommLauncherCustomListBoxItemDrawer::Properties(TInt aItemIndex) const
       
   367     {
       
   368 
       
   369     if (!iPropertyArray) return CTextListItemDrawer::Properties(aItemIndex);
       
   370     CAknListBoxFilterItems *filter = STATIC_CAST(CAknFilteredTextListBoxModel*,iModel)->Filter();
       
   371     if (filter)
       
   372     {
       
   373     aItemIndex = filter->FilteredItemIndex(aItemIndex);
       
   374     }
       
   375     TKeyArrayFix key(0,ECmpTInt);
       
   376     SListProperties prop;
       
   377     prop.iItem = aItemIndex;
       
   378     TInt index;
       
   379     TInt error = iPropertyArray->FindIsq(prop, key, index);
       
   380     if (error) return CTextListItemDrawer::Properties(aItemIndex);
       
   381     return iPropertyArray->At(index).iProperties;
       
   382     }
       
   383 
       
   384 
       
   385 
       
   386 void CCCAppCommLauncherCustomListBoxItemDrawer::CCCAppCommLauncherCustomListBoxItemDrawer_Reserved()
       
   387     {
       
   388     }
       
   389 
       
   390 void CCCAppCommLauncherCustomListBoxItemDrawer::DrawBackgroundAndSeparatorLines( 
       
   391         const TRect& aItemTextRect, TBool aDrawSeparator ) const
       
   392     {
       
   393     MAknsSkinInstance *skin = AknsUtils::SkinInstance();
       
   394     CCoeControl* control = FormattedCellData()->Control();
       
   395     MAknsControlContext *cc = AknsDrawUtils::ControlContext( control );
       
   396 
       
   397     if ( !cc )
       
   398         {
       
   399         cc = FormattedCellData()->SkinBackgroundContext();
       
   400         }
       
   401 
       
   402 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   403     MAknListBoxTfxInternal* transApi = CAknListLoader::TfxApiInternal( iGc );
       
   404     
       
   405     if ( transApi && !transApi->EffectsDisabled() )
       
   406         {
       
   407         MAknListBoxTfx* tfxApi = CAknListLoader::TfxApi( iGc );
       
   408 
       
   409         if ( tfxApi )
       
   410             {
       
   411             tfxApi->EnableEffects( FormattedCellData()->IsBackgroundDrawingEnabled() );
       
   412             }
       
   413         }
       
   414 #endif // RD_UI_TRANSITION_EFFECTS_LIST
       
   415 
       
   416     // background
       
   417     if ( FormattedCellData()->IsBackgroundDrawingEnabled() )
       
   418         {
       
   419 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   420         MAknListBoxTfxInternal* transApi = CAknListLoader::TfxApiInternal( iGc );
       
   421         if ( transApi )
       
   422             {
       
   423             transApi->StartDrawing( MAknListBoxTfxInternal::EListView );
       
   424             }
       
   425 #endif // RD_UI_TRANSITION_EFFECTS_LIST
       
   426         TBool bgDrawn( EFalse );
       
   427         if ( control )
       
   428             {
       
   429             const MCoeControlBackground* backgroundDrawer =
       
   430                 control->FindBackground();
       
   431             if ( backgroundDrawer )
       
   432                 {
       
   433                 backgroundDrawer->Draw( *iGc, *control, aItemTextRect );
       
   434                 bgDrawn = ETrue;
       
   435                 }
       
   436             else if ( CAknEnv::Static()->TransparencyEnabled() )
       
   437                 {
       
   438                 bgDrawn = AknsDrawUtils::Background(
       
   439                     skin, cc, control, *iGc, aItemTextRect,
       
   440                     KAknsDrawParamNoClearUnderImage );
       
   441                 }
       
   442             else
       
   443                 {
       
   444                 bgDrawn = AknsDrawUtils::Background(
       
   445                     skin, cc, control, *iGc, aItemTextRect,
       
   446                     KAknsDrawParamNoClearUnderImage | 
       
   447                     KAknsDrawParamBottomLevelRGBOnly );
       
   448                 }
       
   449             }
       
   450         if ( !bgDrawn )
       
   451             {
       
   452             iGc->Clear( aItemTextRect );
       
   453             }
       
   454 #ifdef RD_UI_TRANSITION_EFFECTS_LIST  
       
   455         if ( transApi )
       
   456             {
       
   457             transApi->StopDrawing();
       
   458             }
       
   459 #endif // RD_UI_TRANSITION_EFFECTS_LIST
       
   460         if ( aDrawSeparator && control &&
       
   461             static_cast<CEikListBox*>( control )->ItemsInSingleLine() == 1 )
       
   462             {
       
   463             AknListUtils::DrawSeparator( *iGc, aItemTextRect, iTextColor );
       
   464             }
       
   465         }
       
   466     }
       
   467 
       
   468 // End of File