Example Application Guide

 

geoprofilescontainer.cpp

00001 /*
00002 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
00003 * All rights reserved.
00004 * This component and the accompanying materials are made available
00005 * under the terms of the License "Eclipse Public License v1.0"
00006 * which accompanies this distribution, and is available
00007 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 *
00009 * Initial Contributors:
00010 * Nokia Corporation - initial contribution.
00011 *
00012 * Contributors:
00013 *
00014 * Description:  Container class for Geo Profiles Application
00015 *
00016 */
00017 
00018 
00019 // SYSTEM INCLUDES
00020 #include <avkon.hrh>
00021 #include <barsread.h> 
00022 #include <barsread.h>                   // TResourceReader
00023 #include <geoprofilesui.rsg>
00024 #include <aknutils.h>
00025 #include <eikspane.h>               // Status pane
00026 #include <akntitle.h>           // CAknTitlePane
00027 #include <stringloader.h>
00028 #include <aknlists.h>       // Settings Style list box
00029 
00030 // USER INCLUDES
00031 #include "geoprofilescontainer.h"
00032 #include "geoprofilesappui.h"
00033 #include "geoprofilesuid.hrh"
00034 #include "geoprofiles.hrh"
00035 #include "geoprofileslbmodel.h"
00036 #include "geoprofilesview.h"
00037 
00038 // CONSTANT DEFINITIONS
00039  
00040 // ----------------- Member funtions for CGeoProfilesContainer class ------------------
00041 
00042 // ---------------------------------------------------------------------------
00043 // CGeoProfilesContainer::CGeoProfilesContainer
00044 // ---------------------------------------------------------------------------
00045 //
00046 CGeoProfilesContainer::CGeoProfilesContainer( CGeoProfilesLBModel&  aListboxModel,
00047                                               CGeoProfilesView&     aView )
00048     :iListboxModel( &aListboxModel ),
00049     iView( aView )
00050     {
00051     }
00052 
00053 // ---------------------------------------------------------------------------
00054 // CGeoProfilesContainer::~CGeoProfilesContainer
00055 // ---------------------------------------------------------------------------
00056 //
00057 CGeoProfilesContainer::~CGeoProfilesContainer()
00058     {
00059     // Delete the list box
00060     delete iListBox;
00061     
00062     }
00063     
00064 // ---------------------------------------------------------------------------
00065 // CGeoProfilesContainer::NewL
00066 // ---------------------------------------------------------------------------
00067 //
00068 CGeoProfilesContainer* CGeoProfilesContainer::NewL( 
00069                                     const TRect&                    aRect,
00070                                           CGeoProfilesLBModel&  aListboxModel,
00071                                           CGeoProfilesView&     aView )     
00072     {
00073     CGeoProfilesContainer* self = new (ELeave) CGeoProfilesContainer( aListboxModel,
00074                                                                       aView );
00075     CleanupStack::PushL( self );
00076     self->ConstructL( aRect );
00077     CleanupStack::Pop();
00078     
00079     return self;
00080     }
00081     
00082 // ---------------------------------------------------------------------------
00083 // CGeoProfilesContainer::ConstructL
00084 // ---------------------------------------------------------------------------
00085 //
00086 void CGeoProfilesContainer::ConstructL( const TRect&    aRect )
00087     {
00088     // This is the cheif control for this application. This has to be made a 
00089     // Window owning control
00090     CreateWindowL();
00091     
00092         // Create a New Title for the View
00093         MakeTitleL( R_GEOPROFILES_TITLE );
00094     
00095     // Create the Geo Profiles list box
00096     CreateListboxL();
00097             
00098     SetRect(aRect);
00099     ActivateL();
00100     }
00101 
00102 // ---------------------------------------------------------------------------
00103 // void CGeoProfilesContainer::UpdateL
00104 // ---------------------------------------------------------------------------
00105 //
00106 void CGeoProfilesContainer::UpdateL( CGeoProfilesLBModel&  aListboxModel )
00107     {
00108     // Store the new list box model
00109     iListboxModel = &aListboxModel;
00110     
00111     // Assign it to the listbox
00112     iListBox->Model()->SetItemTextArray( iListboxModel );
00113     
00114     // Update the list box
00115     iListBox->HandleItemAdditionL();
00116     iListBox->HandleItemRemovalL();
00117     
00118     DrawDeferred();
00119     }
00120 
00121 // ---------------------------------------------------------------------------
00122 // TInt CGeoProfilesContainer::GetFocussedItem
00123 // ---------------------------------------------------------------------------
00124 //
00125 TInt CGeoProfilesContainer::GetFocussedItem()
00126     {
00127     if ( !iListBox )
00128         {
00129         return KErrNotFound;        
00130         }
00131     else 
00132         {
00133         return iListBox->CurrentItemIndex();
00134         }
00135     }
00136     
00137 // ---------------------------------------------------------------------------
00138 // void CGeoProfilesContainer::SizeChanged
00139 // ---------------------------------------------------------------------------
00140 //
00141 void CGeoProfilesContainer::SizeChanged()
00142     {
00143     if ( iListBox )
00144         {
00145         iListBox->SetRect( Rect());
00146         }
00147     }
00148 
00149 // ---------------------------------------------------------------------------
00150 // TInt CGeoProfilesContainer::CountComponentControls
00151 // ---------------------------------------------------------------------------
00152 //
00153 TInt CGeoProfilesContainer::CountComponentControls() const
00154     {
00155     if ( iListBox )
00156         {
00157         return 1;    
00158         }
00159     else
00160         {
00161         return 0;    
00162         }
00163     }
00164 
00165 // ---------------------------------------------------------------------------
00166 // CCoeControl* CGeoProfilesContainer::ComponentControl
00167 // ---------------------------------------------------------------------------
00168 //
00169 CCoeControl* CGeoProfilesContainer::ComponentControl(TInt /* aIndex*/ ) const
00170     {
00171     return iListBox;
00172     }
00173     
00174 // ---------------------------------------------------------------------------
00175 // TKeyResponse CGeoProfilesContainer::OfferKeyEventL
00176 // ---------------------------------------------------------------------------
00177 //    
00178 TKeyResponse CGeoProfilesContainer::OfferKeyEventL( 
00179                                         const TKeyEvent& aKeyEvent,
00180                                                                                           TEventCode aType )
00181     {
00182     switch ( aKeyEvent.iCode )
00183         {
00184         case EKeyLeftArrow:
00185         case EKeyRightArrow:
00186             {
00187             // No action in this application for the Right arrow and left
00188             // arrow.
00189             return EKeyWasNotConsumed;  
00190             }
00191         default:
00192             {
00193             break;  
00194             }
00195         }
00196     return iListBox->OfferKeyEventL( aKeyEvent, aType ); 
00197     }   
00198 
00199 // ---------------------------------------------------------------------------
00200 // void CGeoProfilesContainer::HandleResourceChange
00201 // ---------------------------------------------------------------------------
00202 //
00203 void CGeoProfilesContainer::HandleResourceChange( TInt aType )
00204         {
00205     // Pass the event to the base class
00206     CCoeControl::HandleResourceChange( aType );
00207     
00208     switch( aType )
00209         {
00210         // Dynamic Layout switch and Skin Change
00211         case KEikDynamicLayoutVariantSwitch:
00212             {
00213             iView.ContainerCommandL( aType );
00214             break;
00215             }        
00216         case KAknsMessageSkinChange:
00217             {
00218             break;
00219             }
00220         default:
00221             {
00222             break;
00223             }
00224         }       
00225         }
00226 
00227 // ---------------------------------------------------------------------------
00228 // void CGeoProfilesContainer::HandleListBoxEventL
00229 // ---------------------------------------------------------------------------
00230 //
00231 void CGeoProfilesContainer::HandleListBoxEventL( 
00232                                             CEikListBox*      /* aListBox */, 
00233                                             TListBoxEvent     aEventType )
00234     {
00235     switch (aEventType)
00236         {
00237         // List box Item Selection
00238         case EEventEnterKeyPressed:
00239         case EEventItemDoubleClicked:
00240             {
00241             iView.ContainerCommandL( EGeoProfilesOpen );
00242             break;  
00243             }
00244         default:
00245            break;
00246         }        
00247     }
00248 
00249 // ---------------------------------------------------------------------------
00250 // void CGeoProfilesContainer::FocusChanged
00251 //
00252 // ---------------------------------------------------------------------------
00253 //
00254 void CGeoProfilesContainer::FocusChanged( TDrawNow aDrawNow )
00255     {
00256     CCoeControl::FocusChanged( aDrawNow );
00257     // The focus event has to be explicitly handed over to all the compound
00258     // controls since CCoeControl does not do that implicitly
00259     iListBox->SetFocus( IsFocused(), aDrawNow );
00260     }
00261 
00262 // ---------------------------------------------------------------------------
00263 // void CGeoProfilesContainer::CreateListboxL
00264 // ---------------------------------------------------------------------------  
00265 //
00266 void CGeoProfilesContainer::CreateListboxL()
00267     {
00268     
00269     // Create the List box
00270     iListBox = new ( ELeave ) CAknSettingStyleListBox;
00271     iListBox->ConstructL( this, EAknListBoxSelectionList );
00272     iListBox->SetContainerWindowL( *this ); 
00273     iListBox->SetListBoxObserver( this );
00274     iListBox->CreateScrollBarFrameL( ETrue );
00275     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
00276                                                          CEikScrollBarFrame::EAuto ); 
00277                                                          
00278     // The ownership of the list box model is retained with the Container.
00279     // This is because the model contains the additional functionality of
00280     // changing the settings values in addition to retreiving it.                                                        
00281     iListBox->Model()->SetItemTextArray( iListboxModel );  
00282     iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
00283     
00284     // Set empty text for the list box
00285     HBufC* emptyText = StringLoader::LoadLC( R_LBL_GEOPROFILES_NOPROFILES );
00286     // Set text for empty list
00287     CEikListBox* listbox = iListBox;
00288     listbox->View()->SetListEmptyTextL( *emptyText );
00289     CleanupStack::PopAndDestroy( emptyText );
00290                                          
00291     iListBox->ActivateL();
00292     }
00293                                       
00294 // ---------------------------------------------------------------------------
00295 // void CGeoProfilesContainer::MakeTitleL
00296 // Sets the Title text
00297 //
00298 // @param aResourceText Resource to create title
00299 // ---------------------------------------------------------------------------
00300 //
00301 void CGeoProfilesContainer::MakeTitleL( TInt aResourceText )
00302         {
00303         CEikStatusPane* statusPane = 
00304             static_cast<CEikStatusPane*>( iEikonEnv->AppUiFactory()->StatusPane());
00305         // Obtain the title from the Status Pane
00306         CAknTitlePane* title = static_cast<CAknTitlePane*>( statusPane->
00307         ControlL( TUid::Uid( EEikStatusPaneUidTitle )));
00308        
00309     // Set the Title's buffer    
00310     HBufC* buf = StringLoader::LoadL( aResourceText );
00311     title->SetText( buf ); // Takes ownership of buf
00312         }

© Nokia 2009

Back to top