Legacy Maemo 5 Documentation/Graphical UI Tutorial/Toolbars

(Edit toolbars: Example 4.2. Using an Edit Toolbar: recovered correct snippet)
(wikify slightly)
 
(6 intermediate revisions not shown)
Line 1: Line 1:
-
= Toolbars =
+
{{Legacy documentation}}
-
Toolbars usually simplify the customization of widget look and layout by grouping widgets. The Hildon framework provides two specialized toolbars: HildonFindToolbar and HildonEditToolbar. You can also use GtkToolbars in your Hildon application.
+
 +
Toolbars usually simplify the customization of widget look and layout by grouping widgets. The Hildon framework provides two specialized toolbars: <code>HildonFindToolbar</code> and <code>HildonEditToolbar</code>. You can also use <code>GtkToolbar</code>s in your Hildon application.
==Find toolbars ==
==Find toolbars ==
-
HildonFindToolbar is a toolbar that contains a search entry and a dropdown list with previously searched strings. An internal GtkListStore stores the items in the dropdown list. This list is a property of the widget called "list".
 
-
To create a HildonFindToolbar, use the following:
+
<code>HildonFindToolbar</code> is a toolbar that contains a search entry and a dropdown list with previously searched strings. An internal <code>GtkListStore</code> stores the items in the dropdown list. This list is a property of the widget called "<code>list</code>".
-
<tt>GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_find_toolbar_new</font></span>'''</span>           <span><font color="#990000">(</font></span><span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>label<span><font color="#990000">);</font></span>
+
To create a <code>HildonFindToolbar</code>, use the following:
-
GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_find_toolbar_new_with_model</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>label<span><font color="#990000">,</font></span>
+
 
-
                                                GtkListStore <span><font color="#990000"><nowiki>*</nowiki></font></span>model<span><font color="#990000">,</font></span>
+
<source lang="c">
-
                                                gint column<span><font color="#990000">);</font></span>
+
GtkWidget*  hildon_find_toolbar_new            (const gchar *label);
-
</tt>
+
GtkWidget*  hildon_find_toolbar_new_with_model (const gchar *label,
 +
                                                GtkListStore *model,
 +
                                                gint column);
 +
</source>
In both functions the argument label is used as label which be displayed as label for the dropdown box.
In both functions the argument label is used as label which be displayed as label for the dropdown box.
Line 18: Line 20:
The second function above allows you to set the model used for storing the dropdown box. Also indicate which column the search retrieves the string from.
The second function above allows you to set the model used for storing the dropdown box. Also indicate which column the search retrieves the string from.
-
If you use the first function to create the toolbar, set the properties "list" and "column" manually.
+
If you use the first function to create the toolbar, set the properties "<code>list</code>" and "<code>column</code>" manually.
-
This widget provides the function f for set and retrieve the index in the model of the current active item on the combo. An index -1 indicates no active items in both functions.
+
This widget provides the function <code>f</code> to set and retrieve the index in the model of the current active item on the combo. An index of <code>-1</code> indicates no active items in both functions.
-
<tt><span><font color="#009900">void</font></span>       <span>'''<span><font color="#000000">hildon_find_toolbar_set_active</font></span>'''</span> <span><font color="#990000">(</font></span>HildonFindToolbar <span><font color="#990000"><nowiki>*</nowiki></font></span>toolbar<span><font color="#990000">,</font></span>
+
<source lang="c">
-
                                              gint index<span><font color="#990000">);</font></span>
+
void        hildon_find_toolbar_set_active  (HildonFindToolbar *toolbar,
-
gint        <span>'''<span><font color="#000000">hildon_find_toolbar_get_active</font></span>'''</span> <span><font color="#990000">(</font></span>HildonFindToolbar <span><font color="#990000"><nowiki>*</nowiki></font></span>toolbar<span><font color="#990000">);</font></span>
+
                                            gint index);
-
</tt>
+
gint        hildon_find_toolbar_get_active  (HildonFindToolbar *toolbar);
 +
</source>
To get the index of the most recently added item in the toolbar, use the following function:
To get the index of the most recently added item in the toolbar, use the following function:
-
<tt>gint32      <span>'''<span><font color="#000000">hildon_find_toolbar_get_last_index</font></span>'''</span> <span><font color="#990000">(</font></span>HildonFindToolbar <span><font color="#990000"><nowiki>*</nowiki></font></span>toolbar<span><font color="#990000">);</font></span>
+
<source lang="c">
-
</tt>
+
gint32      hildon_find_toolbar_get_last_index (HildonFindToolbar *toolbar);
 +
</source>
-
Alternatively, you can use a GtkTreeIter to reference the current active item.
+
Alternatively, you can use a <code>GtkTreeIter</code> to reference the current active item.
-
<tt><span><font color="#990000">\</font></span>begin<span><font color="#FF0000">{</font></span>verbatim<span><font color="#FF0000">}</font></span>
+
<source lang="c">
-
<span><font color="#009900">void</font></span>       <span>'''<span><font color="#000000">hildon_find_toolbar_set_active_iter</font></span>'''</span> <span><font color="#990000">(</font></span>HildonFindToolbar <span><font color="#990000"><nowiki>*</nowiki></font></span>toolbar<span><font color="#990000">,</font></span>
+
void        hildon_find_toolbar_set_active_iter (HildonFindToolbar *toolbar,
-
                                                  GtkTreeIter <span><font color="#990000"><nowiki>*</nowiki></font></span>iter<span><font color="#990000">);</font></span>
+
                                                GtkTreeIter *iter);
-
gboolean    <span>'''<span><font color="#000000">hildon_find_toolbar_get_active_iter</font></span>'''</span> <span><font color="#990000">(</font></span>HildonFindToolbar <span><font color="#990000"><nowiki>*</nowiki></font></span>toolbar<span><font color="#990000">,</font></span>
+
gboolean    hildon_find_toolbar_get_active_iter (HildonFindToolbar *toolbar,
-
                                                  GtkTreeIter <span><font color="#990000"><nowiki>*</nowiki></font></span>iter<span><font color="#990000">);</font></span>
+
                                                GtkTreeIter *iter);
-
</tt>
+
</source>
-
After create and properly set up the toolbar is necessary to attach it to any window. HildonWindow provides the following function to attach a toolbar:
+
After creating and properly setting up the toolbar, attach it to any window. <code>HildonWindow</code> provides the following function to attach a toolbar:
-
<tt><span><font color="#009900">void</font></span>       <span>'''<span><font color="#000000">hildon_window_add_toolbar</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>
+
<source lang="c">
-
                                              GtkToolbar <span><font color="#990000"><nowiki>*</nowiki></font></span>toolbar<span><font color="#990000">);</font></span>
+
void        hildon_window_add_toolbar      (HildonWindow *self,
-
</tt>
+
                                            GtkToolbar *toolbar);
 +
</source>
-
In case you need to add a common toolbar to all windows in your program, HildonProgram provides the following function to set and retrtieve a common toolbar to each window registered into the curretn program:
+
In case you need to add a common toolbar to all windows in your program, <code>HildonProgram</code> provides the following function to set and retrieve a common toolbar to each window registered into the current program:
-
<tt><span><font color="#009900">void</font></span>       <span>'''<span><font color="#000000">hildon_program_set_common_toolbar</font></span>'''</span> <span><font color="#990000">(</font></span>HildonProgram <span><font color="#990000"><nowiki>*</nowiki></font></span>self<span><font color="#990000">,</font></span>
+
<source lang="c">
-
                                                GtkToolbar <span><font color="#990000"><nowiki>*</nowiki></font></span>toolbar<span><font color="#990000">);</font></span>
+
void        hildon_program_set_common_toolbar (HildonProgram *self,
-
GtkToolbar<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_program_get_common_toolbar</font></span>'''</span> <span><font color="#990000">(</font></span>HildonProgram <span><font color="#990000"><nowiki>*</nowiki></font></span>self<span><font color="#990000">);</font></span>
+
                                              GtkToolbar *toolbar);
-
</tt>
+
GtkToolbar* hildon_program_get_common_toolbar (HildonProgram *self);
 +
</source>
Here a simple example that shows how to deal with a HildonFindToolbar.
Here a simple example that shows how to deal with a HildonFindToolbar.
-
[[Image:example-toolbar.png|400px]]
+
[[Image:example-toolbar.png|frame|center|alt=Screenshot of example toolbar|'''Example 4.1''' Using a Find Toolbar]]
-
'''Example 4.1. Using a Find Toolbar'''
+
<source lang="c">
 +
#include <hildon/hildon.h>
 +
gboolean
 +
on_history_append (HildonFindToolbar *toolbar,
 +
                  gpointer user_data)
 +
{
 +
  gchar *item;
 +
  GtkTreeIter iter;
 +
  gint index ;
 +
  GtkListStore *list;
 +
  /* Get last added index */
 +
  index = hildon_find_toolbar_get_last_index (toolbar);
 +
  /* Get the inner list */
 +
  g_object_get (G_OBJECT (toolbar),
 +
                "list",&list,
 +
                NULL);
 +
  /* Get the item */
 +
  gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (list) ,
 +
                                      &iter,
 +
                                      g_strdup_printf ("%d",index));
 +
  gtk_tree_model_get (GTK_TREE_MODEL (list),
 +
                      &iter,
 +
                      0, &item,
 +
                      -1);
 +
  g_debug ("ADDED TO THE LIST : %s", item);
 +
  return FALSE;
 +
}
 +
                                                                                                                          int main (int argc, char **argv)
 +
{
 +
  HildonProgram *program;
 +
  GtkWidget *window;
 +
  GtkWidget *toolbar = NULL;
 +
  GtkListStore *store;
 +
  GtkTreeIter iter;
 +
  hildon_gtk_init (&argc, &argv);
 +
  program = hildon_program_get_instance ();
 +
  window = hildon_window_new ();
 +
  hildon_program_add_window (program, HILDON_WINDOW (window));
 +
  /* Create and populate history list model */
 +
  store = gtk_list_store_new (1, G_TYPE_STRING);
 +
  gtk_list_store_append (store, &iter);
 +
  gtk_list_store_set (store, &iter, 0, "Foo", -1);
 +
  gtk_list_store_append (store, &iter);
 +
  gtk_list_store_set (store, &iter, 0, "Bar", -1);
 +
  gtk_list_store_append (store, &iter);
 +
  gtk_list_store_set (store, &iter, 0, "Baz", -1);
 +
  /* Create find toolbar */
 +
  toolbar = hildon_find_toolbar_new_with_model ("Find", store, 0);
 +
  /* Set item on index 0 as the current active*/
 +
  hildon_find_toolbar_set_active (HILDON_FIND_TOOLBAR (toolbar), 0);
 +
  /* Attach a callback to handle "history-append" signal */
 +
  g_signal_connect_after (G_OBJECT (toolbar), "history-append", G_CALLBACK (on_history_append), NULL);
 +
  /* Attach toolbar to window */
 +
  hildon_window_add_toolbar (HILDON_WINDOW (window), GTK_TOOLBAR (toolbar));
 +
  gtk_widget_show_all (GTK_WIDGET (window));
 +
  gtk_main ();
 +
  return 0;
 +
}
 +
</source>
-
<tt><span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span>                                        <span><font color="#FF0000">&lt;hildon/hildon.h&gt;</font></span>
+
In the example above a callback is set to handle the signal "<code>history-append</code>", emitted by the toolbar when a new item is added to the history. Other signals like "history-append" can trigger additional actions when emitted.
-
gboolean
+
-
<span>'''<span><font color="#000000">on_history_append</font></span>'''</span>                              <span><font color="#990000">(</font></span>HildonFindToolbar <span><font color="#990000"><nowiki>*</nowiki></font></span>toolbar<span><font color="#990000">,</font></span>
+
-
                                                  gpointer          user_data<span><font color="#990000">)</font></span>
+
-
<span><font color="#FF0000">{</font></span>
+
-
  gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>item<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
-
  GtkTreeIter iter<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
-
  gint index <span><font color="#990000"><nowiki>;</nowiki></font></span>
+
-
  GtkListStore <span><font color="#990000"><nowiki>*</nowiki></font></span>list<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
-
  <span>''<span><font color="#9A1900">/* Get last added index */</font></span>''</span>
+
-
  index <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_find_toolbar_get_last_index</font></span>'''</span> <span><font color="#990000">(</font></span>toolbar<span><font color="#990000">);</font></span>
+
-
  <span>''<span><font color="#9A1900">/* Get the inner list */</font></span>''</span>
+
-
  <span>'''<span><font color="#000000">g_object_get</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>toolbar<span><font color="#990000">),</font></span>
+
-
                <span><font color="#FF0000">"list"</font></span><span><font color="#990000">,&amp;</font></span>list<span><font color="#990000">,</font></span>
+
-
                NULL<span><font color="#990000">);</font></span>
+
-
  <span>''<span><font color="#9A1900">/* Get the item */</font></span>''</span>
+
-
  <span>'''<span><font color="#000000">gtk_tree_model_get_iter_from_string</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_TREE_MODEL</font></span>'''</span> <span><font color="#990000">(</font></span>list<span><font color="#990000">)</font></span> <span><font color="#990000">,</font></span>
+
-
                                        <span><font color="#990000">&amp;</font></span>iter<span><font color="#990000">,</font></span>
+
-
                                        <span>'''<span><font color="#000000">g_strdup_printf</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"%d"</font></span><span><font color="#990000">,</font></span>index<span><font color="#990000">));</font></span>
+
-
  <span>'''<span><font color="#000000">gtk_tree_model_get</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_TREE_MODEL</font></span>'''</span> <span><font color="#990000">(</font></span>list<span><font color="#990000">),</font></span>
+
-
                      <span><font color="#990000">&amp;</font></span>iter<span><font color="#990000">,</font></span>
+
-
                      <span><font color="#993399">0</font></span><span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>item<span><font color="#990000">,</font></span>
+
-
                      <span><font color="#990000">-</font></span><span><font color="#993399">1</font></span><span><font color="#990000">);</font></span>
+
-
  <span>'''<span><font color="#000000">g_debug</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"ADDED TO THE LIST : %s"</font></span><span><font color="#990000">,</font></span> item<span><font color="#990000">);</font></span>
+
-
  <span>'''<span><font color="#0000FF">return</font></span>'''</span> FALSE<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
-
<span><font color="#FF0000">}</font></span>
+
-
<span><font color="#009900">int</font></span>
+
-
<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>
+
-
                                                  <span><font color="#009900">char</font></span> <span><font color="#990000"><nowiki>**</nowiki></font></span>argv<span><font color="#990000">)</font></span>
+
-
<span><font color="#FF0000">{</font></span>
+
-
  HildonProgram <span><font color="#990000"><nowiki>*</nowiki></font></span>program<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
-
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>window<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
-
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>toolbar <span><font color="#990000"><nowiki>=</nowiki></font></span> NULL<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
-
  GtkListStore <span><font color="#990000"><nowiki>*</nowiki></font></span>store<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
-
  GtkTreeIter iter<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
-
  <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>
+
-
  program <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_program_get_instance</font></span>'''</span> <span><font color="#990000">();</font></span>
+
-
  window <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_window_new</font></span>'''</span> <span><font color="#990000">();</font></span>
+
-
  <span>'''<span><font color="#000000">hildon_program_add_window</font></span>'''</span> <span><font color="#990000">(</font></span>program<span><font color="#990000">,</font></span> <span>'''<span><font color="#000000">HILDON_WINDOW</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">));</font></span>
+
-
  <span>''<span><font color="#9A1900">/* Create and populate history list model */</font></span>''</span>
+
-
  store <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_list_store_new</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#993399">1</font></span><span><font color="#990000">,</font></span> G_TYPE_STRING<span><font color="#990000">);</font></span>
+
-
  <span>'''<span><font color="#000000">gtk_list_store_append</font></span>'''</span> <span><font color="#990000">(</font></span>store<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>iter<span><font color="#990000">);</font></span>
+
-
  <span>'''<span><font color="#000000">gtk_list_store_set</font></span>'''</span> <span><font color="#990000">(</font></span>store<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>iter<span><font color="#990000">,</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">,</font></span> <span><font color="#FF0000">"Foo"</font></span><span><font color="#990000">,</font></span> <span><font color="#990000">-</font></span><span><font color="#993399">1</font></span><span><font color="#990000">);</font></span>
+
-
  <span>'''<span><font color="#000000">gtk_list_store_append</font></span>'''</span> <span><font color="#990000">(</font></span>store<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>iter<span><font color="#990000">);</font></span>
+
-
  <span>'''<span><font color="#000000">gtk_list_store_set</font></span>'''</span> <span><font color="#990000">(</font></span>store<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>iter<span><font color="#990000">,</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">,</font></span> <span><font color="#FF0000">"Bar"</font></span><span><font color="#990000">,</font></span> <span><font color="#990000">-</font></span><span><font color="#993399">1</font></span><span><font color="#990000">);</font></span>
+
-
  <span>'''<span><font color="#000000">gtk_list_store_append</font></span>'''</span> <span><font color="#990000">(</font></span>store<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>iter<span><font color="#990000">);</font></span>
+
-
  <span>'''<span><font color="#000000">gtk_list_store_set</font></span>'''</span> <span><font color="#990000">(</font></span>store<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>iter<span><font color="#990000">,</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">,</font></span> <span><font color="#FF0000">"Baz"</font></span><span><font color="#990000">,</font></span> <span><font color="#990000">-</font></span><span><font color="#993399">1</font></span><span><font color="#990000">);</font></span>
+
-
  <span>''<span><font color="#9A1900">/* Create find toolbar */</font></span>''</span>
+
-
  toolbar <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_find_toolbar_new_with_model</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"Find"</font></span><span><font color="#990000">,</font></span> store<span><font color="#990000">,</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">);</font></span>
+
-
  <span>''<span><font color="#9A1900">/* Set item on index 0 as the current active*/</font></span>''</span>
+
-
  <span>'''<span><font color="#000000">hildon_find_toolbar_set_active</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">HILDON_FIND_TOOLBAR</font></span>'''</span> <span><font color="#990000">(</font></span>toolbar<span><font color="#990000">),</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">);</font></span>
+
-
  <span>''<span><font color="#9A1900">/* Attach a callback to handle "history-append" signal */</font></span>''</span>
+
-
  <span>'''<span><font color="#000000">g_signal_connect_after</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>toolbar<span><font color="#990000">),</font></span> <span><font color="#FF0000">"history-append"</font></span><span><font color="#990000">,</font></span> <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>on_history_append<span><font color="#990000">),</font></span> NULL<span><font color="#990000">);</font></span>
+
-
  <span>''<span><font color="#9A1900">/* Attach toolbar to window */</font></span>''</span>
+
-
  <span>'''<span><font color="#000000">hildon_window_add_toolbar</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>window<span><font color="#990000">),</font></span> <span>'''<span><font color="#000000">GTK_TOOLBAR</font></span>'''</span> <span><font color="#990000">(</font></span>toolbar<span><font color="#990000">));</font></span>
+
-
  <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>window<span><font color="#990000">));</font></span>
+
-
  <span>'''<span><font color="#000000">gtk_main</font></span>'''</span> <span><font color="#990000">();</font></span>
+
-
  <span>'''<span><font color="#0000FF">return</font></span>'''</span> <span><font color="#993399">0</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span>
+
-
<span><font color="#FF0000">}</font></span>
+
-
</tt>
+
-
In the example above a callback is set to handle the signal "history-append", emitted by the toolbar when a new item is added to the history. Other signals like, for example, "history-append" could trigger additional actions when emitted.
+
Apart from the property which stores the internal list, other properties are available such as "max-characters", which set the maximum length of the search string. For a complete description of the signals and properties available, see the Hildon reference manual.
-
 
+
-
Apart from the property which stores the internal list, other properties are available such as "max-characters" , which set the maximum length of the search string. To a complete description of the signals and properties available read the Hildon reference manual.
+
==Edit toolbars ==
==Edit toolbars ==
-
Edit toolbars are implemented by the widget HildonEditToolbar. This widget is a toolbar to be used as main control and navigation interface for the edit UI mode. The toolbar contains a label and two buttons, being one of them an arrow pointing backwards and the other a button to perform a certain action. It also display a label which explain to the users the action that the button performs and give intructions to user on how to perform the action properly.
+
 
 +
Edit toolbars are implemented by the widget <code>HildonEditToolbar</code>. This widget is a toolbar to be used as main control and navigation interface for the edit UI mode. The toolbar contains a label and two buttons, being one of them an arrow pointing backwards and the other a button to perform a certain action. It also display a label which explain to the users the action that the button performs and give intructions to user on how to perform the action properly.
A typical example could be a view to delete several items in a list. The label would advice the user to select the items to delete and those items are deleted by clicking the button.
A typical example could be a view to delete several items in a list. The label would advice the user to select the items to delete and those items are deleted by clicking the button.
-
Typically, the toolbar is attached to an edit view, meaning a HildonStackableWindow used in the program to perform a certain editing action.
+
Typically, the toolbar is attached to an edit view, meaning a <code>HildonStackableWindow</code> used in the program to perform a certain editing action.
-
The action to be performing by clicking the action button should be implemented in a callback to handle the signal "button-clicked", shown in the example.
+
The action to be performing by clicking the action button should be implemented in a callback to handle the signal "<code>button-clicked</code>", shown in the example.
-
To create a new HildonEditToolbar you should use:
+
To create a new <code>HildonEditToolbar</code>, use:
-
<tt>GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_edit_toolbar_new</font></span>'''</span>           <span><font color="#990000">(</font></span><span><font color="#009900">void</font></span><span><font color="#990000">);</font></span>
+
<source lang="c">
-
GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_edit_toolbar_new_with_text</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>label<span><font color="#990000">,</font></span>
+
GtkWidget*  hildon_edit_toolbar_new          (void);
-
                                                <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>button<span><font color="#990000">);</font></span>
+
GtkWidget*  hildon_edit_toolbar_new_with_text (const gchar *label,
-
</tt>
+
                                              const gchar *button);
 +
</source>
-
The second creation function allows to set the two labels of the widget. If you use the simple creation function, you should set the labels by using the following functions.
+
The second creation function allows to set the two labels of the widget. If you use the simple creation function, set the labels by using the following functions.
-
<tt><span><font color="#009900">void</font></span>        <span>'''<span><font color="#000000">hildon_window_add_toolbar</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>
+
<source lang="c">
-
                                              GtkToolbar <span><font color="#990000"><nowiki>*</nowiki></font></span>toolbar<span><font color="#990000">);</font></span>
+
void               hildon_edit_toolbar_set_label       (HildonEditToolbar *toolbar,
-
</tt>
+
                                                        const gchar *label);
 +
void                hildon_edit_toolbar_set_button_label
 +
                                                        (HildonEditToolbar *toolbar,
 +
                                                        const gchar *label);
-
Once the edit toolbar is configured you need to attach it to a window by using:
+
</source>
-
<tt><span><font color="#009900">void</font></span>        <span>'''<span><font color="#000000">hildon_window_add_toolbar</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>
+
When the edit toolbar is configured, attach it to a window by using:
-
                                              GtkToolbar <span><font color="#990000"><nowiki>*</nowiki></font></span>toolbar<span><font color="#990000">);</font></span>
+
-
</tt>
+
-
As was said, the action to be done by clicking the button should be mplemented in a callback attached to the signal "button-clicked". These widgets define also another signal, "arrow-clicked", emitted when users click the arrow. Typically, the callback for the signal "arrow-clicked" should destroy the current edit view.
+
<source lang="c">
 +
void        hildon_window_add_toolbar      (HildonWindow *self,
 +
                                            GtkToolbar *toolbar);
 +
</source>
 +
 
 +
Implement the action to be done by clicking the button in a callback attached to the signal "<code>button-clicked</code>". These widgets define also another signal, "<code>arrow-clicked</code>", emitted when users click the arrow. Typically, the callback for the signal "<code>arrow-clicked</code>" destroys the current edit view.
The example below shows how to use an edit toolbar. This example builds a main window showing a list of items and a button to go to a edit view where users can select several items and deleted by clicking the action button of the toolbar.
The example below shows how to use an edit toolbar. This example builds a main window showing a list of items and a button to go to a edit view where users can select several items and deleted by clicking the action button of the toolbar.
-
[[Image:Edit_toolbar.png|400px]]
+
[[Image:Edit_toolbar_list_view.png|frame|center|alt=Screenshot of edit toolbar|'''Example 4.2''' Using an Edit Toolbar]]
-
'''Example 4.2. Using an Edit Toolbar'''
+
<source lang="c">
 +
#include                                        <hildon/hildon.h>
-
  #include                                        <hildon/hildon.h>
+
enum { TEXT_COLUMN, N_COLUMNS };
-
 
+
 
-
  enum { TEXT_COLUMN, N_COLUMNS };
+
static GtkTreeModel *
-
 
+
get_model                                      (void)
-
  static GtkTreeModel *
+
{
-
  get_model                                      (void)
+
  int i;
-
  {
+
  static GtkListStore *store = NULL;
-
    int i;
+
 
-
    static GtkListStore *store = NULL;
+
  if (store != NULL)
-
 
+
-
    if (store != NULL)
+
-
      return GTK_TREE_MODEL (store);
+
-
 
+
-
    store = gtk_list_store_new (1, G_TYPE_STRING);
+
-
 
+
-
    for (i = 0; i < 50; i++)
+
-
      {
+
-
        gchar *str;
+
-
 
+
-
        str = g_strdup_printf ("\nRow %d\n", i);
+
-
        gtk_list_store_insert_with_values (store, NULL, i, 0, str, -1);
+
-
        g_free (str);
+
-
      }
+
-
 
+
     return GTK_TREE_MODEL (store);
     return GTK_TREE_MODEL (store);
-
  }
+
 
-
    
+
   store = gtk_list_store_new (1, G_TYPE_STRING);
-
  GtkWidget *
+
 
-
  create_treeview                                (HildonUIMode tvmode)
+
   for (i = 0; i < 50; i++)
-
  {
+
     {
-
    GtkWidget *tv;
+
      gchar *str;
-
    GtkTreeViewColumn *col;
+
 
-
    GtkCellRenderer *renderer;
+
      str = g_strdup_printf ("\nRow %d\n", i);
-
    GtkTreeModel *model;
+
      gtk_list_store_insert_with_values (store, NULL, i, 0, str, -1);
-
    GtkTreeSelection *selection;
+
       g_free (str);
-
    
+
-
    tv = hildon_gtk_tree_view_new (tvmode);
+
-
    renderer = gtk_cell_renderer_text_new ();
+
-
    col = gtk_tree_view_column_new_with_attributes ("Title", renderer,
+
-
                                                    "text", TEXT_COLUMN, NULL);
+
-
     gtk_tree_view_append_column (GTK_TREE_VIEW(tv), col);
+
-
 
+
-
    /* Set multiple selection mode*/
+
-
    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
+
-
    gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
+
-
 
+
-
    model = get_model ();
+
-
 
+
-
    gtk_tree_view_set_model (GTK_TREE_VIEW (tv), model);
+
-
 
+
-
    return tv;
+
-
  }
+
-
 
+
-
 
+
-
  static void
+
-
  delete_button_clicked                          (GtkButton  *button,
+
-
                                                  GtkTreeView *treeview)
+
-
  {
+
-
    GtkTreeModel *model;
+
-
    GtkTreePath *path;
+
-
    GtkTreeIter iter;
+
-
    GtkTreeRowReference *ref;
+
-
    GtkTreeSelection *selection;
+
-
    GList *selected_rows, *list, *row_references = NULL;
+
-
 
+
-
    selection = gtk_tree_view_get_selection (treeview);
+
-
 
+
-
    selected_rows = gtk_tree_selection_get_selected_rows (selection,
+
-
                                                          &model);
+
-
 
+
-
    for (list = selected_rows; list; list = g_list_next(list)) {
+
-
 
+
-
      path = list->data;
+
-
 
+
-
      ref = gtk_tree_row_reference_new (model,
+
-
                                        path);
+
-
 
+
-
       row_references = g_list_append (row_references,
+
-
                                      ref);
+
     }
     }
-
    
+
 
-
    for (list = row_references; list; list = g_list_next(list)) {
+
   return GTK_TREE_MODEL (store);
-
    
+
}
-
      path = gtk_tree_row_reference_get_path ((GtkTreeRowReference *) (list->data));
+
 
-
    
+
GtkWidget *
-
      gtk_tree_model_get_iter (model, &iter, path);
+
create_treeview                                (HildonUIMode tvmode)
-
    
+
{
-
      gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+
  GtkWidget *tv;
-
    
+
  GtkTreeViewColumn *col;
-
      gtk_tree_path_free (path);
+
  GtkCellRenderer *renderer;
-
    
+
  GtkTreeModel *model;
-
    }
+
  GtkTreeSelection *selection;
-
    
+
 
-
    g_list_free (selected_rows);
+
  tv = hildon_gtk_tree_view_new (tvmode);
-
     g_list_free (row_references);
+
   renderer = gtk_cell_renderer_text_new ();
-
     g_list_free (list);
+
  col = gtk_tree_view_column_new_with_attributes ("Title", renderer,
 +
                                                  "text", TEXT_COLUMN, NULL);
 +
  gtk_tree_view_append_column (GTK_TREE_VIEW(tv), col);
 +
 
 +
   /* Set multiple selection mode*/
 +
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
 +
  gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
 +
 
 +
   model = get_model ();
 +
 
 +
  gtk_tree_view_set_model (GTK_TREE_VIEW (tv), model);
 +
 
 +
   return tv;
 +
}
 +
 
 +
 
 +
static void
 +
delete_button_clicked                          (GtkButton  *button,
 +
                                                GtkTreeView *treeview)
 +
{
 +
  GtkTreeModel *model;
 +
   GtkTreePath *path;
 +
  GtkTreeIter iter;
 +
   GtkTreeRowReference *ref;
 +
  GtkTreeSelection *selection;
 +
  GList *selected_rows, *list, *row_references = NULL;
 +
 
 +
  selection = gtk_tree_view_get_selection (treeview);
 +
 
 +
  selected_rows = gtk_tree_selection_get_selected_rows (selection,
 +
                                                        &model);
 +
 
 +
  for (list = selected_rows; list; list = g_list_next(list)) {
 +
 
 +
     path = list->data;
 +
 
 +
    ref = gtk_tree_row_reference_new (model,
 +
                                      path);
 +
 
 +
     row_references = g_list_append (row_references,
 +
                                    ref);
   }
   }
-
 
+
 
-
   static void
+
   for (list = row_references; list; list = g_list_next(list)) {
-
  edit_window                                    (void)
+
 
-
  {
+
     path = gtk_tree_row_reference_get_path ((GtkTreeRowReference *) (list->data));
-
    GtkWidget *window;
+
 
-
    GtkWidget *tree_view;
+
     gtk_tree_model_get_iter (model, &iter, path);
-
    GtkWidget *toolbar;
+
 
-
    GtkWidget *area;
+
     gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
-
 
+
 
-
    window = hildon_stackable_window_new ();
+
     gtk_tree_path_free (path);
-
    gtk_container_set_border_width (GTK_CONTAINER (window), 6);
+
 
-
 
+
-
     /* Create a new edit toolbar */
+
-
    toolbar = hildon_edit_toolbar_new_with_text ("Choose items to delete",
+
-
                                                "Delete");
+
-
    area = hildon_pannable_area_new ();
+
-
    tree_view = create_treeview (HILDON_UI_MODE_EDIT);
+
-
 
+
-
    /* Add toolbar to the window */
+
-
    hildon_window_set_edit_toolbar (HILDON_WINDOW (window),
+
-
                                    HILDON_EDIT_TOOLBAR (toolbar));
+
-
 
+
-
    gtk_container_add (GTK_CONTAINER (area), tree_view);
+
-
    gtk_container_add (GTK_CONTAINER (window), area);
+
-
 
+
-
    g_signal_connect (toolbar, "button-clicked",
+
-
                      G_CALLBACK (delete_button_clicked),
+
-
                      tree_view);
+
-
 
+
-
     g_signal_connect_swapped (toolbar, "arrow-clicked",
+
-
                              G_CALLBACK (gtk_widget_destroy),
+
-
                              window);
+
-
 
+
-
     gtk_widget_show_all (window);
+
-
 
+
-
    /* Set window to fullscreen */
+
-
    gtk_window_fullscreen (GTK_WINDOW (window));
+
-
  }
+
-
 
+
-
  int
+
-
  main                                            (int    argc,
+
-
                                                  char **argv)
+
-
  {
+
-
    GtkWidget *window;
+
-
    GtkWidget *tree_view;
+
-
    GtkWidget *vbox;
+
-
    GtkWidget *button;
+
-
    GtkWidget *area;
+
-
 
+
-
    hildon_gtk_init (&argc, &argv);
+
-
 
+
-
     window = hildon_stackable_window_new ();
+
-
    g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
+
-
 
+
-
    vbox = gtk_vbox_new (FALSE, 10);
+
-
    area = hildon_pannable_area_new ();
+
-
 
+
-
    tree_view = create_treeview (HILDON_UI_MODE_NORMAL);
+
-
 
+
-
    button = hildon_gtk_button_new (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT);
+
-
    gtk_button_set_label (GTK_BUTTON (button), "Delete some items");
+
-
 
+
-
    gtk_container_add (GTK_CONTAINER (area), tree_view);
+
-
    gtk_box_pack_start (GTK_BOX (vbox), area, TRUE, TRUE, 0);
+
-
    gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
-
 
+
-
    gtk_container_add (GTK_CONTAINER (window), vbox);
+
-
 
+
-
    g_signal_connect (button, "clicked", G_CALLBACK (edit_window), NULL);
+
-
 
+
-
    gtk_widget_show_all (window);
+
-
 
+
-
    gtk_main ();
+
-
 
+
-
    return 0;
+
   }
   }
-
The most of stuff related to HildonEditToolbar is in the function edit_window. This function creates a edit view, meaning that a new HildonStackableWindow is created showing a treeview in which users can select several items.
+
  g_list_free (selected_rows);
 +
  g_list_free (row_references);
 +
  g_list_free (list);
 +
}
-
Note that the edit window is set to fullscreen and thus displaying the HildonEditToolbar obscures the usual window controls.
+
static void
 +
edit_window                                    (void)
 +
{
 +
  GtkWidget *window;
 +
  GtkWidget *tree_view;
 +
  GtkWidget *toolbar;
 +
  GtkWidget *area;
 +
 
 +
  window = hildon_stackable_window_new ();
 +
  gtk_container_set_border_width (GTK_CONTAINER (window), 6);
 +
 
 +
  /* Create a new edit toolbar */
 +
  toolbar = hildon_edit_toolbar_new_with_text ("Choose items to delete",
 +
                                              "Delete");
 +
  area = hildon_pannable_area_new ();
 +
  tree_view = create_treeview (HILDON_UI_MODE_EDIT);
 +
 
 +
  /* Add toolbar to the window */
 +
  hildon_window_set_edit_toolbar (HILDON_WINDOW (window),
 +
                                  HILDON_EDIT_TOOLBAR (toolbar));
 +
 
 +
  gtk_container_add (GTK_CONTAINER (area), tree_view);
 +
  gtk_container_add (GTK_CONTAINER (window), area);
 +
 
 +
  g_signal_connect (toolbar, "button-clicked",
 +
                    G_CALLBACK (delete_button_clicked),
 +
                    tree_view);
 +
 
 +
  g_signal_connect_swapped (toolbar, "arrow-clicked",
 +
                            G_CALLBACK (gtk_widget_destroy),
 +
                            window);
 +
 
 +
  gtk_widget_show_all (window);
 +
 
 +
  /* Set window to fullscreen */
 +
  gtk_window_fullscreen (GTK_WINDOW (window));
 +
}
 +
 
 +
int
 +
main                                            (int    argc,
 +
                                                char **argv)
 +
{
 +
  GtkWidget *window;
 +
  GtkWidget *tree_view;
 +
  GtkWidget *vbox;
 +
  GtkWidget *button;
 +
  GtkWidget *area;
 +
 
 +
  hildon_gtk_init (&argc, &argv);
 +
 
 +
  window = hildon_stackable_window_new ();
 +
  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
 +
 
 +
  vbox = gtk_vbox_new (FALSE, 10);
 +
  area = hildon_pannable_area_new ();
 +
 
 +
  tree_view = create_treeview (HILDON_UI_MODE_NORMAL);
 +
 
 +
  button = hildon_gtk_button_new (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT);
 +
  gtk_button_set_label (GTK_BUTTON (button), "Delete some items");
 +
 
 +
  gtk_container_add (GTK_CONTAINER (area), tree_view);
 +
  gtk_box_pack_start (GTK_BOX (vbox), area, TRUE, TRUE, 0);
 +
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
 +
 
 +
  gtk_container_add (GTK_CONTAINER (window), vbox);
 +
 
 +
  g_signal_connect (button, "clicked", G_CALLBACK (edit_window), NULL);
 +
 
 +
  gtk_widget_show_all (window);
 +
 
 +
  gtk_main ();
 +
 
 +
  return 0;
 +
}
 +
</source>
 +
 
 +
The most things related to <code>HildonEditToolbar</code> is in the function <code>edit_window</code>. This function creates a edit view, meaning that a new <code>HildonStackableWindow</code> is created showing a treeview in which users can select several items.
 +
 
 +
Note that the edit window is set to fullscreen and thus displaying the <code>HildonEditToolbar</code> obscures the usual window controls.
== Using GtkToolbars in Hildon applications ==
== Using GtkToolbars in Hildon applications ==
-
You can use the widget GtkToolbar as you would use it in a GTK+ application, but take the following considerations into account:
 
-
* Use GtkToolbars when only one content item is visible (e.g. when editing a single image or editing a single email).
+
Use the widget <code>GtkToolbar</code> as you would use it in a GTK+ application, but consider the following:
-
* Provide no menu commands or settings for hiding or showing toolbar. The toolbar is always shown in the view where you decided to put it.
+
-
Like the others toolbars, a GtkToolbar should be attached to a window by using:
+
* Use <code>GtkToolbar</code>s when only one content item is visible (for example when editing a single image or editing a single email).
 +
* Provide no menu commands or settings for hiding or showing toolbar. The toolbar is always shown in the view where you decided to put it.
-
<tt><span><font color="#009900">void</font></span>        <span>'''<span><font color="#000000">hildon_window_add_toolbar</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>
+
Like the others toolbars, attach a <code>GtkToolbar</code> to a window by using:
-
                                              GtkToolbar <span><font color="#990000"><nowiki>*</nowiki></font></span>toolbar<span><font color="#990000">);</font></span>
+
-
</tt>
+
-
The following example shows how to use a GtkToolBar. The use is very close to how it would be use in a normal GTK+ application.
+
<source lang="c">
 +
void        hildon_window_add_toolbar      (HildonWindow *self,
 +
                                            GtkToolbar *toolbar);
 +
</source>
-
[[Image:example-gtktoolbar.png|400px]]
+
The following example shows how to use a <code>GtkToolBar</code>. The use is very close to how it would be use in a normal GTK+ application.
-
'''Example 4.3. Using a GtkToolbar in a Hildon application'''
+
[[Image:example-gtktoolbar.png|frame|center|alt=Screenshot of example GtkToolbar|'''Example 4.3''' Using a GtkToolbar in a Hildon application]]
-
<tt><span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span>                                        <span><font color="#FF0000">&lt;hildon/hildon.h&gt;</font></span>
+
<source lang="c">
-
<span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">on_clicked</font></span>'''</span> <span><font color="#990000">(</font></span>GtkToolButton <span><font color="#990000"><nowiki>*</nowiki></font></span>toolbutton<span><font color="#990000">,</font></span>
+
#include <hildon/hildon.h>
-
                  gint index<span><font color="#990000">)</font></span>
+
void on_clicked (GtkToolButton *toolbutton,
-
<span><font color="#FF0000">{</font></span>
+
                gint index)
-
  <span>'''<span><font color="#000000">g_debug</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"Index of clicked item : %d"</font></span><span><font color="#990000">,</font></span> index<span><font color="#990000">);</font></span>
+
{
-
<span><font color="#FF0000">}</font></span>
+
  g_debug ("Index of clicked item : %d", index);
-
<span><font color="#009900">int</font></span>
+
}
-
<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>
+
int
-
                                                  <span><font color="#009900">char</font></span> <span><font color="#990000"><nowiki>**</nowiki></font></span>argv<span><font color="#990000">)</font></span>
+
main (int argc, char **argv)
-
<span><font color="#FF0000">{</font></span>
+
{
-
  HildonProgram <span><font color="#990000"><nowiki>*</nowiki></font></span>program<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
  HildonProgram *program;
-
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>window<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
  GtkWidget *window;
-
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>toolbar<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
  GtkWidget *toolbar;
-
  GtkToolItem <span><font color="#990000"><nowiki>*</nowiki></font></span>toolitem<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
  GtkToolItem *toolitem;
-
  <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);
-
  program <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_program_get_instance</font></span>'''</span> <span><font color="#990000">();</font></span>
+
  program = hildon_program_get_instance ();
-
  window <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_window_new</font></span>'''</span> <span><font color="#990000">();</font></span>
+
  window = hildon_window_new ();
-
  <span>'''<span><font color="#000000">hildon_program_add_window</font></span>'''</span> <span><font color="#990000">(</font></span>program<span><font color="#990000">,</font></span> <span>'''<span><font color="#000000">HILDON_WINDOW</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">));</font></span>
+
  hildon_program_add_window (program, HILDON_WINDOW (window));
-
  <span>''<span><font color="#9A1900">/* Create a toolbar */</font></span>''</span>
+
  /* Create a toolbar */
-
  toolbar <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_toolbar_new</font></span>'''</span> <span><font color="#990000">();</font></span>
+
  toolbar = gtk_toolbar_new ();
-
  <span>''<span><font color="#9A1900">/* Add items to the toolbar */</font></span>''</span>
+
  /* Add items to the toolbar */
-
  toolitem <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_tool_button_new</font></span>'''</span> <span><font color="#990000">(</font></span>
+
  toolitem = gtk_tool_button_new (
-
    <span>'''<span><font color="#000000">gtk_image_new_from_stock</font></span>'''</span><span><font color="#990000">(</font></span>GTK_STOCK_HOME<span><font color="#990000">,</font></span> HILDON_ICON_PIXEL_SIZE_TOOLBAR<span><font color="#990000">),</font></span>
+
    gtk_image_new_from_stock(GTK_STOCK_HOME, HILDON_ICON_PIXEL_SIZE_TOOLBAR),
-
    <span><font color="#FF0000">"Home"</font></span><span><font color="#990000">);</font></span>
+
    "Home");
-
  <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>toolitem<span><font color="#990000">),</font></span>
+
  g_signal_connect (G_OBJECT (toolitem),
-
                    <span><font color="#FF0000">"clicked"</font></span><span><font color="#990000">,</font></span>
+
                    "clicked",
-
                    <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>on_clicked<span><font color="#990000">),</font></span>
+
                    G_CALLBACK (on_clicked),
-
                    <span><font color="#990000">(</font></span>gpointer<span><font color="#990000">)</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">);</font></span>
+
                    (gpointer) 0);
-
  <span>'''<span><font color="#000000">gtk_toolbar_insert</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_TOOLBAR</font></span>'''</span> <span><font color="#990000">(</font></span>toolbar<span><font color="#990000">),</font></span>
+
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
-
                      toolitem<span><font color="#990000">,</font></span>
+
                      toolitem,
-
                      <span><font color="#993399">0</font></span><span><font color="#990000">);</font></span>
+
                      0);
-
  toolitem <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_tool_button_new</font></span>'''</span> <span><font color="#990000">(</font></span>
+
  toolitem = gtk_tool_button_new (
-
    <span>'''<span><font color="#000000">gtk_image_new_from_stock</font></span>'''</span><span><font color="#990000">(</font></span>GTK_STOCK_GO_BACK<span><font color="#990000">,</font></span> HILDON_ICON_PIXEL_SIZE_TOOLBAR<span><font color="#990000">),</font></span>
+
    gtk_image_new_from_stock(GTK_STOCK_GO_BACK, HILDON_ICON_PIXEL_SIZE_TOOLBAR),
-
    <span><font color="#FF0000">"Back"</font></span><span><font color="#990000">);</font></span>
+
    "Back");
-
  <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>toolitem<span><font color="#990000">),</font></span>
+
  g_signal_connect (G_OBJECT (toolitem),
-
                    <span><font color="#FF0000">"clicked"</font></span><span><font color="#990000">,</font></span>
+
                    "clicked",
-
                    <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>on_clicked<span><font color="#990000">),</font></span>
+
                    G_CALLBACK (on_clicked),
-
                    <span><font color="#990000">(</font></span>gpointer<span><font color="#990000">)</font></span> <span><font color="#993399">1</font></span><span><font color="#990000">);</font></span>
+
                    (gpointer) 1);
-
  <span>'''<span><font color="#000000">gtk_toolbar_insert</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_TOOLBAR</font></span>'''</span> <span><font color="#990000">(</font></span>toolbar<span><font color="#990000">),</font></span>
+
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
-
                      toolitem<span><font color="#990000">,</font></span>
+
                      toolitem,
-
                      <span><font color="#993399">1</font></span><span><font color="#990000">);</font></span>
+
                      1);
-
  toolitem <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_tool_button_new</font></span>'''</span> <span><font color="#990000">(</font></span>
+
  toolitem = gtk_tool_button_new (
-
    <span>'''<span><font color="#000000">gtk_image_new_from_stock</font></span>'''</span><span><font color="#990000">(</font></span>GTK_STOCK_GO_FORWARD<span><font color="#990000">,</font></span> HILDON_ICON_PIXEL_SIZE_TOOLBAR<span><font color="#990000">),</font></span>
+
    gtk_image_new_from_stock(GTK_STOCK_GO_FORWARD, HILDON_ICON_PIXEL_SIZE_TOOLBAR),
-
    <span><font color="#FF0000">"Forward"</font></span><span><font color="#990000">);</font></span>
+
    "Forward");
-
  <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>toolitem<span><font color="#990000">),</font></span>
+
  g_signal_connect (G_OBJECT (toolitem),
-
                    <span><font color="#FF0000">"clicked"</font></span><span><font color="#990000">,</font></span>
+
                    "clicked",
-
                    <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>on_clicked<span><font color="#990000">),</font></span>
+
                    G_CALLBACK (on_clicked),
-
                    <span><font color="#990000">(</font></span>gpointer<span><font color="#990000">)</font></span> <span><font color="#993399">2</font></span><span><font color="#990000">);</font></span>
+
                    (gpointer) 2);
-
  <span>'''<span><font color="#000000">gtk_toolbar_insert</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_TOOLBAR</font></span>'''</span> <span><font color="#990000">(</font></span>toolbar<span><font color="#990000">),</font></span>
+
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
-
                      toolitem<span><font color="#990000">,</font></span>
+
                      toolitem,
-
                      <span><font color="#993399">2</font></span><span><font color="#990000">);</font></span>
+
                      2);
-
  <span>''<span><font color="#9A1900">/* Add toolbar to the window */</font></span>''</span>
+
  /* Add toolbar to the window */
-
  <span>'''<span><font color="#000000">hildon_window_add_toolbar</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>window<span><font color="#990000">),</font></span>
+
  hildon_window_add_toolbar (HILDON_WINDOW (window),
-
                              <span>'''<span><font color="#000000">GTK_TOOLBAR</font></span>'''</span><span><font color="#990000">(</font></span>toolbar<span><font color="#990000">));</font></span>
+
                            GTK_TOOLBAR(toolbar));
-
  <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>window<span><font color="#990000">));</font></span>
+
  gtk_widget_show_all (GTK_WIDGET (window));
-
  <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>

Latest revision as of 13:24, 14 October 2010

Image:Ambox_content.png
This article is legacy documentation, and is superseded by Forum Nokia documentation.
The Forum Nokia documentation is available as the Hildon 2.2 UI style guide, Fremantle master layout guide and the Hildon 2.2 widget UI specification

Toolbars usually simplify the customization of widget look and layout by grouping widgets. The Hildon framework provides two specialized toolbars: HildonFindToolbar and HildonEditToolbar. You can also use GtkToolbars in your Hildon application.

[edit] Find toolbars

HildonFindToolbar is a toolbar that contains a search entry and a dropdown list with previously searched strings. An internal GtkListStore stores the items in the dropdown list. This list is a property of the widget called "list".

To create a HildonFindToolbar, use the following:

GtkWidget*  hildon_find_toolbar_new            (const gchar *label);
GtkWidget*  hildon_find_toolbar_new_with_model (const gchar *label,
                                                GtkListStore *model,
                                                gint column);

In both functions the argument label is used as label which be displayed as label for the dropdown box.

The second function above allows you to set the model used for storing the dropdown box. Also indicate which column the search retrieves the string from.

If you use the first function to create the toolbar, set the properties "list" and "column" manually.

This widget provides the function f to set and retrieve the index in the model of the current active item on the combo. An index of -1 indicates no active items in both functions.

void        hildon_find_toolbar_set_active  (HildonFindToolbar *toolbar,
                                             gint index);
gint        hildon_find_toolbar_get_active  (HildonFindToolbar *toolbar);

To get the index of the most recently added item in the toolbar, use the following function:

gint32      hildon_find_toolbar_get_last_index (HildonFindToolbar *toolbar);

Alternatively, you can use a GtkTreeIter to reference the current active item.

void        hildon_find_toolbar_set_active_iter (HildonFindToolbar *toolbar,
                                                 GtkTreeIter *iter);
gboolean    hildon_find_toolbar_get_active_iter (HildonFindToolbar *toolbar,
                                                 GtkTreeIter *iter);

After creating and properly setting up the toolbar, attach it to any window. HildonWindow provides the following function to attach a toolbar:

void        hildon_window_add_toolbar       (HildonWindow *self,
                                             GtkToolbar *toolbar);

In case you need to add a common toolbar to all windows in your program, HildonProgram provides the following function to set and retrieve a common toolbar to each window registered into the current program:

void        hildon_program_set_common_toolbar (HildonProgram *self,
                                               GtkToolbar *toolbar);
GtkToolbar* hildon_program_get_common_toolbar (HildonProgram *self);

Here a simple example that shows how to deal with a HildonFindToolbar.

Screenshot of example toolbar
Example 4.1 Using a Find Toolbar
#include <hildon/hildon.h>
gboolean
on_history_append (HildonFindToolbar *toolbar,
                   gpointer user_data)
{
  gchar *item;
  GtkTreeIter iter;
  gint index ;
  GtkListStore *list;
  /* Get last added index */
  index = hildon_find_toolbar_get_last_index (toolbar);
  /* Get the inner list */
  g_object_get (G_OBJECT (toolbar),
                "list",&list,
                NULL);
  /* Get the item */
  gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (list) ,
                                       &iter,
                                       g_strdup_printf ("%d",index));
  gtk_tree_model_get (GTK_TREE_MODEL (list),
                      &iter,
                      0, &item,
                      -1);
  g_debug ("ADDED TO THE LIST : %s", item);
  return FALSE;
}
                                                                                                                          int main (int argc, char **argv)
{
  HildonProgram *program;
  GtkWidget *window;
  GtkWidget *toolbar = NULL;
  GtkListStore *store;
  GtkTreeIter iter;
  hildon_gtk_init (&argc, &argv);
  program = hildon_program_get_instance ();
  window = hildon_window_new ();
  hildon_program_add_window (program, HILDON_WINDOW (window));
  /* Create and populate history list model */
  store = gtk_list_store_new (1, G_TYPE_STRING);
  gtk_list_store_append (store, &iter);
  gtk_list_store_set (store, &iter, 0, "Foo", -1);
  gtk_list_store_append (store, &iter);
  gtk_list_store_set (store, &iter, 0, "Bar", -1);
  gtk_list_store_append (store, &iter);
  gtk_list_store_set (store, &iter, 0, "Baz", -1);
  /* Create find toolbar */
  toolbar = hildon_find_toolbar_new_with_model ("Find", store, 0);
  /* Set item on index 0 as the current active*/
  hildon_find_toolbar_set_active (HILDON_FIND_TOOLBAR (toolbar), 0);
  /* Attach a callback to handle "history-append" signal */
  g_signal_connect_after (G_OBJECT (toolbar), "history-append", G_CALLBACK (on_history_append), NULL);
  /* Attach toolbar to window */
  hildon_window_add_toolbar (HILDON_WINDOW (window), GTK_TOOLBAR (toolbar));
  gtk_widget_show_all (GTK_WIDGET (window));
  gtk_main ();
  return 0;
}

In the example above a callback is set to handle the signal "history-append", emitted by the toolbar when a new item is added to the history. Other signals like "history-append" can trigger additional actions when emitted.

Apart from the property which stores the internal list, other properties are available such as "max-characters", which set the maximum length of the search string. For a complete description of the signals and properties available, see the Hildon reference manual.

[edit] Edit toolbars

Edit toolbars are implemented by the widget HildonEditToolbar. This widget is a toolbar to be used as main control and navigation interface for the edit UI mode. The toolbar contains a label and two buttons, being one of them an arrow pointing backwards and the other a button to perform a certain action. It also display a label which explain to the users the action that the button performs and give intructions to user on how to perform the action properly.

A typical example could be a view to delete several items in a list. The label would advice the user to select the items to delete and those items are deleted by clicking the button.

Typically, the toolbar is attached to an edit view, meaning a HildonStackableWindow used in the program to perform a certain editing action.

The action to be performing by clicking the action button should be implemented in a callback to handle the signal "button-clicked", shown in the example.

To create a new HildonEditToolbar, use:

GtkWidget*  hildon_edit_toolbar_new           (void);
GtkWidget*  hildon_edit_toolbar_new_with_text (const gchar *label,
                                               const gchar *button);

The second creation function allows to set the two labels of the widget. If you use the simple creation function, set the labels by using the following functions.

void                hildon_edit_toolbar_set_label       (HildonEditToolbar *toolbar,
                                                         const gchar *label);
void                hildon_edit_toolbar_set_button_label
                                                        (HildonEditToolbar *toolbar,
                                                         const gchar *label);

When the edit toolbar is configured, attach it to a window by using:

void        hildon_window_add_toolbar       (HildonWindow *self,
                                             GtkToolbar *toolbar);

Implement the action to be done by clicking the button in a callback attached to the signal "button-clicked". These widgets define also another signal, "arrow-clicked", emitted when users click the arrow. Typically, the callback for the signal "arrow-clicked" destroys the current edit view.

The example below shows how to use an edit toolbar. This example builds a main window showing a list of items and a button to go to a edit view where users can select several items and deleted by clicking the action button of the toolbar.

Screenshot of edit toolbar
Example 4.2 Using an Edit Toolbar
#include                                        <hildon/hildon.h>
 
enum { TEXT_COLUMN, N_COLUMNS };
 
static GtkTreeModel *
get_model                                       (void)
{
  int i;
  static GtkListStore *store = NULL;
 
  if (store != NULL)
    return GTK_TREE_MODEL (store);
 
  store = gtk_list_store_new (1, G_TYPE_STRING);
 
  for (i = 0; i < 50; i++)
    {
      gchar *str;
 
      str = g_strdup_printf ("\nRow %d\n", i);
      gtk_list_store_insert_with_values (store, NULL, i, 0, str, -1);
      g_free (str);
    }
 
  return GTK_TREE_MODEL (store);
}
 
GtkWidget *
create_treeview                                 (HildonUIMode tvmode)
{
  GtkWidget *tv;
  GtkTreeViewColumn *col;
  GtkCellRenderer *renderer;
  GtkTreeModel *model;
  GtkTreeSelection *selection;
 
  tv = hildon_gtk_tree_view_new (tvmode);
  renderer = gtk_cell_renderer_text_new ();
  col = gtk_tree_view_column_new_with_attributes ("Title", renderer,
                                                  "text", TEXT_COLUMN, NULL);
  gtk_tree_view_append_column (GTK_TREE_VIEW(tv), col);
 
  /* Set multiple selection mode*/
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
  gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
 
  model = get_model ();
 
  gtk_tree_view_set_model (GTK_TREE_VIEW (tv), model);
 
  return tv;
}
 
 
static void
delete_button_clicked                           (GtkButton   *button,
                                                 GtkTreeView *treeview)
{
  GtkTreeModel *model;
  GtkTreePath *path;
  GtkTreeIter iter;
  GtkTreeRowReference *ref;
  GtkTreeSelection *selection;
  GList *selected_rows, *list, *row_references = NULL;
 
  selection = gtk_tree_view_get_selection (treeview);
 
  selected_rows = gtk_tree_selection_get_selected_rows (selection,
                                                        &model);
 
  for (list = selected_rows; list; list = g_list_next(list)) {
 
    path = list->data;
 
    ref = gtk_tree_row_reference_new (model,
                                      path);
 
    row_references = g_list_append (row_references,
                                    ref);
  }
 
  for (list = row_references; list; list = g_list_next(list)) {
 
    path = gtk_tree_row_reference_get_path ((GtkTreeRowReference *) (list->data));
 
    gtk_tree_model_get_iter (model, &iter, path);
 
    gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
 
    gtk_tree_path_free (path);
 
  }
 
  g_list_free (selected_rows);
  g_list_free (row_references);
  g_list_free (list);
}
 
static void
edit_window                                     (void)
{
  GtkWidget *window;
  GtkWidget *tree_view;
  GtkWidget *toolbar;
  GtkWidget *area;
 
  window = hildon_stackable_window_new ();
  gtk_container_set_border_width (GTK_CONTAINER (window), 6);
 
  /* Create a new edit toolbar */
  toolbar = hildon_edit_toolbar_new_with_text ("Choose items to delete",
                                               "Delete");
  area = hildon_pannable_area_new ();
  tree_view = create_treeview (HILDON_UI_MODE_EDIT);
 
  /* Add toolbar to the window */
  hildon_window_set_edit_toolbar (HILDON_WINDOW (window),
                                  HILDON_EDIT_TOOLBAR (toolbar));
 
  gtk_container_add (GTK_CONTAINER (area), tree_view);
  gtk_container_add (GTK_CONTAINER (window), area);
 
  g_signal_connect (toolbar, "button-clicked",
                    G_CALLBACK (delete_button_clicked),
                    tree_view);
 
  g_signal_connect_swapped (toolbar, "arrow-clicked",
                            G_CALLBACK (gtk_widget_destroy),
                            window);
 
  gtk_widget_show_all (window);
 
  /* Set window to fullscreen */
  gtk_window_fullscreen (GTK_WINDOW (window));
}
 
int
main                                            (int    argc,
                                                 char **argv)
{
  GtkWidget *window;
  GtkWidget *tree_view;
  GtkWidget *vbox;
  GtkWidget *button;
  GtkWidget *area;
 
  hildon_gtk_init (&argc, &argv);
 
  window = hildon_stackable_window_new ();
  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
 
  vbox = gtk_vbox_new (FALSE, 10);
  area = hildon_pannable_area_new ();
 
  tree_view = create_treeview (HILDON_UI_MODE_NORMAL);
 
  button = hildon_gtk_button_new (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT);
  gtk_button_set_label (GTK_BUTTON (button), "Delete some items");
 
  gtk_container_add (GTK_CONTAINER (area), tree_view);
  gtk_box_pack_start (GTK_BOX (vbox), area, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
 
  gtk_container_add (GTK_CONTAINER (window), vbox);
 
  g_signal_connect (button, "clicked", G_CALLBACK (edit_window), NULL);
 
  gtk_widget_show_all (window);
 
  gtk_main ();
 
  return 0;
}

The most things related to HildonEditToolbar is in the function edit_window. This function creates a edit view, meaning that a new HildonStackableWindow is created showing a treeview in which users can select several items.

Note that the edit window is set to fullscreen and thus displaying the HildonEditToolbar obscures the usual window controls.

[edit] Using GtkToolbars in Hildon applications

Use the widget GtkToolbar as you would use it in a GTK+ application, but consider the following:

  • Use GtkToolbars when only one content item is visible (for example when editing a single image or editing a single email).
  • Provide no menu commands or settings for hiding or showing toolbar. The toolbar is always shown in the view where you decided to put it.

Like the others toolbars, attach a GtkToolbar to a window by using:

void        hildon_window_add_toolbar       (HildonWindow *self,
                                             GtkToolbar *toolbar);

The following example shows how to use a GtkToolBar. The use is very close to how it would be use in a normal GTK+ application.

Screenshot of example GtkToolbar
Example 4.3 Using a GtkToolbar in a Hildon application
#include <hildon/hildon.h>
void on_clicked (GtkToolButton *toolbutton,
                 gint index)
{
  g_debug ("Index of clicked item : %d", index);
}
int
main (int argc, char **argv)
{
  HildonProgram *program;
  GtkWidget *window;
  GtkWidget *toolbar;
  GtkToolItem *toolitem;
  hildon_gtk_init (&argc, &argv);
  program = hildon_program_get_instance ();
  window = hildon_window_new ();
  hildon_program_add_window (program, HILDON_WINDOW (window));
  /* Create a toolbar */
  toolbar = gtk_toolbar_new ();
  /* Add items to the toolbar */
  toolitem = gtk_tool_button_new (
    gtk_image_new_from_stock(GTK_STOCK_HOME, HILDON_ICON_PIXEL_SIZE_TOOLBAR),
    "Home");
  g_signal_connect (G_OBJECT (toolitem),
                    "clicked",
                    G_CALLBACK (on_clicked),
                    (gpointer) 0);
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
                      toolitem,
                      0);
  toolitem = gtk_tool_button_new (
    gtk_image_new_from_stock(GTK_STOCK_GO_BACK, HILDON_ICON_PIXEL_SIZE_TOOLBAR),
    "Back");
  g_signal_connect (G_OBJECT (toolitem),
                    "clicked",
                    G_CALLBACK (on_clicked),
                    (gpointer) 1);
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
                      toolitem,
                      1);
  toolitem = gtk_tool_button_new (
    gtk_image_new_from_stock(GTK_STOCK_GO_FORWARD, HILDON_ICON_PIXEL_SIZE_TOOLBAR),
    "Forward");
  g_signal_connect (G_OBJECT (toolitem),
                    "clicked",
                    G_CALLBACK (on_clicked),
                    (gpointer) 2);
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
                      toolitem,
                      2);
  /* Add toolbar to the window */
  hildon_window_add_toolbar (HILDON_WINDOW (window),
                             GTK_TOOLBAR(toolbar));
  gtk_widget_show_all (GTK_WIDGET (window));
  gtk_main ();
  return 0;
}