×
Namespaces

Variants
Actions

Listbox creation using Symbian resource definition

From Nokia Developer Wiki
Jump to: navigation, search

The code snippets in this article illustrate how to create a Listbox in Symbian C++ using a resource file definition. The example uses a "SingleStyle" ListBox for illustration, but the technique is valid for other list box types.

Article Metadata
Article
Created: kiran10182 (04 May 2007)
Last edited: hamishwillee (25 Jan 2012)

Contents

Step 1: Supporting all necessary languages

File CYrRss.l01:

// English language support
 
#define lb_item1 "\tItem1\t"
#define lb_item2 "\tItem2\t"
#define lb_item3 "\tItem3\t"
#define lb_item4 "\tItem4\t"
#define lb_item5 "\tItem5\t"
#define lb_item6 "\tItem6\t"
#define lb_item7 "\tItem7\t"
#define lb_item8 "\tItem8\t"
#define lb_item9 "\tItem9\t"

File CYrRss.l16:

// Russian language support - russian text should be saved in UTF 8 !
CHARACTER_SET UTF8
 
#define lb_item1 "\tЭлемент1\t"
#define lb_item2 "\tЭлемент2\t"
#define lb_item3 "\tЭлемент3\t"
#define lb_item4 "\tЭлемент4\t"
#define lb_item5 "\tЭлемент5\t"
#define lb_item6 "\tЭлемент6\t"
#define lb_item7 "\tЭлемент7\t"
#define lb_item8 "\tЭлемент8\t"
#define lb_item9 "\tЭлемент9\t"


Step 2: Defining listbox in project resources

File CYrRss.rss:

CHARACTER_SET UTF8
 
#ifdef LANGUAGE_01
#include "CYrRss.l01"
#endif
 
#ifdef LANGUAGE_16
#include "CYrRss.l16"
#endif
 
...
 
RESOURCE LISTBOX r_list_box
{
flags = EAknListBoxSelectionList;
array_id= r_list_box_item_array;
}
 
RESOURCE ARRAY r_list_box_item_array
{
items =
{
LBUF { txt = lb_item1;},
LBUF { txt = lb_item2;},
LBUF { txt = lb_item3;},
LBUF { txt = lb_item4;},
LBUF { txt = lb_item5;},
LBUF { txt = lb_item6;},
LBUF { txt = lb_item7;},
LBUF { txt = lb_item8;},
LBUF { txt = lb_item9;},
};
}

Step 3: CYrContainer.h

  • Open your CYrContainer.h file.
  • Inlcude entries for required header files.
#include <aknlists.h> // For List Box
#include <barsread.h> //For Resource Reader
  • Add function which will be needed for getting Key response.
TKeyResponse OfferKeyEventL(const TKeyEvent &aKeyEvent, TEventCode aType);
  • Declare object of Listbox:
private: // data
// ..
CAknSingleStyleListBox* iListBox;
  • Define in mmp-file library:
LIBRARY bafl.lib

Step 4: CYrContainer.cpp

  • Open your "CyrContainer.cpp" file.
  • Inlcude an additional entry for .rsg file. Like:
#include <YrListBox.rsg>
  • Now in the ContructL() function of your CYrContaner.cpp file:
void CYrContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
 
iListBox= new (ELeave) CAknSingleStyleListBox();
iListBox->SetContainerWindowL(*this);
 
TResourceReader rr;
iCoeEnv->CreateResourceReaderLC(rr, R_LIST_BOX);
iListBox->ConstructFromResourceL(rr);
iListBox->CreateScrollBarFrameL(ETrue);
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto);
 
CleanupStack::PopAndDestroy();//rr
 
SetRect(aRect);
ActivateL();
}
 
void CYrContainer::SizeChanged()
{
iListBox->SetExtent(TPoint(0,0), iListBox->MinimumSize() );
}
 
 
TInt CYrContainer::CountComponentControls() const
{
return 1; // return number of controls inside this container
}
 
CCoeControl* CYrContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iListBox;
default:
return NULL;
}
}
 
TKeyResponse CYrContainer::OfferKeyEventL(const TKeyEvent &aKeyEvent, TEventCode aType)
{
return iListBox->OfferKeyEventL(aKeyEvent, aType);
}


Related Links

This page was last modified on 25 January 2012, at 01:18.
60 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.

×