gssettingsuis/Gs/GSFramework/src/GSBaseView.cpp
branchRCL_3
changeset 24 8ee96d21d9bf
parent 23 8bda91a87a00
child 25 7e0eff37aedb
equal deleted inserted replaced
23:8bda91a87a00 24:8ee96d21d9bf
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  Base view for all General Settings views.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <gsbaseview.h>
       
    21 #include    <gsbasecontainer.h>
       
    22 
       
    23 #include    <aknnavide.h>
       
    24 #include    <akntabgrp.h>
       
    25 #include    <akntitle.h>
       
    26 #include    <AknUtils.h>
       
    27 #include    <aknViewAppUi.h>
       
    28 #include    <barsread.h>
       
    29 #include    <bautils.h> // BaflUtils
       
    30 #include    <bldvariant.hrh>
       
    31 #include    <featmgr.h>
       
    32 
       
    33 
       
    34 //Disabling warning caused by KGSDoActivateError constant
       
    35 #pragma diag_suppress 177
       
    36 // CONSTANTS
       
    37 _LIT( KGSDoActivateError, "DoActivateL" );
       
    38 
       
    39 // ========================= MEMBER FUNCTIONS ================================
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CGSBaseView::CGSBaseView
       
    43 //
       
    44 // C++ constructor
       
    45 // ---------------------------------------------------------------------------
       
    46 EXPORT_C CGSBaseView::CGSBaseView()
       
    47     : iResourceLoader( *iCoeEnv )
       
    48     {
       
    49     iAppUi = AppUi();
       
    50     iElaf = ( AknLayoutUtils::Variant() == EEuropeanVariant );
       
    51     }
       
    52 
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CGSBaseView::~CGSBaseView
       
    56 //
       
    57 // Destructor
       
    58 // ---------------------------------------------------------------------------
       
    59 EXPORT_C CGSBaseView::~CGSBaseView()
       
    60     {
       
    61     iResourceLoader.Close();
       
    62     if (iContainer)
       
    63         {
       
    64         AppUi()->RemoveFromViewStack( *this, iContainer );
       
    65         delete iContainer;
       
    66         }
       
    67     if ( iNaviPaneContext )
       
    68         {
       
    69         delete iNaviPaneContext;
       
    70         }
       
    71     }
       
    72 
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CGSBaseView::Container
       
    76 //
       
    77 //
       
    78 // ---------------------------------------------------------------------------
       
    79 EXPORT_C CGSBaseContainer* CGSBaseView::Container()
       
    80     {
       
    81     return iContainer;
       
    82     }
       
    83 
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // CGSBaseView::SetCurrentItem
       
    87 //
       
    88 //
       
    89 // ---------------------------------------------------------------------------
       
    90 EXPORT_C void CGSBaseView::SetCurrentItem( TInt aIndex )
       
    91     {
       
    92     iCurrentItem = aIndex;
       
    93     }
       
    94 
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CGSBaseView::HandleListBoxEventL
       
    98 //
       
    99 //
       
   100 // ---------------------------------------------------------------------------
       
   101 
       
   102 EXPORT_C void CGSBaseView::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
   103                                                 TListBoxEvent aEventType )
       
   104     {
       
   105     switch ( aEventType )
       
   106         {
       
   107         case EEventEnterKeyPressed:
       
   108         case EEventItemSingleClicked:
       
   109             HandleListBoxSelectionL();
       
   110             break;
       
   111         default:
       
   112            break;
       
   113         }
       
   114     }
       
   115 
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // CGSBaseView::SetNaviPaneL
       
   119 //
       
   120 //
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 EXPORT_C void CGSBaseView::SetNaviPaneL()
       
   124     {
       
   125     CAknNavigationControlContainer* naviControlContainer = 
       
   126                                             NaviControlContainerL();
       
   127     if ( iNaviPaneContext )
       
   128         {
       
   129         naviControlContainer->PushL( *iNaviPaneContext );
       
   130         }
       
   131     else
       
   132         {
       
   133         naviControlContainer->PushDefaultL();
       
   134         }
       
   135     }
       
   136 
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CGSBaseView::CreateNaviPaneContextL
       
   140 //
       
   141 //
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 EXPORT_C void CGSBaseView::CreateNaviPaneContextL( TInt aResourceId )
       
   145     {
       
   146     TResourceReader reader;
       
   147     iCoeEnv->CreateResourceReaderLC( reader, aResourceId );
       
   148     CAknNavigationControlContainer* naviControlContainer = 
       
   149                                              NaviControlContainerL();
       
   150     iNaviPaneContext = naviControlContainer->CreateMessageLabelL( reader );
       
   151     CleanupStack::PopAndDestroy();  // reader
       
   152     }
       
   153 
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // CGSBaseView::NaviControlContainerL
       
   157 //
       
   158 //
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 CAknNavigationControlContainer* CGSBaseView::NaviControlContainerL()
       
   162     {
       
   163     CAknNavigationControlContainer* control = NULL;
       
   164     if( !iNaviControlContainer )
       
   165         {
       
   166         iNaviControlContainer =
       
   167             static_cast<CAknNavigationControlContainer*>(
       
   168                 AppUi()->StatusPane()->ControlL( TUid::Uid(
       
   169                     EEikStatusPaneUidNavi ) ) );
       
   170         }
       
   171     else
       
   172         {
       
   173         control = iNaviControlContainer;
       
   174         }
       
   175     
       
   176     return control;
       
   177     }
       
   178 
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // CGSBaseView::HandleClientRectChange
       
   182 //
       
   183 //
       
   184 // ---------------------------------------------------------------------------
       
   185 void CGSBaseView::HandleClientRectChange()
       
   186     {
       
   187     if ( iContainer && iContainer->iListBox )
       
   188         {
       
   189         iContainer->SetRect( ClientRect() );
       
   190         }
       
   191     }
       
   192 
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CGSBaseView::DoActivateL
       
   196 // Activates the view.
       
   197 //
       
   198 // ---------------------------------------------------------------------------
       
   199 EXPORT_C void CGSBaseView::DoActivateL( const TVwsViewId& aPrevViewId,
       
   200                                         TUid /*aCustomMessageId*/,
       
   201                                         const TDesC8& /*aCustomMessage*/ )
       
   202     {
       
   203     iPrevViewId = aPrevViewId;
       
   204 //    if( iContainer )
       
   205 //        {
       
   206 //        AppUi()->RemoveFromViewStack( *this, iContainer );
       
   207 //
       
   208 //        delete iContainer;
       
   209 //        iContainer = NULL;
       
   210 //        }
       
   211     if ( !iContainer )
       
   212     	{
       
   213     	CreateContainerL();
       
   214 		AppUi()->AddToViewStackL( *this, iContainer );
       
   215 		iContainer->iListBox->SetListBoxObserver( this ) ;
       
   216 		iContainer->iListBox->SetTopItemIndex( iTopItemIndex );
       
   217 		iContainer->SetSelectedItem( iCurrentItem );
       
   218     	}
       
   219     }
       
   220 
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CGSBaseView::DoDeactivate()
       
   224 //
       
   225 //
       
   226 // ---------------------------------------------------------------------------
       
   227 EXPORT_C void CGSBaseView::DoDeactivate()
       
   228     {
       
   229     if ( iContainer )
       
   230         {
       
   231         iCurrentItem = iContainer->SelectedItem();
       
   232         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   233         delete iContainer;
       
   234         iContainer = NULL;
       
   235         }
       
   236     }
       
   237 
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // CGSBaseView::CreateContainerL()
       
   241 //
       
   242 //
       
   243 // ---------------------------------------------------------------------------
       
   244 //
       
   245 EXPORT_C void CGSBaseView::CreateContainerL()
       
   246     {
       
   247     NewContainerL();
       
   248     __ASSERT_DEBUG(
       
   249         iContainer, User::Panic( KGSDoActivateError, EGSViewPanicNullPtr ) );
       
   250     iContainer->SetMopParent( this );
       
   251 
       
   252     TRAPD( error, iContainer->ConstructL( ClientRect() ) );
       
   253 
       
   254     if ( error )
       
   255         {
       
   256         delete iContainer;
       
   257         iContainer = NULL;
       
   258         User::Leave( error );
       
   259         }
       
   260     }
       
   261 
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 // CGSBaseView::OpenLocalizedResourceFileL()
       
   265 //
       
   266 //
       
   267 // ---------------------------------------------------------------------------
       
   268 //
       
   269 EXPORT_C void CGSBaseView::OpenLocalizedResourceFileL(
       
   270     const TDesC& aResourceFileName,
       
   271     RConeResourceLoader& aResourceLoader )
       
   272     {
       
   273     RFs &fsSession = CCoeEnv::Static()->FsSession();
       
   274 
       
   275     // Find the resource file:
       
   276     TParse parse;
       
   277     parse.Set( aResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL );
       
   278     TFileName fileName( parse.FullName() );
       
   279 
       
   280     // Get language of resource file:
       
   281     BaflUtils::NearestLanguageFile( fsSession, fileName );
       
   282 
       
   283     // Open resource file:
       
   284     aResourceLoader.OpenL( fileName );
       
   285     }
       
   286 
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CGSBaseView::ResetSelectedItemIndex()
       
   290 //
       
   291 //
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 EXPORT_C void CGSBaseView::ResetSelectedItemIndex()
       
   295     {
       
   296     iCurrentItem = 0;
       
   297     if( iContainer )
       
   298         {
       
   299         iContainer->SetSelectedItem( iCurrentItem );
       
   300         }
       
   301     }
       
   302 
       
   303 //End of File