132 UpdateTopVisibleItemIndex(); |
132 UpdateTopVisibleItemIndex(); |
133 if (iTopVisibleItemIndex > KErrNotFound) |
133 if (iTopVisibleItemIndex > KErrNotFound) |
134 { |
134 { |
135 // First top visible element should be highlighted |
135 // First top visible element should be highlighted |
136 iView->SetCurrentItemIndex(iTopVisibleItemIndex); |
136 iView->SetCurrentItemIndex(iTopVisibleItemIndex); |
|
137 |
137 // Item drawer must know, that highlight should be enabled |
138 // Item drawer must know, that highlight should be enabled |
138 // from now. |
139 // from now. |
139 CColumnListBoxItemDrawer* drawer = ItemDrawer(); |
140 if (IsHighlightNeeded(oldCurrent,aKeyEvent)) |
140 if (drawer) |
|
141 { |
141 { |
142 drawer->ClearFlags( |
142 SingleClickDisableHighlightL(EFalse); |
143 CListItemDrawer::ESingleClickDisabledHighlight); |
|
144 } |
143 } |
145 // Report, that current highlighted element changed |
|
146 ReportEventL(MCoeControlObserver::EEventStateChanged); |
|
147 resp = EKeyWasConsumed; |
144 resp = EKeyWasConsumed; |
148 DrawNow(); |
|
149 iTopVisibleItemIndex = KErrNotFound; |
145 iTopVisibleItemIndex = KErrNotFound; |
150 } |
146 } |
151 // Enable highlight flag for this ChoiceGroup, even if top visible |
147 // Enable highlight flag for this ChoiceGroup, even if top visible |
152 // element wasn't found (ChoiceGroup is now fully invisible). |
148 // element wasn't found (ChoiceGroup is now fully invisible). |
153 iHighlight = ETrue; |
149 iHighlight = ETrue; |
168 // If the key was up or down, and the current item did not change, |
164 // If the key was up or down, and the current item did not change, |
169 // we were apparently already on the first or last item. |
165 // we were apparently already on the first or last item. |
170 // Return EKeyWasNotConsumed so that the form knows to transfer focus |
166 // Return EKeyWasNotConsumed so that the form knows to transfer focus |
171 // BUT ONLY if not used in a popup (otherwise the form will get it and |
167 // BUT ONLY if not used in a popup (otherwise the form will get it and |
172 // move focus under the popup) |
168 // move focus under the popup) |
173 TInt newCurrent = iView->CurrentItemIndex(); |
169 if (!IsHighlightNeeded(oldCurrent,aKeyEvent)) |
174 TBool change = oldCurrent != newCurrent; |
|
175 TInt lastItemIdx = KErrNotFound; |
|
176 if (iModel) |
|
177 { |
|
178 lastItemIdx = iModel->NumberOfItems() - 1; |
|
179 } |
|
180 if ((aKeyEvent.iCode == EKeyUpArrow) && !change && (newCurrent == 0)) |
|
181 { |
|
182 resp = EKeyWasNotConsumed; |
|
183 } |
|
184 if ((aKeyEvent.iCode == EKeyDownArrow) && !change && |
|
185 (newCurrent == lastItemIdx)) |
|
186 { |
170 { |
187 resp = EKeyWasNotConsumed; |
171 resp = EKeyWasNotConsumed; |
188 } |
172 } |
189 } |
173 } |
190 |
174 |
467 { |
451 { |
468 DrawDeferred(); |
452 DrawDeferred(); |
469 } |
453 } |
470 } |
454 } |
471 #endif |
455 #endif |
|
456 |
|
457 /** |
|
458 * Checks if highlight is needed |
|
459 * Returns EFalse if there should be no highlight |
|
460 */ |
|
461 TBool CMIDChoiceGroupListBox::IsHighlightNeeded(TInt aCurrentSelected, |
|
462 const TKeyEvent& aKeyEvent) |
|
463 { |
|
464 // If the key was up or down, and the current item did not change, |
|
465 // we were apparently already on the first or last item. |
|
466 // Return EFalse when highlight should be lost |
|
467 TBool isHighlightNeeded = ETrue; |
|
468 TInt newCurrent = iView->CurrentItemIndex(); |
|
469 TBool change = aCurrentSelected != newCurrent; |
|
470 TInt lastItemIdx = KErrNotFound; |
|
471 |
|
472 if (iModel) |
|
473 { |
|
474 lastItemIdx = iModel->NumberOfItems() - 1; |
|
475 } |
|
476 if ((aKeyEvent.iCode == EKeyUpArrow) && !change && (newCurrent == 0)) |
|
477 { |
|
478 isHighlightNeeded = EFalse; |
|
479 } |
|
480 if ((aKeyEvent.iCode == EKeyDownArrow) && !change && |
|
481 (newCurrent == lastItemIdx)) |
|
482 { |
|
483 isHighlightNeeded = EFalse; |
|
484 } |
|
485 return isHighlightNeeded; |
|
486 } |
472 |
487 |
473 #ifdef RD_JAVA_S60_RELEASE_9_2 |
488 #ifdef RD_JAVA_S60_RELEASE_9_2 |
474 /** |
489 /** |
475 * Returns index of ChoiceGroup element, which is the first |
490 * Returns index of ChoiceGroup element, which is the first |
476 * visible element in ChoiceGroup from top of Form. |
491 * visible element in ChoiceGroup from top of Form. |
528 // In case of HW keys interaction, there is no highlight, |
543 // In case of HW keys interaction, there is no highlight, |
529 // so we don't need highlight any element |
544 // so we don't need highlight any element |
530 iTopVisibleItemIndex = KErrNotFound; |
545 iTopVisibleItemIndex = KErrNotFound; |
531 } |
546 } |
532 } |
547 } |
|
548 /** |
|
549 * Fuction sets ESingleClickDisabledHighlight - item drawer flags |
|
550 * and reports current highlight element change event |
|
551 */ |
|
552 void CMIDChoiceGroupListBox::SingleClickDisableHighlightL(TBool aDisable) |
|
553 { |
|
554 // Item drawer must know, that highlight should be enabled/disabled |
|
555 // when listbox element taped |
|
556 CColumnListBoxItemDrawer* drawer = ItemDrawer(); |
|
557 if (drawer) |
|
558 { |
|
559 if (aDisable) |
|
560 { |
|
561 if (iHighlight) |
|
562 { |
|
563 // Set flags in Item drawer so that highlight could be disabled |
|
564 drawer->SetFlags(CListItemDrawer::ESingleClickDisabledHighlight); |
|
565 iHighlight = EFalse; |
|
566 iTopVisibleItemIndex = KErrNotFound; |
|
567 } |
|
568 } |
|
569 else |
|
570 { |
|
571 // Set flags in Item drawer so that highlight could be enabled |
|
572 drawer->ClearFlags(CListItemDrawer::ESingleClickDisabledHighlight); |
|
573 } |
|
574 } |
|
575 // Report, that current highlighted element changed |
|
576 ReportEventL(MCoeControlObserver::EEventStateChanged); |
|
577 DrawNow(); |
|
578 } |
|
579 |
|
580 void CMIDChoiceGroupListBox::SetHighlight(TBool aVisible) |
|
581 { |
|
582 iHighlight = aVisible; |
|
583 } |
533 #endif // RD_JAVA_S60_RELEASE_9_2 |
584 #endif // RD_JAVA_S60_RELEASE_9_2 |