uifw/AvKon/aknhlist/src/aknsinglestyletreeleaf.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2006-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:  Implementation for CAknSingleStyleTreeLeaf class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <AknUtils.h>
       
    20 #include <aknlayoutscalable_avkon.cdl.h>
       
    21 
       
    22 #include "aknsinglestyletreeleaf.h"
       
    23 #include "akntree.h"
       
    24 #include "akntreelistinternalconstants.h"
       
    25 
       
    26 using AknTreeListIconID::KDefault;
       
    27 using AknTreeListIconID::KNone;
       
    28 
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // Two-phased constructor.
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CAknSingleStyleTreeLeaf* CAknSingleStyleTreeLeaf::NewL( const TDesC& aText,
       
    37     TUint32 aFlags )
       
    38     {
       
    39     CAknSingleStyleTreeLeaf* self = CAknSingleStyleTreeLeaf::NewLC( aText,
       
    40         aFlags );
       
    41     CleanupStack::Pop( self );
       
    42     return self;
       
    43     }
       
    44 
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // Two-phased constructor.
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CAknSingleStyleTreeLeaf* CAknSingleStyleTreeLeaf::NewLC( const TDesC& aText,
       
    51     TUint32 aFlags )
       
    52     {
       
    53     CAknSingleStyleTreeLeaf* self = 
       
    54         new ( ELeave ) CAknSingleStyleTreeLeaf( aFlags );
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL( aText );
       
    57     return self;
       
    58     }
       
    59 
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // Destructor.
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CAknSingleStyleTreeLeaf::~CAknSingleStyleTreeLeaf()
       
    66     {
       
    67     delete iText;
       
    68     }
       
    69 
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // Returns the text set for the leaf.
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 const TDesC& CAknSingleStyleTreeLeaf::Text() const
       
    76     {
       
    77     return iText ? *iText : KNullDesC();
       
    78     }
       
    79 
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // Allocates new heap based descriptor for the text, and if the allocation
       
    83 // succeeds, deletes the old descriptor and replaces it with the new.
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void CAknSingleStyleTreeLeaf::SetTextL( const TDesC& aText, TBool aDrawNow  )
       
    87     {
       
    88     HBufC* tmp = aText.AllocL();
       
    89     delete iText;
       
    90     iText = tmp;
       
    91 
       
    92     if ( aDrawNow )
       
    93         {
       
    94         __ASSERT_DEBUG( Root(), User::Invariant() );
       
    95         Root()->ItemModified( this );
       
    96         }
       
    97     }
       
    98 
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // Returns the icon ID set for the specified tree leaf icon type.
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 TInt CAknSingleStyleTreeLeaf::Icon( TIconType aType ) const
       
   105     {
       
   106     TInt iconId = KDefault;
       
   107     switch ( aType )
       
   108         {
       
   109         case EIcon:
       
   110             iconId = iIcon;
       
   111             break;
       
   112 
       
   113         case EOptIcon1:
       
   114             iconId = iOptIcon1;
       
   115             break;
       
   116 
       
   117         case EOptIcon2:
       
   118             iconId = iOptIcon2;
       
   119             break;
       
   120 
       
   121         case EHighlightedIcon:
       
   122             iconId = iHighlightedIcon;
       
   123             break;
       
   124 
       
   125         case EHighlightedOptIcon1:
       
   126             iconId = iHighlightedOptIcon1;
       
   127             break;
       
   128 
       
   129         case EHighlightedOptIcon2:
       
   130             iconId = iHighlightedOptIcon2;
       
   131             break;
       
   132 
       
   133         default:
       
   134             break;
       
   135         }
       
   136     return iconId;
       
   137     }
       
   138 
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 //  Sets the icon ID for specified tree leaf icon type.
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 void CAknSingleStyleTreeLeaf::SetIcon( TIconType aType, TInt aIconId,
       
   145     TBool aDrawNow )
       
   146     {
       
   147     switch( aType )
       
   148         {
       
   149         case EIcon:
       
   150             iIcon = aIconId;
       
   151             break;
       
   152         
       
   153         case EOptIcon1:
       
   154             iOptIcon1 = aIconId;
       
   155             break;
       
   156 
       
   157         case EOptIcon2:
       
   158             iOptIcon2 = aIconId;
       
   159             break;
       
   160 
       
   161         case EHighlightedIcon:
       
   162             iHighlightedIcon = aIconId;
       
   163             break;
       
   164 
       
   165         case EHighlightedOptIcon1:
       
   166             iHighlightedOptIcon1 = aIconId;
       
   167             break;
       
   168 
       
   169         case EHighlightedOptIcon2:
       
   170             iHighlightedOptIcon2 = aIconId;
       
   171             break;
       
   172 
       
   173         default:
       
   174             __ASSERT_DEBUG( EFalse, User::Invariant() );
       
   175             break;
       
   176         }
       
   177 
       
   178     if ( aDrawNow )
       
   179         {
       
   180         __ASSERT_DEBUG( Root(), User::Invariant() );
       
   181         Root()->ItemModified( this );
       
   182         }
       
   183     }
       
   184 
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // Icon ID.
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 TInt CAknSingleStyleTreeLeaf::IconId( TBool aFocused ) const
       
   191     {
       
   192     // Default ID for icon.
       
   193     TInt iconId = CAknTree::EDefaultFileIndication;
       
   194 
       
   195     // Determine ID for the icon based on focusing and set IDs.
       
   196     if ( aFocused && iHighlightedIcon != KDefault )
       
   197         {
       
   198         iconId = iHighlightedIcon;
       
   199         }
       
   200     else if ( iIcon != KDefault )
       
   201         {
       
   202         iconId = iIcon;
       
   203         }
       
   204 
       
   205     return iconId;
       
   206     }
       
   207 
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // Optional icon ID.
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 TInt CAknSingleStyleTreeLeaf::OptionalIconId( TInt aIndex,
       
   214     TBool aFocused ) const
       
   215     {
       
   216     __ASSERT_DEBUG( aIndex == 0 || aIndex == 1, User::Invariant() );
       
   217 
       
   218     // Default ID for optional icon.
       
   219     TInt optIconId = AknTreeListIconID::KNone; 
       
   220 
       
   221     // Determine ID for specified optional icon.
       
   222     if ( aIndex == 0 )
       
   223         {
       
   224         if ( aFocused && iHighlightedOptIcon1 != KDefault )
       
   225             {
       
   226             optIconId = iHighlightedOptIcon1;
       
   227             }
       
   228         else if ( iOptIcon1 != KDefault )
       
   229             {
       
   230             optIconId = iOptIcon1;
       
   231             }
       
   232         }
       
   233     else if ( aIndex == 1 )
       
   234         {
       
   235         if ( aFocused && iHighlightedOptIcon2 != KDefault )
       
   236             {
       
   237             optIconId = iHighlightedOptIcon2;
       
   238             }
       
   239         else if ( iOptIcon2 != KDefault )
       
   240             {
       
   241             optIconId = iOptIcon2;
       
   242             }
       
   243         }
       
   244 
       
   245     return optIconId;
       
   246     }
       
   247 
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // Text variety depending on optional icons.
       
   251 // ---------------------------------------------------------------------------
       
   252 //
       
   253 TInt CAknSingleStyleTreeLeaf::TextVariety( TInt aOptIconId1,
       
   254     TInt aOptIconId2 ) const
       
   255     {
       
   256     TInt textVariety = 0;
       
   257     if ( aOptIconId1 != AknTreeListIconID::KNone )
       
   258         {
       
   259         textVariety = 1;
       
   260         }
       
   261     if ( aOptIconId2 != AknTreeListIconID::KNone )
       
   262         {
       
   263         textVariety = 2;
       
   264         }
       
   265     return textVariety;
       
   266     }
       
   267 
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 // From class CAknTreeItem.
       
   271 // Returns the type of concrete item class.
       
   272 // ---------------------------------------------------------------------------
       
   273 //
       
   274 TInt CAknSingleStyleTreeLeaf::Type() const
       
   275     {
       
   276     return AknTreeList::KSingleStyleTreeLeaf;
       
   277     }
       
   278 
       
   279 
       
   280 // ---------------------------------------------------------------------------
       
   281 // From class CAknTreeItem.
       
   282 // Draws the tree leaf to appointed graphics context.
       
   283 // ---------------------------------------------------------------------------
       
   284 //
       
   285 void CAknSingleStyleTreeLeaf::Draw( CWindowGc& aGc, const TRect& aItemRect,
       
   286     const TRect& /*aRect*/, TBool aFocused ) const
       
   287     {
       
   288     CAknTree* root = Root();
       
   289     __ASSERT_DEBUG( root, User::Invariant() );
       
   290 
       
   291     // Icon.
       
   292     TInt iconVariety = 0; // Arbitrarily selected variety.
       
   293     TRect iconRect = RectFromLayout( aItemRect, AknLayoutScalable_Avkon::
       
   294         list_single_graphic_hl_pane_g2( iconVariety ) );
       
   295 
       
   296     TInt iconId = IconId( aFocused );
       
   297     // Dragging/flicking
       
   298     
       
   299     if ( iIcon != AknTreeListIconID::KNone )
       
   300         {
       
   301         root->DrawIcon( iconId, iconRect.Size(), aGc, iconRect.iTl,
       
   302             iconRect.Size() );
       
   303         }
       
   304 
       
   305     // Optional icon IDs.
       
   306     TInt optIconId1 = OptionalIconId( 0, aFocused );
       
   307     TInt optIconId2 = OptionalIconId( 1, aFocused );
       
   308 
       
   309     // Text variety is set according to required optional icons.
       
   310     TInt textVariety = TextVariety( optIconId1, optIconId2 );
       
   311 
       
   312     // Text.
       
   313     TAknLayoutText layoutText;
       
   314     layoutText.LayoutText( aItemRect, AknLayoutScalable_Avkon::
       
   315         list_single_graphic_hl_pane_t1( textVariety ).LayoutLine() );
       
   316 
       
   317     root->DrawText( aGc, aItemRect, AknLayoutScalable_Avkon::
       
   318         list_single_graphic_hl_pane_t1( textVariety ), *iText, NULL, this,
       
   319         aFocused, ETrue );
       
   320 
       
   321     // Optional item state indication icon.
       
   322     TInt optIconVariety1 = 1;
       
   323     TRect optIconRect1 = RectFromLayout( aItemRect, AknLayoutScalable_Avkon::
       
   324         list_single_graphic_hl_pane_g4( optIconVariety1 ) );
       
   325 
       
   326     if ( optIconId1 != KNone )
       
   327         {
       
   328         root->DrawIcon( optIconId1, optIconRect1.Size(), aGc,
       
   329             optIconRect1.iTl, optIconRect1.Size() );
       
   330         }
       
   331 
       
   332     // Another optional item state indication icon.
       
   333     TInt optIconVariety2 = 1;
       
   334     TRect optIconRect2 = RectFromLayout( aItemRect, AknLayoutScalable_Avkon::
       
   335         list_single_graphic_hl_pane_g5( optIconVariety2 ) );
       
   336 
       
   337     if ( optIconId2 != KNone )
       
   338         {
       
   339         root->DrawIcon( optIconId2, optIconRect2.Size(), aGc,
       
   340             optIconRect2.iTl, optIconRect2.Size() );
       
   341         }    
       
   342     }   
       
   343 
       
   344 
       
   345 // ---------------------------------------------------------------------------
       
   346 // From class CAknTreeItem.
       
   347 // Handles pointer events.
       
   348 // ---------------------------------------------------------------------------
       
   349 //
       
   350 void CAknSingleStyleTreeLeaf::HandlePointerEventL(
       
   351     const TPointerEvent& /*aPointerEvent*/, const TRect& /*aItemRect*/ )
       
   352     {
       
   353     }
       
   354 
       
   355 
       
   356 // ---------------------------------------------------------------------------
       
   357 // C++ constructor.
       
   358 // ---------------------------------------------------------------------------
       
   359 //
       
   360 CAknSingleStyleTreeLeaf::CAknSingleStyleTreeLeaf( TUint32 aFlags )
       
   361     : CAknTreeLeaf( aFlags ),
       
   362     iIcon( KDefault ),
       
   363     iOptIcon1( KDefault ),
       
   364     iOptIcon2( KDefault ),
       
   365     iHighlightedIcon( KDefault ),
       
   366     iHighlightedOptIcon1( KDefault ),
       
   367     iHighlightedOptIcon2( KDefault )
       
   368     {
       
   369     }
       
   370 
       
   371 
       
   372 // ---------------------------------------------------------------------------
       
   373 // Second phase constructor.
       
   374 // ---------------------------------------------------------------------------
       
   375 //
       
   376 void CAknSingleStyleTreeLeaf::ConstructL( const TDesC& aText )
       
   377     {
       
   378     iText = aText.AllocL();
       
   379     }
       
   380