From 2de2e7f12f3b4e5944732d1c2172a3d174d5a219 Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Wed, 27 Oct 2010 21:43:25 +0200 Subject: Workaround GtkComboBoxText/GtkComboBoxEntry in .ui files --- addressbook/gui/contact-editor/contact-editor.ui | 8 +-- calendar/gui/dialogs/event-page.ui | 2 +- e-util/e-datetime-format.c | 2 +- e-util/e-util.c | 8 +++ e-util/gtk-compat.h | 66 ++++++++++++++++++++++++ filter/filter.ui | 2 +- mail/mail-config.ui | 6 +-- smime/gui/smime-ui.ui | 2 +- widgets/misc/e-dateedit.c | 24 ++++++--- 9 files changed, 103 insertions(+), 17 deletions(-) diff --git a/addressbook/gui/contact-editor/contact-editor.ui b/addressbook/gui/contact-editor/contact-editor.ui index 88c90c1c31..1c0dcca2ac 100644 --- a/addressbook/gui/contact-editor/contact-editor.ui +++ b/addressbook/gui/contact-editor/contact-editor.ui @@ -376,7 +376,7 @@ - + True model2 @@ -392,7 +392,7 @@ - + True model3 @@ -410,7 +410,7 @@ - + True model4 @@ -428,7 +428,7 @@ - + True model5 diff --git a/calendar/gui/dialogs/event-page.ui b/calendar/gui/dialogs/event-page.ui index 17919048a6..fe3ece21ca 100644 --- a/calendar/gui/dialogs/event-page.ui +++ b/calendar/gui/dialogs/event-page.ui @@ -1059,7 +1059,7 @@ - + True False True diff --git a/e-util/e-datetime-format.c b/e-util/e-datetime-format.c index e78b8cfe5e..f5155be612 100644 --- a/e-util/e-datetime-format.c +++ b/e-util/e-datetime-format.c @@ -513,7 +513,7 @@ e_datetime_format_add_setup_widget (GtkWidget *table, gint row, const gchar *com store = gtk_list_store_new (1, G_TYPE_STRING); combo = g_object_new ( - GTK_TYPE_COMBO_BOX, + GTK_TYPE_COMBO_BOX_TEXT, "model", store, "has-entry", TRUE, "entry-text-column", 0, diff --git a/e-util/e-util.c b/e-util/e-util.c index 22f792c3a7..f27b3f3660 100644 --- a/e-util/e-util.c +++ b/e-util/e-util.c @@ -57,6 +57,14 @@ #include "e-util.h" #include "e-util-private.h" +#include "gtk-compat.h" + +#if !GTK_CHECK_VERSION (2,23,0) + #undef GtkComboBoxText + ENSURE_GTK_COMBO_BOX_TEXT_TYPE +#else + ENSURE_GTK_COMBO_BOX_ENTRY_TYPE +#endif /** * e_get_gnome2_user_dir: diff --git a/e-util/gtk-compat.h b/e-util/gtk-compat.h index 3b9c7ef2e9..9dfa8a6bc0 100644 --- a/e-util/gtk-compat.h +++ b/e-util/gtk-compat.h @@ -12,10 +12,76 @@ #define gtk_combo_box_text_get_active_text gtk_combo_box_get_active_text #define GTK_COMBO_BOX_TEXT GTK_COMBO_BOX #define GtkComboBoxText GtkComboBox + +/* The below can be used only once in sources */ +#define ENSURE_GTK_COMBO_BOX_TEXT_TYPE \ + GType gtk_combo_box_text_get_type (void); \ + typedef struct _GtkComboBoxText GtkComboBoxText; \ + typedef struct _GtkComboBoxTextClass GtkComboBoxTextClass; \ + \ + struct _GtkComboBoxText { \ + GtkComboBox parent; \ + }; \ + \ + struct _GtkComboBoxTextClass { \ + GtkComboBoxClass parent_class; \ + }; \ + \ + \ + G_DEFINE_TYPE (GtkComboBoxText, gtk_combo_box_text, GTK_TYPE_COMBO_BOX) \ + \ + static void gtk_combo_box_text_init (GtkComboBoxText *cbt) {} \ + static void gtk_combo_box_text_class_init (GtkComboBoxTextClass *kl) {} + #endif #if GTK_CHECK_VERSION (2,23,0) #define GTK_COMBO_BOX_ENTRY GTK_COMBO_BOX + +#define ENSURE_GTK_COMBO_BOX_ENTRY_TYPE \ + GType gtk_combo_box_entry_get_type (void); \ + typedef struct _GtkComboBoxEntry GtkComboBoxEntry; \ + typedef struct _GtkComboBoxEntryClass GtkComboBoxEntryClass; \ + \ + struct _GtkComboBoxEntry { \ + GtkComboBoxText parent; \ + }; \ + \ + struct _GtkComboBoxEntryClass { \ + GtkComboBoxTextClass parent_class; \ + }; \ + \ + G_DEFINE_TYPE (GtkComboBoxEntry, gtk_combo_box_entry, GTK_TYPE_COMBO_BOX_TEXT)\ + \ + static GObject * \ + gtk_combo_box_entry_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) \ + { \ + GObjectConstructParam *params = g_new0 (GObjectConstructParam, n_construct_properties + 1);\ + GValue val = {0}; \ + GObject *res; \ + gint ii; \ + \ + for (ii = 0; ii < n_construct_properties; ii++) { \ + params[ii] = construct_properties[ii]; \ + } \ + \ + g_value_init (&val, G_TYPE_BOOLEAN); \ + g_value_set_boolean (&val, TRUE); \ + \ + params[n_construct_properties].pspec = g_object_class_find_property (G_OBJECT_CLASS (gtk_combo_box_entry_parent_class), "has-entry");\ + params[n_construct_properties].value = &val; \ + \ + res = G_OBJECT_CLASS (gtk_combo_box_entry_parent_class)->constructor (type, n_construct_properties + 1, params);\ + \ + g_free (params); \ + return res; \ + } \ + static void gtk_combo_box_entry_init (GtkComboBoxEntry *cbt) {} \ + static void gtk_combo_box_entry_class_init (GtkComboBoxEntryClass *kl) \ + { \ + GObjectClass *object_class = G_OBJECT_CLASS (kl); \ + object_class->constructor = gtk_combo_box_entry_constructor; \ + } #else #define gtk_combo_box_set_entry_text_column \ gtk_combo_box_entry_set_text_column diff --git a/filter/filter.ui b/filter/filter.ui index b2e11f6fc1..a7e981c936 100644 --- a/filter/filter.ui +++ b/filter/filter.ui @@ -107,7 +107,7 @@ - + True model1 diff --git a/mail/mail-config.ui b/mail/mail-config.ui index 7252206a56..171205c94b 100644 --- a/mail/mail-config.ui +++ b/mail/mail-config.ui @@ -2704,7 +2704,7 @@ For example: "Work" or "Personal" - + True model1 @@ -3342,7 +3342,7 @@ For example: "Work" or "Personal" - + True @@ -3427,7 +3427,7 @@ For example: "Work" or "Personal" - + True model2 diff --git a/smime/gui/smime-ui.ui b/smime/gui/smime-ui.ui index 3d3dd28939..0f876ea36e 100644 --- a/smime/gui/smime-ui.ui +++ b/smime/gui/smime-ui.ui @@ -1332,7 +1332,7 @@ - + True model1 diff --git a/widgets/misc/e-dateedit.c b/widgets/misc/e-dateedit.c index da3c9dbad5..5045a1d53f 100644 --- a/widgets/misc/e-dateedit.c +++ b/widgets/misc/e-dateedit.c @@ -573,11 +573,22 @@ create_children (EDateEdit *dedit) time_store = gtk_list_store_new (1, G_TYPE_STRING); #if GTK_CHECK_VERSION(2,23,0) priv->time_combo = g_object_new ( - GTK_TYPE_COMBO_BOX, + GTK_TYPE_COMBO_BOX_TEXT, "model", time_store, "has-entry", TRUE, "entry-text-column", 0, NULL); + + { + GtkCellRenderer *cell; + + gtk_cell_layout_clear (GTK_CELL_LAYOUT (priv->time_combo)); + + cell = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->time_combo), cell, TRUE); + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (priv->time_combo), cell, "text", 0, NULL); + } + #else priv->time_combo = gtk_combo_box_entry_new_with_model ( GTK_TREE_MODEL (time_store), 0); @@ -1581,16 +1592,16 @@ static void rebuild_time_popup (EDateEdit *dedit) { EDateEditPrivate *priv; - GtkComboBoxText *combo; + GtkListStore *list_store; + GtkTreeIter iter; gchar buffer[40]; struct tm tmp_tm; gint hour, min; priv = dedit->priv; - combo = GTK_COMBO_BOX_TEXT (priv->time_combo); - - gtk_list_store_clear (GTK_LIST_STORE (gtk_combo_box_get_model (combo))); + list_store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (priv->time_combo))); + gtk_list_store_clear (list_store); /* Fill the struct tm with some sane values. */ tmp_tm.tm_year = 2000; @@ -1633,7 +1644,8 @@ rebuild_time_popup (EDateEdit *dedit) if (!priv->use_24_hour_format && buffer[0] == '0') buffer[0] = ' '; - gtk_combo_box_text_append_text (combo, buffer); + gtk_list_store_append (list_store, &iter); + gtk_list_store_set (list_store, &iter, 0, buffer, -1); } } } -- cgit