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