menufw/menufwui/mmwidgets/src/mmwidgetcontainer.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_71.1.17.1.42 % << Don't touch! Updated by Synergy at check-out.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <e32keys.h>
       
    21 #include <e32math.h>
       
    22 #include <AknsDrawUtils.h>
       
    23 #include <layoutmetadata.cdl.h>
       
    24 #include <aknlongtapdetector.h> 
       
    25 
       
    26 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
    27 #include <aknlistloadertfx.h>
       
    28 #include <aknlistboxtfxinternal.h>
       
    29 #include <aknlistboxtfx.h>
       
    30 #endif
       
    31 
       
    32 #include "mmwidgetcontainer.h"
       
    33 #include "mmlistboxmodel.h"
       
    34 #include "mmmarqueeadapter.h"
       
    35 #include "mmwidgetobserver.h"
       
    36 #include "mmhighlighttimer.h"
       
    37 #include "mmvisibilityobserver.h"
       
    38 #include "mmlistboxcontainer.h"
       
    39 #include "mmgridcontainer.h"
       
    40 #include "mmlistboxitemdrawer.h"
       
    41 #include "mmmarqueeadapter.h"
       
    42 #include "mmfloatingitem.h"
       
    43 #include "hnsuitemodel.h"
       
    44 #include "hnitemsorder.h"
       
    45 #include "menudebug.h"
       
    46 #include "mmdraweranimator.h"
       
    47 #include "hnglobals.h"
       
    48 #include "mmpostevaluationprocessor.h"
       
    49 #include "mmgrid.h"
       
    50 #include "mmlongtapobserver.h"
       
    51 
       
    52 class CMmTemplateLibrary;
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 TMmWidgetPosition::TMmWidgetPosition()
       
    59     : iVerticalItemOffset( 0 )
       
    60     , iTopItemIndex( KErrNotFound )
       
    61     , iValid( EFalse )
       
    62     , iLandscape( EFalse )
       
    63     , iHighlightedItemId( KErrNotFound )
       
    64     {
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C CMmWidgetContainer* CMmWidgetContainer::NewGridContainerL( const TRect& aRect,
       
    72         MObjectProvider* aObjectProvider, CMmTemplateLibrary* aLibrary )
       
    73     {
       
    74     return CMmGridContainer::NewL( aRect, aObjectProvider, aLibrary );
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 EXPORT_C CMmWidgetContainer* CMmWidgetContainer::NewListBoxContainerL( const TRect& aRect,
       
    82         MObjectProvider* aObjectProvider, CMmTemplateLibrary* aTemplateLibrary )
       
    83     {
       
    84     return CMmListBoxContainer::NewL( aRect, aObjectProvider, aTemplateLibrary );
       
    85     }
       
    86 
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 void CMmWidgetContainer::ConstructL()
       
    93 	{
       
    94     if ( AknLayoutUtils::PenEnabled() )
       
    95     	{
       
    96     	iTimer = CMmHighlightTimer::NewL( this );
       
    97     	}
       
    98     iBgContext = CAknsBasicBackgroundControlContext::NewL(
       
    99     	KAknsIIDQsnBgAreaMainAppsGrid, Rect(), EFalse);
       
   100     iLongTapDetector = CAknLongTapDetector::NewL( this );
       
   101     iLongTapDetector->EnableLongTapAnimation(ETrue);
       
   102 	}
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 CMmWidgetContainer::CMmWidgetContainer()
       
   109     : iIsFaded( EFalse )
       
   110     , iHasFocus( ETrue )
       
   111     , iInForeground( ETrue )
       
   112     {
       
   113     iMarqueeAdapter = NULL;
       
   114     iBgContext = NULL;
       
   115     iWidgetPositionCache.iValid = EFalse;
       
   116     iLongTapInProgress = EFalse;
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 CMmWidgetContainer::~CMmWidgetContainer()
       
   124     {
       
   125     AknsUtils::DeregisterControlPosition( this );
       
   126     AknsUtils::DeregisterControlPosition( this->iWidget );
       
   127     delete iTimer;
       
   128     delete iBgContext;
       
   129     delete iPostProcessor;
       
   130     delete iLongTapDetector;
       
   131     }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void CMmWidgetContainer::SizeChanged()
       
   138     {
       
   139     if ( iWidget && iWidgetRect != Rect() )
       
   140         {
       
   141     	CMmTemplateLibrary * templateLibrary =
       
   142     	static_cast<CMmListBoxItemDrawer*> (
       
   143     			Widget()->View()->ItemDrawer() )->TemplateLibrary();
       
   144         if ( Rect() != templateLibrary->GetParentRect(
       
   145         		Layout_Meta_Data::IsLandscapeOrientation() ) )
       
   146         	{
       
   147         	templateLibrary->CleanAndClearCache();
       
   148         	}
       
   149         iWidget->View()->SetViewRect( Rect() );
       
   150         iWidget->SetRect( Rect() );
       
   151         iWidgetRect = Rect();
       
   152         }
       
   153 
       
   154     if ( iBgContext )
       
   155         {
       
   156         TRect rect = iCoeEnv->ScreenDevice()->SizeInPixels();
       
   157         iBgContext->SetRect( rect );
       
   158         SetItemDrawerAndViewBgContext( iBgContext );
       
   159         }
       
   160 
       
   161     AknsUtils::RegisterControlPosition( this );
       
   162     AknsUtils::RegisterControlPosition( this->iWidget );
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 void CMmWidgetContainer::Draw( const TRect& /*aRect*/ ) const
       
   170     {
       
   171     // do nothing
       
   172     }
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 TTypeUid::Ptr CMmWidgetContainer::MopSupplyObject(TTypeUid aId)
       
   178     {
       
   179     if (aId.iUid == MAknsControlContext::ETypeId && iBgContext )
       
   180         {
       
   181         return MAknsControlContext::SupplyMopObject(aId, iBgContext );
       
   182         }
       
   183 
       
   184     return CCoeControl::MopSupplyObject(aId);
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 void CMmWidgetContainer::HandleButtonDownL(const TPointerEvent& aPointerEvent )
       
   192     {
       
   193     iTapPoint = aPointerEvent.iPosition;
       
   194     iLastDragPoint = aPointerEvent.iPosition;
       
   195     iLastDragHighlight = GetHighlight();
       
   196     if( !iWidget->View()->XYPosToItemIndex(
       
   197     		aPointerEvent.iPosition, iDraggedIndex ) )
       
   198         {
       
   199         iDraggedIndex = KErrNotFound;
       
   200         }
       
   201     iItemRelativeTapPoint = aPointerEvent.iPosition - iWidget->View()->ItemPos(
       
   202     		iDraggedIndex );
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 void CMmWidgetContainer::HandleButtonUpL(const TPointerEvent& /*aPointerEvent*/ )
       
   210     {
       
   211     iTapPoint = TPoint( 0, 0 );
       
   212     CancelDragL( EFalse );
       
   213     }
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 // -----------------------------------------------------------------------------
       
   218 //
       
   219 void CMmWidgetContainer::HandleResourceChange( TInt aType )
       
   220     {
       
   221     if ( aType == KEikDynamicLayoutVariantSwitch ||
       
   222             aType == KAknsMessageSkinChange )
       
   223         {
       
   224         static_cast<CMmListBoxItemDrawer*>( iDrawer )->InvalidateCache();
       
   225         }
       
   226     
       
   227     CCoeControl::HandleResourceChange( aType );
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 EXPORT_C void CMmWidgetContainer::ItemIconZoomL( TInt /*aItemIndex */)
       
   235     {
       
   236     TInt index = GetHighlight();
       
   237     if (index != iDraggedIndex)
       
   238         {
       
   239         iDrawer->AnimateItemZoomInL( index );
       
   240         }
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 EXPORT_C CHnSuiteModel* CMmWidgetContainer::GetSuiteModelL()
       
   248 	{
       
   249 	return GetMmModel()->GetSuiteModel();
       
   250 	}
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 void CMmWidgetContainer::HandleDragL(const TPointerEvent& aPointerEvent,
       
   257         TBool aAbortAnimation )
       
   258     {
       
   259     DEBUG(("\t_Mm_:CMmWidgetContainer::HandleDragL: iLastDragHighlight = %d ",
       
   260     		iLastDragHighlight ));
       
   261 
       
   262     TInt highlight = GetHighlight();
       
   263     DEBUG(("\t_Mm_:CMmWidgetContainer::HandleDragL: highlight = %d ", highlight ));
       
   264 
       
   265     TPoint dragDelta ( iLastDragPoint - aPointerEvent.iPosition);
       
   266     TInt dragSpeed = dragDelta.iX * dragDelta.iX + dragDelta.iY * dragDelta.iY;
       
   267     TBool tooFast = (dragSpeed > MmEffects::KDragSpeedIgnoreThreshold);
       
   268 
       
   269     if (iLastDragHighlight != highlight )
       
   270         {
       
   271        	iDragAndDropObserver->HandleDragOverL( GetHighlight() );
       
   272         }
       
   273 
       
   274     if (!tooFast)
       
   275     	{
       
   276 		TSize itemSize = iWidget->View()->ItemSize( highlight );
       
   277 		TPoint itemPos = iWidget->View()->ItemPos( highlight );
       
   278 
       
   279 		if ( PointInItemReorderAreaL( highlight, aPointerEvent.iPosition ) )
       
   280 		   {
       
   281 		   CHnSuiteModel* model = GetMmModel()->GetSuiteModel();
       
   282 		   CHnItemModel* onItemModel = model->GetItemModel( model->IdByIndex( highlight ));
       
   283 		   if (iDrawer->GetAnimator()->IsReadyForNewAnimation() && !aAbortAnimation
       
   284 				   && onItemModel->GetItemType() != EItemTypeParentFolder
       
   285 				   && iDraggedIndex != highlight)
       
   286 				   {
       
   287 				   GetMmModel()->ReorderModelL( iDraggedIndex, highlight );
       
   288 				   AnimateShiftL( highlight );
       
   289 				   iDrawer->SetDraggedIndexL( highlight,
       
   290 						   aPointerEvent.iPosition - iItemRelativeTapPoint );
       
   291 				   iDraggedIndex = highlight;
       
   292 				   iDragAndDropObserver->HandleDraggedIndexUpdatedL( highlight );
       
   293 				   }
       
   294 		   }
       
   295     	}
       
   296 
       
   297     if ( DeltaSquare( iTapPoint, aPointerEvent.iPosition ) > KDragDelta &&
       
   298 				!iDrawer->IsDraggable() )
       
   299 		{
       
   300 		iDrawer->SetDraggedIndexL( iDraggedIndex, iTapPoint - iItemRelativeTapPoint );
       
   301 		iDrawer->SetDraggableL( ETrue );
       
   302 		}
       
   303 	else if ( iDrawer->IsDraggable() )
       
   304 		{
       
   305 		iDrawer->SetDraggedPointL( aPointerEvent.iPosition - iItemRelativeTapPoint );
       
   306 		}
       
   307 
       
   308     DEBUG(("\t_Mm_:CMmWidgetContainer::HandleDragL: iLastDragHighlight = %d ", iLastDragHighlight ));
       
   309     DEBUG(("\t_Mm_:CMmWidgetContainer::HandleDragL: highlight = %d ", highlight ));
       
   310     iLastDragPoint = aPointerEvent.iPosition;
       
   311     iLastDragHighlight = highlight;
       
   312     }
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 //
       
   316 // -----------------------------------------------------------------------------
       
   317 //
       
   318 void CMmWidgetContainer::AnimateShiftL(TInt aHighlight)
       
   319 	{
       
   320     TInt lowerVal =  (iDraggedIndex < aHighlight)? iDraggedIndex : aHighlight;
       
   321     TInt higherVal = (iDraggedIndex < aHighlight)? aHighlight : iDraggedIndex;
       
   322     TInt switchOperation = (iDraggedIndex < aHighlight) ? EFalse : ETrue;
       
   323 
       
   324        for(TInt iter(lowerVal); iter < higherVal; iter++ )
       
   325            {
       
   326            TInt from = iter + 1;
       
   327            TInt to = iter;
       
   328            if (switchOperation)
       
   329                {
       
   330                from = iter;
       
   331                to = iter + 1;
       
   332                }
       
   333            iDrawer->AnimateItemSwapL( from, to );
       
   334         }
       
   335      }
       
   336 
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 // -----------------------------------------------------------------------------
       
   340 //
       
   341 EXPORT_C void CMmWidgetContainer::CancelDragL( TBool aAnimate )
       
   342     {
       
   343     if (aAnimate)
       
   344         {
       
   345         iDrawer->AnimateDragItemTransitionL();
       
   346         }
       
   347     
       
   348     SetHighlightAfterDrag();
       
   349     
       
   350     iDraggedIndex = -1;
       
   351     iDrawer->SetDraggedIndexL( iDraggedIndex, TPoint(0,0) );
       
   352     SetDraggableL( EFalse );
       
   353 
       
   354     TInt dragFloatingItem;
       
   355     do
       
   356         {
       
   357         dragFloatingItem = iDrawer->GetFloatingItemIndex( EDrag );
       
   358         iDrawer->RemoveFloatingItem( dragFloatingItem );
       
   359         }
       
   360     while ( dragFloatingItem != KErrNotFound );
       
   361 
       
   362     iDrawer->GetAnimator()->CancelNextRedrawL();
       
   363 
       
   364     }
       
   365 
       
   366 // -----------------------------------------------------------------------------
       
   367 //
       
   368 // -----------------------------------------------------------------------------
       
   369 //
       
   370 
       
   371 TBool CMmWidgetContainer::IsFolderL(TInt aItemIndex)
       
   372 	{
       
   373 	TBool result = EFalse;
       
   374 
       
   375 	CHnSuiteModel* model = GetMmModel()->GetSuiteModel();
       
   376 	if (model)
       
   377 		{
       
   378 		CHnItemModel* onItemModel = model->GetItemModel( model->IdByIndex( aItemIndex ));
       
   379 	    if (onItemModel)
       
   380 	    	{
       
   381 	    	result = onItemModel->GetItemType() == EItemTypeParentFolder ||
       
   382 	      		onItemModel->GetItemType() == EItemTypeFolder;
       
   383 	    	}
       
   384 		}
       
   385 
       
   386 	return result;
       
   387 
       
   388 	}
       
   389 
       
   390 // -----------------------------------------------------------------------------
       
   391 //
       
   392 // -----------------------------------------------------------------------------
       
   393 //
       
   394 
       
   395 TBool CMmWidgetContainer::IsNoItemDragged()
       
   396 	{
       
   397 	TBool noItemDragged = EFalse;
       
   398 	noItemDragged = ( KErrNotFound == iDraggedIndex ) ? ETrue : noItemDragged;
       
   399 	CHnSuiteModel* model = GetMmModel()->GetSuiteModel();
       
   400 	if ( !noItemDragged && model)
       
   401 		{
       
   402 		CHnItemModel* onItemModel = model->GetItemModel( model->IdByIndex( iDraggedIndex ));
       
   403 	    if (onItemModel)
       
   404 	    	{
       
   405 	    	noItemDragged = ( onItemModel->GetItemType() == EItemTypeParentFolder );
       
   406 	    	}
       
   407 		}
       
   408 	return noItemDragged;
       
   409 	}
       
   410 
       
   411 // -----------------------------------------------------------------------------
       
   412 //
       
   413 // -----------------------------------------------------------------------------
       
   414 //
       
   415 EXPORT_C void CMmWidgetContainer::SetHasFocusL( TBool aHasFocus )
       
   416     {
       
   417     if ( !!aHasFocus != !!iHasFocus ) // logical Ex-OR
       
   418         {
       
   419         iHasFocus = aHasFocus;
       
   420         StartOrStopMarquee();
       
   421         }
       
   422     if ( !aHasFocus )
       
   423     	{
       
   424     	ASSERT(iTimer);
       
   425     	iTimer->StopL();
       
   426     	}
       
   427     }
       
   428 
       
   429 // -----------------------------------------------------------------------------
       
   430 //
       
   431 // -----------------------------------------------------------------------------
       
   432 //
       
   433 EXPORT_C void CMmWidgetContainer::SetIsFaded( TBool aIsFaded )
       
   434     {
       
   435     if ( !!aIsFaded != !!iIsFaded ) // logical Ex-OR
       
   436         {
       
   437         iIsFaded = aIsFaded;
       
   438         StartOrStopMarquee();
       
   439         }
       
   440     }
       
   441 
       
   442 // -----------------------------------------------------------------------------
       
   443 //
       
   444 // -----------------------------------------------------------------------------
       
   445 //
       
   446 TBool CMmWidgetContainer::IsDeleteLockedL( TInt aItemIndex )
       
   447 	{
       
   448 	TBool result = ETrue;
       
   449 
       
   450 	CHnSuiteModel* model = GetMmModel()->GetSuiteModel();
       
   451 	if (model)
       
   452 		{
       
   453 		CHnItemModel* onItemModel = model->GetItemModel(model->IdByIndex(
       
   454 				aItemIndex));
       
   455 		if (onItemModel)
       
   456 			{
       
   457 			result = onItemModel->IsDeleteLocked();
       
   458 			}
       
   459 		}
       
   460 
       
   461 	return result;
       
   462 	}
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 //
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 void CMmWidgetContainer::ManageFolderZoomingL( TBool aDraggedItemOverIcons )
       
   469 	{
       
   470 	TBool isAnimated;
       
   471 
       
   472 	isAnimated = EFalse;
       
   473 	for(int i=0; i< iDrawer->GetFloatingItemCount(); i++)
       
   474 		{
       
   475 	    TMmFloatingItem& current = iDrawer->GetFloatingItemAtIndex(i);
       
   476 	    if (/*current.GetFloatingItemType() != EZoomTransition &&*/
       
   477 	    		current.GetFloatingItemType() != EPostHighlightChangeRefreshItem &&
       
   478  				current.GetDrawnItemIndex() == GetHighlight() )
       
   479 	    	{
       
   480 	        isAnimated = ETrue;
       
   481 	        break;
       
   482 	        }
       
   483 	    }
       
   484 
       
   485 	if (!isAnimated)
       
   486 		{
       
   487 		if ( GetHighlight() != iDraggedIndex &&
       
   488 			 IsFolderL( GetHighlight() ) &&
       
   489 			 !IsDeleteLockedL( GetHighlight() ) &&
       
   490 			 iDrawer->IsDraggable() )
       
   491 			{
       
   492 			iDrawer->AnimateItemZoomInL( GetHighlight() );
       
   493 			}
       
   494 		}
       
   495 
       
   496 	isAnimated = EFalse;
       
   497 	for(int i=0; i< iDrawer->GetFloatingItemCount(); i++)
       
   498 		{
       
   499 	    TMmFloatingItem& current = iDrawer->GetFloatingItemAtIndex(i);
       
   500 	    if (current.GetFloatingItemType() != EZoomTransition &&
       
   501 	    		current.GetFloatingItemType() != EPostHighlightChangeRefreshItem &&
       
   502 				current.GetDrawnItemIndex() == iLastDragHighlight )
       
   503 	    	{
       
   504 	        isAnimated = ETrue;
       
   505 	        break;
       
   506 	        }
       
   507 	    }
       
   508 
       
   509 	if (!isAnimated)
       
   510 		{
       
   511 		if ( ( !aDraggedItemOverIcons && IsFolderL( iLastDragHighlight ) ) ||
       
   512 				iLastDragHighlight != Widget()->CurrentItemIndex() )
       
   513 			{
       
   514 			iDrawer->AnimateItemZoomOutL( iLastDragHighlight );
       
   515 			}
       
   516 		}
       
   517 	}
       
   518 // -----------------------------------------------------------------------------
       
   519 //
       
   520 // -----------------------------------------------------------------------------
       
   521 //
       
   522 void CMmWidgetContainer::HandlePointerEventsInEditModeL(
       
   523 		const TPointerEvent& aPointerEvent, TBool aAbortAnimations )
       
   524 	{
       
   525 
       
   526 	TInt pointedItem = KErrNotFound;
       
   527 	TBool draggedItemOverIcons = iWidget->View()->XYPosToItemIndex(
       
   528 			aPointerEvent.iPosition, pointedItem );
       
   529 
       
   530 	if (aPointerEvent.iType == TPointerEvent::EButton1Down)
       
   531         {
       
   532 //TODO: PROTO OF 2PHASE HIGHLIGHT EDITMODE BEHAVIOUR
       
   533 //        if (!IsFolderL(pointedItem))
       
   534 //        	{
       
   535 //        	iDrawer->ClearFlags( CListItemDrawer::EPressedDownState );
       
   536 //        	}
       
   537         HandleButtonDownL(aPointerEvent);
       
   538         iDragAndDropObserver->HandleDragStartL( GetHighlight() );
       
   539         }
       
   540     else if ( (aPointerEvent.iType == TPointerEvent::EDrag ||
       
   541             aPointerEvent.iType == TPointerEvent::EButtonRepeat) &&
       
   542             iDraggedIndex != KErrNotFound)
       
   543         {
       
   544 //TODO: PROTO OF 2PHASE HIGHLIGHT EDITMODE BEHAVIOUR
       
   545 //        if (!IsFolderL(pointedItem))
       
   546 //        	{
       
   547 //        	iDrawer->SetFlags( CListItemDrawer::EPressedDownState );
       
   548 //        	}
       
   549 
       
   550         TPointerEvent pointerEvent = aPointerEvent;
       
   551         if( WidgetType() == EListWidget )
       
   552         	{
       
   553         	pointerEvent.iPosition.iX =
       
   554                     iWidget->View()->ItemPos( pointedItem ).iX +
       
   555                     iItemRelativeTapPoint.iX;
       
   556         	}
       
   557 
       
   558         if (GetHighlight() !=  Widget()->CurrentItemIndex() )
       
   559         	{
       
   560         	SetHighlightL( Widget()->CurrentItemIndex() );
       
   561         	}
       
   562 
       
   563         ManageFolderZoomingL( draggedItemOverIcons );
       
   564 
       
   565         HandleDragL(pointerEvent, aAbortAnimations);
       
   566 
       
   567         }
       
   568     else if (aPointerEvent.iType == TPointerEvent::EButton1Up && iDrawer->IsDraggable())
       
   569         {
       
   570         if ( !draggedItemOverIcons )
       
   571         	{
       
   572         	SetManualHighlightL( iDraggedIndex );
       
   573         	}
       
   574 
       
   575         iDragAndDropObserver->HandleDragStopL( GetHighlight() );
       
   576         HandleButtonUpL(aPointerEvent);
       
   577         }
       
   578 	}
       
   579 
       
   580 // -----------------------------------------------------------------------------
       
   581 //
       
   582 // -----------------------------------------------------------------------------
       
   583 //
       
   584 void CMmWidgetContainer::HandlePointerEventL(const TPointerEvent& aPointerEvent )
       
   585     {
       
   586     if ( iMarqueeAdapter && aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   587     	{
       
   588     	iMarqueeAdapter->StopMarqueeDrawing();
       
   589     	}
       
   590     
       
   591     TInt index = KErrNotFound;
       
   592     TBool itemExists = iWidget->View()->XYPosToItemIndex( aPointerEvent.iPosition, index );
       
   593 
       
   594     CCoeControl::HandlePointerEventL(aPointerEvent);
       
   595     
       
   596     if ( aPointerEvent.iType == TPointerEvent::EButton1Down
       
   597             && itemExists  )
       
   598         {
       
   599         SetHighlightL( index );
       
   600         }
       
   601     else if ( aPointerEvent.iType == TPointerEvent::EDrag
       
   602               // the line below is needed to enable edit mode in the list widget
       
   603     		  // because behaviour in the grid and list is different
       
   604     		  || (aPointerEvent.iType == TPointerEvent::EButtonRepeat && WidgetType() == EGridWidget ))
       
   605     	{
       
   606     	if ( itemExists )
       
   607     		{
       
   608         	if ( GetHighlight() != index )
       
   609         	    {
       
   610         	    iTimer->StopL();
       
   611         	    if ( IsEditMode() )
       
   612         	    	{
       
   613         		    SetHighlightL( index );
       
   614         	    	}
       
   615         	    }
       
   616     		}
       
   617     	else
       
   618     		{
       
   619     		iTimer->StopL();
       
   620     		}
       
   621     	}
       
   622 
       
   623 	TInt lastTopItemIndex = Widget()->TopItemIndex();
       
   624 	
       
   625     TBool abortAnimation = lastTopItemIndex != Widget()->TopItemIndex();
       
   626 
       
   627     if (abortAnimation)
       
   628         {
       
   629         iDrawer->GetAnimator()->CancelAnimationsL();
       
   630         }
       
   631 
       
   632     if ( IsEditMode() && iDragAndDropObserver )
       
   633     	{
       
   634 		HandlePointerEventsInEditModeL(aPointerEvent, abortAnimation);
       
   635     	}
       
   636     
       
   637     if ( iLongTapDetector )
       
   638     	{
       
   639     	TPointerEvent longTapPointerEvent = aPointerEvent;
       
   640         if ( aPointerEvent.iType == TPointerEvent::EButtonRepeat )
       
   641         	{
       
   642         	longTapPointerEvent.iType = TPointerEvent::EDrag;
       
   643         	}
       
   644         iLongTapDetector->PointerEventL( longTapPointerEvent );
       
   645     	}	
       
   646     
       
   647     }
       
   648 
       
   649 // -----------------------------------------------------------------------------
       
   650 //
       
   651 // -----------------------------------------------------------------------------
       
   652 //
       
   653 EXPORT_C TRect CMmWidgetContainer::GetItemRectL( TInt aItemIndex )
       
   654 	{
       
   655 	User::LeaveIfNull( iWidget );
       
   656 	TPoint pos = iWidget->View()->ItemPos( aItemIndex );
       
   657 	TSize size = iDrawer->GetItemSize( aItemIndex, EFalse );
       
   658 	return TRect( pos.iX, pos.iY, pos.iX + size.iWidth, pos.iY + size.iHeight );
       
   659 	}
       
   660 
       
   661 // -----------------------------------------------------------------------------
       
   662 //
       
   663 // -----------------------------------------------------------------------------
       
   664 //
       
   665 void CMmWidgetContainer::SetDraggableL( TBool aDraggable )
       
   666     {
       
   667     
       
   668     iDrawer = STATIC_CAST(CMmListBoxItemDrawer*, iWidget->View()->ItemDrawer());
       
   669     iDrawer->SetDraggableL( aDraggable );
       
   670     }
       
   671 
       
   672 // -----------------------------------------------------------------------------
       
   673 //
       
   674 // -----------------------------------------------------------------------------
       
   675 //
       
   676 TBool CMmWidgetContainer::IsEditMode() const
       
   677 	{
       
   678 	return iIsEditMode;
       
   679 	}
       
   680 
       
   681 // -----------------------------------------------------------------------------
       
   682 //
       
   683 // -----------------------------------------------------------------------------
       
   684 //
       
   685 void CMmWidgetContainer::SetEditModeL( TBool aIsEditMode )
       
   686     {
       
   687     iIsEditMode = aIsEditMode;
       
   688     StartOrStopMarquee();
       
   689 
       
   690     ASSERT(iDrawer);
       
   691     iDrawer->SetEditModeL( aIsEditMode );
       
   692     if ( !AknLayoutUtils::PenEnabled() && aIsEditMode )
       
   693     	{
       
   694         iDraggedIndex = iWidget->CurrentItemIndex();
       
   695         ScrollViewIfNeededL(); //only edit mode non-touch
       
   696     	}
       
   697 
       
   698     // scrollbar does not work when scrolling is disabled
       
   699     // iWidget->DisableScrolling( aIsEditMode );
       
   700     }
       
   701 
       
   702 // -----------------------------------------------------------------------------
       
   703 //
       
   704 // -----------------------------------------------------------------------------
       
   705 //
       
   706 EXPORT_C void CMmWidgetContainer::SetHighlightVisibilityL( TBool aEnable )
       
   707     {
       
   708     // activate the model
       
   709     CHnSuiteModel* suiteModel = GetMmModel()->GetSuiteModel();
       
   710 
       
   711     if ( suiteModel )
       
   712         {
       
   713         suiteModel->SetActiveL( aEnable );
       
   714         }
       
   715 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   716 	    MAknListBoxTfxInternal *transApi = CAknListLoader::TfxApiInternal(
       
   717 	    		iDrawer->Gc() );
       
   718 #endif
       
   719     if ( !aEnable )
       
   720         {
       
   721         iWidget->View()->ItemDrawer()->SetFlags(
       
   722             CListItemDrawer::EDisableHighlight );
       
   723 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   724 	    if ( transApi )
       
   725 	        {
       
   726            	transApi->Remove( MAknListBoxTfxInternal::EListHighlight );
       
   727   	        }
       
   728 #endif
       
   729         }
       
   730     else
       
   731         {
       
   732         iWidget->View()->ItemDrawer()->ClearFlags(
       
   733             CListItemDrawer::EDisableHighlight );
       
   734         }
       
   735    }
       
   736 
       
   737 // -----------------------------------------------------------------------------
       
   738 //
       
   739 // -----------------------------------------------	------------------------------
       
   740 //
       
   741 EXPORT_C TBool CMmWidgetContainer::IsHighlightVisible()
       
   742     {
       
   743     return IsTimerActive();
       
   744     }
       
   745 
       
   746 // -----------------------------------------------------------------------------
       
   747 //
       
   748 // -----------------------------------------------------------------------------
       
   749 //
       
   750 EXPORT_C TBool CMmWidgetContainer::IsDraggable()
       
   751 	{
       
   752     iDrawer = STATIC_CAST(CMmListBoxItemDrawer*, iWidget->View()->ItemDrawer());
       
   753     return iDrawer->IsDraggable();
       
   754     }
       
   755 
       
   756 // -----------------------------------------------------------------------------
       
   757 //
       
   758 // -----------------------------------------------------------------------------
       
   759 //
       
   760 TInt CMmWidgetContainer::CountComponentControls() const
       
   761     {
       
   762     return 1;
       
   763     }
       
   764 
       
   765 // -----------------------------------------------------------------------------
       
   766 //
       
   767 //
       
   768 // -----------------------------------------------------------------------------
       
   769 //
       
   770 CCoeControl* CMmWidgetContainer::ComponentControl(TInt aIndex) const
       
   771     {
       
   772     switch( aIndex )
       
   773         {
       
   774         case 0:
       
   775             return iWidget;
       
   776         default:
       
   777             return NULL;
       
   778         }
       
   779     }
       
   780 
       
   781 // -----------------------------------------------------------------------------
       
   782 //
       
   783 // -----------------------------------------------------------------------------
       
   784 //
       
   785 EXPORT_C TInt CMmWidgetContainer::NumberOfItems()
       
   786     {
       
   787     return GetMmModel()->NumberOfItems();
       
   788     }
       
   789 // -----------------------------------------------------------------------------
       
   790 //
       
   791 // -----------------------------------------------------------------------------
       
   792 //
       
   793 EXPORT_C void CMmWidgetContainer::SetObserver( MMmWidgetObserver*  aObserver )
       
   794     {
       
   795     //iWidget->SetListBoxObserver( aObserver );
       
   796     iListBoxObserver = aObserver;
       
   797     iKeyEventObserver = aObserver;
       
   798 	iDragAndDropObserver = aObserver;
       
   799     }
       
   800 
       
   801 // -----------------------------------------------------------------------------
       
   802 //
       
   803 // -----------------------------------------------------------------------------
       
   804 //
       
   805 EXPORT_C TInt CMmWidgetContainer::GetPreviousHighlight()
       
   806     {
       
   807     return iPreviousHighlight;
       
   808     }
       
   809 // -----------------------------------------------------------------------------
       
   810 //
       
   811 // -----------------------------------------------------------------------------
       
   812 //
       
   813 EXPORT_C TInt CMmWidgetContainer::GetHighlight( )
       
   814     {
       
   815     return iCurrentHighlight;
       
   816     }
       
   817 
       
   818 // -----------------------------------------------------------------------------
       
   819 //
       
   820 // -----------------------------------------------------------------------------
       
   821 //
       
   822 void CMmWidgetContainer::SetManualHighlightL( TInt aItemIndex,
       
   823 		TBool aRedraw )
       
   824 	{
       
   825 	SetHighlightL( aItemIndex );
       
   826 
       
   827 	if ( aItemIndex >= 0 && aItemIndex < GetMmModel()->NumberOfItems() )
       
   828 		{
       
   829 		if ( aItemIndex != iWidget->CurrentItemIndex() )
       
   830 			{
       
   831 			iWidget->View()->SetCurrentItemIndex( aItemIndex );
       
   832 			}
       
   833 
       
   834 		if ( aRedraw )
       
   835 			{
       
   836 			iWidget->SetCurrentItemIndex( aItemIndex );
       
   837 			iWidget->DrawNow();
       
   838 			}
       
   839 		}
       
   840 	}
       
   841 // -----------------------------------------------------------------------------
       
   842 //
       
   843 // -----------------------------------------------------------------------------
       
   844 //
       
   845 void CMmWidgetContainer::SetHighlightL( TInt aItemIndex )
       
   846     {
       
   847     ASSERT( aItemIndex >= KErrNotFound );
       
   848 
       
   849     if (aItemIndex == KErrNotFound)
       
   850         {
       
   851         iCurrentHighlight =	 iPreviousHighlight = KErrNotFound;
       
   852         SetDefaultHighlightL( EFalse );
       
   853         }
       
   854     else if (aItemIndex >= 0 && aItemIndex < GetMmModel()->NumberOfItems())
       
   855         {
       
   856         iPreviousHighlight = iCurrentHighlight;
       
   857         iCurrentHighlight = aItemIndex;
       
   858 
       
   859         if ( iPreviousHighlight != iCurrentHighlight )
       
   860             {
       
   861             HideOptionsMenuIfDisplayed();
       
   862             }
       
   863         
       
   864         CHnSuiteModel* suiteModel = GetMmModel()->GetSuiteModel();
       
   865         
       
   866         if (suiteModel)
       
   867             {
       
   868             suiteModel->SetSuiteHighlightL( iCurrentHighlight );
       
   869             }
       
   870         }
       
   871 
       
   872 
       
   873 	if ( IsEditMode() )
       
   874     	{
       
   875     	TMmFloatingItem postDragCurrent( GetHighlight(),
       
   876     			Widget()->View()->ItemPos( GetHighlight() ),
       
   877     			EPostHighlightChangeRefreshItem,
       
   878 				MmEffects::KNoAnimationFramesCount, Widget()->View() );
       
   879 
       
   880     	iDrawer->AddFloatingItemL( postDragCurrent );
       
   881 
       
   882     	if ( GetPreviousHighlight() != GetHighlight() )
       
   883     		{
       
   884     		TMmFloatingItem postDragPrevious( GetPreviousHighlight(),
       
   885     				Widget()->View()->ItemPos( GetPreviousHighlight() ),
       
   886     				EPostHighlightChangeRefreshItem,
       
   887     				MmEffects::KNoAnimationFramesCount, Widget()->View() );
       
   888 
       
   889     		iDrawer->AddFloatingItemL( postDragPrevious );
       
   890     		}
       
   891     	}
       
   892     }
       
   893 
       
   894 // -----------------------------------------------------------------------------
       
   895 //
       
   896 // -----------------------------------------------------------------------------
       
   897 //
       
   898 TBool CMmWidgetContainer::PointInItemReorderAreaL(
       
   899             TInt aItemIndex, TPoint aPoint )
       
   900     {
       
   901     TRect itemRect = GetItemRectL( aItemIndex );
       
   902     itemRect.Shrink( MmEffects::KShiftRatio * itemRect.Width(),
       
   903             MmEffects::KShiftRatio * itemRect.Height() );
       
   904     return itemRect.Contains( aPoint );
       
   905     }
       
   906 
       
   907 // -----------------------------------------------------------------------------
       
   908 //
       
   909 // -----------------------------------------------------------------------------
       
   910 //
       
   911 void CMmWidgetContainer::HideOptionsMenuIfDisplayed()
       
   912     {
       
   913     CEikMenuBar* menuBar = CEikonEnv::Static()->AppUiFactory()->MenuBar();
       
   914     if ( menuBar && menuBar->IsDisplayed() )
       
   915         {
       
   916         menuBar->StopDisplayingMenuBar();
       
   917         }
       
   918     }
       
   919 
       
   920 // -----------------------------------------------------------------------------
       
   921 //
       
   922 //
       
   923 // -----------------------------------------------------------------------------
       
   924 //
       
   925 void CMmWidgetContainer::SetFlag(TInt /*Flag*/)
       
   926     {
       
   927     }
       
   928 
       
   929 // -----------------------------------------------------------------------------
       
   930 //
       
   931 //
       
   932 // -----------------------------------------------------------------------------
       
   933 //
       
   934 CEikListBox* CMmWidgetContainer::Widget()
       
   935     {
       
   936     return iWidget;
       
   937     }
       
   938 
       
   939 // -----------------------------------------------------------------------------
       
   940 //
       
   941 //
       
   942 // -----------------------------------------------------------------------------
       
   943 //
       
   944 TKeyResponse CMmWidgetContainer::OfferKeyEventL(const TKeyEvent &aKeyEvent,
       
   945                                                    TEventCode aType)
       
   946     {
       
   947     TKeyResponse resp = EKeyWasNotConsumed;
       
   948 
       
   949     TBool highlightVisibleWhenEventReceived = IsHighlightVisible();
       
   950 
       
   951     if ( IsEditMode() && IsDraggable() )
       
   952     	return resp;
       
   953 
       
   954     resp = HandleKeyEventL( aKeyEvent, aType );
       
   955     if ( iMarqueeAdapter && ( aType == EEventKeyDown ) )
       
   956     	{
       
   957     	iMarqueeAdapter->StopMarqueeDrawing();
       
   958     	}
       
   959 
       
   960     if (!AknLayoutUtils::PenEnabled() && iIsEditMode )
       
   961         {
       
   962 		if ((GetHighlight() + ColumnsInCurrentView() > NumberOfItems() - 1) 
       
   963 						&& aKeyEvent.iScanCode == EStdKeyDownArrow)
       
   964 			// the second condition is needed to block moving item down when there is no item below the moved item.
       
   965 			{
       
   966 			return resp;
       
   967 			}
       
   968 
       
   969         if (aType == EEventKey )
       
   970             {
       
   971             TInt prevIndex = GetHighlight();
       
   972             static_cast<CMmListBoxItemDrawer*>(iDrawer)->SetHighlightShown( EFalse );
       
   973             resp = iWidget->OfferKeyEventL( aKeyEvent, aType );
       
   974             static_cast<CMmListBoxItemDrawer*>(iDrawer)->SetHighlightShown( ETrue );
       
   975             SetHighlightL( iWidget->CurrentItemIndex() );
       
   976             ScrollViewIfNeededL(); //only edit mode non-touch
       
   977             
       
   978             if ( prevIndex != GetHighlight()
       
   979             		&& KErrNotFound != prevIndex  )
       
   980             	{
       
   981             	iDraggedIndex = prevIndex;
       
   982                 iDragAndDropObserver->HandleDragStartL( iDraggedIndex );
       
   983                 GetMmModel()->ReorderModelL( iDraggedIndex, GetHighlight() );
       
   984                 iDrawer->AnimateItemSwapL( iDraggedIndex , GetHighlight() );
       
   985                 AnimateShiftL( GetHighlight() );
       
   986             	}
       
   987             return resp;
       
   988             }
       
   989         }
       
   990 
       
   991     if ( resp == EKeyWasNotConsumed )
       
   992         {
       
   993 //        here is a workaround for avkon to enable cursor movement we need to set highlight visibility
       
   994 //        to ETrue so that single click implementation in avkon will change the current item index.
       
   995         SetHighlightVisibilityL(ETrue); //workaround
       
   996         resp = iWidget->OfferKeyEventL( aKeyEvent, aType );
       
   997         SetHighlightVisibilityL(EFalse);//workaround
       
   998         }
       
   999 
       
  1000     if ( iKeyEventObserver )
       
  1001     	{
       
  1002     	resp = iKeyEventObserver->HandleKeyPressedL( aKeyEvent, aType );
       
  1003     	}
       
  1004 
       
  1005     if ( ( aKeyEvent.iScanCode == EStdKeyDevice3 ||
       
  1006     		aKeyEvent.iScanCode == EStdKeyEnter ||
       
  1007     		aKeyEvent.iScanCode == EStdKeyNkpEnter ) && aType == EEventKeyDown )
       
  1008     	{
       
  1009     	if ( highlightVisibleWhenEventReceived )
       
  1010     		{
       
  1011     		iAllowLongPress = EFalse;
       
  1012     		}
       
  1013     	else
       
  1014     		{
       
  1015     		iAllowLongPress = ETrue;
       
  1016 
       
  1017 			SetHighlightVisibilityL( ETrue );
       
  1018 			SetDefaultHighlightL( ETrue );
       
  1019 			if ( iTimer )
       
  1020 				{
       
  1021 				iTimer->StartL( KDelayInSeconds6, EFalse );
       
  1022 				HandleForegroundGainedL();
       
  1023 				}
       
  1024 			}
       
  1025     	}
       
  1026     return resp;
       
  1027     }
       
  1028 
       
  1029 
       
  1030 // -----------------------------------------------------------------------------
       
  1031 //
       
  1032 // -----------------------------------------------------------------------------
       
  1033 //
       
  1034 //TBool CMmWidgetContainer::HighlightWouldLoop( const TKeyEvent& aKeyEvent,
       
  1035 //		const TEventCode& aType )
       
  1036 //	{
       
  1037 //	TInt viewColCount ( ColumnsInCurrentView() );
       
  1038 //
       
  1039 //	if ( viewColCount == 0 )
       
  1040 //		return ETrue;
       
  1041 //
       
  1042 //	// this allows to finish drag'n'drop operation
       
  1043 //	if ( iDraggedIndex != KErrNotFound && aType == EEventKeyUp )
       
  1044 //		return EFalse;
       
  1045 //
       
  1046 //	TBool wouldLoop = EFalse;
       
  1047 //	TInt highlightIndex = GetHighlight();
       
  1048 //
       
  1049 //	TInt highlightRow = highlightIndex / viewColCount;
       
  1050 //	TInt lastRowWithItems = ( NumberOfItems() - 1 ) / viewColCount;
       
  1051 //	TInt highlightCol = highlightIndex % viewColCount;
       
  1052 //	TInt lastItemCol = ( NumberOfItems() - 1 ) % viewColCount;
       
  1053 //
       
  1054 //	TInt keyScanCode = aKeyEvent.iScanCode;
       
  1055 //
       
  1056 //	if ( AknLayoutUtils::LayoutMirrored() )
       
  1057 //		{
       
  1058 //		if ( keyScanCode == EStdKeyLeftArrow )
       
  1059 //			keyScanCode = EStdKeyRightArrow;
       
  1060 //		else if ( keyScanCode == EStdKeyRightArrow )
       
  1061 //			keyScanCode = EStdKeyLeftArrow;
       
  1062 //		}
       
  1063 //
       
  1064 //	if ( keyScanCode == EStdKeyRightArrow )
       
  1065 //		{
       
  1066 //			if ( highlightIndex == NumberOfItems() - 1 )
       
  1067 //				wouldLoop = ETrue;
       
  1068 //			else if ( highlightCol == viewColCount - 1 )
       
  1069 //				wouldLoop = ETrue;
       
  1070 //		}
       
  1071 //	else if ( keyScanCode == EStdKeyLeftArrow )
       
  1072 //		{
       
  1073 //			if ( highlightCol == 0 )
       
  1074 //				wouldLoop = ETrue;
       
  1075 //		}
       
  1076 //	else if ( keyScanCode == EStdKeyUpArrow )
       
  1077 //		{
       
  1078 //			if ( highlightRow == 0 )
       
  1079 //				wouldLoop = ETrue;
       
  1080 //		}
       
  1081 //	else if ( keyScanCode == EStdKeyDownArrow )
       
  1082 //		{
       
  1083 //			if ( highlightRow == lastRowWithItems )
       
  1084 //				wouldLoop = ETrue;
       
  1085 //			else if ( highlightRow == lastRowWithItems - 1 && highlightCol > lastItemCol)
       
  1086 //				wouldLoop = ETrue;
       
  1087 //		}
       
  1088 //
       
  1089 //	return wouldLoop;
       
  1090 //	}
       
  1091 
       
  1092 // -----------------------------------------------------------------------------
       
  1093 //
       
  1094 // -----------------------------------------------------------------------------
       
  1095 //
       
  1096 TInt CMmWidgetContainer::ColumnsInCurrentView()
       
  1097 	{
       
  1098 	//should be overridden by deriving classes
       
  1099 	return NumberOfItems();
       
  1100 	}
       
  1101 // -----------------------------------------------------------------------------
       
  1102 //
       
  1103 // -----------------------------------------------------------------------------
       
  1104 //
       
  1105 TInt CMmWidgetContainer::RowsInCurrentView()
       
  1106     {
       
  1107     //should be overridden by deriving classes   
       
  1108     CListBoxView *view = ((CListBoxView*) Widget()->View());
       
  1109     return view->NumberOfItemsThatFitInRect( Rect());//Widget()->View()->ViewRect());
       
  1110     }
       
  1111 
       
  1112 // -----------------------------------------------------------------------------
       
  1113 //
       
  1114 // -----------------------------------------------------------------------------
       
  1115 //
       
  1116 void CMmWidgetContainer::HandleRockerPressL()
       
  1117 	{
       
  1118     TKeyEvent ke;
       
  1119     ke.iScanCode = EStdKeyNull;
       
  1120     ke.iCode = EStdKeyNull;
       
  1121     ke.iModifiers = 0;
       
  1122     ke.iRepeats = 0;
       
  1123     if( iKeyEventObserver )
       
  1124         {
       
  1125         iKeyEventObserver->HandleKeyPressedL( ke, EEventUser );
       
  1126         }
       
  1127 	}
       
  1128 
       
  1129 // -----------------------------------------------------------------------------
       
  1130 //
       
  1131 // -----------------------------------------------------------------------------
       
  1132 //
       
  1133 TKeyResponse CMmWidgetContainer::HandleKeyEventL( const TKeyEvent &aKeyEvent,
       
  1134         TEventCode aType )
       
  1135     {
       
  1136     TKeyResponse resp = EKeyWasNotConsumed;
       
  1137     TBool arrowKeyPressed = aKeyEvent.iScanCode == EStdKeyRightArrow ||
       
  1138         aKeyEvent.iScanCode == EStdKeyLeftArrow ||
       
  1139         aKeyEvent.iScanCode == EStdKeyUpArrow ||
       
  1140         aKeyEvent.iScanCode == EStdKeyDownArrow;
       
  1141     TBool arrowHasHandling = ( aKeyEvent.iScanCode == EStdKeyRightArrow
       
  1142 									&& WidgetType() != EListWidget )
       
  1143 							|| ( aKeyEvent.iScanCode == EStdKeyLeftArrow
       
  1144 									&& WidgetType() != EListWidget )
       
  1145 							|| aKeyEvent.iScanCode == EStdKeyUpArrow
       
  1146 							|| aKeyEvent.iScanCode == EStdKeyDownArrow;
       
  1147 
       
  1148     // handle arrow: draw highlight when arrow used
       
  1149     if ( arrowHasHandling )
       
  1150         {
       
  1151         if ( !iTimer->IsActive() )
       
  1152             {
       
  1153             if ( aType == EEventKey  || aType == EEventKeyUp )
       
  1154                 {
       
  1155                 // if no highlight and key released - show highlight
       
  1156                 SetDefaultHighlightL( EFalse );
       
  1157                 }
       
  1158            	// ignore all navigation events when highlight not visible
       
  1159          	resp = EKeyWasConsumed;
       
  1160             }
       
  1161         else
       
  1162             {
       
  1163 
       
  1164             // this block is used to set the highlight only once for each event
       
  1165             if ( aKeyEvent.iRepeats > 0 )
       
  1166                 {
       
  1167                 // if repeated key events we move focus on EEventKey
       
  1168                 if ( aType == EEventKey )
       
  1169                     {
       
  1170                     SetHighlightL( iWidget->CurrentItemIndex() );
       
  1171                     }
       
  1172                 }
       
  1173             else
       
  1174                 {
       
  1175                 // if single event we move focus on EEventKeyUp
       
  1176                 if ( aType == EEventKeyUp )
       
  1177                     {
       
  1178                     SetHighlightL( iWidget->CurrentItemIndex() );
       
  1179                     }
       
  1180                 }
       
  1181             }
       
  1182 
       
  1183     	// run timer in order to hide the highlight
       
  1184 	    if ( aType == EEventKey && iTimer)
       
  1185 	        {
       
  1186 	        iTimer->StartL( KDelayInSeconds6, EFalse );
       
  1187 	        HandleForegroundGainedL();
       
  1188 	        }
       
  1189     	}
       
  1190     else if( arrowKeyPressed )
       
  1191         {
       
  1192         // ignore left and right arrows in list
       
  1193         resp = EKeyWasConsumed;
       
  1194         }
       
  1195     // rocker select (short press)
       
  1196     else if ( ( aKeyEvent.iScanCode == EStdKeyDevice3 ) && ( aType == EEventKeyDown  ) )
       
  1197     	{
       
  1198 		HandleRockerPressL();
       
  1199 		resp = EKeyWasConsumed;
       
  1200     	}
       
  1201     else if ( iAllowLongPress && aType == EEventKey && aKeyEvent.iRepeats > 0 &&
       
  1202     		( aKeyEvent.iScanCode == EStdKeyDevice3
       
  1203 				|| aKeyEvent.iScanCode == EStdKeyEnter 
       
  1204 				|| aKeyEvent.iScanCode == EStdKeyNkpEnter ) )
       
  1205     	{
       
  1206     	HandleRockerPressL();
       
  1207     	resp = EKeyWasConsumed;
       
  1208     	iAllowLongPress = EFalse;
       
  1209     	}
       
  1210     
       
  1211     return resp;
       
  1212     }
       
  1213 
       
  1214 // -----------------------------------------------------------------------------
       
  1215 //
       
  1216 //
       
  1217 // -----------------------------------------------------------------------------
       
  1218 //
       
  1219 void CMmWidgetContainer::SetSuiteModelL(CHnSuiteModel* aModel)
       
  1220     {
       
  1221     CHnSuiteModel* prevModel = GetMmModel()->GetSuiteModel();
       
  1222 
       
  1223     TInt numberOfItemsBefore (0);
       
  1224     numberOfItemsBefore = GetMmModel()->NumberOfItems();
       
  1225 
       
  1226     GetMmModel()->SetSuiteModelL( aModel );
       
  1227 
       
  1228     // This needs to be in place (disabling redraw)
       
  1229     // to udpate widget internal state, however to wait for
       
  1230     // drawing until all highlight set matters are solved.
       
  1231     iWidget->MakeVisible(EFalse);
       
  1232     if ( GetMmModel()->NumberOfItems() >= numberOfItemsBefore )
       
  1233         {
       
  1234         HandleItemAdditionL();
       
  1235         }
       
  1236     else
       
  1237         {
       
  1238         HandleItemRemovalL();
       
  1239         }
       
  1240     if ( prevModel && aModel )
       
  1241         {
       
  1242         SetupWidgetLayoutL();
       
  1243         }
       
  1244     iWidget->MakeVisible(ETrue);
       
  1245 
       
  1246     Widget()->View()->ItemDrawer()->ClearFlags( 
       
  1247     		CListItemDrawer::EPressedDownState );
       
  1248 	iPostProcessor->StartAt( iWidget->BottomItemIndex() + 1 );
       
  1249     }
       
  1250 
       
  1251 // ---------------------------------------------------------------------------
       
  1252 //
       
  1253 // ---------------------------------------------------------------------------
       
  1254 //
       
  1255 void CMmWidgetContainer::SetupDrawer()
       
  1256 	{
       
  1257 	iDrawer = STATIC_CAST(CMmListBoxItemDrawer*, iWidget->View()->ItemDrawer());
       
  1258 	}
       
  1259 
       
  1260 
       
  1261 // ---------------------------------------------------------------------------
       
  1262 //
       
  1263 // ---------------------------------------------------------------------------
       
  1264 //
       
  1265 EXPORT_C THnSuiteWidgetType CMmWidgetContainer::WidgetType()
       
  1266 	{
       
  1267 	return EUnspecified;
       
  1268 	}
       
  1269 // ---------------------------------------------------------------------------
       
  1270 //
       
  1271 // ---------------------------------------------------------------------------
       
  1272 //
       
  1273 void CMmWidgetContainer::RemoveLiwObjects()
       
  1274     {
       
  1275     // there is only one place where LIW objects can be (co)owned in mmwidgets
       
  1276     // and that place is item drawer's cache
       
  1277     iDrawer->TrimCacheSize( 0 );
       
  1278     }
       
  1279 // ---------------------------------------------------------------------------
       
  1280 //
       
  1281 // ---------------------------------------------------------------------------
       
  1282 //
       
  1283 EXPORT_C void CMmWidgetContainer::HandleBackgroundGainedL()
       
  1284     {
       
  1285     iInForeground = EFalse;
       
  1286     StartOrStopMarquee();
       
  1287 
       
  1288     CancelDragL();
       
  1289 
       
  1290     // Fix for EMWK-7NYKRJ
       
  1291     // Matrix Menu: Scrollbar highligted when App Key is pressed while it is held
       
  1292     if ( AknLayoutUtils::PenEnabled() )
       
  1293         {
       
  1294         CEikScrollBar* scrollBar =
       
  1295                 iWidget->ScrollBarFrame()->VerticalScrollBar();
       
  1296         if ( scrollBar && scrollBar->IsVisible() )
       
  1297             {
       
  1298             TPointerEvent fakeButton1UpEvent;
       
  1299             fakeButton1UpEvent.iType = TPointerEvent::EButton1Up;
       
  1300             fakeButton1UpEvent.iModifiers = 0;
       
  1301             scrollBar->HandlePointerEventL( fakeButton1UpEvent );
       
  1302             }
       
  1303         }
       
  1304     }
       
  1305 
       
  1306 // ---------------------------------------------------------------------------
       
  1307 //
       
  1308 // ---------------------------------------------------------------------------
       
  1309 //
       
  1310 EXPORT_C void CMmWidgetContainer::HandleForegroundGainedL()
       
  1311     {
       
  1312     iInForeground = ETrue;
       
  1313     StartOrStopMarquee();
       
  1314     }
       
  1315 
       
  1316 // ---------------------------------------------------------------------------
       
  1317 //
       
  1318 // ---------------------------------------------------------------------------
       
  1319 //
       
  1320 TInt CMmWidgetContainer::DeltaSquare( const TPoint aTapPoint,
       
  1321 		const TPoint aPos )
       
  1322 	{
       
  1323 	TInt delta( KErrNotFound );
       
  1324 	TInt height = aTapPoint.iY - aPos.iY;
       
  1325 	TInt width = aTapPoint.iX - aPos.iX;
       
  1326     if( WidgetType() == EListWidget )
       
  1327     	{
       
  1328     	delta = height * height + height * height;
       
  1329     	}
       
  1330     else
       
  1331     	{
       
  1332     	delta = height * height + width * width;
       
  1333     	}
       
  1334 	return delta;
       
  1335 	}
       
  1336 
       
  1337 // ---------------------------------------------------------------------------
       
  1338 //
       
  1339 // ---------------------------------------------------------------------------
       
  1340 //
       
  1341 void CMmWidgetContainer::CancelDragL()
       
  1342     {
       
  1343     if( iIsEditMode && iDrawer )
       
  1344         {
       
  1345         if( iDrawer->GetFloatingItemIndex( EDrag ) != KErrNotFound )
       
  1346             {
       
  1347             CancelDragL( EFalse );
       
  1348             }
       
  1349         }
       
  1350     }
       
  1351 
       
  1352 // ---------------------------------------------------------------------------
       
  1353 //
       
  1354 // ---------------------------------------------------------------------------
       
  1355 //
       
  1356 EXPORT_C void CMmWidgetContainer::HandleItemAdditionL()
       
  1357 	{
       
  1358 	// only the the descended method should be invoked.
       
  1359 	// this is needed to avoid codescanner warning
       
  1360 	User::Leave( KErrNotSupported );
       
  1361 	}
       
  1362 
       
  1363 
       
  1364 // ---------------------------------------------------------------------------
       
  1365 //
       
  1366 // ---------------------------------------------------------------------------
       
  1367 //
       
  1368 EXPORT_C void CMmWidgetContainer::HandleItemRemovalL()
       
  1369 	{
       
  1370 	// only the the descended method should be invoked.
       
  1371 	// this is needed to avoid codescanner warning
       
  1372 	User::Leave( KErrNotSupported );
       
  1373 	}
       
  1374 
       
  1375 // ---------------------------------------------------------------------------
       
  1376 //
       
  1377 // ---------------------------------------------------------------------------
       
  1378 //
       
  1379 TBool CMmWidgetContainer::FlipOpen()
       
  1380 	{
       
  1381 	return iFlipOpen;
       
  1382 	}
       
  1383 
       
  1384 // ---------------------------------------------------------------------------
       
  1385 //
       
  1386 // ---------------------------------------------------------------------------
       
  1387 //
       
  1388 EXPORT_C void CMmWidgetContainer::SetFlipOpenL( TBool aIsFlipOpen )
       
  1389 	{
       
  1390     if ( aIsFlipOpen != iFlipOpen )
       
  1391     	{
       
  1392     	iFlipOpen = aIsFlipOpen;
       
  1393     	FlipStateChangedL();
       
  1394 		}
       
  1395 	}
       
  1396 
       
  1397 // ---------------------------------------------------------------------------
       
  1398 //
       
  1399 // ---------------------------------------------------------------------------
       
  1400 //
       
  1401 void CMmWidgetContainer::FlipStateChangedL()
       
  1402 	{
       
  1403 //	default do nothing
       
  1404 	}
       
  1405 
       
  1406 // ---------------------------------------------------------------------------
       
  1407 //
       
  1408 // ---------------------------------------------------------------------------
       
  1409 //
       
  1410 EXPORT_C void CMmWidgetContainer::StopMovingL()
       
  1411 	{
       
  1412 	if ( !AknLayoutUtils::PenEnabled() && iDragAndDropObserver )
       
  1413 		iDragAndDropObserver->HandleDragStopL( GetHighlight() );
       
  1414 	}
       
  1415 
       
  1416 
       
  1417 // ---------------------------------------------------------------------------
       
  1418 //
       
  1419 // ---------------------------------------------------------------------------
       
  1420 //
       
  1421 void CMmWidgetContainer::ScrollViewIfNeededL()
       
  1422 	{
       
  1423 	if ((iWidget->BottomItemIndex() / ColumnsInCurrentView()
       
  1424 			-  iWidget->TopItemIndex() / ColumnsInCurrentView() ) <= 1 )
       
  1425 		{
       
  1426 		return;
       
  1427 		}
       
  1428 
       
  1429 	TBool needToScrollUp = 
       
  1430 		GetHighlight() - iWidget->TopItemIndex() < ColumnsInCurrentView()
       
  1431 		&& iWidget->TopItemIndex() != 0;
       
  1432 	
       
  1433 	TBool needToScrollDown =
       
  1434 		iWidget->BottomItemIndex() - GetHighlight() < ColumnsInCurrentView()
       
  1435 		&& iWidget->BottomItemIndex() / ColumnsInCurrentView() 
       
  1436 			!= ( NumberOfItems() - 1 )  / ColumnsInCurrentView();
       
  1437 	
       
  1438 	if ( WidgetType() == EGridWidget )
       
  1439 		{
       
  1440 		// TODO: temporary - invisible partial items in MCL grid :/
       
  1441 		needToScrollDown = 
       
  1442 			iWidget->BottomItemIndex() - ColumnsInCurrentView() - GetHighlight() < ColumnsInCurrentView()
       
  1443 		    && ( iWidget->BottomItemIndex() / ColumnsInCurrentView() ) - 1
       
  1444 				!= ( NumberOfItems() - 1 ) / ColumnsInCurrentView()
       
  1445 			&& iWidget->BottomItemIndex() - iWidget->TopItemIndex()
       
  1446 				> ColumnsInCurrentView() * RowsInCurrentView();
       
  1447 		}
       
  1448 	
       
  1449 	if ( needToScrollUp )
       
  1450 		{
       
  1451 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
  1452 			MAknListBoxTfxInternal *transApi = CAknListLoader::TfxApiInternal( iDrawer->Gc() );
       
  1453 			if ( transApi )
       
  1454 				{
       
  1455 				transApi->SetMoveType( MAknListBoxTfxInternal::EListScrollUp );
       
  1456 				}
       
  1457 #endif
       
  1458 		iDrawer->RemoveFloatingItems();
       
  1459 		iWidget->View()->VScrollTo(
       
  1460 				iWidget->TopItemIndex() - ColumnsInCurrentView() );
       
  1461 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
  1462 			if ( transApi )
       
  1463 				{
       
  1464 				transApi->Draw( Rect() );
       
  1465 				}
       
  1466 #endif
       
  1467 		UpdateViewScrollBarThumbs();
       
  1468 		}
       
  1469 	else if ( needToScrollDown )
       
  1470 		{
       
  1471 		
       
  1472 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
  1473 			MAknListBoxTfxInternal *transApi = CAknListLoader::TfxApiInternal( iDrawer->Gc() );
       
  1474 			if ( transApi )
       
  1475 				{
       
  1476 				transApi->SetMoveType( MAknListBoxTfxInternal::EListScrollDown );
       
  1477 				}
       
  1478 #endif
       
  1479 		iDrawer->RemoveFloatingItems();
       
  1480 		iWidget->View()->VScrollTo(
       
  1481 				iWidget->TopItemIndex() + ColumnsInCurrentView() );
       
  1482 
       
  1483 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
  1484 			if ( transApi )
       
  1485 				{
       
  1486 				transApi->Draw( Rect() );
       
  1487 				}
       
  1488 #endif
       
  1489 		
       
  1490 		UpdateViewScrollBarThumbs();
       
  1491 		}
       
  1492 	}
       
  1493 
       
  1494 //----------------------------------------------------------------------------
       
  1495 //
       
  1496 // ---------------------------------------------------------------------------
       
  1497 //
       
  1498 void CMmWidgetContainer::UpdateViewScrollBarThumbs()
       
  1499 	{
       
  1500 	
       
  1501 	}
       
  1502 
       
  1503 //----------------------------------------------------------------------------
       
  1504 //
       
  1505 // ---------------------------------------------------------------------------
       
  1506 //
       
  1507 void CMmWidgetContainer::StartOrStopMarquee()
       
  1508     {
       
  1509     if ( iMarqueeAdapter )
       
  1510         {
       
  1511         TBool marqueeShouldBeEnabled = iHasFocus && iInForeground
       
  1512                 && !iIsFaded && !IsEditMode();
       
  1513         
       
  1514          // logical Ex-OR
       
  1515         if ( !!marqueeShouldBeEnabled != !!iMarqueeAdapter->IsMarqueeEnabled() )
       
  1516             {
       
  1517             if ( !marqueeShouldBeEnabled )
       
  1518                 {
       
  1519                 iMarqueeAdapter->StopMarqueeDrawing();
       
  1520                 }
       
  1521 
       
  1522             iMarqueeAdapter->EnableMarquee( marqueeShouldBeEnabled );
       
  1523             }
       
  1524         }
       
  1525     }
       
  1526 
       
  1527 //----------------------------------------------------------------------------
       
  1528 //
       
  1529 // ---------------------------------------------------------------------------
       
  1530 //
       
  1531 EXPORT_C void CMmWidgetContainer::HandleZoomChanged( TAknUiZoom aZoom )
       
  1532 	{
       
  1533 	SetZoom( aZoom );
       
  1534 	if( WidgetType() == EGridWidget )
       
  1535 	    {
       
  1536 	    CMmGrid* grid = static_cast<CMmGrid*>( iWidget );
       
  1537 	    grid->SetupLayout();
       
  1538 	    }
       
  1539 	Widget()->DrawDeferred();
       
  1540 	}
       
  1541 
       
  1542 // ---------------------------------------------------------------------------
       
  1543 //
       
  1544 // ---------------------------------------------------------------------------
       
  1545 //
       
  1546 EXPORT_C void CMmWidgetContainer::SetZoom( TAknUiZoom aZoom )
       
  1547 	{
       
  1548 	CMmTemplateLibrary * templateLibrary =
       
  1549 	static_cast<CMmListBoxItemDrawer*> (
       
  1550 			Widget()->View()->ItemDrawer() )->TemplateLibrary();
       
  1551 
       
  1552 	if ( WidgetType() == EGridWidget && EAknUiZoomSmall == aZoom )
       
  1553 		{
       
  1554 		aZoom = EAknUiZoomNormal;
       
  1555 		}
       
  1556 	templateLibrary->SetZoom( aZoom );
       
  1557 	}
       
  1558 
       
  1559 // ---------------------------------------------------------------------------
       
  1560 //
       
  1561 // ---------------------------------------------------------------------------
       
  1562 //
       
  1563 void CMmWidgetContainer::SetHighlightAfterDrag()
       
  1564 	{
       
  1565     if ( AknLayoutUtils::PenEnabled() &&
       
  1566     		iDraggedIndex != KErrNotFound && 
       
  1567 			iDraggedIndex != Widget()->CurrentItemIndex()
       
  1568 			&& iDraggedIndex < NumberOfItems() )
       
  1569     	{
       
  1570     	TBool isFolder(EFalse);
       
  1571     	CHnSuiteModel* model = GetMmModel()->GetSuiteModel();
       
  1572 		CHnItemModel* onItemModel = model->GetItemModel( 
       
  1573 				model->IdByIndex( Widget()->CurrentItemIndex() ));
       
  1574 	    if (onItemModel)
       
  1575 	    	{
       
  1576 	    	isFolder = onItemModel->GetItemType() == EItemTypeParentFolder ||
       
  1577 				onItemModel->GetItemType() == EItemTypeFolder;
       
  1578 	    	}
       
  1579 	    if (!isFolder)
       
  1580 	    	{
       
  1581 	    	Widget()->View()->SetCurrentItemIndex( iDraggedIndex );
       
  1582 	    	}
       
  1583     	}
       
  1584 	}
       
  1585 
       
  1586 // ---------------------------------------------------------------------------
       
  1587 //
       
  1588 // ---------------------------------------------------------------------------
       
  1589 //
       
  1590 void CMmWidgetContainer::ValidateWidgetCurrentItemIndex()
       
  1591 	{
       
  1592 	if (Widget()->CurrentItemIndex() >= GetMmModel()->NumberOfItems() 
       
  1593 			|| Widget()->CurrentItemIndex() == KErrNotFound )
       
  1594 		{
       
  1595 		iCurrentHighlight = GetMmModel()->NumberOfItems();
       
  1596 		if( iCurrentHighlight > 0 )
       
  1597 			{
       
  1598 			Widget()->View()->SetCurrentItemIndex( --iCurrentHighlight );
       
  1599 			}
       
  1600 		else
       
  1601 			{
       
  1602 			iCurrentHighlight = KErrNotFound ;
       
  1603 			}
       
  1604 		}
       
  1605 	}
       
  1606 
       
  1607 // ---------------------------------------------------------------------------
       
  1608 //
       
  1609 // ---------------------------------------------------------------------------
       
  1610 //
       
  1611 EXPORT_C void CMmWidgetContainer::CacheWidgetPosition()
       
  1612 	{
       
  1613 	iWidgetPositionCache.iVerticalItemOffset = VerticalItemOffset();
       
  1614 	iWidgetPositionCache.iTopItemIndex = Widget()->TopItemIndex();
       
  1615 	iWidgetPositionCache.iLandscape
       
  1616 			= Layout_Meta_Data::IsLandscapeOrientation();
       
  1617 	iWidgetPositionCache.iHighlightedItemId = KErrNotFound;
       
  1618 	
       
  1619 	TInt highlightedItemIndex = Widget()->CurrentItemIndex();
       
  1620 	CHnSuiteModel* suiteModel = GetMmModel()->GetSuiteModel();
       
  1621 	if ( suiteModel && highlightedItemIndex != KErrNotFound
       
  1622 	        && suiteModel->GetSuiteHighlight() == highlightedItemIndex
       
  1623 	        && ItemIsVisible( highlightedItemIndex ) )
       
  1624 	    {
       
  1625 	    iWidgetPositionCache.iHighlightedItemId =
       
  1626             suiteModel->IdByIndex( highlightedItemIndex );
       
  1627 	    }
       
  1628 	
       
  1629 	iWidgetPositionCache.iValid = ETrue;
       
  1630 	}
       
  1631 
       
  1632 // ---------------------------------------------------------------------------
       
  1633 //
       
  1634 // ---------------------------------------------------------------------------
       
  1635 //
       
  1636 EXPORT_C void CMmWidgetContainer::RestoreWidgetPosition()
       
  1637 	{
       
  1638 	if (iWidgetPositionCache.iValid)
       
  1639 		{
       
  1640 	   if ( iWidgetPositionCache.iLandscape
       
  1641 				== Layout_Meta_Data::IsLandscapeOrientation() )
       
  1642 			{
       
  1643             // If view position was cached during boundary effect, correct the
       
  1644             // cached position.
       
  1645             if ( iWidgetPositionCache.iTopItemIndex == 0 &&
       
  1646                     iWidgetPositionCache.iVerticalItemOffset > 0 )
       
  1647                 {
       
  1648                 iWidgetPositionCache.iVerticalItemOffset = 0;
       
  1649                 // This corrects the position cached during the upper boundary
       
  1650                 // effect. AlignBottomOfViewL will take care of lower boundary
       
  1651                 // effect.
       
  1652                 }
       
  1653 
       
  1654 			Widget()->View()->SetTopItemIndex(iWidgetPositionCache.iTopItemIndex);
       
  1655 			SetVerticalItemOffset(iWidgetPositionCache.iVerticalItemOffset);
       
  1656 			TRAP_IGNORE( AlignBottomOfViewL() );
       
  1657 			
       
  1658 			// Important: If an item that was previously highlighted and visible is
       
  1659 			// still highlighted and yet somehow is not visible after the position
       
  1660 			// has been restored, fix the problem by scrolling the view until that
       
  1661 			// item is visible again:
       
  1662 			CHnSuiteModel* suiteModel = GetMmModel()->GetSuiteModel();
       
  1663 			if ( suiteModel && IsHighlightVisible() )
       
  1664 			    {
       
  1665 			    TInt highlightedItemIndex = suiteModel->GetSuiteHighlight();
       
  1666 			    TInt highlightedItemId = highlightedItemIndex != KErrNotFound ?
       
  1667 			        suiteModel->IdByIndex( highlightedItemIndex ) : KErrNotFound;
       
  1668 			    if ( highlightedItemId != KErrNotFound
       
  1669 			            && highlightedItemId == iWidgetPositionCache.iHighlightedItemId
       
  1670 			            && !ItemIsVisible( highlightedItemIndex ) )
       
  1671 			        {
       
  1672 			        TRAP_IGNORE( ScrollToItemL( highlightedItemIndex ) );
       
  1673 			        }
       
  1674 			    }
       
  1675 			}
       
  1676 		else
       
  1677 			{
       
  1678 			TRAP_IGNORE( ScrollToItemL(Widget()->CurrentItemIndex()) );
       
  1679 			}
       
  1680 		
       
  1681 		iWidgetPositionCache.iValid = EFalse;
       
  1682 		}
       
  1683 	}
       
  1684 
       
  1685 // ---------------------------------------------------------------------------
       
  1686 //
       
  1687 // ---------------------------------------------------------------------------
       
  1688 //
       
  1689 void CMmWidgetContainer::MakeVisible(TBool aVisible)
       
  1690 	{
       
  1691 	if (!aVisible)
       
  1692 		{
       
  1693 		ASSERT(iTimer);
       
  1694 		TRAP_IGNORE( iTimer->StopL( EFalse ) );
       
  1695 		RestoreWidgetPosition();
       
  1696 		CacheWidgetPosition();
       
  1697 		iDrawer->RemoveFloatingItems();
       
  1698 		}
       
  1699 	else if (aVisible)
       
  1700 		{
       
  1701 		RestoreWidgetPosition();
       
  1702 		}
       
  1703 	CCoeControl::MakeVisible(aVisible);
       
  1704 	iWidget->MakeVisible(aVisible);
       
  1705 	}
       
  1706 
       
  1707 // ---------------------------------------------------------------------------
       
  1708 //
       
  1709 // ---------------------------------------------------------------------------
       
  1710 //
       
  1711 EXPORT_C void CMmWidgetContainer::ResetWidgetPosition()
       
  1712 	{
       
  1713 	iWidgetPositionCache.iVerticalItemOffset = 0;
       
  1714 	iWidgetPositionCache.iTopItemIndex = 0;
       
  1715 	iWidgetPositionCache.iValid = EFalse;
       
  1716 	iWidgetPositionCache.iHighlightedItemId = KErrNotFound;
       
  1717 	Widget()->SetTopItemIndex(0);
       
  1718 	SetVerticalItemOffset(0);
       
  1719 	}
       
  1720 
       
  1721 // ---------------------------------------------------------------------------
       
  1722 //
       
  1723 // ---------------------------------------------------------------------------
       
  1724 //
       
  1725 EXPORT_C void CMmWidgetContainer::NumberOfItemsChangedL( TItemsChangeType aChange )
       
  1726 	{
       
  1727 	if ( AknLayoutUtils::PenEnabled() )
       
  1728 		{
       
  1729 		CacheWidgetPosition();
       
  1730 		Widget()->View()->SetDisableRedraw( ETrue );
       
  1731 		
       
  1732 		HandleNumberOfItemsChangedL( aChange );
       
  1733 		
       
  1734 		Widget()->View()->SetDisableRedraw( EFalse );
       
  1735 		RestoreWidgetPosition();
       
  1736 		}
       
  1737 	else
       
  1738 		{
       
  1739 		// there is no need to cache and restore widget position in non-touch;
       
  1740 		// moreover, it can cause some problems with scrolling when adding
       
  1741 		// new folder
       
  1742 		HandleNumberOfItemsChangedL( aChange );
       
  1743 		}
       
  1744 	}
       
  1745 
       
  1746 // ---------------------------------------------------------------------------
       
  1747 //
       
  1748 // ---------------------------------------------------------------------------
       
  1749 //
       
  1750 void CMmWidgetContainer::HandleNumberOfItemsChangedL( TItemsChangeType aChange )
       
  1751 	{
       
  1752 	ASSERT(iTimer);
       
  1753 	iTimer->StopL();
       
  1754 	if ( aChange == EItemsAdded )
       
  1755 		{
       
  1756 		HandleItemAdditionL();
       
  1757 		}
       
  1758 	else if ( aChange == EItemsRemoved )
       
  1759 		{
       
  1760 		HandleItemRemovalL();
       
  1761 		}
       
  1762 	}
       
  1763 
       
  1764 // -----------------------------------------------------------------------------
       
  1765 //
       
  1766 // -----------------------------------------------------------------------------
       
  1767 //
       
  1768 TBool CMmWidgetContainer::AlignBottomOfViewL()
       
  1769 	{
       
  1770 	TInt scrollConsumed( EFalse );
       
  1771 	TInt pixelsToScroll( 0 );
       
  1772 	
       
  1773 	if ( NumberOfItems() > 0 )
       
  1774 		{
       
  1775 		pixelsToScroll = CalcBottomPixelsToScroll();
       
  1776 		}
       
  1777 
       
  1778 	if ( pixelsToScroll != 0 )
       
  1779 		{
       
  1780 		ScrollInPixelsL( pixelsToScroll );
       
  1781 		scrollConsumed = ETrue;
       
  1782 		}
       
  1783 
       
  1784 	return scrollConsumed;
       
  1785 	}
       
  1786 
       
  1787 // -----------------------------------------------------------------------------
       
  1788 //
       
  1789 // -----------------------------------------------------------------------------
       
  1790 //
       
  1791 TInt CMmWidgetContainer::CalcBottomPixelsToScroll()
       
  1792     {
       
  1793     const TInt firstItemIndex( 0 );
       
  1794     TInt lastItemIndex = NumberOfItems() - 1;
       
  1795     TInt viewHeight = Widget()->View()->ViewRect().Height();
       
  1796     TInt lastItemBottomY = Widget()->View()->ItemPos(lastItemIndex).iY
       
  1797                 + Widget()->ItemHeight();
       
  1798     TInt pixelsToScroll( 0 );
       
  1799     
       
  1800     if ( Widget()->ScrollBarFrame()->VerticalScrollBar()->IsVisible() )
       
  1801         {
       
  1802         pixelsToScroll = Min( 0, lastItemBottomY - viewHeight );
       
  1803         }
       
  1804     else
       
  1805         {
       
  1806         pixelsToScroll = Widget()->View()->ItemPos( firstItemIndex ).iY;
       
  1807         }
       
  1808     
       
  1809     return pixelsToScroll;
       
  1810     }
       
  1811 
       
  1812 
       
  1813 // -----------------------------------------------------------------------------
       
  1814 //
       
  1815 // -----------------------------------------------------------------------------
       
  1816 //
       
  1817 TBool CMmWidgetContainer::ItemIsVisible( TInt aItemIndex ) const
       
  1818     {
       
  1819     return iWidget->View()->ItemIsVisible( aItemIndex );
       
  1820     }
       
  1821 
       
  1822 // -----------------------------------------------------------------------------
       
  1823 //
       
  1824 // -----------------------------------------------------------------------------
       
  1825 //
       
  1826 EXPORT_C TBool CMmWidgetContainer::ItemIsFullyVisible(TInt aIndex)
       
  1827 	{
       
  1828 	return ItemIsVisible( aIndex )
       
  1829 			&& !Widget()->View()->ItemIsPartiallyVisible(aIndex);
       
  1830 	}
       
  1831 
       
  1832 // -----------------------------------------------------------------------------
       
  1833 //
       
  1834 // -----------------------------------------------------------------------------
       
  1835 //
       
  1836 void CMmWidgetContainer::ScrollInPixelsL(TInt aPixels)
       
  1837 	{
       
  1838 	SetupScrollingEffectsL( aPixels > 0 );
       
  1839 	
       
  1840 	if ( AknLayoutUtils::PenEnabled() )
       
  1841 		{
       
  1842 		Widget()->HandlePhysicsScrollEventL(aPixels);
       
  1843 		}
       
  1844 	else
       
  1845 		{
       
  1846 		// non-touch avkon doesn't seem to support scrolling by given
       
  1847 		// amount of pixels
       
  1848 		TInt delta = aPixels / Widget()->View()->ItemHeight();
       
  1849 		
       
  1850 		Widget()->View()->VScrollTo( Widget()->TopItemIndex() + 
       
  1851 				delta * ColumnsInCurrentView() );
       
  1852 		}
       
  1853 	}
       
  1854 
       
  1855 // -----------------------------------------------------------------------------
       
  1856 //
       
  1857 // -----------------------------------------------------------------------------
       
  1858 //
       
  1859 EXPORT_C TBool CMmWidgetContainer::ScrollToItemL(TInt aIndex)
       
  1860 	{
       
  1861 	TInt scrollConsumed(EFalse);
       
  1862 	if (aIndex >= 0 && aIndex <= NumberOfItems())
       
  1863 		{
       
  1864 		scrollConsumed = AlignBottomOfViewL();
       
  1865 		if ( !scrollConsumed && Widget()->View()->ItemIsPartiallyVisible(aIndex))
       
  1866 			{
       
  1867 //			the case when the item is partially visible at top or 
       
  1868 //			bottom of screen. Th e view is scrolled the offset to
       
  1869 //			make the item entirely visible.
       
  1870 			TInt offsetBottom = Widget()->View()->ItemPos(aIndex).iY
       
  1871 					+ Widget()->ItemHeight()
       
  1872 					- Widget()->View()->ViewRect().Height();
       
  1873 			TInt offsetTop = Widget()->View()->ItemPos(aIndex).iY;
       
  1874 			TBool takeTop = Abs(offsetTop) < Abs(offsetBottom);
       
  1875 			TInt offset = (takeTop) ? offsetTop : offsetBottom;
       
  1876 			if (offset != 0)
       
  1877 				{
       
  1878 				ScrollInPixelsL( offset );
       
  1879 				scrollConsumed = ETrue;
       
  1880 				}
       
  1881 				
       
  1882 			}
       
  1883 		else if (!Widget()->View()->ItemIsVisible(aIndex))
       
  1884 			{
       
  1885 //			the case when the item is not visible on screen
       
  1886 			SetupScrollingEffectsL( aIndex > Widget()->BottomItemIndex() );
       
  1887 			Widget()->ScrollToMakeItemVisible(aIndex);
       
  1888 			AlignBottomOfViewL();
       
  1889 			scrollConsumed = ETrue;
       
  1890 			}
       
  1891 		}
       
  1892 	return scrollConsumed;
       
  1893 	}
       
  1894 
       
  1895 // -----------------------------------------------------------------------------
       
  1896 //
       
  1897 // -----------------------------------------------------------------------------
       
  1898 //
       
  1899 void CMmWidgetContainer::SetupScrollingEffectsL(TBool aDown)
       
  1900 	{
       
  1901 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
  1902 	MAknListBoxTfxInternal *transApi = CAknListLoader::TfxApiInternal(
       
  1903 			iDrawer->Gc());
       
  1904 	if (transApi)
       
  1905 		{
       
  1906 		MAknListBoxTfxInternal::TMovementType movementType;
       
  1907 		movementType = (aDown == (TInt)ETrue ) ? MAknListBoxTfxInternal::EListScrollDown
       
  1908 				: MAknListBoxTfxInternal::EListScrollUp;
       
  1909 		transApi->SetMoveType(movementType);
       
  1910 		}
       
  1911 #endif
       
  1912 	}
       
  1913 
       
  1914 // -----------------------------------------------------------------------------
       
  1915 //
       
  1916 // -----------------------------------------------------------------------------
       
  1917 //
       
  1918 EXPORT_C void CMmWidgetContainer::PrepareForGarbage()
       
  1919 	{
       
  1920 //	This is called when the suite model is destoyed and the container is set to be destroyed
       
  1921 //	by the garbage collector. There should be no redraws done to the widget in this period 
       
  1922 //	because this will cause the screen to be redrawn only containing the balnk background.
       
  1923 //	Before garbage cleanup an asynchronous redraw event may intend to redraw the widget.
       
  1924 //	SetDisableRedraw() prevents redrawing. Animator is also prepared for garbage so there is
       
  1925 //	no instance which can enable redraw of the widget.
       
  1926 	Widget()->View()->SetDisableRedraw( ETrue );
       
  1927 	iDrawer->RemoveFloatingItems();
       
  1928 //	Prapares the animator for garbage, which means it blocks any animator drawing.
       
  1929 	iDrawer->GetAnimator()->PrepareForGarbage();
       
  1930 	}
       
  1931 
       
  1932 // -----------------------------------------------------------------------------
       
  1933 //
       
  1934 // -----------------------------------------------------------------------------
       
  1935 //
       
  1936 TBool CMmWidgetContainer::IsTimerActive( TInt aItemIndex )
       
  1937 	{
       
  1938 	ASSERT(iTimer);
       
  1939 	TBool timerActive = iTimer->IsActive();
       
  1940 	if ( aItemIndex >= 0 && timerActive )
       
  1941 		{
       
  1942 		timerActive = ( aItemIndex == iTimer->TimerHighlightIndex() );
       
  1943 		}
       
  1944 	return timerActive;
       
  1945 	}
       
  1946 
       
  1947 // -----------------------------------------------------------------------------
       
  1948 //
       
  1949 // -----------------------------------------------------------------------------
       
  1950 //
       
  1951 void CMmWidgetContainer::HandleLongTapEventL( const TPoint& aPenEventLocation, 
       
  1952                                       const TPoint& aPenEventScreenLocation )
       
  1953 	{
       
  1954 	TInt index( KErrNotFound );
       
  1955 	if ( iWidget->View()->XYPosToItemIndex( aPenEventLocation, index ) )
       
  1956 		{
       
  1957 		ASSERT( iTimer );
       
  1958 		iTimer->ContinueL( KDelayInfinite );
       
  1959 	    iLongTapInProgress = ETrue;
       
  1960 		if ( iLongTapObserver )
       
  1961 			{
       
  1962 			iLongTapObserver->HandleLongTapEventL( aPenEventScreenLocation );
       
  1963 			}
       
  1964 		}
       
  1965 	}
       
  1966 
       
  1967 // -----------------------------------------------------------------------------
       
  1968 //
       
  1969 // -----------------------------------------------------------------------------
       
  1970 //
       
  1971 EXPORT_C void CMmWidgetContainer::SetLongTapObserver( MMmLongTapObserver* aObserver )
       
  1972 	{
       
  1973 	iLongTapObserver = aObserver;
       
  1974 	}
       
  1975 
       
  1976 // -----------------------------------------------------------------------------
       
  1977 //
       
  1978 // -----------------------------------------------------------------------------
       
  1979 //
       
  1980 EXPORT_C void CMmWidgetContainer::HandleTopFocusL( TBool aStopTimer )
       
  1981 	{
       
  1982 	if ( iLongTapInProgress )
       
  1983 		{
       
  1984 		iLongTapInProgress = EFalse;
       
  1985 		if( aStopTimer )
       
  1986 			{
       
  1987 			ASSERT( iTimer );
       
  1988 			iTimer->StopL();
       
  1989 			}
       
  1990 		}
       
  1991 	}
       
  1992 
       
  1993 // ---------------------------------------------------------------------------
       
  1994 // 
       
  1995 // ---------------------------------------------------------------------------
       
  1996 //
       
  1997 void CMmWidgetContainer::HandleListBoxEventL( CEikListBox* aListBox,
       
  1998         TListBoxEvent aEventType )
       
  1999     {
       
  2000     ASSERT( iTimer );
       
  2001 //    handle same behaviour in edit mode and normal mode
       
  2002     switch ( aEventType )
       
  2003 		{
       
  2004 		case MEikListBoxObserver::EEventPenDownOnItem:
       
  2005 			{
       
  2006 			iDragOccured = EFalse;
       
  2007 			if ( !iLongTapInProgress )
       
  2008 				{
       
  2009 				iTimer->StartL( KDelayInfinite );
       
  2010 				}
       
  2011 			break;
       
  2012 			}
       
  2013 		case MEikListBoxObserver::EEventItemSingleClicked:
       
  2014 			{
       
  2015 			if ( !iDragOccured && !iLongTapInProgress )
       
  2016 				{
       
  2017 				SetHighlightL( Widget()->CurrentItemIndex() );
       
  2018 				iTimer->StopL( ETrue );
       
  2019 				}
       
  2020 			iDragOccured = EFalse;
       
  2021 			break;
       
  2022 			}
       
  2023 		case MEikListBoxObserver::EEventItemDraggingActioned:
       
  2024 			{
       
  2025 			iTimer->StopL();
       
  2026 			iDragOccured = ETrue;
       
  2027 			break;
       
  2028 			}
       
  2029 		case MEikListBoxObserver::EEventPanningStarted:
       
  2030 		case MEikListBoxObserver::EEventPanningStopped:
       
  2031 		case MEikListBoxObserver::EEventFlickStarted:
       
  2032 		case MEikListBoxObserver::EEventFlickStopped:
       
  2033 			{
       
  2034 			iTimer->StopL( EFalse );
       
  2035 			break;
       
  2036 			}
       
  2037 		}
       
  2038  
       
  2039 //    handle different behaviour in edit mode and normal mode
       
  2040 	if ( !IsEditMode() )
       
  2041 		{
       
  2042 		switch ( aEventType )
       
  2043 			{
       
  2044 			case MEikListBoxObserver::EEventFlickStarted:
       
  2045 				{
       
  2046 				static_cast<CMmListBoxItemDrawer*>( 
       
  2047 						Widget()->View()->ItemDrawer() )->
       
  2048 						EnableCachedDataUse( ETrue );
       
  2049 				break;
       
  2050 				}
       
  2051 			case MEikListBoxObserver::EEventFlickStopped:
       
  2052 				{
       
  2053 				static_cast<CMmListBoxItemDrawer*>( 
       
  2054 						Widget()->View()->ItemDrawer() )->
       
  2055 						EnableCachedDataUse( EFalse );
       
  2056 				DrawView();
       
  2057 				break;
       
  2058 				}
       
  2059 			}
       
  2060 		}
       
  2061 	else 
       
  2062 		{
       
  2063 		switch ( aEventType )
       
  2064 			{
       
  2065 			case MEikListBoxObserver::EEventFlickStopped:
       
  2066 				{
       
  2067 				// this fixes some problems with messed edit mode 
       
  2068 				// caused by kinetic scrolling
       
  2069 				iDrawer->GetAnimator()->SetNextRedrawToWholeScreen();
       
  2070 				break;
       
  2071 				}
       
  2072 			}
       
  2073 		}
       
  2074 	
       
  2075     if ( iListBoxObserver && !iLongTapInProgress )
       
  2076         {
       
  2077         iListBoxObserver->HandleListBoxEventL( aListBox, aEventType );
       
  2078         }
       
  2079     
       
  2080     }
       
  2081 
       
  2082 // ---------------------------------------------------------------------------
       
  2083 // 
       
  2084 // ---------------------------------------------------------------------------
       
  2085 //
       
  2086 EXPORT_C void CMmWidgetContainer::HandleOptionsMenuVisibilityChangeL( 
       
  2087 		TBool aOptionsMenuVisible )
       
  2088 	{
       
  2089 	if ( IsTimerActive() )
       
  2090 		{
       
  2091 		TInt delay = (aOptionsMenuVisible) ? KDelayInfinite : KDelayInSeconds6;
       
  2092 		iTimer->StartL( delay, EFalse );
       
  2093 		}
       
  2094 	}
       
  2095 //End of file