]> Pileus Git - ~andy/gtk/blob - gtk/gtkfontchooser.c
GtkFontChooser: Layout enhancements, using a scrolled window for the preview entry.
[~andy/gtk] / gtk / gtkfontchooser.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * Massively updated for Pango by Owen Taylor, May 2000
5  * GtkFontSelection widget for Gtk+, by Damon Chaplin, May 1998.
6  * Based on the GnomeFontSelector widget, by Elliot Lee, but major changes.
7  * The GnomeFontSelector was derived from app/text_tool.c in the GIMP.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24
25 /*
26  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
27  * file for a list of people on the GTK+ Team.  See the ChangeLog
28  * files for a list of changes.  These files are distributed with
29  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
30  */
31
32 #include "config.h"
33
34 #include <stdlib.h>
35 #include <glib/gprintf.h>
36 #include <string.h>
37
38 #include <atk/atk.h>
39
40 #include "gtkfontsel.h"
41 #include "gtkbutton.h"
42 #include "gtkcellrenderertext.h"
43 #include "gtkentry.h"
44 #include "gtkframe.h"
45 #include "gtkhbbox.h"
46 #include "gtkhbox.h"
47 #include "gtklabel.h"
48 #include "gtkliststore.h"
49 #include "gtkrc.h"
50 #include "gtkstock.h"
51 #include "gtktable.h"
52 #include "gtktreeselection.h"
53 #include "gtktreeview.h"
54 #include "gtkvbox.h"
55 #include "gtkscrolledwindow.h"
56 #include "gtkintl.h"
57 #include "gtkaccessible.h"
58 #include "gtkbuildable.h"
59 #include "gtkprivate.h"
60 #include "gtkalignment.h"
61 #include "gtkscale.h"
62 #include "gtkbox.h"
63 #include "gtkspinbutton.h"
64 #include "gtkwidget.h"
65
66 /**
67  * SECTION:gtkfontsel
68  * @Short_description: A widget for selecting fonts
69  * @Title: GtkFontSelection
70  * @See_also: #GtkFontSelectionDialog
71  *
72  * The #GtkFontSelection widget lists the available fonts, styles and sizes,
73  * allowing the user to select a font.
74  * It is used in the #GtkFontSelectionDialog widget to provide a dialog box for
75  * selecting fonts.
76  *
77  * To set the font which is initially selected, use
78  * gtk_font_selection_set_font_name().
79  *
80  * To get the selected font use gtk_font_selection_get_font_name().
81  *
82  * To change the text which is shown in the preview area, use
83  * gtk_font_selection_set_preview_text().
84  */
85
86
87 struct _GtkFontSelectionPrivate
88 {
89   GtkWidget *search_entry;
90   GtkWidget *family_face_list;
91   GtkWidget *size_slider;
92   GtkWidget *size_spin;
93   GtkWidget *preview;
94
95   GtkListStore *model;  
96   GtkTreeModel *filter;
97
98   gint             size;
99   PangoFontFace   *face;
100   PangoFontFamily *family;
101   
102   gboolean         ignore_slider;
103 };
104
105
106 struct _GtkFontSelectionDialogPrivate
107 {
108   GtkWidget *fontsel;
109
110   GtkWidget *ok_button;
111   GtkWidget *apply_button;
112   GtkWidget *cancel_button;
113 };
114
115
116 /* We don't enable the font and style entries because they don't add
117  * much in terms of visible effect and have a weird effect on keynav.
118  * the Windows font selector has entries similarly positioned but they
119  * act in conjunction with the associated lists to form a single focus
120  * location.
121  */
122 #undef INCLUDE_FONT_ENTRIES
123
124 /* This is the default text shown in the preview entry, though the user
125    can set it. Remember that some fonts only have capital letters. */
126 #define PREVIEW_TEXT N_("abcdefghijk ABCDEFGHIJK")
127
128 #define DEFAULT_FONT_NAME "Sans 10"
129 #define MAX_FONT_SIZE 999
130
131 /* This is the initial fixed height and the top padding of the preview entry */
132 #define PREVIEW_HEIGHT 84
133 #define PREVIEW_TOP_PADDING 6
134
135 /* These are the sizes of the font, style & size lists. */
136 #define FONT_LIST_HEIGHT        136
137 #define FONT_LIST_WIDTH         190
138 #define FONT_STYLE_LIST_WIDTH   170
139 #define FONT_SIZE_LIST_WIDTH    60
140
141 #define ROW_FORMAT_STRING "<span size=\"small\" foreground=\"%s\">%s <i>%s</i></span>\n<span size=\"large\" font_desc=\"%s\">%s</span>"
142
143 /* These are what we use as the standard font sizes, for the size list.
144  */
145 #define FONT_SIZES_LENGTH 25
146 static const guint16 font_sizes[] = {
147   6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 26, 28,
148   32, 36, 40, 48, 56, 64, 72
149 };
150
151 enum {
152    PROP_0,
153    PROP_FONT_NAME,
154    PROP_PREVIEW_TEXT
155 };
156
157
158 enum {
159   FAMILY_COLUMN,
160   FACE_COLUMN,
161   FAMILY_NAME_COLUMN,
162   TEXT_COLUMN
163 };
164
165 static void    gtk_font_selection_set_property       (GObject         *object,
166                                                       guint            prop_id,
167                                                       const GValue    *value,
168                                                       GParamSpec      *pspec);
169 static void    gtk_font_selection_get_property       (GObject         *object,
170                                                       guint            prop_id,
171                                                       GValue          *value,
172                                                       GParamSpec      *pspec);
173 static void    gtk_font_selection_finalize           (GObject         *object);
174 static void    gtk_font_selection_screen_changed     (GtkWidget       *widget,
175                                                       GdkScreen       *previous_screen);
176 static void    gtk_font_selection_style_updated      (GtkWidget      *widget);
177
178 static void     gtk_font_selection_ref_family            (GtkFontSelection *fontsel,
179                                                           PangoFontFamily  *family);
180 static void     gtk_font_selection_ref_face              (GtkFontSelection *fontsel,
181                                                           PangoFontFace    *face);
182 static void gtk_font_selection_bootstrap_fontlist (GtkFontSelection *fontsel);
183
184 G_DEFINE_TYPE (GtkFontSelection, gtk_font_selection, GTK_TYPE_VBOX)
185
186 static void
187 gtk_font_selection_class_init (GtkFontSelectionClass *klass)
188 {
189   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
190   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
191
192   gobject_class->finalize = gtk_font_selection_finalize;
193   gobject_class->set_property = gtk_font_selection_set_property;
194   gobject_class->get_property = gtk_font_selection_get_property;
195
196   widget_class->screen_changed = gtk_font_selection_screen_changed;
197   widget_class->style_updated = gtk_font_selection_style_updated;
198    
199   g_object_class_install_property (gobject_class,
200                                    PROP_FONT_NAME,
201                                    g_param_spec_string ("font-name",
202                                                         P_("Font name"),
203                                                         P_("The string that represents this font"),
204                                                         DEFAULT_FONT_NAME,
205                                                         GTK_PARAM_READWRITE));
206   g_object_class_install_property (gobject_class,
207                                    PROP_PREVIEW_TEXT,
208                                    g_param_spec_string ("preview-text",
209                                                         P_("Preview text"),
210                                                         P_("The text to display in order to demonstrate the selected font"),
211                                                         _(PREVIEW_TEXT),
212                                                         GTK_PARAM_READWRITE));
213
214   g_type_class_add_private (klass, sizeof (GtkFontSelectionPrivate));
215 }
216
217 static void 
218 gtk_font_selection_set_property (GObject         *object,
219                                  guint            prop_id,
220                                  const GValue    *value,
221                                  GParamSpec      *pspec)
222 {
223   GtkFontSelection *fontsel;
224
225   fontsel = GTK_FONT_SELECTION (object);
226
227   switch (prop_id)
228     {
229     case PROP_FONT_NAME:
230       gtk_font_selection_set_font_name (fontsel, g_value_get_string (value));
231       break;
232     case PROP_PREVIEW_TEXT:
233       gtk_font_selection_set_preview_text (fontsel, g_value_get_string (value));
234       break;
235     default:
236       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
237       break;
238     }
239 }
240
241 static void gtk_font_selection_get_property (GObject         *object,
242                                              guint            prop_id,
243                                              GValue          *value,
244                                              GParamSpec      *pspec)
245 {
246   GtkFontSelection *fontsel;
247
248   fontsel = GTK_FONT_SELECTION (object);
249
250   switch (prop_id)
251     {
252     case PROP_FONT_NAME:
253       g_value_take_string (value, gtk_font_selection_get_font_name (fontsel));
254       break;
255     case PROP_PREVIEW_TEXT:
256       g_value_set_string (value, gtk_font_selection_get_preview_text (fontsel));
257       break;
258     default:
259       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
260       break;
261     }
262 }
263
264 void
265 deleted_text_cb (GtkEntryBuffer *buffer,
266                  guint           position,
267                  guint           n_chars,
268                  gpointer        user_data)
269 {
270   GtkFontSelectionPrivate *priv  = (GtkFontSelectionPrivate*)user_data;
271   GtkWidget               *entry = priv->search_entry;
272   
273   if (gtk_entry_buffer_get_length (buffer) == 0)
274     {
275       gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
276                                      GTK_ENTRY_ICON_SECONDARY,
277                                      GTK_STOCK_FIND);
278     }
279
280   gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
281 }
282
283 void
284 inserted_text_cb (GtkEntryBuffer *buffer,
285                   guint           position,
286                   gchar          *chars,
287                   guint           n_chars,
288                   gpointer        user_data) 
289 {
290   GtkFontSelectionPrivate *priv  = (GtkFontSelectionPrivate*)user_data;
291   GtkWidget               *entry = priv->search_entry;
292
293   if (g_strcmp0 (gtk_entry_get_icon_stock (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY),
294                  GTK_STOCK_CLEAR))
295     gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
296                                    GTK_ENTRY_ICON_SECONDARY,
297                                    GTK_STOCK_CLEAR);
298
299
300   gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
301 }
302
303 void
304 icon_press_cb (GtkEntry             *entry,
305                GtkEntryIconPosition  pos,
306                GdkEvent             *event,
307                gpointer              user_data)
308 {
309   gtk_entry_buffer_delete_text (gtk_entry_get_buffer (entry), 0, -1);
310 }
311
312 void
313 slider_change_cb (GtkAdjustment *adjustment, gpointer data)
314 {
315   GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*)data;
316
317   /* If we set the silder value manually, we ignore this callback */
318   if (priv->ignore_slider)
319     {
320       priv->ignore_slider = FALSE;
321       return;
322     }
323
324   gtk_adjustment_set_value (gtk_spin_button_get_adjustment( GTK_SPIN_BUTTON(priv->size_spin)),
325                             gtk_adjustment_get_value (adjustment));
326 }
327
328 void
329 spin_change_cb (GtkAdjustment *adjustment, gpointer data)
330 {
331   PangoFontDescription *desc;
332   GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*)data;
333
334   gdouble size = gtk_adjustment_get_value (adjustment);
335   
336   GtkAdjustment *slider_adj = gtk_range_get_adjustment (GTK_RANGE (priv->size_slider));
337
338   /* We ignore the slider value change callback for both of this set_value call */
339   if (size < gtk_adjustment_get_lower (slider_adj))
340     {
341       priv->ignore_slider = TRUE;
342       gtk_adjustment_set_value (slider_adj, gtk_adjustment_get_lower (slider_adj));
343     }
344   else if (size > gtk_adjustment_get_upper (slider_adj))
345     {
346       priv->ignore_slider = TRUE;
347       gtk_adjustment_set_value (slider_adj, gtk_adjustment_get_upper (slider_adj));
348     }
349
350   priv->size = ((gint)gtk_adjustment_get_value (adjustment)) * PANGO_SCALE;
351
352   desc = pango_context_get_font_description (gtk_widget_get_pango_context (priv->preview));
353   pango_font_description_set_size (desc, priv->size);
354   gtk_widget_modify_font (priv->preview, desc);
355   
356   gtk_widget_queue_draw (priv->preview);
357 }
358
359 static void
360 gtk_font_selection_init (GtkFontSelection *fontsel)
361 {
362   GtkFontSelectionPrivate *priv;
363   PangoFontDescription    *font_desc;
364   GtkWidget               *scrolled_win;
365   GtkWidget               *alignment;
366   GtkWidget               *preview_and_size;
367   GtkWidget               *size_controls;
368 #if 0
369   GList                   *focus_chain = NULL;
370   AtkObject *atk_obj;
371 #endif
372
373   fontsel->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontsel,
374                                                GTK_TYPE_FONT_SELECTION,
375                                                GtkFontSelectionPrivate);
376   priv = fontsel->priv;
377   gtk_widget_push_composite_child ();
378
379   /* Creating fundamental widgets for the private struct */
380   priv->search_entry = gtk_entry_new ();
381   priv->family_face_list = gtk_tree_view_new ();
382   priv->preview = gtk_entry_new ();
383   priv->size_slider = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
384                                                 (gdouble) font_sizes[0],
385                                                 (gdouble) font_sizes[FONT_SIZES_LENGTH - 1],
386                                                 1.0);
387
388   priv->size_spin = gtk_spin_button_new_with_range (0.0, (gdouble)(G_MAXINT / PANGO_SCALE), 1.0);
389
390   /** Bootstrapping widget layout **/  
391   gtk_box_pack_start (GTK_BOX (fontsel), priv->search_entry, FALSE, TRUE, 0);
392
393   /* Main font family/face view */
394   scrolled_win = gtk_scrolled_window_new (NULL, NULL);
395   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
396                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
397   gtk_container_add (GTK_CONTAINER (scrolled_win), priv->family_face_list);
398
399   /* Alignment for the preview and size controls */
400   alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
401   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment),
402                              PREVIEW_TOP_PADDING, 0, 0, 0);
403   gtk_box_pack_start (GTK_BOX (fontsel), scrolled_win, TRUE, TRUE, 0);
404
405   preview_and_size = gtk_vbox_new (TRUE, 0);
406   gtk_box_set_homogeneous (GTK_BOX (preview_and_size), FALSE);
407   
408   /* The preview entry needs a scrolled window to make sure we have a */
409   scrolled_win = gtk_scrolled_window_new (NULL, NULL);
410   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
411                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
412   gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win),
413                                          priv->preview);
414   gtk_box_pack_start (GTK_BOX (preview_and_size), scrolled_win, FALSE, FALSE, 0);
415   
416   /* Setting the size requests for various widgets */
417   gtk_widget_set_size_request (priv->family_face_list, -1, 360);
418   gtk_widget_set_size_request (scrolled_win, -1, PREVIEW_HEIGHT);
419   gtk_widget_set_size_request (priv->preview, -1, PREVIEW_HEIGHT - 6);
420
421   /* Unset the frame on the preview entry and set a shadow in the scrolled window */
422   gtk_entry_set_has_frame (GTK_ENTRY (priv->preview), FALSE);
423   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
424                                        GTK_SHADOW_ETCHED_IN);
425
426   /* Packing the slider and the spin in a hbox */
427   size_controls = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
428   gtk_scale_set_draw_value (GTK_SCALE (priv->size_slider), FALSE);
429   gtk_box_pack_start (GTK_BOX (size_controls), priv->size_slider, TRUE, TRUE, 0);
430   gtk_box_pack_start (GTK_BOX (size_controls), priv->size_spin, FALSE, TRUE, 0);
431
432   gtk_box_pack_start (GTK_BOX (preview_and_size), size_controls, FALSE, FALSE, 0);
433   gtk_container_add (GTK_CONTAINER (alignment), preview_and_size);
434
435   gtk_box_pack_start (GTK_BOX (fontsel), GTK_WIDGET(alignment), FALSE, TRUE, 0);
436
437   /* Getting the default size */
438   font_desc  = pango_context_get_font_description (gtk_widget_get_pango_context (GTK_WIDGET (fontsel)));
439   priv->size = pango_font_description_get_size (font_desc);
440   priv->face = NULL;
441   priv->family = NULL;
442   
443   gtk_adjustment_set_value (gtk_range_get_adjustment (GTK_RANGE (priv->size_slider)),
444                             (gdouble)(priv->size / PANGO_SCALE));
445   gtk_adjustment_set_value (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin)),
446                             (gdouble)(priv->size / PANGO_SCALE));
447
448   gtk_widget_show_all (GTK_WIDGET (fontsel));
449   gtk_widget_hide (GTK_WIDGET (fontsel));
450
451   /* Treeview column and model bootstrapping */
452   gtk_font_selection_bootstrap_fontlist (fontsel);
453   
454   /* Set default preview text */
455   gtk_entry_set_text (GTK_ENTRY (priv->preview),
456                       pango_language_get_sample_string (NULL));
457   
458   /* Set search icon and place holder text */
459   gtk_entry_set_icon_from_stock (GTK_ENTRY (priv->search_entry),
460                                  GTK_ENTRY_ICON_SECONDARY,
461                                  GTK_STOCK_FIND);
462   gtk_entry_set_placeholder_text (GTK_ENTRY (priv->search_entry), _("Search font name"));
463   
464   /** Callback connections **/
465   /* Connect to callback for the live search text entry */
466   g_signal_connect (G_OBJECT (gtk_entry_get_buffer (GTK_ENTRY (priv->search_entry))),
467                     "deleted-text", G_CALLBACK (deleted_text_cb), (gpointer)priv);
468   g_signal_connect (G_OBJECT (gtk_entry_get_buffer (GTK_ENTRY (priv->search_entry))),
469                     "inserted-text", G_CALLBACK (inserted_text_cb), (gpointer)priv);
470   g_signal_connect (G_OBJECT (priv->search_entry),
471                     "icon-press", G_CALLBACK (icon_press_cb), (gpointer)priv);
472
473   /* Size controls callbacks */
474   g_signal_connect (G_OBJECT (gtk_range_get_adjustment (GTK_RANGE (priv->size_slider))),
475                     "value-changed", G_CALLBACK (slider_change_cb), (gpointer)priv);
476   g_signal_connect (G_OBJECT (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin))),
477                     "value-changed", G_CALLBACK (spin_change_cb), (gpointer)priv);
478   priv->ignore_slider = FALSE;
479                     
480   gtk_widget_pop_composite_child();
481 }
482
483 /**
484  * gtk_font_selection_new:
485  *
486  * Creates a new #GtkFontSelection.
487  *
488  * Return value: a n ew #GtkFontSelection
489  */
490 GtkWidget *
491 gtk_font_selection_new (void)
492 {
493   GtkFontSelection *fontsel;
494   
495   fontsel = g_object_new (GTK_TYPE_FONT_SELECTION, NULL);
496   
497   return GTK_WIDGET (fontsel);
498 }
499
500 static int
501 cmp_families (const void *a, const void *b)
502 {
503   const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a);
504   const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b);
505
506   return g_utf8_collate (a_name, b_name);
507 }
508
509 static void
510 set_cursor_to_iter (GtkTreeView *view,
511                     GtkTreeIter *iter)
512 {
513   GtkTreeModel *model = gtk_tree_view_get_model (view);
514   GtkTreePath *path = gtk_tree_model_get_path (model, iter);
515
516   gtk_tree_view_set_cursor (view, path, NULL, FALSE);
517
518   gtk_tree_path_free (path);
519 }
520
521 static void 
522 populate_list (GtkTreeView* treeview, GtkListStore* model)
523 {
524   GtkStyleContext *style_context;
525   GdkRGBA          g_color;
526   PangoColor       p_color;
527   gchar            *color_string;
528
529   GtkTreeIter   match_row;
530
531   gint n_families, i;  
532   PangoFontFamily **families;
533
534   GString     *tmp = g_string_new (NULL);
535
536   pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (treeview)),
537                                &families,
538                                &n_families);
539
540   qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families);
541
542   gtk_list_store_clear (model);
543
544   /* Get row header font color */
545   style_context = gtk_widget_get_style_context (GTK_WIDGET (treeview));
546   gtk_style_context_get_color (style_context,
547                                GTK_STATE_FLAG_NORMAL |GTK_STATE_FLAG_INSENSITIVE,
548                                &g_color);
549
550   p_color.red   = (guint16)((gdouble)G_MAXUINT16 * g_color.red);
551   p_color.green = (guint16)((gdouble)G_MAXUINT16 * g_color.green);
552   p_color.blue  = (guint16)((gdouble)G_MAXUINT16 * g_color.blue);
553   color_string  = pango_color_to_string (&p_color);
554
555   /* Iterate over families and faces */
556   for (i=0; i<n_families; i++)
557     {
558       GtkTreeIter     iter;
559       PangoFontFace **faces;
560       int             j, n_faces;
561       const gchar    *fam_name = pango_font_family_get_name (families[i]);
562
563       pango_font_family_list_faces (families[i], &faces, &n_faces);
564       
565       for (j=0; j<n_faces; j++)
566         {
567           PangoFontDescription *pango_desc = pango_font_face_describe (faces[j]);
568           const gchar *face_name = pango_font_face_get_face_name (faces[j]);
569           gchar       *font_desc = pango_font_description_to_string (pango_desc);
570           
571           /* foreground_color, family_name, face_name, desc, sample string */
572           g_string_printf (tmp, ROW_FORMAT_STRING,
573                                 color_string,
574                                 fam_name,
575                                 face_name,
576                                 font_desc,
577                                 PREVIEW_TEXT);
578
579
580           gtk_list_store_append (model, &iter);
581           gtk_list_store_set (model, &iter,
582                               FAMILY_COLUMN, families[i],
583                               FACE_COLUMN, faces[j],
584                               FAMILY_NAME_COLUMN, fam_name,
585                               TEXT_COLUMN, tmp->str,
586                               -1);
587
588           if ((i == 0 && j == 0) ||
589               (!g_ascii_strcasecmp (face_name, "sans") && j == 0))
590             {
591               match_row = iter;
592             }
593
594           pango_font_description_free(pango_desc);
595           g_free (font_desc);
596         }
597
598       g_free (faces);
599     }
600
601   set_cursor_to_iter (treeview, &match_row);
602
603   g_string_free (tmp, TRUE);
604   g_free (color_string);
605   g_free (families);
606 }
607
608 gboolean
609 visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
610 {
611   gboolean result = FALSE;
612   GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*) data;
613
614   const gchar *search_text = (const gchar*)gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
615   gchar       *font_name;
616   gchar       *font_name_casefold;
617   gchar       *search_text_casefold;
618
619   gtk_tree_model_get (model, iter,
620                       FAMILY_NAME_COLUMN, &font_name,
621                       -1);
622
623   /* Covering some corner cases to speed up the result */
624   if (font_name == NULL ||
625       strlen (search_text) > strlen (font_name))
626     {
627       g_free (font_name);
628       return FALSE;
629     }  
630   if (strlen (search_text) == 0)
631     {
632       g_free (font_name);
633       return TRUE;
634     }
635   
636   font_name_casefold = g_utf8_casefold (font_name, -1);
637   search_text_casefold = g_utf8_casefold (search_text, -1);
638   
639   if (g_strrstr (font_name_casefold, search_text_casefold))
640     result = TRUE;
641
642   g_free (search_text_casefold);
643   g_free (font_name_casefold);
644   g_free (font_name);
645   return result;
646 }
647
648 static void
649 gtk_font_selection_bootstrap_fontlist (GtkFontSelection* fontsel)
650 {
651   GtkTreeView       *treeview = GTK_TREE_VIEW (fontsel->priv->family_face_list);
652   GtkTreeViewColumn *col;
653
654   fontsel->priv->model = gtk_list_store_new (4,
655                                              PANGO_TYPE_FONT_FAMILY,
656                                              PANGO_TYPE_FONT_FACE,
657                                              G_TYPE_STRING,
658                                              G_TYPE_STRING);
659
660   fontsel->priv->filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fontsel->priv->model),
661                                                      NULL);
662   gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (fontsel->priv->filter),
663                                           visible_func,
664                                           (gpointer)fontsel->priv,
665                                           NULL);
666                                           
667
668   gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (fontsel->priv->filter));
669   
670   gtk_tree_view_set_rules_hint      (treeview, TRUE);
671   gtk_tree_view_set_headers_visible (treeview, FALSE);
672
673   col = gtk_tree_view_column_new_with_attributes ("Family",
674                                                    gtk_cell_renderer_text_new (),
675                                                    "markup", TEXT_COLUMN,
676                                                    NULL);
677   gtk_tree_view_append_column (treeview, col);
678
679   populate_list (treeview, fontsel->priv->model);
680 }
681
682
683 static void
684 gtk_font_selection_finalize (GObject *object)
685 {
686   GtkFontSelection *fontsel = GTK_FONT_SELECTION (object);
687
688   gtk_font_selection_ref_family (fontsel, NULL);
689   gtk_font_selection_ref_face (fontsel, NULL);
690
691   G_OBJECT_CLASS (gtk_font_selection_parent_class)->finalize (object);
692 }
693
694 static void
695 gtk_font_selection_screen_changed (GtkWidget *widget,
696                                   GdkScreen *previous_screen)
697 {
698   return;
699 }
700
701 static void
702 gtk_font_selection_style_updated (GtkWidget *widget)
703 {
704   GTK_WIDGET_CLASS (gtk_font_selection_parent_class)->style_updated (widget);
705
706   return;
707 }
708
709 static void
710 gtk_font_selection_ref_family (GtkFontSelection *fontsel,
711                                PangoFontFamily  *family)
712 {
713   GtkFontSelectionPrivate *priv = fontsel->priv;
714
715   if (family)
716     family = g_object_ref (family);
717   if (priv->family)
718     g_object_unref (priv->family);
719   priv->family = family;
720 }
721
722 static void
723 gtk_font_selection_ref_face (GtkFontSelection *fontsel,
724                              PangoFontFace    *face)
725 {
726   GtkFontSelectionPrivate *priv = fontsel->priv;
727
728   if (face)
729     face = g_object_ref (face);
730   if (priv->face)
731     g_object_unref (priv->face);
732   priv->face = face;
733 }
734
735 /*****************************************************************************
736  * These functions are the main public interface for getting/setting the font.
737  *****************************************************************************/
738
739 /**
740  * gtk_font_selection_get_family_list:
741  * @fontsel: a #GtkFontSelection
742  *
743  * This returns the #GtkTreeView that lists font families, for
744  * example, 'Sans', 'Serif', etc.
745  *
746  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
747  *
748  * Deprecated: 3.2
749  */
750 GtkWidget *
751 gtk_font_selection_get_family_list (GtkFontSelection *fontsel)
752 {
753   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
754
755   return NULL;
756 }
757
758 /**
759  * gtk_font_selection_get_face_list:
760  * @fontsel: a #GtkFontSelection
761  *
762  * This returns the #GtkTreeView which lists all styles available for
763  * the selected font. For example, 'Regular', 'Bold', etc.
764  * 
765  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
766  *
767  * Deprecated: 3.2
768  */
769 GtkWidget *
770 gtk_font_selection_get_face_list (GtkFontSelection *fontsel)
771 {
772   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
773
774   return NULL;
775 }
776
777 /**
778  * gtk_font_selection_get_size_entry:
779  * @fontsel: a #GtkFontSelection
780  *
781  * This returns the #GtkEntry used to allow the user to edit the font
782  * number manually instead of selecting it from the list of font sizes.
783  *
784  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
785  *
786  * Deprecated: 3.2
787  */
788 GtkWidget *
789 gtk_font_selection_get_size_entry (GtkFontSelection *fontsel)
790 {
791   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
792
793   return NULL;
794 }
795
796 /**
797  * gtk_font_selection_get_size_list:
798  * @fontsel: a #GtkFontSelection
799  *
800  * This returns the #GtkTreeeView used to list font sizes.
801  *
802  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
803  *
804  * Deprecated: 3.2
805  */
806 GtkWidget *
807 gtk_font_selection_get_size_list (GtkFontSelection *fontsel)
808 {
809   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
810
811   return NULL;
812 }
813
814 /**
815  * gtk_font_selection_get_preview_entry:
816  * @fontsel: a #GtkFontSelection
817  *
818  * This returns the #GtkEntry used to display the font as a preview.
819  *
820  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
821  *
822  * Deprecated: 3.2
823  */
824 GtkWidget *
825 gtk_font_selection_get_preview_entry (GtkFontSelection *fontsel)
826 {
827   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
828
829   return NULL;
830 }
831
832 /**
833  * gtk_font_selection_get_family:
834  * @fontsel: a #GtkFontSelection
835  *
836  * Gets the #PangoFontFamily representing the selected font family.
837  *
838  * Return value: (transfer none): A #PangoFontFamily representing the
839  *     selected font family. Font families are a collection of font
840  *     faces. The returned object is owned by @fontsel and must not
841  *     be modified or freed.
842  *
843  * Since: 2.14
844  */
845 PangoFontFamily *
846 gtk_font_selection_get_family (GtkFontSelection *fontsel)
847 {
848   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
849
850   return NULL;
851 }
852
853 /**
854  * gtk_font_selection_get_face:
855  * @fontsel: a #GtkFontSelection
856  *
857  * Gets the #PangoFontFace representing the selected font group
858  * details (i.e. family, slant, weight, width, etc).
859  *
860  * Return value: (transfer none): A #PangoFontFace representing the
861  *     selected font group details. The returned object is owned by
862  *     @fontsel and must not be modified or freed.
863  *
864  * Since: 2.14
865  */
866 PangoFontFace *
867 gtk_font_selection_get_face (GtkFontSelection *fontsel)
868 {
869   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
870
871   return NULL;
872 }
873
874 /**
875  * gtk_font_selection_get_size:
876  * @fontsel: a #GtkFontSelection
877  *
878  * The selected font size.
879  *
880  * Return value: A n integer representing the selected font size,
881  *     or -1 if no font size is selected.
882  *
883  * Since: 2.14
884  **/
885 gint
886 gtk_font_selection_get_size (GtkFontSelection *fontsel)
887 {
888   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), -1);
889
890   return fontsel->priv->size;
891 }
892
893 /**
894  * gtk_font_selection_get_font_name:
895  * @fontsel: a #GtkFontSelection
896  * 
897  * Gets the currently-selected font name. 
898  *
899  * Note that this can be a different string than what you set with 
900  * gtk_font_selection_set_font_name(), as the font selection widget may 
901  * normalize font names and thus return a string with a different structure. 
902  * For example, "Helvetica Italic Bold 12" could be normalized to 
903  * "Helvetica Bold Italic 12". Use pango_font_description_equal()
904  * if you want to compare two font descriptions.
905  * 
906  * Return value: A string with the name of the current font, or %NULL if 
907  *     no font is selected. You must free this string with g_free().
908  */
909 gchar *
910 gtk_font_selection_get_font_name (GtkFontSelection *fontsel)
911 {
912   return NULL;
913 }
914
915 /* This sets the current font, then selecting the appropriate list rows. */
916
917 /**
918  * gtk_font_selection_set_font_name:
919  * @fontsel: a #GtkFontSelection
920  * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
921  * 
922  * Sets the currently-selected font. 
923  *
924  * Note that the @fontsel needs to know the screen in which it will appear 
925  * for this to work; this can be guaranteed by simply making sure that the 
926  * @fontsel is inserted in a toplevel window before you call this function.
927  * 
928  * Return value: %TRUE if the font could be set successfully; %FALSE if no 
929  *     such font exists or if the @fontsel doesn't belong to a particular 
930  *     screen yet.
931  */
932 gboolean
933 gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
934                                   const gchar      *fontname)
935 {
936 #if 0
937   PangoFontFamily *family = NULL;
938   PangoFontFace *face = NULL;
939   PangoFontDescription *new_desc;
940 #endif
941
942   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), FALSE);
943
944   return TRUE;
945 }
946
947 /**
948  * gtk_font_selection_get_preview_text:
949  * @fontsel: a #GtkFontSelection
950  *
951  * Gets the text displayed in the preview area.
952  * 
953  * Return value: the text displayed in the preview area. 
954  *     This string is owned by the widget and should not be 
955  *     modified or freed 
956  */
957 G_CONST_RETURN gchar*
958 gtk_font_selection_get_preview_text (GtkFontSelection *fontsel)
959 {
960   return NULL;
961 }
962
963
964 /**
965  * gtk_font_selection_set_preview_text:
966  * @fontsel: a #GtkFontSelection
967  * @text: the text to display in the preview area 
968  *
969  * Sets the text displayed in the preview area.
970  * The @text is used to show how the selected font looks.
971  */
972 void
973 gtk_font_selection_set_preview_text  (GtkFontSelection *fontsel,
974                                       const gchar      *text)
975 {
976 #if 0
977   GtkFontSelectionPrivate *priv;
978
979   g_return_if_fail (GTK_IS_FONT_SELECTION (fontsel));
980   g_return_if_fail (text != NULL);
981
982   priv = fontsel->priv;
983 #endif
984 }
985
986
987 /**
988  * SECTION:gtkfontseldlg
989  * @Short_description: A dialog box for selecting fonts
990  * @Title: GtkFontSelectionDialog
991  * @See_also: #GtkFontSelection, #GtkDialog
992  *
993  * The #GtkFontSelectionDialog widget is a dialog box for selecting a font.
994  *
995  * To set the font which is initially selected, use
996  * gtk_font_selection_dialog_set_font_name().
997  *
998  * To get the selected font use gtk_font_selection_dialog_get_font_name().
999  *
1000  * To change the text which is shown in the preview area, use
1001  * gtk_font_selection_dialog_set_preview_text().
1002  *
1003  * <refsect2 id="GtkFontSelectionDialog-BUILDER-UI">
1004  * <title>GtkFontSelectionDialog as GtkBuildable</title>
1005  * The GtkFontSelectionDialog implementation of the GtkBuildable interface
1006  * exposes the embedded #GtkFontSelection as internal child with the
1007  * name "font_selection". It also exposes the buttons with the names
1008  * "ok_button", "cancel_button" and "apply_button".
1009  * </refsect2>
1010  */
1011
1012 static void gtk_font_selection_dialog_buildable_interface_init     (GtkBuildableIface *iface);
1013 static GObject * gtk_font_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
1014                                                                           GtkBuilder   *builder,
1015                                                                           const gchar  *childname);
1016
1017 G_DEFINE_TYPE_WITH_CODE (GtkFontSelectionDialog, gtk_font_selection_dialog,
1018                          GTK_TYPE_DIALOG,
1019                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
1020                                                 gtk_font_selection_dialog_buildable_interface_init))
1021
1022 static GtkBuildableIface *parent_buildable_iface;
1023
1024 static void
1025 gtk_font_selection_dialog_class_init (GtkFontSelectionDialogClass *klass)
1026 {
1027   g_type_class_add_private (klass, sizeof (GtkFontSelectionDialogPrivate));
1028 }
1029
1030 static void
1031 gtk_font_selection_dialog_init (GtkFontSelectionDialog *fontseldiag)
1032 {
1033   GtkFontSelectionDialogPrivate *priv;
1034   GtkDialog *dialog = GTK_DIALOG (fontseldiag);
1035   GtkWidget *action_area, *content_area;
1036
1037   fontseldiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontseldiag,
1038                                                    GTK_TYPE_FONT_SELECTION_DIALOG,
1039                                                    GtkFontSelectionDialogPrivate);
1040   priv = fontseldiag->priv;
1041
1042   content_area = gtk_dialog_get_content_area (dialog);
1043   action_area = gtk_dialog_get_action_area (dialog);
1044
1045   gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
1046   gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
1047   gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
1048   gtk_box_set_spacing (GTK_BOX (action_area), 6);
1049
1050   gtk_widget_push_composite_child ();
1051
1052   gtk_window_set_resizable (GTK_WINDOW (fontseldiag), TRUE);
1053
1054   /* Create the content area */
1055   priv->fontsel = gtk_font_selection_new ();
1056   gtk_container_set_border_width (GTK_CONTAINER (priv->fontsel), 5);
1057   gtk_widget_show (priv->fontsel);
1058   gtk_box_pack_start (GTK_BOX (content_area),
1059                       priv->fontsel, TRUE, TRUE, 0);
1060
1061   /* Create the action area */
1062   priv->cancel_button = gtk_dialog_add_button (dialog,
1063                                                GTK_STOCK_CANCEL,
1064                                                GTK_RESPONSE_CANCEL);
1065
1066   priv->apply_button = gtk_dialog_add_button (dialog,
1067                                               GTK_STOCK_APPLY,
1068                                               GTK_RESPONSE_APPLY);
1069   gtk_widget_hide (priv->apply_button);
1070
1071   priv->ok_button = gtk_dialog_add_button (dialog,
1072                                            GTK_STOCK_OK,
1073                                            GTK_RESPONSE_OK);
1074   gtk_widget_grab_default (priv->ok_button);
1075
1076   gtk_dialog_set_alternative_button_order (GTK_DIALOG (fontseldiag),
1077                                            GTK_RESPONSE_OK,
1078                                            GTK_RESPONSE_APPLY,
1079                                            GTK_RESPONSE_CANCEL,
1080                                            -1);
1081
1082   gtk_window_set_title (GTK_WINDOW (fontseldiag),
1083                         _("Font Selection"));
1084
1085   gtk_widget_pop_composite_child ();
1086 }
1087
1088 /**
1089  * gtk_font_selection_dialog_new:
1090  * @title: the title of the dialog window 
1091  *
1092  * Creates a new #GtkFontSelectionDialog.
1093  *
1094  * Return value: a new #GtkFontSelectionDialog
1095  */
1096 GtkWidget*
1097 gtk_font_selection_dialog_new (const gchar *title)
1098 {
1099   GtkFontSelectionDialog *fontseldiag;
1100   
1101   fontseldiag = g_object_new (GTK_TYPE_FONT_SELECTION_DIALOG, NULL);
1102
1103   if (title)
1104     gtk_window_set_title (GTK_WINDOW (fontseldiag), title);
1105   
1106   return GTK_WIDGET (fontseldiag);
1107 }
1108
1109 /**
1110  * gtk_font_selection_dialog_get_font_selection:
1111  * @fsd: a #GtkFontSelectionDialog
1112  *
1113  * Retrieves the #GtkFontSelection widget embedded in the dialog.
1114  *
1115  * Returns: (transfer none): the embedded #GtkFontSelection
1116  *
1117  * Since: 2.22
1118  **/
1119 GtkWidget*
1120 gtk_font_selection_dialog_get_font_selection (GtkFontSelectionDialog *fsd)
1121 {
1122   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1123
1124   return fsd->priv->fontsel;
1125 }
1126
1127
1128 /**
1129  * gtk_font_selection_dialog_get_ok_button:
1130  * @fsd: a #GtkFontSelectionDialog
1131  *
1132  * Gets the 'OK' button.
1133  *
1134  * Return value: (transfer none): the #GtkWidget used in the dialog
1135  *     for the 'OK' button.
1136  *
1137  * Since: 2.14
1138  */
1139 GtkWidget *
1140 gtk_font_selection_dialog_get_ok_button (GtkFontSelectionDialog *fsd)
1141 {
1142   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1143
1144   return fsd->priv->ok_button;
1145 }
1146
1147 /**
1148  * gtk_font_selection_dialog_get_cancel_button:
1149  * @fsd: a #GtkFontSelectionDialog
1150  *
1151  * Gets the 'Cancel' button.
1152  *
1153  * Return value: (transfer none): the #GtkWidget used in the dialog
1154  *     for the 'Cancel' button.
1155  *
1156  * Since: 2.14
1157  */
1158 GtkWidget *
1159 gtk_font_selection_dialog_get_cancel_button (GtkFontSelectionDialog *fsd)
1160 {
1161   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1162
1163   return fsd->priv->cancel_button;
1164 }
1165
1166 static void
1167 gtk_font_selection_dialog_buildable_interface_init (GtkBuildableIface *iface)
1168 {
1169   parent_buildable_iface = g_type_interface_peek_parent (iface);
1170   iface->get_internal_child = gtk_font_selection_dialog_buildable_get_internal_child;
1171 }
1172
1173 static GObject *
1174 gtk_font_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
1175                                                         GtkBuilder   *builder,
1176                                                         const gchar  *childname)
1177 {
1178   GtkFontSelectionDialogPrivate *priv;
1179
1180   priv = GTK_FONT_SELECTION_DIALOG (buildable)->priv;
1181
1182   if (g_strcmp0 (childname, "ok_button") == 0)
1183     return G_OBJECT (priv->ok_button);
1184   else if (g_strcmp0 (childname, "cancel_button") == 0)
1185     return G_OBJECT (priv->cancel_button);
1186   else if (g_strcmp0 (childname, "apply_button") == 0)
1187     return G_OBJECT (priv->apply_button);
1188   else if (g_strcmp0 (childname, "font_selection") == 0)
1189     return G_OBJECT (priv->fontsel);
1190
1191   return parent_buildable_iface->get_internal_child (buildable, builder, childname);
1192 }
1193
1194 /**
1195  * gtk_font_selection_dialog_get_font_name:
1196  * @fsd: a #GtkFontSelectionDialog
1197  * 
1198  * Gets the currently-selected font name.
1199  *
1200  * Note that this can be a different string than what you set with 
1201  * gtk_font_selection_dialog_set_font_name(), as the font selection widget
1202  * may normalize font names and thus return a string with a different 
1203  * structure. For example, "Helvetica Italic Bold 12" could be normalized 
1204  * to "Helvetica Bold Italic 12".  Use pango_font_description_equal()
1205  * if you want to compare two font descriptions.
1206  * 
1207  * Return value: A string with the name of the current font, or %NULL if no 
1208  *     font is selected. You must free this string with g_free().
1209  */
1210 gchar*
1211 gtk_font_selection_dialog_get_font_name (GtkFontSelectionDialog *fsd)
1212 {
1213   GtkFontSelectionDialogPrivate *priv;
1214
1215   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1216
1217   priv = fsd->priv;
1218
1219   return gtk_font_selection_get_font_name (GTK_FONT_SELECTION (priv->fontsel));
1220 }
1221
1222 /**
1223  * gtk_font_selection_dialog_set_font_name:
1224  * @fsd: a #GtkFontSelectionDialog
1225  * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
1226  *
1227  * Sets the currently selected font. 
1228  * 
1229  * Return value: %TRUE if the font selected in @fsd is now the
1230  *     @fontname specified, %FALSE otherwise. 
1231  */
1232 gboolean
1233 gtk_font_selection_dialog_set_font_name (GtkFontSelectionDialog *fsd,
1234                                          const gchar            *fontname)
1235 {
1236   GtkFontSelectionDialogPrivate *priv;
1237
1238   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), FALSE);
1239   g_return_val_if_fail (fontname, FALSE);
1240
1241   priv = fsd->priv;
1242
1243   return gtk_font_selection_set_font_name (GTK_FONT_SELECTION (priv->fontsel), fontname);
1244 }
1245
1246 /**
1247  * gtk_font_selection_dialog_get_preview_text:
1248  * @fsd: a #GtkFontSelectionDialog
1249  *
1250  * Gets the text displayed in the preview area.
1251  * 
1252  * Return value: the text displayed in the preview area. 
1253  *     This string is owned by the widget and should not be 
1254  *     modified or freed 
1255  */
1256 G_CONST_RETURN gchar*
1257 gtk_font_selection_dialog_get_preview_text (GtkFontSelectionDialog *fsd)
1258 {
1259   GtkFontSelectionDialogPrivate *priv;
1260
1261   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1262
1263   priv = fsd->priv;
1264
1265   return gtk_font_selection_get_preview_text (GTK_FONT_SELECTION (priv->fontsel));
1266 }
1267
1268 /**
1269  * gtk_font_selection_dialog_set_preview_text:
1270  * @fsd: a #GtkFontSelectionDialog
1271  * @text: the text to display in the preview area
1272  *
1273  * Sets the text displayed in the preview area. 
1274  */
1275 void
1276 gtk_font_selection_dialog_set_preview_text (GtkFontSelectionDialog *fsd,
1277                                             const gchar            *text)
1278 {
1279   GtkFontSelectionDialogPrivate *priv;
1280
1281   g_return_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd));
1282   g_return_if_fail (text != NULL);
1283
1284   priv = fsd->priv;
1285
1286   gtk_font_selection_set_preview_text (GTK_FONT_SELECTION (priv->fontsel), text);
1287 }