|
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 <aknenv.h> |
|
14 #include <AknUtils.h> |
|
15 #include <eiktxlbx.h> |
|
16 #include <aknlists.h> |
|
17 #include "swtlist.h" |
|
18 #include "swtscrollbar.h" |
|
19 |
|
20 |
|
21 // ======== MEMBER FUNCTIONS ======== |
|
22 |
|
23 |
|
24 // --------------------------------------------------------------------------- |
|
25 // CSwtList::NewL |
|
26 // --------------------------------------------------------------------------- |
|
27 // |
|
28 CSwtList* CSwtList::NewL( |
|
29 MSwtDisplay& aDisplay, |
|
30 TSwtPeer aPeer, |
|
31 MSwtComposite& aParent, |
|
32 TInt aStyle) |
|
33 { |
|
34 CSwtList* self = new(ELeave) CSwtList(aDisplay, aPeer, aParent, aStyle); |
|
35 CleanupStack::PushL(self); |
|
36 self->ConstructL(); |
|
37 self->InitControlBaseL(); |
|
38 CleanupStack::Pop(self); |
|
39 return self; |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // CSwtList::CSwtList |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CSwtList::CSwtList( |
|
47 MSwtDisplay& aDisplay, |
|
48 TSwtPeer aPeer, |
|
49 MSwtComposite& aParent, |
|
50 TInt aStyle) |
|
51 : CSwtListBase(aDisplay, aPeer, aParent, aStyle) |
|
52 { |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // CSwtList::~CSwtList |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 CSwtList::~CSwtList() |
|
60 { |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // CSwtList::HandleItemAdditionL |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 void CSwtList::HandleItemAdditionL(TInt aNewFocusIndex) |
|
68 { |
|
69 ASSERT(iList); |
|
70 |
|
71 SetTextMaxWidth(ComputeTextMaxWidth()); |
|
72 |
|
73 // S60 behavior: the new added item is the new focused item |
|
74 // and becomes the top item |
|
75 TInt newItemIndex(0); |
|
76 if ((aNewFocusIndex >= 0) && (aNewFocusIndex < GetItemCount())) |
|
77 { |
|
78 newItemIndex = aNewFocusIndex; |
|
79 } |
|
80 |
|
81 iList->SetCurrentItemIndex(newItemIndex); |
|
82 |
|
83 if (iList->CurrentItemIndex() >= 0) |
|
84 { |
|
85 iList->SetTopItemIndex(iList->CurrentItemIndex()); |
|
86 } |
|
87 |
|
88 iList->HandleItemAdditionL(); |
|
89 |
|
90 // if we are in single selection, update the selection |
|
91 // to be the same as the current item index. |
|
92 if ((iStyle & KSwtStyleSingle) != 0) |
|
93 { |
|
94 iList->View()->UpdateSelectionL(CListBoxView::ESingleSelection); |
|
95 } |
|
96 |
|
97 UpdateListMskL(); |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CSwtList::HandleItemRemovalL |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 void CSwtList::HandleItemRemovalL( |
|
105 const RArray<TInt>& aRemovedItemIndices, |
|
106 TInt aOldFocusIndex) |
|
107 { |
|
108 ASSERT(iList); |
|
109 ASSERT(iList->View()); |
|
110 |
|
111 SetTextMaxWidth(ComputeTextMaxWidth()); |
|
112 |
|
113 TInt newFocusIndex(0); |
|
114 |
|
115 if (aRemovedItemIndices.Count()) |
|
116 { |
|
117 CalcFocusIndexAfterItemRemoval( |
|
118 newFocusIndex, |
|
119 aRemovedItemIndices, |
|
120 aOldFocusIndex); |
|
121 } |
|
122 |
|
123 ASSERT((newFocusIndex == 0) |
|
124 || ((newFocusIndex > 0) |
|
125 && (newFocusIndex < iList->Model()->NumberOfItems()))); |
|
126 iList->SetCurrentItemIndex(newFocusIndex); |
|
127 |
|
128 iList->HandleItemRemovalL(); |
|
129 |
|
130 if ((iStyle & KSwtStyleSingle) != 0) |
|
131 { |
|
132 iList->View()->UpdateSelectionL(CListBoxView::ESingleSelection); |
|
133 } |
|
134 |
|
135 UpdateListMskL(); |
|
136 |
|
137 // iList->View()->UpdateSelectionL is not sufficient. |
|
138 Redraw(); |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // CSwtList::ComputeSizeL |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 TSize CSwtList::ComputeSizeL(TInt aWHint, TInt aHHint) |
|
146 { |
|
147 if (iList == NULL) |
|
148 { |
|
149 return TSize(0, 0); |
|
150 } |
|
151 |
|
152 TSize preferredSize(aWHint, aHHint); |
|
153 |
|
154 if (aWHint == KSwtDefault) |
|
155 { |
|
156 preferredSize.iWidth = PreferredWidth(); |
|
157 } |
|
158 |
|
159 if (aHHint == KSwtDefault) |
|
160 { |
|
161 preferredSize.iHeight = PreferredHeight(); |
|
162 } |
|
163 |
|
164 return preferredSize; |
|
165 } |
|
166 |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // CSwtList::Scrollable |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 MSwtScrollable* CSwtList::Scrollable() |
|
173 { |
|
174 return CSwtListBase::Scrollable(); |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // CSwtList::DeselectItems |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 void CSwtList::DeselectItems(const TInt* aIndices, TInt aCount) |
|
182 { |
|
183 CSwtListBase::DeselectItems(aIndices, aCount); |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // CSwtList::DeselectItem |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 void CSwtList::DeselectItem(TInt aIndex) |
|
191 { |
|
192 CSwtListBase::DeselectItem(aIndex); |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // CSwtList::DeselectRange |
|
197 // --------------------------------------------------------------------------- |
|
198 // |
|
199 void CSwtList::DeselectRange(TInt aStart, TInt aEnd) |
|
200 { |
|
201 CSwtListBase::DeselectRange(aStart, aEnd); |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------------------------- |
|
205 // CSwtList::DeselectAll |
|
206 // --------------------------------------------------------------------------- |
|
207 // |
|
208 void CSwtList::DeselectAll() |
|
209 { |
|
210 CSwtListBase::DeselectAll(); |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // CSwtList::GetFocusIndex |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 TInt CSwtList::GetFocusIndex() const |
|
218 { |
|
219 return CSwtListBase::GetFocusIndex(); |
|
220 } |
|
221 |
|
222 // --------------------------------------------------------------------------- |
|
223 // CSwtList::GetSelectionCount |
|
224 // --------------------------------------------------------------------------- |
|
225 // |
|
226 TInt CSwtList::GetSelectionCount() const |
|
227 { |
|
228 return CSwtListBase::GetSelectionCount(); |
|
229 } |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // CSwtList::GetSelectionIndices |
|
233 // --------------------------------------------------------------------------- |
|
234 // |
|
235 const CArrayFix<TInt>* CSwtList::GetSelectionIndices() const |
|
236 { |
|
237 return CSwtListBase::GetSelectionIndices(); |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // CSwtList::SelectItemL |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 void CSwtList::SelectItemL(TInt aIndex, TBool aScroll) |
|
245 { |
|
246 CSwtListBase::SelectItemL(aIndex, aScroll); |
|
247 } |
|
248 |
|
249 // --------------------------------------------------------------------------- |
|
250 // CSwtList::SelectRangeL |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 void CSwtList::SelectRangeL(TInt aStart, TInt aEnd) |
|
254 { |
|
255 CSwtListBase::SelectRangeL(aStart, aEnd); |
|
256 } |
|
257 |
|
258 // --------------------------------------------------------------------------- |
|
259 // CSwtList::SelectAllL |
|
260 // --------------------------------------------------------------------------- |
|
261 // |
|
262 void CSwtList::SelectAllL() |
|
263 { |
|
264 CSwtListBase::SelectAllL(); |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // CSwtList::ShowSelection |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 void CSwtList::ShowSelection() |
|
272 { |
|
273 CSwtListBase::ShowSelection(); |
|
274 } |
|
275 |
|
276 // --------------------------------------------------------------------------- |
|
277 // CSwtList::AppendL |
|
278 // --------------------------------------------------------------------------- |
|
279 // |
|
280 void CSwtList::AppendL(const TDesC& aPtr) |
|
281 { |
|
282 ASSERT(iList); |
|
283 ASSERT(iTextItems); |
|
284 |
|
285 // CDesCArray is the base class for descriptor arrays implementing MDesCArray, |
|
286 // meaning that the array returned by ItemTextArray() is necessarily a subclass |
|
287 // of CDesCArray. |
|
288 CDesCArray* itemTextArray = static_cast<CDesCArray*>(iList->Model()->ItemTextArray()); |
|
289 ASSERT(itemTextArray); |
|
290 HBufC* itemText = CreateItemTextLC(aPtr); |
|
291 TRAPD(error, itemTextArray->AppendL(*itemText)); |
|
292 CleanupStack::PopAndDestroy(); |
|
293 if (error) |
|
294 { |
|
295 User::Leave(ESwtErrorItemNotAdded); |
|
296 } |
|
297 |
|
298 TRAP(error, iTextItems->AppendL(aPtr)); |
|
299 if (error) |
|
300 { |
|
301 itemTextArray->Delete(itemTextArray->Count()-1); |
|
302 User::Leave(ESwtErrorItemNotAdded); |
|
303 } |
|
304 |
|
305 HandleItemAdditionL(GetItemCount()-1); |
|
306 } |
|
307 |
|
308 // --------------------------------------------------------------------------- |
|
309 // CSwtList::InsertL |
|
310 // --------------------------------------------------------------------------- |
|
311 // |
|
312 void CSwtList::InsertL(TInt aPos, const TDesC& aPtr) |
|
313 { |
|
314 ASSERT(iList); |
|
315 ASSERT(iTextItems); |
|
316 |
|
317 // CDesCArray is the base class for descriptor arrays implementing MDesCArray, |
|
318 // meaning that the array returned by ItemTextArray() is necessarily a subclass |
|
319 // of CDesCArray. |
|
320 CDesCArray* itemTextArray = static_cast<CDesCArray*>(iList->Model()->ItemTextArray()); |
|
321 ASSERT(itemTextArray); |
|
322 if (aPos < 0 || aPos > itemTextArray->Count()) |
|
323 { |
|
324 User::Leave(ESwtErrorInvalidRange); |
|
325 } |
|
326 |
|
327 HBufC* itemText = CreateItemTextLC(aPtr); |
|
328 TRAPD(error, itemTextArray->InsertL(aPos, *itemText)); |
|
329 CleanupStack::PopAndDestroy(); |
|
330 if (error) |
|
331 { |
|
332 User::Leave(ESwtErrorItemNotAdded); |
|
333 } |
|
334 |
|
335 TRAP(error, iTextItems->InsertL(aPos, aPtr)); |
|
336 if (error) |
|
337 { |
|
338 itemTextArray->Delete(aPos); |
|
339 User::Leave(ESwtErrorItemNotAdded); |
|
340 } |
|
341 |
|
342 // Update selection indices after item insertion. |
|
343 const CArrayFix<TInt>* selectionIndices = GetSelectionIndices(); |
|
344 if (selectionIndices != NULL) |
|
345 { |
|
346 if (selectionIndices->Count() > 0) |
|
347 { |
|
348 CArrayFix<TInt>* newSelectionArray = new(ELeave) CArrayFixFlat<TInt>(selectionIndices->Count()); |
|
349 CleanupStack::PushL(newSelectionArray); |
|
350 for (TInt ind = 0; ind < selectionIndices->Count(); ind++) |
|
351 { |
|
352 if ((*selectionIndices)[ind] >= aPos) |
|
353 { |
|
354 newSelectionArray->AppendL((*selectionIndices)[ind]+1); |
|
355 } |
|
356 else |
|
357 { |
|
358 newSelectionArray->AppendL((*selectionIndices)[ind]); |
|
359 } |
|
360 } |
|
361 iList->SetSelectionIndexesL(newSelectionArray); |
|
362 CleanupStack::PopAndDestroy(); |
|
363 } |
|
364 } |
|
365 |
|
366 HandleItemAdditionL(aPos); |
|
367 } |
|
368 |
|
369 // --------------------------------------------------------------------------- |
|
370 // CSwtList::GetItemL |
|
371 // --------------------------------------------------------------------------- |
|
372 // |
|
373 void CSwtList::GetItemL(TInt aItemIndex, TPtrC& aString) const |
|
374 { |
|
375 ASSERT(iList); |
|
376 ASSERT(aString.Length()==0); |
|
377 |
|
378 // verify the range |
|
379 TInt count = iList->Model()->NumberOfItems(); |
|
380 if (aItemIndex < 0 || aItemIndex >= count) |
|
381 { |
|
382 User::Leave(ESwtErrorInvalidRange); |
|
383 } |
|
384 aString.Set((*iTextItems)[aItemIndex]); // Remove the inserted tab for avkon list items. |
|
385 } |
|
386 |
|
387 // --------------------------------------------------------------------------- |
|
388 // CSwtList::GetItemCount |
|
389 // --------------------------------------------------------------------------- |
|
390 // |
|
391 TInt CSwtList::GetItemCount() const |
|
392 { |
|
393 ASSERT(iList); |
|
394 return iList->Model()->NumberOfItems(); |
|
395 } |
|
396 |
|
397 // --------------------------------------------------------------------------- |
|
398 // CSwtList::GetItemHeight |
|
399 // --------------------------------------------------------------------------- |
|
400 // |
|
401 TInt CSwtList::GetItemHeight() const |
|
402 { |
|
403 ASSERT(iList); |
|
404 return iList->ItemHeight(); |
|
405 } |
|
406 |
|
407 // --------------------------------------------------------------------------- |
|
408 // CSwtList::GetSelectionIndex |
|
409 // --------------------------------------------------------------------------- |
|
410 // |
|
411 TInt CSwtList::GetSelectionIndex() const |
|
412 { |
|
413 if (!iList) |
|
414 { |
|
415 return -1; |
|
416 } |
|
417 |
|
418 if (!(iStyle & KSwtStyleMulti)) |
|
419 { |
|
420 if (iList->Model()->NumberOfItems() == 0) |
|
421 { |
|
422 return -1; |
|
423 } |
|
424 else |
|
425 { |
|
426 return iList->CurrentItemIndex(); |
|
427 } |
|
428 } |
|
429 else |
|
430 { |
|
431 if (iList->SelectionIndexes()->Count() == 0) |
|
432 { |
|
433 return -1; // no elements selected |
|
434 } |
|
435 else |
|
436 { |
|
437 TInt current = iList->CurrentItemIndex(); |
|
438 if (iList->View()->ItemIsSelected(current)) |
|
439 { |
|
440 return current; |
|
441 } |
|
442 return (*(iList->SelectionIndexes()))[0]; |
|
443 } |
|
444 |
|
445 } |
|
446 } |
|
447 |
|
448 // --------------------------------------------------------------------------- |
|
449 // CSwtList::GetTopIndex |
|
450 // --------------------------------------------------------------------------- |
|
451 // |
|
452 TInt CSwtList::GetTopIndex() const |
|
453 { |
|
454 ASSERT(iList); |
|
455 return iList->TopItemIndex(); |
|
456 } |
|
457 |
|
458 // --------------------------------------------------------------------------- |
|
459 // CSwtList::IndexOf |
|
460 // --------------------------------------------------------------------------- |
|
461 // |
|
462 TInt CSwtList::IndexOf(const TDesC& aString, TInt& aStart) const |
|
463 { |
|
464 if (aStart < 0 || aStart >= GetItemCount()) |
|
465 { |
|
466 return -1; |
|
467 } |
|
468 |
|
469 if (aStart == 0) |
|
470 { |
|
471 TInt pos; |
|
472 if (iTextItems->Find(aString, pos) == KErrNone) |
|
473 { |
|
474 return pos; |
|
475 } |
|
476 } |
|
477 else |
|
478 { |
|
479 for (TInt i = aStart; i < iTextItems->Count(); ++i) |
|
480 { |
|
481 if (aString.Compare((*iTextItems)[i]) == KErrNone) |
|
482 { |
|
483 return i; |
|
484 } |
|
485 } |
|
486 } |
|
487 return -1; |
|
488 } |
|
489 |
|
490 // --------------------------------------------------------------------------- |
|
491 // CSwtList::IsSelected |
|
492 // --------------------------------------------------------------------------- |
|
493 // |
|
494 TBool CSwtList::IsSelected(TInt aIndex) const |
|
495 { |
|
496 ASSERT(iList); |
|
497 return iList->View()->ItemIsSelected(aIndex); |
|
498 } |
|
499 |
|
500 // --------------------------------------------------------------------------- |
|
501 // CSwtList::RemoveItemsL |
|
502 // --------------------------------------------------------------------------- |
|
503 // |
|
504 void CSwtList::RemoveItemsL(const TInt* aIndices, TInt aCount) |
|
505 { |
|
506 ASSERT(iList); |
|
507 ASSERT(iTextItems); |
|
508 ASSERT(aIndices); |
|
509 ASSERT(aCount > 0); |
|
510 |
|
511 TInt count = GetItemCount(); |
|
512 // Elements are ordered from high to low in Java side. |
|
513 TInt min = aIndices[aCount - 1]; |
|
514 TInt max = aIndices[0]; |
|
515 if (min < 0 || max >= count) |
|
516 { |
|
517 User::Leave(ESwtErrorInvalidRange); |
|
518 } |
|
519 |
|
520 TInt currentItemIndex(iList->CurrentItemIndex()); |
|
521 if (iRemovedItemIndices.Count() > 0) |
|
522 { |
|
523 iRemovedItemIndices.Reset(); |
|
524 } |
|
525 |
|
526 TInt oldIndex = -1; |
|
527 CDesCArray* itemTextArray = |
|
528 static_cast<CDesCArray*>(iList->Model()->ItemTextArray()); |
|
529 ASSERT(itemTextArray); |
|
530 for (TInt i = 0; i < aCount; ++i) |
|
531 { |
|
532 if (aIndices[i] != oldIndex) |
|
533 { |
|
534 itemTextArray->Delete(aIndices[i]); |
|
535 iTextItems->Delete(aIndices[i]); |
|
536 oldIndex = aIndices[i]; |
|
537 iRemovedItemIndices.Insert(oldIndex, 0); |
|
538 } |
|
539 } |
|
540 |
|
541 itemTextArray->Compress(); |
|
542 iTextItems->Compress(); |
|
543 |
|
544 HandleItemRemovalL(iRemovedItemIndices, currentItemIndex); |
|
545 iRemovedItemIndices.Reset(); |
|
546 } |
|
547 |
|
548 // --------------------------------------------------------------------------- |
|
549 // CSwtList::RemoveItemL |
|
550 // --------------------------------------------------------------------------- |
|
551 // |
|
552 void CSwtList::RemoveItemL(TInt aIndex) |
|
553 { |
|
554 ASSERT(iList); |
|
555 ASSERT(iTextItems); |
|
556 |
|
557 if (aIndex < 0 || aIndex >= GetItemCount()) |
|
558 { |
|
559 User::Leave(ESwtErrorInvalidRange); |
|
560 } |
|
561 |
|
562 TInt currentItemIndex(iList->CurrentItemIndex()); |
|
563 |
|
564 CDesCArray* itemTextArray = static_cast<CDesCArray*>(iList->Model()->ItemTextArray()); |
|
565 ASSERT(itemTextArray); |
|
566 itemTextArray->Delete(aIndex); |
|
567 iTextItems->Delete(aIndex); |
|
568 |
|
569 itemTextArray->Compress(); |
|
570 iTextItems->Compress(); |
|
571 |
|
572 if (iRemovedItemIndices.Count() > 0) |
|
573 { |
|
574 iRemovedItemIndices.Reset(); |
|
575 } |
|
576 iRemovedItemIndices.Append(aIndex); |
|
577 HandleItemRemovalL(iRemovedItemIndices, currentItemIndex); |
|
578 iRemovedItemIndices.Reset(); |
|
579 } |
|
580 |
|
581 // --------------------------------------------------------------------------- |
|
582 // CSwtList::RemoveRangeL |
|
583 // --------------------------------------------------------------------------- |
|
584 // |
|
585 void CSwtList::RemoveRangeL(TInt aStart, TInt aEnd) |
|
586 { |
|
587 ASSERT(iList); |
|
588 ASSERT(iTextItems); |
|
589 |
|
590 if (aStart < 0 || aEnd >= GetItemCount()) |
|
591 { |
|
592 User::Leave(ESwtErrorInvalidRange); |
|
593 } |
|
594 |
|
595 TInt currentItemIndex(iList->CurrentItemIndex()); |
|
596 |
|
597 CDesCArray* itemTextArray = static_cast<CDesCArray*>(iList->Model()->ItemTextArray()); |
|
598 ASSERT(itemTextArray); |
|
599 itemTextArray->Delete(aStart, (aEnd - aStart) + 1); //lint !e834 |
|
600 iTextItems->Delete(aStart, (aEnd - aStart) + 1); |
|
601 |
|
602 itemTextArray->Compress(); |
|
603 iTextItems->Compress(); |
|
604 |
|
605 |
|
606 if (iRemovedItemIndices.Count() > 0) |
|
607 { |
|
608 iRemovedItemIndices.Reset(); |
|
609 } |
|
610 for (TInt ind = aStart; ind <= aEnd; ind++) |
|
611 { |
|
612 iRemovedItemIndices.Append(ind); |
|
613 } |
|
614 HandleItemRemovalL(iRemovedItemIndices, currentItemIndex); |
|
615 iRemovedItemIndices.Reset(); |
|
616 } |
|
617 |
|
618 // --------------------------------------------------------------------------- |
|
619 // CSwtList::RemoveAllL |
|
620 // --------------------------------------------------------------------------- |
|
621 // |
|
622 void CSwtList::RemoveAllL() |
|
623 { |
|
624 ASSERT(iList); |
|
625 ASSERT(iTextItems); |
|
626 |
|
627 if (GetItemCount() == 0) |
|
628 { |
|
629 return; |
|
630 } |
|
631 |
|
632 CDesCArray* itemTextArray = static_cast<CDesCArray*>(iList->Model()->ItemTextArray()); |
|
633 ASSERT(itemTextArray); |
|
634 itemTextArray->Reset(); |
|
635 iTextItems->Reset(); |
|
636 |
|
637 if (iRemovedItemIndices.Count() > 0) |
|
638 { |
|
639 iRemovedItemIndices.Reset(); |
|
640 } |
|
641 HandleItemRemovalL(iRemovedItemIndices, 0); |
|
642 } |
|
643 |
|
644 // --------------------------------------------------------------------------- |
|
645 // CSwtList::SetFocusIndex |
|
646 // --------------------------------------------------------------------------- |
|
647 // |
|
648 void CSwtList::SetFocusIndex(TInt aIndex) |
|
649 { |
|
650 ASSERT(iList); |
|
651 |
|
652 // By now, we only call this method in multiple selection. |
|
653 // In single selection, we assume that setting the focus means selecting. |
|
654 ASSERT(iStyle & KSwtStyleMulti); |
|
655 |
|
656 if (aIndex < 0 || aIndex >= GetItemCount()) |
|
657 { |
|
658 return; |
|
659 } |
|
660 |
|
661 TInt old = iList->CurrentItemIndex(); |
|
662 if (old != aIndex) |
|
663 { |
|
664 iList->SetCurrentItemIndex(aIndex); |
|
665 iList->View()->DrawItem(aIndex); |
|
666 if (old != -1) |
|
667 { |
|
668 iList->View()->DrawItem(old); |
|
669 } |
|
670 } |
|
671 TRAP_IGNORE(UpdateListMskL()); |
|
672 } |
|
673 |
|
674 // --------------------------------------------------------------------------- |
|
675 // CSwtList::SetItemsL |
|
676 // --------------------------------------------------------------------------- |
|
677 // |
|
678 void CSwtList::SetItemsL(MDesCArray* aStringArray) |
|
679 { |
|
680 ASSERT(iList); |
|
681 ASSERT(iTextItems); |
|
682 ASSERT(aStringArray); |
|
683 |
|
684 // We remove the old selection |
|
685 iList->View()->ClearSelection(); |
|
686 |
|
687 CDesCArray* itemArray = new(ELeave) CDesCArrayFlat(aStringArray->MdcaCount()); |
|
688 CleanupStack::PushL(itemArray); |
|
689 |
|
690 iTextItems->Reset(); |
|
691 |
|
692 for (TInt i = 0; i < aStringArray->MdcaCount(); ++i) |
|
693 { |
|
694 HBufC* itemText = CreateItemTextLC(aStringArray->MdcaPoint(i)); |
|
695 itemArray->AppendL(*itemText); |
|
696 CleanupStack::PopAndDestroy(itemText); |
|
697 iTextItems->AppendL(aStringArray->MdcaPoint(i)); |
|
698 } |
|
699 |
|
700 iList->Model()->SetItemTextArray(itemArray); |
|
701 |
|
702 CleanupStack::Pop(itemArray); |
|
703 |
|
704 HandleItemAdditionL(0); |
|
705 |
|
706 // iList->View()->UpdateSelectionL(CListBoxView::ESingleSelection); |
|
707 // in HandleItemAdditionL is not sufficient. |
|
708 Redraw(); |
|
709 } |
|
710 |
|
711 // --------------------------------------------------------------------------- |
|
712 // CSwtList::SetTopIndex |
|
713 // --------------------------------------------------------------------------- |
|
714 // |
|
715 void CSwtList::SetTopIndex(TInt aIndex) |
|
716 { |
|
717 ASSERT(iList); |
|
718 |
|
719 TInt count = GetItemCount(); |
|
720 |
|
721 if (count == 0) |
|
722 { |
|
723 return; |
|
724 } |
|
725 |
|
726 if (aIndex < 0 || aIndex >= count) |
|
727 { |
|
728 return; |
|
729 } |
|
730 |
|
731 iList->SetTopItemIndex(aIndex); |
|
732 Redraw(); |
|
733 } |