From 12501f93c9ca85daee735a625a29a766607c3032 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Sat, 16 Apr 2011 01:47:39 +0100 Subject: [PATCH] GtkFontChooser: Populated font list model --- gtk/gtkfontchooser.c | 76 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 12 deletions(-) diff --git a/gtk/gtkfontchooser.c b/gtk/gtkfontchooser.c index d0ccb0ac4a..05fd2bfadb 100644 --- a/gtk/gtkfontchooser.c +++ b/gtk/gtkfontchooser.c @@ -312,7 +312,8 @@ gtk_font_selection_init (GtkFontSelection *fontsel) /* Alignment for the preview and size controls */ alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0); - gtk_alignment_set_padding (alignment, PREVIEW_TOP_PADDING, 0, 0, 0); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), + PREVIEW_TOP_PADDING, 0, 0, 0); preview_and_size = gtk_vbox_new (TRUE, 0); gtk_box_set_homogeneous (GTK_BOX (preview_and_size), FALSE); @@ -340,7 +341,7 @@ gtk_font_selection_init (GtkFontSelection *fontsel) gtk_widget_show_all (GTK_WIDGET (fontsel)); gtk_widget_hide (GTK_WIDGET (fontsel)); - gtk_font_selection_bootstrap_fontlist (priv->family_face_list); + gtk_font_selection_bootstrap_fontlist (GTK_TREE_VIEW (priv->family_face_list)); gtk_widget_pop_composite_child(); } @@ -362,18 +363,71 @@ gtk_font_selection_new (void) return GTK_WIDGET (fontsel); } +static int +cmp_families (const void *a, const void *b) +{ + const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a); + const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b); + + return g_utf8_collate (a_name, b_name); +} + +static void +set_cursor_to_iter (GtkTreeView *view, + GtkTreeIter *iter) +{ + GtkTreeModel *model = gtk_tree_view_get_model (view); + GtkTreePath *path = gtk_tree_model_get_path (model, iter); + + gtk_tree_view_set_cursor (view, path, NULL, FALSE); + + gtk_tree_path_free (path); +} static void -gtk_font_selection_populate_model (GtkTreeModel *model) +gtk_font_selection_populate_model (GtkTreeView *treeview, GtkListStore *model) { - + PangoFontFamily *match_family; + PangoFontFamily **families; + gint n_families, i; + GtkTreeIter match_row; + + pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (treeview)), + &families, + &n_families); + + qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families); + + gtk_list_store_clear (model); + + for (i=0; ipriv; -#if 0 + if (family) family = g_object_ref (family); if (priv->family) g_object_unref (priv->family); priv->family = family; -#endif } static void gtk_font_selection_ref_face (GtkFontSelection *fontsel, - PangoFontFace *face) + PangoFontFace *face) { GtkFontSelectionPrivate *priv = fontsel->priv; -#if 0 + if (face) face = g_object_ref (face); if (priv->face) g_object_unref (priv->face); priv->face = face; -#endif } /*****************************************************************************