landmarksui/uicontrols/src/CLmkLmItemListMemento.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     1 /*
       
     2 * Copyright (c) 2002 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:    LandmarksUi Content File -
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 // INCLUDE FILES
       
    26 #include "CLmkLmItemListMemento.h"
       
    27 #include "CLmkLmItemListProvider.h"
       
    28 #include <eiklbx.h>
       
    29 #include <AknUtils.h>
       
    30 #include <lmkerrors.h>
       
    31 
       
    32 
       
    33 // Initial value for iMemorizedCurrentItemId, this is a quick fix for focus on
       
    34 // uncategorised category bug.
       
    35 //const TInt KIdNotFound = KErrNotFound;
       
    36 const TUint32 KInititialValue = 0xFFFFFFFE;
       
    37 #if defined(_DEBUG)
       
    38 
       
    39 // CONSTANTS
       
    40 /// Unnamed namespace for local definitions
       
    41 namespace {
       
    42 
       
    43 _LIT( KPanicMsg, "CLmkLmItemListMemento" );
       
    44 
       
    45 void Panic( TPanicCode aReason )
       
    46     {
       
    47     User::Panic( KPanicMsg, aReason );
       
    48     }
       
    49 }  // namespace
       
    50 
       
    51 #endif
       
    52 // ============================ MEMBER FUNCTIONS ===============================
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CLmkLmItemListMemento::CLmkLmItemListMemento
       
    56 // C++ constructor can NOT contain any code, that
       
    57 // might leave.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CLmkLmItemListMemento::CLmkLmItemListMemento()
       
    61     {
       
    62     //iMemorizedCurrentItemId = KPosLmNullItemId;
       
    63     iMemorizedCurrentItemId = KInititialValue;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CLmkLmItemListMemento::ConstructL
       
    68 // Symbian 2nd phase constructor can leave.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 void CLmkLmItemListMemento::ConstructL()
       
    72     {
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CLmkLmItemListMemento::NewL
       
    77 // Two-phased constructor.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 CLmkLmItemListMemento* CLmkLmItemListMemento::NewL()
       
    81     {
       
    82     CLmkLmItemListMemento* self = new( ELeave ) CLmkLmItemListMemento();
       
    83 
       
    84     CleanupStack::PushL( self );
       
    85     self->ConstructL();
       
    86     CleanupStack::Pop();
       
    87 
       
    88     return self;
       
    89     }
       
    90 
       
    91 // ----------------------------------------------------
       
    92 // CLmkLmItemListMemento::~CLmkLmItemListMemento
       
    93 // ----------------------------------------------------
       
    94 //
       
    95 CLmkLmItemListMemento::~CLmkLmItemListMemento()
       
    96     {
       
    97     }
       
    98 
       
    99 // ----------------------------------------------------
       
   100 // CLmkLmItemListMemento::MemorizedItemId
       
   101 // ----------------------------------------------------
       
   102 //
       
   103 EXPORT_C TPosLmItemId CLmkLmItemListMemento::MemorizedItemId() const
       
   104     {
       
   105     return iMemorizedCurrentItemId;
       
   106     }
       
   107 
       
   108 // ----------------------------------------------------
       
   109 // CLmkLmItemListMemento::Store
       
   110 // ----------------------------------------------------
       
   111 //
       
   112 void CLmkLmItemListMemento::Store(
       
   113     const CEikListBox& aListBox,
       
   114     const CLmkListProviderBase& aProvider,
       
   115     TBool aFiltered )
       
   116     {
       
   117     if ( aFiltered )
       
   118         {
       
   119         CAknFilteredTextListBoxModel* model =
       
   120             static_cast<CAknFilteredTextListBoxModel*>( aListBox.Model() );
       
   121         __ASSERT_DEBUG( model, Panic( KLmkPanicNoLbModel ) );
       
   122         StoreFiltered( aListBox, aProvider, *model );
       
   123         }
       
   124     else
       
   125         {
       
   126         StoreNonFiltered( aListBox, aProvider );
       
   127         }
       
   128     }
       
   129 
       
   130 // ----------------------------------------------------
       
   131 // CLmkLmItemListMemento::Restore
       
   132 // ----------------------------------------------------
       
   133 //
       
   134 void CLmkLmItemListMemento::Restore(
       
   135     const CEikListBox& aListBox,
       
   136     const CLmkListProviderBase& aProvider,
       
   137     TBool aFiltered )
       
   138     {
       
   139     if ( aFiltered )
       
   140         {
       
   141         CAknFilteredTextListBoxModel* model =
       
   142             static_cast<CAknFilteredTextListBoxModel*>( aListBox.Model() );
       
   143         __ASSERT_DEBUG( model, Panic( KLmkPanicNoLbModel ) );
       
   144         RestoreFiltered( aListBox, aProvider, *model );
       
   145         }
       
   146     else
       
   147         {
       
   148         RestoreNonFiltered( aListBox, aProvider );
       
   149         }
       
   150     }
       
   151 
       
   152 // ----------------------------------------------------
       
   153 // CLmkLmItemListMemento::StoreFiltered
       
   154 // ----------------------------------------------------
       
   155 //
       
   156 void CLmkLmItemListMemento::StoreFiltered(
       
   157     const CEikListBox& aListBox,
       
   158     const CLmkListProviderBase& aProvider,
       
   159     const CAknFilteredTextListBoxModel& aModel )
       
   160     {
       
   161     const CLmkLmItemListProvider& provider =
       
   162         static_cast <const CLmkLmItemListProvider&> ( aProvider );
       
   163     if ( aListBox.Model()->NumberOfItems() > 0 &&
       
   164          aListBox.CurrentItemIndex() >= 0 )
       
   165         {
       
   166         iMemorizedCurrentItemIndex =
       
   167             aModel.Filter()->FilteredItemIndex( aListBox.CurrentItemIndex() );
       
   168         provider.GetSelectedItemId( iMemorizedCurrentItemId,
       
   169                                 iMemorizedCurrentItemIndex );
       
   170         }
       
   171     else
       
   172         {
       
   173         iMemorizedCurrentItemIndex = 0;
       
   174        // iMemorizedCurrentItemId = KPosLmNullItemId;
       
   175         iMemorizedCurrentItemId = KInititialValue;
       
   176         }
       
   177     }
       
   178 
       
   179 // ----------------------------------------------------
       
   180 // CLmkLmItemListMemento::RestoreFiltered
       
   181 // ----------------------------------------------------
       
   182 //
       
   183 void CLmkLmItemListMemento::RestoreFiltered(
       
   184     const CEikListBox& aListBox,
       
   185     const CLmkListProviderBase& aProvider,
       
   186     const CAknFilteredTextListBoxModel& /*aModel*/ )
       
   187     {
       
   188     const CLmkLmItemListProvider& provider =
       
   189         static_cast <const CLmkLmItemListProvider&> ( aProvider );
       
   190     TInt index = provider.SelectedIndex( iMemorizedCurrentItemId );
       
   191     if ( index != KErrNotFound &&
       
   192          index < aListBox.Model()->NumberOfItems() )
       
   193         {
       
   194         aListBox.SetCurrentItemIndex( index );
       
   195         aListBox.ScrollToMakeItemVisible( index );
       
   196         }
       
   197     else
       
   198         {
       
   199         aListBox.SetCurrentItemIndex( 0 );
       
   200         }
       
   201     aListBox.DrawDeferred();
       
   202     }
       
   203 
       
   204 // ----------------------------------------------------
       
   205 // CLmkLmItemListMemento::StoreNonFiltered
       
   206 // ----------------------------------------------------
       
   207 //
       
   208 void CLmkLmItemListMemento::StoreNonFiltered(
       
   209     const CEikListBox& aListBox,
       
   210     const CLmkListProviderBase& aProvider )
       
   211     {
       
   212     // TODO: these are not used and implementation is quite sketchy.
       
   213     // Replace with leave KErrNotSupported if this method won't be used.
       
   214     const CLmkLmItemListProvider& provider =
       
   215         static_cast <const CLmkLmItemListProvider&> ( aProvider );
       
   216     iMemorizedCurrentItemIndex = aListBox.CurrentItemIndex();
       
   217     provider.GetSelectedItemId( iMemorizedCurrentItemId,
       
   218                                 iMemorizedCurrentItemIndex );
       
   219     iMemorizedTopItemIndex = aListBox.TopItemIndex();
       
   220     }
       
   221 
       
   222 // ----------------------------------------------------
       
   223 // CLmkLmItemListMemento::RestoreNonFiltered
       
   224 // ----------------------------------------------------
       
   225 //
       
   226 void CLmkLmItemListMemento::RestoreNonFiltered(
       
   227     const CEikListBox& aListBox,
       
   228     const CLmkListProviderBase& aProvider )
       
   229     {
       
   230     // TODO: these are not used and implementation is quite sketchy.
       
   231     // Replace with leave KErrNotSupported if this method won't used.
       
   232     const CLmkLmItemListProvider& provider =
       
   233         static_cast <const CLmkLmItemListProvider&> ( aProvider );
       
   234     TInt index = provider.SelectedIndex( iMemorizedCurrentItemId );
       
   235     if ( index != KErrNotFound )
       
   236         {
       
   237         if ( index == iMemorizedCurrentItemIndex )
       
   238             {
       
   239             aListBox.SetCurrentItemIndex( iMemorizedCurrentItemIndex );
       
   240             aListBox.SetTopItemIndex( iMemorizedTopItemIndex );
       
   241             }
       
   242         else
       
   243             {
       
   244             aListBox.ScrollToMakeItemVisible( index );
       
   245             }
       
   246         }
       
   247     else
       
   248         {
       
   249         aListBox.SetCurrentItemIndex( 0 );
       
   250         }
       
   251     aListBox.DrawDeferred();
       
   252     }
       
   253 
       
   254 // ----------------------------------------------------
       
   255 // CLmkLmItemListMemento::IsModelAvailable
       
   256 // ----------------------------------------------------
       
   257 //anwar
       
   258 TBool CLmkLmItemListMemento::IsModelAvailable()
       
   259 	{
       
   260 	return iModelAvailable;
       
   261 	}
       
   262 // ----------------------------------------------------
       
   263 // CLmkLmItemListMemento::UpdateModelAvailability
       
   264 // ----------------------------------------------------
       
   265 //anwar
       
   266 void  CLmkLmItemListMemento::UpdateModelAvailability(TBool aModelAvailable)
       
   267 	{
       
   268 	iModelAvailable = aModelAvailable;
       
   269 	}
       
   270 //  End of File