locationcentre/lcapp/src/lclistbox.cpp
branchRCL_3
changeset 9 4721bd00d3da
parent 8 3a25f69541ff
child 11 e15b7f06eba6
equal deleted inserted replaced
8:3a25f69541ff 9:4721bd00d3da
     1 /*
       
     2 * Copyright (c)  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:  List box defintion for Location System UI
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDES 
       
    20 #include <eikclbd.h>
       
    21 #include <gulicon.h>
       
    22 #include <AknIconArray.h>
       
    23 
       
    24 // USER INCLUDES
       
    25 #include "lclistbox.h"
       
    26 #include "lclistboxmodel.h"
       
    27 #include "lclocationappinfo.h"
       
    28 
       
    29 // CONSTANT DEFINTION
       
    30 const TInt KLcViewListboxGranularity = 2;
       
    31 
       
    32 
       
    33 // ========================= MEMBER FUNCTIONS ================================
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CLcListBox::CLcListBox
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CLcListBox::CLcListBox()
       
    40     {
       
    41     // C++ Default constructor. No allocations or functions which can Leave
       
    42     // should be called from here.
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CLcListBox::~CLcListBox
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CLcListBox::~CLcListBox()
       
    50     {
       
    51     // C++ Destructor. Free all resources associated with this class.
       
    52         
       
    53     // Delete the listbox model
       
    54     delete iListBoxModel;
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // void CLcListBox::ConstructL
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 void CLcListBox::ConstructL( 	   CLcLocationAppInfoArray*      aAppArray,
       
    62 							 const CCoeControl* 		   		 aParent,
       
    63 							 	   MEikListBoxObserver*			 aObserver )
       
    64     {
       
    65     // Create the List box model using the Application Info array
       
    66     iListBoxModel = CLcListBoxModel::NewL( aAppArray );    
       
    67     
       
    68     // Call the base class constructor
       
    69     CAknSingleLargeStyleListBox::ConstructL( aParent, EAknListBoxSelectionList );
       
    70     
       
    71     // If the parent window has been set, the set it as the Container window
       
    72     if ( aParent )
       
    73     	{
       
    74     	SetContainerWindowL( *aParent );
       
    75     	}
       
    76     // If the list box observer has been set then set ot to the list box
       
    77     if ( aObserver )
       
    78     	{
       
    79     	SetListBoxObserver( aObserver );
       
    80     	}
       
    81     CreateScrollBarFrameL( ETrue );
       
    82     
       
    83     ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
       
    84                                                CEikScrollBarFrame::EAuto );
       
    85                                                          
       
    86     // The ownership of the list box model is retained with the Container.
       
    87     // This is because the model contains the additional functionality of
       
    88     // changing the settings values in addition to retreiving it.                                                       
       
    89     Model()->SetItemTextArray( iListBoxModel );  
       
    90     Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );                                                          
       
    91     
       
    92     UpdateIconsL();    
       
    93    	// ItemDrawer()->ColumnData()->SetIconArray( NULL );
       
    94     ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
       
    95     
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // CLcListBox* CLcListBox::NewL
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 CLcListBox* CLcListBox::NewL( 		
       
   103 									CLcLocationAppInfoArray*     aAppArray,
       
   104 							  const CCoeControl* 		   		 aParent,
       
   105 							  		MEikListBoxObserver*	     aObserver )
       
   106     {
       
   107     CLcListBox* self = new ( ELeave ) CLcListBox;
       
   108     CleanupStack::PushL( self );
       
   109     self->ConstructL( aAppArray, aParent, aObserver );
       
   110     CleanupStack::Pop( self );
       
   111     return self;
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // void CLcListBox::UpdateListBoxContents
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 void CLcListBox::UpdateListBoxContentsL( 
       
   119 							CLcLocationAppInfoArray*      aAppArray )
       
   120     {
       
   121     // This function transfers the ownership of the Application information
       
   122     // array. So first we have to delete the existing array and then we can
       
   123     iListBoxModel->UpdateListBoxContents( aAppArray );
       
   124     
       
   125     UpdateIconsL();
       
   126     }
       
   127     
       
   128 // -----------------------------------------------------------------------------
       
   129 // CLocPsySettingsContainer::UpdateIconsL
       
   130 // -----------------------------------------------------------------------------
       
   131 void CLcListBox::UpdateIconsL()
       
   132     {
       
   133     CLcLocationAppInfoArray& iconArray( iListBoxModel->AppInfoArray());
       
   134     
       
   135     CAknIconArray* icons = new( ELeave ) CAknIconArray( KLcViewListboxGranularity );
       
   136     CleanupStack::PushL( icons );
       
   137 
       
   138 	// Append each of the Icon elements to this array.
       
   139 	for ( TInt i = 0; i < iconArray.Count(); i++ )
       
   140 		{
       
   141 		TRAPD( error, icons->AppendL( iconArray[i].IconL()));
       
   142 		if ( error )
       
   143 			{
       
   144 			User::Leave( error );
       
   145 			}
       
   146 		}
       
   147 
       
   148     // Destroy the old icons because SetIconArray() does not destroy them.
       
   149     CArrayPtr<CGulIcon>* oldIcons = ItemDrawer()->ColumnData()->IconArray();
       
   150     if( oldIcons )
       
   151         {
       
   152         oldIcons->ResetAndDestroy();
       
   153         delete oldIcons;
       
   154         }
       
   155 
       
   156     // Transfer ownership of icon array to the lbx.
       
   157     // SetIconArray() Does not delete the Old icon array
       
   158     ItemDrawer()->ColumnData()->SetIconArray( icons );
       
   159     CleanupStack::Pop( icons );
       
   160 
       
   161     // Draws listbox again
       
   162     HandleItemAdditionL();
       
   163     HandleItemRemovalL();
       
   164     }     
       
   165