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