summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2009-02-01 05:26:54 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2009-02-01 05:26:54 +0000
commit6141b6374915cb56292d79b0421c31e3cc7ae751 (patch)
treefbeea3599aa892b92a4b727546ed699f242f6c70
parent9ddef74ec71ec35feead3d7cfb3913d9921e10d3 (diff)
downloadgdk-pixbuf-6141b6374915cb56292d79b0421c31e3cc7ae751.tar.gz
Bug 569635 – fontchooser should reload list of families/styles on theme
2009-02-01 Behdad Esfahbod <behdad@gnome.org> Bug 569635 – fontchooser should reload list of families/styles on theme change * gtk/gtkfontsel.c (gtk_font_selection_class_init), (gtk_font_selection_init), (gtk_font_selection_finalize), (gtk_font_selection_ref_family), (gtk_font_selection_ref_face), (gtk_font_selection_reload_fonts), (gtk_font_selection_screen_changed), (gtk_font_selection_style_set), (gtk_font_selection_scroll_to_selection), (gtk_font_selection_scroll_on_map), (gtk_font_selection_select_font), (gtk_font_selection_show_available_fonts), (gtk_font_selection_show_available_styles), (gtk_font_selection_select_style), (gtk_font_selection_select_font_desc), (gtk_font_selection_set_font_name): Reload Pango families and faces in style_set. Installing/uninstalling fonts shows up immediately in an open font chooser now. svn path=/trunk/; revision=22269
-rw-r--r--ChangeLog22
-rw-r--r--gtk/gtkfontsel.c207
2 files changed, 170 insertions, 59 deletions
diff --git a/ChangeLog b/ChangeLog
index 810d35b37..d3613065f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2009-02-01 Behdad Esfahbod <behdad@gnome.org>
+
+ Bug 569635 – fontchooser should reload list of families/styles on
+ theme change
+
+ * gtk/gtkfontsel.c (gtk_font_selection_class_init),
+ (gtk_font_selection_init), (gtk_font_selection_finalize),
+ (gtk_font_selection_ref_family), (gtk_font_selection_ref_face),
+ (gtk_font_selection_reload_fonts),
+ (gtk_font_selection_screen_changed),
+ (gtk_font_selection_style_set),
+ (gtk_font_selection_scroll_to_selection),
+ (gtk_font_selection_scroll_on_map),
+ (gtk_font_selection_select_font),
+ (gtk_font_selection_show_available_fonts),
+ (gtk_font_selection_show_available_styles),
+ (gtk_font_selection_select_style),
+ (gtk_font_selection_select_font_desc),
+ (gtk_font_selection_set_font_name):
+ Reload Pango families and faces in style_set. Installing/uninstalling
+ fonts shows up immediately in an open font chooser now.
+
2009-01-31 Matthias Clasen <mclasen@redhat.com>
Bug 162726 – Multiple Latin layouts in XKB break keyboard shortcuts
diff --git a/gtk/gtkfontsel.c b/gtk/gtkfontsel.c
index ef01b0532..84ee9dc85 100644
--- a/gtk/gtkfontsel.c
+++ b/gtk/gtkfontsel.c
@@ -124,9 +124,11 @@ static void gtk_font_selection_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
-static void gtk_font_selection_finalize (GObject *object);
-static void gtk_font_selection_screen_changed (GtkWidget *widget,
- GdkScreen *previous_screen);
+static void gtk_font_selection_finalize (GObject *object);
+static void gtk_font_selection_screen_changed (GtkWidget *widget,
+ GdkScreen *previous_screen);
+static void gtk_font_selection_style_set (GtkWidget *widget,
+ GtkStyle *prev_style);
/* These are the callbacks & related functions. */
static void gtk_font_selection_select_font (GtkTreeSelection *selection,
@@ -155,12 +157,24 @@ static void gtk_font_selection_scroll_on_map (GtkWidget *w,
static void gtk_font_selection_preview_changed (GtkWidget *entry,
GtkFontSelection *fontsel);
+static void gtk_font_selection_scroll_to_selection (GtkFontSelection *fontsel);
+
/* Misc. utility functions. */
static void gtk_font_selection_load_font (GtkFontSelection *fs);
static void gtk_font_selection_update_preview (GtkFontSelection *fs);
static GdkFont* gtk_font_selection_get_font_internal (GtkFontSelection *fontsel);
+static PangoFontDescription *gtk_font_selection_get_font_description (GtkFontSelection *fontsel);
+static gboolean gtk_font_selection_select_font_desc (GtkFontSelection *fontsel,
+ PangoFontDescription *new_desc,
+ PangoFontFamily **pfamily,
+ PangoFontFace **pface);
+static void gtk_font_selection_reload_fonts (GtkFontSelection *fontsel);
+static void gtk_font_selection_ref_family (GtkFontSelection *fontsel,
+ PangoFontFamily *family);
+static void gtk_font_selection_ref_face (GtkFontSelection *fontsel,
+ PangoFontFace *face);
G_DEFINE_TYPE (GtkFontSelection, gtk_font_selection, GTK_TYPE_VBOX)
@@ -174,6 +188,7 @@ gtk_font_selection_class_init (GtkFontSelectionClass *klass)
gobject_class->get_property = gtk_font_selection_get_property;
widget_class->screen_changed = gtk_font_selection_screen_changed;
+ widget_class->style_set = gtk_font_selection_style_set;
g_object_class_install_property (gobject_class,
PROP_FONT_NAME,
@@ -534,7 +549,6 @@ gtk_font_selection_init (GtkFontSelection *fontsel)
-1, INITIAL_PREVIEW_HEIGHT);
gtk_box_pack_start (GTK_BOX (text_box), fontsel->preview_entry,
TRUE, TRUE, 0);
-
gtk_widget_pop_composite_child();
}
@@ -567,24 +581,68 @@ gtk_font_selection_finalize (GObject *object)
if (fontsel->font)
gdk_font_unref (fontsel->font);
+ gtk_font_selection_ref_family (fontsel, NULL);
+ gtk_font_selection_ref_face (fontsel, NULL);
+
G_OBJECT_CLASS (gtk_font_selection_parent_class)->finalize (object);
}
static void
-gtk_font_selection_screen_changed (GtkWidget *widget,
- GdkScreen *previous_screen)
+gtk_font_selection_ref_family (GtkFontSelection *fontsel,
+ PangoFontFamily *family)
{
- GtkFontSelection *fontsel = GTK_FONT_SELECTION (widget);
+ if (family)
+ family = g_object_ref (family);
+ if (fontsel->family)
+ g_object_unref (fontsel->family);
+ fontsel->family = family;
+}
+static void gtk_font_selection_ref_face (GtkFontSelection *fontsel,
+ PangoFontFace *face)
+{
+ if (face)
+ face = g_object_ref (face);
+ if (fontsel->face)
+ g_object_unref (fontsel->face);
+ fontsel->face = face;
+}
+
+static void
+gtk_font_selection_reload_fonts (GtkFontSelection *fontsel)
+{
if (gtk_widget_has_screen (GTK_WIDGET (fontsel)))
{
+ PangoFontDescription *desc;
+ desc = gtk_font_selection_get_font_description (fontsel);
+
gtk_font_selection_show_available_fonts (fontsel);
gtk_font_selection_show_available_sizes (fontsel, TRUE);
gtk_font_selection_show_available_styles (fontsel);
+
+ gtk_font_selection_select_font_desc (fontsel, desc, NULL, NULL);
+ gtk_font_selection_scroll_to_selection (fontsel);
+
+ pango_font_description_free (desc);
}
}
static void
+gtk_font_selection_screen_changed (GtkWidget *widget,
+ GdkScreen *previous_screen)
+{
+ gtk_font_selection_reload_fonts (GTK_FONT_SELECTION (widget));
+}
+
+static void
+gtk_font_selection_style_set (GtkWidget *widget,
+ GtkStyle *prev_style)
+{
+ /* Maybe fonts where installed or removed... */
+ gtk_font_selection_reload_fonts (GTK_FONT_SELECTION (widget));
+}
+
+static void
gtk_font_selection_preview_changed (GtkWidget *entry,
GtkFontSelection *fontsel)
{
@@ -618,19 +676,9 @@ set_cursor_to_iter (GtkTreeView *view,
gtk_tree_path_free (path);
}
-/* This is called when the list is mapped. Here we scroll to the current
- font if necessary. */
static void
-gtk_font_selection_scroll_on_map (GtkWidget *widget,
- gpointer data)
+gtk_font_selection_scroll_to_selection (GtkFontSelection *fontsel)
{
- GtkFontSelection *fontsel;
-
-#ifdef FONTSEL_DEBUG
- g_message ("In expose_list\n");
-#endif
- fontsel = GTK_FONT_SELECTION (data);
-
/* Try to scroll the font family list to the selected item */
scroll_to_selection (GTK_TREE_VIEW (fontsel->family_list));
@@ -639,6 +687,15 @@ gtk_font_selection_scroll_on_map (GtkWidget *widget,
/* Try to scroll the font family list to the selected item */
scroll_to_selection (GTK_TREE_VIEW (fontsel->size_list));
+/* This is called when the list is mapped. Here we scroll to the current
+ font if necessary. */
+}
+
+static void
+gtk_font_selection_scroll_on_map (GtkWidget *widget,
+ gpointer data)
+{
+ gtk_font_selection_scroll_to_selection (GTK_FONT_SELECTION (data));
}
/* This is called when a family is selected in the list. */
@@ -662,7 +719,7 @@ gtk_font_selection_select_font (GtkTreeSelection *selection,
gtk_tree_model_get (model, &iter, FAMILY_COLUMN, &family, -1);
if (fontsel->family != family)
{
- fontsel->family = family;
+ gtk_font_selection_ref_family (fontsel, family);
#ifdef INCLUDE_FONT_ENTRIES
family_name = pango_font_family_get_name (fontsel->family);
@@ -721,7 +778,7 @@ gtk_font_selection_show_available_fonts (GtkFontSelection *fontsel)
}
}
- fontsel->family = match_family;
+ gtk_font_selection_ref_family (fontsel, match_family);
if (match_family)
{
set_cursor_to_iter (GTK_TREE_VIEW (fontsel->family_list), &match_row);
@@ -837,7 +894,7 @@ gtk_font_selection_show_available_styles (GtkFontSelection *fontsel)
if (old_desc)
pango_font_description_free (old_desc);
- fontsel->face = match_face;
+ gtk_font_selection_ref_face (fontsel, match_face);
if (match_face)
{
#ifdef INCLUDE_FONT_ENTRIES
@@ -890,8 +947,7 @@ gtk_font_selection_select_style (GtkTreeSelection *selection,
PangoFontFace *face;
gtk_tree_model_get (model, &iter, FACE_COLUMN, &face, -1);
- fontsel->face = face;
-
+ gtk_font_selection_ref_face (fontsel, face);
g_object_unref (face);
}
@@ -1329,48 +1385,26 @@ gtk_font_selection_get_font_name (GtkFontSelection *fontsel)
return result;
}
-
-/* This sets the current font, selecting the appropriate list rows.
+/* This selects the appropriate list rows.
First we check the fontname is valid and try to find the font family
- i.e. the name in the main list. If we can't find that, then just return.
Next we try to set each of the properties according to the fontname.
Finally we select the font family & style in the lists. */
-
-/**
- * gtk_font_selection_set_font_name:
- * @fontsel: a #GtkFontSelection
- * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
- *
- * Sets the currently-selected font.
- *
- * Note that the @fontsel needs to know the screen in which it will appear
- * for this to work; this can be guaranteed by simply making sure that the
- * @fontsel is inserted in a toplevel window before you call this function.
- *
- * Return value: %TRUE if the font could be set successfully; %FALSE if no
- * such font exists or if the @fontsel doesn't belong to a particular
- * screen yet.
- */
-gboolean
-gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
- const gchar *fontname)
+static gboolean
+gtk_font_selection_select_font_desc (GtkFontSelection *fontsel,
+ PangoFontDescription *new_desc,
+ PangoFontFamily **pfamily,
+ PangoFontFace **pface)
{
PangoFontFamily *new_family = NULL;
PangoFontFace *new_face = NULL;
PangoFontFace *fallback_face = NULL;
- PangoFontDescription *new_desc;
GtkTreeModel *model;
GtkTreeIter iter;
GtkTreeIter match_iter;
gboolean valid;
const gchar *new_family_name;
-
- g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), FALSE);
-
- if (!gtk_widget_has_screen (GTK_WIDGET (fontsel)))
- return FALSE;
- new_desc = pango_font_description_from_string (fontname);
new_family_name = pango_font_description_get_family (new_desc);
if (!new_family_name)
@@ -1389,8 +1423,8 @@ gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
if (g_ascii_strcasecmp (pango_font_family_get_name (family),
new_family_name) == 0)
- new_family = family;
-
+ new_family = g_object_ref (family);
+
g_object_unref (family);
if (new_family)
@@ -1400,7 +1434,10 @@ gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
if (!new_family)
return FALSE;
- fontsel->family = new_family;
+ if (pfamily)
+ *pfamily = new_family;
+ else
+ g_object_unref (new_family);
set_cursor_to_iter (GTK_TREE_VIEW (fontsel->family_list), &iter);
gtk_font_selection_show_available_styles (fontsel);
@@ -1416,11 +1453,11 @@ gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
tmp_desc = pango_font_face_describe (face);
if (font_description_style_equal (tmp_desc, new_desc))
- new_face = face;
+ new_face = g_object_ref (face);
if (!fallback_face)
{
- fallback_face = face;
+ fallback_face = g_object_ref (face);
match_iter = iter;
}
@@ -1436,19 +1473,71 @@ gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
if (!new_face)
new_face = fallback_face;
+ else if (fallback_face)
+ g_object_unref (fallback_face);
- fontsel->face = new_face;
+ if (pface)
+ *pface = new_face;
+ else if (new_face)
+ g_object_unref (new_face);
set_cursor_to_iter (GTK_TREE_VIEW (fontsel->face_list), &match_iter);
gtk_font_selection_set_size (fontsel, pango_font_description_get_size (new_desc));
+
+ return TRUE;
+}
+
+
+/* This sets the current font, then selecting the appropriate list rows. */
+
+/**
+ * gtk_font_selection_set_font_name:
+ * @fontsel: a #GtkFontSelection
+ * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
+ *
+ * Sets the currently-selected font.
+ *
+ * Note that the @fontsel needs to know the screen in which it will appear
+ * for this to work; this can be guaranteed by simply making sure that the
+ * @fontsel is inserted in a toplevel window before you call this function.
+ *
+ * Return value: %TRUE if the font could be set successfully; %FALSE if no
+ * such font exists or if the @fontsel doesn't belong to a particular
+ * screen yet.
+ */
+gboolean
+gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
+ const gchar *fontname)
+{
+ PangoFontFamily *family = NULL;
+ PangoFontFace *face = NULL;
+ PangoFontDescription *new_desc;
+
+ g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), FALSE);
+
+ if (!gtk_widget_has_screen (GTK_WIDGET (fontsel)))
+ return FALSE;
+
+ new_desc = pango_font_description_from_string (fontname);
+
+ if (gtk_font_selection_select_font_desc (fontsel, new_desc, &family, &face))
+ {
+ gtk_font_selection_ref_family (fontsel, family);
+ if (family)
+ g_object_unref (family);
+
+ gtk_font_selection_ref_face (fontsel, face);
+ if (face)
+ g_object_unref (face);
+ }
+
+ pango_font_description_free (new_desc);
g_object_freeze_notify (G_OBJECT (fontsel));
g_object_notify (G_OBJECT (fontsel), "font-name");
g_object_notify (G_OBJECT (fontsel), "font");
g_object_thaw_notify (G_OBJECT (fontsel));
- pango_font_description_free (new_desc);
-
return TRUE;
}