S60 3rd Edition SDK for Symbian OS
Example Applications Guide

LandmarksView.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : LandmarksView.cpp
00004 *  Part of     : Landmark Reference Application
00005 *  Interface   : -
00006 *  Description : Implements the CLandmarksView 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 <eikmenup.h>
00018 #include <aknviewappui.h>
00019 
00020 #include <LmRefApp.rsg>
00021 #include "LmRefApp.hrh"
00022 #include "LandmarksView.h"
00023 #include "LandmarksApplicationEngine.h"
00024 #include "LandmarksContainer.h"
00025 #include "LandmarksEditDialog.h"
00026 
00027 // ============================ MEMBER FUNCTIONS ===============================
00028 
00029 // -----------------------------------------------------------------------------
00030 // CLandmarksView::CLandmarksView
00031 // C++ constructor can NOT contain any code, that
00032 // might leave.
00033 // -----------------------------------------------------------------------------
00034 //
00035 CLandmarksView::CLandmarksView(
00036     CAknNavigationDecorator* aNaviDecorator,
00037     CLandmarksApplicationEngine& aEngine)
00038 :   iEngine(aEngine), 
00039     iNaviDecorator(aNaviDecorator)
00040     {
00041     // No implementation required
00042     }
00043 
00044 // -----------------------------------------------------------------------------
00045 // CLandmarksView::ConstructL
00046 // Symbian 2nd phase constructor can leave.
00047 // -----------------------------------------------------------------------------
00048 //
00049 void CLandmarksView::ConstructL()
00050     {
00051     BaseConstructL(R_LMREFAPP_VIEW);
00052     }
00053 
00054 // -----------------------------------------------------------------------------
00055 // CLandmarksView::NewLC
00056 // Two-phased constructor.
00057 // -----------------------------------------------------------------------------
00058 //
00059 CLandmarksView* CLandmarksView::NewLC(
00060     CAknNavigationDecorator* aNaviDecorator,
00061     CLandmarksApplicationEngine& aEngine)
00062     {
00063     CLandmarksView* self = new (ELeave) CLandmarksView(
00064         aNaviDecorator, aEngine);
00065     CleanupStack::PushL(self);
00066     self->ConstructL();
00067     return self;
00068     }
00069 
00070 // Destructor
00071 CLandmarksView::~CLandmarksView()
00072     {
00073     delete iContainer;
00074     }
00075 
00076 // -----------------------------------------------------------------------------
00077 // CLandmarksView::Id
00078 // 
00079 // (other items were commented in a header).
00080 // -----------------------------------------------------------------------------
00081 //
00082 TUid CLandmarksView::Id() const
00083     {
00084     return TUid::Uid(ELandmarksViewId);
00085     }
00086 
00087 // -----------------------------------------------------------------------------
00088 // CLandmarksView::HandleCommandL
00089 // 
00090 // (other items were commented in a header).
00091 // -----------------------------------------------------------------------------
00092 //
00093 void CLandmarksView::HandleCommandL(TInt aCommand)
00094     {
00095     switch (aCommand)
00096         {
00097         case ELandmarksAddCurrent:
00098             AddLandmarkL(ETrue); // use current location
00099             break;
00100 
00101         case ELandmarksAddBlank:
00102             AddLandmarkL(EFalse); // create blank
00103             break;
00104 
00105         case ELandmarksDelete:
00106             iContainer->DeleteLandmarkL();
00107             break;
00108 
00109         case ELandmarksOpen:
00110             {
00111             TPckgC<TPosLmItemId> lmId(iContainer->CurrentLandmark());
00112             
00113             AppUi()->ActivateLocalViewL(
00114                 TUid::Uid(ELandmarksInfoViewId),
00115                 TUid::Uid(ELandmarksViewInfoById),
00116                 lmId);
00117             break;
00118             }
00119 
00120         default:
00121             AppUi()->HandleCommandL(aCommand);
00122             break;
00123         }
00124     }
00125 
00126 // -----------------------------------------------------------------------------
00127 // CLandmarksView::DoActivateL
00128 // 
00129 // (other items were commented in a header).
00130 // -----------------------------------------------------------------------------
00131 //
00132 void CLandmarksView::DoActivateL(
00133     const TVwsViewId& /*aPrevViewId*/,
00134     TUid /*aCustomMessageId*/,
00135     const TDesC8& /*aCustomMessage*/)
00136     {
00137     if (!iContainer)
00138         {
00139         iContainer = new (ELeave) CLandmarksContainer(
00140             *this, iEngine, iNaviDecorator);
00141         iContainer->SetMopParent(this);
00142             iContainer->ConstructL(ClientRect());
00143         }
00144 
00145     // Enable receiving of keyboard events.
00146     AppUi()->AddToStackL(*this, iContainer);
00147 
00148     // Make view visible.
00149     iContainer->MakeVisible(ETrue);
00150 
00151     // Notify that this view is active
00152     iEngine.NotifyViewActivated(Id(), ETrue);
00153     }
00154 
00155 // -----------------------------------------------------------------------------
00156 // CLandmarksView::DoDeactivate
00157 // 
00158 // (other items were commented in a header).
00159 // -----------------------------------------------------------------------------
00160 //
00161 void CLandmarksView::DoDeactivate()
00162     {
00163     // Hide view.
00164     iContainer->MakeVisible(EFalse);
00165 
00166     // Notify that this view is inactive
00167     iEngine.NotifyViewActivated(Id(), EFalse);
00168 
00169     // Disable receiving keyboard events.
00170     AppUi()->RemoveFromStack(iContainer);
00171     }
00172 
00173 // -----------------------------------------------------------------------------
00174 // CLandmarksView::DynInitMenuPaneL
00175 // 
00176 // (other items were commented in a header).
00177 // -----------------------------------------------------------------------------
00178 //
00179 void CLandmarksView::DynInitMenuPaneL(
00180     TInt aResourceId,
00181     CEikMenuPane* aMenuPane)
00182     {
00183     CAknView::DynInitMenuPaneL(aResourceId, aMenuPane);
00184     if (aResourceId == R_LMREFAPP_MENU)
00185         {
00186         // If no landmark is selected we need to hide some command options.
00187         TBool isListEmpty  = !iContainer->IsItemSelected();
00188         aMenuPane->SetItemDimmed(ELandmarksDelete, isListEmpty);
00189         aMenuPane->SetItemDimmed(ELandmarksOpen, isListEmpty);
00190         }
00191     }
00192 
00193 // -----------------------------------------------------------------------------
00194 // CLandmarksView::AddLandmarkL
00195 // 
00196 // (other items were commented in a header).
00197 // -----------------------------------------------------------------------------
00198 //
00199 void CLandmarksView::AddLandmarkL(TBool aUseCurrentLocation)
00200     {
00201     // Create new landmark
00202     CPosLandmark* newLandmark = CPosLandmark::NewLC();
00203 
00204     // Create edit dialog
00205     TBool isEdited(EFalse);
00206     CLandmarksEditDialog* editDialog = CLandmarksEditDialog::NewLC(
00207         *newLandmark, aUseCurrentLocation, isEdited, iEngine);
00208 
00209     // Remove tabs from this view
00210     iContainer->MakeNaviPaneVisibleL(EFalse);
00211 
00212     // Dialog must not leave without restoring tab group. Must be trapped.
00213     TRAPD(err, editDialog->ExecuteLD(R_LMREFAPP_EDIT_DIALOG));
00214 
00215     // Restore tabs to this view
00216     iContainer->MakeNaviPaneVisibleL(ETrue);
00217 
00218     User::LeaveIfError(err);
00219     CleanupStack::Pop(editDialog);
00220 
00221     if (isEdited)
00222         {
00223         iEngine.AddLandmarkL(*newLandmark);
00224         }
00225 
00226     CleanupStack::PopAndDestroy(newLandmark);
00227     }
00228 
00229 // End of File
00230 

© Nokia 2006

Back to top