|
1 /******************************************************************************* |
|
2 * Copyright (c) 2005, 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. This program and the accompanying materials |
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
|
5 * which accompanies this distribution, and is available at |
|
6 * http://www.eclipse.org/legal/epl-v10.html |
|
7 * |
|
8 * Contributors: |
|
9 * Nokia Corporation - S60 implementation |
|
10 *******************************************************************************/ |
|
11 |
|
12 |
|
13 #include <eikenv.h> |
|
14 #include <aknenv.h> |
|
15 #include <eikclbd.h> |
|
16 #include <gulicon.h> |
|
17 #include <AknUtils.h> |
|
18 #include <aknappui.h> |
|
19 #include <avkon.mbg> |
|
20 #include <aknconsts.h> |
|
21 #ifdef RD_UI_TRANSITION_EFFECTS_LIST |
|
22 #include <aknlistloadertfx.h> |
|
23 #include <aknlistboxtfx.h> |
|
24 #endif // RD_UI_TRANSITION_EFFECTS_LIST |
|
25 #include <swtlaffacade.h> |
|
26 #include "eswtmobileextensions.h" |
|
27 #include "swtfont.h" |
|
28 #include "swtlistbase.h" |
|
29 |
|
30 |
|
31 _LIT(KTextTab, "\t"); |
|
32 const TInt KCheckBoxOffIndex = 1; |
|
33 const TInt KCheckBoxOnIndex = 0; |
|
34 const TUint KIconIndexLengthMax = 1; |
|
35 const TInt KVBorderSides = 2; |
|
36 const TInt KHBorderSides = 2; |
|
37 |
|
38 |
|
39 // ======== MEMBER FUNCTIONS ======== |
|
40 |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // CSwtListBase::CreateListBoxL |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CEikTextListBox* CSwtListBase::CreateListBoxL(TInt aStyle) |
|
47 { |
|
48 iListType = (aStyle & KSwtStyleMulti) ? ESwtLbSingleGraphic : ESwtLbSingle; |
|
49 |
|
50 CEikTextListBox* listBox = CSwtListBoxLists::NewListL(iListType); |
|
51 CSwtListBoxLists::SetListObserver(iListType, listBox, this); |
|
52 |
|
53 |
|
54 CleanupStack::PushL(listBox); |
|
55 listBox->ConstructL(this, (iStyle & KSwtStyleMulti) ? |
|
56 EAknListBoxStylusMultiselectionList : EAknListBoxSelectionList); |
|
57 |
|
58 #ifdef RD_UI_TRANSITION_EFFECTS_LIST |
|
59 // Effects do not work with non window owning scrollbars. |
|
60 CWindowGc* gc = listBox->View()->ItemDrawer()->Gc(); |
|
61 MAknListBoxTfx* transApi = CAknListLoader::TfxApi(gc); |
|
62 if (transApi) |
|
63 { |
|
64 transApi->EnableEffects(EFalse); |
|
65 } |
|
66 #endif // RD_UI_TRANSITION_EFFECTS_LIST |
|
67 |
|
68 listBox->SetContainerWindowL(*this); |
|
69 listBox->SetCurrentItemIndex(0); |
|
70 listBox->MakeVisible(ETrue); |
|
71 listBox->SetComponentsToInheritVisibility(); |
|
72 static_cast<CEikColumnListBox*>(listBox)->ItemDrawer()->ColumnData()->SetSkinEnabledL(EFalse); |
|
73 #ifdef RD_SCALABLE_UI_V2 |
|
74 listBox->SetListBoxObserver(this); |
|
75 #endif // RD_SCALABLE_UI_V2 |
|
76 CleanupStack::Pop(listBox); |
|
77 |
|
78 return listBox; |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // CSwtListBase::CreateListBoxModelL |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 void CSwtListBase::CreateListBoxModelL() |
|
86 { |
|
87 iTextItems = new(ELeave) CDesCArrayFlat(3); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // CSwtListBase::CreateScrollBarsL |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 void CSwtListBase::CreateScrollBarsL(CEikTextListBox* aLb) |
|
95 { |
|
96 ASSERT(aLb); |
|
97 aLb->CreateScrollBarFrameL(); |
|
98 |
|
99 #ifdef RD_SCALABLE_UI_V2 |
|
100 // WARNING!!! The expanded touch area does not move correctly togehter with the scrollbars! |
|
101 aLb->ScrollBarFrame()->SetScrollBarFrameFlags(CEikScrollBarFrame::EDisableExpandedTouchArea); |
|
102 #endif // RD_SCALABLE_UI_V2 |
|
103 |
|
104 // In eSWT all scrollbars must be non window owing the main reason being that |
|
105 // the scrollbars must draw at exact same time with the parent control. This |
|
106 // is especially essential in ScrolledComposite. If the scrollbars would be |
|
107 // window owing, they would draw too much ahead of the parents creating an |
|
108 // ugly visual effect when flicking the ScrolledComposite. |
|
109 // The drawback of having non window owing scrollbars is too many paint events |
|
110 // which affects on the speed of kinetic scrolling in lists. |
|
111 aLb->ScrollBarFrame()->CreateDoubleSpanScrollBarsL(EFalse, EFalse, ETrue, EFalse); |
|
112 aLb->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
113 CEikScrollBarFrame::EOff, |
|
114 iStyle & KSwtStyleVScroll ? |
|
115 CEikScrollBarFrame::EOn : CEikScrollBarFrame::EOff); |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // CSwtListBase::CreateIconArrayL |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 void CSwtListBase::CreateIconArrayL(CEikTextListBox* aLb) |
|
123 { |
|
124 ASSERT(aLb); |
|
125 |
|
126 // Create icon array |
|
127 CArrayPtr<CGulIcon>* icons = new(ELeave)CArrayPtrFlat<CGulIcon>(2); |
|
128 CleanupStack::PushL(icons); |
|
129 |
|
130 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
131 |
|
132 // Check box on |
|
133 CFbsBitmap* bmp = NULL; |
|
134 CFbsBitmap* mask = NULL; |
|
135 CGulIcon* checkBox = NULL; |
|
136 AknsUtils::CreateIconLC(AknsUtils::SkinInstance(), |
|
137 KAknsIIDQgnPropCheckboxOn, bmp, mask, |
|
138 AknIconUtils::AvkonIconFileName(), |
|
139 EMbmAvkonQgn_prop_checkbox_on, |
|
140 EMbmAvkonQgn_prop_checkbox_on_mask); |
|
141 checkBox = CGulIcon::NewL(bmp, mask); |
|
142 CleanupStack::PushL(checkBox); |
|
143 icons->AppendL(checkBox); |
|
144 CleanupStack::Pop(3); // bmp, mask, checkbox |
|
145 |
|
146 // Check box off |
|
147 bmp = NULL; |
|
148 mask = NULL; |
|
149 checkBox = NULL; |
|
150 AknsUtils::CreateIconLC(AknsUtils::SkinInstance(), |
|
151 KAknsIIDQgnPropCheckboxOff, bmp, mask, |
|
152 AknIconUtils::AvkonIconFileName(), |
|
153 EMbmAvkonQgn_prop_checkbox_off, |
|
154 EMbmAvkonQgn_prop_checkbox_off_mask); |
|
155 checkBox = CGulIcon::NewL(bmp, mask); |
|
156 CleanupStack::PushL(checkBox); |
|
157 icons->AppendL(checkBox); |
|
158 CleanupStack::Pop(3); // bmp, mask, checkbox |
|
159 |
|
160 CleanupStack::Pop(icons); |
|
161 |
|
162 // Set icon array |
|
163 CColumnListBoxData* listBoxData = static_cast<CEikColumnListBox*>(aLb)->ItemDrawer()->ColumnData(); |
|
164 if (listBoxData->IconArray()) |
|
165 { |
|
166 listBoxData->IconArray()->ResetAndDestroy(); |
|
167 delete listBoxData->IconArray(); |
|
168 } |
|
169 listBoxData->SetIconArray(icons); |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // CSwtListBase::CreateItemTextLC |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 HBufC* CSwtListBase::CreateItemTextLC( |
|
177 const TDesC& aPtr, |
|
178 TBool aSelected) |
|
179 { |
|
180 // Allocate memory for the resut string. |
|
181 TInt textLength = aPtr.Length() + KTextTab().Length(); |
|
182 if (iStyle & KSwtStyleMulti) |
|
183 { |
|
184 textLength += KIconIndexLengthMax; |
|
185 } |
|
186 HBufC* textBuf = HBufC::NewLC(textLength); |
|
187 TPtr itemText(textBuf->Des()); |
|
188 itemText.Zero(); |
|
189 if (iStyle & KSwtStyleMulti) |
|
190 { |
|
191 itemText.AppendNum(aSelected?KCheckBoxOnIndex:KCheckBoxOffIndex); |
|
192 } |
|
193 itemText.Append(KTextTab); |
|
194 itemText.Append(aPtr); |
|
195 |
|
196 return textBuf; |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // CSwtListBase::UpdateSize |
|
201 // --------------------------------------------------------------------------- |
|
202 // |
|
203 void CSwtListBase::UpdateSize() |
|
204 { |
|
205 ASSERT(iList); |
|
206 ASSERT(iList->Model()); |
|
207 |
|
208 iList->SetSize(BorderInnerRect().Size()); |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // CSwtListBase::UpdateListBoxFontL |
|
213 // --------------------------------------------------------------------------- |
|
214 // |
|
215 void CSwtListBase::UpdateListBoxFontL() |
|
216 { |
|
217 ASSERT(iList); |
|
218 |
|
219 CColumnListBoxItemDrawer* itemDrawer = static_cast<CEikColumnListBox*>(iList)->ItemDrawer(); |
|
220 ASSERT(itemDrawer); |
|
221 CColumnListBoxData* listBoxData = itemDrawer->ColumnData(); |
|
222 ASSERT(listBoxData); |
|
223 |
|
224 // If a font has been set, apply it to the Avkon list. Its item height is also modified. |
|
225 if (iFont) |
|
226 { |
|
227 TInt newItemHeight( |
|
228 iDefaultItemHeight + |
|
229 (iFont->Font().HeightInPixels() - DefaultFont().Font().HeightInPixels())); |
|
230 newItemHeight = Max(iDefaultItemHeight, newItemHeight); |
|
231 iList->SetItemHeightL(newItemHeight); |
|
232 listBoxData->SetColumnFontL(KTextColumnIndex, &iFont->Font()); |
|
233 listBoxData->SetColumnBaselinePosL(KTextColumnIndex, 0); |
|
234 } |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // CSwtListBase::UpdateListBoxTextColorL |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 void CSwtListBase::UpdateListBoxTextColorL() |
|
242 { |
|
243 ASSERT(iList); |
|
244 |
|
245 // If a text color has been set, apply it to the Avkon list. |
|
246 if (iTextColor) |
|
247 { |
|
248 static_cast<CEikColumnListBox*>(iList)->ItemDrawer()->SetTextColor( |
|
249 TRgb(iTextColor->RgbValue())); |
|
250 } |
|
251 // If no color set, then the default color is retrieved |
|
252 // from the current skin and applied to the Avkon list. |
|
253 else |
|
254 { |
|
255 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
256 TRgb defaultColor; |
|
257 TInt error = AknsUtils::GetCachedColor( |
|
258 skin, |
|
259 defaultColor, |
|
260 KAknsIIDQsnTextColors, |
|
261 EAknsCIQsnTextColorsCG6); |
|
262 |
|
263 if (!error) |
|
264 { |
|
265 static_cast<CEikColumnListBox*>(iList)->ItemDrawer()->SetTextColor(defaultColor); |
|
266 } |
|
267 } |
|
268 } |
|
269 |
|
270 // --------------------------------------------------------------------------- |
|
271 // CSwtListBase::Scrollable |
|
272 // --------------------------------------------------------------------------- |
|
273 // |
|
274 MSwtScrollable* CSwtListBase::Scrollable() |
|
275 { |
|
276 return this; |
|
277 } |
|
278 |
|
279 // --------------------------------------------------------------------------- |
|
280 // CSwtListBase::DeselectItems |
|
281 // --------------------------------------------------------------------------- |
|
282 // |
|
283 void CSwtListBase::DeselectItems( |
|
284 const TInt* aIndices, |
|
285 TInt aCount) |
|
286 { |
|
287 ASSERT(iList); |
|
288 ASSERT(iList->View()); |
|
289 |
|
290 if (aIndices) |
|
291 { |
|
292 for (TInt i = 0; i < aCount; i++) |
|
293 { |
|
294 iList->View()->DeselectItem(aIndices[i]); |
|
295 } |
|
296 } |
|
297 TRAP_IGNORE(UpdateListMskL()); |
|
298 } |
|
299 |
|
300 // --------------------------------------------------------------------------- |
|
301 // CSwtListBase::DeselectItem |
|
302 // --------------------------------------------------------------------------- |
|
303 // |
|
304 void CSwtListBase::DeselectItem(const TInt aIndex) |
|
305 { |
|
306 ASSERT(iList); |
|
307 ASSERT(iList->Model()); |
|
308 ASSERT(iList->View()); |
|
309 |
|
310 if (iList->Model()->NumberOfItems() == 0 |
|
311 || iList->SelectionIndexes()->Count() == 0) |
|
312 { |
|
313 return; |
|
314 } |
|
315 |
|
316 iList->View()->DeselectItem(aIndex); |
|
317 TRAP_IGNORE(UpdateListMskL()); |
|
318 } |
|
319 |
|
320 // --------------------------------------------------------------------------- |
|
321 // CSwtListBase::DeselectRange |
|
322 // --------------------------------------------------------------------------- |
|
323 // |
|
324 void CSwtListBase::DeselectRange(TInt aStart, TInt aEnd) |
|
325 { |
|
326 ASSERT(iList); |
|
327 ASSERT(iList->Model()); |
|
328 ASSERT(iList->View()); |
|
329 |
|
330 TInt count = iList->Model()->NumberOfItems(); |
|
331 if (count == 0 |
|
332 || aStart >= count |
|
333 || iList->SelectionIndexes()->Count() == 0) |
|
334 { |
|
335 return; |
|
336 } |
|
337 |
|
338 if (aStart < 0) |
|
339 { |
|
340 aStart = 0; |
|
341 } |
|
342 |
|
343 if (aEnd >= count) |
|
344 { |
|
345 aEnd = count - 1; |
|
346 } |
|
347 |
|
348 for (TInt i = aStart; i <= aEnd; i++) |
|
349 { |
|
350 iList->View()->DeselectItem(i); |
|
351 } |
|
352 TRAP_IGNORE(UpdateListMskL()); |
|
353 } |
|
354 |
|
355 // --------------------------------------------------------------------------- |
|
356 // CSwtListBase::DeselectAll |
|
357 // --------------------------------------------------------------------------- |
|
358 // |
|
359 void CSwtListBase::DeselectAll() |
|
360 { |
|
361 ASSERT(iList); |
|
362 ASSERT(iList->Model()); |
|
363 |
|
364 if (iList->Model()->NumberOfItems() == 0 |
|
365 || iList->SelectionIndexes()->Count() == 0) |
|
366 { |
|
367 return; |
|
368 } |
|
369 |
|
370 iList->ClearSelection(); |
|
371 TRAP_IGNORE(UpdateListMskL()); |
|
372 } |
|
373 |
|
374 // --------------------------------------------------------------------------- |
|
375 // CSwtListBase::GetFocusIndex |
|
376 // --------------------------------------------------------------------------- |
|
377 // |
|
378 TInt CSwtListBase::GetFocusIndex() const |
|
379 { |
|
380 ASSERT(iList); |
|
381 ASSERT(iList->Model()); |
|
382 |
|
383 if (iList->Model()->NumberOfItems() == 0) |
|
384 { |
|
385 return -1; |
|
386 } |
|
387 return iList->CurrentItemIndex(); |
|
388 } |
|
389 |
|
390 // --------------------------------------------------------------------------- |
|
391 // CSwtListBase::GetSelectionCount |
|
392 // --------------------------------------------------------------------------- |
|
393 // |
|
394 TInt CSwtListBase::GetSelectionCount() const |
|
395 { |
|
396 ASSERT(iList); |
|
397 return iList->SelectionIndexes()->Count(); |
|
398 } |
|
399 |
|
400 // --------------------------------------------------------------------------- |
|
401 // CSwtListBase::GetSelectionIndices |
|
402 // --------------------------------------------------------------------------- |
|
403 // |
|
404 const CArrayFix<TInt>* CSwtListBase::GetSelectionIndices() const |
|
405 { |
|
406 ASSERT(iList); |
|
407 return iList->SelectionIndexes(); |
|
408 } |
|
409 |
|
410 // --------------------------------------------------------------------------- |
|
411 // CSwtListBase::SelectItemL |
|
412 // --------------------------------------------------------------------------- |
|
413 // |
|
414 void CSwtListBase::SelectItemL(TInt aIndex, TBool aScroll) |
|
415 { |
|
416 ASSERT(iList); |
|
417 ASSERT(iList->Model()); |
|
418 ASSERT(iList->View()); |
|
419 |
|
420 if (aIndex >= iList->Model()->NumberOfItems() |
|
421 || iList->View()->ItemIsSelected(aIndex)) |
|
422 { |
|
423 return; |
|
424 } |
|
425 |
|
426 if (!(iStyle & KSwtStyleMulti)) |
|
427 { |
|
428 if (aScroll && iList->View()->ViewRect().Height() >= iList->ItemHeight()) |
|
429 { |
|
430 iList->View()->VerticalMoveToItemL(aIndex, CListBoxView::ESingleSelection); |
|
431 } |
|
432 else |
|
433 { |
|
434 TInt old = iList->CurrentItemIndex(); |
|
435 //we do not call CEikListBox::SetCurrentItemIndex, because we do not want to scroll. |
|
436 iList->View()->SetCurrentItemIndex(aIndex); |
|
437 iList->View()->UpdateSelectionL(CListBoxView::ESingleSelection); |
|
438 if (old != -1) |
|
439 { |
|
440 iList->View()->DrawItem(old); |
|
441 } |
|
442 } |
|
443 } |
|
444 else |
|
445 { |
|
446 iList->View()->SelectItemL(aIndex); |
|
447 if (aScroll) |
|
448 { |
|
449 iList->ScrollToMakeItemVisible(aIndex); |
|
450 } |
|
451 } |
|
452 UpdateListMskL(); |
|
453 } |
|
454 |
|
455 // --------------------------------------------------------------------------- |
|
456 // CSwtListBase::SelectRangeL |
|
457 // --------------------------------------------------------------------------- |
|
458 // |
|
459 void CSwtListBase::SelectRangeL(TInt aStart, TInt aEnd) |
|
460 { |
|
461 ASSERT(iList); |
|
462 ASSERT(iList->Model()); |
|
463 ASSERT(iList->View()); |
|
464 |
|
465 TInt count = iList->Model()->NumberOfItems(); |
|
466 if (count == 0 || aStart >= count) |
|
467 { |
|
468 return; |
|
469 } |
|
470 |
|
471 TInt end(aEnd); |
|
472 if (end >= count) |
|
473 { |
|
474 end = count - 1; |
|
475 } |
|
476 TInt start(aStart); |
|
477 if (start < 0) |
|
478 { |
|
479 start = 0; |
|
480 } |
|
481 |
|
482 for (TInt index = start; index <= end; ++index) |
|
483 { |
|
484 iList->View()->SelectItemL(index); |
|
485 } |
|
486 UpdateListMskL(); |
|
487 } |
|
488 |
|
489 // --------------------------------------------------------------------------- |
|
490 // CSwtListBase::SelectAllL |
|
491 // --------------------------------------------------------------------------- |
|
492 // |
|
493 void CSwtListBase::SelectAllL() |
|
494 { |
|
495 ASSERT(iList); |
|
496 ASSERT(iList->View()); |
|
497 |
|
498 for (TInt index = 0; index < iList->Model()->NumberOfItems(); ++index) |
|
499 { |
|
500 iList->View()->SelectItemL(index); |
|
501 } |
|
502 UpdateListMskL(); |
|
503 } |
|
504 |
|
505 // --------------------------------------------------------------------------- |
|
506 // CSwtListBase::ShowSelection |
|
507 // --------------------------------------------------------------------------- |
|
508 // |
|
509 void CSwtListBase::ShowSelection() const |
|
510 { |
|
511 ASSERT(iList); |
|
512 |
|
513 if (GetSelectionCount() == 0) |
|
514 { |
|
515 return; |
|
516 } |
|
517 |
|
518 iList->ScrollToMakeItemVisible((*iList->SelectionIndexes())[0]); |
|
519 } |
|
520 |
|
521 // --------------------------------------------------------------------------- |
|
522 // CSwtListBase::PostSelectionEvent |
|
523 // --------------------------------------------------------------------------- |
|
524 // |
|
525 void CSwtListBase::PostSelectionEvent() const |
|
526 { |
|
527 TRAP_IGNORE(iDisplay.PostSelectionEventL(iPeer)); |
|
528 } |
|
529 |
|
530 // --------------------------------------------------------------------------- |
|
531 // CSwtListBase::CSwtListBase |
|
532 // --------------------------------------------------------------------------- |
|
533 // |
|
534 CSwtListBase::CSwtListBase( |
|
535 MSwtDisplay& aDisplay, |
|
536 TSwtPeer aPeer, |
|
537 MSwtComposite& aParent, |
|
538 TInt aStyle) |
|
539 : ASwtScrollableBase(aDisplay, aPeer, &aParent, aStyle) |
|
540 , iFlickScrollingOngoing(EFalse) |
|
541 { |
|
542 } |
|
543 |
|
544 // --------------------------------------------------------------------------- |
|
545 // CSwtListBase::~CSwtListBase |
|
546 // --------------------------------------------------------------------------- |
|
547 // |
|
548 CSwtListBase::~CSwtListBase() |
|
549 { |
|
550 delete iPrevSelItems; |
|
551 delete iList; |
|
552 delete iTextItems; |
|
553 if (iDefaultFont) |
|
554 { |
|
555 iDefaultFont->RemoveRef(); |
|
556 } |
|
557 |
|
558 iRemovedItemIndices.Close(); |
|
559 iDefaultFont = NULL; |
|
560 iTextColor = NULL; |
|
561 iCurrentLafFont = NULL; |
|
562 } |
|
563 |
|
564 // --------------------------------------------------------------------------- |
|
565 // CSwtListBase::ConstructL |
|
566 // --------------------------------------------------------------------------- |
|
567 // |
|
568 void CSwtListBase::ConstructL() |
|
569 { |
|
570 CCoeControl& coeParent = iParent->Control()->CoeControl(); |
|
571 SetContainerWindowL(coeParent); |
|
572 CCoeControl::MakeVisible(coeParent.IsVisible()); |
|
573 CCoeControl::SetDimmed(coeParent.IsDimmed()); |
|
574 SetComponentsToInheritVisibility(ETrue); |
|
575 |
|
576 iList = CreateListBoxL(iStyle); |
|
577 CreateScrollBarsL(iList); |
|
578 if (iStyle & KSwtStyleMulti) |
|
579 { |
|
580 CreateIconArrayL(iList); |
|
581 } |
|
582 iPrevSelItems = new(ELeave) CArrayFixFlat<TInt>(1); |
|
583 CreateListBoxModelL(); |
|
584 |
|
585 iList->SetPosition(TPoint(GetBorderWidth(), GetBorderWidth())); |
|
586 |
|
587 // Retrieve the default font; a size must be set before retrieving the default font |
|
588 // because the font is set in SizeChanged of Avkon lists. |
|
589 SetSize(TSize(0, 0)); |
|
590 |
|
591 UpdateDefaultFontL(); |
|
592 |
|
593 // This is indeed necessary, otherwise the background might not be drawn! |
|
594 SetBackground(this); |
|
595 |
|
596 ActivateL(); |
|
597 } |
|
598 |
|
599 // --------------------------------------------------------------------------- |
|
600 // CSwtListBase::UpdateDefaultFontL |
|
601 // --------------------------------------------------------------------------- |
|
602 // |
|
603 void CSwtListBase::UpdateDefaultFontL() |
|
604 { |
|
605 ASSERT(iList); |
|
606 |
|
607 CColumnListBoxData* listBoxData = |
|
608 static_cast<CEikColumnListBox*>(iList)->ItemDrawer()->ColumnData(); |
|
609 ASSERT(listBoxData); |
|
610 const CFont* font = listBoxData->ColumnFont(KTextColumnIndex); |
|
611 |
|
612 if (font && iCurrentLafFont != font) |
|
613 { |
|
614 if (iDefaultFont) |
|
615 { |
|
616 iDefaultFont->RemoveRef(); |
|
617 iDefaultFont = NULL; |
|
618 } |
|
619 iDefaultFont = CSwtFont::NewL(iDisplay.Device(), *font); |
|
620 |
|
621 // Current LAF font retrieved |
|
622 iCurrentLafFont = font; |
|
623 |
|
624 // Default item height retrieved |
|
625 iDefaultItemHeight = iList->ItemHeight(); |
|
626 } |
|
627 } |
|
628 |
|
629 // --------------------------------------------------------------------------- |
|
630 // CSwtListBase::HandleResourceChangeL |
|
631 // --------------------------------------------------------------------------- |
|
632 // |
|
633 void CSwtListBase::HandleResourceChangeL(TInt aType) |
|
634 { |
|
635 if (aType == KAknsMessageSkinChange) |
|
636 { |
|
637 CreateIconArrayL(iList); |
|
638 } |
|
639 |
|
640 CAknControl::HandleResourceChange(aType); |
|
641 } |
|
642 |
|
643 // --------------------------------------------------------------------------- |
|
644 // CSwtListBase::GetUserSelectionL |
|
645 // --------------------------------------------------------------------------- |
|
646 // |
|
647 void CSwtListBase::GetUserSelectionL(CArrayFix<TInt>* aCurrSelItems) |
|
648 { |
|
649 if ((iStyle & KSwtStyleMulti) && aCurrSelItems) |
|
650 { |
|
651 iList->View()->GetSelectionIndexesL(aCurrSelItems); |
|
652 } |
|
653 } |
|
654 |
|
655 // --------------------------------------------------------------------------- |
|
656 // CSwtList::CalcNewFocusIndexAndTopItemIndex |
|
657 // --------------------------------------------------------------------------- |
|
658 // |
|
659 void CSwtListBase::CalcFocusIndexAfterItemRemoval(TInt& aNewFocusIndex, |
|
660 const RArray<TInt>& aRemovedItemIndices, TInt aOldFocusIndex) const |
|
661 { |
|
662 ASSERT(iList); |
|
663 ASSERT(iList->View()); |
|
664 ASSERT(iList->Model()); |
|
665 |
|
666 aNewFocusIndex = aOldFocusIndex; |
|
667 |
|
668 if (aRemovedItemIndices.Count() > 0) |
|
669 { |
|
670 TInt oldItemCount( |
|
671 iList->Model()->NumberOfItems() + aRemovedItemIndices.Count()); |
|
672 |
|
673 TInt counter(0); |
|
674 TInt ind = 0; |
|
675 while (ind < aRemovedItemIndices.Count() |
|
676 && aNewFocusIndex >= aRemovedItemIndices[ind]) |
|
677 { |
|
678 counter++; |
|
679 if (aNewFocusIndex == aRemovedItemIndices[ind]) |
|
680 { |
|
681 aNewFocusIndex = (aRemovedItemIndices[ind]+1) % oldItemCount; |
|
682 } |
|
683 ind++; |
|
684 } |
|
685 |
|
686 aNewFocusIndex -= counter; |
|
687 if ((aNewFocusIndex < 0) |
|
688 || (aNewFocusIndex >= iList->Model()->NumberOfItems())) |
|
689 { |
|
690 aNewFocusIndex = 0; |
|
691 } |
|
692 } |
|
693 } |
|
694 |
|
695 // --------------------------------------------------------------------------- |
|
696 // CSwtListBase::MinimumListItemWidth |
|
697 // --------------------------------------------------------------------------- |
|
698 // |
|
699 TInt CSwtListBase::MinimumListItemWidth() const |
|
700 { |
|
701 ASSERT(iTextItems); |
|
702 |
|
703 // Get general list Avkon layout |
|
704 TRect mainRect(TRect::EUninitialized); |
|
705 TAknLayoutRect layoutRect; |
|
706 AknLayoutUtils::LayoutMetricsRect( |
|
707 AknLayoutUtils::EMainPane, |
|
708 mainRect); |
|
709 layoutRect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::EListScrollGenPane, mainRect, 0); |
|
710 layoutRect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::EListGenPane, layoutRect.Rect(), 0); |
|
711 |
|
712 TAknLayoutText txtLayoutRect; |
|
713 |
|
714 if (iStyle & KSwtStyleMulti) |
|
715 { |
|
716 layoutRect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::EListSingleGraphicPane, layoutRect.Rect(), 0); |
|
717 txtLayoutRect = CSwtLafFacade::GetLayoutText(CSwtLafFacade::EListSingleGraphicPaneT1, layoutRect.Rect(), 0); |
|
718 } |
|
719 else |
|
720 { |
|
721 layoutRect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::EListSinglePane, layoutRect.Rect(), 0); |
|
722 txtLayoutRect = CSwtLafFacade::GetLayoutText(CSwtLafFacade::EListSinglePaneT1, layoutRect.Rect(), 0); |
|
723 } |
|
724 |
|
725 if (iFont) |
|
726 { |
|
727 CColumnListBoxData* listBoxData = |
|
728 static_cast<CEikColumnListBox*> |
|
729 (iList)->ItemDrawer()->ColumnData(); |
|
730 ASSERT(listBoxData); |
|
731 return (listBoxData->ColumnWidthPixel(KCheckboxColumnIndex) |
|
732 + iTxtMaxWidth); |
|
733 } |
|
734 |
|
735 TInt diffBrX(Max(0, layoutRect.Rect().iBr.iX - txtLayoutRect.TextRect().iBr.iX)); |
|
736 |
|
737 return (txtLayoutRect.TextRect().iTl.iX + diffBrX + iTxtMaxWidth); |
|
738 } |
|
739 |
|
740 // --------------------------------------------------------------------------- |
|
741 // CSwtListBase::PreferredWidth |
|
742 // --------------------------------------------------------------------------- |
|
743 // |
|
744 TInt CSwtListBase::PreferredWidth() const |
|
745 { |
|
746 TInt preferredWidth(0); |
|
747 |
|
748 // Add the border width |
|
749 preferredWidth = GetBorderWidth() * KHBorderSides; |
|
750 |
|
751 // Add the vertical scrollbar space if present |
|
752 if (SbFrame()->ScrollBarExists(CEikScrollBar::EVertical) |
|
753 && SbFrame()->ScrollBarVisibility(CEikScrollBar::EVertical) |
|
754 != CEikScrollBarFrame::EOff) |
|
755 { |
|
756 preferredWidth += iDisplay.UiUtils().ScrollBarBreadth(SbFrame()->VerticalScrollBar()); |
|
757 } |
|
758 |
|
759 preferredWidth += MinimumListItemWidth(); |
|
760 |
|
761 return preferredWidth; |
|
762 } |
|
763 |
|
764 // --------------------------------------------------------------------------- |
|
765 // CSwtListBase::PreferredWidth |
|
766 // --------------------------------------------------------------------------- |
|
767 // |
|
768 TInt CSwtListBase::PreferredHeight() const |
|
769 { |
|
770 TInt preferredHeight(0); |
|
771 |
|
772 // Add the border width |
|
773 preferredHeight = GetBorderWidth() * KVBorderSides; |
|
774 |
|
775 preferredHeight += iList->CalcHeightBasedOnNumOfItems( |
|
776 Max(1, iList->Model()->NumberOfItems())); |
|
777 |
|
778 // Add horizontal scrollbar width |
|
779 if (SbFrame()->ScrollBarExists(CEikScrollBar::EHorizontal) && |
|
780 SbFrame()->ScrollBarVisibility(CEikScrollBar::EHorizontal) |
|
781 != CEikScrollBarFrame::EOff) |
|
782 { |
|
783 preferredHeight += iDisplay.UiUtils().ScrollBarBreadth( |
|
784 SbFrame()->GetScrollBarHandle(CEikScrollBar::EHorizontal)); |
|
785 } |
|
786 |
|
787 return preferredHeight; |
|
788 } |
|
789 |
|
790 // --------------------------------------------------------------------------- |
|
791 // CSwtListBase::ComputeTextMaxWidth |
|
792 // --------------------------------------------------------------------------- |
|
793 // |
|
794 TInt CSwtListBase::ComputeTextMaxWidth() const |
|
795 { |
|
796 ASSERT(iTextItems); |
|
797 |
|
798 const CFont& font = GetFont()->Font(); |
|
799 TInt txtMaxWidth(0); |
|
800 for (TInt ind = 0; ind < iTextItems->Count(); ind++) |
|
801 { |
|
802 txtMaxWidth = Max(txtMaxWidth, |
|
803 font.TextWidthInPixels((*iTextItems)[ind])); |
|
804 } |
|
805 |
|
806 return txtMaxWidth; |
|
807 } |
|
808 |
|
809 // --------------------------------------------------------------------------- |
|
810 // CSwtListBase::ComputeTextMaxWidth |
|
811 // --------------------------------------------------------------------------- |
|
812 // |
|
813 void CSwtListBase::SetTextMaxWidth(TInt aMaxTxtWidth) |
|
814 { |
|
815 iTxtMaxWidth = aMaxTxtWidth; |
|
816 } |
|
817 |
|
818 // --------------------------------------------------------------------------- |
|
819 // CSwtListBase::UpdateListMSK |
|
820 // --------------------------------------------------------------------------- |
|
821 // |
|
822 void CSwtListBase::UpdateListMskL() |
|
823 { |
|
824 if (AknLayoutUtils::MSKEnabled()) |
|
825 { |
|
826 MSwtCommandArranger* cmdArranger = iDisplay.CommandArranger(); |
|
827 if (cmdArranger) |
|
828 { |
|
829 cmdArranger->UpdateMSKLabelL(); |
|
830 } |
|
831 } |
|
832 } |
|
833 |
|
834 // --------------------------------------------------------------------------- |
|
835 // CSwtListBase::CountComponentControls |
|
836 // From CCoeControl |
|
837 // --------------------------------------------------------------------------- |
|
838 // |
|
839 TInt CSwtListBase::CountComponentControls() const |
|
840 { |
|
841 return iList ? 1 : 0; |
|
842 } |
|
843 |
|
844 // --------------------------------------------------------------------------- |
|
845 // CSwtListBase::ComponentControl |
|
846 // From CCoeControl |
|
847 // --------------------------------------------------------------------------- |
|
848 // |
|
849 CCoeControl* CSwtListBase::ComponentControl(TInt /*aIndex*/) const |
|
850 { |
|
851 return iList; |
|
852 } |
|
853 |
|
854 // --------------------------------------------------------------------------- |
|
855 // CSwtListBase::MakeVisible |
|
856 // From CCoeControl |
|
857 // --------------------------------------------------------------------------- |
|
858 // |
|
859 void CSwtListBase::MakeVisible(TBool aVisible) |
|
860 { |
|
861 CCoeControl::MakeVisible(aVisible); |
|
862 FocusabilityChanged(); |
|
863 } |
|
864 |
|
865 // --------------------------------------------------------------------------- |
|
866 // CSwtListBase::SetDimmed |
|
867 // From CCoeControl |
|
868 // --------------------------------------------------------------------------- |
|
869 // |
|
870 void CSwtListBase::SetDimmed(TBool aDimmed) |
|
871 { |
|
872 ASSERT(iList); |
|
873 |
|
874 CCoeControl::SetDimmed(aDimmed); |
|
875 iList->SetDimmed(aDimmed); |
|
876 FocusabilityChanged(); |
|
877 } |
|
878 |
|
879 // --------------------------------------------------------------------------- |
|
880 // CSwtListBase::OfferKeyEventL |
|
881 // From CCoeControl |
|
882 // --------------------------------------------------------------------------- |
|
883 // |
|
884 TKeyResponse CSwtListBase::OfferKeyEventL(const TKeyEvent& aKeyEvent, |
|
885 TEventCode aType) |
|
886 { |
|
887 ASSERT(iList); |
|
888 ASSERT(iList->Model()); |
|
889 |
|
890 TBool traversalDoIt = ETrue; |
|
891 |
|
892 if ((iStyle & KSwtStyleMulti) |
|
893 && (aKeyEvent.iCode == EKeyEnter || aKeyEvent.iCode == EKeyOK)) |
|
894 { |
|
895 traversalDoIt = EFalse; |
|
896 } |
|
897 |
|
898 if (aKeyEvent.iCode == EKeyDownArrow || aKeyEvent.iCode == EKeyUpArrow) |
|
899 { |
|
900 traversalDoIt = EFalse; |
|
901 } |
|
902 |
|
903 if (aKeyEvent.iCode == EKeyDownArrow) |
|
904 { |
|
905 if (iList->CurrentItemIndex() == (iList->Model()->NumberOfItems()-1)) |
|
906 { |
|
907 if (GetShell().FindTraversalTargetL(ESwtTraverseArrowNext, *this) != NULL) |
|
908 { |
|
909 traversalDoIt = ETrue; |
|
910 } |
|
911 } |
|
912 } |
|
913 else if (aKeyEvent.iCode == EKeyUpArrow) |
|
914 { |
|
915 if (iList->CurrentItemIndex() == 0) |
|
916 { |
|
917 if (GetShell().FindTraversalTargetL(ESwtTraverseArrowPrevious, *this) != NULL) |
|
918 { |
|
919 traversalDoIt = ETrue; |
|
920 } |
|
921 } |
|
922 } |
|
923 |
|
924 return HandleKeyL(aKeyEvent, aType, traversalDoIt); |
|
925 } |
|
926 |
|
927 // --------------------------------------------------------------------------- |
|
928 // CSwtListBase::HandleResourceChange |
|
929 // From CCoeControl |
|
930 // --------------------------------------------------------------------------- |
|
931 // |
|
932 void CSwtListBase::HandleResourceChange(TInt aType) |
|
933 { |
|
934 TRAP_IGNORE(HandleResourceChangeL(aType)); |
|
935 } |
|
936 |
|
937 // --------------------------------------------------------------------------- |
|
938 // CSwtListBase::HandlePointerEventL |
|
939 // From CCoeControl |
|
940 // --------------------------------------------------------------------------- |
|
941 // |
|
942 #ifdef RD_SCALABLE_UI_V2 |
|
943 void CSwtListBase::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
944 { |
|
945 ASSERT(iList); |
|
946 |
|
947 CEikScrollBarFrame* sbFrame = iList->ScrollBarFrame(); |
|
948 CEikScrollBar* vsb = sbFrame ? sbFrame->GetScrollBarHandle(CEikScrollBar::EVertical) : NULL; |
|
949 |
|
950 // Check if we should start scrollbar grabbing |
|
951 if (aPointerEvent.iType == TPointerEvent::EButton1Down && !iVScrollBarGrabsPointerEvents) |
|
952 { |
|
953 if (vsb && vsb->Rect().Contains(aPointerEvent.iPosition)) |
|
954 { |
|
955 iVScrollBarGrabsPointerEvents = ETrue; |
|
956 } |
|
957 } |
|
958 |
|
959 // Deliver event to scrollbar |
|
960 if (iVScrollBarGrabsPointerEvents && vsb) |
|
961 { |
|
962 if (!iFlickScrollingOngoing |
|
963 && aPointerEvent.iType == TPointerEvent::EButton1Down) |
|
964 { |
|
965 // Scrollbar was tapped after scrolling stopped |
|
966 // by itself, so no need to redirect events |
|
967 iScrollbarPointerEventToListbox = EFalse; |
|
968 } |
|
969 |
|
970 if (iScrollbarPointerEventToListbox) |
|
971 { |
|
972 // Stops kinetic scrolling when scrollbar is tapped |
|
973 iList->HandlePointerEventL(aPointerEvent); |
|
974 // Continue delivering events until button up appears to prevent |
|
975 // some unexpected behavior in both scrollbar and listbox |
|
976 switch (aPointerEvent.iType) |
|
977 { |
|
978 case TPointerEvent::EButton1Up: |
|
979 iScrollbarPointerEventToListbox = EFalse; |
|
980 break; |
|
981 } |
|
982 } |
|
983 else |
|
984 { |
|
985 // Handles scrollbar behavior |
|
986 vsb->HandlePointerEventL(aPointerEvent); |
|
987 } |
|
988 } |
|
989 |
|
990 // Deliver event to list |
|
991 if (!iVScrollBarGrabsPointerEvents) |
|
992 { |
|
993 // Store the selection on first pointer event. |
|
994 if (aPointerEvent.iType == TPointerEvent::EButton1Down) |
|
995 { |
|
996 if (iStyle & KSwtStyleMulti) |
|
997 { |
|
998 // Multi lists |
|
999 ASSERT(iPrevSelItems); |
|
1000 GetUserSelectionL(iPrevSelItems); |
|
1001 } |
|
1002 iPrevFocusIndex = iList->View()->CurrentItemIndex(); |
|
1003 } |
|
1004 |
|
1005 iList->HandlePointerEventL(aPointerEvent); |
|
1006 |
|
1007 if (aPointerEvent.iType == TPointerEvent::EButton1Up) |
|
1008 { |
|
1009 TInt focusIndex = iList->View()->CurrentItemIndex(); |
|
1010 |
|
1011 if (iStyle & KSwtStyleMulti) |
|
1012 { |
|
1013 // Multi lists |
|
1014 if ((iList->View()->SelectionIndexes()->Count() != iPrevSelItems->Count())) |
|
1015 { |
|
1016 if (iDisplay.RevertPointerEvent()) |
|
1017 { |
|
1018 // Revert newly checked item. |
|
1019 if (iList->View()->ItemIsSelected(focusIndex)) |
|
1020 { |
|
1021 iList->View()->DeselectItem(focusIndex); |
|
1022 } |
|
1023 else |
|
1024 { |
|
1025 iList->View()->SelectItemL(focusIndex); |
|
1026 } |
|
1027 } |
|
1028 else |
|
1029 { |
|
1030 iDisplay.PostSelectionEventL(iPeer); |
|
1031 } |
|
1032 } |
|
1033 } |
|
1034 else |
|
1035 { |
|
1036 // Single lists |
|
1037 // Compare the focus index after tap or drag ended |
|
1038 if (focusIndex != iPrevFocusIndex) |
|
1039 { |
|
1040 // Ensure the selection and focus index are in sync. |
|
1041 iList->View()->UpdateSelectionL(CListBoxView::ESingleSelection); |
|
1042 |
|
1043 // Item focus highlight moved, send selection event. |
|
1044 // Changing the focus index is not subject to reverting. |
|
1045 iDisplay.PostSelectionEventL(iPeer); |
|
1046 } |
|
1047 |
|
1048 // The default selection is sent from HandleListBoxEventL! |
|
1049 } |
|
1050 } |
|
1051 } |
|
1052 |
|
1053 // Stop scrollbar grabbing |
|
1054 if (iVScrollBarGrabsPointerEvents |
|
1055 && aPointerEvent.iType == TPointerEvent::EButton1Up) |
|
1056 { |
|
1057 iVScrollBarGrabsPointerEvents = EFalse; |
|
1058 } |
|
1059 |
|
1060 PostMouseEventL(aPointerEvent); |
|
1061 } |
|
1062 #else //RD_SCALABLE_UI_V2 |
|
1063 void CSwtListBase::HandlePointerEventL( |
|
1064 const TPointerEvent& /*aPointerEvent*/) |
|
1065 { |
|
1066 } |
|
1067 #endif //RD_SCALABLE_UI_V2 |
|
1068 |
|
1069 // --------------------------------------------------------------------------- |
|
1070 // CSwtListBase::SizeChanged |
|
1071 // From CCoeControl |
|
1072 // --------------------------------------------------------------------------- |
|
1073 // |
|
1074 void CSwtListBase::SizeChanged() |
|
1075 { |
|
1076 UpdateSize(); |
|
1077 HandleSizeChanged(); |
|
1078 } |
|
1079 |
|
1080 // --------------------------------------------------------------------------- |
|
1081 // CSwtListBase::PositionChanged |
|
1082 // From CCoeControl |
|
1083 // --------------------------------------------------------------------------- |
|
1084 // |
|
1085 void CSwtListBase::PositionChanged() |
|
1086 { |
|
1087 HandlePositionChanged(); |
|
1088 } |
|
1089 |
|
1090 // --------------------------------------------------------------------------- |
|
1091 // CSwtListBase::FocusChanged |
|
1092 // From CCoeControl |
|
1093 // --------------------------------------------------------------------------- |
|
1094 // |
|
1095 void CSwtListBase::FocusChanged(TDrawNow aDrawNow) |
|
1096 { |
|
1097 ASSERT(iList); |
|
1098 |
|
1099 TBool isFocused = IsFocusControl(); |
|
1100 #ifdef RD_JAVA_S60_RELEASE_9_2 |
|
1101 EnableFocusHighlight(isFocused); |
|
1102 #endif //RD_JAVA_S60_RELEASE_9_2 |
|
1103 iList->SetFocus(isFocused, aDrawNow); |
|
1104 HandleFocusChanged(aDrawNow); |
|
1105 } |
|
1106 |
|
1107 // --------------------------------------------------------------------------- |
|
1108 // CSwtListBase::MopSupplyObject |
|
1109 // From CCoeControl |
|
1110 // --------------------------------------------------------------------------- |
|
1111 // |
|
1112 TTypeUid::Ptr CSwtListBase::MopSupplyObject(TTypeUid aId) |
|
1113 { |
|
1114 TTypeUid::Ptr id = ASwtControlBase::SwtMopSupplyObject(aId); |
|
1115 |
|
1116 if (id.Pointer() == NULL) |
|
1117 { |
|
1118 return CAknControl::MopSupplyObject(aId); |
|
1119 } |
|
1120 else |
|
1121 { |
|
1122 return id; |
|
1123 } |
|
1124 } |
|
1125 |
|
1126 // --------------------------------------------------------------------------- |
|
1127 // CSwtListBase::Draw |
|
1128 // From CCoeControl |
|
1129 // Overriding Draw just to set correct clipping rect for the item drawer of |
|
1130 // the contained list. The contained list will be drawn immediately after this. |
|
1131 // --------------------------------------------------------------------------- |
|
1132 // |
|
1133 void CSwtListBase::Draw(const TRect& /*aRect*/) const |
|
1134 { |
|
1135 // Suppress margins - they are drawn over scrollbars |
|
1136 CSwtListBoxLists::SetMargins(iListType, iList, 0, 0); |
|
1137 |
|
1138 if (GetShell().UrgentPaintControl() == this) |
|
1139 return; |
|
1140 |
|
1141 TRect clipRect(ClipToVisibleRect(iList->View()->ViewRect())); |
|
1142 if (clipRect != iLastViewVisibleRect) |
|
1143 { |
|
1144 CSwtListBoxLists::SetItemDrawerClippingRect(iListType, iList, clipRect); |
|
1145 iLastViewVisibleRect = clipRect; |
|
1146 } |
|
1147 } |
|
1148 |
|
1149 // --------------------------------------------------------------------------- |
|
1150 // CSwtListBase::SetFontL |
|
1151 // From ASwtControlbase |
|
1152 // --------------------------------------------------------------------------- |
|
1153 // |
|
1154 void CSwtListBase::SetFontL(const MSwtFont* aFont) |
|
1155 { |
|
1156 ASwtControlBase::DoSetFontL(aFont); |
|
1157 |
|
1158 SetTextMaxWidth(ComputeTextMaxWidth()); |
|
1159 |
|
1160 // The font update will be performed in HandleSizeChangedL method. |
|
1161 UpdateSize(); |
|
1162 |
|
1163 Redraw(); |
|
1164 } |
|
1165 |
|
1166 // --------------------------------------------------------------------------- |
|
1167 // CSwtListBase::MSKLabelL |
|
1168 // From ASwtControlbase |
|
1169 // --------------------------------------------------------------------------- |
|
1170 // |
|
1171 HBufC* CSwtListBase::MSKLabelL() const |
|
1172 { |
|
1173 if (!iList || !(iList->Model()->NumberOfItems() > 0)) |
|
1174 { |
|
1175 return ASwtControlBase::MSKLabelL(); |
|
1176 } |
|
1177 |
|
1178 if ((iStyle & KSwtStyleSingle)) |
|
1179 { |
|
1180 HBufC* label = iEikonEnv->AllocReadResourceL(R_QTN_MSK_SELECT); |
|
1181 return label; |
|
1182 } |
|
1183 if ((iStyle & KSwtStyleMulti)) |
|
1184 { |
|
1185 HBufC* label = NULL; |
|
1186 if (iList->View()->ItemIsSelected(iList->CurrentItemIndex())) |
|
1187 { |
|
1188 label = iEikonEnv->AllocReadResourceL(R_QTN_MSK_UNMARK); |
|
1189 } |
|
1190 else |
|
1191 { |
|
1192 label = iEikonEnv->AllocReadResourceL(R_QTN_MSK_MARK); |
|
1193 } |
|
1194 return label; |
|
1195 } |
|
1196 return ASwtControlBase::MSKLabelL(); |
|
1197 } |
|
1198 |
|
1199 // --------------------------------------------------------------------------- |
|
1200 // CSwtListBase::DefaultFont |
|
1201 // From ASwtControlbase |
|
1202 // --------------------------------------------------------------------------- |
|
1203 // |
|
1204 const MSwtFont& CSwtListBase::DefaultFont() const |
|
1205 { |
|
1206 if (iDefaultFont) |
|
1207 { |
|
1208 return *iDefaultFont; |
|
1209 } |
|
1210 |
|
1211 return *(iDisplay.Device().GetSystemFont()); |
|
1212 } |
|
1213 |
|
1214 // --------------------------------------------------------------------------- |
|
1215 // CSwtListBase::CoeControl |
|
1216 // From MSwtControl |
|
1217 // --------------------------------------------------------------------------- |
|
1218 // |
|
1219 CCoeControl& CSwtListBase::CoeControl() |
|
1220 { |
|
1221 return *this; |
|
1222 } |
|
1223 |
|
1224 // --------------------------------------------------------------------------- |
|
1225 // CSwtListBase::CoeControl |
|
1226 // From MSwtControl |
|
1227 // --------------------------------------------------------------------------- |
|
1228 // |
|
1229 const CCoeControl& CSwtListBase::CoeControl() const |
|
1230 { |
|
1231 return *this; |
|
1232 } |
|
1233 |
|
1234 // --------------------------------------------------------------------------- |
|
1235 // CSwtListBase::ProcessKeyEventL |
|
1236 // From MSwtControl |
|
1237 // --------------------------------------------------------------------------- |
|
1238 // |
|
1239 void CSwtListBase::ProcessKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) |
|
1240 { |
|
1241 #ifdef RD_JAVA_S60_RELEASE_9_2 |
|
1242 if (aType == EEventKeyDown) |
|
1243 { |
|
1244 // After panning focus highlight was disabled, so enabling again |
|
1245 EnableFocusHighlight(ETrue); |
|
1246 } |
|
1247 #endif //RD_JAVA_S60_RELEASE_9_2 |
|
1248 |
|
1249 // No items or not a normal key event |
|
1250 if (iList->Model()->NumberOfItems() == 0 || aType != EEventKey) |
|
1251 { |
|
1252 iList->OfferKeyEventL(aKeyEvent, aType); |
|
1253 return; |
|
1254 } |
|
1255 |
|
1256 TBool scroll = aKeyEvent.iCode == EKeyDownArrow || aKeyEvent.iCode == EKeyUpArrow |
|
1257 || aKeyEvent.iCode == EKeyNext || aKeyEvent.iCode == EKeyPrevious; |
|
1258 TBool submit = aKeyEvent.iCode == EKeyEnter || aKeyEvent.iCode == EKeyOK; |
|
1259 |
|
1260 // For performance considerations, assuming that Enter or Select always |
|
1261 // does change the multi selection. If the assumption is wrong, we must |
|
1262 // store the multi selection before the key is handled and then compare: |
|
1263 // if ( ( iStyle & KSwtStyleMulti ) && submit ) GetUserSelectionL( iPrevSelItems ); |
|
1264 |
|
1265 // Store selection before letting the list handle the key. |
|
1266 if ((iStyle & KSwtStyleSingle) && scroll) |
|
1267 { |
|
1268 iPrevFocusIndex = iList->View()->CurrentItemIndex(); |
|
1269 } |
|
1270 |
|
1271 iList->OfferKeyEventL(aKeyEvent, aType); |
|
1272 |
|
1273 if (scroll || submit) |
|
1274 { |
|
1275 if (iStyle & KSwtStyleSingle) |
|
1276 { |
|
1277 // Single lists |
|
1278 if (submit) |
|
1279 { |
|
1280 // Item submited, send default selection event. |
|
1281 iDisplay.PostDefaultSelectionEventL(iPeer); |
|
1282 } |
|
1283 else |
|
1284 { |
|
1285 if (iList->View()->CurrentItemIndex() != iPrevFocusIndex) |
|
1286 { |
|
1287 // Ensure the selection and focus index are in sync. |
|
1288 iList->View()->UpdateSelectionL(CListBoxView::ESingleSelection); |
|
1289 |
|
1290 // Item focus highlight moved, send selection event. |
|
1291 iDisplay.PostSelectionEventL(iPeer); |
|
1292 } |
|
1293 } |
|
1294 } |
|
1295 else |
|
1296 { |
|
1297 // Multi lists |
|
1298 // Msk could have changed: Mark / Unmark |
|
1299 UpdateListMskL(); |
|
1300 |
|
1301 // For performance considerations, assuming that Enter or Select always |
|
1302 // does change the multi selection. If the assumption is wrong, here's |
|
1303 // how we must check if the selection really changed: |
|
1304 // if ( submit && iPrevSelItems && ( iList->View()->SelectionIndexes()-> |
|
1305 // Count() != iPrevSelItems->Count() ) ) |
|
1306 if (submit) |
|
1307 { |
|
1308 // Multi selection changed, send selection event. |
|
1309 iDisplay.PostSelectionEventL(iPeer); |
|
1310 } |
|
1311 } |
|
1312 } |
|
1313 } |
|
1314 |
|
1315 // --------------------------------------------------------------------------- |
|
1316 // CSwtListBase::IsKeyUsed |
|
1317 // From MSwtControl |
|
1318 // --------------------------------------------------------------------------- |
|
1319 // |
|
1320 TBool CSwtListBase::IsKeyUsed(TUint aKeyCode) const |
|
1321 { |
|
1322 // A list does not use the Backspace but uses OK key |
|
1323 if (aKeyCode == EKeyBackspace) |
|
1324 { |
|
1325 return EFalse; |
|
1326 } |
|
1327 else if (aKeyCode == EKeyOK) |
|
1328 { |
|
1329 if (iStyle & KSwtStyleSingle) |
|
1330 { |
|
1331 MSwtCommandArranger* commandArranger = iDisplay.CommandArranger(); |
|
1332 if (commandArranger) |
|
1333 { |
|
1334 if (commandArranger->IsContextSensitiveOperationSet()) |
|
1335 { |
|
1336 return EFalse; |
|
1337 } |
|
1338 } |
|
1339 return ETrue; |
|
1340 } |
|
1341 else |
|
1342 { |
|
1343 return ETrue; |
|
1344 } |
|
1345 } |
|
1346 return ETrue; |
|
1347 } |
|
1348 |
|
1349 |
|
1350 TBool CSwtListBase::MSKSelCmdEnabled() const |
|
1351 { |
|
1352 return ETrue; |
|
1353 } |
|
1354 |
|
1355 // --------------------------------------------------------------------------- |
|
1356 // CSwtListBase::GetForeground |
|
1357 // From MSwtControl |
|
1358 // --------------------------------------------------------------------------- |
|
1359 // |
|
1360 TRgb CSwtListBase::GetForeground() const |
|
1361 { |
|
1362 ASSERT(iList); |
|
1363 return static_cast<CEikColumnListBox*>(iList)->ItemDrawer()->TextColor(); |
|
1364 } |
|
1365 |
|
1366 // --------------------------------------------------------------------------- |
|
1367 // CSwtListBase::SetForegroundL |
|
1368 // From MSwtControl |
|
1369 // --------------------------------------------------------------------------- |
|
1370 // |
|
1371 void CSwtListBase::SetForegroundL(const MSwtColor* aColor) |
|
1372 { |
|
1373 ASwtControlBase::DoSetForegroundL(aColor); |
|
1374 iTextColor = aColor; |
|
1375 UpdateListBoxTextColorL(); |
|
1376 Redraw(); |
|
1377 } |
|
1378 |
|
1379 // --------------------------------------------------------------------------- |
|
1380 // CSwtListBase::SetBackgroundL |
|
1381 // From MSwtControl |
|
1382 // --------------------------------------------------------------------------- |
|
1383 // |
|
1384 void CSwtListBase::SetBackgroundL(const MSwtColor* aColor) |
|
1385 { |
|
1386 ASSERT(iList); |
|
1387 ASwtControlBase::DoSetBackgroundL(aColor); |
|
1388 iList->HandleResourceChange(KEikMessageColorSchemeChange); |
|
1389 Redraw(); |
|
1390 } |
|
1391 |
|
1392 // --------------------------------------------------------------------------- |
|
1393 // CSwtListBase::IsLongTapAnimationCandidate |
|
1394 // From MSwtControl |
|
1395 // --------------------------------------------------------------------------- |
|
1396 // |
|
1397 #ifdef RD_SCALABLE_UI_V2 |
|
1398 TBool CSwtListBase::IsLongTapAnimationCandidate(const TPointerEvent& aPointerEvent) const |
|
1399 { |
|
1400 ASSERT(iList); |
|
1401 TInt itemIndex = KErrNotFound; |
|
1402 TBool pointerOverItem = iList->View()->XYPosToItemIndex(aPointerEvent.iPosition, itemIndex); |
|
1403 return pointerOverItem && ASwtControlBase::IsLongTapAnimationCandidate(aPointerEvent); |
|
1404 } |
|
1405 #else |
|
1406 TBool CSwtListBase::IsLongTapAnimationCandidate(const TPointerEvent& /*aPointerEvent*/) const |
|
1407 { |
|
1408 return EFalse; |
|
1409 } |
|
1410 #endif |
|
1411 |
|
1412 #ifdef RD_JAVA_S60_RELEASE_9_2 |
|
1413 // --------------------------------------------------------------------------- |
|
1414 // CSwtListBase::EnableFocusHighlight |
|
1415 // From MSwtControl |
|
1416 // --------------------------------------------------------------------------- |
|
1417 // |
|
1418 void CSwtListBase::EnableFocusHighlight(TBool aEnable) |
|
1419 { |
|
1420 ASSERT(iList); |
|
1421 ASSERT(iList->View()); |
|
1422 |
|
1423 CSwtListBoxLists::EnableFocusHighlight(iList->View()->ItemDrawer(), |
|
1424 aEnable); |
|
1425 } |
|
1426 #endif //RD_JAVA_S60_RELEASE_9_2 |
|
1427 |
|
1428 TInt CSwtListBase::FocusBackgroundPolicy() const |
|
1429 { |
|
1430 #ifdef RD_JAVA_S60_RELEASE_9_2 |
|
1431 return ENoFocusBackgroundInCaptionedControl; |
|
1432 #else |
|
1433 return EDefaultFocusBackground; |
|
1434 #endif // RD_JAVA_S60_RELEASE_9_2 |
|
1435 } |
|
1436 |
|
1437 // --------------------------------------------------------------------------- |
|
1438 // CSwtListBase::PrepareForTraverse |
|
1439 // From MSwtControl |
|
1440 // --------------------------------------------------------------------------- |
|
1441 // |
|
1442 void CSwtListBase::PrepareForTraverse() |
|
1443 { |
|
1444 ASSERT(iList); |
|
1445 ASSERT(iList->View()); |
|
1446 |
|
1447 #ifdef RD_JAVA_S60_RELEASE_9_2 |
|
1448 // AvKon enables highlight only when key event is recieved. |
|
1449 // When traversing, no key event is sent to AvKon, so we |
|
1450 // have to enable highlight by ourselves. |
|
1451 CListItemDrawer* itemDrawer = iList->View()->ItemDrawer(); |
|
1452 if (itemDrawer) |
|
1453 { |
|
1454 itemDrawer->ClearFlags(CListItemDrawer::ESingleClickDisabledHighlight); |
|
1455 } |
|
1456 #endif //RD_JAVA_S60_RELEASE_9_2 |
|
1457 } |
|
1458 |
|
1459 // --------------------------------------------------------------------------- |
|
1460 // CSwtListBase::SbFrame |
|
1461 // From ASwtScrollableBase |
|
1462 // --------------------------------------------------------------------------- |
|
1463 // |
|
1464 CEikScrollBarFrame* CSwtListBase::SbFrame() const |
|
1465 { |
|
1466 ASSERT(iList); |
|
1467 return iList->ScrollBarFrame(); |
|
1468 } |
|
1469 |
|
1470 // --------------------------------------------------------------------------- |
|
1471 // CSwtListBase::HandleSizeChangedL |
|
1472 // From MSwtListObserver |
|
1473 // --------------------------------------------------------------------------- |
|
1474 // |
|
1475 void CSwtListBase::HandleSizeChangedL() |
|
1476 { |
|
1477 ASSERT(iList); |
|
1478 |
|
1479 CColumnListBoxData* listBoxData = |
|
1480 static_cast<CEikColumnListBox*>(iList)->ItemDrawer()->ColumnData(); |
|
1481 ASSERT(listBoxData); |
|
1482 CColumnListBoxItemDrawer* listBoxDrawer = |
|
1483 static_cast<CEikColumnListBox*>(iList)->ItemDrawer(); |
|
1484 ASSERT(listBoxDrawer); |
|
1485 |
|
1486 // Update default font if font of list box has changed |
|
1487 UpdateDefaultFontL(); |
|
1488 |
|
1489 if (iFont) |
|
1490 { |
|
1491 // If a font has been set, all item layouts are removed |
|
1492 // to display all of them correctly |
|
1493 listBoxData->ResetSLSubCellArray(); |
|
1494 |
|
1495 // WORKAROUND to prevent a crash in CColumnListBoxData::Draw() method. |
|
1496 // An assert ASSERT_ALWAYS is performed if column widths are not correct. |
|
1497 TRect clientRect(ClientRect()); |
|
1498 for (TInt colIndex = 0; |
|
1499 colIndex < listBoxData->LastColumn(); |
|
1500 colIndex++) |
|
1501 { |
|
1502 if (colIndex == KCheckboxColumnIndex) |
|
1503 { |
|
1504 if (listBoxData->ColumnWidthPixel(KCheckboxColumnIndex) <= 1) |
|
1505 { |
|
1506 listBoxData->SetColumnWidthPixelL(KCheckboxColumnIndex, 2); |
|
1507 } |
|
1508 } |
|
1509 else if (colIndex == KTextColumnIndex) |
|
1510 { |
|
1511 TInt txtMaxWidth(0); |
|
1512 if (!iTextItems->Count()) |
|
1513 { |
|
1514 txtMaxWidth = clientRect.Width() - |
|
1515 listBoxData->ColumnWidthPixel(KCheckboxColumnIndex); |
|
1516 } |
|
1517 else |
|
1518 { |
|
1519 txtMaxWidth = Min(iTxtMaxWidth, clientRect.Width() - |
|
1520 listBoxData->ColumnWidthPixel(KCheckboxColumnIndex)); |
|
1521 } |
|
1522 txtMaxWidth = Max(1, txtMaxWidth); |
|
1523 listBoxData->SetColumnWidthPixelL( |
|
1524 KTextColumnIndex, txtMaxWidth); |
|
1525 } |
|
1526 else if (listBoxData->ColumnWidthPixel(colIndex) < 0) |
|
1527 { |
|
1528 listBoxData->SetColumnWidthPixelL(colIndex, 0); |
|
1529 } |
|
1530 } |
|
1531 // END WORKAROUND |
|
1532 } |
|
1533 |
|
1534 // ========================================== |
|
1535 // WORKAROUND to not draw the dotted lines. |
|
1536 // ========================================== |
|
1537 // |
|
1538 listBoxData->SetSeparatorLinePosition(ENoLine); |
|
1539 // END WORKAROUND |
|
1540 |
|
1541 // Update with current font |
|
1542 UpdateListBoxFontL(); |
|
1543 |
|
1544 // Update with current text color |
|
1545 UpdateListBoxTextColorL(); |
|
1546 |
|
1547 // Update background color |
|
1548 listBoxDrawer->SetBackColor(GetBackground()); |
|
1549 |
|
1550 // Suppress margins - they are drawn over scrollbars |
|
1551 // We need to update margins here one more time, because previous |
|
1552 // code re-sets them |
|
1553 CSwtListBoxLists::SetMargins(iListType, iList, 0, 0); |
|
1554 } |
|
1555 |
|
1556 // --------------------------------------------------------------------------- |
|
1557 // CSwtListBase::Utils |
|
1558 // From MSwtListObserver |
|
1559 // --------------------------------------------------------------------------- |
|
1560 // |
|
1561 MSwtUiUtils& CSwtListBase::Utils() const |
|
1562 { |
|
1563 return iDisplay.UiUtils(); |
|
1564 } |
|
1565 |
|
1566 // --------------------------------------------------------------------------- |
|
1567 // CSwtListBase::HandleScrollEventL |
|
1568 // From MEikScrollBarObserver |
|
1569 // --------------------------------------------------------------------------- |
|
1570 // |
|
1571 #ifdef RD_SCALABLE_UI_V2 |
|
1572 void CSwtListBase::HandleScrollEventL(CEikScrollBar* aScrollBar, TEikScrollEvent aEventType) |
|
1573 { |
|
1574 // On 5.0, drawing trough Java gives simply a better fps. |
|
1575 #ifdef RD_JAVA_S60_RELEASE_9_2 |
|
1576 switch (aEventType) |
|
1577 { |
|
1578 case EEikScrollThumbDragVert: |
|
1579 GetShell().SetUrgentPaintControl(this); |
|
1580 break; |
|
1581 case EEikScrollThumbReleaseVert: |
|
1582 GetShell().SetUrgentPaintControl(NULL); |
|
1583 break; |
|
1584 default: |
|
1585 break; |
|
1586 } |
|
1587 #endif // RD_JAVA_S60_RELEASE_9_2 |
|
1588 |
|
1589 iList->HandleScrollEventL(aScrollBar, aEventType); |
|
1590 ASwtScrollableBase::HandleScrollEventL(aScrollBar, aEventType); |
|
1591 } |
|
1592 #else //RD_SCALABLE_UI_V2 |
|
1593 void CSwtListBase::HandleScrollEventL(CEikScrollBar*, TEikScrollEvent) |
|
1594 { |
|
1595 } |
|
1596 #endif //RD_SCALABLE_UI_V2 |
|
1597 |
|
1598 // --------------------------------------------------------------------------- |
|
1599 // CSwtListBase::HandleScrollEventL |
|
1600 // From MEikListBoxObserver |
|
1601 // Handles default selection for touch. Unable to handle the selection events |
|
1602 // here since EEventItemClicked is not always sent for every tap. |
|
1603 // The selection events are handled in HandlePointerEvent. |
|
1604 // --------------------------------------------------------------------------- |
|
1605 // |
|
1606 #ifdef RD_SCALABLE_UI_V2 |
|
1607 void CSwtListBase::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType) |
|
1608 { |
|
1609 if (aListBox != iList) |
|
1610 { |
|
1611 return; |
|
1612 } |
|
1613 |
|
1614 UpdateFlickScrollingState(aEventType); |
|
1615 |
|
1616 switch (aEventType) |
|
1617 { |
|
1618 // On 5.0, drawing trough Java gives simply a better fps. |
|
1619 #ifdef RD_JAVA_S60_RELEASE_9_2 |
|
1620 case EEventPanningStarted: |
|
1621 GetShell().SetUrgentPaintControl(this); |
|
1622 break; |
|
1623 case EEventFlickStopped: |
|
1624 GetShell().SetUrgentPaintControl(NULL); |
|
1625 break; |
|
1626 #endif // RD_JAVA_S60_RELEASE_9_2 |
|
1627 #ifdef RD_JAVA_S60_RELEASE_9_2 |
|
1628 case EEventItemSingleClicked: |
|
1629 #else |
|
1630 case EEventItemDoubleClicked: |
|
1631 #endif // RD_JAVA_S60_RELEASE_9_2 |
|
1632 if (!(iStyle & KSwtStyleMulti)) |
|
1633 { |
|
1634 if (!iDisplay.RevertPointerEvent()) |
|
1635 iDisplay.PostDefaultSelectionEventL(iPeer); |
|
1636 } |
|
1637 break; |
|
1638 default: |
|
1639 // Do nothing |
|
1640 break; |
|
1641 } |
|
1642 } |
|
1643 #else //RD_SCALABLE_UI_V2 |
|
1644 void CSwtListBase::HandleListBoxEventL(CEikListBox*, TListBoxEvent) |
|
1645 { |
|
1646 } |
|
1647 #endif //RD_SCALABLE_UI_V2 |
|
1648 |
|
1649 // --------------------------------------------------------------------------- |
|
1650 // CSwtListBase::UpdateFlickScrollingState |
|
1651 // Updates flick scrolling status based on received listbox event. |
|
1652 // --------------------------------------------------------------------------- |
|
1653 // |
|
1654 void CSwtListBase::UpdateFlickScrollingState(TListBoxEvent aEventType) |
|
1655 { |
|
1656 switch (aEventType) |
|
1657 { |
|
1658 case EEventFlickStarted: |
|
1659 iFlickScrollingOngoing = ETrue; |
|
1660 iScrollbarPointerEventToListbox = ETrue; |
|
1661 break; |
|
1662 case EEventFlickStopped: |
|
1663 iFlickScrollingOngoing = EFalse; |
|
1664 break; |
|
1665 } |
|
1666 } |