[gtk+] Make setting fontname work, independent of a screen
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Make setting fontname work, independent of a screen
- Date: Mon, 15 Aug 2011 23:56:47 +0000 (UTC)
commit 6877893ed5c5ace9e91c111a3c798d71ea34bc19
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Aug 14 23:46:14 2011 -0400
Make setting fontname work, independent of a screen
gtk/gtkfontchooser.c | 61 +++++++++++++++++++++++++++++++++----------------
1 files changed, 41 insertions(+), 20 deletions(-)
---
diff --git a/gtk/gtkfontchooser.c b/gtk/gtkfontchooser.c
index 7f3989a..733758f 100644
--- a/gtk/gtkfontchooser.c
+++ b/gtk/gtkfontchooser.c
@@ -91,6 +91,7 @@ struct _GtkFontChooserPrivate
GtkWidget *size_spin;
GtkWidget *size_slider;
+ gchar *fontname;
gint size;
PangoFontFace *face;
PangoFontFamily *family;
@@ -157,6 +158,8 @@ static void gtk_font_chooser_style_updated (GtkWidget *widget);
static void gtk_font_chooser_bootstrap_fontlist (GtkFontChooser *fontchooser);
+static gboolean gtk_font_chooser_select_font_name (GtkFontChooser *fontchooser);
+
G_DEFINE_TYPE (GtkFontChooser, gtk_font_chooser, GTK_TYPE_BOX)
static void
@@ -693,13 +696,13 @@ populate_list (GtkFontChooser *fontchooser,
GtkListStore *model)
{
GtkFontChooserPrivate *priv = fontchooser->priv;
- GtkStyleContext *style_context;
+ GtkStyleContext *style_context;
PangoFontDescription *default_font;
PangoFontDescription *selected_font;
gint match;
- GtkTreeIter match_row;
- GtkTreePath *path;
+ GtkTreeIter match_row;
+ GtkTreePath *path;
gint n_families, i;
PangoFontFamily **families;
@@ -718,7 +721,6 @@ populate_list (GtkFontChooser *fontchooser,
qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families);
- /* Get theme font */
style_context = gtk_widget_get_style_context (GTK_WIDGET (treeview));
default_font = (PangoFontDescription*) gtk_style_context_get_font (style_context,
GTK_STATE_NORMAL);
@@ -928,6 +930,9 @@ gtk_font_chooser_finalize (GObject *object)
GtkFontChooser *fontchooser = GTK_FONT_CHOOSER (object);
GtkFontChooserPrivate *priv = fontchooser->priv;
+ if (priv->fontname)
+ g_free (priv->fontname);
+
if (priv->family)
g_object_unref (priv->family);
@@ -945,10 +950,14 @@ gtk_font_chooser_screen_changed (GtkWidget *widget,
GdkScreen *previous_screen)
{
GtkFontChooser *fontchooser = GTK_FONT_CHOOSER (widget);
+ GtkFontChooserPrivate *priv = fontchooser->priv;
populate_list (fontchooser,
- GTK_TREE_VIEW (fontchooser->priv->family_face_list),
- fontchooser->priv->model);
+ GTK_TREE_VIEW (priv->family_face_list),
+ priv->model);
+
+ if (priv->fontname)
+ gtk_font_chooser_select_font_name (fontchooser);
}
static void
@@ -1071,11 +1080,6 @@ gtk_font_chooser_get_font_name (GtkFontChooser *fontchooser)
*
* Sets the currently-selected font.
*
- * Note that the @fontchooser needs to know the screen in which
- * it will appear for this to work; this can be guaranteed by simply
- * making sure that the @fontchooser 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 @fontchooser doesn't belong
* to a particular screen yet.
@@ -1087,21 +1091,39 @@ gtk_font_chooser_set_font_name (GtkFontChooser *fontchooser,
const gchar *fontname)
{
GtkFontChooserPrivate *priv = fontchooser->priv;
- GtkTreeIter iter;
- gboolean valid;
- gchar *family_name;
- PangoFontDescription *desc;
- gboolean found = FALSE;
+ gboolean found = FALSE;
g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), FALSE);
g_return_val_if_fail (fontname != NULL, FALSE);
- if (!gtk_widget_has_screen (GTK_WIDGET (fontchooser)))
- return FALSE;
+ if (priv->fontname)
+ g_free (priv->fontname);
+ priv->fontname = g_strdup (fontname);
+
+ if (gtk_widget_has_screen (GTK_WIDGET (fontchooser)))
+ found = gtk_font_chooser_select_font_name (fontchooser);
- desc = pango_font_description_from_string (fontname);
+ g_object_notify (G_OBJECT (fontchooser), "font-name");
+
+ return found;
+}
+
+static gboolean
+gtk_font_chooser_select_font_name (GtkFontChooser *fontchooser)
+{
+ GtkFontChooserPrivate *priv = fontchooser->priv;
+ GtkTreeIter iter;
+ gboolean valid;
+ gchar *family_name;
+ PangoFontDescription *desc;
+ gboolean found = FALSE;
+
+ desc = pango_font_description_from_string (priv->fontname);
family_name = (gchar*)pango_font_description_get_family (desc);
+ g_free (priv->fontname);
+ priv->fontname = NULL;
+
if (!family_name)
{
pango_font_description_free (desc);
@@ -1172,7 +1194,6 @@ gtk_font_chooser_set_font_name (GtkFontChooser *fontchooser,
}
pango_font_description_free (desc);
- g_object_notify (G_OBJECT (fontchooser), "font-name");
return found;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]