locationcentre/lcapp/src/lccontainer.cpp
changeset 0 522cd55cc3d7
child 9 91123d004e8f
equal deleted inserted replaced
-1:000000000000 0:522cd55cc3d7
       
     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:  Container class for Location Centre Application UI.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDES
       
    20 #include <avkon.hrh>
       
    21 #include <barsread.h> 
       
    22 #include <lclocationappinfo.h>
       
    23 #include <aknlists.h>
       
    24 #include <akniconarray.h>		// Icon Array
       
    25 #include <eikclbd.h>			// Column Listbox
       
    26 #include <gulicon.h>			// Gul Icon
       
    27 #include <barsread.h>   		// TResourceReader
       
    28 #include <lcapp.rsg>
       
    29 #include <csxhelp/loccentre.hlp.hrh>
       
    30 #include <aknutils.h>
       
    31 #include <eikspane.h> 		    // Status pane
       
    32 #include <akntitle.h>       	// CAknTitlePane
       
    33 #include <stringloader.h>
       
    34 
       
    35 // USER INCLUDES
       
    36 #include "lccontainer.h"
       
    37 #include "lcappui.h"
       
    38 #include "lclistboxmodel.h"
       
    39 #include "lcappuid.hrh"
       
    40 #include "lcapp.hrh"
       
    41 
       
    42 // CONSTANT DEFINITIONS
       
    43 const TInt KLcNoOfElements = 1;
       
    44 const TInt KMinSelectedItemNumber = 0;
       
    45 const TInt KViewListboxGranularity = 3; // The number of default Applications
       
    46  
       
    47 // ----------------- Member funtions for CLcContainer class ------------------
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CLcContainer::CLcContainer
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CLcContainer::CLcContainer( MLcEventHandler&	aEventHandler,
       
    54 							CLcListBoxModel&	aListBoxModel )
       
    55 	:iEventHandler( aEventHandler ),
       
    56 	iListBoxModel( &aListBoxModel )
       
    57     {
       
    58     }
       
    59 
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CLcContainer::~CLcContainer
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CLcContainer::~CLcContainer()
       
    66     {
       
    67     // Delete the List box
       
    68 	delete iListBox;
       
    69     }
       
    70     
       
    71 // ---------------------------------------------------------------------------
       
    72 // CLcContainer::NewL
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 CLcContainer* CLcContainer::NewL( const TRect&				aRect,
       
    76 										 MLcEventHandler&	aEventHandler,
       
    77 										 CLcListBoxModel&	aListBoxModel )     
       
    78     {
       
    79     CLcContainer* self = new (ELeave) CLcContainer( aEventHandler, aListBoxModel );
       
    80     CleanupStack::PushL( self );
       
    81     self->ConstructL( aRect );
       
    82     CleanupStack::Pop();
       
    83     
       
    84     return self;
       
    85     }
       
    86     
       
    87 // ---------------------------------------------------------------------------
       
    88 // CLcContainer::CLcContainer
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CLcContainer::ConstructL( const TRect& 	aRect )
       
    92     {
       
    93     // This is the cheif control for this application. This has to be made a 
       
    94     // Window owning control
       
    95     CreateWindowL();
       
    96     
       
    97 	// Create a New Title for the View
       
    98 	MakeTitleL( R_LOC_TITLE_CENTRE );
       
    99 	    
       
   100     // Create the List box
       
   101     CreateListboxL();
       
   102       
       
   103     // Get the Help context
       
   104     iContextName = KLOC_HLP_LOC_CENTRE();
       
   105             
       
   106     SetRect(aRect);
       
   107     ActivateL();
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // void CLcContainer::GetHelpContext
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void CLcContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   115 	{
       
   116     aContext.iContext = iContextName;
       
   117     aContext.iMajor = TUid::Uid( KLcAppUid );	
       
   118 	}
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // TInt CLcContainer::GetFocussedItem
       
   122 // ---------------------------------------------------------------------------
       
   123 //	
       
   124 TInt CLcContainer::GetFocussedItem()
       
   125 	{
       
   126 	// No need to check for the List box.
       
   127     return iListBox->CurrentItemIndex();
       
   128 	}
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // void CLcContainer::UpdateL
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 void CLcContainer::UpdateL( CLcListBoxModel&	aListBoxModel )
       
   135 	{
       
   136 	TBool itemRemoved = EFalse;
       
   137 	
       
   138 	if ( aListBoxModel.MdcaCount() < iListBoxModel->MdcaCount() )
       
   139 	    {
       
   140 	    itemRemoved = ETrue;
       
   141 	    }
       
   142 	                              
       
   143 	// Assign the latest list box model
       
   144 	iListBoxModel = &aListBoxModel;
       
   145 	
       
   146 	// If there is a list box update it.
       
   147 	if ( iListBox )
       
   148 		{
       
   149 		// First we have to update the Icons Array
       
   150 		UpdateIconsL();
       
   151 		
       
   152 		if ( itemRemoved )
       
   153 		    {
       
   154 		    iListBox->HandleItemRemovalL();
       
   155 		    }
       
   156         else
       
   157             {
       
   158             iListBox->HandleItemAdditionL();
       
   159             }		    
       
   160 		
       
   161 		// Set the last element as the Selected element if the element has been
       
   162 		// removed.
       
   163 	    TInt currentItem = iListBox->CurrentItemIndex();   
       
   164 	    MDesCArray* array = iListBox->Model()->ItemTextArray();
       
   165 	    if( KErrNotFound == currentItem || currentItem >= array->MdcaCount() )
       
   166 	        {
       
   167 	        TInt newSelected = array->MdcaCount() - 1;
       
   168 	        if( newSelected >= KMinSelectedItemNumber )
       
   169 	            {
       
   170 	            iListBox->SetCurrentItemIndex( newSelected );
       
   171 	            }
       
   172 	        }		
       
   173 		}
       
   174 		
       
   175 	// Update the List box.
       
   176 	DrawDeferred();
       
   177 	}
       
   178 
       
   179 // ---------------------------------------------------------------------------
       
   180 // void CLcContainer::UpdateIconsL
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 void CLcContainer::UpdateIconsL()
       
   184 	{
       
   185 	// Update the Icons only if there are any elements the List box
       
   186 	if ( iListBoxModel->MdcaCount())
       
   187 		{
       
   188 		// Create a new Icons Array
       
   189 	    CAknIconArray* icons = new( ELeave ) CAknIconArray( KViewListboxGranularity );
       
   190 	    CleanupStack::PushL( icons );
       
   191 
       
   192 		CLcLocationAppInfoArray& appArray( iListBoxModel->AppArray());
       
   193 		TInt count = appArray.Count();
       
   194 		// Add All the icons to the Icons array
       
   195 		for ( TInt i = 0; i < count; i++ )
       
   196 			{			
       
   197 			icons->AppendL( appArray[i].IconL() );
       
   198 			}
       
   199 
       
   200 	    // Get old icons and delete those. This is done because SetIconArray will
       
   201 	    // not do it.
       
   202 	    CAknIconArray* oldIcons = 
       
   203 	    	static_cast<CAknIconArray*>( iListBox->ItemDrawer()->ColumnData()->IconArray());
       
   204 	    	    
       
   205 	    delete oldIcons;
       
   206 
       
   207 	    //Set New Icons to array
       
   208 	    iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons );  
       
   209 	    CleanupStack::Pop(icons);		
       
   210 		}				
       
   211 	}
       
   212 		
       
   213 // ---------------------------------------------------------------------------
       
   214 // void CLcContainer::SizeChanged
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 void CLcContainer::SizeChanged()
       
   218     {
       
   219     if ( iListBox )
       
   220     	{
       
   221     	iListBox->SetRect( Rect());
       
   222     	}
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // TInt CLcContainer::CountComponentControls
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 TInt CLcContainer::CountComponentControls() const
       
   230     {
       
   231    	return KLcNoOfElements;
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // CCoeControl* CLcContainer::CLcContainer
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 CCoeControl* CLcContainer::ComponentControl(TInt /* aIndex*/ ) const
       
   239     {
       
   240     return iListBox;
       
   241     }
       
   242     
       
   243 // ---------------------------------------------------------------------------
       
   244 // TKeyResponse CLcContainer::OfferKeyEventL
       
   245 // ---------------------------------------------------------------------------
       
   246 //    
       
   247 TKeyResponse CLcContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   248 								  				 TEventCode aType )
       
   249     {
       
   250     switch ( aKeyEvent.iCode )
       
   251         {
       
   252         case EKeyLeftArrow:
       
   253         case EKeyRightArrow:
       
   254             {
       
   255             // No action in this application for the Right arrow and left
       
   256             // arrow.
       
   257             return EKeyWasNotConsumed;  
       
   258             }
       
   259         default:
       
   260             {
       
   261             break;  
       
   262             }
       
   263         }
       
   264     // Now it's List box's job to process the key event
       
   265     return iListBox->OfferKeyEventL( aKeyEvent, aType ); 
       
   266     }   
       
   267 
       
   268 // ---------------------------------------------------------------------------
       
   269 // void CLcContainer::HandleResourceChange
       
   270 // ---------------------------------------------------------------------------
       
   271 //
       
   272 void CLcContainer::HandleResourceChange( TInt aType )
       
   273 	{
       
   274     // Pass the event to the base class
       
   275     CCoeControl::HandleResourceChange( aType );
       
   276     
       
   277     switch( aType )
       
   278         {
       
   279         // Dynamic Layout switch and Skin Change
       
   280         case KEikDynamicLayoutVariantSwitch:
       
   281         case KAknsMessageSkinChange:
       
   282             {
       
   283             // The Command Handler needs to handle this event. TRAP_IGNORE
       
   284             // the error incase it occurs
       
   285             TRAP_IGNORE( iEventHandler.HandleEventL( aType ));
       
   286             break;
       
   287             }
       
   288         default:
       
   289             {
       
   290             break;
       
   291             }
       
   292         }	
       
   293 	}
       
   294 
       
   295 // ---------------------------------------------------------------------------
       
   296 // void CLcContainer::HandleListBoxEventL
       
   297 // ---------------------------------------------------------------------------
       
   298 //	
       
   299 void CLcContainer::HandleListBoxEventL( CEikListBox*      /* aListBox */, 
       
   300                           				TListBoxEvent     aEventType )
       
   301 	{
       
   302     switch (aEventType)
       
   303         {
       
   304         // List box Item Selection
       
   305         case EEventEnterKeyPressed:
       
   306         case EEventItemSingleClicked:
       
   307             {
       
   308             // A Location based Application or Content/Service has been
       
   309             // selected. This element has to be returned back to the Command
       
   310             // Hanlder inorder to enable it to take appropriate action.
       
   311             iEventHandler.HandleEventL( ELcOpen );
       
   312             break;  
       
   313             }
       
   314         default:
       
   315            break;
       
   316         }	
       
   317 	}
       
   318 
       
   319 // ---------------------------------------------------------------------------
       
   320 // void CLcContainer::FocusChanged
       
   321 // ---------------------------------------------------------------------------
       
   322 //	                     
       
   323 void CLcContainer::FocusChanged( TDrawNow aDrawNow )
       
   324 	{
       
   325     CCoeControl::FocusChanged( aDrawNow );
       
   326     
       
   327     // The focus event has to be explicitly handed over to all the compound
       
   328     // controls since CCoeControl does not do that implicitly
       
   329     iListBox->SetFocus( IsFocused(), aDrawNow );	
       
   330 	}
       
   331 
       
   332 // ---------------------------------------------------------------------------
       
   333 // void CLcContainer::MakeTitleL
       
   334 // Sets the Title text
       
   335 //
       
   336 // @param aResourceText Resource to create title
       
   337 // ---------------------------------------------------------------------------
       
   338 //
       
   339 void CLcContainer::MakeTitleL( TInt aResourceText )
       
   340 	{
       
   341 	CEikStatusPane* statusPane = 
       
   342 	    static_cast<CEikStatusPane*>( iEikonEnv->AppUiFactory()->StatusPane());
       
   343 	// Obtain the title from the Status Pane
       
   344 	CAknTitlePane* title = static_cast<CAknTitlePane*>( statusPane->
       
   345         ControlL( TUid::Uid( EEikStatusPaneUidTitle )));
       
   346        
       
   347     // Set the Title's buffer    
       
   348     HBufC* buf = StringLoader::LoadL( aResourceText );
       
   349     title->SetText( buf ); // Takes ownership of buf
       
   350 	}
       
   351 		
       
   352 // ---------------------------------------------------------------------------
       
   353 // void CLcContainer::CreateListboxL
       
   354 // ---------------------------------------------------------------------------
       
   355 // 	
       
   356 void CLcContainer::CreateListboxL()
       
   357     {
       
   358     // Create the List box
       
   359     iListBox = new ( ELeave ) CAknSingleLargeStyleListBox;
       
   360     iListBox->ConstructL( this, EAknListBoxSelectionList );
       
   361     iListBox->SetContainerWindowL( *this ); 
       
   362     iListBox->SetListBoxObserver( this );
       
   363     iListBox->CreateScrollBarFrameL(ETrue);
       
   364     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
       
   365                                                          CEikScrollBarFrame::EAuto ); 
       
   366      
       
   367     UpdateIconsL();
       
   368                                                                                                                       
       
   369     // The ownership of the List box model is retained with the Container.
       
   370     // This is needed because the model is used to return the identifier of the
       
   371     // Location based Application or Content/Service when its selected.                                                     
       
   372     iListBox->Model()->SetItemTextArray( iListBoxModel );  
       
   373     iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   374     iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
       
   375                                      
       
   376     iListBox->ActivateL();
       
   377     }
       
   378     
       
   379 // End of File