menufw/menufwui/mmwidgets/src/mmgridcontainer.cpp
branchRCL_3
changeset 34 5456b4e8b3a8
child 35 3321d3e205b6
equal deleted inserted replaced
33:5f0182e07bfb 34:5456b4e8b3a8
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *  Version     : %version: MM_76 % << Don't touch! Updated by Synergy at check-out.
       
    16 *  Version     : %version: MM_76 % << Don't touch! Updated by Synergy at check-out.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #include "mmgridcontainer.h"
       
    22 #include "mmgridmodel.h"
       
    23 #include "mmlistboxmodel.h"
       
    24 #include "mmmarqueeadapter.h"
       
    25 #include <AknsLayeredBackgroundControlContext.h>
       
    26 #include <AknsListBoxBackgroundControlContext.h>
       
    27 #include <layoutmetadata.cdl.h>
       
    28 #include "hnsuitemodel.h"
       
    29 #include "mmgrid.h"
       
    30 #include "mmwidgetsconstants.h"
       
    31 #include "hnglobals.h"
       
    32 #include "mmpostevaluationprocessor.h"
       
    33 #include "mmlistboxitemdrawer.h"
       
    34 #include "mmdraweranimator.h"
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CMmGridContainer::NewLC()
       
    38 // Two-phased constructor.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CMmGridContainer* CMmGridContainer::NewLC( const TRect& aRect,
       
    42         MObjectProvider* aObjectProvider, CMmTemplateLibrary* aLibrary )
       
    43     {
       
    44     CMmGridContainer* self = new( ELeave ) CMmGridContainer();
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL( aRect, aObjectProvider, aLibrary );
       
    47     return self;
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CMmGridContainer::NewL()
       
    52 // Two-phased constructor.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CMmGridContainer* CMmGridContainer::NewL( const TRect& aRect,
       
    56         MObjectProvider* aObjectProvider, CMmTemplateLibrary* aLibrary )
       
    57     {
       
    58     CMmGridContainer* self = NewLC( aRect, aObjectProvider, aLibrary);
       
    59     CleanupStack::Pop( self );
       
    60     return self;
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CMmGridContainer::CMmGridContainer()
       
    65 // C++ default constructor
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CMmGridContainer::CMmGridContainer()
       
    69     {
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CAknGrid* CMmGridContainer::Grid()
       
    77     {
       
    78     return iGrid;
       
    79     }
       
    80 // -----------------------------------------------------------------------------
       
    81 // CMmGridContainer::~CMmGridContainer()
       
    82 // Destructor
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 CMmGridContainer::~CMmGridContainer()
       
    86     {
       
    87     delete iGrid;
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 THnSuiteWidgetType CMmGridContainer::WidgetType()
       
    95   {
       
    96   return EGridWidget;
       
    97   }
       
    98 // -----------------------------------------------------------------------------
       
    99 // CMmGridContainer::ConstructL()
       
   100 // 2nd phase constructor
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CMmGridContainer::ConstructL( const TRect& aRect, MObjectProvider* aObjectProvider,
       
   104         CMmTemplateLibrary* aTemplateLibrary )
       
   105     {
       
   106     CMmWidgetContainer::ConstructL();
       
   107 
       
   108     SetMopParent( aObjectProvider );
       
   109     CreateWindowL(); // Creates window.
       
   110     iWidget = CreateGridL(aTemplateLibrary);
       
   111     iWidget->SetListBoxObserver( this );
       
   112     SetRect( aRect ); // Sets rectangle of frame.
       
   113     ActivateL(); // Activates window. ( Ready to draw )
       
   114     SetupDrawer();
       
   115     SetHighlightVisibilityL( !AknLayoutUtils::PenEnabled() );
       
   116     iPostProcessor = CMmPostEvaluationProcessor::NewL( *iDrawer );
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CMmGridContainer::CreateGridL()
       
   121 // Constructs listbox from resource, creates scroll bar and sets empty
       
   122 // list background text.
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 CMmGrid* CMmGridContainer::CreateGridL( CMmTemplateLibrary* aTemplateLibrary )
       
   126     {
       
   127     iGrid = CMmGrid::NewL( this,
       
   128         EAknListBoxSelectionList | EAknListBoxLoopScrolling | EAknListBoxDisableHighlight , aTemplateLibrary );
       
   129     iGrid->SetContainerWindowL( *this );
       
   130     iGrid->CreateScrollBarFrameL( ETrue );
       
   131     iGrid->SetPrimaryScrollingType(
       
   132           CAknGridView::EScrollFollowsItemsAndLoops );
       
   133     iGrid->SetSecondaryScrollingType(
       
   134           CAknGridView::EScrollFollowsGrid );
       
   135     iGrid->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   136         CEikScrollBarFrame::EAuto, CEikScrollBarFrame::EAuto );
       
   137     iGrid->ScrollBarFrame()->DrawBackground( EFalse, EFalse );
       
   138     return iGrid;
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 void CMmGridContainer::SizeChanged()
       
   146     {
       
   147     CMmWidgetContainer::SizeChanged();
       
   148     if ( iGrid )
       
   149       {
       
   150 //    	iGrid->SetRect( Rect() );
       
   151         iGrid->SetupLayout();
       
   152         }
       
   153     }
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 void CMmGridContainer::SetEditModeL( TBool aIsEditMode )
       
   159     {
       
   160   if (aIsEditMode && !AknLayoutUtils::PenEnabled() )
       
   161     {
       
   162     iGrid->SetPrimaryScrollingType(
       
   163         CAknGridView::EScrollStops );
       
   164     iGrid->SetSecondaryScrollingType(
       
   165         CAknGridView::EScrollStops );
       
   166         }
       
   167     else
       
   168       {
       
   169       iGrid->SetPrimaryScrollingType(
       
   170                 CAknGridView::EScrollFollowsItemsAndLoops );
       
   171       iGrid->SetSecondaryScrollingType(
       
   172                 CAknGridView::EScrollFollowsGrid );
       
   173 
       
   174       }
       
   175 
       
   176   // In EditMode we allow Avkon to redraw scrollbar background
       
   177   // to prevent scrollbar flicking.
       
   178   // When edit mode is disabled, this redrawing causes performance problems
       
   179   // (and disabling it does not produce erroneous side-effects).
       
   180   if( aIsEditMode )
       
   181     {
       
   182       iGrid->ScrollBarFrame()->DrawBackground( EFalse, ETrue );
       
   183     }
       
   184   else
       
   185     {
       
   186       iGrid->ScrollBarFrame()->DrawBackground( EFalse, EFalse );
       
   187     }
       
   188 
       
   189     CMmWidgetContainer::SetEditModeL( aIsEditMode );
       
   190     }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 EXPORT_C void CMmGridContainer::SetEmptyTextL(const TDesC& aText)
       
   197     {
       
   198     iGrid->SetEmptyGridTextL( aText );
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 EXPORT_C void CMmGridContainer::SetDefaultHighlightL(  TBool aRedraw )
       
   206     {
       
   207     TInt defaultHighlight( 0 );
       
   208     SetManualHighlightL( defaultHighlight + DefaultHighlightOffset(), aRedraw );
       
   209     }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 //
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 TInt CMmGridContainer::DefaultHighlightOffset()
       
   217   {
       
   218   TInt topVisibleItemIndex = iGrid->View()->TopItemIndex();
       
   219   TInt hiddenPixels = -iGrid->View()->ItemOffsetInPixels();
       
   220 
       
   221   if ( iGrid->View()->ItemIsPartiallyVisible( topVisibleItemIndex )
       
   222     && hiddenPixels > iGrid->View()->ItemSize().iHeight / 2 )
       
   223     {
       
   224     topVisibleItemIndex += ColumnsInCurrentView();
       
   225     }
       
   226 
       
   227   return topVisibleItemIndex;
       
   228   }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 //
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 CMmListBoxModel* CMmGridContainer::GetMmModel()
       
   236     {
       
   237     return iGrid->MmModel()->MmListBoxModel();
       
   238     }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 //
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 void CMmGridContainer::SetItemDrawerAndViewBgContext(
       
   246     CAknsBasicBackgroundControlContext * aBgContext )
       
   247   {
       
   248   iGrid->SetItemDrawerAndViewBgContext (aBgContext);
       
   249   }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 //
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 void CMmGridContainer::SetupWidgetLayoutL()
       
   257   {
       
   258   User::LeaveIfNull( iGrid );
       
   259   iGrid->SetupLayout();
       
   260   }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 void CMmGridContainer::SetSuiteModelL( CHnSuiteModel* aModel )
       
   267     {
       
   268     CMmWidgetContainer::SetSuiteModelL( aModel );
       
   269     }
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 //
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 void CMmGridContainer::SetHighlightVisibilityL( TBool aVisible )
       
   276     {
       
   277     CMmWidgetContainer::SetHighlightVisibilityL( aVisible );
       
   278     }
       
   279 
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 // ---------------------------------------------------------------------------
       
   283 //
       
   284 void CMmGridContainer::HandleItemAdditionL()
       
   285   {
       
   286   iGrid->HandleItemAdditionL();
       
   287   }
       
   288 
       
   289 
       
   290 // ---------------------------------------------------------------------------
       
   291 //
       
   292 // ---------------------------------------------------------------------------
       
   293 //
       
   294 void CMmGridContainer::HandleItemRemovalL()
       
   295   {
       
   296 
       
   297   GetMmModel()->HandleSuiteEventL( ESuiteItemsRemoved, GetMmModel()->GetSuiteModel() );
       
   298   ValidateWidgetCurrentItemIndex();
       
   299   iDrawer->RemoveFloatingItems();
       
   300   if( IsEditMode() )
       
   301     {
       
   302     iDrawer->GetAnimator()->SetNextRedrawToWholeScreen();
       
   303     }
       
   304 
       
   305   CacheWidgetPosition();
       
   306   iGrid->View()->SetDisableRedraw( ETrue ); //prevention scroll view
       
   307   iGrid->HandleItemRemovalL();
       
   308   iGrid->View()->SetDisableRedraw( EFalse );
       
   309   RestoreWidgetPosition();
       
   310   CacheWidgetPosition();
       
   311 
       
   312   if ( iCurrentHighlight != iGrid->CurrentItemIndex() )
       
   313     {
       
   314     iCurrentHighlight = iGrid->CurrentItemIndex();
       
   315     if( !iCurrentHighlight && !iGrid->Model()->NumberOfItems() )
       
   316       {
       
   317       iCurrentHighlight = KErrNotFound ;
       
   318       }
       
   319     CHnSuiteModel* suiteModel = GetSuiteModelL();
       
   320     if ( suiteModel )
       
   321         {
       
   322         suiteModel->SetSuiteHighlightL( iCurrentHighlight );
       
   323         }
       
   324     }
       
   325   static_cast<CMmListBoxItemDrawer*>( iGrid->ItemDrawer() )->TrimCacheSize(
       
   326             GetMmModel()->NumberOfItems() );
       
   327   }
       
   328 
       
   329 // ---------------------------------------------------------------------------
       
   330 //
       
   331 // ---------------------------------------------------------------------------
       
   332 //
       
   333 TInt CMmGridContainer::ColumnsInCurrentView()
       
   334   {
       
   335   CAknGridView* view ( (CAknGridView*) iGrid->View() );
       
   336   return view->NumberOfColsInView();
       
   337   }
       
   338 // ---------------------------------------------------------------------------
       
   339 //
       
   340 // ---------------------------------------------------------------------------
       
   341 //
       
   342 TInt CMmGridContainer::RowsInCurrentView()
       
   343     {
       
   344     CAknGridView* view ( (CAknGridView*) iGrid->View() );
       
   345     return view->NumberOfRowsInView();
       
   346     }
       
   347 
       
   348 // ---------------------------------------------------------------------------
       
   349 //
       
   350 // ---------------------------------------------------------------------------
       
   351 //
       
   352 void CMmGridContainer::DrawView()
       
   353     {
       
   354     iGrid->DrawView();
       
   355     }
       
   356 
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 // -----------------------------------------------------------------------------
       
   360 //
       
   361 void CMmGridContainer::SetVerticalItemOffset( TInt aOffset )
       
   362   {
       
   363   iGrid->SetVerticalItemOffset( aOffset );
       
   364   }
       
   365 
       
   366 // -----------------------------------------------------------------------------
       
   367 //
       
   368 // -----------------------------------------------------------------------------
       
   369 //
       
   370 TInt CMmGridContainer::VerticalItemOffset() const
       
   371   {
       
   372   return iGrid->VerticalItemOffset();
       
   373   }
       
   374 
       
   375 //----------------------------------------------------------------------------
       
   376 //
       
   377 // ---------------------------------------------------------------------------
       
   378 //
       
   379 void CMmGridContainer::UpdateViewScrollBarThumbs()
       
   380   {
       
   381   iGrid->UpdateScrollBarThumbs();
       
   382   }
       
   383 
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 // -----------------------------------------------------------------------------
       
   387 //
       
   388 TBool CMmGridContainer::ItemIsVisible( TInt aItemIndex ) const
       
   389     {
       
   390     CListBoxView* v = iGrid->View();
       
   391     TRect itemRect( v->ItemPos( aItemIndex ), v->ItemSize( aItemIndex ) );
       
   392     TRect viewRect = v->ViewRect();
       
   393     TBool isVisible = EFalse;
       
   394     if ( itemRect.Intersects( viewRect ) )
       
   395         {
       
   396         TRect intersection = itemRect;
       
   397         intersection.Intersection( viewRect );
       
   398         isVisible = intersection.Height() > 1 && intersection.Width() > 1;
       
   399         }
       
   400     return isVisible;
       
   401     }
       
   402 
       
   403 // End of File
       
   404