menufw/menufwui/mmwidgets/src/mmlistboxcontainer.cpp
changeset 0 f72a12da539e
child 4 4d54b72983ae
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   
       
    15 *  Version     : %version: MM_64 % << Don't touch! Updated by Synergy at check-out.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <aknlists.h> 
       
    21 #include <barsread.h> 
       
    22 
       
    23 #include <eikclb.h> 
       
    24 #include <StringLoader.h>
       
    25 #include <AknsLayeredBackgroundControlContext.h>
       
    26 #include <AknsListBoxBackgroundControlContext.h>
       
    27 
       
    28 #include "mmlistbox.h"
       
    29 #include "mmlistboxmodel.h"
       
    30 #include "mmmarqueeadapter.h"
       
    31 #include "hnsuitemodel.h"
       
    32 #include "mmlistboxcontainer.h"
       
    33 #include "mmlistboxitemdrawer.h"
       
    34 #include "mmwidgetsconstants.h"
       
    35 #include "mmtemplatelibrary.h"
       
    36 #include "mmpostevaluationprocessor.h"
       
    37 #include "mmdraweranimator.h"
       
    38 #include "mmhighlighttimer.h"
       
    39 
       
    40 // ============================ MEMBER FUNCTIONS ===============================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CListboxNumberContainer::CListboxNumberContainer()
       
    44 // C++ default constructor
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CMmListBoxContainer* CMmListBoxContainer::NewLC( const TRect& aRect, 
       
    48         MObjectProvider* aObjectProvider, CMmTemplateLibrary* aTemplateLibrary )
       
    49     {        
       
    50     CMmListBoxContainer* self = new( ELeave ) CMmListBoxContainer();
       
    51     CleanupStack::PushL( self );	
       
    52     self->ConstructL( aRect, aObjectProvider, aTemplateLibrary );
       
    53     return self;
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CListboxNumberContainer::CListboxNumberContainer()
       
    58 // C++ default constructor
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CMmListBoxContainer* CMmListBoxContainer::NewL( const TRect& aRect, 
       
    62         MObjectProvider* aObjectProvider, CMmTemplateLibrary* aTemplateLibrary )
       
    63     {        
       
    64     CMmListBoxContainer* self = NewLC( aRect, aObjectProvider, aTemplateLibrary );
       
    65     CleanupStack::Pop( self );
       
    66     return self;
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CListboxNumberContainer::CListboxNumberContainer()
       
    71 // C++ default constructor
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CMmListBoxContainer::CMmListBoxContainer()
       
    75     {       
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CListboxNumberContainer::~CListboxNumberContainer()
       
    80 // Destructor
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CMmListBoxContainer::~CMmListBoxContainer()
       
    84     {  
       
    85     delete iListBox;
       
    86     delete iMarqueeAdapter;
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CMmListBoxContainer::ConstructL()
       
    91 // 2nd phase constructor
       
    92 // -----------------------------------------------------------------------------
       
    93 //    
       
    94 void CMmListBoxContainer::ConstructL( const TRect& aRect, 
       
    95         MObjectProvider* aObjectProvider, CMmTemplateLibrary* aTemplateLibrary )
       
    96     {
       
    97     CMmWidgetContainer::ConstructL();
       
    98     
       
    99     SetMopParent( aObjectProvider );
       
   100     CreateWindowL(); // Creates window.
       
   101     iWidget = CreateListboxL( aTemplateLibrary );
       
   102     iWidget->SetListBoxObserver( this );
       
   103     SetRect( aRect ); // Sets rectangle of frame.
       
   104     ActivateL(); // Activates window. ( Ready to draw )       
       
   105     SetupDrawer();
       
   106 //    SetHighlightVisibilityL( ETrue );
       
   107     iMarqueeAdapter = CMmMarqueeAdapter::NewL();
       
   108     iDrawer->SetMarqueeAdapter( iMarqueeAdapter );
       
   109     iListBox->SetMarqueeAdapter( iMarqueeAdapter );
       
   110     iPostProcessor = CMmPostEvaluationProcessor::NewL( *iDrawer );
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // 
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CMmListBoxContainer::DrawView()
       
   118     {
       
   119     iListBox->DrawView();
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CMmListBoxContainer::CreateListboxL()
       
   124 // Constructs listbox from resource, creates scroll bar and sets empty
       
   125 // list background text. 
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 CMmListBox* CMmListBoxContainer::CreateListboxL( 
       
   129     CMmTemplateLibrary* aTemplateLibrary  )
       
   130     {
       
   131     iListBox = CMmListBox::NewL( this, EAknListBoxSelectionList 
       
   132     		| EAknListBoxLoopScrolling, aTemplateLibrary );
       
   133     iListBox->SetContainerWindowL( *this );
       
   134     iListBox->CreateScrollBarFrameL( ETrue );
       
   135     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( 
       
   136     		CEikScrollBarFrame::EAuto, CEikScrollBarFrame::EAuto );  
       
   137     iListBox->ScrollBarFrame()->DrawBackground( EFalse, EFalse );
       
   138     return iListBox;
       
   139     }
       
   140  
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 THnSuiteWidgetType CMmListBoxContainer::WidgetType()
       
   146 	{
       
   147 	return EListWidget;
       
   148 	}
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 EXPORT_C void CMmListBoxContainer::SetDefaultHighlightL(  TBool aRedraw )
       
   155     {  
       
   156     TInt defaultHighlight = Widget()->TopItemIndex();
       
   157     if ( !ItemIsFullyVisible( defaultHighlight ) 
       
   158     		&& defaultHighlight < NumberOfItems() - 1 )
       
   159     	{
       
   160     	defaultHighlight++;
       
   161     	}
       
   162     	
       
   163     if (defaultHighlight >= 0 )
       
   164     	{
       
   165     	SetManualHighlightL( defaultHighlight, aRedraw );
       
   166     	}
       
   167     }
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 //
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 EXPORT_C void CMmListBoxContainer::SetEmptyTextL(const TDesC& aText)
       
   174     {
       
   175     iListBox->View()->SetListEmptyTextL( aText );  
       
   176     }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 void CMmListBoxContainer::SetEditModeL( TBool aIsEditMode )
       
   183     {
       
   184 	if (aIsEditMode && !AknLayoutUtils::PenEnabled() )
       
   185 		{
       
   186 		iListBox->ClearListFlag( EAknListBoxLoopScrolling );
       
   187         }
       
   188     else
       
   189     	{
       
   190 		iListBox->SetListFlag( EAknListBoxLoopScrolling ); 
       
   191     	}
       
   192     CMmWidgetContainer::SetEditModeL( aIsEditMode );
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 // -----------------------------------------------------------------------------
       
   198 // 
       
   199 CMmListBoxModel* CMmListBoxContainer::GetMmModel()
       
   200     {
       
   201     return iListBox->MmModel();
       
   202     }
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 // -----------------------------------------------------------------------------
       
   207 // 
       
   208 void CMmListBoxContainer::SetupWidgetLayoutL()
       
   209     {
       
   210     }
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 void CMmListBoxContainer::SetItemDrawerAndViewBgContext(
       
   217 		CAknsBasicBackgroundControlContext * aBgContext )
       
   218 	{
       
   219 	iListBox->SetItemDrawerAndViewBgContext (aBgContext);
       
   220 	}
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 void CMmListBoxContainer::SetSuiteModelL( CHnSuiteModel* aModel )
       
   227     {
       
   228     CMmWidgetContainer::SetSuiteModelL( aModel );
       
   229     // highlight always active
       
   230     aModel->SetActiveL( ETrue );
       
   231 	iMarqueeAdapter->StopMarqueeDrawing();
       
   232     }
       
   233 
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 void CMmListBoxContainer::SetHighlightVisibilityL( TBool aVisible )
       
   239     {
       
   240         CMmWidgetContainer::SetHighlightVisibilityL( aVisible );
       
   241     }
       
   242 
       
   243 // ---------------------------------------------------------------------------
       
   244 // 
       
   245 // ---------------------------------------------------------------------------
       
   246 //
       
   247 TBool CMmListBoxContainer::PointInItemReorderAreaL(
       
   248             TInt aItemIndex, TPoint aPoint )
       
   249     {
       
   250     TRect itemRect = GetItemRectL( aItemIndex );
       
   251     itemRect.Shrink( 0, MmEffects::KShiftRatio * itemRect.Height() );
       
   252     return itemRect.Contains( aPoint );
       
   253     }
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 // 
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 void CMmListBoxContainer::HandleItemAdditionL()
       
   260 	{
       
   261 	iListBox->HandleItemAdditionL();
       
   262 	}
       
   263 
       
   264 
       
   265 // ---------------------------------------------------------------------------
       
   266 // 
       
   267 // ---------------------------------------------------------------------------
       
   268 //
       
   269 void CMmListBoxContainer::HandleItemRemovalL()
       
   270 	{
       
   271 	GetMmModel()->HandleSuiteEventL( ESuiteItemsRemoved, GetMmModel()->GetSuiteModel() );
       
   272 	iCurrentHighlight = GetSuiteModelL()->GetSuiteHighlight();
       
   273 	ValidateWidgetCurrentItemIndex();
       
   274 	
       
   275 	iDrawer->RemoveFloatingItems();
       
   276 	if( IsEditMode() )
       
   277 		{
       
   278 		iDrawer->GetAnimator()->SetNextRedrawToWholeScreen();
       
   279 		}
       
   280 	
       
   281 	iListBox->HandleItemRemovalL();
       
   282     
       
   283     CHnSuiteModel* suiteModel = GetSuiteModelL();
       
   284 	suiteModel->SetSuiteHighlightL( iCurrentHighlight );
       
   285 	static_cast<CMmListBoxItemDrawer*>( iListBox->ItemDrawer() )->TrimCacheSize(
       
   286 	        GetMmModel()->NumberOfItems() );
       
   287 	}
       
   288 	
       
   289 // ---------------------------------------------------------------------------
       
   290 // 
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 TInt CMmListBoxContainer::ColumnsInCurrentView()
       
   294 	{
       
   295 	return 1;
       
   296 	}
       
   297 // ---------------------------------------------------------------------------
       
   298 // 
       
   299 // ---------------------------------------------------------------------------
       
   300 //
       
   301 TInt CMmListBoxContainer::RowsInCurrentView()
       
   302     {
       
   303     return iListBox->View()->NumberOfItemsThatFitInRect(
       
   304             iListBox->View()->ViewRect());
       
   305     }
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 // -----------------------------------------------------------------------------
       
   309 //
       
   310 void CMmListBoxContainer::SetVerticalItemOffset( TInt aOffset )
       
   311 	{
       
   312 	iListBox->SetVerticalItemOffset( aOffset );
       
   313 	}
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 //
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 TInt CMmListBoxContainer::VerticalItemOffset() const
       
   320 	{
       
   321 	return iListBox->VerticalItemOffset();
       
   322 	}
       
   323 
       
   324 //----------------------------------------------------------------------------
       
   325 //
       
   326 // ---------------------------------------------------------------------------
       
   327 //
       
   328 void CMmListBoxContainer::UpdateViewScrollBarThumbs()
       
   329 	{
       
   330 	iListBox->UpdateScrollBarThumbs();
       
   331 	}
       
   332 // End of File