Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Usando Menus com as Plataformas S60 e Maemo

From Wiki
Jump to: navigation, search

Archived.pngAquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.

Acredita-se que este artigo ainda seja válido no contexto original (quando ele foi escrito)


Article Metadata

Compatibilidade
Plataforma(s):
Symbian

Artigo
Tradução:
Por leandrodds
Última alteração feita por lpvalente em 04 Dec 2012

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.

MaemoSeparator.PNG

separator = gtk_separator_menu_item_new();

Comparando as Plataformas S60 e Maemo

Plataforma S60

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

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 ) );
}
This page was last modified on 4 December 2012, at 19:57.
133 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.

×