|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : LandmarksCategoriesView.cpp 00004 * Part of : Landmark Reference Application 00005 * Interface : - 00006 * Description : Implements the CLandmarksCategoriesView 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 <aknviewappui.h> 00018 #include <eikmenup.h> 00019 #include <aknquerydialog.h> 00020 00021 #include <EPos_CPosLandmarkCategory.h> 00022 00023 #include "LmRefApp.hrh" 00024 #include <LmRefApp.rsg> 00025 #include "LandmarksCategoriesView.h" 00026 #include "LandmarksCategoriesContainer.h" 00027 #include "LandmarksApplicationEngine.h" 00028 00029 // ============================ MEMBER FUNCTIONS =============================== 00030 00031 // ----------------------------------------------------------------------------- 00032 // CLandmarksCategoriesView::CLandmarksCategoriesView 00033 // C++ constructor can NOT contain any code, that 00034 // might leave. 00035 // ----------------------------------------------------------------------------- 00036 // 00037 CLandmarksCategoriesView::CLandmarksCategoriesView( 00038 CLandmarksApplicationEngine* aEngine) 00039 : iEngine(aEngine) 00040 { 00041 // No implementation required 00042 } 00043 00044 // ----------------------------------------------------------------------------- 00045 // CLandmarksCategoriesView::ConstructL 00046 // Symbian 2nd phase constructor can leave. 00047 // ----------------------------------------------------------------------------- 00048 // 00049 void CLandmarksCategoriesView::ConstructL() 00050 { 00051 BaseConstructL(R_LMREFAPP_CATEGORIES_VIEW); 00052 } 00053 00054 // ----------------------------------------------------------------------------- 00055 // CLandmarksCategoriesView::NewLC 00056 // Two-phased constructor. 00057 // ----------------------------------------------------------------------------- 00058 // 00059 CLandmarksCategoriesView* CLandmarksCategoriesView::NewLC( 00060 CLandmarksApplicationEngine* aEngine) 00061 { 00062 CLandmarksCategoriesView* self = 00063 new (ELeave) CLandmarksCategoriesView(aEngine); 00064 CleanupStack::PushL(self); 00065 self->ConstructL(); 00066 return self; 00067 } 00068 00069 // Destructor 00070 CLandmarksCategoriesView::~CLandmarksCategoriesView() 00071 { 00072 delete iContainer; 00073 00074 // This object is responsible for deleting the application engine instance. 00075 delete iEngine; 00076 } 00077 00078 // ----------------------------------------------------------------------------- 00079 // CLandmarksCategoriesView::Id 00080 // 00081 // (other items were commented in a header). 00082 // ----------------------------------------------------------------------------- 00083 // 00084 TUid CLandmarksCategoriesView::Id() const 00085 { 00086 return TUid::Uid(ELandmarksCategoriesViewId); 00087 } 00088 00089 // ----------------------------------------------------------------------------- 00090 // CLandmarksCategoriesView::HandleCommandL 00091 // 00092 // (other items were commented in a header). 00093 // ----------------------------------------------------------------------------- 00094 // 00095 void CLandmarksCategoriesView::HandleCommandL(TInt aCommand) 00096 { 00097 switch (aCommand) 00098 { 00099 case ELandmarksDelete: 00100 iContainer->DeleteCategoryL(); 00101 break; 00102 00103 case ELandmarksRename: 00104 RenameCategoryL(); 00105 break; 00106 00107 case ELandmarksAddCategory: 00108 AddCategoryL(); 00109 break; 00110 00111 default: 00112 AppUi()->HandleCommandL(aCommand); 00113 break; 00114 } 00115 } 00116 00117 // ----------------------------------------------------------------------------- 00118 // CLandmarksCategoriesView::DoActivateL 00119 // 00120 // (other items were commented in a header). 00121 // ----------------------------------------------------------------------------- 00122 // 00123 void CLandmarksCategoriesView::DoActivateL( 00124 const TVwsViewId& /*aPrevViewId*/, 00125 TUid /*aCustomMessageId*/, 00126 const TDesC8& /*aCustomMessage*/) 00127 { 00128 if (!iContainer) 00129 { 00130 iContainer = new (ELeave) CLandmarksCategoriesContainer( 00131 *this, *iEngine, *(MenuBar())); 00132 iContainer->SetMopParent(this); 00133 iContainer->ConstructL(ClientRect()); 00134 } 00135 00136 // Enable receiving of keyboard events. 00137 AppUi()->AddToStackL(*this, iContainer); 00138 00139 // Make view visible. 00140 iContainer->MakeVisible(ETrue); 00141 00142 // Notify that this view is active. 00143 TBool isActive = ETrue; 00144 iEngine->NotifyViewActivated(Id(), isActive); 00145 } 00146 00147 // ----------------------------------------------------------------------------- 00148 // CLandmarksCategoriesView::DoDeactivate 00149 // 00150 // (other items were commented in a header). 00151 // ----------------------------------------------------------------------------- 00152 // 00153 void CLandmarksCategoriesView::DoDeactivate() 00154 { 00155 // Hide view. 00156 iContainer->MakeVisible(EFalse); 00157 00158 // Notify that this view is inactive. 00159 TBool isActive = EFalse; 00160 iEngine->NotifyViewActivated(Id(), isActive); 00161 00162 // Disable receiving keyboard events. 00163 AppUi()->RemoveFromStack(iContainer); 00164 } 00165 00166 // ----------------------------------------------------------------------------- 00167 // CLandmarksCategoriesView::DynInitMenuPaneL 00168 // 00169 // (other items were commented in a header). 00170 // ----------------------------------------------------------------------------- 00171 // 00172 void CLandmarksCategoriesView::DynInitMenuPaneL( 00173 TInt aResourceId, 00174 CEikMenuPane* aMenuPane) 00175 { 00176 CAknView::DynInitMenuPaneL(aResourceId, aMenuPane); 00177 if (aResourceId == R_LMREFAPP_CATEGORIES_MENU) 00178 { 00179 // If none or a global cat. is selected we need to hide some commands. 00180 TBool dimmed = 00181 !iContainer->IsItemSelected() || iContainer->IsGlobalL(); 00182 aMenuPane->SetItemDimmed(ELandmarksDelete, dimmed); 00183 aMenuPane->SetItemDimmed(ELandmarksRename, dimmed); 00184 } 00185 } 00186 00187 // ----------------------------------------------------------------------------- 00188 // CLandmarksCategoriesView::AddCategoryL 00189 // 00190 // (other items were commented in a header). 00191 // ----------------------------------------------------------------------------- 00192 // 00193 void CLandmarksCategoriesView::AddCategoryL() 00194 { 00195 // Create and initialize dialog 00196 TBuf<KPosLmMaxCategoryNameLength> categoryName; 00197 CAknTextQueryDialog* queryDialog = CAknTextQueryDialog::NewL(categoryName); 00198 queryDialog->SetMaxLength(KPosLmMaxCategoryNameLength); 00199 CleanupStack::PushL(queryDialog); 00200 00201 // Create and set title 00202 HBufC* title = 00203 iCoeEnv->AllocReadResourceAsDes16LC(R_LMREFAPP_NEW_CATEGORY); 00204 queryDialog->SetPromptL(*title); 00205 CleanupStack::PopAndDestroy(title); 00206 00207 // Launch dialog 00208 TBool dialogDismissed = queryDialog->ExecuteLD(R_LMREFAPP_RENAME_QUERY); 00209 CleanupStack::Pop(queryDialog); 00210 if (dialogDismissed) 00211 { 00212 // Create and add a new category with user defined name. 00213 CPosLandmarkCategory* newCategory = CPosLandmarkCategory::NewLC(); 00214 newCategory->SetCategoryNameL(categoryName); 00215 iEngine->AddCategoryL(*newCategory); 00216 CleanupStack::PopAndDestroy(newCategory); 00217 } 00218 } 00219 00220 // ----------------------------------------------------------------------------- 00221 // CLandmarksCategoriesView::RenameCategoryL 00222 // 00223 // (other items were commented in a header). 00224 // ----------------------------------------------------------------------------- 00225 // 00226 void CLandmarksCategoriesView::RenameCategoryL() 00227 { 00228 // Fetch existing category name 00229 CPosLandmarkCategory* category = 00230 iEngine->CategoryLC(iContainer->CurrentCategoryId()); 00231 TPtrC categoryName; 00232 category->GetCategoryName(categoryName); 00233 TBuf<KPosLmMaxCategoryNameLength> newCategoryName; 00234 newCategoryName.Insert(0, categoryName); 00235 00236 // Create and initialize dialog 00237 CAknTextQueryDialog* queryDialog = 00238 CAknTextQueryDialog::NewL(newCategoryName); 00239 queryDialog->SetMaxLength(KPosLmMaxCategoryNameLength); 00240 CleanupStack::PushL(queryDialog); 00241 00242 // Create and set title 00243 HBufC* title = 00244 iCoeEnv->AllocReadResourceAsDes16LC(R_LMREFAPP_CATEGORY_NAME); 00245 queryDialog->SetPromptL(*title); 00246 CleanupStack::PopAndDestroy(title); 00247 00248 // Launch dialog 00249 TBool dialogAccepted = queryDialog->ExecuteLD(R_LMREFAPP_RENAME_QUERY); 00250 CleanupStack::Pop(queryDialog); 00251 if (dialogAccepted) 00252 { 00253 // Update category name 00254 category->SetCategoryNameL(newCategoryName); 00255 iEngine->UpdateCategoryL(*category); 00256 } 00257 00258 CleanupStack::PopAndDestroy(category); 00259 } 00260 00261 // End of File 00262
|
© Nokia 2006 |