|
1 /* |
|
2 * Copyright (c) 2002 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 the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "BrowserSelectElementListBox.h" |
|
22 #include "BrowserSelectElementModel.h" |
|
23 #include "BrowserSelectElementItemDrawer.h" |
|
24 |
|
25 #include <AknSfld.h> |
|
26 |
|
27 // CONSTANTS |
|
28 #include "BrowserDialogsProviderConstants.h" |
|
29 |
|
30 #include "eikon.hrh" |
|
31 |
|
32 |
|
33 // ================= MEMBER FUNCTIONS ======================= |
|
34 // ====== TBrCtlFavouritesListboxFilterTextArray ======= |
|
35 |
|
36 TBrCtlSelectElementFilterTextArray::TBrCtlSelectElementFilterTextArray( |
|
37 const CArrayFix<TBrCtlSelectOptionData>& aOptions ) |
|
38 : iOptions ( aOptions ) |
|
39 { |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------- |
|
43 // TBrCtlFavouritesListboxFilterTextArray::MdcaCount |
|
44 // --------------------------------------------------------- |
|
45 // |
|
46 TInt TBrCtlSelectElementFilterTextArray::MdcaCount() const |
|
47 { |
|
48 return iOptions.Count(); |
|
49 } |
|
50 |
|
51 |
|
52 // --------------------------------------------------------- |
|
53 // TBrCtlFavouritesListboxFilterTextArray::MdcaPoint |
|
54 // --------------------------------------------------------- |
|
55 // |
|
56 TPtrC TBrCtlSelectElementFilterTextArray::MdcaPoint ( TInt aIndex ) const |
|
57 { |
|
58 return iOptions.At( aIndex ).Text(); |
|
59 } |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 // ================= MEMBER FUNCTIONS ======================= |
|
65 // ====== TBrCtlSelectElementItemTextArray ======= |
|
66 |
|
67 TBrCtlSelectElementItemTextArray::TBrCtlSelectElementItemTextArray( |
|
68 const CArrayFix<TBrCtlSelectOptionData>& aOptions ) |
|
69 : iOptions( aOptions ) |
|
70 { |
|
71 iText = NULL; |
|
72 } |
|
73 |
|
74 TBrCtlSelectElementItemTextArray::~TBrCtlSelectElementItemTextArray() |
|
75 { |
|
76 delete iText; |
|
77 } |
|
78 |
|
79 // ---------------------------------------------------------------------------- |
|
80 // TBrCtlSelectElementItemTextArray::AddPrefixLC |
|
81 // ---------------------------------------------------------------------------- |
|
82 // |
|
83 HBufC* TBrCtlSelectElementItemTextArray::AddPrefixLC( |
|
84 const TDesC& aText, |
|
85 TBool aIsOptionGroup ) const |
|
86 { |
|
87 // title = prefix + text + zero terminator |
|
88 TPtrC prefix( aIsOptionGroup ? KPrefixOptionGroup : KPrefixOption ); |
|
89 HBufC* title = HBufC::NewL( prefix.Length() + aText.Length() + 1 ); |
|
90 |
|
91 CleanupStack::PushL( title ); |
|
92 |
|
93 // Copy the text |
|
94 HBufC* buf = HBufC::NewL( aText.Length() ); |
|
95 TPtr ptr = buf->Des(); |
|
96 ptr.Copy( aText ); |
|
97 title->Des().Append( prefix ); |
|
98 title->Des().Append( ptr ); |
|
99 title->Des().ZeroTerminate(); |
|
100 |
|
101 delete buf; |
|
102 |
|
103 return title; |
|
104 } |
|
105 |
|
106 // ---------------------------------------------------------------------------- |
|
107 // TBrCtlSelectElementItemTextArray::FormatTextL |
|
108 // ---------------------------------------------------------------------------- |
|
109 // |
|
110 void TBrCtlSelectElementItemTextArray::FormatTextL( |
|
111 const TBrCtlSelectOptionData& optionData ) |
|
112 { |
|
113 // free the previous text |
|
114 if ( iText ) |
|
115 { |
|
116 delete iText; |
|
117 iText = NULL; |
|
118 } |
|
119 |
|
120 // save the text in the right format |
|
121 HBufC* title = AddPrefixLC( optionData.Text(), optionData.IsOptGroup() ); |
|
122 CleanupStack::Pop(); // title |
|
123 iText = title; |
|
124 } |
|
125 |
|
126 // ---------------------------------------------------------------------------- |
|
127 // TBrCtlSelectElementItemTextArray::MdcaCount |
|
128 // ---------------------------------------------------------------------------- |
|
129 // |
|
130 TPtrC TBrCtlSelectElementItemTextArray::MdcaPoint( TInt aIndex ) const |
|
131 { |
|
132 TBrCtlSelectElementItemTextArray* self = |
|
133 CONST_CAST( TBrCtlSelectElementItemTextArray*, this ); |
|
134 |
|
135 // prepare the new text |
|
136 TRAPD( err, self->FormatTextL( iOptions.At( aIndex ) ) ); |
|
137 |
|
138 if ( !err ) |
|
139 { |
|
140 return iText->Des(); |
|
141 } |
|
142 else |
|
143 { |
|
144 return TPtrC( KNullDesC ); |
|
145 } |
|
146 } |
|
147 |
|
148 |
|
149 |
|
150 // ================= MEMBER FUNCTIONS ========================================= |
|
151 |
|
152 // ---------------------------------------------------------------------------- |
|
153 // CBrowserSelectElementListBox::CBrowserSelectElementListBox |
|
154 // ---------------------------------------------------------------------------- |
|
155 // |
|
156 CBrowserSelectElementListBox::CBrowserSelectElementListBox( |
|
157 const TBrCtlSelectOptionType aBrCtlSelectOptionType, |
|
158 const CArrayFix<TBrCtlSelectOptionData>& aOptions ) : |
|
159 iOptions( aOptions ), |
|
160 iBrCtlSelectOptionType( aBrCtlSelectOptionType ) |
|
161 { |
|
162 } |
|
163 |
|
164 |
|
165 // ---------------------------------------------------------------------------- |
|
166 // CBrowserSelectElementListBox::ConstructL |
|
167 // ---------------------------------------------------------------------------- |
|
168 // |
|
169 void CBrowserSelectElementListBox::ConstructL( const CCoeControl& aParent ) |
|
170 { |
|
171 iHasNotMoved = ETrue; |
|
172 iModel = CBrowserSelectElementModel::NewL( iOptions ); |
|
173 STATIC_CAST (CBrowserSelectElementModel*,iModel)->SetItemArray(); |
|
174 CreateItemDrawerL(); |
|
175 |
|
176 CEikListBox::ConstructL( &aParent, EAknListBoxMultiselectionList ); |
|
177 |
|
178 // this method call is required for correct support of |
|
179 // pictographs in S60 Japanese |
|
180 EnableExtendedDrawingL(); |
|
181 |
|
182 SetSelectionIndexesL(); |
|
183 ItemDrawer()->FormattedCellData()->SetControl(this); |
|
184 ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue ); |
|
185 } |
|
186 |
|
187 |
|
188 // ---------------------------------------------------------------------------- |
|
189 // CBrowserSelectElementListBox::CreateItemDrawerL |
|
190 // ---------------------------------------------------------------------------- |
|
191 // |
|
192 void CBrowserSelectElementListBox::CreateItemDrawerL() |
|
193 { |
|
194 CFormattedCellListBoxData* data = CPopupFormattedListBoxData::NewL(); |
|
195 CleanupStack::PushL( data ); |
|
196 iItemDrawer = new (ELeave) CBrowserSelectElementItemDrawer |
|
197 ( *Model(), *LatinBold13(), *data, iBrCtlSelectOptionType, iOptions ); |
|
198 CleanupStack::Pop(); // data |
|
199 STATIC_CAST( CBrowserSelectElementItemDrawer*, |
|
200 iItemDrawer )->LoadIconsL(); |
|
201 } |
|
202 |
|
203 // ---------------------------------------------------------------------------- |
|
204 // CBrowserSelectElementListBox::OfferKeyEventL |
|
205 // ---------------------------------------------------------------------------- |
|
206 // |
|
207 TKeyResponse CBrowserSelectElementListBox::OfferKeyEventL( |
|
208 const TKeyEvent& aKeyEvent, |
|
209 TEventCode aType ) |
|
210 { |
|
211 TKeyResponse resp; |
|
212 TInt index = CurrentItemIndex(); |
|
213 iHasNotMoved = EFalse; |
|
214 switch ( aKeyEvent.iCode ) |
|
215 { |
|
216 case EKeyEscape: |
|
217 ReportEventL( MCoeControlObserver::EEventRequestCancel ); |
|
218 resp = EKeyWasConsumed; |
|
219 break; |
|
220 case EKeyLeftUpArrow: // Northwest |
|
221 case EStdKeyDevice10: // : Extra KeyEvent supports diagonal event simulator wedge |
|
222 case EKeyUpArrow: // North |
|
223 case EKeyRightUpArrow: // Northeast |
|
224 case EStdKeyDevice11: // : Extra KeyEvent supports diagonal event simulator wedge |
|
225 |
|
226 for ( ;( --index >= 0 );) |
|
227 { |
|
228 |
|
229 if (!(iOptions.At(((CBrowserSelectElementModel*)Model())->Filter() |
|
230 ->FilteredItemIndex(index)).IsOptGroup())) // find the previous option |
|
231 { |
|
232 break; |
|
233 } |
|
234 } |
|
235 |
|
236 if ( index >= 0 ) |
|
237 { |
|
238 SetCurrentItemIndexAndDraw( index ); |
|
239 } |
|
240 else // no previous option |
|
241 { |
|
242 if ( TopItemIndex() != 0 ) |
|
243 { |
|
244 // show the invisible part |
|
245 SetTopItemIndex( 0 ); |
|
246 DrawNow(); |
|
247 } |
|
248 } |
|
249 resp = EKeyWasConsumed; |
|
250 break; |
|
251 |
|
252 case EKeyLeftDownArrow: // Southwest |
|
253 case EStdKeyDevice13: // : Extra KeyEvent supports diagonal event simulator wedge |
|
254 case EKeyDownArrow: // South |
|
255 case EKeyRightDownArrow: // Southeast |
|
256 case EStdKeyDevice12: // : Extra KeyEvent supports diagonal event simulator wedge |
|
257 { |
|
258 TInt count = 0; |
|
259 |
|
260 //Findbox is visible, accept only filtered items. |
|
261 // |
|
262 if ( ((CBrowserSelectElementModel*)Model())->Filter() ) |
|
263 { |
|
264 count = ((CBrowserSelectElementModel*)Model())->Filter() |
|
265 ->FilteredNumberOfItems(); |
|
266 } |
|
267 |
|
268 for ( ;( ++index < count ); ) |
|
269 { |
|
270 |
|
271 if ( !(iOptions.At(((CBrowserSelectElementModel*)Model())->Filter() |
|
272 ->FilteredItemIndex(index)).IsOptGroup()) ) // find the next option |
|
273 { |
|
274 break; |
|
275 } |
|
276 } |
|
277 |
|
278 if ( index < count ) |
|
279 { |
|
280 SetCurrentItemIndexAndDraw( index ); |
|
281 } |
|
282 resp = EKeyWasConsumed; |
|
283 } |
|
284 break; |
|
285 |
|
286 case EKeyOK: |
|
287 case EKeyEnter: |
|
288 { |
|
289 |
|
290 if ( iBrCtlSelectOptionType != ESelectTypeMultiple ) |
|
291 { |
|
292 // select the current item |
|
293 View()->ClearSelection(); |
|
294 View()->SelectItemL( index ); |
|
295 resp = EKeyWasConsumed; |
|
296 // need to report the event because might be onpick |
|
297 ReportListBoxEventL |
|
298 ( MEikListBoxObserver::EEventEnterKeyPressed ); |
|
299 |
|
300 } |
|
301 else |
|
302 { |
|
303 if (index >= 0 && !(iOptions.At(((CBrowserSelectElementModel*)Model())-> |
|
304 Filter()->FilteredItemIndex(index)).IsOptGroup())) |
|
305 { |
|
306 resp = CEikListBox::OfferKeyEventL |
|
307 ( aKeyEvent, aType ); |
|
308 |
|
309 ReportListBoxEventL |
|
310 ( MEikListBoxObserver::EEventEnterKeyPressed ); |
|
311 } |
|
312 else |
|
313 { |
|
314 // Avoid to select optiongroup text |
|
315 resp = EKeyWasConsumed; |
|
316 } |
|
317 } |
|
318 } |
|
319 break; |
|
320 |
|
321 default: |
|
322 // workaround for autoselection problem |
|
323 // (Ok softkey selects focused item) |
|
324 if ( aKeyEvent.iCode != EKeyApplicationF ) |
|
325 { |
|
326 resp = CEikListBox::OfferKeyEventL( aKeyEvent, aType ); |
|
327 } |
|
328 else |
|
329 { |
|
330 resp = EKeyWasConsumed; |
|
331 } |
|
332 } |
|
333 |
|
334 return resp; |
|
335 } |
|
336 |
|
337 // ---------------------------------------------------------------------------- |
|
338 // CBrowserSelectElementListBox::HandlePointerEventL |
|
339 // ---------------------------------------------------------------------------- |
|
340 // |
|
341 void CBrowserSelectElementListBox::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
342 { |
|
343 CAknSingleGraphicPopupMenuStyleListBox::HandlePointerEventL(aPointerEvent); |
|
344 TInt index = CurrentItemIndex(); |
|
345 iHasNotMoved = EFalse; |
|
346 switch (aPointerEvent.iType) |
|
347 { |
|
348 case TPointerEvent::EButton1Up: |
|
349 if ( iBrCtlSelectOptionType != ESelectTypeMultiple ) |
|
350 { |
|
351 // select the current item |
|
352 View()->ClearSelection(); |
|
353 View()->SelectItemL( index ); |
|
354 ReportListBoxEventL( MEikListBoxObserver::EEventEnterKeyPressed ); |
|
355 } |
|
356 else |
|
357 { |
|
358 if (index >= 0 && !(iOptions.At(((CBrowserSelectElementModel*)Model())-> |
|
359 Filter()->FilteredItemIndex(index)).IsOptGroup())) |
|
360 { |
|
361 View()->ToggleItemL(index); |
|
362 ReportListBoxEventL( MEikListBoxObserver::EEventEnterKeyPressed ); |
|
363 } |
|
364 } |
|
365 break; |
|
366 default: |
|
367 break; |
|
368 } |
|
369 } |
|
370 |
|
371 // ---------------------------------------------------------------------------- |
|
372 // CBrowserSelectElementListBox::FocusChanged |
|
373 // ---------------------------------------------------------------------------- |
|
374 // |
|
375 void CBrowserSelectElementListBox::FocusChanged( TDrawNow aDrawNow ) |
|
376 { |
|
377 // Do nothing until the listbox is fully constructed |
|
378 // The dialogpage sets the focus before calling ConstructL |
|
379 if ( iView ) |
|
380 { |
|
381 CEikListBox::FocusChanged( aDrawNow ); |
|
382 } |
|
383 } |
|
384 |
|
385 // ---------------------------------------------------------------------------- |
|
386 // CBrowserSelectElementListBox::SizeChanged |
|
387 // ---------------------------------------------------------------------------- |
|
388 // |
|
389 void CBrowserSelectElementListBox::SizeChanged() |
|
390 { |
|
391 CAknSingleGraphicPopupMenuStyleListBox::SizeChanged(); |
|
392 AdjustHighlight(); |
|
393 } |
|
394 |
|
395 // ---------------------------------------------------------------------------- |
|
396 // CBrCtlSelectElementListBox::SetSelectionIndexesL |
|
397 // ---------------------------------------------------------------------------- |
|
398 // |
|
399 void CBrowserSelectElementListBox::SetSelectionIndexesL() |
|
400 { |
|
401 CListBoxView::CSelectionIndexArray* arrayOfSelectionIndexes; |
|
402 arrayOfSelectionIndexes = new (ELeave) CArrayFixFlat<TInt>(10); |
|
403 CleanupStack::PushL( arrayOfSelectionIndexes ); |
|
404 for ( TInt ii = 0; ii < iOptions.Count(); ++ii ) |
|
405 { |
|
406 if ( iOptions.At( ii ).IsSelected() || iOptions.At( ii ).IsOptGroup() ) |
|
407 { |
|
408 arrayOfSelectionIndexes->AppendL( ii ); |
|
409 } |
|
410 } |
|
411 CEikListBox::SetSelectionIndexesL( arrayOfSelectionIndexes ); |
|
412 CleanupStack::PopAndDestroy(); // arrayOfSelectionIndexes |
|
413 AdjustHighlight(); |
|
414 } |
|
415 |
|
416 |
|
417 //----------------------------------------------------------------------------- |
|
418 // CBrowserSelectElementListBox::HighlightSelectableItem |
|
419 //----------------------------------------------------------------------------- |
|
420 // |
|
421 void CBrowserSelectElementListBox::HighlightSelectableItem() |
|
422 { |
|
423 AdjustHighlight(); |
|
424 } |
|
425 |
|
426 |
|
427 //----------------------------------------------------------------------------- |
|
428 // CBrowserSelectElementListBox::AdjustHighlight |
|
429 //----------------------------------------------------------------------------- |
|
430 // |
|
431 void CBrowserSelectElementListBox::AdjustHighlight() |
|
432 { |
|
433 const CListBoxView::CSelectionIndexArray* selection = SelectionIndexes(); |
|
434 TInt count = Min( iOptions.Count(), Model()->NumberOfItems() ); |
|
435 TInt i; |
|
436 TBool filterExist = EFalse; |
|
437 TBool notFound = ETrue; |
|
438 |
|
439 //at first time the highlight should be on the item |
|
440 //which was selected last time |
|
441 if ( iHasNotMoved ) |
|
442 { |
|
443 for ( i = 0 ; i < count ; i++ ) |
|
444 { |
|
445 if ( iOptions.At( i ).IsSelected() ) |
|
446 { |
|
447 ScrollToMakeItemVisible( i ); |
|
448 SetCurrentItemIndexAndDraw( i ); |
|
449 break; |
|
450 } |
|
451 } |
|
452 return; |
|
453 } |
|
454 |
|
455 if ( ( (CBrowserSelectElementModel*)Model() )->Filter() ) |
|
456 { |
|
457 filterExist = ETrue; |
|
458 count = ( (CBrowserSelectElementModel*) Model() )-> |
|
459 Filter()->FilteredNumberOfItems(); |
|
460 } |
|
461 |
|
462 for ( i = 0 ; i < count ; i++ ) |
|
463 { |
|
464 TInt index = i; |
|
465 |
|
466 if ( filterExist ) |
|
467 { |
|
468 index = ( (CBrowserSelectElementModel*) Model() )-> |
|
469 Filter()-> |
|
470 FilteredItemIndex( i ); |
|
471 } |
|
472 |
|
473 TBrCtlSelectOptionData optdat = iOptions.At( index ); |
|
474 |
|
475 if ( !optdat.IsOptGroup() && filterExist ) // find the next option |
|
476 { |
|
477 TPtrC data(optdat.Text()); |
|
478 TBuf<KSearchFieldBuferLength> criteria; |
|
479 ( (CAknSearchField*)( ((CAknFilteredTextListBoxModel*)Model()) |
|
480 ->Filter()->FindBox() ) )->GetSearchText( criteria ); |
|
481 |
|
482 if ( AknFind::IsFindMatch( data,criteria ) ) |
|
483 { |
|
484 notFound = EFalse; |
|
485 break; |
|
486 } |
|
487 } |
|
488 } |
|
489 |
|
490 if ( notFound ) |
|
491 { |
|
492 for ( i = 0; i < count; i++ ) |
|
493 { |
|
494 if (iOptions.At( i ).IsSelected() ) |
|
495 { |
|
496 ScrollToMakeItemVisible( i ); |
|
497 SetCurrentItemIndexAndDraw( i ); |
|
498 break; |
|
499 } |
|
500 } |
|
501 return; |
|
502 } |
|
503 |
|
504 if ( i < count) |
|
505 { |
|
506 ScrollToMakeItemVisible(i); |
|
507 SetCurrentItemIndexAndDraw( i ); |
|
508 } |
|
509 else if ( selection->Count() ) // selected array except the optgrup becaue optg always selected |
|
510 { |
|
511 for ( i = 0 ; i < selection->Count() ; i++ ) |
|
512 { |
|
513 if ( !iOptions.At( selection->At( i ) ).IsOptGroup() ) |
|
514 { // make visible (scroll ) and highlight it |
|
515 ScrollToMakeItemVisible( selection->At( i ) ); |
|
516 SetCurrentItemIndexAndDraw( selection->At( i ) ); |
|
517 break; |
|
518 } |
|
519 } |
|
520 } |
|
521 } |
|
522 //----------------------------------------------------------------------------- |
|
523 // CBrowserSelectElementListBox::HandleResourceChangeL |
|
524 //----------------------------------------------------------------------------- |
|
525 // |
|
526 void CBrowserSelectElementListBox::HandleResourceChangeL( TInt aType ) |
|
527 { |
|
528 if ( aType == KAknsMessageSkinChange ) |
|
529 { |
|
530 CArrayPtr<CGulIcon>* array = |
|
531 ItemDrawer()->ColumnData()->IconArray(); |
|
532 |
|
533 array->ResetAndDestroy(); |
|
534 delete array; |
|
535 |
|
536 STATIC_CAST( CBrowserSelectElementItemDrawer*, |
|
537 iItemDrawer )->LoadIconsL(); |
|
538 } |
|
539 } |
|
540 |
|
541 // End of File |