S60 3rd Edition SDK for Symbian OS
Example Applications Guide

LandmarksCategoriesDialog.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : LandmarksCategoriesDialog.cpp
00004 *  Part of     : Landmark Reference Application
00005 *  Interface   : -
00006 *  Description : Implements the CLandmarksCategoriesDialog 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 <e32std.h>
00018 #include <akntitle.h> 
00019 #include <aknappui.h>
00020 #include <eikmenup.h>
00021 
00022 #include "LmRefApp.hrh"
00023 #include <LmRefApp.rsg>
00024 #include "LandmarksLmCategoriesModel.h"
00025 #include "LandmarksApplicationEngine.h"
00026 #include "LandmarksCategoriesDialog.h"
00027 
00028 // ============================ MEMBER FUNCTIONS ===============================
00029 
00030 // -----------------------------------------------------------------------------
00031 // CLandmarksCategoriesDialog::CLandmarksCategoriesDialog
00032 // C++ constructor can NOT contain any code, that
00033 // might leave.
00034 // -----------------------------------------------------------------------------
00035 //
00036 CLandmarksCategoriesDialog::CLandmarksCategoriesDialog(
00037     TInt& aSelectedItem,
00038     CArrayFixFlat<TInt>* aMarkedItems,
00039     CDesCArray* aListItems)
00040     : 
00041     CAknMarkableListDialog(aSelectedItem, aMarkedItems, aListItems, -1, -1, NULL)
00042         {
00043         }
00044 
00045 // Destructor
00046 CLandmarksCategoriesDialog::~CLandmarksCategoriesDialog()
00047         {
00048     // Restore title pane. Ownership of iOriginalTitle transferred.
00049     if (iOriginalTitle && iTitlePane)
00050         {
00051         iTitlePane->SetText(iOriginalTitle);
00052         }
00053         }
00054 
00055 // -----------------------------------------------------------------------------
00056 // CLandmarksCategoriesDialog::RunDialogL
00057 // Two-phased constructor.
00058 // -----------------------------------------------------------------------------
00059 //
00060 TInt CLandmarksCategoriesDialog::RunDialogL(
00061     CLandmarksLmCategoriesModel& aLmCategoriesModel)
00062     {
00063     // Create array of marked indeces
00064     CArrayFixFlat<TInt>* markedItems = aLmCategoriesModel.SelectedCategoriesL();
00065     CleanupStack::PushL(markedItems);
00066 
00067     // Create name array
00068     CDesCArray* listItems = aLmCategoriesModel.FormattedCategoryNamesL();
00069     CleanupStack::PushL(listItems);
00070 
00071     // Create the dialog
00072     TInt selectedItem = 0;
00073 
00074     CLandmarksCategoriesDialog* dialog = 
00075         new (ELeave) CLandmarksCategoriesDialog(
00076             selectedItem, markedItems, listItems);
00077     
00078         dialog->PrepareLC(R_LMREFAPP_EDIT_CATEGORIES_DIALOG);
00079 
00080         // pre-mark currently selected categories 
00081     CEikListBox* listBox = (CEikListBox*) dialog->Control(ESelectionListControl);
00082     for (TInt i = 0; i < markedItems->Count(); i++)
00083     {
00084         listBox->View()->SelectItemL((*markedItems)[i]);
00085     }
00086 
00087     TInt res = dialog->RunLD();
00088     if (res)
00089         {
00090         aLmCategoriesModel.SelectCategoriesL(*markedItems);
00091         }
00092         
00093     CleanupStack::PopAndDestroy(2, markedItems);
00094     return res;
00095     }
00096 
00097 // -----------------------------------------------------------------------------
00098 // CLandmarksCategoriesDialog::PostLayoutDynInitL
00099 // 
00100 // (other items were commented in a header).
00101 // -----------------------------------------------------------------------------
00102 //
00103 void CLandmarksCategoriesDialog::PostLayoutDynInitL()
00104     {
00105     CAknMarkableListDialog::PostLayoutDynInitL();
00106     
00107     // Save original title
00108     CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
00109     iTitlePane = (CAknTitlePane*) statusPane->ControlL(
00110         TUid::Uid(EEikStatusPaneUidTitle));
00111     iOriginalTitle = iTitlePane->Text()->AllocL();
00112 
00113     // Update title
00114     HBufC* title = iCoeEnv->AllocReadResourceAsDes16L(
00115         R_LMREFAPP_EDIT_CAT_TITLE);
00116     iTitlePane->SetText(title);
00117     }
00118 
00119 // -----------------------------------------------------------------------------
00120 // CLandmarksCategoriesDialog::OfferKeyEventL
00121 // 
00122 // (other items were commented in a header).
00123 // -----------------------------------------------------------------------------
00124 //
00125 TKeyResponse CLandmarksCategoriesDialog::OfferKeyEventL(
00126     const TKeyEvent& aKeyEvent, 
00127     TEventCode aType)
00128     {
00129     if (aKeyEvent.iCode == EKeyDevice3)
00130         {
00131         // An item should be marked/unmarked.
00132         CEikListBox* listBox = (CEikListBox*) Control(ESelectionListControl);
00133         listBox->View()->ToggleItemL(listBox->View()->CurrentItemIndex());
00134         listBox->DrawDeferred();
00135         return EKeyWasConsumed;
00136         }
00137 
00138     return CAknMarkableListDialog::OfferKeyEventL(aKeyEvent, aType);
00139     }
00140 
00141 // End of File
00142 

© Nokia 2006

Back to top