|
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: CAknChoiceList - Choice list for S60 |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <AknControl.h> |
|
20 #include <aknlists.h> |
|
21 #include <aknbutton.h> |
|
22 #include <avkon.hrh> // AknButton flags |
|
23 #include <barsread.h> // TResourceReader |
|
24 #include <AknInfoPopupNoteController.h> // Tooltip |
|
25 #include "aknchoicelist.h" |
|
26 |
|
27 #include <AknLayout2ScalableDef.h> |
|
28 #include <aknlayoutscalable_avkon.cdl.h> |
|
29 |
|
30 #include <AknsFrameBackgroundControlContext.h> |
|
31 #include <AknsConstants.h> |
|
32 #include <avkon.mbg> |
|
33 #include <aknglobalpopupprioritycontroller.h> |
|
34 #include <touchfeedback.h> |
|
35 #include <AknTasHook.h> |
|
36 #include <akntranseffect.h> |
|
37 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS |
|
38 #include <akntransitionutils.h> |
|
39 #endif |
|
40 |
|
41 #include "akntrace.h" |
|
42 |
|
43 // CONSTANTS |
|
44 |
|
45 const TInt KTimeoutBeforeTooltipNote = 150; // in milliseconds |
|
46 const TInt KTimeoutInViewTooltipNote = 3000; // in milliseconds |
|
47 |
|
48 // CLASS DECLARATION |
|
49 |
|
50 /** |
|
51 * CAknChoiceListPopupList |
|
52 * This is a List to be used in side of CAknChoiceListPopup. |
|
53 * We had to create a own list for this because currently AvKon |
|
54 * lists are not parent relative but main pane relative. |
|
55 * @internal This should not be used anywhere else! |
|
56 */ |
|
57 |
|
58 NONSHARABLE_CLASS(CAknChoiceListPopupList): public CEikFormattedCellListBox |
|
59 { |
|
60 public: // Functions from base classes |
|
61 |
|
62 // --------------------------------------------------------- |
|
63 // CAknChoiceListPopupList::SizeChanged() |
|
64 // --------------------------------------------------------- |
|
65 // |
|
66 void SizeChanged() |
|
67 { |
|
68 CEikFormattedCellListBox::SizeChanged(); |
|
69 TRAP_IGNORE( SizeChangedL() ); |
|
70 |
|
71 TAknLayoutRect cellRect; |
|
72 cellRect.LayoutRect( Rect(), |
|
73 AknLayoutScalable_Avkon::list_single_choice_list_pane(0) ); |
|
74 |
|
75 CFormattedCellListBoxItemDrawer *itemDrawer( ItemDrawer() ); |
|
76 |
|
77 itemDrawer->SetItemCellSize( cellRect.Rect().Size() ); |
|
78 } |
|
79 |
|
80 TSize MinimumSize() |
|
81 { |
|
82 return Size(); |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------- |
|
86 // CAknChoiceListPopupList::CreateItemDrawerL |
|
87 // Item drawer construction |
|
88 // --------------------------------------------------------- |
|
89 // |
|
90 void CreateItemDrawerL() |
|
91 { |
|
92 CFormattedCellListBoxData* data=CFormattedCellListBoxData::NewL(); |
|
93 CleanupStack::PushL( data ); |
|
94 |
|
95 TAknLayoutText itemText; |
|
96 itemText.LayoutText( Rect(), AknLayoutScalable_Avkon::list_single_choice_list_pane_t1(0) ); |
|
97 const CFont* font = itemText.Font(); |
|
98 |
|
99 iItemDrawer=new (ELeave) CFormattedCellListBoxItemDrawer( |
|
100 Model(), |
|
101 font, |
|
102 data |
|
103 ); //takes ownership |
|
104 // Let the choice list background context control the grid skinning |
|
105 ItemDrawer()->FormattedCellData()->SetSkinEnabledL( EFalse ); |
|
106 // Marquee can be requested.. ;) |
|
107 ItemDrawer()->FormattedCellData()->EnableMarqueeL( EFalse ); |
|
108 CleanupStack::Pop(); |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------- |
|
112 // CAknChoiceListPopupList::UpdateTextColors |
|
113 // Skin items |
|
114 // --------------------------------------------------------- |
|
115 // |
|
116 void UpdateTextColors() |
|
117 { |
|
118 TRgb color( KRgbBlack ); // sane default for nonskinned case |
|
119 if ( AknsUtils::AvkonSkinEnabled() ) |
|
120 { |
|
121 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), |
|
122 color, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG8 ); |
|
123 } |
|
124 |
|
125 ItemDrawer()->SetTextColor( color ); |
|
126 ItemDrawer()->SetBackColor( AKN_LAF_COLOR( 0 ) ); |
|
127 |
|
128 if ( AknsUtils::AvkonSkinEnabled() ) |
|
129 { |
|
130 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), |
|
131 color, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG8 ); |
|
132 } |
|
133 |
|
134 ItemDrawer()->SetHighlightedTextColor( color ); |
|
135 ItemDrawer()->SetHighlightedBackColor( AKN_LAF_COLOR( 0 ) ); |
|
136 } |
|
137 |
|
138 private: |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CAknChoiceListPopupList::SizeChangedL |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 void SizeChangedL() |
|
145 { |
|
146 CFormattedCellListBoxItemDrawer* itemDrawer = ItemDrawer(); |
|
147 CFormattedCellListBoxData* d = itemDrawer->FormattedCellData(); |
|
148 |
|
149 TAknLayoutRect cellRect; |
|
150 cellRect.LayoutRect( Rect(), |
|
151 AknLayoutScalable_Avkon::list_single_choice_list_pane(0) ); |
|
152 |
|
153 TRect cell( cellRect.Rect() ); |
|
154 |
|
155 SetItemHeightL( cell.Height() ); |
|
156 |
|
157 d->SetTextSubCellL( 0, AknLayoutScalable_Avkon::list_single_choice_list_pane_t1(0) ); |
|
158 } |
|
159 |
|
160 }; |
|
161 |
|
162 // CLASS DECLARATION |
|
163 /** |
|
164 * Control container for choice list |
|
165 */ |
|
166 NONSHARABLE_CLASS( CAknChoiceListPopup ) : public CCoeControl, |
|
167 public MEikListBoxObserver, |
|
168 MEikCommandObserver |
|
169 { |
|
170 public: |
|
171 CAknChoiceListPopup() : iIndex( -1 ), iCancelled( EFalse ) |
|
172 { |
|
173 AKNTASHOOK_ADD( this, "CAknChoiceListPopup" ); |
|
174 } |
|
175 |
|
176 // Symbian OS default constructor can leave. |
|
177 void ConstructL() |
|
178 { |
|
179 CreateWindowL(); |
|
180 |
|
181 if( CAknEnv::Static()->TransparencyEnabled() ) |
|
182 { |
|
183 Window().SetRequiredDisplayMode( EColor16MA ); |
|
184 TInt err = Window().SetTransparencyAlphaChannel(); |
|
185 |
|
186 if ( err == KErrNone ) |
|
187 { |
|
188 Window().SetBackgroundColor(~0); |
|
189 } |
|
190 } |
|
191 SetComponentsToInheritVisibility(); |
|
192 CreateChoiceListL(); |
|
193 Window().SetShadowDisabled( ETrue ); |
|
194 |
|
195 Window().SetPointerGrab( ETrue ); |
|
196 SetGloballyCapturing( ETrue ); |
|
197 |
|
198 MakeVisible( EFalse ); |
|
199 |
|
200 TRect nullRect( 0, 0, 0, 0 ); |
|
201 |
|
202 iBgContext = CAknsFrameBackgroundControlContext::NewL( |
|
203 KAknsIIDQsnFrPopupSub, nullRect, nullRect, EFalse ); |
|
204 |
|
205 if ( AknLayoutUtils::PenEnabled() ) |
|
206 { |
|
207 SetGloballyCapturing( ETrue ); |
|
208 SetPointerCapture( ETrue ); |
|
209 } |
|
210 iList->UpdateTextColors(); |
|
211 } |
|
212 |
|
213 // Destructor |
|
214 ~CAknChoiceListPopup() |
|
215 { |
|
216 AKNTASHOOK_REMOVE(); |
|
217 AknGlobalPopupPriorityController::RemovePopupPriority(*this); |
|
218 delete iCba; |
|
219 delete iList; |
|
220 delete iBgContext; |
|
221 } |
|
222 |
|
223 // New functions |
|
224 public: |
|
225 |
|
226 // --------------------------------------------------------- |
|
227 // CAknChoiceListPopup::CloseChoiceList |
|
228 // Dismisses CAknChoiceListPopup |
|
229 // from the screen and removes it from the control stack |
|
230 // --------------------------------------------------------- |
|
231 // |
|
232 void CloseChoiceList() |
|
233 { |
|
234 if ( iIsDisplayed ) |
|
235 { |
|
236 MakeVisible( EFalse ); |
|
237 |
|
238 if (iCba) |
|
239 AknGlobalPopupPriorityController::RemovePopupPriority(*iCba->ButtonGroup()->AsControl()); |
|
240 delete iCba; |
|
241 iCba = NULL; |
|
242 |
|
243 SetFocus( EFalse ); |
|
244 |
|
245 iAvkonAppUi->RemoveFromStack( this ); |
|
246 iEikonEnv->BringForwards( EFalse ); |
|
247 AknGlobalPopupPriorityController::ShowPopup(*this, EFalse); |
|
248 |
|
249 if ( AknLayoutUtils::PenEnabled() ) |
|
250 { |
|
251 SetPointerCapture( EFalse ); |
|
252 } |
|
253 |
|
254 if( iCancelled ) |
|
255 { |
|
256 TRAP_IGNORE( Observer()->HandleControlEventL( this, MCoeControlObserver::EEventRequestCancel ) ); |
|
257 } |
|
258 else |
|
259 { |
|
260 TRAP_IGNORE( Observer()->HandleControlEventL( this, MCoeControlObserver::EEventStateChanged ) ); |
|
261 } |
|
262 DrawNow(); |
|
263 } |
|
264 iIsDisplayed = EFalse; |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------- |
|
268 // CAknChoiceListPopup::UpdateControlContext |
|
269 // --------------------------------------------------------- |
|
270 // |
|
271 void UpdateControlContext() |
|
272 { |
|
273 TRect rectParent( Rect() ); |
|
274 |
|
275 TAknLayoutRect layoutRect; |
|
276 TInt variety = 0; |
|
277 |
|
278 // check if scrollbar-layout should be selected |
|
279 if ( iList->Model()->ItemTextArray()->MdcaCount() > 6 ) |
|
280 { |
|
281 variety = 1; |
|
282 |
|
283 TRAP_IGNORE( iList->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
284 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOn) ); |
|
285 |
|
286 AknLayoutUtils::LayoutVerticalScrollBar( iList->ScrollBarFrame(), |
|
287 rectParent, |
|
288 AknLayoutScalable_Avkon::scroll_pane_cp23().LayoutLine() |
|
289 ); |
|
290 } |
|
291 else |
|
292 { |
|
293 TRAP_IGNORE( iList->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
294 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOff) ); |
|
295 |
|
296 // Enable scrolling |
|
297 iList->DisableScrolling( EFalse ); |
|
298 } |
|
299 |
|
300 layoutRect.LayoutRect( rectParent, |
|
301 AknLayoutScalable_Avkon::list_choice_list_pane( variety ).LayoutLine() ); |
|
302 iList->SetRect( layoutRect.Rect() ); |
|
303 |
|
304 TAknLayoutRect innerRect; |
|
305 innerRect.LayoutRect( |
|
306 rectParent, |
|
307 AknLayoutScalable_Avkon::list_choice_list_pane(0).LayoutLine() |
|
308 ); |
|
309 |
|
310 iBgContext->SetFrameRects(rectParent, innerRect.Rect()); |
|
311 } |
|
312 |
|
313 // --------------------------------------------------------- |
|
314 // CAknChoiceListPopup::SetItemsL |
|
315 // set content array |
|
316 // --------------------------------------------------------- |
|
317 // |
|
318 |
|
319 void SetItemsL( CDesCArray& aArray ) |
|
320 { |
|
321 // Set list items. |
|
322 CTextListBoxModel* model = iList->Model(); |
|
323 model->SetItemTextArray( &aArray ); |
|
324 iList->HandleItemAdditionL(); |
|
325 // We don't want to transfer ownership |
|
326 model->SetOwnershipType( ELbmDoesNotOwnItemArray ); |
|
327 } |
|
328 |
|
329 // --------------------------------------------------------- |
|
330 // CAknChoiceListPopup::SelectedItem() |
|
331 // Ask selected item from the choice list |
|
332 // --------------------------------------------------------- |
|
333 // |
|
334 TInt SelectedItem() const |
|
335 { |
|
336 return iIndex; |
|
337 } |
|
338 |
|
339 void SetSelectedItem( const TInt aIndex ) |
|
340 { |
|
341 if ( aIndex >= 0 ) |
|
342 { |
|
343 iIndex = aIndex; |
|
344 if ( iIsDisplayed && aIndex < iList->Model()->ItemTextArray()->MdcaCount() ) |
|
345 { |
|
346 iList->SetCurrentItemIndexAndDraw( aIndex ); |
|
347 } |
|
348 } |
|
349 else |
|
350 { |
|
351 iIndex = -1; |
|
352 } |
|
353 } |
|
354 |
|
355 // --------------------------------------------------------- |
|
356 // CAknChoiceListPopup::SetPopupSizeAndLocation |
|
357 // --------------------------------------------------------- |
|
358 // |
|
359 void SetPopupSizeAndLocation( const TRect& aRect ) |
|
360 { |
|
361 if ( iIsDisplayed ) |
|
362 { |
|
363 Window().Invalidate(); |
|
364 } |
|
365 SetRect( aRect ); |
|
366 TAknLayoutRect listRect; |
|
367 |
|
368 TInt variety = 0; |
|
369 if ( iList->Model()->ItemTextArray()->MdcaCount() > 6 ) |
|
370 { |
|
371 variety = 1; |
|
372 } |
|
373 listRect.LayoutRect( aRect, AknLayoutScalable_Avkon::list_choice_list_pane( variety ) ); |
|
374 iList->SetSize( listRect.Rect().Size() ); |
|
375 } |
|
376 |
|
377 void OpenChoiceListL() |
|
378 { |
|
379 if ( iIsDisplayed || iList->Model()->ItemTextArray()->MdcaCount() == 0 ) |
|
380 { |
|
381 return; |
|
382 } |
|
383 |
|
384 if ( AknLayoutUtils::PenEnabled() ) |
|
385 { |
|
386 SetPointerCapture( ETrue ); |
|
387 } |
|
388 |
|
389 iIsDisplayed = ETrue; |
|
390 AknGlobalPopupPriorityController::AddPopupToControlStackL( *this ); |
|
391 iEikonEnv->BringForwards( ETrue ); |
|
392 DrawableWindow()->SetOrdinalPosition( 0 ); |
|
393 AknGlobalPopupPriorityController::ShowPopup(*this, ETrue); |
|
394 |
|
395 // this will fix possibly corrupted index |
|
396 if ( iIndex < iList->Model()->ItemTextArray()->MdcaCount() && iIndex >= 0 ) |
|
397 { |
|
398 iList->SetCurrentItemIndex( iIndex ); |
|
399 } |
|
400 else if ( iList->Model()->ItemTextArray()->MdcaCount() > 0 ) |
|
401 { |
|
402 iList->SetCurrentItemIndex( 0 ); |
|
403 } |
|
404 CreateCbaL(); |
|
405 ActivateL(); |
|
406 MakeVisible( ETrue ); |
|
407 SetFocus( ETrue ); |
|
408 iList->SetFocus( ETrue ); |
|
409 iCancelled = EFalse; |
|
410 UpdateControlContext(); |
|
411 DrawNow(); |
|
412 } |
|
413 |
|
414 // Functions from base classes |
|
415 public: |
|
416 |
|
417 // --------------------------------------------------------- |
|
418 // CAknChoiceListPopup::Draw |
|
419 // Symbian OS framework drawing function. Draws the window shadows and |
|
420 // outline frame. |
|
421 // --------------------------------------------------------- |
|
422 // |
|
423 void Draw(const TRect& aRect) const |
|
424 { |
|
425 CWindowGc& gc = SystemGc(); |
|
426 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
427 if ( !AknsDrawUtils::Background( skin, iBgContext, gc, aRect ) ) |
|
428 { |
|
429 SystemGc().Clear( aRect ); |
|
430 } |
|
431 |
|
432 } |
|
433 |
|
434 // --------------------------------------------------------- |
|
435 // CAknChoiceListPopup::SizeChanged |
|
436 // --------------------------------------------------------- |
|
437 // |
|
438 void SizeChanged() |
|
439 { |
|
440 CCoeControl::SizeChanged(); |
|
441 UpdateControlContext(); |
|
442 } |
|
443 |
|
444 // --------------------------------------------------------- |
|
445 // CAknChoiceListPopup::HandleResourceChange |
|
446 // --------------------------------------------------------- |
|
447 // |
|
448 void HandleResourceChange(TInt aType) |
|
449 { |
|
450 CCoeControl::HandleResourceChange(aType); |
|
451 if ( iCba ) |
|
452 { |
|
453 iCba->HandleResourceChange(aType); |
|
454 } |
|
455 if( aType == KEikDynamicLayoutVariantSwitch ) |
|
456 { |
|
457 MakeVisible( ETrue ); |
|
458 } |
|
459 if ( aType == KAknsMessageSkinChange ) |
|
460 { |
|
461 iList->UpdateTextColors(); |
|
462 } |
|
463 } |
|
464 |
|
465 TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
466 { |
|
467 if ( aType == EEventKey ) |
|
468 { |
|
469 if ( aKeyEvent.iScanCode == EStdKeyUpArrow || |
|
470 aKeyEvent.iScanCode == EStdKeyDownArrow || |
|
471 aKeyEvent.iScanCode == EStdKeyEnter || |
|
472 aKeyEvent.iScanCode == EStdKeyDevice3 ) |
|
473 { |
|
474 return iList->OfferKeyEventL(aKeyEvent, aType); |
|
475 } |
|
476 else |
|
477 { |
|
478 CloseChoiceList(); |
|
479 return EKeyWasConsumed; |
|
480 } |
|
481 } |
|
482 return EKeyWasNotConsumed; |
|
483 } |
|
484 |
|
485 private: |
|
486 |
|
487 // --------------------------------------------------------- |
|
488 // CAknChoiceListPopup::CountComponentControls |
|
489 // --------------------------------------------------------- |
|
490 // |
|
491 TInt CountComponentControls() const |
|
492 { |
|
493 return 1; |
|
494 } |
|
495 |
|
496 // --------------------------------------------------------- |
|
497 // CAknChoiceListPopup::ComponentControl |
|
498 // --------------------------------------------------------- |
|
499 // |
|
500 CCoeControl* ComponentControl(TInt aIndex) const |
|
501 { |
|
502 if ( aIndex == 0 ) |
|
503 { |
|
504 return iList; |
|
505 } |
|
506 return NULL; |
|
507 } |
|
508 |
|
509 // --------------------------------------------------------- |
|
510 // CAknChoiceListPopup::HandlePointerEventL |
|
511 // Decides what to do when pen is used and choice list is active |
|
512 // --------------------------------------------------------- |
|
513 // |
|
514 void HandlePointerEventL(const TPointerEvent &aPointerEvent) |
|
515 { |
|
516 |
|
517 if ( AknLayoutUtils::PenEnabled() ) |
|
518 { |
|
519 |
|
520 // Make sure that scrolling is enabled for choicelist |
|
521 if ( iList->ScrollingDisabled() ) |
|
522 { |
|
523 iList->DisableScrolling( EFalse ); |
|
524 } |
|
525 |
|
526 TRect ctrlArea = iList->Rect(); |
|
527 |
|
528 if ( aPointerEvent.iType == TPointerEvent::EButton1Down ) |
|
529 { |
|
530 if ( !ctrlArea.Contains( aPointerEvent.iPosition ) ) |
|
531 { |
|
532 iCancelled = ETrue; |
|
533 SetSelectedItem( iIndex ); |
|
534 CloseChoiceList(); |
|
535 return; |
|
536 } |
|
537 |
|
538 TInt index; |
|
539 if ( iList->View()->XYPosToItemIndex( aPointerEvent.iPosition, index )) |
|
540 { |
|
541 if ( !iAvkonAppUi->IsSingleClickCompatible() ) |
|
542 { |
|
543 // Pressed Down Effect |
|
544 iList->View()->ItemDrawer()->SetFlags( |
|
545 CListItemDrawer::EPressedDownState ); |
|
546 } |
|
547 } |
|
548 } |
|
549 CCoeControl::HandlePointerEventL( aPointerEvent ); |
|
550 } |
|
551 } |
|
552 |
|
553 // --------------------------------------------------------- |
|
554 // CAknChoiceListPopup::ProcessCommandL |
|
555 // Softkey event handling |
|
556 // --------------------------------------------------------- |
|
557 // |
|
558 void ProcessCommandL(TInt aCommandId) |
|
559 { |
|
560 switch (aCommandId) |
|
561 { |
|
562 case EAknSoftkeyCancel: |
|
563 iCancelled = ETrue; |
|
564 CloseChoiceList(); |
|
565 break; |
|
566 case EAknSoftkeySelect: |
|
567 iCancelled = EFalse; |
|
568 HandleListBoxEventL( iList, EEventEnterKeyPressed ); |
|
569 break; |
|
570 default: |
|
571 return; |
|
572 } |
|
573 } |
|
574 |
|
575 // --------------------------------------------------------- |
|
576 // CAknChoiceListPopup::HandleListBoxEventL |
|
577 // Handles item selection in the grid |
|
578 // --------------------------------------------------------- |
|
579 // |
|
580 void HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType) |
|
581 { |
|
582 if ( aListBox == iList |
|
583 && ( aEventType == EEventEnterKeyPressed |
|
584 || aEventType == EEventItemClicked |
|
585 || aEventType == EEventItemSingleClicked ) ) |
|
586 { |
|
587 iIndex = iList->CurrentItemIndex(); |
|
588 CloseChoiceList(); |
|
589 } |
|
590 } |
|
591 |
|
592 TTypeUid::Ptr MopSupplyObject(TTypeUid aId) |
|
593 { |
|
594 if ( aId.iUid == MAknsControlContext::ETypeId ) |
|
595 { |
|
596 return ( MAknsControlContext::SupplyMopObject( aId, iBgContext ) ) ; |
|
597 } |
|
598 if ( iCba ) |
|
599 { |
|
600 return MAknsControlContext::SupplyMopObject(aId, (MAknsControlContext*)iCba); |
|
601 } |
|
602 return TTypeUid::Null(); |
|
603 } |
|
604 |
|
605 private: |
|
606 |
|
607 // --------------------------------------------------------- |
|
608 // CAknChoiceListPopup::CreateChoiceListL |
|
609 // Choice list construction (component control of CAknChoiceListPopup) |
|
610 // --------------------------------------------------------- |
|
611 // |
|
612 void CreateChoiceListL() |
|
613 { |
|
614 ASSERT(!iList); |
|
615 iList = new ( ELeave ) CAknChoiceListPopupList; |
|
616 iList->SetContainerWindowL( *this ); |
|
617 iList->ConstructL( this, EAknListBoxSelectionList ); |
|
618 iList->CreateScrollBarFrameL( ETrue ); |
|
619 iList->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOn); |
|
620 iList->SetListBoxObserver(this); |
|
621 iList->SetMopParent( this ); |
|
622 } |
|
623 |
|
624 |
|
625 // --------------------------------------------------------- |
|
626 // CAknChoiceListPopup::CreateCbaL |
|
627 // Softkey construction (component control of CAknChoiceListPopup) |
|
628 // --------------------------------------------------------- |
|
629 // |
|
630 void CreateCbaL() |
|
631 { |
|
632 ASSERT(!iCba); |
|
633 |
|
634 iCba = CEikButtonGroupContainer::NewL(CEikButtonGroupContainer::ECba, |
|
635 CEikButtonGroupContainer::EHorizontal, |
|
636 this, R_AVKON_SOFTKEYS_SELECT_CANCEL__SELECT); |
|
637 AknGlobalPopupPriorityController::AddSubPopupL(*this, *iCba->ButtonGroup()->AsControl()); |
|
638 AknGlobalPopupPriorityController::AddPopupToControlStackL(*iCba->ButtonGroup()->AsControl(), |
|
639 ECoeStackPriorityCba, ECoeStackFlagRefusesFocus ); |
|
640 iCba->DrawDeferred(); |
|
641 } |
|
642 |
|
643 // Data |
|
644 private: |
|
645 CAknChoiceListPopupList* iList; |
|
646 CEikButtonGroupContainer* iCba; |
|
647 TInt iIndex; |
|
648 TBool iIsDisplayed; |
|
649 CAknsFrameBackgroundControlContext* iBgContext; |
|
650 TBool iCancelled; |
|
651 }; |
|
652 |
|
653 // -------------------------------------------------------------------------- |
|
654 // Two-phased constructor. |
|
655 // -------------------------------------------------------------------------- |
|
656 // |
|
657 EXPORT_C CAknChoiceList* CAknChoiceList::NewL( CCoeControl* aParent, |
|
658 CDesCArray* aItemArray, TInt aFlags, CAknButton* aButton ) |
|
659 { |
|
660 _AKNTRACE_FUNC_ENTER; |
|
661 CAknChoiceList* self = NewLC( aParent, aItemArray, aFlags, aButton ); |
|
662 CleanupStack::Pop( self ); |
|
663 _AKNTRACE_FUNC_EXIT; |
|
664 return self; |
|
665 } |
|
666 |
|
667 EXPORT_C CAknChoiceList* CAknChoiceList::NewLC( CCoeControl* aParent, |
|
668 CDesCArray* aItemArray, TInt aFlags, CAknButton* aButton ) |
|
669 { |
|
670 _AKNTRACE_FUNC_ENTER; |
|
671 CAknChoiceList* self = new (ELeave) CAknChoiceList; |
|
672 CleanupStack::PushL( self ); |
|
673 self->ConstructL( aParent, aItemArray, aFlags, aButton ); |
|
674 AKNTASHOOK_ADDL( self, "CAknChoiceList" ); |
|
675 _AKNTRACE_FUNC_EXIT; |
|
676 return self; |
|
677 } |
|
678 |
|
679 // -------------------------------------------------------------------------- |
|
680 // default constructor. |
|
681 // -------------------------------------------------------------------------- |
|
682 // |
|
683 CAknChoiceList::CAknChoiceList() : |
|
684 iSelectedIndex( 0 ), |
|
685 iIsClosed( ETrue ), |
|
686 iTooltipWaitInterval( KTimeoutBeforeTooltipNote ), |
|
687 iTooltipInViewInterval( KTimeoutInViewTooltipNote ), |
|
688 iTooltipPosition( EPositionTop ) |
|
689 { |
|
690 } |
|
691 |
|
692 // -------------------------------------------------------------------------- |
|
693 // default destructor. |
|
694 // -------------------------------------------------------------------------- |
|
695 // |
|
696 CAknChoiceList::~CAknChoiceList() |
|
697 { |
|
698 _AKNTRACE_FUNC_ENTER; |
|
699 AKNTASHOOK_REMOVE(); |
|
700 if ( !iIsClosed ) |
|
701 { |
|
702 HideChoiceList(); |
|
703 } |
|
704 |
|
705 delete iButton; |
|
706 delete iLabel; |
|
707 |
|
708 if( iArray ) |
|
709 { |
|
710 iArray->Reset(); |
|
711 } |
|
712 delete iArray; |
|
713 delete iPopup; |
|
714 delete iTooltipText; |
|
715 delete iTooltip; |
|
716 _AKNTRACE_FUNC_EXIT; |
|
717 } |
|
718 |
|
719 // -------------------------------------------------------------------------- |
|
720 // CAknChoiceList::ConstructL |
|
721 // -------------------------------------------------------------------------- |
|
722 // |
|
723 void CAknChoiceList::ConstructL( CCoeControl* aParent, |
|
724 CDesCArray* aItemArray, TInt aFlags, CAknButton* aButton ) |
|
725 { |
|
726 _AKNTRACE_FUNC_ENTER; |
|
727 if ( ! iTooltip ) |
|
728 { |
|
729 iTooltip = CAknInfoPopupNoteController::NewL(); |
|
730 } |
|
731 |
|
732 iTooltip->SetTimeDelayBeforeShow( iTooltipWaitInterval ); |
|
733 iTooltip->SetTimePopupInView( iTooltipInViewInterval ); |
|
734 iTooltip->SetTooltipModeL( ETrue ); |
|
735 |
|
736 iFlags = aFlags; |
|
737 SetContainerWindowL( *aParent ); |
|
738 |
|
739 iPopup = new (ELeave) CAknChoiceListPopup; |
|
740 iPopup->ConstructL(); |
|
741 iPopup->SetObserver( this ); |
|
742 |
|
743 iArray = aItemArray; |
|
744 |
|
745 // Check here which type of choice list is used and construct them properly |
|
746 if ( iFlags & EAknChoiceListWithoutCurrentSelection ) |
|
747 { |
|
748 SetButtonL( aButton ); |
|
749 } |
|
750 else if ( iFlags & EAknChoiceListWithCurrentSelection ) |
|
751 { |
|
752 ConstructTypicalChoiceListL(); |
|
753 } |
|
754 |
|
755 SetComponentsToInheritVisibility( ETrue ); |
|
756 _AKNTRACE_FUNC_EXIT; |
|
757 } |
|
758 |
|
759 // -------------------------------------------------------------------------- |
|
760 // CAknChoiceList::SizeChanged |
|
761 // -------------------------------------------------------------------------- |
|
762 // |
|
763 void CAknChoiceList::SizeChanged() |
|
764 { |
|
765 _AKNTRACE_FUNC_ENTER; |
|
766 if ( iFlags & EAknChoiceListWithCurrentSelection ) |
|
767 { |
|
768 |
|
769 TAknWindowLineLayout layout = AknLayoutScalable_Avkon::choice_list_pane().LayoutLine(); |
|
770 |
|
771 // width is taken from given rect, height is fixed value from layout data |
|
772 iSize = TSize( Size().iWidth, layout.iH ); |
|
773 TRect parent( Rect() ); |
|
774 |
|
775 AknLayoutUtils::LayoutLabel( |
|
776 iLabel, |
|
777 parent, |
|
778 AknLayoutScalable_Avkon::choice_list_pane_t1().LayoutLine() |
|
779 ); |
|
780 // Override font color |
|
781 if ( AknsUtils::AvkonSkinEnabled() ) |
|
782 { |
|
783 TRgb textColor; |
|
784 |
|
785 if ( AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), textColor, |
|
786 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG8) == KErrNone ) |
|
787 { |
|
788 TRAP_IGNORE( AknLayoutUtils::OverrideControlColorL( |
|
789 *iLabel, EColorLabelText, textColor) ); |
|
790 } |
|
791 } |
|
792 TAknLayoutRect buttonLayoutRect; |
|
793 buttonLayoutRect.LayoutRect( parent, AknLayoutScalable_Avkon::choice_list_pane_g1().LayoutLine() ); |
|
794 |
|
795 iButton->SetRect( buttonLayoutRect.Rect() ); |
|
796 } |
|
797 else if ( iFlags & EAknChoiceListWithoutCurrentSelection ) |
|
798 { |
|
799 iButton->SetRect( Rect() ); |
|
800 } |
|
801 |
|
802 // if Choice list is open then update it by opening and closing it. |
|
803 if ( !iIsClosed ) |
|
804 { |
|
805 SetPopupRect(); |
|
806 } |
|
807 } |
|
808 |
|
809 // -------------------------------------------------------------------------- |
|
810 // CAknChoiceList::Draw |
|
811 // -------------------------------------------------------------------------- |
|
812 // |
|
813 EXPORT_C void CAknChoiceList::Draw( const TRect& /*aRect*/ ) const |
|
814 { |
|
815 } |
|
816 |
|
817 EXPORT_C void CAknChoiceList::PositionChanged() |
|
818 { |
|
819 _AKNTRACE_FUNC_ENTER; |
|
820 CAknControl::PositionChanged(); |
|
821 _AKNTRACE_FUNC_EXIT; |
|
822 } |
|
823 |
|
824 // -------------------------------------------------------------------------- |
|
825 // CAknChoiceList::ComponentControl |
|
826 // -------------------------------------------------------------------------- |
|
827 // |
|
828 EXPORT_C CCoeControl* CAknChoiceList::ComponentControl( TInt aIndex ) const |
|
829 { |
|
830 switch ( aIndex ) |
|
831 { |
|
832 case 0: |
|
833 return (CCoeControl*)iButton; |
|
834 case 1: |
|
835 return (CCoeControl*)iLabel; |
|
836 default: |
|
837 return NULL; |
|
838 } |
|
839 |
|
840 } |
|
841 |
|
842 // -------------------------------------------------------------------------- |
|
843 // CAknChoiceList::CountComponentControls |
|
844 // -------------------------------------------------------------------------- |
|
845 // |
|
846 EXPORT_C TInt CAknChoiceList::CountComponentControls() const |
|
847 { |
|
848 TInt count = 1; // always button |
|
849 |
|
850 // If using the default type of choice list then using two controls inside this control |
|
851 if ( iFlags & EAknChoiceListWithCurrentSelection ) |
|
852 { |
|
853 count++; |
|
854 } |
|
855 |
|
856 return count; |
|
857 } |
|
858 |
|
859 // -------------------------------------------------------------------------- |
|
860 // CAknChoiceList::ShowChoiceList |
|
861 // -------------------------------------------------------------------------- |
|
862 // |
|
863 EXPORT_C TInt CAknChoiceList::ShowChoiceListL() |
|
864 { |
|
865 _AKNTRACE_FUNC_ENTER; |
|
866 if( !iIsClosed || iArray->Count() < 1 ) |
|
867 { |
|
868 _AKNTRACE("ShowChoiceListL: !iIsClosed or iArray->Count() < 1, return"); |
|
869 return KErrGeneral; |
|
870 } |
|
871 |
|
872 // Set choice list to opened mode |
|
873 iIsClosed = EFalse; |
|
874 iPopup->SetItemsL( *iArray ); |
|
875 SetSelectedIndex( iSelectedIndex ); |
|
876 SetPopupRect(); |
|
877 iPopup->OpenChoiceListL(); |
|
878 |
|
879 _AKNTRACE_FUNC_EXIT; |
|
880 return KErrNone; |
|
881 } |
|
882 |
|
883 // -------------------------------------------------------------------------- |
|
884 // CAknChoiceList::HideChoiceList |
|
885 // -------------------------------------------------------------------------- |
|
886 // |
|
887 EXPORT_C void CAknChoiceList::HideChoiceList() |
|
888 { |
|
889 iPopup->CloseChoiceList(); |
|
890 iIsClosed = ETrue; |
|
891 iSelectedIndex = iPopup->SelectedItem(); |
|
892 } |
|
893 |
|
894 // -------------------------------------------------------------------------- |
|
895 // CAknChoiceList::SetTooltipTextL |
|
896 // -------------------------------------------------------------------------- |
|
897 // |
|
898 EXPORT_C void CAknChoiceList::SetTooltipTextL( const TDesC& aText ) |
|
899 { |
|
900 _AKNTRACE("CAknChoiceList::SetTooltipTextL aText=%S", &aText); |
|
901 delete iTooltipText; |
|
902 iTooltipText = NULL; |
|
903 |
|
904 iTooltipText = aText.AllocL(); |
|
905 } |
|
906 |
|
907 // -------------------------------------------------------------------------- |
|
908 // CAknChoiceList::SetTooltipTimeouts |
|
909 // -------------------------------------------------------------------------- |
|
910 // |
|
911 EXPORT_C void CAknChoiceList::SetTooltipTimeouts( const TInt aBeforeTimeout, |
|
912 const TInt aInViewTimeout ) |
|
913 { |
|
914 if ( aBeforeTimeout >= 0 ) |
|
915 { |
|
916 iTooltipWaitInterval = aBeforeTimeout; |
|
917 } |
|
918 if ( aInViewTimeout >= 0 ) |
|
919 { |
|
920 iTooltipInViewInterval = aInViewTimeout; |
|
921 } |
|
922 iTooltip->SetTimeDelayBeforeShow( iTooltipWaitInterval ); |
|
923 iTooltip->SetTimePopupInView( iTooltipInViewInterval ); |
|
924 } |
|
925 |
|
926 // -------------------------------------------------------------------------- |
|
927 // CAknChoiceList::SetTooltipPosition |
|
928 // -------------------------------------------------------------------------- |
|
929 // |
|
930 EXPORT_C void CAknChoiceList::SetTooltipPosition( |
|
931 TTooltipPosition aPosition ) |
|
932 { |
|
933 iTooltipPosition = aPosition; |
|
934 } |
|
935 |
|
936 // -------------------------------------------------------------------------- |
|
937 // CAknChoiceList::SetButtonL |
|
938 // -------------------------------------------------------------------------- |
|
939 // |
|
940 EXPORT_C void CAknChoiceList::SetButtonL( CAknButton* aButton ) |
|
941 { |
|
942 if ( iButton ) |
|
943 { |
|
944 delete iButton; |
|
945 iButton = NULL; |
|
946 } |
|
947 |
|
948 iButton = aButton; |
|
949 iButton->SetObserver( this ); |
|
950 iButton->SetContainerWindowL( *this ); |
|
951 } |
|
952 |
|
953 // -------------------------------------------------------------------------- |
|
954 // CAknChoiceList::SetSelectedIndex |
|
955 // -------------------------------------------------------------------------- |
|
956 // |
|
957 EXPORT_C void CAknChoiceList::SetSelectedIndex( const TInt aIndex ) |
|
958 { |
|
959 _AKNTRACE_FUNC_ENTER; |
|
960 _AKNTRACE("SetSelectedIndex: aIndex=%d", aIndex); |
|
961 if ( !iArray ) |
|
962 { |
|
963 _AKNTRACE("SetSelectedIndex: no iArray, return"); |
|
964 return; |
|
965 } |
|
966 |
|
967 if ( aIndex >= -1 && aIndex < iArray->Count() ) |
|
968 { |
|
969 iSelectedIndex = aIndex; |
|
970 } |
|
971 else |
|
972 { |
|
973 iSelectedIndex = 0; |
|
974 } |
|
975 if ( !iIsClosed ) |
|
976 { |
|
977 iPopup->SetSelectedItem( iSelectedIndex ); |
|
978 } |
|
979 if ( iFlags & EAknChoiceListWithCurrentSelection ) |
|
980 { |
|
981 TRAP_IGNORE( UpdateLabelL() ); |
|
982 Window().Invalidate( iLabel->Rect() ); |
|
983 } |
|
984 |
|
985 SizeChanged(); |
|
986 _AKNTRACE_FUNC_EXIT; |
|
987 } |
|
988 |
|
989 // -------------------------------------------------------------------------- |
|
990 // CAknChoiceList::MinimumSize |
|
991 // -------------------------------------------------------------------------- |
|
992 // |
|
993 EXPORT_C TSize CAknChoiceList::MinimumSize() |
|
994 { |
|
995 TSize size; |
|
996 |
|
997 // Although if there's only a button then it's size is used. |
|
998 if ( iFlags & EAknChoiceListWithoutCurrentSelection ) |
|
999 { |
|
1000 size = iButton->MinimumSize(); |
|
1001 } |
|
1002 else |
|
1003 { |
|
1004 size = Size(); |
|
1005 } |
|
1006 |
|
1007 return size; |
|
1008 } |
|
1009 |
|
1010 // -------------------------------------------------------------------------- |
|
1011 // CAknChoiceList::HandleControlEvent |
|
1012 // -------------------------------------------------------------------------- |
|
1013 // |
|
1014 EXPORT_C void CAknChoiceList::HandleControlEventL( CCoeControl* aControl,TCoeEvent aEventType ) |
|
1015 { |
|
1016 _AKNTRACE_FUNC_ENTER; |
|
1017 if ( ( aControl == iButton || aControl == iLabel ) && aEventType == EEventStateChanged ) |
|
1018 { |
|
1019 if ( iIsClosed ) |
|
1020 { |
|
1021 ShowChoiceListL(); |
|
1022 } |
|
1023 } |
|
1024 // Popup is closed |
|
1025 else if ( !iIsClosed && aControl == iPopup && |
|
1026 ( aEventType == EEventStateChanged || aEventType == EEventRequestCancel ) ) |
|
1027 { |
|
1028 if( aEventType == EEventStateChanged ) |
|
1029 { |
|
1030 iSelectedIndex = iPopup->SelectedItem(); |
|
1031 SetSelectedIndex( iPopup->SelectedItem() ); |
|
1032 } |
|
1033 iIsClosed = ETrue; |
|
1034 |
|
1035 if ( Observer() ) |
|
1036 { |
|
1037 Observer()->HandleControlEventL( this, aEventType ); |
|
1038 } |
|
1039 } |
|
1040 _AKNTRACE_FUNC_EXIT; |
|
1041 } |
|
1042 |
|
1043 // -------------------------------------------------------------------------- |
|
1044 // CAknChoiceList::HandleResourceChange |
|
1045 // -------------------------------------------------------------------------- |
|
1046 // |
|
1047 EXPORT_C void CAknChoiceList::HandleResourceChange( TInt aType ) |
|
1048 { |
|
1049 _AKNTRACE_FUNC_ENTER; |
|
1050 CCoeControl::HandleResourceChange( aType ); |
|
1051 |
|
1052 if ( aType == KAknsMessageSkinChange ) |
|
1053 { |
|
1054 if ( !(iFlags & EAknChoiceListWithoutCurrentSelection) ) |
|
1055 { |
|
1056 // has to be done for button update |
|
1057 TRAP_IGNORE( ConstructTypicalChoiceListL() ); |
|
1058 } |
|
1059 // Item colors |
|
1060 iPopup->HandleResourceChange( aType ); |
|
1061 |
|
1062 // Label color |
|
1063 if ( AknsUtils::AvkonSkinEnabled() && iLabel ) |
|
1064 { |
|
1065 TRgb textColor; |
|
1066 |
|
1067 if ( AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), textColor, |
|
1068 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG8) == KErrNone ) |
|
1069 { |
|
1070 TRAP_IGNORE( |
|
1071 AknLayoutUtils::OverrideControlColorL( |
|
1072 *iLabel, EColorLabelText, textColor) ); |
|
1073 } |
|
1074 } |
|
1075 } |
|
1076 else if ( aType == KEikDynamicLayoutVariantSwitch ) |
|
1077 { |
|
1078 SizeChanged(); |
|
1079 } |
|
1080 _AKNTRACE_FUNC_EXIT; |
|
1081 } |
|
1082 |
|
1083 // -------------------------------------------------------------------------- |
|
1084 // CAknChoiceList::OfferKeyEventL |
|
1085 // -------------------------------------------------------------------------- |
|
1086 // |
|
1087 EXPORT_C TKeyResponse CAknChoiceList::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
1088 { |
|
1089 _AKNTRACE_FUNC_ENTER; |
|
1090 if ( aType == EEventKey ) |
|
1091 { |
|
1092 if ( iIsClosed && ( aKeyEvent.iScanCode == EStdKeyEnter || |
|
1093 aKeyEvent.iScanCode == EStdKeyDevice3 ) ) |
|
1094 { |
|
1095 ShowChoiceListL(); |
|
1096 return EKeyWasConsumed; |
|
1097 } |
|
1098 else if ( !iIsClosed ) |
|
1099 { |
|
1100 return iPopup->OfferKeyEventL( aKeyEvent, aType ); |
|
1101 } |
|
1102 return EKeyWasNotConsumed; |
|
1103 } |
|
1104 _AKNTRACE_FUNC_EXIT; |
|
1105 return EKeyWasNotConsumed; |
|
1106 } |
|
1107 |
|
1108 // -------------------------------------------------------------------------- |
|
1109 // CAknChoiceList::HandlePointerEventL |
|
1110 // -------------------------------------------------------------------------- |
|
1111 // |
|
1112 void CAknChoiceList::HandlePointerEventL( const TPointerEvent& aPointerEvent ) |
|
1113 { |
|
1114 _AKNTRACE_FUNC_ENTER; |
|
1115 CCoeControl::HandlePointerEventL( aPointerEvent ); |
|
1116 |
|
1117 if ( !AknLayoutUtils::PenEnabled() || !iLabel ) |
|
1118 { |
|
1119 return; |
|
1120 } |
|
1121 |
|
1122 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
1123 switch ( aPointerEvent.iType ) |
|
1124 { |
|
1125 case TPointerEvent::EButton1Down: |
|
1126 { |
|
1127 if ( feedback && iArray->Count() > 0 ) |
|
1128 { |
|
1129 feedback->InstantFeedback( |
|
1130 this, |
|
1131 ETouchFeedbackList, |
|
1132 aPointerEvent ); |
|
1133 } |
|
1134 if ( Rect().Contains( aPointerEvent.iPosition )) |
|
1135 { |
|
1136 ShowTooltipL(); |
|
1137 } |
|
1138 } |
|
1139 break; |
|
1140 |
|
1141 case TPointerEvent::EDrag: |
|
1142 { |
|
1143 if ( !Rect().Contains( aPointerEvent.iPosition )) |
|
1144 { |
|
1145 iTooltip->HideInfoPopupNote(); |
|
1146 } |
|
1147 } |
|
1148 break; |
|
1149 |
|
1150 case TPointerEvent::EButton1Up: |
|
1151 { |
|
1152 if ( feedback && iArray->Count() > 0 ) |
|
1153 { |
|
1154 if ( CAknTransitionUtils::TransitionsEnabled( |
|
1155 AknTransEffect::EComponentTransitionsOff ) ) |
|
1156 { |
|
1157 feedback->InstantFeedback( |
|
1158 this, |
|
1159 ETouchFeedbackIncreasingPopUp, |
|
1160 aPointerEvent ); |
|
1161 } |
|
1162 else |
|
1163 { |
|
1164 feedback->InstantFeedback( |
|
1165 this, |
|
1166 ETouchFeedbackPopUp, |
|
1167 aPointerEvent ); |
|
1168 } |
|
1169 } |
|
1170 iTooltip->HideInfoPopupNote(); |
|
1171 TRect ctrlArea = iLabel->Rect(); |
|
1172 if ( ctrlArea.Contains( aPointerEvent.iPosition )) |
|
1173 { |
|
1174 HandleControlEventL( iLabel, EEventStateChanged ); |
|
1175 } |
|
1176 } |
|
1177 break; |
|
1178 } |
|
1179 _AKNTRACE_FUNC_EXIT; |
|
1180 } |
|
1181 |
|
1182 // -------------------------------------------------------------------------- |
|
1183 // CAknChoiceList::SelectedIndex |
|
1184 // -------------------------------------------------------------------------- |
|
1185 // |
|
1186 EXPORT_C TInt CAknChoiceList::SelectedIndex() const |
|
1187 { |
|
1188 return iSelectedIndex; |
|
1189 } |
|
1190 |
|
1191 // -------------------------------------------------------------------------- |
|
1192 // CAknChoiceList::SetItems |
|
1193 // -------------------------------------------------------------------------- |
|
1194 // |
|
1195 EXPORT_C void CAknChoiceList::SetItems( CDesCArray* aArray ) |
|
1196 { |
|
1197 if ( iArray && aArray && iArray != aArray ) |
|
1198 { |
|
1199 iArray->Reset(); |
|
1200 delete iArray; |
|
1201 iArray = NULL; |
|
1202 } |
|
1203 iArray = aArray; |
|
1204 TRAP_IGNORE( iPopup->SetItemsL( *iArray ) ); |
|
1205 |
|
1206 if ( !iIsClosed ) |
|
1207 { |
|
1208 if ( iArray && iArray->Count() > 0 ) |
|
1209 { |
|
1210 SetPopupRect(); |
|
1211 } |
|
1212 else |
|
1213 { |
|
1214 HideChoiceList(); |
|
1215 } |
|
1216 } |
|
1217 SetSelectedIndex( 0 ); |
|
1218 } |
|
1219 |
|
1220 // -------------------------------------------------------------------------- |
|
1221 // CAknChoiceList::SetItems |
|
1222 // -------------------------------------------------------------------------- |
|
1223 // |
|
1224 EXPORT_C void CAknChoiceList::SetItemsL( TInt aResourceId ) |
|
1225 { |
|
1226 TResourceReader reader; |
|
1227 CCoeEnv::Static()->CreateResourceReaderLC( reader, aResourceId ); |
|
1228 CDesCArray* array; |
|
1229 array = reader.ReadDesC16ArrayL(); |
|
1230 iSelectedIndex = 0; |
|
1231 |
|
1232 CleanupStack::PopAndDestroy(); // reader |
|
1233 |
|
1234 if ( iArray ) |
|
1235 { |
|
1236 iArray->Reset(); |
|
1237 delete iArray; |
|
1238 iArray = NULL; |
|
1239 } |
|
1240 iArray = array; |
|
1241 iPopup->SetItemsL( *iArray ); |
|
1242 |
|
1243 if ( !iIsClosed ) |
|
1244 { |
|
1245 if ( iArray->Count() > 0 ) |
|
1246 { |
|
1247 SetPopupRect(); |
|
1248 } |
|
1249 else |
|
1250 { |
|
1251 HideChoiceList(); |
|
1252 } |
|
1253 } |
|
1254 SetSelectedIndex( 0 ); |
|
1255 } |
|
1256 |
|
1257 |
|
1258 |
|
1259 // -------------------------------------------------------------------------- |
|
1260 // CAknChoiceList::AddItemL |
|
1261 // -------------------------------------------------------------------------- |
|
1262 // |
|
1263 EXPORT_C TInt CAknChoiceList::AddItemL( const TDesC* aDesC ) |
|
1264 { |
|
1265 _AKNTRACE("CAknChoiceList::AddItemL: aDesC=%S", aDesC); |
|
1266 iArray->AppendL( *aDesC ); |
|
1267 iPopup->SetItemsL( *iArray ); |
|
1268 |
|
1269 if ( !iIsClosed ) |
|
1270 { |
|
1271 SetPopupRect(); |
|
1272 } |
|
1273 UpdateLabelL(); |
|
1274 TInt index = iArray->Count() - 1; // return new items index |
|
1275 return index; |
|
1276 } |
|
1277 |
|
1278 // -------------------------------------------------------------------------- |
|
1279 // CAknChoiceList::RemoveItem |
|
1280 // -------------------------------------------------------------------------- |
|
1281 // |
|
1282 EXPORT_C void CAknChoiceList::RemoveItem( const TInt aIndex ) |
|
1283 { |
|
1284 _AKNTRACE("CAknChoiceList::RemoveItem: aIndex=%d", aIndex); |
|
1285 // if the choice list is open then just return. |
|
1286 |
|
1287 if( aIndex < iArray->Count() && aIndex >= 0 ) |
|
1288 { |
|
1289 iArray->Delete( aIndex ); |
|
1290 if ( aIndex <= iSelectedIndex && iSelectedIndex > -1 ) |
|
1291 { |
|
1292 iSelectedIndex--; |
|
1293 } |
|
1294 SetSelectedIndex( iSelectedIndex ); |
|
1295 } |
|
1296 |
|
1297 if ( !iIsClosed ) |
|
1298 { |
|
1299 if ( iArray->Count() > 0 ) |
|
1300 { |
|
1301 TRAP_IGNORE( iPopup->SetItemsL( *iArray ) ); |
|
1302 SetPopupRect(); |
|
1303 } |
|
1304 else |
|
1305 { |
|
1306 HideChoiceList(); |
|
1307 } |
|
1308 } |
|
1309 |
|
1310 } |
|
1311 |
|
1312 // -------------------------------------------------------------------------- |
|
1313 // CAknChoiceList::SetFlags |
|
1314 // -------------------------------------------------------------------------- |
|
1315 // |
|
1316 EXPORT_C void CAknChoiceList::SetFlags( const TInt aFlags ) |
|
1317 { |
|
1318 // List type must be remained if not inculed in aFlags |
|
1319 if ( !( aFlags & EAknChoiceListWithCurrentSelection )&& |
|
1320 !( aFlags & EAknChoiceListWithoutCurrentSelection ) ) |
|
1321 { |
|
1322 if ( iFlags & EAknChoiceListWithCurrentSelection ) |
|
1323 { |
|
1324 iFlags = aFlags | EAknChoiceListWithCurrentSelection; |
|
1325 } |
|
1326 else |
|
1327 { |
|
1328 iFlags = aFlags | EAknChoiceListWithoutCurrentSelection; |
|
1329 } |
|
1330 } |
|
1331 else |
|
1332 { |
|
1333 iFlags = aFlags; |
|
1334 } |
|
1335 } |
|
1336 |
|
1337 // -------------------------------------------------------------------------- |
|
1338 // CAknChoiceList::Flags |
|
1339 // -------------------------------------------------------------------------- |
|
1340 // |
|
1341 EXPORT_C TInt CAknChoiceList::Flags() const |
|
1342 { |
|
1343 return iFlags; |
|
1344 } |
|
1345 |
|
1346 // -------------------------------------------------------------------------- |
|
1347 // CAknChoiceList::InsertItemL |
|
1348 // -------------------------------------------------------------------------- |
|
1349 // |
|
1350 EXPORT_C TInt CAknChoiceList::InsertItemL( TInt aIndex, const TDesC& aText ) |
|
1351 { |
|
1352 ASSERT( iArray ); |
|
1353 if ( aIndex >= 0 && aIndex <= iArray->Count() ) |
|
1354 { |
|
1355 iArray->InsertL( aIndex, aText ); |
|
1356 if ( aIndex <= iSelectedIndex ) |
|
1357 { |
|
1358 SetSelectedIndex( ++iSelectedIndex ); |
|
1359 } |
|
1360 } |
|
1361 else |
|
1362 { |
|
1363 aIndex = iArray->Count(); |
|
1364 iArray->InsertL( aIndex, aText ); |
|
1365 } |
|
1366 iPopup->SetItemsL( *iArray ); |
|
1367 if ( !iIsClosed ) |
|
1368 { |
|
1369 SetPopupRect(); |
|
1370 } |
|
1371 return aIndex; |
|
1372 } |
|
1373 |
|
1374 // -------------------------------------------------------------------------- |
|
1375 // CAknChoiceList::ConstructTypicalChoiceListL |
|
1376 // -------------------------------------------------------------------------- |
|
1377 // |
|
1378 void CAknChoiceList::ConstructTypicalChoiceListL() |
|
1379 { |
|
1380 CGulIcon* icon = AknsUtils::CreateGulIconL( AknsUtils::SkinInstance(), |
|
1381 KAknsIIDQgnPropSetButton, |
|
1382 AknIconUtils::AvkonIconFileName(), |
|
1383 EMbmAvkonQgn_prop_set_button, |
|
1384 EMbmAvkonQgn_prop_set_button_mask ); |
|
1385 |
|
1386 |
|
1387 CAknButton* button = CAknButton::NewL( |
|
1388 icon, |
|
1389 NULL, |
|
1390 NULL, |
|
1391 NULL, |
|
1392 KNullDesC, |
|
1393 KNullDesC, |
|
1394 KAknButtonNoFrame, |
|
1395 0 |
|
1396 ); |
|
1397 |
|
1398 SetButtonL( button ); |
|
1399 SetSelectedIndex( iSelectedIndex ); |
|
1400 } |
|
1401 |
|
1402 // -------------------------------------------------------------------------- |
|
1403 // CAknChoiceList::SetPopupRect |
|
1404 // -------------------------------------------------------------------------- |
|
1405 // |
|
1406 void CAknChoiceList::SetPopupRect() |
|
1407 { |
|
1408 TInt numItems( iArray->Count() ); |
|
1409 if ( numItems == 0 ) |
|
1410 { |
|
1411 return; |
|
1412 } |
|
1413 |
|
1414 // height must be adjusted. Max variety is 5 (6 visible items) |
|
1415 if ( numItems > 6 ) |
|
1416 { |
|
1417 numItems = 6; |
|
1418 } |
|
1419 |
|
1420 TAknWindowComponentLayout window = AknLayoutScalable_Avkon:: |
|
1421 popup_choice_list_window( numItems - 1 ); |
|
1422 |
|
1423 TAknWindowLineLayout layout = window.LayoutLine(); |
|
1424 |
|
1425 TInt height( layout.iH ); |
|
1426 TInt width; |
|
1427 |
|
1428 width = Size().iWidth; |
|
1429 |
|
1430 TPoint position; |
|
1431 |
|
1432 // allowed rect |
|
1433 TRect clientRect; |
|
1434 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, clientRect ); |
|
1435 |
|
1436 if ( iFlags & EAknChoiceListPositionLeft ) |
|
1437 { |
|
1438 position = TPoint( PositionRelativeToScreen() - TPoint( width, 0 ) ); |
|
1439 } |
|
1440 else if ( iFlags & EAknChoiceListPositionRight ) |
|
1441 { |
|
1442 position = TPoint( PositionRelativeToScreen() + TPoint( width, 0 ) ); |
|
1443 } |
|
1444 else if ( iFlags & EAknChoiceListPositionBottom )// bottom |
|
1445 { |
|
1446 position = TPoint( PositionRelativeToScreen() + TPoint(0, Size().iHeight ) ); |
|
1447 } |
|
1448 else // with current selection locate popup on top of the area |
|
1449 { |
|
1450 position = TPoint( PositionRelativeToScreen() - TPoint(0, height ) ); |
|
1451 } |
|
1452 |
|
1453 // Horizontal check, readjusted if needed. |
|
1454 if ( position.iX < clientRect.iTl.iX ) |
|
1455 { |
|
1456 position.iX = clientRect.iTl.iX; |
|
1457 } |
|
1458 else if ( ( position.iX + width ) > clientRect.iBr.iX ) |
|
1459 { |
|
1460 position.iX = clientRect.iBr.iX - width; |
|
1461 } |
|
1462 |
|
1463 // Vertical check, readjusted if needed. |
|
1464 if ( position.iY < clientRect.iTl.iY ) |
|
1465 { |
|
1466 position.iY = clientRect.iTl.iY; |
|
1467 } |
|
1468 else if ( ( position.iY + height ) > clientRect.iBr.iY ) |
|
1469 { |
|
1470 position.iY = clientRect.iBr.iY - height; |
|
1471 } |
|
1472 TRect old (iPopup->Rect() ); |
|
1473 iPopup->SetPopupSizeAndLocation( TRect( position, TSize( width, height ) ) ); |
|
1474 Window().Invalidate( old ); |
|
1475 } |
|
1476 |
|
1477 // -------------------------------------------------------------------------- |
|
1478 // CAknChoiceList::UpdateLabelL |
|
1479 // -------------------------------------------------------------------------- |
|
1480 // |
|
1481 void CAknChoiceList::UpdateLabelL() |
|
1482 { |
|
1483 if ( !iFlags & EAknChoiceListWithCurrentSelection ) |
|
1484 { |
|
1485 return; |
|
1486 } |
|
1487 if ( !iLabel ) |
|
1488 { |
|
1489 iLabel = new (ELeave) CEikLabel; |
|
1490 iLabel->SetContainerWindowL( *this ); |
|
1491 |
|
1492 // Set font |
|
1493 TAknTextComponentLayout labelLayout = |
|
1494 AknLayoutScalable_Avkon::choice_list_pane_t1(); |
|
1495 iLabel->SetFont( AknLayoutUtils::FontFromId( labelLayout.Font() ) ); |
|
1496 |
|
1497 // Set font color |
|
1498 if ( AknsUtils::AvkonSkinEnabled() ) |
|
1499 { |
|
1500 TRgb textColor; |
|
1501 |
|
1502 if ( AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), textColor, |
|
1503 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG8) == KErrNone ) |
|
1504 { |
|
1505 TRAP_IGNORE( AknLayoutUtils::OverrideControlColorL( |
|
1506 *iLabel, EColorLabelText, textColor) ); |
|
1507 } |
|
1508 } |
|
1509 } |
|
1510 |
|
1511 if ( iSelectedIndex >= 0 && iArray->Count() > 0 ) |
|
1512 { |
|
1513 TPtrC text = iArray->MdcaPoint( iSelectedIndex ); |
|
1514 if ( &text ) |
|
1515 { |
|
1516 iLabel->SetTextL( text ); |
|
1517 } |
|
1518 } |
|
1519 else if ( iSelectedIndex == -1 || iArray->Count() == 0 ) |
|
1520 { |
|
1521 iLabel->SetTextL( KNullDesC ); |
|
1522 } |
|
1523 else |
|
1524 { |
|
1525 iSelectedIndex = 0; |
|
1526 UpdateLabelL(); |
|
1527 } |
|
1528 } |
|
1529 |
|
1530 // -------------------------------------------------------------------------- |
|
1531 // CAknChoiceList::ShowTooltipL |
|
1532 // -------------------------------------------------------------------------- |
|
1533 // |
|
1534 void CAknChoiceList::ShowTooltipL() |
|
1535 { |
|
1536 if ( !iTooltipText || (iTooltipText->Length() <= 0 )) |
|
1537 { |
|
1538 return; |
|
1539 } |
|
1540 iTooltip->SetTextL( *iTooltipText ); |
|
1541 |
|
1542 |
|
1543 // Position the tooltip |
|
1544 TPoint position; |
|
1545 |
|
1546 if ( AknsUtils::GetControlPosition( this, position ) != KErrNone ) |
|
1547 { |
|
1548 position = PositionRelativeToScreen(); |
|
1549 } |
|
1550 |
|
1551 TRect rect( position, Size() ); |
|
1552 TPoint center = rect.Center(); |
|
1553 |
|
1554 switch ( iTooltipPosition ) |
|
1555 { |
|
1556 case EPositionTop: |
|
1557 { |
|
1558 iTooltip->SetPositionAndAlignment( |
|
1559 TPoint( center.iX, rect.iTl.iY ), EHCenterVBottom ); |
|
1560 break; |
|
1561 } |
|
1562 case EPositionBottom: |
|
1563 { |
|
1564 iTooltip->SetPositionAndAlignment( |
|
1565 TPoint( center.iX, rect.iBr.iY ), EHCenterVTop ); |
|
1566 break; |
|
1567 } |
|
1568 case EPositionLeft: |
|
1569 { |
|
1570 iTooltip->SetPositionAndAlignment( |
|
1571 TPoint( rect.iTl.iX, center.iY ), EHRightVCenter ); |
|
1572 break; |
|
1573 } |
|
1574 case EPositionRight: |
|
1575 { |
|
1576 iTooltip->SetPositionAndAlignment( |
|
1577 TPoint( rect.iBr.iX, center.iY ), EHLeftVCenter ); |
|
1578 break; |
|
1579 } |
|
1580 default: |
|
1581 { |
|
1582 return; |
|
1583 } |
|
1584 } |
|
1585 iTooltip->ShowInfoPopupNote(); |
|
1586 } |
|
1587 // End of File |