Categories: S60 | Maemo
This page was last modified 13:18, 15 November 2007.
Using menus with S60 and Maemo Platform
From Forum Nokia Wiki
Comparison
Both S60 Platform and Maemo Platform support menus with submenus. The graphical look is fairly the same. On S60 device the menu is opened by the left soft key. On Maemo device the menu is opened by the menu key or title bar.
The typical way to create a menu in S60 Platform is to define it in a resource file. Each menu item either initiates a command or opens a submenu.
MENU_ITEM MENU_ITEM
{ {
command = EAknSoftkeyExit; cascade = r_file_menu;
txt = "Close"; txt = "File";
} }
To ease the localization the strings are usually replaced by defines:
#define qtn_file "File"
...
MENU_ITEM
{
cascade = r_file_menu;
txt = qtn_file;
}
Normally the menu commands are handled using the AppUi's classes derived HandleCommandL function.
void CUTFViewerAppUi::HandleCommandL( TInt aCommand )
{
switch( aCommand )
{
case EEikCmdExit:
case EAknSoftkeyExit:
Exit();
break;
...
On Maemo Platform the menu is created within the source code.
GtkMenu *main_menu;
GtkWidget *file_menu;
GtkWidget *close;
main_menu = GTK_MENU( gtk_menu_new () );
file_menu = gtk_menu_new ();
close = gtk_menu_item_new_with_label( _("Close") );
The menu items are added one by one to the menu structure.
gtk_menu_append( main_menu, close );
Each menu item is tied to a call back function. For example when "Close" is selected from the menu the function gtk_main_quit gets called with a parameter NULL.
g_signal_connect( G_OBJECT( close ), "activate", gtk_main_quit, NULL );
On Maemo Platform it is possible to separate a group of menu items using a specific separator item.
separator = gtk_separator_menu_item_new();
Comparing S60 and Maemo Platforms
S60 Platform
// UTFViewer enumerate command codes
enum TUTFViewerIds
{
ECommandCharacters = 0x6001, // start value must not be 0
ECommandOpenFile,
ECommandReset,
ECommandUp,
ECommandDown,
ECommandLeft,
ECommandRight,
ECommandFullScreen,
EHelp,
EAbout
};
// -----------------------------------------------------------------------------
//
// r_menu
// Menu for "Options"
//
// -----------------------------------------------------------------------------
//
RESOURCE MENU_PANE r_menu
{
items =
{
MENU_ITEM
{
cascade = r_file_menu;
txt = "File";
},
MENU_ITEM
{
cascade = r_move_menu;
txt = "Move";
},
MENU_ITEM
{
command = ECommandFullScreen;
txt = "Full Screen";
},
MENU_ITEM
{
command = EHelp;
txt = "Help";
},
MENU_ITEM
{
command = EAknSoftkeyExit;
txt = "Close";
}
};
}
// -----------------------------------------------------------------------------
//
// r_file_menu
// Menu for "File"
//
// -----------------------------------------------------------------------------
//
RESOURCE MENU_PANE r_file_menu
{
items =
{
MENU_ITEM
{
command = ECommandCharacters;
txt = "Characters";
},
MENU_ITEM
{
command = ECommandOpenFile;
txt = "UTF-8 text file";
}
};
}
// -----------------------------------------------------------------------------
//
// r_move_menu
// Menu for "Move"
//
// -----------------------------------------------------------------------------
//
RESOURCE MENU_PANE r_move_menu
{
items =
{
MENU_ITEM
{
command = ECommandReset;
txt = "Reset";
},
MENU_ITEM
{
command = ECommandUp;
txt = "Up";
},
MENU_ITEM
{
command = ECommandDown;
txt = "Down";
},
MENU_ITEM
{
command = ECommandLeft;
txt = "Left";
},
MENU_ITEM
{
command = ECommandRight;
txt = "Right";
}
};
}
Maemo Platform
typedef struct _AppData AppData;
struct _AppData
{
HildonProgram *program; /* handle to application */
HildonWindow *window; /* handle to app's window */
osso_context_t *osso; /* handle to osso */
};
/* Struct to include view's information */
typedef struct _MainView MainView;
struct _MainView
{
/* Handle to app's data */
AppData *data;
...
/* Items for menu */
GtkWidget *file_item;
GtkWidget *code_set_item;
GtkWidget *open_item;
GtkWidget *move_item;
GtkWidget *reset_item;
GtkWidget *up_item;
GtkWidget *down_item;
GtkWidget *left_item;
GtkWidget *right_item;
GtkWidget *fullscreen_item;
...
};
/* Create the menu items needed for the drop down menu */
static void create_menu( MainView *main )
{
/* Create needed handles */
GtkMenu *main_menu;
GtkWidget *file_menu, *move_menu;
GtkWidget *separator = NULL;
GtkWidget *help = NULL, *close = NULL;
/* Create main menu and new menus for submenus in our drop down menu */
main_menu = GTK_MENU( gtk_menu_new () );
file_menu = gtk_menu_new ();
move_menu = gtk_menu_new ();
/* Create the menu items */
main->file_item = gtk_menu_item_new_with_label ( _("File") );
main->code_set_item = gtk_menu_item_new_with_label ( _("Characters") );
main->open_item = gtk_menu_item_new_with_label ( _("UTF-8 text file") );
main->move_item = gtk_menu_item_new_with_label ( _("Move") );
main->reset_item = gtk_menu_item_new_with_label ( _("Reset") );
main->up_item = gtk_menu_item_new_with_label ( _("Up") );
main->down_item = gtk_menu_item_new_with_label ( _("Down") );
main->left_item = gtk_menu_item_new_with_label ( _("Left") );
main->right_item = gtk_menu_item_new_with_label ( _("Right") );
main->fullscreen_item = gtk_menu_item_new_with_label ( _("Full Screen") );
separator = gtk_separator_menu_item_new();
help = gtk_menu_item_new_with_label( _("Help") );
close = gtk_menu_item_new_with_label( _("Close") );
/* Add menu items to right menus */
gtk_menu_append( main_menu, main->file_item );
gtk_menu_append( file_menu, main->code_set_item );
gtk_menu_append( file_menu, main->open_item );
gtk_menu_append( main_menu, main->move_item );
gtk_menu_append( move_menu, main->reset_item );
gtk_menu_append( move_menu, main->up_item );
gtk_menu_append( move_menu, main->down_item );
gtk_menu_append( move_menu, main->left_item );
gtk_menu_append( move_menu, main->right_item );
gtk_menu_append( main_menu, main->fullscreen_item );
gtk_menu_append( main_menu, separator );
gtk_menu_append( main_menu, help );
gtk_menu_append( main_menu, close );
/* Add submenus to the right items */
gtk_menu_item_set_submenu( GTK_MENU_ITEM (main->file_item), file_menu );
gtk_menu_item_set_submenu( GTK_MENU_ITEM (main->move_item), move_menu );
/* Attach the callback functions to the activate signal */
g_signal_connect( G_OBJECT( main->code_set_item ), "activate",
G_CALLBACK ( callback_code_set), main );
g_signal_connect( G_OBJECT( main->open_item ), "activate",
G_CALLBACK ( callback_file_open), main );
g_signal_connect( G_OBJECT( main->reset_item ), "activate",
G_CALLBACK ( callback_reset ), main );
g_signal_connect( G_OBJECT( main->up_item ), "activate",
G_CALLBACK ( callback_up ), main );
g_signal_connect( G_OBJECT( main->down_item ), "activate",
G_CALLBACK( callback_down ), main );
g_signal_connect( G_OBJECT( main->left_item ), "activate",
G_CALLBACK( callback_left ), main );
g_signal_connect( G_OBJECT( main->right_item ), "activate",
G_CALLBACK ( callback_right ), main );
g_signal_connect( G_OBJECT( main->fullscreen_item ), "activate",
G_CALLBACK ( callback_fullscreen ), main );
g_signal_connect( G_OBJECT( help ), "activate",
G_CALLBACK ( callback_help ), main );
g_signal_connect( G_OBJECT( close ), "activate", gtk_main_quit, NULL );
/* Add menu to HildonWindow */
hildon_window_set_menu(main->data->window, main_menu);
/* We need to show menu items */
gtk_widget_show_all( GTK_WIDGET( main_menu ) );
}
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Missing Menus | sappsys | General Symbian C++ | 1 | 2004-03-16 06:24 |
| A question about debugging | avi1000 | Mobile Java General | 6 | 2007-11-20 11:34 |
| Modify a device driver on the S60 platform | lihsus | General Symbian C++ | 1 | 2008-03-12 08:27 |
| Need a better way of editing themes on a 6270 | Yoda 3114 | Graphics & Video & Streaming | 4 | 2006-04-27 01:57 |
| Simple Question | malloc | General Symbian C++ | 3 | 2007-04-11 16:27 |


