menufw/menufwui/mmwidgets/src/mmgridcontainer.cpp
branchRCL_3
changeset 25 137ebc85284b
parent 4 4d54b72983ae
child 26 1b758917cafc
equal deleted inserted replaced
23:7be2816dbabd 25:137ebc85284b
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *  Version     : %version: MM_74 % << Don't touch! Updated by Synergy at check-out.
    15 *  Version     : %version: MM_75 % << Don't touch! Updated by Synergy at check-out.
    16 *  Version     : %version: MM_74 % << Don't touch! Updated by Synergy at check-out.
    16 *  Version     : %version: MM_75 % << Don't touch! Updated by Synergy at check-out.
    17 *
    17 *
    18 */
    18 */
    19 
    19 
    20 
    20 
    21 #include "mmgridcontainer.h"
    21 #include "mmgridcontainer.h"
    90 // -----------------------------------------------------------------------------
    90 // -----------------------------------------------------------------------------
    91 //
    91 //
    92 // -----------------------------------------------------------------------------
    92 // -----------------------------------------------------------------------------
    93 //
    93 //
    94 THnSuiteWidgetType CMmGridContainer::WidgetType()
    94 THnSuiteWidgetType CMmGridContainer::WidgetType()
    95 	{
    95   {
    96 	return EGridWidget;
    96   return EGridWidget;
    97 	}
    97   }
    98 // -----------------------------------------------------------------------------
    98 // -----------------------------------------------------------------------------
    99 // CMmGridContainer::ConstructL()
    99 // CMmGridContainer::ConstructL()
   100 // 2nd phase constructor
   100 // 2nd phase constructor
   101 // -----------------------------------------------------------------------------
   101 // -----------------------------------------------------------------------------
   102 //
   102 //
   123 // -----------------------------------------------------------------------------
   123 // -----------------------------------------------------------------------------
   124 //
   124 //
   125 CMmGrid* CMmGridContainer::CreateGridL( CMmTemplateLibrary* aTemplateLibrary )
   125 CMmGrid* CMmGridContainer::CreateGridL( CMmTemplateLibrary* aTemplateLibrary )
   126     {
   126     {
   127     iGrid = CMmGrid::NewL( this,
   127     iGrid = CMmGrid::NewL( this,
   128     		EAknListBoxSelectionList | EAknListBoxLoopScrolling | EAknListBoxDisableHighlight , aTemplateLibrary );
   128         EAknListBoxSelectionList | EAknListBoxLoopScrolling | EAknListBoxDisableHighlight , aTemplateLibrary );
   129     iGrid->SetContainerWindowL( *this );
   129     iGrid->SetContainerWindowL( *this );
   130     iGrid->CreateScrollBarFrameL( ETrue );
   130     iGrid->CreateScrollBarFrameL( ETrue );
   131     iGrid->SetPrimaryScrollingType(
   131     iGrid->SetPrimaryScrollingType(
   132     			CAknGridView::EScrollFollowsItemsAndLoops );
   132           CAknGridView::EScrollFollowsItemsAndLoops );
   133     iGrid->SetSecondaryScrollingType(
   133     iGrid->SetSecondaryScrollingType(
   134     			CAknGridView::EScrollFollowsGrid );
   134           CAknGridView::EScrollFollowsGrid );
   135     iGrid->ScrollBarFrame()->SetScrollBarVisibilityL(
   135     iGrid->ScrollBarFrame()->SetScrollBarVisibilityL(
   136     		CEikScrollBarFrame::EAuto, CEikScrollBarFrame::EAuto );
   136         CEikScrollBarFrame::EAuto, CEikScrollBarFrame::EAuto );
   137     iGrid->ScrollBarFrame()->DrawBackground( EFalse, EFalse );
   137     iGrid->ScrollBarFrame()->DrawBackground( EFalse, EFalse );
   138     return iGrid;
   138     return iGrid;
   139     }
   139     }
   140 
   140 
   141 // -----------------------------------------------------------------------------
   141 // -----------------------------------------------------------------------------
   144 //
   144 //
   145 void CMmGridContainer::SizeChanged()
   145 void CMmGridContainer::SizeChanged()
   146     {
   146     {
   147     CMmWidgetContainer::SizeChanged();
   147     CMmWidgetContainer::SizeChanged();
   148     if ( iGrid )
   148     if ( iGrid )
   149     	{
   149       {
   150 //    	iGrid->SetRect( Rect() );
   150 //    	iGrid->SetRect( Rect() );
   151         iGrid->SetupLayout();
   151         iGrid->SetupLayout();
   152         }
   152         }
   153     }
   153     }
   154 // -----------------------------------------------------------------------------
   154 // -----------------------------------------------------------------------------
   155 //
   155 //
   156 // -----------------------------------------------------------------------------
   156 // -----------------------------------------------------------------------------
   157 //
   157 //
   158 void CMmGridContainer::SetEditModeL( TBool aIsEditMode )
   158 void CMmGridContainer::SetEditModeL( TBool aIsEditMode )
   159     {
   159     {
   160 	if (aIsEditMode && !AknLayoutUtils::PenEnabled() )
   160   if (aIsEditMode && !AknLayoutUtils::PenEnabled() )
   161 		{
   161     {
   162 		iGrid->SetPrimaryScrollingType(
   162     iGrid->SetPrimaryScrollingType(
   163 				CAknGridView::EScrollStops );
   163         CAknGridView::EScrollStops );
   164 		iGrid->SetSecondaryScrollingType(
   164     iGrid->SetSecondaryScrollingType(
   165 				CAknGridView::EScrollStops );
   165         CAknGridView::EScrollStops );
   166         }
   166         }
   167     else
   167     else
   168     	{
   168       {
   169     	iGrid->SetPrimaryScrollingType(
   169       iGrid->SetPrimaryScrollingType(
   170     	    			CAknGridView::EScrollFollowsItemsAndLoops );
   170                 CAknGridView::EScrollFollowsItemsAndLoops );
   171     	iGrid->SetSecondaryScrollingType(
   171       iGrid->SetSecondaryScrollingType(
   172     	    			CAknGridView::EScrollFollowsGrid );
   172                 CAknGridView::EScrollFollowsGrid );
   173 
   173 
   174     	}
   174       }
   175 
   175 
   176 	// In EditMode we allow Avkon to redraw scrollbar background
   176   // In EditMode we allow Avkon to redraw scrollbar background
   177 	// to prevent scrollbar flicking.
   177   // to prevent scrollbar flicking.
   178 	// When edit mode is disabled, this redrawing causes performance problems
   178   // When edit mode is disabled, this redrawing causes performance problems
   179 	// (and disabling it does not produce erroneous side-effects).
   179   // (and disabling it does not produce erroneous side-effects).
   180 	if( aIsEditMode )
   180   if( aIsEditMode )
   181 		{
   181     {
   182 	    iGrid->ScrollBarFrame()->DrawBackground( EFalse, ETrue );
   182       iGrid->ScrollBarFrame()->DrawBackground( EFalse, ETrue );
   183 		}
   183     }
   184 	else
   184   else
   185 		{
   185     {
   186 	    iGrid->ScrollBarFrame()->DrawBackground( EFalse, EFalse );
   186       iGrid->ScrollBarFrame()->DrawBackground( EFalse, EFalse );
   187 		}
   187     }
   188 
   188 
   189     CMmWidgetContainer::SetEditModeL( aIsEditMode );
   189     CMmWidgetContainer::SetEditModeL( aIsEditMode );
   190     }
   190     }
   191 
   191 
   192 // -----------------------------------------------------------------------------
   192 // -----------------------------------------------------------------------------
   212 //
   212 //
   213 //
   213 //
   214 // -----------------------------------------------------------------------------
   214 // -----------------------------------------------------------------------------
   215 //
   215 //
   216 TInt CMmGridContainer::DefaultHighlightOffset()
   216 TInt CMmGridContainer::DefaultHighlightOffset()
   217 	{
   217   {
   218 	TInt topVisibleItemIndex = iGrid->View()->TopItemIndex();
   218   TInt topVisibleItemIndex = iGrid->View()->TopItemIndex();
   219 	TInt hiddenPixels = -iGrid->View()->ItemOffsetInPixels();
   219   TInt hiddenPixels = -iGrid->View()->ItemOffsetInPixels();
   220 
   220 
   221 	if ( iGrid->View()->ItemIsPartiallyVisible( topVisibleItemIndex )
   221   if ( iGrid->View()->ItemIsPartiallyVisible( topVisibleItemIndex )
   222 		&& hiddenPixels > iGrid->View()->ItemSize().iHeight / 2 )
   222     && hiddenPixels > iGrid->View()->ItemSize().iHeight / 2 )
   223 		{
   223     {
   224 		topVisibleItemIndex += ColumnsInCurrentView();
   224     topVisibleItemIndex += ColumnsInCurrentView();
   225 		}
   225     }
   226 
   226 
   227 	return topVisibleItemIndex;
   227   return topVisibleItemIndex;
   228 	}
   228   }
   229 
   229 
   230 // -----------------------------------------------------------------------------
   230 // -----------------------------------------------------------------------------
   231 //
   231 //
   232 //
   232 //
   233 // -----------------------------------------------------------------------------
   233 // -----------------------------------------------------------------------------
   241 //
   241 //
   242 //
   242 //
   243 // -----------------------------------------------------------------------------
   243 // -----------------------------------------------------------------------------
   244 //
   244 //
   245 void CMmGridContainer::SetItemDrawerAndViewBgContext(
   245 void CMmGridContainer::SetItemDrawerAndViewBgContext(
   246 		CAknsBasicBackgroundControlContext * aBgContext )
   246     CAknsBasicBackgroundControlContext * aBgContext )
   247 	{
   247   {
   248 	iGrid->SetItemDrawerAndViewBgContext (aBgContext);
   248   iGrid->SetItemDrawerAndViewBgContext (aBgContext);
   249 	}
   249   }
   250 
   250 
   251 // -----------------------------------------------------------------------------
   251 // -----------------------------------------------------------------------------
   252 //
   252 //
   253 //
   253 //
   254 // -----------------------------------------------------------------------------
   254 // -----------------------------------------------------------------------------
   255 //
   255 //
   256 void CMmGridContainer::SetupWidgetLayoutL()
   256 void CMmGridContainer::SetupWidgetLayoutL()
   257 	{
   257   {
   258 	User::LeaveIfNull( iGrid );
   258   User::LeaveIfNull( iGrid );
   259 	iGrid->SetupLayout();
   259   iGrid->SetupLayout();
   260 	}
   260   }
   261 
   261 
   262 // -----------------------------------------------------------------------------
   262 // -----------------------------------------------------------------------------
   263 //
   263 //
   264 // -----------------------------------------------------------------------------
   264 // -----------------------------------------------------------------------------
   265 //
   265 //
   284 // ---------------------------------------------------------------------------
   284 // ---------------------------------------------------------------------------
   285 //
   285 //
   286 // ---------------------------------------------------------------------------
   286 // ---------------------------------------------------------------------------
   287 //
   287 //
   288 void CMmGridContainer::HandleItemAdditionL()
   288 void CMmGridContainer::HandleItemAdditionL()
   289 	{
   289   {
   290 	iGrid->HandleItemAdditionL();
   290   iGrid->HandleItemAdditionL();
   291 	}
   291   }
   292 
   292 
   293 
   293 
   294 // ---------------------------------------------------------------------------
   294 // ---------------------------------------------------------------------------
   295 //
   295 //
   296 // ---------------------------------------------------------------------------
   296 // ---------------------------------------------------------------------------
   297 //
   297 //
   298 void CMmGridContainer::HandleItemRemovalL()
   298 void CMmGridContainer::HandleItemRemovalL()
   299 	{
   299   {
   300 
   300 
   301 	GetMmModel()->HandleSuiteEventL( ESuiteItemsRemoved, GetMmModel()->GetSuiteModel() );
   301   GetMmModel()->HandleSuiteEventL( ESuiteItemsRemoved, GetMmModel()->GetSuiteModel() );
   302 	ValidateWidgetCurrentItemIndex();
   302   ValidateWidgetCurrentItemIndex();
   303 	iDrawer->RemoveFloatingItems();
   303   iDrawer->RemoveFloatingItems();
   304 	if( IsEditMode() )
   304   if( IsEditMode() )
   305 		{
   305     {
   306 		iDrawer->GetAnimator()->SetNextRedrawToWholeScreen();
   306     iDrawer->GetAnimator()->SetNextRedrawToWholeScreen();
   307 		}
   307     }
   308 
   308 
   309 	CacheWidgetPosition();
   309   CacheWidgetPosition();
   310 	iGrid->HandleItemRemovalL();
   310   iGrid->View()->SetDisableRedraw( ETrue ); //prevention scroll view
   311 	RestoreWidgetPosition();
   311   iGrid->HandleItemRemovalL();
   312 	CacheWidgetPosition();
   312   iGrid->View()->SetDisableRedraw( EFalse );
   313 
   313   RestoreWidgetPosition();
   314 	if ( iCurrentHighlight != iGrid->CurrentItemIndex() )
   314   CacheWidgetPosition();
   315 		{
   315 
   316 		iCurrentHighlight = iGrid->CurrentItemIndex();
   316   if ( iCurrentHighlight != iGrid->CurrentItemIndex() )
   317 		if( !iCurrentHighlight && !iGrid->Model()->NumberOfItems() )
   317     {
   318 			{
   318     iCurrentHighlight = iGrid->CurrentItemIndex();
   319 			iCurrentHighlight = KErrNotFound ;
   319     if( !iCurrentHighlight && !iGrid->Model()->NumberOfItems() )
   320 			}
   320       {
   321 		CHnSuiteModel* suiteModel = GetSuiteModelL();
   321       iCurrentHighlight = KErrNotFound ;
   322 		if ( suiteModel )
   322       }
   323 		    {
   323     CHnSuiteModel* suiteModel = GetSuiteModelL();
   324 		    suiteModel->SetSuiteHighlightL( iCurrentHighlight );
   324     if ( suiteModel )
   325 		    }
   325         {
   326 		}
   326         suiteModel->SetSuiteHighlightL( iCurrentHighlight );
   327 	static_cast<CMmListBoxItemDrawer*>( iGrid->ItemDrawer() )->TrimCacheSize(
   327         }
       
   328     }
       
   329   static_cast<CMmListBoxItemDrawer*>( iGrid->ItemDrawer() )->TrimCacheSize(
   328             GetMmModel()->NumberOfItems() );
   330             GetMmModel()->NumberOfItems() );
   329 	}
   331   }
   330 
   332 
   331 // ---------------------------------------------------------------------------
   333 // ---------------------------------------------------------------------------
   332 //
   334 //
   333 // ---------------------------------------------------------------------------
   335 // ---------------------------------------------------------------------------
   334 //
   336 //
   335 TInt CMmGridContainer::ColumnsInCurrentView()
   337 TInt CMmGridContainer::ColumnsInCurrentView()
   336 	{
   338   {
   337 	CAknGridView* view ( (CAknGridView*) iGrid->View() );
   339   CAknGridView* view ( (CAknGridView*) iGrid->View() );
   338 	return view->NumberOfColsInView();
   340   return view->NumberOfColsInView();
   339 	}
   341   }
   340 // ---------------------------------------------------------------------------
   342 // ---------------------------------------------------------------------------
   341 //
   343 //
   342 // ---------------------------------------------------------------------------
   344 // ---------------------------------------------------------------------------
   343 //
   345 //
   344 TInt CMmGridContainer::RowsInCurrentView()
   346 TInt CMmGridContainer::RowsInCurrentView()
   359 // -----------------------------------------------------------------------------
   361 // -----------------------------------------------------------------------------
   360 //
   362 //
   361 // -----------------------------------------------------------------------------
   363 // -----------------------------------------------------------------------------
   362 //
   364 //
   363 void CMmGridContainer::SetVerticalItemOffset( TInt aOffset )
   365 void CMmGridContainer::SetVerticalItemOffset( TInt aOffset )
   364 	{
   366   {
   365 	iGrid->SetVerticalItemOffset( aOffset );
   367   iGrid->SetVerticalItemOffset( aOffset );
   366 	}
   368   }
   367 
   369 
   368 // -----------------------------------------------------------------------------
   370 // -----------------------------------------------------------------------------
   369 //
   371 //
   370 // -----------------------------------------------------------------------------
   372 // -----------------------------------------------------------------------------
   371 //
   373 //
   372 TInt CMmGridContainer::VerticalItemOffset() const
   374 TInt CMmGridContainer::VerticalItemOffset() const
   373 	{
   375   {
   374 	return iGrid->VerticalItemOffset();
   376   return iGrid->VerticalItemOffset();
   375 	}
   377   }
   376 
   378 
   377 //----------------------------------------------------------------------------
   379 //----------------------------------------------------------------------------
   378 //
   380 //
   379 // ---------------------------------------------------------------------------
   381 // ---------------------------------------------------------------------------
   380 //
   382 //
   381 void CMmGridContainer::UpdateViewScrollBarThumbs()
   383 void CMmGridContainer::UpdateViewScrollBarThumbs()
   382 	{
   384   {
   383 	iGrid->UpdateScrollBarThumbs();
   385   iGrid->UpdateScrollBarThumbs();
   384 	}
   386   }
   385 
   387 
   386 // -----------------------------------------------------------------------------
   388 // -----------------------------------------------------------------------------
   387 //
   389 //
   388 // -----------------------------------------------------------------------------
   390 // -----------------------------------------------------------------------------
   389 //
   391 //