.h 文件:
#include <coecntrl.h>
#include <akniconutils.h>
#include <gulicon.h>
#include <eiklbo.h>
class MEikCommandObserver;
class CAknSingleGraphicStyleListBox;
class CEikTextListBox;
class CTestContainer : public CCoeControl
{
......
private:
CAknSingleGraphicStyleListBox* iListBox;
......
}
.cpp 文件
......
#include <avkon.mbg> //For EMbmAvkonQgn_indi_checkbox_on/off and EMbmAvkonQgn_indi_checkbox_on/off_mask
#include <aknconsts.h> //For KAknsIIDQgnPropCheckboxOn and KAknsIIDQgnPropCheckboxOff
void CTestContainer::InitializeControlsL()
{
iListBox = new ( ELeave ) CAknSingleGraphicStyleListBox;
// Construct listbox
TInt markable = ( EAknListBoxMarkableList |
EAknListBoxMultiselectionList |
CEikListBox::EMultipleSelection |
CEikListBox::ES60StyleMultiselection |
CEikListBox::ES60StyleMarkable );
iListBox->ConstructL( this, markable | EAknListBoxLoopScrolling );
iListBox->SetContainerWindowL( *this );
// Set scrollbars
iListBox->CreateScrollBarFrameL( ETrue );
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto );
// Create listbox item array
CDesCArrayFlat* iListBoxItems = new (ELeave) CDesCArrayFlat(4);
// Create listbox items
iListBoxItems->AppendL( _L("1/tItem1") );
iListBoxItems->AppendL( _L("1/tItem2") );
iListBoxItems->AppendL( _L("1/tItem3") );
// Add items to listbox
iListBox->Model()->SetItemTextArray( iListBoxItems );
// Listbox deletes the item array
iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
iListBox->HandleItemAdditionL( );
// Add icons to listbox
SetupListBoxIconsL();
// Activate Listbox
iListBox->SetRect( Rect() );
iListBox->ActivateL();
iListBox->SetFocus( ETrue );
iFocusControl = iListBox;
}
void CTestContainer::SetupListBoxIconsL()
{
CAknIconArray* iconArray = new( ELeave ) CAknIconArray( 3 );
CleanupStack::PushL( iconArray );
CFbsBitmap* checkboxOnBitmap = NULL;
CFbsBitmap* checkboxOnBitmapMask = NULL;
CFbsBitmap* checkboxOffBitmap = NULL;
CFbsBitmap* checkboxOffBitmapMask = NULL;
//CListItemDrawer is using this logical color as default for its marked icons
TRgb defaultColor;
defaultColor = CEikonEnv::Static()->Color( EColorControlText );
AknsUtils::CreateColorIconLC( AknsUtils::SkinInstance(),
KAknsIIDQgnPropCheckboxOn,
KAknsIIDQsnIconColors,
EAknsCIQsnIconColorsCG13,
checkboxOnBitmap,
checkboxOnBitmapMask,
KAvkonBitmapFile,
EMbmAvkonQgn_indi_checkbox_on,
EMbmAvkonQgn_indi_checkbox_on_mask,
defaultColor
);
CGulIcon* checkboxOnIcon = CGulIcon::NewL( checkboxOnBitmap, checkboxOnBitmapMask );
CleanupStack::Pop( 2 ); // checkboxOnBitmap, checkboxOnBitmapMask
CleanupStack::PushL( checkboxOnIcon );
iconArray->AppendL( checkboxOnIcon );
AknsUtils::CreateColorIconLC( AknsUtils::SkinInstance(),
KAknsIIDQgnPropCheckboxOff,
KAknsIIDQsnIconColors,
EAknsCIQsnIconColorsCG13,
checkboxOffBitmap,
checkboxOffBitmapMask,
KAvkonBitmapFile,
EMbmAvkonQgn_indi_checkbox_off,
EMbmAvkonQgn_indi_checkbox_off_mask,
defaultColor
);
CGulIcon* checkboxOffIcon = CGulIcon::NewL( checkboxOffBitmap, checkboxOffBitmapMask );
CleanupStack::Pop( 2 ); // checkboxOffBitmap, checkboxOffBitmapMask
CleanupStack::PushL( checkboxOffIcon );
iconArray->AppendL( checkboxOffIcon );
iListBox->ItemDrawer()->ColumnData()->SetIconArray( iconArray );
// checkboxOffIcon, checkboxOnIcon, iconArray
CleanupStack::Pop( 3 );
}