From: Jim Evins Date: Sat, 9 Apr 2005 02:29:00 +0000 (+0000) Subject: 2005-04-08 Jim Evins X-Git-Tag: glabels-2_3_0~432 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=21cb58ded51cba453457ac6c47517b32f5915f59;p=glabels 2005-04-08 Jim Evins * src/util.h: * src/util.c: (gl_util_combo_box_set_strings), (search_text_func), (gl_util_combo_box_set_active_text): Added utility functions to simplify working with GtkComboBox widgets in GTK-2.6. * src/ui-property-bar.h: * src/ui-property-bar.c: (gl_ui_property_bar_construct), (reset_to_default_properties), (update_text_properties), (font_family_changed_cb): Replaced deprecated GtkCombo with GtkComboBox. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@515 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 2da805c4..71a4a2c3 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,17 @@ +2005-04-08 Jim Evins + + * src/util.h: + * src/util.c: (gl_util_combo_box_set_strings), (search_text_func), + (gl_util_combo_box_set_active_text): + Added utility functions to simplify working with GtkComboBox + widgets in GTK-2.6. + * src/ui-property-bar.h: + * src/ui-property-bar.c: (gl_ui_property_bar_construct), + (reset_to_default_properties), (update_text_properties), + (font_family_changed_cb): + Replaced deprecated GtkCombo with GtkComboBox. + + 2005-04-03 Jim Evins * src/Makefile.am: diff --git a/glabels2/src/ui-property-bar.c b/glabels2/src/ui-property-bar.c index bd7fc837..640ea540 100644 --- a/glabels2/src/ui-property-bar.c +++ b/glabels2/src/ui-property-bar.c @@ -105,7 +105,7 @@ static void gl_ui_property_bar_construct (glUIPropertyBar *property static void selection_changed_cb (glUIPropertyBar *property_bar); -static void font_family_changed_cb (GtkEntry *entry, +static void font_family_changed_cb (GtkComboBox *combo, glUIPropertyBar *property_bar); static void font_size_changed_cb (GtkSpinButton *spin, @@ -251,10 +251,10 @@ gl_ui_property_bar_construct (glUIPropertyBar *property_bar, { GtkWidget *wcombo; GList *family_names = NULL; + GList *family_node; GtkObject *adjust; ColorGroup *cg; GdkPixbuf *pixbuf; - gchar *good_font_family; GdkColor *gdk_color; gl_debug (DEBUG_PROPERTY_BAR, "START"); @@ -263,31 +263,26 @@ gl_ui_property_bar_construct (glUIPropertyBar *property_bar, property_bar->ui_component = ui_component; /* Font family entry widget */ - wcombo = gtk_combo_new (); + wcombo = gtk_combo_box_new_text (); family_names = gnome_font_family_list (); - gtk_combo_set_popdown_strings (GTK_COMBO (wcombo), family_names); - property_bar->font_family_entry = GTK_COMBO (wcombo)->entry; - gtk_combo_set_value_in_list (GTK_COMBO(wcombo), TRUE, TRUE); - gtk_entry_set_editable (GTK_ENTRY (property_bar->font_family_entry), FALSE); + gl_util_combo_box_set_strings (GTK_COMBO_BOX (wcombo), family_names); + property_bar->font_family_combo = wcombo; gtk_widget_set_size_request (wcombo, 200, -1); - /* Make sure we have a valid font family. if not provide a good default. */ - if (g_list_find_custom (family_names, - gl_prefs->default_font_family, - (GCompareFunc)g_utf8_collate)) { - good_font_family = g_strdup (gl_prefs->default_font_family); + /* Make sure we have a valid font. if not provide a good default. */ + family_node = g_list_find_custom (family_names, + gl_prefs->default_font_family, + (GCompareFunc)g_utf8_collate); + if (family_node) { + gtk_combo_box_set_active (wcombo, + g_list_position (family_names, + family_node)); } else { - if (family_names != NULL) { - good_font_family = g_strdup (family_names->data); /* 1st entry */ - } else { - good_font_family = NULL; - } + gtk_combo_box_set_active (wcombo, 0); } - gtk_entry_set_text (GTK_ENTRY (property_bar->font_family_entry), good_font_family); - g_free (good_font_family); gnome_font_family_list_free (family_names); - g_signal_connect (G_OBJECT (property_bar->font_family_entry), + g_signal_connect (G_OBJECT (property_bar->font_family_combo), "changed", G_CALLBACK (font_family_changed_cb), property_bar); gl_ui_util_insert_widget (ui_component, wcombo, "/PropertyToolbar/PropFontName"); @@ -407,13 +402,13 @@ gl_ui_property_bar_construct (glUIPropertyBar *property_bar, /****************************************************************************/ static void reset_to_default_properties (glView *view, - glUIPropertyBar *property_bar) + glUIPropertyBar *property_bar) { GList *family_names; gchar *good_font_family; GdkColor *gdk_color; - /* Make sure we have a valid font family. if not provide a good default. */ + /* Make sure we have a valid font. if not provide a good default. */ family_names = gnome_font_family_list (); if (g_list_find_custom (family_names, view->default_font_family, @@ -426,7 +421,8 @@ reset_to_default_properties (glView *view, good_font_family = NULL; } } - gtk_entry_set_text (GTK_ENTRY (property_bar->font_family_entry), good_font_family); + gl_util_combo_box_set_active_text (GTK_COMBO_BOX (property_bar->font_family_combo), + good_font_family); g_free (good_font_family); gtk_spin_button_set_value (GTK_SPIN_BUTTON(property_bar->font_size_spin), @@ -591,8 +587,8 @@ update_text_properties (glView *view, if (is_same_font_family && (selection_font_family != NULL)) gl_debug (DEBUG_PROPERTY_BAR, "same font family = %s", selection_font_family); - gtk_entry_set_text (GTK_ENTRY (property_bar->font_family_entry), - is_same_font_family?selection_font_family:""); + gl_util_combo_box_set_active_text (GTK_COMBO_BOX (property_bar->font_family_combo), + is_same_font_family?selection_font_family:""); g_free (selection_font_family); if (is_same_font_size) { @@ -837,7 +833,7 @@ selection_changed_cb (glUIPropertyBar *property_bar) /* PRIVATE. Font family entry changed. */ /*--------------------------------------------------------------------------*/ static void -font_family_changed_cb (GtkEntry *entry, +font_family_changed_cb (GtkComboBox *combo, glUIPropertyBar *property_bar) { gchar *font_family; @@ -851,7 +847,7 @@ font_family_changed_cb (GtkEntry *entry, selection_changed_cb, property_bar); - font_family = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1); + font_family = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo)); if ( strlen(font_family) ) { gl_view_set_selection_font_family (property_bar->view, font_family); diff --git a/glabels2/src/ui-property-bar.h b/glabels2/src/ui-property-bar.h index b1d3680c..73aa1e66 100644 --- a/glabels2/src/ui-property-bar.h +++ b/glabels2/src/ui-property-bar.h @@ -51,7 +51,7 @@ struct _glUIPropertyBar { glView *view; - GtkWidget *font_family_entry; + GtkWidget *font_family_combo; GtkWidget *font_size_spin; GtkWidget *text_color_combo; diff --git a/glabels2/src/util.c b/glabels2/src/util.c index ea92bf56..53f3deee 100644 --- a/glabels2/src/util.c +++ b/glabels2/src/util.c @@ -193,3 +193,75 @@ gl_util_string_to_weight (const gchar *string) } +void +gl_util_combo_box_set_strings (GtkComboBox *combo, + GList *list) +{ + GList *p; + + g_return_if_fail (list); + + for (p=list; p!=NULL; p=p->next) { + if (p->data) { + gtk_combo_box_append_text (combo, p->data); + } + } +} + +typedef struct { + const gchar *text; + GtkTreeIter iter; + gboolean found; +} TextSearchData; + +static gboolean +search_text_func (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + gpointer data) +{ + TextSearchData *search_data = (TextSearchData *)data; + gchar *text = NULL; + + gtk_tree_model_get (model, iter, 0, &text, -1); + + if (strcmp (text,search_data->text) == 0) { + search_data->found = TRUE; + search_data->iter = *iter; + } + + g_free (text); + + return FALSE; +} + +void +gl_util_combo_box_set_active_text (GtkComboBox *combo, + const gchar *text) +{ + GtkTreeModel *model = gtk_combo_box_get_model(combo); + + g_return_if_fail (GTK_IS_LIST_STORE (model)); + + if (!text) { + + gtk_combo_box_set_active (combo, -1); + + } else { + TextSearchData search_data; + + search_data.text = text; + search_data.found = FALSE; + + gtk_tree_model_foreach (model, search_text_func, &search_data); + if (search_data.found) { + gtk_combo_box_set_active_iter (combo, + &search_data.iter); + } else { + gtk_combo_box_set_active (combo, -1); + } + + } + +} + diff --git a/glabels2/src/util.h b/glabels2/src/util.h index 8e6942ed..89af5b03 100644 --- a/glabels2/src/util.h +++ b/glabels2/src/util.h @@ -41,6 +41,11 @@ GtkJustification gl_util_string_to_just (const gchar *string); const gchar *gl_util_weight_to_string (GnomeFontWeight weight); GnomeFontWeight gl_util_string_to_weight (const gchar *string); +void gl_util_combo_box_set_strings (GtkComboBox *combo, + GList *list); +void gl_util_combo_box_set_active_text (GtkComboBox *combo, + const gchar *text); + G_END_DECLS #endif /* __UTIL_H__ */