]> Pileus Git - ~andy/gtk/blob - gtk/gtkfontchooser.c
GtkFontChooser: Add private members to GtkFontSelectionPrivate
[~andy/gtk] / gtk / gtkfontchooser.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * Massively updated for Pango by Owen Taylor, May 2000
5  * GtkFontSelection widget for Gtk+, by Damon Chaplin, May 1998.
6  * Based on the GnomeFontSelector widget, by Elliot Lee, but major changes.
7  * The GnomeFontSelector was derived from app/text_tool.c in the GIMP.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24
25 /*
26  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
27  * file for a list of people on the GTK+ Team.  See the ChangeLog
28  * files for a list of changes.  These files are distributed with
29  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
30  */
31
32 #include "config.h"
33
34 #include <stdlib.h>
35 #include <glib/gprintf.h>
36 #include <string.h>
37
38 #include <atk/atk.h>
39
40 #include "gtkfontsel.h"
41 #include "gtkbutton.h"
42 #include "gtkcellrenderertext.h"
43 #include "gtkentry.h"
44 #include "gtkframe.h"
45 #include "gtkhbbox.h"
46 #include "gtkhbox.h"
47 #include "gtklabel.h"
48 #include "gtkliststore.h"
49 #include "gtkrc.h"
50 #include "gtkstock.h"
51 #include "gtktable.h"
52 #include "gtktreeselection.h"
53 #include "gtktreeview.h"
54 #include "gtkvbox.h"
55 #include "gtkscrolledwindow.h"
56 #include "gtkintl.h"
57 #include "gtkaccessible.h"
58 #include "gtkbuildable.h"
59 #include "gtkprivate.h"
60
61
62 /**
63  * SECTION:gtkfontsel
64  * @Short_description: A widget for selecting fonts
65  * @Title: GtkFontSelection
66  * @See_also: #GtkFontSelectionDialog
67  *
68  * The #GtkFontSelection widget lists the available fonts, styles and sizes,
69  * allowing the user to select a font.
70  * It is used in the #GtkFontSelectionDialog widget to provide a dialog box for
71  * selecting fonts.
72  *
73  * To set the font which is initially selected, use
74  * gtk_font_selection_set_font_name().
75  *
76  * To get the selected font use gtk_font_selection_get_font_name().
77  *
78  * To change the text which is shown in the preview area, use
79  * gtk_font_selection_set_preview_text().
80  */
81
82
83 struct _GtkFontSelectionPrivate
84 {
85   GtkWidget *search_entry;
86   GtkWidget *family_face_list;
87   GtkWidget *size_slider;
88   GtkWidget *size_spinner;
89
90   gint             size;
91   PangoFontFace   *face;
92   PangoFontFamily *family;
93 };
94
95
96 struct _GtkFontSelectionDialogPrivate
97 {
98   GtkWidget *fontsel;
99
100   GtkWidget *ok_button;
101   GtkWidget *apply_button;
102   GtkWidget *cancel_button;
103 };
104
105
106 /* We don't enable the font and style entries because they don't add
107  * much in terms of visible effect and have a weird effect on keynav.
108  * the Windows font selector has entries similarly positioned but they
109  * act in conjunction with the associated lists to form a single focus
110  * location.
111  */
112 #undef INCLUDE_FONT_ENTRIES
113
114 /* This is the default text shown in the preview entry, though the user
115    can set it. Remember that some fonts only have capital letters. */
116 #define PREVIEW_TEXT N_("abcdefghijk ABCDEFGHIJK")
117
118 #define DEFAULT_FONT_NAME "Sans 10"
119
120 /* This is the initial and maximum height of the preview entry (it expands
121    when large font sizes are selected). Initial height is also the minimum. */
122 #define INITIAL_PREVIEW_HEIGHT 44
123 #define MAX_PREVIEW_HEIGHT 300
124
125 /* These are the sizes of the font, style & size lists. */
126 #define FONT_LIST_HEIGHT        136
127 #define FONT_LIST_WIDTH         190
128 #define FONT_STYLE_LIST_WIDTH   170
129 #define FONT_SIZE_LIST_WIDTH    60
130
131 /* These are what we use as the standard font sizes, for the size list.
132  */
133 static const guint16 font_sizes[] = {
134   6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 26, 28,
135   32, 36, 40, 48, 56, 64, 72
136 };
137
138 enum {
139    PROP_0,
140    PROP_FONT_NAME,
141    PROP_PREVIEW_TEXT
142 };
143
144
145 enum {
146   FAMILY_COLUMN,
147   FAMILY_NAME_COLUMN
148 };
149
150 enum {
151   FACE_COLUMN,
152   FACE_NAME_COLUMN
153 };
154
155 enum {
156   SIZE_COLUMN
157 };
158
159 static void    gtk_font_selection_set_property       (GObject         *object,
160                                                       guint            prop_id,
161                                                       const GValue    *value,
162                                                       GParamSpec      *pspec);
163 static void    gtk_font_selection_get_property       (GObject         *object,
164                                                       guint            prop_id,
165                                                       GValue          *value,
166                                                       GParamSpec      *pspec);
167 static void    gtk_font_selection_finalize           (GObject         *object);
168 static void    gtk_font_selection_screen_changed     (GtkWidget       *widget,
169                                                       GdkScreen       *previous_screen);
170 static void    gtk_font_selection_style_updated      (GtkWidget      *widget);
171
172 static void     gtk_font_selection_ref_family            (GtkFontSelection *fontsel,
173                                                           PangoFontFamily  *family);
174 static void     gtk_font_selection_ref_face              (GtkFontSelection *fontsel,
175                                                           PangoFontFace    *face);
176
177 G_DEFINE_TYPE (GtkFontSelection, gtk_font_selection, GTK_TYPE_VBOX)
178
179 static void
180 gtk_font_selection_class_init (GtkFontSelectionClass *klass)
181 {
182   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
183   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
184
185   gobject_class->finalize = gtk_font_selection_finalize;
186   gobject_class->set_property = gtk_font_selection_set_property;
187   gobject_class->get_property = gtk_font_selection_get_property;
188
189   widget_class->screen_changed = gtk_font_selection_screen_changed;
190   widget_class->style_updated = gtk_font_selection_style_updated;
191    
192   g_object_class_install_property (gobject_class,
193                                    PROP_FONT_NAME,
194                                    g_param_spec_string ("font-name",
195                                                         P_("Font name"),
196                                                         P_("The string that represents this font"),
197                                                         DEFAULT_FONT_NAME,
198                                                         GTK_PARAM_READWRITE));
199   g_object_class_install_property (gobject_class,
200                                    PROP_PREVIEW_TEXT,
201                                    g_param_spec_string ("preview-text",
202                                                         P_("Preview text"),
203                                                         P_("The text to display in order to demonstrate the selected font"),
204                                                         _(PREVIEW_TEXT),
205                                                         GTK_PARAM_READWRITE));
206
207   g_type_class_add_private (klass, sizeof (GtkFontSelectionPrivate));
208 }
209
210 static void 
211 gtk_font_selection_set_property (GObject         *object,
212                                  guint            prop_id,
213                                  const GValue    *value,
214                                  GParamSpec      *pspec)
215 {
216   GtkFontSelection *fontsel;
217
218   fontsel = GTK_FONT_SELECTION (object);
219
220   switch (prop_id)
221     {
222     case PROP_FONT_NAME:
223       gtk_font_selection_set_font_name (fontsel, g_value_get_string (value));
224       break;
225     case PROP_PREVIEW_TEXT:
226       gtk_font_selection_set_preview_text (fontsel, g_value_get_string (value));
227       break;
228     default:
229       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
230       break;
231     }
232 }
233
234 static void gtk_font_selection_get_property (GObject         *object,
235                                              guint            prop_id,
236                                              GValue          *value,
237                                              GParamSpec      *pspec)
238 {
239   GtkFontSelection *fontsel;
240
241   fontsel = GTK_FONT_SELECTION (object);
242
243   switch (prop_id)
244     {
245     case PROP_FONT_NAME:
246       g_value_take_string (value, gtk_font_selection_get_font_name (fontsel));
247       break;
248     case PROP_PREVIEW_TEXT:
249       g_value_set_string (value, gtk_font_selection_get_preview_text (fontsel));
250       break;
251     default:
252       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
253       break;
254     }
255 }
256
257 /* Handles key press events on the lists, so that we can trap Enter to
258  * activate the default button on our own.
259  */
260 static gboolean
261 list_row_activated (GtkWidget *widget)
262 {
263   GtkWidget *default_widget, *focus_widget;
264   GtkWindow *window;
265   
266   window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (widget)));
267   if (!gtk_widget_is_toplevel (GTK_WIDGET (window)))
268     window = NULL;
269
270   if (window)
271     {
272       default_widget = gtk_window_get_default_widget (window);
273       focus_widget = gtk_window_get_focus (window);
274
275       if (widget != default_widget &&
276           !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
277         gtk_window_activate_default (window);
278     }
279
280   return TRUE;
281 }
282
283 static void
284 gtk_font_selection_init (GtkFontSelection *fontsel)
285 {
286   GtkFontSelectionPrivate *priv;
287   GtkWidget *scrolled_win;
288   GtkWidget *text_box;
289   GtkWidget *table, *label;
290   GtkWidget *font_label, *style_label;
291   GtkWidget *vbox;
292   GtkListStore *model;
293   GtkTreeViewColumn *column;
294   GList *focus_chain = NULL;
295   AtkObject *atk_obj;
296
297   fontsel->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontsel,
298                                                GTK_TYPE_FONT_SELECTION,
299                                                GtkFontSelectionPrivate);
300   priv = fontsel->priv;
301   gtk_widget_push_composite_child ();
302   gtk_widget_pop_composite_child();
303 }
304
305 /**
306  * gtk_font_selection_new:
307  *
308  * Creates a new #GtkFontSelection.
309  *
310  * Return value: a n ew #GtkFontSelection
311  */
312 GtkWidget *
313 gtk_font_selection_new (void)
314 {
315   GtkFontSelection *fontsel;
316   
317   fontsel = g_object_new (GTK_TYPE_FONT_SELECTION, NULL);
318   
319   return GTK_WIDGET (fontsel);
320 }
321
322 static void
323 gtk_font_selection_finalize (GObject *object)
324 {
325   GtkFontSelection *fontsel = GTK_FONT_SELECTION (object);
326
327   gtk_font_selection_ref_family (fontsel, NULL);
328   gtk_font_selection_ref_face (fontsel, NULL);
329
330   G_OBJECT_CLASS (gtk_font_selection_parent_class)->finalize (object);
331 }
332
333 static void
334 gtk_font_selection_screen_changed (GtkWidget *widget,
335                                   GdkScreen *previous_screen)
336 {
337   return;
338 }
339
340 static void
341 gtk_font_selection_style_updated (GtkWidget *widget)
342 {
343   GTK_WIDGET_CLASS (gtk_font_selection_parent_class)->style_updated (widget);
344
345   return;
346 }
347
348 static void
349 gtk_font_selection_ref_family (GtkFontSelection *fontsel,
350                               PangoFontFamily  *family)
351 {
352   GtkFontSelectionPrivate *priv = fontsel->priv;
353 #if 0
354   if (family)
355     family = g_object_ref (family);
356   if (priv->family)
357     g_object_unref (priv->family);
358   priv->family = family;
359 #endif
360 }
361
362 static void
363 gtk_font_selection_ref_face (GtkFontSelection *fontsel,
364                                         PangoFontFace    *face)
365 {
366   GtkFontSelectionPrivate *priv = fontsel->priv;
367 #if 0
368   if (face)
369     face = g_object_ref (face);
370   if (priv->face)
371     g_object_unref (priv->face);
372   priv->face = face;
373 #endif
374 }
375
376 /*****************************************************************************
377  * These functions are the main public interface for getting/setting the font.
378  *****************************************************************************/
379
380 /**
381  * gtk_font_selection_get_family_list:
382  * @fontsel: a #GtkFontSelection
383  *
384  * This returns the #GtkTreeView that lists font families, for
385  * example, 'Sans', 'Serif', etc.
386  *
387  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
388  *
389  * Deprecated: 3.2
390  */
391 GtkWidget *
392 gtk_font_selection_get_family_list (GtkFontSelection *fontsel)
393 {
394   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
395
396   return NULL;
397 }
398
399 /**
400  * gtk_font_selection_get_face_list:
401  * @fontsel: a #GtkFontSelection
402  *
403  * This returns the #GtkTreeView which lists all styles available for
404  * the selected font. For example, 'Regular', 'Bold', etc.
405  * 
406  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
407  *
408  * Deprecated: 3.2
409  */
410 GtkWidget *
411 gtk_font_selection_get_face_list (GtkFontSelection *fontsel)
412 {
413   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
414
415   return NULL;
416 }
417
418 /**
419  * gtk_font_selection_get_size_entry:
420  * @fontsel: a #GtkFontSelection
421  *
422  * This returns the #GtkEntry used to allow the user to edit the font
423  * number manually instead of selecting it from the list of font sizes.
424  *
425  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
426  *
427  * Deprecated: 3.2
428  */
429 GtkWidget *
430 gtk_font_selection_get_size_entry (GtkFontSelection *fontsel)
431 {
432   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
433
434   return NULL;
435 }
436
437 /**
438  * gtk_font_selection_get_size_list:
439  * @fontsel: a #GtkFontSelection
440  *
441  * This returns the #GtkTreeeView used to list font sizes.
442  *
443  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
444  *
445  * Deprecated: 3.2
446  */
447 GtkWidget *
448 gtk_font_selection_get_size_list (GtkFontSelection *fontsel)
449 {
450   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
451
452   return NULL;
453 }
454
455 /**
456  * gtk_font_selection_get_preview_entry:
457  * @fontsel: a #GtkFontSelection
458  *
459  * This returns the #GtkEntry used to display the font as a preview.
460  *
461  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
462  *
463  * Deprecated: 3.2
464  */
465 GtkWidget *
466 gtk_font_selection_get_preview_entry (GtkFontSelection *fontsel)
467 {
468   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
469
470   return NULL;
471 }
472
473 /**
474  * gtk_font_selection_get_family:
475  * @fontsel: a #GtkFontSelection
476  *
477  * Gets the #PangoFontFamily representing the selected font family.
478  *
479  * Return value: (transfer none): A #PangoFontFamily representing the
480  *     selected font family. Font families are a collection of font
481  *     faces. The returned object is owned by @fontsel and must not
482  *     be modified or freed.
483  *
484  * Since: 2.14
485  */
486 PangoFontFamily *
487 gtk_font_selection_get_family (GtkFontSelection *fontsel)
488 {
489   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
490
491   return NULL;
492 }
493
494 /**
495  * gtk_font_selection_get_face:
496  * @fontsel: a #GtkFontSelection
497  *
498  * Gets the #PangoFontFace representing the selected font group
499  * details (i.e. family, slant, weight, width, etc).
500  *
501  * Return value: (transfer none): A #PangoFontFace representing the
502  *     selected font group details. The returned object is owned by
503  *     @fontsel and must not be modified or freed.
504  *
505  * Since: 2.14
506  */
507 PangoFontFace *
508 gtk_font_selection_get_face (GtkFontSelection *fontsel)
509 {
510   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
511
512   return NULL;
513 }
514
515 /**
516  * gtk_font_selection_get_size:
517  * @fontsel: a #GtkFontSelection
518  *
519  * The selected font size.
520  *
521  * Return value: A n integer representing the selected font size,
522  *     or -1 if no font size is selected.
523  *
524  * Since: 2.14
525  **/
526 gint
527 gtk_font_selection_get_size (GtkFontSelection *fontsel)
528 {
529   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), -1);
530
531   return NULL;
532 }
533
534 /**
535  * gtk_font_selection_get_font_name:
536  * @fontsel: a #GtkFontSelection
537  * 
538  * Gets the currently-selected font name. 
539  *
540  * Note that this can be a different string than what you set with 
541  * gtk_font_selection_set_font_name(), as the font selection widget may 
542  * normalize font names and thus return a string with a different structure. 
543  * For example, "Helvetica Italic Bold 12" could be normalized to 
544  * "Helvetica Bold Italic 12". Use pango_font_description_equal()
545  * if you want to compare two font descriptions.
546  * 
547  * Return value: A string with the name of the current font, or %NULL if 
548  *     no font is selected. You must free this string with g_free().
549  */
550 gchar *
551 gtk_font_selection_get_font_name (GtkFontSelection *fontsel)
552 {
553   return NULL;
554 }
555
556 /* This sets the current font, then selecting the appropriate list rows. */
557
558 /**
559  * gtk_font_selection_set_font_name:
560  * @fontsel: a #GtkFontSelection
561  * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
562  * 
563  * Sets the currently-selected font. 
564  *
565  * Note that the @fontsel needs to know the screen in which it will appear 
566  * for this to work; this can be guaranteed by simply making sure that the 
567  * @fontsel is inserted in a toplevel window before you call this function.
568  * 
569  * Return value: %TRUE if the font could be set successfully; %FALSE if no 
570  *     such font exists or if the @fontsel doesn't belong to a particular 
571  *     screen yet.
572  */
573 gboolean
574 gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
575                                   const gchar      *fontname)
576 {
577   PangoFontFamily *family = NULL;
578   PangoFontFace *face = NULL;
579   PangoFontDescription *new_desc;
580   
581   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), FALSE);
582
583   return TRUE;
584 }
585
586 /**
587  * gtk_font_selection_get_preview_text:
588  * @fontsel: a #GtkFontSelection
589  *
590  * Gets the text displayed in the preview area.
591  * 
592  * Return value: the text displayed in the preview area. 
593  *     This string is owned by the widget and should not be 
594  *     modified or freed 
595  */
596 G_CONST_RETURN gchar*
597 gtk_font_selection_get_preview_text (GtkFontSelection *fontsel)
598 {
599   return NULL;
600 }
601
602
603 /**
604  * gtk_font_selection_set_preview_text:
605  * @fontsel: a #GtkFontSelection
606  * @text: the text to display in the preview area 
607  *
608  * Sets the text displayed in the preview area.
609  * The @text is used to show how the selected font looks.
610  */
611 void
612 gtk_font_selection_set_preview_text  (GtkFontSelection *fontsel,
613                                       const gchar      *text)
614 {
615   GtkFontSelectionPrivate *priv;
616
617   g_return_if_fail (GTK_IS_FONT_SELECTION (fontsel));
618   g_return_if_fail (text != NULL);
619
620   priv = fontsel->priv;
621 }
622
623
624 /**
625  * SECTION:gtkfontseldlg
626  * @Short_description: A dialog box for selecting fonts
627  * @Title: GtkFontSelectionDialog
628  * @See_also: #GtkFontSelection, #GtkDialog
629  *
630  * The #GtkFontSelectionDialog widget is a dialog box for selecting a font.
631  *
632  * To set the font which is initially selected, use
633  * gtk_font_selection_dialog_set_font_name().
634  *
635  * To get the selected font use gtk_font_selection_dialog_get_font_name().
636  *
637  * To change the text which is shown in the preview area, use
638  * gtk_font_selection_dialog_set_preview_text().
639  *
640  * <refsect2 id="GtkFontSelectionDialog-BUILDER-UI">
641  * <title>GtkFontSelectionDialog as GtkBuildable</title>
642  * The GtkFontSelectionDialog implementation of the GtkBuildable interface
643  * exposes the embedded #GtkFontSelection as internal child with the
644  * name "font_selection". It also exposes the buttons with the names
645  * "ok_button", "cancel_button" and "apply_button".
646  * </refsect2>
647  */
648
649 static void gtk_font_selection_dialog_buildable_interface_init     (GtkBuildableIface *iface);
650 static GObject * gtk_font_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
651                                                                           GtkBuilder   *builder,
652                                                                           const gchar  *childname);
653
654 G_DEFINE_TYPE_WITH_CODE (GtkFontSelectionDialog, gtk_font_selection_dialog,
655                          GTK_TYPE_DIALOG,
656                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
657                                                 gtk_font_selection_dialog_buildable_interface_init))
658
659 static GtkBuildableIface *parent_buildable_iface;
660
661 static void
662 gtk_font_selection_dialog_class_init (GtkFontSelectionDialogClass *klass)
663 {
664   g_type_class_add_private (klass, sizeof (GtkFontSelectionDialogPrivate));
665 }
666
667 static void
668 gtk_font_selection_dialog_init (GtkFontSelectionDialog *fontseldiag)
669 {
670   GtkFontSelectionDialogPrivate *priv;
671   GtkDialog *dialog = GTK_DIALOG (fontseldiag);
672   GtkWidget *action_area, *content_area;
673
674   fontseldiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontseldiag,
675                                                    GTK_TYPE_FONT_SELECTION_DIALOG,
676                                                    GtkFontSelectionDialogPrivate);
677   priv = fontseldiag->priv;
678
679   content_area = gtk_dialog_get_content_area (dialog);
680   action_area = gtk_dialog_get_action_area (dialog);
681
682   gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
683   gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
684   gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
685   gtk_box_set_spacing (GTK_BOX (action_area), 6);
686
687   gtk_widget_push_composite_child ();
688
689   gtk_window_set_resizable (GTK_WINDOW (fontseldiag), TRUE);
690
691   /* Create the content area */
692   priv->fontsel = gtk_font_selection_new ();
693   gtk_container_set_border_width (GTK_CONTAINER (priv->fontsel), 5);
694   gtk_widget_show (priv->fontsel);
695   gtk_box_pack_start (GTK_BOX (content_area),
696                       priv->fontsel, TRUE, TRUE, 0);
697
698   /* Create the action area */
699   priv->cancel_button = gtk_dialog_add_button (dialog,
700                                                GTK_STOCK_CANCEL,
701                                                GTK_RESPONSE_CANCEL);
702
703   priv->apply_button = gtk_dialog_add_button (dialog,
704                                               GTK_STOCK_APPLY,
705                                               GTK_RESPONSE_APPLY);
706   gtk_widget_hide (priv->apply_button);
707
708   priv->ok_button = gtk_dialog_add_button (dialog,
709                                            GTK_STOCK_OK,
710                                            GTK_RESPONSE_OK);
711   gtk_widget_grab_default (priv->ok_button);
712
713   gtk_dialog_set_alternative_button_order (GTK_DIALOG (fontseldiag),
714                                            GTK_RESPONSE_OK,
715                                            GTK_RESPONSE_APPLY,
716                                            GTK_RESPONSE_CANCEL,
717                                            -1);
718
719   gtk_window_set_title (GTK_WINDOW (fontseldiag),
720                         _("Font Selection"));
721
722   gtk_widget_pop_composite_child ();
723 }
724
725 /**
726  * gtk_font_selection_dialog_new:
727  * @title: the title of the dialog window 
728  *
729  * Creates a new #GtkFontSelectionDialog.
730  *
731  * Return value: a new #GtkFontSelectionDialog
732  */
733 GtkWidget*
734 gtk_font_selection_dialog_new (const gchar *title)
735 {
736   GtkFontSelectionDialog *fontseldiag;
737   
738   fontseldiag = g_object_new (GTK_TYPE_FONT_SELECTION_DIALOG, NULL);
739
740   if (title)
741     gtk_window_set_title (GTK_WINDOW (fontseldiag), title);
742   
743   return GTK_WIDGET (fontseldiag);
744 }
745
746 /**
747  * gtk_font_selection_dialog_get_font_selection:
748  * @fsd: a #GtkFontSelectionDialog
749  *
750  * Retrieves the #GtkFontSelection widget embedded in the dialog.
751  *
752  * Returns: (transfer none): the embedded #GtkFontSelection
753  *
754  * Since: 2.22
755  **/
756 GtkWidget*
757 gtk_font_selection_dialog_get_font_selection (GtkFontSelectionDialog *fsd)
758 {
759   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
760
761   return fsd->priv->fontsel;
762 }
763
764
765 /**
766  * gtk_font_selection_dialog_get_ok_button:
767  * @fsd: a #GtkFontSelectionDialog
768  *
769  * Gets the 'OK' button.
770  *
771  * Return value: (transfer none): the #GtkWidget used in the dialog
772  *     for the 'OK' button.
773  *
774  * Since: 2.14
775  */
776 GtkWidget *
777 gtk_font_selection_dialog_get_ok_button (GtkFontSelectionDialog *fsd)
778 {
779   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
780
781   return fsd->priv->ok_button;
782 }
783
784 /**
785  * gtk_font_selection_dialog_get_cancel_button:
786  * @fsd: a #GtkFontSelectionDialog
787  *
788  * Gets the 'Cancel' button.
789  *
790  * Return value: (transfer none): the #GtkWidget used in the dialog
791  *     for the 'Cancel' button.
792  *
793  * Since: 2.14
794  */
795 GtkWidget *
796 gtk_font_selection_dialog_get_cancel_button (GtkFontSelectionDialog *fsd)
797 {
798   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
799
800   return fsd->priv->cancel_button;
801 }
802
803 static void
804 gtk_font_selection_dialog_buildable_interface_init (GtkBuildableIface *iface)
805 {
806   parent_buildable_iface = g_type_interface_peek_parent (iface);
807   iface->get_internal_child = gtk_font_selection_dialog_buildable_get_internal_child;
808 }
809
810 static GObject *
811 gtk_font_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
812                                                         GtkBuilder   *builder,
813                                                         const gchar  *childname)
814 {
815   GtkFontSelectionDialogPrivate *priv;
816
817   priv = GTK_FONT_SELECTION_DIALOG (buildable)->priv;
818
819   if (g_strcmp0 (childname, "ok_button") == 0)
820     return G_OBJECT (priv->ok_button);
821   else if (g_strcmp0 (childname, "cancel_button") == 0)
822     return G_OBJECT (priv->cancel_button);
823   else if (g_strcmp0 (childname, "apply_button") == 0)
824     return G_OBJECT (priv->apply_button);
825   else if (g_strcmp0 (childname, "font_selection") == 0)
826     return G_OBJECT (priv->fontsel);
827
828   return parent_buildable_iface->get_internal_child (buildable, builder, childname);
829 }
830
831 /**
832  * gtk_font_selection_dialog_get_font_name:
833  * @fsd: a #GtkFontSelectionDialog
834  * 
835  * Gets the currently-selected font name.
836  *
837  * Note that this can be a different string than what you set with 
838  * gtk_font_selection_dialog_set_font_name(), as the font selection widget
839  * may normalize font names and thus return a string with a different 
840  * structure. For example, "Helvetica Italic Bold 12" could be normalized 
841  * to "Helvetica Bold Italic 12".  Use pango_font_description_equal()
842  * if you want to compare two font descriptions.
843  * 
844  * Return value: A string with the name of the current font, or %NULL if no 
845  *     font is selected. You must free this string with g_free().
846  */
847 gchar*
848 gtk_font_selection_dialog_get_font_name (GtkFontSelectionDialog *fsd)
849 {
850   GtkFontSelectionDialogPrivate *priv;
851
852   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
853
854   priv = fsd->priv;
855
856   return gtk_font_selection_get_font_name (GTK_FONT_SELECTION (priv->fontsel));
857 }
858
859 /**
860  * gtk_font_selection_dialog_set_font_name:
861  * @fsd: a #GtkFontSelectionDialog
862  * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
863  *
864  * Sets the currently selected font. 
865  * 
866  * Return value: %TRUE if the font selected in @fsd is now the
867  *     @fontname specified, %FALSE otherwise. 
868  */
869 gboolean
870 gtk_font_selection_dialog_set_font_name (GtkFontSelectionDialog *fsd,
871                                          const gchar            *fontname)
872 {
873   GtkFontSelectionDialogPrivate *priv;
874
875   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), FALSE);
876   g_return_val_if_fail (fontname, FALSE);
877
878   priv = fsd->priv;
879
880   return gtk_font_selection_set_font_name (GTK_FONT_SELECTION (priv->fontsel), fontname);
881 }
882
883 /**
884  * gtk_font_selection_dialog_get_preview_text:
885  * @fsd: a #GtkFontSelectionDialog
886  *
887  * Gets the text displayed in the preview area.
888  * 
889  * Return value: the text displayed in the preview area. 
890  *     This string is owned by the widget and should not be 
891  *     modified or freed 
892  */
893 G_CONST_RETURN gchar*
894 gtk_font_selection_dialog_get_preview_text (GtkFontSelectionDialog *fsd)
895 {
896   GtkFontSelectionDialogPrivate *priv;
897
898   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
899
900   priv = fsd->priv;
901
902   return gtk_font_selection_get_preview_text (GTK_FONT_SELECTION (priv->fontsel));
903 }
904
905 /**
906  * gtk_font_selection_dialog_set_preview_text:
907  * @fsd: a #GtkFontSelectionDialog
908  * @text: the text to display in the preview area
909  *
910  * Sets the text displayed in the preview area. 
911  */
912 void
913 gtk_font_selection_dialog_set_preview_text (GtkFontSelectionDialog *fsd,
914                                             const gchar            *text)
915 {
916   GtkFontSelectionDialogPrivate *priv;
917
918   g_return_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd));
919   g_return_if_fail (text != NULL);
920
921   priv = fsd->priv;
922
923   gtk_font_selection_set_preview_text (GTK_FONT_SELECTION (priv->fontsel), text);
924 }