uifw/AvKon/aknhlist/src/akntreeitem.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2006 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 the CAknTreeItem class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aknappui.h>
       
    20 #include <AknUtils.h>
       
    21 #include <aknlayoutscalable_avkon.cdl.h>
       
    22 
       
    23 #include "akntreeitem.h"
       
    24 #include "akntreenode.h"
       
    25 #include "akntree.h"
       
    26 
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // Destructor.
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 CAknTreeItem::~CAknTreeItem()
       
    35     {
       
    36     iParent = NULL;
       
    37     }
       
    38 
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // Returns pointer to the parent node.
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 const CAknTreeNode* CAknTreeItem::Parent() const
       
    45     {
       
    46     return iParent;
       
    47     }
       
    48 
       
    49 
       
    50 CAknTreeNode* CAknTreeItem::Parent()
       
    51     {
       
    52     return iParent;
       
    53     }
       
    54 
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // Sets the parent node.
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 void CAknTreeItem::SetParent( CAknTreeNode* aParent )
       
    61     {
       
    62     __ASSERT_DEBUG( aParent != this, User::Invariant() );
       
    63     iParent = aParent;
       
    64     }
       
    65 
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // Returns pointer to the tree root.
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 CAknTree* CAknTreeItem::Root() const
       
    72     {
       
    73     return iParent ? iParent->Root() : NULL;
       
    74     }
       
    75 
       
    76 
       
    77 TInt CAknTreeItem::Level() const
       
    78     {
       
    79     return iParent ? iParent->Level() + 1 : 0;
       
    80     }
       
    81 
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // These virtual functions are intended for compensating the absence of
       
    85 // dynamic casting. Default implementations return null pointers.
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 CAknTreeLeaf* CAknTreeItem::Leaf()
       
    89     {
       
    90     return NULL;
       
    91     }
       
    92 
       
    93 
       
    94 const CAknTreeLeaf* CAknTreeItem::Leaf() const
       
    95     {
       
    96     return NULL;
       
    97     }
       
    98 
       
    99 
       
   100 CAknTreeNode* CAknTreeItem::Node()
       
   101     {
       
   102     return NULL;
       
   103     }
       
   104 
       
   105 
       
   106 const CAknTreeNode* CAknTreeItem::Node() const
       
   107     {
       
   108     return NULL;
       
   109     }
       
   110 
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // Determines whether the object is an intance of CAknTreeLeaf with the
       
   114 // virtual Leaf() method that should be overriden by CAknTreeLeaf class to
       
   115 // return pointer to the object instead of null pointer.
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 TBool CAknTreeItem::IsLeaf() const
       
   119     {
       
   120     return Leaf() != NULL;
       
   121     }
       
   122 
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // Determines whether the object is an instance of CAknTreeNode with the
       
   126 // virtual Node() method, that should be overriden by CAknTreeNode class to
       
   127 // return pointer to the object instead of null pointer.
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 TBool CAknTreeItem::IsNode() const
       
   131     {
       
   132     return Node() != NULL;
       
   133     }
       
   134 
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // Gets the minimum size for the hierarchical list item from the layout data.
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 TSize CAknTreeItem::MinimumSize() const
       
   141     {
       
   142     TAknWindowLineLayout lineLayout = 
       
   143         AknLayoutScalable_Avkon::aid_size_min_hl_cp1().LayoutLine();
       
   144     TRect parentRect = iAvkonAppUi->ApplicationRect(); // Not according to LAF!
       
   145     TAknLayoutRect layoutRect;
       
   146     layoutRect.LayoutRect( parentRect, lineLayout );
       
   147     TRect minimumSize = layoutRect.Rect();
       
   148     return minimumSize.Size();
       
   149     }
       
   150 
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // Empty implementation for pointer event handling.
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 void CAknTreeItem::HandlePointerEventL( const TPointerEvent& /*aPointerEvent*/,
       
   157     const TRect& /*aItemRect*/ )
       
   158     {
       
   159     }
       
   160 
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // Static comparison function.
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 TInt CAknTreeItem::Compare( const CAknTreeItem& aFirst,
       
   167     const CAknTreeItem& aSecond )
       
   168     {
       
   169     CAknTree* root = aFirst.Root();
       
   170     if ( !root )
       
   171         {
       
   172         root = aSecond.Root();
       
   173         }
       
   174 
       
   175     if ( root )
       
   176         {
       
   177         return root->Compare( aFirst, aSecond );
       
   178         }
       
   179     else
       
   180         {
       
   181         return NULL;
       
   182         }
       
   183     }
       
   184 
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // Default C++ constructor.
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 CAknTreeItem::CAknTreeItem()
       
   191     {
       
   192     }
       
   193 
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // Gets specified rectangle from the layout data.
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 TRect CAknTreeItem::RectFromLayout( const TRect& aParent,
       
   200     const TAknWindowComponentLayout& aComponentLayout ) const
       
   201     {
       
   202     TAknLayoutRect layoutRect;
       
   203     layoutRect.LayoutRect( aParent, aComponentLayout.LayoutLine() );
       
   204     return layoutRect.Rect();
       
   205     }
       
   206 
       
   207