From: Jim Evins Date: Wed, 9 Sep 2009 02:16:13 +0000 (+0000) Subject: 2009-09-08 Jim Evins X-Git-Tag: glabels-2_3_0~197 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=245cb815f5a040b97443fff0229afd0d74711a5c;p=glabels 2009-09-08 Jim Evins * src/font-util.c: (gl_font_util_validate_family): * src/font-util.h: Added gl_font_util_validate_family(). * src/font-combo.c: (gl_font_combo_class_init), (gl_font_combo_new), (gl_font_combo_set_family): Use gl_font_util_validate_family() when setting family. * src/label-text.c: (set_font_family): * src/prefs-dialog.c: (construct_object_page), (update_object_page_from_prefs): * src/ui-property-bar.c: (gl_ui_property_bar_construct), (reset_to_default_properties): * src/object-editor-text-page.c: (gl_object_editor_prepare_text_page), (gl_object_editor_set_font_family): Removed code obsoleted by the addition of gl_font_util_validate_family(). * src/color-swatch.c: (gl_color_swatch_class_init), (style_set_cb), (draw_swatch): * src/font-sample.c: (gl_font_sample_class_init), (style_set_cb), (draw_sample): Added handler for style_set event. * src/color-combo-button.c: (gl_color_combo_button_class_init): * src/color-combo-color-menu-item.c: (gl_color_combo_color_menu_item_class_init): * src/color-combo-history.c: (gl_color_combo_history_class_init): * src/color-combo-menu.c: (map_event_cb): * src/color-combo.c: (gl_color_combo_class_init), (gl_color_combo_new): * src/font-combo-menu-item.c: (gl_font_combo_menu_item_class_init): * src/font-combo-menu.c: (gl_font_combo_menu_class_init): * src/wdgt-rotate-label.c: (create_pixbuf): Various cleanups -- mostly removing unused variables. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@877 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index dcaaac4d..60c7bf89 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,37 @@ +2009-09-08 Jim Evins + + * src/font-util.c: (gl_font_util_validate_family): + * src/font-util.h: + Added gl_font_util_validate_family(). + * src/font-combo.c: (gl_font_combo_class_init), + (gl_font_combo_new), (gl_font_combo_set_family): + Use gl_font_util_validate_family() when setting family. + * src/label-text.c: (set_font_family): + * src/prefs-dialog.c: (construct_object_page), + (update_object_page_from_prefs): + * src/ui-property-bar.c: (gl_ui_property_bar_construct), + (reset_to_default_properties): + * src/object-editor-text-page.c: + (gl_object_editor_prepare_text_page), + (gl_object_editor_set_font_family): + Removed code obsoleted by the addition of gl_font_util_validate_family(). + * src/color-swatch.c: (gl_color_swatch_class_init), (style_set_cb), + (draw_swatch): + * src/font-sample.c: (gl_font_sample_class_init), (style_set_cb), + (draw_sample): + Added handler for style_set event. + * src/color-combo-button.c: (gl_color_combo_button_class_init): + * src/color-combo-color-menu-item.c: + (gl_color_combo_color_menu_item_class_init): + * src/color-combo-history.c: (gl_color_combo_history_class_init): + * src/color-combo-menu.c: (map_event_cb): + * src/color-combo.c: (gl_color_combo_class_init), + (gl_color_combo_new): + * src/font-combo-menu-item.c: (gl_font_combo_menu_item_class_init): + * src/font-combo-menu.c: (gl_font_combo_menu_class_init): + * src/wdgt-rotate-label.c: (create_pixbuf): + Various cleanups -- mostly removing unused variables. + 2009-09-07 Jim Evins Created new glFontCombo widget family subsystem + minor refinements to glColorCombo diff --git a/glabels2/src/color-combo-button.c b/glabels2/src/color-combo-button.c index c444ee88..f32bbf2d 100644 --- a/glabels2/src/color-combo-button.c +++ b/glabels2/src/color-combo-button.c @@ -110,8 +110,6 @@ static void gl_color_combo_button_class_init (glColorComboButtonClass *class) { GObjectClass *gobject_class = (GObjectClass *) class; - GtkWidgetClass *widget_class = (GtkWidgetClass *) class; - glColorComboButtonClass *object_class = (glColorComboButtonClass *) class; gl_color_combo_button_parent_class = g_type_class_peek_parent (class); diff --git a/glabels2/src/color-combo-color-menu-item.c b/glabels2/src/color-combo-color-menu-item.c index 9fc6c79d..2ffc1cbc 100644 --- a/glabels2/src/color-combo-color-menu-item.c +++ b/glabels2/src/color-combo-color-menu-item.c @@ -62,11 +62,6 @@ struct _glColorComboColorMenuItemPrivate { static void gl_color_combo_color_menu_item_finalize (GObject *object); -static GdkPixbuf * -create_color_pixbuf (gdouble w, - gdouble h, - guint color); - /****************************************************************************/ /* Boilerplate Object stuff. */ @@ -81,7 +76,6 @@ static void gl_color_combo_color_menu_item_class_init (glColorComboColorMenuItemClass *class) { GObjectClass *gobject_class = G_OBJECT_CLASS (class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); gl_color_combo_color_menu_item_parent_class = g_type_class_peek_parent (class); diff --git a/glabels2/src/color-combo-history.c b/glabels2/src/color-combo-history.c index fa62c0d8..decc99e4 100644 --- a/glabels2/src/color-combo-history.c +++ b/glabels2/src/color-combo-history.c @@ -65,7 +65,6 @@ static void gl_color_combo_history_class_init (glColorComboHistoryClass *class) { GObjectClass *gobject_class = (GObjectClass *) class; - glColorComboHistoryClass *object_class = (glColorComboHistoryClass *) class; gl_color_combo_history_parent_class = g_type_class_peek_parent (class); diff --git a/glabels2/src/color-combo-menu.c b/glabels2/src/color-combo-menu.c index c3425273..c96573e0 100644 --- a/glabels2/src/color-combo-menu.c +++ b/glabels2/src/color-combo-menu.c @@ -337,6 +337,8 @@ map_event_cb (GtkWidget *widget, glColorComboMenu *this = GL_COLOR_COMBO_MENU (widget); load_custom_color_history (this); + + return FALSE; } diff --git a/glabels2/src/color-combo.c b/glabels2/src/color-combo.c index 172f2e20..02008b2e 100644 --- a/glabels2/src/color-combo.c +++ b/glabels2/src/color-combo.c @@ -100,8 +100,6 @@ static void gl_color_combo_class_init (glColorComboClass *class) { GObjectClass *gobject_class = (GObjectClass *) class; - GtkWidgetClass *widget_class = (GtkWidgetClass *) class; - glColorComboClass *object_class = (glColorComboClass *) class; gl_color_combo_parent_class = g_type_class_peek_parent (class); @@ -172,8 +170,6 @@ gl_color_combo_new (const gchar *default_label, guint color) { glColorCombo *this; - GdkPixbuf *pixbuf; - GtkWidget *wimage; this = g_object_new (TYPE_GL_COLOR_COMBO, NULL); diff --git a/glabels2/src/color-swatch.c b/glabels2/src/color-swatch.c index ae72e3dc..8a413462 100644 --- a/glabels2/src/color-swatch.c +++ b/glabels2/src/color-swatch.c @@ -53,6 +53,9 @@ struct _glColorSwatchPrivate { static void gl_color_swatch_finalize (GObject *object); +static void style_set_cb (GtkWidget *widget, + GtkStyle *previous_style); + static void redraw (glColorSwatch *this); static gboolean expose_event_cb (GtkWidget *widget, @@ -83,6 +86,7 @@ gl_color_swatch_class_init (glColorSwatchClass *class) gobject_class->finalize = gl_color_swatch_finalize; widget_class->expose_event = expose_event_cb; + widget_class->style_set = style_set_cb; } @@ -148,6 +152,17 @@ gl_color_swatch_set_color (glColorSwatch *this, } +/*--------------------------------------------------------------------------*/ +/* Style set handler (updates colors when style/theme changes). */ +/*--------------------------------------------------------------------------*/ +static void +style_set_cb (GtkWidget *widget, + GtkStyle *previous_style) +{ + redraw (GL_COLOR_SWATCH (widget)); +} + + /*****************************************************************************/ /* Request redraw. */ /*****************************************************************************/ @@ -199,7 +214,6 @@ static void draw_swatch (glColorSwatch *this, cairo_t *cr) { - GdkPixbuf *pixbuf; GtkStyle *style; gdouble w, h; guint fill_color, line_color; diff --git a/glabels2/src/font-combo-menu-item.c b/glabels2/src/font-combo-menu-item.c index bbaafb28..5c16ffae 100644 --- a/glabels2/src/font-combo-menu-item.c +++ b/glabels2/src/font-combo-menu-item.c @@ -22,6 +22,7 @@ #include "font-combo-menu-item.h" +#include "font-sample.h" #include "marshal.h" #include #include @@ -75,7 +76,6 @@ static void gl_font_combo_menu_item_class_init (glFontComboMenuItemClass *class) { GObjectClass *gobject_class = G_OBJECT_CLASS (class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); gl_font_combo_menu_item_parent_class = g_type_class_peek_parent (class); diff --git a/glabels2/src/font-combo-menu.c b/glabels2/src/font-combo-menu.c index cf263702..87c1ece7 100644 --- a/glabels2/src/font-combo-menu.c +++ b/glabels2/src/font-combo-menu.c @@ -83,7 +83,6 @@ static void gl_font_combo_menu_class_init (glFontComboMenuClass *class) { GObjectClass *gobject_class = G_OBJECT_CLASS (class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); gl_font_combo_menu_parent_class = g_type_class_peek_parent (class); diff --git a/glabels2/src/font-combo.c b/glabels2/src/font-combo.c index 44dfc396..f77d5ad2 100644 --- a/glabels2/src/font-combo.c +++ b/glabels2/src/font-combo.c @@ -23,6 +23,7 @@ #include "font-combo.h" #include "font-combo-menu.h" +#include "font-util.h" #include #include #include @@ -91,8 +92,6 @@ static void gl_font_combo_class_init (glFontComboClass *class) { GObjectClass *gobject_class = (GObjectClass *) class; - GtkWidgetClass *widget_class = (GtkWidgetClass *) class; - glFontComboClass *object_class = (glFontComboClass *) class; gl_font_combo_parent_class = g_type_class_peek_parent (class); @@ -165,9 +164,9 @@ gl_font_combo_new (const gchar *font_family) this = g_object_new (TYPE_GL_FONT_COMBO, NULL); - this->priv->font_family = g_strdup (font_family); + this->priv->font_family = gl_font_util_validate_family (font_family); - gtk_label_set_text (GTK_LABEL (this->priv->label), font_family); + gtk_label_set_text (GTK_LABEL (this->priv->label), this->priv->font_family); this->priv->menu = gl_font_combo_menu_new (); @@ -201,9 +200,9 @@ gl_font_combo_set_family (glFontCombo *this, const gchar *font_family) { - this->priv->font_family = g_strdup (font_family); + this->priv->font_family = gl_font_util_validate_family (font_family); - gtk_label_set_text (GTK_LABEL (this->priv->label), font_family); + gtk_label_set_text (GTK_LABEL (this->priv->label), this->priv->font_family); } diff --git a/glabels2/src/font-sample.c b/glabels2/src/font-sample.c index 299b9ba8..da2c13aa 100644 --- a/glabels2/src/font-sample.c +++ b/glabels2/src/font-sample.c @@ -56,6 +56,9 @@ struct _glFontSamplePrivate { static void gl_font_sample_finalize (GObject *object); +static void style_set_cb (GtkWidget *widget, + GtkStyle *previous_style); + static void redraw (glFontSample *this); static gboolean expose_event_cb (GtkWidget *widget, @@ -86,6 +89,7 @@ gl_font_sample_class_init (glFontSampleClass *class) gobject_class->finalize = gl_font_sample_finalize; widget_class->expose_event = expose_event_cb; + widget_class->style_set = style_set_cb; } @@ -142,6 +146,17 @@ gl_font_sample_new (gint w, } +/*--------------------------------------------------------------------------*/ +/* Style set handler (updates colors when style/theme changes). */ +/*--------------------------------------------------------------------------*/ +static void +style_set_cb (GtkWidget *widget, + GtkStyle *previous_style) +{ + redraw (GL_FONT_SAMPLE (widget)); +} + + /*****************************************************************************/ /* Request redraw. */ /*****************************************************************************/ @@ -193,7 +208,6 @@ static void draw_sample (glFontSample *this, cairo_t *cr) { - GdkPixbuf *pixbuf; GtkStyle *style; gdouble w, h; guint fill_color, line_color; @@ -211,7 +225,7 @@ draw_sample (glFontSample *this, style = gtk_widget_get_style (GTK_WIDGET (this)); if ( GTK_WIDGET_IS_SENSITIVE (GTK_WIDGET (this)) ) { - fill_color = GL_COLOR_WHITE; + fill_color = gl_color_from_gdk_color (&style->light[GTK_STATE_NORMAL]); line_color = gl_color_from_gdk_color (&style->fg[GTK_STATE_NORMAL]); } else diff --git a/glabels2/src/font-util.c b/glabels2/src/font-util.c index 15555f5a..1bb54b77 100644 --- a/glabels2/src/font-util.c +++ b/glabels2/src/font-util.c @@ -148,6 +148,42 @@ gl_font_util_get_fixed_width_families (void) } +/****************************************************************************/ +/* Make sure we have a valid font. If not provide a good default. */ +/****************************************************************************/ +gchar * +gl_font_util_validate_family (const gchar *family) +{ + const GList *installed_families; + gchar *good_family; + + installed_families = gl_font_util_get_all_families (); + + if (g_list_find_custom ((GList *)installed_families, + family, + (GCompareFunc)g_utf8_collate)) + { + good_family = g_strdup (family); + } + else if (g_list_find_custom ((GList *)installed_families, + "Sans", + (GCompareFunc)g_utf8_collate)) + { + good_family = g_strdup ("Sans"); + } + else if (installed_families != NULL) + { + good_family = g_strdup (installed_families->data); /* 1st entry */ + } + else + { + good_family = NULL; + } + + return good_family; +} + + /* * Local Variables: -- emacs diff --git a/glabels2/src/font-util.h b/glabels2/src/font-util.h index 38541f77..7060d117 100644 --- a/glabels2/src/font-util.h +++ b/glabels2/src/font-util.h @@ -29,6 +29,8 @@ const GList *gl_font_util_get_all_families (void); const GList *gl_font_util_get_proportional_families (void); const GList *gl_font_util_get_fixed_width_families (void); +gchar *gl_font_util_validate_family (const gchar *family); + G_END_DECLS #endif /* __FONT_UTIL_H__ */ diff --git a/glabels2/src/label-text.c b/glabels2/src/label-text.c index 118af190..1e38f7ea 100644 --- a/glabels2/src/label-text.c +++ b/glabels2/src/label-text.c @@ -459,7 +459,6 @@ set_font_family (glLabelObject *object, const gchar *font_family) { glLabelText *ltext = (glLabelText *)object; - GList *family_names; gchar *good_font_family; gl_debug (DEBUG_LABEL, "START"); @@ -467,16 +466,7 @@ set_font_family (glLabelObject *object, g_return_if_fail (ltext && GL_IS_LABEL_TEXT (ltext)); g_return_if_fail (font_family); - family_names = gl_font_util_get_all_families (); - if (g_list_find_custom (family_names, font_family, (GCompareFunc)g_utf8_collate)) { - good_font_family = g_strdup (font_family); - } else { - if (family_names != NULL) { - good_font_family = g_strdup (family_names->data); /* 1st entry */ - } else { - good_font_family = g_strdup (font_family); - } - } + good_font_family = gl_font_util_validate_family (font_family); if (ltext->priv->font_family) { if (strcmp (ltext->priv->font_family, good_font_family) == 0) { diff --git a/glabels2/src/object-editor-text-page.c b/glabels2/src/object-editor-text-page.c index ee4280ef..61606681 100644 --- a/glabels2/src/object-editor-text-page.c +++ b/glabels2/src/object-editor-text-page.c @@ -70,8 +70,6 @@ static void text_radio_toggled_cb (glObjectEditor *editor); void gl_object_editor_prepare_text_page (glObjectEditor *editor) { - GList *family_names = NULL; - gl_debug (DEBUG_EDITOR, "START"); /* Extract widgets from XML tree. */ @@ -225,9 +223,7 @@ void gl_object_editor_set_font_family (glObjectEditor *editor, const gchar *font_family) { - GList *family_names; gchar *old_font_family; - gchar *good_font_family; gl_debug (DEBUG_EDITOR, "START"); @@ -237,20 +233,8 @@ gl_object_editor_set_font_family (glObjectEditor *editor, if ( !old_font_family || g_utf8_collate( old_font_family, font_family ) ) { - - /* Make sure we have a valid font family. if not provide a good default. */ - family_names = gl_font_util_get_all_families (); - if (g_list_find_custom (family_names, font_family, (GCompareFunc)g_utf8_collate)) { - good_font_family = g_strdup (font_family); - } else { - if (family_names != NULL) { - good_font_family = g_strdup (family_names->data); /* 1st entry */ - } else { - good_font_family = NULL; - } - } - gl_font_combo_set_family (GL_FONT_COMBO (editor->priv->text_family_combo), good_font_family); - g_free (good_font_family); + gl_font_combo_set_family (GL_FONT_COMBO (editor->priv->text_family_combo), + font_family); } g_free (old_font_family); diff --git a/glabels2/src/prefs-dialog.c b/glabels2/src/prefs-dialog.c index b263e522..3c76bc1d 100644 --- a/glabels2/src/prefs-dialog.c +++ b/glabels2/src/prefs-dialog.c @@ -322,8 +322,6 @@ construct_locale_page (glPrefsDialog *dialog) static void construct_object_page (glPrefsDialog *dialog) { - GList *family_names; - gl_util_get_builder_widgets (dialog->priv->builder, "text_family_hbox", &dialog->priv->text_family_hbox, "text_size_spin", &dialog->priv->text_size_spin, @@ -517,34 +515,11 @@ update_locale_page_from_prefs (glPrefsDialog *dialog) static void update_object_page_from_prefs (glPrefsDialog *dialog) { - const GList *family_names; - gchar *good_font_family; dialog->priv->stop_signals = TRUE; - - /* Make sure we have a valid font family. if not provide a good default. */ - family_names = gl_font_util_get_all_families (); - if (g_list_find_custom ((GList *)family_names, - gl_prefs->default_font_family, - (GCompareFunc)g_utf8_collate)) - { - good_font_family = g_strdup (gl_prefs->default_font_family); - } - else - { - if (family_names != NULL) - { - good_font_family = g_strdup (family_names->data); /* 1st entry */ - } - else - { - good_font_family = NULL; - } - } gl_font_combo_set_family (GL_FONT_COMBO (dialog->priv->text_family_combo), - good_font_family); - g_free (good_font_family); + gl_prefs->default_font_family); gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->text_size_spin), gl_prefs->default_font_size); diff --git a/glabels2/src/ui-property-bar.c b/glabels2/src/ui-property-bar.c index 6ed7ed28..d2bb94c4 100644 --- a/glabels2/src/ui-property-bar.c +++ b/glabels2/src/ui-property-bar.c @@ -237,8 +237,6 @@ gl_ui_property_bar_construct (glUIPropertyBar *this) "adjustment1", "adjustment2", NULL }; GError *error = NULL; - GList *family_names = NULL; - GList *family_node; GdkPixbuf *pixbuf = NULL; gl_debug (DEBUG_PROPERTY_BAR, "START"); @@ -391,34 +389,12 @@ gl_ui_property_bar_construct (glUIPropertyBar *this) /* Fill widgets with default values. */ /****************************************************************************/ static void -reset_to_default_properties (glView *view, +reset_to_default_properties (glView *view, glUIPropertyBar *this) { - GList *family_names; - gchar *good_font_family; - - /* Make sure we have a valid font. if not provide a good default. */ - family_names = gl_font_util_get_all_families (); - if (g_list_find_custom (family_names, - view->default_font_family, - (GCompareFunc)g_utf8_collate)) - { - good_font_family = g_strdup (view->default_font_family); - } - else - { - if (family_names != NULL) - { - good_font_family = g_strdup (family_names->data); /* 1st entry */ - } - else - { - good_font_family = NULL; - } - } + gl_font_combo_set_family (GL_FONT_COMBO (this->priv->font_family_combo), - good_font_family); - g_free (good_font_family); + view->default_font_family); gtk_spin_button_set_value (GTK_SPIN_BUTTON(this->priv->font_size_spin), view->default_font_size); diff --git a/glabels2/src/wdgt-rotate-label.c b/glabels2/src/wdgt-rotate-label.c index 993eab20..4a924280 100644 --- a/glabels2/src/wdgt-rotate-label.c +++ b/glabels2/src/wdgt-rotate-label.c @@ -215,7 +215,6 @@ create_pixbuf (lglTemplate *template, cairo_surface_t *surface; const lglTemplateFrame *frame; gdouble m, m_canvas, w, h, scale; - GtkStyle *style; cairo_t *cr; /* Create pixbuf and cairo context. */