emailuis/uicomponents/src/fstreenode.cpp
changeset 0 8466d47a6819
child 23 dcf0eedfc1a3
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:  Freestyle tree node implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 #include "fstreenode.h"
       
    20 #include "fstreenodevisualizer.h"
       
    21 #include "fsgenericpanic.h"
       
    22 
       
    23 // ======== MEMBER FUNCTIONS ========
       
    24 
       
    25 // ---------------------------------------------------------------------------
       
    26 // Two-phased constructor.
       
    27 // ---------------------------------------------------------------------------
       
    28 //
       
    29 EXPORT_C CFsTreeNode* CFsTreeNode::NewL( CFsTreeNode& aParent,
       
    30     MFsTreeItemData& aData, MFsTreeNodeVisualizer& aVisualizer )
       
    31     {
       
    32     FUNC_LOG;
       
    33     CFsTreeNode* self = new( ELeave ) CFsTreeNode( &aParent, aData,
       
    34             aVisualizer );
       
    35     CleanupStack::PushL( self );
       
    36     self->ConstructL( );
       
    37     CleanupStack::Pop( self );
       
    38     return self;
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // C++ destructor.
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CFsTreeNode::~CFsTreeNode()
       
    46     {
       
    47     FUNC_LOG;
       
    48     iChildren.Close();
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // Gets node visualizer.
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 MFsTreeNodeVisualizer* CFsTreeNode::NodeVisualizer() const
       
    56     {
       
    57     FUNC_LOG;
       
    58     return ( static_cast<MFsTreeNodeVisualizer*>(iVisualizer) );
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // Inserts child with given index.
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 TInt CFsTreeNode::InsertChild( CFsTreeItem* aItem, const TInt aIndex )
       
    66     {
       
    67     FUNC_LOG;
       
    68     TInt childIndex = 0;
       
    69 
       
    70     if ( aIndex == KFsTreeChildIndexLast )
       
    71         {
       
    72         childIndex = iChildren.Append( aItem );
       
    73         }
       
    74     else
       
    75         {
       
    76         childIndex = iChildren.Insert( aItem, aIndex );
       
    77         }
       
    78 
       
    79     return childIndex;
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // Removes child with given index.
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 CFsTreeItem* CFsTreeNode::RemoveChild( const TInt aIndex )
       
    87     {
       
    88     FUNC_LOG;
       
    89     CFsTreeItem* childItem = NULL;
       
    90 
       
    91     childItem = Child( aIndex );
       
    92     if (childItem)
       
    93         {
       
    94         iChildren.Remove( aIndex );
       
    95         }
       
    96 
       
    97     return childItem;
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // Gets child with given index (position).
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 CFsTreeItem* CFsTreeNode::Child( const TInt aIndex ) const
       
   105     {
       
   106     FUNC_LOG;
       
   107     CFsTreeItem* treeItem = NULL;
       
   108 
       
   109     if (( aIndex < iChildren.Count() ) && ( aIndex >= 0 ))
       
   110         {
       
   111         treeItem = iChildren[aIndex];
       
   112         }
       
   113     else
       
   114         {
       
   115         FsGenericPanic(EFsListPanicIndexOutOfRange);
       
   116         }
       
   117 
       
   118     return treeItem;
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // Gets an index of desired child tree item.
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 TInt CFsTreeNode::Index( const CFsTreeItem* aItem ) const
       
   126     {
       
   127     FUNC_LOG;
       
   128     return iChildren.Find(aItem);
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // Returns the number of children for the node.
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 TUint CFsTreeNode::CountChildren() const
       
   136     {
       
   137     FUNC_LOG;
       
   138     return iChildren.Count();
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // Returns recursively the number of all children under the node
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 TUint CFsTreeNode::CountChildrenRecursively() const
       
   146     {
       
   147     FUNC_LOG;
       
   148     TInt count ( 0 );
       
   149     for ( TInt i = 0; i < iChildren.Count(); i++ )
       
   150         {
       
   151         count++;
       
   152         count += iChildren[i]->CountChildrenRecursively();
       
   153         }
       
   154     return count;
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // Checks if tree item is a node.
       
   159 // ---------------------------------------------------------------------------
       
   160 TBool CFsTreeNode::IsNode() const
       
   161     {
       
   162     FUNC_LOG;
       
   163     return ETrue;
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // Return pointer to node object. Returned value is @c NULL, if the item
       
   168 // is not derived from @c CFsTreeNode.
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 CFsTreeNode* CFsTreeNode::Node()
       
   172     {
       
   173     FUNC_LOG;
       
   174     return this;
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 //  C++ constructor.
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 CFsTreeNode::CFsTreeNode( CFsTreeNode* aParent, MFsTreeItemData& aData,
       
   182     MFsTreeNodeVisualizer& aVisualizer )
       
   183     : CFsTreeItem( aParent, aData, aVisualizer )
       
   184     {
       
   185     FUNC_LOG;
       
   186 
       
   187     }
       
   188 
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 //  Second phase constructor.
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 void CFsTreeNode::ConstructL( )
       
   195     {
       
   196     FUNC_LOG;
       
   197 
       
   198     }
       
   199