S60 3rd Edition SDK for Symbian OS
Example Applications Guide

LandmarksInfoContainer.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : LandmarksInfoContainer.cpp
00004 *  Part of     : Landmark Reference Application
00005 *  Interface   : -
00006 *  Description : Implements the CLandmarksInfoContainer class
00007 *  Version     : 1.0
00008 *
00009 *  Copyright (c) 2004-2006 Nokia Corporation.
00010 *  This material, including documentation and any related 
00011 *  computer programs, is protected by copyright controlled by 
00012 *  Nokia Corporation.
00013 * ==============================================================================
00014 */
00015 
00016 // INCLUDE FILES
00017 #include <aknsfld.h>
00018 #include <aknnavi.h>
00019 #include <aknlists.h> 
00020 #include <eikclbd.h>
00021 #include <akntitle.h>
00022 #include <aknview.h>
00023 
00024 #include <LmRefApp.rsg>
00025 #include "LmRefApp.hrh"
00026 #include "LandmarksCommonData.h"
00027 #include "LandmarksInfoContainer.h"
00028 #include "LandmarksInfoModel.h"
00029 #include "LandmarksEditDialog.h"
00030 #include "LandmarksApplicationEngine.h"
00031 
00032 // ============================ MEMBER FUNCTIONS ===============================
00033 
00034 // -----------------------------------------------------------------------------
00035 // CLandmarksInfoContainer::CLandmarksInfoContainer
00036 // C++ constructor can NOT contain any code, that
00037 // might leave.
00038 // -----------------------------------------------------------------------------
00039 //
00040 CLandmarksInfoContainer::CLandmarksInfoContainer(
00041     CAknView& aView,
00042     CLandmarksApplicationEngine& aEngine,
00043     CAknNavigationDecorator* aNaviDecorator)
00044 :   iView(aView),
00045     iEngine(aEngine), 
00046     iNaviDecorator(aNaviDecorator)
00047     {
00048     }
00049 
00050 // -----------------------------------------------------------------------------
00051 // CLandmarksInfoContainer::ConstructL
00052 // Symbian 2nd phase constructor can leave.
00053 // -----------------------------------------------------------------------------
00054 //
00055 void CLandmarksInfoContainer::ConstructL(const TRect& aRect)
00056     {
00057     CreateWindowL();
00058     CreateListBoxL();
00059 
00060     // Create data model.
00061     iModel = new (ELeave) CLandmarksInfoModel(iEngine);
00062 
00063     SetRect(aRect);
00064     ActivateL();
00065     }
00066 
00067 // Destructor
00068 CLandmarksInfoContainer::~CLandmarksInfoContainer()
00069     {
00070     iFields.Close();
00071     delete iListBox;
00072         delete iLandmark;
00073     delete iModel;
00074     }
00075 
00076 // -----------------------------------------------------------------------------
00077 // CLandmarksCategoriesView::CountComponentControls
00078 // 
00079 // (other items were commented in a header).
00080 // -----------------------------------------------------------------------------
00081 //
00082 TInt CLandmarksInfoContainer::CountComponentControls() const
00083     {
00084     TInt count = 0;
00085     if (iListBox)
00086         {
00087         count++;
00088         }
00089 
00090     return count; // Return the number of controls inside this container.
00091     }
00092 
00093 // -----------------------------------------------------------------------------
00094 // CLandmarksCategoriesView::ComponentControl
00095 // 
00096 // (other items were commented in a header).
00097 // -----------------------------------------------------------------------------
00098 //
00099 CCoeControl* CLandmarksInfoContainer::ComponentControl(TInt aIndex) const
00100     {
00101     switch (aIndex)
00102         {
00103         case 0:
00104             return iListBox; // Returns the pointer to listbox object.
00105         default:
00106             return NULL; // Exception : Returns NULL.
00107         }
00108     }
00109 
00110 // -----------------------------------------------------------------------------
00111 // CLandmarksInfoContainer::OfferKeyEventL
00112 // 
00113 // (other items were commented in a header).
00114 // -----------------------------------------------------------------------------
00115 //
00116 TKeyResponse CLandmarksInfoContainer::OfferKeyEventL(
00117     const TKeyEvent& aKeyEvent, TEventCode aType)
00118     {
00119         TKeyResponse response = EKeyWasNotConsumed;
00120 
00121     switch (aKeyEvent.iCode)
00122         {
00123         case EKeyUpArrow:
00124         case EKeyDownArrow:
00125             // Scrolling the listbox. Forward to iListBox.
00126             response = iListBox->OfferKeyEventL(aKeyEvent, aType);
00127             break;
00128 
00129         case EKeyLeftArrow:
00130         case EKeyRightArrow:
00131             // Eat these to disable switching views
00132             response = EKeyWasConsumed;
00133             break;
00134 
00135         case EKeyDevice3:
00136             EditLandmarkL();
00137             response = EKeyWasConsumed;
00138             break;
00139             
00140         default:
00141             // menu keys should be handled
00142             break;
00143         }
00144         
00145         return response;
00146     }
00147     
00148 // -----------------------------------------------------------------------------
00149 // CLandmarksInfoContainer::StoreTitlePaneL
00150 // 
00151 // (other items were commented in a header).
00152 // -----------------------------------------------------------------------------
00153 //
00154 void CLandmarksInfoContainer::StoreTitlePaneL()
00155     {
00156     CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
00157     iTitlePane = (CAknTitlePane*) statusPane->ControlL(
00158         TUid::Uid(EEikStatusPaneUidTitle));
00159 
00160     iOriginalTitle = iTitlePane->Text()->AllocL();
00161     }
00162 
00163 // -----------------------------------------------------------------------------
00164 // CLandmarksInfoContainer::RetoreTitlePane
00165 // 
00166 // (other items were commented in a header).
00167 // -----------------------------------------------------------------------------
00168 //
00169 void CLandmarksInfoContainer::RestoreTitlePane()
00170     {
00171     if (iTitlePane && iOriginalTitle)
00172         {
00173         iTitlePane->SetText(iOriginalTitle); // ownership is transferred
00174         }
00175     else
00176         {
00177         delete iOriginalTitle;
00178         }
00179     iOriginalTitle = NULL;
00180     }
00181 
00182 // -----------------------------------------------------------------------------
00183 // CLandmarksInfoContainer::MakeNaviPaneVisibleL
00184 // 
00185 // (other items were commented in a header).
00186 // -----------------------------------------------------------------------------
00187 //
00188 void CLandmarksInfoContainer::MakeNaviPaneVisibleL(TBool aVisible)
00189     {
00190     CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
00191     CAknNavigationControlContainer* naviPane = 
00192         (CAknNavigationControlContainer*) statusPane->
00193             ControlL(TUid::Uid(EEikStatusPaneUidNavi));
00194 
00195     if (!aVisible)
00196         {
00197         // Remove tabs from this view's navi pane
00198         naviPane->Pop(iNaviDecorator);
00199         }
00200     else
00201         {
00202         // Recreate tabs to this view's navi pane
00203         naviPane->PushL(*iNaviDecorator);
00204         }
00205     }
00206 
00207 // -----------------------------------------------------------------------------
00208 // CLandmarksInfoContainer::CreateListBoxL
00209 // 
00210 // (other items were commented in a header).
00211 // -----------------------------------------------------------------------------
00212 //
00213 void CLandmarksInfoContainer::CreateListBoxL()
00214     {
00215     // Create a control to display a list of descriptors
00216     iListBox = new (ELeave) CAknSingleHeadingStyleListBox();
00217     iListBox->SetContainerWindowL(*this);
00218     iListBox->ConstructL(this, 0);
00219 
00220     // Create scrollbars
00221     CEikScrollBarFrame* scrollBar = iListBox->CreateScrollBarFrameL();
00222     scrollBar->SetScrollBarVisibilityL(
00223                 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
00224     }
00225 
00226 // -----------------------------------------------------------------------------
00227 // CLandmarksInfoContainer::SizeChanged
00228 // 
00229 // (other items were commented in a header).
00230 // -----------------------------------------------------------------------------
00231 //
00232 void CLandmarksInfoContainer::SizeChanged()
00233     {
00234         // Set list box size.
00235         iListBox->SetRect(Rect());
00236     }
00237 
00238 // -----------------------------------------------------------------------------
00239 // CLandmarksInfoContainer::HandleResourceChange
00240 // 
00241 // (other items were commented in a header).
00242 // -----------------------------------------------------------------------------
00243 //
00244 void CLandmarksInfoContainer::HandleResourceChange(TInt aType)
00245     {
00246     CCoeControl::HandleResourceChange(aType);
00247     if ( aType == KEikDynamicLayoutVariantSwitch )
00248         {
00249         SetRect(iView.ClientRect());
00250         }
00251     }
00252 
00253 // -----------------------------------------------------------------------------
00254 // CLandmarksInfoContainer::LoadLandmarkL
00255 // 
00256 // (other items were commented in a header).
00257 // -----------------------------------------------------------------------------
00258 //
00259 void CLandmarksInfoContainer::LoadLandmarkL(TPosLmItemId aLandmarkId)
00260     {
00261         delete iLandmark;
00262         iLandmark = NULL;
00263 
00264     iLandmark = iEngine.LandmarkLC(aLandmarkId);
00265     CleanupStack::Pop(iLandmark);
00266 
00267     UpdateL();
00268     iListBox->View()->SetCurrentItemIndex(0);
00269     }
00270     
00271 // -----------------------------------------------------------------------------
00272 // CLandmarksInfoContainer::EditLandmarkL
00273 // 
00274 // (other items were commented in a header).
00275 // -----------------------------------------------------------------------------
00276 //
00277 void CLandmarksInfoContainer::EditLandmarkL()
00278     {
00279     // Create editor
00280     TBool isEdited = EFalse;
00281 
00282     TInt selectedLine = iListBox->View()->CurrentItemIndex();
00283     TInt activeField = 0;
00284     if (selectedLine >= 0 && selectedLine < iFields.Count())
00285         {
00286         activeField = iFields[selectedLine];
00287         }
00288     
00289     CLandmarksEditDialog* editDialog = CLandmarksEditDialog::NewLC(
00290         *iLandmark, EFalse, isEdited, iEngine, activeField);
00291 
00292     TInt err = editDialog->ExecuteLD(R_LMREFAPP_EDIT_DIALOG);
00293     CleanupStack::Pop(editDialog);
00294     User::LeaveIfError(err);
00295 
00296     // Commit if edited
00297     if (isEdited)
00298         {
00299         iEngine.CommitLandmarkL(*iLandmark);
00300         UpdateL();
00301     
00302         // move to first field
00303         iListBox->View()->SetCurrentItemIndex(0);
00304         }
00305     }
00306 
00307 // -----------------------------------------------------------------------------
00308 // CLandmarksInfoContainer::UpdateL
00309 // 
00310 // (other items were commented in a header).
00311 // -----------------------------------------------------------------------------
00312 //
00313 void CLandmarksInfoContainer::UpdateL()
00314     {
00315     CDesCArray* infoArray = iModel->GetLandmarkInfoL(*iLandmark, iFields);
00316 
00317     CTextListBoxModel* model = iListBox->Model();
00318     model->SetItemTextArray(infoArray);
00319     model->SetOwnershipType(ELbmOwnsItemArray);
00320     iListBox->HandleItemAdditionL();
00321 
00322     UpdateTitleBarL();
00323     }
00324 
00325 // -----------------------------------------------------------------------------
00326 // CLandmarksInfoContainer::UpdateTitleBarL
00327 // 
00328 // (other items were commented in a header).
00329 // -----------------------------------------------------------------------------
00330 //
00331 void CLandmarksInfoContainer::UpdateTitleBarL()
00332     {
00333     TPtrC ptr;
00334     if (iLandmark)
00335         {
00336         iLandmark->GetLandmarkName(ptr);
00337         iTitlePane->SetTextL(ptr);
00338         }
00339     else 
00340         {
00341         iTitlePane->SetTextL(*iOriginalTitle);
00342         }
00343     }
00344 
00345 // End of File
00346 

© Nokia 2006

Back to top