Legacy Maemo 5 Documentation/Graphical UI Tutorial/Toolbars

= Toolbars = 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.

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 ); </tt>

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 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.

<tt> <font color="#009900">void        <font color="#000000">hildon_find_toolbar_set_active   <font color="#990000">( HildonFindToolbar <font color="#990000"> * toolbar <font color="#990000">,                                               gint index <font color="#990000">); gint        <font color="#000000">hildon_find_toolbar_get_active   <font color="#990000">( HildonFindToolbar <font color="#990000"> * toolbar <font color="#990000">); </tt>

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

<tt>gint32      <font color="#000000">hildon_find_toolbar_get_last_index   <font color="#990000">( HildonFindToolbar <font color="#990000"> * toolbar <font color="#990000">); </tt>

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

<tt> <font color="#990000">\ begin <font color="#FF0000">{ verbatim <font color="#FF0000">} <font color="#009900">void        <font color="#000000">hildon_find_toolbar_set_active_iter   <font color="#990000">( HildonFindToolbar <font color="#990000"> * toolbar <font color="#990000">,                                                   GtkTreeIter <font color="#990000"> * iter <font color="#990000">); gboolean    <font color="#000000">hildon_find_toolbar_get_active_iter   <font color="#990000">( HildonFindToolbar <font color="#990000"> * toolbar <font color="#990000">,                                                   GtkTreeIter <font color="#990000"> * iter <font color="#990000">); </tt>

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:

<tt> <font color="#009900">void        <font color="#000000">hildon_window_add_toolbar        <font color="#990000">( HildonWindow <font color="#990000"> * self <font color="#990000">,                                               GtkToolbar <font color="#990000"> * toolbar <font color="#990000">); </tt>

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:

<tt> <font color="#009900">void        <font color="#000000">hildon_program_set_common_toolbar   <font color="#990000">( HildonProgram <font color="#990000"> * self <font color="#990000">,                                                 GtkToolbar <font color="#990000"> * toolbar <font color="#990000">); GtkToolbar <font color="#990000"> *  <font color="#000000">hildon_program_get_common_toolbar   <font color="#990000">( HildonProgram <font color="#990000"> * self <font color="#990000">); </tt>

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

@@IMAGE@@: MAIN VIEW IN EXAMPLE BELLOW

'''Example 4.1. Using a Find Toolbar'''

<tt>  <font color="#000080"> #include                                        <font color="#FF0000">&lt;hildon/hildon.h&gt; gboolean  <font color="#000000">on_history_append                               <font color="#990000">( HildonFindToolbar <font color="#990000"> * toolbar <font color="#990000">,                                                   gpointer           user_data <font color="#990000">) <font color="#FF0000">{ gchar <font color="#990000"> * item <font color="#990000"> ; GtkTreeIter iter <font color="#990000"> ; gint index <font color="#990000"> ; GtkListStore <font color="#990000"> * list <font color="#990000"> ;  <font color="#9A1900">/* Get last added index */  index <font color="#990000"> =  <font color="#000000">hildon_find_toolbar_get_last_index   <font color="#990000">( toolbar <font color="#990000">);  <font color="#9A1900">/* Get the inner list */   <font color="#000000">g_object_get  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( toolbar <font color="#990000">),                  <font color="#FF0000">"list"  <font color="#990000">,&amp; list <font color="#990000">,                  NULL <font color="#990000">);  <font color="#9A1900">/* Get the item */   <font color="#000000">gtk_tree_model_get_iter_from_string  <font color="#990000">(   <font color="#000000">GTK_TREE_MODEL   <font color="#990000">( list <font color="#990000">)  <font color="#990000">,                                         <font color="#990000">&amp; iter <font color="#990000">,                                          <font color="#000000">g_strdup_printf   <font color="#990000">(  <font color="#FF0000">"%d"  <font color="#990000">, index <font color="#990000">));  <font color="#000000">gtk_tree_model_get  <font color="#990000">(   <font color="#000000">GTK_TREE_MODEL   <font color="#990000">( list <font color="#990000">),                        <font color="#990000">&amp; iter <font color="#990000">,                        <font color="#993399">0  <font color="#990000">,  <font color="#990000">&amp; item <font color="#990000">,                        <font color="#990000">-  <font color="#993399">1  <font color="#990000">);  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"ADDED TO THE LIST : %s"  <font color="#990000">, item <font color="#990000">);  <font color="#0000FF">return  FALSE <font color="#990000"> ; <font color="#FF0000">} <font color="#009900">int  <font color="#000000">main                                            <font color="#990000">(  <font color="#009900">int argc <font color="#990000">,                                                   <font color="#009900">char  <font color="#990000"> ** argv <font color="#990000">) <font color="#FF0000">{ HildonProgram <font color="#990000"> * program <font color="#990000"> ; GtkWidget <font color="#990000"> * window <font color="#990000"> ; GtkWidget <font color="#990000"> * toolbar <font color="#990000"> = NULL <font color="#990000"> ; GtkListStore <font color="#990000"> * store <font color="#990000"> ; GtkTreeIter iter <font color="#990000"> ;  <font color="#000000">hildon_gtk_init  <font color="#990000">(&amp; argc <font color="#990000">,  <font color="#990000">&amp; argv <font color="#990000">); program <font color="#990000"> =  <font color="#000000">hildon_program_get_instance   <font color="#990000">; window <font color="#990000"> =  <font color="#000000">hildon_window_new   <font color="#990000">;  <font color="#000000">hildon_program_add_window  <font color="#990000">( program <font color="#990000">,   <font color="#000000">HILDON_WINDOW   <font color="#990000">( window <font color="#990000">));  <font color="#9A1900">/* Create and populate history list model */  store <font color="#990000"> =  <font color="#000000">gtk_list_store_new   <font color="#990000">(  <font color="#993399">1  <font color="#990000">, G_TYPE_STRING <font color="#990000">);  <font color="#000000">gtk_list_store_append  <font color="#990000">( store <font color="#990000">,  <font color="#990000">&amp; iter <font color="#990000">);  <font color="#000000">gtk_list_store_set  <font color="#990000">( store <font color="#990000">,  <font color="#990000">&amp; iter <font color="#990000">,  <font color="#993399">0  <font color="#990000">,  <font color="#FF0000">"Foo"  <font color="#990000">,  <font color="#990000">-  <font color="#993399">1  <font color="#990000">);  <font color="#000000">gtk_list_store_append  <font color="#990000">( store <font color="#990000">,  <font color="#990000">&amp; iter <font color="#990000">);  <font color="#000000">gtk_list_store_set  <font color="#990000">( store <font color="#990000">,  <font color="#990000">&amp; iter <font color="#990000">,  <font color="#993399">0  <font color="#990000">,  <font color="#FF0000">"Bar"  <font color="#990000">,  <font color="#990000">-  <font color="#993399">1  <font color="#990000">);  <font color="#000000">gtk_list_store_append  <font color="#990000">( store <font color="#990000">,  <font color="#990000">&amp; iter <font color="#990000">);  <font color="#000000">gtk_list_store_set  <font color="#990000">( store <font color="#990000">,  <font color="#990000">&amp; iter <font color="#990000">,  <font color="#993399">0  <font color="#990000">,  <font color="#FF0000">"Baz"  <font color="#990000">,  <font color="#990000">-  <font color="#993399">1  <font color="#990000">);  <font color="#9A1900">/* Create find toolbar */  toolbar <font color="#990000"> =  <font color="#000000">hildon_find_toolbar_new_with_model   <font color="#990000">(  <font color="#FF0000">"Find"  <font color="#990000">, store <font color="#990000">,  <font color="#993399">0  <font color="#990000">);  <font color="#9A1900">/* Set item on index 0 as the current active*/   <font color="#000000">hildon_find_toolbar_set_active  <font color="#990000">(   <font color="#000000">HILDON_FIND_TOOLBAR   <font color="#990000">( toolbar <font color="#990000">),  <font color="#993399">0  <font color="#990000">);  <font color="#9A1900">/* Attach a callback to handle "history-append" signal */   <font color="#000000">g_signal_connect_after  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( toolbar <font color="#990000">),  <font color="#FF0000">"history-append"  <font color="#990000">,   <font color="#000000">G_CALLBACK   <font color="#990000">( on_history_append <font color="#990000">), NULL <font color="#990000">);  <font color="#9A1900">/* Attach toolbar to window */   <font color="#000000">hildon_window_add_toolbar  <font color="#990000">(   <font color="#000000">HILDON_WINDOW   <font color="#990000">( window <font color="#990000">),   <font color="#000000">GTK_TOOLBAR   <font color="#990000">( toolbar <font color="#990000">));  <font color="#000000">gtk_widget_show_all  <font color="#990000">(   <font color="#000000">GTK_WIDGET   <font color="#990000">( window <font color="#990000">));  <font color="#000000">gtk_main  <font color="#990000">;  <font color="#0000FF">return  <font color="#993399">0  <font color="#990000"> ; <font color="#FF0000">} </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. To a complete description of the signals and properties available read the Hildon reference manual.

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 you should use:

<tt>GtkWidget <font color="#990000"> *  <font color="#000000">hildon_edit_toolbar_new            <font color="#990000">(  <font color="#009900">void  <font color="#990000">); GtkWidget <font color="#990000"> *  <font color="#000000">hildon_edit_toolbar_new_with_text   <font color="#990000">(   <font color="#0000FF">const  gchar <font color="#990000"> * label <font color="#990000">,                                                  <font color="#0000FF">const  gchar <font color="#990000"> * button <font color="#990000">); </tt>

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.

<tt> <font color="#009900">void        <font color="#000000">hildon_window_add_toolbar        <font color="#990000">( HildonWindow <font color="#990000"> * self <font color="#990000">,                                               GtkToolbar <font color="#990000"> * toolbar <font color="#990000">); </tt>

Once the edit toolbar is configured you need to attach it to a window by using:

<tt> <font color="#009900">void        <font color="#000000">hildon_window_add_toolbar        <font color="#990000">( HildonWindow <font color="#990000"> * self <font color="#990000">,                                               GtkToolbar <font color="#990000"> * toolbar <font color="#990000">); </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.

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 WINDOW FROM EXAMPLE BELLOW

'''Example 4.2. Using an Edit Toolbar'''

<tt> <font color="#990000">[ Desktop Entry <font color="#990000">] Name <font color="#990000"> = TimeOut Applet Comment <font color="#990000"> = Execute an action at a given time Type <font color="#990000"> =  <font color="#0000FF">default  X <font color="#990000">- Path <font color="#990000"> = lib <font color="#990000">- timeout <font color="#990000">- home <font color="#990000">- applet <font color="#990000">. so </tt>

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.

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

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).
 * 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:

<tt> <font color="#009900">void        <font color="#000000">hildon_window_add_toolbar        <font color="#990000">( HildonWindow <font color="#990000"> * self <font color="#990000">,                                               GtkToolbar <font color="#990000"> * toolbar <font color="#990000">); </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.

@@IMAGE@@: FROM EXAMPLE BELLOW

'''Example 4.3. Using a GtkToolbar in a Hildon application'''

<tt>  <font color="#000080"> #include                                        <font color="#FF0000">&lt;hildon/hildon.h&gt; <font color="#009900">void  <font color="#000000">on_clicked   <font color="#990000">( GtkToolButton <font color="#990000"> * toolbutton <font color="#990000">,                   gint index <font color="#990000">) <font color="#FF0000">{  <font color="#000000">g_debug  <font color="#990000">(  <font color="#FF0000">"Index of clicked item : %d"  <font color="#990000">, index <font color="#990000">); <font color="#FF0000">} <font color="#009900">int  <font color="#000000">main                                            <font color="#990000">(  <font color="#009900">int argc <font color="#990000">,                                                   <font color="#009900">char  <font color="#990000"> ** argv <font color="#990000">) <font color="#FF0000">{ HildonProgram <font color="#990000"> * program <font color="#990000"> ; GtkWidget <font color="#990000"> * window <font color="#990000"> ; GtkWidget <font color="#990000"> * toolbar <font color="#990000"> ; GtkToolItem <font color="#990000"> * toolitem <font color="#990000"> ;  <font color="#000000">hildon_gtk_init  <font color="#990000">(&amp; argc <font color="#990000">,  <font color="#990000">&amp; argv <font color="#990000">); program <font color="#990000"> =  <font color="#000000">hildon_program_get_instance   <font color="#990000">; window <font color="#990000"> =  <font color="#000000">hildon_window_new   <font color="#990000">;  <font color="#000000">hildon_program_add_window  <font color="#990000">( program <font color="#990000">,   <font color="#000000">HILDON_WINDOW   <font color="#990000">( window <font color="#990000">));  <font color="#9A1900">/* Create a toolbar */  toolbar <font color="#990000"> =  <font color="#000000">gtk_toolbar_new   <font color="#990000">;  <font color="#9A1900">/* Add items to the toolbar */  toolitem <font color="#990000"> =  <font color="#000000">gtk_tool_button_new   <font color="#990000">(       <font color="#000000">gtk_image_new_from_stock   <font color="#990000">( GTK_STOCK_HOME <font color="#990000">, HILDON_ICON_PIXEL_SIZE_TOOLBAR <font color="#990000">),      <font color="#FF0000">"Home"  <font color="#990000">);  <font color="#000000">g_signal_connect  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( toolitem <font color="#990000">),                      <font color="#FF0000">"clicked"  <font color="#990000">,                       <font color="#000000">G_CALLBACK   <font color="#990000">( on_clicked <font color="#990000">),                      <font color="#990000">( gpointer <font color="#990000">)  <font color="#993399">0  <font color="#990000">);  <font color="#000000">gtk_toolbar_insert  <font color="#990000">(   <font color="#000000">GTK_TOOLBAR   <font color="#990000">( toolbar <font color="#990000">),                        toolitem <font color="#990000">,                        <font color="#993399">0  <font color="#990000">); toolitem <font color="#990000"> =  <font color="#000000">gtk_tool_button_new   <font color="#990000">(       <font color="#000000">gtk_image_new_from_stock   <font color="#990000">( GTK_STOCK_GO_BACK <font color="#990000">, HILDON_ICON_PIXEL_SIZE_TOOLBAR <font color="#990000">),      <font color="#FF0000">"Back"  <font color="#990000">);  <font color="#000000">g_signal_connect  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( toolitem <font color="#990000">),                      <font color="#FF0000">"clicked"  <font color="#990000">,                       <font color="#000000">G_CALLBACK   <font color="#990000">( on_clicked <font color="#990000">),                      <font color="#990000">( gpointer <font color="#990000">)  <font color="#993399">1  <font color="#990000">);  <font color="#000000">gtk_toolbar_insert  <font color="#990000">(   <font color="#000000">GTK_TOOLBAR   <font color="#990000">( toolbar <font color="#990000">),                        toolitem <font color="#990000">,                        <font color="#993399">1  <font color="#990000">); toolitem <font color="#990000"> =  <font color="#000000">gtk_tool_button_new   <font color="#990000">(       <font color="#000000">gtk_image_new_from_stock   <font color="#990000">( GTK_STOCK_GO_FORWARD <font color="#990000">, HILDON_ICON_PIXEL_SIZE_TOOLBAR <font color="#990000">),      <font color="#FF0000">"Forward"  <font color="#990000">);  <font color="#000000">g_signal_connect  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( toolitem <font color="#990000">),                      <font color="#FF0000">"clicked"  <font color="#990000">,                       <font color="#000000">G_CALLBACK   <font color="#990000">( on_clicked <font color="#990000">),                      <font color="#990000">( gpointer <font color="#990000">)  <font color="#993399">2  <font color="#990000">);  <font color="#000000">gtk_toolbar_insert  <font color="#990000">(   <font color="#000000">GTK_TOOLBAR   <font color="#990000">( toolbar <font color="#990000">),                        toolitem <font color="#990000">,                        <font color="#993399">2  <font color="#990000">);  <font color="#9A1900">/* Add toolbar to the window */   <font color="#000000">hildon_window_add_toolbar  <font color="#990000">(   <font color="#000000">HILDON_WINDOW   <font color="#990000">( window <font color="#990000">),                                <font color="#000000">GTK_TOOLBAR   <font color="#990000">( toolbar <font color="#990000">));  <font color="#000000">gtk_widget_show_all  <font color="#990000">(   <font color="#000000">GTK_WIDGET   <font color="#990000">( window <font color="#990000">));  <font color="#000000">gtk_main  <font color="#990000">;  <font color="#0000FF">return  <font color="#993399">0  <font color="#990000"> ; <font color="#FF0000">} </tt>