]> git.sur5r.net Git - glabels/commitdiff
2005-04-08 Jim Evins <evins@snaught.com>
authorJim Evins <evins@snaught.com>
Sat, 9 Apr 2005 02:29:00 +0000 (02:29 +0000)
committerJim Evins <evins@snaught.com>
Sat, 9 Apr 2005 02:29:00 +0000 (02:29 +0000)
* 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

glabels2/ChangeLog
glabels2/src/ui-property-bar.c
glabels2/src/ui-property-bar.h
glabels2/src/util.c
glabels2/src/util.h

index 2da805c4d1a82a110f976616d0181e59d99e8e59..71a4a2c3d9e5f10fffde0711edda42e80e772d6a 100644 (file)
@@ -1,3 +1,17 @@
+2005-04-08  Jim Evins <evins@snaught.com>
+
+       * 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 <evins@snaught.com>
 
        * src/Makefile.am:
index bd7fc83784885e1a5109ebf429f3bcb4472e252c..640ea540bd38ee203533b19267ed961c03c7f337 100644 (file)
@@ -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);
index b1d3680c3de53f8017334896de4561721a56484d..73aa1e669f7f4b1cf84f9cef61c494b3c6cf0343 100644 (file)
@@ -51,7 +51,7 @@ struct _glUIPropertyBar {
 
        glView              *view;
 
-       GtkWidget           *font_family_entry;
+       GtkWidget           *font_family_combo;
        GtkWidget           *font_size_spin;
        GtkWidget           *text_color_combo;
 
index ea92bf56b90bb121112cff52447c3056147c66d9..53f3deeea333695eba213031c2bd380d9465ec80 100644 (file)
@@ -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);
+               }    
+
+       }
+
+}
+
index 8e6942ed35ed959cd8608713346f710704aacc69..89af5b031397411529e73bb8cd7873d9824e044d 100644 (file)
@@ -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__ */