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