locationcentre/lcservice/src/lcpopuplistbox.cpp
branchRCL_3
changeset 16 4721bd00d3da
parent 14 3a25f69541ff
child 21 e15b7f06eba6
equal deleted inserted replaced
14:3a25f69541ff 16:4721bd00d3da
     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:  List box used to display the Location Centre pop-up.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDES 
       
    20 #include <AknIconArray.h>		// Icon Array
       
    21 #include <eikclbd.h>			// Column Listbox
       
    22 
       
    23 // USER INCLUDES
       
    24 #include "lcpopuplistbox.h"
       
    25 #include "lcpopuplistboxmodel.h"
       
    26 #include "lclocationappinfo.h"
       
    27 
       
    28 // CONSTANT DEFINTION
       
    29 const TInt KLcPopupListboxGranularity = 4;
       
    30 
       
    31 // ========================= MEMBER FUNCTIONS ================================
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // CLcPopupListBox::CLcPopupListBox
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CLcPopupListBox::CLcPopupListBox( CLcLocationAppInfoArray*	aAppArray )
       
    38 	:iAppArray( aAppArray )
       
    39     {
       
    40     // C++ Default constructor. No allocations or functions which can Leave
       
    41     // should be called from here.
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CLcPopupListBox::~CLcPopupListBox
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CLcPopupListBox::~CLcPopupListBox()
       
    49     {
       
    50     // C++ Destructor. Free all resources associated with this class.
       
    51     
       
    52     // Delete the List box model.
       
    53     delete iListBoxModel;
       
    54     
       
    55     // Delete the Application Info array
       
    56     delete iAppArray;
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // void CLcPopupListBox::ConstructL
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 void CLcPopupListBox::ConstructL( CCoeControl*   aParent )
       
    64     {
       
    65     // Create the list box model
       
    66     iListBoxModel = CLcPopupListBoxModel::NewL( *iAppArray );
       
    67     
       
    68     CAknSingleGraphicPopupMenuStyleListBox::ConstructL( aParent, EAknListBoxMenuList );
       
    69     CreateScrollBarFrameL(ETrue);
       
    70     ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
       
    71                                                CEikScrollBarFrame::EAuto ); 
       
    72      
       
    73     UpdateIconsL();
       
    74                                                                                                                       
       
    75     // The ownership of the List box model is retained with the Container.
       
    76     // This is needed because the model is used to return the identifier of the
       
    77     // Location based Application or Content/Service when its selected.                                                     
       
    78     Model()->SetItemTextArray( iListBoxModel );  
       
    79     Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
    80     
       
    81     ActivateL();
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // void CLcPopupListBox::UpdateModel
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 void CLcPopupListBox::UpdateListBoxL( CLcLocationAppInfoArray*	aAppArray )
       
    89 	{
       
    90 	// Delete the existing contents and set the new Application info array
       
    91 	// to the listbox model.
       
    92 	delete iAppArray;
       
    93 	iAppArray = aAppArray;
       
    94 	
       
    95 	iListBoxModel->UpdateModel( *iAppArray );
       
    96 	
       
    97 	UpdateIconsL();
       
    98 	
       
    99 	HandleItemAdditionL();
       
   100 	HandleItemRemovalL();
       
   101 	
       
   102 	DrawDeferred();
       
   103 	}
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // void CLcPopupListBox::UpdateIconsL
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 void CLcPopupListBox::UpdateIconsL()
       
   110 	{
       
   111 	TInt count = iAppArray->Count();
       
   112 	// Update the Icons only if there are any elements the List box
       
   113 	if ( count )
       
   114 		{
       
   115 		// Create a new Icons Array
       
   116 	    CAknIconArray* icons = new( ELeave ) CAknIconArray( KLcPopupListboxGranularity );
       
   117 	    CleanupStack::PushL( icons );
       
   118 
       
   119 		// Add All the icons to the Icons array
       
   120 		for ( TInt i = 0; i < count; i++ )
       
   121 			{			
       
   122 			icons->AppendL(( *iAppArray )[i].IconL() );
       
   123 			}
       
   124 
       
   125 	    // Get old icons and delete those. This is done because SetIconArray will
       
   126 	    // not do it.
       
   127 	    CAknIconArray* oldIcons = 
       
   128 	    	static_cast<CAknIconArray*>( ItemDrawer()->ColumnData()->IconArray());
       
   129 	    	    
       
   130 	    delete oldIcons;
       
   131 
       
   132 	    //Set New Icons to array
       
   133 	    ItemDrawer()->ColumnData()->SetIconArray( icons );  
       
   134 	    CleanupStack::Pop(icons);		
       
   135 		}
       
   136     ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );   	
       
   137     
       
   138     DrawDeferred();
       
   139 	}
       
   140 	
       
   141 // ---------------------------------------------------------------------------
       
   142 // TInt CLcPopupListBox::AppInfoId
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 TPtrC CLcPopupListBox::AppInfoId() const
       
   146 	{   	
       
   147 	return ( *iAppArray )[ CurrentItemIndex() ].Id();
       
   148 	}
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // void CLcPopupListBox::HandleResourceChange
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 void CLcPopupListBox::HandleResourceChange( TInt    aType )
       
   155     {
       
   156     // Pass the event to the base class
       
   157     CCoeControl::HandleResourceChange( aType );
       
   158     switch( aType )
       
   159         {
       
   160         // Dynamic Layout switch and Skin Change
       
   161         case KEikDynamicLayoutVariantSwitch:
       
   162             {
       
   163             SetRect( Rect());
       
   164             break;
       
   165             }
       
   166         case KAknsMessageSkinChange:
       
   167             {
       
   168             TRAP_IGNORE( UpdateIconsL());
       
   169             break;
       
   170             }
       
   171         default:
       
   172             {
       
   173             break;
       
   174             }
       
   175         } 
       
   176     DrawDeferred();
       
   177     }