menufw/menufwui/mmwidgets/src/mmgrid.cpp
changeset 0 f72a12da539e
child 1 5315654608de
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2007 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 *  Version     : %version: MM_92 % << Don't touch! Updated by Synergy at check-out.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <AknsDrawUtils.h>
       
    21 #include <layoutmetadata.cdl.h>
       
    22 #include "mmgrid.h"
       
    23 #include "mmgridmodel.h"
       
    24 #include "mmlistboxitemdrawer.h"
       
    25 #include "mmgridview.h"
       
    26 #include "mmtemplatelibrary.h"
       
    27 #include "mmlistboxmodel.h"
       
    28 #include "mmmarqueeadapter.h"
       
    29 #include "mmwidgetsconstants.h"
       
    30 #include "mmwidgetcontainer.h"
       
    31 #include "hnsuitemodel.h"
       
    32 #include "mmdraweranimator.h"
       
    33 
       
    34 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
    35 #include <aknlistloadertfx.h>
       
    36 #include <aknlistboxtfxinternal.h>
       
    37 #endif
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CMmGrid::CMmGrid()
       
    44     {
       
    45     // No implementation required
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CMmGrid::~CMmGrid()
       
    53     {
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CMmGrid* CMmGrid::NewLC( const CCoeControl* aParent, TInt aFlags,
       
    61         CMmTemplateLibrary* aTemplateLibrary)
       
    62     {
       
    63     CMmGrid* self = new (ELeave)CMmGrid();
       
    64     CleanupStack::PushL(self);
       
    65     self->ConstructL( aParent, aFlags, aTemplateLibrary );
       
    66     return self;
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CMmGrid* CMmGrid::NewL( const CCoeControl* aParent, TInt aFlags,
       
    74         CMmTemplateLibrary* aTemplateLibrary )
       
    75     {
       
    76     CMmGrid* self = CMmGrid::NewLC( aParent, aFlags, aTemplateLibrary );
       
    77     CleanupStack::Pop( self );
       
    78     return self;
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // If a parent to the supplied control has its Gc set, this function will find
       
    83 // it and return it. (Copied from EIKLBX.CPP, needed by CMmGrid::Draw)
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 LOCAL_C CWindowGc* ReplaceGcWithCustomGc( const CEikListBox* aListBox )
       
    87     {
       
    88     const CCoeControl* parent = aListBox;
       
    89     CWindowGc* customGc;
       
    90     while(parent)
       
    91         {
       
    92         customGc = parent->GetGc();
       
    93         if ( customGc )
       
    94             {
       
    95             CListItemDrawer* itemDrawer = aListBox->View()->ItemDrawer();
       
    96             CWindowGc* originalGc = itemDrawer->Gc();
       
    97             if ( customGc == originalGc )
       
    98             {
       
    99                 return NULL;
       
   100                 }
       
   101             else
       
   102                 {
       
   103                 itemDrawer->SetGc( customGc );
       
   104                 return originalGc;
       
   105                 }
       
   106             }
       
   107         parent = parent->Parent();
       
   108         }
       
   109     return NULL;
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 void CMmGrid::Draw(const TRect& aRect) const
       
   117     {
       
   118     if ( View()->RedrawDisabled () || !IsVisible () )
       
   119         {
       
   120         return;
       
   121         }
       
   122     iMmDrawer->SetNumberOfColsInView(
       
   123             static_cast<CMmGridView*>(iView)->NumberOfColsInView() );
       
   124 
       
   125     // If a parent has a custom gc, draw listbox using that gc
       
   126     CWindowGc* replacedGc = ReplaceGcWithCustomGc( this );
       
   127 
       
   128     CWindowGc* gc = iItemDrawer->Gc();
       
   129     TGulBorder::TColors borderColors;
       
   130     iBorder.Draw(*gc, Rect(), borderColors);
       
   131 
       
   132 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   133     MAknListBoxTfxInternal* transApi = CAknListLoader::TfxApiInternal(
       
   134             static_cast<CMmGridView*>(iView)->Gc() );
       
   135     TBool effects = transApi && !transApi->EffectsDisabled();
       
   136     if ( effects )
       
   137         {
       
   138         // ViewRect might have been moved to the right to prevent grid items
       
   139         // from overlapping the scrollbar in mirrored layout.
       
   140         // However, we still have to draw scrollbar background, thus the
       
   141         // rectangle object passed to MAknListBoxTfxInternal::BeginRedraw must
       
   142         // be placed at (0, 0) so that it covers the area where scrollbar is
       
   143         // drawn.
       
   144         TRect r( View()->ViewRect().Size() );
       
   145         transApi->BeginRedraw( MAknListBoxTfxInternal::EListView, r );
       
   146         transApi->StartDrawing( MAknListBoxTfxInternal::EListView );
       
   147         }
       
   148 #endif // RD_UI_TRANSITION_EFFECTS_LIST
       
   149 
       
   150     ClearMargins();
       
   151     RedrawScrollbarBackground();
       
   152 
       
   153 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   154     if ( effects )
       
   155         {
       
   156         transApi->StopDrawing();
       
   157         }
       
   158 #endif // RD_UI_TRANSITION_EFFECTS_LIST
       
   159     iView->Draw(&aRect);
       
   160 
       
   161 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   162     if ( effects )
       
   163         {
       
   164         transApi->EndViewRedraw( aRect );
       
   165         }
       
   166 #endif // RD_UI_TRANSITION_EFFECTS_LIST
       
   167 
       
   168     if ( replacedGc )
       
   169         {
       
   170         // Stop using the custom gc
       
   171         iItemDrawer->SetGc( replacedGc );
       
   172         }
       
   173     }
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 void CMmGrid::DrawView()
       
   179     {
       
   180     iDisableChildComponentDrawing = ETrue;
       
   181     DrawNow(Rect());
       
   182     iDisableChildComponentDrawing = EFalse;
       
   183     }
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 // -----------------------------------------------------------------------------
       
   188 //   
       
   189 void CMmGrid::CreateItemDrawerL()
       
   190     {
       
   191     iItemDrawer = iMmDrawer;
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 void CMmGrid::CreateItemDrawerL( CMmTemplateLibrary* aTemplateLibrary )
       
   199     {
       
   200     CFormattedCellListBoxData* data=CFormattedCellGridData::NewL();
       
   201     CleanupStack::PushL(data);
       
   202 
       
   203     iMmDrawer = CMmListBoxItemDrawer::NewL(
       
   204         MmModel()->MmListBoxModel(), iEikonEnv->NormalFont(), data, EGrid,
       
   205         aTemplateLibrary );
       
   206     iItemDrawer = iMmDrawer;
       
   207     data->SetControl( this );
       
   208     CleanupStack::Pop( data );
       
   209     }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 void CMmGrid::HandleScrollEventL( CEikScrollBar* aScrollBar,
       
   216         TEikScrollEvent aEventType )
       
   217     {
       
   218     CAknGrid::HandleScrollEventL(aScrollBar, aEventType);
       
   219     iCurrentTopItemIndex = TopItemIndex();
       
   220 
       
   221     // setting default highligh in order not to overwrite the top item index
       
   222     // set before in the SetLayout method
       
   223     CMmWidgetContainer* parent = static_cast< CMmWidgetContainer* > ( Parent() );
       
   224     if (!parent->IsHighlightVisible())
       
   225          {
       
   226          parent->SetDefaultHighlightL( EFalse );
       
   227 
       
   228 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   229          MAknListBoxTfxInternal* transApi = CAknListLoader::TfxApiInternal(
       
   230                  static_cast<CMmGridView*>(iView)->Gc() );
       
   231          TBool effects = transApi && !transApi->EffectsDisabled();
       
   232          if ( effects && aEventType == EEikScrollPageUp ||
       
   233                  aEventType == EEikScrollPageDown )
       
   234              {
       
   235              DrawNow();
       
   236              }
       
   237 #endif
       
   238          
       
   239          }
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 void CMmGrid::HandlePointerEventInEditModeL( const TPointerEvent& aPointerEvent )
       
   247     {
       
   248     TInt itemUnderPointerIndex = KErrNotFound;
       
   249 
       
   250     if ( aPointerEvent.iType == TPointerEvent::EButton1Up ||
       
   251             aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   252         {
       
   253         CAknGrid::HandlePointerEventL( aPointerEvent );
       
   254         }
       
   255     else if ( View()->XYPosToItemIndex(
       
   256             aPointerEvent.iPosition, itemUnderPointerIndex ) )
       
   257         {
       
   258         if ( CurrentItemIndex() != itemUnderPointerIndex )
       
   259             {
       
   260             CMmWidgetContainer* parent = static_cast<CMmWidgetContainer*>( Parent() );
       
   261     		if ( parent->IsNoItemDragged() )
       
   262     			{
       
   263     			if ( ItemDrawer()->Flags() & CListItemDrawer::EPressedDownState )
       
   264     				{
       
   265     				ItemDrawer()->ClearFlags( CListItemDrawer::EPressedDownState );
       
   266     				iView->DrawItem( CurrentItemIndex() );
       
   267     				}
       
   268     			}
       
   269     		else
       
   270     			{
       
   271     			iView->SetCurrentItemIndex( itemUnderPointerIndex );
       
   272 				iView->DrawItem(itemUnderPointerIndex);
       
   273     			}
       
   274             }
       
   275         }
       
   276 
       
   277     HandleScrollingInEditMode( aPointerEvent );
       
   278     }
       
   279 
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 // -----------------------------------------------------------------------------
       
   283 //
       
   284 void CMmGrid::HandlePointerEventInNormalModeL( const TPointerEvent& aPointerEvent )
       
   285     {
       
   286     CMmWidgetContainer* parent = static_cast<CMmWidgetContainer*>( Parent() );
       
   287     if ( aPointerEvent.iType == TPointerEvent::EButton1Down && !parent->FlipOpen() )
       
   288 		{
       
   289         const TInt KIgnoreRectSize = 40;
       
   290         TRect ignoreDragRect(aPointerEvent.iPosition,
       
   291                 TSize(KIgnoreRectSize, KIgnoreRectSize));
       
   292         ignoreDragRect.Move( - KIgnoreRectSize / 2, - KIgnoreRectSize / 2 );
       
   293         Window().RequestPointerRepeatEvent( 50000, ignoreDragRect );
       
   294 		}
       
   295     else if ( aPointerEvent.iType == TPointerEvent::EButtonRepeat )
       
   296         {
       
   297         HandleButtonRepeatEventInNormalModeL( aPointerEvent );
       
   298         }
       
   299 	CAknGrid::HandlePointerEventL(aPointerEvent);
       
   300     }
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 // -----------------------------------------------------------------------------
       
   305 //
       
   306 void CMmGrid::HandleButtonRepeatEventInNormalModeL(
       
   307         const TPointerEvent& aPointerEvent )
       
   308     {
       
   309     TInt itemUnderPointerIndex = KErrNotFound;
       
   310     TBool itemFound = View()->XYPosToItemIndex(
       
   311             aPointerEvent.iPosition, itemUnderPointerIndex );
       
   312     if ( !itemFound )
       
   313         {
       
   314         return;
       
   315         }
       
   316 
       
   317     View()->ItemDrawer()->SetFlags( CListItemDrawer::EPressedDownState );
       
   318     CMmWidgetContainer* parent = static_cast<CMmWidgetContainer*>( Parent() );
       
   319     TBool highlightWasVisible = parent->IsHighlightVisible();
       
   320     
       
   321     if( itemUnderPointerIndex == View()->CurrentItemIndex() )
       
   322         {
       
   323 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   324         MAknListBoxTfxInternal *transApi = CAknListLoader::TfxApiInternal(
       
   325                 iMmDrawer->Gc() );
       
   326          if ( transApi )
       
   327              {
       
   328              transApi->Remove( MAknListBoxTfxInternal::EListHighlight );
       
   329              View()->DrawItem( itemUnderPointerIndex );
       
   330              TRect itemUnderPointerIndexRect (
       
   331                      View()->ItemPos(itemUnderPointerIndex),
       
   332                      View()->ItemSize(itemUnderPointerIndex));
       
   333              transApi->Draw( itemUnderPointerIndexRect );
       
   334              }
       
   335          else
       
   336         	 {
       
   337         	 View()->DrawItem( itemUnderPointerIndex );
       
   338         	 }
       
   339 #else
       
   340          View()->DrawItem( itemUnderPointerIndex );
       
   341 #endif
       
   342         }  
       
   343      else
       
   344         {
       
   345         TInt previouslyHighlightedItemIndex = View()->CurrentItemIndex();
       
   346         parent->SetManualHighlightL( itemUnderPointerIndex , EFalse );
       
   347         if ( highlightWasVisible )
       
   348             {
       
   349             View()->DrawItem( previouslyHighlightedItemIndex );
       
   350             }
       
   351         }
       
   352     }
       
   353     
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 // -----------------------------------------------------------------------------
       
   357 //
       
   358 void CMmGrid::HandleScrollingInEditMode( const TPointerEvent& aPointerEvent )
       
   359     {
       
   360     if ( aPointerEvent.iType == TPointerEvent::EDrag
       
   361             || aPointerEvent.iType == TPointerEvent::EButtonRepeat )
       
   362         {
       
   363         TInt nextScrollDelay = ScrollIfNeeded( aPointerEvent );
       
   364         if ( nextScrollDelay )
       
   365             {
       
   366             TRect ignoreDragRect(
       
   367                 TPoint(aPointerEvent.iParentPosition.iX - MmEffects::KDragIgnoreRectValue,
       
   368                     aPointerEvent.iParentPosition.iY - MmEffects::KDragIgnoreRectValue),
       
   369                 TPoint(aPointerEvent.iParentPosition.iX + MmEffects::KDragIgnoreRectValue,
       
   370                     aPointerEvent.iParentPosition.iY + MmEffects::KDragIgnoreRectValue));
       
   371 
       
   372             Window().CancelPointerRepeatEventRequest();
       
   373             Window().RequestPointerRepeatEvent( nextScrollDelay, ignoreDragRect );
       
   374             }
       
   375         }
       
   376     }
       
   377 
       
   378 // -----------------------------------------------------------------------------
       
   379 //
       
   380 // -----------------------------------------------------------------------------
       
   381 //
       
   382 TBool CMmGrid::IsPointerInTopScrollingThreshold(
       
   383             const TPointerEvent& aPointerEvent ) const
       
   384     {
       
   385     TInt topScrollingTreshold = Rect().iTl.iY
       
   386         + ( MmEffects::KFocusScrollingThreshold
       
   387             * TReal( View()->ItemSize().iHeight ) );
       
   388 
       
   389     return ( aPointerEvent.iPosition.iY < topScrollingTreshold );
       
   390     }
       
   391 
       
   392 // -----------------------------------------------------------------------------
       
   393 //
       
   394 // -----------------------------------------------------------------------------
       
   395 //
       
   396 TBool CMmGrid::IsPointerInBottomScrollingThreshold(
       
   397             const TPointerEvent& aPointerEvent ) const
       
   398     {
       
   399     TInt bottomScrollingTreshold = Rect().iBr.iY
       
   400         - ( MmEffects::KFocusScrollingThreshold
       
   401             * TReal( View()->ItemSize().iHeight ) );
       
   402 
       
   403     return ( aPointerEvent.iPosition.iY > bottomScrollingTreshold );
       
   404     }
       
   405 
       
   406 // -----------------------------------------------------------------------------
       
   407 //
       
   408 // -----------------------------------------------------------------------------
       
   409 //
       
   410 TInt CMmGrid::ScrollIfNeeded( const TPointerEvent& aPointerEvent )
       
   411     {
       
   412     CAknGridView* view = static_cast<CAknGridView*>( View() );
       
   413     TInt nextScrollDelay = 0;
       
   414 
       
   415     TBool readyForScrolling = iMmDrawer->GetAnimator()->IsReadyForNewAnimation() 
       
   416 		&& iMmDrawer->GetFloatingItemCount() != 0;
       
   417     
       
   418 	if ( IsPointerInTopScrollingThreshold( aPointerEvent ) )
       
   419 		{
       
   420 		// scroll up by one row
       
   421 		      TInt newCurrentItemIndex = CurrentItemIndex() - view->NumberOfColsInView();
       
   422         if ( newCurrentItemIndex < 0 )
       
   423             {
       
   424             newCurrentItemIndex = CurrentItemIndex();
       
   425             }
       
   426 
       
   427         if ( !View()->ItemIsVisible( 0 ) )
       
   428             {
       
   429             nextScrollDelay = MmEffects::KEditModeScrollingDelayFactor *
       
   430                 Max( 1, aPointerEvent.iPosition.iY - Rect().iTl.iY );
       
   431             
       
   432             if ( readyForScrolling )
       
   433                 {
       
   434                 TRAP_IGNORE( HandlePhysicsScrollEventL( -iItemHeight ) );
       
   435                 View()->SetCurrentItemIndex( newCurrentItemIndex );
       
   436                 }
       
   437             }
       
   438         else
       
   439             {
       
   440             if ( readyForScrolling )
       
   441             	{
       
   442 				TBool redrawDisabledBefore = View()->RedrawDisabled();
       
   443 				View()->SetDisableRedraw( EFalse );
       
   444 				CMmWidgetContainer* parent = static_cast<CMmWidgetContainer*>( Parent() );
       
   445 				parent->ResetWidgetPosition();
       
   446 				DrawNow();
       
   447 				View()->SetDisableRedraw( redrawDisabledBefore );
       
   448             	}
       
   449             }
       
   450 		}
       
   451 	else if ( IsPointerInBottomScrollingThreshold( aPointerEvent) )
       
   452 		{
       
   453 		// scroll down by one row
       
   454 		TInt lastItemIndex = iModel->NumberOfItems() - 1;
       
   455 
       
   456 		// maximum top item index that can be set (greater top item index value would
       
   457 		// cause an empty row at the bottom of the menu)
       
   458 		TInt maxTopItemIndex = View()->CalcNewTopItemIndexSoItemIsVisible( lastItemIndex );
       
   459 		TInt currentItemIndex = CurrentItemIndex();
       
   460 		TInt newCurrentItemIndex = currentItemIndex + view->NumberOfColsInView();
       
   461 		TInt distanceToScroll( iItemHeight );
       
   462 		if ( View()->ItemIsVisible( lastItemIndex ) )
       
   463 			{
       
   464 			TPoint lastItemPos( View()->ItemPos( lastItemIndex ) );
       
   465 			distanceToScroll = iItemHeight - ( Rect().iBr.iY - lastItemPos.iY )
       
   466 								+ Rect().Height() - iViewLayout.iHeight * iItemHeight;
       
   467 			}
       
   468 		
       
   469 		if ( newCurrentItemIndex <= lastItemIndex )
       
   470 			{
       
   471 			nextScrollDelay = MmEffects::KEditModeScrollingDelayFactor *
       
   472 				Max( 1, Rect().iBr.iY - aPointerEvent.iPosition.iY );
       
   473 			
       
   474 		    if ( readyForScrolling )
       
   475 		    	{
       
   476 		    	TRAP_IGNORE( HandlePhysicsScrollEventL( distanceToScroll ) );
       
   477 		    	View()->SetCurrentItemIndex( newCurrentItemIndex );
       
   478 		    	}
       
   479 			}
       
   480 		else if ( TopItemIndex() < maxTopItemIndex )
       
   481 			{
       
   482 		    if ( readyForScrolling )
       
   483 		    	{
       
   484 		    	TRAP_IGNORE( HandlePhysicsScrollEventL( distanceToScroll ) );
       
   485 		    	View()->SetCurrentItemIndex( currentItemIndex );
       
   486 		    	}
       
   487 			}
       
   488 		}
       
   489 	
       
   490     return nextScrollDelay;
       
   491     }
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 //
       
   495 // -----------------------------------------------------------------------------
       
   496 //
       
   497 void CMmGrid::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
   498     {
       
   499 //    if ( aPointerEvent.iType == TPointerEvent::EButton1Down &&
       
   500 //            iMmDrawer->CachedDataUseIsEnabled() )
       
   501 //        {
       
   502 //        // Touching the screen stops flick but avkon does not send us
       
   503 //        // MEikListBoxObserver::EEventFlickStopped event in such case.
       
   504 //        // Thus this little hack:
       
   505 //        iMmDrawer->EnableCachedDataUse( EFalse );
       
   506 //        DrawView();
       
   507 //        }
       
   508 
       
   509     CMmWidgetContainer* parent = static_cast<CMmWidgetContainer*>( Parent() );
       
   510     if ( parent->IsEditMode() )
       
   511         {
       
   512         HandlePointerEventInEditModeL( aPointerEvent );
       
   513         }
       
   514     else
       
   515         {
       
   516         HandlePointerEventInNormalModeL( aPointerEvent );
       
   517         }
       
   518 
       
   519     if ( iMmDrawer->GetFloatingItemCount() > 0 &&
       
   520             iMmDrawer->GetAnimator()->IsActive() )
       
   521         {
       
   522         iMmDrawer->GetAnimator()->CancelNextRedrawL();
       
   523         }
       
   524     }
       
   525 
       
   526 // -----------------------------------------------------------------------------
       
   527 //
       
   528 // -----------------------------------------------------------------------------
       
   529 //
       
   530 void CMmGrid::HandleOverridenHighlightDrawing( const TPointerEvent& aPointerEvent,
       
   531         TInt aIndexBefore, TInt aIndexAfter )
       
   532     {
       
   533     // In grid our behaviour is a little different than defalt avkon.
       
   534     // It is required to clean the highlight after the finger has been raised,
       
   535     // and simulate the tap effect, when an item that has an invisible
       
   536     // highlight is tapped again.
       
   537     TBool effects (EFalse);
       
   538 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   539         MAknListBoxTfxInternal *transApi = CAknListLoader::TfxApiInternal(
       
   540                 iMmDrawer->Gc() );
       
   541         effects = transApi && !transApi->EffectsDisabled();
       
   542 #endif
       
   543     if (effects)
       
   544         {
       
   545         CMmWidgetContainer* parent = static_cast< CMmWidgetContainer* > ( Parent() );
       
   546         if ( aIndexBefore == aIndexAfter
       
   547                 && !parent->IsEditMode()
       
   548                 && aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   549             {
       
   550             DrawItem( aIndexAfter );
       
   551 
       
   552 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   553             MAknListBoxTfxInternal *transApi = CAknListLoader::TfxApiInternal(
       
   554                     iMmDrawer->Gc() );
       
   555              if ( transApi )
       
   556                  {
       
   557                  transApi->SetMoveType( MAknListBoxTfxInternal::EListTap);
       
   558                  transApi->Draw( Rect() );
       
   559                  }
       
   560 #endif
       
   561             }
       
   562         else if ( aIndexBefore == aIndexAfter
       
   563                 && aPointerEvent.iType == TPointerEvent::EButton1Up
       
   564                 && !parent->IsHighlightVisible())
       
   565             {
       
   566 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   567             MAknListBoxTfxInternal *transApi = CAknListLoader::TfxApiInternal(
       
   568                     iMmDrawer->Gc() );
       
   569              if ( transApi )
       
   570                  {
       
   571                  transApi->Draw( Rect() );
       
   572                  }
       
   573 #endif
       
   574             }
       
   575         }
       
   576 
       
   577     }
       
   578 // -----------------------------------------------------------------------------
       
   579 //
       
   580 // -----------------------------------------------------------------------------
       
   581 //
       
   582 void CMmGrid::FixViewForMirroredLayout()
       
   583     {
       
   584     TInt scrollbarWidth = ScrollBarOffset() +
       
   585             ScrollBarFrame()->VerticalScrollBar()->Rect().Width();
       
   586     TRect r( View()->ViewRect() );
       
   587     TInt currentShift = r.iTl.iX;
       
   588     TBool scrollbarVisible = ScrollBarFrame()->VerticalScrollBar()->IsVisible();
       
   589     TBool layoutMirrored = AknLayoutUtils::LayoutMirrored();
       
   590 
       
   591     if ( layoutMirrored )
       
   592         {
       
   593         // Extra width, which results from the fact that it is not always
       
   594         // possible to divide screen width by the number of columns without
       
   595         // a non-zero remainder. This makes the distance of grid items from
       
   596         // scrollbar in mirrored layout exactly the same as in normal layout.
       
   597         scrollbarWidth += ( r.Width() - scrollbarWidth ) %
       
   598             ( (CAknGridView*) View() )->NumberOfColsInView();
       
   599         }
       
   600 
       
   601     if ( layoutMirrored && scrollbarVisible && currentShift != scrollbarWidth )
       
   602         {
       
   603         // shift view rect to the right
       
   604         r.Move( scrollbarWidth - currentShift, 0 );
       
   605         View()->SetViewRect( r );
       
   606         }
       
   607     else if ( ( !layoutMirrored || !scrollbarVisible ) && currentShift != 0 )
       
   608         {
       
   609         // restore view rect to its normal position
       
   610         r.Move( -currentShift, 0 );
       
   611         View()->SetViewRect( r );
       
   612         }
       
   613     }
       
   614 
       
   615 // -----------------------------------------------------------------------------
       
   616 //
       
   617 // -----------------------------------------------------------------------------
       
   618 //
       
   619 void CMmGrid::ConstructL( const CCoeControl* aParent, TInt aFlags,
       
   620         CMmTemplateLibrary* aTemplateLibrary )
       
   621     {
       
   622     iDisableChildComponentDrawing = EFalse;
       
   623     iModel = iMmModel = CMmGridModel::NewL();
       
   624     CreateItemDrawerL(aTemplateLibrary);
       
   625     CAknGrid::ConstructL( aParent, aFlags );
       
   626     iMmDrawer->SetView( this );
       
   627 
       
   628     //set initial value so avkon does not panic
       
   629     if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
   630         {
       
   631         iViewLayout = TSize( MmGrid::K4By3LayoutX, MmGrid::K4By3LayoutY );
       
   632         }
       
   633     else
       
   634         {
       
   635         iViewLayout = TSize( MmGrid::K3By4LayoutX, MmGrid::K3By4LayoutY );
       
   636         }
       
   637 
       
   638     DoSetupLayoutL();
       
   639     }
       
   640 
       
   641 // -----------------------------------------------------------------------------
       
   642 //
       
   643 // -----------------------------------------------------------------------------
       
   644 //
       
   645 CListBoxView* CMmGrid::MakeViewClassInstanceL()
       
   646     {
       
   647     return CMmGridView::NewL();
       
   648     }
       
   649 
       
   650 // -----------------------------------------------------------------------------
       
   651 //
       
   652 // -----------------------------------------------------------------------------
       
   653 //
       
   654 CMmGridModel* CMmGrid::MmModel()
       
   655     {
       
   656     return iMmModel;
       
   657     }
       
   658 
       
   659 // -----------------------------------------------------------------------------
       
   660 //
       
   661 // -----------------------------------------------------------------------------
       
   662 //
       
   663 TKeyResponse CMmGrid::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   664     {
       
   665     TKeyEvent eventCopy( aKeyEvent );
       
   666     if ( AknLayoutUtils::LayoutMirrored() )
       
   667         {
       
   668         if ( eventCopy.iCode == EKeyLeftArrow )
       
   669             {
       
   670             eventCopy.iCode = EKeyRightArrow;
       
   671             }
       
   672         else if ( eventCopy.iCode == EKeyRightArrow )
       
   673             {
       
   674             eventCopy.iCode = EKeyLeftArrow;
       
   675             }
       
   676         }
       
   677     return CAknGrid::OfferKeyEventL( eventCopy, aType );
       
   678     }
       
   679 
       
   680 // -----------------------------------------------------------------------------
       
   681 //
       
   682 // -----------------------------------------------------------------------------
       
   683 //
       
   684 void CMmGrid::HandleViewRectSizeChangeL()
       
   685     {
       
   686     if ( !AknLayoutUtils::LayoutMirrored() )
       
   687         {
       
   688         CAknGrid::HandleViewRectSizeChangeL();
       
   689         }
       
   690     else	
       
   691         {
       
   692         // for mirrored layout this function should do
       
   693         // exactly the same things as CAknGrid::HandleViewRectSizeChangeL
       
   694         // would do for normal layout
       
   695         iView->CalcBottomItemIndex();
       
   696         if ( CurrentItemIndex() >= 0 )
       
   697             {
       
   698             AdjustTopItemIndex();
       
   699             iView->CalcDataWidth();
       
   700             UpdateScrollBarsL();
       
   701             iView->CalcBottomItemIndex();
       
   702             }
       
   703         }
       
   704     }
       
   705 
       
   706 // -----------------------------------------------------------------------------
       
   707 //
       
   708 // -----------------------------------------------------------------------------
       
   709 //
       
   710 void CMmGrid::AdjustTopItemIndex() const
       
   711     {
       
   712     CAknGridView* view = static_cast<CAknGridView*>( iView );
       
   713     const TInt numOfCols = view->NumberOfColsInView();
       
   714     const TInt numOfRows = view->NumberOfRowsInView();
       
   715     const TInt itemCount = iModel->NumberOfItems();
       
   716     
       
   717     ASSERT( numOfCols > 0 );
       
   718     
       
   719     TInt lastRow = 0;
       
   720     if ( itemCount > 0 )
       
   721         {
       
   722         lastRow = ( itemCount - 1 ) / numOfCols;
       
   723         }
       
   724     TInt maxPossibleTopRow = Max( 0, lastRow - numOfRows + 1 );
       
   725     
       
   726     TInt topRow = TopItemIndex() / numOfCols;
       
   727 
       
   728     if ( !( TopItemIndex() % numOfCols == 0 &&
       
   729          topRow <= maxPossibleTopRow ) )
       
   730         {
       
   731         topRow = Min( topRow, maxPossibleTopRow );
       
   732         SetTopItemIndex( topRow * numOfCols );
       
   733         }
       
   734 
       
   735     // prevent problems with view being scrolled up beyond limits
       
   736     if ( topRow == maxPossibleTopRow && VerticalItemOffset() < 0 )
       
   737         {
       
   738         TRAP_IGNORE(
       
   739                 ( ( CMmWidgetContainer* ) Parent() )->AlignBottomOfViewL() );
       
   740         }
       
   741     }
       
   742 
       
   743 // -----------------------------------------------------------------------------
       
   744 //
       
   745 // -----------------------------------------------------------------------------
       
   746 //
       
   747 void CMmGrid::DoHandleResourceChangeL( TSize& aCellSize,
       
   748         TSize& aViewLayout )
       
   749     {
       
   750     TBool cond = Layout_Meta_Data::IsLandscapeOrientation();
       
   751     TRAPD( err, DoHandleResourceChangeL( cond, aCellSize, aViewLayout ) );
       
   752     if ( err == KErrNotFound )
       
   753         {
       
   754         aViewLayout = iViewLayout;
       
   755         aCellSize = TSize (1,1);
       
   756         }
       
   757     else if ( err == KErrNoMemory )
       
   758         {
       
   759         User::Leave( KErrNoMemory );
       
   760         }
       
   761     }
       
   762 
       
   763 // -----------------------------------------------------------------------------
       
   764 //
       
   765 // -----------------------------------------------------------------------------
       
   766 //
       
   767 void CMmGrid::DoHandleResourceChangeL( TBool aIsLandscape, TSize& aCellSize,
       
   768         TSize& aViewLayout )
       
   769     {
       
   770     CHnSuiteModel* model = iMmModel->MmListBoxModel()->GetSuiteModel();
       
   771     const TDesC8& templ = (model) ? model->GetTemplate() : KNullDesC8();
       
   772     aCellSize = iMmDrawer->TemplateLibrary()->GetSize(
       
   773         EGrid, templ, aIsLandscape, EFalse, iView->ViewRect() );
       
   774     aViewLayout = iMmDrawer->TemplateLibrary()->GetLayoutSizeL(
       
   775         EGrid, templ, aIsLandscape );
       
   776     iViewLayout = aViewLayout;
       
   777     }
       
   778 
       
   779 // -----------------------------------------------------------------------------
       
   780 //
       
   781 // -----------------------------------------------------------------------------
       
   782 //
       
   783 void CMmGrid::SetItemDrawerAndViewBgContext(
       
   784         CAknsBasicBackgroundControlContext * aBgContext )
       
   785     {
       
   786     iMmDrawer->SetBgContext (aBgContext);
       
   787     }
       
   788 
       
   789 // -----------------------------------------------------------------------------
       
   790 //
       
   791 // -----------------------------------------------------------------------------
       
   792 //
       
   793 TBool CMmGrid::HandleScrollbarVisibilityChangeL()
       
   794     {
       
   795     TBool ret = EFalse;
       
   796     if ( AllItemsFitInViewRect() )
       
   797         {
       
   798         if ( ScrollBarFrame()->VerticalScrollBar()->IsVisible()
       
   799              || iMmDrawer->TemplateLibrary()->GetScrollbarVisibility() )
       
   800             {
       
   801             ScrollBarFrame()->VerticalScrollBar()->MakeVisible( EFalse );
       
   802             iMmDrawer->SetScrollbarVisibilityL( EFalse );
       
   803             SetTopItemIndex( 0 );
       
   804             iCurrentTopItemIndex = 0;
       
   805             ret = ETrue;
       
   806             }
       
   807         }
       
   808     else if ( !ScrollBarFrame()->VerticalScrollBar()->IsVisible()
       
   809             || !iMmDrawer->TemplateLibrary()->GetScrollbarVisibility() )
       
   810         {
       
   811         ScrollBarFrame()->VerticalScrollBar()->MakeVisible( ETrue );
       
   812         iMmDrawer->SetScrollbarVisibilityL( ETrue );
       
   813         ret = ETrue;
       
   814         }
       
   815 
       
   816     return ret;
       
   817     }
       
   818 
       
   819 // -----------------------------------------------------------------------------
       
   820 //
       
   821 // -----------------------------------------------------------------------------
       
   822 //
       
   823 
       
   824 TBool CMmGrid::AllItemsFitInViewRect()
       
   825     {
       
   826     if ( iMmModel->NumberOfItems() <= iViewLayout.iWidth * iViewLayout.iHeight
       
   827             || iViewLayout == TSize(0,0) )
       
   828         {
       
   829         return ETrue;
       
   830         }
       
   831     else
       
   832         {
       
   833         return EFalse;
       
   834         }
       
   835     }
       
   836 
       
   837 // -----------------------------------------------------------------------------
       
   838 //
       
   839 // -----------------------------------------------------------------------------
       
   840 //
       
   841 void CMmGrid::UpdateScrollBarsL()
       
   842     {
       
   843     TBool redrawNeeded = HandleScrollbarVisibilityChangeL();
       
   844     if (ScrollBarFrame()->VerticalScrollBar()->IsVisible())
       
   845         {
       
   846         CAknGrid::UpdateScrollBarsL();
       
   847         }
       
   848     iCurrentTopItemIndex = TopItemIndex();
       
   849     iMmDrawer->TemplateLibrary()->SetScrollbarWidthL(
       
   850             ScrollBarFrame()->VerticalScrollBar()->Rect().Width() + ScrollBarOffset() );
       
   851     FixViewForMirroredLayout();
       
   852     }
       
   853 
       
   854 // -----------------------------------------------------------------------------
       
   855 //
       
   856 // -----------------------------------------------------------------------------
       
   857 //
       
   858 void CMmGrid::SetMarqueeAdapter( CMmMarqueeAdapter* aAdapter )
       
   859     {
       
   860     iMarqueeAdapter = aAdapter;
       
   861     }
       
   862 
       
   863 
       
   864 // -----------------------------------------------------------------------------
       
   865 //
       
   866 // -----------------------------------------------------------------------------
       
   867 //
       
   868 void CMmGrid::SetupLayout()
       
   869     {
       
   870     TRAP_IGNORE( DoSetupLayoutL() );
       
   871     }
       
   872 
       
   873 // -----------------------------------------------------------------------------
       
   874 //
       
   875 // -----------------------------------------------------------------------------
       
   876 //
       
   877 void CMmGrid::DoSetupLayoutL()
       
   878     {
       
   879     TSize cellSize;
       
   880     TSize viewLayout;
       
   881     DoHandleResourceChangeL( cellSize, viewLayout );
       
   882 //  The mirrored layout arabic item lineout ( right to left )
       
   883 //  is handled by CMmGridView::ItemPos( TInt aItemIndex )
       
   884 //  and CMmGridView::XYPosToItemIndex( TPoint aPosition, TInt& aItemIndex )
       
   885     SetLayoutL( EFalse, ETrue /*!AknLayoutUtils::LayoutMirrored()*/, ETrue, viewLayout.iWidth,
       
   886         viewLayout.iHeight, cellSize, 0, 0 );
       
   887     iMmDrawer->SetNumberOfColsInView(
       
   888             static_cast<CMmGridView*>(iView)->NumberOfColsInView() );
       
   889     // setting the top item index when changing orientation
       
   890     TInt cols( static_cast<CMmGridView*>(iView)->NumberOfColsInView() );
       
   891     SetTopItemIndex( ( (TInt) ( iCurrentTopItemIndex / cols ) ) * cols );
       
   892     UpdateScrollBarsL();
       
   893     AknsUtils::RegisterControlPosition( iMmDrawer->FormattedCellData()->Control() );
       
   894     }
       
   895 
       
   896 // -----------------------------------------------------------------------------
       
   897 //
       
   898 // -----------------------------------------------------------------------------
       
   899 //
       
   900 TInt CMmGrid::ScrollBarOffset()
       
   901     {
       
   902     TInt offset = 0;
       
   903     if ( ScrollBarFrame()->ScrollBarExists( CEikScrollBar::EVertical ) )
       
   904         {
       
   905         if ( AknLayoutUtils::LayoutMirrored() )
       
   906             {
       
   907             offset = ScrollBarFrame()->VerticalScrollBar()->Position().iX;
       
   908             }
       
   909         else
       
   910             {
       
   911             offset = View()->ViewRect().Width()
       
   912                     - ( ScrollBarFrame()->VerticalScrollBar()->Position().iX
       
   913                         + ScrollBarFrame()->VerticalScrollBar()->Rect().Width() );
       
   914             }
       
   915         }
       
   916     return offset;
       
   917     }
       
   918 
       
   919 // -----------------------------------------------------------------------------
       
   920 //
       
   921 // -----------------------------------------------------------------------------
       
   922 //
       
   923 void CMmGrid::RedrawScrollbarBackground() const
       
   924     {
       
   925     TRect viewRect( View()->ViewRect() );
       
   926     if ( viewRect.iTl.iX > 0 )
       
   927         {
       
   928         TRect scrollbarRect( TPoint( 0, 0 ),
       
   929                 TSize( viewRect.iTl.iX, viewRect.Height() ) );
       
   930 
       
   931         CWindowGc* gc = iItemDrawer->Gc();
       
   932         CMmListBoxItemDrawer* itemDrawer =
       
   933                 static_cast<CMmListBoxItemDrawer*>( iItemDrawer );
       
   934         MAknsSkinInstance *skin = AknsUtils::SkinInstance();
       
   935         CCoeControl* control = itemDrawer->FormattedCellData()->Control();
       
   936         MAknsControlContext *cc = AknsDrawUtils::ControlContext( control );
       
   937         if( gc )
       
   938             {
       
   939             if ( control )
       
   940                 {
       
   941                 AknsDrawUtils::Background( skin, cc, control, *gc, scrollbarRect );
       
   942                 }
       
   943             else
       
   944                 {
       
   945                 gc->SetBrushColor( BackColor() );
       
   946                 gc->Clear( scrollbarRect );
       
   947                 }
       
   948             }
       
   949         }
       
   950     }
       
   951 
       
   952 // -----------------------------------------------------------------------------
       
   953 //
       
   954 // -----------------------------------------------------------------------------
       
   955 //
       
   956 void CMmGrid::SetVerticalItemOffset(TInt aOffset)
       
   957 	{
       
   958 	static_cast<CMmGridView*> (View())->SetItemOffsetInPixels(aOffset);
       
   959 	UpdateScrollBarThumbs();
       
   960 	}
       
   961 
       
   962 // -----------------------------------------------------------------------------
       
   963 //
       
   964 // -----------------------------------------------------------------------------
       
   965 //
       
   966 TInt CMmGrid::VerticalItemOffset() const
       
   967 	{
       
   968 	return static_cast<CMmGridView*> (View())->VerticalItemOffset();
       
   969 	}
       
   970 
       
   971 // -----------------------------------------------------------------------------
       
   972 //
       
   973 // -----------------------------------------------------------------------------
       
   974 //
       
   975 void CMmGrid::SetItemHeight( TInt aItemHeight )
       
   976 	{
       
   977 	iItemHeight = aItemHeight;
       
   978 	}
       
   979 
       
   980 // -----------------------------------------------------------------------------
       
   981 //
       
   982 // -----------------------------------------------------------------------------
       
   983 //
       
   984 void CMmGrid::UpdateScrollBarThumbs()
       
   985 	{
       
   986 	CAknGrid::UpdateScrollBarThumbs();
       
   987 	}
       
   988 
       
   989 // -----------------------------------------------------------------------------
       
   990 //
       
   991 // -----------------------------------------------------------------------------
       
   992 //
       
   993 TInt CMmGrid::CountComponentControls() const
       
   994     {
       
   995     TInt componentControls(0);
       
   996     if ( !iDisableChildComponentDrawing )
       
   997     	{
       
   998         componentControls = CAknGrid::CountComponentControls();
       
   999     	}
       
  1000     return componentControls;
       
  1001     }
       
  1002 // -----------------------------------------------------------------------------
       
  1003 //
       
  1004 // -----------------------------------------------------------------------------
       
  1005 //
       
  1006 void CMmGrid::SetDisableChildComponentDrawing( TBool aDisable )
       
  1007     {
       
  1008     iDisableChildComponentDrawing = aDisable;
       
  1009     }
       
  1010 //End of file