|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Container for the main view of General Settings |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <bldvariant.hrh> |
|
21 |
|
22 #include "GSUi.h" |
|
23 #include "gsmainview.h" |
|
24 #include "GSMainContainer.h" |
|
25 #include "gsplugininterface.h" |
|
26 #include "GsLogger.h" |
|
27 #include <GSApp.rsg> // Resources for mainview |
|
28 |
|
29 #include <aknlists.h> |
|
30 #include <calslbs.h> |
|
31 #include <eikclbd.h> |
|
32 #include <AknIconArray.h> // For loading icons |
|
33 #include <AknsUtils.h> // For loading icons |
|
34 #include <aknViewAppUi.h> |
|
35 #include <akntitle.h> |
|
36 #include <barsread.h> |
|
37 #include <gulicon.h> // For CGulIcon |
|
38 #include <csxhelp/cp.hlp.hrh> |
|
39 #include <gsfwviewuids.h> // for KUidGS |
|
40 |
|
41 //CONSTANTS |
|
42 |
|
43 // ========================= MEMBER FUNCTIONS ================================ |
|
44 |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // CGSMainContainer::ConstructL(const TRect& aRect) |
|
48 // Symbian OS two phased constructor |
|
49 // |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 void CGSMainContainer::ConstructL( |
|
53 const TRect& aRect, |
|
54 CAknViewAppUi* aAppUi, |
|
55 CArrayPtrFlat<CGSPluginInterface>* aPluginArray ) |
|
56 { |
|
57 iAppUi = aAppUi; |
|
58 iPluginArray = aPluginArray; |
|
59 |
|
60 // Initialize the array containing pointers to plugins that are actually |
|
61 // displayed in lbx. |
|
62 iVisiblePlugins = new CArrayPtrFlat<CGSPluginInterface>( 10 ); |
|
63 |
|
64 CEikStatusPane* sp = iAppUi->StatusPane(); |
|
65 CAknTitlePane* title = static_cast<CAknTitlePane*> |
|
66 ( sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) ); |
|
67 |
|
68 // Set view title from resource: |
|
69 TResourceReader rReader; |
|
70 iCoeEnv->CreateResourceReaderLC( rReader, R_GS_MAIN_VIEW_TITLE ); |
|
71 title->SetFromResourceL( rReader ); |
|
72 CleanupStack::PopAndDestroy(); //rReader |
|
73 |
|
74 CreateWindowL(); // Makes this control a window-owning control |
|
75 |
|
76 // Create listbox: |
|
77 iListBox = new( ELeave ) CAknSingleLargeStyleListBox; |
|
78 iListBox->ConstructL( this ); |
|
79 iListBox->SetContainerWindowL( *this ); |
|
80 iListBox->SetListBoxObserver( this ); |
|
81 iListBox->CreateScrollBarFrameL(ETrue); |
|
82 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
83 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); |
|
84 |
|
85 // Obtain reference to listbox's item text array: |
|
86 iItemTextArray |
|
87 = STATIC_CAST( CDesCArray*, iListBox->Model()->ItemTextArray() ); |
|
88 |
|
89 SetRect( aRect ); |
|
90 ActivateL(); |
|
91 __GSLOGSTRING( "[CGSMainContainer] ConstructL()" ); |
|
92 } |
|
93 |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // CGSMainContainer::~CGSMainContainer() |
|
97 // Destructor |
|
98 // |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 CGSMainContainer::~CGSMainContainer() |
|
102 { |
|
103 if ( iVisiblePlugins ) |
|
104 { |
|
105 iVisiblePlugins->Reset(); |
|
106 } |
|
107 delete iVisiblePlugins; |
|
108 |
|
109 if ( iItemTextArray ) |
|
110 { |
|
111 iItemTextArray->Reset(); |
|
112 } |
|
113 |
|
114 if ( iListBox ) |
|
115 { |
|
116 delete iListBox; |
|
117 } |
|
118 __GSLOGSTRING( "[CGSMainContainer] ~CGSMainContainer" ); |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // CGSMainContainer::UpdateListbox |
|
123 // |
|
124 // Updates listbox from iPluginArray. |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 void CGSMainContainer::UpdateListBoxL() |
|
128 { |
|
129 __GSLOGSTRING( "[CGSMainContainer::UpdateListBoxL]" ); |
|
130 |
|
131 // Empty item array because it will be reoccupied. |
|
132 iItemTextArray->Reset(); |
|
133 |
|
134 // Empty the array because it will be updated. |
|
135 iVisiblePlugins->Reset(); |
|
136 |
|
137 // Array for icons in the listbox. Owns the icons. |
|
138 CAknIconArray* icons = new (ELeave) CAknIconArray( 10 ); |
|
139 CleanupStack::PushL( icons ); |
|
140 |
|
141 // Index of the plugin inserted into lbx item array. |
|
142 TInt pluginIndex = 0; |
|
143 |
|
144 // 1) Add each plugin's data to listbox if the plugin is visible. |
|
145 for( TInt i = 0; i < iPluginArray->Count(); i++ ) |
|
146 { |
|
147 CGSPluginInterface* plugin = iPluginArray->operator[]( i ); |
|
148 if( plugin->Visible() ) |
|
149 { |
|
150 AddPluginDataToLbxL( plugin, pluginIndex, iItemTextArray, icons ); |
|
151 pluginIndex++; |
|
152 } |
|
153 } |
|
154 |
|
155 // Destroy the old icons because SetIconArray() does not destroy them. |
|
156 CArrayPtr<CGulIcon>* oldIcons |
|
157 = iListBox->ItemDrawer()->ColumnData()->IconArray(); |
|
158 if( oldIcons ) |
|
159 { |
|
160 oldIcons->ResetAndDestroy(); |
|
161 delete oldIcons; |
|
162 } |
|
163 |
|
164 // Transfer ownership of icon array to the lbx. |
|
165 // SetIconArray() does not delete the old icon array |
|
166 iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons ); |
|
167 CleanupStack::Pop( icons ); |
|
168 |
|
169 // Draws listbox again |
|
170 iListBox->HandleItemAdditionL(); |
|
171 } |
|
172 |
|
173 |
|
174 //Disabling warning caused by err variable used inside macros |
|
175 #pragma diag_suppress 550 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CGSMainContainer::AddPluginDataToLbxL() |
|
178 // |
|
179 // |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 void CGSMainContainer::AddPluginDataToLbxL( CGSPluginInterface* aPlugin, |
|
183 TInt aIndex, |
|
184 CDesCArray* aItemTextArray, |
|
185 CAknIconArray* aIconArray ) |
|
186 { |
|
187 // Add the plugin to visible plugins array: |
|
188 iVisiblePlugins->AppendL( aPlugin ); |
|
189 |
|
190 // 1.1) Read item descriptor from plugin: |
|
191 TBuf<256> buf; |
|
192 _LIT( KTab, "\t" ); |
|
193 |
|
194 TRAPD |
|
195 ( |
|
196 captionErr, |
|
197 aPlugin->GetCaptionL( buf ); |
|
198 ) |
|
199 |
|
200 // If plugin caption fails, set caption to error string. |
|
201 if( captionErr != KErrNone ) |
|
202 { |
|
203 _LIT( KGSParentPluginCaptionErrorTxt, "Error" ); |
|
204 buf.Append( KGSParentPluginCaptionErrorTxt ); |
|
205 } |
|
206 else |
|
207 { |
|
208 __GSLOGSTRING2( "[CGSMainContainer] 0x%X::GetCaptionL Error: %d", |
|
209 aPlugin->Id().iUid, captionErr ); |
|
210 } |
|
211 |
|
212 /** |
|
213 * 1.2) Create formatted item string. |
|
214 * list_single_large_pane: |
|
215 * list item string format: "1\tTextLabel\t0\t0" |
|
216 * where 0 is an index to icon array |
|
217 */ |
|
218 TBuf<256> item; |
|
219 item.AppendNum( aIndex ); |
|
220 item.Append( KTab ); |
|
221 item.Append( buf ); |
|
222 |
|
223 aItemTextArray->AppendL( item ); |
|
224 |
|
225 // 1.3) Add icons if listbox uses them: |
|
226 CGulIcon* icon; |
|
227 TRAPD |
|
228 ( |
|
229 iconErr, |
|
230 icon = aPlugin->CreateIconL( KGSIconTypeLbxItem ); |
|
231 ) |
|
232 |
|
233 __GSLOGSTRING2( |
|
234 "[CGSMainContainer] CreateIconL result for 0x%X: %d", |
|
235 aPlugin->Id().iUid, iconErr ); |
|
236 TSize size = icon->Bitmap()->SizeInPixels(); |
|
237 CleanupStack::PushL( icon ); |
|
238 aIconArray->AppendL( icon ); |
|
239 CleanupStack::Pop( icon ); |
|
240 |
|
241 } |
|
242 //Enabling warnings |
|
243 #pragma diag_default 550 |
|
244 |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // CGSMainContainer::GetHelpContext(TCoeHelpContext& aContext) const |
|
248 // Gets Help |
|
249 // |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 void CGSMainContainer::GetHelpContext( TCoeHelpContext& aContext ) const |
|
253 { |
|
254 aContext.iMajor = KUidGS; |
|
255 aContext.iContext = KCP_HLP_MAIN_VIEW; |
|
256 } |
|
257 |
|
258 |
|
259 // --------------------------------------------------------------------------- |
|
260 // CGSMainContainer::SizeChanged |
|
261 // called by framwork when the view size is changed |
|
262 // |
|
263 // --------------------------------------------------------------------------- |
|
264 // |
|
265 void CGSMainContainer::SizeChanged() |
|
266 { |
|
267 if ( iListBox ) |
|
268 { |
|
269 iListBox->SetRect( Rect() ); |
|
270 } |
|
271 } |
|
272 |
|
273 |
|
274 // --------------------------------------------------------------------------- |
|
275 // CGSMainContainer::CountComponentControls |
|
276 // |
|
277 // |
|
278 // --------------------------------------------------------------------------- |
|
279 // |
|
280 TInt CGSMainContainer::CountComponentControls() const |
|
281 { |
|
282 return 1; |
|
283 } |
|
284 |
|
285 |
|
286 // --------------------------------------------------------------------------- |
|
287 // CGSMainContainer::ComponentControl |
|
288 // |
|
289 // |
|
290 // --------------------------------------------------------------------------- |
|
291 // |
|
292 CCoeControl* CGSMainContainer::ComponentControl(TInt /*aIndex*/) const |
|
293 { |
|
294 return iListBox; |
|
295 } |
|
296 |
|
297 |
|
298 // --------------------------------------------------------------------------- |
|
299 // CGSMainContainer::TKeyResponse OfferKeyEventL |
|
300 // Called when a key is pressed. |
|
301 // |
|
302 // --------------------------------------------------------------------------- |
|
303 // |
|
304 TKeyResponse CGSMainContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, |
|
305 TEventCode aType) |
|
306 { |
|
307 switch ( aKeyEvent.iCode ) |
|
308 { |
|
309 case EKeyLeftArrow: |
|
310 case EKeyRightArrow: |
|
311 // Listbox takes all event even if it doesn't use them |
|
312 return EKeyWasNotConsumed; |
|
313 default: |
|
314 break; |
|
315 } |
|
316 // now it's iListBox's job to process the key event |
|
317 return iListBox->OfferKeyEventL(aKeyEvent, aType); |
|
318 } |
|
319 |
|
320 |
|
321 // --------------------------------------------------------------------------- |
|
322 // CGSMainContainer::HandleListBoxEventL |
|
323 // |
|
324 // |
|
325 // --------------------------------------------------------------------------- |
|
326 void CGSMainContainer::HandleListBoxEventL( |
|
327 CEikListBox* aListBox, |
|
328 TListBoxEvent aEventType ) |
|
329 { |
|
330 __GSLOGSTRING1( |
|
331 "[CGSMainContainer] HandleListBoxEventL aEventType:%d", |
|
332 aEventType); |
|
333 switch ( aEventType ) |
|
334 { |
|
335 case EEventEnterKeyPressed: |
|
336 case EEventItemSingleClicked: |
|
337 { |
|
338 if (aListBox->CurrentItemIndex() < 0) |
|
339 { |
|
340 // Negative listbox value -> no item selected? |
|
341 break; |
|
342 } |
|
343 |
|
344 CGSPluginInterface* selectedPlugin = iVisiblePlugins->operator[]( |
|
345 aListBox->CurrentItemIndex()); |
|
346 |
|
347 // Different command is used depending on the plugin type. |
|
348 switch (selectedPlugin->ItemType()) |
|
349 { |
|
350 // In these cases the plugin is a view: |
|
351 case EGSItemTypeSingleLarge: |
|
352 case EGSItemTypeSetting: |
|
353 case EGSItemTypeSettingIcon: |
|
354 iAppUi->ActivateLocalViewL(selectedPlugin->Id()); |
|
355 break; |
|
356 // In these cases the plugin is a dialog: |
|
357 case EGSItemTypeSettingDialog: |
|
358 case EGSItemTypeSingleLargeDialog: |
|
359 selectedPlugin->HandleSelection( |
|
360 EGSSelectionBySelectionKey); |
|
361 UpdateListBoxL(); // Refrest the listbox if value changed. |
|
362 break; |
|
363 } |
|
364 } |
|
365 break; |
|
366 default: |
|
367 break; |
|
368 } |
|
369 } |
|
370 |
|
371 |
|
372 // --------------------------------------------------------------------------- |
|
373 // CGSMainContainer::ListBox() |
|
374 // |
|
375 // |
|
376 // --------------------------------------------------------------------------- |
|
377 // |
|
378 CAknSingleLargeStyleListBox* CGSMainContainer::ListBox() |
|
379 { |
|
380 return iListBox; |
|
381 } |
|
382 |
|
383 |
|
384 // --------------------------------------------------------------------------- |
|
385 // CGSMainContainer::HandleResourceChange() |
|
386 // |
|
387 // |
|
388 // --------------------------------------------------------------------------- |
|
389 // |
|
390 void CGSMainContainer::HandleResourceChange( TInt aType ) |
|
391 { |
|
392 //Handle layout orientation or skin change |
|
393 CCoeControl::HandleResourceChange( aType ); |
|
394 if ( aType == KAknsMessageSkinChange ) |
|
395 { |
|
396 TRAP_IGNORE( UpdateListBoxL() ); |
|
397 } |
|
398 else if ( aType == KEikDynamicLayoutVariantSwitch ) |
|
399 { |
|
400 TRect mainPaneRect; |
|
401 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, |
|
402 mainPaneRect); |
|
403 SetRect( mainPaneRect ); |
|
404 } |
|
405 } |
|
406 |
|
407 |
|
408 // ----------------------------------------------------------------------------- |
|
409 // CGSMainContainer::SelectedPlugin() |
|
410 // |
|
411 // |
|
412 // ----------------------------------------------------------------------------- |
|
413 // |
|
414 CGSPluginInterface* CGSMainContainer::SelectedPlugin() |
|
415 { |
|
416 CGSPluginInterface* plugin = NULL; |
|
417 const TInt index = iListBox->CurrentItemIndex(); |
|
418 if ( index >= 0 && index <= iVisiblePlugins->Count() ) |
|
419 { |
|
420 plugin = iVisiblePlugins->operator[]( index ); |
|
421 __GSLOGSTRING2( "[CGSMainContainer] SelectedPlugin 0x%X in index %d", |
|
422 plugin->Id().iUid, index ); |
|
423 } |
|
424 return plugin; |
|
425 } |
|
426 |
|
427 |
|
428 // ----------------------------------------------------------------------------- |
|
429 // CGSMainContainer::SetSelectedItem() |
|
430 // |
|
431 // |
|
432 // ----------------------------------------------------------------------------- |
|
433 // |
|
434 void CGSMainContainer::SetSelectedItem( TUid aSelectedItemUid ) |
|
435 { |
|
436 __GSLOGSTRING1( "[CGSMainContainer] SetSelectedItem(0x%X)", |
|
437 aSelectedItemUid.iUid ); |
|
438 |
|
439 TInt selectedItemIndex = 0; |
|
440 for( TInt i = 0; i < iVisiblePlugins->Count(); i++ ) |
|
441 { |
|
442 CGSPluginInterface* plugin = iVisiblePlugins->operator[]( i ); |
|
443 |
|
444 __GSLOGSTRING2( "[CGSMainContainer] Checking [%d] 0x%X)", |
|
445 i, plugin->Id().iUid ); |
|
446 |
|
447 // If plugin is found, select it: |
|
448 if( plugin->Id() == aSelectedItemUid ) |
|
449 { |
|
450 __GSLOGSTRING2( "[CGSMainContainer] Match 0x%X in index %d", |
|
451 plugin->Id().iUid, i ); |
|
452 selectedItemIndex = i; |
|
453 break; |
|
454 } |
|
455 } |
|
456 iListBox->SetCurrentItemIndexAndDraw( selectedItemIndex ); |
|
457 } |
|
458 |
|
459 |
|
460 // --------------------------------------------------------------------------- |
|
461 // CGSMainContainer::FocusChanged |
|
462 // |
|
463 // Set focus on the selected listbox. For animated skins feature. |
|
464 // --------------------------------------------------------------------------- |
|
465 void CGSMainContainer::FocusChanged( TDrawNow /*aDrawNow*/ ) |
|
466 { |
|
467 if( iListBox ) |
|
468 { |
|
469 iListBox->SetFocus( IsFocused() ); |
|
470 } |
|
471 } |
|
472 |
|
473 |
|
474 // ----------------------------------------------------------------------------- |
|
475 // CGSMainContainer::SetListBoxEmptyTextL() |
|
476 // |
|
477 //Set the empty text of list box. |
|
478 // ----------------------------------------------------------------------------- |
|
479 // |
|
480 void CGSMainContainer::SetListBoxEmptyTextL(const TDes& aEmpty ) |
|
481 { |
|
482 if( iListBox ) |
|
483 { |
|
484 iListBox->View()->SetListEmptyTextL( aEmpty ); |
|
485 } |
|
486 } |
|
487 |
|
488 // ----------------------------------------------------------------------------- |
|
489 // CGSParentContainer::GetPositionL() |
|
490 // |
|
491 //Get the exact position of listbox. |
|
492 // ----------------------------------------------------------------------------- |
|
493 // |
|
494 void CGSMainContainer::GetPositionL(RArray<TInt>& posArray) |
|
495 { |
|
496 posArray.AppendL(iListBox->CurrentItemIndex()); |
|
497 posArray.AppendL(iListBox->View()->ItemOffsetInPixels()); |
|
498 posArray.AppendL(iListBox->View()->TopItemIndex()); |
|
499 return; |
|
500 } |
|
501 |
|
502 // ----------------------------------------------------------------------------- |
|
503 // CGSParentContainer::GetPositionL() |
|
504 // |
|
505 //Get the exact position of listbox. |
|
506 // ----------------------------------------------------------------------------- |
|
507 // |
|
508 void CGSMainContainer::SetPosition(const RArray<TInt>& pos, TBool aChangeMode) |
|
509 { |
|
510 iListBox->SetCurrentItemIndex(pos.operator[](0)); |
|
511 |
|
512 if (aChangeMode) |
|
513 { |
|
514 iListBox->View()->VerticalMoveToItemL(pos.operator[](0), |
|
515 CListBoxView::ESingleSelection); |
|
516 } |
|
517 else |
|
518 { |
|
519 iListBox->View()->SetItemOffsetInPixels(pos.operator[](1)); |
|
520 iListBox->View()->SetTopItemIndex(pos.operator[](2)); |
|
521 } |
|
522 } |
|
523 // End of File |