|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : ListboxDocument.h 00004 * Part of : Listbox example 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2007 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 #ifndef __VIEWTEMPLATE_H__ 00017 #define __VIEWTEMPLATE_H__ 00018 00019 #include <aknview.h> 00020 #include <aknutils.h> 00021 #include "Listbox.hrh" 00022 00023 /** 00024 * CViewTemplate is a template class for creating a view for Avkon 00025 * View-switching architecture. 00026 * CViewTemplate is used as view classes for CListboxNumberContainer 00027 * and CListboxGraphicContainer containers. 00028 * 00029 * CViewTemplate sets context specific options menu for view's MSK by giving 00030 * the menubar resource id to CViewTemplate::NewL(). Setting is done with 00031 * CEikMenuBar::SetContextMenuTitleResourceId() function call, which is 00032 * required for the MSK functionality. If menu is not given, MSK does not have 00033 * menu. 00034 * 00035 * This template class requires that container class implements following 00036 * functions : 00037 * - ConstructL() for container construction and for passing rectangle 00038 * for drawing. 00039 * - AddItemL() for adding new item to listbox. 00040 * - RemoveItemL() for removing item from listbox 00041 * - ItemCount() for getting the listbox item count 00042 * 00043 * @param T container class used by this view 00044 */ 00045 00046 template <class T> 00047 class CViewTemplate : public CAknView 00048 { 00049 public: // New methods 00050 00051 /** 00052 * Two-phased constructor. 00053 * @param aViewResource Resource id of the view 00054 * @param aMenubarResource Resource id of the view menubar 00055 * @param aViewId Unique id of the view 00056 * @return a pointer to the created instance of CViewTemplate. 00057 */ 00058 static CViewTemplate* NewL( TInt aViewResource, 00059 TInt aMenubarResource, TUid aViewId ); 00060 00061 /** 00062 * Two-phased constructor. 00063 * @param aViewResource Resource id of the view 00064 * @param aMenubarResource Resource id of the view menubar 00065 * @param aViewId Unique id of the view 00066 * @return A pointer to the created instance of CViewTemplate. 00067 */ 00068 static CViewTemplate* NewLC( TInt aViewResource, 00069 TInt aMenubarResource, TUid aViewId ); 00070 00071 /** 00072 * Virtual Destructor. 00073 */ 00074 virtual ~CViewTemplate(); 00075 00076 public: // Functions from base classes from CAknView 00077 00078 /** 00079 * @return Id Uid value 00080 */ 00081 TUid Id() const; 00082 00083 /** 00084 * HandleCommandL 00085 * From CAknView, takes care of command handling. 00086 * @param aCommand Command to be handled 00087 */ 00088 void HandleCommandL( TInt aCommand ); 00089 00090 /** 00091 * From CAknExView, activate an AknView. 00092 * @param aPrevViewId The id of the previous view 00093 * @param aCustomMessageId message identifier 00094 * @param aCustomMessage custom message provided when the view is changed 00095 */ 00096 void DoActivateL( const TVwsViewId& aPrevViewId, 00097 TUid aCustomMessageId, 00098 const TDesC8& aCustomMessage ); 00099 00100 /** 00101 * From AknView, deactivate an AknView 00102 * Remove the container class instance from the App UI's stack and 00103 * deletes the instance 00104 */ 00105 void DoDeactivate(); 00106 00107 /** 00108 * From MEikMenuObserver, DynInitMenuPaneL. 00109 * This function is called by the EIKON framework just before it 00110 * displays a menu pane. 00111 * @param aResourceId The ID of command which defined in resource file. 00112 * @param aMenuPane Pointer to menu-pane object. 00113 */ 00114 void DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane ); 00115 00116 public: 00117 00118 /** 00119 * Called by HandleResourceChangeL() from CListboxAppUi when layout 00120 * is changed. 00121 * @param aType Type of resources that have changed 00122 */ 00123 void HandleSizeChange( TInt aType ); 00124 00125 /** 00126 * With this function is possible to dimm selected menuitem from options 00127 * menu or from its submenus. 00128 * @param aMenuItemId Menu item id 00129 */ 00130 void MenuItemToDimm( TInt aMenuItemId ); 00131 00132 private: 00133 00134 /** 00135 * 2nd phase constructor. 00136 */ 00137 void ConstructL( TInt aViewResource ); 00138 00139 /** 00140 * C++ default constructor. 00141 * @param aViewId Unique id of the view 00142 * @param aMenubarResource Resource id of the view menubar 00143 */ 00144 CViewTemplate( TUid aViewId, TInt aMenubarResource ); 00145 00146 00147 private: // Data 00148 00149 /** 00150 * Container for this view. 00151 * 00152 * Owned. 00153 */ 00154 T* iContainer; 00155 00156 /** 00157 * View Identifier 00158 */ 00159 TUid iIdentifier; 00160 00161 /** 00162 * MSK menubar resource ID 00163 */ 00164 TInt iMenubarResource; 00165 00166 /** 00167 * Identifier for dimmed menu item 00168 */ 00169 TInt iItemToDimm; 00170 }; 00171 00172 00173 // ----------------------------------------------------------------------------- 00174 // C++ default constructor. 00175 // ----------------------------------------------------------------------------- 00176 // 00177 template <class T> CViewTemplate<T>::CViewTemplate( TUid aViewId, 00178 TInt aMenubarResource ) : 00179 iIdentifier( aViewId ), 00180 iMenubarResource( aMenubarResource ), 00181 iItemToDimm( 0 ) 00182 { 00183 } 00184 00185 // ----------------------------------------------------------------------------- 00186 // Destructor 00187 // ----------------------------------------------------------------------------- 00188 // 00189 template <class T> CViewTemplate<T>::~CViewTemplate() 00190 { 00191 if( iContainer ) 00192 delete iContainer; 00193 } 00194 00195 // ----------------------------------------------------------------------------- 00196 // CViewTemplate::NewL() 00197 // Two-phased constructor. 00198 // ----------------------------------------------------------------------------- 00199 // 00200 template <class T> CViewTemplate<T>* CViewTemplate<T>::NewL( 00201 TInt aViewResource, TInt aMenubarResource, TUid aViewId ) 00202 { 00203 CViewTemplate<T>* self = CViewTemplate<T>::NewLC( aViewResource, 00204 aMenubarResource, aViewId ); 00205 CleanupStack::Pop( self ); 00206 return self; 00207 } 00208 00209 // ----------------------------------------------------------------------------- 00210 // CViewTemplate::NewLC() 00211 // Two-phased constructor. 00212 // ----------------------------------------------------------------------------- 00213 // 00214 template <class T> CViewTemplate<T>* CViewTemplate<T>::NewLC( 00215 TInt aViewResource, TInt aMenubarResource, TUid aViewId ) 00216 { 00217 CViewTemplate<T>* self = new ( ELeave ) CViewTemplate<T>( aViewId, 00218 aMenubarResource ); 00219 CleanupStack::PushL( self ); 00220 self->ConstructL( aViewResource ); 00221 return self; 00222 } 00223 00224 // ----------------------------------------------------------------------------- 00225 // CViewTemplate::ConstructL() 00226 // Symbian 2nd phase constructor can leave. 00227 // ----------------------------------------------------------------------------- 00228 // 00229 template <class T> void CViewTemplate<T>::ConstructL( TInt aViewResource ) 00230 { 00231 BaseConstructL( aViewResource ); 00232 } 00233 00234 // ----------------------------------------------------------------------------- 00235 // CViewTemplate::Id() 00236 // Returns View's ID. 00237 // ----------------------------------------------------------------------------- 00238 // 00239 template <class T> TUid CViewTemplate<T>::Id() const 00240 { 00241 return iIdentifier; 00242 } 00243 00244 // ----------------------------------------------------------------------------- 00245 // CViewTemplate::DoActivateL() 00246 // Activate view 00247 // ----------------------------------------------------------------------------- 00248 // 00249 template <class T> void CViewTemplate<T>::DoActivateL( 00250 const TVwsViewId& /*aPrevViewId*/, 00251 TUid /*aCustomMessageId*/, 00252 const TDesC8& /*aCustomMessage*/) 00253 { 00254 iContainer = new ( ELeave ) T(); 00255 iContainer->SetMopParent( this ); 00256 iContainer->ConstructL( ClientRect() ); 00257 00258 00259 if( iMenubarResource > 0 ) 00260 { 00261 CEikMenuBar* menuBar = MenuBar(); 00262 menuBar->SetContextMenuTitleResourceId( iMenubarResource ); 00263 } 00264 00265 AppUi()->AddToStackL( *this, iContainer ); 00266 00267 iContainer->MakeVisible( ETrue ); 00268 } 00269 00270 // ----------------------------------------------------------------------------- 00271 // CViewTemplate::DoDeactivate() 00272 // DeActivate view 00273 // ----------------------------------------------------------------------------- 00274 // 00275 template <class T> void CViewTemplate<T>::DoDeactivate() 00276 { 00277 if ( iContainer ) 00278 { 00279 // Remove container form controllStack 00280 AppUi()->RemoveFromStack( iContainer ); 00281 delete iContainer; 00282 iContainer = NULL; 00283 } 00284 } 00285 00286 // ----------------------------------------------------------------------------- 00287 // CViewTemplate::HandleCommandL() 00288 // Takes care of Command handling. 00289 // ----------------------------------------------------------------------------- 00290 // 00291 template <class T> void CViewTemplate<T>::HandleCommandL( TInt aCommand ) 00292 { 00293 switch( aCommand ) 00294 { 00295 case EListboxCommandAddItem: 00296 iContainer->AddItemL(); 00297 break; 00298 case EListboxCommandRemoveItem: 00299 iContainer->RemoveItemL(); 00300 break; 00301 default: 00302 AppUi()->HandleCommandL( aCommand ); 00303 } 00304 } 00305 00306 // ----------------------------------------------------------------------------- 00307 // CViewTemplate::HandleSizeChange() 00308 // Called by HandleResourceChangeL() from CListboxAppUi when layout is 00309 // changed. 00310 // ----------------------------------------------------------------------------- 00311 // 00312 template <class T> void CViewTemplate<T>::HandleSizeChange( TInt aType ) 00313 { 00314 if( iContainer ) 00315 { 00316 iContainer->HandleResourceChange( aType ); 00317 00318 if( aType==KEikDynamicLayoutVariantSwitch ) 00319 { 00320 TRect rect; 00321 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect); 00322 iContainer->SetRect(rect); 00323 } 00324 } 00325 } 00326 00327 // --------------------------------------------------------------------------- 00328 // CViewTemplate::MenuItemToDimm() 00329 // With this function is possible to dimm selected menuitem from options 00330 // menu or from its submenus. 00331 // --------------------------------------------------------------------------- 00332 // 00333 template <class T> void CViewTemplate<T>::MenuItemToDimm( TInt aMenuItemId ) 00334 { 00335 iItemToDimm = aMenuItemId; 00336 } 00337 00338 // --------------------------------------------------------------------------- 00339 // CViewTemplate::DynInitMenuPaneL() 00340 // This function is called by the EIKON framework just before it displays a 00341 // menu pane. 00342 // --------------------------------------------------------------------------- 00343 // 00344 template <class T> void CViewTemplate<T>::DynInitMenuPaneL( TInt /*aResourceId*/, 00345 CEikMenuPane* aMenuPane ) 00346 { 00347 // Hide user selected menu item 00348 TInt index; 00349 if( aMenuPane->MenuItemExists (iItemToDimm, index) ) 00350 { 00351 aMenuPane->SetItemDimmed( iItemToDimm, ETrue ); 00352 } 00353 00354 // From options menu and MSK menu we remove always "Remove item" item 00355 // if there is no items to remove 00356 if( aMenuPane->MenuItemExists (EListboxCommandRemoveItem, index) ) 00357 { 00358 // Hide "Remove item" menu item if listbox does not contain any items 00359 if( iContainer->ItemCount() < 1 ) 00360 aMenuPane->SetItemDimmed( EListboxCommandRemoveItem, ETrue ); 00361 } 00362 } 00363 00364 00365 #endif // __VIEWTEMPLATE_H__
|
© Nokia 2009 |