|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================ 00003 * Name : CDynamicSettingListAppView from DynamicSettingListAppView.cpp 00004 * Part of : Dynamic Setting List 00005 * Created : 09/21/2005 by Forum Nokia 00006 * Version : 1.0 00007 * 00008 * Copyright (c) 2005 - 2007 Nokia Corporation. 00009 * This material, including documentation and any related 00010 * computer programs, is protected by copyright controlled by 00011 * Nokia Corporation. 00012 * ============================================================================ 00013 */ 00014 00015 // INCLUDE FILES 00016 #include <coemain.h> 00017 #include <DynamicSettingList.rsg> 00018 #include "DynamicSettingList.hrh" 00019 #include "DynamicSettingListAppView.h" 00020 #include "DynamicSettingListSlider.h" 00021 #include <eikfrlbd.h> 00022 00023 // CONSTANTS 00024 _LIT(KEmptyText, "None"); 00025 _LIT(KName, "Text"); 00026 _LIT(KName2, "Integer"); 00027 _LIT(KName3, "Password"); 00028 _LIT(KName4, "Volume"); 00029 _LIT(KName5, "Slider"); 00030 _LIT(KName6, "Date"); 00031 _LIT(KName7, "Time offset"); 00032 _LIT(KName8, "IP"); 00033 _LIT(KName9, "Enumerated text"); 00034 _LIT(KName10, "Binary"); 00035 _LIT(KEnumText1, "Enum text 1"); 00036 _LIT(KEnumText2, "Enum text 2"); 00037 const TUint32 KDefaultIp = 0; 00038 const TUint KDefaultIpPort = 80; 00039 00040 // ================= MEMBER FUNCTIONS ======================= 00041 00042 // Constructor 00043 CDynamicSettingListAppView::CDynamicSettingListAppView() 00044 : iVolume(KDefaultVolume), iIp(KDefaultIp, KDefaultIpPort) 00045 { 00046 iDate.HomeTime(); 00047 } 00048 00049 // Destructor 00050 CDynamicSettingListAppView::~CDynamicSettingListAppView() 00051 { 00052 delete iItemList; 00053 } 00054 00055 // ---------------------------------------------------- 00056 // CDynamicSettingListAppView::ConstructL() 00057 // Symbian OS default constructor can leave. 00058 // ---------------------------------------------------- 00059 // 00060 void CDynamicSettingListAppView::ConstructL(const TRect& aRect) 00061 { 00062 // Create a window for this application view 00063 CreateWindowL(); 00064 00065 iItemList = new (ELeave) CAknSettingItemList; 00066 iItemList->SetMopParent(this); 00067 iItemList->ConstructFromResourceL(R_ENTRY_SETTINGS_LIST); 00068 00069 LoadListL(); 00070 00071 iItemList->MakeVisible(ETrue); 00072 iItemList->SetRect(aRect); 00073 iItemList->ActivateL(); 00074 iItemList->ListBox()->UpdateScrollBarsL(); 00075 iItemList->DrawNow(); 00076 00077 // Set the windows size 00078 SetRect(aRect); 00079 00080 // Activate the window, which makes it ready to be drawn 00081 ActivateL(); 00082 } 00083 00084 // ---------------------------------------------------- 00085 // CDynamicSettingListAppView::Draw() 00086 // This function is used for window server-initiated 00087 // redrawing of controls, and for some 00088 // application-initiated drawing. 00089 // ---------------------------------------------------- 00090 // 00091 void CDynamicSettingListAppView::Draw(const TRect& /*aRect*/) const 00092 { 00093 // Get the standard graphics context 00094 CWindowGc& gc = SystemGc(); 00095 00096 // Gets the control's extent 00097 TRect rect = Rect(); 00098 00099 // Clears the screen 00100 gc.Clear(rect); 00101 } 00102 00103 // ---------------------------------------------------- 00104 // CDynamicSettingListAppView::CountComponentControls() 00105 // Gets the number of controls contained in a compound 00106 // control. 00107 // ---------------------------------------------------- 00108 // 00109 TInt CDynamicSettingListAppView::CountComponentControls() const 00110 { 00111 TInt count = 0; 00112 if (iItemList) 00113 count++; 00114 return count; 00115 } 00116 00117 // ---------------------------------------------------- 00118 // CDynamicSettingListAppView::ComponentControl() 00119 // Gets the specified component of a compound control. 00120 // ---------------------------------------------------- 00121 // 00122 CCoeControl* CDynamicSettingListAppView::ComponentControl(TInt /*aIndex*/) const 00123 { 00124 return iItemList; 00125 } 00126 00127 // ---------------------------------------------------- 00128 // CDynamicSettingListAppView::OfferKeyEventL() 00129 // When a key event occurs, the control framework calls 00130 // this function for each control on the control stack, 00131 // until one of them can process the key event 00132 // (and returns EKeyWasConsumed). 00133 // ---------------------------------------------------- 00134 // 00135 TKeyResponse CDynamicSettingListAppView::OfferKeyEventL( const TKeyEvent& aKeyEvent, 00136 TEventCode aType ) 00137 { 00138 if(aType != EEventKey) 00139 { 00140 return EKeyWasNotConsumed; 00141 } 00142 else if(iItemList) 00143 { 00144 return iItemList->OfferKeyEventL( aKeyEvent, aType ); 00145 } 00146 else 00147 { 00148 return EKeyWasNotConsumed; 00149 } 00150 00151 } 00152 00153 // ---------------------------------------------------- 00154 // CDynamicSettingListAppView::LoadListL() 00155 // Loads the setting item list dynamically. 00156 // ---------------------------------------------------- 00157 // 00158 void CDynamicSettingListAppView::LoadListL() 00159 { 00160 TBool isNumberedStyle = iItemList->IsNumberedStyle(); 00161 CArrayPtr<CGulIcon>* icons = iItemList->ListBox()->ItemDrawer()->FormattedCellData()->IconArray(); 00162 00163 00164 /* Text setting item */ 00165 CAknTextSettingItem* item = new (ELeave) CAknTextSettingItem(1, iText); 00166 CleanupStack::PushL(item); 00167 item->SetEmptyItemTextL( KEmptyText ); 00168 // The same resource id can be used for multiple text setting pages. 00169 item->ConstructL(isNumberedStyle, 1, KName, icons, R_TEXT_SETTING_PAGE, -1); 00170 iItemList->SettingItemArray()->AppendL(item); 00171 CleanupStack::Pop(item); 00172 00173 00174 /* Integer setting item */ 00175 CAknIntegerEdwinSettingItem* item2 = new (ELeave) CAknIntegerEdwinSettingItem(2, iNumber); 00176 CleanupStack::PushL(item2); 00177 // The same resource id can be used for multiple integer setting pages. 00178 item2->ConstructL(isNumberedStyle, 2, KName2, icons, R_INTEGER_SETTING_PAGE, -1); 00179 iItemList->SettingItemArray()->AppendL(item2); 00180 CleanupStack::Pop(item2); 00181 00182 00183 /* Password setting item */ 00184 CAknPasswordSettingItem* item3 = new (ELeave) CAknPasswordSettingItem( 3, 00185 CAknPasswordSettingItem::EAlpha, 00186 iPassword); 00187 CleanupStack::PushL(item3); 00188 item3->SetEmptyItemTextL( KEmptyText ); 00189 // The same resource id can be used for multiple password setting pages. 00190 item3->ConstructL(isNumberedStyle, 3, KName3, icons, R_PASSWORD_SETTING_PAGE, -1); 00191 iItemList->SettingItemArray()->AppendL(item3); 00192 CleanupStack::Pop(item3); 00193 00194 00195 /* Volume setting item */ 00196 CAknVolumeSettingItem* item4 = new (ELeave) CAknVolumeSettingItem(4, iVolume); 00197 CleanupStack::PushL(item4); 00198 // The same resource id can be used for multiple volume setting pages. 00199 item4->ConstructL(isNumberedStyle, 4, KName4, icons, R_VOLUME_SETTING_PAGE, -1); 00200 iItemList->SettingItemArray()->AppendL(item4); 00201 CleanupStack::Pop(item4); 00202 00203 00204 /* Slider setting item. Read comments in CDynamicSettingListSlider, why 00205 * a derived class is used instead of CAknSliderSettingItem 00206 */ 00207 CDynamicSettingListSlider* item5 = new (ELeave) CDynamicSettingListSlider(5, iSlider); 00208 CleanupStack::PushL(item5); 00209 // The same resource id can be used for multiple slider setting pages. 00210 item5->ConstructL(isNumberedStyle, 5, KName5, icons, R_SLIDER_SETTING_PAGE, -1); 00211 iItemList->SettingItemArray()->AppendL(item5); 00212 CleanupStack::Pop(item5); 00213 00214 00215 /* Date setting item */ 00216 CAknTimeOrDateSettingItem* item6 = new (ELeave) CAknTimeOrDateSettingItem( 6, 00217 CAknTimeOrDateSettingItem::EDate, 00218 iDate); 00219 CleanupStack::PushL(item6); 00220 // The same resource id can be used for multiple date setting pages. 00221 item6->ConstructL(isNumberedStyle, 6, KName6, icons, R_DATE_SETTING_PAGE, -1); 00222 iItemList->SettingItemArray()->AppendL(item6); 00223 CleanupStack::Pop(item6); 00224 00225 00226 /* Time offset setting item */ 00227 CAknTimeOffsetSettingItem* item7 = new (ELeave) CAknTimeOffsetSettingItem(7, iTime); 00228 CleanupStack::PushL(item7); 00229 // The same resource id can be used for multiple time offset setting pages. 00230 item7->ConstructL(isNumberedStyle, 7, KName7, icons, R_TIMEOFFSET_SETTING_PAGE, -1); 00231 iItemList->SettingItemArray()->AppendL(item7); 00232 CleanupStack::Pop(item7); 00233 00234 00235 /* Ip field setting item */ 00236 CAknIpFieldSettingItem* item8 = new (ELeave) CAknIpFieldSettingItem(8, iIp); 00237 CleanupStack::PushL(item8); 00238 // The same resource id can be used for multiple ip field setting pages. 00239 item8->ConstructL(isNumberedStyle, 8, KName8, icons, R_IPFIELD_SETTING_PAGE, -1); 00240 iItemList->SettingItemArray()->AppendL(item8); 00241 CleanupStack::Pop(item8); 00242 00243 00244 /* Enumerated text setting item */ 00245 CAknEnumeratedTextPopupSettingItem* item9 = new (ELeave) CAknEnumeratedTextPopupSettingItem(9, iEnumText); 00246 CleanupStack::PushL(item9); 00247 // The same resource id can be used for multiple enumerated text setting pages. 00248 item9->ConstructL(isNumberedStyle, 9, KName9, icons, R_ENUMERATEDTEXT_SETTING_PAGE, -1, 0, R_POPUP_SETTING_TEXTS); 00249 00250 // Load texts dynamically. 00251 CArrayPtr<CAknEnumeratedText>* texts = item9->EnumeratedTextArray(); 00252 texts->ResetAndDestroy(); 00253 CAknEnumeratedText* enumText; 00254 // Text 1 00255 HBufC* text = KEnumText1().AllocLC(); 00256 enumText = new (ELeave) CAknEnumeratedText(0, text); 00257 CleanupStack::Pop(text); 00258 CleanupStack::PushL(enumText); 00259 texts->AppendL(enumText); 00260 CleanupStack::Pop(enumText); 00261 // Text 2 00262 text = KEnumText2().AllocLC(); 00263 enumText = new (ELeave) CAknEnumeratedText(1, text); 00264 CleanupStack::Pop(text); 00265 CleanupStack::PushL(enumText); 00266 texts->AppendL(enumText); 00267 CleanupStack::Pop(enumText); 00268 00269 iItemList->SettingItemArray()->AppendL(item9); 00270 CleanupStack::Pop(item9); 00271 00272 00273 /* Binary popup setting item */ 00274 CAknBinaryPopupSettingItem* item10 = new (ELeave) CAknBinaryPopupSettingItem(10, iBinary); 00275 CleanupStack::PushL(item10); 00276 // The same resource id can be used for multiple binary setting pages. 00277 item10->ConstructL(isNumberedStyle, 10, KName10, icons, R_BINARY_SETTING_PAGE, -1, 0, R_BINARY_TEXTS); 00278 00279 // Load texts dynamically. 00280 texts = item10->EnumeratedTextArray(); 00281 texts->ResetAndDestroy(); 00282 // Text 1 00283 text = KEnumText1().AllocLC(); 00284 enumText = new (ELeave) CAknEnumeratedText(0, text); 00285 CleanupStack::Pop(text); 00286 CleanupStack::PushL(enumText); 00287 texts->AppendL(enumText); 00288 CleanupStack::Pop(enumText); 00289 // Text 2 00290 text = KEnumText2().AllocLC(); 00291 enumText = new (ELeave) CAknEnumeratedText(1, text); 00292 CleanupStack::Pop(text); 00293 CleanupStack::PushL(enumText); 00294 texts->AppendL(enumText); 00295 CleanupStack::Pop(enumText); 00296 00297 // Sets the correct text visible 00298 item10->LoadL(); 00299 00300 iItemList->SettingItemArray()->AppendL(item10); 00301 CleanupStack::Pop(item10); 00302 00303 // Required when there is only one setting item. 00304 iItemList->SettingItemArray()->RecalculateVisibleIndicesL(); 00305 00306 iItemList->HandleChangeInItemArrayOrVisibilityL(); 00307 } 00308 00309 // ---------------------------------------------------- 00310 // CDynamicSettingListAppView::StoreSettingsL() 00311 // Stores the settings of the setting list. 00312 // ---------------------------------------------------- 00313 // 00314 void CDynamicSettingListAppView::StoreSettingsL() 00315 { 00316 iItemList->StoreSettingsL(); 00317 } 00318 00319 // End of file
|
© Nokia 2009 |