1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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.
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.
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/.
35 #include <glib/gprintf.h>
40 #include "gtkfontsel.h"
41 #include "gtkbutton.h"
42 #include "gtkcellrenderertext.h"
48 #include "gtkliststore.h"
52 #include "gtktreeselection.h"
53 #include "gtktreeview.h"
55 #include "gtkscrolledwindow.h"
57 #include "gtkaccessible.h"
58 #include "gtkbuildable.h"
59 #include "gtkprivate.h"
60 #include "gtkalignment.h"
63 #include "gtkspinbutton.h"
64 #include "gtkwidget.h"
68 * @Short_description: A widget for selecting fonts
69 * @Title: GtkFontSelection
70 * @See_also: #GtkFontSelectionDialog
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
77 * To set the font which is initially selected, use
78 * gtk_font_selection_set_font_name().
80 * To get the selected font use gtk_font_selection_get_font_name().
82 * To change the text which is shown in the preview area, use
83 * gtk_font_selection_set_preview_text().
87 struct _GtkFontSelectionPrivate
89 GtkWidget *search_entry;
90 GtkWidget *family_face_list;
91 GtkWidget *size_slider;
100 PangoFontFamily *family;
102 gboolean ignore_slider;
104 #ifndef GTK_DISABLE_DEPRECATED
105 GtkWidget *size_list;
106 GtkWidget *font_list;
107 GtkWidget *face_list;
109 GtkListStore *_size_model;
110 GtkListStore *_font_model;
111 GtkListStore *_face_model;
116 struct _GtkFontSelectionDialogPrivate
120 GtkWidget *ok_button;
121 GtkWidget *apply_button;
122 GtkWidget *cancel_button;
126 #define DEFAULT_FONT_NAME "Sans 10"
127 #define MAX_FONT_SIZE 999
129 /* This is the initial fixed height and the top padding of the preview entry */
130 #define PREVIEW_HEIGHT 72
131 #define PREVIEW_TOP_PADDING 6
133 /* Widget default geometry */
134 #define FONTSEL_WIDTH 540
135 #define FONTSEL_HEIGHT 408
137 /* These are the sizes of the font, style & size lists. */
138 #define FONT_LIST_HEIGHT 136
139 #define FONT_LIST_WIDTH 190
140 #define FONT_STYLE_LIST_WIDTH 170
141 #define FONT_SIZE_LIST_WIDTH 60
143 #define ROW_FORMAT_STRING "<span weight=\"bold\" size=\"small\" foreground=\"%s\">%s</span>\n<span size=\"x-large\" font_desc=\"%s\">%s</span>"
145 /* These are what we use as the standard font sizes, for the size list.
147 #define FONT_SIZES_LENGTH 14
148 static const gint font_sizes[] = {
149 6, 8, 9, 10, 11, 12, 13, 14, 16, 20, 24, 36, 48, 72
166 static void gtk_font_selection_set_property (GObject *object,
170 static void gtk_font_selection_get_property (GObject *object,
174 static void gtk_font_selection_finalize (GObject *object);
177 static void gtk_font_selection_screen_changed (GtkWidget *widget,
178 GdkScreen *previous_screen);
179 static void gtk_font_selection_style_updated (GtkWidget *widget);
182 static void gtk_font_selection_ref_family (GtkFontSelection *fontsel,
183 PangoFontFamily *family);
184 static void gtk_font_selection_ref_face (GtkFontSelection *fontsel,
185 PangoFontFace *face);
187 static void gtk_font_selection_bootstrap_fontlist (GtkFontSelection *fontsel);
189 #ifndef GTK_DISABLE_DEPRECATED
190 static void update_face_model (GtkFontSelection *fontsel);
193 G_DEFINE_TYPE (GtkFontSelection, gtk_font_selection, GTK_TYPE_VBOX)
196 gtk_font_selection_class_init (GtkFontSelectionClass *klass)
198 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
199 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
202 widget_class->screen_changed = gtk_font_selection_screen_changed;
203 widget_class->style_updated = gtk_font_selection_style_updated;
206 gobject_class->finalize = gtk_font_selection_finalize;
207 gobject_class->set_property = gtk_font_selection_set_property;
208 gobject_class->get_property = gtk_font_selection_get_property;
210 g_object_class_install_property (gobject_class,
212 g_param_spec_string ("font-name",
214 P_("The string that represents this font"),
216 GTK_PARAM_READWRITE));
217 g_object_class_install_property (gobject_class,
219 g_param_spec_string ("preview-text",
221 P_("The text to display in order to demonstrate the selected font"),
222 pango_language_get_sample_string (NULL),
223 GTK_PARAM_READWRITE));
225 g_type_class_add_private (klass, sizeof (GtkFontSelectionPrivate));
229 gtk_font_selection_set_property (GObject *object,
234 GtkFontSelection *fontsel;
236 fontsel = GTK_FONT_SELECTION (object);
241 gtk_font_selection_set_font_name (fontsel, g_value_get_string (value));
243 case PROP_PREVIEW_TEXT:
244 gtk_font_selection_set_preview_text (fontsel, g_value_get_string (value));
247 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
253 gtk_font_selection_get_property (GObject *object,
258 GtkFontSelection *fontsel;
260 fontsel = GTK_FONT_SELECTION (object);
265 g_value_take_string (value, gtk_font_selection_get_font_name (fontsel));
267 case PROP_PREVIEW_TEXT:
268 g_value_set_string (value, gtk_font_selection_get_preview_text (fontsel));
271 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
277 refilter_and_focus (GtkFontSelectionPrivate *priv)
280 GtkTreeView *treeview = GTK_TREE_VIEW (priv->family_face_list);
281 GtkTreePath *path = gtk_tree_path_new ();
283 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
288 gtk_tree_view_get_cursor (treeview, &path, NULL);
290 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->filter), &iter, path))
292 gtk_tree_path_free (path);
296 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0.0, 0.0);
297 gtk_tree_path_free (path);
301 deleted_text_cb (GtkEntryBuffer *buffer,
306 GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*)user_data;
307 GtkWidget *entry = priv->search_entry;
309 if (gtk_entry_buffer_get_length (buffer) == 0)
311 gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
312 GTK_ENTRY_ICON_SECONDARY,
316 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
320 inserted_text_cb (GtkEntryBuffer *buffer,
326 GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*)user_data;
327 GtkWidget *entry = priv->search_entry;
329 if (g_strcmp0 (gtk_entry_get_icon_stock (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY),
331 gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
332 GTK_ENTRY_ICON_SECONDARY,
336 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
340 icon_press_cb (GtkEntry *entry,
341 GtkEntryIconPosition pos,
345 gtk_entry_buffer_delete_text (gtk_entry_get_buffer (entry), 0, -1);
349 slider_change_cb (GtkAdjustment *adjustment, gpointer data)
351 GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*)data;
353 /* If we set the silder value manually, we ignore this callback */
354 if (priv->ignore_slider)
356 priv->ignore_slider = FALSE;
360 gtk_adjustment_set_value (gtk_spin_button_get_adjustment( GTK_SPIN_BUTTON(priv->size_spin)),
361 gtk_adjustment_get_value (adjustment));
365 spin_change_cb (GtkAdjustment *adjustment, gpointer data)
367 PangoFontDescription *desc;
368 GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*)data;
370 gdouble size = gtk_adjustment_get_value (adjustment);
372 GtkAdjustment *slider_adj = gtk_range_get_adjustment (GTK_RANGE (priv->size_slider));
374 /* We ignore the slider value change callback for both of this set_value call */
375 priv->ignore_slider = TRUE;
376 if (size < gtk_adjustment_get_lower (slider_adj))
377 gtk_adjustment_set_value (slider_adj, gtk_adjustment_get_lower (slider_adj));
378 else if (size > gtk_adjustment_get_upper (slider_adj))
379 gtk_adjustment_set_value (slider_adj, gtk_adjustment_get_upper (slider_adj));
381 gtk_adjustment_set_value (slider_adj, size);
383 priv->size = ((gint)gtk_adjustment_get_value (adjustment)) * PANGO_SCALE;
385 desc = pango_context_get_font_description (gtk_widget_get_pango_context (priv->preview));
386 pango_font_description_set_size (desc, priv->size);
387 gtk_widget_override_font (priv->preview, desc);
389 gtk_widget_queue_draw (priv->preview);
393 set_range_marks (GtkFontSelectionPrivate *priv,
394 GtkWidget* size_slider,
404 sizes = (gint*)font_sizes;
405 length = FONT_SIZES_LENGTH;
408 gtk_scale_clear_marks (GTK_SCALE (size_slider));
410 adj = gtk_range_get_adjustment(GTK_RANGE (size_slider));
412 gtk_adjustment_set_lower (adj, (gdouble) sizes[0]);
413 gtk_adjustment_set_upper (adj, (gdouble) sizes[length-1]);
415 value = gtk_adjustment_get_value (adj);
416 if (value > (gdouble) sizes[length-1])
418 gtk_adjustment_set_value (adj, (gdouble) sizes[length-1]);
419 priv->ignore_slider = TRUE;
421 else if (value < (gdouble) sizes[0])
423 gtk_adjustment_set_value (adj, (gdouble) sizes[0]);
424 priv->ignore_slider = TRUE;
427 #ifndef GTK_DISABLE_DEPRECATED
428 if (!priv->_size_model)
430 for (i=0; i<length; i++)
431 gtk_scale_add_mark (GTK_SCALE (size_slider),
433 GTK_POS_BOTTOM, NULL);
437 GString *size_str = g_string_new (NULL);
438 gtk_list_store_clear (priv->_size_model);
440 for (i=0; i<length; i++)
444 g_string_printf (size_str, "%d", sizes[i]);
446 gtk_scale_add_mark (GTK_SCALE (size_slider),
448 GTK_POS_BOTTOM, NULL);
450 gtk_list_store_append (priv->_size_model, &iter);
451 gtk_list_store_set (priv->_size_model, &iter,
456 g_string_free (size_str, TRUE);
459 for (i=0; i<length; i++)
460 gtk_scale_add_mark (GTK_SCALE (size_slider),
462 GTK_POS_BOTTOM, NULL);
467 cursor_changed_cb (GtkTreeView *treeview, gpointer data)
469 PangoFontFamily *family;
471 PangoFontDescription *desc;
477 GtkTreePath *path = gtk_tree_path_new ();
479 GtkFontSelection *fontsel = (GtkFontSelection*)data;
481 gtk_tree_view_get_cursor (treeview, &path, NULL);
486 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (fontsel->priv->filter), &iter, path))
488 gtk_tree_path_free (path);
493 gtk_tree_model_get (GTK_TREE_MODEL (fontsel->priv->filter), &iter,
495 FAMILY_COLUMN, &family,
498 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0.0, 0.0);
500 gtk_tree_path_free (path);
503 if (!face || !family)
505 g_object_unref (face);
506 g_object_unref (family);
510 desc = pango_font_face_describe (face);
511 pango_font_description_set_size (desc, fontsel->priv->size);
512 gtk_widget_override_font (fontsel->priv->preview, desc);
514 pango_font_face_list_sizes (face, &sizes, &n_sizes);
515 /* It seems not many fonts actually have a sane set of sizes */
516 for (i=0; i<n_sizes; i++)
517 sizes[i] = sizes[i] / PANGO_SCALE;
519 set_range_marks (fontsel->priv, fontsel->priv->size_slider, sizes, n_sizes);
521 gtk_font_selection_ref_family (fontsel, family);
522 gtk_font_selection_ref_face (fontsel, face);
524 #ifndef GTK_DISABLE_DEPRECATED
525 if (fontsel->priv->_face_model)
526 update_face_model (fontsel);
530 g_object_unref ((gpointer)face);
531 pango_font_description_free(desc);
535 zoom_preview_cb (GtkWidget *scrolled_window, GdkEventScroll *event, gpointer data)
537 GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*)data;
539 GtkAdjustment *adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin));
541 if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_RIGHT)
542 gtk_adjustment_set_value (adj,
543 gtk_adjustment_get_value (adj) +
544 gtk_adjustment_get_step_increment (adj));
545 else if (event->direction == GDK_SCROLL_DOWN || event->direction == GDK_SCROLL_LEFT)
546 gtk_adjustment_set_value (adj,
547 gtk_adjustment_get_value (adj) -
548 gtk_adjustment_get_step_increment (adj));
553 gtk_font_selection_init (GtkFontSelection *fontsel)
555 GtkFontSelectionPrivate *priv;
556 PangoFontDescription *font_desc;
557 GtkWidget *scrolled_win;
558 GtkWidget *alignment;
559 GtkWidget *preview_and_size;
560 GtkWidget *size_controls;
562 fontsel->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontsel,
563 GTK_TYPE_FONT_SELECTION,
564 GtkFontSelectionPrivate);
566 priv = fontsel->priv;
568 #ifndef GTK_DISABLE_DEPRECATED
569 priv->size_list = NULL;
570 priv->font_list = NULL;
571 priv->face_list = NULL;
573 priv->_size_model = NULL;
574 priv->_font_model = NULL;
575 priv->_face_model = NULL;
576 #endif /* GTK_DISABLE_DEPRECATED */
578 gtk_widget_push_composite_child ();
580 /* Creating fundamental widgets for the private struct */
581 priv->search_entry = gtk_entry_new ();
582 priv->family_face_list = gtk_tree_view_new ();
583 priv->preview = gtk_entry_new ();
584 priv->size_slider = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
585 (gdouble) font_sizes[0],
586 (gdouble) font_sizes[FONT_SIZES_LENGTH - 1],
589 priv->size_spin = gtk_spin_button_new_with_range (0.0, (gdouble)(G_MAXINT / PANGO_SCALE), 1.0);
591 /** Bootstrapping widget layout **/
592 gtk_box_set_spacing (GTK_BOX (fontsel), 6);
593 gtk_box_pack_start (GTK_BOX (fontsel), priv->search_entry, FALSE, TRUE, 0);
595 /* Main font family/face view */
596 scrolled_win = gtk_scrolled_window_new (NULL, NULL);
597 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
598 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
599 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
600 GTK_SHADOW_ETCHED_IN);
601 gtk_container_add (GTK_CONTAINER (scrolled_win), priv->family_face_list);
603 /* Alignment for the preview and size controls */
604 /* alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
605 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment),
606 PREVIEW_TOP_PADDING, 0, 0, 0);*/
607 gtk_box_pack_start (GTK_BOX (fontsel), scrolled_win, TRUE, TRUE, 0);
609 preview_and_size = gtk_vbox_new (TRUE, 0);
610 gtk_box_set_homogeneous (GTK_BOX (preview_and_size), FALSE);
611 gtk_box_set_spacing (GTK_BOX (preview_and_size), 6);
613 /* The preview entry needs a scrolled window to make sure we have a */
614 scrolled_win = gtk_scrolled_window_new (NULL, NULL);
615 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
616 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
617 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
618 GTK_SHADOW_ETCHED_IN);
619 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win),
621 gtk_box_pack_start (GTK_BOX (preview_and_size), scrolled_win, FALSE, FALSE, 0);
623 /* Setting the size requests for various widgets */
624 gtk_widget_set_size_request (GTK_WIDGET (fontsel), FONTSEL_WIDTH, FONTSEL_HEIGHT);
625 gtk_widget_set_size_request (scrolled_win, -1, PREVIEW_HEIGHT);
626 gtk_widget_set_size_request (priv->preview, -1, PREVIEW_HEIGHT - 6);
628 /* Unset the frame on the preview entry */
629 gtk_entry_set_has_frame (GTK_ENTRY (priv->preview), FALSE);
631 /* Packing the slider and the spin in a hbox */
632 size_controls = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
633 gtk_scale_set_draw_value (GTK_SCALE (priv->size_slider), FALSE);
634 gtk_box_set_spacing (GTK_BOX (size_controls), 6);
635 gtk_box_pack_start (GTK_BOX (size_controls), priv->size_slider, TRUE, TRUE, 0);
636 gtk_box_pack_start (GTK_BOX (size_controls), priv->size_spin, FALSE, TRUE, 0);
638 gtk_widget_set_valign (priv->size_spin, GTK_ALIGN_START);
640 gtk_box_pack_start (GTK_BOX (preview_and_size), size_controls, FALSE, FALSE, 0);
641 // gtk_container_add (GTK_CONTAINER (alignment), preview_and_size);
643 gtk_box_pack_start (GTK_BOX (fontsel), GTK_WIDGET(preview_and_size), FALSE, TRUE, 0);
645 /* Getting the default size */
646 font_desc = pango_context_get_font_description (gtk_widget_get_pango_context (GTK_WIDGET (fontsel)));
647 priv->size = pango_font_description_get_size (font_desc);
651 gtk_adjustment_set_value (gtk_range_get_adjustment (GTK_RANGE (priv->size_slider)),
652 (gdouble)(priv->size / PANGO_SCALE));
653 gtk_adjustment_set_value (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin)),
654 (gdouble)(priv->size / PANGO_SCALE));
656 gtk_widget_show_all (GTK_WIDGET (fontsel));
657 gtk_widget_hide (GTK_WIDGET (fontsel));
659 /* Treeview column and model bootstrapping */
660 gtk_font_selection_bootstrap_fontlist (fontsel);
662 /* Set default preview text */
663 gtk_entry_set_text (GTK_ENTRY (priv->preview),
664 pango_language_get_sample_string (NULL));
666 /* Set search icon and place holder text */
667 gtk_entry_set_icon_from_stock (GTK_ENTRY (priv->search_entry),
668 GTK_ENTRY_ICON_SECONDARY,
670 gtk_entry_set_placeholder_text (GTK_ENTRY (priv->search_entry), _("Search font name"));
672 /** Callback connections **/
673 /* Connect to callback for the live search text entry */
674 g_signal_connect (G_OBJECT (gtk_entry_get_buffer (GTK_ENTRY (priv->search_entry))),
675 "deleted-text", G_CALLBACK (deleted_text_cb), priv);
676 g_signal_connect (G_OBJECT (gtk_entry_get_buffer (GTK_ENTRY (priv->search_entry))),
677 "inserted-text", G_CALLBACK (inserted_text_cb), priv);
678 g_signal_connect (G_OBJECT (priv->search_entry),
679 "icon-press", G_CALLBACK (icon_press_cb), priv);
681 /* Size controls callbacks */
682 g_signal_connect (G_OBJECT (gtk_range_get_adjustment (GTK_RANGE (priv->size_slider))),
683 "value-changed", G_CALLBACK (slider_change_cb), priv);
684 g_signal_connect (G_OBJECT (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin))),
685 "value-changed", G_CALLBACK (spin_change_cb), priv);
686 priv->ignore_slider = FALSE;
688 /* Font selection callback */
689 g_signal_connect (G_OBJECT (priv->family_face_list), "cursor-changed",
690 G_CALLBACK (cursor_changed_cb), fontsel);
692 /* Zoom on preview scroll*/
693 g_signal_connect (G_OBJECT (scrolled_win), "scroll-event",
694 G_CALLBACK (zoom_preview_cb), priv);
696 g_signal_connect (G_OBJECT (priv->size_slider), "scroll-event",
697 G_CALLBACK (zoom_preview_cb), priv);
699 set_range_marks (priv, priv->size_slider, (gint*)font_sizes, FONT_SIZES_LENGTH);
701 /* Set default focus */
702 gtk_widget_pop_composite_child();
706 * gtk_font_selection_new:
708 * Creates a new #GtkFontSelection.
710 * Return value: a new #GtkFontSelection
713 gtk_font_selection_new (void)
715 GtkFontSelection *fontsel;
717 fontsel = g_object_new (GTK_TYPE_FONT_SELECTION, NULL);
719 return GTK_WIDGET (fontsel);
723 cmp_families (const void *a, const void *b)
725 const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a);
726 const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b);
728 return g_utf8_collate (a_name, b_name);
732 populate_list (GtkTreeView* treeview, GtkListStore* model)
734 GtkStyleContext *style_context;
739 GtkTreeIter match_row;
743 PangoFontFamily **families;
745 GString *tmp = g_string_new (NULL);
746 GString *family_and_face = g_string_new (NULL);
748 pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (treeview)),
752 qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families);
754 gtk_list_store_clear (model);
756 /* Get row header font color */
757 style_context = gtk_widget_get_style_context (GTK_WIDGET (treeview));
758 gtk_style_context_get_color (style_context,
759 GTK_STATE_FLAG_NORMAL |GTK_STATE_FLAG_INSENSITIVE,
762 p_color.red = (guint16)((gdouble)G_MAXUINT16 * g_color.red);
763 p_color.green = (guint16)((gdouble)G_MAXUINT16 * g_color.green);
764 p_color.blue = (guint16)((gdouble)G_MAXUINT16 * g_color.blue);
765 color_string = pango_color_to_string (&p_color);
767 /* Iterate over families and faces */
768 for (i=0; i<n_families; i++)
771 PangoFontFace **faces;
774 const gchar *fam_name = pango_font_family_get_name (families[i]);
776 pango_font_family_list_faces (families[i], &faces, &n_faces);
778 for (j=0; j<n_faces; j++)
780 PangoFontDescription *pango_desc = pango_font_face_describe (faces[j]);
781 const gchar *face_name = pango_font_face_get_face_name (faces[j]);
782 gchar *font_desc = pango_font_description_to_string (pango_desc);
784 /* foreground_color, family_name, face_name, desc, sample string */
785 g_string_printf (family_and_face, "%s %s",
789 g_string_printf (tmp, ROW_FORMAT_STRING,
791 family_and_face->str,
793 pango_language_get_sample_string (NULL));
795 gtk_list_store_append (model, &iter);
796 gtk_list_store_set (model, &iter,
797 FAMILY_COLUMN, families[i],
798 FACE_COLUMN, faces[j],
799 PREVIEW_TITLE_COLUMN, family_and_face->str,
800 PREVIEW_TEXT_COLUMN, tmp->str,
803 if ((i == 0 && j == 0) ||
804 (!g_ascii_strcasecmp (face_name, "sans") && j == 0))
807 pango_font_description_free(pango_desc);
814 path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &match_row);
818 gtk_tree_view_set_cursor (treeview, path, NULL, FALSE);
819 gtk_tree_path_free(path);
823 g_string_free (family_and_face, TRUE);
824 g_string_free (tmp, TRUE);
825 g_free (color_string);
830 visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
832 gboolean result = FALSE;
833 GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*) data;
835 const gchar *search_text = (const gchar*)gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
837 gchar *font_name_casefold;
838 gchar *search_text_casefold;
840 gtk_tree_model_get (model, iter,
841 PREVIEW_TITLE_COLUMN, &font_name,
844 /* Covering some corner cases to speed up the result */
845 if (font_name == NULL ||
846 strlen (search_text) > strlen (font_name))
851 if (strlen (search_text) == 0)
857 font_name_casefold = g_utf8_casefold (font_name, -1);
858 search_text_casefold = g_utf8_casefold (search_text, -1);
860 if (g_strrstr (font_name_casefold, search_text_casefold))
863 g_free (search_text_casefold);
864 g_free (font_name_casefold);
870 gtk_font_selection_bootstrap_fontlist (GtkFontSelection* fontsel)
872 GtkTreeView *treeview = GTK_TREE_VIEW (fontsel->priv->family_face_list);
873 GtkCellRenderer *cell;
874 GtkTreeViewColumn *col;
876 fontsel->priv->model = gtk_list_store_new (4,
877 PANGO_TYPE_FONT_FAMILY,
878 PANGO_TYPE_FONT_FACE,
882 fontsel->priv->filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fontsel->priv->model),
884 g_object_unref (fontsel->priv->model);
886 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (fontsel->priv->filter),
888 (gpointer)fontsel->priv,
891 gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (fontsel->priv->filter));
892 g_object_unref (fontsel->priv->filter);
894 gtk_tree_view_set_rules_hint (treeview, TRUE);
895 gtk_tree_view_set_headers_visible (treeview, FALSE);
897 cell = gtk_cell_renderer_text_new ();
898 col = gtk_tree_view_column_new_with_attributes ("Family",
900 "markup", PREVIEW_TEXT_COLUMN,
903 g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
905 gtk_tree_view_append_column (treeview, col);
907 populate_list (treeview, fontsel->priv->model);
912 gtk_font_selection_finalize (GObject *object)
914 GtkFontSelection *fontsel = GTK_FONT_SELECTION (object);
916 gtk_font_selection_ref_family (fontsel, NULL);
917 gtk_font_selection_ref_face (fontsel, NULL);
919 #ifndef GTK_DISABLE_DEPRECATED
920 if (fontsel->priv->size_list)
922 g_object_unref (fontsel->priv->size_list);
923 g_object_unref (fontsel->priv->font_list);
924 g_object_unref (fontsel->priv->face_list);
928 G_OBJECT_CLASS (gtk_font_selection_parent_class)->finalize (object);
933 gtk_font_selection_screen_changed (GtkWidget *widget,
934 GdkScreen *previous_screen)
940 gtk_font_selection_style_updated (GtkWidget *widget)
942 /*GTK_WIDGET_CLASS (gtk_font_selection_parent_class)->style_updated (widget);*/
948 gtk_font_selection_ref_family (GtkFontSelection *fontsel,
949 PangoFontFamily *family)
951 GtkFontSelectionPrivate *priv = fontsel->priv;
954 family = g_object_ref (family);
956 g_object_unref (priv->family);
957 priv->family = family;
961 gtk_font_selection_ref_face (GtkFontSelection *fontsel,
964 GtkFontSelectionPrivate *priv = fontsel->priv;
967 face = g_object_ref (face);
969 g_object_unref (priv->face);
973 #ifndef GTK_DISABLE_DEPRECATED
975 populate_font_model (GtkFontSelection *fontsel)
978 PangoFontFamily **families;
979 GtkFontSelectionPrivate *priv = fontsel->priv;
981 pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (fontsel)),
985 qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families);
987 gtk_list_store_clear (priv->_font_model);
989 for (i=0; i<n_families; i++)
993 gtk_list_store_append (priv->_font_model, &iter);
994 gtk_list_store_set (priv->_font_model, &iter,
996 1, pango_font_family_get_name (families[i]),
1003 update_font_model_selection (GtkFontSelection *fontsel)
1005 GtkFontSelectionPrivate *priv = fontsel->priv;
1009 update_face_model (GtkFontSelection *fontsel)
1011 GtkFontSelectionPrivate *priv = fontsel->priv;
1012 PangoFontFace **faces;
1015 pango_font_family_list_faces (priv->family, &faces, &n_faces);
1016 pango_font_family_get_name (priv->family);
1018 gtk_list_store_clear (priv->_face_model);
1020 for (i=0; i<n_faces; i++)
1024 gtk_list_store_append (priv->_face_model, &iter);
1025 gtk_list_store_set (priv->_face_model, &iter,
1027 1, pango_font_face_get_face_name (faces[i]),
1035 size_list_cursor_changed_cb (GtkTreeView *treeview, gpointer data)
1041 family_list_cursor_changed_cb (GtkTreeView *treeview, gpointer data)
1046 face_list_cursor_changed_cb (GtkTreeView *treeview, gpointer data)
1052 initialize_deprecated_widgets (GtkFontSelection *fontsel)
1054 GtkTreeViewColumn *col;
1055 GtkCellRenderer *cell;
1056 GtkFontSelectionPrivate *priv = fontsel->priv;
1058 GtkWidget *size_list;
1059 GtkWidget *font_list;
1060 GtkWidget *face_list;
1062 priv->_size_model = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING);
1063 priv->_font_model = gtk_list_store_new (2, PANGO_TYPE_FONT_FAMILY, G_TYPE_STRING);
1064 priv->_face_model = gtk_list_store_new (2, PANGO_TYPE_FONT_FACE, G_TYPE_STRING);
1066 size_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->_size_model));
1067 font_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->_font_model));
1068 face_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->_face_model));
1070 g_object_unref (priv->_size_model);
1071 g_object_unref (priv->_font_model);
1072 g_object_unref (priv->_face_model);
1074 col = gtk_tree_view_column_new_with_attributes ("Size",
1075 gtk_cell_renderer_text_new (),
1078 gtk_tree_view_append_column (GTK_TREE_VIEW (size_list), col);
1080 col = gtk_tree_view_column_new_with_attributes ("Family",
1081 gtk_cell_renderer_text_new (),
1084 gtk_tree_view_append_column (GTK_TREE_VIEW (font_list), col);
1086 col = gtk_tree_view_column_new_with_attributes ("Face",
1087 gtk_cell_renderer_text_new (),
1090 gtk_tree_view_append_column (GTK_TREE_VIEW (face_list), col);
1093 priv->font_list = gtk_scrolled_window_new (NULL, NULL);
1094 priv->face_list = gtk_scrolled_window_new (NULL, NULL);
1095 priv->size_list = gtk_scrolled_window_new (NULL, NULL);
1097 gtk_container_add (GTK_CONTAINER (priv->font_list), font_list);
1098 gtk_container_add (GTK_CONTAINER (priv->face_list), face_list);
1099 gtk_container_add (GTK_CONTAINER (priv->size_list), size_list);
1101 g_signal_connect (G_OBJECT (font_list), "cursor-changed",
1102 G_CALLBACK (family_list_cursor_changed_cb), fontsel);
1104 g_signal_connect (G_OBJECT (face_list), "cursor-changed",
1105 G_CALLBACK (face_list_cursor_changed_cb), fontsel);
1107 g_signal_connect (G_OBJECT (size_list), "cursor-changed",
1108 G_CALLBACK (size_list_cursor_changed_cb), fontsel);
1110 populate_font_model (fontsel);
1111 cursor_changed_cb (priv->family_face_list, priv);
1114 #endif /* GTK_DISABLE_DEPRECATED */
1116 /*****************************************************************************
1117 * These functions are the main public interface for getting/setting the font.
1118 *****************************************************************************/
1121 * gtk_font_selection_get_family:
1122 * @fontsel: a #GtkFontSelection
1124 * Gets the #PangoFontFamily representing the selected font family.
1126 * Return value: (transfer none): A #PangoFontFamily representing the
1127 * selected font family. Font families are a collection of font
1128 * faces. The returned object is owned by @fontsel and must not
1129 * be modified or freed.
1134 gtk_font_selection_get_family (GtkFontSelection *fontsel)
1136 g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1138 return fontsel->priv->family;
1142 * gtk_font_selection_get_face:
1143 * @fontsel: a #GtkFontSelection
1145 * Gets the #PangoFontFace representing the selected font group
1146 * details (i.e. family, slant, weight, width, etc).
1148 * Return value: (transfer none): A #PangoFontFace representing the
1149 * selected font group details. The returned object is owned by
1150 * @fontsel and must not be modified or freed.
1155 gtk_font_selection_get_face (GtkFontSelection *fontsel)
1157 g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1159 return fontsel->priv->face;
1163 * gtk_font_selection_get_size:
1164 * @fontsel: a #GtkFontSelection
1166 * The selected font size.
1168 * Return value: A n integer representing the selected font size,
1169 * or -1 if no font size is selected.
1174 gtk_font_selection_get_size (GtkFontSelection *fontsel)
1176 g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), -1);
1178 return fontsel->priv->size;
1182 * gtk_font_selection_get_font_name:
1183 * @fontsel: a #GtkFontSelection
1185 * Gets the currently-selected font name.
1187 * Note that this can be a different string than what you set with
1188 * gtk_font_selection_set_font_name(), as the font selection widget may
1189 * normalize font names and thus return a string with a different structure.
1190 * For example, "Helvetica Italic Bold 12" could be normalized to
1191 * "Helvetica Bold Italic 12". Use pango_font_description_equal()
1192 * if you want to compare two font descriptions.
1194 * Return value: (transfer full) (allow-none): A string with the name of the
1195 * current font, or %NULL if no font is selected. You must free this
1196 * string with g_free().
1199 gtk_font_selection_get_font_name (GtkFontSelection *fontsel)
1201 if (!fontsel->priv->family)
1204 return g_strdup (pango_font_family_get_name (fontsel->priv->family));
1207 /* This sets the current font, then selecting the appropriate list rows. */
1210 * gtk_font_selection_set_font_name:
1211 * @fontsel: a #GtkFontSelection
1212 * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
1214 * Sets the currently-selected font.
1216 * Note that the @fontsel needs to know the screen in which it will appear
1217 * for this to work; this can be guaranteed by simply making sure that the
1218 * @fontsel is inserted in a toplevel window before you call this function.
1220 * Return value: %TRUE if the font could be set successfully; %FALSE if no
1221 * such font exists or if the @fontsel doesn't belong to a particular
1225 gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
1226 const gchar *fontname)
1229 PangoFontFamily *family = NULL;
1230 PangoFontFace *face = NULL;
1231 PangoFontDescription *new_desc;
1234 g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), FALSE);
1240 * gtk_font_selection_get_preview_text:
1241 * @fontsel: a #GtkFontSelection
1243 * Gets the text displayed in the preview area.
1245 * Return value: the text displayed in the preview area.
1246 * This string is owned by the widget and should not be
1249 G_CONST_RETURN gchar*
1250 gtk_font_selection_get_preview_text (GtkFontSelection *fontsel)
1257 * gtk_font_selection_set_preview_text:
1258 * @fontsel: a #GtkFontSelection
1259 * @text: the text to display in the preview area
1261 * Sets the text displayed in the preview area.
1262 * The @text is used to show how the selected font looks.
1265 gtk_font_selection_set_preview_text (GtkFontSelection *fontsel,
1269 GtkFontSelectionPrivate *priv;
1271 g_return_if_fail (GTK_IS_FONT_SELECTION (fontsel));
1272 g_return_if_fail (text != NULL);
1274 priv = fontsel->priv;
1278 #ifndef GTK_DISABLE_DEPRECATED
1281 * gtk_font_selection_get_family_list:
1282 * @fontsel: a #GtkFontSelection
1284 * This returns the #GtkTreeView that lists font families, for
1285 * example, 'Sans', 'Serif', etc.
1287 * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1292 gtk_font_selection_get_family_list (GtkFontSelection *fontsel)
1294 GtkFontSelectionPrivate *priv = fontsel->priv;
1295 g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1296 if (!priv->font_list)
1297 initialize_deprecated_widgets (fontsel);
1299 return priv->font_list;
1303 * gtk_font_selection_get_face_list:
1304 * @fontsel: a #GtkFontSelection
1306 * This returns the #GtkTreeView which lists all styles available for
1307 * the selected font. For example, 'Regular', 'Bold', etc.
1309 * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1314 gtk_font_selection_get_face_list (GtkFontSelection *fontsel)
1316 GtkFontSelectionPrivate *priv = fontsel->priv;
1317 g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1318 if (!priv->face_list)
1319 initialize_deprecated_widgets (fontsel);
1321 return priv->face_list;
1325 * gtk_font_selection_get_size_entry:
1326 * @fontsel: a #GtkFontSelection
1328 * This returns the #GtkEntry used to allow the user to edit the font
1329 * number manually instead of selecting it from the list of font sizes.
1331 * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1336 gtk_font_selection_get_size_entry (GtkFontSelection *fontsel)
1338 GtkFontSelectionPrivate *priv = fontsel->priv;
1339 g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1341 return priv->size_spin;
1345 * gtk_font_selection_get_size_list:
1346 * @fontsel: a #GtkFontSelection
1348 * This returns the #GtkTreeeView used to list font sizes.
1350 * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1355 gtk_font_selection_get_size_list (GtkFontSelection *fontsel)
1357 GtkFontSelectionPrivate *priv = fontsel->priv;
1358 g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1359 if (!priv->size_list)
1360 initialize_deprecated_widgets (fontsel);
1362 return priv->size_list;
1366 * gtk_font_selection_get_preview_entry:
1367 * @fontsel: a #GtkFontSelection
1369 * This returns the #GtkEntry used to display the font as a preview.
1371 * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1376 gtk_font_selection_get_preview_entry (GtkFontSelection *fontsel)
1378 GtkFontSelectionPrivate *priv = fontsel->priv;
1379 g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1381 return priv->preview;
1384 #endif /* GTK_DISABLE_DEPRECATED */
1387 * SECTION:gtkfontseldlg
1388 * @Short_description: A dialog box for selecting fonts
1389 * @Title: GtkFontSelectionDialog
1390 * @See_also: #GtkFontSelection, #GtkDialog
1392 * The #GtkFontSelectionDialog widget is a dialog box for selecting a font.
1394 * To set the font which is initially selected, use
1395 * gtk_font_selection_dialog_set_font_name().
1397 * To get the selected font use gtk_font_selection_dialog_get_font_name().
1399 * To change the text which is shown in the preview area, use
1400 * gtk_font_selection_dialog_set_preview_text().
1402 * <refsect2 id="GtkFontSelectionDialog-BUILDER-UI">
1403 * <title>GtkFontSelectionDialog as GtkBuildable</title>
1404 * The GtkFontSelectionDialog implementation of the GtkBuildable interface
1405 * exposes the embedded #GtkFontSelection as internal child with the
1406 * name "font_selection". It also exposes the buttons with the names
1407 * "ok_button", "cancel_button" and "apply_button".
1411 static void gtk_font_selection_dialog_buildable_interface_init (GtkBuildableIface *iface);
1412 static GObject * gtk_font_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
1413 GtkBuilder *builder,
1414 const gchar *childname);
1416 G_DEFINE_TYPE_WITH_CODE (GtkFontSelectionDialog, gtk_font_selection_dialog,
1418 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
1419 gtk_font_selection_dialog_buildable_interface_init))
1421 static GtkBuildableIface *parent_buildable_iface;
1424 gtk_font_selection_dialog_class_init (GtkFontSelectionDialogClass *klass)
1426 g_type_class_add_private (klass, sizeof (GtkFontSelectionDialogPrivate));
1430 gtk_font_selection_dialog_init (GtkFontSelectionDialog *fontseldiag)
1432 GtkFontSelectionDialogPrivate *priv;
1433 GtkDialog *dialog = GTK_DIALOG (fontseldiag);
1434 GtkWidget *action_area, *content_area;
1436 fontseldiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontseldiag,
1437 GTK_TYPE_FONT_SELECTION_DIALOG,
1438 GtkFontSelectionDialogPrivate);
1439 priv = fontseldiag->priv;
1441 content_area = gtk_dialog_get_content_area (dialog);
1442 action_area = gtk_dialog_get_action_area (dialog);
1444 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
1445 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
1446 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
1447 gtk_box_set_spacing (GTK_BOX (action_area), 6);
1449 gtk_widget_push_composite_child ();
1451 gtk_window_set_resizable (GTK_WINDOW (fontseldiag), TRUE);
1453 /* Create the content area */
1454 priv->fontsel = gtk_font_selection_new ();
1455 gtk_container_set_border_width (GTK_CONTAINER (priv->fontsel), 5);
1456 gtk_widget_show (priv->fontsel);
1457 gtk_box_pack_start (GTK_BOX (content_area),
1458 priv->fontsel, TRUE, TRUE, 0);
1460 /* Create the action area */
1461 priv->cancel_button = gtk_dialog_add_button (dialog,
1463 GTK_RESPONSE_CANCEL);
1465 priv->apply_button = gtk_dialog_add_button (dialog,
1467 GTK_RESPONSE_APPLY);
1468 gtk_widget_hide (priv->apply_button);
1470 priv->ok_button = gtk_dialog_add_button (dialog,
1473 gtk_widget_grab_default (priv->ok_button);
1475 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fontseldiag),
1478 GTK_RESPONSE_CANCEL,
1481 gtk_window_set_title (GTK_WINDOW (fontseldiag),
1482 _("Font Selection"));
1484 gtk_widget_pop_composite_child ();
1488 * gtk_font_selection_dialog_new:
1489 * @title: the title of the dialog window
1491 * Creates a new #GtkFontSelectionDialog.
1493 * Return value: a new #GtkFontSelectionDialog
1496 gtk_font_selection_dialog_new (const gchar *title)
1498 GtkFontSelectionDialog *fontseldiag;
1500 fontseldiag = g_object_new (GTK_TYPE_FONT_SELECTION_DIALOG, NULL);
1503 gtk_window_set_title (GTK_WINDOW (fontseldiag), title);
1505 return GTK_WIDGET (fontseldiag);
1509 * gtk_font_selection_dialog_get_font_selection:
1510 * @fsd: a #GtkFontSelectionDialog
1512 * Retrieves the #GtkFontSelection widget embedded in the dialog.
1514 * Returns: (transfer none): the embedded #GtkFontSelection
1519 gtk_font_selection_dialog_get_font_selection (GtkFontSelectionDialog *fsd)
1521 g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1523 return fsd->priv->fontsel;
1528 * gtk_font_selection_dialog_get_ok_button:
1529 * @fsd: a #GtkFontSelectionDialog
1531 * Gets the 'OK' button.
1533 * Return value: (transfer none): the #GtkWidget used in the dialog
1534 * for the 'OK' button.
1539 gtk_font_selection_dialog_get_ok_button (GtkFontSelectionDialog *fsd)
1541 g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1543 return fsd->priv->ok_button;
1547 * gtk_font_selection_dialog_get_cancel_button:
1548 * @fsd: a #GtkFontSelectionDialog
1550 * Gets the 'Cancel' button.
1552 * Return value: (transfer none): the #GtkWidget used in the dialog
1553 * for the 'Cancel' button.
1558 gtk_font_selection_dialog_get_cancel_button (GtkFontSelectionDialog *fsd)
1560 g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1562 return fsd->priv->cancel_button;
1566 gtk_font_selection_dialog_buildable_interface_init (GtkBuildableIface *iface)
1568 parent_buildable_iface = g_type_interface_peek_parent (iface);
1569 iface->get_internal_child = gtk_font_selection_dialog_buildable_get_internal_child;
1573 gtk_font_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
1574 GtkBuilder *builder,
1575 const gchar *childname)
1577 GtkFontSelectionDialogPrivate *priv;
1579 priv = GTK_FONT_SELECTION_DIALOG (buildable)->priv;
1581 if (g_strcmp0 (childname, "ok_button") == 0)
1582 return G_OBJECT (priv->ok_button);
1583 else if (g_strcmp0 (childname, "cancel_button") == 0)
1584 return G_OBJECT (priv->cancel_button);
1585 else if (g_strcmp0 (childname, "apply_button") == 0)
1586 return G_OBJECT (priv->apply_button);
1587 else if (g_strcmp0 (childname, "font_selection") == 0)
1588 return G_OBJECT (priv->fontsel);
1590 return parent_buildable_iface->get_internal_child (buildable, builder, childname);
1594 * gtk_font_selection_dialog_get_font_name:
1595 * @fsd: a #GtkFontSelectionDialog
1597 * Gets the currently-selected font name.
1599 * Note that this can be a different string than what you set with
1600 * gtk_font_selection_dialog_set_font_name(), as the font selection widget
1601 * may normalize font names and thus return a string with a different
1602 * structure. For example, "Helvetica Italic Bold 12" could be normalized
1603 * to "Helvetica Bold Italic 12". Use pango_font_description_equal()
1604 * if you want to compare two font descriptions.
1606 * Return value: A string with the name of the current font, or %NULL if no
1607 * font is selected. You must free this string with g_free().
1610 gtk_font_selection_dialog_get_font_name (GtkFontSelectionDialog *fsd)
1612 GtkFontSelectionDialogPrivate *priv;
1614 g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1618 return gtk_font_selection_get_font_name (GTK_FONT_SELECTION (priv->fontsel));
1622 * gtk_font_selection_dialog_set_font_name:
1623 * @fsd: a #GtkFontSelectionDialog
1624 * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
1626 * Sets the currently selected font.
1628 * Return value: %TRUE if the font selected in @fsd is now the
1629 * @fontname specified, %FALSE otherwise.
1632 gtk_font_selection_dialog_set_font_name (GtkFontSelectionDialog *fsd,
1633 const gchar *fontname)
1635 GtkFontSelectionDialogPrivate *priv;
1637 g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), FALSE);
1638 g_return_val_if_fail (fontname, FALSE);
1642 return gtk_font_selection_set_font_name (GTK_FONT_SELECTION (priv->fontsel), fontname);
1646 * gtk_font_selection_dialog_get_preview_text:
1647 * @fsd: a #GtkFontSelectionDialog
1649 * Gets the text displayed in the preview area.
1651 * Return value: the text displayed in the preview area.
1652 * This string is owned by the widget and should not be
1655 G_CONST_RETURN gchar*
1656 gtk_font_selection_dialog_get_preview_text (GtkFontSelectionDialog *fsd)
1658 GtkFontSelectionDialogPrivate *priv;
1660 g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1664 return gtk_font_selection_get_preview_text (GTK_FONT_SELECTION (priv->fontsel));
1668 * gtk_font_selection_dialog_set_preview_text:
1669 * @fsd: a #GtkFontSelectionDialog
1670 * @text: the text to display in the preview area
1672 * Sets the text displayed in the preview area.
1675 gtk_font_selection_dialog_set_preview_text (GtkFontSelectionDialog *fsd,
1678 GtkFontSelectionDialogPrivate *priv;
1680 g_return_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd));
1681 g_return_if_fail (text != NULL);
1685 gtk_font_selection_set_preview_text (GTK_FONT_SELECTION (priv->fontsel), text);