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