]> Pileus Git - ~andy/gtk/blob - gtk/gtkfontchooserwidget.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / gtkfontchooserwidget.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, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include "config.h"
19
20 #include <stdlib.h>
21 #include <glib/gprintf.h>
22 #include <string.h>
23
24 #include <atk/atk.h>
25
26 #include "gtkfontchooserwidget.h"
27
28 #include "gtkadjustment.h"
29 #include "gtkbuildable.h"
30 #include "gtkbox.h"
31 #include "gtkcellrenderertext.h"
32 #include "gtkentry.h"
33 #include "gtksearchentry.h"
34 #include "gtkgrid.h"
35 #include "gtkfontchooser.h"
36 #include "gtkfontchooserutils.h"
37 #include "gtkintl.h"
38 #include "gtklabel.h"
39 #include "gtkliststore.h"
40 #include "gtknotebook.h"
41 #include "gtkprivate.h"
42 #include "gtkscale.h"
43 #include "gtkscrolledwindow.h"
44 #include "gtkspinbutton.h"
45 #include "gtktextview.h"
46 #include "gtktreeselection.h"
47 #include "gtktreeview.h"
48 #include "gtkwidget.h"
49
50 /**
51  * SECTION:gtkfontchooserwidget
52  * @Short_description: A widget for selecting fonts
53  * @Title: GtkFontChooserWidget
54  * @See_also: #GtkFontChooserDialog
55  *
56  * The #GtkFontChooserWidget widget lists the available fonts,
57  * styles and sizes, allowing the user to select a font. It is
58  * used in the #GtkFontChooserDialog widget to provide a
59  * dialog box for selecting fonts.
60  *
61  * To set the font which is initially selected, use
62  * gtk_font_chooser_set_font() or gtk_font_chooser_set_font_desc().
63  *
64  * To get the selected font use gtk_font_chooser_get_font() or
65  * gtk_font_chooser_get_font_desc().
66  *
67  * To change the text which is shown in the preview area, use
68  * gtk_font_chooser_set_preview_text().
69  *
70  * Since: 3.2
71  */
72
73
74 struct _GtkFontChooserWidgetPrivate
75 {
76   GtkWidget    *search_entry;
77   GtkWidget    *family_face_list;
78   GtkCellRenderer *family_face_cell;
79   GtkWidget    *list_scrolled_window;
80   GtkWidget    *empty_list;
81   GtkWidget    *list_notebook;
82   GtkTreeModel *model;
83   GtkTreeModel *filter_model;
84
85   GtkWidget       *preview;
86   gchar           *preview_text;
87   gboolean         show_preview_entry;
88
89   GtkWidget *size_spin;
90   GtkWidget *size_slider;
91
92   PangoFontDescription *font_desc;
93   GtkTreeIter           font_iter;      /* invalid if font not available or pointer into model
94                                            (not filter_model) to the row containing font */
95   GtkFontFilterFunc filter_func;
96   gpointer          filter_data;
97   GDestroyNotify    filter_data_destroy;
98 };
99
100 /* This is the initial fixed height and the top padding of the preview entry */
101 #define PREVIEW_HEIGHT 72
102 #define PREVIEW_TOP_PADDING 6
103
104 /* These are the sizes of the font, style & size lists. */
105 #define FONT_LIST_HEIGHT  136
106 #define FONT_LIST_WIDTH   190
107 #define FONT_STYLE_LIST_WIDTH 170
108 #define FONT_SIZE_LIST_WIDTH  60
109
110 #define NO_FONT_MATCHED_SEARCH N_("No fonts matched your search. You can revise your search and try again.")
111
112 enum {
113   FAMILY_COLUMN,
114   FACE_COLUMN,
115   FONT_DESC_COLUMN,
116   PREVIEW_TITLE_COLUMN
117 };
118
119 static void gtk_font_chooser_widget_set_property         (GObject         *object,
120                                                           guint            prop_id,
121                                                           const GValue    *value,
122                                                           GParamSpec      *pspec);
123 static void gtk_font_chooser_widget_get_property         (GObject         *object,
124                                                           guint            prop_id,
125                                                           GValue          *value,
126                                                           GParamSpec      *pspec);
127 static void gtk_font_chooser_widget_finalize             (GObject         *object);
128
129 static void gtk_font_chooser_widget_screen_changed       (GtkWidget       *widget,
130                                                           GdkScreen       *previous_screen);
131
132 static void gtk_font_chooser_widget_bootstrap_fontlist   (GtkFontChooserWidget *fontchooser);
133
134 static gboolean gtk_font_chooser_widget_find_font        (GtkFontChooserWidget *fontchooser,
135                                                           const PangoFontDescription *font_desc,
136                                                           GtkTreeIter          *iter);
137 static void     gtk_font_chooser_widget_ensure_selection (GtkFontChooserWidget *fontchooser);
138
139 static gchar   *gtk_font_chooser_widget_get_font         (GtkFontChooserWidget *fontchooser);
140 static void     gtk_font_chooser_widget_set_font         (GtkFontChooserWidget *fontchooser,
141                                                           const gchar          *fontname);
142
143 static PangoFontDescription *gtk_font_chooser_widget_get_font_desc  (GtkFontChooserWidget *fontchooser);
144 static void                  gtk_font_chooser_widget_merge_font_desc(GtkFontChooserWidget *fontchooser,
145                                                                      PangoFontDescription *font_desc,
146                                                                      GtkTreeIter          *iter);
147 static void                  gtk_font_chooser_widget_take_font_desc (GtkFontChooserWidget *fontchooser,
148                                                                      PangoFontDescription *font_desc);
149
150
151 static const gchar *gtk_font_chooser_widget_get_preview_text (GtkFontChooserWidget *fontchooser);
152 static void         gtk_font_chooser_widget_set_preview_text (GtkFontChooserWidget *fontchooser,
153                                                               const gchar          *text);
154
155 static gboolean gtk_font_chooser_widget_get_show_preview_entry (GtkFontChooserWidget *fontchooser);
156 static void     gtk_font_chooser_widget_set_show_preview_entry (GtkFontChooserWidget *fontchooser,
157                                                                 gboolean              show_preview_entry);
158
159 static void gtk_font_chooser_widget_iface_init (GtkFontChooserIface *iface);
160
161 G_DEFINE_TYPE_WITH_CODE (GtkFontChooserWidget, gtk_font_chooser_widget, GTK_TYPE_BOX,
162                          G_IMPLEMENT_INTERFACE (GTK_TYPE_FONT_CHOOSER,
163                                                 gtk_font_chooser_widget_iface_init))
164
165 static void
166 gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
167 {
168   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
169   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
170
171   widget_class->screen_changed = gtk_font_chooser_widget_screen_changed;
172
173   gobject_class->finalize = gtk_font_chooser_widget_finalize;
174   gobject_class->set_property = gtk_font_chooser_widget_set_property;
175   gobject_class->get_property = gtk_font_chooser_widget_get_property;
176
177   _gtk_font_chooser_install_properties (gobject_class);
178
179   g_type_class_add_private (klass, sizeof (GtkFontChooserWidgetPrivate));
180 }
181
182 static void
183 gtk_font_chooser_widget_set_property (GObject         *object,
184                                       guint            prop_id,
185                                       const GValue    *value,
186                                       GParamSpec      *pspec)
187 {
188   GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (object);
189
190   switch (prop_id)
191     {
192     case GTK_FONT_CHOOSER_PROP_FONT:
193       gtk_font_chooser_widget_set_font (fontchooser, g_value_get_string (value));
194       break;
195     case GTK_FONT_CHOOSER_PROP_FONT_DESC:
196       gtk_font_chooser_widget_take_font_desc (fontchooser, g_value_dup_boxed (value));
197       break;
198     case GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT:
199       gtk_font_chooser_widget_set_preview_text (fontchooser, g_value_get_string (value));
200       break;
201     case GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY:
202       gtk_font_chooser_widget_set_show_preview_entry (fontchooser, g_value_get_boolean (value));
203       break;
204     default:
205       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
206       break;
207     }
208 }
209
210 static void
211 gtk_font_chooser_widget_get_property (GObject         *object,
212                                       guint            prop_id,
213                                       GValue          *value,
214                                       GParamSpec      *pspec)
215 {
216   GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (object);
217
218   switch (prop_id)
219     {
220     case GTK_FONT_CHOOSER_PROP_FONT:
221       g_value_take_string (value, gtk_font_chooser_widget_get_font (fontchooser));
222       break;
223     case GTK_FONT_CHOOSER_PROP_FONT_DESC:
224       g_value_set_boxed (value, gtk_font_chooser_widget_get_font_desc (fontchooser));
225       break;
226     case GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT:
227       g_value_set_string (value, gtk_font_chooser_widget_get_preview_text (fontchooser));
228       break;
229     case GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY:
230       g_value_set_boolean (value, gtk_font_chooser_widget_get_show_preview_entry (fontchooser));
231       break;
232     default:
233       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
234       break;
235     }
236 }
237
238 static void
239 gtk_font_chooser_widget_refilter_font_list (GtkFontChooserWidget *fontchooser)
240 {
241   gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (fontchooser->priv->filter_model));
242   gtk_font_chooser_widget_ensure_selection (fontchooser);
243 }
244
245 static void
246 text_changed_cb (GtkEntry             *entry,
247                  GParamSpec           *pspec,
248                  GtkFontChooserWidget *fc)
249 {
250   gtk_font_chooser_widget_refilter_font_list (fc);
251 }
252
253 static void
254 size_change_cb (GtkAdjustment *adjustment,
255                 gpointer       user_data)
256 {
257   GtkFontChooserWidget *fontchooser = user_data;
258   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
259   PangoFontDescription *font_desc;
260   gdouble size = gtk_adjustment_get_value (adjustment);
261
262   font_desc = pango_font_description_new ();
263   if (pango_font_description_get_size_is_absolute (priv->font_desc))
264     pango_font_description_set_absolute_size (font_desc, size * PANGO_SCALE);
265   else
266     pango_font_description_set_size (font_desc, size * PANGO_SCALE);
267
268   gtk_font_chooser_widget_take_font_desc (fontchooser, font_desc);
269 }
270
271 static void
272 gtk_font_chooser_widget_update_marks (GtkFontChooserWidget *fontchooser)
273 {
274   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
275   GtkAdjustment *adj;
276   const int *sizes;
277   gint *font_sizes;
278   gint i, n_sizes;
279
280   if (gtk_list_store_iter_is_valid (GTK_LIST_STORE (priv->model), &priv->font_iter))
281     {
282       PangoFontFace *face;
283
284       gtk_tree_model_get (priv->model, &priv->font_iter,
285                           FACE_COLUMN, &face,
286                           -1);
287
288       pango_font_face_list_sizes (face, &font_sizes, &n_sizes);
289
290       /* It seems not many fonts actually have a sane set of sizes */
291       for (i = 0; i < n_sizes; i++)
292         font_sizes[i] = font_sizes[i] / PANGO_SCALE;
293
294       g_object_unref (face);
295     }
296   else
297     {
298       font_sizes = NULL;
299       n_sizes = 0;
300     }
301
302   if (n_sizes < 2)
303     {
304       static const gint fallback_sizes[] = {
305         6, 8, 9, 10, 11, 12, 13, 14, 16, 20, 24, 36, 48, 72
306       };
307
308       sizes = fallback_sizes;
309       n_sizes = G_N_ELEMENTS (fallback_sizes);
310     }
311   else
312     {
313       sizes = font_sizes;
314     }
315
316   gtk_scale_clear_marks (GTK_SCALE (priv->size_slider));
317
318   adj = gtk_range_get_adjustment(GTK_RANGE (priv->size_slider));
319
320   /* ensure clamping doesn't callback into font resizing code */
321   g_signal_handlers_block_by_func (adj, size_change_cb, fontchooser);
322   gtk_adjustment_configure (adj,
323                             gtk_adjustment_get_value (adj),
324                             sizes[0],
325                             sizes[n_sizes - 1],
326                             gtk_adjustment_get_step_increment (adj),
327                             gtk_adjustment_get_page_increment (adj),
328                             gtk_adjustment_get_page_size (adj));
329   g_signal_handlers_unblock_by_func (adj, size_change_cb, fontchooser);
330
331   for (i = 0; i < n_sizes; i++)
332     {
333       gtk_scale_add_mark (GTK_SCALE (priv->size_slider),
334                           sizes[i],
335                           GTK_POS_BOTTOM, NULL);
336     }
337
338   g_free (font_sizes);
339 }
340
341 static void
342 row_activated_cb (GtkTreeView       *view,
343                   GtkTreePath       *path,
344                   GtkTreeViewColumn *column,
345                   gpointer           user_data)
346 {
347   GtkFontChooserWidget *fontchooser = user_data;
348   gchar *fontname;
349
350   fontname = gtk_font_chooser_widget_get_font (fontchooser);
351   _gtk_font_chooser_font_activated (GTK_FONT_CHOOSER (fontchooser), fontname);
352   g_free (fontname);
353 }
354
355 static PangoFontDescription *
356 tree_model_get_font_description (GtkTreeModel *model,
357                                  GtkTreeIter  *iter)
358 {
359   PangoFontDescription *desc;
360   PangoFontFace *face;
361   GtkTreeIter child_iter;
362
363   gtk_tree_model_get (model, iter,
364                       FONT_DESC_COLUMN, &desc,
365                       -1);
366   if (desc != NULL)
367     return desc;
368
369   gtk_tree_model_get (model, iter,
370                       FACE_COLUMN, &face,
371                       -1);
372   desc = pango_font_face_describe (face);
373   g_object_unref (face);
374   
375   if (GTK_IS_TREE_MODEL_FILTER (model))
376     {
377       gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model),
378                                                         &child_iter,
379                                                         iter);
380       iter = &child_iter;
381       model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
382     }
383
384   gtk_list_store_set (GTK_LIST_STORE (model), iter,
385                       FONT_DESC_COLUMN, desc,
386                       -1);
387
388   return desc;
389 }
390
391 static void
392 cursor_changed_cb (GtkTreeView *treeview,
393                    gpointer     user_data)
394 {
395   GtkFontChooserWidget *fontchooser = user_data;
396   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
397   PangoFontDescription *desc;
398   GtkTreeIter filter_iter, iter;
399   GtkTreePath *path = NULL;
400
401   gtk_tree_view_get_cursor (treeview, &path, NULL);
402
403   if (!path)
404     return;
405
406   if (!gtk_tree_model_get_iter (priv->filter_model, &filter_iter, path))
407     {
408       gtk_tree_path_free (path);
409       return;
410     }
411
412   gtk_tree_path_free (path);
413
414   gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (priv->filter_model),
415                                                     &iter,
416                                                     &filter_iter);
417   desc = tree_model_get_font_description (priv->model, &iter);
418
419   gtk_font_chooser_widget_merge_font_desc (fontchooser, desc, &iter);
420 }
421
422 static gboolean
423 zoom_preview_cb (GtkWidget      *scrolled_window,
424                  GdkEventScroll *event,
425                  gpointer        user_data)
426 {
427   GtkFontChooserWidget *fc = user_data;
428   GtkFontChooserWidgetPrivate *priv = fc->priv;
429   GtkAdjustment *adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin));
430
431   if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_RIGHT)
432     gtk_adjustment_set_value (adj,
433                               gtk_adjustment_get_value (adj) +
434                               gtk_adjustment_get_step_increment (adj));
435   else if (event->direction == GDK_SCROLL_DOWN || event->direction == GDK_SCROLL_LEFT)
436     gtk_adjustment_set_value (adj,
437                               gtk_adjustment_get_value (adj) -
438                               gtk_adjustment_get_step_increment (adj));
439   return TRUE;
440 }
441
442 static void
443 row_inserted_cb (GtkTreeModel *model,
444                  GtkTreePath  *path,
445                  GtkTreeIter  *iter,
446                  gpointer      user_data)
447 {
448   GtkFontChooserWidget *fontchooser = user_data;
449   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
450
451   gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->list_notebook), 0);
452 }
453
454 static void
455 row_deleted_cb  (GtkTreeModel *model,
456                  GtkTreePath  *path,
457                  gpointer      user_data)
458 {
459   GtkFontChooserWidget *fontchooser = user_data;
460   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
461
462   if (gtk_tree_model_iter_n_children (model, NULL) == 0)
463     gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->list_notebook), 1);
464 }
465
466 static void
467 gtk_font_chooser_widget_init (GtkFontChooserWidget *fontchooser)
468 {
469   GtkFontChooserWidgetPrivate *priv;
470   GtkWidget *scrolled_win;
471   GtkWidget *grid;
472
473   fontchooser->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontchooser,
474                                                    GTK_TYPE_FONT_CHOOSER_WIDGET,
475                                                    GtkFontChooserWidgetPrivate);
476
477   priv = fontchooser->priv;
478
479   /* Default preview string  */
480   priv->preview_text = g_strdup (pango_language_get_sample_string (NULL));
481   priv->show_preview_entry = TRUE;
482   priv->font_desc = pango_font_description_new ();
483
484   gtk_widget_push_composite_child ();
485
486   /* Creating fundamental widgets for the private struct */
487   priv->search_entry = gtk_search_entry_new ();
488   priv->family_face_list = gtk_tree_view_new ();
489   gtk_tree_view_set_enable_search (GTK_TREE_VIEW (priv->family_face_list), FALSE);
490   priv->preview = gtk_entry_new ();
491   priv->size_slider = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
492                                                 0.0,
493                                                 (gdouble)(G_MAXINT / PANGO_SCALE),
494                                                 1.0);
495
496   priv->size_spin = gtk_spin_button_new_with_range (0.0, (gdouble)(G_MAXINT / PANGO_SCALE), 1.0);
497
498   /** Bootstrapping widget layout **/
499   gtk_box_set_spacing (GTK_BOX (fontchooser), 6);
500
501   /* Main font family/face view */
502   priv->list_scrolled_window = gtk_scrolled_window_new (NULL, NULL);
503   scrolled_win = priv->list_scrolled_window;
504   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
505                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
506   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
507                                        GTK_SHADOW_ETCHED_IN);
508   gtk_widget_set_size_request (scrolled_win, 400, 300);
509   gtk_container_add (GTK_CONTAINER (scrolled_win), priv->family_face_list);
510
511   /* Text to display when list is empty */
512   priv->empty_list = gtk_label_new (_(NO_FONT_MATCHED_SEARCH));
513   gtk_widget_set_margin_top    (priv->empty_list, 12);
514   gtk_widget_set_margin_left   (priv->empty_list, 12);
515   gtk_widget_set_margin_right  (priv->empty_list, 12);
516   gtk_widget_set_margin_bottom (priv->empty_list, 12);
517   gtk_widget_set_halign (priv->empty_list, GTK_ALIGN_CENTER);
518   gtk_widget_set_valign (priv->empty_list, GTK_ALIGN_START);
519
520   priv->list_notebook = gtk_notebook_new ();
521   gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->list_notebook), FALSE);
522   gtk_notebook_append_page (GTK_NOTEBOOK (priv->list_notebook), scrolled_win, NULL);
523   gtk_notebook_append_page (GTK_NOTEBOOK (priv->list_notebook), priv->empty_list, NULL);
524
525   /* Basic layout */
526   grid = gtk_grid_new ();
527
528   gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
529   gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
530
531   gtk_grid_attach (GTK_GRID (grid), priv->search_entry, 0, 0, 2, 1);
532   gtk_grid_attach (GTK_GRID (grid), priv->list_notebook, 0, 1, 2, 1);
533   gtk_grid_attach (GTK_GRID (grid), priv->preview,      0, 2, 2, 1);
534
535   gtk_grid_attach (GTK_GRID (grid), priv->size_slider,  0, 3, 1, 1);
536   gtk_grid_attach (GTK_GRID (grid), priv->size_spin,    1, 3, 1, 1);
537
538   gtk_widget_set_hexpand  (GTK_WIDGET (scrolled_win),      TRUE);
539   gtk_widget_set_vexpand  (GTK_WIDGET (scrolled_win),      TRUE);
540   gtk_widget_set_hexpand  (GTK_WIDGET (priv->search_entry), TRUE);
541
542   gtk_widget_set_hexpand  (GTK_WIDGET (priv->size_slider), TRUE);
543   gtk_widget_set_hexpand  (GTK_WIDGET (priv->size_spin),   FALSE);
544
545   gtk_box_pack_start (GTK_BOX (fontchooser), grid, TRUE, TRUE, 0);
546
547   gtk_widget_show_all (GTK_WIDGET (fontchooser));
548   gtk_widget_hide     (GTK_WIDGET (fontchooser));
549
550   /* Treeview column and model bootstrapping */
551   gtk_font_chooser_widget_bootstrap_fontlist (fontchooser);
552
553   /* Set default preview text */
554   gtk_entry_set_text (GTK_ENTRY (priv->preview),
555                       pango_language_get_sample_string (NULL));
556
557   gtk_entry_set_placeholder_text (GTK_ENTRY (priv->search_entry), _("Search font name"));
558
559   /* Callback connections */
560   g_signal_connect (priv->search_entry, "notify::text",
561                     G_CALLBACK (text_changed_cb), fontchooser);
562
563   g_signal_connect (gtk_range_get_adjustment (GTK_RANGE (priv->size_slider)),
564                     "value-changed", G_CALLBACK (size_change_cb), fontchooser);
565   g_signal_connect (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin)),
566                     "value-changed", G_CALLBACK (size_change_cb), fontchooser);
567
568   g_signal_connect (priv->family_face_list, "cursor-changed",
569                     G_CALLBACK (cursor_changed_cb), fontchooser);
570   g_signal_connect (priv->family_face_list, "row-activated",
571                     G_CALLBACK (row_activated_cb), fontchooser);
572
573   /* Zoom on preview scroll */
574   g_signal_connect (priv->preview, "scroll-event",
575                     G_CALLBACK (zoom_preview_cb), fontchooser);
576
577   g_signal_connect (priv->size_slider, "scroll-event",
578                     G_CALLBACK (zoom_preview_cb), fontchooser);
579
580   /* Font list empty hides the scrolledwindow */
581   g_signal_connect (G_OBJECT (priv->filter_model), "row-deleted",
582                     G_CALLBACK (row_deleted_cb), fontchooser);
583   g_signal_connect (G_OBJECT (priv->filter_model), "row-inserted",
584                     G_CALLBACK (row_inserted_cb), fontchooser);
585
586   /* Set default focus */
587   gtk_widget_pop_composite_child ();
588
589   gtk_font_chooser_widget_take_font_desc (fontchooser, NULL);
590 }
591
592 /**
593  * gtk_font_chooser_widget_new:
594  *
595  * Creates a new #GtkFontChooserWidget.
596  *
597  * Return value: a new #GtkFontChooserWidget
598  *
599  * Since: 3.2
600  */
601 GtkWidget *
602 gtk_font_chooser_widget_new (void)
603 {
604   return g_object_new (GTK_TYPE_FONT_CHOOSER_WIDGET, NULL);
605 }
606
607 static int
608 cmp_families (const void *a,
609               const void *b)
610 {
611   const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a);
612   const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b);
613
614   return g_utf8_collate (a_name, b_name);
615 }
616
617 static void
618 gtk_font_chooser_widget_load_fonts (GtkFontChooserWidget *fontchooser)
619 {
620   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
621   GtkListStore *list_store;
622   gint n_families, i;
623   PangoFontFamily **families;
624   gchar *family_and_face;
625
626   list_store = GTK_LIST_STORE (priv->model);
627
628   pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (fontchooser)),
629                                &families,
630                                &n_families);
631
632   qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families);
633
634   gtk_list_store_clear (list_store);
635
636   /* Iterate over families and faces */
637   for (i = 0; i < n_families; i++)
638     {
639       GtkTreeIter     iter;
640       PangoFontFace **faces;
641       int             j, n_faces;
642       const gchar    *fam_name = pango_font_family_get_name (families[i]);
643
644       pango_font_family_list_faces (families[i], &faces, &n_faces);
645
646       for (j = 0; j < n_faces; j++)
647         {
648           const gchar *face_name;
649
650           face_name = pango_font_face_get_face_name (faces[j]);
651
652           family_and_face = g_strconcat (fam_name, " ", face_name, NULL);
653
654           gtk_list_store_insert_with_values (list_store, &iter, -1,
655                                              FAMILY_COLUMN, families[i],
656                                              FACE_COLUMN, faces[j],
657                                              PREVIEW_TITLE_COLUMN, family_and_face,
658                                              -1);
659
660           g_free (family_and_face);
661         }
662
663       g_free (faces);
664     }
665
666   g_free (families);
667
668   /* now make sure the font list looks right */
669   if (!gtk_font_chooser_widget_find_font (fontchooser,
670                                           priv->font_desc,
671                                           &priv->font_iter))
672     memset (&priv->font_iter, 0, sizeof (GtkTreeIter));
673
674   gtk_font_chooser_widget_ensure_selection (fontchooser);
675 }
676
677 static gboolean
678 visible_func (GtkTreeModel *model,
679               GtkTreeIter  *iter,
680               gpointer      user_data)
681 {
682   GtkFontChooserWidgetPrivate *priv = user_data;
683   gboolean result = TRUE;
684   const gchar *search_text;
685   gchar **split_terms;
686   gchar *font_name, *font_name_casefold;
687   guint i;
688
689   if (priv->filter_func != NULL)
690     {
691       PangoFontFamily *family;
692       PangoFontFace *face;
693
694       gtk_tree_model_get (model, iter,
695                           FAMILY_COLUMN, &family,
696                           FACE_COLUMN, &face,
697                           -1);
698
699       result = priv->filter_func (family, face, priv->filter_data);
700
701       g_object_unref (family);
702       g_object_unref (face);
703       
704       if (!result)
705         return FALSE;
706     }
707
708   /* If there's no filter string we show the item */
709   search_text = gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
710   if (strlen (search_text) == 0)
711     return TRUE;
712
713   gtk_tree_model_get (model, iter,
714                       PREVIEW_TITLE_COLUMN, &font_name,
715                       -1);
716
717   if (font_name == NULL)
718     return FALSE;
719
720   split_terms = g_strsplit (search_text, " ", 0);
721   font_name_casefold = g_utf8_casefold (font_name, -1);
722
723   for (i = 0; split_terms[i] && result; i++)
724     {
725       gchar* term_casefold = g_utf8_casefold (split_terms[i], -1);
726
727       if (!strstr (font_name_casefold, term_casefold))
728         result = FALSE;
729
730       g_free (term_casefold);
731     }
732
733   g_free (font_name_casefold);
734   g_free (font_name);
735   g_strfreev (split_terms);
736
737   return result;
738 }
739
740 /* in pango units */
741 static int
742 gtk_font_chooser_widget_get_preview_text_height (GtkFontChooserWidget *fontchooser)
743 {
744   GtkWidget *treeview = fontchooser->priv->family_face_list;
745   double dpi, font_size;
746
747   dpi = gdk_screen_get_resolution (gtk_widget_get_screen (treeview));
748   gtk_style_context_get (gtk_widget_get_style_context (treeview),
749                          gtk_widget_get_state_flags (treeview),
750                          "font-size", &font_size,
751                          NULL);
752
753   return (dpi < 0.0 ? 96.0 : dpi) / 72.0 * PANGO_SCALE_X_LARGE * font_size * PANGO_SCALE;
754 }
755
756 static PangoAttrList *
757 gtk_font_chooser_widget_get_preview_attributes (GtkFontChooserWidget       *fontchooser,
758                                                 const PangoFontDescription *font_desc,
759                                                 gsize                       first_line_len)
760 {
761   PangoAttribute *attribute;
762   PangoAttrList *attrs;
763
764   attrs = pango_attr_list_new ();
765
766   attribute = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
767   attribute->end_index = first_line_len;
768   pango_attr_list_insert (attrs, attribute);
769
770   attribute = pango_attr_scale_new (PANGO_SCALE_SMALL);
771   attribute->end_index = first_line_len;
772   pango_attr_list_insert (attrs, attribute);
773
774   if (font_desc)
775     {
776       attribute = pango_attr_font_desc_new (font_desc);
777       attribute->start_index = first_line_len;
778       pango_attr_list_insert (attrs, attribute);
779     }
780
781   attribute = pango_attr_fallback_new (FALSE);
782   attribute->start_index = first_line_len;
783   pango_attr_list_insert (attrs, attribute);
784
785   attribute = pango_attr_size_new_absolute (gtk_font_chooser_widget_get_preview_text_height (fontchooser));
786   attribute->start_index = first_line_len;
787   pango_attr_list_insert (attrs, attribute);
788
789   return attrs;
790 }
791
792 static void
793 gtk_font_chooser_widget_cell_data_func (GtkTreeViewColumn *column,
794                                         GtkCellRenderer   *cell,
795                                         GtkTreeModel      *tree_model,
796                                         GtkTreeIter       *iter,
797                                         gpointer           user_data)
798 {
799   GtkFontChooserWidget *fontchooser = user_data;
800   PangoFontDescription *font_desc;
801   PangoAttrList *attrs;
802   char *to_string, *text;
803   gsize first_line_len;
804
805   font_desc = tree_model_get_font_description (tree_model, iter);
806
807   to_string = pango_font_description_to_string (font_desc);
808
809   text = g_strconcat (to_string, "\n", fontchooser->priv->preview_text, NULL);
810   first_line_len = strlen (to_string) + 1;
811   
812   attrs = gtk_font_chooser_widget_get_preview_attributes (fontchooser, 
813                                                           font_desc,
814                                                           first_line_len);
815
816   g_object_set (cell,
817                 "attributes", attrs,
818                 "text", text,
819                 NULL);
820
821   pango_font_description_free (font_desc);
822   pango_attr_list_unref (attrs);
823   g_free (to_string);
824   g_free (text);
825 }
826
827 static void
828 gtk_font_chooser_widget_set_cell_size (GtkFontChooserWidget *fontchooser)
829 {
830   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
831   PangoAttrList *attrs;
832   GtkRequisition size;
833
834   gtk_cell_renderer_set_fixed_size (priv->family_face_cell, -1, -1);
835
836   attrs = gtk_font_chooser_widget_get_preview_attributes (fontchooser, 
837                                                           NULL,
838                                                           1);
839   
840   g_object_set (priv->family_face_cell,
841                 "attributes", attrs,
842                 "text", "x\nx",
843                 NULL);
844
845   pango_attr_list_unref (attrs);
846
847   gtk_cell_renderer_get_preferred_size (priv->family_face_cell,
848                                         priv->family_face_list,
849                                         &size,
850                                         NULL);
851   gtk_cell_renderer_set_fixed_size (priv->family_face_cell, size.width, size.height);
852 }
853
854 static void
855 gtk_font_chooser_widget_bootstrap_fontlist (GtkFontChooserWidget *fontchooser)
856 {
857   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
858   GtkTreeView *treeview = GTK_TREE_VIEW (priv->family_face_list);
859   GtkTreeViewColumn *col;
860
861   g_signal_connect_data (priv->family_face_list,
862                          "style-updated",
863                          G_CALLBACK (gtk_font_chooser_widget_set_cell_size),
864                          fontchooser,
865                          NULL,
866                          G_CONNECT_AFTER | G_CONNECT_SWAPPED);
867
868   priv->model = GTK_TREE_MODEL (gtk_list_store_new (4,
869                                                     PANGO_TYPE_FONT_FAMILY,
870                                                     PANGO_TYPE_FONT_FACE,
871                                                     PANGO_TYPE_FONT_DESCRIPTION,
872                                                     G_TYPE_STRING));
873
874   priv->filter_model = gtk_tree_model_filter_new (priv->model, NULL);
875   g_object_unref (priv->model);
876
877   gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (priv->filter_model),
878                                           visible_func, (gpointer)priv, NULL);
879
880   gtk_tree_view_set_model (treeview, priv->filter_model);
881   g_object_unref (priv->filter_model);
882
883   gtk_tree_view_set_rules_hint      (treeview, TRUE);
884   gtk_tree_view_set_headers_visible (treeview, FALSE);
885   gtk_tree_view_set_fixed_height_mode (treeview, TRUE);
886
887   priv->family_face_cell = gtk_cell_renderer_text_new ();
888   g_object_set (priv->family_face_cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
889
890   col = gtk_tree_view_column_new ();
891   gtk_tree_view_column_set_title (col, _("Font Family"));
892   gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
893   gtk_tree_view_column_pack_start (col, priv->family_face_cell, TRUE);
894   gtk_tree_view_column_set_cell_data_func (col,
895                                            priv->family_face_cell,
896                                            gtk_font_chooser_widget_cell_data_func,
897                                            fontchooser,
898                                            NULL);
899
900   gtk_tree_view_append_column (treeview, col);
901
902   gtk_font_chooser_widget_load_fonts (fontchooser);
903
904   gtk_font_chooser_widget_set_cell_size (fontchooser);
905 }
906
907 static void
908 gtk_font_chooser_widget_finalize (GObject *object)
909 {
910   GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (object);
911   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
912
913   if (priv->font_desc)
914     pango_font_description_free (priv->font_desc);
915
916   if (priv->filter_data_destroy)
917     priv->filter_data_destroy (priv->filter_data);
918
919   G_OBJECT_CLASS (gtk_font_chooser_widget_parent_class)->finalize (object);
920 }
921
922 static gboolean
923 my_pango_font_family_equal (const char *familya,
924                             const char *familyb)
925 {
926   return g_ascii_strcasecmp (familya, familyb) == 0;
927 }
928
929 static gboolean
930 gtk_font_chooser_widget_find_font (GtkFontChooserWidget        *fontchooser,
931                                    const PangoFontDescription  *font_desc,
932                                    /* out arguments */
933                                    GtkTreeIter                 *iter)
934 {
935   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
936   PangoFontDescription *desc;
937   PangoFontFamily *family;
938   gboolean valid;
939
940   if (pango_font_description_get_family (font_desc) == NULL)
941     return FALSE;
942
943   for (valid = gtk_tree_model_get_iter_first (priv->model, iter);
944        valid;
945        valid = gtk_tree_model_iter_next (priv->model, iter))
946     {
947       gtk_tree_model_get (priv->model, iter,
948                           FAMILY_COLUMN, &family,
949                           -1);
950
951       if (!my_pango_font_family_equal (pango_font_description_get_family (font_desc),
952                                        pango_font_family_get_name (family)))
953         continue;
954
955       desc = tree_model_get_font_description (priv->model, iter);
956
957       pango_font_description_merge_static (desc, font_desc, FALSE);
958       if (pango_font_description_equal (desc, font_desc))
959         break;
960
961       pango_font_description_free (desc);
962     }
963   
964   return valid;
965 }
966
967 static void
968 gtk_font_chooser_widget_screen_changed (GtkWidget *widget,
969                                         GdkScreen *previous_screen)
970 {
971   GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (widget);
972
973   if (GTK_WIDGET_CLASS (gtk_font_chooser_widget_parent_class)->screen_changed)
974     GTK_WIDGET_CLASS (gtk_font_chooser_widget_parent_class)->screen_changed (widget, previous_screen);
975
976   if (previous_screen == NULL)
977     previous_screen = gdk_screen_get_default ();
978
979   if (previous_screen == gtk_widget_get_screen (widget))
980     return;
981
982   gtk_font_chooser_widget_load_fonts (fontchooser);
983 }
984
985 static PangoFontFamily *
986 gtk_font_chooser_widget_get_family (GtkFontChooser *chooser)
987 {
988   GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (chooser);
989   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
990   PangoFontFamily *family;
991
992   if (!gtk_list_store_iter_is_valid (GTK_LIST_STORE (priv->model), &priv->font_iter))
993     return NULL;
994
995   gtk_tree_model_get (priv->model, &priv->font_iter,
996                       FAMILY_COLUMN, &family,
997                       -1);
998   g_object_unref (family);
999
1000   return family;
1001 }
1002
1003 static PangoFontFace *
1004 gtk_font_chooser_widget_get_face (GtkFontChooser *chooser)
1005 {
1006   GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (chooser);
1007   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
1008   PangoFontFace *face;
1009
1010   if (!gtk_list_store_iter_is_valid (GTK_LIST_STORE (priv->model), &priv->font_iter))
1011     return NULL;
1012
1013   gtk_tree_model_get (priv->model, &priv->font_iter,
1014                       FACE_COLUMN, &face,
1015                       -1);
1016   g_object_unref (face);
1017
1018   return face;
1019 }
1020
1021 static gint
1022 gtk_font_chooser_widget_get_size (GtkFontChooser *chooser)
1023 {
1024   GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (chooser);
1025
1026   return pango_font_description_get_size (fontchooser->priv->font_desc);
1027 }
1028
1029 static gchar *
1030 gtk_font_chooser_widget_get_font (GtkFontChooserWidget *fontchooser)
1031 {
1032   return pango_font_description_to_string (fontchooser->priv->font_desc);
1033 }
1034
1035 static PangoFontDescription *
1036 gtk_font_chooser_widget_get_font_desc (GtkFontChooserWidget *fontchooser)
1037 {
1038   return fontchooser->priv->font_desc;
1039 }
1040
1041 static void
1042 gtk_font_chooser_widget_set_font (GtkFontChooserWidget *fontchooser,
1043                                   const gchar          *fontname)
1044 {
1045   PangoFontDescription *font_desc;
1046
1047   font_desc = pango_font_description_from_string (fontname);
1048   gtk_font_chooser_widget_take_font_desc (fontchooser, font_desc);
1049 }
1050
1051 static void
1052 gtk_font_chooser_widget_ensure_selection (GtkFontChooserWidget *fontchooser)
1053 {
1054   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
1055   GtkTreeSelection *selection;
1056   GtkTreeIter filter_iter;
1057   
1058   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->family_face_list));
1059
1060   if (gtk_list_store_iter_is_valid (GTK_LIST_STORE (priv->model), &priv->font_iter) &&
1061       gtk_tree_model_filter_convert_child_iter_to_iter (GTK_TREE_MODEL_FILTER (priv->filter_model),
1062                                                         &filter_iter,
1063                                                         &priv->font_iter))
1064     {
1065       GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->filter_model),
1066                                                    &filter_iter);
1067
1068       gtk_tree_selection_select_iter (selection, &filter_iter);
1069       gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->family_face_list),
1070                                     path, NULL, FALSE, 0.0, 0.0);
1071       gtk_tree_path_free (path);
1072     }
1073   else
1074     {
1075       gtk_tree_selection_unselect_all (selection);
1076     }
1077 }
1078
1079 static void
1080 gtk_font_chooser_widget_merge_font_desc (GtkFontChooserWidget *fontchooser,
1081                                          PangoFontDescription *font_desc,
1082                                          GtkTreeIter          *iter)
1083 {
1084   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
1085   PangoFontMask mask;
1086
1087   g_assert (font_desc != NULL);
1088   /* iter may be NULL if the font doesn't exist on the list */
1089
1090   mask = pango_font_description_get_set_fields (font_desc);
1091
1092   /* sucky test, because we can't restrict the comparison to 
1093    * only the parts that actually do get merged */
1094   if (pango_font_description_equal (font_desc, priv->font_desc))
1095     {
1096       pango_font_description_free (font_desc);
1097       return;
1098     }
1099
1100   pango_font_description_merge (priv->font_desc, font_desc, TRUE);
1101   
1102   if (mask & PANGO_FONT_MASK_SIZE)
1103     {
1104       double font_size = (double) pango_font_description_get_size (priv->font_desc) / PANGO_SCALE;
1105       /* XXX: This clamps, which can cause it to reloop into here, do we need
1106        * to block its signal handler? */
1107       gtk_range_set_value (GTK_RANGE (priv->size_slider), font_size);
1108       gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->size_spin), font_size);
1109     }
1110   if (mask & (PANGO_FONT_MASK_FAMILY | PANGO_FONT_MASK_STYLE | PANGO_FONT_MASK_VARIANT |
1111               PANGO_FONT_MASK_WEIGHT | PANGO_FONT_MASK_STRETCH))
1112     {
1113       if (&priv->font_iter != iter)
1114         {
1115           if (iter == NULL)
1116             memset (&priv->font_iter, 0, sizeof (GtkTreeIter));
1117           else
1118             memcpy (&priv->font_iter, iter, sizeof (GtkTreeIter));
1119           
1120           gtk_font_chooser_widget_ensure_selection (fontchooser);
1121         }
1122
1123       gtk_font_chooser_widget_update_marks (fontchooser);
1124     }
1125
1126   gtk_widget_override_font (priv->preview, priv->font_desc);
1127
1128   pango_font_description_free (font_desc); /* adopted */
1129
1130   g_object_notify (G_OBJECT (fontchooser), "font");
1131   g_object_notify (G_OBJECT (fontchooser), "font-desc");
1132 }
1133
1134 static void
1135 gtk_font_chooser_widget_take_font_desc (GtkFontChooserWidget *fontchooser,
1136                                         PangoFontDescription *font_desc)
1137 {
1138   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
1139   PangoFontMask mask;
1140
1141   if (font_desc == NULL)
1142     font_desc = pango_font_description_from_string (GTK_FONT_CHOOSER_DEFAULT_FONT_NAME);
1143
1144   mask = pango_font_description_get_set_fields (font_desc);
1145   if (mask & (PANGO_FONT_MASK_FAMILY | PANGO_FONT_MASK_STYLE | PANGO_FONT_MASK_VARIANT |
1146               PANGO_FONT_MASK_WEIGHT | PANGO_FONT_MASK_STRETCH))
1147     {
1148       GtkTreeIter iter;
1149
1150       if (gtk_font_chooser_widget_find_font (fontchooser,
1151                                              font_desc,
1152                                              &iter))
1153         {
1154           gtk_font_chooser_widget_merge_font_desc (fontchooser,
1155                                                    font_desc,
1156                                                    &iter);
1157         }
1158       else
1159         {
1160           gtk_font_chooser_widget_merge_font_desc (fontchooser,
1161                                                    font_desc,
1162                                                    NULL);
1163         }
1164     }
1165   else
1166     {
1167       gtk_font_chooser_widget_merge_font_desc (fontchooser,
1168                                                font_desc,
1169                                                &priv->font_iter);
1170                                                           
1171     }
1172 }
1173
1174 static const gchar*
1175 gtk_font_chooser_widget_get_preview_text (GtkFontChooserWidget *fontchooser)
1176 {
1177   return fontchooser->priv->preview_text;
1178 }
1179
1180 static void
1181 gtk_font_chooser_widget_set_preview_text (GtkFontChooserWidget *fontchooser,
1182                                           const gchar          *text)
1183 {
1184   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
1185
1186   g_free (priv->preview_text);
1187   priv->preview_text = g_strdup (text);
1188
1189   gtk_entry_set_text (GTK_ENTRY (priv->preview), text);
1190
1191   g_object_notify (G_OBJECT (fontchooser), "preview-text");
1192
1193   /* XXX: There's no API to tell the treeview that a column has changed,
1194    * so we just */
1195   gtk_widget_queue_draw (priv->family_face_list);
1196 }
1197
1198 static gboolean
1199 gtk_font_chooser_widget_get_show_preview_entry (GtkFontChooserWidget *fontchooser)
1200 {
1201   return fontchooser->priv->show_preview_entry;
1202 }
1203
1204 static void
1205 gtk_font_chooser_widget_set_show_preview_entry (GtkFontChooserWidget *fontchooser,
1206                                                 gboolean              show_preview_entry)
1207 {
1208   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
1209
1210   if (priv->show_preview_entry != show_preview_entry)
1211     {
1212       fontchooser->priv->show_preview_entry = show_preview_entry;
1213
1214       if (show_preview_entry)
1215         gtk_widget_show (fontchooser->priv->preview);
1216       else
1217         gtk_widget_hide (fontchooser->priv->preview);
1218
1219       g_object_notify (G_OBJECT (fontchooser), "show-preview-entry");
1220     }
1221 }
1222
1223 static void
1224 gtk_font_chooser_widget_set_filter_func (GtkFontChooser  *chooser,
1225                                          GtkFontFilterFunc filter,
1226                                          gpointer          data,
1227                                          GDestroyNotify    destroy)
1228 {
1229   GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (chooser);
1230   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
1231
1232   if (priv->filter_data_destroy)
1233     priv->filter_data_destroy (priv->filter_data);
1234
1235   priv->filter_func = filter;
1236   priv->filter_data = data;
1237   priv->filter_data_destroy = destroy;
1238
1239   gtk_font_chooser_widget_refilter_font_list (fontchooser);
1240 }
1241
1242 static void
1243 gtk_font_chooser_widget_iface_init (GtkFontChooserIface *iface)
1244 {
1245   iface->get_font_family = gtk_font_chooser_widget_get_family;
1246   iface->get_font_face = gtk_font_chooser_widget_get_face;
1247   iface->get_font_size = gtk_font_chooser_widget_get_size;
1248   iface->set_filter_func = gtk_font_chooser_widget_set_filter_func;
1249 }