]> Pileus Git - ~andy/gtk/blob - gtk/gtkfontchooser.c
GtkFontChooser: Inserted and deleted text callbacks
[~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 #include "gtkalignment.h"
61 #include "gtkscale.h"
62 #include "gtkbox.h"
63 #include "gtkspinbutton.h"
64
65
66 /**
67  * SECTION:gtkfontsel
68  * @Short_description: A widget for selecting fonts
69  * @Title: GtkFontSelection
70  * @See_also: #GtkFontSelectionDialog
71  *
72  * The #GtkFontSelection widget lists the available fonts, styles and sizes,
73  * allowing the user to select a font.
74  * It is used in the #GtkFontSelectionDialog widget to provide a dialog box for
75  * selecting fonts.
76  *
77  * To set the font which is initially selected, use
78  * gtk_font_selection_set_font_name().
79  *
80  * To get the selected font use gtk_font_selection_get_font_name().
81  *
82  * To change the text which is shown in the preview area, use
83  * gtk_font_selection_set_preview_text().
84  */
85
86
87 struct _GtkFontSelectionPrivate
88 {
89   GtkWidget *search_entry;
90   GtkWidget *family_face_list;
91   GtkWidget *size_slider;
92   GtkWidget *size_spin;
93   GtkWidget *preview;
94
95   GtkListStore *model;  
96   GtkTreeModel *filter;
97
98   gint             size;
99   PangoFontFace   *face;
100   PangoFontFamily *family;
101 };
102
103
104 struct _GtkFontSelectionDialogPrivate
105 {
106   GtkWidget *fontsel;
107
108   GtkWidget *ok_button;
109   GtkWidget *apply_button;
110   GtkWidget *cancel_button;
111 };
112
113
114 /* We don't enable the font and style entries because they don't add
115  * much in terms of visible effect and have a weird effect on keynav.
116  * the Windows font selector has entries similarly positioned but they
117  * act in conjunction with the associated lists to form a single focus
118  * location.
119  */
120 #undef INCLUDE_FONT_ENTRIES
121
122 /* This is the default text shown in the preview entry, though the user
123    can set it. Remember that some fonts only have capital letters. */
124 #define PREVIEW_TEXT N_("abcdefghijk ABCDEFGHIJK")
125
126 #define DEFAULT_FONT_NAME "Sans 10"
127
128 /* This is the initial fixed height and the top padding of the preview entry */
129 #define PREVIEW_HEIGHT 84
130 #define PREVIEW_TOP_PADDING 6
131
132 /* These are the sizes of the font, style & size lists. */
133 #define FONT_LIST_HEIGHT        136
134 #define FONT_LIST_WIDTH         190
135 #define FONT_STYLE_LIST_WIDTH   170
136 #define FONT_SIZE_LIST_WIDTH    60
137
138 #define ROW_FORMAT_STRING "<span size=\"small\" foreground=\"%s\">%s <i>%s</i></span>\n<span size=\"large\" font_desc=\"%s\">%s</span>"
139
140 /* These are what we use as the standard font sizes, for the size list.
141  */
142 #define FONT_SIZES_LENGTH 25
143 static const guint16 font_sizes[] = {
144   6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 26, 28,
145   32, 36, 40, 48, 56, 64, 72
146 };
147
148 enum {
149    PROP_0,
150    PROP_FONT_NAME,
151    PROP_PREVIEW_TEXT
152 };
153
154
155 enum {
156   FAMILY_COLUMN,
157   FACE_COLUMN,
158   FAMILY_NAME_COLUMN,
159   TEXT_COLUMN
160 };
161
162 static void    gtk_font_selection_set_property       (GObject         *object,
163                                                       guint            prop_id,
164                                                       const GValue    *value,
165                                                       GParamSpec      *pspec);
166 static void    gtk_font_selection_get_property       (GObject         *object,
167                                                       guint            prop_id,
168                                                       GValue          *value,
169                                                       GParamSpec      *pspec);
170 static void    gtk_font_selection_finalize           (GObject         *object);
171 static void    gtk_font_selection_screen_changed     (GtkWidget       *widget,
172                                                       GdkScreen       *previous_screen);
173 static void    gtk_font_selection_style_updated      (GtkWidget      *widget);
174
175 static void     gtk_font_selection_ref_family            (GtkFontSelection *fontsel,
176                                                           PangoFontFamily  *family);
177 static void     gtk_font_selection_ref_face              (GtkFontSelection *fontsel,
178                                                           PangoFontFace    *face);
179 static void gtk_font_selection_bootstrap_fontlist (GtkFontSelection *fontsel);
180
181 G_DEFINE_TYPE (GtkFontSelection, gtk_font_selection, GTK_TYPE_VBOX)
182
183 static void
184 gtk_font_selection_class_init (GtkFontSelectionClass *klass)
185 {
186   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
187   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
188
189   gobject_class->finalize = gtk_font_selection_finalize;
190   gobject_class->set_property = gtk_font_selection_set_property;
191   gobject_class->get_property = gtk_font_selection_get_property;
192
193   widget_class->screen_changed = gtk_font_selection_screen_changed;
194   widget_class->style_updated = gtk_font_selection_style_updated;
195    
196   g_object_class_install_property (gobject_class,
197                                    PROP_FONT_NAME,
198                                    g_param_spec_string ("font-name",
199                                                         P_("Font name"),
200                                                         P_("The string that represents this font"),
201                                                         DEFAULT_FONT_NAME,
202                                                         GTK_PARAM_READWRITE));
203   g_object_class_install_property (gobject_class,
204                                    PROP_PREVIEW_TEXT,
205                                    g_param_spec_string ("preview-text",
206                                                         P_("Preview text"),
207                                                         P_("The text to display in order to demonstrate the selected font"),
208                                                         _(PREVIEW_TEXT),
209                                                         GTK_PARAM_READWRITE));
210
211   g_type_class_add_private (klass, sizeof (GtkFontSelectionPrivate));
212 }
213
214 static void 
215 gtk_font_selection_set_property (GObject         *object,
216                                  guint            prop_id,
217                                  const GValue    *value,
218                                  GParamSpec      *pspec)
219 {
220   GtkFontSelection *fontsel;
221
222   fontsel = GTK_FONT_SELECTION (object);
223
224   switch (prop_id)
225     {
226     case PROP_FONT_NAME:
227       gtk_font_selection_set_font_name (fontsel, g_value_get_string (value));
228       break;
229     case PROP_PREVIEW_TEXT:
230       gtk_font_selection_set_preview_text (fontsel, g_value_get_string (value));
231       break;
232     default:
233       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
234       break;
235     }
236 }
237
238 static void gtk_font_selection_get_property (GObject         *object,
239                                              guint            prop_id,
240                                              GValue          *value,
241                                              GParamSpec      *pspec)
242 {
243   GtkFontSelection *fontsel;
244
245   fontsel = GTK_FONT_SELECTION (object);
246
247   switch (prop_id)
248     {
249     case PROP_FONT_NAME:
250       g_value_take_string (value, gtk_font_selection_get_font_name (fontsel));
251       break;
252     case PROP_PREVIEW_TEXT:
253       g_value_set_string (value, gtk_font_selection_get_preview_text (fontsel));
254       break;
255     default:
256       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
257       break;
258     }
259 }
260
261 void
262 deleted_text_cb (GtkEntryBuffer *buffer,
263                  guint           position,
264                  guint           n_chars,
265                  gpointer        user_data)
266 {
267   g_debug( "deleted text");
268 }
269
270 void
271 inserted_text_cb (GtkEntryBuffer *buffer,
272                   guint           position,
273                   gchar          *chars,
274                   guint           n_chars,
275                   gpointer        user_data) 
276 {
277   g_debug ("inserted text");
278 }
279
280 static void
281 gtk_font_selection_init (GtkFontSelection *fontsel)
282 {
283   GtkFontSelectionPrivate *priv;
284   PangoFontDescription    *font_desc;
285   GtkWidget               *scrolled_win;
286   GtkWidget               *alignment;
287   GtkWidget               *preview_and_size;
288   GtkWidget               *size_controls;
289 #if 0
290   GList                   *focus_chain = NULL;
291   AtkObject *atk_obj;
292 #endif
293
294   fontsel->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontsel,
295                                                GTK_TYPE_FONT_SELECTION,
296                                                GtkFontSelectionPrivate);
297   priv = fontsel->priv;
298   gtk_widget_push_composite_child ();
299
300   /* Creating fundamental widgets for the private struct */
301   priv->search_entry = gtk_entry_new ();
302   priv->family_face_list = gtk_tree_view_new ();
303   priv->preview = gtk_entry_new ();
304   priv->size_slider = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
305                                                 (gdouble) font_sizes[0],
306                                                 (gdouble) font_sizes[FONT_SIZES_LENGTH - 1],
307                                                 1.0);
308
309   priv->size_spin = gtk_spin_button_new (NULL, 1.0, 0);
310
311
312   /** Bootstrapping widget layout **/
313   /* Main font family/face view */
314   scrolled_win = gtk_scrolled_window_new (NULL, NULL);
315   gtk_container_add (GTK_CONTAINER (scrolled_win), priv->family_face_list);
316
317   /* Alignment for the preview and size controls */
318   alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
319   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment),
320                              PREVIEW_TOP_PADDING, 0, 0, 0);
321
322   preview_and_size = gtk_vbox_new (TRUE, 0);
323   gtk_box_set_homogeneous (GTK_BOX (preview_and_size), FALSE);
324   gtk_box_pack_start (GTK_BOX (preview_and_size), priv->preview, FALSE, TRUE, 0);
325   gtk_widget_set_size_request (priv->preview, -1, PREVIEW_HEIGHT);
326
327   /* Packing the slider and the spin in a hbox */
328   size_controls = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
329   gtk_scale_set_draw_value (GTK_SCALE (priv->size_slider), FALSE);
330   gtk_box_pack_start (GTK_BOX (size_controls), priv->size_slider, TRUE, TRUE, 0);
331   gtk_box_pack_start (GTK_BOX (size_controls), priv->size_spin, FALSE, TRUE, 0);
332
333   gtk_box_pack_start (GTK_BOX (preview_and_size), size_controls, FALSE, FALSE, 0);
334   gtk_container_add (GTK_CONTAINER (alignment), preview_and_size);
335
336   /* Packing everything in the selection */
337   gtk_box_pack_start (GTK_BOX (fontsel), priv->search_entry, FALSE, TRUE, 0);
338   gtk_box_pack_start (GTK_BOX (fontsel), scrolled_win, TRUE, TRUE, 0);
339   gtk_box_pack_start (GTK_BOX (fontsel), GTK_WIDGET(alignment), FALSE, TRUE, 0);
340
341   /* Getting the default size */
342   font_desc  = pango_context_get_font_description (gtk_widget_get_pango_context (GTK_WIDGET (fontsel)));
343   priv->size = pango_font_description_get_size (font_desc);
344   priv->face = NULL;
345   priv->family = NULL;
346
347   gtk_widget_show_all (GTK_WIDGET (fontsel));
348   gtk_widget_hide (GTK_WIDGET (fontsel));
349
350   /* Treeview column and model bootstrapping */
351   gtk_font_selection_bootstrap_fontlist (fontsel);
352   
353   /* Set default preview text */
354   gtk_entry_set_text (GTK_ENTRY (priv->preview),
355                       pango_language_get_sample_string (NULL));
356   
357   /** Callback connections **/
358   /* Connect to callback for the live search text entry */
359   g_signal_connect (G_OBJECT (gtk_entry_get_buffer (GTK_ENTRY (priv->search_entry))),
360                     "deleted-text", G_CALLBACK (deleted_text_cb), (gpointer)priv);
361   g_signal_connect (G_OBJECT (gtk_entry_get_buffer (GTK_ENTRY (priv->search_entry))),
362                     "inserted-text", G_CALLBACK (inserted_text_cb), (gpointer)priv);
363
364   gtk_widget_pop_composite_child();
365 }
366
367 /**
368  * gtk_font_selection_new:
369  *
370  * Creates a new #GtkFontSelection.
371  *
372  * Return value: a n ew #GtkFontSelection
373  */
374 GtkWidget *
375 gtk_font_selection_new (void)
376 {
377   GtkFontSelection *fontsel;
378   
379   fontsel = g_object_new (GTK_TYPE_FONT_SELECTION, NULL);
380   
381   return GTK_WIDGET (fontsel);
382 }
383
384 static int
385 cmp_families (const void *a, const void *b)
386 {
387   const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a);
388   const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b);
389
390   return g_utf8_collate (a_name, b_name);
391 }
392
393 static void
394 set_cursor_to_iter (GtkTreeView *view,
395                     GtkTreeIter *iter)
396 {
397   GtkTreeModel *model = gtk_tree_view_get_model (view);
398   GtkTreePath *path = gtk_tree_model_get_path (model, iter);
399
400   gtk_tree_view_set_cursor (view, path, NULL, FALSE);
401
402   gtk_tree_path_free (path);
403 }
404
405 static void 
406 populate_list (GtkTreeView* treeview, GtkListStore* model)
407 {
408   GtkStyleContext *style_context;
409   GdkRGBA          g_color;
410   PangoColor       p_color;
411   gchar            *color_string;
412
413   GtkTreeIter   match_row;
414
415   gint n_families, i;  
416   PangoFontFamily **families;
417
418   GString     *tmp = g_string_new (NULL);
419
420   pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (treeview)),
421                                &families,
422                                &n_families);
423
424   qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families);
425
426   gtk_list_store_clear (model);
427
428   /* Get row header font color */
429   style_context = gtk_widget_get_style_context (GTK_WIDGET (treeview));
430   gtk_style_context_get_color (style_context,
431                                GTK_STATE_FLAG_NORMAL |GTK_STATE_FLAG_INSENSITIVE,
432                                &g_color);
433
434   p_color.red   = (guint16)((gdouble)G_MAXUINT16 * g_color.red);
435   p_color.green = (guint16)((gdouble)G_MAXUINT16 * g_color.green);
436   p_color.blue  = (guint16)((gdouble)G_MAXUINT16 * g_color.blue);
437   color_string  = pango_color_to_string (&p_color);
438
439   /* Iterate over families and faces */
440   for (i=0; i<n_families; i++)
441     {
442       GtkTreeIter     iter;
443       PangoFontFace **faces;
444       int             j, n_faces;
445       const gchar    *fam_name = pango_font_family_get_name (families[i]);
446
447       pango_font_family_list_faces (families[i], &faces, &n_faces);
448       
449       for (j=0; j<n_faces; j++)
450         {
451           PangoFontDescription *pango_desc = pango_font_face_describe (faces[j]);
452           const gchar *face_name = pango_font_face_get_face_name (faces[j]);
453           gchar       *font_desc = pango_font_description_to_string (pango_desc);
454           
455           /* foreground_color, family_name, face_name, desc, sample string */
456           g_string_printf (tmp, ROW_FORMAT_STRING,
457                                 color_string,
458                                 fam_name,
459                                 face_name,
460                                 font_desc,
461                                 PREVIEW_TEXT);
462
463
464           gtk_list_store_append (model, &iter);
465           gtk_list_store_set (model, &iter,
466                               FAMILY_COLUMN, families[i],
467                               FACE_COLUMN, faces[j],
468                               FAMILY_NAME_COLUMN, fam_name,
469                               TEXT_COLUMN, tmp->str,
470                               -1);
471
472           if ((i == 0 && j == 0) ||
473               (!g_ascii_strcasecmp (face_name, "sans") && j == 0))
474             {
475               match_row = iter;
476             }
477
478           pango_font_description_free(pango_desc);
479           g_free (font_desc);
480         }
481
482       g_free (faces);
483     }
484
485   set_cursor_to_iter (treeview, &match_row);
486
487   g_string_free (tmp, TRUE);
488   g_free (color_string);
489   g_free (families);
490 }
491
492 gboolean
493 visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
494 {
495   GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*) data;
496
497   const gchar *search_text = (const gchar*)gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
498   gchar       *font_name;
499   gchar       *font_name_casefold;
500   gchar       *search_text_casefold;
501
502   gtk_tree_model_get (model, iter,
503                       FAMILY_NAME_COLUMN, &font_name,
504                       -1);
505
506   if (font_name == NULL)
507     {
508       g_free (font_name);
509       return FALSE;
510     }
511   
512   font_name_casefold = g_utf8_casefold (font_name, -1);
513   search_text_casefold = g_utf8_casefold (search_text, -1);
514
515   g_free (search_text_casefold);
516   g_free (font_name_casefold);
517   g_free (font_name);
518   return FALSE;
519 }
520
521 static void
522 gtk_font_selection_bootstrap_fontlist (GtkFontSelection* fontsel)
523 {
524   GtkTreeView       *treeview = GTK_TREE_VIEW (fontsel->priv->family_face_list);
525   GtkTreeViewColumn *col;
526
527   fontsel->priv->model = gtk_list_store_new (4,
528                                              PANGO_TYPE_FONT_FAMILY,
529                                              PANGO_TYPE_FONT_FACE,
530                                              G_TYPE_STRING,
531                                              G_TYPE_STRING);
532   fontsel->priv->filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fontsel->priv->model),
533                                                      NULL);
534   
535   gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (fontsel->priv->filter));
536   
537   gtk_tree_view_set_rules_hint      (treeview, TRUE);
538   gtk_tree_view_set_headers_visible (treeview, FALSE);
539
540   col = gtk_tree_view_column_new_with_attributes ("Family",
541                                                    gtk_cell_renderer_text_new (),
542                                                    "markup", TEXT_COLUMN,
543                                                    NULL);
544   gtk_tree_view_append_column (treeview, col);
545
546   populate_list (treeview, fontsel->priv->model);
547 }
548
549
550 static void
551 gtk_font_selection_finalize (GObject *object)
552 {
553   GtkFontSelection *fontsel = GTK_FONT_SELECTION (object);
554
555   gtk_font_selection_ref_family (fontsel, NULL);
556   gtk_font_selection_ref_face (fontsel, NULL);
557
558   G_OBJECT_CLASS (gtk_font_selection_parent_class)->finalize (object);
559 }
560
561 static void
562 gtk_font_selection_screen_changed (GtkWidget *widget,
563                                   GdkScreen *previous_screen)
564 {
565   return;
566 }
567
568 static void
569 gtk_font_selection_style_updated (GtkWidget *widget)
570 {
571   GTK_WIDGET_CLASS (gtk_font_selection_parent_class)->style_updated (widget);
572
573   return;
574 }
575
576 static void
577 gtk_font_selection_ref_family (GtkFontSelection *fontsel,
578                                PangoFontFamily  *family)
579 {
580   GtkFontSelectionPrivate *priv = fontsel->priv;
581
582   if (family)
583     family = g_object_ref (family);
584   if (priv->family)
585     g_object_unref (priv->family);
586   priv->family = family;
587 }
588
589 static void
590 gtk_font_selection_ref_face (GtkFontSelection *fontsel,
591                              PangoFontFace    *face)
592 {
593   GtkFontSelectionPrivate *priv = fontsel->priv;
594
595   if (face)
596     face = g_object_ref (face);
597   if (priv->face)
598     g_object_unref (priv->face);
599   priv->face = face;
600 }
601
602 /*****************************************************************************
603  * These functions are the main public interface for getting/setting the font.
604  *****************************************************************************/
605
606 /**
607  * gtk_font_selection_get_family_list:
608  * @fontsel: a #GtkFontSelection
609  *
610  * This returns the #GtkTreeView that lists font families, for
611  * example, 'Sans', 'Serif', etc.
612  *
613  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
614  *
615  * Deprecated: 3.2
616  */
617 GtkWidget *
618 gtk_font_selection_get_family_list (GtkFontSelection *fontsel)
619 {
620   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
621
622   return NULL;
623 }
624
625 /**
626  * gtk_font_selection_get_face_list:
627  * @fontsel: a #GtkFontSelection
628  *
629  * This returns the #GtkTreeView which lists all styles available for
630  * the selected font. For example, 'Regular', 'Bold', etc.
631  * 
632  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
633  *
634  * Deprecated: 3.2
635  */
636 GtkWidget *
637 gtk_font_selection_get_face_list (GtkFontSelection *fontsel)
638 {
639   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
640
641   return NULL;
642 }
643
644 /**
645  * gtk_font_selection_get_size_entry:
646  * @fontsel: a #GtkFontSelection
647  *
648  * This returns the #GtkEntry used to allow the user to edit the font
649  * number manually instead of selecting it from the list of font sizes.
650  *
651  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
652  *
653  * Deprecated: 3.2
654  */
655 GtkWidget *
656 gtk_font_selection_get_size_entry (GtkFontSelection *fontsel)
657 {
658   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
659
660   return NULL;
661 }
662
663 /**
664  * gtk_font_selection_get_size_list:
665  * @fontsel: a #GtkFontSelection
666  *
667  * This returns the #GtkTreeeView used to list font sizes.
668  *
669  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
670  *
671  * Deprecated: 3.2
672  */
673 GtkWidget *
674 gtk_font_selection_get_size_list (GtkFontSelection *fontsel)
675 {
676   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
677
678   return NULL;
679 }
680
681 /**
682  * gtk_font_selection_get_preview_entry:
683  * @fontsel: a #GtkFontSelection
684  *
685  * This returns the #GtkEntry used to display the font as a preview.
686  *
687  * Return value: (transfer none): A #GtkWidget that is part of @fontsel
688  *
689  * Deprecated: 3.2
690  */
691 GtkWidget *
692 gtk_font_selection_get_preview_entry (GtkFontSelection *fontsel)
693 {
694   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
695
696   return NULL;
697 }
698
699 /**
700  * gtk_font_selection_get_family:
701  * @fontsel: a #GtkFontSelection
702  *
703  * Gets the #PangoFontFamily representing the selected font family.
704  *
705  * Return value: (transfer none): A #PangoFontFamily representing the
706  *     selected font family. Font families are a collection of font
707  *     faces. The returned object is owned by @fontsel and must not
708  *     be modified or freed.
709  *
710  * Since: 2.14
711  */
712 PangoFontFamily *
713 gtk_font_selection_get_family (GtkFontSelection *fontsel)
714 {
715   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
716
717   return NULL;
718 }
719
720 /**
721  * gtk_font_selection_get_face:
722  * @fontsel: a #GtkFontSelection
723  *
724  * Gets the #PangoFontFace representing the selected font group
725  * details (i.e. family, slant, weight, width, etc).
726  *
727  * Return value: (transfer none): A #PangoFontFace representing the
728  *     selected font group details. The returned object is owned by
729  *     @fontsel and must not be modified or freed.
730  *
731  * Since: 2.14
732  */
733 PangoFontFace *
734 gtk_font_selection_get_face (GtkFontSelection *fontsel)
735 {
736   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
737
738   return NULL;
739 }
740
741 /**
742  * gtk_font_selection_get_size:
743  * @fontsel: a #GtkFontSelection
744  *
745  * The selected font size.
746  *
747  * Return value: A n integer representing the selected font size,
748  *     or -1 if no font size is selected.
749  *
750  * Since: 2.14
751  **/
752 gint
753 gtk_font_selection_get_size (GtkFontSelection *fontsel)
754 {
755   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), -1);
756
757   return fontsel->priv->size;
758 }
759
760 /**
761  * gtk_font_selection_get_font_name:
762  * @fontsel: a #GtkFontSelection
763  * 
764  * Gets the currently-selected font name. 
765  *
766  * Note that this can be a different string than what you set with 
767  * gtk_font_selection_set_font_name(), as the font selection widget may 
768  * normalize font names and thus return a string with a different structure. 
769  * For example, "Helvetica Italic Bold 12" could be normalized to 
770  * "Helvetica Bold Italic 12". Use pango_font_description_equal()
771  * if you want to compare two font descriptions.
772  * 
773  * Return value: A string with the name of the current font, or %NULL if 
774  *     no font is selected. You must free this string with g_free().
775  */
776 gchar *
777 gtk_font_selection_get_font_name (GtkFontSelection *fontsel)
778 {
779   return NULL;
780 }
781
782 /* This sets the current font, then selecting the appropriate list rows. */
783
784 /**
785  * gtk_font_selection_set_font_name:
786  * @fontsel: a #GtkFontSelection
787  * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
788  * 
789  * Sets the currently-selected font. 
790  *
791  * Note that the @fontsel needs to know the screen in which it will appear 
792  * for this to work; this can be guaranteed by simply making sure that the 
793  * @fontsel is inserted in a toplevel window before you call this function.
794  * 
795  * Return value: %TRUE if the font could be set successfully; %FALSE if no 
796  *     such font exists or if the @fontsel doesn't belong to a particular 
797  *     screen yet.
798  */
799 gboolean
800 gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
801                                   const gchar      *fontname)
802 {
803 #if 0
804   PangoFontFamily *family = NULL;
805   PangoFontFace *face = NULL;
806   PangoFontDescription *new_desc;
807 #endif
808
809   g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), FALSE);
810
811   return TRUE;
812 }
813
814 /**
815  * gtk_font_selection_get_preview_text:
816  * @fontsel: a #GtkFontSelection
817  *
818  * Gets the text displayed in the preview area.
819  * 
820  * Return value: the text displayed in the preview area. 
821  *     This string is owned by the widget and should not be 
822  *     modified or freed 
823  */
824 G_CONST_RETURN gchar*
825 gtk_font_selection_get_preview_text (GtkFontSelection *fontsel)
826 {
827   return NULL;
828 }
829
830
831 /**
832  * gtk_font_selection_set_preview_text:
833  * @fontsel: a #GtkFontSelection
834  * @text: the text to display in the preview area 
835  *
836  * Sets the text displayed in the preview area.
837  * The @text is used to show how the selected font looks.
838  */
839 void
840 gtk_font_selection_set_preview_text  (GtkFontSelection *fontsel,
841                                       const gchar      *text)
842 {
843 #if 0
844   GtkFontSelectionPrivate *priv;
845
846   g_return_if_fail (GTK_IS_FONT_SELECTION (fontsel));
847   g_return_if_fail (text != NULL);
848
849   priv = fontsel->priv;
850 #endif
851 }
852
853
854 /**
855  * SECTION:gtkfontseldlg
856  * @Short_description: A dialog box for selecting fonts
857  * @Title: GtkFontSelectionDialog
858  * @See_also: #GtkFontSelection, #GtkDialog
859  *
860  * The #GtkFontSelectionDialog widget is a dialog box for selecting a font.
861  *
862  * To set the font which is initially selected, use
863  * gtk_font_selection_dialog_set_font_name().
864  *
865  * To get the selected font use gtk_font_selection_dialog_get_font_name().
866  *
867  * To change the text which is shown in the preview area, use
868  * gtk_font_selection_dialog_set_preview_text().
869  *
870  * <refsect2 id="GtkFontSelectionDialog-BUILDER-UI">
871  * <title>GtkFontSelectionDialog as GtkBuildable</title>
872  * The GtkFontSelectionDialog implementation of the GtkBuildable interface
873  * exposes the embedded #GtkFontSelection as internal child with the
874  * name "font_selection". It also exposes the buttons with the names
875  * "ok_button", "cancel_button" and "apply_button".
876  * </refsect2>
877  */
878
879 static void gtk_font_selection_dialog_buildable_interface_init     (GtkBuildableIface *iface);
880 static GObject * gtk_font_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
881                                                                           GtkBuilder   *builder,
882                                                                           const gchar  *childname);
883
884 G_DEFINE_TYPE_WITH_CODE (GtkFontSelectionDialog, gtk_font_selection_dialog,
885                          GTK_TYPE_DIALOG,
886                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
887                                                 gtk_font_selection_dialog_buildable_interface_init))
888
889 static GtkBuildableIface *parent_buildable_iface;
890
891 static void
892 gtk_font_selection_dialog_class_init (GtkFontSelectionDialogClass *klass)
893 {
894   g_type_class_add_private (klass, sizeof (GtkFontSelectionDialogPrivate));
895 }
896
897 static void
898 gtk_font_selection_dialog_init (GtkFontSelectionDialog *fontseldiag)
899 {
900   GtkFontSelectionDialogPrivate *priv;
901   GtkDialog *dialog = GTK_DIALOG (fontseldiag);
902   GtkWidget *action_area, *content_area;
903
904   fontseldiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontseldiag,
905                                                    GTK_TYPE_FONT_SELECTION_DIALOG,
906                                                    GtkFontSelectionDialogPrivate);
907   priv = fontseldiag->priv;
908
909   content_area = gtk_dialog_get_content_area (dialog);
910   action_area = gtk_dialog_get_action_area (dialog);
911
912   gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
913   gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
914   gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
915   gtk_box_set_spacing (GTK_BOX (action_area), 6);
916
917   gtk_widget_push_composite_child ();
918
919   gtk_window_set_resizable (GTK_WINDOW (fontseldiag), TRUE);
920
921   /* Create the content area */
922   priv->fontsel = gtk_font_selection_new ();
923   gtk_container_set_border_width (GTK_CONTAINER (priv->fontsel), 5);
924   gtk_widget_show (priv->fontsel);
925   gtk_box_pack_start (GTK_BOX (content_area),
926                       priv->fontsel, TRUE, TRUE, 0);
927
928   /* Create the action area */
929   priv->cancel_button = gtk_dialog_add_button (dialog,
930                                                GTK_STOCK_CANCEL,
931                                                GTK_RESPONSE_CANCEL);
932
933   priv->apply_button = gtk_dialog_add_button (dialog,
934                                               GTK_STOCK_APPLY,
935                                               GTK_RESPONSE_APPLY);
936   gtk_widget_hide (priv->apply_button);
937
938   priv->ok_button = gtk_dialog_add_button (dialog,
939                                            GTK_STOCK_OK,
940                                            GTK_RESPONSE_OK);
941   gtk_widget_grab_default (priv->ok_button);
942
943   gtk_dialog_set_alternative_button_order (GTK_DIALOG (fontseldiag),
944                                            GTK_RESPONSE_OK,
945                                            GTK_RESPONSE_APPLY,
946                                            GTK_RESPONSE_CANCEL,
947                                            -1);
948
949   gtk_window_set_title (GTK_WINDOW (fontseldiag),
950                         _("Font Selection"));
951
952   gtk_widget_pop_composite_child ();
953 }
954
955 /**
956  * gtk_font_selection_dialog_new:
957  * @title: the title of the dialog window 
958  *
959  * Creates a new #GtkFontSelectionDialog.
960  *
961  * Return value: a new #GtkFontSelectionDialog
962  */
963 GtkWidget*
964 gtk_font_selection_dialog_new (const gchar *title)
965 {
966   GtkFontSelectionDialog *fontseldiag;
967   
968   fontseldiag = g_object_new (GTK_TYPE_FONT_SELECTION_DIALOG, NULL);
969
970   if (title)
971     gtk_window_set_title (GTK_WINDOW (fontseldiag), title);
972   
973   return GTK_WIDGET (fontseldiag);
974 }
975
976 /**
977  * gtk_font_selection_dialog_get_font_selection:
978  * @fsd: a #GtkFontSelectionDialog
979  *
980  * Retrieves the #GtkFontSelection widget embedded in the dialog.
981  *
982  * Returns: (transfer none): the embedded #GtkFontSelection
983  *
984  * Since: 2.22
985  **/
986 GtkWidget*
987 gtk_font_selection_dialog_get_font_selection (GtkFontSelectionDialog *fsd)
988 {
989   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
990
991   return fsd->priv->fontsel;
992 }
993
994
995 /**
996  * gtk_font_selection_dialog_get_ok_button:
997  * @fsd: a #GtkFontSelectionDialog
998  *
999  * Gets the 'OK' button.
1000  *
1001  * Return value: (transfer none): the #GtkWidget used in the dialog
1002  *     for the 'OK' button.
1003  *
1004  * Since: 2.14
1005  */
1006 GtkWidget *
1007 gtk_font_selection_dialog_get_ok_button (GtkFontSelectionDialog *fsd)
1008 {
1009   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1010
1011   return fsd->priv->ok_button;
1012 }
1013
1014 /**
1015  * gtk_font_selection_dialog_get_cancel_button:
1016  * @fsd: a #GtkFontSelectionDialog
1017  *
1018  * Gets the 'Cancel' button.
1019  *
1020  * Return value: (transfer none): the #GtkWidget used in the dialog
1021  *     for the 'Cancel' button.
1022  *
1023  * Since: 2.14
1024  */
1025 GtkWidget *
1026 gtk_font_selection_dialog_get_cancel_button (GtkFontSelectionDialog *fsd)
1027 {
1028   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1029
1030   return fsd->priv->cancel_button;
1031 }
1032
1033 static void
1034 gtk_font_selection_dialog_buildable_interface_init (GtkBuildableIface *iface)
1035 {
1036   parent_buildable_iface = g_type_interface_peek_parent (iface);
1037   iface->get_internal_child = gtk_font_selection_dialog_buildable_get_internal_child;
1038 }
1039
1040 static GObject *
1041 gtk_font_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
1042                                                         GtkBuilder   *builder,
1043                                                         const gchar  *childname)
1044 {
1045   GtkFontSelectionDialogPrivate *priv;
1046
1047   priv = GTK_FONT_SELECTION_DIALOG (buildable)->priv;
1048
1049   if (g_strcmp0 (childname, "ok_button") == 0)
1050     return G_OBJECT (priv->ok_button);
1051   else if (g_strcmp0 (childname, "cancel_button") == 0)
1052     return G_OBJECT (priv->cancel_button);
1053   else if (g_strcmp0 (childname, "apply_button") == 0)
1054     return G_OBJECT (priv->apply_button);
1055   else if (g_strcmp0 (childname, "font_selection") == 0)
1056     return G_OBJECT (priv->fontsel);
1057
1058   return parent_buildable_iface->get_internal_child (buildable, builder, childname);
1059 }
1060
1061 /**
1062  * gtk_font_selection_dialog_get_font_name:
1063  * @fsd: a #GtkFontSelectionDialog
1064  * 
1065  * Gets the currently-selected font name.
1066  *
1067  * Note that this can be a different string than what you set with 
1068  * gtk_font_selection_dialog_set_font_name(), as the font selection widget
1069  * may normalize font names and thus return a string with a different 
1070  * structure. For example, "Helvetica Italic Bold 12" could be normalized 
1071  * to "Helvetica Bold Italic 12".  Use pango_font_description_equal()
1072  * if you want to compare two font descriptions.
1073  * 
1074  * Return value: A string with the name of the current font, or %NULL if no 
1075  *     font is selected. You must free this string with g_free().
1076  */
1077 gchar*
1078 gtk_font_selection_dialog_get_font_name (GtkFontSelectionDialog *fsd)
1079 {
1080   GtkFontSelectionDialogPrivate *priv;
1081
1082   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1083
1084   priv = fsd->priv;
1085
1086   return gtk_font_selection_get_font_name (GTK_FONT_SELECTION (priv->fontsel));
1087 }
1088
1089 /**
1090  * gtk_font_selection_dialog_set_font_name:
1091  * @fsd: a #GtkFontSelectionDialog
1092  * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
1093  *
1094  * Sets the currently selected font. 
1095  * 
1096  * Return value: %TRUE if the font selected in @fsd is now the
1097  *     @fontname specified, %FALSE otherwise. 
1098  */
1099 gboolean
1100 gtk_font_selection_dialog_set_font_name (GtkFontSelectionDialog *fsd,
1101                                          const gchar            *fontname)
1102 {
1103   GtkFontSelectionDialogPrivate *priv;
1104
1105   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), FALSE);
1106   g_return_val_if_fail (fontname, FALSE);
1107
1108   priv = fsd->priv;
1109
1110   return gtk_font_selection_set_font_name (GTK_FONT_SELECTION (priv->fontsel), fontname);
1111 }
1112
1113 /**
1114  * gtk_font_selection_dialog_get_preview_text:
1115  * @fsd: a #GtkFontSelectionDialog
1116  *
1117  * Gets the text displayed in the preview area.
1118  * 
1119  * Return value: the text displayed in the preview area. 
1120  *     This string is owned by the widget and should not be 
1121  *     modified or freed 
1122  */
1123 G_CONST_RETURN gchar*
1124 gtk_font_selection_dialog_get_preview_text (GtkFontSelectionDialog *fsd)
1125 {
1126   GtkFontSelectionDialogPrivate *priv;
1127
1128   g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1129
1130   priv = fsd->priv;
1131
1132   return gtk_font_selection_get_preview_text (GTK_FONT_SELECTION (priv->fontsel));
1133 }
1134
1135 /**
1136  * gtk_font_selection_dialog_set_preview_text:
1137  * @fsd: a #GtkFontSelectionDialog
1138  * @text: the text to display in the preview area
1139  *
1140  * Sets the text displayed in the preview area. 
1141  */
1142 void
1143 gtk_font_selection_dialog_set_preview_text (GtkFontSelectionDialog *fsd,
1144                                             const gchar            *text)
1145 {
1146   GtkFontSelectionDialogPrivate *priv;
1147
1148   g_return_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd));
1149   g_return_if_fail (text != NULL);
1150
1151   priv = fsd->priv;
1152
1153   gtk_font_selection_set_preview_text (GTK_FONT_SELECTION (priv->fontsel), text);
1154 }