author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:23:59 +0300 | |
branch | RCL_3 |
changeset 83 | 26b2b12093af |
parent 77 | 7cee158cb8cd |
permissions | -rw-r--r-- |
66 | 1 |
/* |
2 |
* Copyright (c) 2003-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: The CMIDChoiceGroup listbox |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
#include "CMIDChoiceGroupListBox.h" |
|
20 |
// API for iChoiceControl |
|
21 |
#include "CMIDChoiceGroupControl.h" |
|
22 |
#include "CMIDChoiceGroupModel.h" |
|
23 |
||
24 |
#include <e32def.h> |
|
25 |
// using for CColumnListBoxData related to colors |
|
26 |
// and in HandleResourceChange function - setting icon array |
|
27 |
#include <eikclbd.h> |
|
28 |
#include <AknsFrameBackgroundControlContext.h> |
|
29 |
#include <AknUtils.h> |
|
30 |
#include <AknsDrawUtils.h> |
|
31 |
#include <skinlayout.cdl.h> |
|
32 |
#include <layoutmetadata.cdl.h> |
|
33 |
||
34 |
// LAF |
|
35 |
// AknLayoutScalable_Avkon::list_single_pane_cp2 |
|
36 |
#include <aknlayoutscalable_avkon.cdl.h> // LAF |
|
37 |
||
38 |
#include <j2me/jdebug.h> |
|
39 |
||
40 |
#undef TRAP_INSTRUMENTATION_LEAVE |
|
41 |
#define TRAP_INSTRUMENTATION_LEAVE(aResult) DEBUG_INT2("In CMIDChoiceGroupListBox.cpp, trapped method was called at line %D and got exception %D", __LINE__, aResult); |
|
42 |
||
43 |
||
44 |
CMIDChoiceGroupListBox::CMIDChoiceGroupListBox(CMIDChoiceGroupControl* aChoiceControl) |
|
45 |
: CAknColumnListBox() |
|
46 |
, iChoiceControl(aChoiceControl) |
|
47 |
#ifdef RD_JAVA_S60_RELEASE_9_2 |
|
48 |
, iHighlight(EFalse) |
|
49 |
, iTopVisibleItemIndex(KErrNotFound) |
|
50 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
|
51 |
{ |
|
52 |
ASSERT(iChoiceControl); |
|
53 |
} |
|
54 |
||
55 |
CMIDChoiceGroupListBox::~CMIDChoiceGroupListBox() |
|
56 |
{ |
|
57 |
} |
|
58 |
||
59 |
// Constructs the listbox with the model created and owned outside. |
|
60 |
// Makes sure the EKeepModel flag is set, in order to not destroy |
|
61 |
// the model when listbox is destroyed |
|
62 |
void CMIDChoiceGroupListBox::ConstructL( |
|
63 |
const CCoeControl* aParent, |
|
64 |
TInt aFlags, |
|
65 |
CMIDChoiceGroupModel* aModel) |
|
66 |
{ |
|
67 |
// Model is owned outside, set it here, so that when |
|
68 |
// CCAknColumnListBox::ConstructL() calls CreateModelL(), |
|
69 |
// it is already in place. Absolutely make sure that the |
|
70 |
// model owned outside flag is set |
|
71 |
iModel = aModel; |
|
72 |
aFlags |= EKeepModel; |
|
73 |
||
74 |
CAknColumnListBox::ConstructL(aParent, aFlags); |
|
75 |
iListBoxFlags &= ~ELoopScrolling; |
|
76 |
||
77 |
if (iChoiceControl->ChoiceType() == MMIDChoiceGroup::EPopup) |
|
78 |
{ |
|
79 |
TAknLayoutRect layoutRect; |
|
80 |
// layout in respect of the screen as only the height is needed |
|
81 |
layoutRect.LayoutRect(iEikonEnv->ScreenDevice()->SizeInPixels(), AknLayoutScalable_Avkon::list_single_pane_cp2(0).LayoutLine()); |
|
82 |
SetItemHeightL(layoutRect.Rect().Height()); |
|
83 |
} |
|
84 |
#ifndef RD_JAVA_FOR_S60_5_0_w49_2008 |
|
85 |
else |
|
86 |
{ |
|
87 |
// Disable flick/panning functionality |
|
88 |
// Disbled in OMJ DisableScrolling( ETrue ); |
|
89 |
} |
|
90 |
#endif // RD_JAVA_FOR_S60_5_0_w49_2008 |
|
91 |
||
92 |
#ifdef RD_SCALABLE_UI_V2 |
|
93 |
SetAllowStrayPointers(); |
|
94 |
#endif |
|
95 |
||
96 |
#ifdef RD_TACTILE_FEEDBACK |
|
97 |
iFeedback = MTouchFeedback::Instance(); |
|
98 |
#ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
99 |
iFeedback->EnableFeedbackForControl(this, FALSE); |
|
100 |
#endif //RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
101 |
#endif //RD_TACTILE_FEEDBACK |
|
102 |
||
103 |
} |
|
104 |
||
105 |
// Overridden, because CEikListBox returns EKeyWasConsumed when |
|
106 |
// up is pressed on the first item, or down on last. We need to |
|
107 |
// return not consumed in order to make the form move focus |
|
108 |
// to other items |
|
109 |
// Offers key events to the listbox |
|
110 |
TKeyResponse CMIDChoiceGroupListBox::OfferKeyEventL( |
|
111 |
const TKeyEvent& aKeyEvent, |
|
112 |
TEventCode aType) |
|
113 |
{ |
|
114 |
// First save the currently selected item |
|
115 |
TInt oldCurrent = iView->CurrentItemIndex(); |
|
116 |
||
117 |
TKeyResponse resp = EKeyWasNotConsumed; |
|
118 |
||
119 |
#ifdef RD_JAVA_S60_RELEASE_9_2 |
|
120 |
if (iChoiceControl->ChoiceType() != MMIDChoiceGroup::EPopup) |
|
121 |
{ |
|
122 |
if (aType != EEventKey || iHighlight) |
|
123 |
{ |
|
124 |
// Do not pass the EEventKey to ListBox in case of first |
|
125 |
// HW key action after highlight was disabled. |
|
126 |
resp = CAknColumnListBox::OfferKeyEventL(aKeyEvent, aType); |
|
127 |
} |
|
128 |
else |
|
129 |
{ |
|
130 |
// This is first HW key action after highlight was disabled: |
|
131 |
// highlight should be enabled |
|
132 |
UpdateTopVisibleItemIndex(); |
|
133 |
if (iTopVisibleItemIndex > KErrNotFound) |
|
134 |
{ |
|
135 |
// First top visible element should be highlighted |
|
136 |
iView->SetCurrentItemIndex(iTopVisibleItemIndex); |
|
137 |
||
138 |
// Item drawer must know, that highlight should be enabled |
|
139 |
// from now. |
|
140 |
if (IsHighlightNeeded(oldCurrent,aKeyEvent)) |
|
141 |
{ |
|
142 |
SingleClickDisableHighlightL(EFalse); |
|
143 |
} |
|
144 |
resp = EKeyWasConsumed; |
|
145 |
iTopVisibleItemIndex = KErrNotFound; |
|
146 |
} |
|
147 |
// Enable highlight flag for this ChoiceGroup, even if top visible |
|
148 |
// element wasn't found (ChoiceGroup is now fully invisible). |
|
149 |
iHighlight = ETrue; |
|
150 |
} |
|
151 |
} |
|
152 |
else |
|
153 |
{ |
|
154 |
// For popup ChoiceGroup, handle key events in usual way |
|
155 |
resp = CAknColumnListBox::OfferKeyEventL(aKeyEvent, aType); |
|
156 |
} |
|
157 |
#else |
|
158 |
// Let the ListBox handle the key |
|
159 |
resp = CAknColumnListBox::OfferKeyEventL(aKeyEvent, aType); |
|
160 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
|
161 |
||
162 |
if (iChoiceControl->ChoiceType() != MMIDChoiceGroup::EPopup) |
|
163 |
{ |
|
164 |
// If the key was up or down, and the current item did not change, |
|
165 |
// we were apparently already on the first or last item. |
|
166 |
// Return EKeyWasNotConsumed so that the form knows to transfer focus |
|
167 |
// BUT ONLY if not used in a popup (otherwise the form will get it and |
|
168 |
// move focus under the popup) |
|
169 |
if (!IsHighlightNeeded(oldCurrent,aKeyEvent)) |
|
170 |
{ |
|
171 |
resp = EKeyWasNotConsumed; |
|
172 |
} |
|
173 |
} |
|
174 |
||
175 |
//For Popup ChoiceGroup in landscape mode we have to redraw listbox |
|
176 |
//to display background properly |
|
177 |
if (iChoiceControl->ChoiceType() == MMIDChoiceGroup::EPopup && |
|
178 |
Layout_Meta_Data::IsLandscapeOrientation() && |
|
179 |
(aKeyEvent.iCode == EKeyUpArrow || |
|
180 |
aKeyEvent.iCode == EKeyDownArrow)) |
|
181 |
{ |
|
182 |
DrawDeferred(); |
|
183 |
} |
|
184 |
||
185 |
return resp; |
|
186 |
} |
|
187 |
||
188 |
||
189 |
// Overridden in order to prevent the listbox from creating its |
|
190 |
// own model. |
|
191 |
void CMIDChoiceGroupListBox::CreateModelL() |
|
192 |
{ |
|
193 |
// Model should've already been given |
|
194 |
ASSERT(iModel); |
|
195 |
if (!iModel) |
|
196 |
{ |
|
197 |
User::Leave(KErrArgument); |
|
198 |
} |
|
199 |
} |
|
200 |
||
201 |
void CMIDChoiceGroupListBox::SizeChanged() |
|
202 |
{ |
|
203 |
// Because SizeChanged() is the only method called by CAknPopupList during a screen |
|
204 |
// resolution change, we must call these two in here. If we don't, |
|
205 |
// open popup dialogs do not update their content during a screen resolution change |
|
206 |
// @see CMIDChoiceGroupListBox::HandleResolutionChange() and CAknPopupList::HandleResolutionChange(). |
|
207 |
if (iChoiceControl->ChoiceType() == MMIDChoiceGroup::EPopup) |
|
208 |
{ |
|
209 |
TRAP_IGNORE( |
|
210 |
iChoiceControl->SetupColumnsL(ItemDrawer()->ColumnData()); |
|
211 |
TAknLayoutRect layoutRect; |
|
212 |
// layout in respect of the screen as only the height is needed |
|
213 |
layoutRect.LayoutRect(iEikonEnv->ScreenDevice()->SizeInPixels(), AknLayoutScalable_Avkon::list_single_pane_cp2(0).LayoutLine()); |
|
214 |
SetItemHeightL(layoutRect.Rect().Height()); |
|
215 |
); |
|
216 |
} |
|
217 |
||
218 |
CAknColumnListBox::SizeChanged(); |
|
219 |
||
220 |
// Assure that non-popup choicegroup is updated correctly visually |
|
221 |
// after dynamic resolution change. |
|
222 |
TInt lbHeight = Rect().Height(); |
|
223 |
TInt lbItemHeight = iItemHeight; |
|
224 |
||
225 |
// check that listbox's size is already set |
|
226 |
if ((lbHeight > 0) && (lbItemHeight > 0) && (lbHeight >= lbItemHeight) && |
|
227 |
iChoiceControl && |
|
228 |
(iChoiceControl->ChoiceType() != MMIDChoiceGroup::EPopup)) |
|
229 |
{ |
|
230 |
TInt topItemIndex = TopItemIndex(); |
|
231 |
TInt bottomItemIndex = BottomItemIndex(); |
|
232 |
TInt currentItemIndex = CurrentItemIndex(); |
|
233 |
TInt numOfItems = (Model()) ? Model()->NumberOfItems() : 0; |
|
234 |
||
235 |
// check that listbox-view is set correctly |
|
236 |
if ((topItemIndex >= 0) && (bottomItemIndex >= topItemIndex) && |
|
237 |
(bottomItemIndex < numOfItems) && |
|
238 |
(currentItemIndex >= topItemIndex) && |
|
239 |
(currentItemIndex <= bottomItemIndex)) |
|
240 |
{ |
|
241 |
// number of actually/possible visible items |
|
242 |
TInt numOfActuallyVisibleItems = bottomItemIndex - topItemIndex + 1; |
|
243 |
TInt numOfPossiblyVisibleItems = lbHeight / lbItemHeight; |
|
244 |
||
245 |
// detect if it is possible to display more items than it is |
|
246 |
// currently displayed (this indicates that listbox-view is not |
|
247 |
// updated correctly after dynamic resolution change) and |
|
248 |
// eventually update listbox-view's top-item-index |
|
249 |
if ((numOfPossiblyVisibleItems > numOfActuallyVisibleItems) && |
|
250 |
(topItemIndex >= numOfPossiblyVisibleItems - |
|
251 |
numOfActuallyVisibleItems)) |
|
252 |
{ |
|
253 |
topItemIndex -= numOfPossiblyVisibleItems - |
|
254 |
numOfActuallyVisibleItems; |
|
255 |
SetTopItemIndex(topItemIndex); |
|
256 |
} |
|
257 |
} |
|
258 |
} |
|
259 |
} |
|
260 |
||
261 |
void CMIDChoiceGroupListBox::Draw(const TRect& aRect) const |
|
262 |
{ |
|
263 |
//For Popup ChoiceGroup we have to draw its background, |
|
264 |
//because native side doesn't do that properly. |
|
265 |
if (iChoiceControl->ChoiceType() == MMIDChoiceGroup::EPopup) |
|
266 |
{ |
|
267 |
CWindowGc& gc = SystemGc(); |
|
268 |
MAknsControlContext* cc = NULL; |
|
269 |
//create background context: |
|
270 |
//KAknsIIDQsnFrPopupCenter - id of proper background |
|
271 |
//for popup dialog, background is without borders |
|
272 |
TRAP_IGNORE(cc = CAknsBasicBackgroundControlContext::NewL( |
|
273 |
KAknsIIDQsnFrPopupCenter, |
|
274 |
aRect, |
|
275 |
EFalse)); |
|
276 |
if (cc) |
|
277 |
{ |
|
278 |
//draw background |
|
279 |
AknsDrawUtils::DrawBackground( |
|
280 |
AknsUtils::SkinInstance(), |
|
281 |
cc, |
|
282 |
NULL, |
|
283 |
gc, |
|
284 |
Position(), //current listobox position on popup dialog |
|
285 |
aRect, |
|
286 |
KAknsDrawParamDefault); |
|
287 |
} |
|
288 |
} |
|
289 |
||
290 |
CAknColumnListBox::Draw(aRect); |
|
291 |
} |
|
292 |
||
293 |
TTypeUid::Ptr CMIDChoiceGroupListBox::MopSupplyObject(TTypeUid aId) |
|
294 |
{ |
|
295 |
if (iChoiceControl->ChoiceType() != MMIDChoiceGroup::EPopup) |
|
296 |
{ |
|
297 |
return iChoiceControl->MopSupplyObject(aId); |
|
298 |
} |
|
299 |
else // no skinned background in popup list |
|
300 |
{ |
|
301 |
return CAknColumnListBox::MopSupplyObject(aId); |
|
302 |
} |
|
303 |
} |
|
304 |
||
305 |
/** This is currently only used for the open popup choice group items. For the normal |
|
306 |
closed items at the moment form won't pass the notification to them. They are instead |
|
307 |
recreated on a screen resolution change. See CMIChoiceGroupItem::ResolutionChange() and |
|
308 |
CMIChoiceGroupItem::ColorChange(). */ |
|
309 |
void CMIDChoiceGroupListBox::HandleResourceChange(TInt aType) |
|
310 |
{ |
|
311 |
if (aType == KEikColorResourceChange || |
|
312 |
aType == KAknsMessageSkinChange || aType == KUidValueCoeColorSchemeChangeEvent) |
|
313 |
{//skin or color scheme have changed |
|
314 |
TRAP_IGNORE(((CMIDChoiceGroupModel*)Model())->ReConstructSelectionIconsL()); |
|
315 |
ItemDrawer()->ColumnData()->SetIconArray(((CMIDChoiceGroupModel*)Model())->IconArray(ETrue)); |
|
316 |
||
317 |
SetTextColors(); |
|
318 |
} |
|
319 |
else if (aType == KEikDynamicLayoutVariantSwitch) |
|
320 |
{ |
|
321 |
// NOTE for the open popup choicegroup items: |
|
322 |
// CAknPopupList never calls HandleResourceChange() on the list box when aType |
|
323 |
// is KEikDynamicLayoutVariantSwitch so do not put any code here, |
|
324 |
// SizeChanged() will be called instead. |
|
325 |
} |
|
326 |
||
327 |
CAknColumnListBox::HandleResourceChange(aType); |
|
328 |
} |
|
329 |
||
330 |
/** Initialise the listbox text and background colors with values |
|
331 |
from LAF first, and then from the skin if this is supported. */ |
|
332 |
void CMIDChoiceGroupListBox::SetTextColors() |
|
333 |
{ |
|
334 |
CColumnListBoxData::TColors colors; |
|
335 |
||
336 |
colors.iText = AKN_LAF_COLOR_STATIC(215); |
|
337 |
colors.iHighlightedText = AKN_LAF_COLOR_STATIC(0); |
|
338 |
||
339 |
if (AknsUtils::AvkonSkinEnabled()) |
|
340 |
{ |
|
341 |
MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
342 |
TRgb color; |
|
343 |
||
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
344 |
// icon color, checkbox, radio button |
66 | 345 |
TInt error = AknsUtils::GetCachedColor(skin, |
346 |
color, |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
347 |
KAknsIIDQsnIconColors, |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
348 |
EAknsCIQsnIconColorsCG14); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
349 |
|
66 | 350 |
if (!error) |
351 |
{ |
|
352 |
colors.iText = color; |
|
353 |
} |
|
354 |
||
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
355 |
// icon color, setting list highlight checkbox, radio button |
66 | 356 |
error = AknsUtils::GetCachedColor(skin, |
357 |
color, |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
358 |
KAknsIIDQsnIconColors, |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
359 |
EAknsCIQsnIconColorsCG14); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
360 |
|
66 | 361 |
if (!error) |
362 |
{ |
|
363 |
colors.iHighlightedText = color; |
|
364 |
} |
|
365 |
} |
|
366 |
||
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
367 |
View()->ItemDrawer()->SetTextColor(colors.iText); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
368 |
View()->ItemDrawer()->SetHighlightedTextColor(colors.iHighlightedText); |
66 | 369 |
} |
370 |
||
371 |
||
372 |
void CMIDChoiceGroupListBox::PositionChanged() |
|
373 |
{ |
|
374 |
// Code copied from CEikListBox::SizeChanged() |
|
375 |
TRect clientRect = iBorder.InnerRect(Rect()); |
|
376 |
SetViewRectFromClientRect(clientRect); |
|
377 |
} |
|
378 |
||
379 |
#ifdef RD_SCALABLE_UI_V2 |
|
380 |
void CMIDChoiceGroupListBox::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
381 |
{ |
|
382 |
#ifdef RD_JAVA_S60_RELEASE_9_2 |
|
383 |
if (aPointerEvent.iType == TPointerEvent::EButton1Down) |
|
384 |
{ |
|
385 |
iUpEventSent = EFalse; |
|
386 |
iHighlight = EFalse; |
|
387 |
UpdateTopVisibleItemIndex(); |
|
388 |
} |
|
389 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
|
390 |
||
391 |
// In non-popup case, don't forward to base class the drag events |
|
392 |
// that occur outside the listbox |
|
393 |
||
394 |
#ifdef RD_TACTILE_FEEDBACK |
|
395 |
if ((aPointerEvent.iType == TPointerEvent::EButton1Down || |
|
396 |
aPointerEvent.iType == TPointerEvent::EButton1Up) && |
|
397 |
iChoiceControl->ChoiceType() == MMIDChoiceGroup::EPopup) |
|
398 |
{ |
|
399 |
#ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
400 |
iFeedback->InstantFeedback(ETouchFeedbackList); |
|
401 |
#else |
|
402 |
iFeedback->InstantFeedback(ETouchFeedbackBasic); |
|
403 |
#endif //RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
404 |
} |
|
405 |
#endif //RD_TACTILE_FEEDBACK |
|
406 |
||
407 |
#ifndef RD_JAVA_S60_RELEASE_9_2 |
|
408 |
if (iChoiceControl->ChoiceType() != MMIDChoiceGroup::EPopup && |
|
409 |
aPointerEvent.iType == TPointerEvent::EDrag) |
|
410 |
{ |
|
411 |
||
412 |
if (!View()->ViewRect().Contains(aPointerEvent.iPosition)) |
|
413 |
{ |
|
414 |
return; |
|
415 |
} |
|
416 |
else |
|
417 |
{ |
|
418 |
||
419 |
// this flag must be set in order that drag events can change |
|
420 |
// the focused listbox item |
|
421 |
iListBoxFlags |= ELeftDownInViewRect; |
|
422 |
} |
|
423 |
} |
|
424 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
|
425 |
||
426 |
#ifdef RD_JAVA_S60_RELEASE_9_2 |
|
427 |
if (aPointerEvent.iType == TPointerEvent::EDrag && !iUpEventSent && iChoiceControl->Form()->PhysicsScrolling()) |
|
428 |
{ |
|
429 |
TPointerEvent pointerEvent = aPointerEvent; |
|
430 |
pointerEvent.iType = TPointerEvent::EButton1Up; |
|
431 |
CAknColumnListBox::HandlePointerEventL(pointerEvent); |
|
432 |
iUpEventSent = ETrue; |
|
433 |
} |
|
434 |
else if (!iUpEventSent) |
|
435 |
{ |
|
436 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
|
437 |
CAknColumnListBox::HandlePointerEventL(aPointerEvent); |
|
438 |
#ifdef RD_JAVA_S60_RELEASE_9_2 |
|
439 |
if (aPointerEvent.iType == TPointerEvent::EButton1Up) |
|
440 |
{ |
|
441 |
iUpEventSent = ETrue; |
|
442 |
} |
|
443 |
} |
|
444 |
||
445 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
|
446 |
||
447 |
//For Popup ChoiceGroup in landscape mode we have to redraw listbox |
|
448 |
//to display background properly |
|
449 |
if (iChoiceControl->ChoiceType() == MMIDChoiceGroup::EPopup && |
|
450 |
Layout_Meta_Data::IsLandscapeOrientation()) |
|
451 |
{ |
|
452 |
DrawDeferred(); |
|
453 |
} |
|
454 |
} |
|
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 |
} |
|
487 |
||
488 |
#ifdef RD_JAVA_S60_RELEASE_9_2 |
|
489 |
/** |
|
490 |
* Returns index of ChoiceGroup element, which is the first |
|
491 |
* visible element in ChoiceGroup from top of Form. |
|
492 |
* Used in CMIDChoiceGroupControl, which needs to know |
|
493 |
* current element for possible scrolling |
|
494 |
* (@see CMIDChoiceGroupControl::RequestScrollIfNeededL()). |
|
495 |
*/ |
|
496 |
TInt CMIDChoiceGroupListBox::TopVisibleItemIndex() |
|
497 |
{ |
|
498 |
return iTopVisibleItemIndex; |
|
499 |
} |
|
500 |
||
501 |
/** |
|
502 |
* Fuction calculates index of element, which is the first |
|
503 |
* visible element in ChoiceGroup from top of Form. |
|
504 |
*/ |
|
505 |
void CMIDChoiceGroupListBox::UpdateTopVisibleItemIndex() |
|
506 |
{ |
|
507 |
if (!iHighlight) |
|
508 |
{ |
|
509 |
// There is touch interaction, so we need index for element, |
|
510 |
// which will be highlighted, when user starts using HW keys |
|
511 |
if (iPosition.iY < 0) |
|
512 |
{ |
|
513 |
// ChoiceGroup is now partially visible and its top edge is |
|
514 |
// above the Form top edge. |
|
515 |
||
516 |
// Calculate index of first (partially) visible element |
|
517 |
iTopVisibleItemIndex = Abs(iPosition.iY) / iView->ItemHeight(); |
|
518 |
TRect lbitemRect = TRect( |
|
519 |
iView->ItemPos(iTopVisibleItemIndex), |
|
520 |
iView->ItemSize(iTopVisibleItemIndex)); |
|
521 |
if (lbitemRect.iTl.iY < 0) |
|
522 |
{ |
|
523 |
// Item is really partially visible. |
|
524 |
// Because we don't want index of partially visible item, |
|
525 |
// move index to next item |
|
526 |
iTopVisibleItemIndex++; |
|
527 |
} |
|
528 |
if (iTopVisibleItemIndex >= iModel->NumberOfItems()) |
|
529 |
{ |
|
530 |
// ChoiceGroup is fully invisible (whole rect is above |
|
531 |
// the Form top edge): no element is visible now |
|
532 |
iTopVisibleItemIndex = KErrNotFound; |
|
533 |
} |
|
534 |
} |
|
535 |
else |
|
536 |
{ |
|
537 |
// Top item idge is lower than top edge of Form - is visible |
|
538 |
iTopVisibleItemIndex = 0; |
|
539 |
} |
|
540 |
} |
|
541 |
else |
|
542 |
{ |
|
543 |
// In case of HW keys interaction, there is no highlight, |
|
544 |
// so we don't need highlight any element |
|
545 |
iTopVisibleItemIndex = KErrNotFound; |
|
546 |
} |
|
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 |
} |
|
584 |
#endif // RD_JAVA_S60_RELEASE_9_2 |