profilesapplication/Profiles/ProfileAiwProvider/src/CPapPopupList.cpp
changeset 0 ca436256272f
child 8 09aa63f9b2bc
equal deleted inserted replaced
-1:000000000000 0:ca436256272f
       
     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:  A thin CAknPopupList extension.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // CLASS HEADER
       
    21 #include "CPapPopupList.h"
       
    22 
       
    23 // INTERNAL INCLUDES
       
    24 
       
    25 // EXTERNAL INCLUDES
       
    26 #include <AknIconArray.h>
       
    27 #include <aknlists.h>
       
    28 #include <AknsSkinInstance.h>
       
    29 #include <AknsUtils.h>
       
    30 #include <aknconsts.h>
       
    31 #include <avkon.mbg>
       
    32 #include <gulicon.h>
       
    33 
       
    34 // CONSTANTS
       
    35 namespace
       
    36 	{
       
    37 	// Granularities
       
    38 	const TInt KIconGranularity( 3 );
       
    39 	}
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CPapPopupList::CPapPopupList
       
    45 // C++ constructor can NOT contain any code, that might leave.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CPapPopupList::CPapPopupList()
       
    49 	: CAknPopupList()
       
    50     {
       
    51     }
       
    52 
       
    53 
       
    54 void CPapPopupList::ConstructL( CEikListBox* aListBox, TInt aCbaResource )
       
    55 	{
       
    56     CAknPopupList::ConstructL( aListBox, aCbaResource, AknPopupLayouts::EMenuWindow );
       
    57 	}
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CPapPopupList::NewL
       
    61 // Two-phased constructor.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CPapPopupList* CPapPopupList::NewL( CEikListBox* aListBox, TInt aCbaResource )
       
    65 	{
       
    66 	CPapPopupList* self = new( ELeave ) CPapPopupList();
       
    67 	CleanupStack::PushL( self );
       
    68 	self->ConstructL( aListBox, aCbaResource );
       
    69 	CleanupStack::Pop( self );
       
    70 	return self;
       
    71 	}
       
    72 
       
    73 // Destructor
       
    74  CPapPopupList::~CPapPopupList()
       
    75     {
       
    76     }
       
    77     
       
    78 // -----------------------------------------------------------------------------
       
    79 // CPapPopupList::HandleResourceChange
       
    80 // (other items were commented in a header).
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CPapPopupList::HandleResourceChange( TInt aType )
       
    84     {
       
    85     if( aType == KAknsMessageSkinChange )
       
    86         {
       
    87         TRAP_IGNORE( SetIconsL() );
       
    88         }
       
    89     CAknPopupList::HandleResourceChange( aType );
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CPapPopupList::HandleListBoxEventL
       
    94 // (other items were commented in a header).
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void CPapPopupList::HandleListBoxEventL( CEikListBox* aListBox, TListBoxEvent aEventType )
       
    98     {
       
    99     switch( aEventType )
       
   100         {
       
   101         case EEventItemClicked:
       
   102             UpdateCba();
       
   103             break;
       
   104 
       
   105         default:
       
   106             break;
       
   107         }
       
   108 
       
   109     CAknPopupList::HandleListBoxEventL( aListBox, aEventType );
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CPapPopupList::ProcessCommandL
       
   114 // (other items were commented in a header).
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 void CPapPopupList::ProcessCommandL( TInt aCommandId )
       
   118     {
       
   119     switch( aCommandId )
       
   120         {
       
   121         // Fall through
       
   122         case EAknSoftkeyMark:
       
   123         case EAknSoftkeyUnmark:
       
   124             UpdateCba();
       
   125             break;
       
   126             
       
   127         default:
       
   128             break;
       
   129         }
       
   130 
       
   131     CAknPopupList::ProcessCommandL( aCommandId );
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CPapPopupList::UpdateCba
       
   136 // (other items were commented in a header).
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void CPapPopupList::UpdateCba()
       
   140     {
       
   141     // Cache the pointer to button group container
       
   142     CEikButtonGroupContainer* cba = ButtonGroupContainer();
       
   143     // Left softkey should be visible if there are items selected,
       
   144     // i.e. the selection index array has items.
       
   145     TBool visible( ListBox()->View()->SelectionIndexes()->Count() > 0 );
       
   146     // Resolve left softkey command id
       
   147     TInt leftId( cba->ButtonGroup()->CommandId( 0 ) );
       
   148     // Check if left softkey visibility has changed
       
   149     if( visible != cba->IsCommandVisible( leftId ) )
       
   150         {
       
   151         // Left softkey visibility has changed, update it
       
   152         cba->MakeCommandVisible( leftId, visible );
       
   153         }
       
   154     }
       
   155 
       
   156 // ----------------------------------------------------------------------------
       
   157 // CPapPopupList::SetIconsL
       
   158 // (other items were commented in a header).
       
   159 // ----------------------------------------------------------------------------
       
   160 //
       
   161 void CPapPopupList::SetIconsL()
       
   162     {
       
   163     CAknSingleGraphicPopupMenuStyleListBox* listBox = 
       
   164     	static_cast<CAknSingleGraphicPopupMenuStyleListBox*>( ListBox() );
       
   165 
       
   166     // Create new icon array
       
   167     CAknIconArray* iconArray = new( ELeave ) CAknIconArray( KIconGranularity );
       
   168     CleanupStack::PushL( iconArray );
       
   169 
       
   170 	MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   171     CGulIcon* icon = CGulIcon::NewLC();
       
   172     CFbsBitmap* bitmap = 0;
       
   173     CFbsBitmap* mask = 0;
       
   174     AknsUtils::CreateColorIconL( skin, KAknsIIDQgnIndiCheckboxOn,
       
   175     	KAknsIIDQsnIconColors, EAknsCIQsnIconColorsCG15,
       
   176     	bitmap, mask, KAvkonBitmapFile, EMbmAvkonQgn_indi_checkbox_on,
       
   177     	EMbmAvkonQgn_indi_checkbox_on_mask, KRgbBlack  );
       
   178     icon->SetBitmap( bitmap );
       
   179     icon->SetMask( mask );
       
   180     iconArray->AppendL( icon );
       
   181     CleanupStack::Pop( icon );
       
   182 
       
   183     icon = CGulIcon::NewLC();
       
   184     AknsUtils::CreateColorIconL( skin, KAknsIIDQgnIndiCheckboxOff,
       
   185     	KAknsIIDQsnIconColors, EAknsCIQsnIconColorsCG15,
       
   186     	bitmap, mask, KAvkonBitmapFile, EMbmAvkonQgn_indi_checkbox_off,
       
   187     	EMbmAvkonQgn_indi_checkbox_off_mask, KRgbBlack  );
       
   188     icon->SetBitmap( bitmap );
       
   189     icon->SetMask( mask );
       
   190     iconArray->AppendL( icon );
       
   191     CleanupStack::Pop( icon );
       
   192 
       
   193     // Delete old icons
       
   194     CArrayPtr<CGulIcon>* arr = listBox->ItemDrawer()->ColumnData()->IconArray();
       
   195     if( arr )
       
   196     	{
       
   197     	arr->ResetAndDestroy();
       
   198 	    delete arr;
       
   199 	    arr = NULL;
       
   200     	}
       
   201 
       
   202 	// Set new icon array
       
   203     listBox->ItemDrawer()->ColumnData()->SetIconArray( iconArray );	// changes ownership
       
   204     CleanupStack::Pop( iconArray );
       
   205 
       
   206     }
       
   207 
       
   208 
       
   209 //  End of File