Editing Legacy Maemo 5 Documentation/Graphical UI Tutorial/Menus

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
{{Legacy documentation}}
{{Legacy documentation}}
 +
=Menus =
The use of menus in Hildon applications follows a very different approach from the traditional application menus.
The use of menus in Hildon applications follows a very different approach from the traditional application menus.
Line 7: Line 8:
Additionally Hildon provides Context menus, but avoid them when possible.
Additionally Hildon provides Context menus, but avoid them when possible.
-
==Touch view menu ==
 
-
Use the <code>HildonAppMenu</code> widget as a menu in the windows of a Hildon application.
+
==Touch view menu ==
 +
Use the HildonAppmenu widget as a menu in the windows of a Hildon application.
This widget opens at the top of the screen, obscuring the topmost window, and contains several entries organized in one or two columns, depending on screen orientation. Besides entries, application menus can also contain a group of filter buttons.
This widget opens at the top of the screen, obscuring the topmost window, and contains several entries organized in one or two columns, depending on screen orientation. Besides entries, application menus can also contain a group of filter buttons.
-
The entries are <code>GtkButton</code>s. Assign an action to the menu item for when they are activated.
+
The entries are GtkButtons. Assign an action to the menu item for when they are activated.
Filters are toggle buttons that can be used for presentation/sorting purposes. For example, sorting alphabetically a list of contacts or changing the size of icons in a list.
Filters are toggle buttons that can be used for presentation/sorting purposes. For example, sorting alphabetically a list of contacts or changing the size of icons in a list.
-
To create a <code>HildonAppMenu</code>, use the following command:
+
To create a HildonAppMenu, use the following command:
-
<source lang="c">
+
<tt>GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_app_menu_new</font></span>'''</span>             <span><font color="#990000">(</font></span><span><font color="#009900">void</font></span><span><font color="#990000">);</font></span>
-
GtkWidget*  hildon_app_menu_new            (void);
+
</tt>
-
</source>
+
When the application menu is created, add entries to the menu by using the following functions:
When the application menu is created, add entries to the menu by using the following functions:
-
<source lang="c">
+
<tt> <span><font color="#009900">void</font></span>       <span>'''<span><font color="#000000">hildon_app_menu_append</font></span>'''</span>         <span><font color="#990000">(</font></span>HildonAppMenu <span><font color="#990000"><nowiki>*</nowiki></font></span>menu<span><font color="#990000">,</font></span>
-
void        hildon_app_menu_append          (HildonAppMenu *menu,
+
                                            GtkButton <span><font color="#990000"><nowiki>*</nowiki></font></span>item<span><font color="#990000">);</font></span>
-
                                    GtkButton *item);
+
<span><font color="#009900">void</font></span>       <span>'''<span><font color="#000000">hildon_app_menu_prepend</font></span>'''</span>         <span><font color="#990000">(</font></span>HildonAppMenu <span><font color="#990000"><nowiki>*</nowiki></font></span>menu<span><font color="#990000">,</font></span>
-
void        hildon_app_menu_prepend        (HildonAppMenu *menu,
+
                                            GtkButton <span><font color="#990000"><nowiki>*</nowiki></font></span>item<span><font color="#990000">);</font></span>
-
                                    GtkButton *item);
+
<span><font color="#009900">void</font></span>       <span>'''<span><font color="#000000">hildon_app_menu_insert</font></span>'''</span>         <span><font color="#990000">(</font></span>HildonAppMenu <span><font color="#990000"><nowiki>*</nowiki></font></span>menu<span><font color="#990000">,</font></span>
-
void        hildon_app_menu_insert          (HildonAppMenu *menu,
+
                                            GtkButton <span><font color="#990000"><nowiki>*</nowiki></font></span>item<span><font color="#990000">,</font></span>
-
                                    GtkButton *item,
+
                                            gint position<span><font color="#990000">);</font></span>
-
                                    gint position);
+
</tt>
-
</source>
+
These functions allow you to append, prepend an entry or add it in a certain position (from 0 to N-1, where N is the number of menus).
These functions allow you to append, prepend an entry or add it in a certain position (from 0 to N-1, where N is the number of menus).
Line 41: Line 40:
To add filter buttons, use the following:
To add filter buttons, use the following:
-
<source lang="c">
+
<tt><span><font color="#009900">void</font></span>       <span>'''<span><font color="#000000">hildon_app_menu_add_filter</font></span>'''</span>     <span><font color="#990000">(</font></span>HildonAppMenu <span><font color="#990000"><nowiki>*</nowiki></font></span>menu<span><font color="#990000">,</font></span>
-
void        hildon_app_menu_add_filter      (HildonAppMenu *menu,
+
                                            GtkButton <span><font color="#990000"><nowiki>*</nowiki></font></span>filter<span><font color="#990000">);</font></span>
-
                                            GtkButton *filter);
+
</tt>
-
</source>
+
-
Again, be careful with the number of filters that you add to the application menu. More than 4 might not be well displayed, even less, depending on the length of the labels. Filters should be grouped and act as radio buttons, that is, for any filter, at least another filter with a different/opposite action must exist. Actually, <code>GtkRadioButton</code>s can be easily used to accomplish this by having them grouped (using <code>gtk_radio_button_new_from_widget()</code> like the next example shows) and by not drawing their indicator - with the function <code>gtk_toggle_button_set_mode()</code>.
+
Again, be careful with the number of filters that you add to the application menu. More than 4 might not be well displayed, even less, depending on the length of the labels. Filters should be grouped and act as radio buttons, that is, for any filter, at least another filter with a different/opposite action must exist. Actually, GtkRadioButtons can be easily used to accomplish this by having them grouped (using <code>gtk_radio_button_new_from_widget()</code> like the next example shows) and by not drawing their indicator - with the function gtk_toggle_button_set_mode().
-
When the menu is properly created and filled up with entries and filters, add the menu to a <code>HildonWindow</code>. To set and retrieve a window's menu, use the following functions:
+
When the menu is properly created and filled up with entries and filters, add the menu to a HildonWindow. To set and retrieve a window's menu, use the following functions:
-
<source lang="c">
+
<tt> <span><font color="#009900">void</font></span>       <span>'''<span><font color="#000000">hildon_window_set_app_menu</font></span>'''</span>     <span><font color="#990000">(</font></span>HildonWindow <span><font color="#990000"><nowiki>*</nowiki></font></span>self<span><font color="#990000">,</font></span>
-
void        hildon_window_set_app_menu      (HildonWindow *self,
+
                                            HildonAppMenu <span><font color="#990000"><nowiki>*</nowiki></font></span>menu<span><font color="#990000">);</font></span>
-
                                    HildonAppMenu *menu);
+
HildonAppMenu<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_window_get_app_menu</font></span>'''</span>   <span><font color="#990000">(</font></span>HildonWindow <span><font color="#990000"><nowiki>*</nowiki></font></span>self<span><font color="#990000">);</font></span>
-
HildonAppMenu* hildon_window_get_app_menu  (HildonWindow *self);
+
</tt>
-
</source>
+
As the menu is a widget, you finally have to display it:
As the menu is a widget, you finally have to display it:
-
<source lang="c">
+
<tt>
-
void        gtk_widget_show_all          (GtkWidget *menu);
+
  <span><font color="#009900">void</font></span>       <span>'''<span><font color="#000000">gtk_widget_show_all</font></span>'''</span>         <span><font color="#990000">(</font></span>GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>menu<span><font color="#990000">);</font></span>
-
</source>
+
</tt>
The following example shows how to create and set up an application menu.
The following example shows how to create and set up an application menu.
Line 66: Line 63:
[[Image:Example-application-menu-clicked.png|frame|center|alt=Screenshot of Hildon application menu|'''Example 3.1''' Example of a Hildon application menu]]
[[Image:Example-application-menu-clicked.png|frame|center|alt=Screenshot of Hildon application menu|'''Example 3.1''' Example of a Hildon application menu]]
-
<source lang="c">
+
<tt><span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span>                                       <span><font color="#FF0000">&lt;hildon/hildon.h&gt;</font></span>
-
#include                                        <hildon/hildon.h>
+
-
 
+
<span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span>
-
static void
+
<span>'''<span><font color="#000000">menu_button_clicked</font></span>'''</span>                             <span><font color="#990000">(</font></span>GtkButton <span><font color="#990000"><nowiki>*</nowiki></font></span>button<span><font color="#990000">,</font></span>
-
menu_button_clicked                            (GtkButton *button,
+
                                                  GtkLabel <span><font color="#990000"><nowiki>*</nowiki></font></span>label<span><font color="#990000">)</font></span>
-
                                                GtkLabel *label)
+
<span><font color="#FF0000">{</font></span>
-
{
+
  <span>'''<span><font color="#0000FF">const</font></span>'''</span> <span><font color="#009900">char</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>buttontext <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_button_get_label</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">);</font></span>
-
  const char *buttontext = gtk_button_get_label (button);
+
  <span><font color="#009900">char</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>text <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">g_strdup_printf</font></span>'''</span><span><font color="#990000">(</font></span><span><font color="#FF0000">"Last option selected:</font></span><span><font color="#CC33CC">\n</font></span><span><font color="#FF0000">%s"</font></span><span><font color="#990000">,</font></span> buttontext<span><font color="#990000">);</font></span>
-
  char *text = g_strdup_printf("Last option selected:\n%s", buttontext);
+
  <span>'''<span><font color="#000000">gtk_label_set_text</font></span>'''</span> <span><font color="#990000">(</font></span>label<span><font color="#990000">,</font></span> text<span><font color="#990000">);</font></span>
-
  gtk_label_set_text (label, text);
+
  <span>'''<span><font color="#000000">g_free</font></span>'''</span> <span><font color="#990000">(</font></span>text<span><font color="#990000">);</font></span>
-
  g_free (text);
+
  <span>'''<span><font color="#000000">g_debug</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"Button clicked: %s"</font></span><span><font color="#990000">,</font></span> buttontext<span><font color="#990000">);</font></span>
-
  g_debug ("Button clicked:¬†%s", buttontext);
+
<span><font color="#FF0000">}</font></span>
-
}
+
-
 
+
<span>'''<span><font color="#0000FF">static</font></span>'''</span> HildonAppMenu <span><font color="#990000"><nowiki>*</nowiki></font></span>
-
static HildonAppMenu *
+
<span>'''<span><font color="#000000">create_menu</font></span>'''</span>                                     <span><font color="#990000">(</font></span>GtkWidget    <span><font color="#990000"><nowiki>*</nowiki></font></span>label<span><font color="#990000">)</font></span>
-
create_menu                                    (GtkWidget    *label)
+
<span><font color="#FF0000">{</font></span>
-
{
+
  <span><font color="#009900">int</font></span> i<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  int i;
+
  gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>command_id<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  gchar *command_id;
+
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span> button<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  GtkWidget * button;
+
  HildonAppMenu <span><font color="#990000"><nowiki>*</nowiki></font></span>menu <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">HILDON_APP_MENU</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">hildon_app_menu_new</font></span>'''</span> <span><font color="#990000">());</font></span>
-
  HildonAppMenu *menu = HILDON_APP_MENU (hildon_app_menu_new ());
+
-
 
+
  <span>'''<span><font color="#0000FF">for</font></span>'''</span> <span><font color="#990000">(</font></span>i <span><font color="#990000"><nowiki>=</nowiki></font></span> <span><font color="#993399">1</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span> i <span><font color="#990000">&lt;</font></span> <span><font color="#993399">6</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span> i<span><font color="#990000">++)</font></span> <span><font color="#FF0000">{</font></span>
-
  for (i = 1; i < 6; i++) {
+
    <span>''<span><font color="#9A1900">/* Create menu entries */</font></span>''</span>
-
    /* Create menu entries */
+
    button <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_gtk_button_new</font></span>'''</span> <span><font color="#990000">(</font></span>HILDON_SIZE_AUTO<span><font color="#990000">);</font></span>
-
    button = hildon_gtk_button_new (HILDON_SIZE_AUTO);
+
    command_id <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">g_strdup_printf</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"Menu command %d"</font></span><span><font color="#990000">,</font></span> i<span><font color="#990000">);</font></span>
-
    command_id = g_strdup_printf ("Menu command¬†%d", i);
+
    <span>'''<span><font color="#000000">gtk_button_set_label</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">),</font></span> command_id<span><font color="#990000">);</font></span>
-
    gtk_button_set_label (GTK_BUTTON (button), command_id);
+
-
 
+
    <span>''<span><font color="#9A1900">/* Attach callback to clicked signal */</font></span>''</span>
-
    /* Attach callback to clicked signal */
+
    <span>'''<span><font color="#000000">g_signal_connect_after</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">,</font></span> <span><font color="#FF0000">"clicked"</font></span><span><font color="#990000">,</font></span>
-
    g_signal_connect_after (button, "clicked",
+
                            <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>menu_button_clicked<span><font color="#990000">),</font></span>
-
                            G_CALLBACK (menu_button_clicked),
+
                            label<span><font color="#990000">);</font></span>
-
                            label);
+
-
 
+
    <span>''<span><font color="#9A1900">/* Add entry to the view menu */</font></span>''</span>
-
    /* Add entry to the view menu */
+
    <span>'''<span><font color="#000000">hildon_app_menu_append</font></span>'''</span> <span><font color="#990000">(</font></span>menu<span><font color="#990000">,</font></span> <span>'''<span><font color="#000000">GTK_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">));</font></span>
-
    hildon_app_menu_append (menu, GTK_BUTTON (button));
+
  <span><font color="#FF0000">}</font></span>
-
  }
+
-
 
+
  <span>''<span><font color="#9A1900">/* Create filters */</font></span>''</span>
-
  /* Create filters */
+
  button <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_gtk_radio_button_new</font></span>'''</span> <span><font color="#990000">(</font></span>HILDON_SIZE_AUTO<span><font color="#990000">,</font></span> NULL<span><font color="#990000">);</font></span>
-
  button = hildon_gtk_radio_button_new (HILDON_SIZE_AUTO, NULL);
+
  <span>'''<span><font color="#000000">gtk_button_set_label</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">),</font></span> <span><font color="#FF0000">"filter one"</font></span><span><font color="#990000">);</font></span>
-
  gtk_button_set_label (GTK_BUTTON (button), "filter one");
+
  <span>'''<span><font color="#000000">g_signal_connect_after</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">,</font></span> <span><font color="#FF0000">"clicked"</font></span><span><font color="#990000">,</font></span> <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>menu_button_clicked<span><font color="#990000">),</font></span> label<span><font color="#990000">);</font></span>
-
  g_signal_connect_after (button, "clicked", G_CALLBACK (menu_button_clicked), label);
+
  <span>'''<span><font color="#000000">hildon_app_menu_add_filter</font></span>'''</span> <span><font color="#990000">(</font></span>menu<span><font color="#990000">,</font></span> <span>'''<span><font color="#000000">GTK_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">));</font></span>
-
  hildon_app_menu_add_filter (menu, GTK_BUTTON (button));
+
  <span>'''<span><font color="#000000">gtk_toggle_button_set_mode</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_TOGGLE_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">),</font></span> FALSE<span><font color="#990000">);</font></span>
-
  gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
+
-
 
+
  button <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_gtk_radio_button_new_from_widget</font></span>'''</span> <span><font color="#990000">(</font></span>HILDON_SIZE_AUTO<span><font color="#990000">,</font></span>
-
  button = hildon_gtk_radio_button_new_from_widget (HILDON_SIZE_AUTO,
+
                                                    <span>'''<span><font color="#000000">GTK_RADIO_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">));</font></span>
-
                                                    GTK_RADIO_BUTTON (button));
+
  <span>'''<span><font color="#000000">gtk_button_set_label</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">),</font></span> <span><font color="#FF0000">"filter two"</font></span><span><font color="#990000">);</font></span>
-
  gtk_button_set_label (GTK_BUTTON (button), "filter two");
+
  <span>'''<span><font color="#000000">g_signal_connect_after</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">,</font></span> <span><font color="#FF0000">"clicked"</font></span><span><font color="#990000">,</font></span> <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>menu_button_clicked<span><font color="#990000">),</font></span> label<span><font color="#990000">);</font></span>
-
  g_signal_connect_after (button, "clicked", G_CALLBACK (menu_button_clicked), label);
+
  <span>'''<span><font color="#000000">hildon_app_menu_add_filter</font></span>'''</span> <span><font color="#990000">(</font></span>menu<span><font color="#990000">,</font></span> <span>'''<span><font color="#000000">GTK_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">));</font></span>
-
  hildon_app_menu_add_filter (menu, GTK_BUTTON (button));
+
  <span>'''<span><font color="#000000">gtk_toggle_button_set_mode</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_TOGGLE_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">),</font></span> FALSE<span><font color="#990000">);</font></span>
-
  gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
+
-
 
+
  <span>'''<span><font color="#000000">gtk_widget_show_all</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_WIDGET</font></span>'''</span> <span><font color="#990000">(</font></span>menu<span><font color="#990000">));</font></span>
-
  gtk_widget_show_all (GTK_WIDGET (menu));
+
-
 
+
  <span>'''<span><font color="#0000FF">return</font></span>'''</span> menu<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  return menu;
+
<span><font color="#FF0000">}</font></span>
-
}
+
-
 
+
<span><font color="#009900">int</font></span>
-
int
+
<span>'''<span><font color="#000000">main</font></span>'''</span>                                           <span><font color="#990000">(</font></span><span><font color="#009900">int</font></span> argc<span><font color="#990000">,</font></span>
-
main                                            (int argc,
+
                                                  <span><font color="#009900">char</font></span> <span><font color="#990000"><nowiki>**</nowiki></font></span>argv<span><font color="#990000">)</font></span>
-
                                                char **argv)
+
<span><font color="#FF0000">{</font></span>
-
{
+
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>win<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  GtkWidget *win;
+
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>label<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  GtkWidget *label;
+
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>label2<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  GtkWidget *label2;
+
  GtkBox <span><font color="#990000"><nowiki>*</nowiki></font></span>vbox<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  GtkBox *vbox;
+
  HildonAppMenu <span><font color="#990000"><nowiki>*</nowiki></font></span>menu<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  HildonAppMenu *menu;
+
-
 
+
  <span>'''<span><font color="#000000">hildon_gtk_init</font></span>'''</span> <span><font color="#990000">(&amp;</font></span>argc<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>argv<span><font color="#990000">);</font></span>
-
  hildon_gtk_init (&argc, &argv);
+
-
 
+
  win <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_stackable_window_new</font></span>'''</span> <span><font color="#990000">();</font></span>
-
  win = hildon_stackable_window_new ();
+
-
 
+
  <span>''<span><font color="#9A1900">/* Create and pack labels */</font></span>''</span>
-
  /* Create and pack labels */
+
  label <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_label_new</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"This is an example of the</font></span><span><font color="#CC33CC">\n</font></span><span><font color="#FF0000">HildonAppMenu widget.</font></span><span><font color="#CC33CC">\n\n</font></span><span><font color="#FF0000">"</font></span>
-
  label = gtk_label_new ("This is an example of the\nHildonAppMenu widget.\n\n"
+
                          <span><font color="#FF0000">"Click on the titlebar</font></span><span><font color="#CC33CC">\n</font></span><span><font color="#FF0000">to pop up the menu."</font></span><span><font color="#990000">);</font></span>
-
                        "Click on the titlebar\nto pop up the menu.");
+
  label2 <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_label_new</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"No menu option has been selected yet."</font></span><span><font color="#990000">);</font></span>
-
  label2 = gtk_label_new ("No menu option has been selected yet.");
+
-
 
+
  <span>'''<span><font color="#000000">gtk_label_set_justify</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_LABEL</font></span>'''</span> <span><font color="#990000">(</font></span>label<span><font color="#990000">),</font></span> GTK_JUSTIFY_CENTER<span><font color="#990000">);</font></span>
-
  gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
+
  <span>'''<span><font color="#000000">gtk_label_set_justify</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_LABEL</font></span>'''</span> <span><font color="#990000">(</font></span>label2<span><font color="#990000">),</font></span> GTK_JUSTIFY_CENTER<span><font color="#990000">);</font></span>
-
  gtk_label_set_justify (GTK_LABEL (label2), GTK_JUSTIFY_CENTER);
+
-
 
+
  vbox <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">GTK_BOX</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">gtk_vbox_new</font></span>'''</span> <span><font color="#990000">(</font></span>FALSE<span><font color="#990000">,</font></span> <span><font color="#993399">10</font></span><span><font color="#990000">));</font></span>
-
  vbox = GTK_BOX (gtk_vbox_new (FALSE, 10));
+
-
 
+
  <span>'''<span><font color="#000000">gtk_box_pack_start</font></span>'''</span> <span><font color="#990000">(</font></span>vbox<span><font color="#990000">,</font></span> label<span><font color="#990000">,</font></span> TRUE<span><font color="#990000">,</font></span> TRUE<span><font color="#990000">,</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">);</font></span>
-
  gtk_box_pack_start (vbox, label, TRUE, TRUE, 0);
+
  <span>'''<span><font color="#000000">gtk_box_pack_start</font></span>'''</span> <span><font color="#990000">(</font></span>vbox<span><font color="#990000">,</font></span> label2<span><font color="#990000">,</font></span> TRUE<span><font color="#990000">,</font></span> TRUE<span><font color="#990000">,</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">);</font></span>
-
  gtk_box_pack_start (vbox, label2, TRUE, TRUE, 0);
+
-
 
+
  <span>''<span><font color="#9A1900">/* Create menu */</font></span>''</span>
-
  /* Create menu */
+
  menu <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">create_menu</font></span>'''</span> <span><font color="#990000">(</font></span>label2<span><font color="#990000">);</font></span>
-
  menu = create_menu (label2);
+
-
 
+
  <span>''<span><font color="#9A1900">/* Attach menu to the window */</font></span>''</span>
-
  /* Attach menu to the window */
+
  <span>'''<span><font color="#000000">hildon_window_set_app_menu</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">HILDON_WINDOW</font></span>'''</span> <span><font color="#990000">(</font></span>win<span><font color="#990000">),</font></span> menu<span><font color="#990000">);</font></span>
-
  hildon_window_set_app_menu (HILDON_WINDOW (win), menu);
+
-
 
+
  <span>''<span><font color="#9A1900">/* Add label's box to window */</font></span>''</span>
-
  /* Add label's box to window */
+
  <span>'''<span><font color="#000000">gtk_container_add</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_CONTAINER</font></span>'''</span> <span><font color="#990000">(</font></span>win<span><font color="#990000">),</font></span> <span>'''<span><font color="#000000">GTK_WIDGET</font></span>'''</span> <span><font color="#990000">(</font></span>vbox<span><font color="#990000">));</font></span>
-
  gtk_container_add (GTK_CONTAINER (win), GTK_WIDGET (vbox));
+
-
 
+
  <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span>win<span><font color="#990000">,</font></span> <span><font color="#FF0000">"delete_event"</font></span><span><font color="#990000">,</font></span> <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>gtk_main_quit<span><font color="#990000">),</font></span> NULL<span><font color="#990000">);</font></span>
-
  g_signal_connect (win, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
+
-
 
+
  <span>'''<span><font color="#000000">gtk_widget_show_all</font></span>'''</span> <span><font color="#990000">(</font></span>win<span><font color="#990000">);</font></span>
-
  gtk_widget_show_all (win);
+
-
 
+
  <span>'''<span><font color="#000000">gtk_main</font></span>'''</span> <span><font color="#990000">();</font></span>
-
  gtk_main ();
+
-
 
+
  <span>'''<span><font color="#0000FF">return</font></span>'''</span> <span><font color="#993399">0</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  return 0;
+
<span><font color="#FF0000">}</font></span>
-
}
+
</tt>
-
</source>
+
[[Image:Example-application-menu.png|frame|center|alt=Screenshot of HildonAppMenu application before menu is displayed|Example HildonAppMenu, before displaying the menu]]
[[Image:Example-application-menu.png|frame|center|alt=Screenshot of HildonAppMenu application before menu is displayed|Example HildonAppMenu, before displaying the menu]]
Line 172: Line 168:
Each entry and filter button in this example is attached to a function that simply changes a label in the main window.
Each entry and filter button in this example is attached to a function that simply changes a label in the main window.
-
Note that the function used to attach handlers to the entries is <code>g_signal_connect_after()</code>. So the handler are called after the default handler of the signal "<code>clicked</code>". The default handler for entries and filters closes the menu.
+
Note that the function used to attach handlers to the entries is <code>g_signal_connect_after()</code>. So the handler are called after the default handler of the signal "clicked". The default handler for entries and filters closes the menu.
==Application menus and views ==
==Application menus and views ==
-
 
The previous example had only one view. In applications with several views, you can attach a different menu to each view and add only the options that are relevant to the displayed view.
The previous example had only one view. In applications with several views, you can attach a different menu to each view and add only the options that are relevant to the displayed view.
-
The function <code>hildon_window_set_app_menu()</code>allows to set a menu to an HildonWindow and its descendant <code>HildonStackableWindow</code> widget.
+
The function <code>hildon_window_set_app_menu()</code>allows to set a menu to an HildonWindow and its descendant HildonStackableWindow widget.
-
<source lang="c">
+
<tt> <span>'''<span><font color="#000000">hildon_window_set_app_menu</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">HILDON_STACKABLE_WINDOW</font></span>'''</span> <span><font color="#990000">(</font></span>win<span><font color="#990000">),</font></span> menu<span><font color="#990000">);</font></span>
-
hildon_window_set_app_menu (HILDON_STACKABLE_WINDOW (win), menu);
+
</tt>
-
</source>
+
Note that submenus are not supported by view menus. Usually a menu item that would have suboptions in a desktop application is implemented as a new subview in a Hildon application.
Note that submenus are not supported by view menus. Usually a menu item that would have suboptions in a desktop application is implemented as a new subview in a Hildon application.
-
A callback function for a complex menu entry can create a new <code>HildonStackableWindow</code> to accomplish the task that the option refers to. The new window can contain a different view menu to contain buttons to perform the action. The buttons can even reside in the window area.
+
A callback function for a complex menu entry can create a new HildonStackableWindow to accomplish the task that the option refers to. The new window can contain a different view menu to contain buttons to perform the action. The buttons can even reside in the window area.
-
==Context menu ==
 
 +
==Context menu ==
Context menu is usually invoked through a long press over an item on the screen, like holding a finger over an image thumbnail. The menu must contain commands directly related to the chosen item.
Context menu is usually invoked through a long press over an item on the screen, like holding a finger over an image thumbnail. The menu must contain commands directly related to the chosen item.
-
Avoid using context menus, because they are a hidden and inconvenient way of interacting with the UI. Use <code>HildonAppMenu</code>s instead.
+
Avoid using context menus, because they are a hidden and inconvenient way of interacting with the UI. Use HildonAppMenus instead.
-
To create a <code>GtkMenu</code> in a Hildon application, use the following function instead of <code>gtk_menu_new()</code>:
+
To create a GtkMenu in a Hildon application, use the following function instead of <code>gtk_menu_new()</code><nowiki>: </nowiki>
-
<source lang="c">
+
<tt>GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_gtk_menu_new</font></span>'''</span>             <span><font color="#990000">(</font></span><span><font color="#009900">void</font></span><span><font color="#990000">);</font></span>
-
GtkWidget*  hildon_gtk_menu_new            (void);
+
</tt>
-
</source>
+
-
This function creates a <code>GtkMenu</code> that allows Hildon specific styling.
+
This function creates a GtkMenu that allows Hildon specific styling.
-
When you use a <code>GtkMenu</code> in your Hildon application, consider how many menu items you are going to use, because screen space is limited. Also consider the fact that in the interests of keeping the UI clear, submenus are not allowed.
+
When you use a GtkMenu in your Hildon application, consider how many menu items you are going to use, because screen space is limited. Also consider the fact that in the interests of keeping the UI clear, submenus are not allowed.
<hr/>
<hr/>

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)

Templates used on this page: