uifw/AvKon/aknhlist/src/aknsinglestyletreenode.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 CAknSingleStyleTreeNode class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <AknUtils.h>
       
    20 #include <aknlayoutscalable_avkon.cdl.h>
       
    21 
       
    22 #include "aknsinglestyletreenode.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 CAknSingleStyleTreeNode* CAknSingleStyleTreeNode::NewL( const TDesC& aText,
       
    37     TUint32 aFlags )
       
    38     {
       
    39     CAknSingleStyleTreeNode* self =
       
    40         CAknSingleStyleTreeNode::NewLC( aText, aFlags );
       
    41     CleanupStack::Pop( self );
       
    42     return self;
       
    43     }
       
    44 
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // Two-phased constructor.
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CAknSingleStyleTreeNode* CAknSingleStyleTreeNode::NewLC( const TDesC& aText,
       
    51     TUint32 aFlags )
       
    52     {
       
    53     CAknSingleStyleTreeNode* self =
       
    54         new ( ELeave ) CAknSingleStyleTreeNode( aFlags );
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL( aText );
       
    57     return self;
       
    58     }
       
    59 
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // Destructor.
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CAknSingleStyleTreeNode::~CAknSingleStyleTreeNode()
       
    66     {
       
    67     delete iText;
       
    68     }
       
    69 
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // Returns the text set for the the node.
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 const TDesC& CAknSingleStyleTreeNode::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 CAknSingleStyleTreeNode::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 node icon type.
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 TInt CAknSingleStyleTreeNode::Icon( TIconType aType ) const
       
   105     {
       
   106     TInt iconId = KDefault;
       
   107     switch ( aType )
       
   108         {
       
   109         case EExpandedIcon:
       
   110             iconId = iExpandedIcon;
       
   111             break;
       
   112 
       
   113         case ECollapsedIcon:
       
   114             iconId = iCollapsedIcon;
       
   115             break;
       
   116 
       
   117         case EOptIcon1:
       
   118             iconId = iOptIcon1;
       
   119             break;
       
   120 
       
   121         case EOptIcon2:
       
   122             iconId = iOptIcon2;
       
   123             break;
       
   124 
       
   125         case EHighlightedExpandedIcon:
       
   126             iconId = iHighlightedExpandedIcon;
       
   127             break;
       
   128 
       
   129         case EHighlightedCollapsedIcon:
       
   130             iconId = iHighlightedCollapsedIcon;
       
   131             break;
       
   132 
       
   133         case EHighlightedOptIcon1:
       
   134             iconId = iHighlightedOptIcon1;
       
   135             break;
       
   136 
       
   137         case EHighlightedOptIcon2:
       
   138             iconId = iHighlightedOptIcon2;
       
   139             break;
       
   140 
       
   141         default:
       
   142             break;
       
   143         }
       
   144     return iconId;
       
   145     }
       
   146 
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // Sets the icon ID for specified tree node icon type.
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 void CAknSingleStyleTreeNode::SetIcon( TIconType aType, TInt aIconId,
       
   153     TBool aDrawNow )
       
   154     {
       
   155     switch ( aType )
       
   156         {
       
   157         case EExpandedIcon:
       
   158             iExpandedIcon = aIconId;
       
   159             break;
       
   160         
       
   161         case ECollapsedIcon:
       
   162             iCollapsedIcon = aIconId;
       
   163             break;
       
   164 
       
   165         case EOptIcon1:
       
   166             iOptIcon1 = aIconId;
       
   167             break;
       
   168 
       
   169         case EOptIcon2:
       
   170             iOptIcon2 = aIconId;
       
   171             break;
       
   172 
       
   173         case EHighlightedExpandedIcon:
       
   174             iHighlightedExpandedIcon = aIconId;
       
   175             break;
       
   176 
       
   177         case EHighlightedCollapsedIcon:
       
   178             iHighlightedCollapsedIcon = aIconId;
       
   179             break;
       
   180 
       
   181         case EHighlightedOptIcon1:
       
   182             iHighlightedOptIcon1 = aIconId;
       
   183             break;
       
   184 
       
   185         case EHighlightedOptIcon2:
       
   186             iHighlightedOptIcon2 = aIconId;
       
   187             break;
       
   188 
       
   189         default:
       
   190             __ASSERT_DEBUG( EFalse, User::Invariant() );
       
   191             break;
       
   192         }
       
   193 
       
   194     if ( aDrawNow )
       
   195         {
       
   196         __ASSERT_DEBUG( Root(), User::Invariant() );
       
   197         Root()->ItemModified( this );
       
   198         }
       
   199     }
       
   200 
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // Icon ID.
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 TInt CAknSingleStyleTreeNode::IconId( TBool aFocused ) const
       
   207     {
       
   208     TInt iconId = KNone;
       
   209     if ( IsExpanded() )
       
   210         {
       
   211         iconId = CAknTree::EOpenFolderIndication;
       
   212         if ( aFocused && iHighlightedExpandedIcon != KDefault )
       
   213             {
       
   214             iconId = iHighlightedExpandedIcon;
       
   215             }
       
   216         else if ( iExpandedIcon != KDefault )
       
   217             {
       
   218             iconId = iExpandedIcon;
       
   219             }
       
   220         }
       
   221     else
       
   222         {
       
   223         iconId = CAknTree::EClosedFolderIndication;
       
   224         if ( aFocused && iHighlightedCollapsedIcon != KDefault )
       
   225             {
       
   226             iconId = iHighlightedCollapsedIcon;
       
   227             }
       
   228         else if ( iCollapsedIcon != KDefault )
       
   229             {
       
   230             iconId = iCollapsedIcon;
       
   231             }
       
   232         }
       
   233     return iconId;
       
   234     }
       
   235 
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // Optional icon ID.
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 TInt CAknSingleStyleTreeNode::OptionalIconId( TInt aIndex,
       
   242     TBool aFocused ) const
       
   243     {
       
   244     __ASSERT_DEBUG( aIndex == 0 || aIndex == 1, User::Invariant() );
       
   245 
       
   246     // Default ID for optional icon.
       
   247     TInt optIconId = AknTreeListIconID::KNone; 
       
   248 
       
   249     // Determine ID for specified optional icon.
       
   250     if ( aIndex == 0 )
       
   251         {
       
   252         if ( aFocused && iHighlightedOptIcon1 != KDefault )
       
   253             {
       
   254             optIconId = iHighlightedOptIcon1;
       
   255             }
       
   256         else if ( iOptIcon1 != KDefault )
       
   257             {
       
   258             optIconId = iOptIcon1;
       
   259             }
       
   260         }
       
   261     else if ( aIndex == 1 )
       
   262         {
       
   263         if ( aFocused && iHighlightedOptIcon2 != KDefault )
       
   264             {
       
   265             optIconId = iHighlightedOptIcon2;
       
   266             }
       
   267         else if ( iOptIcon2 != KDefault )
       
   268             {
       
   269             optIconId = iOptIcon2;
       
   270             }
       
   271         }
       
   272 
       
   273     return optIconId;
       
   274     }
       
   275 
       
   276 
       
   277 // ---------------------------------------------------------------------------
       
   278 // Text variety depending on optional icons.
       
   279 // ---------------------------------------------------------------------------
       
   280 //
       
   281 TInt CAknSingleStyleTreeNode::TextVariety( TInt aOptIconId1,
       
   282     TInt aOptIconId2 ) const
       
   283     {
       
   284     TInt textVariety = 0;
       
   285     if ( aOptIconId1 != AknTreeListIconID::KNone )
       
   286         {
       
   287         textVariety = 1;
       
   288         }
       
   289     if ( aOptIconId2 != AknTreeListIconID::KNone )
       
   290         {
       
   291         textVariety = 2;
       
   292         }
       
   293     return textVariety;
       
   294     }
       
   295 
       
   296 
       
   297 // ---------------------------------------------------------------------------
       
   298 // From class CAknTreeItem.
       
   299 // Returns the type of concrete item class.
       
   300 // ---------------------------------------------------------------------------
       
   301 //
       
   302 TInt CAknSingleStyleTreeNode::Type() const
       
   303     {
       
   304     return AknTreeList::KSingleStyleTreeNode;
       
   305     }
       
   306 
       
   307 
       
   308 // ---------------------------------------------------------------------------
       
   309 // From class CAknTreeItem.
       
   310 // Draws the content of the node to given graphic context.
       
   311 // ---------------------------------------------------------------------------
       
   312 //
       
   313 void CAknSingleStyleTreeNode::Draw( CWindowGc& aGc, const TRect& aItemRect,
       
   314     const TRect& /*aRect*/, TBool aFocused ) const
       
   315     {
       
   316     CAknTree* root = Root();
       
   317     __ASSERT_DEBUG( root, User::Invariant() );
       
   318 
       
   319     // Icon.
       
   320     TInt iconVariety = 2; // Arbitrarily selected variety.
       
   321     TRect iconRect = RectFromLayout( aItemRect, AknLayoutScalable_Avkon::
       
   322         list_single_graphic_hl_pane_g2( iconVariety ) );
       
   323 
       
   324     TInt iconId = IconId( aFocused );
       
   325     
       
   326     // dragging / flicking
       
   327     
       
   328     if ( iconId != AknTreeListIconID::KNone )
       
   329         {
       
   330         root->DrawIcon( iconId, iconRect.Size(), aGc, iconRect.iTl,
       
   331             iconRect.Size() );
       
   332         }
       
   333 
       
   334     // Non-empty folder indication icon.
       
   335     if ( !IsEmpty() )
       
   336         {
       
   337         TInt indicatorVariety = 2; // Arbitrarily selected variety.
       
   338         TRect indicatorRect = RectFromLayout( aItemRect, AknLayoutScalable_Avkon::
       
   339             list_single_graphic_hl_pane_g3( indicatorVariety ) );
       
   340 
       
   341         TInt indicatorId = IsExpanded() ?
       
   342             CAknTree::ECollapseFunctionIndication : 
       
   343             CAknTree::EExpandFunctionIndication;
       
   344 
       
   345         root->DrawIcon( indicatorId, indicatorRect.Size(), aGc,
       
   346             indicatorRect.iTl, indicatorRect.Size() );
       
   347         }
       
   348 
       
   349     // Optional icon IDs.
       
   350     TInt optIconId1 = OptionalIconId( 0, aFocused );
       
   351     TInt optIconId2 = OptionalIconId( 1, aFocused );
       
   352 
       
   353     // Text variety is set according to required optional icons.
       
   354     TInt textVariety = TextVariety( optIconId1, optIconId2 );
       
   355 
       
   356     // Text.
       
   357     TAknLayoutText layoutText;
       
   358     layoutText.LayoutText( aItemRect, AknLayoutScalable_Avkon::
       
   359         list_single_graphic_hl_pane_t1( textVariety ).LayoutLine() );
       
   360 
       
   361     root->DrawText( aGc, aItemRect, AknLayoutScalable_Avkon::
       
   362         list_single_graphic_hl_pane_t1( textVariety ), *iText, NULL, this,
       
   363         aFocused, ETrue );
       
   364 
       
   365     // Optional item state indication icon.
       
   366     TInt optIconVariety1 = 1;
       
   367     TRect optIconRect1 = RectFromLayout( aItemRect, AknLayoutScalable_Avkon::
       
   368         list_single_graphic_hl_pane_g4( optIconVariety1 ) );
       
   369 
       
   370     if ( optIconId1 != KNone )
       
   371         {
       
   372         root->DrawIcon( optIconId1, optIconRect1.Size(), aGc,
       
   373             optIconRect1.iTl, optIconRect1.Size() );
       
   374         }
       
   375 
       
   376     // Another optional item state indication icon.
       
   377     TInt optIconVariety2 = 1;
       
   378     TRect optIconRect2 = RectFromLayout( aItemRect, AknLayoutScalable_Avkon::
       
   379         list_single_graphic_hl_pane_g5( optIconVariety2 ) );
       
   380 
       
   381     if ( optIconId2 != KNone )
       
   382         {
       
   383         root->DrawIcon( optIconId2, optIconRect2.Size(), aGc,
       
   384             optIconRect2.iTl, optIconRect2.Size() );
       
   385         }    
       
   386 
       
   387     }
       
   388 
       
   389 
       
   390 // ---------------------------------------------------------------------------
       
   391 // From class CAknTreeItem.
       
   392 // Handles pointer events.
       
   393 // ---------------------------------------------------------------------------
       
   394 //
       
   395 void CAknSingleStyleTreeNode::HandlePointerEventL(
       
   396     const TPointerEvent& /*aPointerEvent*/, const TRect& /*aItemRect*/ )
       
   397     {
       
   398     }
       
   399 
       
   400 
       
   401 // ---------------------------------------------------------------------------
       
   402 // C++ constructor.
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 CAknSingleStyleTreeNode::CAknSingleStyleTreeNode( TUint32 aFlags )
       
   406     : CAknTreeNode( aFlags ),
       
   407     iExpandedIcon( KDefault ),
       
   408     iCollapsedIcon( KDefault ),
       
   409     iOptIcon1( KDefault ),
       
   410     iOptIcon2( KDefault ),
       
   411     iHighlightedExpandedIcon( KDefault ),
       
   412     iHighlightedCollapsedIcon( KDefault ),
       
   413     iHighlightedOptIcon1( KDefault ),
       
   414     iHighlightedOptIcon2( KDefault )
       
   415     {
       
   416     }
       
   417 
       
   418 
       
   419 // ---------------------------------------------------------------------------
       
   420 // Second phase constructor.
       
   421 // ---------------------------------------------------------------------------
       
   422 //
       
   423 void CAknSingleStyleTreeNode::ConstructL( const TDesC& aText )
       
   424     {
       
   425     iText = aText.AllocL();
       
   426     }
       
   427