|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <ganes/HgScroller.h> |
|
21 |
|
22 #include <aknphysics.h> |
|
23 |
|
24 #include <ganes/HgScrollBufferObserverIface.h> |
|
25 #include <ganes/HgSelectionObserverIface.h> |
|
26 #include <ganes/HgMarkingObserverIface.h> |
|
27 #include <ganes/HgItem.h> |
|
28 #include "HgScrollbar.h" |
|
29 #include "HgScrollBufferManager.h" |
|
30 #include "HgConstants.h" |
|
31 #include "HgPopupDrawer.h" |
|
32 #include "HgMarquee.h" |
|
33 #include "HgDrawUtils.h" |
|
34 #include "HgIndicatorManager.h" |
|
35 #include "HgTextFind.h" |
|
36 #include "HgKeyUtils.h" |
|
37 |
|
38 #include <ganes.mbg> |
|
39 |
|
40 #include <AknIconUtils.h> |
|
41 #include <avkon.mbg> |
|
42 #include <AknsDrawUtils.h> |
|
43 #include <touchfeedback.h> |
|
44 #include <gulicon.h> |
|
45 #include <AknUtils.h> |
|
46 #include <layoutmetadata.cdl.h> |
|
47 #include <AknLayout2ScalableDef.h> |
|
48 #include <aknitemactionmenu.h> |
|
49 #include <aknappui.h> |
|
50 |
|
51 #include <featdiscovery.h> |
|
52 |
|
53 const TInt KIntensity = 50; // 50% |
|
54 |
|
55 // ============================ MEMBER FUNCTIONS =============================== |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CHgScroller::ConstructL() |
|
59 // Symbian 2nd phase constructor can leave. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 void CHgScroller::ConstructL (const TRect& aRect, RWsSession* aSession ) |
|
63 { |
|
64 // Create a window for this application view |
|
65 CreateWindowL ( ); |
|
66 EnableDragEvents(); |
|
67 ClaimPointerGrab(); |
|
68 |
|
69 iUpperCaseTitle.CreateL( KMaxSearchLenght ); |
|
70 iPopupText1.CreateL( KMaxPopupTextLength ); |
|
71 iPopupText2.CreateL( KMaxPopupTextLength ); |
|
72 |
|
73 iScrollbar = CHgScrollbar::NewL(*this); |
|
74 iPopupDrawer = new (ELeave) THgPopupDrawer(); |
|
75 |
|
76 TCallBack callback(CHgScroller::MarqueeCallback, this); |
|
77 iDrawUtils = CHgDrawUtils::NewL( callback ); |
|
78 |
|
79 iIndicatorManager = CHgIndicatorManager::NewL(); |
|
80 |
|
81 /* |
|
82 * TODO: Vasco says it supports qwerty, so the variation cannot be done. |
|
83 * Commented out for the time being to fix a crash. |
|
84 // Enable key search only in non-touch or hybrid (touch + qwerty) devices |
|
85 if( !AknLayoutUtils::PenEnabled() || |
|
86 CFeatureDiscovery::IsFeatureSupportedL(TUid::Uid(KFeatureIdQwertyInput)) ) |
|
87 { |
|
88 iTextFind = CHgTextFind::NewL( *this ); |
|
89 iKeyUtils = CHgKeyUtils::NewL(*this); |
|
90 } |
|
91 */ |
|
92 |
|
93 // Init Stuff |
|
94 if( aSession ) |
|
95 { |
|
96 InitScreenL( aRect, *aSession ); |
|
97 } |
|
98 else |
|
99 { |
|
100 InitScreenL( aRect ); |
|
101 } |
|
102 |
|
103 iHighlightTimer = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
104 iKeyScrollingTimer = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
105 |
|
106 CAknAppUi* appUi = static_cast<CAknAppUi*>(iEikonEnv->AppUi()); |
|
107 if( appUi && appUi->IsSingleClickCompatible() ) |
|
108 { |
|
109 iDetector = CAknLongTapDetector::NewL(this); |
|
110 iActionMenu = CAknItemActionMenu::RegisterCollectionL(*this); |
|
111 } |
|
112 |
|
113 iDrawUtils->EnableMarquee(HasHighlight()); |
|
114 |
|
115 InitItemsL(); |
|
116 |
|
117 iCoeEnv->AddForegroundObserverL( *this ); |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CHgScroller::InputCapabilities() |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 TCoeInputCapabilities CHgScroller::InputCapabilities() const |
|
125 { |
|
126 TCoeInputCapabilities cap( TCoeInputCapabilities::ENone ); |
|
127 |
|
128 if(iTextFind) |
|
129 { |
|
130 MCoeFepAwareTextEditor* editor = NULL; |
|
131 |
|
132 if( iSelectionMode == ENoSelection |
|
133 && iFlags & EHgScrollerSearchWithQWERTY ) |
|
134 editor = iTextFind; |
|
135 |
|
136 cap = TCoeInputCapabilities( TCoeInputCapabilities::EAllText, |
|
137 editor, |
|
138 NULL ); |
|
139 |
|
140 cap.SetObjectProvider( const_cast<CHgScroller*>(this) ); |
|
141 } |
|
142 |
|
143 return cap; |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CHgScroller::InitScreenL() |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 EXPORT_C void CHgScroller::InitScreenL( const TRect& /*aRect*/, RWsSession& /*aSession*/ ) |
|
151 { |
|
152 // DSA not supported anymore. |
|
153 User::Leave( KErrNotSupported ); |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // CHgScroller::InitScreenL() |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 EXPORT_C void CHgScroller::InitScreenL( const TRect& aRect ) |
|
161 { |
|
162 // Set the windows size |
|
163 SetRect ( aRect ); |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CHgScroller::RefreshScreen() |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 EXPORT_C void CHgScroller::RefreshScreen( TInt aIndex ) |
|
171 { |
|
172 if( IsDisplayed( aIndex ) ) |
|
173 DrawDeferred(); |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CHgScroller::RefreshScreen() |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 EXPORT_C TInt CHgScroller::FirstIndexOnScreen() |
|
181 { |
|
182 return CurrentIndex(); |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CHgScroller::RefreshScreen() |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 EXPORT_C TInt CHgScroller::ItemsOnScreen() |
|
190 { |
|
191 return iItemsOnScreen; |
|
192 } |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // CHgScroller::RefreshScreen() |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 EXPORT_C TInt CHgScroller::SelectedIndex() |
|
199 { |
|
200 return iSelectedIndex; |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CHgScroller::RefreshScreen() |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 EXPORT_C void CHgScroller::SetSelectedIndex( TInt aIndex ) |
|
208 { |
|
209 if( aIndex >= 0 && aIndex < iItems.Count() ) |
|
210 { |
|
211 iSelectedIndex = aIndex; |
|
212 // Move view position so that it is fully visible. |
|
213 FitSelectionToView(); |
|
214 SelectionChanged(); |
|
215 } |
|
216 } |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // CHgScroller::Mark() |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 EXPORT_C void CHgScroller::Mark( TInt aIndex ) |
|
223 { |
|
224 if( aIndex >= 0 && aIndex < iItems.Count() ) |
|
225 { |
|
226 if( !(iItems[aIndex]->Flags() & CHgItem::EHgItemFlagMarked) ) |
|
227 { |
|
228 iItems[aIndex]->SetFlags( CHgItem::EHgItemFlagMarked ); |
|
229 if( iMarkingObserver ) |
|
230 { |
|
231 TRAP_IGNORE( iMarkingObserver->HandleMarkingL( aIndex, ETrue ) ); |
|
232 } |
|
233 } |
|
234 } |
|
235 } |
|
236 |
|
237 // ----------------------------------------------------------------------------- |
|
238 // CHgScroller::UnMark() |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 EXPORT_C void CHgScroller::UnMark( TInt aIndex ) |
|
242 { |
|
243 if( aIndex >= 0 && aIndex < iItems.Count() ) |
|
244 { |
|
245 if( iItems[aIndex]->Flags() & CHgItem::EHgItemFlagMarked ) |
|
246 { |
|
247 iItems[aIndex]->ClearFlags( CHgItem::EHgItemFlagMarked ); |
|
248 if( iMarkingObserver ) |
|
249 { |
|
250 TRAP_IGNORE( iMarkingObserver->HandleMarkingL( aIndex, EFalse ) ); |
|
251 } |
|
252 } |
|
253 } |
|
254 } |
|
255 |
|
256 // ----------------------------------------------------------------------------- |
|
257 // CHgScroller::MarkAll() |
|
258 // ----------------------------------------------------------------------------- |
|
259 // |
|
260 EXPORT_C void CHgScroller::MarkAll() |
|
261 { |
|
262 for(TInt i = 0; i < iItems.Count(); ++i) |
|
263 { |
|
264 iItems[i]->SetFlags( CHgItem::EHgItemFlagMarked ); |
|
265 } |
|
266 |
|
267 DrawDeferred(); |
|
268 } |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CHgScroller::UnMarkAll() |
|
272 // ----------------------------------------------------------------------------- |
|
273 // |
|
274 EXPORT_C void CHgScroller::UnMarkAll() |
|
275 { |
|
276 for(TInt i = 0; i < iItems.Count(); ++i) |
|
277 { |
|
278 iItems[i]->ClearFlags(CHgItem::EHgItemFlagMarked); |
|
279 } |
|
280 |
|
281 DrawDeferred(); |
|
282 } |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 // CHgScroller::GetMarkedItemsL() |
|
286 // ----------------------------------------------------------------------------- |
|
287 // |
|
288 EXPORT_C void CHgScroller::GetMarkedItemsL( RArray<TInt>& aIndexes ) |
|
289 { |
|
290 for(TInt i = 0; i < iItems.Count(); ++i) |
|
291 { |
|
292 if(iItems[i]->Flags() & CHgItem::EHgItemFlagMarked ) |
|
293 { |
|
294 aIndexes.AppendL( i ); |
|
295 } |
|
296 } |
|
297 } |
|
298 |
|
299 // ----------------------------------------------------------------------------- |
|
300 // CHgScroller::EnableScrollBufferL() |
|
301 // ----------------------------------------------------------------------------- |
|
302 // |
|
303 EXPORT_C void CHgScroller::EnableScrollBufferL( |
|
304 MHgScrollBufferObserver& aObserver, |
|
305 TInt aBufferSize, |
|
306 TInt aBufferTreshold ) |
|
307 { |
|
308 delete iManager; iManager = NULL; |
|
309 |
|
310 iManager = CHgScrollBufferManager::NewL( |
|
311 aObserver, |
|
312 aBufferSize, |
|
313 aBufferTreshold, |
|
314 CurrentIndex(), |
|
315 iItemCount); |
|
316 |
|
317 iManager->SetBufferOwner( *this ); |
|
318 } |
|
319 |
|
320 // ----------------------------------------------------------------------------- |
|
321 // CHgScroller::EnableNaviStripL() |
|
322 // ----------------------------------------------------------------------------- |
|
323 // |
|
324 EXPORT_C void CHgScroller::SetScrollBarTypeL( THgScrollBarType aType ) |
|
325 { |
|
326 iScrollBarType = aType; |
|
327 DrawDeferred(); |
|
328 } |
|
329 |
|
330 // ----------------------------------------------------------------------------- |
|
331 // CHgScroller::SetSelectionObserver() |
|
332 // ----------------------------------------------------------------------------- |
|
333 // |
|
334 EXPORT_C void CHgScroller::SetSelectionObserver( MHgSelectionObserver& aObserver ) |
|
335 { |
|
336 iSelectionObserver = &aObserver; |
|
337 } |
|
338 |
|
339 // ----------------------------------------------------------------------------- |
|
340 // CHgScroller::SetMarkingObserver() |
|
341 // ----------------------------------------------------------------------------- |
|
342 // |
|
343 EXPORT_C void CHgScroller::SetMarkingObserver( MHgMarkingObserver& aObserver ) |
|
344 { |
|
345 iMarkingObserver = &aObserver; |
|
346 } |
|
347 |
|
348 // ----------------------------------------------------------------------------- |
|
349 // CHgScroller::CHgScroller() |
|
350 // C++ default constructor can NOT contain any code, that might leave. |
|
351 // ----------------------------------------------------------------------------- |
|
352 // |
|
353 CHgScroller::CHgScroller( |
|
354 TInt aItemCount, |
|
355 CGulIcon* aDefaultIcon ) |
|
356 : iDefaultIcon( aDefaultIcon ), |
|
357 iItemCount(aItemCount), |
|
358 iCurrentRow(-1), |
|
359 iSelectedIndex(KErrNotFound), |
|
360 iScrollBarType( EHgScrollerScrollBar ), |
|
361 iFirstTime(ETrue) |
|
362 { |
|
363 // No implementation required |
|
364 } |
|
365 |
|
366 // ----------------------------------------------------------------------------- |
|
367 // CHgScroller::~CHgScroller() |
|
368 // Destructor. |
|
369 // ----------------------------------------------------------------------------- |
|
370 // |
|
371 EXPORT_C CHgScroller::~CHgScroller ( ) |
|
372 { |
|
373 iCoeEnv->RemoveForegroundObserver( *this ); |
|
374 |
|
375 iItems.ResetAndDestroy(); |
|
376 |
|
377 delete iManager; |
|
378 delete iPhysics; |
|
379 delete iScrollbar; |
|
380 delete iEmptyText; |
|
381 delete iDefaultIcon; |
|
382 delete iPopupDrawer; |
|
383 delete iDrawUtils; |
|
384 delete iHighlightTimer; |
|
385 delete iIndicatorManager; |
|
386 delete iKeyUtils; |
|
387 delete iTextFind; |
|
388 delete iKeyScrollingTimer; |
|
389 delete iDetector; |
|
390 |
|
391 if(iActionMenu) |
|
392 iActionMenu->RemoveCollection(*this); |
|
393 |
|
394 iUpperCaseTitle.Close(); |
|
395 iPopupText1.Close(); |
|
396 iPopupText2.Close(); |
|
397 |
|
398 } |
|
399 |
|
400 // ----------------------------------------------------------------------------- |
|
401 // CHgScroller::InitPhysicsL() |
|
402 // ----------------------------------------------------------------------------- |
|
403 // |
|
404 void CHgScroller::InitPhysicsL() |
|
405 { |
|
406 if(!iPhysics) |
|
407 { |
|
408 iPhysics = CAknPhysics::NewL(*this, this); |
|
409 } |
|
410 |
|
411 // For to be able to pan on a empty area. |
|
412 // The world is set to be at least the size of the view. |
|
413 TSize worldSize = TotalSize(); |
|
414 |
|
415 if( !iLandscapeScrolling && (worldSize.iHeight < iHeight) ) |
|
416 worldSize.iHeight = iHeight; |
|
417 |
|
418 if( iLandscapeScrolling && (worldSize.iWidth < iWidth) ) |
|
419 worldSize.iWidth = iWidth; |
|
420 |
|
421 iPhysics->InitPhysicsL( worldSize, |
|
422 TSize(iWidth, iHeight), |
|
423 iLandscapeScrolling); |
|
424 } |
|
425 |
|
426 // ----------------------------------------------------------------------------- |
|
427 // CHgGrid::Draw() |
|
428 // Draws the display. |
|
429 // ----------------------------------------------------------------------------- |
|
430 // |
|
431 void CHgScroller::Draw ( const TRect& aRect ) const |
|
432 { |
|
433 CWindowGc& gc = SystemGc(); |
|
434 |
|
435 // Flush screen buffer |
|
436 InitDrawBuffer(); |
|
437 |
|
438 DoDraw( aRect ); |
|
439 |
|
440 if( iScrollbar && iItemCount ) |
|
441 { |
|
442 iScrollbar->Draw( gc ); |
|
443 } |
|
444 |
|
445 if( iPopupDrawer ) |
|
446 { |
|
447 if(iPopupText2.Length() > 0) |
|
448 { |
|
449 iPopupDrawer->Draw( gc, |
|
450 iPopupText1, |
|
451 iPopupText2 |
|
452 ); |
|
453 } |
|
454 else if( iPopupText1.Length( ) > 0 ) |
|
455 { |
|
456 if( iScrollBarType == EHgScrollerLetterStrip |
|
457 || iScrollBarType == EHgScrollerLetterStripLite ) |
|
458 { |
|
459 iPopupDrawer->DrawNaviChar( gc, iPopupText1 ); |
|
460 } |
|
461 else |
|
462 { |
|
463 iPopupDrawer->Draw( gc, iPopupText1 ); |
|
464 } |
|
465 } |
|
466 else if( iTextFind && iTextFind->Text().Length() > 0 ) |
|
467 { |
|
468 iPopupDrawer->Draw( gc, iTextFind->Text() ); |
|
469 } |
|
470 } |
|
471 } |
|
472 |
|
473 // ----------------------------------------------------------------------------- |
|
474 // CHgScroller::InitDrawBuffer() |
|
475 // ----------------------------------------------------------------------------- |
|
476 // |
|
477 void CHgScroller::InitDrawBuffer() const |
|
478 { |
|
479 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
480 MAknsControlContext* cc = AknsDrawUtils::ControlContext( this ); |
|
481 AknsDrawUtils::DrawBackground( skin, cc, this, SystemGc(), |
|
482 TPoint(0,0), Rect(), KAknsDrawParamDefault ); |
|
483 } |
|
484 |
|
485 // ----------------------------------------------------------------------------- |
|
486 // CHgScroller::SizeChanged() |
|
487 // Called by framework when the view size is changed. |
|
488 // ----------------------------------------------------------------------------- |
|
489 // |
|
490 void CHgScroller::SizeChanged ( ) |
|
491 { |
|
492 iWidth = Rect().Width(); |
|
493 iHeight = Rect().Height(); |
|
494 |
|
495 HandleItemCountChanged(); |
|
496 |
|
497 if( iPopupDrawer ) |
|
498 { |
|
499 iPopupDrawer->Init( Rect(), |
|
500 &ScreenFont( TCoeFont( KFocusTextFontSize, TCoeFont::EPlain ) ) ); |
|
501 } |
|
502 |
|
503 if(iFirstTime) |
|
504 { |
|
505 iViewPosition = TPoint(iWidth/2, iHeight/2); |
|
506 iFirstTime = EFalse; |
|
507 } |
|
508 |
|
509 HandleViewPositionChanged(); |
|
510 |
|
511 TRAP_IGNORE( InitGraphicsL(); ) |
|
512 DrawDeferred ( ); |
|
513 } |
|
514 |
|
515 // ----------------------------------------------------------------------------- |
|
516 // CHgScroller::HandleItemCountChaged() |
|
517 // ----------------------------------------------------------------------------- |
|
518 // |
|
519 void CHgScroller::HandleItemCountChanged() |
|
520 { |
|
521 HandleSizeChanged(); |
|
522 |
|
523 if( iSelectedIndex >= iItemCount ) |
|
524 { |
|
525 iSelectedIndex = iItemCount - 1; |
|
526 SelectionChanged(); |
|
527 } |
|
528 |
|
529 TRAP_IGNORE ( |
|
530 InitScrollbarL(); |
|
531 InitPhysicsL(); |
|
532 ) |
|
533 } |
|
534 |
|
535 // ----------------------------------------------------------------------------- |
|
536 // CHgScroller::InitScrollbarL() |
|
537 // ----------------------------------------------------------------------------- |
|
538 // |
|
539 void CHgScroller::InitScrollbarL() |
|
540 { |
|
541 if( iScrollbar && iItemCount ) |
|
542 { |
|
543 iScrollbar->InitScrollBarL( Rect(), |
|
544 TotalSize(), |
|
545 TSize(iWidth, iHeight), |
|
546 iLandscapeScrolling); |
|
547 |
|
548 iScrollbar->SetViewPosition( iViewPosition - TPoint(iWidth/2, iHeight/2)); |
|
549 } |
|
550 } |
|
551 // ----------------------------------------------------------------------------- |
|
552 // CHgScroller::HandlePointerEventL() |
|
553 // ----------------------------------------------------------------------------- |
|
554 // |
|
555 void CHgScroller::HandlePointerEventL( const TPointerEvent& aEvent ) |
|
556 { |
|
557 if( !HandleScrollbarEventL( aEvent ) && iItemCount ) |
|
558 { |
|
559 iShowHighlight = EFalse; |
|
560 |
|
561 // Start drag |
|
562 if( aEvent.iType == TPointerEvent::EButton1Down ) |
|
563 { |
|
564 iPointerDown = ETrue; |
|
565 HandleDownEventL( aEvent ); |
|
566 |
|
567 if( iDetector |
|
568 && iSelectedIndex != KErrNotFound |
|
569 && !HasHighlight() |
|
570 && iActionMenu->InitMenuL() ) |
|
571 iDetector->PointerEventL( aEvent ); |
|
572 } |
|
573 // Drag |
|
574 else if( aEvent.iType == TPointerEvent::EDrag && iPointerDown ) |
|
575 { |
|
576 HandleDragEventL( aEvent ); |
|
577 |
|
578 if( iPanning && iDetector && !HasHighlight() ) |
|
579 iDetector->CancelAnimationL(); |
|
580 } |
|
581 // End drag |
|
582 else if( aEvent.iType == TPointerEvent::EButton1Up && iPointerDown ) |
|
583 { |
|
584 if( iDetector && !HasHighlight() ) |
|
585 iDetector->PointerEventL( aEvent ); |
|
586 |
|
587 HandleUpEventL( aEvent ); |
|
588 iPointerDown = EFalse; |
|
589 } |
|
590 } |
|
591 } |
|
592 |
|
593 // ----------------------------------------------------------------------------- |
|
594 // CHgScroller::HandleScrollbarEventL() |
|
595 // ----------------------------------------------------------------------------- |
|
596 // |
|
597 TBool CHgScroller::HandleScrollbarEventL( const TPointerEvent& aEvent ) |
|
598 { |
|
599 TBool sbHandles = EFalse; |
|
600 if( iScrollbar ) |
|
601 { |
|
602 sbHandles = iScrollbar->HandlePointerEventL( aEvent ); |
|
603 if ( sbHandles && !iScrollbar->IsStatic() ) |
|
604 { |
|
605 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
606 // Start drag |
|
607 if( aEvent.iType == TPointerEvent::EButton1Down ) |
|
608 { |
|
609 if ( feedback ) |
|
610 { |
|
611 feedback->InstantFeedback( this, ETouchFeedbackSlider, aEvent ); |
|
612 } |
|
613 } |
|
614 // Drag |
|
615 else if( aEvent.iType == TPointerEvent::EDrag |
|
616 && iScrollbar->IsDragging() ) |
|
617 { |
|
618 // Smooth continuous tactile feedback is produced |
|
619 // during thumb dragging. The tactile feedback API |
|
620 // filters out possible re-startings of the effect. |
|
621 if ( feedback ) |
|
622 { |
|
623 TTimeIntervalMicroSeconds32 timeout( 300000 ); |
|
624 feedback->StartFeedback( this, |
|
625 ETouchContinuousSlider, |
|
626 &aEvent, |
|
627 KIntensity, // intensity 50% |
|
628 timeout ); |
|
629 } |
|
630 } |
|
631 // End drag |
|
632 else if( aEvent.iType == TPointerEvent::EButton1Up ) |
|
633 { |
|
634 // Stop the continuous tactile feedback that may be playing |
|
635 // at the time due to possible previous thumb dragging. |
|
636 if ( feedback ) |
|
637 { |
|
638 feedback->StopFeedback( this ); |
|
639 TTouchFeedbackType type = ETouchFeedbackVibra; |
|
640 feedback->InstantFeedback( this, ETouchFeedbackSlider, type, aEvent ); |
|
641 } |
|
642 iPopupText1.Zero(); |
|
643 iPopupText2.Zero(); |
|
644 DrawDeferred(); |
|
645 } |
|
646 } |
|
647 } |
|
648 return sbHandles; |
|
649 } |
|
650 |
|
651 // ----------------------------------------------------------------------------- |
|
652 // CHgScroller::HandleDownEventL() |
|
653 // ----------------------------------------------------------------------------- |
|
654 // |
|
655 void CHgScroller::HandleDownEventL( const TPointerEvent& aEvent ) |
|
656 { |
|
657 if( !HasHighlight() |
|
658 && (iPhysics->OngoingPhysicsAction() == CAknPhysics::EAknPhysicsActionFlicking) ) |
|
659 { |
|
660 iPanning = ETrue; |
|
661 if(iDetector) |
|
662 iDetector->CancelAnimationL(); |
|
663 } |
|
664 else |
|
665 { |
|
666 iPanning = EFalse; |
|
667 } |
|
668 |
|
669 iPhysics->StopPhysics(); |
|
670 iPhysics->ResetFriction(); |
|
671 |
|
672 iStart = aEvent.iPosition; |
|
673 iPrev = iStart; |
|
674 iStartTime.HomeTime(); |
|
675 |
|
676 if(iLandscapeScrolling) |
|
677 iViewPosition.iY = iHeight / 2; |
|
678 else |
|
679 iViewPosition.iX = iWidth / 2; |
|
680 |
|
681 iFocusedIndex = KErrNotFound; |
|
682 iSelectionToFocusedItem = EFalse; |
|
683 iDrawUtils->EnableMarquee(HasHighlight()); |
|
684 if(HasHighlight()) |
|
685 { |
|
686 LaunchHighlightTimer(); |
|
687 } |
|
688 else if( !iPanning ) |
|
689 { |
|
690 SetHighlightL(); |
|
691 } |
|
692 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
693 if ( feedback && iSelectedIndex != KErrNotFound ) |
|
694 { |
|
695 feedback->InstantFeedback( this, ETouchFeedbackList, aEvent ); |
|
696 } |
|
697 } |
|
698 |
|
699 // ----------------------------------------------------------------------------- |
|
700 // CHgScroller::HandleDragEventL() |
|
701 // ----------------------------------------------------------------------------- |
|
702 // |
|
703 void CHgScroller::HandleDragEventL( const TPointerEvent& aEvent ) |
|
704 { |
|
705 if(!iPanning) |
|
706 { |
|
707 TInt delta = 0; |
|
708 if(iLandscapeScrolling) |
|
709 { |
|
710 delta = iPrev.iX - aEvent.iPosition.iX; |
|
711 } |
|
712 else |
|
713 { |
|
714 delta = iPrev.iY - aEvent.iPosition.iY; |
|
715 } |
|
716 |
|
717 delta = delta < 0 ? -delta : delta; |
|
718 iPanning = delta >= iPhysics->DragThreshold(); |
|
719 } |
|
720 |
|
721 if(iPanning) |
|
722 { |
|
723 TPoint delta = iPrev - aEvent.iPosition; |
|
724 if(iLandscapeScrolling && AknLayoutUtils::LayoutMirrored()) |
|
725 delta = -delta; |
|
726 iPhysics->RegisterPanningPosition( delta ); |
|
727 iPrev = aEvent.iPosition; |
|
728 iHighlightTimer->Cancel(); |
|
729 } |
|
730 } |
|
731 |
|
732 // ----------------------------------------------------------------------------- |
|
733 // CHgScroller::HandleUpEventL() |
|
734 // ----------------------------------------------------------------------------- |
|
735 // |
|
736 void CHgScroller::HandleUpEventL( const TPointerEvent& aEvent ) |
|
737 { |
|
738 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
739 TTouchFeedbackType type = ETouchFeedbackVibra; |
|
740 if( iPanning ) |
|
741 { |
|
742 // enable physics |
|
743 TPoint drag = iStart - aEvent.iPosition; |
|
744 if(iLandscapeScrolling && AknLayoutUtils::LayoutMirrored()) |
|
745 drag = -drag; |
|
746 iPhysics->StartPhysics(drag, iStartTime); |
|
747 if ( feedback && iPhysics->OngoingPhysicsAction() == CAknPhysics::EAknPhysicsActionFlicking ) |
|
748 { |
|
749 feedback->InstantFeedback( this, ETouchFeedbackFlick, type, aEvent ); |
|
750 } |
|
751 } |
|
752 else |
|
753 { |
|
754 HandleSelectionL(); |
|
755 if ( feedback && iSelectedIndex != KErrNotFound ) |
|
756 { |
|
757 feedback->InstantFeedback( this, ETouchFeedbackList, type, aEvent ); |
|
758 } |
|
759 } |
|
760 } |
|
761 |
|
762 // ----------------------------------------------------------------------------- |
|
763 // CHgScroller::HandleSelectionL() |
|
764 // ----------------------------------------------------------------------------- |
|
765 // |
|
766 void CHgScroller::HandleSelectionL() |
|
767 { |
|
768 TInt index = GetSelected(iStart); |
|
769 if(index != KErrNotFound) |
|
770 { |
|
771 if( iFocusedIndex == KErrNotFound ) |
|
772 { |
|
773 // Highlight timer hasn't triggered so lets set the highlight. |
|
774 // this is not usually the case since interval is 50ms but just to be sure. |
|
775 SetHighlightL(); |
|
776 } |
|
777 |
|
778 if( iFlags & EHgScrollerSelectionMode || iSelectionMode != ENoSelection ) |
|
779 // Marking mode or shift key pressed ( or hash ) |
|
780 { |
|
781 if( iItems[iSelectedIndex]->Flags() & CHgItem::EHgItemFlagMarked ) |
|
782 { |
|
783 UnMark( iSelectedIndex ); |
|
784 } |
|
785 else |
|
786 { |
|
787 Mark( iSelectedIndex ); |
|
788 } |
|
789 DrawDeferred(); |
|
790 } |
|
791 else // Selection |
|
792 { |
|
793 if( iSelectionToFocusedItem || !HasHighlight() ) |
|
794 { |
|
795 if(iSelectionObserver) |
|
796 iSelectionObserver->HandleOpenL(iSelectedIndex); |
|
797 } |
|
798 } |
|
799 } |
|
800 } |
|
801 |
|
802 // ----------------------------------------------------------------------------- |
|
803 // CHgScroller::OfferKeyEventL() |
|
804 // ----------------------------------------------------------------------------- |
|
805 // |
|
806 TKeyResponse CHgScroller::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
807 { |
|
808 if( iKeyUtils |
|
809 && !(iFlags & EHgScrollerKeyMarkingDisabled) |
|
810 && iKeyUtils->OfferKeyEventL( aKeyEvent, aType ) == EKeyWasConsumed ) |
|
811 return EKeyWasConsumed; |
|
812 |
|
813 switch( aType ) |
|
814 { |
|
815 case EEventKeyDown: |
|
816 KeyEventDown(); |
|
817 break; |
|
818 case EEventKey: |
|
819 return HandleKeyEvent( aKeyEvent ); |
|
820 case EEventKeyUp: |
|
821 KeyEventUp(); |
|
822 default: |
|
823 break; |
|
824 } |
|
825 |
|
826 // Let CCoeControl handle other cases. |
|
827 return CCoeControl::OfferKeyEventL( aKeyEvent, aType ); |
|
828 } |
|
829 |
|
830 // ----------------------------------------------------------------------------- |
|
831 // CHgScroller::KeyEventDown() |
|
832 // ----------------------------------------------------------------------------- |
|
833 // |
|
834 void CHgScroller::KeyEventDown() |
|
835 { |
|
836 iKeyRepeats = 0; |
|
837 iKeyScrollingState = ENoKeyScrolling; |
|
838 |
|
839 iPointerDown = EFalse; |
|
840 iPanning = EFalse; |
|
841 iShowHighlight = ETrue; |
|
842 iDrawUtils->EnableMarquee(HasHighlight()); |
|
843 } |
|
844 |
|
845 // ----------------------------------------------------------------------------- |
|
846 // CHgScroller::KeyEventUp() |
|
847 // ----------------------------------------------------------------------------- |
|
848 // |
|
849 void CHgScroller::KeyEventUp() |
|
850 { |
|
851 if( iKeyScrollingState != ENoKeyScrolling ) |
|
852 { |
|
853 // Key has been released so stop the key scrolling. |
|
854 StopKeyScrolling(); |
|
855 } |
|
856 } |
|
857 |
|
858 // ----------------------------------------------------------------------------- |
|
859 // CHgScroller::SetItem() |
|
860 // ----------------------------------------------------------------------------- |
|
861 // |
|
862 EXPORT_C void CHgScroller::SetItem(CHgItem* aItem, TInt aIndex) |
|
863 { |
|
864 if( aItem && aIndex >= 0 && aIndex < iItems.Count() ) |
|
865 { |
|
866 delete iItems[aIndex]; |
|
867 iItems[aIndex] = aItem; |
|
868 } |
|
869 } |
|
870 |
|
871 // ----------------------------------------------------------------------------- |
|
872 // CHgScroller::AddItem() |
|
873 // ----------------------------------------------------------------------------- |
|
874 // |
|
875 EXPORT_C void CHgScroller::AddItem(CHgItem* aItem) |
|
876 { |
|
877 if( aItem ) |
|
878 { |
|
879 iItems.Append(aItem); |
|
880 iItemCount++; |
|
881 HandleItemCountChanged(); |
|
882 if( iManager ) |
|
883 { |
|
884 iManager->ItemCountChanged( iItemCount-1, EFalse, iItemCount ); |
|
885 } |
|
886 } |
|
887 } |
|
888 |
|
889 // ----------------------------------------------------------------------------- |
|
890 // CHgScroller::InsertItem() |
|
891 // ----------------------------------------------------------------------------- |
|
892 // |
|
893 EXPORT_C void CHgScroller::InsertItem(CHgItem* aItem, TInt aIndex) |
|
894 { |
|
895 if( aItem && aIndex >= 0 ) |
|
896 { |
|
897 if(aIndex < iItems.Count()) |
|
898 { |
|
899 iItems.Insert(aItem, aIndex); |
|
900 } |
|
901 else |
|
902 { |
|
903 iItems.Append(aItem); |
|
904 } |
|
905 iItemCount++; |
|
906 HandleItemCountChanged(); |
|
907 |
|
908 if( iManager ) |
|
909 { |
|
910 iManager->ItemCountChanged( aIndex, EFalse, iItemCount ); |
|
911 } |
|
912 } |
|
913 } |
|
914 |
|
915 // ----------------------------------------------------------------------------- |
|
916 // CHgScroller::RemoveItem() |
|
917 // ----------------------------------------------------------------------------- |
|
918 // |
|
919 EXPORT_C void CHgScroller::RemoveItem(TInt aIndex) |
|
920 { |
|
921 if( aIndex >= 0 && aIndex < iItems.Count() ) |
|
922 { |
|
923 delete iItems[aIndex]; iItems[aIndex] = NULL; |
|
924 iItems.Remove(aIndex); |
|
925 iItemCount--; |
|
926 HandleItemCountChanged(); |
|
927 |
|
928 if( iManager ) |
|
929 { |
|
930 iManager->ItemCountChanged( aIndex, ETrue, iItemCount ); |
|
931 } |
|
932 } |
|
933 } |
|
934 |
|
935 // ----------------------------------------------------------------------------- |
|
936 // CHgScroller::ResizeL() |
|
937 // ----------------------------------------------------------------------------- |
|
938 // |
|
939 EXPORT_C void CHgScroller::ResizeL( TInt aItemCount ) |
|
940 { |
|
941 // Add More |
|
942 if( iItems.Count() < aItemCount ) |
|
943 { |
|
944 while( iItems.Count() < aItemCount ) |
|
945 { |
|
946 iItems.AppendL( CHgItem::NewL() ); |
|
947 } |
|
948 } |
|
949 // remove from the end |
|
950 else if( iItems.Count() > aItemCount ) |
|
951 { |
|
952 while( iItems.Count() > aItemCount ) |
|
953 { |
|
954 delete iItems[iItems.Count() - 1]; |
|
955 iItems.Remove( iItems.Count() - 1 ); |
|
956 } |
|
957 } |
|
958 else |
|
959 { |
|
960 return; // no change needed |
|
961 } |
|
962 |
|
963 iItemCount = aItemCount; |
|
964 |
|
965 if( iManager ) |
|
966 { |
|
967 iManager->ResetBuffer( iSelectedIndex, iItemCount ); |
|
968 } |
|
969 |
|
970 HandleItemCountChanged(); |
|
971 } |
|
972 |
|
973 // ----------------------------------------------------------------------------- |
|
974 // CHgScroller::ItemL() |
|
975 // ----------------------------------------------------------------------------- |
|
976 // |
|
977 EXPORT_C CHgItem& CHgScroller::ItemL(TInt aIndex) |
|
978 { |
|
979 if( aIndex < 0 || aIndex >= iItems.Count() ) |
|
980 { |
|
981 User::Leave( KErrArgument ); |
|
982 } |
|
983 |
|
984 return *iItems[aIndex]; |
|
985 } |
|
986 |
|
987 // ----------------------------------------------------------------------------- |
|
988 // CHgScroller::ViewPositionChanged() |
|
989 // ----------------------------------------------------------------------------- |
|
990 // |
|
991 void CHgScroller::ViewPositionChanged( const TPoint& aNewPosition, |
|
992 TBool aDrawNow, |
|
993 TUint /*aFlags*/ ) |
|
994 { |
|
995 iViewPosition = aNewPosition; |
|
996 HandleViewPositionChanged(); |
|
997 if( aDrawNow ) |
|
998 DrawNow(); |
|
999 } |
|
1000 |
|
1001 // ----------------------------------------------------------------------------- |
|
1002 // CHgScroller::ScrollBarPositionChanged() |
|
1003 // ----------------------------------------------------------------------------- |
|
1004 // |
|
1005 void CHgScroller::ScrollBarPositionChanged( const TPoint& aNewPosition ) |
|
1006 { |
|
1007 iViewPosition = aNewPosition; |
|
1008 iPhysics->StopPhysics(); |
|
1009 |
|
1010 if( iScrollBarType == EHgScrollerTimeStrip ) |
|
1011 { |
|
1012 // Show first item's time. |
|
1013 TInt selectedItem = CurrentIndex(); |
|
1014 if( selectedItem >= 0 && selectedItem < iItems.Count() ) |
|
1015 { |
|
1016 TRAP_IGNORE( |
|
1017 iItems[selectedItem]->Time().FormatL( iPopupText1, KGanesMonthString ); |
|
1018 iItems[selectedItem]->Time().FormatL( iPopupText2, KGanesYearString ); |
|
1019 ) |
|
1020 // To display year correctly in arabic. |
|
1021 AknTextUtils::LanguageSpecificNumberConversion( iPopupText2 ); |
|
1022 } |
|
1023 } |
|
1024 else if( iScrollBarType == EHgScrollerLetterStrip |
|
1025 || iScrollBarType == EHgScrollerLetterStripLite ) |
|
1026 { |
|
1027 TInt selectedItem = CurrentIndex(); |
|
1028 if( selectedItem >= 0 && selectedItem < iItems.Count() ) |
|
1029 { |
|
1030 if(iItems[selectedItem]->Title().Length()) |
|
1031 { |
|
1032 iPopupText1.Zero(); |
|
1033 iPopupText1.Append( iItems[selectedItem]->Title()[0] ); |
|
1034 } |
|
1035 } |
|
1036 } |
|
1037 HandleViewPositionChanged( EFalse ); |
|
1038 DrawNow(); |
|
1039 } |
|
1040 |
|
1041 // ----------------------------------------------------------------------------- |
|
1042 // CHgScroller::HandleNaviStripChar() |
|
1043 // ----------------------------------------------------------------------------- |
|
1044 // |
|
1045 void CHgScroller::HandleNaviStripChar( const TChar& /*aChar*/ ) |
|
1046 { |
|
1047 // Feature not used anymore |
|
1048 } |
|
1049 |
|
1050 // ----------------------------------------------------------------------------- |
|
1051 // CHgScroller::PhysicEmulationEnded() |
|
1052 // ----------------------------------------------------------------------------- |
|
1053 // |
|
1054 void CHgScroller::PhysicEmulationEnded() |
|
1055 { |
|
1056 // Nothing to do. |
|
1057 } |
|
1058 |
|
1059 // ----------------------------------------------------------------------------- |
|
1060 // CHgScroller::HandleViewPositionChanged() |
|
1061 // ----------------------------------------------------------------------------- |
|
1062 // |
|
1063 void CHgScroller::HandleViewPositionChanged(TBool aUpdateScrollbar) |
|
1064 { |
|
1065 TInt newRow = iLandscapeScrolling ? |
|
1066 (iViewPosition.iX-(iWidth/2))/((iRowHeight)): |
|
1067 (iViewPosition.iY-(iHeight/2))/(iRowHeight); |
|
1068 |
|
1069 if(iScrollbar && aUpdateScrollbar) |
|
1070 iScrollbar->SetViewPosition( iViewPosition - TPoint(iWidth/2, iHeight/2)); |
|
1071 |
|
1072 if(newRow != iCurrentRow) |
|
1073 { |
|
1074 iCurrentRow = newRow; |
|
1075 |
|
1076 if(iManager) |
|
1077 { |
|
1078 iManager->SetPosition( CurrentIndex() ); |
|
1079 } |
|
1080 } |
|
1081 } |
|
1082 |
|
1083 // ----------------------------------------------------------------------------- |
|
1084 // CHgScroller::HandleViewPositionChanged() |
|
1085 // ----------------------------------------------------------------------------- |
|
1086 // |
|
1087 TPoint CHgScroller::ViewPosition() const |
|
1088 { |
|
1089 return iViewPosition; |
|
1090 } |
|
1091 |
|
1092 // ----------------------------------------------------------------------------- |
|
1093 // CHgScroller::HandleKeyEvent() |
|
1094 // ----------------------------------------------------------------------------- |
|
1095 // |
|
1096 TKeyResponse CHgScroller::HandleKeyEvent(const TKeyEvent& aKeyEvent) |
|
1097 { |
|
1098 iKeyRepeats++; |
|
1099 TInt prevSelected = iSelectedIndex; |
|
1100 |
|
1101 TKeyScrollingState possibleKeyScrollingState = ENoKeyScrolling; |
|
1102 |
|
1103 switch( aKeyEvent.iCode ) |
|
1104 { |
|
1105 case EKeyUpArrow: |
|
1106 if( !iLandscapeScrolling ) |
|
1107 possibleKeyScrollingState = EKeyScrollingUp; |
|
1108 break; |
|
1109 case EKeyDownArrow: |
|
1110 if( !iLandscapeScrolling ) |
|
1111 possibleKeyScrollingState = EKeyScrollingDown; |
|
1112 break; |
|
1113 case EKeyLeftArrow: |
|
1114 if( iLandscapeScrolling ) |
|
1115 possibleKeyScrollingState = EKeyScrollingLeft; |
|
1116 break; |
|
1117 case EKeyRightArrow: |
|
1118 if( iLandscapeScrolling ) |
|
1119 possibleKeyScrollingState = EKeyScrollingRight; |
|
1120 break; |
|
1121 case EKeyEnter: |
|
1122 { |
|
1123 if( iSelectedIndex != KErrNotFound && iSelectionObserver ) |
|
1124 { |
|
1125 TRAP_IGNORE( iSelectionObserver->HandleOpenL( iSelectedIndex ); ) |
|
1126 return EKeyWasConsumed; |
|
1127 } |
|
1128 return EKeyWasNotConsumed; |
|
1129 } |
|
1130 default: |
|
1131 break; |
|
1132 } |
|
1133 |
|
1134 if( possibleKeyScrollingState != ENoKeyScrolling |
|
1135 && iKeyRepeats > KPhysLaunchKeyCount |
|
1136 && iSelectionMode == ENoSelection ) |
|
1137 { |
|
1138 if( !iKeyScrollingTimer->IsActive() ) |
|
1139 { |
|
1140 iKeyScrollingState = possibleKeyScrollingState; |
|
1141 iKeyScrollingTimer->Start( |
|
1142 TTimeIntervalMicroSeconds32( 0 ), |
|
1143 TTimeIntervalMicroSeconds32( KKeyScrollingUpdateInterval ), |
|
1144 TCallBack( KeyScrollingTimerCallback, this ) ); |
|
1145 } |
|
1146 } |
|
1147 |
|
1148 TBool handled = DoHandleKeyEvent(aKeyEvent); |
|
1149 |
|
1150 if( iSelectedIndex != prevSelected && iSelectionObserver ) |
|
1151 { |
|
1152 iDrawUtils->ResetMarquee(); |
|
1153 TRAP_IGNORE( iSelectionObserver->HandleSelectL(iSelectedIndex); ) |
|
1154 } |
|
1155 |
|
1156 if( !handled ) |
|
1157 iKeyRepeats--; |
|
1158 |
|
1159 return handled ? EKeyWasConsumed : EKeyWasNotConsumed; |
|
1160 } |
|
1161 |
|
1162 // ----------------------------------------------------------------------------- |
|
1163 // CHgScroller::Release() |
|
1164 // ----------------------------------------------------------------------------- |
|
1165 // |
|
1166 void CHgScroller::Release(TInt aReleaseStart, TInt aReleaseEnd) |
|
1167 { |
|
1168 for(; aReleaseStart <= aReleaseEnd; ++aReleaseStart) |
|
1169 { |
|
1170 if( aReleaseStart >= 0 && aReleaseStart < iItems.Count()) |
|
1171 { |
|
1172 iItems[aReleaseStart]->SetIcon(NULL, iItems[aReleaseStart]->Flags()); |
|
1173 } |
|
1174 } |
|
1175 } |
|
1176 |
|
1177 // ----------------------------------------------------------------------------- |
|
1178 // CHgScroller::Reset() |
|
1179 // ----------------------------------------------------------------------------- |
|
1180 // |
|
1181 EXPORT_C void CHgScroller::Reset() |
|
1182 { |
|
1183 if(iItemCount) |
|
1184 { |
|
1185 iItems.ResetAndDestroy(); |
|
1186 iItemCount = 0; |
|
1187 iSelectedIndex = -1; |
|
1188 |
|
1189 if( iManager ) |
|
1190 { |
|
1191 iManager->ResetBuffer( iSelectedIndex, iItemCount ); |
|
1192 } |
|
1193 |
|
1194 HandleItemCountChanged(); |
|
1195 } |
|
1196 } |
|
1197 |
|
1198 // ----------------------------------------------------------------------------- |
|
1199 // CHgScroller::SetFlags() |
|
1200 // ----------------------------------------------------------------------------- |
|
1201 // |
|
1202 EXPORT_C void CHgScroller::SetFlags(TInt aFlags) |
|
1203 { |
|
1204 iFlags |= aFlags; |
|
1205 } |
|
1206 |
|
1207 // ----------------------------------------------------------------------------- |
|
1208 // CHgScroller::ClearFlags() |
|
1209 // ----------------------------------------------------------------------------- |
|
1210 // |
|
1211 EXPORT_C void CHgScroller::ClearFlags(TInt aFlags) |
|
1212 { |
|
1213 iFlags &= ~aFlags; |
|
1214 } |
|
1215 |
|
1216 // ----------------------------------------------------------------------------- |
|
1217 // CHgScroller::Flags() |
|
1218 // ----------------------------------------------------------------------------- |
|
1219 // |
|
1220 EXPORT_C TInt CHgScroller::Flags() |
|
1221 { |
|
1222 return iFlags; |
|
1223 } |
|
1224 |
|
1225 // ----------------------------------------------------------------------------- |
|
1226 // CHgScroller::SetEmptyTextL() |
|
1227 // ----------------------------------------------------------------------------- |
|
1228 // |
|
1229 EXPORT_C void CHgScroller::SetEmptyTextL( const TDesC& aEmptyText ) |
|
1230 { |
|
1231 delete iEmptyText; |
|
1232 iEmptyText = 0; |
|
1233 iEmptyText = aEmptyText.AllocL(); |
|
1234 } |
|
1235 |
|
1236 // ----------------------------------------------------------------------------- |
|
1237 // CHgScroller::ItemCount() |
|
1238 // ----------------------------------------------------------------------------- |
|
1239 // |
|
1240 EXPORT_C TInt CHgScroller::ItemCount() const |
|
1241 { |
|
1242 return iItems.Count(); |
|
1243 } |
|
1244 |
|
1245 // ----------------------------------------------------------------------------- |
|
1246 // CHgScroller::HightlightItem() |
|
1247 // ----------------------------------------------------------------------------- |
|
1248 // |
|
1249 EXPORT_C TBool CHgScroller::HightlightItem( const TDesC& aHighlightText ) |
|
1250 { |
|
1251 TInt searchStartIndex = aHighlightText.Length() == 1 || |
|
1252 iSelectedIndex == KErrNotFound ? iSelectedIndex + 1 : iSelectedIndex; |
|
1253 |
|
1254 // From selected to end |
|
1255 for(TInt i = searchStartIndex; i < iItems.Count(); ++i) |
|
1256 { |
|
1257 if(iItems[i]->Title().Length() > 0 ) |
|
1258 { |
|
1259 iUpperCaseTitle.Copy( iItems[i]->Title().Left( aHighlightText.Length() ) ); |
|
1260 iUpperCaseTitle.UpperCase(); |
|
1261 TInt result = iUpperCaseTitle.CompareC( aHighlightText ); |
|
1262 |
|
1263 if(result == 0) |
|
1264 { |
|
1265 iSelectedIndex = i; |
|
1266 FitSelectionToView(); |
|
1267 DrawDeferred(); |
|
1268 return ETrue; |
|
1269 } |
|
1270 } |
|
1271 } |
|
1272 |
|
1273 // From beginning to selected - 1 |
|
1274 for(TInt i = 0; i < iSelectedIndex; ++i) |
|
1275 { |
|
1276 if(iItems[i]->Title().Length() > 0 ) |
|
1277 { |
|
1278 iUpperCaseTitle.Copy( iItems[i]->Title().Left( aHighlightText.Length() ) ); |
|
1279 iUpperCaseTitle.UpperCase(); |
|
1280 TInt result = iUpperCaseTitle.CompareC( aHighlightText ); |
|
1281 |
|
1282 if(result == 0) |
|
1283 { |
|
1284 iSelectedIndex = i; |
|
1285 FitSelectionToView(); |
|
1286 DrawDeferred(); |
|
1287 return ETrue; |
|
1288 } |
|
1289 else if( result > 0) |
|
1290 { |
|
1291 break; |
|
1292 } |
|
1293 } |
|
1294 } |
|
1295 |
|
1296 return EFalse; |
|
1297 } |
|
1298 |
|
1299 // ----------------------------------------------------------------------------- |
|
1300 // CHgScroller::SetDefaultIconL() |
|
1301 // ----------------------------------------------------------------------------- |
|
1302 // |
|
1303 EXPORT_C void CHgScroller::SetDefaultIconL( CGulIcon* aDefaultIcon ) |
|
1304 { |
|
1305 if( aDefaultIcon ) |
|
1306 { |
|
1307 delete iDefaultIcon; |
|
1308 iDefaultIcon = aDefaultIcon; |
|
1309 } |
|
1310 } |
|
1311 |
|
1312 // ----------------------------------------------------------------------------- |
|
1313 // CHgScroller::DisableScrollBuffer() |
|
1314 // ----------------------------------------------------------------------------- |
|
1315 // |
|
1316 EXPORT_C void CHgScroller::DisableScrollBuffer() |
|
1317 { |
|
1318 delete iManager; |
|
1319 iManager = NULL; |
|
1320 } |
|
1321 |
|
1322 // ----------------------------------------------------------------------------- |
|
1323 // CHgScroller::InitGraphicsL() |
|
1324 // ----------------------------------------------------------------------------- |
|
1325 // |
|
1326 void CHgScroller::InitGraphicsL() |
|
1327 { |
|
1328 // Non-Skinned icons |
|
1329 // Default icon |
|
1330 if(iIndicatorManager) |
|
1331 { |
|
1332 iIndicatorManager->InitIconL(iDefaultIcon, |
|
1333 EMbmGanesQgn_prop_checkbox_on, EMbmGanesQgn_prop_checkbox_on_mask, iImageSize); |
|
1334 |
|
1335 iIndicatorManager->InitIndicatorsL(iIndicatorSize); |
|
1336 } |
|
1337 } |
|
1338 |
|
1339 // ----------------------------------------------------------------------------- |
|
1340 // CHgScroller::SelectionChanged() |
|
1341 // ----------------------------------------------------------------------------- |
|
1342 // |
|
1343 void CHgScroller::SelectionChanged() |
|
1344 { |
|
1345 } |
|
1346 |
|
1347 // ----------------------------------------------------------------------------- |
|
1348 // CHgScroller::FitRowToView() |
|
1349 // ----------------------------------------------------------------------------- |
|
1350 // |
|
1351 void CHgScroller::FitRowToView( TInt aRow ) |
|
1352 { |
|
1353 if( iLandscapeScrolling ) |
|
1354 { |
|
1355 if ( aRow*iRowHeight < iViewPosition.iX-(iWidth/2) ) |
|
1356 { |
|
1357 // Item is at top but not fully visible |
|
1358 iViewPosition.iX -= (iViewPosition.iX-(iWidth/2) - ((aRow)*iRowHeight)); |
|
1359 HandleViewPositionChanged(); |
|
1360 } |
|
1361 else if ( (aRow+1)*iRowHeight > iViewPosition.iX+(iWidth/2) ) |
|
1362 { |
|
1363 // Item is at bottom but not fully visible |
|
1364 iViewPosition.iX += ((aRow+1)*iRowHeight - (iViewPosition.iX+(iWidth/2))); |
|
1365 HandleViewPositionChanged(); |
|
1366 } |
|
1367 } |
|
1368 else |
|
1369 { |
|
1370 if ( aRow*iRowHeight < iViewPosition.iY-(iHeight/2) ) |
|
1371 { |
|
1372 // Item is at top but not fully visible |
|
1373 iViewPosition.iY -= (iViewPosition.iY-(iHeight/2) - ((aRow)*iRowHeight)); |
|
1374 HandleViewPositionChanged(); |
|
1375 } |
|
1376 else if ( (aRow+1)*iRowHeight > iViewPosition.iY+(iHeight/2) ) |
|
1377 { |
|
1378 // Item is at bottom but not fully visible |
|
1379 iViewPosition.iY += ((aRow+1)*iRowHeight - (iViewPosition.iY+(iHeight/2))); |
|
1380 HandleViewPositionChanged(); |
|
1381 } |
|
1382 } |
|
1383 } |
|
1384 |
|
1385 // ----------------------------------------------------------------------------- |
|
1386 // CHgScroller::MarqueeCallback() |
|
1387 // ----------------------------------------------------------------------------- |
|
1388 // |
|
1389 TInt CHgScroller::MarqueeCallback( TAny* aSelf ) |
|
1390 { |
|
1391 CHgScroller* self = static_cast<CHgScroller*>(aSelf); |
|
1392 if( self->IsDisplayed( self->iSelectedIndex ) ) |
|
1393 { |
|
1394 self->DrawDeferred(); |
|
1395 return ETrue; |
|
1396 } |
|
1397 else |
|
1398 { |
|
1399 return EFalse; |
|
1400 } |
|
1401 } |
|
1402 |
|
1403 // ----------------------------------------------------------------------------- |
|
1404 // CHgScroller::HandleGainingForeground() |
|
1405 // ----------------------------------------------------------------------------- |
|
1406 // |
|
1407 void CHgScroller::HandleGainingForeground() |
|
1408 { |
|
1409 iSelectionMode = ENoSelection; |
|
1410 TRect rect( PositionRelativeToScreen(), Size() ); |
|
1411 TRAP_IGNORE( InitScreenL( rect ); ) |
|
1412 iScrollbar->Reset(); |
|
1413 } |
|
1414 |
|
1415 // ----------------------------------------------------------------------------- |
|
1416 // CHgScroller::HandleLosingForeground() |
|
1417 // ----------------------------------------------------------------------------- |
|
1418 // |
|
1419 void CHgScroller::HandleLosingForeground() |
|
1420 { |
|
1421 iPopupText1.Zero(); |
|
1422 iPopupText2.Zero(); |
|
1423 } |
|
1424 |
|
1425 // --------------------------------------------------------------------------- |
|
1426 // CHgScroller::LaunchHighlightTimer() |
|
1427 // --------------------------------------------------------------------------- |
|
1428 // |
|
1429 void CHgScroller::LaunchHighlightTimer() |
|
1430 { |
|
1431 if ( !iHighlightTimer ) |
|
1432 { |
|
1433 return; |
|
1434 } |
|
1435 |
|
1436 TInt highlightTimeout( 0 ); |
|
1437 if ( iPhysics ) |
|
1438 { |
|
1439 highlightTimeout = iPhysics->HighlightTimeout() * 1000; |
|
1440 } |
|
1441 if ( highlightTimeout == 0 ) |
|
1442 { |
|
1443 highlightTimeout = KDefaultHighlightTimeout; |
|
1444 } |
|
1445 |
|
1446 iHighlightTimer->Cancel(); |
|
1447 iHighlightTimer->Start( |
|
1448 TTimeIntervalMicroSeconds32( highlightTimeout ), |
|
1449 TTimeIntervalMicroSeconds32( highlightTimeout ), |
|
1450 TCallBack( HighlightTimerCallback, this ) ); |
|
1451 } |
|
1452 |
|
1453 |
|
1454 // --------------------------------------------------------------------------- |
|
1455 // CHgScroller::HighlightTimerCallback() |
|
1456 // --------------------------------------------------------------------------- |
|
1457 // |
|
1458 TInt CHgScroller::HighlightTimerCallback( TAny* aPtr ) |
|
1459 { |
|
1460 CHgScroller* scroller = |
|
1461 static_cast<CHgScroller*>( aPtr ); |
|
1462 |
|
1463 TInt err = KErrNotFound; |
|
1464 |
|
1465 if ( scroller ) |
|
1466 { |
|
1467 TRAP( err, scroller->SetHighlightL() ); |
|
1468 } |
|
1469 |
|
1470 return err; |
|
1471 } |
|
1472 |
|
1473 // --------------------------------------------------------------------------- |
|
1474 // CHgScroller::SetHighlightL() |
|
1475 // --------------------------------------------------------------------------- |
|
1476 // |
|
1477 void CHgScroller::SetHighlightL() |
|
1478 { |
|
1479 iHighlightTimer->Cancel(); |
|
1480 |
|
1481 TInt index = GetSelected(iStart); |
|
1482 if((index != KErrNotFound || !HasHighlight()) |
|
1483 && iPointerDown ) |
|
1484 { |
|
1485 iSelectionToFocusedItem = index == iSelectedIndex; |
|
1486 iSelectedIndex = index; |
|
1487 iFocusedIndex = index; |
|
1488 // Selection has changed to valid item |
|
1489 if( !iSelectionToFocusedItem && iSelectedIndex != KErrNotFound ) |
|
1490 { |
|
1491 if( iSelectionObserver ) |
|
1492 iSelectionObserver->HandleSelectL(iSelectedIndex); |
|
1493 |
|
1494 FitSelectionToView(); |
|
1495 SelectionChanged(); |
|
1496 iDrawUtils->ResetMarquee(); |
|
1497 } |
|
1498 DrawDeferred(); |
|
1499 } |
|
1500 } |
|
1501 |
|
1502 // --------------------------------------------------------------------------- |
|
1503 // CHgScroller::SetSelectionMode() |
|
1504 // --------------------------------------------------------------------------- |
|
1505 // |
|
1506 void CHgScroller::SetSelectionMode( TSelectionMode aMode ) |
|
1507 { |
|
1508 iSelectionMode = aMode; |
|
1509 if( iSelectionMode == ESelectionPossible |
|
1510 || iSelectionMode == ENoSelection ) |
|
1511 { |
|
1512 iCoeEnv->InputCapabilitiesChanged(); |
|
1513 } |
|
1514 } |
|
1515 |
|
1516 // --------------------------------------------------------------------------- |
|
1517 // CHgScroller::SelectionMode() |
|
1518 // --------------------------------------------------------------------------- |
|
1519 // |
|
1520 CHgScroller::TSelectionMode CHgScroller::SelectionMode() const |
|
1521 { |
|
1522 return iSelectionMode; |
|
1523 } |
|
1524 |
|
1525 // --------------------------------------------------------------------------- |
|
1526 // CHgScroller::KeyScrollingTimerCallback() |
|
1527 // --------------------------------------------------------------------------- |
|
1528 // |
|
1529 TInt CHgScroller::KeyScrollingTimerCallback( TAny* aPtr ) |
|
1530 { |
|
1531 CHgScroller* scroller = |
|
1532 static_cast<CHgScroller*>( aPtr ); |
|
1533 |
|
1534 TInt err = KErrNotFound; |
|
1535 |
|
1536 if ( scroller ) |
|
1537 { |
|
1538 scroller->DoKeyScrolling(); |
|
1539 err = KErrNone; |
|
1540 } |
|
1541 |
|
1542 return err; |
|
1543 } |
|
1544 |
|
1545 // --------------------------------------------------------------------------- |
|
1546 // CHgScroller::DoKeyScrolling() |
|
1547 // --------------------------------------------------------------------------- |
|
1548 // |
|
1549 void CHgScroller::DoKeyScrolling() |
|
1550 { |
|
1551 TKeyEvent keyevent; |
|
1552 |
|
1553 switch( iKeyScrollingState ) |
|
1554 { |
|
1555 case EKeyScrollingUp: |
|
1556 { |
|
1557 keyevent.iCode = EKeyUpArrow; |
|
1558 HandleKeyEvent( keyevent ); |
|
1559 break; |
|
1560 } |
|
1561 case EKeyScrollingDown: |
|
1562 { |
|
1563 keyevent.iCode = EKeyDownArrow; |
|
1564 HandleKeyEvent( keyevent ); |
|
1565 break; |
|
1566 } |
|
1567 case EKeyScrollingLeft: |
|
1568 { |
|
1569 keyevent.iCode = EKeyLeftArrow; |
|
1570 HandleKeyEvent( keyevent ); |
|
1571 break; |
|
1572 } |
|
1573 case EKeyScrollingRight: |
|
1574 { |
|
1575 keyevent.iCode = EKeyRightArrow; |
|
1576 HandleKeyEvent( keyevent ); |
|
1577 break; |
|
1578 } |
|
1579 case ENoKeyScrolling: |
|
1580 default: |
|
1581 StopKeyScrolling(); |
|
1582 break; |
|
1583 } |
|
1584 |
|
1585 DrawNow(); |
|
1586 } |
|
1587 |
|
1588 // --------------------------------------------------------------------------- |
|
1589 // CHgScroller::StopKeyScrolling() |
|
1590 // --------------------------------------------------------------------------- |
|
1591 // |
|
1592 void CHgScroller::StopKeyScrolling() |
|
1593 { |
|
1594 iKeyScrollingTimer->Cancel(); |
|
1595 iKeyScrollingState = ENoKeyScrolling; |
|
1596 } |
|
1597 |
|
1598 // --------------------------------------------------------------------------- |
|
1599 // CHgScroller::FocusChanged() |
|
1600 // --------------------------------------------------------------------------- |
|
1601 // |
|
1602 void CHgScroller::FocusChanged(TDrawNow aDrawNow) |
|
1603 { |
|
1604 if( iKeyUtils ) |
|
1605 { |
|
1606 if( !(iFlags & EHgScrollerKeyMarkingDisabled) ) |
|
1607 { |
|
1608 if(IsFocused()) |
|
1609 { |
|
1610 iKeyUtils->HandleGainingFocus(); |
|
1611 } |
|
1612 else |
|
1613 { |
|
1614 iKeyUtils->HandleLosingFocus(); |
|
1615 } |
|
1616 } |
|
1617 else |
|
1618 { |
|
1619 iKeyUtils->HandleLosingFocus(); |
|
1620 } |
|
1621 } |
|
1622 |
|
1623 CCoeControl::FocusChanged( aDrawNow ); |
|
1624 } |
|
1625 |
|
1626 // --------------------------------------------------------------------------- |
|
1627 // CHgScroller::HandleResourceChange() |
|
1628 // --------------------------------------------------------------------------- |
|
1629 // |
|
1630 void CHgScroller::HandleResourceChange( TInt aType ) |
|
1631 { |
|
1632 TRAP_IGNORE( |
|
1633 // When skin changes the indicator icons must be reloaded. |
|
1634 if ( aType == KAknsMessageSkinChange ) |
|
1635 { |
|
1636 delete iIndicatorManager; iIndicatorManager = NULL; |
|
1637 iIndicatorManager = CHgIndicatorManager::NewL(); |
|
1638 InitGraphicsL(); |
|
1639 } |
|
1640 ) |
|
1641 } |
|
1642 |
|
1643 // --------------------------------------------------------------------------- |
|
1644 // CHgScroller::HandleLongTapEventL() |
|
1645 // --------------------------------------------------------------------------- |
|
1646 // |
|
1647 void CHgScroller::HandleLongTapEventL( const TPoint& /*aPenEventLocation*/, |
|
1648 const TPoint& aPenEventScreenLocation) |
|
1649 { |
|
1650 if( iActionMenu ) |
|
1651 { |
|
1652 iPointerDown = EFalse; |
|
1653 iActionMenu->ShowMenuL(aPenEventScreenLocation); |
|
1654 } |
|
1655 } |
|
1656 |
|
1657 // --------------------------------------------------------------------------- |
|
1658 // CHgScroller::CollectionState() |
|
1659 // --------------------------------------------------------------------------- |
|
1660 // |
|
1661 TUint CHgScroller::CollectionState() const |
|
1662 { |
|
1663 TUint ret = 0; |
|
1664 |
|
1665 if(IsFocused()) ret |= MAknCollection::EStateCollectionVisible; |
|
1666 |
|
1667 if(HasHighlight()) ret |= MAknCollection::EStateHighlightVisible; |
|
1668 |
|
1669 if( iFlags & EHgScrollerSelectionMode ) ret |= MAknCollection::EStateMultipleSelection; |
|
1670 |
|
1671 return ret; |
|
1672 } |
|
1673 |
|
1674 // --------------------------------------------------------------------------- |
|
1675 // CHgScroller::CollectionState() |
|
1676 // --------------------------------------------------------------------------- |
|
1677 // |
|
1678 void CHgScroller::ItemActionMenuClosed() |
|
1679 { |
|
1680 DrawDeferred(); |
|
1681 } |
|
1682 |
|
1683 // --------------------------------------------------------------------------- |
|
1684 // CHgScroller::CollectionState() |
|
1685 // --------------------------------------------------------------------------- |
|
1686 // |
|
1687 TInt CHgScroller::CollectionExtension( TUint /*aExtensionId*/, TAny*& /*a0*/, TAny* /*a1*/ ) |
|
1688 { |
|
1689 return KErrNone; |
|
1690 } |
|
1691 |
|
1692 // --------------------------------------------------------------------------- |
|
1693 // CHgScroller::HasHighlight() |
|
1694 // --------------------------------------------------------------------------- |
|
1695 // |
|
1696 TBool CHgScroller::HasHighlight() const |
|
1697 { |
|
1698 return (iActionMenu == NULL) || iShowHighlight || (iFlags & EHgScrollerForceDoubleClick); |
|
1699 } |
|
1700 |
|
1701 // End of File |