]> Pileus Git - ~andy/gtk/blob - gtk/gtkfontchooser.c
7f3989a80a3986a4a6004ae8c167848887925cb7
[~andy/gtk] / gtk / gtkfontchooser.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 2011 Alberto Ruiz <aruiz@gnome.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "config.h"
21
22 #include <stdlib.h>
23 #include <glib/gprintf.h>
24 #include <string.h>
25
26 #include <atk/atk.h>
27
28 #include "gtkfontchooser.h"
29 #include "gtkcellrenderertext.h"
30 #include "gtkentry.h"
31 #include "gtkframe.h"
32 #include "gtkhbbox.h"
33 #include "gtkhbox.h"
34 #include "gtklabel.h"
35 #include "gtkliststore.h"
36 #include "gtkstock.h"
37 #include "gtktextview.h"
38 #include "gtktreeselection.h"
39 #include "gtktreeview.h"
40 #include "gtkbox.h"
41 #include "gtkscrolledwindow.h"
42 #include "gtkintl.h"
43 #include "gtkaccessible.h"
44 #include "gtkbuildable.h"
45 #include "gtkprivate.h"
46 #include "gtkalignment.h"
47 #include "gtkscale.h"
48 #include "gtkbox.h"
49 #include "gtkspinbutton.h"
50 #include "gtknotebook.h"
51 #include "gtkwidget.h"
52 #include "gtkgrid.h"
53
54 /**
55  * SECTION:gtkfontchooser
56  * @Short_description: A widget for selecting fonts
57  * @Title: GtkFontChooser
58  * @See_also: #GtkFontChooserDialog
59  *
60  * The #GtkFontChooser widget lists the available fonts, styles and sizes,
61  * allowing the user to select a font.
62  * It is used in the #GtkFontChooserDialog widget to provide a dialog box for
63  * selecting fonts.
64  *
65  * To set the font which is initially selected, use
66  * gtk_font_chooser_set_font_name().
67  *
68  * To get the selected font use gtk_font_chooser_get_font_name().
69  *
70  * To change the text which is shown in the preview area, use
71  * gtk_font_chooser_set_preview_text().
72  *
73  * Since: 3.2
74  */
75
76
77 struct _GtkFontChooserPrivate
78 {
79   GtkWidget    *search_entry;
80   GtkWidget    *family_face_list;
81   GtkWidget    *list_scrolled_window;
82   GtkWidget    *empty_list;
83   GtkWidget    *list_notebook;
84   GtkListStore *model;
85   GtkTreeModel *filter_model;
86
87   GtkWidget       *preview;
88   gchar           *preview_text;
89   gboolean         show_preview_entry;
90
91   GtkWidget *size_spin;
92   GtkWidget *size_slider;
93
94   gint             size;
95   PangoFontFace   *face;
96   PangoFontFamily *family;
97
98   gulong           cursor_changed_handler;
99
100   GtkFontFilterFunc filter_func;
101   gpointer          filter_data;
102   GDestroyNotify    filter_data_destroy;
103 };
104
105 #define DEFAULT_FONT_NAME "Sans 10"
106 #define MAX_FONT_SIZE 999
107
108 /* This is the initial fixed height and the top padding of the preview entry */
109 #define PREVIEW_HEIGHT 72
110 #define PREVIEW_TOP_PADDING 6
111
112 /* These are the sizes of the font, style & size lists. */
113 #define FONT_LIST_HEIGHT  136
114 #define FONT_LIST_WIDTH   190
115 #define FONT_STYLE_LIST_WIDTH 170
116 #define FONT_SIZE_LIST_WIDTH  60
117
118 #define ROW_FORMAT_STRING "<span weight=\"bold\" size=\"small\">%s</span>\n<span size=\"x-large\" font_desc=\"%s\">%s</span>"
119
120 #define NO_FONT_MATCHED_SEARCH "No fonts matched your search. You can revise your search and try again."
121
122 /* These are what we use as the standard font sizes, for the size list.
123  */
124 static const gint font_sizes[] = {
125   6, 8, 9, 10, 11, 12, 13, 14, 16, 20, 24, 36, 48, 72
126 };
127
128 enum {
129    PROP_0,
130    PROP_FONT_NAME,
131    PROP_PREVIEW_TEXT,
132    PROP_SHOW_PREVIEW_ENTRY
133 };
134
135
136 enum {
137   FAMILY_COLUMN,
138   FACE_COLUMN,
139   PREVIEW_TEXT_COLUMN,
140   PREVIEW_TITLE_COLUMN
141 };
142
143 static void  gtk_font_chooser_set_property       (GObject         *object,
144                                                   guint            prop_id,
145                                                   const GValue    *value,
146                                                   GParamSpec      *pspec);
147 static void  gtk_font_chooser_get_property       (GObject         *object,
148                                                   guint            prop_id,
149                                                   GValue          *value,
150                                                   GParamSpec      *pspec);
151 static void  gtk_font_chooser_finalize           (GObject         *object);
152 static void  gtk_font_chooser_dispose            (GObject         *object);
153
154 static void  gtk_font_chooser_screen_changed     (GtkWidget       *widget,
155                                                   GdkScreen       *previous_screen);
156 static void  gtk_font_chooser_style_updated      (GtkWidget       *widget);
157
158 static void gtk_font_chooser_bootstrap_fontlist (GtkFontChooser *fontchooser);
159
160 G_DEFINE_TYPE (GtkFontChooser, gtk_font_chooser, GTK_TYPE_BOX)
161
162 static void
163 gtk_font_chooser_class_init (GtkFontChooserClass *klass)
164 {
165   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
166   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
167
168   widget_class->screen_changed = gtk_font_chooser_screen_changed;
169   widget_class->style_updated = gtk_font_chooser_style_updated;
170
171   gobject_class->dispose = gtk_font_chooser_dispose;
172   gobject_class->finalize = gtk_font_chooser_finalize;
173   gobject_class->set_property = gtk_font_chooser_set_property;
174   gobject_class->get_property = gtk_font_chooser_get_property;
175
176   g_object_class_install_property (gobject_class,
177                                    PROP_FONT_NAME,
178                                    g_param_spec_string ("font-name",
179                                                         P_("Font name"),
180                                                         P_("The string that represents this font"),
181                                                         DEFAULT_FONT_NAME,
182                                                         GTK_PARAM_READWRITE));
183   g_object_class_install_property (gobject_class,
184                                    PROP_PREVIEW_TEXT,
185                                    g_param_spec_string ("preview-text",
186                                                         P_("Preview text"),
187                                                         P_("The text to display in order to demonstrate the selected font"),
188                                                         pango_language_get_sample_string (NULL),
189                                                         GTK_PARAM_READWRITE));
190
191   g_object_class_install_property (gobject_class,
192                                    PROP_SHOW_PREVIEW_ENTRY,
193                                    g_param_spec_boolean ("show-preview-entry",
194                                                         P_("Show preview text entry"),
195                                                         P_("Whether the preview text entry is shown or not"),
196                                                         TRUE,
197                                                         GTK_PARAM_READWRITE));
198
199   g_type_class_add_private (klass, sizeof (GtkFontChooserPrivate));
200 }
201
202 static void
203 gtk_font_chooser_set_property (GObject         *object,
204                                guint            prop_id,
205                                const GValue    *value,
206                                GParamSpec      *pspec)
207 {
208   GtkFontChooser *fontchooser;
209
210   fontchooser = GTK_FONT_CHOOSER (object);
211
212   switch (prop_id)
213     {
214     case PROP_FONT_NAME:
215       gtk_font_chooser_set_font_name (fontchooser, g_value_get_string (value));
216       break;
217     case PROP_PREVIEW_TEXT:
218       gtk_font_chooser_set_preview_text (fontchooser, g_value_get_string (value));
219       break;
220     case PROP_SHOW_PREVIEW_ENTRY:
221       gtk_font_chooser_set_show_preview_entry (fontchooser, g_value_get_boolean (value));
222       break;
223     default:
224       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
225       break;
226     }
227 }
228
229 static void
230 gtk_font_chooser_get_property (GObject         *object,
231                                guint            prop_id,
232                                GValue          *value,
233                                GParamSpec      *pspec)
234 {
235   GtkFontChooser *fontchooser;
236
237   fontchooser = GTK_FONT_CHOOSER (object);
238
239   switch (prop_id)
240     {
241     case PROP_FONT_NAME:
242       g_value_take_string (value, gtk_font_chooser_get_font_name (fontchooser));
243       break;
244     case PROP_PREVIEW_TEXT:
245       g_value_set_string (value, gtk_font_chooser_get_preview_text (fontchooser));
246       break;
247     case PROP_SHOW_PREVIEW_ENTRY:
248       g_value_set_boolean (value, gtk_font_chooser_get_show_preview_entry (fontchooser));
249       break;
250     default:
251       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
252       break;
253     }
254 }
255
256 static void
257 text_changed_cb (GtkEntry       *entry,
258                  GParamSpec     *pspec,
259                  GtkFontChooser *fc)
260 {
261   GtkFontChooserPrivate *priv = fc->priv;
262   const gchar *text;
263
264   text = gtk_entry_get_text (entry);
265
266   if (text == NULL || text[0] == '\0')
267     {
268       GIcon *icon;
269
270       icon = g_themed_icon_new_with_default_fallbacks ("edit-find-symbolic");
271       g_object_set (G_OBJECT (priv->search_entry),
272                     "secondary-icon-gicon", icon,
273                     "secondary-icon-activatable", FALSE,
274                     "secondary-icon-sensitive", FALSE,
275                     NULL);
276       g_object_unref (icon);
277     }
278   else
279     {
280       if (!gtk_entry_get_icon_activatable (GTK_ENTRY (priv->search_entry), GTK_ENTRY_ICON_SECONDARY))
281         {
282           GIcon *icon;
283
284           icon = g_themed_icon_new_with_default_fallbacks ("edit-clear-symbolic");
285           g_object_set (G_OBJECT (priv->search_entry),
286                         "secondary-icon-gicon", icon,
287                         "secondary-icon-activatable", TRUE,
288                         "secondary-icon-sensitive", TRUE,
289                         NULL);
290           g_object_unref (icon);
291         }
292     }
293
294   gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter_model));
295 }
296
297 static void
298 icon_press_cb (GtkEntry             *entry,
299                GtkEntryIconPosition  pos,
300                GdkEvent             *event,
301                gpointer              user_data)
302 {
303   gtk_entry_set_text (entry, "");
304 }
305
306 static void
307 slider_change_cb (GtkAdjustment *adjustment,
308                   gpointer       user_data)
309 {
310   GtkFontChooser        *fc    = (GtkFontChooser*)user_data;
311   GtkFontChooserPrivate *priv  = fc->priv;
312   GtkAdjustment         *spin_adj     = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON (priv->size_spin));
313   gdouble                slider_value = gtk_adjustment_get_value (adjustment);
314   gdouble                spin_value   = gtk_adjustment_get_value (spin_adj);
315
316   if (slider_value != spin_value)
317     gtk_adjustment_set_value (spin_adj,
318                               gtk_adjustment_get_value (adjustment));
319 }
320
321 static void
322 spin_change_cb (GtkAdjustment *adjustment,
323                 gpointer       user_data)
324 {
325   PangoFontDescription    *desc;
326   GtkFontChooser          *fontchooser = (GtkFontChooser*)user_data;
327   GtkFontChooserPrivate   *priv        = fontchooser->priv;
328   GtkAdjustment           *slider_adj  = gtk_range_get_adjustment (GTK_RANGE (priv->size_slider));
329
330   gdouble size = gtk_adjustment_get_value (adjustment);
331   priv->size = ((gint)size) * PANGO_SCALE;
332
333   desc = pango_context_get_font_description (gtk_widget_get_pango_context (priv->preview));
334   pango_font_description_set_size (desc, priv->size);
335   gtk_widget_override_font (priv->preview, desc);
336
337   g_object_notify (G_OBJECT (fontchooser), "font-name");
338
339   /* If the new value is lower than the lower bound of the slider, we set
340    * the slider adjustment to the lower bound value if it is not already set
341    */
342   if (size < gtk_adjustment_get_lower (slider_adj) &&
343       gtk_adjustment_get_value (slider_adj) != gtk_adjustment_get_lower (slider_adj))
344     gtk_adjustment_set_value (slider_adj, gtk_adjustment_get_lower (slider_adj));
345
346   /* If the new value is upper than the upper bound of the slider, we set
347    * the slider adjustment to the upper bound value if it is not already set
348    */
349   else if (size > gtk_adjustment_get_upper (slider_adj) &&
350            gtk_adjustment_get_value (slider_adj) != gtk_adjustment_get_upper (slider_adj))
351     gtk_adjustment_set_value (slider_adj, gtk_adjustment_get_upper (slider_adj));
352
353   /* If the new value is not already set on the slider we set it */
354   else if (size != gtk_adjustment_get_value (slider_adj))
355     gtk_adjustment_set_value (slider_adj, size);
356
357   gtk_widget_queue_draw (priv->preview);
358 }
359
360 static void
361 set_range_marks (GtkFontChooserPrivate *priv,
362                  GtkWidget             *size_slider,
363                  gint                  *sizes,
364                  gint                   length)
365 {
366   GtkAdjustment *adj;
367   gint i;
368   gdouble value;
369
370   if (length < 2)
371     {
372       sizes = (gint*)font_sizes;
373       length = G_N_ELEMENTS (font_sizes);
374     }
375
376   gtk_scale_clear_marks (GTK_SCALE (size_slider));
377
378   adj = gtk_range_get_adjustment(GTK_RANGE (size_slider));
379
380   gtk_adjustment_set_lower (adj, (gdouble) sizes[0]);
381   gtk_adjustment_set_upper (adj, (gdouble) sizes[length-1]);
382
383   value = gtk_adjustment_get_value (adj);
384   if (value > (gdouble) sizes[length-1])
385     gtk_adjustment_set_value (adj, (gdouble) sizes[length-1]);
386   else if (value < (gdouble) sizes[0])
387     gtk_adjustment_set_value (adj, (gdouble) sizes[0]);
388
389   for (i = 0; i < length; i++)
390     gtk_scale_add_mark (GTK_SCALE (size_slider),
391                         (gdouble) sizes[i],
392                         GTK_POS_BOTTOM, NULL);
393 }
394
395 static void
396 cursor_changed_cb (GtkTreeView *treeview,
397                    gpointer     user_data)
398 {
399   GtkFontChooser *fontchooser = (GtkFontChooser*)user_data;
400   GtkFontChooserPrivate *priv = fontchooser->priv;
401
402   PangoFontFamily      *family;
403   PangoFontFace        *face;
404   PangoFontDescription *desc;
405
406   gint *sizes;
407   gint  i, n_sizes;
408
409   GtkTreeIter  iter;
410   GtkTreePath *path = gtk_tree_path_new ();
411
412   gtk_tree_view_get_cursor (treeview, &path, NULL);
413
414   if (!path)
415     return;
416
417   if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->filter_model), &iter, path))
418     {
419       gtk_tree_path_free (path);
420       return;
421     }
422
423
424   gtk_tree_model_get (GTK_TREE_MODEL (priv->filter_model), &iter,
425                       FACE_COLUMN, &face,
426                       FAMILY_COLUMN, &family,
427                       -1);
428
429   gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0.5, 0.5);
430
431   gtk_tree_path_free (path);
432   path = NULL;
433
434   if (face == NULL || family == NULL)
435     {
436       if (face)
437         g_object_unref (face);
438       if (family)
439         g_object_unref (family);
440
441       return;
442     }
443
444   desc = pango_font_face_describe (face);
445   pango_font_description_set_size (desc, priv->size);
446   gtk_widget_override_font (priv->preview, desc);
447
448   pango_font_face_list_sizes (face, &sizes, &n_sizes);
449   /* It seems not many fonts actually have a sane set of sizes */
450   for (i = 0; i < n_sizes; i++)
451     sizes[i] = sizes[i] / PANGO_SCALE;
452
453   set_range_marks (priv, priv->size_slider, sizes, n_sizes);
454
455   if (priv->family)
456     g_object_unref (priv->family);
457   priv->family = family;
458
459   if (priv->face)
460     g_object_unref (priv->face);
461   priv->face = face;
462
463   pango_font_description_free (desc);
464
465   g_object_notify (G_OBJECT (fontchooser), "font-name");
466 }
467
468 static gboolean
469 zoom_preview_cb (GtkWidget      *scrolled_window,
470                  GdkEventScroll *event,
471                  gpointer        user_data)
472 {
473   GtkFontChooser        *fc    = (GtkFontChooser*)user_data;
474   GtkFontChooserPrivate *priv  = fc->priv;
475
476   GtkAdjustment *adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin));
477
478   if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_RIGHT)
479     gtk_adjustment_set_value (adj,
480                               gtk_adjustment_get_value (adj) +
481                               gtk_adjustment_get_step_increment (adj));
482   else if (event->direction == GDK_SCROLL_DOWN || event->direction == GDK_SCROLL_LEFT)
483     gtk_adjustment_set_value (adj,
484                               gtk_adjustment_get_value (adj) -
485                               gtk_adjustment_get_step_increment (adj));
486   return TRUE;
487 }
488
489 static void
490 row_inserted_cb (GtkTreeModel *model,
491                  GtkTreePath  *path,
492                  GtkTreeIter  *iter,
493                  gpointer      user_data)
494 {
495   GtkFontChooser        *fontchooser = (GtkFontChooser*)user_data;
496   GtkFontChooserPrivate *priv        = fontchooser->priv;
497
498   gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->list_notebook), 0);
499 }
500
501 static void
502 row_deleted_cb  (GtkTreeModel *model,
503                  GtkTreePath  *path,
504                  gpointer      user_data)
505 {
506   GtkFontChooser        *fontchooser = (GtkFontChooser*)user_data;
507   GtkFontChooserPrivate *priv        = fontchooser->priv;
508
509   if (gtk_tree_model_iter_n_children (model, NULL) == 0)
510     gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->list_notebook), 1);
511 }
512
513 static void
514 gtk_font_chooser_init (GtkFontChooser *fontchooser)
515 {
516   GIcon                   *icon;
517   GtkFontChooserPrivate   *priv;
518   PangoFontDescription    *font_desc;
519   GtkWidget               *scrolled_win;
520   GtkWidget               *grid;
521
522   fontchooser->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontchooser,
523                                                    GTK_TYPE_FONT_CHOOSER,
524                                                    GtkFontChooserPrivate);
525
526   priv = fontchooser->priv;
527
528   /* Default preview string  */
529   priv->preview_text = g_strdup (pango_language_get_sample_string (NULL));
530   priv->show_preview_entry = TRUE;
531
532   /* Getting the default size */
533   font_desc  = pango_context_get_font_description (gtk_widget_get_pango_context (GTK_WIDGET (fontchooser)));
534   priv->size = pango_font_description_get_size (font_desc);
535   priv->face = NULL;
536   priv->family = NULL;
537
538   gtk_widget_push_composite_child ();
539
540   /* Creating fundamental widgets for the private struct */
541   priv->search_entry = gtk_entry_new ();
542   priv->family_face_list = gtk_tree_view_new ();
543   priv->preview = gtk_entry_new ();
544   priv->size_slider = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
545                                                 (gdouble) font_sizes[0],
546                                                 (gdouble) font_sizes[G_N_ELEMENTS (font_sizes) - 1],
547                                                 1.0);
548
549   priv->size_spin = gtk_spin_button_new_with_range (0.0, (gdouble)(G_MAXINT / PANGO_SCALE), 1.0);
550
551   /** Bootstrapping widget layout **/
552   gtk_box_set_spacing (GTK_BOX (fontchooser), 6);
553
554   /* Main font family/face view */
555   priv->list_scrolled_window = gtk_scrolled_window_new (NULL, NULL);
556   scrolled_win = priv->list_scrolled_window;
557   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
558                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
559   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
560                                        GTK_SHADOW_ETCHED_IN);
561   gtk_widget_set_size_request (scrolled_win, 400, 300);
562   gtk_container_add (GTK_CONTAINER (scrolled_win), priv->family_face_list);
563
564   /* Text to display when list is empty */
565   priv->empty_list = gtk_label_new (_(NO_FONT_MATCHED_SEARCH));
566   gtk_widget_set_margin_top    (priv->empty_list, 12);
567   gtk_widget_set_margin_left   (priv->empty_list, 12);
568   gtk_widget_set_margin_right  (priv->empty_list, 12);
569   gtk_widget_set_margin_bottom (priv->empty_list, 12);
570   gtk_widget_set_halign (priv->empty_list, GTK_ALIGN_CENTER);
571   gtk_widget_set_valign (priv->empty_list, GTK_ALIGN_START);
572
573   priv->list_notebook = gtk_notebook_new ();
574   gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->list_notebook), FALSE);
575   gtk_notebook_append_page (GTK_NOTEBOOK (priv->list_notebook), scrolled_win, NULL);
576   gtk_notebook_append_page (GTK_NOTEBOOK (priv->list_notebook), priv->empty_list, NULL);
577
578   /* Basic layout */
579   grid = gtk_grid_new ();
580
581   gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
582   gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
583
584   gtk_grid_attach (GTK_GRID (grid), priv->search_entry, 0, 0, 2, 1);
585   gtk_grid_attach (GTK_GRID (grid), priv->list_notebook, 0, 1, 2, 1);
586   gtk_grid_attach (GTK_GRID (grid), priv->preview,      0, 2, 2, 1);
587
588   gtk_grid_attach (GTK_GRID (grid), priv->size_slider,  0, 3, 1, 1);
589   gtk_grid_attach (GTK_GRID (grid), priv->size_spin,    1, 3, 1, 1);
590
591   gtk_widget_set_hexpand  (GTK_WIDGET (scrolled_win),      TRUE);
592   gtk_widget_set_vexpand  (GTK_WIDGET (scrolled_win),      TRUE);
593   gtk_widget_set_hexpand  (GTK_WIDGET (priv->search_entry), TRUE);
594
595   gtk_widget_set_hexpand  (GTK_WIDGET (priv->size_slider), TRUE);
596   gtk_widget_set_hexpand  (GTK_WIDGET (priv->size_spin),   FALSE);
597
598   gtk_box_pack_start (GTK_BOX (fontchooser), grid, TRUE, TRUE, 0);
599
600   /* Setting the adjustment values for the size slider */
601   gtk_adjustment_set_value (gtk_range_get_adjustment (GTK_RANGE (priv->size_slider)),
602                             (gdouble)(priv->size / PANGO_SCALE));
603   gtk_adjustment_set_value (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin)),
604                             (gdouble)(priv->size / PANGO_SCALE));
605
606   gtk_widget_show_all (GTK_WIDGET (fontchooser));
607   gtk_widget_hide     (GTK_WIDGET (fontchooser));
608
609   /* Treeview column and model bootstrapping */
610   gtk_font_chooser_bootstrap_fontlist (fontchooser);
611
612   /* Set default preview text */
613   gtk_entry_set_text (GTK_ENTRY (priv->preview),
614                       pango_language_get_sample_string (NULL));
615
616   /* Set search icon and place holder text */
617   icon = g_themed_icon_new_with_default_fallbacks ("edit-find-symbolic");
618   g_object_set (G_OBJECT (priv->search_entry),
619                 "secondary-icon-gicon", icon,
620                 "secondary-icon-activatable", FALSE,
621                 "secondary-icon-sensitive", FALSE,
622                 NULL);
623   g_object_unref (icon);
624
625   gtk_entry_set_placeholder_text (GTK_ENTRY (priv->search_entry), _("Search font name"));
626
627   /** Callback connections **/
628   g_signal_connect (priv->search_entry, "notify::text",
629                     G_CALLBACK (text_changed_cb), fontchooser);
630   g_signal_connect (priv->search_entry,
631                     "icon-press", G_CALLBACK (icon_press_cb), NULL);
632
633   g_signal_connect (gtk_range_get_adjustment (GTK_RANGE (priv->size_slider)),
634                     "value-changed", G_CALLBACK (slider_change_cb), fontchooser);
635   g_signal_connect (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin)),
636                     "value-changed", G_CALLBACK (spin_change_cb), fontchooser);
637
638   priv->cursor_changed_handler =
639       g_signal_connect (priv->family_face_list, "cursor-changed",
640                         G_CALLBACK (cursor_changed_cb), fontchooser);
641
642   /* Zoom on preview scroll*/
643   g_signal_connect (priv->preview, "scroll-event",
644                     G_CALLBACK (zoom_preview_cb), fontchooser);
645
646   g_signal_connect (priv->size_slider, "scroll-event",
647                     G_CALLBACK (zoom_preview_cb), fontchooser);
648
649   set_range_marks (priv, priv->size_slider, (gint*)font_sizes, G_N_ELEMENTS (font_sizes));
650
651   /* Font list empty hides the scrolledwindow */
652   g_signal_connect (G_OBJECT (priv->filter_model), "row-deleted",
653                     G_CALLBACK (row_deleted_cb), fontchooser);
654   g_signal_connect (G_OBJECT (priv->filter_model), "row-inserted",
655                     G_CALLBACK (row_inserted_cb), fontchooser);
656
657   /* Set default focus */
658   gtk_widget_pop_composite_child ();
659 }
660
661 /**
662  * gtk_font_chooser_new:
663  *
664  * Creates a new #GtkFontChooser.
665  *
666  * Return value: a new #GtkFontChooser
667  *
668  * Since: 3.2
669  */
670 GtkWidget *
671 gtk_font_chooser_new (void)
672 {
673   GtkFontChooser *fontchooser;
674
675   fontchooser = g_object_new (GTK_TYPE_FONT_CHOOSER, NULL);
676
677   return GTK_WIDGET (fontchooser);
678 }
679
680 static int
681 cmp_families (const void *a,
682               const void *b)
683 {
684   const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a);
685   const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b);
686
687   return g_utf8_collate (a_name, b_name);
688 }
689
690 static void
691 populate_list (GtkFontChooser *fontchooser,
692                GtkTreeView    *treeview,
693                GtkListStore   *model)
694 {
695   GtkFontChooserPrivate *priv = fontchooser->priv;
696   GtkStyleContext      *style_context;
697   PangoFontDescription *default_font;
698   PangoFontDescription *selected_font;
699
700   gint match;
701   GtkTreeIter   match_row;
702   GtkTreePath  *path;
703
704   gint n_families, i;
705   PangoFontFamily **families;
706   GString     *tmp;
707   GString     *family_and_face;
708
709   if (!gtk_widget_has_screen (GTK_WIDGET (fontchooser)))
710     return;
711
712   tmp = g_string_new (NULL);
713   family_and_face = g_string_new (NULL);
714
715   pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (treeview)),
716                                &families,
717                                &n_families);
718
719   qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families);
720
721   /* Get theme font */
722   style_context = gtk_widget_get_style_context (GTK_WIDGET (treeview));
723   default_font = (PangoFontDescription*) gtk_style_context_get_font (style_context,
724                                                                      GTK_STATE_NORMAL);
725
726   if (priv->face)
727     selected_font = pango_font_face_describe (priv->face);
728   else
729     selected_font = NULL;
730
731   gtk_list_store_clear (model);
732
733   match = 0;
734
735   /* Iterate over families and faces */
736   for (i = 0; i < n_families; i++)
737     {
738       GtkTreeIter     iter;
739       PangoFontFace **faces;
740       int             j, n_faces;
741       const gchar    *fam_name = pango_font_family_get_name (families[i]);
742
743       pango_font_family_list_faces (families[i], &faces, &n_faces);
744
745       for (j = 0; j < n_faces; j++)
746         {
747           PangoFontDescription *pango_desc;
748           const gchar *face_name;
749           gchar *font_desc;
750
751           if (priv->filter_func != NULL &&
752               !priv->filter_func (families[i], faces[j], priv->filter_data))
753             continue;
754
755           pango_desc = pango_font_face_describe (faces[j]);
756           face_name = pango_font_face_get_face_name (faces[j]);
757           font_desc = pango_font_description_to_string (pango_desc);
758
759           g_string_printf (family_and_face, "%s %s", fam_name, face_name);
760           g_string_printf (tmp, ROW_FORMAT_STRING,
761                            family_and_face->str,
762                            font_desc,
763                            fontchooser->priv->preview_text);
764
765           gtk_list_store_append (model, &iter);
766           gtk_list_store_set (model, &iter,
767                               FAMILY_COLUMN, families[i],
768                               FACE_COLUMN, faces[j],
769                               PREVIEW_TITLE_COLUMN, family_and_face->str,
770                               PREVIEW_TEXT_COLUMN, tmp->str,
771                               -1);
772
773           /* Select the current font,
774            * the default font/face from the theme,
775            * or the first font
776            */
777           if (match < 3 &&
778               selected_font != NULL &&
779               pango_font_description_equal (selected_font, pango_desc))
780             {
781               match_row = iter;
782               match = 3;
783             }
784           if (match < 2 &&
785               strcmp (fam_name, pango_font_description_get_family (default_font)) == 0)
786             {
787               match_row = iter;
788               match = 2;
789             }
790           if (match < 1)
791             {
792               match_row = iter;
793               match = 1;
794             }
795
796           pango_font_description_free (pango_desc);
797           g_free (font_desc);
798         }
799
800       g_free (faces);
801     }
802
803   path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &match_row);
804   if (path)
805     {
806       gtk_tree_view_set_cursor (treeview, path, NULL, FALSE);
807       gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0.5, 0.5);
808       gtk_tree_path_free (path);
809     }
810
811   if (selected_font)
812     pango_font_description_free (selected_font);
813
814   g_string_free (family_and_face, TRUE);
815   g_string_free (tmp, TRUE);
816   g_free (families);
817 }
818
819 static gboolean
820 visible_func (GtkTreeModel *model,
821               GtkTreeIter  *iter,
822               gpointer      user_data)
823 {
824   gboolean result = TRUE;
825   GtkFontChooserPrivate *priv = (GtkFontChooserPrivate*)user_data;
826
827   const gchar *search_text = (const gchar*)gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
828   gchar       *font_name;
829   gchar       *term;
830   gchar      **split_terms;
831   gint         n_terms = 0;
832
833   /* If there's no filter string we show the item */
834   if (strlen (search_text) == 0)
835     return TRUE;
836
837   gtk_tree_model_get (model, iter,
838                       PREVIEW_TITLE_COLUMN, &font_name,
839                       -1);
840
841   if (font_name == NULL)
842     return FALSE;
843
844   split_terms = g_strsplit (search_text, " ", 0);
845   term = split_terms[0];
846
847   while (term && result)
848   {
849     gchar* font_name_casefold = g_utf8_casefold (font_name, -1);
850     gchar* term_casefold = g_utf8_casefold (term, -1);
851
852     if (g_strrstr (font_name_casefold, term_casefold))
853       result = result && TRUE;
854     else
855       result = FALSE;
856
857     n_terms++;
858     term = split_terms[n_terms];
859
860     g_free (term_casefold);
861     g_free (font_name_casefold);
862   }
863
864   g_free (font_name);
865   g_strfreev (split_terms);
866
867   return result;
868 }
869
870 static void
871 gtk_font_chooser_bootstrap_fontlist (GtkFontChooser *fontchooser)
872 {
873   GtkFontChooserPrivate *priv = fontchooser->priv;
874   GtkTreeView       *treeview = GTK_TREE_VIEW (priv->family_face_list);
875   GtkCellRenderer   *cell;
876   GtkTreeViewColumn *col;
877
878   priv->model = gtk_list_store_new (4,
879                                     PANGO_TYPE_FONT_FAMILY,
880                                     PANGO_TYPE_FONT_FACE,
881                                     G_TYPE_STRING,
882                                     G_TYPE_STRING);
883
884   priv->filter_model = gtk_tree_model_filter_new (GTK_TREE_MODEL (priv->model), NULL);
885   g_object_unref (priv->model);
886
887   gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (priv->filter_model),
888                                           visible_func, (gpointer)priv, NULL);
889
890   gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (priv->filter_model));
891   g_object_unref (priv->filter_model);
892
893   gtk_tree_view_set_rules_hint      (treeview, TRUE);
894   gtk_tree_view_set_headers_visible (treeview, FALSE);
895
896   cell = gtk_cell_renderer_text_new ();
897   col = gtk_tree_view_column_new_with_attributes ("Family",
898                                                   cell,
899                                                   "markup", PREVIEW_TEXT_COLUMN,
900                                                   NULL);
901
902   g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
903
904   gtk_tree_view_append_column (treeview, col);
905
906   populate_list (fontchooser, treeview, priv->model);
907 }
908
909 static void
910 gtk_font_chooser_dispose (GObject *object)
911 {
912   GtkFontChooser *fontchooser = GTK_FONT_CHOOSER (object);
913   GtkFontChooserPrivate *priv = fontchooser->priv;
914
915   if (priv->cursor_changed_handler != 0)
916     {
917       g_signal_handler_disconnect (priv->family_face_list,
918                                    priv->cursor_changed_handler);
919       priv->cursor_changed_handler = 0;
920     }
921
922   G_OBJECT_CLASS (gtk_font_chooser_parent_class)->dispose (object);
923 }
924
925 static void
926 gtk_font_chooser_finalize (GObject *object)
927 {
928   GtkFontChooser *fontchooser = GTK_FONT_CHOOSER (object);
929   GtkFontChooserPrivate *priv = fontchooser->priv;
930
931   if (priv->family)
932     g_object_unref (priv->family);
933
934   if (priv->face)
935     g_object_unref (priv->face);
936
937   if (priv->filter_data_destroy)
938     priv->filter_data_destroy (priv->filter_data);
939
940   G_OBJECT_CLASS (gtk_font_chooser_parent_class)->finalize (object);
941 }
942
943 static void
944 gtk_font_chooser_screen_changed (GtkWidget *widget,
945                                  GdkScreen *previous_screen)
946 {
947   GtkFontChooser *fontchooser = GTK_FONT_CHOOSER (widget);
948
949   populate_list (fontchooser,
950                  GTK_TREE_VIEW (fontchooser->priv->family_face_list),
951                  fontchooser->priv->model);
952 }
953
954 static void
955 gtk_font_chooser_style_updated (GtkWidget *widget)
956 {
957   GtkFontChooser *fontchooser = GTK_FONT_CHOOSER (widget);
958
959   GTK_WIDGET_CLASS (gtk_font_chooser_parent_class)->style_updated (widget);
960
961   populate_list (fontchooser,
962                  GTK_TREE_VIEW (fontchooser->priv->family_face_list),
963                  fontchooser->priv->model);
964 }
965
966 /**
967  * gtk_font_chooser_get_family:
968  * @fontchooser: a #GtkFontChooser
969  *
970  * Gets the #PangoFontFamily representing the selected font family.
971  * Font families are a collection of font faces.
972  *
973  * Return value: (transfer none): A #PangoFontFamily representing the
974  *     selected font family. The returned object is owned by @fontchooser
975  *     and must not be modified or freed.
976  *
977  * Since: 3.2
978  */
979 PangoFontFamily *
980 gtk_font_chooser_get_family (GtkFontChooser *fontchooser)
981 {
982   g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL);
983
984   return fontchooser->priv->family;
985 }
986
987 /**
988  * gtk_font_chooser_get_face:
989  * @fontchooser: a #GtkFontChooser
990  *
991  * Gets the #PangoFontFace representing the selected font group
992  * details (i.e. family, slant, weight, width, etc).
993  *
994  * Return value: (transfer none): A #PangoFontFace representing the
995  *     selected font group details. The returned object is owned by
996  *     @fontchooser and must not be modified or freed.
997  *
998  * Since: 3.2
999  */
1000 PangoFontFace *
1001 gtk_font_chooser_get_face (GtkFontChooser *fontchooser)
1002 {
1003   g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL);
1004
1005   return fontchooser->priv->face;
1006 }
1007
1008 /**
1009  * gtk_font_chooser_get_size:
1010  * @fontchooser: a #GtkFontChooser
1011  *
1012  * The selected font size.
1013  *
1014  * Return value: A n integer representing the selected font size,
1015  *     or -1 if no font size is selected.
1016  *
1017  * Since: 3.2
1018  */
1019 gint
1020 gtk_font_chooser_get_size (GtkFontChooser *fontchooser)
1021 {
1022   g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), -1);
1023
1024   return fontchooser->priv->size;
1025 }
1026
1027 /**
1028  * gtk_font_chooser_get_font_name:
1029  * @fontchooser: a #GtkFontChooser
1030  *
1031  * Gets the currently-selected font name.
1032  *
1033  * Note that this can be a different string than what you set with
1034  * gtk_font_chooser_set_font_name(), as the font chooser widget may
1035  * normalize font names and thus return a string with a different
1036  * structure. For example, "Helvetica Italic Bold 12" could be
1037  * normalized to "Helvetica Bold Italic 12".
1038  *
1039  * Use pango_font_description_equal() if you want to compare two
1040  * font descriptions.
1041  *
1042  * Return value: (transfer full) (allow-none): A string with the name
1043  *     of the current font, or %NULL if  no font is selected. You must
1044  *     free this string with g_free().
1045  *
1046  * Since: 3.2
1047  */
1048 gchar *
1049 gtk_font_chooser_get_font_name (GtkFontChooser *fontchooser)
1050 {
1051   gchar                *font_name;
1052   gchar                *font_desc_name;
1053   PangoFontDescription *desc;
1054
1055   if (!fontchooser->priv->face)
1056     return NULL;
1057
1058   desc = pango_font_face_describe (fontchooser->priv->face);
1059   font_desc_name = pango_font_description_to_string (desc);
1060   pango_font_description_free (desc);
1061
1062   font_name = g_strdup_printf ("%s %d", font_desc_name, fontchooser->priv->size / PANGO_SCALE);
1063   g_free (font_desc_name);
1064   return font_name;
1065 }
1066
1067 /**
1068  * gtk_font_chooser_set_font_name:
1069  * @fontchooser: a #GtkFontChooser
1070  * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
1071  *
1072  * Sets the currently-selected font.
1073  *
1074  * Note that the @fontchooser needs to know the screen in which
1075  * it will appear for this to work; this can be guaranteed by simply
1076  * making sure that the @fontchooser is inserted in a toplevel window
1077  * before you call this function.
1078  *
1079  * Return value: %TRUE if the font could be set successfully; %FALSE
1080  *     if no such font exists or if the @fontchooser doesn't belong
1081  *     to a particular screen yet.
1082  *
1083  * Since: 3.2
1084  */
1085 gboolean
1086 gtk_font_chooser_set_font_name (GtkFontChooser *fontchooser,
1087                                 const gchar    *fontname)
1088 {
1089   GtkFontChooserPrivate *priv = fontchooser->priv;
1090   GtkTreeIter           iter;
1091   gboolean              valid;
1092   gchar                *family_name;
1093   PangoFontDescription *desc;
1094   gboolean              found = FALSE;
1095
1096   g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), FALSE);
1097   g_return_val_if_fail (fontname != NULL, FALSE);
1098
1099   if (!gtk_widget_has_screen (GTK_WIDGET (fontchooser)))
1100     return FALSE;
1101
1102   desc = pango_font_description_from_string (fontname);
1103   family_name = (gchar*)pango_font_description_get_family (desc);
1104
1105   if (!family_name)
1106     {
1107       pango_font_description_free (desc);
1108       return FALSE;
1109     }
1110
1111   /* We make sure the filter is clear */
1112   gtk_entry_set_text (GTK_ENTRY (priv->search_entry), "");
1113
1114   /* We find the matching family/face */
1115   for (valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->filter_model), &iter);
1116        valid;
1117        valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->filter_model), &iter))
1118     {
1119       PangoFontFace        *face;
1120       PangoFontDescription *tmp_desc;
1121
1122       gtk_tree_model_get (GTK_TREE_MODEL (priv->filter_model), &iter,
1123                           FACE_COLUMN, &face,
1124                           -1);
1125
1126       tmp_desc = pango_font_face_describe (face);
1127       if (pango_font_description_get_size_is_absolute (desc))
1128         pango_font_description_set_absolute_size (tmp_desc,
1129                                                   pango_font_description_get_size (desc));
1130       else
1131         pango_font_description_set_size (tmp_desc,
1132                                          pango_font_description_get_size (desc));
1133
1134       if (pango_font_description_equal (desc, tmp_desc))
1135         {
1136           GtkTreePath *path;
1137           gint size = pango_font_description_get_size (desc);
1138
1139           if (size)
1140             {
1141               if (pango_font_description_get_size_is_absolute (desc))
1142                 size = size * PANGO_SCALE;
1143               gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->size_spin),
1144                                          size / PANGO_SCALE);
1145             }
1146
1147           path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->filter_model), &iter);
1148
1149           if (path)
1150             {
1151               gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->family_face_list),
1152                                         path,
1153                                         NULL,
1154                                         FALSE);
1155               gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->family_face_list),
1156                                             path,
1157                                             NULL,
1158                                             FALSE,
1159                                             0.5,
1160                                             0.5);
1161               gtk_tree_path_free (path);
1162             }
1163
1164           found = TRUE;
1165         }
1166
1167       g_object_unref (face);
1168       pango_font_description_free (tmp_desc);
1169
1170       if (found)
1171         break;
1172     }
1173
1174   pango_font_description_free (desc);
1175   g_object_notify (G_OBJECT (fontchooser), "font-name");
1176
1177   return found;
1178 }
1179
1180 /**
1181  * gtk_font_chooser_get_preview_text:
1182  * @fontchooser: a #GtkFontChooser
1183  *
1184  * Gets the text displayed in the preview area.
1185  *
1186  * Return value: (transfer none): the text displayed in the
1187  *     preview area. This string is owned by the widget and
1188  *     should not be modified or freed
1189  *
1190  * Since: 3.2
1191  */
1192 const gchar*
1193 gtk_font_chooser_get_preview_text (GtkFontChooser *fontchooser)
1194 {
1195   g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL);
1196
1197   return (const gchar*)fontchooser->priv->preview_text;
1198 }
1199
1200
1201 /**
1202  * gtk_font_chooser_set_preview_text:
1203  * @fontchooser: a #GtkFontChooser
1204  * @text: (transfer none): the text to display in the preview area
1205  *
1206  * Sets the text displayed in the preview area.
1207  * The @text is used to show how the selected font looks.
1208  *
1209  * Since: 3.2
1210  */
1211 void
1212 gtk_font_chooser_set_preview_text (GtkFontChooser *fontchooser,
1213                                    const gchar    *text)
1214 {
1215   g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser));
1216   g_return_if_fail (text != NULL);
1217
1218   g_free (fontchooser->priv->preview_text);
1219   fontchooser->priv->preview_text = g_strdup (text);
1220
1221   populate_list (fontchooser,
1222                  GTK_TREE_VIEW (fontchooser->priv->family_face_list),
1223                  fontchooser->priv->model);
1224
1225   gtk_entry_set_text (GTK_ENTRY (fontchooser->priv->preview), text);
1226
1227   g_object_notify (G_OBJECT (fontchooser), "preview-text");
1228 }
1229
1230 /**
1231  * gtk_font_chooser_get_show_preview_entry:
1232  * @fontchooser: a #GtkFontChooser
1233  *
1234  * Returns whether the preview entry is shown or not.
1235  *
1236  * Return value: %TRUE if the preview entry is shown
1237  *     or %FALSE if it is hidden.
1238  *
1239  * Since: 3.2
1240  */
1241 gboolean
1242 gtk_font_chooser_get_show_preview_entry (GtkFontChooser *fontchooser)
1243 {
1244   g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), FALSE);
1245
1246   return fontchooser->priv->show_preview_entry;
1247 }
1248
1249 /**
1250  * gtk_font_chooser_set_show_preview_entry:
1251  * @fontchooser: a #GtkFontChooser
1252  * @show_preview_entry: whether to show the editable preview entry or not
1253  *
1254  * Shows or hides the editable preview entry.
1255  *
1256  * Since: 3.2
1257  */
1258 void
1259 gtk_font_chooser_set_show_preview_entry (GtkFontChooser *fontchooser,
1260                                          gboolean        show_preview_entry)
1261 {
1262   GtkFontChooserPrivate *priv = fontchooser->priv;
1263
1264   g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser));
1265
1266   if (priv->show_preview_entry != show_preview_entry)
1267     {
1268       fontchooser->priv->show_preview_entry = show_preview_entry;
1269
1270       if (show_preview_entry)
1271         gtk_widget_show (fontchooser->priv->preview);
1272       else
1273         gtk_widget_hide (fontchooser->priv->preview);
1274
1275       g_object_notify (G_OBJECT (fontchooser), "show-preview-entry");
1276     }
1277 }
1278
1279 /**
1280  * gtk_font_chooser_set_filter_func:
1281  * @fontchooser: a #GtkFontChooser
1282  * @filter: (allow-none): a #GtkFontFilterFunc, or %NULL
1283  * @data: data to pass to @filter
1284  * @destroy: function to call to free @data when it is no longer needed
1285  *
1286  * Adds a filter function that decides which fonts to display
1287  * in the font chooser.
1288  *
1289  * Since: 3.2
1290  */
1291 void
1292 gtk_font_chooser_set_filter_func (GtkFontChooser   *fontchooser,
1293                                   GtkFontFilterFunc filter,
1294                                   gpointer          data,
1295                                   GDestroyNotify    destroy)
1296 {
1297   GtkFontChooserPrivate *priv = fontchooser->priv;
1298
1299   g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser));
1300
1301   if (priv->filter_data_destroy)
1302     priv->filter_data_destroy (priv->filter_data);
1303
1304   priv->filter_func = filter;
1305   priv->filter_data = data;
1306   priv->filter_data_destroy = destroy;
1307
1308   populate_list (fontchooser,
1309                  GTK_TREE_VIEW (priv->family_face_list),
1310                  priv->model);
1311 }