diff options
author | Rachel Hestilow <hestilow@ximian.com> | 2002-04-11 01:41:17 +0000 |
---|---|---|
committer | Rachel Hestilow <hestgray@src.gnome.org> | 2002-04-11 01:41:17 +0000 |
commit | ef4591f5fb88e20c08f45ada2c3a1bd9e16bdd91 (patch) | |
tree | e4cf1089f2d289b0d68875e6ae9618dbf4e047af | |
parent | 68b79b4fab16f1b5121ea18192836c3b7a23d2e5 (diff) | |
download | gnome-control-center-ef4591f5fb88e20c08f45ada2c3a1bd9e16bdd91.tar.gz |
Add FontType enum, and a font_type parameter to gconf_peditor_new_font.
2002-04-10 Rachel Hestilow <hestilow@ximian.com>
* gconf-proprerty-editor.h: Add FontType enum, and a font_type
parameter to gconf_peditor_new_font.
* gconf-property-editor.c:
(peditor_font_value_changed): Call peditor_font_merge_setting
instead of setting the properties explicitly.
(peditor_font_widget_changed): Switch on font_type to determine
what to set for a GConfValue.
-rw-r--r-- | capplets/common/ChangeLog | 11 | ||||
-rw-r--r-- | capplets/common/gconf-property-editor.c | 104 | ||||
-rw-r--r-- | capplets/common/gconf-property-editor.h | 9 |
3 files changed, 108 insertions, 16 deletions
diff --git a/capplets/common/ChangeLog b/capplets/common/ChangeLog index 46c0bdafa..e88f50c5c 100644 --- a/capplets/common/ChangeLog +++ b/capplets/common/ChangeLog @@ -1,3 +1,14 @@ +2002-04-10 Rachel Hestilow <hestilow@ximian.com> + + * gconf-proprerty-editor.h: Add FontType enum, and a font_type + parameter to gconf_peditor_new_font. + + * gconf-property-editor.c: + (peditor_font_value_changed): Call peditor_font_merge_setting + instead of setting the properties explicitly. + (peditor_font_widget_changed): Switch on font_type to determine + what to set for a GConfValue. + 2002-03-28 Richard Hestilow <hestilow@ximian.com> * gconf-property-editor.c (peditor_image_clicked_cb): Set diff --git a/capplets/common/gconf-property-editor.c b/capplets/common/gconf-property-editor.c index 3c4d52515..e98dcf535 100644 --- a/capplets/common/gconf-property-editor.c +++ b/capplets/common/gconf-property-editor.c @@ -1102,20 +1102,71 @@ gconf_value_float_to_int (const GConfValue *value) } static gint -peditor_font_get_size (const gchar *font_name) +peditor_font_get_size (const gchar *font_str) { PangoFontDescription *desc; int size; - g_return_val_if_fail (font_name != NULL, -1); + g_return_val_if_fail (font_str != NULL, -1); - desc = pango_font_description_from_string (font_name); + desc = pango_font_description_from_string (font_str); size = pango_font_description_get_size (desc); pango_font_description_free (desc); return size / PANGO_SCALE; } +static gchar* +peditor_font_get_name (const gchar *font_str) +{ + PangoFontDescription *desc; + gchar *name; + + g_return_val_if_fail (font_str != NULL, NULL); + + desc = pango_font_description_from_string (font_str); + pango_font_description_unset_fields (desc, PANGO_FONT_MASK_SIZE); + name = pango_font_description_to_string (desc); + pango_font_description_free (desc); + + return name; +} + +static void +peditor_font_merge_setting (GnomeFontPicker *font_picker, GConfValue *value, GConfPEditorFontType font_type) +{ + PangoFontDescription *desc; + gchar *font_str; + + g_return_if_fail (GNOME_IS_FONT_PICKER (font_picker)); + g_return_if_fail (value != NULL); + + + desc = pango_font_description_from_string (gnome_font_picker_get_font_name (font_picker)); + + if (font_type == PEDITOR_FONT_SIZE) + { + pango_font_description_set_size (desc, gconf_value_get_int (value) * PANGO_SCALE); + } + else + { + PangoFontDescription *new_desc; + new_desc = pango_font_description_from_string (gconf_value_get_string (value)); + if (font_type == PEDITOR_FONT_NAME) + pango_font_description_set_size (new_desc, pango_font_description_get_size (desc)); + pango_font_description_free (desc); + desc = new_desc; + } + + font_str = pango_font_description_to_string (desc); + g_object_set (G_OBJECT (font_picker), + "font_name", font_str, + "label-font-size", pango_font_description_get_size (desc) / PANGO_SCALE, + NULL); + g_free (font_str); + pango_font_description_free (desc); +} + static void peditor_font_value_changed (GConfClient *client, guint cnxn_id, @@ -1123,40 +1174,58 @@ peditor_font_value_changed (GConfClient *client, GConfPropertyEditor *peditor) { GConfValue *value, *value_wid; + GConfPEditorFontType font_type; if (peditor->p->changeset != NULL) gconf_change_set_remove (peditor->p->changeset, peditor->p->key); + font_type = GPOINTER_TO_UINT (peditor->p->data); value = gconf_entry_get_value (entry); if (value != NULL) { - const gchar *font_name; - value_wid = peditor->p->conv_to_widget_cb (peditor, value); - font_name = gconf_value_get_string (value_wid); - g_object_set (G_OBJECT (peditor->p->ui_control), - "font_name", font_name, - "label-font-size", peditor_font_get_size (font_name), - NULL); + peditor_font_merge_setting (GNOME_FONT_PICKER (peditor->p->ui_control), value_wid, font_type); gconf_value_free (value_wid); } } static void peditor_font_widget_changed (GConfPropertyEditor *peditor, - gchar *font_name, + gchar *font_str, GnomeFontPicker *font_picker) { - GConfValue *value, *value_wid; + GConfValue *value, *value_wid = NULL; + GConfPEditorFontType font_type; + gchar *font_name; + int font_size; if (!peditor->p->inited) return; + font_type = GPOINTER_TO_UINT (peditor->p->data); + + font_size = peditor_font_get_size (font_str); g_object_set (G_OBJECT (peditor->p->ui_control), - "label-font-size", peditor_font_get_size (font_name), + "label-font-size", font_size, NULL); - value_wid = gconf_value_new (GCONF_VALUE_STRING); - gconf_value_set_string (value_wid, font_name); + switch (font_type) + { + case PEDITOR_FONT_NAME: + value_wid = gconf_value_new (GCONF_VALUE_STRING); + font_name = peditor_font_get_name (font_str); + gconf_value_set_string (value_wid, font_name); + g_free (font_name); + break; + case PEDITOR_FONT_SIZE: + value_wid = gconf_value_new (GCONF_VALUE_INT); + gconf_value_set_int (value_wid, font_size); + break; + case PEDITOR_FONT_COMBINED: + value_wid = gconf_value_new (GCONF_VALUE_STRING); + gconf_value_set_string (value_wid, font_str); + break; + } + value = peditor->p->conv_from_widget_cb (peditor, value_wid); peditor_set_gconf_value (peditor, peditor->p->key, value); @@ -1170,6 +1239,7 @@ GObject * gconf_peditor_new_font (GConfChangeSet *changeset, gchar *key, GtkWidget *font_picker, + GConfPEditorFontType font_type, gchar *first_property_name, ...) { @@ -1188,7 +1258,9 @@ gconf_peditor_new_font (GConfChangeSet *changeset, changeset, G_OBJECT (font_picker), first_property_name, - var_args, NULL); + var_args, + "data", GUINT_TO_POINTER (font_type), + NULL); va_end (var_args); diff --git a/capplets/common/gconf-property-editor.h b/capplets/common/gconf-property-editor.h index da11c7a61..993de71f0 100644 --- a/capplets/common/gconf-property-editor.h +++ b/capplets/common/gconf-property-editor.h @@ -41,6 +41,13 @@ typedef struct _GConfPropertyEditorPrivate GConfPropertyEditorPrivate; typedef GConfValue *(*GConfPEditorValueConvFn) (GConfPropertyEditor *peditor, const GConfValue *); typedef int (*GConfPEditorGetValueFn) (GConfPropertyEditor *peditor, gpointer data); +typedef enum +{ + PEDITOR_FONT_NAME, + PEDITOR_FONT_SIZE, + PEDITOR_FONT_COMBINED +} GConfPEditorFontType; + struct _GConfPropertyEditor { GObject parent; @@ -123,9 +130,11 @@ GObject *gconf_peditor_new_numeric_range (GConfChangeSet *changeset, GtkWidget *range, gchar *first_property_name, ...); + GObject *gconf_peditor_new_font (GConfChangeSet *changeset, gchar *key, GtkWidget *font_picker, + GConfPEditorFontType font_type, gchar *first_property_name, ...); |