Editing Documentation/Maemo 5 Developer Guide/Porting Software/Migration
Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.
Warning: This page is 30 kilobytes long; some browsers may have problems editing pages approaching or longer than 32kb. Please consider breaking the page into smaller sections.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
+ | =Migration = | ||
Because Hildon 2.2 is a big step up from previous versions, many approaches in the development of your program's graphical user interface may need to be migrated to this new interface type. | Because Hildon 2.2 is a big step up from previous versions, many approaches in the development of your program's graphical user interface may need to be migrated to this new interface type. | ||
- | |||
== Menus == | == Menus == | ||
+ | Hildon app menu represents a big difference from the normal menus. If your application is to be finger-friendly, an app menu is mandatory. | ||
- | + | Because the app menu uses buttons, you can easily add them with the functions that the original menu items were assigned. On top of that, given the menu limited size (ten items), the items to be added must be carefully divided. For example, consider an advanced text edition program. The original menu bar had the following menus: | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | Because the | + | |
- | + | ||
- | For example, consider an advanced text | + | |
'''Example 10.1. Menu example''' | '''Example 10.1. Menu example''' | ||
- | < | + | <div class="graybox"> |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | File | |
- | + | \ New | |
- | + | \ Open | |
- | + | \ Save | |
+ | \ Save As | ||
+ | \ Quit | ||
+ | Edit | ||
+ | \ Copy | ||
+ | \ Paste | ||
+ | \ Cut | ||
+ | \ Indent Type | ||
+ | \ Tabs | ||
+ | \ Spaces | ||
+ | \ Preferences | ||
+ | View | ||
+ | \ Zoom In | ||
+ | \ Zoom Out | ||
+ | \ Normal Size | ||
+ | \ Highlight | ||
+ | \ C | ||
+ | \ Python | ||
+ | \ JAVA | ||
+ | Help | ||
+ | \ Contents | ||
+ | \ About | ||
- | + | </div> | |
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | + | A few decisions of what menus to include and which ones to divide or leave out need to be taken. For example, the "File" menu is a mandatory one and should be accessible from the main window's menu. On the other hand, the "Quit" sub menu is not really necessary, because the user can quit the application using the upper right corner's cross. Considering that the device has "+" and "-" keys, those can be assigned the functions of zooming in and out of the "View" menu. The "Copy", "Paste" and "Cut" actions from the "Edit" menu are also present in the application's toolbar as well as by using keyboard shortcuts so, they are not included in the menu. The "Indent Type" menu can be accomplished using app menu filters being, for this, removed from the "Edit" menu as well. This results in the "Edit" menu having only a sub menu "Preferences" which can be added to the app menu directly instead. | |
- | [[Image:example-migrating-menu1.png| | + | The following example shows the implementation of the menu following the above decisions. The first figure below shows the final result of the app menu. The other two figures show the sub views activated by the menus "View" and "Help", respectively. |
+ | |||
+ | [[Image:example-migrating-menu1.png|400px]] | ||
- | [[Image:example-migrating-menu-view.png| | + | [[Image:example-migrating-menu-view.png|400px]] [[Image:example-migrating-menu-help.png|400px]] |
'''Example 10.2. Migrating a menu''' | '''Example 10.2. Migrating a menu''' | ||
- | + | #include <hildon/hildon.h> | |
- | #include <hildon/hildon.h> | + | |
- | + | static void | |
- | + | normal_zoom_cb () | |
- | static void | + | { |
- | + | /* Code to set normal zoom... */ | |
- | { | + | |
- | + | hildon_window_stack_pop_1 (hildon_window_stack_get_default()); | |
- | + | } | |
- | + | ||
- | + | static void | |
- | + | view_subview () | |
- | + | { | |
- | + | HildonStackableWindow *view_window; | |
- | + | view_window = HILDON_STACKABLE_WINDOW (hildon_stackable_window_new ()); | |
- | + | gtk_window_set_title (GTK_WINDOW (view_window), "View"); | |
- | + | ||
- | + | GtkButton *normal_zoom_button = GTK_BUTTON (hildon_gtk_button_new ( | |
- | + | HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); | |
- | + | gtk_button_set_label (normal_zoom_button, "Normal Zoom"); | |
- | + | g_signal_connect (G_OBJECT (normal_zoom_button), "clicked", | |
- | + | G_CALLBACK (normal_zoom_cb), NULL); | |
- | + | ||
- | + | HildonTouchSelector *highlight_selector; | |
- | + | highlight_selector = HILDON_TOUCH_SELECTOR (hildon_touch_selector_new_text ()); | |
- | + | hildon_touch_selector_append_text (highlight_selector, "C"); | |
- | + | hildon_touch_selector_append_text (highlight_selector, "JAVA"); | |
- | + | hildon_touch_selector_append_text (highlight_selector, "Python"); | |
- | + | HildonPickerButton *highlight_picker = HILDON_PICKER_BUTTON (hildon_picker_button_new ( | |
- | + | HILDON_SIZE_THUMB_HEIGHT | HILDON_SIZE_HALFSCREEN_WIDTH, | |
- | + | HILDON_BUTTON_ARRANGEMENT_VERTICAL)); | |
- | + | hildon_button_set_title (HILDON_BUTTON (highlight_picker), "Syntax highlight:"); | |
- | + | hildon_picker_button_set_selector (highlight_picker, highlight_selector); | |
- | + | hildon_picker_button_set_active (highlight_picker, 0); | |
- | + | ||
- | + | GtkVBox *contents = GTK_VBOX (gtk_vbox_new (12, FALSE)); | |
- | + | gtk_box_pack_end (GTK_BOX (contents), GTK_WIDGET (highlight_picker), FALSE, FALSE, 0); | |
- | + | gtk_box_pack_end (GTK_BOX (contents), GTK_WIDGET (normal_zoom_button), FALSE, FALSE, 0); | |
- | + | ||
- | + | gtk_container_add (GTK_CONTAINER (view_window), GTK_WIDGET (contents)); | |
- | + | ||
- | + | gtk_widget_show_all (GTK_WIDGET (view_window)); | |
- | + | } | |
- | + | ||
- | + | static void | |
- | + | help_contents_cb (GtkButton *widget, gpointer data) | |
- | + | { | |
- | + | /* Code to set show help contents... */ | |
- | + | ||
- | + | hildon_window_stack_pop_1 (hildon_window_stack_get_default()); | |
+ | } | ||
+ | |||
+ | static void | ||
+ | help_about_cb (GtkButton *widget, gpointer data) | ||
+ | { | ||
+ | /* Code to set show about information... */ | ||
+ | |||
+ | hildon_window_stack_pop_1 (hildon_window_stack_get_default()); | ||
+ | } | ||
+ | |||
+ | static void | ||
+ | help_subview () | ||
+ | { | ||
+ | HildonStackableWindow *view_window; | ||
+ | view_window = HILDON_STACKABLE_WINDOW (hildon_stackable_window_new ()); | ||
+ | gtk_window_set_title (GTK_WINDOW (view_window), "Help"); | ||
+ | |||
+ | GtkButton *help_contents_button = GTK_BUTTON (hildon_gtk_button_new ( | ||
+ | HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); | ||
+ | gtk_button_set_label (help_contents_button, "Contents"); | ||
+ | g_signal_connect (G_OBJECT (help_contents_button), "clicked", | ||
+ | G_CALLBACK (help_contents_cb), NULL); | ||
+ | |||
+ | GtkButton *help_about_button = GTK_BUTTON (hildon_gtk_button_new ( | ||
+ | HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); | ||
+ | gtk_button_set_label (help_about_button, "About"); | ||
+ | g_signal_connect (G_OBJECT (help_about_button), "clicked", | ||
+ | G_CALLBACK (help_about_cb), NULL); | ||
+ | |||
+ | GtkVBox *contents = GTK_VBOX (gtk_vbox_new (12, FALSE)); | ||
+ | gtk_box_pack_end (GTK_BOX (contents), GTK_WIDGET (help_contents_button), FALSE, FALSE, 0); | ||
+ | gtk_box_pack_end (GTK_BOX (contents), GTK_WIDGET (help_about_button), FALSE, FALSE, 0); | ||
+ | |||
+ | gtk_container_add (GTK_CONTAINER (view_window), GTK_WIDGET (contents)); | ||
+ | |||
+ | gtk_widget_show_all (GTK_WIDGET (view_window)); | ||
+ | } | ||
+ | |||
+ | static HildonAppMenu * | ||
+ | build_menu (void) | ||
+ | { | ||
+ | HildonSizeType button_size = HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH; | ||
+ | HildonAppMenu *menu = HILDON_APP_MENU (hildon_app_menu_new ()); | ||
+ | GtkButton *button; | ||
+ | GtkRadioButton *filter; | ||
+ | |||
+ | /* Menus like New, Open, etc that would open new dialogs (no submenus) | ||
+ | * are not assigned any action in this example | ||
+ | */ | ||
+ | |||
+ | button = GTK_BUTTON (hildon_gtk_button_new (button_size)); | ||
+ | gtk_button_set_label (button, "New"); | ||
+ | hildon_app_menu_append (menu, GTK_BUTTON (button)); | ||
+ | |||
+ | button = GTK_BUTTON (hildon_gtk_button_new (button_size)); | ||
+ | gtk_button_set_label (button, "Open"); | ||
+ | hildon_app_menu_append (menu, GTK_BUTTON (button)); | ||
+ | |||
+ | button = GTK_BUTTON (hildon_gtk_button_new (button_size)); | ||
+ | gtk_button_set_label (button, "Save As"); | ||
+ | hildon_app_menu_append (menu, GTK_BUTTON (button)); | ||
+ | |||
+ | button = GTK_BUTTON (hildon_gtk_button_new (button_size)); | ||
+ | gtk_button_set_label (button, "Preferences"); | ||
+ | hildon_app_menu_append (menu, GTK_BUTTON (button)); | ||
+ | |||
+ | button = GTK_BUTTON (hildon_gtk_button_new (button_size)); | ||
+ | gtk_button_set_label (button, "View"); | ||
+ | g_signal_connect (G_OBJECT (button), "clicked", | ||
+ | G_CALLBACK (view_subview), NULL); | ||
+ | hildon_app_menu_append (menu, GTK_BUTTON (button)); | ||
+ | |||
+ | filter = GTK_RADIO_BUTTON (hildon_gtk_radio_button_new (button_size, NULL)); | ||
+ | gtk_button_set_label (GTK_BUTTON (filter), "Indentation: Spaces"); | ||
+ | hildon_app_menu_add_filter (menu, GTK_BUTTON (filter)); | ||
+ | gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (filter), FALSE); | ||
+ | |||
+ | button = GTK_BUTTON (hildon_gtk_button_new (button_size)); | ||
+ | gtk_button_set_label (button, "Help"); | ||
+ | g_signal_connect (G_OBJECT (button), "clicked", | ||
+ | G_CALLBACK (help_subview), NULL); | ||
+ | hildon_app_menu_append (menu, GTK_BUTTON (button)); | ||
+ | |||
+ | filter = GTK_RADIO_BUTTON (hildon_gtk_radio_button_new_from_widget (button_size, | ||
+ | GTK_RADIO_BUTTON (filter))); | ||
+ | gtk_button_set_label (GTK_BUTTON (filter), "Indentation: Tabs"); | ||
+ | hildon_app_menu_add_filter (menu, GTK_BUTTON (filter)); | ||
+ | gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (filter), FALSE); | ||
+ | |||
+ | return menu; | ||
+ | } | ||
+ | |||
+ | int | ||
+ | main (int argc, char **argv) | ||
+ | { | ||
+ | hildon_gtk_init (&argc, &argv); | ||
+ | |||
+ | GtkWidget *window; | ||
+ | window = hildon_stackable_window_new (); | ||
+ | gtk_window_set_title (GTK_WINDOW (window), "Editor"); | ||
+ | |||
+ | HildonAppMenu *menu = build_menu (); | ||
+ | hildon_stackable_window_set_main_menu (HILDON_STACKABLE_WINDOW (window), menu); | ||
+ | |||
+ | GtkWidget *contents = gtk_label_new ("This example shows how an app menu could be " | ||
+ | "divided.\nMenus that would open new dialogs " | ||
+ | "are not assigned any action."); | ||
+ | gtk_container_add (GTK_CONTAINER (window), contents); | ||
+ | |||
+ | /* ... other widgets in the application */ | ||
+ | |||
+ | g_signal_connect (G_OBJECT (window), "destroy", | ||
+ | G_CALLBACK (gtk_main_quit), NULL); | ||
+ | |||
+ | gtk_widget_show_all (window); | ||
+ | |||
+ | gtk_main (); | ||
+ | return 0; | ||
+ | } | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
==Choices == | ==Choices == | ||
- | |||
Some widgets for choosing options also need to be adapted to the new Hildon way of designing interfaces. If you have several radio buttons to express a choice, replacing them with a picker button is a good idea. | Some widgets for choosing options also need to be adapted to the new Hildon way of designing interfaces. If you have several radio buttons to express a choice, replacing them with a picker button is a good idea. | ||
Consider a dialog that includes, among other widgets, a frame labeled "Proxy Preferences" and three radio buttons: "None", "Auto" and "Manual", displayed vertically like Figure 10.1 "Three radio buttons" shows. The following example shows how such task could be accomplished using a picker button. The frame label becomes the picker button's title and the three radio buttons' labels become the choices in the picker's touch selector. The screenshot below shows the resulting graphical user interface. | Consider a dialog that includes, among other widgets, a frame labeled "Proxy Preferences" and three radio buttons: "None", "Auto" and "Manual", displayed vertically like Figure 10.1 "Three radio buttons" shows. The following example shows how such task could be accomplished using a picker button. The frame label becomes the picker button's title and the three radio buttons' labels become the choices in the picker's touch selector. The screenshot below shows the resulting graphical user interface. | ||
- | [[Image:choices.png| | + | [[Image:choices.png|Image choices]] |
'''Example 10.3. Migrating choice widgets''' | '''Example 10.3. Migrating choice widgets''' | ||
- | < | + | <tt><span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span> <span><font color="#FF0000"><hildon/hildon.h></font></span> |
- | #include <hildon/hildon.h> | + | <span><font color="#009900">int</font></span> |
- | int | + | <span>'''<span><font color="#000000">main</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#009900">int</font></span> argc<span><font color="#990000">,</font></span> <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> |
- | { | + | <span>'''<span><font color="#000000">hildon_gtk_init</font></span>'''</span> <span><font color="#990000">(&</font></span>argc<span><font color="#990000">,</font></span> <span><font color="#990000">&</font></span>argv<span><font color="#990000">);</font></span> |
- | + | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>window<span><font color="#990000"><nowiki>;</nowiki></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">gtk_window_set_title</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_WINDOW</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">),</font></span> <span><font color="#FF0000">"Preferences"</font></span><span><font color="#990000">);</font></span> | |
- | + | <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>window<span><font color="#990000">),</font></span> <span><font color="#FF0000">"destroy"</font></span><span><font color="#990000">,</font></span> | |
- | + | <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>gtk_main_quit<span><font color="#990000">),</font></span> NULL<span><font color="#990000">);</font></span> | |
- | + | HildonPickerButton <span><font color="#990000"><nowiki>*</nowiki></font></span>picker <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">HILDON_PICKER_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">hildon_picker_button_new</font></span>'''</span> <span><font color="#990000">(</font></span> | |
- | + | HILDON_SIZE_THUMB_HEIGHT <span><font color="#990000"><nowiki>|</nowiki></font></span> HILDON_SIZE_HALFSCREEN_WIDTH<span><font color="#990000">,</font></span> | |
- | + | HILDON_BUTTON_ARRANGEMENT_VERTICAL<span><font color="#990000">));</font></span> | |
- | + | <span>'''<span><font color="#000000">hildon_button_set_title</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">HILDON_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>picker<span><font color="#990000">),</font></span> <span><font color="#FF0000">"Proxy preferences:"</font></span><span><font color="#990000">);</font></span> | |
- | + | HildonTouchSelector <span><font color="#990000"><nowiki>*</nowiki></font></span>selector <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">HILDON_TOUCH_SELECTOR</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">hildon_touch_selector_new_text</font></span>'''</span> <span><font color="#990000">());</font></span> | |
- | + | <span>'''<span><font color="#000000">hildon_picker_button_set_selector</font></span>'''</span> <span><font color="#990000">(</font></span>picker<span><font color="#990000">,</font></span> selector<span><font color="#990000">);</font></span> | |
- | + | <span>'''<span><font color="#000000">hildon_touch_selector_append_text</font></span>'''</span> <span><font color="#990000">(</font></span>selector<span><font color="#990000">,</font></span> <span><font color="#FF0000">"None"</font></span><span><font color="#990000">);</font></span> | |
- | + | <span>'''<span><font color="#000000">hildon_touch_selector_append_text</font></span>'''</span> <span><font color="#990000">(</font></span>selector<span><font color="#990000">,</font></span> <span><font color="#FF0000">"Auto"</font></span><span><font color="#990000">);</font></span> | |
- | + | <span>'''<span><font color="#000000">hildon_touch_selector_append_text</font></span>'''</span> <span><font color="#990000">(</font></span>selector<span><font color="#990000">,</font></span> <span><font color="#FF0000">"Manual"</font></span><span><font color="#990000">);</font></span> | |
- | + | <span>'''<span><font color="#000000">hildon_picker_button_set_active</font></span>'''</span> <span><font color="#990000">(</font></span>picker<span><font color="#990000">,</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">);</font></span> | |
- | + | GtkVBox <span><font color="#990000"><nowiki>*</nowiki></font></span>contents <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">GTK_VBOX</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">gtk_vbox_new</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#993399">12</font></span><span><font color="#990000">,</font></span> FALSE<span><font color="#990000">));</font></span> | |
- | + | <span>''<span><font color="#9A1900">/* ... other widgets placed here */</font></span>''</span> | |
- | + | <span>'''<span><font color="#000000">gtk_box_pack_end</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_BOX</font></span>'''</span> <span><font color="#990000">(</font></span>contents<span><font color="#990000">),</font></span> <span>'''<span><font color="#000000">GTK_WIDGET</font></span>'''</span> <span><font color="#990000">(</font></span>picker<span><font color="#990000">),</font></span> FALSE<span><font color="#990000">,</font></span> FALSE<span><font color="#990000">,</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">);</font></span> | |
- | + | <span>'''<span><font color="#000000">gtk_container_add</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_CONTAINER</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">),</font></span> <span>'''<span><font color="#000000">GTK_WIDGET</font></span>'''</span> <span><font color="#990000">(</font></span>contents<span><font color="#990000">));</font></span> | |
- | + | <span>'''<span><font color="#000000">gtk_widget_show_all</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> |
- | </ | + | |
==Notebooks == | ==Notebooks == | ||
+ | Because the use of notebooks is not advised in Hildon, this widget does not have to be replaced to be updated. | ||
+ | |||
+ | Imagine a preferences dialog that has a notebook to divide the preferences in "General", "Colors" and "Tools" like depicted in Figure 10.2 “Typical Notebook”. The way to accomplish the same functionality without having a notebook is to use a window with buttons that open other windows as subviews. Each window opened using the buttons should have the content that the respective page in the notebook had. | ||
+ | |||
+ | '''Figure 10.2. Typical Notebook''' | ||
+ | |||
+ | [[Image:notebook.png|Image notebook]] | ||
+ | |||
+ | The example shows the code to produce a replacement for the notebook (see @@IMAGE@@). | ||
- | + | '''Example 10.4. Migrating a notebook''' | |
- | + | <tt><span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span> <span><font color="#FF0000"><hildon/hildon.h></font></span> | |
- | + | <span>'''<span><font color="#0000FF">static</font></span>'''</span> HildonStackableWindow <span><font color="#990000"><nowiki>*</nowiki></font></span> | |
- | + | <span>'''<span><font color="#000000">new_preferences_window</font></span>'''</span> <span><font color="#990000">(</font></span>gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>title<span><font color="#990000">)</font></span> | |
+ | <span><font color="#FF0000">{</font></span> | ||
+ | HildonStackableWindow <span><font color="#990000"><nowiki>*</nowiki></font></span>pref_window<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | pref_window <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">HILDON_STACKABLE_WINDOW</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">hildon_stackable_window_new</font></span>'''</span> <span><font color="#990000">());</font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_window_set_title</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_WINDOW</font></span>'''</span> <span><font color="#990000">(</font></span>pref_window<span><font color="#990000">),</font></span> title<span><font color="#990000">);</font></span> | ||
+ | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>content <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_label_new</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">g_strdup_printf</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"Set the %s Preferences"</font></span><span><font color="#990000">,</font></span> title<span><font color="#990000">));</font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_widget_show</font></span>'''</span> <span><font color="#990000">(</font></span>content<span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_container_add</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_CONTAINER</font></span>'''</span> <span><font color="#990000">(</font></span>pref_window<span><font color="#990000">),</font></span> content<span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#0000FF">return</font></span>'''</span> pref_window<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | <span><font color="#FF0000">}</font></span> | ||
+ | <span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span> | ||
+ | <span>'''<span><font color="#000000">button_clicked_cb</font></span>'''</span> <span><font color="#990000">(</font></span>GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>button<span><font color="#990000">,</font></span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>title<span><font color="#990000">)</font></span> | ||
+ | <span><font color="#FF0000">{</font></span> | ||
+ | HildonStackableWindow <span><font color="#990000"><nowiki>*</nowiki></font></span>sw <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">new_preferences_window</font></span>'''</span> <span><font color="#990000">(</font></span>title<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>sw<span><font color="#990000">));</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> | ||
+ | <span>'''<span><font color="#000000">hildon_gtk_init</font></span>'''</span> <span><font color="#990000">(&</font></span>argc<span><font color="#990000">,</font></span> <span><font color="#990000">&</font></span>argv<span><font color="#990000">);</font></span> | ||
+ | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>window<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | GtkButton <span><font color="#990000"><nowiki>*</nowiki></font></span>general_pref_button<span><font color="#990000">,</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>colors_pref_button<span><font color="#990000">,</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>tools_pref_button<span><font color="#990000"><nowiki>;</nowiki></font></span> | ||
+ | window <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_stackable_window_new</font></span>'''</span> <span><font color="#990000">();</font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_window_set_title</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_WINDOW</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">),</font></span> <span><font color="#FF0000">"Preferences"</font></span><span><font color="#990000">);</font></span> | ||
+ | general_pref_button <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">GTK_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">hildon_gtk_button_new</font></span>'''</span> <span><font color="#990000">(</font></span>HILDON_SIZE_AUTO_HEIGHT<span><font color="#990000">));</font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_button_set_label</font></span>'''</span> <span><font color="#990000">(</font></span>general_pref_button<span><font color="#990000">,</font></span> <span><font color="#FF0000">"General"</font></span><span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span>general_pref_button<span><font color="#990000">,</font></span> <span><font color="#FF0000">"clicked"</font></span><span><font color="#990000">,</font></span> | ||
+ | <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>button_clicked_cb<span><font color="#990000">),</font></span> <span><font color="#FF0000">"General"</font></span><span><font color="#990000">);</font></span> | ||
+ | colors_pref_button <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">GTK_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">hildon_gtk_button_new</font></span>'''</span> <span><font color="#990000">(</font></span>HILDON_SIZE_AUTO_HEIGHT<span><font color="#990000">));</font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_button_set_label</font></span>'''</span> <span><font color="#990000">(</font></span>colors_pref_button<span><font color="#990000">,</font></span> <span><font color="#FF0000">"Colors"</font></span><span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span>colors_pref_button<span><font color="#990000">,</font></span> <span><font color="#FF0000">"clicked"</font></span><span><font color="#990000">,</font></span> | ||
+ | <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>button_clicked_cb<span><font color="#990000">),</font></span> <span><font color="#FF0000">"Colors"</font></span><span><font color="#990000">);</font></span> | ||
+ | tools_pref_button <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">GTK_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">hildon_gtk_button_new</font></span>'''</span> <span><font color="#990000">(</font></span>HILDON_SIZE_AUTO_HEIGHT<span><font color="#990000">));</font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_button_set_label</font></span>'''</span> <span><font color="#990000">(</font></span>tools_pref_button<span><font color="#990000">,</font></span> <span><font color="#FF0000">"Tools"</font></span><span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span>tools_pref_button<span><font color="#990000">,</font></span> <span><font color="#FF0000">"clicked"</font></span><span><font color="#990000">,</font></span> | ||
+ | <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>button_clicked_cb<span><font color="#990000">),</font></span> <span><font color="#FF0000">"Tools"</font></span><span><font color="#990000">);</font></span> | ||
+ | GtkVBox <span><font color="#990000"><nowiki>*</nowiki></font></span>contents <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">GTK_VBOX</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">gtk_vbox_new</font></span>'''</span> <span><font color="#990000">(</font></span>TRUE<span><font color="#990000">,</font></span> <span><font color="#993399">12</font></span><span><font color="#990000">));</font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_container_add</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_CONTAINER</font></span>'''</span> <span><font color="#990000">(</font></span>contents<span><font color="#990000">),</font></span> <span>'''<span><font color="#000000">GTK_WIDGET</font></span>'''</span> <span><font color="#990000">(</font></span>general_pref_button<span><font color="#990000">));</font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_container_add</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_CONTAINER</font></span>'''</span> <span><font color="#990000">(</font></span>contents<span><font color="#990000">),</font></span> <span>'''<span><font color="#000000">GTK_WIDGET</font></span>'''</span> <span><font color="#990000">(</font></span>colors_pref_button<span><font color="#990000">));</font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_container_add</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_CONTAINER</font></span>'''</span> <span><font color="#990000">(</font></span>contents<span><font color="#990000">),</font></span> <span>'''<span><font color="#000000">GTK_WIDGET</font></span>'''</span> <span><font color="#990000">(</font></span>tools_pref_button<span><font color="#990000">));</font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_container_add</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_CONTAINER</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">),</font></span> <span>'''<span><font color="#000000">GTK_WIDGET</font></span>'''</span> <span><font color="#990000">(</font></span>contents<span><font color="#990000">));</font></span> | ||
+ | <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>window<span><font color="#990000">),</font></span> <span><font color="#FF0000">"destroy"</font></span><span><font color="#990000">,</font></span> | ||
+ | <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>gtk_main_quit<span><font color="#990000">),</font></span> NULL<span><font color="#990000">);</font></span> | ||
+ | <span>'''<span><font color="#000000">gtk_widget_show_all</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> |
Learn more about Contributing to the wiki.