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,
904 g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
906 gtk_tree_view_append_column (treeview, col);
908 populate_list (treeview, fontsel->priv->model);
913 gtk_font_selection_finalize (GObject *object)
915 GtkFontSelection *fontsel = GTK_FONT_SELECTION (object);
917 gtk_font_selection_ref_family (fontsel, NULL);
918 gtk_font_selection_ref_face (fontsel, NULL);
920 #ifndef GTK_DISABLE_DEPRECATED
921 if (fontsel->priv->size_list)
923 g_object_unref (fontsel->priv->size_list);
924 g_object_unref (fontsel->priv->font_list);
925 g_object_unref (fontsel->priv->face_list);
930 G_OBJECT_CLASS (gtk_font_selection_parent_class)->finalize (object);
935 gtk_font_selection_screen_changed (GtkWidget *widget,
936 GdkScreen *previous_screen)
942 gtk_font_selection_style_updated (GtkWidget *widget)
944 /*GTK_WIDGET_CLASS (gtk_font_selection_parent_class)->style_updated (widget);*/
950 gtk_font_selection_ref_family (GtkFontSelection *fontsel,
951 PangoFontFamily *family)
953 GtkFontSelectionPrivate *priv = fontsel->priv;
956 family = g_object_ref (family);
958 g_object_unref (priv->family);
959 priv->family = family;
963 gtk_font_selection_ref_face (GtkFontSelection *fontsel,
966 GtkFontSelectionPrivate *priv = fontsel->priv;
969 face = g_object_ref (face);
971 g_object_unref (priv->face);
975 #ifndef GTK_DISABLE_DEPRECATED
977 populate_font_model (GtkFontSelection *fontsel)
980 PangoFontFamily **families;
981 GtkFontSelectionPrivate *priv = fontsel->priv;
983 pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (fontsel)),
987 qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families);
989 gtk_list_store_clear (priv->_font_model);
991 for (i=0; i<n_families; i++)
995 gtk_list_store_append (priv->_font_model, &iter);
996 gtk_list_store_set (priv->_font_model, &iter,
998 1, pango_font_family_get_name (families[i]),
1005 update_font_model_selection (GtkFontSelection *fontsel)
1007 GtkFontSelectionPrivate *priv = fontsel->priv;
1011 update_face_model (GtkFontSelection *fontsel)
1013 GtkFontSelectionPrivate *priv = fontsel->priv;
1014 PangoFontFace **faces;
1017 pango_font_family_list_faces (priv->family, &faces, &n_faces);
1018 pango_font_family_get_name (priv->family);
1020 gtk_list_store_clear (priv->_face_model);
1022 for (i=0; i<n_faces; i++)
1026 gtk_list_store_append (priv->_face_model, &iter);
1027 gtk_list_store_set (priv->_face_model, &iter,
1029 1, pango_font_face_get_face_name (faces[i]),
1037 initialize_deprecated_widgets (GtkFontSelection *fontsel)
1039 GtkTreeViewColumn *col;
1040 GtkCellRenderer *cell;
1041 GtkFontSelectionPrivate *priv = fontsel->priv;
1043 GtkWidget *size_list;
1044 GtkWidget *font_list;
1045 GtkWidget *face_list;
1047 priv->_size_model = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING);
1048 priv->_font_model = gtk_list_store_new (2, PANGO_TYPE_FONT_FAMILY, G_TYPE_STRING);
1049 priv->_face_model = gtk_list_store_new (2, PANGO_TYPE_FONT_FACE, G_TYPE_STRING);
1051 size_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->_size_model));
1052 font_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->_font_model));
1053 face_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->_face_model));
1055 g_object_unref (priv->_size_model);
1056 g_object_unref (priv->_font_model);
1057 g_object_unref (priv->_face_model);
1059 col = gtk_tree_view_column_new_with_attributes ("Size",
1060 gtk_cell_renderer_text_new (),
1063 gtk_tree_view_append_column (GTK_TREE_VIEW (size_list), col);
1065 col = gtk_tree_view_column_new_with_attributes ("Family",
1066 gtk_cell_renderer_text_new (),
1069 gtk_tree_view_append_column (GTK_TREE_VIEW (font_list), col);
1071 col = gtk_tree_view_column_new_with_attributes ("Face",
1072 gtk_cell_renderer_text_new (),
1075 gtk_tree_view_append_column (GTK_TREE_VIEW (face_list), col);
1078 priv->font_list = gtk_scrolled_window_new (NULL, NULL);
1079 priv->face_list = gtk_scrolled_window_new (NULL, NULL);
1080 priv->size_list = gtk_scrolled_window_new (NULL, NULL);
1082 gtk_container_add (GTK_CONTAINER (priv->font_list), font_list);
1083 gtk_container_add (GTK_CONTAINER (priv->face_list), face_list);
1084 gtk_container_add (GTK_CONTAINER (priv->size_list), size_list);
1086 populate_font_model (fontsel);
1087 cursor_changed_cb (priv->family_face_list, priv);
1090 #endif /* GTK_DISABLE_DEPRECATED */
1092 /*****************************************************************************
1093 * These functions are the main public interface for getting/setting the font.
1094 *****************************************************************************/
1097 * gtk_font_selection_get_family:
1098 * @fontsel: a #GtkFontSelection
1100 * Gets the #PangoFontFamily representing the selected font family.
1102 * Return value: (transfer none): A #PangoFontFamily representing the
1103 * selected font family. Font families are a collection of font
1104 * faces. The returned object is owned by @fontsel and must not
1105 * be modified or freed.
1110 gtk_font_selection_get_family (GtkFontSelection *fontsel)
1112 g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1114 return fontsel->priv->family;
1118 * gtk_font_selection_get_face:
1119 * @fontsel: a #GtkFontSelection
1121 * Gets the #PangoFontFace representing the selected font group
1122 * details (i.e. family, slant, weight, width, etc).
1124 * Return value: (transfer none): A #PangoFontFace representing the
1125 * selected font group details. The returned object is owned by
1126 * @fontsel and must not be modified or freed.
1131 gtk_font_selection_get_face (GtkFontSelection *fontsel)
1133 g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1135 return fontsel->priv->face;
1139 * gtk_font_selection_get_size:
1140 * @fontsel: a #GtkFontSelection
1142 * The selected font size.
1144 * Return value: A n integer representing the selected font size,
1145 * or -1 if no font size is selected.
1150 gtk_font_selection_get_size (GtkFontSelection *fontsel)
1152 g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), -1);
1154 return fontsel->priv->size;
1158 * gtk_font_selection_get_font_name:
1159 * @fontsel: a #GtkFontSelection
1161 * Gets the currently-selected font name.
1163 * Note that this can be a different string than what you set with
1164 * gtk_font_selection_set_font_name(), as the font selection widget may
1165 * normalize font names and thus return a string with a different structure.
1166 * For example, "Helvetica Italic Bold 12" could be normalized to
1167 * "Helvetica Bold Italic 12". Use pango_font_description_equal()
1168 * if you want to compare two font descriptions.
1170 * Return value: (transfer full) (allow-none): A string with the name of the
1171 * current font, or %NULL if no font is selected. You must free this
1172 * string with g_free().
1175 gtk_font_selection_get_font_name (GtkFontSelection *fontsel)
1177 if (!fontsel->priv->family)
1180 return g_strdup (pango_font_family_get_name (fontsel->priv->family));
1183 /* This sets the current font, then selecting the appropriate list rows. */
1186 * gtk_font_selection_set_font_name:
1187 * @fontsel: a #GtkFontSelection
1188 * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
1190 * Sets the currently-selected font.
1192 * Note that the @fontsel needs to know the screen in which it will appear
1193 * for this to work; this can be guaranteed by simply making sure that the
1194 * @fontsel is inserted in a toplevel window before you call this function.
1196 * Return value: %TRUE if the font could be set successfully; %FALSE if no
1197 * such font exists or if the @fontsel doesn't belong to a particular
1201 gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
1202 const gchar *fontname)
1205 PangoFontFamily *family = NULL;
1206 PangoFontFace *face = NULL;
1207 PangoFontDescription *new_desc;
1210 g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), FALSE);
1216 * gtk_font_selection_get_preview_text:
1217 * @fontsel: a #GtkFontSelection
1219 * Gets the text displayed in the preview area.
1221 * Return value: the text displayed in the preview area.
1222 * This string is owned by the widget and should not be
1225 G_CONST_RETURN gchar*
1226 gtk_font_selection_get_preview_text (GtkFontSelection *fontsel)
1233 * gtk_font_selection_set_preview_text:
1234 * @fontsel: a #GtkFontSelection
1235 * @text: the text to display in the preview area
1237 * Sets the text displayed in the preview area.
1238 * The @text is used to show how the selected font looks.
1241 gtk_font_selection_set_preview_text (GtkFontSelection *fontsel,
1245 GtkFontSelectionPrivate *priv;
1247 g_return_if_fail (GTK_IS_FONT_SELECTION (fontsel));
1248 g_return_if_fail (text != NULL);
1250 priv = fontsel->priv;
1254 #ifndef GTK_DISABLE_DEPRECATED
1257 * gtk_font_selection_get_family_list:
1258 * @fontsel: a #GtkFontSelection
1260 * This returns the #GtkTreeView that lists font families, for
1261 * example, 'Sans', 'Serif', etc.
1263 * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1268 gtk_font_selection_get_family_list (GtkFontSelection *fontsel)
1270 GtkFontSelectionPrivate *priv = fontsel->priv;
1271 g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1272 if (!priv->font_list)
1273 initialize_deprecated_widgets (fontsel);
1275 return priv->font_list;
1279 * gtk_font_selection_get_face_list:
1280 * @fontsel: a #GtkFontSelection
1282 * This returns the #GtkTreeView which lists all styles available for
1283 * the selected font. For example, 'Regular', 'Bold', etc.
1285 * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1290 gtk_font_selection_get_face_list (GtkFontSelection *fontsel)
1292 GtkFontSelectionPrivate *priv = fontsel->priv;
1293 g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1294 if (!priv->face_list)
1295 initialize_deprecated_widgets (fontsel);
1297 return priv->face_list;
1301 * gtk_font_selection_get_size_entry:
1302 * @fontsel: a #GtkFontSelection
1304 * This returns the #GtkEntry used to allow the user to edit the font
1305 * number manually instead of selecting it from the list of font sizes.
1307 * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1312 gtk_font_selection_get_size_entry (GtkFontSelection *fontsel)
1314 GtkFontSelectionPrivate *priv = fontsel->priv;
1315 g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1317 return priv->size_spin;
1321 * gtk_font_selection_get_size_list:
1322 * @fontsel: a #GtkFontSelection
1324 * This returns the #GtkTreeeView used to list font sizes.
1326 * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1331 gtk_font_selection_get_size_list (GtkFontSelection *fontsel)
1333 GtkFontSelectionPrivate *priv = fontsel->priv;
1334 g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1335 if (!priv->size_list)
1336 initialize_deprecated_widgets (fontsel);
1338 return priv->size_list;
1342 * gtk_font_selection_get_preview_entry:
1343 * @fontsel: a #GtkFontSelection
1345 * This returns the #GtkEntry used to display the font as a preview.
1347 * Return value: (transfer none): A #GtkWidget that is part of @fontsel
1352 gtk_font_selection_get_preview_entry (GtkFontSelection *fontsel)
1354 GtkFontSelectionPrivate *priv = fontsel->priv;
1355 g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
1357 return priv->preview;
1360 #endif /* GTK_DISABLE_DEPRECATED */
1363 * SECTION:gtkfontseldlg
1364 * @Short_description: A dialog box for selecting fonts
1365 * @Title: GtkFontSelectionDialog
1366 * @See_also: #GtkFontSelection, #GtkDialog
1368 * The #GtkFontSelectionDialog widget is a dialog box for selecting a font.
1370 * To set the font which is initially selected, use
1371 * gtk_font_selection_dialog_set_font_name().
1373 * To get the selected font use gtk_font_selection_dialog_get_font_name().
1375 * To change the text which is shown in the preview area, use
1376 * gtk_font_selection_dialog_set_preview_text().
1378 * <refsect2 id="GtkFontSelectionDialog-BUILDER-UI">
1379 * <title>GtkFontSelectionDialog as GtkBuildable</title>
1380 * The GtkFontSelectionDialog implementation of the GtkBuildable interface
1381 * exposes the embedded #GtkFontSelection as internal child with the
1382 * name "font_selection". It also exposes the buttons with the names
1383 * "ok_button", "cancel_button" and "apply_button".
1387 static void gtk_font_selection_dialog_buildable_interface_init (GtkBuildableIface *iface);
1388 static GObject * gtk_font_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
1389 GtkBuilder *builder,
1390 const gchar *childname);
1392 G_DEFINE_TYPE_WITH_CODE (GtkFontSelectionDialog, gtk_font_selection_dialog,
1394 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
1395 gtk_font_selection_dialog_buildable_interface_init))
1397 static GtkBuildableIface *parent_buildable_iface;
1400 gtk_font_selection_dialog_class_init (GtkFontSelectionDialogClass *klass)
1402 g_type_class_add_private (klass, sizeof (GtkFontSelectionDialogPrivate));
1406 gtk_font_selection_dialog_init (GtkFontSelectionDialog *fontseldiag)
1408 GtkFontSelectionDialogPrivate *priv;
1409 GtkDialog *dialog = GTK_DIALOG (fontseldiag);
1410 GtkWidget *action_area, *content_area;
1412 fontseldiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontseldiag,
1413 GTK_TYPE_FONT_SELECTION_DIALOG,
1414 GtkFontSelectionDialogPrivate);
1415 priv = fontseldiag->priv;
1417 content_area = gtk_dialog_get_content_area (dialog);
1418 action_area = gtk_dialog_get_action_area (dialog);
1420 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
1421 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
1422 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
1423 gtk_box_set_spacing (GTK_BOX (action_area), 6);
1425 gtk_widget_push_composite_child ();
1427 gtk_window_set_resizable (GTK_WINDOW (fontseldiag), TRUE);
1429 /* Create the content area */
1430 priv->fontsel = gtk_font_selection_new ();
1431 gtk_container_set_border_width (GTK_CONTAINER (priv->fontsel), 5);
1432 gtk_widget_show (priv->fontsel);
1433 gtk_box_pack_start (GTK_BOX (content_area),
1434 priv->fontsel, TRUE, TRUE, 0);
1436 /* Create the action area */
1437 priv->cancel_button = gtk_dialog_add_button (dialog,
1439 GTK_RESPONSE_CANCEL);
1441 priv->apply_button = gtk_dialog_add_button (dialog,
1443 GTK_RESPONSE_APPLY);
1444 gtk_widget_hide (priv->apply_button);
1446 priv->ok_button = gtk_dialog_add_button (dialog,
1449 gtk_widget_grab_default (priv->ok_button);
1451 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fontseldiag),
1454 GTK_RESPONSE_CANCEL,
1457 gtk_window_set_title (GTK_WINDOW (fontseldiag),
1458 _("Font Selection"));
1460 gtk_widget_pop_composite_child ();
1464 * gtk_font_selection_dialog_new:
1465 * @title: the title of the dialog window
1467 * Creates a new #GtkFontSelectionDialog.
1469 * Return value: a new #GtkFontSelectionDialog
1472 gtk_font_selection_dialog_new (const gchar *title)
1474 GtkFontSelectionDialog *fontseldiag;
1476 fontseldiag = g_object_new (GTK_TYPE_FONT_SELECTION_DIALOG, NULL);
1479 gtk_window_set_title (GTK_WINDOW (fontseldiag), title);
1481 return GTK_WIDGET (fontseldiag);
1485 * gtk_font_selection_dialog_get_font_selection:
1486 * @fsd: a #GtkFontSelectionDialog
1488 * Retrieves the #GtkFontSelection widget embedded in the dialog.
1490 * Returns: (transfer none): the embedded #GtkFontSelection
1495 gtk_font_selection_dialog_get_font_selection (GtkFontSelectionDialog *fsd)
1497 g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1499 return fsd->priv->fontsel;
1504 * gtk_font_selection_dialog_get_ok_button:
1505 * @fsd: a #GtkFontSelectionDialog
1507 * Gets the 'OK' button.
1509 * Return value: (transfer none): the #GtkWidget used in the dialog
1510 * for the 'OK' button.
1515 gtk_font_selection_dialog_get_ok_button (GtkFontSelectionDialog *fsd)
1517 g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1519 return fsd->priv->ok_button;
1523 * gtk_font_selection_dialog_get_cancel_button:
1524 * @fsd: a #GtkFontSelectionDialog
1526 * Gets the 'Cancel' button.
1528 * Return value: (transfer none): the #GtkWidget used in the dialog
1529 * for the 'Cancel' button.
1534 gtk_font_selection_dialog_get_cancel_button (GtkFontSelectionDialog *fsd)
1536 g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1538 return fsd->priv->cancel_button;
1542 gtk_font_selection_dialog_buildable_interface_init (GtkBuildableIface *iface)
1544 parent_buildable_iface = g_type_interface_peek_parent (iface);
1545 iface->get_internal_child = gtk_font_selection_dialog_buildable_get_internal_child;
1549 gtk_font_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
1550 GtkBuilder *builder,
1551 const gchar *childname)
1553 GtkFontSelectionDialogPrivate *priv;
1555 priv = GTK_FONT_SELECTION_DIALOG (buildable)->priv;
1557 if (g_strcmp0 (childname, "ok_button") == 0)
1558 return G_OBJECT (priv->ok_button);
1559 else if (g_strcmp0 (childname, "cancel_button") == 0)
1560 return G_OBJECT (priv->cancel_button);
1561 else if (g_strcmp0 (childname, "apply_button") == 0)
1562 return G_OBJECT (priv->apply_button);
1563 else if (g_strcmp0 (childname, "font_selection") == 0)
1564 return G_OBJECT (priv->fontsel);
1566 return parent_buildable_iface->get_internal_child (buildable, builder, childname);
1570 * gtk_font_selection_dialog_get_font_name:
1571 * @fsd: a #GtkFontSelectionDialog
1573 * Gets the currently-selected font name.
1575 * Note that this can be a different string than what you set with
1576 * gtk_font_selection_dialog_set_font_name(), as the font selection widget
1577 * may normalize font names and thus return a string with a different
1578 * structure. For example, "Helvetica Italic Bold 12" could be normalized
1579 * to "Helvetica Bold Italic 12". Use pango_font_description_equal()
1580 * if you want to compare two font descriptions.
1582 * Return value: A string with the name of the current font, or %NULL if no
1583 * font is selected. You must free this string with g_free().
1586 gtk_font_selection_dialog_get_font_name (GtkFontSelectionDialog *fsd)
1588 GtkFontSelectionDialogPrivate *priv;
1590 g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1594 return gtk_font_selection_get_font_name (GTK_FONT_SELECTION (priv->fontsel));
1598 * gtk_font_selection_dialog_set_font_name:
1599 * @fsd: a #GtkFontSelectionDialog
1600 * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
1602 * Sets the currently selected font.
1604 * Return value: %TRUE if the font selected in @fsd is now the
1605 * @fontname specified, %FALSE otherwise.
1608 gtk_font_selection_dialog_set_font_name (GtkFontSelectionDialog *fsd,
1609 const gchar *fontname)
1611 GtkFontSelectionDialogPrivate *priv;
1613 g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), FALSE);
1614 g_return_val_if_fail (fontname, FALSE);
1618 return gtk_font_selection_set_font_name (GTK_FONT_SELECTION (priv->fontsel), fontname);
1622 * gtk_font_selection_dialog_get_preview_text:
1623 * @fsd: a #GtkFontSelectionDialog
1625 * Gets the text displayed in the preview area.
1627 * Return value: the text displayed in the preview area.
1628 * This string is owned by the widget and should not be
1631 G_CONST_RETURN gchar*
1632 gtk_font_selection_dialog_get_preview_text (GtkFontSelectionDialog *fsd)
1634 GtkFontSelectionDialogPrivate *priv;
1636 g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1640 return gtk_font_selection_get_preview_text (GTK_FONT_SELECTION (priv->fontsel));
1644 * gtk_font_selection_dialog_set_preview_text:
1645 * @fsd: a #GtkFontSelectionDialog
1646 * @text: the text to display in the preview area
1648 * Sets the text displayed in the preview area.
1651 gtk_font_selection_dialog_set_preview_text (GtkFontSelectionDialog *fsd,
1654 GtkFontSelectionDialogPrivate *priv;
1656 g_return_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd));
1657 g_return_if_fail (text != NULL);
1661 gtk_font_selection_set_preview_text (GTK_FONT_SELECTION (priv->fontsel), text);