]> Pileus Git - ~andy/gtk/blob - gtk/gtkfontchooser.c
GtkFontChooser: Setting the font-name property. Test updates. Remove warnings.
[~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 #ifndef GTK_DISABLE_DEPRECATED
105   GtkWidget    *size_list;
106   GtkWidget    *font_list;
107   GtkWidget    *face_list;
108
109   GtkListStore *_size_model;
110   GtkListStore *_font_model;
111   GtkListStore *_face_model;
112
113   gboolean      ignore_size;
114   gboolean      ignore_face;
115   gboolean      ignore_font;
116 #endif
117 };
118
119
120 struct _GtkFontSelectionDialogPrivate
121 {
122   GtkWidget *fontsel;
123
124   GtkWidget *ok_button;
125   GtkWidget *apply_button;
126   GtkWidget *cancel_button;
127 };
128
129
130 #define DEFAULT_FONT_NAME "Sans 10"
131 #define MAX_FONT_SIZE 999
132
133 /* This is the initial fixed height and the top padding of the preview entry */
134 #define PREVIEW_HEIGHT 72
135 #define PREVIEW_TOP_PADDING 6
136
137 /* Widget default geometry */
138 #define FONTSEL_WIDTH           540
139 #define FONTSEL_HEIGHT          408
140
141 /* These are the sizes of the font, style & size lists. */
142 #define FONT_LIST_HEIGHT  136
143 #define FONT_LIST_WIDTH   190
144 #define FONT_STYLE_LIST_WIDTH 170
145 #define FONT_SIZE_LIST_WIDTH  60
146
147 #define ROW_FORMAT_STRING "<span weight=\"bold\" size=\"small\" foreground=\"%s\">%s</span>\n<span size=\"x-large\" font_desc=\"%s\">%s</span>"
148
149 /* These are what we use as the standard font sizes, for the size list.
150  */
151 #define FONT_SIZES_LENGTH 14
152 static const gint font_sizes[] = {
153   6, 8, 9, 10, 11, 12, 13, 14, 16, 20, 24, 36, 48, 72
154 };
155
156 enum {
157    PROP_0,
158    PROP_FONT_NAME,
159    PROP_PREVIEW_TEXT
160 };
161
162
163 enum {
164   FAMILY_COLUMN,
165   FACE_COLUMN,
166   PREVIEW_TEXT_COLUMN,
167   PREVIEW_TITLE_COLUMN
168 };
169
170 static void  gtk_font_selection_set_property       (GObject         *object,
171                                                     guint            prop_id,
172                                                     const GValue    *value,
173                                                     GParamSpec      *pspec);
174 static void  gtk_font_selection_get_property       (GObject         *object,
175                                                     guint            prop_id,
176                                                     GValue          *value,
177                                                     GParamSpec      *pspec);
178 static void  gtk_font_selection_finalize           (GObject         *object);
179
180 #if 0
181 static void  gtk_font_selection_screen_changed     (GtkWidget       *widget,
182                                                     GdkScreen       *previous_screen);
183 static void  gtk_font_selection_style_updated      (GtkWidget      *widget);
184 #endif
185
186 static void  gtk_font_selection_ref_family        (GtkFontSelection *fontsel,
187                                                    PangoFontFamily  *family);
188 static void  gtk_font_selection_ref_face          (GtkFontSelection *fontsel,
189                                                    PangoFontFace    *face);
190
191 static void gtk_font_selection_bootstrap_fontlist (GtkFontSelection *fontsel);
192
193 #ifndef GTK_DISABLE_DEPRECATED
194 static void update_font_list_selection            (GtkFontSelection *fontsel);
195 static void update_size_list_selection            (GtkFontSelection *fontsel);
196 static void update_face_model                     (GtkFontSelection *fontsel,
197                                                    gboolean          first);
198 #endif
199
200 G_DEFINE_TYPE (GtkFontSelection, gtk_font_selection, GTK_TYPE_VBOX)
201
202 static void
203 gtk_font_selection_class_init (GtkFontSelectionClass *klass)
204 {
205   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
206
207 #if 0
208   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
209   widget_class->screen_changed = gtk_font_selection_screen_changed;
210   widget_class->style_updated = gtk_font_selection_style_updated;
211 #endif
212
213   gobject_class->finalize = gtk_font_selection_finalize;
214   gobject_class->set_property = gtk_font_selection_set_property;
215   gobject_class->get_property = gtk_font_selection_get_property;
216
217   g_object_class_install_property (gobject_class,
218                                    PROP_FONT_NAME,
219                                    g_param_spec_string ("font-name",
220                                                         P_("Font name"),
221                                                         P_("The string that represents this font"),
222                                                         DEFAULT_FONT_NAME,
223                                                         GTK_PARAM_READWRITE));
224   g_object_class_install_property (gobject_class,
225                                    PROP_PREVIEW_TEXT,
226                                    g_param_spec_string ("preview-text",
227                                                         P_("Preview text"),
228                                                         P_("The text to display in order to demonstrate the selected font"),
229                                                         pango_language_get_sample_string (NULL),
230                                                         GTK_PARAM_READWRITE));
231
232   g_type_class_add_private (klass, sizeof (GtkFontSelectionPrivate));
233 }
234
235 static void 
236 gtk_font_selection_set_property (GObject         *object,
237                                  guint            prop_id,
238                                  const GValue    *value,
239                                  GParamSpec      *pspec)
240 {
241   GtkFontSelection *fontsel;
242
243   fontsel = GTK_FONT_SELECTION (object);
244
245   switch (prop_id)
246     {
247     case PROP_FONT_NAME:
248       gtk_font_selection_set_font_name (fontsel, g_value_get_string (value));
249       break;
250     case PROP_PREVIEW_TEXT:
251       gtk_font_selection_set_preview_text (fontsel, g_value_get_string (value));
252       break;
253     default:
254       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
255       break;
256     }
257 }
258
259 static void
260 gtk_font_selection_get_property (GObject         *object,
261                                  guint            prop_id,
262                                  GValue          *value,
263                                  GParamSpec      *pspec)
264 {
265   GtkFontSelection *fontsel;
266
267   fontsel = GTK_FONT_SELECTION (object);
268
269   switch (prop_id)
270     {
271     case PROP_FONT_NAME:
272       g_value_take_string (value, gtk_font_selection_get_font_name (fontsel));
273       break;
274     case PROP_PREVIEW_TEXT:
275       g_value_set_string (value, gtk_font_selection_get_preview_text (fontsel));
276       break;
277     default:
278       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
279       break;
280     }
281 }
282
283 void
284 refilter_and_focus (GtkFontSelectionPrivate *priv)
285 {
286   GtkTreeIter  iter;
287   GtkTreeView *treeview = GTK_TREE_VIEW (priv->family_face_list);
288   GtkTreePath *path = gtk_tree_path_new ();
289
290   gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
291
292   if (!path)
293     return;
294
295   gtk_tree_view_get_cursor (treeview, &path, NULL);
296
297   if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->filter), &iter, path))
298     {
299       gtk_tree_path_free (path);
300       return;
301     }
302
303   gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0.0, 0.0);
304   gtk_tree_path_free (path);
305 }
306
307 void
308 deleted_text_cb (GtkEntryBuffer *buffer,
309                  guint           position,
310                  guint           n_chars,
311                  gpointer        user_data)
312 {
313   GtkFontSelectionPrivate *priv  = (GtkFontSelectionPrivate*)user_data;
314   GtkWidget               *entry = priv->search_entry;
315   
316   if (gtk_entry_buffer_get_length (buffer) == 0)
317     {
318       gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
319                                      GTK_ENTRY_ICON_SECONDARY,
320                                      GTK_STOCK_FIND);
321     }
322
323   gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
324 }
325
326 void
327 inserted_text_cb (GtkEntryBuffer *buffer,
328                   guint           position,
329                   gchar          *chars,
330                   guint           n_chars,
331                   gpointer        user_data) 
332 {
333   GtkFontSelectionPrivate *priv  = (GtkFontSelectionPrivate*)user_data;
334   GtkWidget               *entry = priv->search_entry;
335
336   if (g_strcmp0 (gtk_entry_get_icon_stock (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY),
337                  GTK_STOCK_CLEAR))
338     gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
339                                    GTK_ENTRY_ICON_SECONDARY,
340                                    GTK_STOCK_CLEAR);
341
342
343   gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
344 }
345
346 void
347 icon_press_cb (GtkEntry             *entry,
348                GtkEntryIconPosition  pos,
349                GdkEvent             *event,
350                gpointer              user_data)
351 {
352   gtk_entry_buffer_delete_text (gtk_entry_get_buffer (entry), 0, -1);
353 }
354
355 void
356 slider_change_cb (GtkAdjustment *adjustment, gpointer data)
357 {
358   GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*)data;
359
360   /* If we set the silder value manually, we ignore this callback */
361   if (priv->ignore_slider)
362     {
363       priv->ignore_slider = FALSE;
364       return;
365     }
366
367   gtk_adjustment_set_value (gtk_spin_button_get_adjustment( GTK_SPIN_BUTTON(priv->size_spin)),
368                             gtk_adjustment_get_value (adjustment));
369 }
370
371 void
372 spin_change_cb (GtkAdjustment *adjustment, gpointer data)
373 {
374   PangoFontDescription    *desc;
375   GtkFontSelection        *fontsel = (GtkFontSelection*)data;
376   GtkFontSelectionPrivate *priv    = fontsel->priv;
377
378   gdouble size = gtk_adjustment_get_value (adjustment);
379   
380   GtkAdjustment *slider_adj = gtk_range_get_adjustment (GTK_RANGE (priv->size_slider));
381
382   /* We ignore the slider value change callback for both of this set_value call */
383   priv->ignore_slider = TRUE;
384   if (size < gtk_adjustment_get_lower (slider_adj))
385     gtk_adjustment_set_value (slider_adj, gtk_adjustment_get_lower (slider_adj));
386   else if (size > gtk_adjustment_get_upper (slider_adj))
387     gtk_adjustment_set_value (slider_adj, gtk_adjustment_get_upper (slider_adj));
388   else
389     gtk_adjustment_set_value (slider_adj, size);
390
391   priv->size = ((gint)gtk_adjustment_get_value (adjustment)) * PANGO_SCALE;
392
393   desc = pango_context_get_font_description (gtk_widget_get_pango_context (priv->preview));
394   pango_font_description_set_size (desc, priv->size);
395   gtk_widget_override_font (priv->preview, desc);
396
397
398 #ifndef GTK_DISABLE_DEPRECATED
399   priv->ignore_size = TRUE;
400   update_size_list_selection (fontsel);
401 #endif /* GTK_DISABLE_DEPRECATED */
402
403   gtk_widget_queue_draw (priv->preview);
404 }
405
406 void
407 set_range_marks (GtkFontSelectionPrivate *priv,
408                  GtkWidget* size_slider,
409                  gint* sizes,
410                  gint length)
411 {
412   GtkAdjustment *adj;
413   gint i;
414   gdouble value;
415   
416   if (length<2)
417     {
418       sizes = (gint*)font_sizes;
419       length = FONT_SIZES_LENGTH;
420     }
421   
422   gtk_scale_clear_marks (GTK_SCALE (size_slider));
423   
424   adj = gtk_range_get_adjustment(GTK_RANGE (size_slider));
425   
426   gtk_adjustment_set_lower (adj, (gdouble) sizes[0]);
427   gtk_adjustment_set_upper (adj, (gdouble) sizes[length-1]);
428
429   value = gtk_adjustment_get_value (adj);
430   if (value > (gdouble) sizes[length-1])
431     {
432       gtk_adjustment_set_value (adj, (gdouble) sizes[length-1]);
433       priv->ignore_slider = TRUE;
434     }
435   else if (value < (gdouble) sizes[0])
436     {
437       gtk_adjustment_set_value (adj, (gdouble) sizes[0]);
438       priv->ignore_slider = TRUE; 
439     }
440   
441 #ifndef GTK_DISABLE_DEPRECATED
442   if (!priv->_size_model)
443     {
444       for (i=0; i<length; i++)
445         gtk_scale_add_mark (GTK_SCALE (size_slider),
446                             (gdouble) sizes[i],
447                             GTK_POS_BOTTOM, NULL);
448     }
449   else
450     {
451       GString *size_str = g_string_new (NULL);
452       gtk_list_store_clear (priv->_size_model);
453       
454       for (i=0; i<length; i++)
455         {
456           GtkTreeIter iter;
457
458           g_string_printf (size_str, "%d", sizes[i]);
459
460           gtk_scale_add_mark (GTK_SCALE (size_slider),
461                               (gdouble) sizes[i],
462                               GTK_POS_BOTTOM, NULL);
463
464           gtk_list_store_append (priv->_size_model, &iter);
465           gtk_list_store_set (priv->_size_model, &iter,
466                               0, sizes[i],
467                               1, size_str->str,
468                               -1);
469         }
470       g_string_free (size_str, TRUE);
471     }
472 #else
473   for (i=0; i<length; i++)
474     gtk_scale_add_mark (GTK_SCALE (size_slider),
475                         (gdouble) sizes[i],
476                         GTK_POS_BOTTOM, NULL);
477 #endif
478 }
479
480 void
481 cursor_changed_cb (GtkTreeView *treeview, gpointer data)
482 {
483   PangoFontFamily      *family;
484   PangoFontFace        *face;
485   PangoFontDescription *desc;
486   gchar                *font_str;
487   
488   gint *sizes;
489   gint  i, n_sizes;
490
491   GtkTreeIter iter;
492   GtkTreePath *path = gtk_tree_path_new ();
493   
494   GtkFontSelection *fontsel = (GtkFontSelection*)data;
495   
496   gtk_tree_view_get_cursor (treeview, &path, NULL);
497   
498   if (!path)
499     return;
500
501   if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (fontsel->priv->filter), &iter, path))
502     {
503       gtk_tree_path_free (path);
504       return;
505     } 
506   
507   
508   gtk_tree_model_get (GTK_TREE_MODEL (fontsel->priv->filter), &iter,
509                       FACE_COLUMN, &face,
510                       FAMILY_COLUMN, &family,
511                       -1);
512
513   gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0.0, 0.0);
514
515   gtk_tree_path_free (path);
516   path = NULL;
517   
518   if (!face || !family)
519     {
520       g_object_unref (face);
521       g_object_unref (family);
522       return;
523     }
524
525   desc = pango_font_face_describe (face);
526   pango_font_description_set_size (desc, fontsel->priv->size);
527   gtk_widget_override_font (fontsel->priv->preview, desc);
528
529   pango_font_face_list_sizes (face, &sizes, &n_sizes);
530   /* It seems not many fonts actually have a sane set of sizes */
531   for (i=0; i<n_sizes; i++)
532     sizes[i] = sizes[i] / PANGO_SCALE;
533   
534   set_range_marks (fontsel->priv, fontsel->priv->size_slider, sizes, n_sizes);
535
536   gtk_font_selection_ref_family (fontsel, family);
537   gtk_font_selection_ref_face   (fontsel, face);
538
539 #ifndef GTK_DISABLE_DEPRECATED
540   if (fontsel->priv->_font_model)
541     update_font_list_selection (fontsel);
542 #endif
543
544   font_str = pango_font_description_to_string (desc);
545   g_object_set (fontsel, "font-name", font_str, NULL);
546
547   /* Free resources */
548   g_object_unref ((gpointer)family);
549   g_object_unref ((gpointer)face);
550   pango_font_description_free(desc);
551   g_free (font_str);
552 }
553
554 gboolean
555 zoom_preview_cb (GtkWidget *scrolled_window, GdkEventScroll *event, gpointer data)
556 {
557   GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*)data;
558
559   GtkAdjustment *adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin));
560
561   if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_RIGHT)
562     gtk_adjustment_set_value (adj,
563                               gtk_adjustment_get_value (adj) +
564                               gtk_adjustment_get_step_increment (adj));
565   else if (event->direction == GDK_SCROLL_DOWN || event->direction == GDK_SCROLL_LEFT)
566     gtk_adjustment_set_value (adj,
567                               gtk_adjustment_get_value (adj) -
568                               gtk_adjustment_get_step_increment (adj));
569   return TRUE;
570 }
571
572 static void
573 gtk_font_selection_init (GtkFontSelection *fontsel)
574 {
575   GtkFontSelectionPrivate *priv;
576   PangoFontDescription    *font_desc;
577   GtkWidget               *scrolled_win;
578   GtkWidget               *preview_and_size;
579   GtkWidget               *size_controls;
580
581   fontsel->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontsel,
582                                                GTK_TYPE_FONT_SELECTION,
583                                                GtkFontSelectionPrivate);
584
585   priv = fontsel->priv;
586
587 #ifndef GTK_DISABLE_DEPRECATED
588   priv->size_list = NULL;
589   priv->font_list = NULL;
590   priv->face_list = NULL;
591
592   priv->_size_model = NULL;
593   priv->_font_model = NULL;
594   priv->_face_model = NULL;
595
596   priv->ignore_size = FALSE;
597   priv->ignore_face = FALSE;
598   priv->ignore_font = FALSE;
599 #endif /* GTK_DISABLE_DEPRECATED */
600
601   /* Getting the default size */
602   font_desc  = pango_context_get_font_description (gtk_widget_get_pango_context (GTK_WIDGET (fontsel)));
603   priv->size = pango_font_description_get_size (font_desc);
604   priv->face = NULL;
605   priv->family = NULL;
606
607   gtk_widget_push_composite_child ();
608
609   /* Creating fundamental widgets for the private struct */
610   priv->search_entry = gtk_entry_new ();
611   priv->family_face_list = gtk_tree_view_new ();
612   priv->preview = gtk_entry_new ();
613   priv->size_slider = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
614                                                 (gdouble) font_sizes[0],
615                                                 (gdouble) font_sizes[FONT_SIZES_LENGTH - 1],
616                                                 1.0);
617
618   priv->size_spin = gtk_spin_button_new_with_range (0.0, (gdouble)(G_MAXINT / PANGO_SCALE), 1.0);
619
620   /** Bootstrapping widget layout **/
621   gtk_box_set_spacing (GTK_BOX (fontsel), 6);
622   gtk_box_pack_start (GTK_BOX (fontsel), priv->search_entry, FALSE, TRUE, 0);
623
624   /* Main font family/face view */
625   scrolled_win = gtk_scrolled_window_new (NULL, NULL);
626   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
627                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
628   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
629                                        GTK_SHADOW_ETCHED_IN);
630   gtk_container_add (GTK_CONTAINER (scrolled_win), priv->family_face_list);
631
632   /* Alignment for the preview and size controls */
633   gtk_box_pack_start (GTK_BOX (fontsel), scrolled_win, TRUE, TRUE, 0);
634
635   preview_and_size = gtk_vbox_new (TRUE, 0);
636   gtk_box_set_homogeneous (GTK_BOX (preview_and_size), FALSE);
637   gtk_box_set_spacing (GTK_BOX (preview_and_size), 6);
638
639   /* The preview entry needs a scrolled window to make sure we have a */
640   scrolled_win = gtk_scrolled_window_new (NULL, NULL);
641   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
642                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
643   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
644                                        GTK_SHADOW_ETCHED_IN);
645   gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win),
646                                          priv->preview);
647   gtk_box_pack_start (GTK_BOX (preview_and_size), scrolled_win, FALSE, FALSE, 0);
648   
649   /* Setting the size requests for various widgets */
650   gtk_widget_set_size_request (GTK_WIDGET (fontsel), FONTSEL_WIDTH, FONTSEL_HEIGHT);
651   gtk_widget_set_size_request (scrolled_win,  -1, PREVIEW_HEIGHT);
652   gtk_widget_set_size_request (priv->preview, -1, PREVIEW_HEIGHT - 6);
653
654   /* Unset the frame on the preview entry */
655   gtk_entry_set_has_frame (GTK_ENTRY (priv->preview), FALSE);
656
657   /* Packing the slider and the spin in a hbox */
658   size_controls = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
659   gtk_scale_set_draw_value (GTK_SCALE (priv->size_slider), FALSE);
660   gtk_box_set_spacing (GTK_BOX (size_controls), 6);
661   gtk_box_pack_start  (GTK_BOX (size_controls), priv->size_slider, TRUE, TRUE, 0);
662   gtk_box_pack_start  (GTK_BOX (size_controls), priv->size_spin, FALSE, TRUE, 0);
663   
664   gtk_widget_set_valign (priv->size_spin, GTK_ALIGN_START);
665
666   gtk_box_pack_start (GTK_BOX (preview_and_size), size_controls, FALSE, FALSE, 0);
667
668   gtk_box_pack_start (GTK_BOX (fontsel), GTK_WIDGET(preview_and_size), FALSE, TRUE, 0);
669   
670   gtk_adjustment_set_value (gtk_range_get_adjustment (GTK_RANGE (priv->size_slider)),
671                             (gdouble)(priv->size / PANGO_SCALE));
672   gtk_adjustment_set_value (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin)),
673                             (gdouble)(priv->size / PANGO_SCALE));
674
675   gtk_widget_show_all (GTK_WIDGET (fontsel));
676   gtk_widget_hide (GTK_WIDGET (fontsel));
677
678   /* Treeview column and model bootstrapping */
679   gtk_font_selection_bootstrap_fontlist (fontsel);
680   
681   /* Set default preview text */
682   gtk_entry_set_text (GTK_ENTRY (priv->preview),
683                       pango_language_get_sample_string (NULL));
684   
685   /* Set search icon and place holder text */
686   gtk_entry_set_icon_from_stock (GTK_ENTRY (priv->search_entry),
687                                  GTK_ENTRY_ICON_SECONDARY,
688                                  GTK_STOCK_FIND);
689   gtk_entry_set_placeholder_text (GTK_ENTRY (priv->search_entry), _("Search font name"));
690   
691   /** Callback connections **/
692   /* Connect to callback for the live search text entry */
693   g_signal_connect (G_OBJECT (gtk_entry_get_buffer (GTK_ENTRY (priv->search_entry))),
694                     "deleted-text", G_CALLBACK (deleted_text_cb), priv);
695   g_signal_connect (G_OBJECT (gtk_entry_get_buffer (GTK_ENTRY (priv->search_entry))),
696                     "inserted-text", G_CALLBACK (inserted_text_cb), priv);
697   g_signal_connect (G_OBJECT (priv->search_entry),
698                     "icon-press", G_CALLBACK (icon_press_cb), priv);
699
700   /* Size controls callbacks */
701   g_signal_connect (G_OBJECT (gtk_range_get_adjustment (GTK_RANGE (priv->size_slider))),
702                     "value-changed", G_CALLBACK (slider_change_cb), priv);
703   g_signal_connect (G_OBJECT (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin))),
704                     "value-changed", G_CALLBACK (spin_change_cb), fontsel);
705   priv->ignore_slider = FALSE;
706   
707   /* Font selection callback */
708   g_signal_connect (G_OBJECT (priv->family_face_list), "cursor-changed",
709                     G_CALLBACK (cursor_changed_cb),    fontsel);
710
711   /* Zoom on preview scroll*/
712   g_signal_connect (G_OBJECT (scrolled_win),      "scroll-event",
713                     G_CALLBACK (zoom_preview_cb), priv);
714
715   g_signal_connect (G_OBJECT (priv->size_slider), "scroll-event",
716                     G_CALLBACK (zoom_preview_cb), priv);
717
718   set_range_marks (priv, priv->size_slider, (gint*)font_sizes, FONT_SIZES_LENGTH);
719
720   /* Set default focus */
721   gtk_widget_pop_composite_child();
722 }
723
724 /**
725  * gtk_font_selection_new:
726  *
727  * Creates a new #GtkFontSelection.
728  *
729  * Return value: a new #GtkFontSelection
730  */
731 GtkWidget *
732 gtk_font_selection_new (void)
733 {
734   GtkFontSelection *fontsel;
735   
736   fontsel = g_object_new (GTK_TYPE_FONT_SELECTION, NULL);
737   
738   return GTK_WIDGET (fontsel);
739 }
740
741 static int
742 cmp_families (const void *a, const void *b)
743 {
744   const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a);
745   const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b);
746
747   return g_utf8_collate (a_name, b_name);
748 }
749
750 static void 
751 populate_list (GtkTreeView* treeview, GtkListStore* model)
752 {
753   GtkStyleContext      *style_context;
754   GdkRGBA               g_color;
755   PangoColor            p_color;
756   gchar                *color_string;
757   PangoFontDescription *default_font;
758
759   GtkTreeIter   match_row;
760   GtkTreePath  *path;
761
762   gint n_families, i;  
763   PangoFontFamily **families;
764
765   GString     *tmp = g_string_new (NULL);
766   GString     *family_and_face = g_string_new (NULL);
767
768   pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (treeview)),
769                                &families,
770                                &n_families);
771
772   qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families);
773
774   gtk_list_store_clear (model);
775
776   /* Get row header font color */
777   style_context = gtk_widget_get_style_context (GTK_WIDGET (treeview));
778   gtk_style_context_get_color (style_context,
779                                GTK_STATE_FLAG_NORMAL | GTK_STATE_FLAG_INSENSITIVE,
780                                &g_color);
781
782   p_color.red   = (guint16)((gdouble)G_MAXUINT16 * g_color.red);
783   p_color.green = (guint16)((gdouble)G_MAXUINT16 * g_color.green);
784   p_color.blue  = (guint16)((gdouble)G_MAXUINT16 * g_color.blue);
785   color_string  = pango_color_to_string (&p_color);
786
787   /* Get theme font */
788   default_font  = (PangoFontDescription*) gtk_style_context_get_font (style_context,
789                                                                       GTK_STATE_NORMAL);
790
791   /* Iterate over families and faces */
792   for (i=0; i<n_families; i++)
793     {
794       GtkTreeIter     iter;
795       PangoFontFace **faces;
796       
797       int             j, n_faces;
798       const gchar    *fam_name = pango_font_family_get_name (families[i]);
799
800       pango_font_family_list_faces (families[i], &faces, &n_faces);
801       
802       for (j=0; j<n_faces; j++)
803         {
804           PangoFontDescription *pango_desc = pango_font_face_describe (faces[j]);
805           const gchar *face_name = pango_font_face_get_face_name (faces[j]);
806           gchar       *font_desc = pango_font_description_to_string (pango_desc);
807           
808           /* foreground_color, family_name, face_name, desc, sample string */
809           g_string_printf (family_and_face, "%s %s",
810                                             fam_name,
811                                             face_name);
812           
813           g_string_printf (tmp, ROW_FORMAT_STRING,
814                                 color_string,
815                                 family_and_face->str,
816                                 font_desc,
817                                 pango_language_get_sample_string (NULL));
818
819           gtk_list_store_append (model, &iter);
820           gtk_list_store_set (model, &iter,
821                               FAMILY_COLUMN, families[i],
822                               FACE_COLUMN, faces[j],
823                               PREVIEW_TITLE_COLUMN, family_and_face->str,
824                               PREVIEW_TEXT_COLUMN, tmp->str,
825                               -1);
826
827           /* Select the first font or the default font/face from the style context */
828           if ((i == 0 && j == 0) ||
829               (!strcmp (fam_name, pango_font_description_get_family (default_font)) && j == 0))
830             match_row = iter;
831
832           pango_font_description_free(pango_desc);
833           g_free (font_desc);
834         }
835
836       g_free (faces);
837     }
838
839   path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &match_row);
840
841   if (path)
842   {
843     gtk_tree_view_set_cursor (treeview, path, NULL, FALSE);
844     gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0.0, 0.0);
845     gtk_tree_path_free(path);
846   }
847
848   g_string_free (family_and_face, TRUE);
849   g_string_free (tmp, TRUE);
850   g_free (color_string);
851   g_free (families);
852 }
853
854 gboolean
855 visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
856 {
857   gboolean result = FALSE;
858   GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*) data;
859
860   const gchar *search_text = (const gchar*)gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
861   gchar       *font_name;
862   gchar       *font_name_casefold;
863   gchar       *search_text_casefold;
864
865   gtk_tree_model_get (model, iter,
866                       PREVIEW_TITLE_COLUMN, &font_name,
867                       -1);
868
869   /* Covering some corner cases to speed up the result */
870   if (font_name == NULL ||
871       strlen (search_text) > strlen (font_name))
872     {
873       g_free (font_name);
874       return FALSE;
875     }  
876   if (strlen (search_text) == 0)
877     {
878       g_free (font_name);
879       return TRUE;
880     }
881   
882   font_name_casefold = g_utf8_casefold (font_name, -1);
883   search_text_casefold = g_utf8_casefold (search_text, -1);
884   
885   if (g_strrstr (font_name_casefold, search_text_casefold))
886     result = TRUE;
887
888   g_free (search_text_casefold);
889   g_free (font_name_casefold);
890   g_free (font_name);
891   return result;
892 }
893
894 static void
895 gtk_font_selection_bootstrap_fontlist (GtkFontSelection* fontsel)
896 {
897   GtkTreeView       *treeview = GTK_TREE_VIEW (fontsel->priv->family_face_list);
898   GtkCellRenderer   *cell;
899   GtkTreeViewColumn *col;
900
901   fontsel->priv->model = gtk_list_store_new (4,
902                                              PANGO_TYPE_FONT_FAMILY,
903                                              PANGO_TYPE_FONT_FACE,
904                                              G_TYPE_STRING,
905                                              G_TYPE_STRING);
906
907   fontsel->priv->filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fontsel->priv->model),
908                                                      NULL);
909   g_object_unref (fontsel->priv->model);
910
911   gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (fontsel->priv->filter),
912                                           visible_func,
913                                           (gpointer)fontsel->priv,
914                                           NULL);
915
916   gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (fontsel->priv->filter));
917   g_object_unref (fontsel->priv->filter);
918
919   gtk_tree_view_set_rules_hint      (treeview, TRUE);
920   gtk_tree_view_set_headers_visible (treeview, FALSE);
921
922   cell = gtk_cell_renderer_text_new ();
923   col = gtk_tree_view_column_new_with_attributes ("Family",
924                                                   cell,
925                                                   "markup", PREVIEW_TEXT_COLUMN,
926                                                   NULL);
927                                                   
928   g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
929
930   gtk_tree_view_append_column (treeview, col);
931
932   populate_list (treeview, fontsel->priv->model);
933 }
934
935
936 static void
937 gtk_font_selection_finalize (GObject *object)
938 {
939   GtkFontSelection *fontsel = GTK_FONT_SELECTION (object);
940
941   gtk_font_selection_ref_family (fontsel, NULL);
942   gtk_font_selection_ref_face (fontsel, NULL);
943
944 #ifndef GTK_DISABLE_DEPRECATED
945   if (fontsel->priv->size_list)
946     {
947       g_object_unref (fontsel->priv->size_list);
948       g_object_unref (fontsel->priv->font_list);
949       g_object_unref (fontsel->priv->face_list);
950     }
951 #endif
952
953   G_OBJECT_CLASS (gtk_font_selection_parent_class)->finalize (object);
954 }
955
956 #if 0
957 static void
958 gtk_font_selection_screen_changed (GtkWidget *widget,
959                                    GdkScreen *previous_screen)
960 {
961   return;
962 }
963
964 static void
965 gtk_font_selection_style_updated (GtkWidget *widget)
966 {
967   /*GTK_WIDGET_CLASS (gtk_font_selection_parent_class)->style_updated (widget);*/
968   return;
969 }
970 #endif 
971
972 static void
973 gtk_font_selection_ref_family (GtkFontSelection *fontsel,
974                                PangoFontFamily  *family)
975 {
976   GtkFontSelectionPrivate *priv = fontsel->priv;
977
978   if (family)
979     family = g_object_ref (family);
980   if (priv->family)
981     g_object_unref (priv->family);
982   priv->family = family;
983 }
984
985 static void
986 gtk_font_selection_ref_face (GtkFontSelection *fontsel,
987                              PangoFontFace    *face)
988 {
989   GtkFontSelectionPrivate *priv = fontsel->priv;
990
991   if (face)
992     face = g_object_ref (face);
993   if (priv->face)
994     g_object_unref (priv->face);
995   priv->face = face;
996 }
997
998 #ifndef GTK_DISABLE_DEPRECATED
999 static void
1000 populate_font_model (GtkFontSelection *fontsel)
1001 {
1002   gint                      n_families, i;
1003   PangoFontFamily         **families;
1004   GtkFontSelectionPrivate  *priv = fontsel->priv;
1005   GtkTreePath              *path;
1006
1007   pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (fontsel)),
1008                                &families,
1009                                &n_families);
1010
1011   qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families);
1012
1013   gtk_list_store_clear (priv->_font_model);
1014   
1015   for (i=0; i<n_families; i++)
1016     {
1017       GtkTreeIter  iter;
1018
1019       gtk_list_store_append (priv->_font_model, &iter);
1020       gtk_list_store_set (priv->_font_model, &iter,
1021                           0, families[i],
1022                           1, pango_font_family_get_name (families[i]),
1023                           -1);
1024       if (priv->family &&
1025           !strcmp (pango_font_family_get_name (families[i]),
1026                    pango_font_family_get_name (priv->family)))
1027         {
1028           path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->_face_model),
1029                                           &iter);
1030           if (path)
1031             {
1032               GtkWidget *tv = gtk_bin_get_child (GTK_BIN (priv->font_list));
1033               gtk_tree_view_set_cursor (GTK_TREE_VIEW (tv),
1034                                         path,
1035                                         NULL,
1036                                         FALSE);
1037               gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tv),
1038                                             path, NULL, FALSE, 0.0, 0.0);
1039               gtk_tree_path_free (path);
1040             }
1041         }
1042     }
1043
1044   g_free (families);
1045 }
1046
1047 static void
1048 update_font_list_selection (GtkFontSelection *fontsel)
1049 {
1050   GtkTreeIter              iter;
1051   gboolean                 valid;
1052   GtkFontSelectionPrivate *priv = fontsel->priv;
1053   gchar                   *family_name;
1054
1055   valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->_font_model), &iter);
1056   while (valid)
1057     {
1058       GtkWidget   *tv;
1059       GtkTreePath *path;
1060       gtk_tree_model_get (GTK_TREE_MODEL (priv->_font_model), &iter,
1061                           1, &family_name,
1062                           -1);
1063       if (strcmp (family_name, pango_font_family_get_name (priv->family)))
1064         {
1065           gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->_font_model), &iter);
1066           g_free (family_name);
1067           continue;
1068         }
1069       path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->_font_model), &iter);
1070
1071       if (!path)
1072         {
1073           g_free (family_name);
1074           break;
1075         }
1076
1077       tv = gtk_bin_get_child (GTK_BIN (priv->font_list));
1078
1079       priv->ignore_font = TRUE;
1080       gtk_tree_view_set_cursor (GTK_TREE_VIEW (tv), path, NULL, FALSE);
1081       gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tv), path, NULL, FALSE, 0.0, 0.0);
1082
1083       /* Free resources */
1084       gtk_tree_path_free (path);
1085       g_free (family_name);
1086       break;
1087     }
1088
1089   update_face_model (fontsel, FALSE);
1090 }
1091
1092 static void
1093 update_face_model (GtkFontSelection *fontsel, gboolean first)
1094 {
1095   GtkFontSelectionPrivate  *priv = fontsel->priv;
1096   PangoFontFace           **faces;
1097   PangoFontDescription     *desc;
1098   gchar                    *font_str;
1099   int                       i, n_faces;
1100
1101   pango_font_family_list_faces (priv->family, &faces, &n_faces);
1102
1103   gtk_list_store_clear (priv->_face_model);
1104
1105   for (i=0; i<n_faces; i++)
1106     {
1107       GtkTreeIter  iter;
1108
1109       gtk_list_store_append (priv->_face_model, &iter);
1110       gtk_list_store_set (priv->_face_model, &iter,
1111                           0, faces[i],
1112                           1, pango_font_face_get_face_name (faces[i]),
1113                           -1);
1114
1115       if ((!first && faces[i] == priv->face) ||
1116           (first && i == 0))
1117         {
1118           GtkTreePath *path;
1119           GtkWidget *tv;
1120
1121           path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->_face_model), &iter);
1122           if (!path)
1123             continue;
1124
1125           tv = gtk_bin_get_child (GTK_BIN (priv->face_list));
1126
1127           if (!first)
1128             priv->ignore_face = TRUE;
1129
1130           gtk_tree_view_set_cursor (GTK_TREE_VIEW (tv), path, NULL, FALSE);
1131
1132           gtk_tree_path_free (path);
1133
1134           if (first)
1135               gtk_font_selection_ref_face (fontsel, faces[i]);
1136         }
1137     }
1138
1139   desc = pango_font_face_describe (priv->face);
1140   pango_font_description_set_size (desc, priv->size);
1141   font_str = pango_font_description_to_string (desc);
1142   g_object_set (fontsel, "font-name", font_str, NULL);
1143
1144   update_size_list_selection (fontsel);
1145
1146   pango_font_description_free (desc);
1147   g_free (font_str);
1148   g_free (faces);
1149 }
1150
1151 static void
1152 update_size_list_selection (GtkFontSelection *fontsel)
1153 {
1154   GtkTreeIter              iter;
1155   gboolean                 valid;
1156   GtkFontSelectionPrivate *priv = fontsel->priv;
1157   GtkWidget               *tv = gtk_bin_get_child (GTK_BIN (priv->size_list));
1158
1159   gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (tv)));
1160
1161   valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->_size_model), &iter);
1162   while (valid)
1163     {
1164       gint         size;
1165       gtk_tree_model_get (GTK_TREE_MODEL (priv->_size_model), &iter,
1166                           0, &size,
1167                           -1);
1168
1169       if (size * PANGO_SCALE == priv->size)
1170         {
1171           GtkTreePath *path;
1172
1173
1174           path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->_size_model), &iter);
1175           if (!path)
1176             break;
1177
1178  
1179           priv->ignore_size = TRUE;
1180           gtk_tree_view_set_cursor (GTK_TREE_VIEW (tv), path, NULL, FALSE);
1181
1182           gtk_tree_path_free (path);
1183           break;
1184         }
1185       valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->_size_model), &iter);
1186     }
1187 }
1188
1189
1190 static void
1191 select_family_and_face (GtkFontSelection *fontsel)
1192 {
1193   GtkTreeIter              iter;
1194   gboolean                 valid;
1195   GtkFontSelectionPrivate *priv = fontsel->priv;
1196   PangoFontFace           *face;
1197   PangoFontFamily         *family;
1198
1199   gtk_entry_set_text (GTK_ENTRY (priv->search_entry), "");
1200
1201   valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->filter), &iter);
1202   while (valid)
1203     {
1204       gtk_tree_model_get (GTK_TREE_MODEL (priv->filter), &iter,
1205                           FACE_COLUMN,   &face,
1206                           FAMILY_COLUMN, &family, 
1207                           -1);
1208
1209       if (face == priv->face && family == priv->family)
1210         {
1211           GtkTreePath *path;
1212
1213           path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->filter), &iter);
1214           if (!path)
1215           {
1216             g_object_unref (face);
1217             g_object_unref (family);
1218             break;
1219           }
1220
1221           priv->ignore_size = TRUE;
1222           gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->family_face_list), path, NULL, FALSE);
1223
1224           gtk_tree_path_free (path);
1225           g_object_unref (face);
1226           g_object_unref (family);
1227           break;
1228         }
1229
1230       g_object_unref (face);
1231       g_object_unref (family);
1232       valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->filter), &iter);
1233     }
1234 }
1235
1236
1237 static void
1238 family_list_cursor_changed_cb (GtkTreeView *treeview, gpointer data)
1239 {
1240   GtkWidget        *tv;
1241   GtkTreeIter       iter;
1242   GtkTreePath      *path;
1243   GtkFontSelection *fontsel = (GtkFontSelection*)data;
1244   PangoFontFamily  *font;
1245
1246   if (fontsel->priv->ignore_font)
1247     {
1248       fontsel->priv->ignore_font = FALSE;
1249       return;
1250     }
1251
1252   tv = gtk_bin_get_child (GTK_BIN (fontsel->priv->font_list));
1253   gtk_tree_view_get_cursor (GTK_TREE_VIEW (tv), &path, NULL);
1254
1255   if (!path)
1256     return;
1257
1258   gtk_tree_model_get_iter (GTK_TREE_MODEL (fontsel->priv->_font_model),
1259                            &iter,
1260                            path);
1261   
1262   gtk_tree_model_get (GTK_TREE_MODEL (fontsel->priv->_font_model), &iter,
1263                       0, &font,
1264                       -1);
1265
1266   gtk_font_selection_ref_family (fontsel, font);
1267   update_face_model (fontsel, TRUE);
1268
1269   fontsel->priv->ignore_font = TRUE;
1270   select_family_and_face (fontsel);
1271
1272   gtk_tree_path_free (path);
1273   g_object_unref (font);
1274 }
1275
1276 static void
1277 face_list_cursor_changed_cb (GtkTreeView *treeview, gpointer data)
1278 {
1279   GtkWidget        *tv;
1280   GtkTreeIter       iter;
1281   GtkTreePath      *path;
1282   GtkFontSelection *fontsel = (GtkFontSelection*)data;
1283   PangoFontFace    *face;
1284
1285   if (fontsel->priv->ignore_face)
1286     {
1287       fontsel->priv->ignore_face = FALSE;
1288       return;
1289     }
1290
1291   tv = gtk_bin_get_child (GTK_BIN (fontsel->priv->face_list));
1292   gtk_tree_view_get_cursor (GTK_TREE_VIEW (tv), &path, NULL);
1293
1294   if (!path)
1295     return;
1296
1297   gtk_tree_model_get_iter (GTK_TREE_MODEL (fontsel->priv->_face_model),
1298                            &iter,
1299                            path);
1300   
1301   gtk_tree_model_get (GTK_TREE_MODEL (fontsel->priv->_face_model), &iter,
1302                       0, &face,
1303                       -1);
1304
1305   gtk_font_selection_ref_face (fontsel, face);
1306
1307   fontsel->priv->ignore_face = TRUE;
1308   select_family_and_face (fontsel);
1309
1310   gtk_tree_path_free (path);
1311   g_object_unref (face);
1312 }
1313
1314 static void
1315 size_list_cursor_changed_cb (GtkTreeView *treeview, gpointer data)
1316 {
1317   GtkWidget        *tv;
1318   GtkTreeIter       iter;
1319   GtkTreePath      *path;
1320   GtkFontSelection *fontsel = (GtkFontSelection*)data;
1321   gint              value;
1322
1323   if (fontsel->priv->ignore_size)
1324     {
1325       fontsel->priv->ignore_size = FALSE;
1326       return;
1327     }
1328
1329   tv = gtk_bin_get_child (GTK_BIN (fontsel->priv->size_list));
1330   gtk_tree_view_get_cursor (GTK_TREE_VIEW (tv), &path, NULL);
1331
1332   if (!path)
1333     return;
1334
1335   gtk_tree_model_get_iter (GTK_TREE_MODEL (fontsel->priv->_size_model),
1336                            &iter,
1337                            path);
1338   
1339   gtk_tree_model_get (GTK_TREE_MODEL (fontsel->priv->_size_model), &iter,
1340                       0, &value,
1341                       -1);
1342
1343   gtk_spin_button_set_value (GTK_SPIN_BUTTON (fontsel->priv->size_spin), value);
1344   gtk_tree_path_free (path);
1345 }
1346
1347 static void
1348 initialize_deprecated_widgets (GtkFontSelection *fontsel)
1349 {
1350   GtkTreeViewColumn       *col;
1351   GtkFontSelectionPrivate *priv = fontsel->priv;
1352
1353   GtkWidget *size_list;
1354   GtkWidget *font_list;
1355   GtkWidget *face_list;
1356
1357   priv->_size_model = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING);
1358   priv->_font_model = gtk_list_store_new (2, PANGO_TYPE_FONT_FAMILY, G_TYPE_STRING);
1359   priv->_face_model = gtk_list_store_new (2, PANGO_TYPE_FONT_FACE,   G_TYPE_STRING);
1360
1361   size_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->_size_model));
1362   font_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->_font_model));
1363   face_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->_face_model));
1364
1365   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (size_list), FALSE);
1366   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (font_list), FALSE);
1367   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (face_list), FALSE);
1368
1369   g_object_unref (priv->_size_model);
1370   g_object_unref (priv->_font_model);
1371   g_object_unref (priv->_face_model);
1372
1373   col = gtk_tree_view_column_new_with_attributes ("Size",
1374                                                   gtk_cell_renderer_text_new (),
1375                                                   "text", 1,
1376                                                   NULL);
1377   gtk_tree_view_append_column (GTK_TREE_VIEW (size_list), col);
1378
1379   col = gtk_tree_view_column_new_with_attributes ("Family",
1380                                                   gtk_cell_renderer_text_new (),
1381                                                   "text", 1,
1382                                                   NULL);
1383   gtk_tree_view_append_column (GTK_TREE_VIEW (font_list), col);
1384
1385   col = gtk_tree_view_column_new_with_attributes ("Face",
1386                                                   gtk_cell_renderer_text_new (),
1387                                                   "text", 1,
1388                                                   NULL);
1389   gtk_tree_view_append_column (GTK_TREE_VIEW (face_list), col);
1390
1391
1392   priv->font_list = gtk_scrolled_window_new (NULL, NULL);
1393   priv->face_list = gtk_scrolled_window_new (NULL, NULL);
1394   priv->size_list = gtk_scrolled_window_new (NULL, NULL);
1395
1396   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->font_list),
1397                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1398   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->face_list),
1399                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1400   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->size_list),
1401                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1402
1403   gtk_container_add (GTK_CONTAINER (priv->font_list), font_list);
1404   gtk_container_add (GTK_CONTAINER (priv->face_list), face_list);
1405   gtk_container_add (GTK_CONTAINER (priv->size_list), size_list);
1406
1407   g_signal_connect (G_OBJECT (font_list), "cursor-changed",
1408                     G_CALLBACK (family_list_cursor_changed_cb), fontsel);
1409
1410   g_signal_connect (G_OBJECT (face_list), "cursor-changed",
1411                     G_CALLBACK (face_list_cursor_changed_cb), fontsel);
1412
1413   g_signal_connect (G_OBJECT (size_list), "cursor-changed",
1414                     G_CALLBACK (size_list_cursor_changed_cb), fontsel);
1415
1416   populate_font_model (fontsel);
1417   cursor_changed_cb (GTK_TREE_VIEW (priv->family_face_list), fontsel);
1418 }
1419
1420 #endif /* GTK_DISABLE_DEPRECATED */
1421
1422 /*****************************************************************************
1423  * These functions are the main public interface for getting/setting the font.
1424  *****************************************************************************/
1425
1426 /**
1427  * gtk_font_selection_get_family:
1428  * @fontsel: a #GtkFontSelection
1429  *
1430  * Gets the #PangoFontFamily representing the selected font family.
1431  *
1432  * Return value: (transfer none): A #PangoFontFamily representing the
1433  *     selected font family. Font families are a collection of font
1434  *     faces. The returned object is owned by @fontsel and must not
1435  *     be modified or freed.
1436  *
1437  * Since: 2.14
1438  */
1439 PangoFontFamily *
1440 gtk_font_selection_get_family (GtkFontSelection *fontsel)
1441 {
1442   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1443
1444   return fontsel->priv->family;
1445 }
1446
1447 /**
1448  * gtk_font_selection_get_face:
1449  * @fontsel: a #GtkFontSelection
1450  *
1451  * Gets the #PangoFontFace representing the selected font group
1452  * details (i.e. family, slant, weight, width, etc).
1453  *
1454  * Return value: (transfer none): A #PangoFontFace representing the
1455  *     selected font group details. The returned object is owned by
1456  *     @fontsel and must not be modified or freed.
1457  *
1458  * Since: 2.14
1459  */
1460 PangoFontFace *
1461 gtk_font_selection_get_face (GtkFontSelection *fontsel)
1462 {
1463   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1464
1465   return fontsel->priv->face;
1466 }
1467
1468 /**
1469  * gtk_font_selection_get_size:
1470  * @fontsel: a #GtkFontSelection
1471  *
1472  * The selected font size.
1473  *
1474  * Return value: A n integer representing the selected font size,
1475  *     or -1 if no font size is selected.
1476  *
1477  * Since: 2.14
1478  **/
1479 gint
1480 gtk_font_selection_get_size (GtkFontSelection *fontsel)
1481 {
1482   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), -1);
1483
1484   return fontsel->priv->size;
1485 }
1486
1487 /**
1488  * gtk_font_selection_get_font_name:
1489  * @fontsel: a #GtkFontSelection
1490  * 
1491  * Gets the currently-selected font name. 
1492  *
1493  * Note that this can be a different string than what you set with 
1494  * gtk_font_selection_set_font_name(), as the font selection widget may 
1495  * normalize font names and thus return a string with a different structure. 
1496  * For example, "Helvetica Italic Bold 12" could be normalized to 
1497  * "Helvetica Bold Italic 12". Use pango_font_description_equal()
1498  * if you want to compare two font descriptions.
1499  * 
1500  * Return value: (transfer full) (allow-none): A string with the name of the
1501  *     current font, or %NULL if  no font is selected. You must free this
1502  *     string with g_free().
1503  */
1504 gchar *
1505 gtk_font_selection_get_font_name (GtkFontSelection *fontsel)
1506 {
1507   if (!fontsel->priv->family)
1508     return NULL;
1509
1510   return g_strdup (pango_font_family_get_name (fontsel->priv->family));
1511 }
1512
1513 /* This sets the current font, then selecting the appropriate list rows. */
1514
1515 /**
1516  * gtk_font_selection_set_font_name:
1517  * @fontsel: a #GtkFontSelection
1518  * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
1519  * 
1520  * Sets the currently-selected font. 
1521  *
1522  * Note that the @fontsel needs to know the screen in which it will appear 
1523  * for this to work; this can be guaranteed by simply making sure that the 
1524  * @fontsel is inserted in a toplevel window before you call this function.
1525  * 
1526  * Return value: %TRUE if the font could be set successfully; %FALSE if no 
1527  *     such font exists or if the @fontsel doesn't belong to a particular 
1528  *     screen yet.
1529  */
1530 gboolean
1531 gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
1532           const gchar      *fontname)
1533 {
1534 #if 0
1535   PangoFontFamily *family = NULL;
1536   PangoFontFace *face = NULL;
1537   PangoFontDescription *new_desc;
1538 #endif
1539
1540   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), FALSE);
1541
1542   return TRUE;
1543 }
1544
1545 /**
1546  * gtk_font_selection_get_preview_text:
1547  * @fontsel: a #GtkFontSelection
1548  *
1549  * Gets the text displayed in the preview area.
1550  * 
1551  * Return value: the text displayed in the preview area. 
1552  *     This string is owned by the widget and should not be 
1553  *     modified or freed 
1554  */
1555 G_CONST_RETURN gchar*
1556 gtk_font_selection_get_preview_text (GtkFontSelection *fontsel)
1557 {
1558   return NULL;
1559 }
1560
1561
1562 /**
1563  * gtk_font_selection_set_preview_text:
1564  * @fontsel: a #GtkFontSelection
1565  * @text: the text to display in the preview area 
1566  *
1567  * Sets the text displayed in the preview area.
1568  * The @text is used to show how the selected font looks.
1569  */
1570 void
1571 gtk_font_selection_set_preview_text  (GtkFontSelection *fontsel,
1572               const gchar      *text)
1573 {
1574 #if 0
1575   GtkFontSelectionPrivate *priv;
1576
1577   g_return_if_fail (GTK_IS_FONT_SELECTION (fontsel));
1578   g_return_if_fail (text != NULL);
1579
1580   priv = fontsel->priv;
1581 #endif
1582 }
1583
1584 #ifndef GTK_DISABLE_DEPRECATED
1585
1586 /**
1587  * gtk_font_selection_get_family_list:
1588  * @fontsel: a #GtkFontSelection
1589  *
1590  * This returns the #GtkTreeView that lists font families, for
1591  * example, 'Sans', 'Serif', etc.
1592  *
1593  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1594  *
1595  * Deprecated: 3.2
1596  */
1597 GtkWidget *
1598 gtk_font_selection_get_family_list (GtkFontSelection *fontsel)
1599 {
1600   GtkFontSelectionPrivate *priv = fontsel->priv;
1601   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1602   if (!priv->font_list)
1603     initialize_deprecated_widgets (fontsel);
1604
1605   return priv->font_list;
1606 }
1607
1608 /**
1609  * gtk_font_selection_get_face_list:
1610  * @fontsel: a #GtkFontSelection
1611  *
1612  * This returns the #GtkTreeView which lists all styles available for
1613  * the selected font. For example, 'Regular', 'Bold', etc.
1614  * 
1615  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1616  *
1617  * Deprecated: 3.2
1618  */
1619 GtkWidget *
1620 gtk_font_selection_get_face_list (GtkFontSelection *fontsel)
1621 {
1622   GtkFontSelectionPrivate *priv = fontsel->priv;
1623   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1624   if (!priv->face_list)
1625     initialize_deprecated_widgets (fontsel);
1626
1627   return priv->face_list;
1628 }
1629
1630 /**
1631  * gtk_font_selection_get_size_entry:
1632  * @fontsel: a #GtkFontSelection
1633  *
1634  * This returns the #GtkEntry used to allow the user to edit the font
1635  * number manually instead of selecting it from the list of font sizes.
1636  *
1637  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1638  *
1639  * Deprecated: 3.2
1640  */
1641 GtkWidget *
1642 gtk_font_selection_get_size_entry (GtkFontSelection *fontsel)
1643 {
1644   GtkFontSelectionPrivate *priv = fontsel->priv;
1645   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1646
1647   return priv->size_spin;
1648 }
1649
1650 /**
1651  * gtk_font_selection_get_size_list:
1652  * @fontsel: a #GtkFontSelection
1653  *
1654  * This returns the #GtkTreeeView used to list font sizes.
1655  *
1656  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1657  *
1658  * Deprecated: 3.2
1659  */
1660 GtkWidget *
1661 gtk_font_selection_get_size_list (GtkFontSelection *fontsel)
1662 {
1663   GtkFontSelectionPrivate *priv = fontsel->priv;
1664   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1665   if (!priv->size_list)
1666     initialize_deprecated_widgets (fontsel);
1667
1668   return priv->size_list;
1669 }
1670
1671 /**
1672  * gtk_font_selection_get_preview_entry:
1673  * @fontsel: a #GtkFontSelection
1674  *
1675  * This returns the #GtkEntry used to display the font as a preview.
1676  *
1677  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1678  *
1679  * Deprecated: 3.2
1680  */
1681 GtkWidget *
1682 gtk_font_selection_get_preview_entry (GtkFontSelection *fontsel)
1683 {
1684   GtkFontSelectionPrivate *priv = fontsel->priv;
1685   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1686
1687   return priv->preview;
1688 }
1689
1690 #endif /* GTK_DISABLE_DEPRECATED */
1691
1692 /**
1693  * SECTION:gtkfontseldlg
1694  * @Short_description: A dialog box for selecting fonts
1695  * @Title: GtkFontSelectionDialog
1696  * @See_also: #GtkFontSelection, #GtkDialog
1697  *
1698  * The #GtkFontSelectionDialog widget is a dialog box for selecting a font.
1699  *
1700  * To set the font which is initially selected, use
1701  * gtk_font_selection_dialog_set_font_name().
1702  *
1703  * To get the selected font use gtk_font_selection_dialog_get_font_name().
1704  *
1705  * To change the text which is shown in the preview area, use
1706  * gtk_font_selection_dialog_set_preview_text().
1707  *
1708  * <refsect2 id="GtkFontSelectionDialog-BUILDER-UI">
1709  * <title>GtkFontSelectionDialog as GtkBuildable</title>
1710  * The GtkFontSelectionDialog implementation of the GtkBuildable interface
1711  * exposes the embedded #GtkFontSelection as internal child with the
1712  * name "font_selection". It also exposes the buttons with the names
1713  * "ok_button", "cancel_button" and "apply_button".
1714  * </refsect2>
1715  */
1716
1717 static void gtk_font_selection_dialog_buildable_interface_init     (GtkBuildableIface *iface);
1718 static GObject * gtk_font_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
1719                     GtkBuilder   *builder,
1720                     const gchar  *childname);
1721
1722 G_DEFINE_TYPE_WITH_CODE (GtkFontSelectionDialog, gtk_font_selection_dialog,
1723        GTK_TYPE_DIALOG,
1724        G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
1725             gtk_font_selection_dialog_buildable_interface_init))
1726
1727 static GtkBuildableIface *parent_buildable_iface;
1728
1729 static void
1730 gtk_font_selection_dialog_class_init (GtkFontSelectionDialogClass *klass)
1731 {
1732   g_type_class_add_private (klass, sizeof (GtkFontSelectionDialogPrivate));
1733 }
1734
1735 static void
1736 gtk_font_selection_dialog_init (GtkFontSelectionDialog *fontseldiag)
1737 {
1738   GtkFontSelectionDialogPrivate *priv;
1739   GtkDialog *dialog = GTK_DIALOG (fontseldiag);
1740   GtkWidget *action_area, *content_area;
1741
1742   fontseldiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontseldiag,
1743                                                    GTK_TYPE_FONT_SELECTION_DIALOG,
1744                                                    GtkFontSelectionDialogPrivate);
1745   priv = fontseldiag->priv;
1746
1747   content_area = gtk_dialog_get_content_area (dialog);
1748   action_area = gtk_dialog_get_action_area (dialog);
1749
1750   gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
1751   gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
1752   gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
1753   gtk_box_set_spacing (GTK_BOX (action_area), 6);
1754
1755   gtk_widget_push_composite_child ();
1756
1757   gtk_window_set_resizable (GTK_WINDOW (fontseldiag), TRUE);
1758
1759   /* Create the content area */
1760   priv->fontsel = gtk_font_selection_new ();
1761   gtk_container_set_border_width (GTK_CONTAINER (priv->fontsel), 5);
1762   gtk_widget_show (priv->fontsel);
1763   gtk_box_pack_start (GTK_BOX (content_area),
1764           priv->fontsel, TRUE, TRUE, 0);
1765
1766   /* Create the action area */
1767   priv->cancel_button = gtk_dialog_add_button (dialog,
1768                                                GTK_STOCK_CANCEL,
1769                                                GTK_RESPONSE_CANCEL);
1770
1771   priv->apply_button = gtk_dialog_add_button (dialog,
1772                                               GTK_STOCK_APPLY,
1773                                               GTK_RESPONSE_APPLY);
1774   gtk_widget_hide (priv->apply_button);
1775
1776   priv->ok_button = gtk_dialog_add_button (dialog,
1777                                            GTK_STOCK_OK,
1778                                            GTK_RESPONSE_OK);
1779   gtk_widget_grab_default (priv->ok_button);
1780
1781   gtk_dialog_set_alternative_button_order (GTK_DIALOG (fontseldiag),
1782              GTK_RESPONSE_OK,
1783              GTK_RESPONSE_APPLY,
1784              GTK_RESPONSE_CANCEL,
1785              -1);
1786
1787   gtk_window_set_title (GTK_WINDOW (fontseldiag),
1788                         _("Font Selection"));
1789
1790   gtk_widget_pop_composite_child ();
1791 }
1792
1793 /**
1794  * gtk_font_selection_dialog_new:
1795  * @title: the title of the dialog window 
1796  *
1797  * Creates a new #GtkFontSelectionDialog.
1798  *
1799  * Return value: a new #GtkFontSelectionDialog
1800  */
1801 GtkWidget*
1802 gtk_font_selection_dialog_new (const gchar *title)
1803 {
1804   GtkFontSelectionDialog *fontseldiag;
1805   
1806   fontseldiag = g_object_new (GTK_TYPE_FONT_SELECTION_DIALOG, NULL);
1807
1808   if (title)
1809     gtk_window_set_title (GTK_WINDOW (fontseldiag), title);
1810   
1811   return GTK_WIDGET (fontseldiag);
1812 }
1813
1814 /**
1815  * gtk_font_selection_dialog_get_font_selection:
1816  * @fsd: a #GtkFontSelectionDialog
1817  *
1818  * Retrieves the #GtkFontSelection widget embedded in the dialog.
1819  *
1820  * Returns: (transfer none): the embedded #GtkFontSelection
1821  *
1822  * Since: 2.22
1823  **/
1824 GtkWidget*
1825 gtk_font_selection_dialog_get_font_selection (GtkFontSelectionDialog *fsd)
1826 {
1827   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1828
1829   return fsd->priv->fontsel;
1830 }
1831
1832
1833 /**
1834  * gtk_font_selection_dialog_get_ok_button:
1835  * @fsd: a #GtkFontSelectionDialog
1836  *
1837  * Gets the 'OK' button.
1838  *
1839  * Return value: (transfer none): the #GtkWidget used in the dialog
1840  *     for the 'OK' button.
1841  *
1842  * Since: 2.14
1843  */
1844 GtkWidget *
1845 gtk_font_selection_dialog_get_ok_button (GtkFontSelectionDialog *fsd)
1846 {
1847   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1848
1849   return fsd->priv->ok_button;
1850 }
1851
1852 /**
1853  * gtk_font_selection_dialog_get_cancel_button:
1854  * @fsd: a #GtkFontSelectionDialog
1855  *
1856  * Gets the 'Cancel' button.
1857  *
1858  * Return value: (transfer none): the #GtkWidget used in the dialog
1859  *     for the 'Cancel' button.
1860  *
1861  * Since: 2.14
1862  */
1863 GtkWidget *
1864 gtk_font_selection_dialog_get_cancel_button (GtkFontSelectionDialog *fsd)
1865 {
1866   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1867
1868   return fsd->priv->cancel_button;
1869 }
1870
1871 static void
1872 gtk_font_selection_dialog_buildable_interface_init (GtkBuildableIface *iface)
1873 {
1874   parent_buildable_iface = g_type_interface_peek_parent (iface);
1875   iface->get_internal_child = gtk_font_selection_dialog_buildable_get_internal_child;
1876 }
1877
1878 static GObject *
1879 gtk_font_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
1880               GtkBuilder   *builder,
1881               const gchar  *childname)
1882 {
1883   GtkFontSelectionDialogPrivate *priv;
1884
1885   priv = GTK_FONT_SELECTION_DIALOG (buildable)->priv;
1886
1887   if (g_strcmp0 (childname, "ok_button") == 0)
1888     return G_OBJECT (priv->ok_button);
1889   else if (g_strcmp0 (childname, "cancel_button") == 0)
1890     return G_OBJECT (priv->cancel_button);
1891   else if (g_strcmp0 (childname, "apply_button") == 0)
1892     return G_OBJECT (priv->apply_button);
1893   else if (g_strcmp0 (childname, "font_selection") == 0)
1894     return G_OBJECT (priv->fontsel);
1895
1896   return parent_buildable_iface->get_internal_child (buildable, builder, childname);
1897 }
1898
1899 /**
1900  * gtk_font_selection_dialog_get_font_name:
1901  * @fsd: a #GtkFontSelectionDialog
1902  * 
1903  * Gets the currently-selected font name.
1904  *
1905  * Note that this can be a different string than what you set with 
1906  * gtk_font_selection_dialog_set_font_name(), as the font selection widget
1907  * may normalize font names and thus return a string with a different 
1908  * structure. For example, "Helvetica Italic Bold 12" could be normalized 
1909  * to "Helvetica Bold Italic 12".  Use pango_font_description_equal()
1910  * if you want to compare two font descriptions.
1911  * 
1912  * Return value: A string with the name of the current font, or %NULL if no 
1913  *     font is selected. You must free this string with g_free().
1914  */
1915 gchar*
1916 gtk_font_selection_dialog_get_font_name (GtkFontSelectionDialog *fsd)
1917 {
1918   GtkFontSelectionDialogPrivate *priv;
1919
1920   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1921
1922   priv = fsd->priv;
1923
1924   return gtk_font_selection_get_font_name (GTK_FONT_SELECTION (priv->fontsel));
1925 }
1926
1927 /**
1928  * gtk_font_selection_dialog_set_font_name:
1929  * @fsd: a #GtkFontSelectionDialog
1930  * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
1931  *
1932  * Sets the currently selected font. 
1933  * 
1934  * Return value: %TRUE if the font selected in @fsd is now the
1935  *     @fontname specified, %FALSE otherwise. 
1936  */
1937 gboolean
1938 gtk_font_selection_dialog_set_font_name (GtkFontSelectionDialog *fsd,
1939            const gchar          *fontname)
1940 {
1941   GtkFontSelectionDialogPrivate *priv;
1942
1943   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), FALSE);
1944   g_return_val_if_fail (fontname, FALSE);
1945
1946   priv = fsd->priv;
1947
1948   return gtk_font_selection_set_font_name (GTK_FONT_SELECTION (priv->fontsel), fontname);
1949 }
1950
1951 /**
1952  * gtk_font_selection_dialog_get_preview_text:
1953  * @fsd: a #GtkFontSelectionDialog
1954  *
1955  * Gets the text displayed in the preview area.
1956  * 
1957  * Return value: the text displayed in the preview area. 
1958  *     This string is owned by the widget and should not be 
1959  *     modified or freed 
1960  */
1961 G_CONST_RETURN gchar*
1962 gtk_font_selection_dialog_get_preview_text (GtkFontSelectionDialog *fsd)
1963 {
1964   GtkFontSelectionDialogPrivate *priv;
1965
1966   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1967
1968   priv = fsd->priv;
1969
1970   return gtk_font_selection_get_preview_text (GTK_FONT_SELECTION (priv->fontsel));
1971 }
1972
1973 /**
1974  * gtk_font_selection_dialog_set_preview_text:
1975  * @fsd: a #GtkFontSelectionDialog
1976  * @text: the text to display in the preview area
1977  *
1978  * Sets the text displayed in the preview area. 
1979  */
1980 void
1981 gtk_font_selection_dialog_set_preview_text (GtkFontSelectionDialog *fsd,
1982               const gchar            *text)
1983 {
1984   GtkFontSelectionDialogPrivate *priv;
1985
1986   g_return_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd));
1987   g_return_if_fail (text != NULL);
1988
1989   priv = fsd->priv;
1990
1991   gtk_font_selection_set_preview_text (GTK_FONT_SELECTION (priv->fontsel), text);
1992 }