×
Namespaces

Variants
Actions

Archived:How to implement vertical option list in Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

This Symbian C++ code example shows how to create a standard Symbian vertical option listbox (where the list displays vertically arranged radio buttons.

Article Metadata
Code ExampleCompatibilityArticle
Keywords: CAknSingleGraphicStyleListBox, CTextListBoxModel, CDesCArray
Created: chenziteng (30 Sep 2009)
Last edited: hamishwillee (18 Sep 2012)

Solution

First we create a normal selection list-box of type CAknSingleGraphicStyleListBox,

void CZoyvlyooListBox::InitializeControlsL()
{
iListBox = new ( ELeave ) CAknSingleGraphicStyleListBox;
iListBox->SetContainerWindowL( *this );
{
TResourceReader reader;
iEikonEnv->CreateResourceReaderLC( reader, R_ZOYVLYOO_LIST_BOX_LIST_BOX );
iListBox->ConstructFromResourceL( reader );
CleanupStack::PopAndDestroy(); // reader internal state
}
...

and then we add two icons (RadioOn.PNG selected and RadioOff.PNG unselected) to its icon array.

void CZoyvlyooListBox::SetupListBoxIconsL()
{
CArrayPtr< CGulIcon >* icons = NULL;
icons = new (ELeave) CAknIconArray( 2 );
CleanupStack::PushL( icons );
// for EListBoxZoyvlyooRationonIndex
icons->AppendL( CEikonEnv::Static()->CreateIconL(
KZoyvlyooFile, EMbmZoyvlyooRationon ) );
// for EListBoxZoyvlyooRationoffIndex
icons->AppendL( CEikonEnv::Static()->CreateIconL(
KZoyvlyooFile, EMbmZoyvlyooRationoff ) );
CleanupStack::Pop( icons );
 
if ( icons != NULL )
{
iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons );
}
}

As we know the item format string of CAknSingleGraphicStyleListBox is "Icon\tText", let's assume that the first item (option) is selected by default, then we append several options to the list, and then we use iSelectedOption to remember the index of the current selected option.

...
AddListBoxItemL(iListBox, _L("0\tItem1")); // zero is the index of the "selected" icon
AddListBoxItemL(iListBox, _L("1\tItem2")); // one is the index of the "unselected" icon
AddListBoxItemL(iListBox, _L("1\tItem3"));
...
iSelectedOption = 0;
...
void CZoyvlyooListBox::AddListBoxItemL(
CEikTextListBox* aListBox,
const TDesC& aString)
{
CTextListBoxModel* model = aListBox->Model();
CDesCArray* itemArray = static_cast< CDesCArray* > ( model->ItemTextArray() );
itemArray->AppendL( aString );
aListBox->HandleItemAdditionL();
}

Whenever the user selects a new option we first set the icon of the previous selected option to "unselected", and then set the icon of the selected option to "selected", and don't forget to update the iSelectedOption.

void CZoyvlyooListBox::HandleListBoxEnterKeyPressedL( 
CEikListBox* aListBox,
TListBoxEvent anEventType)
{
// TODO: implement enterKeyPressed event handler
if((anEventType==EEventEnterKeyPressed)
||(anEventType==EEventItemClicked))
{
TInt index = aListBox->CurrentItemIndex();
if(index!=iSelectedOption)
{
CTextListBoxModel* model = static_cast<CTextListBoxModel*>(aListBox->Model());
CDesCArray* itemArray = static_cast< CDesCArray* > ( model->ItemTextArray() );
{
TPtrC ptr = (*itemArray)[iSelectedOption];
_LIT(KSeparater, "\t");
TInt i = ptr.Find(KSeparater);
ptr.Set(ptr.Right(ptr.Length()-i-1));
TBuf<512> listString;
CreateListBoxItemL( listString, EListBoxZoyvlyooRationoffIndex, ptr);
itemArray->Delete(iSelectedOption);
itemArray->InsertL(iSelectedOption, listString);
aListBox->HandleItemAdditionL();
}
{
TPtrC ptr = (*itemArray)[index];
_LIT(KSeparater, "\t");
TInt i = ptr.Find(KSeparater);
ptr.Set(ptr.Right(ptr.Length()-i-1));
TBuf<512> listString;
CreateListBoxItemL( listString, EListBoxZoyvlyooRationonIndex, ptr);
itemArray->Delete(index);
itemArray->InsertL(index, listString);
aListBox->HandleItemAdditionL();
}
iSelectedOption = index;
}
}
}

Source Code

Full example: Zoyvlyoo(VertOptionList).zip

Zoyvlyoo(VertOptionList).PNG

Relative articles

This page was last modified on 18 September 2012, at 08:59.
57 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×