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-2008 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: Implements the Form LCDUI component. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
//RD_SCALABLE_UI definition |
|
20 |
#include <bldvariant.hrh> |
|
21 |
// using CEikScrollBarFrame API for iSBFrame |
|
22 |
#include <eiksbfrm.h> |
|
23 |
||
24 |
// API used for retrieving layout for initial alignment (in ConstructL) |
|
25 |
#include <centralrepository.h> |
|
26 |
// constants used in retrieving layout for initial alignment (in ConstructL) |
|
27 |
#include <AvkonInternalCRKeys.h> |
|
28 |
||
29 |
// control context that provides a layout background |
|
30 |
#include <AknsListBoxBackgroundControlContext.h> |
|
31 |
// highlight background |
|
32 |
#include <AknsFrameBackgroundControlContext.h> |
|
33 |
// API for text formatting used in DrawNoDataStringL function |
|
34 |
#include <AknBidiTextUtils.h> |
|
35 |
||
36 |
#include "CMIDForm.h" |
|
37 |
#include "CMIDFormRow.h" |
|
38 |
// API for iDisplayable |
|
39 |
#include "CMIDDisplayable.h" |
|
40 |
#include "CMIDItem.h" |
|
41 |
#include "CMIDControlItem.h" |
|
42 |
#include "CMIDGaugeItem.h" |
|
43 |
#include "CMIDImageItem.h" |
|
44 |
#include "CMIDStringItem.h" |
|
45 |
// CMIDLabelContainerItem API used to obtain CMIDStringItem item |
|
46 |
#include "CMIDLabelContainerItem.h" |
|
47 |
#include "CMIDTextFieldItem.h" |
|
48 |
#include "CMIDChoiceGroupItem.h" |
|
49 |
#include "CMIDSpacer.h" |
|
50 |
#include "CMIDCustomItem.h" |
|
51 |
#include "CMIDDateFieldItem.h" |
|
52 |
#include "CMIDComponentFactory.h" |
|
53 |
#include "CMIDUtils.h" |
|
54 |
#include "CMIDItemLabel.h" |
|
55 |
#include "CMIDTicker.h" |
|
56 |
#include "CMIDFont.h" |
|
57 |
#include "CMIDPopupNoteController.h" |
|
58 |
// Kinetic scrolling |
|
59 |
#include "CMIDFormPhysics.h" |
|
60 |
||
61 |
#include <applayout.cdl.h> |
|
62 |
// LAF |
|
63 |
#include <aknlayoutscalable_avkon.cdl.h> |
|
64 |
// LAF |
|
65 |
#include <layoutmetadata.cdl.h> |
|
66 |
||
67 |
// Api for skin layout |
|
68 |
#include <skinlayout.cdl.h> |
|
69 |
using namespace SkinLayout; |
|
70 |
||
71 |
#include <j2me/jdebug.h> |
|
72 |
||
73 |
#undef TRAP_INSTRUMENTATION_LEAVE |
|
74 |
#define TRAP_INSTRUMENTATION_LEAVE(aResult) DEBUG_INT2("In CMIDForm.cpp, trapped method was called at line %D and got exception %D", __LINE__, aResult); |
|
75 |
||
76 |
#ifdef RD_SCALABLE_UI_V2 |
|
77 |
/** Dividers used when the the scroll amount is calculated*/ |
|
78 |
const TInt KScrollAmountDivider = 4; |
|
79 |
const TInt KScrollAmountDividerForThumbDrag = 10; |
|
80 |
||
81 |
/** Interval for scrolling when stylus is dragged outside the form and held down */ |
|
82 |
const TInt KScrollInterval = 100000; // 0,1 sec |
|
83 |
#endif //RD_SCALABLE_UI_V2 |
|
84 |
||
85 |
/** The minimum amount to scroll */ |
|
86 |
const TInt KMinScrollAmount = 40; |
|
87 |
||
88 |
/** The timeout in microseconds for visual updates. When items are added or removed |
|
89 |
or modified, the form is not redrawn immediately but only after this timeout. This way |
|
90 |
if more items are being added or removed or changed we reduce the number of redraws. |
|
91 |
*/ |
|
92 |
const TInt KLayoutTimeout = 60000; //60 msecs |
|
93 |
||
94 |
/** If layout has been requested for a period longer than the cap then perform layout |
|
95 |
even if the midlet is still performing form insert/delete operations. */ |
|
96 |
const TInt KLayoutCap = 1000000; // 1 sec |
|
97 |
||
98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
99 |
// MMIDForm interface |
|
100 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
101 |
||
102 |
/** |
|
103 |
* Add items list. Note: this is no longer called by framework!! |
|
104 |
*/ |
|
105 |
void CMIDForm::SetAllItemsL(const RArray<MMIDItem*>& aItems) |
|
106 |
{ |
|
107 |
DEBUG("CMIDForm::SetAllItemsL"); |
|
108 |
||
109 |
ASSERT(iItems.Count() == 0); |
|
110 |
// |
|
111 |
TInt count = aItems.Count(); |
|
112 |
for (TInt i=0; i<count; i++) |
|
113 |
{ |
|
114 |
User::LeaveIfError(iItems.Append(aItems[i])); |
|
115 |
CMIDControlItem& ci = ControlItem(i); |
|
116 |
||
117 |
AddItemToFormL(ci); |
|
118 |
ci.MakeVisible(ETrue); |
|
119 |
} |
|
120 |
||
121 |
RequestLayoutL(); |
|
122 |
} |
|
123 |
||
124 |
/** |
|
125 |
* Replaces an item. Keeps the same item focused which had focus before, |
|
126 |
* and if that's the one that this is replacing, then this will be focused |
|
127 |
* if possible. |
|
128 |
*/ |
|
129 |
void CMIDForm::SetItemL(MMIDItem& aItem,TInt aIndex) |
|
130 |
{ |
|
131 |
DEBUG("CMIDForm::SetItemL"); |
|
132 |
||
133 |
CMIDControlItem& oldCi = ControlItem(aIndex); |
|
134 |
RemoveItemFromForm(oldCi); |
|
135 |
||
136 |
iItems[aIndex] = &aItem; |
|
137 |
CMIDControlItem& ci = ControlItem(aIndex); |
|
138 |
AddItemToFormL(ci); |
|
139 |
||
140 |
ci.MakeVisible(ETrue); |
|
141 |
||
142 |
if (iFocused == aIndex) |
|
143 |
{ |
|
144 |
iDisplayable.MenuHandler()->HideMenuIfVisible(); |
|
145 |
||
146 |
if (ci.IsSelectable()) |
|
147 |
{ |
|
148 |
SetFocusedItem(aIndex); |
|
149 |
} |
|
150 |
else |
|
151 |
{ |
|
152 |
SetFocusedItem(KErrNotFound); |
|
153 |
} |
|
154 |
} |
|
155 |
||
156 |
RequestLayoutL(); |
|
157 |
} |
|
158 |
||
159 |
/** |
|
160 |
* Inserts a new Item. |
|
161 |
*/ |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
162 |
void CMIDForm::InsertItemL(MMIDItem& aItem,TInt aIndex) |
66 | 163 |
{ |
164 |
DEBUG("CMIDForm::InsertItemL"); |
|
165 |
||
166 |
User::LeaveIfError(iItems.Insert(&aItem,aIndex)); |
|
167 |
CMIDControlItem& ci = ControlItem(aIndex); |
|
168 |
||
169 |
AddItemToFormL(ci); |
|
170 |
ci.MakeVisible(ETrue); |
|
171 |
// if insert item then index of pointed control is increase |
|
172 |
if (aIndex <= iIndexPointedControl) |
|
173 |
{ |
|
174 |
iIndexPointedControl++; |
|
175 |
} |
|
176 |
||
177 |
// If there isn't any focused item yet, we have to set focus |
|
178 |
// to first item which is focusable. Once the item has focus, |
|
179 |
// we can skip this step. |
|
180 |
if (iFocused == KErrNotFound) |
|
181 |
{ |
|
182 |
SetFocusedItem(ci.IsSelectable() ? aIndex : KErrNotFound); |
|
183 |
} |
|
184 |
else if (aIndex <= iFocused) |
|
185 |
{ |
|
186 |
// If new item is inserted to Form above the current item, |
|
187 |
// index must increase |
|
188 |
iFocused++; |
|
189 |
} |
|
190 |
||
191 |
RequestLayoutL(); |
|
192 |
} |
|
193 |
||
194 |
void CMIDForm::DeleteItemL(TInt aIndex) |
|
195 |
{ |
|
196 |
DEBUG("CMIDForm::DeleteItemL"); |
|
197 |
||
198 |
TBool updateFocused = EFalse; |
|
199 |
// if delete item then index of pointed control is decrease |
|
200 |
if (iIndexPointedControl > aIndex) |
|
201 |
{ |
|
202 |
iIndexPointedControl--; |
|
203 |
} |
|
204 |
else |
|
205 |
// if delete item is same as index of pointed control then index is set to not active |
|
206 |
{ |
|
207 |
if (iIndexPointedControl == aIndex) |
|
208 |
{ |
|
209 |
iIndexPointedControl = -1; |
|
210 |
} |
|
211 |
} |
|
212 |
if (iFocused > aIndex) |
|
213 |
{ |
|
214 |
iFocused--; |
|
215 |
} |
|
216 |
else if (iFocused == aIndex) |
|
217 |
{ |
|
218 |
iDisplayable.MenuHandler()->HideMenuIfVisible(); |
|
219 |
ReplaceFocusedItem(); |
|
220 |
updateFocused = ETrue; |
|
221 |
} |
|
222 |
||
223 |
CMIDControlItem& ci = ControlItem(aIndex); |
|
224 |
RemoveItemFromForm(ci); |
|
225 |
if (&ci == iPointedControl) |
|
226 |
{ |
|
227 |
iPointedControl = NULL; |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
228 |
iLastPointedControl = KErrNotFound; |
66 | 229 |
} |
230 |
||
231 |
iItems.Remove(aIndex); |
|
232 |
||
233 |
if (iFocused != KErrNotFound && updateFocused) |
|
234 |
{ |
|
235 |
iFocused--; |
|
236 |
} |
|
237 |
||
238 |
RequestLayoutL(); |
|
239 |
} |
|
240 |
||
241 |
void CMIDForm::DeleteAllItemsL() |
|
242 |
{ |
|
243 |
DEBUG("CMIDForm::DeleteAllItemsL"); |
|
244 |
iDisplayable.MenuHandler()->HideMenuIfVisible(); |
|
245 |
SetFocusedItem(KErrNotFound); |
|
246 |
||
247 |
TInt itemCount = iItems.Count(); |
|
248 |
for (TInt i=0; i < itemCount; i++) |
|
249 |
{ |
|
250 |
CMIDControlItem& ci = ControlItem(i); |
|
251 |
RemoveItemFromForm(ci); |
|
252 |
} |
|
253 |
iItems.Reset(); |
|
254 |
||
255 |
iScroll = 0; |
|
256 |
// if delete all then index of pointed control is set to not active |
|
257 |
iIndexPointedControl = -1; |
|
258 |
||
259 |
iPointedControl = NULL; |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
260 |
iLastPointedControl = KErrNotFound; |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
261 |
|
66 | 262 |
RequestLayoutL(); |
263 |
} |
|
264 |
||
265 |
/** |
|
266 |
* Called when the item has changed its appearance in some way. |
|
267 |
*/ |
|
268 |
void CMIDForm::RefreshItemL(TInt aIndex) |
|
269 |
{ |
|
270 |
DEBUG("CMIDForm::RefreshItemL"); |
|
271 |
||
272 |
if (aIndex != KErrNotFound) |
|
273 |
{ |
|
274 |
RequestLayoutL(); |
|
275 |
} |
|
276 |
} |
|
277 |
||
278 |
/** |
|
279 |
* Returns whether the item is actually visible to the user. Must therefore take into |
|
280 |
* account the visibility of the entire form, and whether the specific item is scrolled |
|
281 |
* in/out of the viewable area. |
|
282 |
*/ |
|
283 |
TBool CMIDForm::IsItemVisible(TInt aIndex) |
|
284 |
{ |
|
285 |
DEBUG("CMIDForm::IsItemVisible"); |
|
286 |
||
287 |
CMIDControlItem& control = ControlItem(aIndex); |
|
288 |
||
289 |
if ((control.Position().iY > Height()) || |
|
290 |
((control.Position().iY + control.Size().iHeight) < 0)) |
|
291 |
{ |
|
292 |
return EFalse; |
|
293 |
} |
|
294 |
return ETrue; |
|
295 |
} |
|
296 |
||
297 |
/** |
|
298 |
* Called prior to the Form itself being made the current Displayable. |
|
299 |
* It provides an opportunity to prepare the form such that this item will |
|
300 |
* be visible and focused when the form is eventually made current |
|
301 |
*/ |
|
302 |
void CMIDForm::SetCurrentItemL(TInt aIndex) |
|
303 |
{ |
|
304 |
DEBUG("CMIDForm::SetCurrentItemL"); |
|
305 |
||
306 |
// If it is pending request for layout, than layout now. |
|
307 |
if (LayoutPending()) |
|
308 |
{ |
|
309 |
LayoutAndDrawL(); |
|
310 |
} |
|
311 |
||
312 |
// Set focus of item to aIndex and scroll to it. |
|
313 |
SetFocusedItem(aIndex); |
|
314 |
||
315 |
} |
|
316 |
||
317 |
||
318 |
// |
|
319 |
// End of MMIDForm interface |
|
320 |
// |
|
321 |
||
322 |
TInt CMIDForm::CountComponentControls() const |
|
323 |
{ |
|
324 |
return iRows.Count(); |
|
325 |
} |
|
326 |
||
327 |
CCoeControl* CMIDForm::ComponentControl(TInt aIndex) const |
|
328 |
{ |
|
329 |
return iRows[aIndex]; |
|
330 |
} |
|
331 |
||
332 |
TKeyResponse CMIDForm::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
333 |
{ |
|
334 |
DEBUG("< CMIDForm::OfferKeyEventL"); |
|
335 |
||
336 |
TBool isArrowKey = (aKeyEvent.iCode == EKeyDownArrow || aKeyEvent.iCode == EKeyUpArrow || |
|
337 |
aKeyEvent.iCode == EKeyLeftArrow || aKeyEvent.iCode == EKeyRightArrow); |
|
338 |
||
339 |
if (iFocused != KErrNotFound) |
|
340 |
{ |
|
341 |
CMIDControlItem& controlItem = ControlItem(iFocused); |
|
342 |
TRect controlRect = GetControlRect(iFocused); |
|
343 |
TBool visible = RectPartiallyVisible(controlRect); |
|
344 |
||
345 |
// arrow key events are not sent to the hidden focused item |
|
346 |
if ((visible || !isArrowKey) && |
|
347 |
controlItem.OfferKeyEventL(aKeyEvent,aType) == EKeyWasConsumed) |
|
348 |
{ |
|
349 |
DEBUG("CMIDForm::OfferKeyEventL - out after item consumed key"); |
|
350 |
||
351 |
#ifdef RD_SCALABLE_UI_V2 |
|
352 |
// If focused TextField or DateField item is at least partly out of |
|
353 |
// Form viewport, then key event (excluding arrow keys and soft keys) |
|
354 |
// scrolls the item completely visible. This situation |
|
355 |
// is possible when scrolling has been done with scrollbar. |
|
356 |
||
357 |
// Soft keys and arrow keys are ignored. Filtering must be done comparing |
|
358 |
// scan codes because the aEventType.iCode is not available for all key presses. |
|
359 |
TBool ignoreKey = (aKeyEvent.iScanCode == EStdKeyRightArrow || |
|
360 |
aKeyEvent.iScanCode == EStdKeyUpArrow || |
|
361 |
aKeyEvent.iScanCode == EStdKeyDownArrow || |
|
362 |
aKeyEvent.iScanCode == EStdKeyLeftArrow || |
|
363 |
aKeyEvent.iScanCode == EStdKeyDevice0 || |
|
364 |
aKeyEvent.iScanCode == EStdKeyDevice1 || |
|
365 |
aKeyEvent.iScanCode == EStdKeyDevice3); |
|
366 |
||
367 |
if ((controlItem.Type() == MMIDComponent::ETextField || |
|
368 |
controlItem.Type() == MMIDComponent::EDateField) && |
|
369 |
!RectFullyVisible(controlRect) && !ignoreKey) |
|
370 |
{ |
|
371 |
// Scroll up if controlItem is above the Form viewport. |
|
372 |
// Otherwise scroll down. |
|
373 |
if (controlRect.iTl.iY < 0) |
|
374 |
{ |
|
375 |
ScrollToFocused(EUp, ETrue); |
|
376 |
} |
|
377 |
else |
|
378 |
{ |
|
379 |
ScrollToFocused(EDown, ETrue); |
|
380 |
} |
|
381 |
||
382 |
} |
|
383 |
#endif // RD_SCALABLE_UI_V2 |
|
384 |
||
385 |
return EKeyWasConsumed; |
|
386 |
} |
|
387 |
} |
|
388 |
||
389 |
DEBUG("CMIDForm::OfferKeyEventL - got chance to scroll"); |
|
390 |
||
391 |
if ((aType == EEventKey) && isArrowKey && (iItems.Count() > 0)) |
|
392 |
{ |
|
393 |
DEBUG("CMIDForm::OfferKeyEventL - about to call Traverse"); |
|
394 |
||
395 |
Traverse(ConvertKeyToDirection(aKeyEvent.iCode)); |
|
396 |
||
397 |
DEBUG("CMIDForm::OfferKeyEventL - out after Traverse"); |
|
398 |
return EKeyWasConsumed; |
|
399 |
} |
|
400 |
||
401 |
// msk: this is needed if MSK is not enabled |
|
402 |
if ((aType == EEventKey) && |
|
403 |
((aKeyEvent.iScanCode == EStdKeyDevice3) || (aKeyEvent.iCode == EKeyEnter)) |
|
404 |
) |
|
405 |
{ |
|
406 |
if (!DoDefaultCommand()) |
|
407 |
{ |
|
408 |
iDisplayable.ShowOkOptionsMenuL(); |
|
409 |
} |
|
410 |
||
411 |
DEBUG("CMIDForm::OfferKeyEventL - out after default command or ok menu"); |
|
412 |
return EKeyWasConsumed; |
|
413 |
} |
|
414 |
// end msk |
|
415 |
DEBUG("> CMIDForm::OfferKeyEventL"); |
|
416 |
return EKeyWasNotConsumed; |
|
417 |
} |
|
418 |
||
419 |
/** Handle a focus change. Make sure there is no layout pending and if there is |
|
420 |
one then do it, see TrappedLayoutAndDraw(). This is because when there is a layout |
|
421 |
pending we are in a temporary inconsistent phase with no rows and the rows are the |
|
422 |
intermediary to the items via the CountComponentControl() and ComponentControl() calls. |
|
423 |
Then pass on focus to our children according to the value stored in iFocused. Finally |
|
424 |
update the scroll bars if gaining focus and draw. */ |
|
425 |
void CMIDForm::FocusChanged(TDrawNow /*aDrawNow*/) |
|
426 |
{ |
|
427 |
DEBUG("CMIDForm::FocusChanged"); |
|
428 |
||
429 |
TrappedLayoutAndDraw(ETrue); |
|
430 |
||
431 |
TInt i = -1; |
|
432 |
TInt itemCount = iItems.Count(); |
|
433 |
while (++i < itemCount) |
|
434 |
{ |
|
435 |
if (i == iFocused) |
|
436 |
{ |
|
437 |
ControlItem(iFocused).SetFocus(IsFocused()); |
|
438 |
} |
|
439 |
else |
|
440 |
{ |
|
441 |
ControlItem(i).SetFocus(EFalse); |
|
442 |
} |
|
443 |
} |
|
444 |
||
445 |
// make sure scrollbar is up to date when we get focus |
|
446 |
if (IsFocused()) |
|
447 |
{ |
|
448 |
UpdateScrollBar(); |
|
449 |
} |
|
450 |
||
451 |
DrawNow(); |
|
452 |
} |
|
453 |
||
454 |
void CMIDForm::SizeChanged() |
|
455 |
{ |
|
456 |
DEBUG("CMIDForm::SizeChanged"); |
|
457 |
||
458 |
iBackgroundControlContext->SetParentPos(PositionRelativeToScreen()) ; |
|
459 |
iBackgroundControlContext->SetRect(Rect()) ; |
|
460 |
} |
|
461 |
||
462 |
/** Before calling CCoeControl::InputCapabilities(), make sure there is |
|
463 |
no outstanding layout. This is because if there is one outstanding, we have |
|
464 |
no rows and hence ComponentControls() returns zero. This means that, for example |
|
465 |
if there are any editors in the items, CCoeControl::InputCapabilities() will not |
|
466 |
reach them and the FEP will not be initialised. @see TrappedLayoutAndDraw(), |
|
467 |
CCoeControl::InputCapabilities(), CAknFepManager::HandleChangeInFocusL() and |
|
468 |
CCoeAppUi::InputCapabilities() */ |
|
469 |
TCoeInputCapabilities CMIDForm::InputCapabilities() const |
|
470 |
{ |
|
471 |
if (iFocused != KErrNotFound) |
|
472 |
{ |
|
473 |
return ControlItem(iFocused).InputCapabilities(); |
|
474 |
} |
|
475 |
return CCoeControl::InputCapabilities(); //TCoeInputCapabilities::ENone |
|
476 |
} |
|
477 |
||
478 |
TTypeUid::Ptr CMIDForm::MopSupplyObject(TTypeUid aId) |
|
479 |
{ |
|
480 |
if (aId.iUid == MAknsControlContext::ETypeId && iBackgroundControlContext) |
|
481 |
{ |
|
482 |
return MAknsControlContext::SupplyMopObject(aId, iBackgroundControlContext); |
|
483 |
} |
|
484 |
||
485 |
CMIDMenuHandler* menuHandler = iDisplayable.MenuHandler(); |
|
486 |
return SupplyMopObject(aId, menuHandler->Cba(), menuHandler->MenuBar()); |
|
487 |
} |
|
488 |
||
489 |
||
490 |
#ifdef RD_SCALABLE_UI_V2 |
|
491 |
void CMIDForm::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
492 |
{ |
|
493 |
if (!AknLayoutUtils::PenEnabled()) |
|
494 |
{ |
|
495 |
return; |
|
496 |
} |
|
497 |
||
498 |
if (iPhysics) |
|
499 |
{ |
|
500 |
HandlePhysicsPointerEventL(aPointerEvent); |
|
501 |
return; |
|
502 |
} |
|
503 |
||
504 |
switch (aPointerEvent.iType) |
|
505 |
{ |
|
506 |
case TPointerEvent::EButton1Down: |
|
507 |
{ |
|
508 |
DEBUG_INT3("CMIDForm::HandlePointerEventL(): event=%D, x,y=%D,%D", |
|
509 |
aPointerEvent.iType, aPointerEvent.iPosition.iX, aPointerEvent.iPosition.iY); |
|
510 |
iLastValidPointerEvent = aPointerEvent; |
|
511 |
||
512 |
CMIDControlItem* ci = ControlItemAtPoint(aPointerEvent.iPosition); |
|
513 |
// stored on ButtonDown value |
|
514 |
||
515 |
if (ci && ci->IsSelectable()) |
|
516 |
{ |
|
517 |
TInt itemIndex = ItemIndex(*ci); |
|
518 |
iIndexPointedControl = itemIndex; |
|
519 |
iLastValidPointedItemPosition = ci->Position(); |
|
520 |
TBool changeFocus = (itemIndex != iFocused); |
|
521 |
||
522 |
if (changeFocus) |
|
523 |
{ |
|
524 |
// changing the focused item by dragging must start from unfocused item |
|
525 |
iCanDragFocus = ETrue; |
|
526 |
iFocusChangingWithPen = ETrue; |
|
527 |
// give basic tactile feedback on button down when move focus |
|
528 |
#ifdef RD_TACTILE_FEEDBACK |
|
529 |
DoFeedbackOnFocusChange(*ci); |
|
530 |
#endif // RD_TACTILE_FEEDBACK |
|
531 |
SetFocusedItem(itemIndex, ENone, EFalse); |
|
532 |
} |
|
533 |
||
534 |
TInt scroll = ScrollDistanceToTappedItem(ci); |
|
535 |
||
536 |
iScrollOnPointerDown = (scroll != 0); |
|
537 |
||
538 |
CCoeControl::HandlePointerEventL(aPointerEvent); |
|
539 |
||
540 |
if (iScrollOnPointerDown) |
|
541 |
{ |
|
542 |
ScrollRelative(scroll); |
|
543 |
ControlItem(iFocused).NotifyScrollingCompleted(); |
|
544 |
} |
|
545 |
else if (changeFocus) |
|
546 |
{ |
|
547 |
HandleItemVisibilityChange(); |
|
548 |
DrawNow(); |
|
549 |
} |
|
550 |
else |
|
551 |
{ |
|
552 |
iCanDragFocus = ETrue; |
|
553 |
} |
|
554 |
} |
|
555 |
else // pointer down did not happen on any control item, allow starting drag |
|
556 |
{ |
|
557 |
iCanDragFocus = ETrue; |
|
558 |
} |
|
559 |
||
560 |
break; |
|
561 |
} |
|
562 |
||
563 |
case TPointerEvent::EButton1Up: |
|
564 |
{ |
|
565 |
if (iIndexPointedControl>-1 && &ControlItem(iIndexPointedControl) == ControlItemAtPoint(aPointerEvent.iPosition)) |
|
566 |
// When this is item where TPointerEvent::EButton1Down was happened, |
|
567 |
// then event is forwarded to item. It is its responsibility check that |
|
568 |
// up event occured if it have some actions on up event. |
|
569 |
{ |
|
570 |
DEBUG_INT3("CMIDForm::HandlePointerEventL(): event=%D, x,y=%D,%D", |
|
571 |
aPointerEvent.iType, aPointerEvent.iPosition.iX, aPointerEvent.iPosition.iY); |
|
572 |
||
573 |
HandleDragEventL(aPointerEvent, ETrue); |
|
574 |
} |
|
575 |
else |
|
576 |
{ |
|
577 |
// When this is not item where TPointerEvent::EButton1Down was happened, |
|
578 |
// then e`vent is forwarded to item where originally. It is its responsibility |
|
579 |
// check that up event occured if it have some actions on up event. |
|
580 |
// Setting default values of related variables. |
|
581 |
||
582 |
if (iIndexPointedControl>-1 && &ControlItem(iIndexPointedControl)) |
|
583 |
{ |
|
584 |
TBool bbutton = EFalse; |
|
585 |
||
586 |
if (IsStringItem(ControlItem(iIndexPointedControl))) |
|
587 |
{ |
|
588 |
// get appearance from StringItem |
|
589 |
CMIDStringItem *strItem = static_cast< CMIDStringItem* >(&ControlItem(iIndexPointedControl)); |
|
590 |
MMIDItem::TAppearance appearance = strItem->Appearance(); |
|
591 |
bbutton = (appearance == MMIDItem::EButton || appearance == MMIDItem::EHyperLink); |
|
592 |
} |
|
593 |
||
594 |
if (ControlItem(iIndexPointedControl).Type() != MMIDComponent::EChoiceGroup && !bbutton) |
|
595 |
{ |
|
596 |
TPointerEvent pointerevent; |
|
597 |
pointerevent.iType = TPointerEvent::EButton1Up; |
|
598 |
pointerevent.iModifiers = aPointerEvent.iModifiers; |
|
599 |
pointerevent.iPosition = iLastValidPointerEvent.iPosition + |
|
600 |
ControlItem(iIndexPointedControl).Position() - iLastValidPointedItemPosition; |
|
601 |
pointerevent.iParentPosition = iLastValidPointerEvent.iParentPosition; |
|
602 |
||
603 |
ControlItem(iIndexPointedControl).HandlePointerEventL(pointerevent); |
|
604 |
||
605 |
DEBUG_INT3("CMIDForm::HandlePointerEventL(): event=%D, x,y=%D,%D", |
|
606 |
pointerevent.iType, pointerevent.iPosition.iX, pointerevent.iPosition.iY); |
|
607 |
||
608 |
} |
|
609 |
||
610 |
// forward event for aPointerEvent |
|
611 |
CCoeControl::HandlePointerEventL(aPointerEvent); |
|
612 |
} |
|
613 |
} |
|
614 |
||
615 |
// If it is pending request for layout, than layout form now and refresh. |
|
616 |
if (LayoutPending()) |
|
617 |
{ |
|
618 |
LayoutFormL(); |
|
619 |
DrawDeferred(); |
|
620 |
} |
|
621 |
||
622 |
iCanDragFocus = EFalse; |
|
623 |
iFocusChangingWithPen = EFalse; |
|
624 |
iScrollOnPointerDown = EFalse; |
|
625 |
iIndexPointedControl = -1; |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
626 |
iLastPointedControl = KErrNotFound; |
66 | 627 |
|
628 |
break; |
|
629 |
} |
|
630 |
||
631 |
case TPointerEvent::EDrag: |
|
632 |
// for dragging |
|
633 |
{ |
|
634 |
if (iIndexPointedControl>-1 && &ControlItem(iIndexPointedControl) == ControlItemAtPoint(aPointerEvent.iPosition)) |
|
635 |
{ |
|
636 |
// When this is item where TPointerEvent::EButton1Down was happened, |
|
637 |
// then it is updated iLastValidPointerEvent. |
|
638 |
iLastValidPointerEvent = aPointerEvent; |
|
639 |
// If it is pending request for layout, than layout Form now and refresh |
|
640 |
// elsewhere call HandleDragEventL and forward EDrag events to event. |
|
641 |
if (LayoutPending()) |
|
642 |
{ |
|
643 |
LayoutFormL(); |
|
644 |
DrawDeferred(); |
|
645 |
} |
|
646 |
else |
|
647 |
{ |
|
648 |
HandleDragEventL(aPointerEvent, ETrue); |
|
649 |
} |
|
650 |
DEBUG_INT3("CMIDForm::HandlePointerEventL(): event=%D, x,y=%D,%D", |
|
651 |
aPointerEvent.iType, aPointerEvent.iPosition.iX, |
|
652 |
aPointerEvent.iPosition.iY); |
|
653 |
} |
|
654 |
else |
|
655 |
{ |
|
656 |
// When this is not item where TPointerEvent::EButton1Down was happened, |
|
657 |
// then we do only dragging. There it is not send event to item. |
|
658 |
HandleDragEventL(aPointerEvent, EFalse); |
|
659 |
} |
|
660 |
break; |
|
661 |
} |
|
662 |
||
663 |
case TPointerEvent::EButtonRepeat: |
|
664 |
// For button repeating |
|
665 |
{ |
|
666 |
DEBUG_INT3("CMIDForm::HandlePointerEventL(): event=%D, x,y=%D,%D", |
|
667 |
aPointerEvent.iType, aPointerEvent.iPosition.iX, |
|
668 |
aPointerEvent.iPosition.iY); |
|
669 |
||
670 |
RequestPointerRepeat(aPointerEvent); |
|
671 |
||
672 |
if (iCanDragFocus) |
|
673 |
{ |
|
674 |
if (aPointerEvent.iPosition.iY < 0 && CanScrollUp()) |
|
675 |
{ |
|
676 |
TimedScroll(EUp); |
|
677 |
} |
|
678 |
else if (aPointerEvent.iPosition.iY > Height() && CanScrollDown()) |
|
679 |
{ |
|
680 |
TimedScroll(EDown); |
|
681 |
} |
|
682 |
} |
|
683 |
else |
|
684 |
{ |
|
685 |
CCoeControl::HandlePointerEventL(aPointerEvent); |
|
686 |
} |
|
687 |
||
688 |
break; |
|
689 |
} |
|
690 |
default: |
|
691 |
// By defalt only implementation of base class. |
|
692 |
{ |
|
693 |
CCoeControl::HandlePointerEventL(aPointerEvent); |
|
694 |
DEBUG_INT3("CMIDForm::HandlePointerEventL(): event=%D, x,y=%D,%D", |
|
695 |
aPointerEvent.iType, aPointerEvent.iPosition.iX, |
|
696 |
aPointerEvent.iPosition.iY); |
|
697 |
break; |
|
698 |
} |
|
699 |
} |
|
700 |
} |
|
701 |
||
702 |
||
703 |
void CMIDForm::HandleDragEventL(const TPointerEvent& aPointerEvent, TBool aForItem) |
|
704 |
{ |
|
705 |
RequestPointerRepeat(aPointerEvent); |
|
706 |
||
707 |
if (iCanDragFocus) |
|
708 |
{ |
|
709 |
// formRect covers the whole vertical form area, but excludes |
|
710 |
// the left and right margins and the scroll bar area |
|
711 |
TRect formRect(TPoint(iFormRect.Rect().iTl.iX, 0), |
|
712 |
TPoint(iFormRect.Rect().iBr.iX, Height())); |
|
713 |
||
714 |
// Try to find the new focused item, if needed |
|
715 |
if (formRect.Contains(aPointerEvent.iPosition) && |
|
716 |
!FocusedItemContainsPoint(aPointerEvent.iPosition)) |
|
717 |
{ |
|
718 |
CMIDControlItem* ci = ControlItemAtPoint(aPointerEvent.iPosition); |
|
719 |
||
720 |
if (ci && ci->IsSelectable()) |
|
721 |
{ |
|
722 |
TInt itemIndex = ItemIndex(*ci); |
|
723 |
||
724 |
// Find the direction to which the focus is dragged |
|
725 |
TDirection direction = ENone; |
|
726 |
if (iFocused != KErrNotFound) |
|
727 |
{ |
|
728 |
TRect rect = ControlItem(iFocused).Rect(); |
|
729 |
||
730 |
if (aPointerEvent.iPosition.iY < rect.iTl.iY) |
|
731 |
{ |
|
732 |
direction = EUp; |
|
733 |
} |
|
734 |
else if (aPointerEvent.iPosition.iY >= rect.iBr.iY) |
|
735 |
{ |
|
736 |
direction = EDown; |
|
737 |
} |
|
738 |
else // focus is moved horizontally |
|
739 |
{ |
|
740 |
direction = (itemIndex < iFocused) ? ELeft : ERight; |
|
741 |
} |
|
742 |
} |
|
743 |
||
744 |
#ifdef RD_TACTILE_FEEDBACK |
|
745 |
if (iFocused != itemIndex) |
|
746 |
{ |
|
747 |
iFeedback->InstantFeedback(ETouchFeedbackSensitive); |
|
748 |
} |
|
749 |
#endif |
|
750 |
SetFocusedItem(itemIndex, direction, EFalse); |
|
751 |
HandleItemVisibilityChange(); |
|
752 |
DrawNow(); |
|
753 |
} |
|
754 |
} |
|
755 |
||
756 |
if (FocusedItemContainsPoint(aPointerEvent.iPosition)) |
|
757 |
{ |
|
758 |
// forward EDrag events to the focused so that the focus can |
|
759 |
// move inside the item |
|
760 |
// (only when this is item where TPointerEvent::EButton1Down was occured) |
|
761 |
||
762 |
CMIDControlItem* focusedControl = ControlItemAtPoint(aPointerEvent.iPosition); |
|
763 |
||
764 |
if (aForItem || (iIndexPointedControl > -1 && &ControlItem(iIndexPointedControl) && |
|
765 |
(IsChoiceGroup(ControlItem(iIndexPointedControl)) || IsCustomItem(ControlItem(iIndexPointedControl)))) || |
|
766 |
focusedControl && IsChoiceGroup(*focusedControl) || |
|
767 |
focusedControl && IsCustomItem(*focusedControl)) |
|
768 |
{ |
|
769 |
ControlItem(iFocused).HandlePointerEventL(aPointerEvent); |
|
770 |
} |
|
771 |
else |
|
772 |
{ |
|
773 |
if (iIndexPointedControl > -1 && &ControlItem(iIndexPointedControl)) |
|
774 |
{ |
|
775 |
TBool bbutton = EFalse; |
|
776 |
||
777 |
if (IsStringItem(ControlItem(iIndexPointedControl))) |
|
778 |
{ |
|
779 |
CMIDStringItem *strItem = static_cast< CMIDStringItem* >(&ControlItem(iIndexPointedControl)); |
|
780 |
MMIDItem::TAppearance appearance = strItem->Appearance(); |
|
781 |
bbutton = (appearance == MMIDItem::EButton || appearance == MMIDItem::EHyperLink); |
|
782 |
} |
|
783 |
||
784 |
//forward event (only for changing focus) for Button & Hyperlink |
|
785 |
if (bbutton && &ControlItem(iIndexPointedControl)) |
|
786 |
{ |
|
787 |
ControlItem(iIndexPointedControl).HandlePointerEventL(aPointerEvent); |
|
788 |
} |
|
789 |
else |
|
790 |
{ |
|
791 |
iDisplayable.TryDetectLongTapL(aPointerEvent); |
|
792 |
} |
|
793 |
} |
|
794 |
else |
|
795 |
{ |
|
796 |
iDisplayable.TryDetectLongTapL(aPointerEvent); |
|
797 |
} |
|
798 |
} |
|
799 |
} |
|
800 |
else |
|
801 |
{ |
|
802 |
// make sure that long tap animation is canceled in this case |
|
803 |
iDisplayable.TryDetectLongTapL(aPointerEvent); |
|
804 |
} |
|
805 |
} |
|
806 |
else // cannot drag focus |
|
807 |
{ |
|
808 |
CCoeControl::HandlePointerEventL(aPointerEvent); |
|
809 |
} |
|
810 |
} |
|
811 |
||
812 |
||
813 |
void CMIDForm::RequestPointerRepeat(const TPointerEvent& aPointerEvent) |
|
814 |
{ |
|
815 |
if (aPointerEvent.iPosition.iY < 0 || |
|
816 |
aPointerEvent.iPosition.iY > Height()) |
|
817 |
{ |
|
818 |
TRect screen; |
|
819 |
AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EScreen, screen); |
|
820 |
||
821 |
TRect repeatRect = screen; |
|
822 |
if (aPointerEvent.iPosition.iY < 0) |
|
823 |
{ |
|
824 |
repeatRect.iBr.iY = iMidpFormRect.Rect().iTl.iY; |
|
825 |
} |
|
826 |
else |
|
827 |
{ |
|
828 |
repeatRect.iTl.iY = iMidpFormRect.Rect().iBr.iY; |
|
829 |
} |
|
830 |
||
831 |
// repeatRect must be given in propotion to form's window, move it up |
|
832 |
repeatRect.Move(0, -iMidpFormRect.Rect().iTl.iY); |
|
833 |
Window().RequestPointerRepeatEvent(KScrollInterval, repeatRect); |
|
834 |
} |
|
835 |
} |
|
836 |
||
837 |
||
838 |
void CMIDForm::TimedScroll(TDirection aDirection) |
|
839 |
{ |
|
840 |
ASSERT(aDirection == EDown || aDirection == EUp); |
|
841 |
||
842 |
// First find the row that is the first or last row (depending on |
|
843 |
// the scroll direction) that is at least partailly visible on the form. |
|
844 |
// Search direction is opposite to aDirection. |
|
845 |
TDirection searchDirection = (aDirection == EUp) ? EDown : EUp; |
|
846 |
TInt idx = FirstRowOnScreen(searchDirection); |
|
847 |
||
848 |
if (idx == KErrNotFound) |
|
849 |
{ |
|
850 |
return; |
|
851 |
} |
|
852 |
||
853 |
TInt scroll = Height() / KScrollAmountDividerForThumbDrag; |
|
854 |
||
855 |
// Find the row that will be visible (at least partially) after |
|
856 |
// after the scrolling. |
|
857 |
if (aDirection == EUp) |
|
858 |
{ |
|
859 |
while (idx > 0 && (iRows[idx]->Rect().iTl.iY + scroll > 0)) |
|
860 |
{ |
|
861 |
--idx; |
|
862 |
} |
|
863 |
} |
|
864 |
else |
|
865 |
{ |
|
866 |
while ((idx < iRows.Count() - 1) && |
|
867 |
(iRows[idx]->Rect().iBr.iY - scroll < Height())) |
|
868 |
{ |
|
869 |
++idx; |
|
870 |
} |
|
871 |
} |
|
872 |
||
873 |
TBool rowFocused = EFalse; |
|
874 |
if (iFocused != KErrNotFound) |
|
875 |
{ |
|
876 |
rowFocused = GetControlRect(iFocused).Intersects(iRows[idx]->Rect()); |
|
877 |
} |
|
878 |
||
879 |
// If the focus is not yet on the row, try to set one of its items focused |
|
880 |
if (!rowFocused) |
|
881 |
{ |
|
882 |
for (TInt i = 0; i < iRows[idx]->NumItems(); ++i) |
|
883 |
{ |
|
884 |
CMIDControlItem* item = iRows[idx]->Item(i); |
|
885 |
if (item->IsSelectable()) |
|
886 |
{ |
|
887 |
SetFocusedItem(ItemIndex(*item), aDirection, EFalse); |
|
888 |
} |
|
889 |
} |
|
890 |
} |
|
891 |
||
892 |
#ifdef RD_TACTILE_FEEDBACK |
|
893 |
iFeedback->InstantFeedback(ETouchFeedbackSensitive); |
|
894 |
#endif |
|
895 |
||
896 |
ScrollRelative((aDirection == EUp) ? scroll : -scroll); |
|
897 |
} |
|
898 |
||
899 |
||
900 |
TBool CMIDForm::CanScrollUp() const |
|
901 |
{ |
|
902 |
return (iScroll < 0); |
|
903 |
} |
|
904 |
||
905 |
||
906 |
TBool CMIDForm::CanScrollDown() const |
|
907 |
{ |
|
908 |
return ((iFormHeight - iScroll) < iTotalFormHeight); |
|
909 |
} |
|
910 |
||
911 |
||
912 |
TBool CMIDForm::FocusedItemContainsPoint(const TPoint& aPoint) const |
|
913 |
{ |
|
914 |
if (iFocused != KErrNotFound) |
|
915 |
{ |
|
916 |
if (ItemIsUnconstrained(iFocused)) |
|
917 |
{ |
|
918 |
return StringItemContainsPoint( |
|
919 |
static_cast<CMIDStringItem*>(&ControlItem(iFocused)), aPoint); |
|
920 |
} |
|
921 |
else |
|
922 |
{ |
|
923 |
return ControlItem(iFocused).Rect().Contains(aPoint); |
|
924 |
} |
|
925 |
} |
|
926 |
else |
|
927 |
{ |
|
928 |
return EFalse; |
|
929 |
} |
|
930 |
} |
|
931 |
||
932 |
CMIDControlItem* CMIDForm::ControlItemAtPoint(const TPoint& aPoint) const |
|
933 |
{ |
|
934 |
TInt idx = RowAtPoint(aPoint); |
|
935 |
||
936 |
if (idx != KErrNotFound) |
|
937 |
{ |
|
938 |
for (TInt i = 0; i < iRows[idx]->NumItems(); ++i) |
|
939 |
{ |
|
940 |
CMIDControlItem* ci = iRows[idx]->Item(i); |
|
941 |
if (ci && ci->Rect().Contains(aPoint)) |
|
942 |
{ |
|
943 |
return ci; |
|
944 |
} |
|
945 |
} |
|
946 |
} |
|
947 |
||
948 |
return NULL; |
|
949 |
} |
|
950 |
||
951 |
||
952 |
TInt CMIDForm::RowAtPoint(const TPoint& aPoint) const |
|
953 |
{ |
|
954 |
TInt rowCount = iRows.Count(); |
|
955 |
// loop until the first row fully below the visible form area |
|
956 |
for (TInt i = 0; i < rowCount && (iRows[i]->Position().iY < iFormHeight); ++i) |
|
957 |
{ |
|
958 |
if (iRows[i]->Rect().Contains(aPoint)) |
|
959 |
{ |
|
960 |
return i; |
|
961 |
} |
|
962 |
} |
|
963 |
return KErrNotFound; |
|
964 |
} |
|
965 |
||
966 |
#endif // #ifdef RD_SCALABLE_UI_V2 |
|
967 |
||
968 |
||
969 |
void CMIDForm::SetFocusedItemIfNone(CMIDItem* aItem) |
|
970 |
{ |
|
971 |
if (iFocused == KErrNotFound) |
|
972 |
{ |
|
973 |
ASSERT(aItem); |
|
974 |
TInt index = Index(aItem); |
|
975 |
||
976 |
if (index >= 0 && index < iItems.Count()) |
|
977 |
{ |
|
978 |
CMIDControlItem& ci = ControlItem(iItems[index]); |
|
979 |
if (ci.IsSelectable()) |
|
980 |
{ |
|
981 |
SetFocusedItem(index); |
|
982 |
ScrollToFocused(); |
|
983 |
} |
|
984 |
} |
|
985 |
} |
|
986 |
} |
|
987 |
||
988 |
/** This method is called when an item loses focusability, |
|
989 |
for example because it loses all its commands. If this item |
|
990 |
is focused, call ReplaceFocusedItem() to find another focusable |
|
991 |
item. @see CMIDItem::RemoveCommand() and ReplaceFocusedItem*/ |
|
992 |
void CMIDForm::RemoveFocusIfFocused(CMIDItem* aItem) |
|
993 |
{ |
|
994 |
ASSERT(aItem); |
|
995 |
TInt index = Index(aItem); |
|
996 |
if (iFocused == index) |
|
997 |
{ |
|
998 |
// Hide menu because item has lost all item commands and |
|
999 |
// another item may have become focused behind the menu. |
|
1000 |
iDisplayable.MenuHandler()->HideMenuIfVisible(); |
|
1001 |
ReplaceFocusedItem(); |
|
1002 |
} |
|
1003 |
} |
|
1004 |
||
1005 |
/** |
|
1006 |
* Traverse is a method to go thorough the form; it includes moving focus from |
|
1007 |
* item to another possibly scrolling the form. Note that sometimes traversal |
|
1008 |
* does not move focus, because an item is larger that the screen and thus form |
|
1009 |
* is scrolled little by little so that the user can see the whole content. On |
|
1010 |
* other cases, traversing means only moving focus from item to another as both |
|
1011 |
* items are visible on the screen. |
|
1012 |
* |
|
1013 |
* @param aDirection defines the direction of the traversing (up, down, left, right). |
|
1014 |
**/ |
|
1015 |
void CMIDForm::Traverse(TDirection aDirection) |
|
1016 |
{ |
|
1017 |
DEBUG("< CMIDForm::Traverse"); |
|
1018 |
DEBUG_INT("< CMIDForm::Traverse Direction is %D", aDirection); |
|
1019 |
TBool horizontalScroll = EFalse; |
|
1020 |
||
1021 |
if (LayoutPending()) |
|
1022 |
{ |
|
1023 |
DEBUG("CMIDForm::Traverse - calling layout"); |
|
1024 |
// lets do the layout now so we can always assume that we are layed out before doing this stuff |
|
1025 |
TrappedLayoutAndDraw(); |
|
1026 |
} |
|
1027 |
||
1028 |
#ifdef RD_SCALABLE_UI_V2 |
|
1029 |
TBool focusHidden = EFalse; |
|
1030 |
// If the focused item is currently fully outside the visible form area, |
|
1031 |
// it means that form has been scrolled by moving the scrollbar with pen. In this case |
|
1032 |
// set iFocused (temporarily) to KErrNone in order that scrolling with arrow keys works ok. |
|
1033 |
if (iFocused != KErrNotFound && !RectPartiallyVisible(GetControlRect(iFocused))) |
|
1034 |
{ |
|
1035 |
focusHidden = ETrue; |
|
1036 |
SetFocusedItem(KErrNotFound, ENone, EFalse); |
|
1037 |
} |
|
1038 |
#endif |
|
1039 |
||
1040 |
if (aDirection == ELeft || aDirection == ERight) |
|
1041 |
{ |
|
1042 |
DEBUG("CMIDForm::Traverse - move focus horizontally"); |
|
1043 |
if (!TryMovingFocusHorizontally(aDirection)) |
|
1044 |
{ |
|
1045 |
if (iInitialAlignment == MMIDItem::ERight) |
|
1046 |
{//RIGHT TO LEFT |
|
1047 |
TryMovingFocusVertically(aDirection == ELeft ? EDown : EUp, EFalse); |
|
1048 |
} |
|
1049 |
else |
|
1050 |
{//LEFT TO RIGHT |
|
1051 |
TryMovingFocusVertically(aDirection == ELeft ? EUp : EDown, EFalse); |
|
1052 |
} |
|
1053 |
} |
|
1054 |
else |
|
1055 |
{ |
|
1056 |
horizontalScroll = ETrue; |
|
1057 |
} |
|
1058 |
} |
|
1059 |
else if (aDirection == EUp || aDirection == EDown) |
|
1060 |
{ |
|
1061 |
DEBUG("CMIDForm::Traverse - move focus vertically"); |
|
1062 |
TryMovingFocusVertically(aDirection, ETrue); |
|
1063 |
} |
|
1064 |
||
1065 |
// if there is still a focused item, make sure it is still on the screen. |
|
1066 |
// if it isn't remove focus as we've already tried out best to have a |
|
1067 |
// focussed item on screen |
|
1068 |
if (iFocused != KErrNotFound) |
|
1069 |
{ |
|
1070 |
TRect rect = GetControlRect(iFocused); |
|
1071 |
if (!RectPartiallyVisible(rect)) |
|
1072 |
{ |
|
1073 |
SetFocusedItem(KErrNotFound, ENone); |
|
1074 |
} |
|
1075 |
} |
|
1076 |
#ifdef RD_SCALABLE_UI_V2 |
|
1077 |
else if (focusHidden) |
|
1078 |
{ |
|
1079 |
// Try to bring the focus back to visible area by setting the last focusable |
|
1080 |
// item in the scroll direction focused. |
|
1081 |
TDirection searchDirection = (aDirection == EDown || aDirection == ERight) ? |
|
1082 |
EUp : EDown; |
|
1083 |
TInt newFocusIndex = IndexOfFirstFocusableItemOnScreen(searchDirection); |
|
1084 |
if (newFocusIndex != KErrNotFound) |
|
1085 |
{ |
|
1086 |
// Pass searchDirection also to SetFocusedItem(). This is needed at least |
|
1087 |
// for choice group and custom item cases, so that they can set there |
|
1088 |
// internal focus to the last element in the actual scroll direction. |
|
1089 |
SetFocusedItem(newFocusIndex, searchDirection, EFalse); |
|
1090 |
DrawDeferred(); |
|
1091 |
} |
|
1092 |
} |
|
1093 |
#endif |
|
1094 |
||
1095 |
RawScrollFinalize(horizontalScroll); |
|
1096 |
DEBUG("> CMIDForm::Traverse"); |
|
1097 |
} |
|
1098 |
||
1099 |
||
1100 |
// ----------------------------------------------------------------------------- |
|
1101 |
// Form scrolling methods |
|
1102 |
// ----------------------------------------------------------------------------- |
|
1103 |
/** |
|
1104 |
* Scroll to the focused control if there is one and update form visibility (draw) and scroll bar. |
|
1105 |
* @see ScrollToRect() and SetRowExtentsWithRespectToScrolledLocation(). |
|
1106 |
**/ |
|
1107 |
void CMIDForm::ScrollToFocused(TDirection aDirection /*=EDown*/, TBool aReset /*= ETrue*/) |
|
1108 |
{ |
|
1109 |
DEBUG("< CMIDForm::ScrollToFocused"); |
|
1110 |
if (!LayoutPending()) |
|
1111 |
{ |
|
1112 |
if (iFocused != KErrNotFound) |
|
1113 |
{ |
|
1114 |
TRect rect = GetControlRect(iFocused); |
|
1115 |
DEBUG_INT4("CMIDForm::ScrollToFocused - rect is %D %D %D %D", |
|
1116 |
rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iBr.iY); |
|
1117 |
RawScrollToRect(rect, aDirection, aReset); |
|
1118 |
} |
|
1119 |
||
1120 |
RawScrollFinalize(ETrue); |
|
1121 |
||
1122 |
if (iFocused != KErrNotFound) |
|
1123 |
{ |
|
1124 |
ControlItem(iFocused).NotifyScrollingCompleted(); |
|
1125 |
} |
|
1126 |
} |
|
1127 |
||
1128 |
UpdatePhysics(); |
|
1129 |
||
1130 |
DEBUG("> CMIDForm::ScrollToFocused"); |
|
1131 |
} |
|
1132 |
||
1133 |
TInt CMIDForm::ScrollDistanceToTappedItem(CMIDControlItem* aPointedControl) |
|
1134 |
{ |
|
1135 |
TRect focusedRect = aPointedControl->Rect(); |
|
1136 |
TInt scroll = 0; |
|
1137 |
||
1138 |
// Calculate how much we need to scroll to make the tapped item fully/more visible |
|
1139 |
if (!RectFullyVisible(focusedRect)) |
|
1140 |
{ |
|
1141 |
TInt topMargin = iFormRect.Rect().iTl.iY - iMidpFormRect.Rect().iTl.iY; |
|
1142 |
TInt bottomMargin = iMidpFormRect.Rect().iBr.iY - iFormRect.Rect().iBr.iY; |
|
1143 |
||
1144 |
if (focusedRect.Height() <= Height()) |
|
1145 |
{ |
|
1146 |
scroll = (focusedRect.iBr.iY > Height()) ? |
|
1147 |
Height() - focusedRect.iBr.iY : -focusedRect.iTl.iY; |
|
1148 |
} |
|
1149 |
// Scroll long item so that it fills the whole form height. |
|
1150 |
// No scroll in case item already fills the whole screen or if there would |
|
1151 |
// be just few pixels (~margins) to scroll. |
|
1152 |
else if ((focusedRect.iTl.iY > 0 && focusedRect.iTl.iY > topMargin) || |
|
1153 |
(focusedRect.iBr.iY < Height() && |
|
1154 |
Height() - focusedRect.iBr.iY > bottomMargin)) |
|
1155 |
{ |
|
1156 |
scroll = (focusedRect.iTl.iY > 0) ? |
|
1157 |
-focusedRect.iTl.iY : -(focusedRect.iBr.iY - Height()); |
|
1158 |
} |
|
1159 |
} |
|
1160 |
return scroll; |
|
1161 |
} |
|
1162 |
||
1163 |
/** |
|
1164 |
* Scrolls to the rect corresponding to the row specified by aIdx using |
|
1165 |
* the direction indicated by aDirection. @see ScrollToRect() |
|
1166 |
**/ |
|
1167 |
void CMIDForm::RawScrollToRow(TInt aIdx, TDirection aDirection) |
|
1168 |
{ |
|
1169 |
DEBUG("< CMIDForm::RawScrollToRow"); |
|
1170 |
if (aIdx >= 0 && aIdx < iRows.Count()) |
|
1171 |
{ |
|
1172 |
TRect rect = iRows[aIdx]->Rect(); |
|
1173 |
DEBUG("CMIDForm::RawScrollToRow - scroll to rect"); |
|
1174 |
RawScrollToRect(rect, aDirection); |
|
1175 |
} |
|
1176 |
DEBUG("> CMIDForm::RawScrollToRow"); |
|
1177 |
} |
|
1178 |
||
1179 |
/** */ |
|
1180 |
void CMIDForm::RawScrollToRect(const TRect& aRect, TDirection aDirection, TBool aReset) |
|
1181 |
{ |
|
1182 |
DEBUG("< CMIDForm::RawScrollToRect"); |
|
1183 |
DEBUG_INT4("CMIDForm::RawScrollToRect - rect is %D %D %D %D", aRect.iTl.iX, aRect.iTl.iY, |
|
1184 |
aRect.iBr.iX, aRect.iBr.iY); |
|
1185 |
||
1186 |
if (RectFullyVisible(aRect)) |
|
1187 |
{ |
|
1188 |
DEBUG("CMIDForm::RawScrollToRect - return rect fully visible"); |
|
1189 |
TInt maxScrollValue = Height() - HeightOfAllItems(); |
|
1190 |
// Avoid scrolling out of the form (i.e. after the view port has lower height) |
|
1191 |
||
1192 |
if (iScroll < maxScrollValue) |
|
1193 |
{ |
|
1194 |
RawScroll(maxScrollValue); |
|
1195 |
} |
|
1196 |
return; |
|
1197 |
} |
|
1198 |
||
1199 |
TInt scrollOffset = 0; |
|
1200 |
if (aRect.Size().iHeight > Height()) |
|
1201 |
{//rect higher than screen height |
|
1202 |
if (RectPartiallyVisible(aRect) && !aReset) |
|
1203 |
{//if already visible, scroll only of KMinScrollAmount (panning) |
|
1204 |
scrollOffset = (aDirection == EDown) ? -KMinScrollAmount : KMinScrollAmount; |
|
1205 |
} |
|
1206 |
else |
|
1207 |
{//if not visible and scrolling down scroll to top - KMinScrollAmount |
|
1208 |
// or to bottom + KMinScrollAmount if scrolling up |
|
1209 |
scrollOffset = (aDirection == EDown) ? (Height() - (aRect.iTl.iY + KMinScrollAmount)) |
|
1210 |
: -(aRect.iBr.iY - KMinScrollAmount); |
|
1211 |
} |
|
1212 |
} |
|
1213 |
else |
|
1214 |
{//if it fits on screen make sure its BR is at the bottom if scrolling down |
|
1215 |
//or its TL is at the top if scrolling up |
|
1216 |
scrollOffset = (aDirection == EDown) ? (Height() - aRect.iBr.iY) : (-aRect.iTl.iY); |
|
1217 |
} |
|
1218 |
||
1219 |
RawScroll(iScroll + scrollOffset); |
|
1220 |
DEBUG("> CMIDForm::RawScrollToRect"); |
|
1221 |
} |
|
1222 |
||
1223 |
void CMIDForm::ScrollRelative(TInt aScroll) |
|
1224 |
{ |
|
1225 |
DEBUG("CMIDForm::ScrollRelative"); |
|
1226 |
RawScrollRelative(aScroll); |
|
1227 |
RawScrollFinalize(EFalse); |
|
1228 |
} |
|
1229 |
||
1230 |
void CMIDForm::RawScrollRelative(TInt aScroll) |
|
1231 |
{ |
|
1232 |
TInt scroll = iScroll + aScroll; |
|
1233 |
RawScroll(scroll); |
|
1234 |
} |
|
1235 |
||
1236 |
void CMIDForm::RawScroll(TInt aScroll) |
|
1237 |
{ |
|
1238 |
TInt contentHeight = HeightOfAllItems(); |
|
1239 |
TInt viewPortHeight = Height(); |
|
1240 |
if (aScroll > 0 || contentHeight <= viewPortHeight) |
|
1241 |
{ // make sure that top does not slide down |
|
1242 |
aScroll = 0; |
|
1243 |
} |
|
1244 |
if (contentHeight > viewPortHeight && ((-aScroll) + viewPortHeight) > contentHeight) |
|
1245 |
{ // scroll only as long as there is content |
|
1246 |
aScroll = -(contentHeight - viewPortHeight); |
|
1247 |
} |
|
1248 |
iHasScrolled = iScroll != aScroll; |
|
1249 |
iScrollDelta = aScroll - iScroll; |
|
1250 |
iScroll = aScroll; |
|
1251 |
||
1252 |
SetRowPositionsWithRespectToScrolledLocation(); |
|
1253 |
} |
|
1254 |
||
1255 |
void CMIDForm::SetRowExtentsWithRespectToScrolledLocation() |
|
1256 |
{ |
|
1257 |
iTotalFormHeight = 0; |
|
1258 |
TInt xMargin = iFormRect.Rect().iTl.iX; |
|
1259 |
TInt yTopMargin = iFormRect.Rect().iTl.iY - iMidpFormRect.Rect().iTl.iY; |
|
1260 |
TInt yBottomMargin = iMidpFormRect.Rect().iBr.iY - iFormRect.Rect().iBr.iY; |
|
1261 |
||
1262 |
iTotalFormHeight = yTopMargin; |
|
1263 |
||
1264 |
TInt rowCount = iRows.Count(); |
|
1265 |
for (TInt i=0; i < rowCount; i++) |
|
1266 |
{ |
|
1267 |
// Form left margin is added in the beginning of each row |
|
1268 |
iRows[i]->SetExtent(TPoint(xMargin, iScroll + iTotalFormHeight), |
|
1269 |
TSize(Width(), iRows[i]->Size().iHeight)); |
|
1270 |
iTotalFormHeight += iRows[i]->Size().iHeight; |
|
1271 |
} |
|
1272 |
// Form bottom margin is added |
|
1273 |
iTotalFormHeight += yBottomMargin; |
|
1274 |
} |
|
1275 |
||
1276 |
void CMIDForm::SetRowPositionsWithRespectToScrolledLocation() |
|
1277 |
{ |
|
1278 |
TInt rowCount = iRows.Count(); |
|
1279 |
for (TInt i=0; i < rowCount; i++) |
|
1280 |
{ |
|
1281 |
// Form left margin is added in the beginning of each row |
|
1282 |
TPoint pos = iRows[i]->Position(); |
|
1283 |
pos.iY += ScrollDelta(); |
|
1284 |
iRows[i]->SetPosition(pos); |
|
1285 |
} |
|
1286 |
} |
|
1287 |
||
1288 |
// Finalizes scrolling after any RawScrollXxxx method call, e.g. causes repaint. |
|
1289 |
// Draw can be prevented e.g. because of the performance reasons. |
|
1290 |
void CMIDForm::RawScrollFinalize(TBool forseAction, TBool aDraw /*= ETrue*/) |
|
1291 |
{ |
|
1292 |
if (iHasScrolled || forseAction) |
|
1293 |
{ |
|
1294 |
UpdateHighlightBackgroundPosition(); |
|
1295 |
HandleItemVisibilityChange(); |
|
1296 |
UpdateScrollBar(); |
|
1297 |
if (iFocused != KErrNotFound) |
|
1298 |
{ |
|
1299 |
CMIDControlItem& ci = ControlItem(iFocused); |
|
1300 |
if (IsTextFieldItem(ci)) |
|
1301 |
{ |
|
1302 |
if (RectPartiallyVisible(ci.Rect())) |
|
1303 |
{ |
|
1304 |
((CMIDTextFieldItem&) ci).SetCursorVisibility(ETrue); |
|
1305 |
} |
|
1306 |
else |
|
1307 |
{ |
|
1308 |
((CMIDTextFieldItem&) ci).SetCursorVisibility(EFalse); |
|
1309 |
} |
|
1310 |
} |
|
1311 |
if (IsDateField(ci)) |
|
1312 |
{ |
|
1313 |
// Update right cursor position on Datefiled |
|
1314 |
((CMIDDateFieldItem&) ci).CursorUpdate(); |
|
1315 |
} |
|
1316 |
} |
|
1317 |
if (aDraw) |
|
1318 |
{ |
|
1319 |
DrawDeferred(); |
|
1320 |
} |
|
1321 |
iHasScrolled = EFalse; |
|
1322 |
} |
|
1323 |
} |
|
1324 |
||
1325 |
/** Returns the client area */ |
|
1326 |
TRect CMIDForm::GetClientArea() |
|
1327 |
{ |
|
1328 |
TRect scrolledClientArea = TRect(Position(), TSize(Width(), Height())); |
|
1329 |
return scrolledClientArea; |
|
1330 |
} |
|
1331 |
||
1332 |
// returns ETrue if it moved the focus |
|
1333 |
// returns EFalse otherwise |
|
1334 |
TBool CMIDForm::TryMovingFocusHorizontally(TDirection aDirection) |
|
1335 |
{ |
|
1336 |
ASSERT(aDirection == ELeft || aDirection == ERight); |
|
1337 |
||
1338 |
TInt idx = NextFocusableHorizontalIdx(aDirection); |
|
1339 |
if (idx != KErrNotFound) |
|
1340 |
{ |
|
1341 |
SetFocusedItem(idx, aDirection); |
|
1342 |
return ETrue; |
|
1343 |
} |
|
1344 |
||
1345 |
return EFalse; |
|
1346 |
} |
|
1347 |
||
1348 |
/** |
|
1349 |
Moves the focus vertically. |
|
1350 |
||
1351 |
We check if there is a focussable item, |
|
1352 |
which is on a row totally or partially visible and if there is such |
|
1353 |
an item we then select that row. This is done by calling |
|
1354 |
NextPartiallyVisibleRowWithFocusableItem(). If no such item was found we pick |
|
1355 |
the top or bottom (depending on scrolling direction) row that is partially |
|
1356 |
visible or the first not visible if the last one is completely shown. |
|
1357 |
This is done by FirstRowWithBottomBelowScreen() and LastRowWithTopAboveScreen(). |
|
1358 |
||
1359 |
At this point if we have a row, we select a focussable item on it and |
|
1360 |
scroll to it if aScroll is true. Calling scroll methods doesn't mean there is going to be |
|
1361 |
scrolling of the form, |
|
1362 |
if the item is already visible no scrolling is done. We select the |
|
1363 |
next focussable item according to the value of the parameter aSelectClosest. |
|
1364 |
If this paramerter is true we call SelectClosestFocussableItem() otherwise |
|
1365 |
we either select the first or the last selectable item on the row depending |
|
1366 |
on the direction. |
|
1367 |
||
1368 |
If we find a control we scroll to it by calling ScrollToFocused() (if aScroll is true) and move |
|
1369 |
the focus to it by calling SetFocusedItem(). Otherwise we |
|
1370 |
scroll to the row by calling ScrollToRow() if aScroll is true. |
|
1371 |
||
1372 |
If we could not find any row with a focusable item on it, we scroll the form |
|
1373 |
of a fixed quantity, KMinScrollAmount, if aScroll is true. |
|
1374 |
||
1375 |
We return ETrue if the focus was moved, EFalse otherwise. Note: Currently the |
|
1376 |
return value of this method is ignored. |
|
1377 |
||
1378 |
@see NextPartiallyVisibleRowWithFocusableItem(), FirstRowWithBottomBelowScreen(), |
|
1379 |
LastRowWithTopAboveScreen(), SelectClosestFocussableItem() |
|
1380 |
ScrollToRow(), SetFocusedItem() and DoScrollRelative(). |
|
1381 |
Also see ReplaceFocusedItem(), called when the focused item is removed or |
|
1382 |
loses focusability - in this case no scrolling will occur. |
|
1383 |
*/ |
|
1384 |
TBool CMIDForm::TryMovingFocusVertically(TDirection aDirection, TBool aSelectClosest, |
|
1385 |
TBool aScroll /*=ETrue*/) |
|
1386 |
{ |
|
1387 |
DEBUG("> CMIDForm::TryMovingFocusVertically"); |
|
1388 |
ASSERT(aDirection == EUp || aDirection == EDown); |
|
1389 |
||
1390 |
// is VKB opened |
|
1391 |
if (iDisplayable.IsVKBOnScreen()) |
|
1392 |
{ |
|
1393 |
return ETrue; |
|
1394 |
} |
|
1395 |
||
1396 |
TInt rowIdx = NextPartiallyVisibleRowWithFocusableItem(aDirection); |
|
1397 |
||
1398 |
if (rowIdx == KErrNotFound) |
|
1399 |
{ |
|
1400 |
DEBUG("CMIDForm::TryMovingFocusVertically - no partially visible focusable control found"); |
|
1401 |
rowIdx = aDirection == EDown ? FirstRowWithBottomBelowScreen() : LastRowWithTopAboveScreen(); |
|
1402 |
} |
|
1403 |
||
1404 |
if (rowIdx != KErrNotFound) |
|
1405 |
{ |
|
1406 |
CMIDControlItem* ci = aSelectClosest ? SelectClosestFocussableItem(rowIdx) : |
|
1407 |
(aDirection == EDown ? iRows[rowIdx]->FirstFocusableItem() : |
|
1408 |
iRows[rowIdx]->LastFocusableItem()); |
|
1409 |
||
1410 |
||
1411 |
if (ci) |
|
1412 |
{ |
|
1413 |
DEBUG("CMIDForm::TryMovingFocusVertically - got control"); |
|
1414 |
TInt index = Index(ci); |
|
1415 |
||
1416 |
if (index == KErrNotFound && IsLabelContainerItem(*ci)) |
|
1417 |
{ |
|
1418 |
CMIDLabelContainerItem* ucsi = static_cast<CMIDLabelContainerItem*>(ci); |
|
1419 |
CMIDStringItem& si = ucsi->StringItem(); |
|
1420 |
index = Index(&si); |
|
1421 |
} |
|
1422 |
||
1423 |
if (index != KErrNotFound) |
|
1424 |
{ |
|
1425 |
TRect rect = GetControlRect(index); |
|
1426 |
||
1427 |
if (aScroll) |
|
1428 |
{ |
|
1429 |
SetFocusedItem(index, aDirection, ETrue); |
|
1430 |
} |
|
1431 |
else if (RectPartiallyVisible(rect)) |
|
1432 |
{ |
|
1433 |
SetFocusedItem(index, aDirection); |
|
1434 |
} |
|
1435 |
else |
|
1436 |
{ |
|
1437 |
SetFocusedItem(KErrNotFound); |
|
1438 |
} |
|
1439 |
||
1440 |
DEBUG("CMIDForm::TryMovingFocusVertically - out after scroll to control"); |
|
1441 |
return ETrue; |
|
1442 |
} |
|
1443 |
} |
|
1444 |
||
1445 |
DEBUG("CMIDForm::TryMovingFocusVertically - scrolling to row"); |
|
1446 |
if (aScroll) |
|
1447 |
{ |
|
1448 |
RawScrollToRow(rowIdx, aDirection); |
|
1449 |
} |
|
1450 |
} |
|
1451 |
else |
|
1452 |
{ |
|
1453 |
DEBUG("CMIDForm::TryMovingFocusVertically - small default scrolling"); |
|
1454 |
if (aScroll) |
|
1455 |
{ |
|
1456 |
RawScrollRelative((aDirection == EDown) ? -KMinScrollAmount : KMinScrollAmount); |
|
1457 |
} |
|
1458 |
} |
|
1459 |
||
1460 |
DEBUG("< CMIDForm::TryMovingFocusVertically"); |
|
1461 |
return EFalse; |
|
1462 |
} |
|
1463 |
||
1464 |
/** Given a row index, selects on this row the focusable control whose center on |
|
1465 |
the x axis is closes to the center of the currently focused item, if there is one. |
|
1466 |
If no control is found, returns the first selectable item on the row. */ |
|
1467 |
CMIDControlItem* CMIDForm::SelectClosestFocussableItem(TInt aRowIndex) const |
|
1468 |
{ |
|
1469 |
ASSERT(aRowIndex >= 0 && aRowIndex < iRows.Count()); |
|
1470 |
TInt selectedIndex = -1; |
|
1471 |
||
1472 |
if (iFocused != -1) |
|
1473 |
{ |
|
1474 |
TRect rect = GetControlRect(iFocused); |
|
1475 |
TInt focusedCenter = rect.iTl.iX + rect.Width()/2; |
|
1476 |
||
1477 |
TInt diff = iInnerWidth; |
|
1478 |
||
1479 |
TInt numItemsOnRow = iRows[aRowIndex]->NumItems(); |
|
1480 |
for (TInt i = 0; i < numItemsOnRow; i++) |
|
1481 |
{ |
|
1482 |
CMIDControlItem* item = iRows[aRowIndex]->Item(i); |
|
1483 |
if (item->IsSelectable()) |
|
1484 |
{ |
|
1485 |
TInt center = item->Position().iX + (item->Size().iWidth / 2); |
|
1486 |
TInt itemDiff = focusedCenter > center ? (focusedCenter - center) : (center - focusedCenter); |
|
1487 |
||
1488 |
if (itemDiff < diff) |
|
1489 |
{ |
|
1490 |
selectedIndex = i; |
|
1491 |
diff = itemDiff; |
|
1492 |
} |
|
1493 |
} |
|
1494 |
} |
|
1495 |
} |
|
1496 |
||
1497 |
return selectedIndex == -1 ? iRows[aRowIndex]->FirstFocusableItem() : |
|
1498 |
iRows[aRowIndex]->Item(selectedIndex); |
|
1499 |
} |
|
1500 |
||
1501 |
TInt CMIDForm::IndexOfFirstFocusableItemOnScreen(TDirection aDirection) |
|
1502 |
{ |
|
1503 |
ASSERT(aDirection == EUp || aDirection == EDown); |
|
1504 |
||
1505 |
TInt startIdx = FirstRowOnScreen(aDirection); |
|
1506 |
||
1507 |
if (startIdx == KErrNotFound) |
|
1508 |
{ |
|
1509 |
return KErrNotFound; |
|
1510 |
} |
|
1511 |
||
1512 |
CMIDControlItem* ci = NULL; |
|
1513 |
||
1514 |
if (aDirection == EDown) |
|
1515 |
{ |
|
1516 |
TInt idx = startIdx - 1; |
|
1517 |
TInt rowCount = iRows.Count(); |
|
1518 |
while (++idx < rowCount) |
|
1519 |
{ |
|
1520 |
CMIDFormRow* row = iRows[idx]; |
|
1521 |
if (row->Position().iY > Height()) |
|
1522 |
{ |
|
1523 |
break; |
|
1524 |
} |
|
1525 |
ci = row->FirstFocusableItemOnScreen(); |
|
1526 |
if (ci) |
|
1527 |
{ |
|
1528 |
break; |
|
1529 |
} |
|
1530 |
} |
|
1531 |
} |
|
1532 |
else |
|
1533 |
{ |
|
1534 |
TInt idx = startIdx + 1; |
|
1535 |
while (--idx >= 0) |
|
1536 |
{ |
|
1537 |
CMIDFormRow* row = iRows[idx]; |
|
1538 |
if ((row->Position().iY + row->Size().iHeight) < 0) |
|
1539 |
{ |
|
1540 |
break; |
|
1541 |
} |
|
1542 |
ci = row->FirstFocusableItemOnScreen(); |
|
1543 |
if (ci) |
|
1544 |
{ |
|
1545 |
break; |
|
1546 |
} |
|
1547 |
} |
|
1548 |
} |
|
1549 |
||
1550 |
if (!ci) |
|
1551 |
{ |
|
1552 |
return KErrNotFound; |
|
1553 |
} |
|
1554 |
||
1555 |
TInt index = Index(ci); |
|
1556 |
if (index == KErrNotFound) |
|
1557 |
{ |
|
1558 |
if (IsLabelContainerItem(*ci)) |
|
1559 |
{ |
|
1560 |
CMIDLabelContainerItem* ucsi = static_cast<CMIDLabelContainerItem*>(ci); |
|
1561 |
CMIDStringItem& si = ucsi->StringItem(); |
|
1562 |
index = Index(&si); |
|
1563 |
} |
|
1564 |
} |
|
1565 |
||
1566 |
return index; |
|
1567 |
} |
|
1568 |
||
1569 |
/** Return the rect for a control, taking into account if the control is an |
|
1570 |
unconstrained string item which has been split over more than one label container |
|
1571 |
*/ |
|
1572 |
TRect CMIDForm::GetControlRect(TInt aIdx) const |
|
1573 |
{ |
|
1574 |
CMIDControlItem& ci = ControlItem(aIdx); |
|
1575 |
TRect rect; |
|
1576 |
||
1577 |
if (ItemIsUnconstrained(aIdx)) |
|
1578 |
{ |
|
1579 |
rect = GetUnconstrainedStringItemRect(static_cast<CMIDStringItem*>(&ci)); |
|
1580 |
} |
|
1581 |
else |
|
1582 |
{ |
|
1583 |
rect = ci.Rect(); |
|
1584 |
} |
|
1585 |
||
1586 |
return rect; |
|
1587 |
} |
|
1588 |
||
1589 |
/** Collate rects for unconstrained string items that have been split across more |
|
1590 |
than one lable container */ |
|
1591 |
TRect CMIDForm::GetUnconstrainedStringItemRect(CMIDStringItem* aStringItem) const |
|
1592 |
{ |
|
1593 |
TRect rect(0,0,0,0); |
|
1594 |
TBool found = EFalse; |
|
1595 |
||
1596 |
TInt rowIdx = FirstRowOfUnconstrainedStringItem(*aStringItem); |
|
1597 |
TInt rowCount = iRows.Count(); |
|
1598 |
||
1599 |
// if the first row of unconstrained string item cannot be found |
|
1600 |
// it means that string item is placed as default item |
|
1601 |
// so simply return item's rect |
|
1602 |
if (rowIdx == KErrNotFound) |
|
1603 |
{ |
|
1604 |
return aStringItem->Rect(); |
|
1605 |
} |
|
1606 |
||
1607 |
while (rowIdx != KErrNotFound && rowIdx < rowCount) |
|
1608 |
{ |
|
1609 |
CMIDFormRow* row = iRows[rowIdx]; |
|
1610 |
for (TInt idxOnRow = 0; idxOnRow < row->NumItems(); idxOnRow++) |
|
1611 |
{ |
|
1612 |
CMIDControlItem* ci = row->Item(idxOnRow); |
|
1613 |
if (ci && IsLabelContainerItem(*ci)) |
|
1614 |
{ |
|
1615 |
CMIDLabelContainerItem* usil = static_cast<CMIDLabelContainerItem*>(ci); |
|
1616 |
CMIDStringItem* si = &(usil->StringItem()); |
|
1617 |
||
1618 |
if (si == aStringItem) |
|
1619 |
{ |
|
1620 |
if (!found) |
|
1621 |
{ |
|
1622 |
rect.iTl = usil->Rect().iTl; |
|
1623 |
found = ETrue; |
|
1624 |
} |
|
1625 |
rect.iBr = usil->Rect().iBr; |
|
1626 |
} |
|
1627 |
else if (found) |
|
1628 |
{ |
|
1629 |
return rect; |
|
1630 |
} |
|
1631 |
} |
|
1632 |
else if (found) |
|
1633 |
{ |
|
1634 |
return rect; |
|
1635 |
} |
|
1636 |
} |
|
1637 |
rowIdx++; |
|
1638 |
} |
|
1639 |
||
1640 |
return rect; |
|
1641 |
} |
|
1642 |
||
1643 |
TBool CMIDForm::RectPartiallyVisible(const TRect& aRect) |
|
1644 |
{ |
|
1645 |
return ((aRect.iTl.iY >= 0) && (aRect.iTl.iY < Height())) || |
|
1646 |
((aRect.iBr.iY >= 0) && (aRect.iBr.iY < Height())) || |
|
1647 |
((aRect.iTl.iY < 0) && (aRect.iBr.iY >= Height())); |
|
1648 |
} |
|
1649 |
||
1650 |
TBool CMIDForm::RectFullyVisible(const TRect& aRect) |
|
1651 |
{ |
|
1652 |
return (aRect.iTl.iY >= 0) && (aRect.iBr.iY <= Height()); |
|
1653 |
} |
|
1654 |
||
1655 |
TInt CMIDForm::FirstRowWithBottomBelowScreen() |
|
1656 |
{ |
|
1657 |
TInt idx = -1; |
|
1658 |
TInt rowWithFocus = iFocused == KErrNotFound ? -1 : Row(ControlItem(iFocused)); |
|
1659 |
TInt rowCount = iRows.Count(); |
|
1660 |
while (++idx < rowCount) |
|
1661 |
{ |
|
1662 |
CMIDFormRow* row = iRows[idx]; |
|
1663 |
TInt height = row->Size().iHeight; |
|
1664 |
TInt yPos = row->Position().iY; |
|
1665 |
if ((height + yPos) > Height() && row->HasNonSpacerItems() && idx != rowWithFocus) |
|
1666 |
{ |
|
1667 |
return idx; |
|
1668 |
} |
|
1669 |
} |
|
1670 |
||
1671 |
return KErrNotFound; |
|
1672 |
} |
|
1673 |
||
1674 |
TInt CMIDForm::LastRowWithTopAboveScreen() |
|
1675 |
{ |
|
1676 |
TInt idx = iRows.Count(); |
|
1677 |
TInt rowWithFocus = iFocused == KErrNotFound ? -1 : Row(ControlItem(iFocused)); |
|
1678 |
||
1679 |
while (--idx >= 0) |
|
1680 |
{ |
|
1681 |
CMIDFormRow* row = iRows[idx]; |
|
1682 |
TInt yPos = row->Position().iY; |
|
1683 |
if (yPos < 0 && row->HasNonSpacerItems() && idx != rowWithFocus) |
|
1684 |
{ |
|
1685 |
return idx; |
|
1686 |
} |
|
1687 |
} |
|
1688 |
||
1689 |
return KErrNotFound; |
|
1690 |
} |
|
1691 |
||
1692 |
// note: inspite of the name of this method, we only consider rows with |
|
1693 |
// a focusable item that has not already been scrolled off the screen. |
|
1694 |
// For Example: |
|
1695 |
// |
|
1696 |
// ---- |
|
1697 |
// | A | This is a |
|
1698 |
// | | string item |
|
1699 |
// ---- that is placed |
|
1700 |
//----------------------- <- top of form |
|
1701 |
// next to item A. |
|
1702 |
// This |
|
1703 |
// string |
|
1704 |
// item |
|
1705 |
// is |
|
1706 |
// quite |
|
1707 |
// tall |
|
1708 |
// and |
|
1709 |
//----------------------- <- botom of form |
|
1710 |
// fills |
|
1711 |
// the |
|
1712 |
// screen |
|
1713 |
// |
|
1714 |
// Assuming that A is focusable, and we are scrolling down, and also assuming |
|
1715 |
// that the string item is not focusable, we do not consider A when looking |
|
1716 |
// for focusable items, because we are scrolling down and A is already above |
|
1717 |
// the screen. |
|
1718 |
TInt CMIDForm::NextPartiallyVisibleRowWithFocusableItem(TDirection aDirection) |
|
1719 |
{ |
|
1720 |
ASSERT(aDirection == EUp || aDirection == EDown); |
|
1721 |
||
1722 |
TInt startIdx = 0; |
|
1723 |
if (iFocused != KErrNotFound) |
|
1724 |
{ |
|
1725 |
//If there is layout request pending, the array of rows is probably |
|
1726 |
//empty. So we need to do layout of form, which fills the array of rows. |
|
1727 |
//Then row, where current focused item is, will be found. |
|
1728 |
if (iRows.Count() == 0) |
|
1729 |
{ |
|
1730 |
TrappedLayoutAndDraw(ETrue); |
|
1731 |
} |
|
1732 |
TInt row = Row(ControlItem(iFocused)); |
|
1733 |
if (row == KErrNotFound) |
|
1734 |
{ |
|
1735 |
CMIDControlItem& ci = ControlItem(iFocused); |
|
1736 |
if (IsStringItem(ci)) |
|
1737 |
{ |
|
1738 |
// find the first row either above or below (depends on direction) |
|
1739 |
// this unconstrained stringItem |
|
1740 |
CMIDStringItem& stringItem = |
|
1741 |
*(static_cast<CMIDStringItem*>(&ci)); |
|
1742 |
if (aDirection == EDown) |
|
1743 |
{ |
|
1744 |
startIdx = FirstRowBelowUnconstrainedStringItem(stringItem); |
|
1745 |
} |
|
1746 |
else |
|
1747 |
{ |
|
1748 |
startIdx = FirstRowAboveUnconstrainedStringItem(stringItem); |
|
1749 |
} |
|
1750 |
} |
|
1751 |
else |
|
1752 |
{ |
|
1753 |
// shouldn't get here |
|
1754 |
ASSERT(EFalse); |
|
1755 |
} |
|
1756 |
} |
|
1757 |
else |
|
1758 |
{ |
|
1759 |
startIdx = row + ((aDirection == EDown) ? 1 : -1); |
|
1760 |
} |
|
1761 |
} |
|
1762 |
else |
|
1763 |
{ |
|
1764 |
// There is no focused item on Form (iFocused value is KErrNotFound). |
|
1765 |
// So we need to try to find another Item which could gain focus. |
|
1766 |
startIdx = FirstRowOnScreen(aDirection); |
|
1767 |
} |
|
1768 |
||
1769 |
if (startIdx == KErrNotFound) |
|
1770 |
{ |
|
1771 |
return KErrNotFound; |
|
1772 |
} |
|
1773 |
||
1774 |
if (aDirection == EDown) |
|
1775 |
{ |
|
1776 |
TInt idx = startIdx - 1; |
|
1777 |
TInt rowCount = iRows.Count(); |
|
1778 |
while (++idx < rowCount) |
|
1779 |
{ |
|
1780 |
CMIDFormRow* row = iRows[idx]; |
|
1781 |
if (row->Position().iY > Height()) |
|
1782 |
{ |
|
1783 |
break; |
|
1784 |
} |
|
1785 |
if (row->HasFocusableItemOnOrBelowScreen()) |
|
1786 |
{ |
|
1787 |
return idx; |
|
1788 |
} |
|
1789 |
} |
|
1790 |
} |
|
1791 |
else |
|
1792 |
{ |
|
1793 |
TInt idx = startIdx + 1; |
|
1794 |
while (--idx >= 0) |
|
1795 |
{ |
|
1796 |
CMIDFormRow* row = iRows[idx]; |
|
1797 |
||
1798 |
if (row->HasFocusableItemOnOrAboveScreen()) |
|
1799 |
{ |
|
1800 |
return idx; |
|
1801 |
} |
|
1802 |
||
1803 |
if ((row->Position().iY + row->Size().iHeight) < 0) |
|
1804 |
{ |
|
1805 |
break; |
|
1806 |
} |
|
1807 |
} |
|
1808 |
} |
|
1809 |
||
1810 |
return KErrNotFound; |
|
1811 |
} |
|
1812 |
||
1813 |
// if aFromTop is false we look from the bottom up |
|
1814 |
TInt CMIDForm::FirstRowOnScreen(TDirection aDirection) |
|
1815 |
{ |
|
1816 |
ASSERT(aDirection == EUp || aDirection == EDown); |
|
1817 |
||
1818 |
TInt idx = 0; |
|
1819 |
if (aDirection == EDown) |
|
1820 |
{ |
|
1821 |
idx = -1; |
|
1822 |
TInt rowCount = iRows.Count(); |
|
1823 |
while (++idx < rowCount) |
|
1824 |
{ |
|
1825 |
CMIDFormRow* row = iRows[idx]; |
|
1826 |
TInt bottom = row->Position().iY + row->Size().iHeight; |
|
1827 |
if (bottom > 0) |
|
1828 |
{ |
|
1829 |
return idx; |
|
1830 |
} |
|
1831 |
} |
|
1832 |
} |
|
1833 |
else |
|
1834 |
{ |
|
1835 |
idx = iRows.Count(); |
|
1836 |
while (--idx >= 0) |
|
1837 |
{ |
|
1838 |
CMIDFormRow* row = iRows[idx]; |
|
1839 |
TInt top = row->Position().iY; |
|
1840 |
if (top < Height()) |
|
1841 |
{ |
|
1842 |
return idx; |
|
1843 |
} |
|
1844 |
} |
|
1845 |
} |
|
1846 |
||
1847 |
return KErrNotFound; |
|
1848 |
} |
|
1849 |
||
1850 |
// Returns the item index of the next focusable item in the given direction. |
|
1851 |
// Note: this may return an object that is not on the current row if there is |
|
1852 |
// an unconstrained string item on the current row. |
|
1853 |
// |
|
1854 |
// -------- |
|
1855 |
// | | |
|
1856 |
// | A | |
|
1857 |
// | | -------- |
|
1858 |
// -------- -------- |
|
1859 |
// ----------------- |
|
1860 |
// __________ ------ |
|
1861 |
// | | |
|
1862 |
// | B | |
|
1863 |
// | | |
|
1864 |
// ------ |
|
1865 |
// In the above diagram we see a selectable item A, an unconstrained stringItem, |
|
1866 |
// and another selectable item B. If A has focus and the stringItem is not focusable |
|
1867 |
// then calling NextFocusableHorizontalIdx( ERight ) should return the index of B. |
|
1868 |
// If the string item is selectable then its index would get returned and a further |
|
1869 |
// call to NextFocusableHorizontalIdx( ERight ) would return the index of B. |
|
1870 |
// If B has focus calling NextFocusableHorizontalIdx( ELeft ) would simply return the |
|
1871 |
// index of the stringItem if it is selectable or A if not. |
|
1872 |
TInt CMIDForm::NextFocusableHorizontalIdx(TDirection aDirection) |
|
1873 |
{ |
|
1874 |
ASSERT(aDirection == ELeft || aDirection == ERight); |
|
1875 |
||
1876 |
TInt idx = KErrNotFound; |
|
1877 |
||
1878 |
if (iFocused != KErrNotFound) |
|
1879 |
{ |
|
1880 |
CMIDFormRow* rowPtr = NULL; |
|
1881 |
CMIDControlItem& controlItem = ControlItem(iFocused); |
|
1882 |
||
1883 |
TInt rowIdx = Row(controlItem, rowPtr); |
|
1884 |
||
1885 |
if (rowIdx != KErrNotFound) |
|
1886 |
{ |
|
1887 |
||
1888 |
idx = rowPtr->Find(&controlItem); |
|
1889 |
||
1890 |
if (aDirection == ELeft) |
|
1891 |
{ |
|
1892 |
while (--idx >= 0) |
|
1893 |
{ |
|
1894 |
if (rowPtr->Item(idx)->IsSelectable()) |
|
1895 |
{ |
|
1896 |
return ItemIndex(*(rowPtr->Item(idx))); |
|
1897 |
} |
|
1898 |
} |
|
1899 |
||
1900 |
} |
|
1901 |
else |
|
1902 |
{ |
|
1903 |
// direction is ERight |
|
1904 |
while (++idx < rowPtr->NumItems()) |
|
1905 |
{ |
|
1906 |
if (rowPtr->Item(idx)->IsSelectable()) |
|
1907 |
{ |
|
1908 |
return ItemIndex(*(rowPtr->Item(idx))); |
|
1909 |
} |
|
1910 |
} |
|
1911 |
||
1912 |
} |
|
1913 |
} |
|
1914 |
else |
|
1915 |
{ |
|
1916 |
// there is something focused but we failed to find a row index for it, |
|
1917 |
// so it is probably an unconstrained stringItem |
|
1918 |
if (aDirection == ELeft) |
|
1919 |
{ |
|
1920 |
if (IsStringItem(controlItem)) |
|
1921 |
{ |
|
1922 |
CMIDStringItem* si = static_cast<CMIDStringItem*>(&controlItem); |
|
1923 |
idx = FirstFocusableItemBeforeStartOfUnconstrainedStringItemIdx(*si); |
|
1924 |
return idx; |
|
1925 |
} |
|
1926 |
} |
|
1927 |
else |
|
1928 |
{ |
|
1929 |
// direction ie ERight |
|
1930 |
if (IsStringItem(controlItem)) |
|
1931 |
{ |
|
1932 |
CMIDStringItem* si = static_cast<CMIDStringItem*>(&controlItem); |
|
1933 |
idx = FirstFocusableItemOnLastLineOfUnconstrainedStringItemIdx(*si); |
|
1934 |
return idx; |
|
1935 |
} |
|
1936 |
} |
|
1937 |
} |
|
1938 |
} |
|
1939 |
||
1940 |
return KErrNotFound; |
|
1941 |
} |
|
1942 |
||
1943 |
/** Replaces the currently focused item. This is called when the focused item is removed |
|
1944 |
or it loses focusability, for example a string item that loses all its commands. So this |
|
1945 |
is always triggered by a java call, never by the user. We call the same methods that are |
|
1946 |
used by Scroll(), ie TryMovingFocusHorizontally() and TryMovingFocusVertically(). However |
|
1947 |
in this case we don't want the form to scroll if the focused item is not on screen. So |
|
1948 |
these two methods will move the focus if a focusable item is either completely or partially |
|
1949 |
visible on screen following the good direction (right-down for left to right devices and |
|
1950 |
vice-versa for right to left devices). TryMovingFocusVertically() will set the focused item |
|
1951 |
to KErrNotFound if no focusable item is currently visible. */ |
|
1952 |
void CMIDForm::ReplaceFocusedItem() |
|
1953 |
{ |
|
1954 |
if (LayoutPending()) |
|
1955 |
{ |
|
1956 |
DEBUG("CMIDForm::ReplaceFocusedItem - calling layout"); |
|
1957 |
TRAP_IGNORE(LayoutFormL()); |
|
1958 |
} |
|
1959 |
||
1960 |
CMIDForm::TDirection direction = (iInitialAlignment == MMIDItem::ERight) ? ELeft : ERight; |
|
1961 |
||
1962 |
if (!TryMovingFocusHorizontally(direction)) |
|
1963 |
{ |
|
1964 |
if (iInitialAlignment == MMIDItem::ERight) |
|
1965 |
{//RIGHT TO LEFT |
|
1966 |
if (!TryMovingFocusVertically(direction == ELeft ? EDown : EUp, EFalse, EFalse)) |
|
1967 |
{ |
|
1968 |
SetFocusedItem(KErrNotFound); |
|
1969 |
} |
|
1970 |
} |
|
1971 |
else |
|
1972 |
{//LEFT TO RIGHT |
|
1973 |
if (!TryMovingFocusVertically(direction == ELeft ? EUp : EDown, EFalse, EFalse)) |
|
1974 |
{ |
|
1975 |
SetFocusedItem(KErrNotFound); |
|
1976 |
} |
|
1977 |
} |
|
1978 |
} |
|
1979 |
} |
|
1980 |
||
1981 |
void CMIDForm::SetFocusedItem(TInt aFocusIdx, TDirection aDirection /*= ENone*/, |
|
1982 |
TBool aDoScroll /*= ETrue*/) |
|
1983 |
{ |
|
1984 |
TInt oldFocused = iFocused; |
|
1985 |
TInt focusIndexDelta = aFocusIdx - iFocused; |
|
1986 |
if (iFocused != KErrNotFound) |
|
1987 |
{ // actions for the item loosing focus |
|
1988 |
CMIDControlItem& control = ControlItem(iFocused); |
|
1989 |
control.PostFocusTransferEvent(EFalse, aDirection); |
|
1990 |
// setting highlight must be called before setting focus |
|
1991 |
control.SetHighlight(EFalse); |
|
1992 |
control.SetFocus(EFalse); |
|
1993 |
UpdateItemCommands(NULL, NULL); |
|
1994 |
} |
|
1995 |
||
1996 |
iFocused = aFocusIdx; |
|
1997 |
||
1998 |
//If there is traverse from visible to invisible TextField, Form has to scroll first |
|
1999 |
//before actions for the item which gaining focus are done. Form scrolling provides |
|
2000 |
//position settings to all visible items in form. |
|
2001 |
//When TextField gains focus, cursor values are calculated. Because this step was done before |
|
2002 |
//scrolling, position of edwin in TextField was not set (@see CMIDFormRow::SizeChanged()) |
|
2003 |
//and cursor was drawn to wrong position. |
|
2004 |
//So Form has to scroll first -> this action provides proper position settings |
|
2005 |
//to item and items which are part of it (e.g. edwin in TextField) and after that |
|
2006 |
//changing focus makes proper cursor drawing. |
|
2007 |
if (focusIndexDelta != 0 && aDoScroll) |
|
2008 |
{ |
|
2009 |
if (oldFocused != KErrNotFound) |
|
2010 |
{ |
|
2011 |
aDirection = (focusIndexDelta > 0) ? EDown : EUp; |
|
2012 |
} |
|
2013 |
||
2014 |
ScrollToFocused(aDirection, EFalse); |
|
2015 |
} |
|
2016 |
||
2017 |
if (iFocused != KErrNotFound) |
|
2018 |
{ // actions for the item gaining focus |
|
2019 |
CMIDControlItem& control = ControlItem(iFocused); |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
2020 |
|
66 | 2021 |
SetHighlightBackgroundRects(); |
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
2022 |
|
66 | 2023 |
control.PostFocusTransferEvent(ETrue, aDirection); |
2024 |
control.SetHighlight(ETrue); |
|
2025 |
control.SetFocus(ETrue); |
|
2026 |
// msk: deliver also the possible MSK command to displayable |
|
2027 |
UpdateItemCommands(control.CommandList(), control.GetMSKCommand()); |
|
2028 |
} |
|
2029 |
} |
|
2030 |
||
2031 |
/** Updates the model of the scrollbar and moves the thumb. Scroll bar must have |
|
2032 |
already been layouted.*/ |
|
2033 |
void CMIDForm::UpdateScrollBar() |
|
2034 |
{ |
|
2035 |
ASSERT(iSBFrame); |
|
2036 |
DEBUG_INT("CMIDForm::UpdateScrollBar - iScroll is %D", iScroll); |
|
2037 |
||
2038 |
TInt heightOfAllItems = HeightOfAllItems(); |
|
2039 |
TInt height = heightOfAllItems > Height() ? heightOfAllItems : Height(); |
|
2040 |
||
2041 |
TEikScrollBarModel vSbarModel(height, Height(), -iScroll); |
|
2042 |
iSBFrame->Tile(&vSbarModel); |
|
2043 |
iSBFrame->MoveVertThumbTo(-iScroll); |
|
2044 |
||
2045 |
iPopupController->HidePopup(); // hide info popup window if visible |
|
2046 |
} |
|
2047 |
||
2048 |
CMIDForm* CMIDForm::NewL(MMIDEnv& aEnv,MMIDDisplayable& aDisplayable) |
|
2049 |
{ |
|
2050 |
CMIDForm* form = new(ELeave) CMIDForm(aEnv, static_cast<CMIDDisplayable&>(aDisplayable)); |
|
2051 |
CleanupStack::PushL(form); |
|
2052 |
form->ConstructL(); |
|
2053 |
CleanupStack::Pop(form); |
|
2054 |
return form; |
|
2055 |
} |
|
2056 |
||
2057 |
CMIDForm::CMIDForm(MMIDEnv& aEnv, CMIDDisplayable& aDisplayable) |
|
2058 |
: iDisplayable(aDisplayable), iEnv(&aEnv), iFocused(KErrNotFound), |
|
2059 |
iInitialAlignment(MMIDItem::ELeft), iHasScrolled(EFalse), |
|
71
d5e927d5853b
Revision: v2.2.11
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
2060 |
iLastFadeMessage(0), |
d5e927d5853b
Revision: v2.2.11
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
2061 |
iLastPointedControl(KErrNotFound) |
66 | 2062 |
{ |
2063 |
} |
|
2064 |
||
2065 |
CMIDForm::~CMIDForm() |
|
2066 |
{ |
|
2067 |
TRAP_IGNORE(DeleteAllItemsL()); |
|
2068 |
DeleteRows(); |
|
2069 |
iCurrentRow = NULL; |
|
2070 |
||
2071 |
delete iSBFrame; |
|
2072 |
SetItemsFormPointersToVal(NULL); |
|
2073 |
iItems.Close(); |
|
2074 |
iRows.Close(); |
|
2075 |
||
2076 |
delete iLayoutTimer; |
|
2077 |
delete iNoDataText; |
|
2078 |
||
2079 |
if (iBackgroundControlContext) |
|
2080 |
{ |
|
2081 |
delete iBackgroundControlContext; |
|
2082 |
iBackgroundControlContext = NULL; |
|
2083 |
} |
|
2084 |
if (iHighlightedBackgroundCc) |
|
2085 |
{ |
|
2086 |
delete iHighlightedBackgroundCc; |
|
2087 |
iHighlightedBackgroundCc = NULL; |
|
2088 |
} |
|
2089 |
||
2090 |
// Displayable is notified about content control deletion |
|
2091 |
iDisplayable.NotifyContentDestroyed(); |
|
2092 |
||
2093 |
delete iPopupController; |
|
2094 |
||
2095 |
if (iHighlightTimer) |
|
2096 |
{ |
|
2097 |
iHighlightTimer->Cancel(); |
|
2098 |
} |
|
2099 |
delete iHighlightTimer; |
|
2100 |
||
2101 |
delete iPhysics; |
|
2102 |
} |
|
2103 |
||
2104 |
#include "javaoslayer.h" |
|
2105 |
||
2106 |
void CMIDForm::Draw(const TRect& aRect) const |
|
2107 |
{ |
|
2108 |
if (!iStartUpTraceDone) |
|
2109 |
{ |
|
2110 |
java::util::JavaOsLayer::startUpTrace("MIDP: CMIDForm::Draw starts", -1, -1); |
|
2111 |
} |
|
2112 |
if (LayoutPending()) |
|
2113 |
{ |
|
2114 |
return; |
|
2115 |
} |
|
2116 |
||
2117 |
CWindowGc& gc = SystemGc(); |
|
2118 |
||
2119 |
MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
2120 |
AknsDrawUtils::Background(skin, iBackgroundControlContext, this, gc, aRect); |
|
2121 |
||
2122 |
// Draw focus highlight |
|
2123 |
if (iFocused != KErrNotFound) |
|
2124 |
{ |
|
2125 |
TRect focusedRect = ControlItem(iFocused).Rect(); |
|
2126 |
if (focusedRect.Intersects(aRect)) |
|
2127 |
{ |
|
2128 |
AknsDrawUtils::Background(AknsUtils::SkinInstance(), |
|
2129 |
iHighlightedBackgroundCc, this, |
|
2130 |
SystemGc(), focusedRect); |
|
2131 |
} |
|
2132 |
} |
|
2133 |
||
2134 |
// If there is no items, "No data" string is printed to the middle of the screen |
|
2135 |
if (iItems.Count() == 0) |
|
2136 |
{ |
|
2137 |
TRAP_IGNORE(DrawNoDataStringL()); |
|
2138 |
} |
|
2139 |
if (!iStartUpTraceDone) |
|
2140 |
{ |
|
2141 |
java::util::JavaOsLayer::startUpTrace("MIDP: CMIDForm::Draw done", -1, -1); |
|
2142 |
iStartUpTraceDone = ETrue; |
|
2143 |
} |
|
2144 |
} |
|
2145 |
||
2146 |
void CMIDForm::DrawNoDataStringL() const |
|
2147 |
{ |
|
2148 |
CWindowGc& gc = SystemGc(); |
|
2149 |
||
2150 |
// Actual skin instance |
|
2151 |
MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
2152 |
||
2153 |
// If there is not the color fot the particular skin and id found, default (black) is used |
|
2154 |
TRgb color; |
|
2155 |
// Try to receive the color by skin and color Id, if not successful, black is used |
|
2156 |
TInt err = AknsUtils::GetCachedColor(skin, color, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6); |
|
2157 |
if (err != KErrNone) |
|
2158 |
{ |
|
2159 |
color = AKN_LAF_COLOR(AknLayout::Title_pane_texts_Line_1(0, 0).iC); |
|
2160 |
} |
|
2161 |
||
2162 |
const CFont* font = CMIDFont::DefaultFont(CMIDFont::EDefaultTextId); |
|
2163 |
TInt textWidth = font->TextWidthInPixels(iNoDataText->Des()); |
|
2164 |
||
2165 |
// Rectangle for computing the center |
|
2166 |
TRect screenRect; |
|
2167 |
AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EScreen, screenRect); |
|
2168 |
||
2169 |
// Centers the string to the middle of the screen |
|
2170 |
TInt x = (screenRect.Width() - textWidth) / 2; |
|
2171 |
TInt y = (iInnerHeight - font->HeightInPixels()) / 2; |
|
2172 |
TPoint point(x, y); |
|
2173 |
//Reserve extra space for biditext formatting |
|
2174 |
HBufC* bidiTextBuffer = HBufC::NewLC(iNoDataText->Size() + KAknBidiExtraSpacePerLine); |
|
2175 |
TPtr bidiText = bidiTextBuffer->Des(); |
|
2176 |
TPtr caption = iNoDataText->Des(); |
|
2177 |
bidiText = caption; |
|
2178 |
// Handle (bidi)text formatting for all languages |
|
2179 |
AknBidiTextUtils::ConvertToVisualAndClipL(bidiText, *font, textWidth, textWidth); |
|
2180 |
||
2181 |
gc.SetPenColor(color); |
|
2182 |
gc.UseFont(font); |
|
2183 |
gc.DrawText(bidiText, point); |
|
2184 |
CleanupStack::PopAndDestroy(bidiTextBuffer); |
|
2185 |
gc.DiscardFont(); |
|
2186 |
} |
|
2187 |
||
2188 |
||
2189 |
/** Request a layout operaiton. We must delete the rows if postponing layout |
|
2190 |
in case java side some of the controls have been deleted. Otherwise because those |
|
2191 |
controls may be on existing rows we would get a panic in a draw request outside |
|
2192 |
our control. By deleting the rows in the worse scenario we'll get a blank form |
|
2193 |
drawn temporarily until the next layout operation. */ |
|
2194 |
void CMIDForm::RequestLayoutL(TBool aImmediately /*= EFalse*/) |
|
2195 |
{ |
|
2196 |
if (aImmediately) |
|
2197 |
{ |
|
2198 |
iLayoutTimer->Cancel(); |
|
2199 |
LayoutAndDrawL(); |
|
2200 |
} |
|
2201 |
else |
|
2202 |
{ |
|
2203 |
if (LayoutPending()) |
|
2204 |
{ |
|
2205 |
TTime now; |
|
2206 |
now.HomeTime(); |
|
2207 |
||
2208 |
if (now.MicroSecondsFrom(iLayoutRequestTime) > KLayoutCap) |
|
2209 |
{ |
|
2210 |
LayoutAndDrawL(); |
|
2211 |
} |
|
2212 |
else |
|
2213 |
{ |
|
2214 |
iLayoutTimer->Cancel(); |
|
2215 |
} |
|
2216 |
} |
|
2217 |
else |
|
2218 |
{ |
|
2219 |
iLayoutRequestTime.HomeTime(); |
|
2220 |
DeleteRows(); |
|
2221 |
} |
|
2222 |
||
2223 |
if (iLayoutRequestTime != -1) |
|
2224 |
{ |
|
2225 |
iLayoutTimer->After(KLayoutTimeout); |
|
2226 |
} |
|
2227 |
} |
|
2228 |
} |
|
2229 |
||
2230 |
/** Return true if a layout request has been made. */ |
|
2231 |
TBool CMIDForm::LayoutPending() const |
|
2232 |
{ |
|
2233 |
return (iLayoutRequestTime != -1) && (iLayoutTimer->IsActive()); |
|
2234 |
} |
|
2235 |
||
2236 |
/** |
|
2237 |
Layout the form, do scrolling and draw. Reset any previous layout request. |
|
2238 |
||
2239 |
@see RequestLayout(), LayoutPending(), LayoutFormL() and DoScroll() |
|
2240 |
*/ |
|
2241 |
void CMIDForm::LayoutAndDrawL() |
|
2242 |
{ |
|
2243 |
DEBUG("CMIDForm::LayoutAndDrawL"); |
|
2244 |
||
2245 |
LayoutFormL(); |
|
2246 |
||
2247 |
HandleItemVisibilityChange(); |
|
2248 |
UpdateScrollBar(); |
|
2249 |
SetHighlightBackgroundRects(); |
|
2250 |
DrawDeferred(); |
|
2251 |
||
2252 |
UpdatePhysics(); |
|
2253 |
} |
|
2254 |
||
2255 |
/** Call LayoutAndDrawL() inside a trap harness and log an error message if it |
|
2256 |
levaes. |
|
2257 |
||
2258 |
@param aOnlyIfPending Call LayoutAndDrawL() only if there is one pending, |
|
2259 |
@see LayoutPending(). By default this parameter is EFalse, i.e. always do layout |
|
2260 |
||
2261 |
@return The leave code returned by LayoutAndDrawL() |
|
2262 |
*/ |
|
2263 |
TInt CMIDForm::TrappedLayoutAndDraw(TBool aOnlyIfPending /* = EFalse */) |
|
2264 |
{ |
|
2265 |
if (aOnlyIfPending && !LayoutPending()) |
|
2266 |
{ |
|
2267 |
return KErrNone; |
|
2268 |
} |
|
2269 |
||
2270 |
TRAPD(err, LayoutAndDrawL()); |
|
2271 |
return err; |
|
2272 |
} |
|
2273 |
||
2274 |
/* Called when the form becomes current and after the focus was set |
|
2275 |
* @see CMIDDisplayable::HandleCurrentL() |
|
2276 |
*/ |
|
2277 |
void CMIDForm::HandleCurrentL(TBool aCurrent) |
|
2278 |
{ |
|
2279 |
if (iFocused != KErrNotFound) |
|
2280 |
{ |
|
2281 |
CMIDControlItem& control = ControlItem(iFocused); |
|
2282 |
control.HandleCurrentL(aCurrent); |
|
2283 |
} |
|
2284 |
||
2285 |
if (!aCurrent) |
|
2286 |
{ |
|
2287 |
iPopupController->HidePopup(); |
|
2288 |
} |
|
2289 |
||
2290 |
#ifdef RD_SCALABLE_UI_V2 |
|
2291 |
iCanDragFocus = EFalse; |
|
2292 |
#endif |
|
2293 |
} |
|
2294 |
||
2295 |
void CMIDForm::ConstructL() |
|
2296 |
{ |
|
2297 |
UpdateMemberVariables(); |
|
2298 |
||
2299 |
SetContainerWindowL(iDisplayable); |
|
2300 |
||
2301 |
iPopupController = CMIDPopupNoteController::NewL(); |
|
2302 |
||
2303 |
// Scroll initialisations |
|
2304 |
#ifdef RD_SCALABLE_UI_V2 |
|
2305 |
iSBFrame = new(ELeave) CEikScrollBarFrame(this, this, ETrue); |
|
2306 |
Window().SetPointerGrab(ETrue); |
|
2307 |
#else |
|
2308 |
iSBFrame = new(ELeave) CEikScrollBarFrame(this, NULL, ETrue); |
|
2309 |
#endif //RD_SCALABLE_UI_V2 |
|
2310 |
||
2311 |
iSBFrame->SetScrollBarVisibilityL( |
|
2312 |
CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
2313 |
iSBFrame->CreateDoubleSpanScrollBarsL(ETrue, EFalse); |
|
2314 |
||
2315 |
// Background initialisation |
|
2316 |
iBackgroundControlContext = CAknsListBoxBackgroundControlContext::NewL( |
|
2317 |
KAknsIIDQsnBgAreaMainListGene, Rect(), ETrue, |
|
2318 |
KAknsIIDQsnBgColumnAB, Rect()) ; // Rect parameters are only place-holders |
|
2319 |
||
2320 |
// Background for highlighted item, frame rects are set later |
|
2321 |
iHighlightedBackgroundCc = CAknsFrameBackgroundControlContext::NewL( |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
2322 |
#ifdef RD_JAVA_S60_RELEASE_9_2 |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
2323 |
KAknsIIDQsnFrPopupPreview, |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
2324 |
#else |
66 | 2325 |
KAknsIIDQsnFrInput, |
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
2326 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
66 | 2327 |
TRect(), TRect(), ETrue); |
2328 |
||
2329 |
iDisplayable.SetComponentL(*this); |
|
2330 |
||
2331 |
// get the layout from shared data so we can tell what our |
|
2332 |
// initial alignment should be |
|
2333 |
TInt layoutId = 0; |
|
2334 |
||
2335 |
CRepository* repository = CRepository::NewL(KCRUidAvkon); |
|
2336 |
repository->Get(KAknLayoutId, layoutId); |
|
2337 |
delete repository; |
|
2338 |
||
2339 |
if (layoutId == EAknLayoutIdABRW) |
|
2340 |
{ |
|
2341 |
iInitialAlignment = MMIDItem::ERight; |
|
2342 |
} |
|
2343 |
||
2344 |
iLayoutTimer = CTimeOutTimer::NewL(CActive::EPriorityIdle, *this); |
|
2345 |
iNoDataText = iEikonEnv->AllocReadResourceL(R_AVKON_NO_DATA); |
|
2346 |
||
2347 |
#ifdef RD_TACTILE_FEEDBACK |
|
2348 |
iFeedback = MTouchFeedback::Instance(); |
|
2349 |
#ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
2350 |
UpdateTactileFeedbackDensity(); |
|
2351 |
#endif // RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
2352 |
#endif // RD_TACTILE_FEEDBACK |
|
2353 |
||
2354 |
//index of pointed control is set to not active |
|
2355 |
iIndexPointedControl=-1; |
|
2356 |
||
2357 |
if (CMIDFormPhysics::FeatureEnabled()) |
|
2358 |
{ |
|
2359 |
iPhysics = CMIDFormPhysics::NewL(*this); |
|
2360 |
||
2361 |
// Destroy iPhysics immediately if physics is not allowed. |
|
2362 |
// This should happen in error situation only, when implementation |
|
2363 |
// dll couldn't be loaded although the feature was enabled. |
|
2364 |
if (iPhysics && !iPhysics->PhysicsAllowed()) |
|
2365 |
{ |
|
2366 |
delete iPhysics; |
|
2367 |
iPhysics = NULL; |
|
2368 |
} |
|
2369 |
else |
|
2370 |
{ |
|
2371 |
iHighlightTimer = CPeriodic::NewL(CActive::EPriorityStandard); |
|
2372 |
} |
|
2373 |
} |
|
2374 |
||
2375 |
LayoutAndDrawL(); |
|
2376 |
} |
|
2377 |
||
2378 |
void CMIDForm::UpdateMemberVariables() |
|
2379 |
{ |
|
2380 |
TAknLayoutRect mainMidpPane; |
|
2381 |
||
2382 |
#ifdef RD_JAVA_S60_RELEASE_9_2 |
|
2383 |
TRect mainPaneRect; |
|
2384 |
AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect); |
|
2385 |
mainMidpPane.LayoutRect(mainPaneRect, |
|
2386 |
AknLayoutScalable_Avkon::main_midp_pane().LayoutLine()); |
|
2387 |
#else |
|
2388 |
mainMidpPane.LayoutRect(iEikonEnv->ScreenDevice()->SizeInPixels(), |
|
2389 |
AknLayoutScalable_Avkon::main_midp_pane().LayoutLine()); |
|
2390 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
|
2391 |
||
2392 |
TInt variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0; |
|
2393 |
iMidpFormRect.LayoutRect(mainMidpPane.Rect(), |
|
2394 |
AknLayoutScalable_Avkon::midp_form_pane(variety).LayoutLine()); |
|
2395 |
||
2396 |
TAknLayoutRect listForm2MidpPane; |
|
2397 |
listForm2MidpPane.LayoutRect(iMidpFormRect.Rect(), |
|
2398 |
AknLayoutScalable_Avkon::list_form2_midp_pane().LayoutLine()); |
|
2399 |
||
2400 |
iFormRect.LayoutRect(listForm2MidpPane.Rect(), |
|
2401 |
AknLayoutScalable_Avkon::form2_midp_field_pane().LayoutLine()); |
|
2402 |
||
2403 |
iInnerWidth = iFormRect.Rect().Width(); |
|
2404 |
||
2405 |
iInnerHeight = iFormRect.Rect().Height(); |
|
2406 |
iFormHeight = iMidpFormRect.Rect().Height(); |
|
2407 |
} |
|
2408 |
||
2409 |
MMIDItem* CMIDForm::CurrentItem() const |
|
2410 |
{ |
|
2411 |
return iFocused == KErrNotFound ? NULL : iItems[iFocused]; |
|
2412 |
} |
|
2413 |
||
2414 |
CMIDItem& CMIDForm::Item(TInt aIndex) const |
|
2415 |
{ |
|
2416 |
MMIDItem* item = iItems[aIndex]; |
|
2417 |
return ControlItem(item->Type()); |
|
2418 |
} |
|
2419 |
||
2420 |
CMIDControlItem& CMIDForm::ControlItem(TInt aIndex) const |
|
2421 |
{ |
|
2422 |
return ControlItem(iItems[aIndex]); |
|
2423 |
} |
|
2424 |
||
2425 |
CMIDControlItem& CMIDForm::ControlItem(MMIDItem* aMMidItem) |
|
2426 |
{ |
|
2427 |
CMIDControlItem* base = NULL; |
|
2428 |
TInt type = (TInt) aMMidItem->Type(); |
|
2429 |
switch (type) |
|
2430 |
{ |
|
2431 |
case MMIDComponent::EImageItem: |
|
2432 |
base = static_cast<CMIDImageItem*>(aMMidItem); |
|
2433 |
break; |
|
2434 |
case MMIDComponent::EStringItem: |
|
2435 |
base = static_cast<CMIDStringItem*>(aMMidItem); |
|
2436 |
break; |
|
2437 |
case MMIDComponent::ESpacer: |
|
2438 |
base = static_cast<CMIDSpacer*>(aMMidItem); |
|
2439 |
break; |
|
2440 |
case MMIDComponent::EGauge: |
|
2441 |
base = static_cast<CMIDGaugeItem*>(aMMidItem); |
|
2442 |
break; |
|
2443 |
case MMIDComponent::ETextField: |
|
2444 |
base = static_cast<CMIDTextFieldItem*>(aMMidItem); |
|
2445 |
break; |
|
2446 |
case MMIDComponent::EChoiceGroup: |
|
2447 |
base = static_cast<CMIDChoiceGroupItem*>(aMMidItem); |
|
2448 |
break; |
|
2449 |
case MMIDComponent::EDateField: |
|
2450 |
base = static_cast<CMIDDateFieldItem*>(aMMidItem); |
|
2451 |
break; |
|
2452 |
case MMIDComponent::ECustomItem: |
|
2453 |
base = static_cast<CMIDCustomItem*>(aMMidItem); |
|
2454 |
break; |
|
2455 |
default: |
|
2456 |
ASSERT(EFalse); |
|
2457 |
break; |
|
2458 |
} |
|
2459 |
||
2460 |
return *base; |
|
2461 |
} |
|
2462 |
||
2463 |
TInt CMIDForm::Index(CCoeControl* aControl) const |
|
2464 |
{ |
|
2465 |
TInt itemCount = iItems.Count(); |
|
2466 |
for (TInt i=0; i < itemCount; i++) |
|
2467 |
{ |
|
2468 |
CCoeControl* control = static_cast<CCoeControl*>(&(ControlItem(i))); |
|
2469 |
if (control == aControl) |
|
2470 |
{ |
|
2471 |
return i; |
|
2472 |
} |
|
2473 |
} |
|
2474 |
return KErrNotFound; |
|
2475 |
} |
|
2476 |
||
2477 |
TInt CMIDForm::FormWidth() |
|
2478 |
{ |
|
2479 |
return CMIDForm::StaticFormRect().Width(); |
|
2480 |
} |
|
2481 |
||
2482 |
/*static*/ TRect CMIDForm::StaticFormRect() |
|
2483 |
{ |
|
2484 |
TInt variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0; |
|
2485 |
TRect mainPaneRect; |
|
2486 |
||
2487 |
#ifdef RD_JAVA_S60_RELEASE_9_2 |
|
2488 |
AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect); |
|
2489 |
#else |
|
2490 |
mainPaneRect = iAvkonAppUi->ApplicationRect(); |
|
2491 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
|
2492 |
||
2493 |
TAknLayoutRect mainMidpPane; |
|
2494 |
mainMidpPane.LayoutRect(mainPaneRect, |
|
2495 |
AknLayoutScalable_Avkon::main_midp_pane().LayoutLine()); |
|
2496 |
||
2497 |
TAknLayoutRect midpFormRect; |
|
2498 |
midpFormRect.LayoutRect(mainMidpPane.Rect(), |
|
2499 |
AknLayoutScalable_Avkon::midp_form_pane(variety).LayoutLine()); |
|
2500 |
||
2501 |
TAknLayoutRect listForm2MidpPane; |
|
2502 |
listForm2MidpPane.LayoutRect(midpFormRect.Rect(), |
|
2503 |
AknLayoutScalable_Avkon::list_form2_midp_pane().LayoutLine()); |
|
2504 |
||
2505 |
TAknLayoutRect formRect; |
|
2506 |
formRect.LayoutRect(listForm2MidpPane.Rect(), |
|
2507 |
AknLayoutScalable_Avkon::form2_midp_field_pane().LayoutLine()); |
|
2508 |
||
2509 |
return formRect.Rect(); |
|
2510 |
} |
|
2511 |
||
2512 |
||
2513 |
TBool CMIDForm::IsCurrentItem(CMIDItem* aItem) const |
|
2514 |
{ |
|
2515 |
return (iFocused != KErrNotFound) && |
|
2516 |
(iFocused == Index(static_cast<CCoeControl*>(aItem))); |
|
2517 |
} |
|
2518 |
||
2519 |
||
2520 |
void CMIDForm::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType) |
|
2521 |
{ |
|
2522 |
switch (aEventType) |
|
2523 |
{ |
|
2524 |
case MCoeControlObserver::EEventStateChanged: |
|
2525 |
{ |
|
2526 |
TInt index = KErrNotFound; |
|
2527 |
User::LeaveIfError(index = Index(aControl)); |
|
2528 |
MMIDComponent::TType type = iItems[index]->Type(); |
|
2529 |
if (type == EStringItem || type == EImageItem || type == ECustomItem) |
|
2530 |
{ |
|
2531 |
// These don't change state in the MIDP sense, so it must be a button |
|
2532 |
// press so we need to post a default command event, if there is one |
|
2533 |
||
2534 |
// msk: this is needed if msk is not enabled |
|
2535 |
PostDefaultItemCommandEvent(index); |
|
2536 |
} |
|
2537 |
else |
|
2538 |
{ |
|
2539 |
iEnv->PostJavaEvent(*this,EDisplayable,index); |
|
2540 |
} |
|
2541 |
} |
|
2542 |
break; |
|
2543 |
case MCoeControlObserver::EEventRequestFocus: |
|
2544 |
if (!aControl->IsNonFocusing()) |
|
2545 |
{ |
|
2546 |
SetFocusedItem(Index(aControl)); |
|
2547 |
} |
|
2548 |
break; |
|
2549 |
default: |
|
2550 |
break; |
|
2551 |
} |
|
2552 |
} |
|
2553 |
||
2554 |
||
2555 |
/* |
|
2556 |
* Pointer events from different Items are are routed via this function to private HandleControlEventL. |
|
2557 |
* Focus is not accepted if Item is not focusable. |
|
2558 |
*/ |
|
2559 |
void CMIDForm::HandleTouchControlEventL(CCoeControl* aControl,TCoeEvent aEventType) |
|
2560 |
{ |
|
2561 |
||
2562 |
CMIDControlItem& ci = ControlItem(Index(aControl)); |
|
2563 |
if (ci.IsSelectable()) |
|
2564 |
{ |
|
2565 |
HandleControlEventL(aControl, aEventType); |
|
2566 |
} |
|
2567 |
} |
|
2568 |
||
2569 |
||
2570 |
void CMIDForm::TimerExpired() |
|
2571 |
{ |
|
2572 |
TrappedLayoutAndDraw(); |
|
2573 |
} |
|
2574 |
||
2575 |
/* |
|
2576 |
* Called whenever something's happened which could change the visibility of an item |
|
2577 |
* controls. e.g. when made current, when update Items, when scroll. |
|
2578 |
*/ |
|
2579 |
void CMIDForm::HandleItemVisibilityChange() |
|
2580 |
{ |
|
2581 |
||
2582 |
// CUSTOM ITEM ONLY |
|
2583 |
TInt count = iItems.Count(); |
|
2584 |
for (TInt i=0; i<count; i++) |
|
2585 |
{ |
|
2586 |
if (iItems[i]->Type() == MMIDComponent::ECustomItem) |
|
2587 |
{ |
|
2588 |
// this will get the CustomItem's FocusChanged method called which will cause |
|
2589 |
// some visibility events to be sent |
|
2590 |
CMIDControlItem& ci = ControlItem(i); |
|
2591 |
((CMIDCustomItem&) ci).HandleVisibilityChange(); |
|
2592 |
} |
|
2593 |
} |
|
2594 |
// END CUSTOM ITEM |
|
2595 |
||
2596 |
} |
|
2597 |
||
2598 |
/** Handles an item size change event. This is called by within the plugin, not by java |
|
2599 |
side unlike RefreshItemL(TInt). |
|
2600 |
||
2601 |
First of all we check if there is a layout pending operation. |
|
2602 |
If there is one we don't do anything. This is because this method is called during |
|
2603 |
control creation when items are inserted in the form. However, it is also called later |
|
2604 |
on when the control is already displaying and its size changes. During control creation |
|
2605 |
we should do a delayed layout (for performance reasons) wheras if we delay layout in the |
|
2606 |
second case we get an unpleasant redraw effect because the item control usually draws |
|
2607 |
immediately. So we should try and layout+draw immediately in the second case. |
|
2608 |
We distinguish between the two cases by checking if there is a layout |
|
2609 |
operation (which is requested by InsertItemL()). Also, in the second case, instead of |
|
2610 |
doing a full LayoutAndDrawL() we only resize elements already assigned to rows and |
|
2611 |
update the scroll bars. And then we draw. This is a bit more efficient than recreating |
|
2612 |
the rows. Because this method is only called by items that fill an entire row anyway, |
|
2613 |
we shouln't need to re-create rows. |
|
2614 |
*/ |
|
2615 |
void CMIDForm::RefreshItemL(MMIDItem* aItem) |
|
2616 |
{ |
|
2617 |
TInt index = iItems.Find(aItem); |
|
2618 |
||
2619 |
if (!LayoutPending() && index != KErrNotFound) |
|
2620 |
{ |
|
2621 |
SizeItemsInFormRowsL(); |
|
2622 |
SetRowExtentsWithRespectToScrolledLocation(); |
|
2623 |
||
2624 |
if ((aItem->Type() == MMIDComponent::ETextField) && (index == iFocused)) |
|
2625 |
{ |
|
2626 |
CMIDTextFieldItem* tf = static_cast<CMIDTextFieldItem*>(aItem); |
|
2627 |
TPoint p; |
|
2628 |
TBool success = tf->GetCursorPosL(p); |
|
2629 |
if (success) |
|
2630 |
{ |
|
2631 |
if (p.iY < 0) |
|
2632 |
{ |
|
2633 |
RawScrollRelative(p.iY + 10); |
|
2634 |
} |
|
2635 |
else if (p.iY > Height()) |
|
2636 |
{ |
|
2637 |
RawScrollRelative(Height() - (p.iY + 10)); |
|
2638 |
} |
|
2639 |
} |
|
2640 |
} |
|
2641 |
RawScrollFinalize(ETrue); |
|
2642 |
} |
|
2643 |
} |
|
2644 |
||
2645 |
/** |
|
2646 |
* If the item at aIndex has a default command set for it, then this will be invoked and True |
|
2647 |
* will be returned. False if a command has not been posted |
|
2648 |
*/ |
|
2649 |
// msk: this method is needed if msk is not enabled |
|
2650 |
TBool CMIDForm::PostDefaultItemCommandEvent(TInt aIndex) |
|
2651 |
{ |
|
2652 |
if (aIndex != KErrNotFound) |
|
2653 |
{ |
|
2654 |
CMIDCommand* defaultCommand = ControlItem(iItems[aIndex]).DefaultCommand(); |
|
2655 |
if (defaultCommand) |
|
2656 |
{ |
|
2657 |
iEnv->PostJavaEvent(*iItems[aIndex],EItem,ECommand,defaultCommand->Id()); |
|
2658 |
return ETrue; |
|
2659 |
} |
|
2660 |
} |
|
2661 |
return EFalse; |
|
2662 |
} |
|
2663 |
||
2664 |
void CMIDForm::AddItemToFormL(CMIDControlItem& aControlItem) |
|
2665 |
{ |
|
2666 |
aControlItem.SetForm(this); |
|
2667 |
aControlItem.SetContainerWindowL(*this); |
|
2668 |
aControlItem.ItemAddedToFormL(); |
|
2669 |
} |
|
2670 |
||
2671 |
void CMIDForm::RemoveItemFromForm(CMIDControlItem& aControlItem) |
|
2672 |
{ |
|
2673 |
aControlItem.MakeVisible(EFalse); |
|
2674 |
aControlItem.SetPosition(TPoint(-Width(), 0)); |
|
2675 |
// Item is not allowed to access container window from now. |
|
2676 |
aControlItem.ItemRemovedFromForm(); |
|
2677 |
aControlItem.SetForm(NULL); |
|
2678 |
} |
|
2679 |
||
2680 |
void CMIDForm::UpdateItemCommands(CMIDCommandList* aCommandList, CMIDCommand* aMSKCommand) |
|
2681 |
{ |
|
2682 |
iDisplayable.SetItemCommandList(aCommandList, aMSKCommand); |
|
2683 |
} |
|
2684 |
||
2685 |
// msk: this method is needed if msk is not enabled |
|
2686 |
TBool CMIDForm::DoDefaultCommand() |
|
2687 |
{ |
|
2688 |
if (iFocused != KErrNotFound) |
|
2689 |
{ |
|
2690 |
CMIDControlItem& ci = ControlItem(iFocused); |
|
2691 |
||
2692 |
CMIDCommand* defaultCommand = ci.DefaultCommand(); |
|
2693 |
if (defaultCommand) |
|
2694 |
{ |
|
2695 |
iEnv->PostJavaEvent(*(iItems[iFocused]), EItem, ECommand, defaultCommand->Id()); |
|
2696 |
return ETrue; |
|
2697 |
} |
|
2698 |
} |
|
2699 |
||
2700 |
return EFalse; |
|
2701 |
} |
|
2702 |
||
2703 |
||
2704 |
TInt CMIDForm::Row(const CMIDControlItem& aItem) const |
|
2705 |
{ |
|
2706 |
CMIDFormRow* rowPtr = NULL; |
|
2707 |
return Row(aItem, rowPtr); |
|
2708 |
} |
|
2709 |
||
2710 |
TInt CMIDForm::Row(const CMIDControlItem& aItem, CMIDFormRow*& aRowPtr) const |
|
2711 |
{ |
|
2712 |
aRowPtr = NULL; |
|
2713 |
TInt rowCount = iRows.Count(); |
|
2714 |
for (TInt i=0; i < rowCount; i++) |
|
2715 |
{ |
|
2716 |
TInt idx = iRows[i]->Find(&aItem); |
|
2717 |
if (idx != KErrNotFound) |
|
2718 |
{ |
|
2719 |
aRowPtr = iRows[i]; |
|
2720 |
return i; |
|
2721 |
} |
|
2722 |
} |
|
2723 |
return KErrNotFound; |
|
2724 |
} |
|
2725 |
||
2726 |
CMIDForm::TDirection CMIDForm::ConvertKeyToDirection(TUint aCode) |
|
2727 |
{ |
|
2728 |
switch (aCode) |
|
2729 |
{ |
|
2730 |
case EKeyDownArrow: |
|
2731 |
return EDown; |
|
2732 |
case EKeyUpArrow: |
|
2733 |
return EUp; |
|
2734 |
case EKeyLeftArrow: |
|
2735 |
return ELeft; |
|
2736 |
case EKeyRightArrow: |
|
2737 |
return ERight; |
|
2738 |
default: |
|
2739 |
return ENone; |
|
2740 |
} |
|
2741 |
} |
|
2742 |
||
2743 |
// returns the index of a CMIDControlItem in the iItems array. If the |
|
2744 |
// CMIDControlItem is a CMIDLabelContainerItem, then the index |
|
2745 |
// of the stringItem associated with it is returned. |
|
2746 |
TInt CMIDForm::ItemIndex(CMIDControlItem& aItem) |
|
2747 |
{ |
|
2748 |
MMIDItem* item = aItem.iMMidItem; |
|
2749 |
||
2750 |
TInt idx = 0; |
|
2751 |
TInt itemCount = iItems.Count(); |
|
2752 |
while (idx < itemCount) |
|
2753 |
{ |
|
2754 |
if (iItems[idx] == item) |
|
2755 |
{ |
|
2756 |
return idx; |
|
2757 |
} |
|
2758 |
idx++; |
|
2759 |
} |
|
2760 |
||
2761 |
// OK, so we didn't find it. Maybe it is a CMIDLabelContainerItem |
|
2762 |
if (IsLabelContainerItem(aItem)) |
|
2763 |
{ |
|
2764 |
CMIDLabelContainerItem* usil = static_cast<CMIDLabelContainerItem*>(&aItem); |
|
2765 |
return ItemIndex(usil->StringItem()); |
|
2766 |
} |
|
2767 |
||
2768 |
return KErrNotFound; |
|
2769 |
} |
|
2770 |
||
2771 |
// this method will return the index of the row ABOVE the indicated unconstrained string item |
|
2772 |
// if the string item was on the top row then KErrNotFound is returned, also if the string item |
|
2773 |
// could not be found or was not an unconstrained string item. |
|
2774 |
TInt CMIDForm::FirstRowAboveUnconstrainedStringItem(CMIDStringItem& aStringItem) const |
|
2775 |
{ |
|
2776 |
TInt idx = FirstRowOfUnconstrainedStringItem(aStringItem); |
|
2777 |
return (idx == KErrNotFound) ? KErrNotFound : idx - 1; |
|
2778 |
} |
|
2779 |
||
2780 |
// returns the index of the first row of an unconstrained string item. |
|
2781 |
// Returns KErrNotFound if the string item could not be found (or if it was not |
|
2782 |
// an unconstrained string item). |
|
2783 |
TInt CMIDForm::FirstRowOfUnconstrainedStringItem(CMIDStringItem& aStringItem) const |
|
2784 |
{ |
|
2785 |
TInt idx = -1; |
|
2786 |
TInt rowCount = iRows.Count(); |
|
2787 |
while (++idx < rowCount) |
|
2788 |
{ |
|
2789 |
CMIDFormRow* row = iRows[idx]; |
|
2790 |
TInt innerIdx = -1; |
|
2791 |
while (++innerIdx < row->NumItems()) |
|
2792 |
{ |
|
2793 |
CMIDControlItem* ci = row->Item(innerIdx); |
|
2794 |
if (IsLabelContainerItem(*ci)) |
|
2795 |
{ |
|
2796 |
CMIDLabelContainerItem* ucsi = static_cast<CMIDLabelContainerItem*>(ci); |
|
2797 |
if (&(ucsi->StringItem()) == &aStringItem) |
|
2798 |
{ |
|
2799 |
return idx; |
|
2800 |
} |
|
2801 |
} |
|
2802 |
} |
|
2803 |
} |
|
2804 |
return KErrNotFound; |
|
2805 |
} |
|
2806 |
||
2807 |
TInt CMIDForm::FirstRowBelowUnconstrainedStringItem(CMIDStringItem& aStringItem) const |
|
2808 |
{ |
|
2809 |
TInt idx = iRows.Count(); |
|
2810 |
TInt rowCount = iRows.Count(); |
|
2811 |
while (--idx < rowCount) |
|
2812 |
{ |
|
2813 |
CMIDFormRow* row = iRows[idx]; |
|
2814 |
TInt innerIdx = -1; |
|
2815 |
while (++innerIdx < row->NumItems()) |
|
2816 |
{ |
|
2817 |
CMIDControlItem* ci = row->Item(innerIdx); |
|
2818 |
if (IsLabelContainerItem(*ci)) |
|
2819 |
{ |
|
2820 |
CMIDLabelContainerItem* ucsi = static_cast<CMIDLabelContainerItem*>(ci); |
|
2821 |
if (&(ucsi->StringItem()) == &aStringItem) |
|
2822 |
{ |
|
2823 |
return ((idx + 1) >= rowCount) ? KErrNotFound : idx + 1; |
|
2824 |
} |
|
2825 |
} |
|
2826 |
} |
|
2827 |
} |
|
2828 |
return KErrNotFound; |
|
2829 |
} |
|
2830 |
||
2831 |
TInt CMIDForm::FirstFocusableItemBeforeStartOfUnconstrainedStringItemIdx(CMIDStringItem& aStringItem) |
|
2832 |
{ |
|
2833 |
TInt rowIdx = FirstRowOfUnconstrainedStringItem(aStringItem); |
|
2834 |
if (rowIdx != KErrNotFound) |
|
2835 |
{ |
|
2836 |
CMIDFormRow* row = iRows[rowIdx]; |
|
2837 |
TInt idxOnRow = row->NumItems(); |
|
2838 |
while (--idxOnRow >= 0) // search backward along the row for the unconstrained string item |
|
2839 |
// we probably could assume it is the last element |
|
2840 |
{ |
|
2841 |
CMIDControlItem* ci = row->Item(idxOnRow); |
|
2842 |
if (IsLabelContainerItem(*ci)) |
|
2843 |
{ |
|
2844 |
CMIDLabelContainerItem* usil = static_cast<CMIDLabelContainerItem*>(ci); |
|
2845 |
CMIDStringItem* si = &(usil->StringItem()); |
|
2846 |
if (si == &aStringItem) |
|
2847 |
{ |
|
2848 |
break; |
|
2849 |
} |
|
2850 |
} |
|
2851 |
} |
|
2852 |
if (idxOnRow > 0) |
|
2853 |
{ |
|
2854 |
// there are some items on the row before the start of the unconstrained string item |
|
2855 |
while (--idxOnRow >= 0) // search backward along the row for the first focusable item |
|
2856 |
{ |
|
2857 |
CMIDControlItem* ci = row->Item(idxOnRow); |
|
2858 |
if (ci->IsSelectable()) |
|
2859 |
{ |
|
2860 |
return ItemIndex(*ci); |
|
2861 |
} |
|
2862 |
} |
|
2863 |
} |
|
2864 |
} |
|
2865 |
return KErrNotFound; |
|
2866 |
} |
|
2867 |
||
2868 |
TInt CMIDForm::FirstFocusableItemOnLastLineOfUnconstrainedStringItemIdx(CMIDStringItem& aStringItem) |
|
2869 |
{ |
|
2870 |
TInt rowIdx = FirstRowBelowUnconstrainedStringItem(aStringItem) - 1; |
|
2871 |
||
2872 |
if (rowIdx == -2) |
|
2873 |
{ |
|
2874 |
rowIdx = iRows.Count() -1; |
|
2875 |
} |
|
2876 |
||
2877 |
if (rowIdx > KErrNotFound) // if FirstRowBelowUnconstrainedStringItem returned KErrNotFound then we have -2 so check with '>' |
|
2878 |
{ |
|
2879 |
CMIDFormRow* row = iRows[rowIdx]; |
|
2880 |
TInt idxOnRow = -1; |
|
2881 |
||
2882 |
TBool found = EFalse; |
|
2883 |
while (++idxOnRow < row->NumItems()) |
|
2884 |
{ |
|
2885 |
CMIDControlItem* ci = row->Item(idxOnRow); |
|
2886 |
||
2887 |
if (ControlBelongsToSameUnconstrainedItem(ci,aStringItem)) |
|
2888 |
{//ok we found our item, if the next one is selectable we return |
|
2889 |
found = ETrue; |
|
2890 |
} |
|
2891 |
else if (found && ci->IsSelectable()) |
|
2892 |
{ |
|
2893 |
return ItemIndex(*ci); |
|
2894 |
} |
|
2895 |
} |
|
2896 |
} |
|
2897 |
return KErrNotFound; |
|
2898 |
} |
|
2899 |
||
2900 |
/** Return true if aCi belongs to the same unconstrained string item (aStringItem) */ |
|
2901 |
TBool CMIDForm::ControlBelongsToSameUnconstrainedItem(CMIDControlItem* aCi, CMIDStringItem& aStringItem) const |
|
2902 |
{ |
|
2903 |
if (IsLabelContainerItem(*aCi)) |
|
2904 |
{ |
|
2905 |
CMIDLabelContainerItem* usil = static_cast<CMIDLabelContainerItem*>(aCi); |
|
2906 |
if (&(usil->StringItem()) == &aStringItem) |
|
2907 |
{ |
|
2908 |
return ETrue; |
|
2909 |
} |
|
2910 |
} |
|
2911 |
||
2912 |
return EFalse; |
|
2913 |
} |
|
2914 |
||
2915 |
/** */ |
|
2916 |
void CMIDForm::RemoveDeletedItem(CMIDControlItem& aItem) |
|
2917 |
{ |
|
2918 |
iFocused = KErrNotFound; |
|
2919 |
TInt i=-1; |
|
2920 |
TInt rowCount = iRows.Count(); |
|
2921 |
while (++i < rowCount) |
|
2922 |
{ |
|
2923 |
CMIDFormRow* row = iRows[i]; |
|
2924 |
if (row->RemoveItemIfExists(aItem)) |
|
2925 |
{ |
|
2926 |
break; |
|
2927 |
} |
|
2928 |
} |
|
2929 |
||
2930 |
i = -1; |
|
2931 |
TInt itemCount = iItems.Count(); |
|
2932 |
while (++i < itemCount) |
|
2933 |
{ |
|
2934 |
if (aItem.iMMidItem) |
|
2935 |
{ |
|
2936 |
if (aItem.iMMidItem == iItems[i]) |
|
2937 |
{ |
|
2938 |
iItems.Remove(i); |
|
2939 |
break; |
|
2940 |
} |
|
2941 |
} |
|
2942 |
} |
|
2943 |
||
2944 |
} |
|
2945 |
||
2946 |
||
2947 |
///////////////////////////////////////////////////////////////////////////////////////// |
|
2948 |
// new layout methods |
|
2949 |
///////////////////////////////////////////////////////////////////////////////////////// |
|
2950 |
||
2951 |
// does the layout for the entire form |
|
2952 |
void CMIDForm::LayoutFormL() |
|
2953 |
{ |
|
2954 |
DEBUG("CMIDForm::LayoutFormL"); |
|
2955 |
||
2956 |
if (LayoutPending()) |
|
2957 |
{ |
|
2958 |
iLayoutRequestTime = -1; |
|
2959 |
iLayoutTimer->Cancel(); |
|
2960 |
} |
|
2961 |
||
2962 |
TReal prevHeight = HeightOfAllItems() - Height(); |
|
2963 |
TInt prevFocusedYPos = 0; // by default it is on top of screen |
|
2964 |
TInt focusedItem = iFocused; |
|
2965 |
||
2966 |
if (focusedItem != KErrNotFound) |
|
2967 |
{ |
|
2968 |
TRect rect = GetControlRect(focusedItem); |
|
2969 |
prevFocusedYPos = rect.iTl.iY; |
|
2970 |
} |
|
2971 |
||
2972 |
||
2973 |
// scroll bar layouting |
|
2974 |
AknLayoutUtils::LayoutVerticalScrollBar(iSBFrame, Rect(), |
|
2975 |
AknLayoutScalable_Avkon::scroll_pane_cp51().LayoutLine()); |
|
2976 |
ResetItemsPreferredSizes(); |
|
2977 |
||
2978 |
// this prevents items from calling layout recursively |
|
2979 |
SetItemsFormPointersToVal(NULL); |
|
2980 |
||
2981 |
AssignItemsToRowsL(); |
|
2982 |
SizeItemsInFormRowsL(); |
|
2983 |
||
2984 |
SetItemsFormPointersToVal(this); |
|
2985 |
||
2986 |
SetRowExtentsWithRespectToScrolledLocation(); |
|
2987 |
||
2988 |
TReal newHeight = HeightOfAllItems() - Height(); |
|
2989 |
||
2990 |
if (newHeight != prevHeight) |
|
2991 |
{ |
|
2992 |
// layout has changed significantly, but we need to keep focused component scrolled so that |
|
2993 |
// user sees it at the same level in viewport |
|
2994 |
TInt newFocusedYPos = 0; |
|
2995 |
if (focusedItem != KErrNotFound) |
|
2996 |
{ |
|
2997 |
TRect rect = GetControlRect(focusedItem); |
|
2998 |
newFocusedYPos = rect.iTl.iY; |
|
2999 |
TInt delta = prevFocusedYPos - newFocusedYPos; |
|
3000 |
if (iScroll != 0) |
|
3001 |
{ |
|
3002 |
// correct only if not on top of window |
|
3003 |
ScrollRelative(delta); |
|
3004 |
} |
|
3005 |
} |
|
3006 |
else |
|
3007 |
{ |
|
3008 |
if (newHeight < prevHeight) |
|
3009 |
{ |
|
3010 |
// no focused item, just try to keep same component visible |
|
3011 |
iScroll = newHeight > 0 ? ((TReal) iScroll * (newHeight / prevHeight)) : 0; |
|
3012 |
} |
|
3013 |
} |
|
3014 |
||
3015 |
SetRowExtentsWithRespectToScrolledLocation(); |
|
3016 |
} |
|
3017 |
} |
|
3018 |
||
3019 |
void CMIDForm::ResetItemsPreferredSizes() |
|
3020 |
{ |
|
3021 |
TInt itemCount = iItems.Count(); |
|
3022 |
for (TInt i=0; i < itemCount; i++) |
|
3023 |
{ |
|
3024 |
CMIDControlItem& ci = ControlItem(i); |
|
3025 |
ci.ResetPreferredSize(); |
|
3026 |
} |
|
3027 |
} |
|
3028 |
||
3029 |
void CMIDForm::SetItemsFormPointersToVal(CMIDForm* aVal) |
|
3030 |
{ |
|
3031 |
TInt itemCount = iItems.Count(); |
|
3032 |
for (TInt i=0; i < itemCount; i++) |
|
3033 |
{ |
|
3034 |
CMIDControlItem& ci = ControlItem(i); |
|
3035 |
ci.SetForm(aVal); |
|
3036 |
} |
|
3037 |
} |
|
3038 |
||
3039 |
/** If an items preferred size is zero |
|
3040 |
we shouldn't add it to the form row and so we skip it */ |
|
3041 |
TBool CMIDForm::SkipNullItem(TInt aIndex) |
|
3042 |
{ |
|
3043 |
CMIDControlItem& ci = ControlItem(iItems[aIndex]); |
|
3044 |
if (ci.PreferredSize() == TSize(0, 0)) |
|
3045 |
{ |
|
3046 |
if (iFocused == aIndex) |
|
3047 |
{ |
|
3048 |
SetFocusedItem(KErrNotFound); |
|
3049 |
} |
|
3050 |
||
3051 |
return ETrue; |
|
3052 |
} |
|
3053 |
||
3054 |
return EFalse; |
|
3055 |
} |
|
3056 |
||
3057 |
/** |
|
3058 |
If the current row index is the same as the row count, |
|
3059 |
create and append to iRows a new row and store it into |
|
3060 |
iCurrentRow. Increment the current row index. Also reset |
|
3061 |
the current alignment. |
|
3062 |
*/ |
|
3063 |
void CMIDForm::CreateNewRowAndSetAsCurrentL() |
|
3064 |
{ |
|
3065 |
CMIDFormRow* row = CMIDFormRow::NewL(*this); |
|
3066 |
CleanupStack::PushL(row); |
|
3067 |
||
3068 |
User::LeaveIfError(iRows.Append(row)); |
|
3069 |
CleanupStack::Pop(row); |
|
3070 |
||
3071 |
iCurrentRow = row; |
|
3072 |
iCurrentRow->SetAlignment(iCurrentAlignment); |
|
3073 |
} |
|
3074 |
||
3075 |
/** Verify the current alignment and change it if the current row |
|
3076 |
is empty. If the row is not empty and the item alignement is different |
|
3077 |
and the item requires a row break, then add a new row. */ |
|
3078 |
void CMIDForm::VerifyRowAlignmentL(TInt aIndex) |
|
3079 |
{ |
|
3080 |
TInt leftRightMask = MMIDItem::ELeft | MMIDItem::ERight; |
|
3081 |
CMIDControlItem& ci = ControlItem(iItems[aIndex]); |
|
3082 |
||
3083 |
if (iCurrentRow->NumItems() == 0) |
|
3084 |
{ |
|
3085 |
// this is the first item in the row |
|
3086 |
if (!LayoutDefault(ci)) |
|
3087 |
{ |
|
3088 |
// we take the items alignment for the row |
|
3089 |
iCurrentAlignment = MMIDItem::TLayout(ci.Layout() & leftRightMask); |
|
3090 |
iCurrentRow->SetAlignment(iCurrentAlignment); |
|
3091 |
} |
|
3092 |
} |
|
3093 |
else if (!LayoutMatchesCurrentAlignment(ci, iCurrentAlignment)) |
|
3094 |
{ |
|
3095 |
// the new layout doesn't match the current so go to the next row |
|
3096 |
CreateNewRowAndSetAsCurrentL(); |
|
3097 |
iCurrentAlignment = MMIDItem::TLayout(ci.Layout() & leftRightMask); |
|
3098 |
iCurrentRow->SetAlignment(iCurrentAlignment); |
|
3099 |
} |
|
3100 |
} |
|
3101 |
||
3102 |
/** |
|
3103 |
Inserts the specified number of new rows (aNumNewLines). If there is a control |
|
3104 |
item passed as a parameter it means the lines to be inserted are empty lines |
|
3105 |
preceeding the control and therefore should have their empty size set to the |
|
3106 |
size of the control. |
|
3107 |
||
3108 |
@param aControlItem The control item used to set the size of empty rows. |
|
3109 |
||
3110 |
@param aNumNewLines The number of rows to be added, if equal to zero this method does |
|
3111 |
nothing |
|
3112 |
*/ |
|
3113 |
void CMIDForm::InsertNewlinesL(TInt aNumNewlines, CMIDControlItem* aControlItem) |
|
3114 |
{ |
|
3115 |
for (TInt idx = 0; idx < aNumNewlines; idx++) |
|
3116 |
{ |
|
3117 |
if (aControlItem && aControlItem->LabelControl() && iCurrentRow && iCurrentRow->NumItems() == 0) |
|
3118 |
{ |
|
3119 |
iCurrentRow->SetEmptyRowSize(TSize(iInnerWidth,aControlItem->OneLineLabelHeight())); |
|
3120 |
} |
|
3121 |
||
3122 |
CreateNewRowAndSetAsCurrentL(); |
|
3123 |
} |
|
3124 |
} |
|
3125 |
||
3126 |
||
3127 |
/** |
|
3128 |
* Creates a new string item, using special type CMIDLabelContainerItem. |
|
3129 |
* This is a special string item which has no label and is added to wrap |
|
3130 |
* content of a previous string item across several rows. |
|
3131 |
* |
|
3132 |
* @see CMIDLabelContainerItem |
|
3133 |
*/ |
|
3134 |
void CMIDForm::CreateAndAddLabelContainerItemL(CMIDStringItem& aStringItem, |
|
3135 |
CEikLabel& aLabel, TBool aIsStringItemContent) |
|
3136 |
{ |
|
3137 |
// Label container items items have an horizontal margin only |
|
3138 |
// when at the beginning of the row |
|
3139 |
TBool hasHMargin = (iCurrentRow->NumItems() == 0); |
|
3140 |
||
3141 |
CMIDLabelContainerItem* usil = |
|
3142 |
CMIDLabelContainerItem::NewL(aStringItem, aLabel, hasHMargin); |
|
3143 |
||
3144 |
CleanupStack::PushL(usil); |
|
3145 |
usil->SetContainerWindowL(*this); |
|
3146 |
// sets flag for detecting if label container item is created |
|
3147 |
// from string item label or content |
|
3148 |
usil->SetIsStringItemContent(aIsStringItemContent); |
|
3149 |
||
3150 |
iCurrentRow->AppendL(usil); |
|
3151 |
CleanupStack::Pop(usil); |
|
3152 |
} |
|
3153 |
||
3154 |
/** |
|
3155 |
* Inserts a CMIDLabelContainerItem for each line in aTextControl. |
|
3156 |
* |
|
3157 |
* @see CreateAndAddLabelContainerItemL() |
|
3158 |
*/ |
|
3159 |
void CMIDForm::InsertContainerItemsL(CMIDStringItem& aStringItem, |
|
3160 |
CMIDItemLabel& aTextControl, TBool aIsStringItemContent) |
|
3161 |
{ |
|
3162 |
TInt numLines = aTextControl.NumLines(); |
|
3163 |
for (TInt j = 0; j < numLines; j++) |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
3164 |
{ // insert every line as a CMIDLabelContainerItem |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
3165 |
CreateAndAddLabelContainerItemL( |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
3166 |
aStringItem, *(aTextControl.LabelAtIdx(j)), aIsStringItemContent); |
66 | 3167 |
|
3168 |
if (j != (numLines-1)) |
|
3169 |
{ // insert a row break except for the last line |
|
3170 |
CreateNewRowAndSetAsCurrentL(); |
|
3171 |
} |
|
3172 |
} |
|
3173 |
} |
|
3174 |
||
3175 |
/** |
|
3176 |
Adds an unconstrained string item to one or more rows. If the item |
|
3177 |
has a label always insert a line break (new row) before and if it |
|
3178 |
is followed by constrained item also after the label. Crop the label |
|
3179 |
to the full line width and insert is as a CMIDLabelContainerItem. |
|
3180 |
||
3181 |
If the item has no label we can start anywhere in the current row. |
|
3182 |
Split its content across the remaining width for the first line |
|
3183 |
and then across the full line width. Insert a CMIDLabelContainerItem |
|
3184 |
for each line and insert a row break after each CMIDLabelContainerItem |
|
3185 |
except the last one. |
|
3186 |
||
3187 |
Item with label can be inserted as default item when one of this |
|
3188 |
situation occurs: |
|
3189 |
- it is the last item in form |
|
3190 |
- following item is constrained |
|
3191 |
- following item is unconstrained but has a label |
|
3192 |
||
3193 |
Item without label can be inserted as default item when: |
|
3194 |
- it is the only item in form |
|
3195 |
- it is the first item in form and following item is |
|
3196 |
unconstrained but has a label (it starts in a new row) |
|
3197 |
||
3198 |
@see CMILabelContainerItem, InsertContainerItemsL(), |
|
3199 |
CreateNewRowAndSetAsCurrentL(), InsertNewlinesL() |
|
3200 |
*/ |
|
3201 |
void CMIDForm::AddUnconstrainedStringItemL(TInt& aIndex) |
|
3202 |
{ |
|
3203 |
CMIDStringItem* si = (CMIDStringItem*)iItems[aIndex]; |
|
3204 |
||
3205 |
TInt widthForText = Width(); |
|
3206 |
||
3207 |
// check if next item is unconstrained and has label |
|
3208 |
TBool nextUnconstrainedHasLabel(EFalse); |
|
3209 |
if (aIndex < iItems.Count()-1 && ItemIsUnconstrained(aIndex + 1)) |
|
3210 |
{ |
|
3211 |
CMIDStringItem* nextItem = (CMIDStringItem*)iItems[aIndex+1]; |
|
3212 |
if (nextItem->LabelControl() && |
|
3213 |
(nextItem->LabelControl()->Text()->Length() > 0)) |
|
3214 |
{ |
|
3215 |
nextUnconstrainedHasLabel = ETrue; |
|
3216 |
} |
|
3217 |
} |
|
3218 |
||
3219 |
if (si->LabelControl() && (si->LabelControl()->Text()->Length() > 0)) |
|
3220 |
{//item has a label - it should be placed in a new row |
|
3221 |
if (iCurrentRow->NumItems() > 0) |
|
3222 |
{ |
|
3223 |
CreateNewRowAndSetAsCurrentL(); |
|
3224 |
} |
|
3225 |
||
3226 |
// If the item is last or next item is constrained or next item |
|
3227 |
// is unconstrained but has a label (it will be placed in a new row) |
|
3228 |
// this item is placed as default item. |
|
3229 |
if ((aIndex == iItems.Count()-1) || !ItemIsUnconstrained(aIndex + 1) |
|
3230 |
|| nextUnconstrainedHasLabel) |
|
3231 |
{ |
|
3232 |
AddDefaultItemL(aIndex); |
|
3233 |
return; |
|
3234 |
} |
|
3235 |
||
3236 |
// otherwise place the label in one row and then insert the text |
|
3237 |
si->LabelControl()->SetWidthL(widthForText); |
|
3238 |
// label of string item is inserted as label container item |
|
3239 |
// EFalse identifies that label container item is created from string item label |
|
3240 |
InsertContainerItemsL(*si, *(si->LabelControl()), EFalse); |
|
3241 |
// string items is divided to label container items due to concatenation of contents |
|
3242 |
// contained in adjacent string items |
|
3243 |
si->SetIsDivided(ETrue); |
|
3244 |
CreateNewRowAndSetAsCurrentL(); |
|
3245 |
} |
|
3246 |
else |
|
3247 |
{ // item has no label |
|
3248 |
||
3249 |
// If the item is the only item in form or it is the first item in form |
|
3250 |
// and the next item is unconstrained with label (it starts at a new row) |
|
3251 |
// this item is placed as default item |
|
3252 |
if ((iItems.Count() == 1) || (aIndex == 0 && nextUnconstrainedHasLabel)) |
|
3253 |
{ |
|
3254 |
AddDefaultItemL(aIndex); |
|
3255 |
return; |
|
3256 |
} |
|
3257 |
} |
|
3258 |
||
3259 |
// this is either the remaining width on the current row or the full |
|
3260 |
// line width if we are on a new row |
|
3261 |
TInt remainingLineWidth = widthForText - iCurrentRow->CurrentWidth(); |
|
3262 |
||
3263 |
if ((remainingLineWidth < si->StringContentControl()->FirstWordWidth()) |
|
3264 |
&& (iCurrentRow->NumItems() != 0)) |
|
3265 |
{ // if not even one word fits then go to the next line unless |
|
3266 |
// we are already on a new line |
|
3267 |
CreateNewRowAndSetAsCurrentL(); |
|
3268 |
remainingLineWidth = widthForText; |
|
3269 |
} |
|
3270 |
||
3271 |
// wrap the content to the remaining width for the first line and to |
|
3272 |
// the full width for any other line |
|
3273 |
si->StringContentControl()->SetVariableWidthL(remainingLineWidth, widthForText); |
|
3274 |
// content of string item is inserted as label container item |
|
3275 |
// ETrue identifies that label container item is created from string item content |
|
3276 |
InsertContainerItemsL(*si, *(si->StringContentControl()), ETrue); |
|
3277 |
} |
|
3278 |
||
3279 |
/** |
|
3280 |
* Adds a standard case item to the current row. It verifies if a new |
|
3281 |
* row should be added and adds one if so. Then it appends the item |
|
3282 |
* to the current row. |
|
3283 |
* |
|
3284 |
* @see CMIDControlItem, OkToMoveToNextRow() |
|
3285 |
*/ |
|
3286 |
void CMIDForm::AddDefaultItemL(TInt& aIndex) |
|
3287 |
{ |
|
3288 |
CMIDControlItem& ci = ControlItem(iItems[aIndex]); |
|
3289 |
||
3290 |
TSize itemSize = LayoutShrink(ci) ? ci.MinimumSize() : ci.PreferredSize(); |
|
3291 |
ci.SetSizeQuiet(itemSize); |
|
3292 |
||
3293 |
if (OkToMoveToNextRow(itemSize)) |
|
3294 |
{ |
|
3295 |
CreateNewRowAndSetAsCurrentL(); |
|
3296 |
} |
|
3297 |
||
3298 |
iCurrentRow->AppendL(&ci); |
|
3299 |
} |
|
3300 |
||
3301 |
/** |
|
3302 |
Return true if the given size does not fit into the current |
|
3303 |
row and the row is not empty and the size is not bigger than |
|
3304 |
an empty row. |
|
3305 |
*/ |
|
3306 |
TBool CMIDForm::OkToMoveToNextRow(const TSize& aItemSize) const |
|
3307 |
{ |
|
3308 |
return ((iCurrentRow->CurrentWidth() + aItemSize.iWidth) > iInnerWidth) && |
|
3309 |
!((aItemSize.iWidth > iInnerWidth) && (iCurrentRow->NumItems() == 0)); |
|
3310 |
} |
|
3311 |
||
3312 |
/** |
|
3313 |
Assigns the items to the rows, which are re-created. |
|
3314 |
*/ |
|
3315 |
void CMIDForm::AssignItemsToRowsL() |
|
3316 |
{ |
|
3317 |
DeleteRows(); |
|
3318 |
||
3319 |
//reset current alignment |
|
3320 |
iCurrentAlignment = InitialAlignment(); |
|
3321 |
||
3322 |
//Create a row, the form must have at least an empty row |
|
3323 |
CreateNewRowAndSetAsCurrentL(); |
|
3324 |
||
3325 |
for (TInt i = 0; i < iItems.Count(); i++) |
|
3326 |
{ |
|
3327 |
if (SkipNullItem(i)) |
|
3328 |
{ //zero size items are ignored |
|
3329 |
continue; |
|
3330 |
} |
|
3331 |
||
3332 |
// if the current alignment changes we may need to change row |
|
3333 |
VerifyRowAlignmentL(i); |
|
3334 |
||
3335 |
CMIDControlItem& ci = ControlItem(iItems[i]); |
|
3336 |
||
3337 |
// add any extra rows before the current item if needed |
|
3338 |
InsertNewlinesL(NumNewLinesBefore(ci), &ci); |
|
3339 |
||
3340 |
if (ItemIsUnconstrained(i)) |
|
3341 |
{ // unconstrained string items are processed specially |
|
3342 |
AddUnconstrainedStringItemL(i); |
|
3343 |
} |
|
3344 |
else |
|
3345 |
{ // any other item is processed in here |
|
3346 |
AddDefaultItemL(i); |
|
3347 |
} |
|
3348 |
||
3349 |
// add any additional row breaks if needed |
|
3350 |
InsertNewlinesL(NumNewLinesAfter(ci), &ci); |
|
3351 |
} |
|
71
d5e927d5853b
Revision: v2.2.11
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
3352 |
|
d5e927d5853b
Revision: v2.2.11
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
3353 |
// Restore pointed control |
d5e927d5853b
Revision: v2.2.11
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
3354 |
if (iLastPointedControl != KErrNotFound) |
d5e927d5853b
Revision: v2.2.11
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
3355 |
{ |
d5e927d5853b
Revision: v2.2.11
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
3356 |
iPointedControl = &ControlItem(iLastPointedControl); |
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
3357 |
iLastPointedControl = KErrNotFound; |
71
d5e927d5853b
Revision: v2.2.11
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
3358 |
} |
66 | 3359 |
} |
3360 |
||
3361 |
/** Return true if the item is an unconstrained string item, false otherwise */ |
|
3362 |
TBool CMIDForm::ItemIsUnconstrained(TInt aIndex) const |
|
3363 |
{ |
|
3364 |
if (aIndex >= 0 && aIndex < iItems.Count()) |
|
3365 |
{ |
|
3366 |
CMIDControlItem& ci = ControlItem(iItems[aIndex]); |
|
3367 |
return (IsStringItem(ci) && ((CMIDStringItem*)&ci)->IsUnconstrainedStringItem()); |
|
3368 |
} |
|
3369 |
||
3370 |
return EFalse; |
|
3371 |
} |
|
3372 |
||
3373 |
TBool CMIDForm::LayoutMatchesCurrentAlignment(CMIDControlItem& aControlItem, |
|
3374 |
MMIDItem::TLayout aCurrentAlignment) |
|
3375 |
{ |
|
3376 |
TInt leftRightMask = MMIDItem::ELeft | MMIDItem::ERight; |
|
3377 |
||
3378 |
return ((aControlItem.Layout() & leftRightMask) == MMIDItem::EDefault) || |
|
3379 |
((aControlItem.Layout() & leftRightMask) == aCurrentAlignment); |
|
3380 |
} |
|
3381 |
||
3382 |
TBool CMIDForm::LayoutDefault(CMIDControlItem& aControlItem) |
|
3383 |
{ |
|
3384 |
TInt leftRightMask = MMIDItem::ELeft | MMIDItem::ERight; |
|
3385 |
||
3386 |
return ((aControlItem.Layout() & leftRightMask) == MMIDItem::EDefault); |
|
3387 |
} |
|
3388 |
||
3389 |
TBool CMIDForm::LayoutNewLineBefore(CMIDControlItem& aControlItem) |
|
3390 |
{ |
|
3391 |
return (aControlItem.Layout() & MMIDItem::ENewLineBefore); |
|
3392 |
} |
|
3393 |
||
3394 |
TBool CMIDForm::LayoutNewLineAfter(CMIDControlItem& aControlItem) |
|
3395 |
{ |
|
3396 |
return (aControlItem.Layout() & MMIDItem::ENewLineAfter); |
|
3397 |
} |
|
3398 |
||
3399 |
/** Return true if the LAYOUT_SHRINK directive has been set. For |
|
3400 |
string items which have one or both dimensions of the preferred |
|
3401 |
size set the layout shrink directive is ignored. */ |
|
3402 |
TBool CMIDForm::LayoutShrink(CMIDControlItem& aControlItem) |
|
3403 |
{ |
|
3404 |
if (IsStringItem(aControlItem)) |
|
3405 |
{ |
|
3406 |
CMIDStringItem* si = (CMIDStringItem*)(&aControlItem); |
|
3407 |
||
3408 |
if (si->WidthOrHeightSpecified()) |
|
3409 |
{ |
|
3410 |
return EFalse; |
|
3411 |
} |
|
3412 |
} |
|
3413 |
||
3414 |
return (aControlItem.Layout() & MMIDItem::EShrink); |
|
3415 |
} |
|
3416 |
||
3417 |
/** Return true if the LAYOUT_EXPAND directive has been set. For |
|
3418 |
string items which have one or both dimensions of the preferred |
|
3419 |
size set the layout expand directive is ignored. */ |
|
3420 |
TBool CMIDForm::LayoutExpand(CMIDControlItem& aControlItem) |
|
3421 |
{ |
|
3422 |
if (IsStringItem(aControlItem)) |
|
3423 |
{ |
|
3424 |
CMIDStringItem* si = (CMIDStringItem*)(&aControlItem); |
|
3425 |
||
3426 |
if (si->WidthOrHeightSpecified()) |
|
3427 |
{ |
|
3428 |
return EFalse; |
|
3429 |
} |
|
3430 |
} |
|
3431 |
||
3432 |
return (aControlItem.Layout() & MMIDItem::EExpand); |
|
3433 |
} |
|
3434 |
||
3435 |
/** Return true if the LAYOUT_VSHIRNK directive has been set. For |
|
3436 |
string items which have one or both dimensions of the preferred |
|
3437 |
size set the layout vertical shrink directive is ignored. */ |
|
3438 |
TBool CMIDForm::LayoutVerticalShrink(CMIDControlItem& aControlItem) |
|
3439 |
{ |
|
3440 |
if (IsStringItem(aControlItem)) |
|
3441 |
{ |
|
3442 |
CMIDStringItem* si = (CMIDStringItem*)(&aControlItem); |
|
3443 |
||
3444 |
if (si->WidthOrHeightSpecified()) |
|
3445 |
{ |
|
3446 |
return EFalse; |
|
3447 |
} |
|
3448 |
} |
|
3449 |
||
3450 |
return (aControlItem.Layout() & MMIDItem::EVerticalShrink); |
|
3451 |
} |
|
3452 |
||
3453 |
/** Return true if the LAYOUT_VEXPAND directive has been set. For |
|
3454 |
string items which have one or both dimensions of the preferred |
|
3455 |
size set the layout vertical expand directive is ignored. */ |
|
3456 |
TBool CMIDForm::LayoutVerticalExpand(CMIDControlItem& aControlItem) |
|
3457 |
{ |
|
3458 |
if (IsStringItem(aControlItem)) |
|
3459 |
{ |
|
3460 |
CMIDStringItem* si = (CMIDStringItem*)(&aControlItem); |
|
3461 |
||
3462 |
if (si->WidthOrHeightSpecified()) |
|
3463 |
{ |
|
3464 |
return EFalse; |
|
3465 |
} |
|
3466 |
} |
|
3467 |
||
3468 |
return (aControlItem.Layout() & MMIDItem::EVerticalExpand); |
|
3469 |
} |
|
3470 |
||
3471 |
TBool CMIDForm::LayoutVerticalCenter(CMIDControlItem& aControlItem) |
|
3472 |
{ |
|
3473 |
TInt layout = aControlItem.Layout(); |
|
3474 |
layout &= MMIDItem::EVerticalCenter; |
|
3475 |
return (layout == MMIDItem::EVerticalCenter); |
|
3476 |
} |
|
3477 |
||
3478 |
TBool CMIDForm::LayoutBottom(CMIDControlItem& aControlItem) |
|
3479 |
{ |
|
3480 |
TInt layout = aControlItem.Layout(); |
|
3481 |
layout &= MMIDItem::EVerticalCenter; |
|
3482 |
return (layout == MMIDItem::EBottom) || (layout == 0); |
|
3483 |
} |
|
3484 |
||
3485 |
TBool CMIDForm::IsStringItem(CMIDControlItem& aControlItem) |
|
3486 |
{ |
|
3487 |
if (!aControlItem.iMMidItem) |
|
3488 |
{ |
|
3489 |
return EFalse; |
|
3490 |
} |
|
3491 |
return (aControlItem.iMMidItem->Type() == MMIDComponent::EStringItem); |
|
3492 |
} |
|
3493 |
||
3494 |
TBool CMIDForm::IsStringItemHyperlink(CMIDControlItem& aControlItem) |
|
3495 |
{ |
|
3496 |
if (!aControlItem.iMMidItem) |
|
3497 |
{ |
|
3498 |
return EFalse; |
|
3499 |
} |
|
3500 |
if (aControlItem.iMMidItem->Type() == MMIDComponent::EStringItem) |
|
3501 |
{ |
|
3502 |
return (((CMIDStringItem&) aControlItem).Appearance() == MMIDItem::EHyperLink); |
|
3503 |
} |
|
3504 |
else |
|
3505 |
{ |
|
3506 |
return EFalse; |
|
3507 |
} |
|
3508 |
} |
|
3509 |
||
3510 |
TBool CMIDForm::IsStringItemButton(CMIDControlItem& aControlItem) |
|
3511 |
{ |
|
3512 |
if (!aControlItem.iMMidItem) |
|
3513 |
{ |
|
3514 |
return EFalse; |
|
3515 |
} |
|
3516 |
if (aControlItem.iMMidItem->Type() == MMIDComponent::EStringItem) |
|
3517 |
{ |
|
3518 |
return (((CMIDStringItem&) aControlItem).Appearance() == MMIDItem::EButton); |
|
3519 |
} |
|
3520 |
else |
|
3521 |
{ |
|
3522 |
return EFalse; |
|
3523 |
} |
|
3524 |
} |
|
3525 |
||
3526 |
TBool CMIDForm::IsCustomItem(CMIDControlItem& aControlItem) |
|
3527 |
{ |
|
3528 |
if (!aControlItem.iMMidItem) |
|
3529 |
{ |
|
3530 |
return EFalse; |
|
3531 |
} |
|
3532 |
return (aControlItem.iMMidItem->Type() == MMIDComponent::ECustomItem); |
|
3533 |
} |
|
3534 |
||
3535 |
TBool CMIDForm::IsGaugeItem(CMIDControlItem& aControlItem) |
|
3536 |
{ |
|
3537 |
if (!aControlItem.iMMidItem) |
|
3538 |
{ |
|
3539 |
return EFalse; |
|
3540 |
} |
|
3541 |
return (aControlItem.iMMidItem->Type() == MMIDComponent::EGauge); |
|
3542 |
} |
|
3543 |
||
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
3544 |
TBool CMIDForm::IsInteractiveGaugeItem(CMIDControlItem& aControlItem) |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
3545 |
{ |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
3546 |
if (IsGaugeItem(aControlItem)) |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
3547 |
{ |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
3548 |
CMIDGaugeItem* gauge = static_cast<CMIDGaugeItem*>(&aControlItem); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
3549 |
if (gauge) |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
3550 |
{ |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
3551 |
return gauge->IsInteractive(); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
3552 |
} |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
3553 |
} |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
3554 |
return EFalse; |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
3555 |
} |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
3556 |
|
66 | 3557 |
TBool CMIDForm::IsTextFieldItem(CMIDControlItem& aControlItem) |
3558 |
{ |
|
3559 |
if (!aControlItem.iMMidItem) |
|
3560 |
{ |
|
3561 |
return EFalse; |
|
3562 |
} |
|
3563 |
return (aControlItem.iMMidItem->Type() == MMIDComponent::ETextField); |
|
3564 |
} |
|
3565 |
||
3566 |
TBool CMIDForm::IsChoiceGroup(CMIDControlItem& aControlItem) |
|
3567 |
{ |
|
3568 |
if (!aControlItem.iMMidItem) |
|
3569 |
{ |
|
3570 |
return EFalse; |
|
3571 |
} |
|
3572 |
return (aControlItem.iMMidItem->Type() == MMIDComponent::EChoiceGroup); |
|
3573 |
} |
|
3574 |
||
3575 |
TBool CMIDForm::IsDateField(CMIDControlItem& aControlItem) |
|
3576 |
{ |
|
3577 |
if (!aControlItem.iMMidItem) |
|
3578 |
{ |
|
3579 |
return EFalse; |
|
3580 |
} |
|
3581 |
return (aControlItem.iMMidItem->Type() == MMIDComponent::EDateField); |
|
3582 |
} |
|
3583 |
||
3584 |
TBool CMIDForm::IsLabelContainerItem(CMIDControlItem& aControlItem) |
|
3585 |
{ |
|
3586 |
return (aControlItem.Type() == KLabelContainerItem); |
|
3587 |
} |
|
3588 |
||
3589 |
TBool CMIDForm::IsSpacerUsedForFormatting(CMIDControlItem& aControlItem) |
|
3590 |
{ |
|
3591 |
if (!aControlItem.iMMidItem) |
|
3592 |
{ |
|
3593 |
return EFalse; |
|
3594 |
} |
|
3595 |
if (aControlItem.iMMidItem->Type() == MMIDComponent::ESpacer) |
|
3596 |
{ |
|
3597 |
CMIDSpacer* spacer = static_cast<CMIDSpacer*>(&aControlItem); |
|
3598 |
return spacer->UsedForStringFormatting(); |
|
3599 |
} |
|
3600 |
return EFalse; |
|
3601 |
} |
|
3602 |
||
3603 |
TBool CMIDForm::IsImageItem(CMIDControlItem& aControlItem) |
|
3604 |
{ |
|
3605 |
if (!aControlItem.iMMidItem) |
|
3606 |
{ |
|
3607 |
return EFalse; |
|
3608 |
} |
|
3609 |
return (aControlItem.iMMidItem->Type() == MMIDItem::EImageItem); |
|
3610 |
} |
|
3611 |
||
3612 |
#ifdef RD_JAVA_S60_RELEASE_9_2 |
|
3613 |
void CMIDForm::PostPendingUpEventL() |
|
3614 |
{ |
|
3615 |
MMIDItem* curItem = CurrentItem(); |
|
3616 |
if (curItem) |
|
3617 |
{ |
|
3618 |
CMIDControlItem& item = ControlItem(curItem); |
|
3619 |
||
3620 |
if (IsChoiceGroup(item)) |
|
3621 |
{ |
|
3622 |
CMIDChoiceGroupItem* cgItem = static_cast<CMIDChoiceGroupItem*>(&item); |
|
3623 |
cgItem->PostPendingUpEventL(); |
|
3624 |
} |
|
3625 |
} |
|
3626 |
} |
|
3627 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
|
3628 |
||
3629 |
// returns: The number of new lines before an item. |
|
3630 |
// This only takes into account new lines that come from |
|
3631 |
// preceeding a string item with new line characters. |
|
3632 |
TInt CMIDForm::NumNewLinesBefore(CMIDControlItem& aControlItem) |
|
3633 |
{ |
|
3634 |
if (IsStringItem(aControlItem)) |
|
3635 |
{ |
|
3636 |
CMIDStringItem* si = (CMIDStringItem*)(&aControlItem); |
|
3637 |
TInt nLinesBefore = si->NumNewlinesBefore(); |
|
3638 |
if (nLinesBefore > 0) |
|
3639 |
{ |
|
3640 |
return nLinesBefore; |
|
3641 |
} |
|
3642 |
} |
|
3643 |
if (iCurrentRow && iCurrentRow->NumItems() == 0) |
|
3644 |
{ |
|
3645 |
return 0; |
|
3646 |
} |
|
3647 |
return LayoutNewLineBefore(aControlItem) ? 1 : 0; |
|
3648 |
} |
|
3649 |
||
3650 |
// returns: The number of new lines that should appear after an item |
|
3651 |
// This takes into account the new lines that can occour from |
|
3652 |
// newlines at the end of a string item, and if there are none |
|
3653 |
// of these, then it returns 1 if the Layout NewLineAfter |
|
3654 |
// directive has been used and 0 otherwise. |
|
3655 |
TInt CMIDForm::NumNewLinesAfter(CMIDControlItem& aControlItem) |
|
3656 |
{ |
|
3657 |
if (IsStringItem(aControlItem)) |
|
3658 |
{ |
|
3659 |
CMIDStringItem* si = (CMIDStringItem*)(&aControlItem); |
|
3660 |
if (si->NumNewlinesAfter() > 0) |
|
3661 |
{ |
|
3662 |
TInt nLinesAfter = si->NumNewlinesAfter(); |
|
3663 |
if (nLinesAfter > 0) |
|
3664 |
{ |
|
3665 |
return nLinesAfter; |
|
3666 |
} |
|
3667 |
} |
|
3668 |
} |
|
3669 |
return LayoutNewLineAfter(aControlItem) ? 1 : 0; |
|
3670 |
} |
|
3671 |
||
3672 |
// effects: Sizes the items within the rows based on their layout characteristics |
|
3673 |
// modifies: CMIDFormRow |
|
3674 |
void CMIDForm::SizeItemsInFormRowsL() |
|
3675 |
{ |
|
3676 |
TInt rowCount = iRows.Count(); |
|
3677 |
for (TInt i=0; i < rowCount; i++) |
|
3678 |
{ |
|
3679 |
iRows[i]->SizeItemsL(); |
|
3680 |
} |
|
3681 |
} |
|
3682 |
||
3683 |
// effects: Deletes all rows in the Form. It doesn't affect the items that have |
|
3684 |
// been added to the form. |
|
3685 |
// modifies: CMIDForm, CMIDFormRow |
|
3686 |
void CMIDForm::DeleteRows() |
|
3687 |
{ |
|
3688 |
// By deleting rows we are losing pointers to original items. |
|
3689 |
// To avoid any problems with using iPointedControl, which |
|
3690 |
// could points to invalid object (e.g. used in |
|
3691 |
// CMIDForm::HandleHighlightTimer or |
|
3692 |
// in CMIDForm::HandlePhysicsPointerEventL), |
|
3693 |
// iPointedControl must be set to NULL. |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
3694 |
if (iPointedControl && !iUpEventSent) |
71
d5e927d5853b
Revision: v2.2.11
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
3695 |
{ |
d5e927d5853b
Revision: v2.2.11
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
3696 |
// Store the index to last poited control. It will |
d5e927d5853b
Revision: v2.2.11
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
3697 |
// be restored after item are placed to new rows |
d5e927d5853b
Revision: v2.2.11
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
3698 |
// (see CMIDForm::AssignItemsToRowsL). |
d5e927d5853b
Revision: v2.2.11
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
3699 |
iLastPointedControl = ItemIndex(*iPointedControl); |
d5e927d5853b
Revision: v2.2.11
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
3700 |
} |
66 | 3701 |
iPointedControl = NULL; |
3702 |
||
3703 |
for (TInt i=0; i < iRows.Count(); i++) |
|
3704 |
{ |
|
3705 |
delete iRows[i]; |
|
3706 |
} |
|
3707 |
||
3708 |
iRows.Reset(); |
|
3709 |
iCurrentRow = NULL; |
|
3710 |
} |
|
3711 |
||
3712 |
TInt CMIDForm::HeightOfAllItems() |
|
3713 |
{ |
|
3714 |
return iTotalFormHeight; |
|
3715 |
} |
|
3716 |
||
3717 |
void CMIDForm::UpdateHeightOfAllItems() |
|
3718 |
{ |
|
3719 |
TInt yTopMargin = iFormRect.Rect().iTl.iY - iMidpFormRect.Rect().iTl.iY; |
|
3720 |
TInt yBottomMargin = iMidpFormRect.Rect().iBr.iY - iFormRect.Rect().iBr.iY; |
|
3721 |
||
3722 |
iTotalFormHeight = yTopMargin; |
|
3723 |
||
3724 |
TInt rowCount = iRows.Count(); |
|
3725 |
for (TInt i=0; i < rowCount; i++) |
|
3726 |
{ |
|
3727 |
iTotalFormHeight += iRows[i]->Size().iHeight; |
|
3728 |
} |
|
3729 |
// Form bottom margin is added |
|
3730 |
iTotalFormHeight += yBottomMargin; |
|
3731 |
} |
|
3732 |
||
3733 |
/* HandleResourceChange |
|
3734 |
* |
|
3735 |
* This method is called after a resource change event, for example after |
|
3736 |
* screen dynamic resolution change. |
|
3737 |
* |
|
3738 |
* In the case of a screen dynamic resolution change we notify all items and |
|
3739 |
* repeat the entire form layout. |
|
3740 |
* |
|
3741 |
* We calculate the % of form that has been scrolled so far and we |
|
3742 |
* modify iScroll so that we have scrolled the same % of form after resolution |
|
3743 |
* change. Note that the max extent of iScroll is HeightOfAllItems() - Height() |
|
3744 |
* and not simply HeightOfAllItems() as one may think, see |
|
3745 |
* SetRowExtentsWithRespectToScrolledLocation(). Also note that applying a % |
|
3746 |
* scrolling does not necessarily mean the same items will be on screen after a |
|
3747 |
* resolution change. |
|
3748 |
* Especially when changing from portrait to landscape or vice-versa the |
|
3749 |
* number of items on a row vary greatly and as a consequence the number of |
|
3750 |
* rows may vary. Therefore, if there is a focused item on screen before |
|
3751 |
* resolution change (iFocused not KErrNotFound) we make sure this item is |
|
3752 |
* visible and focused after res change by scrolling to it, see SetFocusedItem() |
|
3753 |
* and ScrollToFocused(). |
|
3754 |
*/ |
|
3755 |
void CMIDForm::HandleResourceChange(TInt aType) |
|
3756 |
{ |
|
3757 |
TInt maxScrollExtentOld = HeightOfAllItems() - Height(); //max extent of iScroll |
|
3758 |
CCoeControl::HandleResourceChange(aType); |
|
3759 |
||
3760 |
if (aType == KEikDynamicLayoutVariantSwitch) |
|
3761 |
{ // dynamic resolution change |
|
3762 |
TInt focusedItem = iFocused; |
|
3763 |
||
3764 |
UpdateMemberVariables(); |
|
3765 |
UpdateHeightOfAllItems(); |
|
3766 |
||
3767 |
TInt itemCount = iItems.Count(); |
|
3768 |
for (TInt i=0; i < itemCount; i++) |
|
3769 |
{ |
|
3770 |
CMIDControlItem& controlItem = ControlItem(i); |
|
3771 |
controlItem.ResolutionChange(aType); |
|
3772 |
||
3773 |
if (controlItem.LabelControl()) |
|
3774 |
{ |
|
3775 |
controlItem.LabelControl()->ResolutionChange(); |
|
3776 |
} |
|
3777 |
} |
|
3778 |
||
3779 |
TInt maxScrollExtentNew = HeightOfAllItems() - Height(); //max extent of iScroll |
|
3780 |
||
3781 |
TRAPD(err,LayoutFormL()); |
|
3782 |
||
3783 |
if (err == KErrNone) |
|
3784 |
{ |
|
3785 |
if ((maxScrollExtentNew <= 0) && (maxScrollExtentOld > 0)) |
|
3786 |
{ |
|
3787 |
// scroll on top |
|
3788 |
RawScroll(0); |
|
3789 |
if (focusedItem != KErrNotFound) |
|
3790 |
{ |
|
3791 |
// restore the form item focus |
|
3792 |
CMIDControlItem& control = ControlItem(focusedItem); |
|
3793 |
control.RestoreInnerFocus(); |
|
3794 |
} |
|
3795 |
} |
|
3796 |
else |
|
3797 |
{ |
|
3798 |
if ((maxScrollExtentNew > 0) || (maxScrollExtentOld > 0)) |
|
3799 |
{ |
|
3800 |
// if there is something focused |
|
3801 |
if (focusedItem != KErrNotFound) |
|
3802 |
{ |
|
3803 |
// restore the form item focus |
|
3804 |
CMIDControlItem& control = ControlItem(focusedItem); |
|
3805 |
ScrollToFocused(); |
|
3806 |
control.RestoreInnerFocus(); |
|
3807 |
} |
|
3808 |
// if scroll out of maxScrollExtent |
|
3809 |
if (maxScrollExtentNew+iScroll < 0) |
|
3810 |
{ |
|
3811 |
// scroll to bottom |
|
3812 |
RawScroll(-maxScrollExtentNew); |
|
3813 |
} |
|
3814 |
||
3815 |
} |
|
3816 |
} |
|
3817 |
} |
|
3818 |
||
3819 |
SetHighlightBackgroundRects(); |
|
3820 |
HandleItemVisibilityChange(); |
|
3821 |
UpdateScrollBar(); |
|
3822 |
DrawDeferred(); |
|
3823 |
} |
|
3824 |
else if (aType == KEikColorResourceChange || aType == KAknsMessageSkinChange || |
|
3825 |
aType == KUidValueCoeColorSchemeChangeEvent) |
|
3826 |
{//skin or color scheme change |
|
3827 |
TInt itemCount = iItems.Count(); |
|
3828 |
for (TInt i=0; i < itemCount; i++) |
|
3829 |
{ |
|
3830 |
CMIDControlItem& controlItem = ControlItem(i); |
|
3831 |
controlItem.ColorChange(aType); |
|
3832 |
} |
|
3833 |
||
3834 |
// send this event also to form scrollbar |
|
3835 |
CEikScrollBar* sb = iSBFrame->GetScrollBarHandle(CEikScrollBar::EVertical); |
|
3836 |
if (sb) |
|
3837 |
{ |
|
3838 |
sb->HandleResourceChange(aType); |
|
3839 |
} |
|
3840 |
} |
|
3841 |
else if ((aType == KEikMessageUnfadeWindows) || |
|
3842 |
(aType == KEikMessageFadeAllWindows)) |
|
3843 |
{ |
|
3844 |
iLastFadeMessage = aType; |
|
3845 |
} |
|
3846 |
else if ((aType == KEikMessageWindowsFadeChange) && |
|
3847 |
((iLastFadeMessage == KEikMessageUnfadeWindows) || |
|
3848 |
(iLastFadeMessage == KEikMessageFadeAllWindows))) |
|
3849 |
{ |
|
3850 |
TInt itemCount = iItems.Count(); |
|
3851 |
for (TInt i=0; i < itemCount; i++) |
|
3852 |
{ |
|
3853 |
CMIDControlItem& controlItem = ControlItem(i); |
|
3854 |
controlItem.HandleWindowFade(iLastFadeMessage == KEikMessageFadeAllWindows); |
|
3855 |
} |
|
3856 |
iLastFadeMessage = 0; |
|
3857 |
} |
|
3858 |
||
3859 |
UpdatePhysics(); |
|
3860 |
||
3861 |
#ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
3862 |
UpdateTactileFeedbackDensity(); |
|
3863 |
#endif // RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
3864 |
} |
|
3865 |
||
3866 |
TBool CMIDForm::TryDetectLongTapL(const TPointerEvent &aPointerEvent) |
|
3867 |
{ |
|
3868 |
return iDisplayable.TryDetectLongTapL(aPointerEvent); |
|
3869 |
} |
|
3870 |
||
3871 |
#ifdef RD_SCALABLE_UI_V2 |
|
3872 |
void CMIDForm::HandleScrollEventL(CEikScrollBar* aScrollBar, TEikScrollEvent aEventType) |
|
3873 |
{ |
|
3874 |
if (AknLayoutUtils::PenEnabled()) |
|
3875 |
{ |
|
3876 |
||
3877 |
if (LayoutPending()) |
|
3878 |
{ |
|
3879 |
LayoutFormL(); |
|
3880 |
} |
|
3881 |
||
3882 |
TInt pixelIndex; |
|
3883 |
||
3884 |
switch (aEventType) |
|
3885 |
{ |
|
3886 |
case EEikScrollUp: |
|
3887 |
{ |
|
3888 |
pixelIndex = iScroll + (Height() / KScrollAmountDivider); |
|
3889 |
break; |
|
3890 |
} |
|
3891 |
||
3892 |
case EEikScrollDown: |
|
3893 |
{ |
|
3894 |
pixelIndex = iScroll - (Height() / KScrollAmountDivider); |
|
3895 |
break; |
|
3896 |
} |
|
3897 |
||
3898 |
case EEikScrollPageUp: |
|
3899 |
{ |
|
3900 |
pixelIndex = iScroll + Height(); |
|
3901 |
break; |
|
3902 |
} |
|
3903 |
||
3904 |
case EEikScrollPageDown: |
|
3905 |
{ |
|
3906 |
pixelIndex = iScroll - Height(); |
|
3907 |
break; |
|
3908 |
} |
|
3909 |
||
3910 |
default://thumb drag |
|
3911 |
{ |
|
3912 |
//scroll form if thumb position has moved more than 1/10 of the screen height either up or down |
|
3913 |
//or thumb position is at top or at bottom of the scrollbar. |
|
3914 |
if (-aScrollBar->ThumbPosition() < (iScroll - (Height() / KScrollAmountDividerForThumbDrag)) |
|
3915 |
|| -aScrollBar->ThumbPosition() > (iScroll + (Height() / KScrollAmountDividerForThumbDrag)) |
|
3916 |
|| aScrollBar->ThumbPosition() == 0 |
|
3917 |
|| aScrollBar->ThumbPosition() == aScrollBar->Model()->MaxThumbPos()) |
|
3918 |
{ |
|
3919 |
aScrollBar->DrawNow(); |
|
3920 |
pixelIndex = - aScrollBar->ThumbPosition(); |
|
3921 |
} |
|
3922 |
else |
|
3923 |
{ |
|
3924 |
return; |
|
3925 |
} |
|
3926 |
break; |
|
3927 |
} |
|
3928 |
} |
|
3929 |
RawScroll(pixelIndex); |
|
3930 |
RawScrollFinalize(ETrue); |
|
3931 |
UpdatePhysics(); |
|
3932 |
} |
|
3933 |
} |
|
3934 |
||
3935 |
||
3936 |
TBool CMIDForm::StringItemContainsPoint(CMIDStringItem* aStringItem, const TPoint& aPoint) const |
|
3937 |
{ |
|
3938 |
CMIDControlItem* ci = ControlItemAtPoint(aPoint); |
|
3939 |
||
3940 |
if (ci) |
|
3941 |
{ |
|
3942 |
if (IsLabelContainerItem(*ci)) |
|
3943 |
{ |
|
3944 |
CMIDLabelContainerItem *lci = static_cast<CMIDLabelContainerItem*>(ci); |
|
3945 |
CMIDStringItem& si = lci->StringItem(); |
|
3946 |
if (&si == aStringItem) |
|
3947 |
{ // LabelContainer item is (part of) StringItem |
|
3948 |
if (si.IsDivided()) |
|
3949 |
{ // StringItem was divided due to concatenation of contents |
|
3950 |
if (lci->IsStringItemContent()) |
|
3951 |
{ // return ETrue if is pointed to StringItem content |
|
3952 |
return ETrue; |
|
3953 |
} |
|
3954 |
else |
|
3955 |
{ // return EFasle if is pointed to StringItem label |
|
3956 |
return EFalse; |
|
3957 |
} |
|
3958 |
} |
|
3959 |
else |
|
3960 |
{ // StringItem was not divided, pointed directly to unconstrained StringItem |
|
3961 |
return ETrue; |
|
3962 |
} |
|
3963 |
} |
|
3964 |
} |
|
3965 |
else |
|
3966 |
{ |
|
3967 |
return (ci == aStringItem && aStringItem->TappingActionRect().Contains(aPoint)); |
|
3968 |
} |
|
3969 |
} |
|
3970 |
||
3971 |
return EFalse; |
|
3972 |
} |
|
3973 |
||
3974 |
TBool CMIDForm::IsFocusChangingWithPen() const |
|
3975 |
{ |
|
3976 |
return iFocusChangingWithPen; |
|
3977 |
} |
|
3978 |
||
3979 |
#endif //RD_SCALABLE_UI_V2 |
|
3980 |
||
3981 |
||
3982 |
void CMIDForm::HandleForegroundL(TBool aForeground) |
|
3983 |
{ |
|
3984 |
// send HandleForegroundL notification to gauge items |
|
3985 |
TInt itemsCount = iItems.Count(); |
|
3986 |
for (TInt i=0; i < itemsCount; i++) |
|
3987 |
{ |
|
3988 |
if (iItems[i]->Type() == MMIDComponent::EGauge) |
|
3989 |
{ |
|
3990 |
CMIDGaugeItem* gauge = static_cast<CMIDGaugeItem*>(iItems[i]); |
|
3991 |
ASSERT(gauge); |
|
3992 |
gauge->HandleForegroundL(aForeground); |
|
3993 |
} |
|
3994 |
} |
|
3995 |
} |
|
3996 |
||
3997 |
CMIDPopupNoteController* CMIDForm::GetPopupNoteController() const |
|
3998 |
{ |
|
3999 |
return iPopupController; |
|
4000 |
} |
|
4001 |
||
4002 |
TInt CMIDForm::GetMidpNaviPos() |
|
4003 |
{ |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4004 |
// get main pane size from CEikAppU |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4005 |
TRect mainPane = iAvkonAppUi->ApplicationRect(); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4006 |
|
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4007 |
// get screen size in pixels |
66 | 4008 |
TAknLayoutRect mainMidpPane; |
4009 |
mainMidpPane.LayoutRect(iEikonEnv->ScreenDevice()->SizeInPixels(), |
|
4010 |
AknLayoutScalable_Avkon::main_midp_pane().LayoutLine()); |
|
4011 |
||
4012 |
// getting form size depends on screen orientation |
|
4013 |
TInt variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0; |
|
4014 |
iMidpFormRect.LayoutRect(mainMidpPane.Rect(), |
|
4015 |
AknLayoutScalable_Avkon::midp_form_pane(variety).LayoutLine()); |
|
4016 |
||
4017 |
// different between screen size and form size |
|
4018 |
TInt xFormDiff = mainMidpPane.Rect().iBr.iX - iMidpFormRect.Rect().iBr.iX; |
|
4019 |
// width of navi bar position only for ( iAlignment == MMIDItem::ERight ) |
|
4020 |
TInt xNaviPos = iMidpFormRect.Rect().iTl.iX - xFormDiff; |
|
4021 |
||
4022 |
return xNaviPos; |
|
4023 |
} |
|
4024 |
||
4025 |
void CMIDForm::UpdatePhysics() |
|
4026 |
{ |
|
4027 |
if (iPhysics) |
|
4028 |
{ |
|
4029 |
TSize worldSize(Width(), HeightOfAllItems()); |
|
4030 |
TSize viewSize(Width(), Height()); |
|
4031 |
TPoint viewCenter(Width() / 2, -iScroll + Height() / 2); |
|
4032 |
TRAP_IGNORE(iPhysics->InitPhysicsL(worldSize, viewSize, viewCenter)); |
|
4033 |
} |
|
4034 |
} |
|
4035 |
||
4036 |
TInt CMIDForm::HighlightTimerCallback(TAny* aPtr) |
|
4037 |
{ |
|
4038 |
CMIDForm* me = static_cast<CMIDForm*>(aPtr); |
|
4039 |
me->HandleHighlightTimer(); |
|
4040 |
return 0; |
|
4041 |
} |
|
4042 |
||
4043 |
void CMIDForm::HandleHighlightTimer() |
|
4044 |
{ |
|
4045 |
iHighlightTimer->Cancel(); |
|
4046 |
||
4047 |
if (iPointedControl && iPointedControl->IsSelectable()) |
|
4048 |
{ |
|
4049 |
// If tactile feedback has not been given already |
|
4050 |
// give basic tactile feedback when focus changes. |
|
4051 |
// Don't give tactile feedback for button because it is handled |
|
4052 |
// by button implementation. |
|
4053 |
#ifdef RD_TACTILE_FEEDBACK |
|
4054 |
if (!iFeedbackExecutedInPointerDown) |
|
4055 |
{ |
|
4056 |
DoFeedbackOnFocusChange(*iPointedControl); |
|
4057 |
iFeedbackExecutedInPointerDown = ETrue; |
|
4058 |
} |
|
4059 |
#endif // RD_TACTILE_FEEDBACK |
|
4060 |
||
4061 |
TInt itemIndex = ItemIndex(*iPointedControl); |
|
4062 |
||
4063 |
if (itemIndex != iFocused) |
|
4064 |
{ |
|
4065 |
SetFocusedItem(itemIndex, ENone, EFalse); |
|
4066 |
DrawDeferred(); |
|
4067 |
} |
|
4068 |
||
4069 |
if (!PhysicsScrolling() && !iUpEventSent) |
|
4070 |
{ |
|
4071 |
TRAP_IGNORE(ForwardPointerEventToItemL(iLastPointerDownEvent)); |
|
4072 |
} |
|
4073 |
} |
|
4074 |
} |
|
4075 |
||
4076 |
void CMIDForm::SetHighlightBackgroundRects() |
|
4077 |
{ |
|
4078 |
if (iFocused == KErrNotFound) |
|
4079 |
{ |
|
4080 |
return; |
|
4081 |
} |
|
4082 |
||
4083 |
CMIDControlItem& ci = ControlItem(iFocused); |
|
4084 |
||
4085 |
// Limit rect size to screen size. If Rect() is way larger |
|
4086 |
// than screen, the svg engine will not cope handling that. |
|
4087 |
TRect r(ci.Size()); |
|
4088 |
TRect s; |
|
4089 |
AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EScreen, s); |
|
4090 |
||
4091 |
if (r.Intersects(s)) |
|
4092 |
{ |
|
4093 |
s.Intersection(r); |
|
4094 |
} |
|
4095 |
||
4096 |
TRect rect(s); |
|
4097 |
rect.Normalize(); // ensure positive w & h, just in case |
|
4098 |
||
4099 |
TAknLayoutRect topLeft ; |
|
4100 |
topLeft.LayoutRect(rect, SkinLayout::Input_field_skin_placing__general__Line_2()); |
|
4101 |
||
4102 |
TAknLayoutRect bottomRight; |
|
4103 |
bottomRight.LayoutRect(rect, SkinLayout::Input_field_skin_placing__general__Line_5()); |
|
4104 |
||
4105 |
TRect outerRect = TRect(topLeft.Rect().iTl, bottomRight.Rect().iBr); |
|
4106 |
TRect innerRect = TRect(topLeft.Rect().iBr, bottomRight.Rect().iTl); |
|
4107 |
||
4108 |
iHighlightedBackgroundCc->SetParentContext(iDisplayable.BackGroundControlContext()); |
|
4109 |
iHighlightedBackgroundCc->SetFrameRects(outerRect, innerRect); |
|
4110 |
||
4111 |
UpdateHighlightBackgroundPosition(); |
|
4112 |
} |
|
4113 |
||
4114 |
void CMIDForm::UpdateHighlightBackgroundPosition() |
|
4115 |
{ |
|
4116 |
||
4117 |
if (iFocused != KErrNotFound) |
|
4118 |
{ |
|
4119 |
CMIDControlItem& ci = ControlItem(iFocused); |
|
4120 |
TPoint highlightPosition = ci.PositionRelativeToScreen(); |
|
4121 |
TRect focusedRect = ci.Rect(); |
|
4122 |
||
4123 |
// Max size of the higlight background is limited to screen size, |
|
4124 |
// see SetHighlightBackgroundRects(). |
|
4125 |
// Need to adjust the highlight position if focused item is partially visible |
|
4126 |
// on top of the form and it is larger than screen. |
|
4127 |
if (focusedRect.iTl.iY < 0 && focusedRect.iBr.iY > 0) |
|
4128 |
{ |
|
4129 |
TRect screen; |
|
4130 |
AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EScreen, screen); |
|
4131 |
if (focusedRect.Height() > screen.Height()) |
|
4132 |
{ |
|
4133 |
if (focusedRect.iBr.iY > iSize.iHeight) |
|
4134 |
{ |
|
4135 |
// Focused item fills the visible form area fully |
|
4136 |
highlightPosition.iY = 0; |
|
4137 |
} |
|
4138 |
else |
|
4139 |
{ |
|
4140 |
// Bottom of focused item is in the visible form area |
|
4141 |
highlightPosition.iY += focusedRect.Height() - screen.Height(); |
|
4142 |
} |
|
4143 |
} |
|
4144 |
} |
|
4145 |
||
4146 |
iHighlightedBackgroundCc->SetParentPos(highlightPosition); |
|
4147 |
} |
|
4148 |
} |
|
4149 |
||
4150 |
void CMIDForm::HandlePhysicsPointerEventL(const TPointerEvent& aPointerEvent) |
|
4151 |
{ |
|
4152 |
#ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
4153 |
iLastPointerEventType = aPointerEvent.iType; |
|
4154 |
#endif |
|
4155 |
||
4156 |
if (iPhysics && iPhysics->CanBeStopped()) |
|
4157 |
{ |
|
4158 |
switch (aPointerEvent.iType) |
|
4159 |
{ |
|
4160 |
case TPointerEvent::EButton1Down: |
|
4161 |
{ |
|
4162 |
iPreventPhysicsScrolling = EFalse; |
|
4163 |
iFlickStoppedOnDownEvent = iFlickOngoing; |
|
4164 |
iFeedbackExecutedInPointerDown = EFalse; |
|
4165 |
iPhysics->Stop(); |
|
4166 |
CMIDControlItem* ci = ControlItemAtPoint(aPointerEvent.iPosition); |
|
4167 |
||
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4168 |
if (ci && IsInteractiveGaugeItem(*ci)) |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4169 |
{ |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4170 |
CMIDGaugeItem* gauge = static_cast<CMIDGaugeItem*>(ci); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4171 |
this->iLastGaugeValue = gauge->GetValue(); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4172 |
} |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4173 |
|
66 | 4174 |
// Physics scrolling was not ongoing and tap hit already selected item. |
4175 |
// Then forward pointer event to the item. |
|
4176 |
if (ci && IsCurrentItem((CMIDItem*)ci) && !iFlickStoppedOnDownEvent) |
|
4177 |
{ |
|
4178 |
iPointedControl = ci; |
|
4179 |
ForwardPointerEventToItemL(aPointerEvent); |
|
4180 |
} |
|
4181 |
else |
|
4182 |
{ |
|
4183 |
// Tactile fedback is executed when kinetic scrolling is stopped on down event. |
|
4184 |
if (iFlickStoppedOnDownEvent) |
|
4185 |
{ |
|
4186 |
#ifdef RD_TACTILE_FEEDBACK |
|
4187 |
#ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
4188 |
iFeedback->InstantFeedback(ETouchFeedbackList); |
|
4189 |
#else |
|
4190 |
iFeedback->InstantFeedback(ETouchFeedbackBasic); |
|
4191 |
#endif // RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
4192 |
iFeedbackExecutedInPointerDown = ETrue; |
|
4193 |
#endif // RD_TACTILE_FEEDBACK |
|
4194 |
} |
|
4195 |
||
4196 |
// Pointed control changes. |
|
4197 |
if (ci && ci->IsSelectable() && (MMIDItem*)ci != CurrentItem()) |
|
4198 |
{ |
|
4199 |
iFocusChangingWithPen = ETrue; |
|
4200 |
} |
|
4201 |
||
4202 |
// Start highlight timer |
|
4203 |
iPointedControl = ci; |
|
4204 |
iHighlightTimer->Cancel(); |
|
4205 |
// Start highlight timer if some any control is tapped. |
|
4206 |
if (iPointedControl) |
|
4207 |
{ |
|
4208 |
TInt highlightTimeout = iPhysics->HighlightDelay() * 1000; |
|
4209 |
iHighlightTimer->Start(TTimeIntervalMicroSeconds32(highlightTimeout), |
|
4210 |
TTimeIntervalMicroSeconds32(highlightTimeout), |
|
4211 |
TCallBack(HighlightTimerCallback, this)); |
|
4212 |
} |
|
4213 |
} |
|
4214 |
// Setup members |
|
4215 |
iStartPosition = aPointerEvent.iPosition; |
|
4216 |
iLastPointerDownEvent = aPointerEvent; |
|
4217 |
iUpEventSent = EFalse; |
|
4218 |
iStartTime.HomeTime(); |
|
4219 |
iLastDragPosition = aPointerEvent.iPosition; |
|
4220 |
||
4221 |
break; |
|
4222 |
} |
|
4223 |
// EDrag |
|
4224 |
case TPointerEvent::EDrag: |
|
4225 |
{ |
|
4226 |
TInt dragY = iStartPosition.iY - aPointerEvent.iPosition.iY; |
|
4227 |
TInt dragX = iStartPosition.iX - aPointerEvent.iPosition.iX; |
|
4228 |
iDisplayable.TryDetectLongTapL(aPointerEvent); |
|
4229 |
||
4230 |
// Override triggering of physicsScrolling in case of doing text painting in TextField-item |
|
4231 |
// or moving slider in Gauge-item. |
|
4232 |
if (!iPreventPhysicsScrolling && iPointedControl && iPointedControl->iMMidItem && |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4233 |
(iPointedControl->iMMidItem->Type() == MMIDComponent::ETextField || |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4234 |
IsInteractiveGaugeItem(*iPointedControl))) |
66 | 4235 |
{ |
4236 |
// If physics scrolling is not ongoing (abs(dragY) < DragTreshold) |
|
4237 |
// then stop flicking and forward event to the item (iPreventPhysicsScrolling = ETrue). |
|
4238 |
if ((Abs(dragX) > iPhysics->DragThreshold()) && (Abs(dragY) < iPhysics->DragThreshold() |
|
4239 |
&& !iPanningOngoing)) |
|
4240 |
{ |
|
4241 |
iPreventPhysicsScrolling = ETrue; |
|
4242 |
} |
|
4243 |
} |
|
4244 |
||
4245 |
// Check whether DragTreshold for panning is exceeded. If yes, then cancel timer and longtap. |
|
4246 |
if (!iPanningOngoing && Abs(dragY) > iPhysics->DragThreshold() && !iPreventPhysicsScrolling) |
|
4247 |
{ |
|
4248 |
iPanningOngoing = ETrue; |
|
4249 |
iHighlightTimer->Cancel(); |
|
4250 |
// Start panning from aPointerEvent.iPosition with iPhysics->DragThreshold() margin |
|
4251 |
iLastDragPosition = aPointerEvent.iPosition; |
|
4252 |
iPhysics->SetPanningPosition(iLastDragPosition - aPointerEvent.iPosition); |
|
4253 |
//Forward one drag event to the focused textField or Gauge when panning is triggered |
|
4254 |
if ((iFocused != KErrNotFound) |
|
4255 |
&& IsTextFieldItem(ControlItem(iFocused))) |
|
4256 |
{ |
|
4257 |
ControlItem(iFocused).HandlePointerEventL(aPointerEvent); |
|
4258 |
} |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4259 |
if (iPointedControl && IsInteractiveGaugeItem(*iPointedControl)) |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4260 |
{ |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4261 |
CMIDGaugeItem* gauge = static_cast<CMIDGaugeItem*>(iPointedControl); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4262 |
|
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4263 |
// If panning is started here (i.e. dragging of slider |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4264 |
// didn't exceed the horizontal threshold), reset |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4265 |
// gauge value to original value (from pointer down). |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4266 |
// To ensure that slider updates its visual appearance |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4267 |
// (i.e. thumb will be displayed as released), |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4268 |
// lets send dummy event with original position. |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4269 |
TPointerEvent newEvent; |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4270 |
newEvent.iType = TPointerEvent::EButton1Up; |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4271 |
newEvent.iPosition = iStartPosition; |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4272 |
ForwardPointerEventToItemL(newEvent); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4273 |
|
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4274 |
// reset value |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4275 |
gauge->SetValueL(iLastGaugeValue); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4276 |
|
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4277 |
// post event to ensure that item state listener is notified |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4278 |
// about change |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4279 |
iEnv->PostJavaEvent(*this, EDisplayable, Index(iPointedControl)); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4280 |
} |
66 | 4281 |
} |
4282 |
// If panning is already ongoing. Update panning position. Also we redraw entire Form |
|
4283 |
// to prevent unexpected behavior(artifacts on the screen) during flick scrolling and |
|
4284 |
// to make scrolling smoother. |
|
4285 |
else if (iPanningOngoing) |
|
4286 |
{ |
|
4287 |
iPhysics->SetPanningPosition(iLastDragPosition - aPointerEvent.iPosition); |
|
4288 |
iLastDragPosition = aPointerEvent.iPosition; |
|
4289 |
DrawDeferred(); |
|
4290 |
} |
|
4291 |
// If dragged outside of StringItem area or panning starts, then up event is sent to the item. |
|
4292 |
if (!iUpEventSent && iPointedControl && IsStringItem(*iPointedControl) && (iPanningOngoing || |
|
4293 |
(iPointedControl && !iPointedControl->Rect().Contains(aPointerEvent.iPosition))) |
|
4294 |
) |
|
4295 |
{ |
|
4296 |
TPointerEvent pointerEvent = aPointerEvent; |
|
4297 |
pointerEvent.iType = TPointerEvent::EButton1Up; |
|
4298 |
ForwardPointerEventToItemL(pointerEvent); |
|
4299 |
iPointedControl = ControlItemAtPoint(aPointerEvent.iPosition); |
|
4300 |
iUpEventSent = ETrue; |
|
4301 |
} |
|
4302 |
// If physics scrolling is not ongoing forward event to the item. |
|
4303 |
else if (!iHighlightTimer->IsActive() && !PhysicsScrolling() && |
|
4304 |
(iPointedControl && iPointedControl->Rect().Contains(aPointerEvent.iPosition))) |
|
4305 |
{ |
|
4306 |
ForwardPointerEventToItemL(aPointerEvent); |
|
4307 |
} |
|
4308 |
#ifdef RD_JAVA_S60_RELEASE_9_2 |
|
4309 |
// ChoiceGroup gets drag events while physics scrolling. |
|
4310 |
// Enables internal highlight disappearing when panning begins. |
|
4311 |
// We have control if there is any Item on Form. |
|
4312 |
else if (!iHighlightTimer->IsActive() |
|
4313 |
&& (iFocused > KErrNotFound) |
|
4314 |
&& IsChoiceGroup(ControlItem(iFocused)) |
|
4315 |
&& PhysicsScrolling()) |
|
4316 |
{ |
|
4317 |
ForwardPointerEventToItemL(aPointerEvent); |
|
4318 |
} |
|
4319 |
||
4320 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
|
4321 |
break; |
|
4322 |
} |
|
4323 |
||
4324 |
// EButton1Up |
|
4325 |
case TPointerEvent::EButton1Up: |
|
4326 |
{ |
|
4327 |
// If physics scrolling is ongoing then start flicking |
|
4328 |
// and forward event to the item. |
|
4329 |
if (iPanningOngoing && !iPreventPhysicsScrolling) |
|
4330 |
{ |
|
4331 |
TPoint distance = iStartPosition - aPointerEvent.iPosition; |
|
4332 |
iFlickOngoing = iPhysics->StartFlick(distance, iStartTime); |
|
4333 |
} |
|
4334 |
||
4335 |
// If physics scrolling is not ongoing then only |
|
4336 |
// forward event to the item. |
|
4337 |
if (!iUpEventSent) |
|
4338 |
{ |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4339 |
if (iPointedControl && IsInteractiveGaugeItem(*iPointedControl)) |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4340 |
{ |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4341 |
// In case that pointed control is GaugeItem and |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4342 |
// pointer up happened outside of its bound, |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4343 |
// reset gauge value to original value (from pointer down). |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4344 |
CMIDGaugeItem* gauge = static_cast<CMIDGaugeItem*>(iPointedControl); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4345 |
if (!gauge->Rect().Contains(aPointerEvent.iPosition)) |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4346 |
{ |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4347 |
// To ensure that slider updates its visual appearance |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4348 |
// (i.e. thumb will be displayed as released), |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4349 |
// lets send dummy event with original position. |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4350 |
TPointerEvent newEvent; |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4351 |
newEvent.iType = TPointerEvent::EButton1Up; |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4352 |
newEvent.iPosition = iStartPosition; |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4353 |
ForwardPointerEventToItemL(newEvent); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4354 |
|
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4355 |
// reset value |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4356 |
gauge->SetValueL(iLastGaugeValue); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4357 |
|
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4358 |
// post event to ensure that item state listener is notified |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4359 |
// about change |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4360 |
iEnv->PostJavaEvent(*this, EDisplayable, Index(iPointedControl)); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4361 |
} |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4362 |
else |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4363 |
{ |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4364 |
// Pointer up happened inside of GaugeItem, |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4365 |
// forward pointer event to item. |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4366 |
ForwardPointerEventToItemL(aPointerEvent); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4367 |
} |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4368 |
} |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4369 |
else |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4370 |
{ |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4371 |
ForwardPointerEventToItemL(aPointerEvent); |
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4372 |
} |
66 | 4373 |
iUpEventSent = ETrue; |
4374 |
} |
|
4375 |
||
4376 |
iPanningOngoing = EFalse; |
|
4377 |
iCanDragFocus = EFalse; |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4378 |
iLastPointedControl = KErrNotFound; |
66 | 4379 |
break; |
4380 |
} |
|
4381 |
default: |
|
4382 |
{ |
|
4383 |
ForwardPointerEventToItemL(aPointerEvent); |
|
4384 |
break; |
|
4385 |
} |
|
4386 |
} |
|
4387 |
} |
|
4388 |
else |
|
4389 |
{ |
|
4390 |
IgnoreEventsUntilNextPointerUp(); |
|
4391 |
return; |
|
4392 |
} |
|
4393 |
} |
|
4394 |
||
4395 |
void CMIDForm::ForwardPointerEventToItemL(const TPointerEvent& aPointerEvent) |
|
4396 |
{ |
|
4397 |
if (iPointedControl) |
|
4398 |
{ |
|
4399 |
// Drag events are not forwarded to CustomItem |
|
4400 |
if (!iFlickStoppedOnDownEvent && |
|
4401 |
!(IsCustomItem(*iPointedControl) && aPointerEvent.iType == TPointerEvent::EDrag)) |
|
4402 |
{ |
|
4403 |
if (iFocused != KErrNotFound) |
|
4404 |
{ |
|
83
26b2b12093af
Revision: v2.2.17
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
77
diff
changeset
|
4405 |
ControlItem(iFocused).HandlePointerEventL(aPointerEvent); |
66 | 4406 |
} |
4407 |
||
4408 |
if (LayoutPending()) |
|
4409 |
{ |
|
4410 |
LayoutFormL(); |
|
4411 |
DrawDeferred(); |
|
4412 |
} |
|
4413 |
} |
|
4414 |
||
4415 |
if (aPointerEvent.iType == TPointerEvent::EButton1Up) |
|
4416 |
{ |
|
4417 |
iFocusChangingWithPen = EFalse; |
|
4418 |
} |
|
4419 |
} |
|
4420 |
} |
|
4421 |
||
4422 |
void CMIDForm::HandlePhysicsScroll(TInt aScroll, TBool aDrawNow, TUint /*aFlags*/) |
|
4423 |
{ |
|
4424 |
iScroll = iScroll + aScroll; |
|
4425 |
if (aScroll) |
|
4426 |
{ |
|
4427 |
iHasScrolled = ETrue; |
|
4428 |
} |
|
4429 |
iScrollDelta = aScroll; |
|
4430 |
SetRowPositionsWithRespectToScrolledLocation(); |
|
4431 |
||
4432 |
if (aDrawNow) |
|
4433 |
{ |
|
4434 |
RawScrollFinalize(ETrue, ETrue); |
|
4435 |
DrawNow(); |
|
4436 |
} |
|
4437 |
else |
|
4438 |
{ |
|
4439 |
RawScrollFinalize(ETrue, EFalse); |
|
4440 |
} |
|
4441 |
||
4442 |
#ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
4443 |
//Tactile feedback on dragging/flicking. |
|
4444 |
DoScrollingFeedback(); |
|
4445 |
#endif //RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
4446 |
} |
|
4447 |
||
4448 |
void CMIDForm::PhysicsScrollingEnd() |
|
4449 |
{ |
|
4450 |
iFlickOngoing = EFalse; |
|
4451 |
iPanningOngoing = EFalse; |
|
4452 |
} |
|
4453 |
||
4454 |
TBool CMIDForm::PhysicsEnabled() |
|
4455 |
{ |
|
4456 |
if (iPhysics) |
|
4457 |
{ |
|
4458 |
return ETrue; |
|
4459 |
} |
|
4460 |
else |
|
4461 |
{ |
|
4462 |
return EFalse; |
|
4463 |
} |
|
4464 |
} |
|
4465 |
||
4466 |
TBool CMIDForm::PhysicsScrolling() |
|
4467 |
{ |
|
4468 |
return iFlickOngoing | iPanningOngoing; |
|
4469 |
} |
|
4470 |
||
4471 |
TInt CMIDForm::ScrollDelta() |
|
4472 |
{ |
|
4473 |
return iScrollDelta; |
|
4474 |
} |
|
4475 |
||
4476 |
void CMIDForm::DoFeedbackOnFocusChange(CMIDControlItem& aControlItem) |
|
4477 |
{ |
|
4478 |
//Tapping on StringItem BUTTON should not do feedback, here. |
|
4479 |
//Native class CAknButton does it by itself |
|
4480 |
if (!IsStringItemButton(aControlItem)) |
|
4481 |
{ |
|
4482 |
//Other items should do some feedback |
|
4483 |
#ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
4484 |
if (IsStringItemHyperlink(aControlItem)) |
|
4485 |
{ |
|
4486 |
//if StringItem is HYPERLIK it should give sensitive button feedback |
|
4487 |
iFeedback->InstantFeedback(ETouchFeedbackSensitiveButton); |
|
4488 |
} |
|
4489 |
else if (IsImageItem(aControlItem)) |
|
4490 |
{ |
|
4491 |
//if pointed control is ImageItem, its focusable, it has to be either |
|
4492 |
//HYPERLIK ot BUTTON, so it should give sensitive button feedback |
|
4493 |
iFeedback->InstantFeedback(ETouchFeedbackSensitiveButton); |
|
4494 |
} |
|
4495 |
else if (IsChoiceGroup(aControlItem)) |
|
4496 |
{ |
|
4497 |
//tapping on unfocused ChoiceGroup makes also activation, so it should |
|
4498 |
//give basic list feedback |
|
4499 |
iFeedback->InstantFeedback(ETouchFeedbackList); |
|
4500 |
} |
|
4501 |
else |
|
4502 |
{ |
|
4503 |
//changing focus to other items should give sensitive list feedback |
|
4504 |
iFeedback->InstantFeedback(ETouchFeedbackSensitiveList); |
|
4505 |
} |
|
4506 |
#else |
|
4507 |
iFeedback->InstantFeedback(ETouchFeedbackBasic); |
|
4508 |
#endif //RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
4509 |
} |
|
4510 |
} |
|
4511 |
||
4512 |
#ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
4513 |
void CMIDForm::UpdateTactileFeedbackDensity() |
|
4514 |
{ |
|
4515 |
TAknLayoutRect layoutRect; |
|
4516 |
layoutRect.LayoutRect(TRect(), AknLayoutScalable_Avkon:: |
|
4517 |
list_single_heading_pane(0).LayoutLine()); |
|
4518 |
iTactileFeedbackDensity = layoutRect.Rect().Height(); |
|
4519 |
} |
|
4520 |
||
4521 |
void CMIDForm::DoScrollingFeedback() |
|
4522 |
{ |
|
4523 |
TRect formRect(Rect()); |
|
4524 |
TInt topEdgePos = iScroll; |
|
4525 |
TInt bottomEdgePos = iScroll + HeightOfAllItems(); |
|
4526 |
// Calculate distance between current Form content position |
|
4527 |
// and previous position, where last feedback happened. |
|
4528 |
TInt lastFeedbackDistanceY = Abs(iLastTactileFeedbackPos - iScroll); |
|
4529 |
TTouchLogicalFeedback feedbackType(ETouchFeedbackNone); |
|
4530 |
if (lastFeedbackDistanceY >= iTactileFeedbackDensity) |
|
4531 |
{ |
|
4532 |
if ((topEdgePos < formRect.iTl.iY) |
|
4533 |
&& (bottomEdgePos > formRect.iBr.iY)) |
|
4534 |
{ |
|
4535 |
// If top (or bottom) edge of the content is outside |
|
4536 |
// of visible area of Form, do feedback every time. |
|
4537 |
feedbackType = ETouchFeedbackSensitiveList; |
|
4538 |
} |
|
4539 |
else if (iLastPointerEventType != TPointerEvent::EButton1Up) |
|
4540 |
{ |
|
4541 |
// Begining or end of the content reached (i.e. top or bottom |
|
4542 |
// egde of the contont is now visible): feedback is given |
|
4543 |
// only if user do panning. No feedback, if touch release |
|
4544 |
// happened. |
|
4545 |
feedbackType = ETouchFeedbackSensitiveList; |
|
4546 |
} |
|
4547 |
// Store the position of the content. |
|
4548 |
iLastTactileFeedbackPos = iScroll; |
|
4549 |
} |
|
4550 |
||
4551 |
if (iFeedback && feedbackType != ETouchFeedbackNone) |
|
4552 |
{ |
|
4553 |
if (iLastPointerEventType != TPointerEvent::EButton1Up) |
|
4554 |
{ |
|
4555 |
iFeedback->EnableFeedbackForControl(this, ETrue, ETrue); |
|
4556 |
} |
|
4557 |
else |
|
4558 |
{ |
|
4559 |
// Disable audion feedback on flicking (i.e. user don't pan by |
|
4560 |
// touch input). |
|
4561 |
iFeedback->EnableFeedbackForControl(this, ETrue, EFalse); |
|
4562 |
} |
|
4563 |
// Do the feedback if needed. |
|
4564 |
iFeedback->InstantFeedback(this, feedbackType); |
|
4565 |
} |
|
4566 |
} |
|
4567 |
#endif //RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
4568 |