GTK Questions
This section describes how to migrate the applications base on Gtk+-2.0 to make it LSB compliant. There are many depricated, experimenatal and private functions exposed by GTK which are not meant for application developers and hence are not in LSB 3.1. Fortunately, Gtk maintainers have written some documents explaining how to move from some of the depricated set of interefaces to new ones. These documents can be found at http://developer.gnome.org/doc/API/2.0/gtk/index.html Section IV.
This section is provided as an add-on section to those documents.
1. Migrating from the original headers: Because LSB only provides only the high level headers for each library, the lower level headers like '#include <gtk/gtktooltips.h>' need to be replaced by higher level one like '#include <gtk/gtk.h>'; and it's the same for glib, atk and pango.
2. Migrating from GtkOptionMenu to GtkComboBox: In the gtk-doc, there is a paper to decribe how to migrate the GtkOptionMenu to GtkComboBox, but that's a simple guide. Whiling migrating the application Gaim, some specific usage need to be highlighted.
a. gtk_option_menu_new: If we want to create a new option menu only for the text, we can use gtk_combo_box_entry_new_text. But if we want to create a new option menu with texts and pictures, we have to use gtk_combo_box_entry_new_with_model.
b. gtk_option_menu_remove_menu: For replacing the gtk_option_menu_remove_menu, the gtk_cell_layout_clear should be used. Original, after using gtk_option_menu_remove_menu, the function gtk_option_menu_set_menu would be used to add a new menu. But for using the GtkComboBox, we don't need to add new menu, and we only need to clear the cell layout, then add new elements.
c. gtk_option_menu_set_history, gtk_option_menu_get_history: The function gtk_combo_box_set_active is used to replace gtk_option_menu_set_history. The function gtk_combo_box_get_active is used to replace gtk_option_menu_get_history.
d. set the data using g_object_set_data(): In the gaim, there are some specific usage. For example: g_object_set_data(G_OBJECT(item), "account", account); //the item is generated by the function gtk_menu_item_new. it means setting the value for the key "type" for each menu items. Because for the GtkOptionMenu, each menu item is a widget inherited from the GObject. But for the GtkComboBox, each item is a text or a GtkListStore structures. The GtkListStore implements the GtkTreeModel interface, it means it is inherited from GInterface. So we cannot use g_object_set_data to set the value for each menu_item. In the gaim, we use the GtkComboBox to store the value for each menu items, but we define the different keys. The example is below:
GString *ac_account = g_string_sized_new(10); g_string_append_printf(ac_account, "%s%d", "account", i); g_object_set_data(G_OBJECT(optmenu), ac_account->str, account);
3. migrate from GtkItemFactory to GtkUIManager: Just two points: one is using GtkToggleActionEntry to replace <CheckItem>. The other is the action for <CheckItem> should be action_function(GtkAction *action, gpointer data)
4. gtk_toolbar_insert_stock: This is an example:
toolbar = gtk_toolbar_new(); gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_FIND, NULL, NULL, G_CALLBACK(find_cb), win, -1);
we should use:
toolbutton = gtk_tool_button_new_from_stock(GTK_STOCK_FIND); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(toolbutton), -1); g_signal_connect(toolbutton, "clicked", G_CALLBACK(find_cb), win);
to replace it. But if the icon on the button is from an image. For example:
image = gtk_image_new_from_stock(GAIM_STOCK_PAUSE, GTK_ICON_SIZE_MENU);
button = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
GTK_TOOLBAR_CHILD_TOGGLEBUTTON,
NULL, _("Pause"), NULL, NULL,
image, G_CALLBACK(pause_cb), win);
we should use
image = gtk_image_new_from_stock(GAIM_STOCK_PAUSE, GTK_ICON_SIZE_MENU);
GtkWidget *item = gtk_tool_button_new(image, _("Pause"));
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);
g_signal_connect(item, "clicked", G_CALLBACK(pause_cb), win);


