emailuis/uicomponents/src/fstreeitemvisualizerbase.cpp
changeset 0 8466d47a6819
child 16 4ce476e64c59
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     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:  Base class of item visualizer.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include <AknsUtils.h>
       
    21 #include <AknsSkinInstance.h>
       
    22 #include <biditext.h>
       
    23 
       
    24 #include "fstreeitemvisualizerbase.h"
       
    25 #include "fstreelist.h"
       
    26 #include "fslayoutmanager.h"
       
    27 #include "fsalftextstylemanager.h"
       
    28 
       
    29 // <cmail> SF
       
    30 #include <alf/alfgradientbrush.h>
       
    31 #include <alf/alfimagebrush.h>
       
    32 #include <alf/alfanchorlayout.h>
       
    33 #include <alf/alfcontrol.h>
       
    34 #include <alf/alftexture.h>
       
    35 #include <alf/alfimage.h>
       
    36 #include <alf/alfenv.h>
       
    37 #include <alf/alftextstyle.h>
       
    38 #include <alf/alftextvisual.h>
       
    39 #include <alf/alfmappingfunctions.h>
       
    40 // </cmail>
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // C++ destructor.
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 CFsTreeItemVisualizerBase::~CFsTreeItemVisualizerBase()
       
    47     {
       
    48     FUNC_LOG;
       
    49     if (iLayout)
       
    50         {
       
    51         iLayout->Env().CancelCustomCommands(this);
       
    52         iLayout->RemoveAndDestroyAllD();
       
    53         }
       
    54     }
       
    55 
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // Returns visualizer's type.
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 TFsTreeItemVisualizerType CFsTreeItemVisualizerBase::Type() const
       
    62     {
       
    63     FUNC_LOG;
       
    64     return EFsTreeItemVisualizerBase;
       
    65     }
       
    66 
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 //  Sets the alignment for text item.
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 void CFsTreeItemVisualizerBase::SetTextAlign(
       
    73     const TAlfAlignHorizontal aAlign )
       
    74     {
       
    75     FUNC_LOG;
       
    76     iTextAlign = aAlign;
       
    77     }
       
    78 
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 //  The function sets item's text color for the focused state.
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 void CFsTreeItemVisualizerBase::SetFocusedStateTextColor( TRgb& aColor )
       
    85     {
       
    86     FUNC_LOG;
       
    87     iIsCustomTextFocusedColor = ETrue;
       
    88     iFocusedTextColor = aColor;
       
    89     }
       
    90 
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 //  The function returns item's text color for the focused state.
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 TRgb CFsTreeItemVisualizerBase::FocusedStateTextColor() const
       
    97     {
       
    98     FUNC_LOG;
       
    99     return iFocusedTextColor;
       
   100     }
       
   101 
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 //  The function sets item's text color for the normal (unfocused) state.
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 void CFsTreeItemVisualizerBase::SetNormalStateTextColor( TRgb& aColor )
       
   108     {
       
   109     FUNC_LOG;
       
   110     iIsCustomTextNormalColor = ETrue;
       
   111     iNormalTextColor = aColor;
       
   112     }
       
   113 
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // The function returns item's text color for the normal (unfocused) state.
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 TRgb CFsTreeItemVisualizerBase::NormalStateTextColor() const
       
   120     {
       
   121     FUNC_LOG;
       
   122     return iNormalTextColor;
       
   123     }
       
   124 
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 //  The function sets the style of item's text.
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CFsTreeItemVisualizerBase::SetTextStyleId ( const TInt aTextStyleId )
       
   131     {
       
   132     FUNC_LOG;
       
   133     iIsCustomTextStyle = ETrue;
       
   134     iTextStyleId = aTextStyleId;
       
   135     }
       
   136 
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 //  The function returns the style of item's text.
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 TInt CFsTreeItemVisualizerBase::TextStyleId () const
       
   143     {
       
   144     FUNC_LOG;
       
   145     TInt styleId(0);
       
   146     if ( iIsCustomTextStyle )
       
   147         {
       
   148         styleId = iTextStyleId;
       
   149         }
       
   150     else
       
   151         {
       
   152         TRAP_IGNORE( styleId = ModifiedStyleIdL() );
       
   153         }
       
   154     return styleId;
       
   155     }
       
   156 
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // From class MFsTreeItemVisualizer.
       
   160 // Sets multiple flags for an item at one time.
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 void CFsTreeItemVisualizerBase::SetFlags( TUint32 aFlags )
       
   164     {
       
   165     FUNC_LOG;
       
   166     iFlags = aFlags;
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // From class MFsTreeItemVisualizer.
       
   171 // Returns flags of the item visualizer.
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 TUint32 CFsTreeItemVisualizerBase::Flags()
       
   175     {
       
   176     FUNC_LOG;
       
   177     return iFlags;
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // From class MFsTreeItemVisualizer.
       
   182 // Sets visualized item's state to marked/unmarked.
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 void CFsTreeItemVisualizerBase::SetMarked( TBool aFlag )
       
   186     {
       
   187     FUNC_LOG;
       
   188     if ( aFlag )
       
   189         {
       
   190         iFlags |= KFsTreeListItemMarked;
       
   191         }
       
   192     else
       
   193         {
       
   194         iFlags &= ~KFsTreeListItemMarked;
       
   195         }
       
   196     }
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // From class MFsTreeItemVisualizer.
       
   200 // Returns mark/unmark state of the item's visualization.
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 TBool CFsTreeItemVisualizerBase::IsMarked() const
       
   204     {
       
   205     FUNC_LOG;
       
   206     return iFlags & KFsTreeListItemMarked ? ETrue : EFalse;
       
   207     }
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // From class MFsTreeItemVisualizer.
       
   211 // Sets visualized item's state to dimmed/not dimmed.
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 void CFsTreeItemVisualizerBase::SetDimmed( TBool aFlag )
       
   215     {
       
   216     FUNC_LOG;
       
   217     if ( aFlag )
       
   218         {
       
   219         iFlags |= KFsTreeListItemDimmed;
       
   220         }
       
   221     else
       
   222         {
       
   223         iFlags &= ~KFsTreeListItemDimmed;
       
   224         }
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // From class MFsTreeItemVisualizer.
       
   229 // Returns dimmed/not dimmed state of the item's visualization.
       
   230 // ---------------------------------------------------------------------------
       
   231 //
       
   232 TBool CFsTreeItemVisualizerBase::IsDimmed() const
       
   233     {
       
   234     FUNC_LOG;
       
   235     return iFlags & KFsTreeListItemDimmed ? ETrue : EFalse;
       
   236     }
       
   237 
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // From class MFsTreeItemVisualizer.
       
   241 // Sets the size of the item visualization when item is not in expanded state.
       
   242 // ---------------------------------------------------------------------------
       
   243 //
       
   244 void CFsTreeItemVisualizerBase::SetSize( const TSize aSize )
       
   245     {
       
   246     FUNC_LOG;
       
   247     iSize = aSize;
       
   248     }
       
   249 
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 // From class MFsTreeItemVisualizer.
       
   253 // Returns the size of an item in a normal (not expanded) state.
       
   254 // ---------------------------------------------------------------------------
       
   255 //
       
   256 
       
   257 #include <AknUtils.h>
       
   258 
       
   259 TSize CFsTreeItemVisualizerBase::Size() const
       
   260     {
       
   261     FUNC_LOG;
       
   262     if ( iFlags & KFsTreeListItemManagedLayout )
       
   263         {
       
   264         CFsLayoutManager::TFsLayoutMetrics normalSizeMetrics (CFsLayoutManager::EFsLmListSingleDycRowPane);
       
   265         TRect mainPaneRect;
       
   266         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
       
   267         TSize size(0,0);
       
   268         TBool retVal(EFalse);
       
   269 
       
   270                
       
   271         retVal = CFsLayoutManager::LayoutMetricsSize(
       
   272                 mainPaneRect,
       
   273                 normalSizeMetrics,
       
   274                 size );
       
   275 
       
   276         if ( !retVal )
       
   277             {
       
   278             size = iSize;
       
   279             }
       
   280 
       
   281         return size;
       
   282         }
       
   283     else
       
   284         {
       
   285         return iSize;
       
   286         }
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // From class MFsTreeItemVisualizer.
       
   291 // Sets the item's visualization state to expanded.
       
   292 // ---------------------------------------------------------------------------
       
   293 //
       
   294 void CFsTreeItemVisualizerBase::SetExtended( const TBool aFlag )
       
   295     {
       
   296     FUNC_LOG;
       
   297     if ( aFlag )
       
   298         {
       
   299         iFlags |= KFsTreeListItemExtended;
       
   300         }
       
   301     else
       
   302         {
       
   303         iFlags &= ~KFsTreeListItemExtended;
       
   304         }
       
   305     }
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 // From class MFsTreeItemVisualizer.
       
   309 // Returns expanded/not expanded state of the item visualization.
       
   310 // ---------------------------------------------------------------------------
       
   311 //
       
   312 TBool CFsTreeItemVisualizerBase::IsExtended() const
       
   313     {
       
   314     FUNC_LOG;
       
   315     return iFlags & KFsTreeListItemExtended ? ETrue : EFalse;
       
   316     }
       
   317 
       
   318 // ---------------------------------------------------------------------------
       
   319 // From class MFsTreeItemVisualizer.
       
   320 // Sets if an item can be in expanded state or not.
       
   321 // ---------------------------------------------------------------------------
       
   322 //
       
   323 void CFsTreeItemVisualizerBase::SetExtendable( TBool aFlag )
       
   324     {
       
   325     FUNC_LOG;
       
   326     if ( aFlag )
       
   327         {
       
   328         iFlags |= KFsTreeListItemExtendable;
       
   329         }
       
   330     else
       
   331         {
       
   332         iFlags &= ~KFsTreeListItemExtendable;
       
   333         }
       
   334     }
       
   335 
       
   336 // ---------------------------------------------------------------------------
       
   337 // From class MFsTreeItemVisualizer.
       
   338 // Returns an information if item can be in expanded state.
       
   339 // ---------------------------------------------------------------------------
       
   340 //
       
   341 TBool CFsTreeItemVisualizerBase::IsExtendable( )
       
   342     {
       
   343     FUNC_LOG;
       
   344     return iFlags & KFsTreeListItemExtendable ? ETrue : EFalse;
       
   345     }
       
   346 
       
   347 // ---------------------------------------------------------------------------
       
   348 // From class MFsTreeItemVisualizer.
       
   349 // Returns an information if item can be focusable.
       
   350 // ---------------------------------------------------------------------------
       
   351 //
       
   352 TBool CFsTreeItemVisualizerBase::IsFocusable( ) const
       
   353     {
       
   354     FUNC_LOG;
       
   355     return iFlags & KFsTreeListItemFocusable ? ETrue : EFalse;
       
   356     }
       
   357 
       
   358 // ---------------------------------------------------------------------------
       
   359 // From class MFsTreeItemVisualizer.
       
   360 // Sets the item's ability to receive focus.
       
   361 // ---------------------------------------------------------------------------
       
   362 //
       
   363 void CFsTreeItemVisualizerBase::SetFocusable( const TBool aFlag )
       
   364     {
       
   365     FUNC_LOG;
       
   366     if ( aFlag )
       
   367         {
       
   368         iFlags |= KFsTreeListItemFocusable;
       
   369         }
       
   370     else
       
   371         {
       
   372         iFlags &= ~KFsTreeListItemFocusable;
       
   373         }
       
   374     }
       
   375 
       
   376 // ---------------------------------------------------------------------------
       
   377 // From class MFsTreeItemVisualizer.
       
   378 // Sets the size of the item visualization area when item is in expanded
       
   379 // state.
       
   380 // ---------------------------------------------------------------------------
       
   381 //
       
   382 void CFsTreeItemVisualizerBase::SetExtendedSize(
       
   383     const TSize aExtendedSize )
       
   384     {
       
   385     FUNC_LOG;
       
   386     iExtendedSize = aExtendedSize;
       
   387     }
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // From class MFsTreeItemVisualizer.
       
   391 // Returns the size of an item in expanded state.
       
   392 // ---------------------------------------------------------------------------
       
   393 //
       
   394 TSize CFsTreeItemVisualizerBase::ExtendedSize() const
       
   395     {
       
   396     FUNC_LOG;
       
   397     if ( iFlags & KFsTreeListItemManagedLayout )
       
   398         {
       
   399         CFsLayoutManager::TFsLayoutMetrics extendedSizeMetrics( CFsLayoutManager::EFsLmListMediumLineX2 );
       
   400         TRect parentLayoutRect(0,0,0,0);
       
   401         TSize extSize(0,0);
       
   402         TBool retVal(EFalse);
       
   403 
       
   404         retVal = CFsLayoutManager::LayoutMetricsSize(
       
   405                                     parentLayoutRect,
       
   406                                     extendedSizeMetrics,
       
   407                                     extSize );
       
   408 
       
   409         if ( !retVal )
       
   410             {
       
   411             extSize = iExtendedSize;
       
   412             }
       
   413 
       
   414         return extSize;
       
   415         }
       
   416     else
       
   417         {
       
   418         return iExtendedSize;
       
   419         }
       
   420     }
       
   421 
       
   422 // ---------------------------------------------------------------------------
       
   423 // From class MFsTreeItemVisualizer.
       
   424 // Sets visualized item's state to hidden/visible.
       
   425 // ---------------------------------------------------------------------------
       
   426 //
       
   427 void CFsTreeItemVisualizerBase::SetHidden( TBool aFlag )
       
   428     {
       
   429     FUNC_LOG;
       
   430     if ( aFlag )
       
   431         {
       
   432         iFlags |= KFsTreeListItemHidden;
       
   433         }
       
   434     else
       
   435         {
       
   436         iFlags &= ~KFsTreeListItemHidden;
       
   437         }
       
   438     }
       
   439 
       
   440 // ---------------------------------------------------------------------------
       
   441 // From class MFsTreeItemVisualizer.
       
   442 // Returns an information if the item is hidden or not.
       
   443 // ---------------------------------------------------------------------------
       
   444 //
       
   445 TBool CFsTreeItemVisualizerBase::IsHidden()
       
   446     {
       
   447     FUNC_LOG;
       
   448     return iFlags & KFsTreeListItemHidden ? ETrue : EFalse;
       
   449     }
       
   450 
       
   451 // ---------------------------------------------------------------------------
       
   452 // From MFsTreeItemVisualizer.
       
   453 // Enables or disables text shadow.
       
   454 // ---------------------------------------------------------------------------
       
   455 //
       
   456 void CFsTreeItemVisualizerBase::EnableTextShadow(
       
   457         const TBool aShadowOn )
       
   458     {
       
   459     FUNC_LOG;
       
   460     if (aShadowOn)
       
   461         {
       
   462         iFlags |= KFsTreeListItemTextShadow;
       
   463         }
       
   464     else
       
   465         {
       
   466         iFlags &= ~KFsTreeListItemTextShadow;
       
   467         }
       
   468     }
       
   469 
       
   470 // ---------------------------------------------------------------------------
       
   471 // From class MFsTreeItemVisualizer.
       
   472 // Sets text indentation.
       
   473 // ---------------------------------------------------------------------------
       
   474 void CFsTreeItemVisualizerBase::SetIndentation(
       
   475         const TInt aIndentation )
       
   476     {
       
   477     FUNC_LOG;
       
   478     iTextIndentation = aIndentation;
       
   479     }
       
   480 
       
   481 
       
   482 // ---------------------------------------------------------------------------
       
   483 // From MFsTreeItemVisualizer.
       
   484 // Sets item background color.
       
   485 // ---------------------------------------------------------------------------
       
   486 //
       
   487 void CFsTreeItemVisualizerBase::SetBackgroundColor(const TRgb aColor)
       
   488     {
       
   489     FUNC_LOG;
       
   490     iBackgroundColor = aColor;
       
   491     iBackgroundState = EFsItemBackgroundColor;
       
   492     }
       
   493 
       
   494 // ---------------------------------------------------------------------------
       
   495 // From MFsTreeItemVisualizer.
       
   496 // Returns background color if it's set.
       
   497 // ---------------------------------------------------------------------------
       
   498 //
       
   499 TBool CFsTreeItemVisualizerBase::GetBackgroundColor( TRgb& aColor )
       
   500     {
       
   501     FUNC_LOG;
       
   502     TBool retVal(EFalse);
       
   503     if ( iBackgroundState == EFsItemBackgroundColor )
       
   504         {
       
   505         aColor = iBackgroundColor;
       
   506         retVal = ETrue;
       
   507         }
       
   508     return retVal;
       
   509     }
       
   510 
       
   511 // ---------------------------------------------------------------------------
       
   512 // From MFsTreeItemVisualizer.
       
   513 // Sets item background texture.
       
   514 // ---------------------------------------------------------------------------
       
   515 //
       
   516 void CFsTreeItemVisualizerBase::SetBackgroundTexture(
       
   517         const CAlfTexture& aTexture)
       
   518     {
       
   519     FUNC_LOG;
       
   520     iBackgroundTexture = &aTexture;
       
   521     iBackgroundState = EFsItemBackgroundTexture;
       
   522     }
       
   523 
       
   524 // ---------------------------------------------------------------------------
       
   525 // From MFsTreeItemVisualizer.
       
   526 // Returns background texture if it's set.
       
   527 // ---------------------------------------------------------------------------
       
   528 //
       
   529 TBool CFsTreeItemVisualizerBase::GetBackgroundTexture( const CAlfTexture*& aTexture )
       
   530     {
       
   531     FUNC_LOG;
       
   532     TBool retVal( EFalse );
       
   533     if ( iBackgroundState == EFsItemBackgroundTexture )
       
   534         {
       
   535         aTexture = iBackgroundTexture;
       
   536         retVal = ETrue;
       
   537         }
       
   538     return retVal;
       
   539     }
       
   540 
       
   541 // <cmail>
       
   542 // ---------------------------------------------------------------------------
       
   543 // From MFsTreeItemVisualizer.
       
   544 // Sets item background brush.
       
   545 // ---------------------------------------------------------------------------
       
   546 //
       
   547 void CFsTreeItemVisualizerBase::SetBackgroundBrush( CAlfBrush* aBrush )
       
   548     {
       
   549     FUNC_LOG;
       
   550     iBackgroundBrush = aBrush;
       
   551     iBackgroundState = EFsItemBackgroundBrush;
       
   552     }
       
   553 
       
   554 // ---------------------------------------------------------------------------
       
   555 // From MFsTreeItemVisualizer.
       
   556 // Returns item background brush and opacity.
       
   557 // ---------------------------------------------------------------------------
       
   558 //
       
   559 TBool CFsTreeItemVisualizerBase::GetBackgroundBrush( CAlfBrush*& aBrush )
       
   560     {
       
   561     FUNC_LOG;
       
   562     TBool retVal( EFalse );
       
   563     if ( iBackgroundState == EFsItemBackgroundBrush && iBackgroundBrush )
       
   564         {
       
   565         aBrush = iBackgroundBrush;
       
   566         retVal = ETrue;
       
   567         }
       
   568 
       
   569     return retVal;
       
   570     }
       
   571 // </cmail>
       
   572   
       
   573 // ---------------------------------------------------------------------------
       
   574 // From MFsTreeItemVisualizer.
       
   575 // Clears item background.
       
   576 // ---------------------------------------------------------------------------
       
   577 //
       
   578 void CFsTreeItemVisualizerBase::ClearBackground( )
       
   579     {
       
   580     FUNC_LOG;
       
   581     iBackgroundState = EFsItemBackgroundNone;
       
   582     }
       
   583 
       
   584 // ---------------------------------------------------------------------------
       
   585 //  Returns reference to the item's main layout
       
   586 // ---------------------------------------------------------------------------
       
   587 //
       
   588 CAlfLayout& CFsTreeItemVisualizerBase::Layout() const
       
   589     {
       
   590     FUNC_LOG;
       
   591     return (static_cast<CAlfLayout&>(*iLayout));
       
   592     }
       
   593 
       
   594 // ---------------------------------------------------------------------------
       
   595 //  Sets menu for item
       
   596 // ---------------------------------------------------------------------------
       
   597 //
       
   598 void CFsTreeItemVisualizerBase::SetMenu( CFsTreeList* aMenu )
       
   599     {
       
   600     FUNC_LOG;
       
   601     iMenu = aMenu;
       
   602     if ( iMenu )
       
   603         {
       
   604         iFlags |= KFsTreeListItemHasMenu;
       
   605         }
       
   606     else
       
   607         {//null menu pointer - no menu
       
   608         iFlags &= ~KFsTreeListItemHasMenu;
       
   609         }
       
   610     }
       
   611 
       
   612 // ---------------------------------------------------------------------------
       
   613 //  Returns CFsTreeList object contaning menu items
       
   614 // ---------------------------------------------------------------------------
       
   615 //
       
   616 CFsTreeList* CFsTreeItemVisualizerBase::Menu() const
       
   617     {
       
   618     FUNC_LOG;
       
   619     return iMenu;
       
   620     }
       
   621 
       
   622 // ---------------------------------------------------------------------------
       
   623 //  This functions sets wether an item should always be in extended state.
       
   624 // ---------------------------------------------------------------------------
       
   625 //
       
   626 void CFsTreeItemVisualizerBase::SetAlwaysExtended( TBool aAlwaysExtended )
       
   627     {
       
   628     FUNC_LOG;
       
   629     if ( aAlwaysExtended )
       
   630         {
       
   631         iFlags |= KFsTreeListItemAlwaysExtended;
       
   632         }
       
   633     else
       
   634         {
       
   635         iFlags &= ~KFsTreeListItemAlwaysExtended;
       
   636         }
       
   637     }
       
   638 
       
   639 // ---------------------------------------------------------------------------
       
   640 //  This function returns wether an item is always in extended state.
       
   641 // ---------------------------------------------------------------------------
       
   642 //
       
   643 TBool CFsTreeItemVisualizerBase::IsAlwaysExtended( ) const
       
   644     {
       
   645     FUNC_LOG;
       
   646     return iFlags & KFsTreeListItemAlwaysExtended ? ETrue : EFalse;
       
   647     }
       
   648 
       
   649 
       
   650 // ---------------------------------------------------------------------------
       
   651 // From class MFsTreeItemVisualizer.
       
   652 //  A call to this function means that the visualization of empty root
       
   653 // becomes visible and should draw itself within specified parent layout.
       
   654 // ---------------------------------------------------------------------------
       
   655 //
       
   656 void CFsTreeItemVisualizerBase::ShowL( CAlfLayout& /*aParentLayout*/,
       
   657                                         const TUint /*aTimeout*/ )
       
   658     {
       
   659     FUNC_LOG;
       
   660     }
       
   661 
       
   662 // ---------------------------------------------------------------------------
       
   663 // From class MFsTreeItemVisualizer.
       
   664 // Stub.
       
   665 // ---------------------------------------------------------------------------
       
   666 //
       
   667 void CFsTreeItemVisualizerBase::UpdateL( const MFsTreeItemData& /*aData*/,
       
   668                                           TBool /*aFocused*/,
       
   669                                           const TUint /*aLevel*/,
       
   670                                           CAlfTexture*& /*aMarkIcon*/,
       
   671                                           CAlfTexture*& /*aMenuIcon*/,
       
   672                                           const TUint /*aTimeout*/,
       
   673                                           TBool /*aUpdateData*/)
       
   674     {
       
   675     FUNC_LOG;
       
   676     }
       
   677 
       
   678 // ---------------------------------------------------------------------------
       
   679 // From class MFsTreeItemVisualizer.
       
   680 // Stub.
       
   681 // ---------------------------------------------------------------------------
       
   682 //
       
   683 void CFsTreeItemVisualizerBase::Hide( const TInt /*aTimeout*/ )
       
   684     {
       
   685     FUNC_LOG;
       
   686     }
       
   687 
       
   688 
       
   689 // ---------------------------------------------------------------------------
       
   690 // From class MFsTreeItemVisualizer.
       
   691 // Stub.
       
   692 // ---------------------------------------------------------------------------
       
   693 //
       
   694 void CFsTreeItemVisualizerBase::MarqueeL(const TFsTextMarqueeType /*aMarqueeType*/,
       
   695                                          const TUint /*aMarqueeSpeed*/,
       
   696                                          const TInt /*aMarqueeStartDelay*/,
       
   697                                          const TInt /*aMarqueeCycleStartDelay*/,
       
   698                                          const TInt /*aMarqueeRepetitions*/)
       
   699     {
       
   700     FUNC_LOG;
       
   701     }
       
   702 
       
   703 
       
   704 // ---------------------------------------------------------------------------
       
   705 //  From MAlfEventHandler. Stub.
       
   706 // ---------------------------------------------------------------------------
       
   707 //
       
   708 TBool CFsTreeItemVisualizerBase::OfferEventL(const TAlfEvent& /*aEvent*/)
       
   709     {
       
   710     FUNC_LOG;
       
   711     return EFalse;
       
   712     }
       
   713 
       
   714 
       
   715 // ---------------------------------------------------------------------------
       
   716 //  Sets the text style manager for the item visualizer.
       
   717 // ---------------------------------------------------------------------------
       
   718 //
       
   719 void CFsTreeItemVisualizerBase::SetTextStyleManager(
       
   720         CFsAlfTextStyleManager& aManager )
       
   721     {
       
   722     FUNC_LOG;
       
   723     iTextStyleManager = &aManager;
       
   724     }
       
   725 
       
   726 
       
   727 // ---------------------------------------------------------------------------
       
   728 //  Sets the text stroke weight for the item visualizer.
       
   729 // ---------------------------------------------------------------------------
       
   730 //
       
   731 void CFsTreeItemVisualizerBase::SetTextBold( const TBool aIsBold )
       
   732     {
       
   733     FUNC_LOG;
       
   734     if (aIsBold)
       
   735         {
       
   736         iFlags |= KFsTreeListItemTextBold;
       
   737         }
       
   738     else
       
   739         {
       
   740         iFlags &= ~KFsTreeListItemTextBold;
       
   741         }
       
   742     }
       
   743 
       
   744 
       
   745 // ---------------------------------------------------------------------------
       
   746 //  Gets the text stroke weight for the item visualizer.
       
   747 // ---------------------------------------------------------------------------
       
   748 //
       
   749 TBool CFsTreeItemVisualizerBase::IsTextBold( ) const
       
   750     {
       
   751     FUNC_LOG;
       
   752     return iFlags & KFsTreeListItemTextBold;
       
   753     }
       
   754 
       
   755 
       
   756 // ---------------------------------------------------------------------------
       
   757 // Function gets text color for a focused item. The color is taken from the
       
   758 // skin if skin support is  on, if not then a default value is used.
       
   759 // ---------------------------------------------------------------------------
       
   760 //
       
   761 TRgb CFsTreeItemVisualizerBase::FocusedStateTextSkinColor( )
       
   762     {
       
   763     FUNC_LOG;
       
   764     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   765     TRgb textColor;
       
   766     // First try to get the FS specific text color
       
   767     if( AknsUtils::GetCachedColor( skin, textColor,
       
   768             KAknsIIDFsHighlightColors, EAknsCIFsHighlightColorsCG1 ) != KErrNone )
       
   769         {
       
   770         // If FS specific text color not found, try to get the
       
   771         // normal Avkon list highlight text color
       
   772         if( AknsUtils::GetCachedColor( skin, textColor,
       
   773                 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG10 ) != KErrNone )
       
   774             {
       
   775             textColor = KRgbBlack;
       
   776             }
       
   777         }
       
   778     return textColor;
       
   779     }
       
   780 
       
   781 // ---------------------------------------------------------------------------
       
   782 // Function gets text color for a non focused item. The color is taken from
       
   783 // the skin if skin support is  on, if not then a default value is used.
       
   784 // ---------------------------------------------------------------------------
       
   785 //
       
   786 TRgb CFsTreeItemVisualizerBase::NormalStateTextSkinColor( )
       
   787     {
       
   788     FUNC_LOG;
       
   789     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   790     TRgb textColor;
       
   791     if ( AknsUtils::GetCachedColor( skin, textColor,
       
   792             KAknsIIDFsTextColors, EAknsCIFsTextColorsCG3 ) != KErrNone )
       
   793         {
       
   794         textColor = KRgbBlack;
       
   795         }
       
   796     return textColor;
       
   797     }
       
   798 
       
   799 
       
   800 // ---------------------------------------------------------------------------
       
   801 // Returns horizontal alignment of the displayed text in respect to current layout.
       
   802 // ---------------------------------------------------------------------------
       
   803 //
       
   804 TAlfAlignHorizontal CFsTreeItemVisualizerBase::CurrentTextAlignmentL( TAlfAlignHorizontal aAlignment,
       
   805                                                                      TDesC* aText,
       
   806                                                                      CAlfTextVisual* aVisual)
       
   807     {
       
   808     FUNC_LOG;
       
   809     TAlfAlignHorizontal align (aAlignment);
       
   810     TBool isMirrored( EFalse );
       
   811 
       
   812     isMirrored = CFsLayoutManager::IsMirrored();
       
   813 
       
   814     if ( align == EAlfAlignHLocale )
       
   815         {
       
   816         if ( aText && aVisual )
       
   817             {
       
   818             TInt textWidth(0), visualWidth(0);
       
   819             textWidth = aVisual->SubstringExtents(0, aVisual->Text().Length()).Width();
       
   820             visualWidth = aVisual->Size().Target().iX;
       
   821 
       
   822             if ( textWidth >= visualWidth )
       
   823                 {
       
   824                 TBool found(EFalse);
       
   825                 TBidiText * bidiText = TBidiText::NewL(aText->Length() + 1, 1);
       
   826                 TBidiText::TDirectionality direction = bidiText->TextDirectionality( *aText, &found );
       
   827                 delete bidiText;
       
   828                 if ( direction == TBidiText::ELeftToRight )
       
   829                     {
       
   830                     align = EAlfAlignHLeft;
       
   831                     }
       
   832                 else
       
   833                     { //direction == TBidiText::ERightToLeft
       
   834                     align = EAlfAlignHRight;
       
   835                     }
       
   836                 }
       
   837             else
       
   838                 {
       
   839                 if ( isMirrored )
       
   840                     {
       
   841                     align = EAlfAlignHRight;
       
   842                     }
       
   843                 else
       
   844                     {
       
   845                     align = EAlfAlignHLeft;
       
   846                     }
       
   847                 }
       
   848             }
       
   849         }
       
   850     else if ( isMirrored )
       
   851         {//convert left <-> right in mirrored layout
       
   852         if ( align == EAlfAlignHLeft )
       
   853             {
       
   854             align = EAlfAlignHRight;
       
   855             }
       
   856         else if ( align == EAlfAlignHRight )
       
   857             {
       
   858             align = EAlfAlignHLeft;
       
   859             }
       
   860         }
       
   861 
       
   862     return align;
       
   863     }
       
   864 
       
   865 
       
   866 // ---------------------------------------------------------------------------
       
   867 // Returns text style id used in the item.
       
   868 // ---------------------------------------------------------------------------
       
   869 //
       
   870 TInt CFsTreeItemVisualizerBase::ModifiedStyleIdL( ) const
       
   871     {
       
   872     FUNC_LOG;
       
   873     TInt styleId(iTextStyleId);
       
   874     TCharFormat charFormat;
       
   875 
       
   876     if ( iIsCustomTextStyle )
       
   877         {
       
   878         CAlfTextStyle* textStyle( iOwnerControl.Env().TextStyleManager().TextStyle( styleId ) );
       
   879         HBufC* name = textStyle->TypefaceNameL();
       
   880         charFormat.iFontSpec.iTypeface.iName = name->Left( KMaxTypefaceNameLength );
       
   881         delete name;
       
   882 
       
   883         charFormat.iFontSpec.iHeight = textStyle->TextSizeInTwips();
       
   884         charFormat.iFontPresentation.iTextColor = textStyle->TextColor();
       
   885 
       
   886         charFormat.iFontPresentation.iStrikethrough = textStyle->IsStrikeThrough() ? EStrikethroughOn : EStrikethroughOff;
       
   887         charFormat.iFontPresentation.iUnderline = textStyle->IsUnderline() ? EUnderlineOn : EUnderlineOff;
       
   888 
       
   889         }
       
   890     else
       
   891         {
       
   892         TRect parentRect( Size() );
       
   893         CFsLayoutManager::TFsText text;
       
   894         CFsLayoutManager::LayoutMetricsText( parentRect,CFsLayoutManager::EFsLmListSingleDycRowTextPaneT1, text, 0 );
       
   895         charFormat.iFontSpec = text.iFont->FontSpecInTwips();
       
   896         }
       
   897 
       
   898     if (iFontHeight>0)
       
   899         {
       
   900         charFormat.iFontSpec.iHeight = iFontHeight;
       
   901         }
       
   902 
       
   903     TBool isBold(EFalse);
       
   904     isBold = iFlags & KFsTreeListItemTextBold;
       
   905     if ( isBold )
       
   906         {
       
   907         charFormat.iFontSpec.iFontStyle.SetStrokeWeight( EStrokeWeightBold );
       
   908         }
       
   909     else
       
   910         {
       
   911         charFormat.iFontSpec.iFontStyle.SetStrokeWeight( EStrokeWeightNormal );
       
   912         }
       
   913 
       
   914     if ( iTextStyleManager )
       
   915         {
       
   916         styleId = iTextStyleManager->GetStyleIDL( charFormat );
       
   917         }
       
   918 
       
   919     return styleId;
       
   920     }
       
   921 
       
   922 
       
   923 // ---------------------------------------------------------------------------
       
   924 //  Method to set text font height in twips.
       
   925 // ---------------------------------------------------------------------------
       
   926 //
       
   927 void CFsTreeItemVisualizerBase::SetFontHeight(const TInt aHeightInTwips)
       
   928     {
       
   929     FUNC_LOG;
       
   930     iFontHeight = aHeightInTwips;
       
   931     }
       
   932 
       
   933 
       
   934 // ---------------------------------------------------------------------------
       
   935 //  Gets height of a text font in twips.
       
   936 // ---------------------------------------------------------------------------
       
   937 //
       
   938 TInt CFsTreeItemVisualizerBase::FontHeight() const
       
   939     {
       
   940     FUNC_LOG;
       
   941     return iFontHeight;
       
   942     }
       
   943 
       
   944 
       
   945 // ---------------------------------------------------------------------------
       
   946 //  Method to set text font height in pixels.
       
   947 // ---------------------------------------------------------------------------
       
   948 //
       
   949 void CFsTreeItemVisualizerBase::SetFontHeightInPixels(const TInt aHeightInPixels)
       
   950     {
       
   951     FUNC_LOG;
       
   952     TZoomFactor devicemap(CCoeEnv::Static()->ScreenDevice());
       
   953     devicemap.SetZoomFactor(TZoomFactor::EZoomOneToOne);
       
   954     TInt heightInTwips = devicemap.VerticalPixelsToTwips(aHeightInPixels);
       
   955 
       
   956     iFontHeight = heightInTwips;
       
   957     }
       
   958 
       
   959 
       
   960 // ---------------------------------------------------------------------------
       
   961 //  Gets height of a text font in pixels.
       
   962 // ---------------------------------------------------------------------------
       
   963 //
       
   964 TInt CFsTreeItemVisualizerBase::FontHeightInPixels() const
       
   965     {
       
   966     FUNC_LOG;
       
   967     TZoomFactor devicemap(CCoeEnv::Static()->ScreenDevice());
       
   968     devicemap.SetZoomFactor(TZoomFactor::EZoomOneToOne);
       
   969 
       
   970     return devicemap.VerticalTwipsToPixels(iFontHeight);
       
   971     }
       
   972 
       
   973 // ---------------------------------------------------------------------------
       
   974 //  Second phase constructor.
       
   975 // ---------------------------------------------------------------------------
       
   976 //
       
   977 void CFsTreeItemVisualizerBase::ConstructL( )
       
   978     {
       
   979     FUNC_LOG;
       
   980     //get default skin values
       
   981     iNormalTextColor = NormalStateTextSkinColor();
       
   982     iFocusedTextColor = FocusedStateTextSkinColor();
       
   983     }
       
   984 
       
   985 // ---------------------------------------------------------------------------
       
   986 //  Set layouting hints
       
   987 // ---------------------------------------------------------------------------
       
   988 //
       
   989 void CFsTreeItemVisualizerBase::SetLayoutHints( const TUint aHints )
       
   990     {   
       
   991     FUNC_LOG;
       
   992     iLayoutHints |= aHints;
       
   993     }
       
   994 
       
   995 // ---------------------------------------------------------------------------
       
   996 //  Check if hint is set
       
   997 // ---------------------------------------------------------------------------
       
   998 //
       
   999 TBool CFsTreeItemVisualizerBase::IsLayoutHintSet( const TLayoutHint aHint ) const
       
  1000     {
       
  1001     FUNC_LOG;
       
  1002     return iLayoutHints & aHint;
       
  1003     }
       
  1004 
       
  1005 // ---------------------------------------------------------------------------
       
  1006 //  C++ constructor.
       
  1007 // ---------------------------------------------------------------------------
       
  1008 //
       
  1009 CFsTreeItemVisualizerBase::CFsTreeItemVisualizerBase(
       
  1010         CAlfControl& aOwnerControl)
       
  1011 
       
  1012     : iOwnerControl(aOwnerControl),
       
  1013     iLayout(NULL),
       
  1014     iFlags(KFsTreeListItemFocusable | KFsTreeListItemManagedLayout ),
       
  1015     iTextAlign( EAlfAlignHLocale ),
       
  1016     iTextIndentation( KFsDefaultIndentation ),
       
  1017     iIsCustomTextNormalColor(EFalse),
       
  1018     iIsCustomTextFocusedColor(EFalse),
       
  1019     iTextStyleId ( EAlfTextStyleNormal ),
       
  1020     iIsCustomTextStyle( EFalse ),
       
  1021     iFontHeight(0),
       
  1022     iBackgroundState( EFsItemBackgroundNone )
       
  1023     {
       
  1024     FUNC_LOG;
       
  1025     //normal size not set
       
  1026     iSize.iWidth = 0;
       
  1027     iSize.iHeight = 0;
       
  1028     //extended size not set
       
  1029     iExtendedSize.iWidth = 0;
       
  1030     iExtendedSize.iHeight = 0;
       
  1031     }
       
  1032