menufw/menufwui/mmwidgets/src/mmlistboxmodel.cpp
branchv5backport
changeset 14 1abc632eb502
parent 13 6205fd287e8a
child 20 636d517f67e6
equal deleted inserted replaced
13:6205fd287e8a 14:1abc632eb502
     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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "mmlistboxmodel.h"
       
    20 #include "mmwidgetsconstants.h"
       
    21 #include <eiktxlbm.h> 
       
    22 #include "hnconvutils.h"
       
    23 #include "hnsuiteobserver.h"
       
    24 #include "hnsuitemodel.h"
       
    25 #include "hnitemmodel.h"
       
    26 #include "hnattributebase.h"
       
    27 #include "hnattributeimage.h"
       
    28 #include "hnmenuitemmodel.h"
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 // -----------------------------------------------------------------------------
       
    33 //    
       
    34 CMmListBoxModel::CMmListBoxModel() 
       
    35     : iSuiteModel( NULL )
       
    36 	{
       
    37 	
       
    38 	}
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 // -----------------------------------------------------------------------------
       
    43 // 
       
    44 CMmListBoxModel::~CMmListBoxModel()
       
    45 	{
       
    46     if (iSuiteModel)
       
    47     	{
       
    48         iSuiteModel->UnregisterSuiteObserver( this );
       
    49     	}
       
    50 	}
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 // -----------------------------------------------------------------------------
       
    55 // 
       
    56 CMmListBoxModel* CMmListBoxModel::NewLC()
       
    57 	{
       
    58 	CMmListBoxModel* self = new (ELeave) CMmListBoxModel();
       
    59 	CleanupStack::PushL(self);
       
    60 	self->ConstructL();
       
    61 	return self;
       
    62 	}
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 // -----------------------------------------------------------------------------
       
    67 // 
       
    68 CMmListBoxModel* CMmListBoxModel::NewL()
       
    69 	{
       
    70 	CMmListBoxModel* self = CMmListBoxModel::NewLC();
       
    71 	CleanupStack::Pop( self );
       
    72 	return self;
       
    73 	}
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 // -----------------------------------------------------------------------------
       
    78 // 
       
    79 void CMmListBoxModel::SetSuiteModelL( CHnSuiteModel * aSuiteModel )
       
    80     {   
       
    81     if (iSuiteModel)
       
    82         iSuiteModel->UnregisterSuiteObserver( this );
       
    83     
       
    84     iSuiteModel = aSuiteModel;
       
    85     UpdateDummyArrayDataL();
       
    86     
       
    87     if (iSuiteModel)
       
    88         iSuiteModel->RegisterSuiteObserverL( this, EPriorityNormal );
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 // -----------------------------------------------------------------------------
       
    94 // 
       
    95 CHnAttributeBase* CMmListBoxModel::GetAttribute( TInt aIndex,
       
    96         const TDesC8 & aAttributeName )
       
    97     {
       
    98     CHnItemModel* item = (iSuiteModel) ? iSuiteModel->GetItemModel( iSuiteModel->IdByIndex( aIndex ) ) : NULL;
       
    99     return (item) ? item->GetAttribute( aAttributeName ) : NULL;
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 // -----------------------------------------------------------------------------
       
   105 // 
       
   106 const TDesC8& CMmListBoxModel::GetAttributeAsText( TInt aIndex,
       
   107 		const TDesC8 & aAttributeName )
       
   108     {
       
   109     CHnAttributeBase* attribute = GetAttribute( aIndex, aAttributeName );
       
   110     return (attribute) ? attribute->Value() : KNullDesC8;
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 CHnIconHolder* CMmListBoxModel::GetAttributeAsRefCountedGraphics( TInt aIndex,
       
   118         const TDesC8 & aAttributeName, TSize* aDesiredIconSize)
       
   119     {
       
   120     CHnAttributeBase* attribute = GetAttribute( aIndex, aAttributeName );
       
   121     if ( !attribute || attribute->Type() != EImageAttribute )
       
   122         {
       
   123         return NULL;
       
   124         }
       
   125     return attribute->GetIconHolder( aDesiredIconSize );
       
   126     }
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 // -----------------------------------------------------------------------------
       
   130 // 
       
   131 void CMmListBoxModel::ConstructL()
       
   132 	{
       
   133 	CTextListBoxModel::ConstructL();
       
   134 	}
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 // -----------------------------------------------------------------------------
       
   139 // 
       
   140 void CMmListBoxModel::UpdateDummyArrayDataL( )
       
   141     {
       
   142     CDesCArrayFlat* dataArray = static_cast<CDesC16ArrayFlat*>( ItemTextArray() );
       
   143     dataArray->Reset();
       
   144     for( TInt i(0); iSuiteModel && i < iSuiteModel->GetItemModelsCount(); i++ )
       
   145         {
       
   146         CHnItemModel* itemModel = iSuiteModel->GetItemModel( iSuiteModel->IdByIndex( i ) );
       
   147         CHnItemModel* emptyItem = iSuiteModel->GetItemModel( iSuiteModel->IdByIndex( -1 ) );
       
   148         if (!itemModel || itemModel == emptyItem )
       
   149             {
       
   150             continue;
       
   151             }
       
   152         dataArray->AppendL( KNullDesC16() );
       
   153         }
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 // -----------------------------------------------------------------------------
       
   159 // 
       
   160 void CMmListBoxModel::ReorderModelL(TInt aFromIndex, TInt aToIndex)
       
   161     {
       
   162     iSuiteModel->ReorderItemsL( aFromIndex, aToIndex );
       
   163     UpdateDummyArrayDataL();
       
   164     }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 // -----------------------------------------------------------------------------
       
   169 // 
       
   170 CHnSuiteModel* CMmListBoxModel::GetSuiteModel()
       
   171     {
       
   172     return iSuiteModel;
       
   173     }
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 // -----------------------------------------------------------------------------
       
   178 // 
       
   179 void CMmListBoxModel::HandleSuiteEventL( THnCustomSuiteEvent aCustomSuiteEvent,
       
   180         CHnSuiteModel* aModel)
       
   181     {
       
   182     if (iSuiteModel == aModel)
       
   183         {
       
   184         switch ( aCustomSuiteEvent )
       
   185     	    {
       
   186     	    case ESuiteModelDestroyed:
       
   187     		    iSuiteModel = NULL;
       
   188     		    break;
       
   189     	    case ESuiteItemsAdded:
       
   190     	    case ESuiteItemsRemoved:
       
   191     	    case ESuiteItemsUpdated:
       
   192     	        UpdateDummyArrayDataL( );
       
   193     	    default:
       
   194     	    	break;
       
   195     	    }
       
   196         }
       
   197     }
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 // -----------------------------------------------------------------------------
       
   202 // 
       
   203 TInt CMmListBoxModel::GetNumberOfSpecificMenuItemsL( TInt aItemIndex )
       
   204     {
       
   205     TInt itemSpecificMenuItemCount = KErrNotFound;
       
   206     if ( iSuiteModel )
       
   207         {
       
   208         TInt itemId = iSuiteModel->IdByIndex( aItemIndex );
       
   209         if ( itemId != KErrNotFound )
       
   210             {
       
   211             itemSpecificMenuItemCount = 0;
       
   212             MHnMenuItemModelIterator* menuItemModelIter =
       
   213                     iSuiteModel->GetMenuStructureL( itemId );
       
   214             while ( menuItemModelIter && menuItemModelIter->HasNextSpecific() )
       
   215                 {
       
   216                 menuItemModelIter->GetNextSpecific();
       
   217                 ++itemSpecificMenuItemCount;
       
   218                 }
       
   219             }
       
   220         }
       
   221     return itemSpecificMenuItemCount;
       
   222     }
       
   223 
       
   224 // End of file