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