menufw/menufwui/mmwidgets/src/mmgrid.cpp
changeset 4 4d54b72983ae
parent 2 08c6ee43b396
child 5 c743ef5928ba
equal deleted inserted replaced
3:fb3763350a08 4:4d54b72983ae
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *  Version     : %version: MM_95 % << Don't touch! Updated by Synergy at check-out.
    15 *  Version     : %version: MM_97 % << Don't touch! Updated by Synergy at check-out.
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 
    19 
    20 #include <AknsDrawUtils.h>
    20 #include <AknsDrawUtils.h>
    49 //
    49 //
    50 // -----------------------------------------------------------------------------
    50 // -----------------------------------------------------------------------------
    51 //
    51 //
    52 CMmGrid::~CMmGrid()
    52 CMmGrid::~CMmGrid()
    53     {
    53     {
       
    54     delete iRedrawTimer;
    54     }
    55     }
    55 
    56 
    56 // -----------------------------------------------------------------------------
    57 // -----------------------------------------------------------------------------
    57 //
    58 //
    58 // -----------------------------------------------------------------------------
    59 // -----------------------------------------------------------------------------
   213 // -----------------------------------------------------------------------------
   214 // -----------------------------------------------------------------------------
   214 //
   215 //
   215 void CMmGrid::HandleScrollEventL( CEikScrollBar* aScrollBar,
   216 void CMmGrid::HandleScrollEventL( CEikScrollBar* aScrollBar,
   216         TEikScrollEvent aEventType )
   217         TEikScrollEvent aEventType )
   217     {
   218     {
   218     CAknGrid::HandleScrollEventL(aScrollBar, aEventType);
   219     if ( aEventType == EEikScrollThumbDragVert && !iScrollbarThumbIsBeingDragged )
   219     iCurrentTopItemIndex = TopItemIndex();
   220         {
   220 
   221         iScrollbarThumbIsBeingDragged = ETrue;
   221     // setting default highligh in order not to overwrite the top item index
   222         static_cast<CMmListBoxItemDrawer*>(
   222     // set before in the SetLayout method
   223                 View()->ItemDrawer() )->EnableCachedDataUse( ETrue );
   223     CMmWidgetContainer* parent = static_cast< CMmWidgetContainer* > ( Parent() );
   224         iRedrawTimer->Start( KScrollingRedrawInterval, KScrollingRedrawInterval,
   224     if (!parent->IsHighlightVisible())
   225                 TCallBack( &CMmGrid::RedrawTimerCallback, static_cast<TAny*>( this ) ) );
   225          {
   226         }
   226          parent->SetDefaultHighlightL( EFalse );
   227     else if ( aEventType == EEikScrollThumbReleaseVert )
   227 
   228         {
   228 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
   229         iScrollbarThumbIsBeingDragged = EFalse;
   229          MAknListBoxTfxInternal* transApi = CAknListLoader::TfxApiInternal(
   230         static_cast<CMmListBoxItemDrawer*>(
   230                  static_cast<CMmGridView*>(iView)->Gc() );
   231                 View()->ItemDrawer() )->EnableCachedDataUse( EFalse );
   231          TBool effects = transApi && !transApi->EffectsDisabled();
   232         // The view will be redrawn with cache disabled when ProcessScrollEventL
   232          if ( effects && aEventType == EEikScrollPageUp ||
   233         // calls the base class's HandleScrollEventL method -- no need to
   233                  aEventType == EEikScrollPageDown )
   234         // explicitly redraw the view.
   234              {
   235         iRedrawTimer->Cancel();
   235              DrawNow();
   236         }
   236              }
   237 
   237 #endif
   238     if ( !iScrollbarThumbIsBeingDragged )
   238 
   239         {
   239          }
   240         ProcessScrollEventL( aScrollBar, aEventType );
   240     }
   241         }
   241 
   242     else
   242 // -----------------------------------------------------------------------------
   243         {
   243 //
   244         __ASSERT_DEBUG( aEventType == EEikScrollThumbDragVert, User::Invariant() );
       
   245         ++iSkippedScrollbarEventsCount;
       
   246         }
       
   247     }
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // Clearing ELeftDownInViewRect flag before invoking the base class
       
   251 // HandlePointerEventL method effectively prevents that method from doing most
       
   252 // of the things it would normally do in response to EButton1Down event.
       
   253 // This flag is explicitly cleared to achieve two things:
       
   254 // 1. Prevent kinetic scrolling (flick) in edit mode.
       
   255 // 2. Prevent highlight removal when popup menu is displayed.
   244 // -----------------------------------------------------------------------------
   256 // -----------------------------------------------------------------------------
   245 //
   257 //
   246 void CMmGrid::HandlePointerEventInEditModeL( const TPointerEvent& aPointerEvent )
   258 void CMmGrid::HandlePointerEventInEditModeL( const TPointerEvent& aPointerEvent )
   247     {
   259     {
       
   260     if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   261         {
       
   262         iButton1DownPos = aPointerEvent.iPosition;
       
   263         }
       
   264     else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   265         {
       
   266         CMmWidgetContainer* parent = static_cast<CMmWidgetContainer*>( Parent() );
       
   267         TPoint dragDelta = iButton1DownPos - aPointerEvent.iPosition;
       
   268         if ( Abs( dragDelta.iY ) > KDragTreshold || parent->LongTapInProgress() )
       
   269             {
       
   270             iListBoxFlags &= ~ELeftDownInViewRect;
       
   271             }
       
   272         }
       
   273 
   248     TInt itemUnderPointerIndex = KErrNotFound;
   274     TInt itemUnderPointerIndex = KErrNotFound;
   249 
       
   250     if ( aPointerEvent.iType == TPointerEvent::EButton1Up ||
   275     if ( aPointerEvent.iType == TPointerEvent::EButton1Up ||
   251             aPointerEvent.iType == TPointerEvent::EButton1Down )
   276             aPointerEvent.iType == TPointerEvent::EButton1Down )
   252         {
   277         {
   253         iListBoxFlags &= ~ELeftDownInViewRect; // prevent kinetic scrolling
       
   254         CAknGrid::HandlePointerEventL( aPointerEvent );
   278         CAknGrid::HandlePointerEventL( aPointerEvent );
   255         }
   279         }
   256     else if ( View()->XYPosToItemIndex(
   280     else if ( View()->XYPosToItemIndex(
   257             aPointerEvent.iPosition, itemUnderPointerIndex ) )
   281             aPointerEvent.iPosition, itemUnderPointerIndex ) )
   258         {
   282         {
   636         {
   660         {
   637         iViewLayout = TSize( MmGrid::K3By4LayoutX, MmGrid::K3By4LayoutY );
   661         iViewLayout = TSize( MmGrid::K3By4LayoutX, MmGrid::K3By4LayoutY );
   638         }
   662         }
   639 
   663 
   640     DoSetupLayoutL();
   664     DoSetupLayoutL();
       
   665     iRedrawTimer = CPeriodic::NewL( EPriorityRealTime );
   641     }
   666     }
   642 
   667 
   643 // -----------------------------------------------------------------------------
   668 // -----------------------------------------------------------------------------
   644 //
   669 //
   645 // -----------------------------------------------------------------------------
   670 // -----------------------------------------------------------------------------
   953 
   978 
   954 // -----------------------------------------------------------------------------
   979 // -----------------------------------------------------------------------------
   955 //
   980 //
   956 // -----------------------------------------------------------------------------
   981 // -----------------------------------------------------------------------------
   957 //
   982 //
       
   983 void CMmGrid::ProcessScrollEventL( CEikScrollBar* aScrollBar, 
       
   984             TEikScrollEvent aEventType )
       
   985     {
       
   986     CAknGrid::HandleScrollEventL( aScrollBar, aEventType );
       
   987     iCurrentTopItemIndex = TopItemIndex();
       
   988 
       
   989     // setting default highligh in order not to overwrite the top item index
       
   990     // set before in the SetLayout method
       
   991     CMmWidgetContainer* parent = static_cast< CMmWidgetContainer* > ( Parent() );
       
   992     if (!parent->IsHighlightVisible())
       
   993          {
       
   994          parent->SetDefaultHighlightL( EFalse );
       
   995 
       
   996 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   997          MAknListBoxTfxInternal* transApi = CAknListLoader::TfxApiInternal(
       
   998                  static_cast<CMmGridView*>(iView)->Gc() );
       
   999          TBool effects = transApi && !transApi->EffectsDisabled();
       
  1000          if ( effects && aEventType == EEikScrollPageUp ||
       
  1001                  aEventType == EEikScrollPageDown )
       
  1002              {
       
  1003              DrawNow();
       
  1004              }
       
  1005 #endif
       
  1006 
       
  1007          }
       
  1008     }
       
  1009 
       
  1010 // -----------------------------------------------------------------------------
       
  1011 //
       
  1012 // -----------------------------------------------------------------------------
       
  1013 //
       
  1014 void CMmGrid::HandleRedrawTimerEvent()
       
  1015     {
       
  1016     if ( iSkippedScrollbarEventsCount )
       
  1017         {
       
  1018         ProcessScrollEventL( ScrollBarFrame()->VerticalScrollBar(),
       
  1019                 EEikScrollThumbDragVert );
       
  1020         }
       
  1021     iSkippedScrollbarEventsCount = 0;
       
  1022     }
       
  1023     
       
  1024 // -----------------------------------------------------------------------------
       
  1025 //
       
  1026 // -----------------------------------------------------------------------------
       
  1027 //
       
  1028 TInt CMmGrid::RedrawTimerCallback( TAny* aPtr )
       
  1029     {
       
  1030     CMmGrid* self = static_cast<CMmGrid*>( aPtr );
       
  1031     self->HandleRedrawTimerEvent();
       
  1032     return 0;
       
  1033     }
       
  1034 
       
  1035 // -----------------------------------------------------------------------------
       
  1036 //
       
  1037 // -----------------------------------------------------------------------------
       
  1038 //
   958 void CMmGrid::SetVerticalItemOffset(TInt aOffset)
  1039 void CMmGrid::SetVerticalItemOffset(TInt aOffset)
   959 	{
  1040 	{
   960 	static_cast<CMmGridView*> (View())->SetItemOffsetInPixels(aOffset);
  1041 	static_cast<CMmGridView*> (View())->SetItemOffsetInPixels(aOffset);
   961 	UpdateScrollBarThumbs();
  1042 	UpdateScrollBarThumbs();
   962 	}
  1043 	}