menufw/hierarchynavigator/hnpresentationmodel/src/hnmenuitemmodel.cpp
changeset 0 f72a12da539e
child 4 4d54b72983ae
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  menu item presentation model
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "hnmenuitemmodel.h"
       
    20 
       
    21 // ============================ MEMBER FUNCTIONS =============================
       
    22 
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // 
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 EXPORT_C CHnMenuItemModel* CHnMenuItemModel:: NewL( const TDesC& aName )
       
    29     {
       
    30     CHnMenuItemModel* self = new( ELeave ) CHnMenuItemModel();
       
    31     CleanupStack::PushL( self );
       
    32     self->ConstructL( aName );
       
    33     CleanupStack::Pop( self );
       
    34     return self;
       
    35     }
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // 
       
    39 // ---------------------------------------------------------------------------
       
    40 //    
       
    41 CHnMenuItemModel::~CHnMenuItemModel()
       
    42     {
       
    43     iName.Close();
       
    44     iChildren.ResetAndDestroy();
       
    45     }
       
    46     
       
    47 // ---------------------------------------------------------------------------
       
    48 // 
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 EXPORT_C TBool CHnMenuItemModel::HasNext()
       
    52     {
       
    53     TBool ret = ETrue;
       
    54     if( iNextMenu >= iChildren.Count() )
       
    55         {
       
    56         ret = EFalse;
       
    57         Reset();
       
    58         }
       
    59     return ret;
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // 
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 EXPORT_C CHnMenuItemModel* CHnMenuItemModel::GetNext()
       
    67     {
       
    68     ASSERT( iNextMenu < iChildren.Count() );
       
    69     CHnMenuItemModel* ret = iChildren[ iNextMenu ];
       
    70     iNextMenu++;
       
    71     return ret;
       
    72     }
       
    73 
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // 
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 EXPORT_C TBool CHnMenuItemModel::HasNextSpecific()
       
    80     {
       
    81     TBool hasNext = EFalse;
       
    82     if ( iNextMenu >= iChildren.Count() )
       
    83     	{
       
    84     	Reset();
       
    85     	}
       
    86     else if ( iChildren[iNextMenu]->IsItemSpecific() )
       
    87     	{
       
    88     	hasNext = ETrue;
       
    89     	}
       
    90     else
       
    91     	{
       
    92     	iNextMenu++;
       
    93     	hasNext = HasNextSpecific();
       
    94     	}
       
    95     return hasNext;
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // 
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 EXPORT_C CHnMenuItemModel* CHnMenuItemModel::GetNextSpecific()
       
   103     {
       
   104     ASSERT( iNextMenu < iChildren.Count() );
       
   105     ASSERT( iChildren[iNextMenu]->IsItemSpecific() );
       
   106     CHnMenuItemModel* nextSpecific = iChildren[ iNextMenu ];
       
   107     iNextMenu++;
       
   108     return nextSpecific;
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // 
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 EXPORT_C void CHnMenuItemModel::Reset()
       
   116     {
       
   117     iNextMenu = 0;
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // 
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 EXPORT_C void CHnMenuItemModel::AppendChildMenuL( CHnMenuItemModel* aMenuModel )
       
   125     {
       
   126     ASSERT( aMenuModel );
       
   127     iChildren.AppendL( aMenuModel );
       
   128     }
       
   129     
       
   130 // ---------------------------------------------------------------------------
       
   131 // 
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 CHnMenuItemModel::CHnMenuItemModel()
       
   135     {
       
   136     
       
   137     }
       
   138     
       
   139 // ---------------------------------------------------------------------------
       
   140 // 
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 void CHnMenuItemModel::ConstructL( const TDesC& aName )
       
   144     {
       
   145     ASSERT( aName.Length() );
       
   146     iItemSpecific = EFalse;
       
   147     iName.CreateL( aName );
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // 
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 EXPORT_C const TDesC& CHnMenuItemModel::NameL()
       
   155     {
       
   156     return iName;
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // 
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 EXPORT_C TInt CHnMenuItemModel::Command()
       
   164     {
       
   165     return iCommand;
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // 
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 EXPORT_C void CHnMenuItemModel::SetCommand( TInt aCommandId )
       
   173     {
       
   174     iCommand = aCommandId;
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // 
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 EXPORT_C TInt CHnMenuItemModel::Position()
       
   182     {
       
   183     return iPosition;
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // 
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 EXPORT_C void CHnMenuItemModel::SetPosition( TInt aPosition )
       
   191     {
       
   192     iPosition = aPosition;
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // 
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 EXPORT_C void CHnMenuItemModel::SetItemSpecific( TBool aItemSpecific )
       
   200     {
       
   201     iItemSpecific = aItemSpecific;
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // 
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 EXPORT_C TBool CHnMenuItemModel::IsItemSpecific()
       
   209     {
       
   210     return iItemSpecific;
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // 
       
   215 // ---------------------------------------------------------------------------
       
   216 //  
       
   217 EXPORT_C MHnMenuItemModelIterator* CHnMenuItemModel::GetMenuStructure()
       
   218     {
       
   219     return this;
       
   220     }
       
   221 
       
   222