Archived:Adding menu items dynamically using Symbian C++
debjit.roy
(Talk | contribs) (Debjit.roy -) |
hamishwillee
(Talk | contribs) m (moved TSS000712 - Adding menu items dynamically to Archived:Adding menu items dynamically using Symbian C++) |
||
| (2 intermediate revisions by one user not shown) | |||
| Line 1: | Line 1: | ||
| − | + | {{Archived|timestamp=20120314045706|user=roy.debjit| }} | |
| − | + | [[Category:Symbian C++]][[Category:UI]][[Category:S60 1st Edition]][[Category:S60 2nd Edition (initial release)]][[Category:S60 3rd Edition (initial release)]][[Category:Series 80 2nd Edition]] | |
| − | + | ||
| − | + | ||
| − | {{ArticleMetaData | + | {{ArticleMetaData <!-- v1.2 --> |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) --> | |sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) --> | ||
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | |installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | ||
| − | |sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) --> | + | |devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') --> |
| − | |devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) --> | + | |sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) --> |
| − | |signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer --> | + | |platform= S60 1st Edition<br>S60 2nd Edition<br>S60 3rd Edition<br>Series 80 2nd Edition |
| − | |capabilities=<!-- Capabilities required (e.g. Location, NetworkServices. | + | |devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) --> |
| − | |author=[[User:Technical writer 2]] | + | |dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> |
| + | |signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer --> | ||
| + | |capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. --> | ||
| + | |keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase --> | ||
| + | |language= <!-- Language category code for non-English topics - e.g. Lang-Chinese --> | ||
| + | |translated-by= <!-- [[User:XXXX]] --> | ||
| + | |translated-from-title= <!-- Title only --> | ||
| + | |translated-from-id= <!-- Id of translated revision --> | ||
| + | |review-by= <!-- After re-review: [[User:username]] --> | ||
| + | |review-timestamp= <!-- After re-review: YYYYMMDD --> | ||
| + | |update-by= <!-- After significant update: [[User:username]]--> | ||
| + | |update-timestamp= <!-- After significant update: YYYYMMDD --> | ||
| + | |creationdate= 20070704 | ||
| + | |author= [[User:Technical writer 2]] | ||
| + | <!-- The following are not in current metadata --> | ||
| + | |subcategory= UI | ||
| + | |id= TSS000712 | ||
}} | }} | ||
| − | |||
== Overview == | == Overview == | ||
Adding menu items dynamically | Adding menu items dynamically | ||
| Line 32: | Line 38: | ||
== Solution == | == Solution == | ||
| − | First, use an | + | First, use an 'empty' menu definition in the application resource file:<br> #include <nowiki><</nowiki>eikon.rh<nowiki>></nowiki><br> #include <nowiki><</nowiki>avkon.rh<nowiki>></nowiki><br> #include <nowiki><</nowiki>avkon.rsg<nowiki>></nowiki><br> #include "MyApp.hrh"<br> RESOURCE RSS_SIGNATURE<br> <nowiki>{</nowiki><br> <nowiki>}</nowiki><br> RESOURCE TBUF r_default_document_name<br> <nowiki>{</nowiki><br> buf="";<br> <nowiki>}</nowiki><br> RESOURCE EIK_APP_INFO<br> <nowiki>{</nowiki><br> menubar = r_myapp_menubar;<br> cba = R_AVKON_SOFTKEYS_OPTIONS_EXIT;<br> <nowiki>}</nowiki><br> RESOURCE MENU_BAR r_myapp_menubar<br> <nowiki>{</nowiki><br> titles =<br> <nowiki>{</nowiki><br> MENU_TITLE<br> <nowiki>{</nowiki><br> menu_pane = r_myapp_menu;<br> <nowiki>}</nowiki><br> <nowiki>}</nowiki>;<br> <nowiki>}</nowiki><br> RESOURCE MENU_PANE r_myapp_menu<br> <nowiki>{</nowiki><br> items =<br> <nowiki>{</nowiki><br> // Empty implementation of menu<br> <nowiki>}</nowiki>;<br> <nowiki>}</nowiki><br>Then, override MEikMenuObserver::DynInitMenuPaneL() in the application UI class:<br> void CMyAppUi::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )<br> <nowiki>{</nowiki><br> if( aResourceId == R_MYAPP_MENU )<br> <nowiki>{</nowiki><br> CEikMenuPaneItem::SData itemData;<br> itemData.iText = _L("New menu item"); // Label text for the menu item<br> itemData.iCommandId = ECmdYourMenu; // Command ID for the menu item<br> itemData.iFlags = 0;<br> itemData.iCascadeId = 0;<br> aMenuPane-<nowiki>></nowiki>AddMenuItemL( itemData );<br> <nowiki>}</nowiki><br> <nowiki>}</nowiki><br>Note that there is no need to call DynInitMenuPaneL() directly as it will be called by the framework once the menu softkey is pressed. |
Latest revision as of 10:48, 14 June 2012
Article Metadata
Compatibility
S60 2nd Edition
S60 3rd Edition
Series 80 2nd Edition
Article
Overview
Adding menu items dynamically
Description
Items can be added to the menu dynamically, without making any changes to the resource file.
Solution
First, use an 'empty' menu definition in the application resource file:
#include <eikon.rh>
#include <avkon.rh>
#include <avkon.rsg>
#include "MyApp.hrh"
RESOURCE RSS_SIGNATURE
{
}
RESOURCE TBUF r_default_document_name
{
buf="";
}
RESOURCE EIK_APP_INFO
{
menubar = r_myapp_menubar;
cba = R_AVKON_SOFTKEYS_OPTIONS_EXIT;
}
RESOURCE MENU_BAR r_myapp_menubar
{
titles =
{
MENU_TITLE
{
menu_pane = r_myapp_menu;
}
};
}
RESOURCE MENU_PANE r_myapp_menu
{
items =
{
// Empty implementation of menu
};
}
Then, override MEikMenuObserver::DynInitMenuPaneL() in the application UI class:
void CMyAppUi::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
{
if( aResourceId == R_MYAPP_MENU )
{
CEikMenuPaneItem::SData itemData;
itemData.iText = _L("New menu item"); // Label text for the menu item
itemData.iCommandId = ECmdYourMenu; // Command ID for the menu item
itemData.iFlags = 0;
itemData.iCascadeId = 0;
aMenuPane->AddMenuItemL( itemData );
}
}
Note that there is no need to call DynInitMenuPaneL() directly as it will be called by the framework once the menu softkey is pressed.

