menufw/menufwui/mmwidgets/src/mmgrid.cpp
branchRCL_3
changeset 25 137ebc85284b
parent 19 79311d856354
child 26 1b758917cafc
equal deleted inserted replaced
23:7be2816dbabd 25:137ebc85284b
    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_103 % << Don't touch! Updated by Synergy at check-out.
    15 *  Version     : %version: MM_104 % << 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>
   275     if ( aPointerEvent.iType == TPointerEvent::EButton1Up ||
   275     if ( aPointerEvent.iType == TPointerEvent::EButton1Up ||
   276             aPointerEvent.iType == TPointerEvent::EButton1Down )
   276             aPointerEvent.iType == TPointerEvent::EButton1Down )
   277         {
   277         {
   278         TBool highlightWasVisible = parent->IsHighlightVisible();
   278         TBool highlightWasVisible = parent->IsHighlightVisible();
   279         CAknGrid::HandlePointerEventL( aPointerEvent );
   279         CAknGrid::HandlePointerEventL( aPointerEvent );
   280         // Tricky: Do not allow the base class implementation of HandlePointerEventL 
   280         // Tricky: Do not allow the base class implementation of HandlePointerEventL
   281         //         to remove the highlight on EButton1Up event when context menu
   281         //         to remove the highlight on EButton1Up event when context menu
   282         //         is displayed for an item
   282         //         is displayed for an item
   283         if ( aPointerEvent.iType == TPointerEvent::EButton1Up &&
   283         if ( aPointerEvent.iType == TPointerEvent::EButton1Up &&
   284                 highlightWasVisible && parent->LongTapInProgress()
   284                 highlightWasVisible && parent->LongTapInProgress()
   285                 && !parent->IsHighlightVisible() )
   285                 && !parent->IsHighlightVisible() )
   291             aPointerEvent.iPosition, itemUnderPointerIndex ) )
   291             aPointerEvent.iPosition, itemUnderPointerIndex ) )
   292         {
   292         {
   293         if ( CurrentItemIndex() != itemUnderPointerIndex )
   293         if ( CurrentItemIndex() != itemUnderPointerIndex )
   294             {
   294             {
   295             CMmWidgetContainer* parent = static_cast<CMmWidgetContainer*>( Parent() );
   295             CMmWidgetContainer* parent = static_cast<CMmWidgetContainer*>( Parent() );
   296     		if ( parent->IsNoItemDragged() )
   296         if ( parent->IsNoItemDragged() )
   297     			{
   297           {
   298     			if ( ItemDrawer()->Flags() & CListItemDrawer::EPressedDownState )
   298           if ( ItemDrawer()->Flags() & CListItemDrawer::EPressedDownState )
   299     				{
   299             {
   300     				ItemDrawer()->ClearFlags( CListItemDrawer::EPressedDownState );
   300             ItemDrawer()->ClearFlags( CListItemDrawer::EPressedDownState );
   301     				iView->DrawItem( CurrentItemIndex() );
   301             iView->DrawItem( CurrentItemIndex() );
   302     				}
   302             }
   303     			}
   303           }
   304     		else
   304         else
   305     			{
   305           {
   306     			iView->SetCurrentItemIndex( itemUnderPointerIndex );
   306           iView->SetCurrentItemIndex( itemUnderPointerIndex );
   307 				iView->DrawItem(itemUnderPointerIndex);
   307         iView->DrawItem(itemUnderPointerIndex);
   308     			}
   308           }
   309             }
   309             }
   310         }
   310         }
   311 
   311 
   312     HandleScrollingInEditMode( aPointerEvent );
   312     HandleScrollingInEditMode( aPointerEvent );
   313     }
   313     }
   387     if ( itemCount % numOfCols )
   387     if ( itemCount % numOfCols )
   388         {
   388         {
   389         ++totalNumberOfRows;
   389         ++totalNumberOfRows;
   390         }
   390         }
   391     const TInt topItemRowIndex = TopItemIndex() / numOfCols;
   391     const TInt topItemRowIndex = TopItemIndex() / numOfCols;
   392     
   392 
   393     // desired view position relative to the first item in grid (always positive)
   393     // desired view position relative to the first item in grid (always positive)
   394     TInt desiredViewPosition = rowHeight * topItemRowIndex - VerticalItemOffset();
   394     TInt desiredViewPosition = rowHeight * topItemRowIndex - VerticalItemOffset();
   395     
   395 
   396     desiredViewPosition += distanceInPixels;
   396     desiredViewPosition += distanceInPixels;
   397     
   397 
   398     const TInt viewPositionMin = 0;
   398     const TInt viewPositionMin = 0;
   399     const TInt viewPositionMax = 
   399     const TInt viewPositionMax =
   400 		Max( 0, ( totalNumberOfRows * rowHeight ) - view->ViewRect().Height() );
   400     Max( 0, ( totalNumberOfRows * rowHeight ) - view->ViewRect().Height() );
   401     
   401 
   402     desiredViewPosition = Min( desiredViewPosition, viewPositionMax );
   402     desiredViewPosition = Min( desiredViewPosition, viewPositionMax );
   403     desiredViewPosition = Max( desiredViewPosition, viewPositionMin );
   403     desiredViewPosition = Max( desiredViewPosition, viewPositionMin );
   404    
   404 
   405     ASSERT( desiredViewPosition >= 0 );
   405     ASSERT( desiredViewPosition >= 0 );
   406     
   406 
   407     TInt newTopItemIndex = ( desiredViewPosition / rowHeight ) * numOfCols;
   407     TInt newTopItemIndex = ( desiredViewPosition / rowHeight ) * numOfCols;
   408     TInt newVerticalOffset = -( desiredViewPosition % rowHeight ); 
   408     TInt newVerticalOffset = -( desiredViewPosition % rowHeight );
   409     SetTopItemIndex( newTopItemIndex );
   409     SetTopItemIndex( newTopItemIndex );
   410     SetVerticalItemOffset( newVerticalOffset );
   410     SetVerticalItemOffset( newVerticalOffset );
   411     }
   411     }
   412 
   412 
   413 // -----------------------------------------------------------------------------
   413 // -----------------------------------------------------------------------------
   418     {
   418     {
   419     CAknGridView* view = static_cast<CAknGridView*>( View() );
   419     CAknGridView* view = static_cast<CAknGridView*>( View() );
   420     TInt nextScrollDelay = 0;
   420     TInt nextScrollDelay = 0;
   421 
   421 
   422     TBool readyForScrolling = iMmDrawer->GetAnimator()->IsReadyForNewAnimation()
   422     TBool readyForScrolling = iMmDrawer->GetAnimator()->IsReadyForNewAnimation()
   423 		&& iMmDrawer->GetFloatingItemCount() != 0;
   423     && iMmDrawer->GetFloatingItemCount() != 0;
   424 
   424 
   425 	if ( IsPointerInTopScrollingThreshold( aPointerEvent ) )
   425   if ( IsPointerInTopScrollingThreshold( aPointerEvent ) )
   426 		{
   426     {
   427 		// scroll up by one row
   427     // scroll up by one row
   428 		TInt newCurrentItemIndex = CurrentItemIndex() - view->NumberOfColsInView();
   428     TInt newCurrentItemIndex = CurrentItemIndex() - view->NumberOfColsInView();
   429         if ( newCurrentItemIndex < 0 )
   429         if ( newCurrentItemIndex < 0 )
   430             {
   430             {
   431             newCurrentItemIndex = CurrentItemIndex();
   431             newCurrentItemIndex = CurrentItemIndex();
   432             }
   432             }
   433 
   433 
   434        nextScrollDelay = MmEffects::KEditModeScrollingDelayFactor *
   434        nextScrollDelay = MmEffects::KEditModeScrollingDelayFactor *
   435 		   Max( 1, aPointerEvent.iPosition.iY - Rect().iTl.iY );
   435        Max( 1, aPointerEvent.iPosition.iY - Rect().iTl.iY );
   436 
   436 
   437 		if ( readyForScrolling )
   437     if ( readyForScrolling )
   438 			{
   438       {
   439 			ScrollWithoutRedraw( -iItemHeight );
   439       ScrollWithoutRedraw( -iItemHeight );
   440 			View()->SetCurrentItemIndex( newCurrentItemIndex );
   440       View()->SetCurrentItemIndex( newCurrentItemIndex );
   441 			}
   441       }
   442 		}
   442     }
   443 	else if ( IsPointerInBottomScrollingThreshold( aPointerEvent) )
   443   else if ( IsPointerInBottomScrollingThreshold( aPointerEvent) )
   444 		{
   444     {
   445 		TInt newCurrentItemIndex = CurrentItemIndex() + view->NumberOfColsInView();
   445     TInt newCurrentItemIndex = CurrentItemIndex() + view->NumberOfColsInView();
   446 		if ( newCurrentItemIndex > iModel->NumberOfItems() - 1 )
   446     if ( newCurrentItemIndex > iModel->NumberOfItems() - 1 )
   447 			{
   447       {
   448 			newCurrentItemIndex = CurrentItemIndex();
   448       newCurrentItemIndex = CurrentItemIndex();
   449 			}
   449       }
   450 	
   450 
   451 		nextScrollDelay = MmEffects::KEditModeScrollingDelayFactor *
   451     nextScrollDelay = MmEffects::KEditModeScrollingDelayFactor *
   452 			Max( 1, Rect().iBr.iY - aPointerEvent.iPosition.iY );
   452       Max( 1, Rect().iBr.iY - aPointerEvent.iPosition.iY );
   453 
   453 
   454 		if ( readyForScrolling )
   454     if ( readyForScrolling )
   455 			{
   455       {
   456 			ScrollWithoutRedraw( iItemHeight );
   456       ScrollWithoutRedraw( iItemHeight );
   457 			View()->SetCurrentItemIndex( newCurrentItemIndex );
   457       View()->SetCurrentItemIndex( newCurrentItemIndex );
   458 			}
   458       }
   459 		}
   459     }
   460 
   460 
   461     return nextScrollDelay;
   461     return nextScrollDelay;
   462     }
   462     }
   463 
   463 
   464 // -----------------------------------------------------------------------------
   464 // -----------------------------------------------------------------------------
   689         }
   689         }
   690     TInt maxPossibleTopRow = Max( 0, lastRow - numOfRows + 1 );
   690     TInt maxPossibleTopRow = Max( 0, lastRow - numOfRows + 1 );
   691 
   691 
   692     TInt topRow = TopItemIndex() / numOfCols;
   692     TInt topRow = TopItemIndex() / numOfCols;
   693 
   693 
   694     if ( !( TopItemIndex() % numOfCols == 0 &&
   694     if( !( TopItemIndex() % numOfCols == 0
   695          topRow <= maxPossibleTopRow ) )
   695             && topRow <= maxPossibleTopRow ) )
   696         {
   696         {
   697         topRow = Min( topRow, maxPossibleTopRow );
   697         topRow = Min( topRow, maxPossibleTopRow );
   698         SetTopItemIndex( topRow * numOfCols );
   698         SetTopItemIndex( topRow * numOfCols );
       
   699         }
       
   700     else if( ( (CMmWidgetContainer* ) Parent() )->IsEditMode()
       
   701             && ( Abs(maxPossibleTopRow - topRow) == 1) // prevention scrolling both scrollbar and view too much rows
       
   702             && !View()->ItemIsPartiallyVisible(TopItemIndex())) // prevention scrolling view during remove item via menu
       
   703         {
       
   704         SetTopItemIndex( maxPossibleTopRow * numOfCols );
   699         }
   705         }
   700 
   706 
   701     // prevent problems with view being scrolled up beyond limits
   707     // prevent problems with view being scrolled up beyond limits
   702     if ( topRow == maxPossibleTopRow && VerticalItemOffset() < 0 )
   708     if ( topRow == maxPossibleTopRow && VerticalItemOffset() < 0 )
   703         {
   709         {
   922 
   928 
   923 // -----------------------------------------------------------------------------
   929 // -----------------------------------------------------------------------------
   924 //
   930 //
   925 // -----------------------------------------------------------------------------
   931 // -----------------------------------------------------------------------------
   926 //
   932 //
   927 void CMmGrid::ProcessScrollEventL( CEikScrollBar* aScrollBar, 
   933 void CMmGrid::ProcessScrollEventL( CEikScrollBar* aScrollBar,
   928             TEikScrollEvent aEventType )
   934             TEikScrollEvent aEventType )
   929     {
   935     {
   930     CAknGrid::HandleScrollEventL( aScrollBar, aEventType );
   936     CAknGrid::HandleScrollEventL( aScrollBar, aEventType );
   931     iCurrentTopItemIndex = TopItemIndex();
   937     iCurrentTopItemIndex = TopItemIndex();
   932 
   938 
   933     // setting default highligh in order not to overwrite the top item index
   939     // setting default highlight in order not to overwrite the top item index
   934     // set before in the SetLayout method
   940     // set before in the SetLayout method
   935     CMmWidgetContainer* parent = static_cast< CMmWidgetContainer* > ( Parent() );
   941     CMmWidgetContainer* parent = static_cast< CMmWidgetContainer* > ( Parent() );
   936     if (!parent->IsHighlightVisible())
   942     if (!parent->IsHighlightVisible())
   937          {
   943          {
   938          parent->SetDefaultHighlightL( EFalse );
   944          parent->SetDefaultHighlightL( EFalse );
   962         ProcessScrollEventL( ScrollBarFrame()->VerticalScrollBar(),
   968         ProcessScrollEventL( ScrollBarFrame()->VerticalScrollBar(),
   963                 EEikScrollThumbDragVert );
   969                 EEikScrollThumbDragVert );
   964         }
   970         }
   965     iSkippedScrollbarEventsCount = 0;
   971     iSkippedScrollbarEventsCount = 0;
   966     }
   972     }
   967     
   973 
   968 // -----------------------------------------------------------------------------
   974 // -----------------------------------------------------------------------------
   969 //
   975 //
   970 // -----------------------------------------------------------------------------
   976 // -----------------------------------------------------------------------------
   971 //
   977 //
   972 TInt CMmGrid::RedrawTimerCallback( TAny* aPtr )
   978 TInt CMmGrid::RedrawTimerCallback( TAny* aPtr )
   981 // -----------------------------------------------------------------------------
   987 // -----------------------------------------------------------------------------
   982 //
   988 //
   983 // -----------------------------------------------------------------------------
   989 // -----------------------------------------------------------------------------
   984 //
   990 //
   985 void CMmGrid::SetVerticalItemOffset(TInt aOffset)
   991 void CMmGrid::SetVerticalItemOffset(TInt aOffset)
   986 	{
   992   {
   987 	static_cast<CMmGridView*> (View())->SetItemOffsetInPixels(aOffset);
   993   static_cast<CMmGridView*> (View())->SetItemOffsetInPixels(aOffset);
   988 	UpdateScrollBarThumbs();
   994   UpdateScrollBarThumbs();
   989 	}
   995   }
   990 
   996 
   991 // -----------------------------------------------------------------------------
   997 // -----------------------------------------------------------------------------
   992 //
   998 //
   993 // -----------------------------------------------------------------------------
   999 // -----------------------------------------------------------------------------
   994 //
  1000 //
   995 TInt CMmGrid::VerticalItemOffset() const
  1001 TInt CMmGrid::VerticalItemOffset() const
   996 	{
  1002   {
   997 	return static_cast<CMmGridView*> (View())->VerticalItemOffset();
  1003   return static_cast<CMmGridView*> (View())->VerticalItemOffset();
   998 	}
  1004   }
   999 
  1005 
  1000 // -----------------------------------------------------------------------------
  1006 // -----------------------------------------------------------------------------
  1001 //
  1007 //
  1002 // -----------------------------------------------------------------------------
  1008 // -----------------------------------------------------------------------------
  1003 //
  1009 //
  1004 void CMmGrid::SetItemHeight( TInt aItemHeight )
  1010 void CMmGrid::SetItemHeight( TInt aItemHeight )
  1005 	{
  1011   {
  1006 	iItemHeight = aItemHeight;
  1012   iItemHeight = aItemHeight;
  1007 	}
  1013   }
  1008 
  1014 
  1009 // -----------------------------------------------------------------------------
  1015 // -----------------------------------------------------------------------------
  1010 //
  1016 //
  1011 // -----------------------------------------------------------------------------
  1017 // -----------------------------------------------------------------------------
  1012 //
  1018 //
  1013 void CMmGrid::UpdateScrollBarThumbs()
  1019 void CMmGrid::UpdateScrollBarThumbs()
  1014 	{
  1020   {
  1015 	CAknGrid::UpdateScrollBarThumbs();
  1021   CAknGrid::UpdateScrollBarThumbs();
  1016 	}
  1022   }
  1017 
  1023 
  1018 // -----------------------------------------------------------------------------
  1024 // -----------------------------------------------------------------------------
  1019 //
  1025 //
  1020 // -----------------------------------------------------------------------------
  1026 // -----------------------------------------------------------------------------
  1021 //
  1027 //
  1022 TInt CMmGrid::CountComponentControls() const
  1028 TInt CMmGrid::CountComponentControls() const
  1023     {
  1029     {
  1024     TInt componentControls(0);
  1030     TInt componentControls(0);
  1025     if ( !iDisableChildComponentDrawing )
  1031     if ( !iDisableChildComponentDrawing )
  1026     	{
  1032       {
  1027         componentControls = CAknGrid::CountComponentControls();
  1033         componentControls = CAknGrid::CountComponentControls();
  1028     	}
  1034       }
  1029     return componentControls;
  1035     return componentControls;
  1030     }
  1036     }
  1031 // -----------------------------------------------------------------------------
  1037 // -----------------------------------------------------------------------------
  1032 //
  1038 //
  1033 // -----------------------------------------------------------------------------
  1039 // -----------------------------------------------------------------------------