profilesapplication/Profiles/ProfileAiwProvider/src/CPapPopupList.cpp
branchRCL_3
changeset 19 cd54903d48da
equal deleted inserted replaced
18:b7fa36b488f8 19:cd54903d48da
       
     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         case EEventItemSingleClicked:
       
   103             UpdateCba();
       
   104             break;
       
   105 
       
   106         default:
       
   107             break;
       
   108         }
       
   109 
       
   110     CAknPopupList::HandleListBoxEventL( aListBox, aEventType );
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CPapPopupList::ProcessCommandL
       
   115 // (other items were commented in a header).
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 void CPapPopupList::ProcessCommandL( TInt aCommandId )
       
   119     {
       
   120     switch( aCommandId )
       
   121         {
       
   122         // Fall through
       
   123         case EAknSoftkeyMark:
       
   124         case EAknSoftkeyUnmark:
       
   125             UpdateCba();
       
   126             break;
       
   127             
       
   128         default:
       
   129             break;
       
   130         }
       
   131 
       
   132     CAknPopupList::ProcessCommandL( aCommandId );
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CPapPopupList::UpdateCba
       
   137 // (other items were commented in a header).
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 void CPapPopupList::UpdateCba()
       
   141     {
       
   142     // Cache the pointer to button group container
       
   143     CEikButtonGroupContainer* cba = ButtonGroupContainer();
       
   144     // Left softkey should be visible if there are items selected,
       
   145     // i.e. the selection index array has items.
       
   146     TBool visible( ListBox()->View()->SelectionIndexes()->Count() > 0 );
       
   147     // Resolve left softkey command id
       
   148     TInt leftId( cba->ButtonGroup()->CommandId( 0 ) );
       
   149     // Check if left softkey visibility has changed
       
   150     if( visible != cba->IsCommandVisible( leftId ) )
       
   151         {
       
   152         // Left softkey visibility has changed, update it
       
   153         cba->MakeCommandVisible( leftId, visible );
       
   154         }
       
   155     }
       
   156 
       
   157 // ----------------------------------------------------------------------------
       
   158 // CPapPopupList::SetIconsL
       
   159 // (other items were commented in a header).
       
   160 // ----------------------------------------------------------------------------
       
   161 //
       
   162 void CPapPopupList::SetIconsL()
       
   163     {
       
   164     CAknSingleGraphicPopupMenuStyleListBox* listBox = 
       
   165     	static_cast<CAknSingleGraphicPopupMenuStyleListBox*>( ListBox() );
       
   166 
       
   167     // Create new icon array
       
   168     CAknIconArray* iconArray = new( ELeave ) CAknIconArray( KIconGranularity );
       
   169     CleanupStack::PushL( iconArray );
       
   170 
       
   171 	MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   172     CGulIcon* icon = CGulIcon::NewLC();
       
   173     CFbsBitmap* bitmap = 0;
       
   174     CFbsBitmap* mask = 0;
       
   175     AknsUtils::CreateColorIconL( skin, KAknsIIDQgnIndiCheckboxOn,
       
   176     	KAknsIIDQsnIconColors, EAknsCIQsnIconColorsCG15,
       
   177     	bitmap, mask, KAvkonBitmapFile, EMbmAvkonQgn_indi_checkbox_on,
       
   178     	EMbmAvkonQgn_indi_checkbox_on_mask, KRgbBlack  );
       
   179     icon->SetBitmap( bitmap );
       
   180     icon->SetMask( mask );
       
   181     iconArray->AppendL( icon );
       
   182     CleanupStack::Pop( icon );
       
   183 
       
   184     icon = CGulIcon::NewLC();
       
   185     AknsUtils::CreateColorIconL( skin, KAknsIIDQgnIndiCheckboxOff,
       
   186     	KAknsIIDQsnIconColors, EAknsCIQsnIconColorsCG15,
       
   187     	bitmap, mask, KAvkonBitmapFile, EMbmAvkonQgn_indi_checkbox_off,
       
   188     	EMbmAvkonQgn_indi_checkbox_off_mask, KRgbBlack  );
       
   189     icon->SetBitmap( bitmap );
       
   190     icon->SetMask( mask );
       
   191     iconArray->AppendL( icon );
       
   192     CleanupStack::Pop( icon );
       
   193 
       
   194     // Delete old icons
       
   195     CArrayPtr<CGulIcon>* arr = listBox->ItemDrawer()->ColumnData()->IconArray();
       
   196     if( arr )
       
   197     	{
       
   198     	arr->ResetAndDestroy();
       
   199 	    delete arr;
       
   200 	    arr = NULL;
       
   201     	}
       
   202 
       
   203 	// Set new icon array
       
   204     listBox->ItemDrawer()->ColumnData()->SetIconArray( iconArray );	// changes ownership
       
   205     CleanupStack::Pop( iconArray );
       
   206 
       
   207     }
       
   208 
       
   209 
       
   210 //  End of File