Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 21:49, 5 April 2008.

Usando Menus com as Plataformas S60 e Maemo

From Forum Nokia Wiki

Original: Using_menus_with_S60_and_Maemo_Platform

Comparação

Ambas as plataformas S60 e Maemo disponibilizam menus com submenus. O visual gráfico é praticamente o mesmo. Num dispositivo S60 o menu é aberto pela tecla da esquerda. Num dispositivo Maemo o menu é aberto pela tecla menu ou pela barra de título.

A forma Típica de Criar um Menu na Plataforma S60 é definir ele em um arquivo de recursos. Cada ítem de menu ou inicia um comando ou abre um submenu.

MENU_ITEM					MENU_ITEM
	{						{
	command = EAknSoftkeyExit;			cascade = r_file_menu;
	txt = "Close";					txt = "File";	
	}						}

Para facilitar a localização, as strings são geralmente substituídas por defines:

#define qtn_file "File"
...
MENU_ITEM
	{
	cascade = r_file_menu;
	txt = qtn_file;	
	}

Normalmente, os comandos do menu são gerenciados usando a função HandleCommandL derivada das classes da AppUi

void CUTFViewerAppUi::HandleCommandL( TInt aCommand )
	{
	switch( aCommand )
		{
		case EEikCmdExit:
		case EAknSoftkeyExit:
			Exit();
			break;
...

Na Plataforma Maemo o menu é criado dentro do código fonte.

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") );

Os ítens de menu são adicionados um a um a estrutura de menu.

gtk_menu_append( main_menu, close );

Cada ítem de menu é associado a uma função de retorno. Por exemplo, quando "Close" é selecionado no menu a função gtk_main_quit é chamada com o parâmetro NULL.

g_signal_connect( G_OBJECT( close ), "activate", gtk_main_quit, NULL );

Na plataforma Maemo é possível separar um grupo de ítens de menu usando um ítem separador específico.

Image:MaemoSeparator.PNG

separator = gtk_separator_menu_item_new();

Comparando as Plataformas S60 e Maemo

Plataforma S60

Image:S60Menu.png

// 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";
				}
		};
	}

Plataforma Maemo

Image:MaemoMenu.png

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
Multi view & dynamic menus bertma Symbian User Interface 2 2005-11-02 07:39
series 40 theme studio help please lumpycrumpet Themes/Carbide.ui 1 2008-01-03 08:28
menu pane question nomadph Symbian User Interface 7 2007-10-02 09:32
Application looks odd on some models macsth General Symbian C++ 3 2006-12-05 10:07
Menus in Nokia :( vignesh@i10n Mobile Java General 3 2007-06-22 11:12
 
Powered by MediaWiki