]> Pileus Git - ~andy/gtk/blob - gtk/gtkfontsel.c
Don't use *DISABLE_DEPRECATED guards
[~andy/gtk] / gtk / gtkfontsel.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 #define GDK_DISABLE_DEPRECATION_WARNINGS
41
42 #include "gtkfontsel.h"
43
44 #include "gtkbutton.h"
45 #include "gtkcellrenderertext.h"
46 #include "gtkentry.h"
47 #include "gtkframe.h"
48 #include "gtklabel.h"
49 #include "gtkliststore.h"
50 #include "gtkstock.h"
51 #include "gtktable.h"
52 #include "gtktreeselection.h"
53 #include "gtktreeview.h"
54 #include "gtkscrolledwindow.h"
55 #include "gtkintl.h"
56 #include "gtkaccessible.h"
57 #include "gtkbuildable.h"
58 #include "gtkorientable.h"
59 #include "gtkprivate.h"
60
61
62 /**
63  * SECTION:gtkfontsel
64  * @Short_description: Deprecated widget for selecting fonts
65  * @Title: GtkFontSelection
66  * @See_also: #GtkFontSelectionDialog, #GtkFontChooser
67  *
68  * The #GtkFontSelection widget lists the available fonts, styles and sizes,
69  * allowing the user to select a font.
70  * It is used in the #GtkFontSelectionDialog widget to provide a dialog box for
71  * selecting fonts.
72  *
73  * To set the font which is initially selected, use
74  * gtk_font_selection_set_font_name().
75  *
76  * To get the selected font use gtk_font_selection_get_font_name().
77  *
78  * To change the text which is shown in the preview area, use
79  * gtk_font_selection_set_preview_text().
80  *
81  * In GTK+ 3.2, #GtkFontSelection has been deprecated in favor of
82  * #GtkFontChooser.
83  */
84
85
86 struct _GtkFontSelectionPrivate
87 {
88   GtkWidget *font_entry;        /* Used _get_family_entry() for consistency, -mr */
89   GtkWidget *font_style_entry;  /* Used _get_face_entry() for consistency, -mr */
90
91   GtkWidget *size_entry;
92   GtkWidget *preview_entry;
93
94   GtkWidget *family_list;
95   GtkWidget *face_list;
96   GtkWidget *size_list;
97
98   PangoFontFamily *family;      /* Current family */
99   PangoFontFace *face;          /* Current face */
100
101   gint size;
102 };
103
104
105 struct _GtkFontSelectionDialogPrivate
106 {
107   GtkWidget *fontsel;
108
109   GtkWidget *ok_button;
110   GtkWidget *apply_button;
111   GtkWidget *cancel_button;
112 };
113
114
115 /* We don't enable the font and style entries because they don't add
116  * much in terms of visible effect and have a weird effect on keynav.
117  * the Windows font selector has entries similarly positioned but they
118  * act in conjunction with the associated lists to form a single focus
119  * location.
120  */
121 #undef INCLUDE_FONT_ENTRIES
122
123 /* This is the default text shown in the preview entry, though the user
124    can set it. Remember that some fonts only have capital letters. */
125 #define PREVIEW_TEXT N_("abcdefghijk ABCDEFGHIJK")
126
127 #define DEFAULT_FONT_NAME "Sans 10"
128
129 /* This is the initial and maximum height of the preview entry (it expands
130    when large font sizes are selected). Initial height is also the minimum. */
131 #define INITIAL_PREVIEW_HEIGHT 44
132 #define MAX_PREVIEW_HEIGHT 300
133
134 /* These are the sizes of the font, style & size lists. */
135 #define FONT_LIST_HEIGHT        136
136 #define FONT_LIST_WIDTH         190
137 #define FONT_STYLE_LIST_WIDTH   170
138 #define FONT_SIZE_LIST_WIDTH    60
139
140 /* These are what we use as the standard font sizes, for the size list.
141  */
142 static const guint16 font_sizes[] = {
143   6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 26, 28,
144   32, 36, 40, 48, 56, 64, 72
145 };
146
147 enum {
148    PROP_0,
149    PROP_FONT_NAME,
150    PROP_PREVIEW_TEXT
151 };
152
153
154 enum {
155   FAMILY_COLUMN,
156   FAMILY_NAME_COLUMN
157 };
158
159 enum {
160   FACE_COLUMN,
161   FACE_NAME_COLUMN
162 };
163
164 enum {
165   SIZE_COLUMN
166 };
167
168 static void    gtk_font_selection_set_property       (GObject         *object,
169                                                       guint            prop_id,
170                                                       const GValue    *value,
171                                                       GParamSpec      *pspec);
172 static void    gtk_font_selection_get_property       (GObject         *object,
173                                                       guint            prop_id,
174                                                       GValue          *value,
175                                                       GParamSpec      *pspec);
176 static void    gtk_font_selection_finalize           (GObject         *object);
177 static void    gtk_font_selection_screen_changed     (GtkWidget       *widget,
178                                                       GdkScreen       *previous_screen);
179 static void    gtk_font_selection_style_updated      (GtkWidget      *widget);
180
181 /* These are the callbacks & related functions. */
182 static void     gtk_font_selection_select_font           (GtkTreeSelection *selection,
183                                                           gpointer          data);
184 static void     gtk_font_selection_show_available_fonts  (GtkFontSelection *fs);
185
186 static void     gtk_font_selection_show_available_styles (GtkFontSelection *fs);
187 static void     gtk_font_selection_select_best_style     (GtkFontSelection *fs,
188                                                           gboolean          use_first);
189 static void     gtk_font_selection_select_style          (GtkTreeSelection *selection,
190                                                           gpointer          data);
191
192 static void     gtk_font_selection_select_best_size      (GtkFontSelection *fs);
193 static void     gtk_font_selection_show_available_sizes  (GtkFontSelection *fs,
194                                                           gboolean          first_time);
195 static void     gtk_font_selection_size_activate         (GtkWidget        *w,
196                                                           gpointer          data);
197 static gboolean gtk_font_selection_size_focus_out        (GtkWidget        *w,
198                                                           GdkEventFocus    *event,
199                                                           gpointer          data);
200 static void     gtk_font_selection_select_size           (GtkTreeSelection *selection,
201                                                           gpointer          data);
202
203 static void     gtk_font_selection_scroll_on_map         (GtkWidget        *w,
204                                                           gpointer          data);
205
206 static void     gtk_font_selection_preview_changed       (GtkWidget        *entry,
207                                                           GtkFontSelection *fontsel);
208 static void     gtk_font_selection_scroll_to_selection   (GtkFontSelection *fontsel);
209
210
211 /* Misc. utility functions. */
212 static void    gtk_font_selection_load_font          (GtkFontSelection *fs);
213 static void    gtk_font_selection_update_preview     (GtkFontSelection *fs);
214
215 static PangoFontDescription *gtk_font_selection_get_font_description (GtkFontSelection *fontsel);
216 static gboolean gtk_font_selection_select_font_desc  (GtkFontSelection      *fontsel,
217                                                       PangoFontDescription  *new_desc,
218                                                       PangoFontFamily      **pfamily,
219                                                       PangoFontFace        **pface);
220 static void     gtk_font_selection_reload_fonts          (GtkFontSelection *fontsel);
221 static void     gtk_font_selection_ref_family            (GtkFontSelection *fontsel,
222                                                           PangoFontFamily  *family);
223 static void     gtk_font_selection_ref_face              (GtkFontSelection *fontsel,
224                                                           PangoFontFace    *face);
225
226 G_DEFINE_TYPE (GtkFontSelection, gtk_font_selection, GTK_TYPE_BOX)
227
228 static void
229 gtk_font_selection_class_init (GtkFontSelectionClass *klass)
230 {
231   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
232   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
233
234   gobject_class->finalize = gtk_font_selection_finalize;
235   gobject_class->set_property = gtk_font_selection_set_property;
236   gobject_class->get_property = gtk_font_selection_get_property;
237
238   widget_class->screen_changed = gtk_font_selection_screen_changed;
239   widget_class->style_updated = gtk_font_selection_style_updated;
240    
241   g_object_class_install_property (gobject_class,
242                                    PROP_FONT_NAME,
243                                    g_param_spec_string ("font-name",
244                                                         P_("Font name"),
245                                                         P_("The string that represents this font"),
246                                                         DEFAULT_FONT_NAME,
247                                                         GTK_PARAM_READWRITE));
248   g_object_class_install_property (gobject_class,
249                                    PROP_PREVIEW_TEXT,
250                                    g_param_spec_string ("preview-text",
251                                                         P_("Preview text"),
252                                                         P_("The text to display in order to demonstrate the selected font"),
253                                                         _(PREVIEW_TEXT),
254                                                         GTK_PARAM_READWRITE));
255
256   g_type_class_add_private (klass, sizeof (GtkFontSelectionPrivate));
257 }
258
259 static void 
260 gtk_font_selection_set_property (GObject         *object,
261                                  guint            prop_id,
262                                  const 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       gtk_font_selection_set_font_name (fontsel, g_value_get_string (value));
273       break;
274     case PROP_PREVIEW_TEXT:
275       gtk_font_selection_set_preview_text (fontsel, g_value_get_string (value));
276       break;
277     default:
278       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
279       break;
280     }
281 }
282
283 static void gtk_font_selection_get_property (GObject         *object,
284                                              guint            prop_id,
285                                              GValue          *value,
286                                              GParamSpec      *pspec)
287 {
288   GtkFontSelection *fontsel;
289
290   fontsel = GTK_FONT_SELECTION (object);
291
292   switch (prop_id)
293     {
294     case PROP_FONT_NAME:
295       g_value_take_string (value, gtk_font_selection_get_font_name (fontsel));
296       break;
297     case PROP_PREVIEW_TEXT:
298       g_value_set_string (value, gtk_font_selection_get_preview_text (fontsel));
299       break;
300     default:
301       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
302       break;
303     }
304 }
305
306 /* Handles key press events on the lists, so that we can trap Enter to
307  * activate the default button on our own.
308  */
309 static gboolean
310 list_row_activated (GtkWidget *widget)
311 {
312   GtkWidget *default_widget, *focus_widget;
313   GtkWindow *window;
314   
315   window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (widget)));
316   if (!gtk_widget_is_toplevel (GTK_WIDGET (window)))
317     window = NULL;
318
319   if (window)
320     {
321       default_widget = gtk_window_get_default_widget (window);
322       focus_widget = gtk_window_get_focus (window);
323
324       if (widget != default_widget &&
325           !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
326         gtk_window_activate_default (window);
327     }
328
329   return TRUE;
330 }
331
332 static void
333 gtk_font_selection_init (GtkFontSelection *fontsel)
334 {
335   GtkFontSelectionPrivate *priv;
336   GtkWidget *scrolled_win;
337   GtkWidget *text_box;
338   GtkWidget *table, *label;
339   GtkWidget *font_label, *style_label;
340   GtkWidget *vbox;
341   GtkListStore *model;
342   GtkTreeViewColumn *column;
343   GList *focus_chain = NULL;
344   AtkObject *atk_obj;
345
346   fontsel->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontsel,
347                                                GTK_TYPE_FONT_SELECTION,
348                                                GtkFontSelectionPrivate);
349   priv = fontsel->priv;
350
351   gtk_orientable_set_orientation (GTK_ORIENTABLE (fontsel),
352                                   GTK_ORIENTATION_VERTICAL);
353
354   gtk_widget_push_composite_child ();
355
356   gtk_box_set_spacing (GTK_BOX (fontsel), 12);
357   priv->size = 12 * PANGO_SCALE;
358   
359   /* Create the table of font, style & size. */
360   table = gtk_table_new (3, 3, FALSE);
361   gtk_widget_show (table);
362   gtk_table_set_row_spacings (GTK_TABLE (table), 6);
363   gtk_table_set_col_spacings (GTK_TABLE (table), 12);
364   gtk_box_pack_start (GTK_BOX (fontsel), table, TRUE, TRUE, 0);
365
366 #ifdef INCLUDE_FONT_ENTRIES
367   priv->font_entry = gtk_entry_new ();
368   gtk_editable_set_editable (GTK_EDITABLE (priv->font_entry), FALSE);
369   gtk_widget_set_size_request (priv->font_entry, 20, -1);
370   gtk_widget_show (priv->font_entry);
371   gtk_table_attach (GTK_TABLE (table), priv->font_entry, 0, 1, 1, 2,
372                     GTK_FILL, 0, 0, 0);
373   
374   priv->font_style_entry = gtk_entry_new ();
375   gtk_editable_set_editable (GTK_EDITABLE (priv->font_style_entry), FALSE);
376   gtk_widget_set_size_request (priv->font_style_entry, 20, -1);
377   gtk_widget_show (priv->font_style_entry);
378   gtk_table_attach (GTK_TABLE (table), priv->font_style_entry, 1, 2, 1, 2,
379                     GTK_FILL, 0, 0, 0);
380 #endif /* INCLUDE_FONT_ENTRIES */
381   
382   priv->size_entry = gtk_entry_new ();
383   gtk_widget_set_size_request (priv->size_entry, 20, -1);
384   gtk_widget_show (priv->size_entry);
385   gtk_table_attach (GTK_TABLE (table), priv->size_entry, 2, 3, 1, 2,
386                     GTK_FILL, 0, 0, 0);
387   g_signal_connect (priv->size_entry, "activate",
388                     G_CALLBACK (gtk_font_selection_size_activate),
389                     fontsel);
390   g_signal_connect_after (priv->size_entry, "focus-out-event",
391                           G_CALLBACK (gtk_font_selection_size_focus_out),
392                           fontsel);
393   
394   font_label = gtk_label_new_with_mnemonic (_("_Family:"));
395   gtk_widget_set_halign (font_label, GTK_ALIGN_START);
396   gtk_widget_set_valign (font_label, GTK_ALIGN_CENTER);
397   gtk_widget_show (font_label);
398   gtk_table_attach (GTK_TABLE (table), font_label, 0, 1, 0, 1,
399                     GTK_FILL, 0, 0, 0);  
400
401   style_label = gtk_label_new_with_mnemonic (_("_Style:"));
402   gtk_widget_set_halign (style_label, GTK_ALIGN_START);
403   gtk_widget_set_valign (style_label, GTK_ALIGN_CENTER);
404   gtk_widget_show (style_label);
405   gtk_table_attach (GTK_TABLE (table), style_label, 1, 2, 0, 1,
406                     GTK_FILL, 0, 0, 0);
407   
408   label = gtk_label_new_with_mnemonic (_("Si_ze:"));
409   gtk_label_set_mnemonic_widget (GTK_LABEL (label),
410                                  priv->size_entry);
411   gtk_widget_set_halign (label, GTK_ALIGN_START);
412   gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
413   gtk_widget_show (label);
414   gtk_table_attach (GTK_TABLE (table), label, 2, 3, 0, 1,
415                     GTK_FILL, 0, 0, 0);
416   
417   
418   /* Create the lists  */
419
420   model = gtk_list_store_new (2,
421                               G_TYPE_OBJECT,  /* FAMILY_COLUMN */
422                               G_TYPE_STRING); /* FAMILY_NAME_COLUMN */
423   priv->family_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
424   g_object_unref (model);
425
426   g_signal_connect (priv->family_list, "row-activated",
427                     G_CALLBACK (list_row_activated), fontsel);
428
429   column = gtk_tree_view_column_new_with_attributes ("Family",
430                                                      gtk_cell_renderer_text_new (),
431                                                      "text", FAMILY_NAME_COLUMN,
432                                                      NULL);
433   gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
434   gtk_tree_view_append_column (GTK_TREE_VIEW (priv->family_list), column);
435
436   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->family_list), FALSE);
437   gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->family_list)),
438                                GTK_SELECTION_BROWSE);
439   
440   gtk_label_set_mnemonic_widget (GTK_LABEL (font_label), priv->family_list);
441
442   scrolled_win = gtk_scrolled_window_new (NULL, NULL);
443   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), GTK_SHADOW_IN);
444   gtk_widget_set_size_request (scrolled_win,
445                                FONT_LIST_WIDTH, FONT_LIST_HEIGHT);
446   gtk_container_add (GTK_CONTAINER (scrolled_win), priv->family_list);
447   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
448                                   GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
449   gtk_widget_show (priv->family_list);
450   gtk_widget_show (scrolled_win);
451
452   gtk_table_attach (GTK_TABLE (table), scrolled_win, 0, 1, 1, 3,
453                     GTK_EXPAND | GTK_FILL,
454                     GTK_EXPAND | GTK_FILL, 0, 0);
455   focus_chain = g_list_append (focus_chain, scrolled_win);
456   
457   model = gtk_list_store_new (2,
458                               G_TYPE_OBJECT,  /* FACE_COLUMN */
459                               G_TYPE_STRING); /* FACE_NAME_COLUMN */
460   priv->face_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
461   g_object_unref (model);
462   g_signal_connect (priv->face_list, "row-activated",
463                     G_CALLBACK (list_row_activated), fontsel);
464
465   gtk_label_set_mnemonic_widget (GTK_LABEL (style_label), priv->face_list);
466
467   column = gtk_tree_view_column_new_with_attributes ("Face",
468                                                      gtk_cell_renderer_text_new (),
469                                                      "text", FACE_NAME_COLUMN,
470                                                      NULL);
471   gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
472   gtk_tree_view_append_column (GTK_TREE_VIEW (priv->face_list), column);
473
474   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->face_list), FALSE);
475   gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->face_list)),
476                                GTK_SELECTION_BROWSE);
477   
478   scrolled_win = gtk_scrolled_window_new (NULL, NULL);
479   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), GTK_SHADOW_IN);
480   gtk_widget_set_size_request (scrolled_win,
481                                FONT_STYLE_LIST_WIDTH, FONT_LIST_HEIGHT);
482   gtk_container_add (GTK_CONTAINER (scrolled_win), priv->face_list);
483   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
484                                   GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
485   gtk_widget_show (priv->face_list);
486   gtk_widget_show (scrolled_win);
487   gtk_table_attach (GTK_TABLE (table), scrolled_win, 1, 2, 1, 3,
488                     GTK_EXPAND | GTK_FILL,
489                     GTK_EXPAND | GTK_FILL, 0, 0);
490   focus_chain = g_list_append (focus_chain, scrolled_win);
491   
492   focus_chain = g_list_append (focus_chain, priv->size_entry);
493
494   model = gtk_list_store_new (1, G_TYPE_INT);
495   priv->size_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
496   g_object_unref (model);
497   g_signal_connect (priv->size_list, "row-activated",
498                     G_CALLBACK (list_row_activated), fontsel);
499
500   column = gtk_tree_view_column_new_with_attributes ("Size",
501                                                      gtk_cell_renderer_text_new (),
502                                                      "text", SIZE_COLUMN,
503                                                      NULL);
504   gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
505   gtk_tree_view_append_column (GTK_TREE_VIEW (priv->size_list), column);
506
507   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->size_list), FALSE);
508   gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->size_list)),
509                                GTK_SELECTION_BROWSE);
510   
511   scrolled_win = gtk_scrolled_window_new (NULL, NULL);
512   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), GTK_SHADOW_IN);
513   gtk_container_add (GTK_CONTAINER (scrolled_win), priv->size_list);
514   gtk_widget_set_size_request (scrolled_win, -1, FONT_LIST_HEIGHT);
515   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
516                                   GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
517   gtk_widget_show (priv->size_list);
518   gtk_widget_show (scrolled_win);
519   gtk_table_attach (GTK_TABLE (table), scrolled_win, 2, 3, 2, 3,
520                     GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
521   focus_chain = g_list_append (focus_chain, scrolled_win);
522
523   gtk_container_set_focus_chain (GTK_CONTAINER (table), focus_chain);
524   g_list_free (focus_chain);
525   
526   /* Insert the fonts. */
527   g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->family_list)), "changed",
528                     G_CALLBACK (gtk_font_selection_select_font), fontsel);
529
530   g_signal_connect_after (priv->family_list, "map",
531                           G_CALLBACK (gtk_font_selection_scroll_on_map),
532                           fontsel);
533   
534   g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->face_list)), "changed",
535                     G_CALLBACK (gtk_font_selection_select_style), fontsel);
536
537   g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->size_list)), "changed",
538                     G_CALLBACK (gtk_font_selection_select_size), fontsel);
539   atk_obj = gtk_widget_get_accessible (priv->size_list);
540   if (GTK_IS_ACCESSIBLE (atk_obj))
541     {
542       /* Accessibility support is enabled.
543        * Make the label ATK_RELATON_LABEL_FOR for the size list as well.
544        */
545       AtkObject *atk_label;
546       AtkRelationSet *relation_set;
547       AtkRelation *relation;
548       AtkObject *obj_array[1];
549
550       atk_label = gtk_widget_get_accessible (label);
551       relation_set = atk_object_ref_relation_set (atk_obj);
552       relation = atk_relation_set_get_relation_by_type (relation_set, ATK_RELATION_LABELLED_BY);
553       if (relation)
554         {
555           atk_relation_add_target (relation, atk_label);
556         }
557       else 
558         {
559           obj_array[0] = atk_label;
560           relation = atk_relation_new (obj_array, 1, ATK_RELATION_LABELLED_BY);
561           atk_relation_set_add (relation_set, relation);
562         }
563       g_object_unref (relation_set);
564
565       relation_set = atk_object_ref_relation_set (atk_label);
566       relation = atk_relation_set_get_relation_by_type (relation_set, ATK_RELATION_LABEL_FOR);
567       if (relation)
568         {
569           atk_relation_add_target (relation, atk_obj);
570         }
571       else 
572         {
573           obj_array[0] = atk_obj;
574           relation = atk_relation_new (obj_array, 1, ATK_RELATION_LABEL_FOR);
575           atk_relation_set_add (relation_set, relation);
576         }
577       g_object_unref (relation_set);
578     }
579
580   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
581   gtk_widget_show (vbox);
582   gtk_box_pack_start (GTK_BOX (fontsel), vbox, FALSE, TRUE, 0);
583   
584   /* create the text entry widget */
585   label = gtk_label_new_with_mnemonic (_("_Preview:"));
586   gtk_widget_set_halign (label, GTK_ALIGN_START);
587   gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
588   gtk_widget_show (label);
589   gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
590
591   text_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
592   gtk_widget_show (text_box);
593   gtk_box_pack_start (GTK_BOX (vbox), text_box, FALSE, TRUE, 0);
594   
595   priv->preview_entry = gtk_entry_new ();
596   gtk_label_set_mnemonic_widget (GTK_LABEL (label), priv->preview_entry);
597   gtk_entry_set_text (GTK_ENTRY (priv->preview_entry), _(PREVIEW_TEXT));
598   
599   gtk_widget_show (priv->preview_entry);
600   g_signal_connect (priv->preview_entry, "changed",
601                     G_CALLBACK (gtk_font_selection_preview_changed), fontsel);
602   gtk_widget_set_size_request (priv->preview_entry,
603                                -1, INITIAL_PREVIEW_HEIGHT);
604   gtk_box_pack_start (GTK_BOX (text_box), priv->preview_entry,
605                       TRUE, TRUE, 0);
606   gtk_widget_pop_composite_child();
607 }
608
609 /**
610  * gtk_font_selection_new:
611  *
612  * Creates a new #GtkFontSelection.
613  *
614  * Return value: a n ew #GtkFontSelection
615  */
616 GtkWidget *
617 gtk_font_selection_new (void)
618 {
619   GtkFontSelection *fontsel;
620   
621   fontsel = g_object_new (GTK_TYPE_FONT_SELECTION, NULL);
622   
623   return GTK_WIDGET (fontsel);
624 }
625
626 static void
627 gtk_font_selection_finalize (GObject *object)
628 {
629   GtkFontSelection *fontsel = GTK_FONT_SELECTION (object);
630
631   gtk_font_selection_ref_family (fontsel, NULL);
632   gtk_font_selection_ref_face (fontsel, NULL);
633
634   G_OBJECT_CLASS (gtk_font_selection_parent_class)->finalize (object);
635 }
636
637 static void
638 gtk_font_selection_ref_family (GtkFontSelection *fontsel,
639                                PangoFontFamily  *family)
640 {
641   GtkFontSelectionPrivate *priv = fontsel->priv;
642
643   if (family)
644     family = g_object_ref (family);
645   if (priv->family)
646     g_object_unref (priv->family);
647   priv->family = family;
648 }
649
650 static void gtk_font_selection_ref_face (GtkFontSelection *fontsel,
651                                          PangoFontFace    *face)
652 {
653   GtkFontSelectionPrivate *priv = fontsel->priv;
654
655   if (face)
656     face = g_object_ref (face);
657   if (priv->face)
658     g_object_unref (priv->face);
659   priv->face = face;
660 }
661
662 static void
663 gtk_font_selection_reload_fonts (GtkFontSelection *fontsel)
664 {
665   if (gtk_widget_has_screen (GTK_WIDGET (fontsel)))
666     {
667       PangoFontDescription *desc;
668       desc = gtk_font_selection_get_font_description (fontsel);
669
670       gtk_font_selection_show_available_fonts (fontsel);
671       gtk_font_selection_show_available_sizes (fontsel, TRUE);
672       gtk_font_selection_show_available_styles (fontsel);
673
674       gtk_font_selection_select_font_desc (fontsel, desc, NULL, NULL);
675       gtk_font_selection_scroll_to_selection (fontsel);
676
677       pango_font_description_free (desc);
678     }
679 }
680
681 static void
682 gtk_font_selection_screen_changed (GtkWidget *widget,
683                                    GdkScreen *previous_screen)
684 {
685   gtk_font_selection_reload_fonts (GTK_FONT_SELECTION (widget));
686 }
687
688 static void
689 gtk_font_selection_style_updated (GtkWidget *widget)
690 {
691   GTK_WIDGET_CLASS (gtk_font_selection_parent_class)->style_updated (widget);
692
693   /* Maybe fonts where installed or removed... */
694   gtk_font_selection_reload_fonts (GTK_FONT_SELECTION (widget));
695 }
696
697 static void
698 gtk_font_selection_preview_changed (GtkWidget        *entry,
699                                     GtkFontSelection *fontsel)
700 {
701   g_object_notify (G_OBJECT (fontsel), "preview-text");
702 }
703
704 static void
705 scroll_to_selection (GtkTreeView *tree_view)
706 {
707   GtkTreeSelection *selection = gtk_tree_view_get_selection (tree_view);
708   GtkTreeModel *model;
709   GtkTreeIter iter;
710
711   if (gtk_tree_selection_get_selected (selection, &model, &iter))
712     {
713       GtkTreePath *path = gtk_tree_model_get_path (model, &iter);
714       gtk_tree_view_scroll_to_cell (tree_view, path, NULL, TRUE, 0.5, 0.5);
715       gtk_tree_path_free (path);
716     }
717 }
718
719 static void
720 set_cursor_to_iter (GtkTreeView *view,
721                     GtkTreeIter *iter)
722 {
723   GtkTreeModel *model = gtk_tree_view_get_model (view);
724   GtkTreePath *path = gtk_tree_model_get_path (model, iter);
725   
726   gtk_tree_view_set_cursor (view, path, NULL, FALSE);
727
728   gtk_tree_path_free (path);
729 }
730
731 static void
732 gtk_font_selection_scroll_to_selection (GtkFontSelection *fontsel)
733 {
734   GtkFontSelectionPrivate *priv = fontsel->priv;
735
736   /* Try to scroll the font family list to the selected item */
737   scroll_to_selection (GTK_TREE_VIEW (priv->family_list));
738
739   /* Try to scroll the font family list to the selected item */
740   scroll_to_selection (GTK_TREE_VIEW (priv->face_list));
741
742   /* Try to scroll the font family list to the selected item */
743   scroll_to_selection (GTK_TREE_VIEW (priv->size_list));
744 /* This is called when the list is mapped. Here we scroll to the current
745    font if necessary. */
746 }
747
748 static void
749 gtk_font_selection_scroll_on_map (GtkWidget             *widget,
750                                   gpointer               data)
751 {
752   gtk_font_selection_scroll_to_selection (GTK_FONT_SELECTION (data));
753 }
754
755 /* This is called when a family is selected in the list. */
756 static void
757 gtk_font_selection_select_font (GtkTreeSelection *selection,
758                                 gpointer          data)
759 {
760   GtkFontSelection *fontsel;
761   GtkFontSelectionPrivate *priv;
762   GtkTreeModel *model;
763   GtkTreeIter iter;
764 #ifdef INCLUDE_FONT_ENTRIES
765   const gchar *family_name;
766 #endif
767
768   fontsel = GTK_FONT_SELECTION (data);
769   priv = fontsel->priv;
770
771   if (gtk_tree_selection_get_selected (selection, &model, &iter))
772     {
773       PangoFontFamily *family;
774
775       gtk_tree_model_get (model, &iter, FAMILY_COLUMN, &family, -1);
776       if (priv->family != family)
777         {
778           gtk_font_selection_ref_family (fontsel, family);
779
780 #ifdef INCLUDE_FONT_ENTRIES
781           family_name = pango_font_family_get_name (priv->family);
782           gtk_entry_set_text (GTK_ENTRY (priv->font_entry), family_name);
783 #endif
784
785           gtk_font_selection_show_available_styles (fontsel);
786           gtk_font_selection_select_best_style (fontsel, TRUE);
787         }
788
789       g_object_unref (family);
790     }
791 }
792
793 static int
794 cmp_families (const void *a, const void *b)
795 {
796   const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a);
797   const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b);
798   
799   return g_utf8_collate (a_name, b_name);
800 }
801
802 static void
803 gtk_font_selection_show_available_fonts (GtkFontSelection *fontsel)
804 {
805   GtkFontSelectionPrivate *priv = fontsel->priv;
806   GtkListStore *model;
807   PangoFontFamily **families;
808   PangoFontFamily *match_family = NULL;
809   gint n_families, i;
810   GtkTreeIter match_row;
811
812   model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->family_list)));
813
814   pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (fontsel)),
815                                &families, &n_families);
816   qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families);
817
818   gtk_list_store_clear (model);
819
820   for (i=0; i<n_families; i++)
821     {
822       const gchar *name = pango_font_family_get_name (families[i]);
823       GtkTreeIter iter;
824
825       gtk_list_store_append (model, &iter);
826       gtk_list_store_set (model, &iter,
827                           FAMILY_COLUMN, families[i],
828                           FAMILY_NAME_COLUMN, name,
829                           -1);
830       
831       if (i == 0 || !g_ascii_strcasecmp (name, "sans"))
832         {
833           match_family = families[i];
834           match_row = iter;
835         }
836     }
837
838   gtk_font_selection_ref_family (fontsel, match_family);
839   if (match_family)
840     {
841       set_cursor_to_iter (GTK_TREE_VIEW (priv->family_list), &match_row);
842 #ifdef INCLUDE_FONT_ENTRIES
843       gtk_entry_set_text (GTK_ENTRY (priv->font_entry), 
844                           pango_font_family_get_name (match_family));
845 #endif /* INCLUDE_FONT_ENTRIES */
846     }
847
848   g_free (families);
849 }
850
851 static int
852 compare_font_descriptions (const PangoFontDescription *a, const PangoFontDescription *b)
853 {
854   int val = strcmp (pango_font_description_get_family (a), pango_font_description_get_family (b));
855   if (val != 0)
856     return val;
857
858   if (pango_font_description_get_weight (a) != pango_font_description_get_weight (b))
859     return pango_font_description_get_weight (a) - pango_font_description_get_weight (b);
860
861   if (pango_font_description_get_style (a) != pango_font_description_get_style (b))
862     return pango_font_description_get_style (a) - pango_font_description_get_style (b);
863   
864   if (pango_font_description_get_stretch (a) != pango_font_description_get_stretch (b))
865     return pango_font_description_get_stretch (a) - pango_font_description_get_stretch (b);
866
867   if (pango_font_description_get_variant (a) != pango_font_description_get_variant (b))
868     return pango_font_description_get_variant (a) - pango_font_description_get_variant (b);
869
870   return 0;
871 }
872
873 static int
874 faces_sort_func (const void *a, const void *b)
875 {
876   PangoFontDescription *desc_a = pango_font_face_describe (*(PangoFontFace **)a);
877   PangoFontDescription *desc_b = pango_font_face_describe (*(PangoFontFace **)b);
878   
879   int ord = compare_font_descriptions (desc_a, desc_b);
880
881   pango_font_description_free (desc_a);
882   pango_font_description_free (desc_b);
883
884   return ord;
885 }
886
887 static gboolean
888 font_description_style_equal (const PangoFontDescription *a,
889                               const PangoFontDescription *b)
890 {
891   return (pango_font_description_get_weight (a) == pango_font_description_get_weight (b) &&
892           pango_font_description_get_style (a) == pango_font_description_get_style (b) &&
893           pango_font_description_get_stretch (a) == pango_font_description_get_stretch (b) &&
894           pango_font_description_get_variant (a) == pango_font_description_get_variant (b));
895 }
896
897 /* This fills the font style list with all the possible style combinations
898    for the current font family. */
899 static void
900 gtk_font_selection_show_available_styles (GtkFontSelection *fontsel)
901 {
902   GtkFontSelectionPrivate *priv = fontsel->priv;
903   gint n_faces, i;
904   PangoFontFace **faces;
905   PangoFontDescription *old_desc;
906   GtkListStore *model;
907   GtkTreeIter match_row;
908   PangoFontFace *match_face = NULL;
909
910   model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->face_list)));
911
912   if (priv->face)
913     old_desc = pango_font_face_describe (priv->face);
914   else
915     old_desc= NULL;
916
917   pango_font_family_list_faces (priv->family, &faces, &n_faces);
918   qsort (faces, n_faces, sizeof (PangoFontFace *), faces_sort_func);
919
920   gtk_list_store_clear (model);
921
922   for (i=0; i < n_faces; i++)
923     {
924       GtkTreeIter iter;
925       const gchar *str = pango_font_face_get_face_name (faces[i]);
926
927       gtk_list_store_append (model, &iter);
928       gtk_list_store_set (model, &iter,
929                           FACE_COLUMN, faces[i],
930                           FACE_NAME_COLUMN, str,
931                           -1);
932
933       if (i == 0)
934         {
935           match_row = iter;
936           match_face = faces[i];
937         }
938       else if (old_desc)
939         {
940           PangoFontDescription *tmp_desc = pango_font_face_describe (faces[i]);
941           
942           if (font_description_style_equal (tmp_desc, old_desc))
943             {
944               match_row = iter;
945               match_face = faces[i];
946             }
947       
948           pango_font_description_free (tmp_desc);
949         }
950     }
951
952   if (old_desc)
953     pango_font_description_free (old_desc);
954
955   gtk_font_selection_ref_face (fontsel, match_face);
956   if (match_face)
957     {
958 #ifdef INCLUDE_FONT_ENTRIES
959       const gchar *str = pango_font_face_get_face_name (priv->face);
960
961       gtk_entry_set_text (GTK_ENTRY (priv->font_style_entry), str);
962 #endif
963       set_cursor_to_iter (GTK_TREE_VIEW (priv->face_list), &match_row);
964     }
965
966   g_free (faces);
967 }
968
969 /* This selects a style when the user selects a font. It just uses the first
970    available style at present. I was thinking of trying to maintain the
971    selected style, e.g. bold italic, when the user selects different fonts.
972    However, the interface is so easy to use now I'm not sure it's worth it.
973    Note: This will load a font. */
974 static void
975 gtk_font_selection_select_best_style (GtkFontSelection *fontsel,
976                                       gboolean          use_first)
977 {
978   GtkFontSelectionPrivate *priv = fontsel->priv;
979   GtkTreeIter iter;
980   GtkTreeModel *model;
981
982   model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->face_list));
983
984   if (gtk_tree_model_get_iter_first (model, &iter))
985     {
986       set_cursor_to_iter (GTK_TREE_VIEW (priv->face_list), &iter);
987       scroll_to_selection (GTK_TREE_VIEW (priv->face_list));
988     }
989
990   gtk_font_selection_show_available_sizes (fontsel, FALSE);
991   gtk_font_selection_select_best_size (fontsel);
992 }
993
994
995 /* This is called when a style is selected in the list. */
996 static void
997 gtk_font_selection_select_style (GtkTreeSelection *selection,
998                                  gpointer          data)
999 {
1000   GtkFontSelection *fontsel = GTK_FONT_SELECTION (data);
1001   GtkTreeModel *model;
1002   GtkTreeIter iter;
1003
1004   if (gtk_tree_selection_get_selected (selection, &model, &iter))
1005     {
1006       PangoFontFace *face;
1007       
1008       gtk_tree_model_get (model, &iter, FACE_COLUMN, &face, -1);
1009       gtk_font_selection_ref_face (fontsel, face);
1010       g_object_unref (face);
1011     }
1012
1013   gtk_font_selection_show_available_sizes (fontsel, FALSE);
1014   gtk_font_selection_select_best_size (fontsel);
1015 }
1016
1017 static void
1018 gtk_font_selection_show_available_sizes (GtkFontSelection *fontsel,
1019                                          gboolean          first_time)
1020 {
1021   GtkFontSelectionPrivate *priv = fontsel->priv;
1022   gint i;
1023   GtkListStore *model;
1024   gchar buffer[128];
1025   gchar *p;
1026
1027   model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->size_list)));
1028
1029   /* Insert the standard font sizes */
1030   if (first_time)
1031     {
1032       gtk_list_store_clear (model);
1033
1034       for (i = 0; i < G_N_ELEMENTS (font_sizes); i++)
1035         {
1036           GtkTreeIter iter;
1037
1038           gtk_list_store_append (model, &iter);
1039           gtk_list_store_set (model, &iter, SIZE_COLUMN, font_sizes[i], -1);
1040
1041           if (font_sizes[i] * PANGO_SCALE == priv->size)
1042             set_cursor_to_iter (GTK_TREE_VIEW (priv->size_list), &iter);
1043         }
1044     }
1045   else
1046     {
1047       GtkTreeIter iter;
1048       gboolean found = FALSE;
1049
1050       gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter);
1051       for (i = 0; i < G_N_ELEMENTS (font_sizes) && !found; i++)
1052         {
1053           if (font_sizes[i] * PANGO_SCALE == priv->size)
1054             {
1055               set_cursor_to_iter (GTK_TREE_VIEW (priv->size_list), &iter);
1056               found = TRUE;
1057             }
1058
1059           gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter);
1060         }
1061
1062       if (!found)
1063         {
1064           GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->size_list));
1065           gtk_tree_selection_unselect_all (selection);
1066         }
1067     }
1068
1069   /* Set the entry to the new size, rounding to 1 digit,
1070    * trimming of trailing 0's and a trailing period
1071    */
1072   g_snprintf (buffer, sizeof (buffer), "%.1f", priv->size / (1.0 * PANGO_SCALE));
1073   if (strchr (buffer, '.'))
1074     {
1075       p = buffer + strlen (buffer) - 1;
1076       while (*p == '0')
1077         p--;
1078       if (*p == '.')
1079         p--;
1080       p[1] = '\0';
1081     }
1082
1083   /* Compare, to avoid moving the cursor unecessarily */
1084   if (strcmp (gtk_entry_get_text (GTK_ENTRY (priv->size_entry)), buffer) != 0)
1085     gtk_entry_set_text (GTK_ENTRY (priv->size_entry), buffer);
1086 }
1087
1088 static void
1089 gtk_font_selection_select_best_size (GtkFontSelection *fontsel)
1090 {
1091   gtk_font_selection_load_font (fontsel);  
1092 }
1093
1094 static void
1095 gtk_font_selection_set_size (GtkFontSelection *fontsel,
1096                              gint              new_size)
1097 {
1098   GtkFontSelectionPrivate *priv = fontsel->priv;
1099
1100   if (priv->size != new_size)
1101     {
1102       priv->size = new_size;
1103
1104       gtk_font_selection_show_available_sizes (fontsel, FALSE);      
1105       gtk_font_selection_load_font (fontsel);
1106     }
1107 }
1108
1109 /* If the user hits return in the font size entry, we change to the new font
1110    size. */
1111 static void
1112 gtk_font_selection_size_activate (GtkWidget   *w,
1113                                   gpointer     data)
1114 {
1115   GtkFontSelection *fontsel = GTK_FONT_SELECTION (data);
1116   GtkFontSelectionPrivate *priv = fontsel->priv;
1117   gint new_size;
1118   const gchar *text;
1119
1120   text = gtk_entry_get_text (GTK_ENTRY (priv->size_entry));
1121   new_size = MAX (0.1, atof (text) * PANGO_SCALE + 0.5);
1122
1123   if (priv->size != new_size)
1124     gtk_font_selection_set_size (fontsel, new_size);
1125   else 
1126     list_row_activated (w);
1127 }
1128
1129 static gboolean
1130 gtk_font_selection_size_focus_out (GtkWidget     *w,
1131                                    GdkEventFocus *event,
1132                                    gpointer       data)
1133 {
1134   GtkFontSelection *fontsel = GTK_FONT_SELECTION (data);
1135   GtkFontSelectionPrivate *priv = fontsel->priv;
1136   gint new_size;
1137   const gchar *text;
1138
1139   text = gtk_entry_get_text (GTK_ENTRY (priv->size_entry));
1140   new_size = MAX (0.1, atof (text) * PANGO_SCALE + 0.5);
1141
1142   gtk_font_selection_set_size (fontsel, new_size);
1143
1144   return TRUE;
1145 }
1146
1147 /* This is called when a size is selected in the list. */
1148 static void
1149 gtk_font_selection_select_size (GtkTreeSelection *selection,
1150                                 gpointer          data)
1151 {
1152   GtkFontSelection *fontsel = GTK_FONT_SELECTION (data);
1153   GtkTreeModel *model;
1154   GtkTreeIter iter;
1155   gint new_size;
1156
1157   if (gtk_tree_selection_get_selected (selection, &model, &iter))
1158     {
1159       gtk_tree_model_get (model, &iter, SIZE_COLUMN, &new_size, -1);
1160       gtk_font_selection_set_size (fontsel, new_size * PANGO_SCALE);
1161     }
1162 }
1163
1164 static void
1165 gtk_font_selection_load_font (GtkFontSelection *fontsel)
1166 {
1167   gtk_font_selection_update_preview (fontsel);
1168 }
1169
1170 static PangoFontDescription *
1171 gtk_font_selection_get_font_description (GtkFontSelection *fontsel)
1172 {
1173   GtkFontSelectionPrivate *priv = fontsel->priv;
1174   PangoFontDescription *font_desc;
1175
1176   if (priv->face)
1177     {
1178       font_desc = pango_font_face_describe (priv->face);
1179       pango_font_description_set_size (font_desc, priv->size);
1180     }
1181   else
1182     font_desc = pango_font_description_from_string (DEFAULT_FONT_NAME);
1183
1184   return font_desc;
1185 }
1186
1187 /* This sets the font in the preview entry to the selected font,
1188  * and tries to make sure that the preview entry is a reasonable
1189  * size, i.e. so that the text can be seen with a bit of space to
1190  * spare. But it tries to avoid resizing the entry every time the
1191  * font changes. This also used to shrink the preview if the font
1192  * size was decreased, but that made it awkward if the user wanted
1193  * to resize the window themself.
1194  */
1195 static void
1196 gtk_font_selection_update_preview (GtkFontSelection *fontsel)
1197 {
1198   GtkFontSelectionPrivate *priv = fontsel->priv;
1199   gint new_height;
1200   GtkRequisition old_requisition, new_requisition;
1201   GtkWidget *preview_entry = priv->preview_entry;
1202   const gchar *text;
1203
1204   gtk_widget_get_preferred_size (preview_entry, &old_requisition, NULL);
1205
1206   gtk_widget_override_font (preview_entry,
1207                             gtk_font_selection_get_font_description (fontsel));
1208
1209   gtk_widget_get_preferred_size (preview_entry, &new_requisition, NULL);
1210
1211   /* We don't ever want to be over MAX_PREVIEW_HEIGHT pixels high. */
1212   new_height = CLAMP (new_requisition.height, INITIAL_PREVIEW_HEIGHT, MAX_PREVIEW_HEIGHT);
1213
1214   if (new_height > old_requisition.height || new_height < old_requisition.height - 30)
1215     gtk_widget_set_size_request (preview_entry, -1, new_height);
1216
1217   /* This sets the preview text, if it hasn't been set already. */
1218   text = gtk_entry_get_text (GTK_ENTRY (preview_entry));
1219   if (strlen (text) == 0)
1220     gtk_entry_set_text (GTK_ENTRY (preview_entry), _(PREVIEW_TEXT));
1221   gtk_editable_set_position (GTK_EDITABLE (preview_entry), 0);
1222 }
1223
1224
1225 /*****************************************************************************
1226  * These functions are the main public interface for getting/setting the font.
1227  *****************************************************************************/
1228
1229 /**
1230  * gtk_font_selection_get_family_list:
1231  * @fontsel: a #GtkFontSelection
1232  *
1233  * This returns the #GtkTreeView that lists font families, for
1234  * example, 'Sans', 'Serif', etc.
1235  *
1236  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1237  *
1238  * Since: 2.14
1239  *
1240  * Deprecated: 3.2: Use #GtkFontChooser
1241  */
1242 GtkWidget *
1243 gtk_font_selection_get_family_list (GtkFontSelection *fontsel)
1244 {
1245   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1246
1247   return fontsel->priv->family_list;
1248 }
1249
1250 /**
1251  * gtk_font_selection_get_face_list:
1252  * @fontsel: a #GtkFontSelection
1253  *
1254  * This returns the #GtkTreeView which lists all styles available for
1255  * the selected font. For example, 'Regular', 'Bold', etc.
1256  * 
1257  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1258  *
1259  * Since: 2.14
1260  *
1261  * Deprecated: 3.2: Use #GtkFontChooser
1262  */
1263 GtkWidget *
1264 gtk_font_selection_get_face_list (GtkFontSelection *fontsel)
1265 {
1266   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1267
1268   return fontsel->priv->face_list;
1269 }
1270
1271 /**
1272  * gtk_font_selection_get_size_entry:
1273  * @fontsel: a #GtkFontSelection
1274  *
1275  * This returns the #GtkEntry used to allow the user to edit the font
1276  * number manually instead of selecting it from the list of font sizes.
1277  *
1278  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1279  *
1280  * Since: 2.14
1281  *
1282  * Deprecated: 3.2: Use #GtkFontChooser
1283  */
1284 GtkWidget *
1285 gtk_font_selection_get_size_entry (GtkFontSelection *fontsel)
1286 {
1287   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1288
1289   return fontsel->priv->size_entry;
1290 }
1291
1292 /**
1293  * gtk_font_selection_get_size_list:
1294  * @fontsel: a #GtkFontSelection
1295  *
1296  * This returns the #GtkTreeeView used to list font sizes.
1297  *
1298  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1299  *
1300  * Since: 2.14
1301  *
1302  * Deprecated: 3.2: Use #GtkFontChooser
1303  */
1304 GtkWidget *
1305 gtk_font_selection_get_size_list (GtkFontSelection *fontsel)
1306 {
1307   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1308
1309   return fontsel->priv->size_list;
1310 }
1311
1312 /**
1313  * gtk_font_selection_get_preview_entry:
1314  * @fontsel: a #GtkFontSelection
1315  *
1316  * This returns the #GtkEntry used to display the font as a preview.
1317  *
1318  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1319  *
1320  * Since: 2.14
1321  *
1322  * Deprecated: 3.2: Use #GtkFontChooser
1323  */
1324 GtkWidget *
1325 gtk_font_selection_get_preview_entry (GtkFontSelection *fontsel)
1326 {
1327   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1328
1329   return fontsel->priv->preview_entry;
1330 }
1331
1332 /**
1333  * gtk_font_selection_get_family:
1334  * @fontsel: a #GtkFontSelection
1335  *
1336  * Gets the #PangoFontFamily representing the selected font family.
1337  *
1338  * Return value: (transfer none): A #PangoFontFamily representing the
1339  *     selected font family. Font families are a collection of font
1340  *     faces. The returned object is owned by @fontsel and must not
1341  *     be modified or freed.
1342  *
1343  * Since: 2.14
1344  *
1345  * Deprecated: 3.2: Use #GtkFontChooser
1346  */
1347 PangoFontFamily *
1348 gtk_font_selection_get_family (GtkFontSelection *fontsel)
1349 {
1350   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1351
1352   return fontsel->priv->family;
1353 }
1354
1355 /**
1356  * gtk_font_selection_get_face:
1357  * @fontsel: a #GtkFontSelection
1358  *
1359  * Gets the #PangoFontFace representing the selected font group
1360  * details (i.e. family, slant, weight, width, etc).
1361  *
1362  * Return value: (transfer none): A #PangoFontFace representing the
1363  *     selected font group details. The returned object is owned by
1364  *     @fontsel and must not be modified or freed.
1365  *
1366  * Since: 2.14
1367  *
1368  * Deprecated: 3.2: Use #GtkFontChooser
1369  */
1370 PangoFontFace *
1371 gtk_font_selection_get_face (GtkFontSelection *fontsel)
1372 {
1373   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1374
1375   return fontsel->priv->face;
1376 }
1377
1378 /**
1379  * gtk_font_selection_get_size:
1380  * @fontsel: a #GtkFontSelection
1381  *
1382  * The selected font size.
1383  *
1384  * Return value: A n integer representing the selected font size,
1385  *     or -1 if no font size is selected.
1386  *
1387  * Since: 2.14
1388  *
1389  * Deprecated: 3.2: Use #GtkFontChooser
1390  **/
1391 gint
1392 gtk_font_selection_get_size (GtkFontSelection *fontsel)
1393 {
1394   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), -1);
1395
1396   return fontsel->priv->size;
1397 }
1398
1399 /**
1400  * gtk_font_selection_get_font_name:
1401  * @fontsel: a #GtkFontSelection
1402  * 
1403  * Gets the currently-selected font name. 
1404  *
1405  * Note that this can be a different string than what you set with 
1406  * gtk_font_selection_set_font_name(), as the font selection widget may 
1407  * normalize font names and thus return a string with a different structure. 
1408  * For example, "Helvetica Italic Bold 12" could be normalized to 
1409  * "Helvetica Bold Italic 12". Use pango_font_description_equal()
1410  * if you want to compare two font descriptions.
1411  * 
1412  * Return value: A string with the name of the current font, or %NULL if 
1413  *     no font is selected. You must free this string with g_free().
1414  *
1415  * Deprecated: 3.2: Use #GtkFontChooser
1416  */
1417 gchar *
1418 gtk_font_selection_get_font_name (GtkFontSelection *fontsel)
1419 {
1420   gchar *result;
1421   
1422   PangoFontDescription *font_desc = gtk_font_selection_get_font_description (fontsel);
1423   result = pango_font_description_to_string (font_desc);
1424   pango_font_description_free (font_desc);
1425
1426   return result;
1427 }
1428
1429 /* This selects the appropriate list rows.
1430    First we check the fontname is valid and try to find the font family
1431    - i.e. the name in the main list. If we can't find that, then just return.
1432    Next we try to set each of the properties according to the fontname.
1433    Finally we select the font family & style in the lists. */
1434 static gboolean
1435 gtk_font_selection_select_font_desc (GtkFontSelection      *fontsel,
1436                                      PangoFontDescription  *new_desc,
1437                                      PangoFontFamily      **pfamily,
1438                                      PangoFontFace        **pface)
1439 {
1440   GtkFontSelectionPrivate *priv = fontsel->priv;
1441   PangoFontFamily *new_family = NULL;
1442   PangoFontFace *new_face = NULL;
1443   PangoFontFace *fallback_face = NULL;
1444   GtkTreeModel *model;
1445   GtkTreeIter iter;
1446   GtkTreeIter match_iter;
1447   gboolean valid;
1448   const gchar *new_family_name;
1449
1450   new_family_name = pango_font_description_get_family (new_desc);
1451
1452   if (!new_family_name)
1453     return FALSE;
1454
1455   /* Check to make sure that this is in the list of allowed fonts 
1456    */
1457   model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->family_list));
1458   for (valid = gtk_tree_model_get_iter_first (model, &iter);
1459        valid;
1460        valid = gtk_tree_model_iter_next (model, &iter))
1461     {
1462       PangoFontFamily *family;
1463       
1464       gtk_tree_model_get (model, &iter, FAMILY_COLUMN, &family, -1);
1465       
1466       if (g_ascii_strcasecmp (pango_font_family_get_name (family),
1467                               new_family_name) == 0)
1468         new_family = g_object_ref (family);
1469
1470       g_object_unref (family);
1471       
1472       if (new_family)
1473         break;
1474     }
1475
1476   if (!new_family)
1477     return FALSE;
1478
1479   if (pfamily)
1480     *pfamily = new_family;
1481   else
1482     g_object_unref (new_family);
1483   set_cursor_to_iter (GTK_TREE_VIEW (priv->family_list), &iter);
1484   gtk_font_selection_show_available_styles (fontsel);
1485
1486   model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->face_list));
1487   for (valid = gtk_tree_model_get_iter_first (model, &iter);
1488        valid;
1489        valid = gtk_tree_model_iter_next (model, &iter))
1490     {
1491       PangoFontFace *face;
1492       PangoFontDescription *tmp_desc;
1493       
1494       gtk_tree_model_get (model, &iter, FACE_COLUMN, &face, -1);
1495       tmp_desc = pango_font_face_describe (face);
1496       
1497       if (font_description_style_equal (tmp_desc, new_desc))
1498         new_face = g_object_ref (face);
1499       
1500       if (!fallback_face)
1501         {
1502           fallback_face = g_object_ref (face);
1503           match_iter = iter;
1504         }
1505       
1506       pango_font_description_free (tmp_desc);
1507       g_object_unref (face);
1508       
1509       if (new_face)
1510         {
1511           match_iter = iter;
1512           break;
1513         }
1514     }
1515
1516   if (!new_face)
1517     new_face = fallback_face;
1518   else if (fallback_face)
1519     g_object_unref (fallback_face);
1520
1521   if (pface)
1522     *pface = new_face;
1523   else if (new_face)
1524     g_object_unref (new_face);
1525   set_cursor_to_iter (GTK_TREE_VIEW (priv->face_list), &match_iter);  
1526
1527   gtk_font_selection_set_size (fontsel, pango_font_description_get_size (new_desc));
1528
1529   return TRUE;
1530 }
1531
1532
1533 /* This sets the current font, then selecting the appropriate list rows. */
1534
1535 /**
1536  * gtk_font_selection_set_font_name:
1537  * @fontsel: a #GtkFontSelection
1538  * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
1539  * 
1540  * Sets the currently-selected font. 
1541  *
1542  * Note that the @fontsel needs to know the screen in which it will appear 
1543  * for this to work; this can be guaranteed by simply making sure that the 
1544  * @fontsel is inserted in a toplevel window before you call this function.
1545  * 
1546  * Return value: %TRUE if the font could be set successfully; %FALSE if no 
1547  *     such font exists or if the @fontsel doesn't belong to a particular 
1548  *     screen yet.
1549  *
1550  * Deprecated: 3.2: Use #GtkFontChooser
1551  */
1552 gboolean
1553 gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
1554                                   const gchar      *fontname)
1555 {
1556   PangoFontFamily *family = NULL;
1557   PangoFontFace *face = NULL;
1558   PangoFontDescription *new_desc;
1559   
1560   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), FALSE);
1561
1562   if (!gtk_widget_has_screen (GTK_WIDGET (fontsel)))
1563     return FALSE;
1564
1565   new_desc = pango_font_description_from_string (fontname);
1566
1567   if (gtk_font_selection_select_font_desc (fontsel, new_desc, &family, &face))
1568     {
1569       gtk_font_selection_ref_family (fontsel, family);
1570       if (family)
1571         g_object_unref (family);
1572
1573       gtk_font_selection_ref_face (fontsel, face);
1574       if (face)
1575         g_object_unref (face);
1576     }
1577
1578   pango_font_description_free (new_desc);
1579   
1580   g_object_notify (G_OBJECT (fontsel), "font-name");
1581
1582   return TRUE;
1583 }
1584
1585 /**
1586  * gtk_font_selection_get_preview_text:
1587  * @fontsel: a #GtkFontSelection
1588  *
1589  * Gets the text displayed in the preview area.
1590  * 
1591  * Return value: the text displayed in the preview area. 
1592  *     This string is owned by the widget and should not be 
1593  *     modified or freed 
1594  *
1595  * Deprecated: 3.2: Use #GtkFontChooser
1596  */
1597 const gchar*
1598 gtk_font_selection_get_preview_text (GtkFontSelection *fontsel)
1599 {
1600   GtkFontSelectionPrivate *priv;
1601
1602   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1603
1604   priv = fontsel->priv;
1605
1606   return gtk_entry_get_text (GTK_ENTRY (priv->preview_entry));
1607 }
1608
1609
1610 /**
1611  * gtk_font_selection_set_preview_text:
1612  * @fontsel: a #GtkFontSelection
1613  * @text: the text to display in the preview area 
1614  *
1615  * Sets the text displayed in the preview area.
1616  * The @text is used to show how the selected font looks.
1617  *
1618  * Deprecated: 3.2: Use #GtkFontChooser
1619  */
1620 void
1621 gtk_font_selection_set_preview_text  (GtkFontSelection *fontsel,
1622                                       const gchar      *text)
1623 {
1624   GtkFontSelectionPrivate *priv;
1625
1626   g_return_if_fail (GTK_IS_FONT_SELECTION (fontsel));
1627   g_return_if_fail (text != NULL);
1628
1629   priv = fontsel->priv;
1630
1631   gtk_entry_set_text (GTK_ENTRY (priv->preview_entry), text);
1632 }
1633
1634
1635 /**
1636  * SECTION:gtkfontseldlg
1637  * @Short_description: A dialog box for selecting fonts
1638  * @Title: GtkFontSelectionDialog
1639  * @See_also: #GtkFontSelection, #GtkDialog, #GtkFontChooserDialog
1640  *
1641  * The #GtkFontSelectionDialog widget is a dialog box for selecting a font.
1642  *
1643  * To set the font which is initially selected, use
1644  * gtk_font_selection_dialog_set_font_name().
1645  *
1646  * To get the selected font use gtk_font_selection_dialog_get_font_name().
1647  *
1648  * To change the text which is shown in the preview area, use
1649  * gtk_font_selection_dialog_set_preview_text().
1650  *
1651  * In GTK+ 3.2, #GtkFontSelectionDialog has been deprecated in favor of
1652  * #GtkFontChooserDialog.
1653  *
1654  * <refsect2 id="GtkFontSelectionDialog-BUILDER-UI">
1655  * <title>GtkFontSelectionDialog as GtkBuildable</title>
1656  * The GtkFontSelectionDialog implementation of the GtkBuildable interface
1657  * exposes the embedded #GtkFontSelection as internal child with the
1658  * name "font_selection". It also exposes the buttons with the names
1659  * "ok_button", "cancel_button" and "apply_button".
1660  * </refsect2>
1661  */
1662
1663 static void gtk_font_selection_dialog_buildable_interface_init     (GtkBuildableIface *iface);
1664 static GObject * gtk_font_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
1665                                                                           GtkBuilder   *builder,
1666                                                                           const gchar  *childname);
1667
1668 G_DEFINE_TYPE_WITH_CODE (GtkFontSelectionDialog, gtk_font_selection_dialog,
1669                          GTK_TYPE_DIALOG,
1670                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
1671                                                 gtk_font_selection_dialog_buildable_interface_init))
1672
1673 static GtkBuildableIface *parent_buildable_iface;
1674
1675 static void
1676 gtk_font_selection_dialog_class_init (GtkFontSelectionDialogClass *klass)
1677 {
1678   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1679
1680   gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_FONT_CHOOSER);
1681
1682   g_type_class_add_private (klass, sizeof (GtkFontSelectionDialogPrivate));
1683 }
1684
1685 static void
1686 gtk_font_selection_dialog_init (GtkFontSelectionDialog *fontseldiag)
1687 {
1688   GtkFontSelectionDialogPrivate *priv;
1689   GtkDialog *dialog = GTK_DIALOG (fontseldiag);
1690   GtkWidget *action_area, *content_area;
1691
1692   fontseldiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontseldiag,
1693                                                    GTK_TYPE_FONT_SELECTION_DIALOG,
1694                                                    GtkFontSelectionDialogPrivate);
1695   priv = fontseldiag->priv;
1696
1697   content_area = gtk_dialog_get_content_area (dialog);
1698   action_area = gtk_dialog_get_action_area (dialog);
1699
1700   gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
1701   gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
1702   gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
1703   gtk_box_set_spacing (GTK_BOX (action_area), 6);
1704
1705   gtk_widget_push_composite_child ();
1706
1707   gtk_window_set_resizable (GTK_WINDOW (fontseldiag), TRUE);
1708
1709   /* Create the content area */
1710   priv->fontsel = gtk_font_selection_new ();
1711   gtk_container_set_border_width (GTK_CONTAINER (priv->fontsel), 5);
1712   gtk_widget_show (priv->fontsel);
1713   gtk_box_pack_start (GTK_BOX (content_area),
1714                       priv->fontsel, TRUE, TRUE, 0);
1715
1716   /* Create the action area */
1717   priv->cancel_button = gtk_dialog_add_button (dialog,
1718                                                GTK_STOCK_CANCEL,
1719                                                GTK_RESPONSE_CANCEL);
1720
1721   priv->apply_button = gtk_dialog_add_button (dialog,
1722                                               GTK_STOCK_APPLY,
1723                                               GTK_RESPONSE_APPLY);
1724   gtk_widget_hide (priv->apply_button);
1725
1726   priv->ok_button = gtk_dialog_add_button (dialog,
1727                                            GTK_STOCK_OK,
1728                                            GTK_RESPONSE_OK);
1729   gtk_widget_grab_default (priv->ok_button);
1730
1731   gtk_dialog_set_alternative_button_order (GTK_DIALOG (fontseldiag),
1732                                            GTK_RESPONSE_OK,
1733                                            GTK_RESPONSE_APPLY,
1734                                            GTK_RESPONSE_CANCEL,
1735                                            -1);
1736
1737   gtk_window_set_title (GTK_WINDOW (fontseldiag),
1738                         _("Font Selection"));
1739
1740   gtk_widget_pop_composite_child ();
1741 }
1742
1743 /**
1744  * gtk_font_selection_dialog_new:
1745  * @title: the title of the dialog window 
1746  *
1747  * Creates a new #GtkFontSelectionDialog.
1748  *
1749  * Return value: a new #GtkFontSelectionDialog
1750  *
1751  * Deprecated: 3.2: Use #GtkFontChooserDialog
1752  */
1753 GtkWidget*
1754 gtk_font_selection_dialog_new (const gchar *title)
1755 {
1756   GtkFontSelectionDialog *fontseldiag;
1757   
1758   fontseldiag = g_object_new (GTK_TYPE_FONT_SELECTION_DIALOG, NULL);
1759
1760   if (title)
1761     gtk_window_set_title (GTK_WINDOW (fontseldiag), title);
1762   
1763   return GTK_WIDGET (fontseldiag);
1764 }
1765
1766 /**
1767  * gtk_font_selection_dialog_get_font_selection:
1768  * @fsd: a #GtkFontSelectionDialog
1769  *
1770  * Retrieves the #GtkFontSelection widget embedded in the dialog.
1771  *
1772  * Returns: (transfer none): the embedded #GtkFontSelection
1773  *
1774  * Since: 2.22
1775  *
1776  * Deprecated: 3.2: Use #GtkFontChooserDialog
1777  **/
1778 GtkWidget*
1779 gtk_font_selection_dialog_get_font_selection (GtkFontSelectionDialog *fsd)
1780 {
1781   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1782
1783   return fsd->priv->fontsel;
1784 }
1785
1786
1787 /**
1788  * gtk_font_selection_dialog_get_ok_button:
1789  * @fsd: a #GtkFontSelectionDialog
1790  *
1791  * Gets the 'OK' button.
1792  *
1793  * Return value: (transfer none): the #GtkWidget used in the dialog
1794  *     for the 'OK' button.
1795  *
1796  * Since: 2.14
1797  *
1798  * Deprecated: 3.2: Use #GtkFontChooserDialog
1799  */
1800 GtkWidget *
1801 gtk_font_selection_dialog_get_ok_button (GtkFontSelectionDialog *fsd)
1802 {
1803   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1804
1805   return fsd->priv->ok_button;
1806 }
1807
1808 /**
1809  * gtk_font_selection_dialog_get_cancel_button:
1810  * @fsd: a #GtkFontSelectionDialog
1811  *
1812  * Gets the 'Cancel' button.
1813  *
1814  * Return value: (transfer none): the #GtkWidget used in the dialog
1815  *     for the 'Cancel' button.
1816  *
1817  * Since: 2.14
1818  *
1819  * Deprecated: 3.2: Use #GtkFontChooserDialog
1820  */
1821 GtkWidget *
1822 gtk_font_selection_dialog_get_cancel_button (GtkFontSelectionDialog *fsd)
1823 {
1824   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1825
1826   return fsd->priv->cancel_button;
1827 }
1828
1829 static void
1830 gtk_font_selection_dialog_buildable_interface_init (GtkBuildableIface *iface)
1831 {
1832   parent_buildable_iface = g_type_interface_peek_parent (iface);
1833   iface->get_internal_child = gtk_font_selection_dialog_buildable_get_internal_child;
1834 }
1835
1836 static GObject *
1837 gtk_font_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
1838                                                         GtkBuilder   *builder,
1839                                                         const gchar  *childname)
1840 {
1841   GtkFontSelectionDialogPrivate *priv;
1842
1843   priv = GTK_FONT_SELECTION_DIALOG (buildable)->priv;
1844
1845   if (g_strcmp0 (childname, "ok_button") == 0)
1846     return G_OBJECT (priv->ok_button);
1847   else if (g_strcmp0 (childname, "cancel_button") == 0)
1848     return G_OBJECT (priv->cancel_button);
1849   else if (g_strcmp0 (childname, "apply_button") == 0)
1850     return G_OBJECT (priv->apply_button);
1851   else if (g_strcmp0 (childname, "font_selection") == 0)
1852     return G_OBJECT (priv->fontsel);
1853
1854   return parent_buildable_iface->get_internal_child (buildable, builder, childname);
1855 }
1856
1857 /**
1858  * gtk_font_selection_dialog_get_font_name:
1859  * @fsd: a #GtkFontSelectionDialog
1860  * 
1861  * Gets the currently-selected font name.
1862  *
1863  * Note that this can be a different string than what you set with 
1864  * gtk_font_selection_dialog_set_font_name(), as the font selection widget
1865  * may normalize font names and thus return a string with a different 
1866  * structure. For example, "Helvetica Italic Bold 12" could be normalized 
1867  * to "Helvetica Bold Italic 12".  Use pango_font_description_equal()
1868  * if you want to compare two font descriptions.
1869  * 
1870  * Return value: A string with the name of the current font, or %NULL if no 
1871  *     font is selected. You must free this string with g_free().
1872  *
1873  * Deprecated: 3.2: Use #GtkFontChooserDialog
1874  */
1875 gchar*
1876 gtk_font_selection_dialog_get_font_name (GtkFontSelectionDialog *fsd)
1877 {
1878   GtkFontSelectionDialogPrivate *priv;
1879
1880   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1881
1882   priv = fsd->priv;
1883
1884   return gtk_font_selection_get_font_name (GTK_FONT_SELECTION (priv->fontsel));
1885 }
1886
1887 /**
1888  * gtk_font_selection_dialog_set_font_name:
1889  * @fsd: a #GtkFontSelectionDialog
1890  * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
1891  *
1892  * Sets the currently selected font. 
1893  * 
1894  * Return value: %TRUE if the font selected in @fsd is now the
1895  *     @fontname specified, %FALSE otherwise. 
1896  *
1897  * Deprecated: 3.2: Use #GtkFontChooserDialog
1898  */
1899 gboolean
1900 gtk_font_selection_dialog_set_font_name (GtkFontSelectionDialog *fsd,
1901                                          const gchar            *fontname)
1902 {
1903   GtkFontSelectionDialogPrivate *priv;
1904
1905   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), FALSE);
1906   g_return_val_if_fail (fontname, FALSE);
1907
1908   priv = fsd->priv;
1909
1910   return gtk_font_selection_set_font_name (GTK_FONT_SELECTION (priv->fontsel), fontname);
1911 }
1912
1913 /**
1914  * gtk_font_selection_dialog_get_preview_text:
1915  * @fsd: a #GtkFontSelectionDialog
1916  *
1917  * Gets the text displayed in the preview area.
1918  * 
1919  * Return value: the text displayed in the preview area. 
1920  *     This string is owned by the widget and should not be 
1921  *     modified or freed 
1922  *
1923  * Deprecated: 3.2: Use #GtkFontChooserDialog
1924  */
1925 const gchar*
1926 gtk_font_selection_dialog_get_preview_text (GtkFontSelectionDialog *fsd)
1927 {
1928   GtkFontSelectionDialogPrivate *priv;
1929
1930   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1931
1932   priv = fsd->priv;
1933
1934   return gtk_font_selection_get_preview_text (GTK_FONT_SELECTION (priv->fontsel));
1935 }
1936
1937 /**
1938  * gtk_font_selection_dialog_set_preview_text:
1939  * @fsd: a #GtkFontSelectionDialog
1940  * @text: the text to display in the preview area
1941  *
1942  * Sets the text displayed in the preview area. 
1943  *
1944  * Deprecated: 3.2: Use #GtkFontChooserDialog
1945  */
1946 void
1947 gtk_font_selection_dialog_set_preview_text (GtkFontSelectionDialog *fsd,
1948                                             const gchar            *text)
1949 {
1950   GtkFontSelectionDialogPrivate *priv;
1951
1952   g_return_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd));
1953   g_return_if_fail (text != NULL);
1954
1955   priv = fsd->priv;
1956
1957   gtk_font_selection_set_preview_text (GTK_FONT_SELECTION (priv->fontsel), text);
1958 }