118 EnableExtendedDrawingL(); |
117 EnableExtendedDrawingL(); |
119 |
118 |
120 iItemDrawer->SetDrawMark(EFalse); |
119 iItemDrawer->SetDrawMark(EFalse); |
121 CEikListBox::ConstructL(aParent,aFlags); |
120 CEikListBox::ConstructL(aParent,aFlags); |
122 iMmDrawer->SetView( this ); |
121 iMmDrawer->SetView( this ); |
123 iRedrawTimer = CPeriodic::NewL( EPriorityRealTime ); |
|
124 } |
122 } |
125 |
123 |
126 // ----------------------------------------------------------------------------- |
124 // ----------------------------------------------------------------------------- |
127 // Clearing ELeftDownInViewRect flag before invoking the base class |
125 // Clearing ELeftDownInViewRect flag before invoking the base class |
128 // HandlePointerEventL method effectively prevents that method from doing most |
126 // HandlePointerEventL method effectively prevents that method from doing most |
232 |
230 |
233 // ----------------------------------------------------------------------------- |
231 // ----------------------------------------------------------------------------- |
234 // |
232 // |
235 // ----------------------------------------------------------------------------- |
233 // ----------------------------------------------------------------------------- |
236 // |
234 // |
|
235 void CMmListBox::ScrollWithoutRedraw( TInt distanceInPixels ) |
|
236 { |
|
237 // desired view position relative to the first item in list (always positive) |
|
238 TInt desiredViewPosition = ItemHeight() * TopItemIndex() - VerticalItemOffset(); |
|
239 desiredViewPosition += distanceInPixels; |
|
240 |
|
241 const TInt viewPositionMax = Max( 0, ( iModel->NumberOfItems() |
|
242 * ItemHeight() ) - iView->ViewRect().Height() ); |
|
243 |
|
244 desiredViewPosition = Min( desiredViewPosition, viewPositionMax ); |
|
245 desiredViewPosition = Max( desiredViewPosition, 0 ); |
|
246 |
|
247 ASSERT( desiredViewPosition >= 0 ); |
|
248 |
|
249 SetTopItemIndex( desiredViewPosition / ItemHeight() ); |
|
250 SetVerticalItemOffset( -( desiredViewPosition % ItemHeight() ) ); |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
237 TInt CMmListBox::ScrollIfNeeded( const TPointerEvent& aPointerEvent ) |
257 TInt CMmListBox::ScrollIfNeeded( const TPointerEvent& aPointerEvent ) |
238 { |
258 { |
239 TInt nextScrollDelay = 0; |
259 TInt nextScrollDelay = 0; |
240 |
260 |
241 TBool readyForScrolling = |
261 TBool readyForScrolling = iMmDrawer->GetAnimator()->IsReadyForNewAnimation() |
242 iMmDrawer->GetAnimator()->IsReadyForNewAnimation() |
262 && iMmDrawer->GetFloatingItemCount() != 0; |
243 && iMmDrawer->GetFloatingItemCount() != 0; |
263 |
244 |
264 if( IsPointerInTopScrollingThreshold( aPointerEvent ) ) |
245 if ( IsPointerInTopScrollingThreshold( aPointerEvent ) ) |
265 { |
246 { |
266 // scroll up |
247 // scroll up by one row |
267 TInt startPos = MmListBox::KFocusScrollingThreshold * TReal( |
248 TInt newCurrentItemIndex = CurrentItemIndex() - 1; |
268 View()->ItemSize().iHeight ); |
249 |
269 TInt diff = Max( 1, Min( aPointerEvent.iPosition.iY |
250 if ( newCurrentItemIndex >= 0 ) |
270 - Rect().iTl.iY, startPos ) ); |
251 { |
271 nextScrollDelay = ( (TReal) diff / (TReal) startPos ) |
252 nextScrollDelay = MmEffects::KEditModeScrollingDelayFactor * |
272 * ( MmListBox::KEditModeScrollingListBoxMaxDelay |
253 Max( 1, aPointerEvent.iPosition.iY - Rect().iTl.iY ); |
273 - MmListBox::KEditModeScrollingListBoxMinDelay ) |
254 if (readyForScrolling) |
274 + MmListBox::KEditModeScrollingListBoxMinDelay; |
255 { |
275 if( readyForScrolling ) |
256 View()->VScrollTo( View()->CalcNewTopItemIndexSoItemIsVisible( |
276 { |
257 newCurrentItemIndex ) ); |
277 ScrollWithoutRedraw( -MmListBox::KScrollingStep ); |
258 View()->SetCurrentItemIndex( newCurrentItemIndex ); |
278 } |
259 UpdateScrollBarThumbs(); |
279 } |
260 } |
280 else if( IsPointerInBottomScrollingThreshold( aPointerEvent ) ) |
261 } |
281 { |
262 } |
282 // scroll down |
263 else if ( IsPointerInBottomScrollingThreshold( aPointerEvent) ) |
283 TInt startPos = MmListBox::KFocusScrollingThreshold * TReal( |
264 { |
284 View()->ItemSize().iHeight ); |
265 // scroll down by one row |
285 TInt diff = Max( 1, Min( Rect().iBr.iY |
266 TInt lastItemIndex = iModel->NumberOfItems() - 1; |
286 - aPointerEvent.iPosition.iY, startPos ) ); |
267 TInt newCurrentItemIndex = CurrentItemIndex() + 1; |
287 nextScrollDelay = ( (TReal) diff / (TReal) startPos ) |
268 |
288 * ( MmListBox::KEditModeScrollingListBoxMaxDelay |
269 |
289 - MmListBox::KEditModeScrollingListBoxMinDelay ) |
270 if ( newCurrentItemIndex <= lastItemIndex ) |
290 + MmListBox::KEditModeScrollingListBoxMinDelay; |
271 { |
291 |
272 nextScrollDelay = MmEffects::KEditModeScrollingDelayFactor * |
292 if( readyForScrolling ) |
273 Max( 1, Rect().iBr.iY - aPointerEvent.iPosition.iY ); |
293 { |
274 |
294 ScrollWithoutRedraw( MmListBox::KScrollingStep ); |
275 if (readyForScrolling) |
295 } |
276 { |
296 } |
277 View()->VScrollTo( View()->CalcNewTopItemIndexSoItemIsVisible( |
|
278 newCurrentItemIndex ) ); |
|
279 View()->SetCurrentItemIndex( newCurrentItemIndex ); |
|
280 UpdateScrollBarThumbs(); |
|
281 } |
|
282 } |
|
283 } |
|
284 |
297 |
285 return nextScrollDelay; |
298 return nextScrollDelay; |
286 } |
299 } |
287 |
300 |
288 // ----------------------------------------------------------------------------- |
301 // ----------------------------------------------------------------------------- |
381 void CMmListBox::ProcessScrollEventL( CEikScrollBar* aScrollBar, |
394 void CMmListBox::ProcessScrollEventL( CEikScrollBar* aScrollBar, |
382 TEikScrollEvent aEventType ) |
395 TEikScrollEvent aEventType ) |
383 { |
396 { |
384 CEikFormattedCellListBoxTypedef::HandleScrollEventL( |
397 CEikFormattedCellListBoxTypedef::HandleScrollEventL( |
385 aScrollBar, aEventType ); |
398 aScrollBar, aEventType ); |
386 } |
|
387 |
|
388 // ----------------------------------------------------------------------------- |
|
389 // |
|
390 // ----------------------------------------------------------------------------- |
|
391 // |
|
392 void CMmListBox::HandleRedrawTimerEventL() |
|
393 { |
|
394 if ( iSkippedScrollbarEventsCount ) |
|
395 { |
|
396 ProcessScrollEventL( ScrollBarFrame()->VerticalScrollBar(), |
|
397 EEikScrollThumbDragVert ); |
|
398 } |
|
399 iSkippedScrollbarEventsCount = 0; |
|
400 } |
|
401 |
|
402 // ----------------------------------------------------------------------------- |
|
403 // |
|
404 // ----------------------------------------------------------------------------- |
|
405 // |
|
406 TInt CMmListBox::RedrawTimerCallback( TAny* aPtr ) |
|
407 { |
|
408 CMmListBox* self = static_cast<CMmListBox*>( aPtr ); |
|
409 TRAP_IGNORE( self->HandleRedrawTimerEventL() ); |
|
410 // Do not bother returning a meaningful error code, CPeriodic will ignore it |
|
411 // anyway. |
|
412 return 0; |
|
413 } |
399 } |
414 |
400 |
415 // ----------------------------------------------------------------------------- |
401 // ----------------------------------------------------------------------------- |
416 // |
402 // |
417 // ----------------------------------------------------------------------------- |
403 // ----------------------------------------------------------------------------- |
954 // ----------------------------------------------------------------------------- |
940 // ----------------------------------------------------------------------------- |
955 // |
941 // |
956 void CMmListBox::HandleScrollEventL( CEikScrollBar* aScrollBar, |
942 void CMmListBox::HandleScrollEventL( CEikScrollBar* aScrollBar, |
957 TEikScrollEvent aEventType ) |
943 TEikScrollEvent aEventType ) |
958 { |
944 { |
959 if ( aEventType == EEikScrollThumbDragVert && !iScrollbarThumbIsBeingDragged ) |
945 if ( aEventType == EEikScrollThumbDragVert ) |
960 { |
946 { |
961 iScrollbarThumbIsBeingDragged = ETrue; |
|
962 static_cast<CMmListBoxItemDrawer*>( |
947 static_cast<CMmListBoxItemDrawer*>( |
963 View()->ItemDrawer() )->EnableCachedDataUse( ETrue ); |
948 View()->ItemDrawer() )->EnableCachedDataUse( ETrue ); |
964 iRedrawTimer->Start( KScrollingRedrawInterval, KScrollingRedrawInterval, |
|
965 TCallBack( &CMmListBox::RedrawTimerCallback, static_cast<TAny*>( this ) ) ); |
|
966 } |
949 } |
967 else if ( aEventType == EEikScrollThumbReleaseVert ) |
950 else if ( aEventType == EEikScrollThumbReleaseVert ) |
968 { |
951 { |
969 iScrollbarThumbIsBeingDragged = EFalse; |
|
970 static_cast<CMmListBoxItemDrawer*>( |
952 static_cast<CMmListBoxItemDrawer*>( |
971 View()->ItemDrawer() )->EnableCachedDataUse( EFalse ); |
953 View()->ItemDrawer() )->EnableCachedDataUse( EFalse ); |
972 // The view will be redrawn with cache disabled when ProcessScrollEventL |
954 } |
973 // calls the base class's HandleScrollEventL method -- no need to |
955 ProcessScrollEventL( aScrollBar, aEventType ); |
974 // explicitly redraw the view. |
|
975 iRedrawTimer->Cancel(); |
|
976 } |
|
977 |
|
978 if ( !iScrollbarThumbIsBeingDragged ) |
|
979 { |
|
980 ProcessScrollEventL( aScrollBar, aEventType ); |
|
981 } |
|
982 else |
|
983 { |
|
984 __ASSERT_DEBUG( aEventType == EEikScrollThumbDragVert, User::Invariant() ); |
|
985 ++iSkippedScrollbarEventsCount; |
|
986 } |
|
987 } |
956 } |
988 |
957 |
989 // End of file |
958 // End of file |