|
1 /* |
|
2 * Copyright (c) 2002-2009 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: |
|
15 * Support for Radio button style popup setting pages |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #include "aknradiobuttonsettingpage.h" |
|
22 |
|
23 // For icon support |
|
24 #include <barsread.h> |
|
25 #include <gulicon.h> |
|
26 |
|
27 // lists |
|
28 #include <aknlists.h> |
|
29 |
|
30 // For icon array support |
|
31 #include <AknIconArray.h> |
|
32 |
|
33 #include <AknTasHook.h> |
|
34 // Used for setting 1 in the radio button |
|
35 _LIT(KOneSlashT, "1\t"); |
|
36 |
|
37 enum TAknRadioButtonSettingPagePanicCodes |
|
38 { |
|
39 EAknPanicRadioButtonSettingPageIndexOutOfRange |
|
40 }; |
|
41 |
|
42 GLDEF_C void Panic(TAknRadioButtonSettingPagePanicCodes aPanic) |
|
43 { |
|
44 _LIT(KPanicCat,"AknRadioButtonSettingPage"); |
|
45 User::Panic(KPanicCat, aPanic); |
|
46 } |
|
47 |
|
48 |
|
49 // ---------------------------------------------------------------------------- |
|
50 // Extension class definition |
|
51 // ---------------------------------------------------------------------------- |
|
52 // |
|
53 NONSHARABLE_CLASS( CAknRadioButtonSettingPageExtension ) : public CBase |
|
54 { |
|
55 public: // Data |
|
56 CAknRadioButtonSettingPageExtension( CCoeControl& aOwner ); |
|
57 ~CAknRadioButtonSettingPageExtension(); |
|
58 |
|
59 // This CBase object is owned. Note that this depends upon the ownership flag given |
|
60 // to the CTextListBoxModel object |
|
61 CDesCArrayFlat* iInternalItemArray; |
|
62 |
|
63 TInt iOldFocusedItemIndex; // Index of item that was focused before pointer down event |
|
64 TBool iIsDragged; |
|
65 |
|
66 /** |
|
67 * Extension flags definition. |
|
68 */ |
|
69 enum TFlags |
|
70 { |
|
71 ESingleClickEnabled |
|
72 }; |
|
73 |
|
74 /** |
|
75 * Extension flags. |
|
76 */ |
|
77 TBitFlags iFlags; |
|
78 }; |
|
79 // end of CAknRadioButtonSettingPageExtension class definition |
|
80 |
|
81 |
|
82 CAknRadioButtonSettingPageExtension::CAknRadioButtonSettingPageExtension( |
|
83 CCoeControl& aOwner ) : |
|
84 iOldFocusedItemIndex(-1), iIsDragged( EFalse ) |
|
85 { |
|
86 if ( static_cast<CAknAppUi*>( |
|
87 aOwner.ControlEnv()->AppUi() )->IsSingleClickCompatible() ) |
|
88 { |
|
89 iFlags.Set( ESingleClickEnabled ); |
|
90 } |
|
91 } |
|
92 |
|
93 CAknRadioButtonSettingPageExtension::~CAknRadioButtonSettingPageExtension() |
|
94 { |
|
95 } |
|
96 |
|
97 |
|
98 |
|
99 ////////////////////////////////////////////////////////////////////// |
|
100 // Construction/Destruction |
|
101 ////////////////////////////////////////////////////////////////////// |
|
102 |
|
103 |
|
104 EXPORT_C CAknRadioButtonSettingPage::CAknRadioButtonSettingPage( TInt aResourceId, TInt& aCurrentSelectionItem, const MDesCArray* aItemArray): |
|
105 CAknListBoxSettingPage(aResourceId), iOldSelectionIndex(aCurrentSelectionItem), iCurrentSelectionIndex(aCurrentSelectionItem), iItemArray(aItemArray) |
|
106 { |
|
107 AKNTASHOOK_ADD( this, "CAknRadioButtonSettingPage" ); |
|
108 } |
|
109 |
|
110 |
|
111 EXPORT_C CAknRadioButtonSettingPage::CAknRadioButtonSettingPage( |
|
112 const TDesC* aSettingText, |
|
113 TInt aSettingNumber, |
|
114 TInt aControlType, |
|
115 TInt aEditorResourceId, |
|
116 TInt aSettingPageResourceId, |
|
117 TInt& aCurrentSelectionIndex, |
|
118 const MDesCArray* aItemArray ) |
|
119 : CAknListBoxSettingPage( |
|
120 aSettingText, |
|
121 aSettingNumber, |
|
122 aControlType, |
|
123 aEditorResourceId, |
|
124 aSettingPageResourceId ), |
|
125 iOldSelectionIndex(aCurrentSelectionIndex), |
|
126 iCurrentSelectionIndex(aCurrentSelectionIndex), |
|
127 iItemArray(aItemArray) |
|
128 { |
|
129 AKNTASHOOK_ADD( this, "CAknRadioButtonSettingPage" ); |
|
130 } |
|
131 |
|
132 |
|
133 /** |
|
134 * Destructor |
|
135 * |
|
136 */ |
|
137 EXPORT_C CAknRadioButtonSettingPage::~CAknRadioButtonSettingPage() |
|
138 { |
|
139 AKNTASHOOK_REMOVE(); |
|
140 if ( iExtension ) |
|
141 { |
|
142 delete iExtension->iInternalItemArray; |
|
143 delete iExtension; |
|
144 } |
|
145 } |
|
146 |
|
147 EXPORT_C void CAknRadioButtonSettingPage::ConstructL() |
|
148 { |
|
149 BaseConstructL(); |
|
150 |
|
151 // Construct an appropriate control context for the contained editor areas. |
|
152 // Context produced is owned by CAknSettingPage. |
|
153 SetEditedItemFrameIID( KAknsIIDQsnFrSetOpt, KAknsIIDQsnFrSetOptCenter ); |
|
154 |
|
155 GenerateInternalArrayAndGiveToListBoxL(); |
|
156 |
|
157 // This updates the CBA |
|
158 CheckAndSetDataValidity(); |
|
159 UpdateCbaL(); |
|
160 |
|
161 // Only a reference to the CBase object; not owned |
|
162 CAknSetStyleListBox* listBox = ListBoxControl(); |
|
163 |
|
164 InitialiseRadioButtonBitmapsL(); |
|
165 |
|
166 if (!iExtension) |
|
167 { |
|
168 iExtension = new (ELeave) CAknRadioButtonSettingPageExtension( *this ); |
|
169 } |
|
170 |
|
171 // Range should be within the valid indices, or -1: |
|
172 // So valid range is >= -1 and also < Count. |
|
173 __ASSERT_ALWAYS( iCurrentSelectionIndex >= -1, Panic( EAknPanicRadioButtonSettingPageIndexOutOfRange) ); |
|
174 __ASSERT_ALWAYS( iCurrentSelectionIndex < iExtension->iInternalItemArray->Count(), Panic( EAknPanicRadioButtonSettingPageIndexOutOfRange) ); |
|
175 |
|
176 listBox->View()->CalcBottomItemIndex(); |
|
177 // Set initial highlight to the top element |
|
178 if (FocusToFirstItem()) |
|
179 {// Set initial highlight to the top element |
|
180 if ( iExtension->iInternalItemArray->Count() > 0 ) |
|
181 listBox->SetCurrentItemIndex( 0 ); |
|
182 } |
|
183 if (FocusToSelectedItem()) |
|
184 {// Set initial highlight to the current element. |
|
185 if ( iExtension->iInternalItemArray->Count() > 0 ) |
|
186 { |
|
187 if (iCurrentSelectionIndex != -1) |
|
188 listBox->SetCurrentItemIndex( iCurrentSelectionIndex ); |
|
189 else |
|
190 listBox->SetCurrentItemIndex( 0 ); // Set at the top if selected is -1 |
|
191 } |
|
192 } |
|
193 |
|
194 listBox->SetListBoxObserver(this); |
|
195 |
|
196 // Set the current "pushed in" indication |
|
197 if ( iCurrentSelectionIndex != -1 ) |
|
198 { |
|
199 TBool redrawDisabled = listBox->View()->RedrawDisabled(); |
|
200 listBox->View()->SetDisableRedraw(ETrue); |
|
201 listBox->View()->SelectItemL( iCurrentSelectionIndex ); |
|
202 listBox->View()->SetDisableRedraw(redrawDisabled); |
|
203 } |
|
204 |
|
205 // Set the scroller indication to appear when needed |
|
206 listBox->CreateScrollBarFrameL(ETrue, ETrue); |
|
207 listBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto); |
|
208 |
|
209 listBox->ItemDrawer()->FormattedCellData()->SetDrawScrollbarBackground( EFalse ); |
|
210 // Need to do this to set up the scroll bar model |
|
211 listBox->ScrollBarFrame()->VerticalScrollBar()->SetMopParent(this); |
|
212 listBox->UpdateScrollBarsL(); |
|
213 |
|
214 if(!IsBackgroundDrawingEnabled()) |
|
215 listBox->ScrollBarFrame()->DrawBackground(EFalse, EFalse); |
|
216 |
|
217 // Force a size changed |
|
218 SizeChanged(); |
|
219 } |
|
220 |
|
221 |
|
222 EXPORT_C void CAknRadioButtonSettingPage::HandleListBoxEventL(CEikListBox* /*aListBox*/, |
|
223 MEikListBoxObserver::TListBoxEvent aEventType) |
|
224 { |
|
225 if (!iExtension) |
|
226 { |
|
227 iExtension = new (ELeave) CAknRadioButtonSettingPageExtension( *this ); |
|
228 } |
|
229 |
|
230 switch ( aEventType ) |
|
231 { |
|
232 case MEikListBoxObserver::EEventItemSingleClicked: |
|
233 case MEikListBoxObserver::EEventItemDoubleClicked: |
|
234 { |
|
235 SelectCurrentItemL(); |
|
236 AttemptExitL( ETrue ); |
|
237 break; |
|
238 } |
|
239 |
|
240 case MEikListBoxObserver::EEventFlickStopped: // fallthrough |
|
241 case MEikListBoxObserver::EEventPanningStopped: |
|
242 { |
|
243 // The current item index (highlighted item) of the listbox control |
|
244 // has been changed when starting the dragging / flicking, so |
|
245 // it must be reverted back to represent the same item as |
|
246 // the current selection in the setting page. |
|
247 // Only in single click enabled applications. |
|
248 if ( iExtension && |
|
249 iExtension->iFlags.IsSet( |
|
250 CAknRadioButtonSettingPageExtension::ESingleClickEnabled ) ) |
|
251 { |
|
252 ListBoxControl()->View()->SetCurrentItemIndex( |
|
253 iCurrentSelectionIndex ); |
|
254 } |
|
255 break; |
|
256 } |
|
257 |
|
258 default: |
|
259 break; |
|
260 } |
|
261 } |
|
262 |
|
263 EXPORT_C void CAknRadioButtonSettingPage::UpdateSettingL() |
|
264 { |
|
265 } |
|
266 |
|
267 EXPORT_C CAknSetStyleListBox* CAknRadioButtonSettingPage::ListBoxControl() const |
|
268 { |
|
269 return STATIC_CAST( CAknSetStyleListBox*, EditorControl()); |
|
270 } |
|
271 |
|
272 EXPORT_C void CAknRadioButtonSettingPage::DynamicInitL() |
|
273 { |
|
274 } |
|
275 |
|
276 void CAknRadioButtonSettingPage::SetRadioButtonSelectionL( TInt aPushed ) |
|
277 { |
|
278 if ( aPushed != iOldSelectionIndex ) |
|
279 { |
|
280 CListBoxView* view = ListBoxControl()->View(); |
|
281 view->DeselectItem( iOldSelectionIndex ); |
|
282 iOldSelectionIndex = aPushed; |
|
283 view->SelectItemL( aPushed ); |
|
284 } |
|
285 } |
|
286 |
|
287 EXPORT_C void CAknRadioButtonSettingPage::SelectCurrentItemL() |
|
288 { |
|
289 iCurrentSelectionIndex = ListBoxControl()->CurrentItemIndex(); |
|
290 SetRadioButtonSelectionL( iCurrentSelectionIndex ); |
|
291 UpdateSettingL(); |
|
292 if( iSettingPageObserver ) |
|
293 iSettingPageObserver->HandleSettingPageEventL(this, MAknSettingPageObserver::EEventSettingChanged); |
|
294 } |
|
295 |
|
296 |
|
297 EXPORT_C void CAknRadioButtonSettingPage::SetItemArrayAndSelectionL( const MDesCArray* aItemArray, TInt aPushed ) |
|
298 { |
|
299 SetRadioButtonSelectionL(0); // Put the selection into a known state |
|
300 iItemArray = aItemArray; |
|
301 GenerateInternalArrayAndGiveToListBoxL(); |
|
302 |
|
303 // This updates the CBA |
|
304 CheckAndSetDataValidity(); |
|
305 UpdateCbaL(); |
|
306 |
|
307 SizeChanged(); |
|
308 SetRadioButtonSelectionL(aPushed); |
|
309 |
|
310 DrawDeferred(); |
|
311 } |
|
312 |
|
313 void CAknRadioButtonSettingPage::GenerateInternalArrayAndGiveToListBoxL() |
|
314 { |
|
315 if (!iExtension) |
|
316 { |
|
317 iExtension = new (ELeave) CAknRadioButtonSettingPageExtension( *this ); |
|
318 } |
|
319 |
|
320 delete iExtension->iInternalItemArray; |
|
321 iExtension->iInternalItemArray = 0; |
|
322 |
|
323 // Make a new owned text array from the input one with the "Pushed in" icon index: |
|
324 iExtension->iInternalItemArray = new(ELeave)CDesCArrayFlat(1); |
|
325 TInt nItems = iItemArray->MdcaCount(); |
|
326 |
|
327 for (TInt ii=0; ii<nItems; ii++) |
|
328 { |
|
329 // Fill up the control-owned space for the modified buffers: |
|
330 TInt newLen = (iItemArray->MdcaPoint(ii)).Length() + KOneSlashT().Length(); |
|
331 HBufC* newText = HBufC::NewMaxLC( newLen ); |
|
332 TPtr newTPtr = newText->Des(); |
|
333 newTPtr.Copy( KOneSlashT ); |
|
334 newTPtr.Append( iItemArray->MdcaPoint(ii) ); |
|
335 // A copy of the new buffer goes to the internal itemarray: |
|
336 iExtension->iInternalItemArray->AppendL(newTPtr); |
|
337 CleanupStack::PopAndDestroy(); // newText |
|
338 } |
|
339 |
|
340 // Only a reference to the CBase object; not owned |
|
341 CAknSetStyleListBox* listBox = ListBoxControl(); |
|
342 |
|
343 // Set the text data |
|
344 CTextListBoxModel* model=listBox->Model(); |
|
345 model->SetItemTextArray(iExtension->iInternalItemArray); |
|
346 model->SetOwnershipType(ELbmDoesNotOwnItemArray); |
|
347 |
|
348 } |
|
349 |
|
350 |
|
351 void CAknRadioButtonSettingPage::InitialiseRadioButtonBitmapsL() |
|
352 { |
|
353 // This method is more or less a verbatim copy of |
|
354 // CAknPopupField::InitialiseRadioButtonBitmapsL |
|
355 |
|
356 CAknSetStyleListBox* listBox = ListBoxControl(); |
|
357 |
|
358 // In case CAknPopupSettingList has already created the icons |
|
359 if ( listBox->ItemDrawer()->FormattedCellData()->IconArray() ) |
|
360 { |
|
361 listBox->ItemDrawer()->FormattedCellData()->IconArray()->ResetAndDestroy(); |
|
362 delete (listBox->ItemDrawer()->FormattedCellData()->IconArray()); |
|
363 } |
|
364 |
|
365 TResourceReader reader; |
|
366 |
|
367 iCoeEnv->CreateResourceReaderLC(reader, R_AVKON_SETTING_PAGE_RADIOBUTTON_ICONS); |
|
368 |
|
369 reader.ReadInt16(); //not needed, simple or complex |
|
370 |
|
371 HBufC* bmpFile = reader.ReadHBufCL(); |
|
372 TInt count = reader.ReadInt16(); // count |
|
373 |
|
374 if(count<2) |
|
375 User::Leave(KErrCorrupt); |
|
376 |
|
377 TInt32 bmpSelected = reader.ReadInt32(); |
|
378 TInt32 bmpSelectedM = reader.ReadInt32(); |
|
379 TInt32 bmp = reader.ReadInt32(); |
|
380 TInt32 bmpM = reader.ReadInt32(); |
|
381 CleanupStack::PopAndDestroy(); // reader |
|
382 |
|
383 if (bmpFile == NULL) |
|
384 User::Leave(KErrCorrupt); |
|
385 |
|
386 CleanupStack::PushL(bmpFile); |
|
387 |
|
388 CArrayPtr<CGulIcon>* icons = new(ELeave) CAknIconArray(4); |
|
389 // put on the cleanup stack until ownership is transferred |
|
390 CleanupStack::PushL( icons ); |
|
391 |
|
392 // create normally colored icons |
|
393 CreateIconAndAddToArrayL( icons, |
|
394 KAknsIIDQgnIndiRadiobuttOn, |
|
395 EAknsCIQsnIconColorsCG14, |
|
396 *bmpFile, |
|
397 bmpSelected, |
|
398 bmpSelectedM ); |
|
399 |
|
400 CreateIconAndAddToArrayL( icons, |
|
401 KAknsIIDQgnIndiRadiobuttOff, |
|
402 EAknsCIQsnIconColorsCG14, |
|
403 *bmpFile, |
|
404 bmp, |
|
405 bmpM ); |
|
406 |
|
407 // create highlight colored icons |
|
408 CreateIconAndAddToArrayL( icons, |
|
409 KAknsIIDQgnIndiRadiobuttOn, |
|
410 EAknsCIQsnIconColorsCG18, |
|
411 *bmpFile, |
|
412 bmpSelected, |
|
413 bmpSelectedM ); |
|
414 |
|
415 CreateIconAndAddToArrayL( icons, |
|
416 KAknsIIDQgnIndiRadiobuttOff, |
|
417 EAknsCIQsnIconColorsCG18, |
|
418 *bmpFile, |
|
419 bmp, |
|
420 bmpM ); |
|
421 |
|
422 |
|
423 __ASSERT_DEBUG(listBox != NULL, Panic(EAknPanicRadioButtonSettingPageListDoesntExist)); |
|
424 listBox->ItemDrawer()->FormattedCellData()->SetIconArrayL( icons ); // ownership transferred |
|
425 listBox->ItemDrawer()->FormattedCellData()->UseHighlightIconSwapping( ETrue ); |
|
426 CleanupStack::Pop(); // icons - ownership now transferred; do not destroy |
|
427 CleanupStack::PopAndDestroy(); // bmpfile |
|
428 } |
|
429 |
|
430 /** |
|
431 * Writes the internal state of the control and its components to aStream. |
|
432 * Does nothing in release mode. |
|
433 * Designed to be overidden and base called by subclasses. |
|
434 */ |
|
435 #ifndef _DEBUG |
|
436 EXPORT_C void CAknRadioButtonSettingPage::WriteInternalStateL(RWriteStream& /*aWriteStream*/) const |
|
437 {} |
|
438 #else |
|
439 EXPORT_C void CAknRadioButtonSettingPage::WriteInternalStateL(RWriteStream& aWriteStream) const |
|
440 { |
|
441 CAknSettingPage::WriteInternalStateL(aWriteStream); |
|
442 } |
|
443 #endif |
|
444 |
|
445 //--------------------------------------------------------------------------------------- |
|
446 // CAknRadioButtonSettingPage::HandlePointerEventL() |
|
447 // Handles pointer events by removing Shift and Control button modifiers from it and |
|
448 // sends modified pointerevent to CEikListbox. This prevents multiselection |
|
449 //--------------------------------------------------------------------------------------- |
|
450 // |
|
451 |
|
452 EXPORT_C void CAknRadioButtonSettingPage::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
453 { |
|
454 TPointerEvent& event = const_cast<TPointerEvent&>( aPointerEvent ); |
|
455 event.iModifiers &= ~EModifierShift; |
|
456 event.iModifiers &= ~EModifierCtrl; |
|
457 |
|
458 CAknListBoxSettingPage::HandlePointerEventL( aPointerEvent ); |
|
459 } |
|
460 |
|
461 EXPORT_C void* CAknRadioButtonSettingPage::ExtensionInterface( TUid /*aInterface*/ ) |
|
462 { |
|
463 return NULL; |
|
464 } |
|
465 |
|
466 |
|
467 /** |
|
468 * Reserved method derived from CCoeControl |
|
469 */ |
|
470 EXPORT_C void CAknRadioButtonSettingPage::Reserved_2() |
|
471 { |
|
472 } |
|
473 |
|
474 /** |
|
475 * Setting Page reserved methods |
|
476 */ |
|
477 EXPORT_C void CAknRadioButtonSettingPage::HandleResourceChange(TInt aType) |
|
478 { |
|
479 if( aType == KAknsMessageSkinChange ) |
|
480 { |
|
481 TRAP_IGNORE( InitialiseRadioButtonBitmapsL() ); |
|
482 } |
|
483 |
|
484 CAknListBoxSettingPage::HandleResourceChange(aType); |
|
485 } |
|
486 |
|
487 EXPORT_C void CAknRadioButtonSettingPage::CAknSettingPage_Reserved_1() |
|
488 { |
|
489 } |
|
490 |
|
491 EXPORT_C void CAknRadioButtonSettingPage::CAknSettingPage_Reserved_2() |
|
492 { |
|
493 } |
|
494 /** |
|
495 * CAknListBoxSettingPage-derived reserved methods |
|
496 */ |
|
497 EXPORT_C void CAknRadioButtonSettingPage::CAknListBoxSettingPage_Reserved_1() |
|
498 { |
|
499 } |
|
500 |
|
501 // End of File |