×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:Adding menu items dynamically using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search
Forum Nokia KB (Talk | contribs)
hamishwillee (Talk | contribs)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{KBTS}}
+
{{Archived|timestamp=20120314045706|user=roy.debjit| }}
__NOTOC__
+
[[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]]
__NOEDITSECTION__
+
  
[[Category:Technical Solution]]
 
  
{|border="2" cellspacing="0" cellpadding="4" width="100%"
 
|
 
====Subject:====
 
|colspan = "2"|
 
====Adding menu items dynamically====
 
|TSS000712
 
  
|-
+
{{ArticleMetaData <!-- v1.2 -->
|rowspan = "2"|
+
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
====&nbsp;====
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|Platform(s):
+
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
|colspan = "2"|Device(s), SW version(s):
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
 +
|platform= S60 1st Edition<br>S60 2nd Edition<br>S60 3rd Edition<br>Series 80 2nd Edition
 +
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 +
|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 ==
|S60 1st Edition<br>S60 2nd Edition<br>S60 3rd Edition<br>Series 80 2nd Edition
+
Adding menu items dynamically
|colspan = "2"|&nbsp;
+
  
|-
+
== Description ==
|
+
Items can be added to the menu dynamically, without making any changes to the resource file.
====Category:====
+
|colspan = "3"|Symbian C<nowiki>++</nowiki>
+
  
|-
+
== Solution ==
|
+
First, use an 'empty' menu definition in the application resource file:<br>&nbsp;&nbsp;&nbsp;&nbsp;#include <nowiki><</nowiki>eikon.rh<nowiki>></nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;#include <nowiki><</nowiki>avkon.rh<nowiki>></nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;#include <nowiki><</nowiki>avkon.rsg<nowiki>></nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;#include "MyApp.hrh"<br>&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE RSS_SIGNATURE<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE TBUF r_default_document_name<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf="";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE EIK_APP_INFO<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;menubar = r_myapp_menubar;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cba = R_AVKON_SOFTKEYS_OPTIONS_EXIT;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE MENU_BAR r_myapp_menubar<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;titles =<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MENU_TITLE<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;menu_pane = r_myapp_menu;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE MENU_PANE r_myapp_menu<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;items =<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Empty implementation of menu<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>Then, override MEikMenuObserver::DynInitMenuPaneL() in the application UI class:<br>&nbsp;&nbsp;&nbsp;&nbsp;void CMyAppUi::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if( aResourceId == R_MYAPP_MENU )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CEikMenuPaneItem::SData itemData;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itemData.iText = _L("New menu item"); &nbsp;// Label text for the menu item<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itemData.iCommandId = ECmdYourMenu; &nbsp;&nbsp;&nbsp;// Command ID for the menu item<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itemData.iFlags = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itemData.iCascadeId = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aMenuPane-<nowiki>></nowiki>AddMenuItemL( itemData );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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.
====Subcategory:====
+
|colspan = "3"|UI
+
 
+
|-
+
|
+
====Description:====
+
|colspan = "3"|'''Description:'''<br>Items can be added to the menu dynamically, without making any changes to the resource file.<br>'''Solution:'''<br>First, use an <nowiki>’</nowiki>empty<nowiki>’</nowiki> menu definition in the application resource file:<br>&nbsp;&nbsp;&nbsp;&nbsp;#include <nowiki><</nowiki>eikon.rh<nowiki>></nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;#include <nowiki><</nowiki>avkon.rh<nowiki>></nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;#include <nowiki><</nowiki>avkon.rsg<nowiki>></nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;#include "MyApp.hrh"<br>&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE RSS_SIGNATURE<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE TBUF r_default_document_name<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf="";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE EIK_APP_INFO<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;menubar = r_myapp_menubar;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cba = R_AVKON_SOFTKEYS_OPTIONS_EXIT;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE MENU_BAR r_myapp_menubar<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;titles =<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MENU_TITLE<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;menu_pane = r_myapp_menu;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE MENU_PANE r_myapp_menu<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;items =<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Empty implementation of menu<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>Then, override MEikMenuObserver::DynInitMenuPaneL() in the application UI class:<br>&nbsp;&nbsp;&nbsp;&nbsp;void CMyAppUi::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if( aResourceId == R_MYAPP_MENU )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CEikMenuPaneItem::SData itemData;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itemData.iText = _L("New menu item"); &nbsp;// Label text for the menu item<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itemData.iCommandId = ECmdYourMenu; &nbsp;&nbsp;&nbsp;// Command ID for the menu item<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itemData.iFlags = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itemData.iCascadeId = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aMenuPane-<nowiki>></nowiki>AddMenuItemL( itemData );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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.
+
 
+
|-
+
|
+
====Creation date:====
+
|colspan = "3"|July 4, 2007
+
 
+
|-
+
|
+
====Last modified:====
+
|colspan = "3"|-
+
 
+
|-
+
[[Category:Symbian C++]][[Category:UI]][[Category:S60 1st Edition]] [[Category:S60 2nd Edition]][[Category:S60 3rd Edition]][[Category:Series 80 2nd Edition]]
+

Latest revision as of 10:48, 14 June 2012

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}}.



Article Metadata
Compatibility
Platform(s): S60 1st Edition
S60 2nd Edition
S60 3rd Edition
Series 80 2nd Edition
S60 3rd Edition (initial release)
S60 2nd Edition (initial release)
S60 1st Edition
Article
Created: User:Technical writer 2 (04 Jul 2007)
Last edited: hamishwillee (14 Jun 2012)

[edit] Overview

Adding menu items dynamically

[edit] Description

Items can be added to the menu dynamically, without making any changes to the resource file.

[edit] 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.

This page was last modified on 14 June 2012, at 10:48.
80 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.

×