[patch] replacing GtkOptionMenu by GktComboBox
Douglas Burke <[email protected]>
| Newsgroups | gmane.editors.conglomerate.devel |
|---|---|
| Message-ID | <Pine.GSO.4.58.0410131359570.10883@lagado> |
This patch completes the move from GtkOptionMenu to GtkComboBox I started way back in August. Doug
cong.diff
(text/plain, 18.8 KB)
Index: glade/ChangeLog =================================================================== RCS file: /cvs/gnome/conglomerate/glade/ChangeLog,v retrieving revision 1.9 diff -u -r1.9 ChangeLog --- glade/ChangeLog 28 Sep 2004 03:43:22 -0000 1.9 +++ glade/ChangeLog 13 Oct 2004 17:58:29 -0000 @@ -1,3 +1,9 @@ +2004-10-13 Douglas Burke <[email protected]> + + * plugin-random.glade: + + Changed GtkOptionMenu to GtkComboBox. + 2004-09-27 David Malcolm <[email protected]> * docbook-common-properties.glade: Index: glade/plugin-random.glade =================================================================== RCS file: /cvs/gnome/conglomerate/glade/plugin-random.glade,v retrieving revision 1.1 diff -u -r1.1 plugin-random.glade --- glade/plugin-random.glade 19 Jan 2004 22:01:10 -0000 1.1 +++ glade/plugin-random.glade 13 Oct 2004 17:58:29 -0000 @@ -65,10 +65,10 @@ <property name="spacing">0</property> <child> - <widget class="GtkOptionMenu" id="optionmenu_doctype"> + <widget class="GtkComboBox" id="combobox_doctype"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="history">-1</property> + <property name="items" translatable="no">dummy-item</property> </widget> <packing> <property name="padding">0</property> Index: src/ChangeLog =================================================================== RCS file: /cvs/gnome/conglomerate/src/ChangeLog,v retrieving revision 1.728 diff -u -r1.728 ChangeLog --- src/ChangeLog 13 Oct 2004 00:27:05 -0000 1.728 +++ src/ChangeLog 13 Oct 2004 17:58:29 -0000 @@ -1,3 +1,13 @@ +2004-10-13 Douglas Burke <[email protected]> + + * cong-file-export.c, cong-file-print.c, plugin-random.c + + Updated to use GtkComboBox rather than GtkOptionMenu. + + * cong-eel.c, cong-eel.h + + Removed the cong_eel_option_menu_get_selected_menu_item() function. + 2004-10-12 Douglas Burke <[email protected]> * plugin-validate.c Index: src/cong-eel.c =================================================================== RCS file: /cvs/gnome/conglomerate/src/cong-eel.c,v retrieving revision 1.13 diff -u -r1.13 cong-eel.c --- src/cong-eel.c 25 Jun 2004 00:33:02 -0000 1.13 +++ src/cong-eel.c 13 Oct 2004 17:58:29 -0000 @@ -170,40 +170,6 @@ return g_strdup_printf ("#%06X", (guint) (color & 0xFFFFFF)); } -/** - * cong_eel_option_menu_get_selected_menu_item: - * @option_menu: - * - * TODO: Write me - * Returns: - */ -GtkMenuItem* -cong_eel_option_menu_get_selected_menu_item(GtkOptionMenu *option_menu) -{ - gint selected_index; - GList *list_of_menu_items; - GtkMenuItem *selected_menu_item; - - g_return_val_if_fail (option_menu, NULL); - - selected_index = gtk_option_menu_get_history (option_menu); - - if (selected_index==-1) { - /* Nothing selected: */ - return NULL; - } - - list_of_menu_items = gtk_container_get_children (GTK_CONTAINER(gtk_option_menu_get_menu(option_menu))); - g_assert(list_of_menu_items); - - selected_menu_item = g_list_nth_data (list_of_menu_items, selected_index); - - g_list_free (list_of_menu_items); - - return selected_menu_item; - -} - static gchar* cong_eel_utf8_capitalise(const gchar *str) { Index: src/cong-eel.h =================================================================== RCS file: /cvs/gnome/conglomerate/src/cong-eel.h,v retrieving revision 1.8 diff -u -r1.8 cong-eel.h --- src/cong-eel.h 11 Sep 2003 15:19:53 -0000 1.8 +++ src/cong-eel.h 13 Oct 2004 17:58:29 -0000 @@ -150,10 +150,6 @@ (CONG_EEL_ACCESS_METHOD (class_cast_macro, object, method) ? 0 : \ CONG_EEL_INVOKE_METHOD (class_cast_macro, object, method, parameters)) - -/* This isn't from eel, but perhaps should be: */ -GtkMenuItem* cong_eel_option_menu_get_selected_menu_item (GtkOptionMenu *option_menu); - /* This isn't from eel, but perhaps should be: */ /* Routines that take an xml tag or attribute name e.g. <conditional-page-master-reference>, split it into words, and apply the given capitalisation (see the GNOME HIG for descriptions of capitalisation) Index: src/cong-file-export.c =================================================================== RCS file: /cvs/gnome/conglomerate/src/cong-file-export.c,v retrieving revision 1.21 diff -u -r1.21 cong-file-export.c --- src/cong-file-export.c 30 Jul 2004 04:18:40 -0000 1.21 +++ src/cong-file-export.c 13 Oct 2004 17:58:29 -0000 @@ -43,8 +43,8 @@ GtkDialog *dialog; GtkEntry *filename_entry; - GtkWidget *select_exporter_menu; - GtkOptionMenu *select_exporter_option_menu; + GtkWidget *combo_box; + GPtrArray *combo_array; GtkLabel *description; guint connection_id; GtkWidget *option_holder; @@ -56,19 +56,18 @@ static CongServiceExporter* get_selected_exporter(CongExportDialogDetails *dialog_details) { - GtkMenuItem* selected_menu_item; + gint selected; + g_return_val_if_fail (dialog_details, NULL); - g_return_val_if_fail(dialog_details, NULL); + selected = gtk_combo_box_get_active( GTK_COMBO_BOX(dialog_details->combo_box) ); - /* Which plugin has been selected? */ - selected_menu_item = cong_eel_option_menu_get_selected_menu_item (dialog_details->select_exporter_option_menu); - - if (selected_menu_item) { - return (CongServiceExporter*)g_object_get_data(G_OBJECT(selected_menu_item), - "exporter"); - } else { + /* can selected ever be -1 here? */ + if ( selected == -1 ) { return NULL; + } else { + return (CongServiceExporter*)g_ptr_array_index (dialog_details->combo_array, selected); } + } static void add_exporter_to_menu(CongServiceExporter *exporter, gpointer user_data) @@ -77,17 +76,12 @@ if (cong_exporter_supports_document(exporter, dialog_details->doc)) { - GtkWidget *menu = dialog_details->select_exporter_menu; - - GtkMenuItem *menu_item = GTK_MENU_ITEM(gtk_menu_item_new_with_label( cong_service_get_name(CONG_SERVICE(exporter)))); + /* g_message( "adding exporter to menu - %s", cong_service_get_name(CONG_SERVICE(exporter)) ); */ - gtk_menu_shell_append(GTK_MENU_SHELL(menu), - GTK_WIDGET(menu_item)); - - g_object_set_data(G_OBJECT(menu_item), - "exporter", - exporter); + gtk_combo_box_append_text (GTK_COMBO_BOX (dialog_details->combo_box), + cong_service_get_name(CONG_SERVICE(exporter)) ); + g_ptr_array_add (dialog_details->combo_array, (gpointer) exporter); dialog_details->got_any_exporters = TRUE; } } @@ -181,7 +175,7 @@ } } -static void on_exporter_selection_changed(GtkOptionMenu *optionmenu, +static void on_exporter_selection_changed(GtkWidget *combo_box, gpointer user_data) { CongExportDialogDetails *details = user_data; @@ -231,6 +225,20 @@ } } +/* + * The change to use a GtkComboBox rather than a GtkOptionMenu + * means that a GPtrArray is used to store the exporter information, + * rather than the old scheme of storing this information in the + * option menu itself (or rather the GtkMenuItem). It means that + * the CongExportDialogDetails structure now needs to be + * explicitly cleaned up (in order to free up the GPtrArray). + * + * The use of the GtkComboBox probably does not preclude the old style, + * it is just that I find this way easier. + * + * Doug. + */ + static GtkWidget *cong_document_export_dialog_new(CongDocument *doc, GtkWindow *parent_window) { @@ -274,14 +282,15 @@ /* Set up exporter selection option menu: */ { - dialog_details->select_exporter_option_menu = GTK_OPTION_MENU(gtk_option_menu_new()); - dialog_details->select_exporter_menu = gtk_menu_new(); - gtk_option_menu_set_menu(dialog_details->select_exporter_option_menu, - dialog_details->select_exporter_menu); - - cong_plugin_manager_for_each_exporter(cong_app_get_plugin_manager (cong_app_singleton()), add_exporter_to_menu, dialog_details); + dialog_details->combo_box = gtk_combo_box_new_text(); + dialog_details->combo_array = g_ptr_array_new (); + + cong_plugin_manager_for_each_exporter (cong_app_get_plugin_manager (cong_app_singleton()), + add_exporter_to_menu, + dialog_details); + + gtk_combo_box_set_active (GTK_COMBO_BOX(dialog_details->combo_box), 0); - gtk_option_menu_set_history(dialog_details->select_exporter_option_menu,0); } dialog_details->description = GTK_LABEL(gtk_label_new(NULL)); @@ -305,7 +314,7 @@ gtk_box_pack_start(GTK_BOX(hbox), select_filename_button, FALSE, FALSE,0); } - cong_dialog_category_add_field(general_category, _("Exporter:"), GTK_WIDGET(dialog_details->select_exporter_option_menu), FALSE); + cong_dialog_category_add_field(general_category, _("Exporter:"), GTK_WIDGET(dialog_details->combo_box), FALSE); cong_dialog_category_add_field(general_category, "", GTK_WIDGET(dialog_details->description), FALSE); cong_dialog_category_add_field(general_category, _("File:"), hbox, TRUE); @@ -322,7 +331,7 @@ setup_options(dialog_details); } - g_signal_connect(dialog_details->select_exporter_option_menu, + g_signal_connect(dialog_details->combo_box, "changed", G_CALLBACK(on_exporter_selection_changed), dialog_details); @@ -345,6 +354,23 @@ return dialog; } +static void +cong_document_export_dialog_delete (GtkWidget *dialog) +{ + CongExportDialogDetails *dialog_details; + g_assert (dialog); + + dialog_details = g_object_get_data (G_OBJECT(dialog), + "dialog_details"); + g_assert (dialog_details); + + if ( dialog_details->combo_array ) + g_ptr_array_free (dialog_details->combo_array, FALSE); + + gtk_widget_destroy (dialog); + g_free (dialog_details); +} + /** * cong_ui_hook_file_export: * @doc: @@ -418,7 +444,6 @@ } /* FIXME: Somewhat hackish cleanup: */ - gtk_widget_destroy(dialog); + cong_document_export_dialog_delete (dialog); - g_free(dialog_details); } Index: src/cong-file-print.c =================================================================== RCS file: /cvs/gnome/conglomerate/src/cong-file-print.c,v retrieving revision 1.12 diff -u -r1.12 cong-file-print.c --- src/cong-file-print.c 18 Apr 2004 05:32:29 -0000 1.12 +++ src/cong-file-print.c 13 Oct 2004 17:58:29 -0000 @@ -47,24 +47,23 @@ gboolean got_any_print_methods; GtkDialog *dialog; - GtkOptionMenu *select_print_method_option_menu; + GtkWidget *combo_box; + GPtrArray *combo_array; GtkWidget *select_print_method_menu; } CongPrintDialogDetails; static CongServicePrintMethod* get_selected_print_method(CongPrintDialogDetails *dialog_details) { - GtkMenuItem* selected_menu_item; - + gint selected; g_return_val_if_fail(dialog_details, NULL); - /* Which plugin has been selected? */ - selected_menu_item = cong_eel_option_menu_get_selected_menu_item (dialog_details->select_print_method_option_menu); - - if (selected_menu_item) { - return (CongServicePrintMethod*)g_object_get_data(G_OBJECT(selected_menu_item), - "print_method"); - } else { + selected = gtk_combo_box_get_active( GTK_COMBO_BOX(dialog_details->combo_box) ); + + /* can selected ever be -1 here? */ + if ( selected == -1 ) { return NULL; + } else { + return (CongServicePrintMethod*)g_ptr_array_index (dialog_details->combo_array, selected); } } @@ -73,17 +72,15 @@ CongPrintDialogDetails *dialog_details = (CongPrintDialogDetails*)user_data; if (cong_print_method_supports_document(print_method, dialog_details->doc)) { - GtkWidget *menu = dialog_details->select_print_method_menu; - GtkMenuItem *menu_item = GTK_MENU_ITEM(gtk_menu_item_new_with_label( cong_service_get_name(CONG_SERVICE(print_method)))); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), - GTK_WIDGET(menu_item)); - - g_object_set_data(G_OBJECT(menu_item), - "print_method", - print_method); + /* g_message( "adding print method to menu - %s", cong_service_get_name(CONG_SERVICE(exporter)) ); */ + + gtk_combo_box_append_text (GTK_COMBO_BOX (dialog_details->combo_box), + cong_service_get_name(CONG_SERVICE(exporter)) ); + g_ptr_array_add (dialog_details->combo_array, (gpointer) exporter); dialog_details->got_any_print_methods = TRUE; + } } @@ -124,10 +121,11 @@ } #endif -static void on_print_method_selection_changed(GtkOptionMenu *optionmenu, +static void on_print_method_selection_changed(GtkWidget *combo_box, gpointer user_data) { #if 0 + /* NOTE: this would need to be changed since we now use a ComboBox for the menu */ GtkWidget* menu = gtk_option_menu_get_menu(optionmenu); CongPrintDialogDetails *details = user_data; #endif @@ -220,20 +218,20 @@ /* Set up print_method selection option menu: */ { - dialog_details->select_print_method_option_menu = GTK_OPTION_MENU(gtk_option_menu_new()); - dialog_details->select_print_method_menu = gtk_menu_new(); - gtk_option_menu_set_menu(dialog_details->select_print_method_option_menu, - dialog_details->select_print_method_menu); - - cong_plugin_manager_for_each_print_method (cong_app_get_plugin_manager (cong_app_singleton ()), - add_print_method_to_menu, + dialog_details->combo_box = gtk_combo_box_new_text(); + dialog_details->combo_array = g_ptr_array_new (); + + cong_plugin_manager_for_each_print_method (cong_app_get_plugin_manager (cong_app_singleton()), + add_print_method_to_menu, dialog_details); - gtk_option_menu_set_history(dialog_details->select_print_method_option_menu,0); + + gtk_combo_box_set_active (GTK_COMBO_BOX(dialog_details->combo_box), 0); + } cong_dialog_category_add_field (general_category, _("Print Method:"), - GTK_WIDGET(dialog_details->select_print_method_option_menu), + GTK_WIDGET(dialog_details->combo_box), TRUE); #if 0 @@ -242,7 +240,7 @@ print_method_category = cong_dialog_content_add_category(content, _("Print Options")); - g_signal_connect(dialog_details->select_print_method_option_menu, + g_signal_connect(dialog_details->combo_box, "changed", G_CALLBACK(on_print_method_selection_changed), dialog_details); @@ -266,6 +264,23 @@ } static void +cong_document_print_dialog_delete (GtkWidget *dialog) +{ + CongExportDialogDetails *dialog_details; + g_assert (dialog); + + dialog_details = g_object_get_data (G_OBJECT(dialog), + "dialog_details"); + g_assert (dialog_details); + + if ( dialog_details->combo_array ) + g_ptr_array_free (dialog_details->combo_array, FALSE); + + gtk_widget_destroy (dialog); + g_free (dialog_details); +} + +static void do_ui_file_print(CongDocument *doc, GtkWindow *toplevel_window, gboolean is_preview) @@ -338,8 +353,7 @@ gtk_widget_destroy(GTK_WIDGET(error_dialog)); } - gtk_widget_destroy(dialog); - g_free(dialog_details); + cong_document_print_dialog_delete (dialog); } Index: src/plugin-random.c =================================================================== RCS file: /cvs/gnome/conglomerate/src/plugin-random.c,v retrieving revision 1.12 diff -u -r1.12 plugin-random.c --- src/plugin-random.c 25 Jun 2004 00:33:03 -0000 1.12 +++ src/plugin-random.c 13 Oct 2004 17:58:29 -0000 @@ -50,8 +50,8 @@ GnomeDruidPageStandard *page; GladeXML *xml; GtkWidget *middle_page; - GtkOptionMenu *dispspec_option_menu; - GtkMenu *dispspec_menu; + GtkWidget *combo_box; + GPtrArray *combo_array; }; struct RandomCreationInfo @@ -66,16 +66,14 @@ static CongDispspec* random_gui_get_selected_dispspec (RandomGUI *random_gui) { - GtkMenuItem *selected_menu_item; - + gint selected; g_assert (random_gui); - g_assert (random_gui->dispspec_option_menu); + g_assert (random_gui->combo_box); + + selected = gtk_combo_box_get_active( GTK_COMBO_BOX(random_gui->combo_box) ); + g_return_val_if_fail (selected != -1, NULL); + return (CongDispspec*)g_ptr_array_index (random_gui->combo_array, selected ); - selected_menu_item = cong_eel_option_menu_get_selected_menu_item (random_gui->dispspec_option_menu); - g_assert (selected_menu_item); - - return (CongDispspec*)g_object_get_data (G_OBJECT (selected_menu_item), - "dispspec"); } static gint @@ -91,20 +89,12 @@ random_gui_add_option_for_dispspec (RandomGUI *random_gui, CongDispspec *dispspec) { - GtkMenuItem *menu_item; - g_assert (random_gui); g_assert (dispspec); - menu_item = GTK_MENU_ITEM (gtk_menu_item_new_with_label ( cong_dispspec_get_name (dispspec))); - gtk_widget_show (GTK_WIDGET (menu_item)); - - gtk_menu_shell_append (GTK_MENU_SHELL (random_gui->dispspec_menu), - GTK_WIDGET (menu_item)); - - g_object_set_data (G_OBJECT (menu_item), - "dispspec", - dispspec); + gtk_combo_box_append_text (GTK_COMBO_BOX (random_gui->combo_box), + cong_dispspec_get_name (dispspec) ); + g_ptr_array_add (random_gui->combo_array, (gpointer) dispspec); } static void @@ -116,6 +106,9 @@ random_gui = (RandomGUI*)factory_data; + if ( random_gui->combo_array ) + g_ptr_array_free (random_gui->combo_array, FALSE); + g_object_unref (G_OBJECT (random_gui->xml)); g_free (random_gui); } @@ -156,12 +149,21 @@ random_gui->middle_page, ""); - random_gui->dispspec_option_menu = GTK_OPTION_MENU (glade_xml_get_widget (random_gui->xml, "optionmenu_doctype")); - random_gui->dispspec_menu = GTK_MENU (gtk_menu_new()); - gtk_option_menu_set_menu (random_gui->dispspec_option_menu, - GTK_WIDGET (random_gui->dispspec_menu)); - gtk_widget_show (GTK_WIDGET (random_gui->dispspec_menu)); - + /* + * In order to get the combo box to work in its "simple" mode - i.e. + * without having to create a list store - I seem to have to have at + * least one "items" entry in Glade. So we delete it here. Which is + * plain ugly. Is there a way to tell glade that we want the "simple" + * form of the GtkComboBox widget? Aha. I can hack the glade file so that + * it has an items property for the widget, but that the contents are + * empty. This could be fragile (I don't know what glade will do it saves + * the file), so I leave in the "dummy-item" which we have to delete. + * Doug Burke + */ + random_gui->combo_box = glade_xml_get_widget (random_gui->xml, "combobox_doctype"); + gtk_combo_box_remove_text (GTK_COMBO_BOX(random_gui->combo_box), 0 ); + random_gui->combo_array = g_ptr_array_new (); + /* Generate the available document types from the dispspecs that are known */ { unsigned int i; @@ -174,8 +176,9 @@ cong_dispspec_registry_get (ds_registry, i)); } - gtk_option_menu_set_history (random_gui->dispspec_option_menu, - 0); + gtk_combo_box_set_active (GTK_COMBO_BOX(random_gui->combo_box), 0); + gtk_widget_show (random_gui->combo_box); + } cong_new_file_assistant_set_data_for_factory (assistant,