X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkfontchooser.c;h=21a5deb234661de771831f89f20e34f1a9c5a6bf;hb=HEAD;hp=074124abe1e50b186523222f109bfc8672b9b042;hpb=bbe8d13c6e2e6d134fb2d099b1ac83c82d391a88;p=~andy%2Fgtk diff --git a/gtk/gtkfontchooser.c b/gtk/gtkfontchooser.c index 074124abe..21a5deb23 100644 --- a/gtk/gtkfontchooser.c +++ b/gtk/gtkfontchooser.c @@ -1,2178 +1,417 @@ /* GTK - The GIMP Toolkit - * Copyright (C) 2011 Alberto Ruiz - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * Massively updated to rework the user interface by Alberto Ruiz, 2011 - * Massively updated for Pango by Owen Taylor, May 2000 - * GtkFontSelection widget for Gtk+, by Damon Chaplin, May 1998. - * Based on the GnomeFontSelector widget, by Elliot Lee, but major changes. - * The GnomeFontSelector was derived from app/text_tool.c in the GIMP. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#include "config.h" - -#include -#include -#include - -#include - -#include "gtkfontsel.h" -#include "gtkbutton.h" -#include "gtkcellrenderertext.h" -#include "gtkentry.h" -#include "gtkframe.h" -#include "gtkhbbox.h" -#include "gtkhbox.h" -#include "gtklabel.h" -#include "gtkliststore.h" -#include "gtkrc.h" -#include "gtkstock.h" -#include "gtktable.h" -#include "gtktreeselection.h" -#include "gtktreeview.h" -#include "gtkvbox.h" -#include "gtkscrolledwindow.h" -#include "gtkintl.h" -#include "gtkaccessible.h" -#include "gtkbuildable.h" -#include "gtkprivate.h" -#include "gtkalignment.h" -#include "gtkscale.h" -#include "gtkbox.h" -#include "gtkspinbutton.h" -#include "gtkwidget.h" - -/** - * SECTION:gtkfontsel - * @Short_description: A widget for selecting fonts - * @Title: GtkFontSelection - * @See_also: #GtkFontSelectionDialog - * - * The #GtkFontSelection widget lists the available fonts, styles and sizes, - * allowing the user to select a font. - * It is used in the #GtkFontSelectionDialog widget to provide a dialog box for - * selecting fonts. - * - * To set the font which is initially selected, use - * gtk_font_selection_set_font_name(). - * - * To get the selected font use gtk_font_selection_get_font_name(). - * - * To change the text which is shown in the preview area, use - * gtk_font_selection_set_preview_text(). - */ - - -struct _GtkFontSelectionPrivate -{ - GtkWidget *search_entry; - GtkWidget *family_face_list; - GtkListStore *model; - GtkTreeModel *filter; - - GtkWidget *preview; - GtkWidget *preview_scrolled_window; - gchar *preview_text; - gboolean show_preview_entry; - - GtkWidget *size_spin; - GtkWidget *size_slider; - gboolean ignore_slider; - - gint size; - PangoFontFace *face; - PangoFontFamily *family; - -#ifndef GTK_DISABLE_DEPRECATED - GtkWidget *size_list; - GtkWidget *font_list; - GtkWidget *face_list; - - GtkListStore *_size_model; - GtkListStore *_font_model; - GtkListStore *_face_model; - - gboolean ignore_size; - gboolean ignore_face; - gboolean ignore_font; -#endif -}; - - -struct _GtkFontSelectionDialogPrivate -{ - GtkWidget *fontsel; - - GtkWidget *select_button; - GtkWidget *cancel_button; -#ifndef GTK_DISABLE_DEPRECATED - GtkWidget *apply_button; -#endif -}; - - -#define DEFAULT_FONT_NAME "Sans 10" -#define MAX_FONT_SIZE 999 - -/* This is the initial fixed height and the top padding of the preview entry */ -#define PREVIEW_HEIGHT 72 -#define PREVIEW_TOP_PADDING 6 - -/* Widget default geometry */ -#define FONTSEL_WIDTH 540 -#define FONTSEL_HEIGHT 408 - -/* These are the sizes of the font, style & size lists. */ -#define FONT_LIST_HEIGHT 136 -#define FONT_LIST_WIDTH 190 -#define FONT_STYLE_LIST_WIDTH 170 -#define FONT_SIZE_LIST_WIDTH 60 - -#define ROW_FORMAT_STRING "%s\n%s" - -/* These are what we use as the standard font sizes, for the size list. - */ -#define FONT_SIZES_LENGTH 14 -static const gint font_sizes[] = { - 6, 8, 9, 10, 11, 12, 13, 14, 16, 20, 24, 36, 48, 72 -}; - -enum { - PROP_0, - PROP_FONT_NAME, - PROP_PREVIEW_TEXT, - PROP_SHOW_PREVIEW_ENTRY -}; - - -enum { - FAMILY_COLUMN, - FACE_COLUMN, - PREVIEW_TEXT_COLUMN, - PREVIEW_TITLE_COLUMN -}; - -static void gtk_font_selection_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void gtk_font_selection_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static void gtk_font_selection_finalize (GObject *object); - -static void gtk_font_selection_screen_changed (GtkWidget *widget, - GdkScreen *previous_screen); -static void gtk_font_selection_style_updated (GtkWidget *widget); - -static void gtk_font_selection_ref_family (GtkFontSelection *fontsel, - PangoFontFamily *family); -static void gtk_font_selection_ref_face (GtkFontSelection *fontsel, - PangoFontFace *face); - -static void gtk_font_selection_bootstrap_fontlist (GtkFontSelection *fontsel); - -#ifndef GTK_DISABLE_DEPRECATED -static void update_font_list_selection (GtkFontSelection *fontsel); -static void update_size_list_selection (GtkFontSelection *fontsel); -static void update_face_model (GtkFontSelection *fontsel, - gboolean first); -#endif - -G_DEFINE_TYPE (GtkFontSelection, gtk_font_selection, GTK_TYPE_VBOX) - -static void -gtk_font_selection_class_init (GtkFontSelectionClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - widget_class->screen_changed = gtk_font_selection_screen_changed; - widget_class->style_updated = gtk_font_selection_style_updated; - - gobject_class->finalize = gtk_font_selection_finalize; - gobject_class->set_property = gtk_font_selection_set_property; - gobject_class->get_property = gtk_font_selection_get_property; - - g_object_class_install_property (gobject_class, - PROP_FONT_NAME, - g_param_spec_string ("font-name", - P_("Font name"), - P_("The string that represents this font"), - DEFAULT_FONT_NAME, - GTK_PARAM_READWRITE)); - g_object_class_install_property (gobject_class, - PROP_PREVIEW_TEXT, - g_param_spec_string ("preview-text", - P_("Preview text"), - P_("The text to display in order to demonstrate the selected font"), - pango_language_get_sample_string (NULL), - GTK_PARAM_READWRITE)); - - g_object_class_install_property (gobject_class, - PROP_SHOW_PREVIEW_ENTRY, - g_param_spec_boolean ("show-preview-entry", - P_("Show preview text entry"), - P_("Whether the preview text entry is shown or not"), - TRUE, - GTK_PARAM_READWRITE)); - - g_type_class_add_private (klass, sizeof (GtkFontSelectionPrivate)); -} - -static void -gtk_font_selection_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - GtkFontSelection *fontsel; - - fontsel = GTK_FONT_SELECTION (object); - - switch (prop_id) - { - case PROP_FONT_NAME: - gtk_font_selection_set_font_name (fontsel, g_value_get_string (value)); - break; - case PROP_PREVIEW_TEXT: - gtk_font_selection_set_preview_text (fontsel, g_value_get_string (value)); - break; - case PROP_SHOW_PREVIEW_ENTRY: - gtk_font_selection_set_show_preview_entry (fontsel, g_value_get_boolean (value)); - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -gtk_font_selection_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GtkFontSelection *fontsel; - - fontsel = GTK_FONT_SELECTION (object); - - switch (prop_id) - { - case PROP_FONT_NAME: - g_value_take_string (value, gtk_font_selection_get_font_name (fontsel)); - break; - case PROP_PREVIEW_TEXT: - g_value_set_string (value, gtk_font_selection_get_preview_text (fontsel)); - break; - case PROP_SHOW_PREVIEW_ENTRY: - g_value_set_boolean (value, gtk_font_selection_get_show_preview_entry (fontsel)); - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -void -refilter_and_focus (GtkFontSelectionPrivate *priv) -{ - GtkTreeIter iter; - GtkTreeView *treeview = GTK_TREE_VIEW (priv->family_face_list); - GtkTreePath *path = gtk_tree_path_new (); - - gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter)); - - if (!path) - return; - - gtk_tree_view_get_cursor (treeview, &path, NULL); - - if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->filter), &iter, path)) - { - gtk_tree_path_free (path); - return; - } - - gtk_tree_view_scroll_to_cell (treeview, path, NULL, TRUE, 0.5, 0.5); - gtk_tree_path_free (path); -} - -void -deleted_text_cb (GtkEntryBuffer *buffer, - guint position, - guint n_chars, - gpointer user_data) -{ - GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*)user_data; - GtkWidget *entry = priv->search_entry; - - if (gtk_entry_buffer_get_length (buffer) == 0) - { - gtk_entry_set_icon_from_stock (GTK_ENTRY (entry), - GTK_ENTRY_ICON_SECONDARY, - GTK_STOCK_FIND); - } - - gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter)); -} - -void -inserted_text_cb (GtkEntryBuffer *buffer, - guint position, - gchar *chars, - guint n_chars, - gpointer user_data) -{ - GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*)user_data; - GtkWidget *entry = priv->search_entry; - - if (g_strcmp0 (gtk_entry_get_icon_stock (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY), - GTK_STOCK_CLEAR)) - gtk_entry_set_icon_from_stock (GTK_ENTRY (entry), - GTK_ENTRY_ICON_SECONDARY, - GTK_STOCK_CLEAR); - - - gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter)); -} - -void -icon_press_cb (GtkEntry *entry, - GtkEntryIconPosition pos, - GdkEvent *event, - gpointer user_data) -{ - gtk_entry_buffer_delete_text (gtk_entry_get_buffer (entry), 0, -1); -} - -void -slider_change_cb (GtkAdjustment *adjustment, gpointer data) -{ - GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*)data; - - /* If we set the silder value manually, we ignore this callback */ - if (priv->ignore_slider) - { - priv->ignore_slider = FALSE; - return; - } - - gtk_adjustment_set_value (gtk_spin_button_get_adjustment( GTK_SPIN_BUTTON(priv->size_spin)), - gtk_adjustment_get_value (adjustment)); -} - -void -spin_change_cb (GtkAdjustment *adjustment, gpointer data) -{ - PangoFontDescription *desc; - GtkFontSelection *fontsel = (GtkFontSelection*)data; - GtkFontSelectionPrivate *priv = fontsel->priv; - - gdouble size = gtk_adjustment_get_value (adjustment); - - GtkAdjustment *slider_adj = gtk_range_get_adjustment (GTK_RANGE (priv->size_slider)); - - /* We ignore the slider value change callback for both of this set_value call */ - priv->ignore_slider = TRUE; - if (size < gtk_adjustment_get_lower (slider_adj)) - gtk_adjustment_set_value (slider_adj, gtk_adjustment_get_lower (slider_adj)); - else if (size > gtk_adjustment_get_upper (slider_adj)) - gtk_adjustment_set_value (slider_adj, gtk_adjustment_get_upper (slider_adj)); - else - gtk_adjustment_set_value (slider_adj, size); - - priv->size = ((gint)gtk_adjustment_get_value (adjustment)) * PANGO_SCALE; - - desc = pango_context_get_font_description (gtk_widget_get_pango_context (priv->preview)); - pango_font_description_set_size (desc, priv->size); - gtk_widget_override_font (priv->preview, desc); - - -#ifndef GTK_DISABLE_DEPRECATED - if (priv->size_list) - { - priv->ignore_size = TRUE; - update_size_list_selection (fontsel); - } -#endif /* GTK_DISABLE_DEPRECATED */ - - gtk_widget_queue_draw (priv->preview); - - g_object_notify (G_OBJECT (fontsel), "font-name"); -} - -void -set_range_marks (GtkFontSelectionPrivate *priv, - GtkWidget* size_slider, - gint* sizes, - gint length) -{ - GtkAdjustment *adj; - gint i; - gdouble value; - - if (length<2) - { - sizes = (gint*)font_sizes; - length = FONT_SIZES_LENGTH; - } - - gtk_scale_clear_marks (GTK_SCALE (size_slider)); - - adj = gtk_range_get_adjustment(GTK_RANGE (size_slider)); - - gtk_adjustment_set_lower (adj, (gdouble) sizes[0]); - gtk_adjustment_set_upper (adj, (gdouble) sizes[length-1]); - - value = gtk_adjustment_get_value (adj); - if (value > (gdouble) sizes[length-1]) - { - gtk_adjustment_set_value (adj, (gdouble) sizes[length-1]); - priv->ignore_slider = TRUE; - } - else if (value < (gdouble) sizes[0]) - { - gtk_adjustment_set_value (adj, (gdouble) sizes[0]); - priv->ignore_slider = TRUE; - } - -#ifndef GTK_DISABLE_DEPRECATED - if (!priv->_size_model) - { - for (i=0; i_size_model); - - for (i=0; i_size_model, &iter); - gtk_list_store_set (priv->_size_model, &iter, - 0, sizes[i], - 1, size_str->str, - -1); - } - g_string_free (size_str, TRUE); - } -#else - for (i=0; ipriv->filter), &iter, path)) - { - gtk_tree_path_free (path); - return; - } - - - gtk_tree_model_get (GTK_TREE_MODEL (fontsel->priv->filter), &iter, - FACE_COLUMN, &face, - FAMILY_COLUMN, &family, - -1); - - gtk_tree_view_scroll_to_cell (treeview, path, NULL, TRUE, 0.5, 0.5); - - gtk_tree_path_free (path); - path = NULL; - - if (!face || !family) - { - g_object_unref (face); - g_object_unref (family); - return; - } - - desc = pango_font_face_describe (face); - pango_font_description_set_size (desc, fontsel->priv->size); - gtk_widget_override_font (fontsel->priv->preview, desc); - - pango_font_face_list_sizes (face, &sizes, &n_sizes); - /* It seems not many fonts actually have a sane set of sizes */ - for (i=0; ipriv, fontsel->priv->size_slider, sizes, n_sizes); - - gtk_font_selection_ref_family (fontsel, family); - gtk_font_selection_ref_face (fontsel, face); - -#ifndef GTK_DISABLE_DEPRECATED - if (fontsel->priv->_font_model) - update_font_list_selection (fontsel); -#endif - - /* Free resources */ - g_object_unref ((gpointer)family); - g_object_unref ((gpointer)face); - pango_font_description_free(desc); - - g_object_notify (G_OBJECT (fontsel), "font-name"); -} - -gboolean -zoom_preview_cb (GtkWidget *scrolled_window, GdkEventScroll *event, gpointer data) -{ - GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*)data; - - GtkAdjustment *adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin)); - - if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_RIGHT) - gtk_adjustment_set_value (adj, - gtk_adjustment_get_value (adj) + - gtk_adjustment_get_step_increment (adj)); - else if (event->direction == GDK_SCROLL_DOWN || event->direction == GDK_SCROLL_LEFT) - gtk_adjustment_set_value (adj, - gtk_adjustment_get_value (adj) - - gtk_adjustment_get_step_increment (adj)); - return TRUE; -} - -static void -gtk_font_selection_init (GtkFontSelection *fontsel) -{ - GtkFontSelectionPrivate *priv; - PangoFontDescription *font_desc; - GtkWidget *scrolled_win; - GtkWidget *preview_and_size; - GtkWidget *size_controls; - - fontsel->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontsel, - GTK_TYPE_FONT_SELECTION, - GtkFontSelectionPrivate); - - priv = fontsel->priv; - -#ifndef GTK_DISABLE_DEPRECATED - priv->size_list = NULL; - priv->font_list = NULL; - priv->face_list = NULL; - - priv->_size_model = NULL; - priv->_font_model = NULL; - priv->_face_model = NULL; - - priv->ignore_size = FALSE; - priv->ignore_face = FALSE; - priv->ignore_font = FALSE; -#endif /* GTK_DISABLE_DEPRECATED */ - - /* Default preview string */ - priv->preview_text = g_strdup (pango_language_get_sample_string (NULL)); - priv->show_preview_entry = TRUE; - - /* Getting the default size */ - font_desc = pango_context_get_font_description (gtk_widget_get_pango_context (GTK_WIDGET (fontsel))); - priv->size = pango_font_description_get_size (font_desc); - priv->face = NULL; - priv->family = NULL; - - gtk_widget_push_composite_child (); - - /* Creating fundamental widgets for the private struct */ - priv->search_entry = gtk_entry_new (); - priv->family_face_list = gtk_tree_view_new (); - priv->preview = gtk_entry_new (); - priv->size_slider = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, - (gdouble) font_sizes[0], - (gdouble) font_sizes[FONT_SIZES_LENGTH - 1], - 1.0); - - priv->size_spin = gtk_spin_button_new_with_range (0.0, (gdouble)(G_MAXINT / PANGO_SCALE), 1.0); - - /** Bootstrapping widget layout **/ - gtk_box_set_spacing (GTK_BOX (fontsel), 6); - gtk_box_pack_start (GTK_BOX (fontsel), priv->search_entry, FALSE, TRUE, 0); - - /* Main font family/face view */ - scrolled_win = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), - GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), - GTK_SHADOW_ETCHED_IN); - gtk_container_add (GTK_CONTAINER (scrolled_win), priv->family_face_list); - - /* Alignment for the preview and size controls */ - gtk_box_pack_start (GTK_BOX (fontsel), scrolled_win, TRUE, TRUE, 0); - - preview_and_size = gtk_vbox_new (TRUE, 0); - gtk_box_set_homogeneous (GTK_BOX (preview_and_size), FALSE); - gtk_box_set_spacing (GTK_BOX (preview_and_size), 6); - - /* The preview entry needs a scrolled window to make sure we have a */ - scrolled_win = gtk_scrolled_window_new (NULL, NULL); - priv->preview_scrolled_window = scrolled_win; - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), - GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), - GTK_SHADOW_ETCHED_IN); - gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win), - priv->preview); - gtk_box_pack_start (GTK_BOX (preview_and_size), scrolled_win, FALSE, FALSE, 0); - - /* Setting the size requests for various widgets */ - gtk_widget_set_size_request (GTK_WIDGET (fontsel), FONTSEL_WIDTH, FONTSEL_HEIGHT); - gtk_widget_set_size_request (scrolled_win, -1, PREVIEW_HEIGHT); - gtk_widget_set_size_request (priv->preview, -1, PREVIEW_HEIGHT - 6); - - /* Unset the frame on the preview entry */ - gtk_entry_set_has_frame (GTK_ENTRY (priv->preview), FALSE); - - /* Packing the slider and the spin in a hbox */ - size_controls = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - gtk_scale_set_draw_value (GTK_SCALE (priv->size_slider), FALSE); - gtk_box_set_spacing (GTK_BOX (size_controls), 6); - gtk_box_pack_start (GTK_BOX (size_controls), priv->size_slider, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (size_controls), priv->size_spin, FALSE, TRUE, 0); - - gtk_widget_set_valign (priv->size_spin, GTK_ALIGN_START); - - gtk_box_pack_start (GTK_BOX (preview_and_size), size_controls, FALSE, FALSE, 0); - - gtk_box_pack_start (GTK_BOX (fontsel), GTK_WIDGET(preview_and_size), FALSE, TRUE, 0); - - gtk_adjustment_set_value (gtk_range_get_adjustment (GTK_RANGE (priv->size_slider)), - (gdouble)(priv->size / PANGO_SCALE)); - gtk_adjustment_set_value (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin)), - (gdouble)(priv->size / PANGO_SCALE)); - - gtk_widget_show_all (GTK_WIDGET (fontsel)); - gtk_widget_hide (GTK_WIDGET (fontsel)); - - /* Treeview column and model bootstrapping */ - gtk_font_selection_bootstrap_fontlist (fontsel); - - /* Set default preview text */ - gtk_entry_set_text (GTK_ENTRY (priv->preview), - pango_language_get_sample_string (NULL)); - - /* Set search icon and place holder text */ - gtk_entry_set_icon_from_stock (GTK_ENTRY (priv->search_entry), - GTK_ENTRY_ICON_SECONDARY, - GTK_STOCK_FIND); - gtk_entry_set_placeholder_text (GTK_ENTRY (priv->search_entry), _("Search font name")); - - /** Callback connections **/ - /* Connect to callback for the live search text entry */ - g_signal_connect (G_OBJECT (gtk_entry_get_buffer (GTK_ENTRY (priv->search_entry))), - "deleted-text", G_CALLBACK (deleted_text_cb), priv); - g_signal_connect (G_OBJECT (gtk_entry_get_buffer (GTK_ENTRY (priv->search_entry))), - "inserted-text", G_CALLBACK (inserted_text_cb), priv); - g_signal_connect (G_OBJECT (priv->search_entry), - "icon-press", G_CALLBACK (icon_press_cb), priv); - - /* Size controls callbacks */ - g_signal_connect (G_OBJECT (gtk_range_get_adjustment (GTK_RANGE (priv->size_slider))), - "value-changed", G_CALLBACK (slider_change_cb), priv); - g_signal_connect (G_OBJECT (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin))), - "value-changed", G_CALLBACK (spin_change_cb), fontsel); - priv->ignore_slider = FALSE; - - /* Font selection callback */ - g_signal_connect (G_OBJECT (priv->family_face_list), "cursor-changed", - G_CALLBACK (cursor_changed_cb), fontsel); - - /* Zoom on preview scroll*/ - g_signal_connect (G_OBJECT (scrolled_win), "scroll-event", - G_CALLBACK (zoom_preview_cb), priv); - - g_signal_connect (G_OBJECT (priv->size_slider), "scroll-event", - G_CALLBACK (zoom_preview_cb), priv); - - set_range_marks (priv, priv->size_slider, (gint*)font_sizes, FONT_SIZES_LENGTH); - - /* Set default focus */ - gtk_widget_pop_composite_child(); -} - -/** - * gtk_font_selection_new: - * - * Creates a new #GtkFontSelection. - * - * Return value: a new #GtkFontSelection - */ -GtkWidget * -gtk_font_selection_new (void) -{ - GtkFontSelection *fontsel; - - fontsel = g_object_new (GTK_TYPE_FONT_SELECTION, NULL); - - return GTK_WIDGET (fontsel); -} - -static int -cmp_families (const void *a, const void *b) -{ - const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a); - const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b); - - return g_utf8_collate (a_name, b_name); -} - -static void -populate_list (GtkFontSelection *fontsel, GtkTreeView* treeview, GtkListStore* model) -{ - GtkStyleContext *style_context; - GdkRGBA g_color; - PangoColor p_color; - gchar *color_string; - PangoFontDescription *default_font; - - GtkTreeIter match_row; - GtkTreePath *path; - - gint n_families, i; - PangoFontFamily **families; - - GString *tmp = g_string_new (NULL); - GString *family_and_face = g_string_new (NULL); - - pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (treeview)), - &families, - &n_families); - - qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families); - - gtk_list_store_clear (model); - - /* Get row header font color */ - style_context = gtk_widget_get_style_context (GTK_WIDGET (treeview)); - gtk_style_context_get_color (style_context, - GTK_STATE_FLAG_NORMAL | GTK_STATE_FLAG_INSENSITIVE, - &g_color); - - p_color.red = (guint16)((gdouble)G_MAXUINT16 * g_color.red); - p_color.green = (guint16)((gdouble)G_MAXUINT16 * g_color.green); - p_color.blue = (guint16)((gdouble)G_MAXUINT16 * g_color.blue); - color_string = pango_color_to_string (&p_color); - - /* Get theme font */ - default_font = (PangoFontDescription*) gtk_style_context_get_font (style_context, - GTK_STATE_NORMAL); - - /* Iterate over families and faces */ - for (i=0; istr, - font_desc, - fontsel->priv->preview_text); - - gtk_list_store_append (model, &iter); - gtk_list_store_set (model, &iter, - FAMILY_COLUMN, families[i], - FACE_COLUMN, faces[j], - PREVIEW_TITLE_COLUMN, family_and_face->str, - PREVIEW_TEXT_COLUMN, tmp->str, - -1); - - /* Select the first font or the default font/face from the style context */ - if ((i == 0 && j == 0) || - (!strcmp (fam_name, pango_font_description_get_family (default_font)) && j == 0)) - match_row = iter; - - pango_font_description_free(pango_desc); - g_free (font_desc); - } - - g_free (faces); - } - - path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &match_row); - - if (path) - { - gtk_tree_view_set_cursor (treeview, path, NULL, FALSE); - gtk_tree_view_scroll_to_cell (treeview, path, NULL, TRUE, 0.5, 0.5); - gtk_tree_path_free(path); - } - - g_string_free (family_and_face, TRUE); - g_string_free (tmp, TRUE); - g_free (color_string); - g_free (families); -} - -gboolean -visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data) -{ - gboolean result = FALSE; - GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*) data; - - const gchar *search_text = (const gchar*)gtk_entry_get_text (GTK_ENTRY (priv->search_entry)); - gchar *font_name; - gchar *font_name_casefold; - gchar *search_text_casefold; - - gtk_tree_model_get (model, iter, - PREVIEW_TITLE_COLUMN, &font_name, - -1); - - /* Covering some corner cases to speed up the result */ - if (font_name == NULL || - strlen (search_text) > strlen (font_name)) - { - g_free (font_name); - return FALSE; - } - if (strlen (search_text) == 0) - { - g_free (font_name); - return TRUE; - } - - font_name_casefold = g_utf8_casefold (font_name, -1); - search_text_casefold = g_utf8_casefold (search_text, -1); - - if (g_strrstr (font_name_casefold, search_text_casefold)) - result = TRUE; - - g_free (search_text_casefold); - g_free (font_name_casefold); - g_free (font_name); - return result; -} - -static void -gtk_font_selection_bootstrap_fontlist (GtkFontSelection* fontsel) -{ - GtkTreeView *treeview = GTK_TREE_VIEW (fontsel->priv->family_face_list); - GtkCellRenderer *cell; - GtkTreeViewColumn *col; - - fontsel->priv->model = gtk_list_store_new (4, - PANGO_TYPE_FONT_FAMILY, - PANGO_TYPE_FONT_FACE, - G_TYPE_STRING, - G_TYPE_STRING); - - fontsel->priv->filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fontsel->priv->model), - NULL); - g_object_unref (fontsel->priv->model); - - gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (fontsel->priv->filter), - visible_func, - (gpointer)fontsel->priv, - NULL); - - gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (fontsel->priv->filter)); - g_object_unref (fontsel->priv->filter); - - gtk_tree_view_set_rules_hint (treeview, TRUE); - gtk_tree_view_set_headers_visible (treeview, FALSE); - - cell = gtk_cell_renderer_text_new (); - col = gtk_tree_view_column_new_with_attributes ("Family", - cell, - "markup", PREVIEW_TEXT_COLUMN, - NULL); - - g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL); - - gtk_tree_view_append_column (treeview, col); - - populate_list (fontsel, treeview, fontsel->priv->model); -} - - -static void -gtk_font_selection_finalize (GObject *object) -{ - GtkFontSelection *fontsel = GTK_FONT_SELECTION (object); - - gtk_font_selection_ref_family (fontsel, NULL); - gtk_font_selection_ref_face (fontsel, NULL); - -#ifndef GTK_DISABLE_DEPRECATED - if (fontsel->priv->size_list) - { - g_object_unref (fontsel->priv->size_list); - g_object_unref (fontsel->priv->font_list); - g_object_unref (fontsel->priv->face_list); - } -#endif - - G_OBJECT_CLASS (gtk_font_selection_parent_class)->finalize (object); -} - - -static void -gtk_font_selection_screen_changed (GtkWidget *widget, - GdkScreen *previous_screen) -{ - GtkFontSelection *fontsel = GTK_FONT_SELECTION (widget); - - populate_list (fontsel, - GTK_TREE_VIEW (fontsel->priv->family_face_list), - fontsel->priv->model); - return; -} - -static void -gtk_font_selection_style_updated (GtkWidget *widget) -{ - GtkFontSelection *fontsel = GTK_FONT_SELECTION (widget); - - GTK_WIDGET_CLASS (gtk_font_selection_parent_class)->style_updated (widget); - - populate_list (fontsel, - GTK_TREE_VIEW (fontsel->priv->family_face_list), - fontsel->priv->model); - return; -} - -static void -gtk_font_selection_ref_family (GtkFontSelection *fontsel, - PangoFontFamily *family) -{ - GtkFontSelectionPrivate *priv = fontsel->priv; - - if (family) - family = g_object_ref (family); - if (priv->family) - g_object_unref (priv->family); - priv->family = family; -} - -static void -gtk_font_selection_ref_face (GtkFontSelection *fontsel, - PangoFontFace *face) -{ - GtkFontSelectionPrivate *priv = fontsel->priv; - - if (face) - face = g_object_ref (face); - if (priv->face) - g_object_unref (priv->face); - priv->face = face; -} - -#ifndef GTK_DISABLE_DEPRECATED -static void -populate_font_model (GtkFontSelection *fontsel) -{ - gint n_families, i; - PangoFontFamily **families; - GtkFontSelectionPrivate *priv = fontsel->priv; - GtkTreePath *path; - - pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (fontsel)), - &families, - &n_families); - - qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families); - - gtk_list_store_clear (priv->_font_model); - - for (i=0; i_font_model, &iter); - gtk_list_store_set (priv->_font_model, &iter, - 0, families[i], - 1, pango_font_family_get_name (families[i]), - -1); - if (priv->family && - !strcmp (pango_font_family_get_name (families[i]), - pango_font_family_get_name (priv->family))) - { - path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->_face_model), - &iter); - if (path) - { - GtkWidget *tv = gtk_bin_get_child (GTK_BIN (priv->font_list)); - gtk_tree_view_set_cursor (GTK_TREE_VIEW (tv), - path, - NULL, - FALSE); - gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tv), - path, NULL, TRUE, 0.5, 0.5); - gtk_tree_path_free (path); - } - } - } - - g_free (families); -} - -static void -update_font_list_selection (GtkFontSelection *fontsel) -{ - GtkTreeIter iter; - gboolean valid; - GtkFontSelectionPrivate *priv = fontsel->priv; - gchar *family_name; - - valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->_font_model), &iter); - while (valid) - { - GtkWidget *tv; - GtkTreePath *path; - gtk_tree_model_get (GTK_TREE_MODEL (priv->_font_model), &iter, - 1, &family_name, - -1); - if (strcmp (family_name, pango_font_family_get_name (priv->family))) - { - gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->_font_model), &iter); - g_free (family_name); - continue; - } - path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->_font_model), &iter); - - if (!path) - { - g_free (family_name); - break; - } - - tv = gtk_bin_get_child (GTK_BIN (priv->font_list)); - - priv->ignore_font = TRUE; - gtk_tree_view_set_cursor (GTK_TREE_VIEW (tv), path, NULL, FALSE); - gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tv), path, NULL, TRUE, 0.5, 0.5); - - /* Free resources */ - gtk_tree_path_free (path); - g_free (family_name); - break; - } - - update_face_model (fontsel, FALSE); -} - -static void -update_face_model (GtkFontSelection *fontsel, gboolean first) -{ - GtkFontSelectionPrivate *priv = fontsel->priv; - PangoFontFace **faces; - int i, n_faces; - - pango_font_family_list_faces (priv->family, &faces, &n_faces); - - gtk_list_store_clear (priv->_face_model); - - for (i=0; i_face_model, &iter); - gtk_list_store_set (priv->_face_model, &iter, - 0, faces[i], - 1, pango_font_face_get_face_name (faces[i]), - -1); - - if ((!first && faces[i] == priv->face) || - (first && i == 0)) - { - GtkTreePath *path; - GtkWidget *tv; - - path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->_face_model), &iter); - if (!path) - continue; - - tv = gtk_bin_get_child (GTK_BIN (priv->face_list)); - - if (!first) - priv->ignore_face = TRUE; - - gtk_tree_view_set_cursor (GTK_TREE_VIEW (tv), path, NULL, FALSE); - - gtk_tree_path_free (path); - - if (first) - gtk_font_selection_ref_face (fontsel, faces[i]); - } - } - - update_size_list_selection (fontsel); - - g_object_notify (G_OBJECT (fontsel), "font-name"); -} - -static void -update_size_list_selection (GtkFontSelection *fontsel) -{ - GtkTreeIter iter; - gboolean valid; - GtkFontSelectionPrivate *priv = fontsel->priv; - GtkWidget *tv = gtk_bin_get_child (GTK_BIN (priv->size_list)); - - gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (tv))); - - valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->_size_model), &iter); - while (valid) - { - gint size; - gtk_tree_model_get (GTK_TREE_MODEL (priv->_size_model), &iter, - 0, &size, - -1); - - if (size * PANGO_SCALE == priv->size) - { - GtkTreePath *path; - - - path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->_size_model), &iter); - if (!path) - break; - - - priv->ignore_size = TRUE; - gtk_tree_view_set_cursor (GTK_TREE_VIEW (tv), path, NULL, FALSE); - - gtk_tree_path_free (path); - break; - } - valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->_size_model), &iter); - } -} - - -static void -select_family_and_face (GtkFontSelection *fontsel) -{ - GtkTreeIter iter; - gboolean valid; - GtkFontSelectionPrivate *priv = fontsel->priv; - PangoFontFace *face; - PangoFontFamily *family; - - gtk_entry_set_text (GTK_ENTRY (priv->search_entry), ""); - - valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->filter), &iter); - while (valid) - { - gtk_tree_model_get (GTK_TREE_MODEL (priv->filter), &iter, - FACE_COLUMN, &face, - FAMILY_COLUMN, &family, - -1); - - if (face == priv->face && family == priv->family) - { - GtkTreePath *path; - - path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->filter), &iter); - if (!path) - { - g_object_unref (face); - g_object_unref (family); - break; - } - - priv->ignore_size = TRUE; - gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->family_face_list), path, NULL, FALSE); - - gtk_tree_path_free (path); - g_object_unref (face); - g_object_unref (family); - break; - } - - g_object_unref (face); - g_object_unref (family); - valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->filter), &iter); - } -} - - -static void -family_list_cursor_changed_cb (GtkTreeView *treeview, gpointer data) -{ - GtkWidget *tv; - GtkTreeIter iter; - GtkTreePath *path; - GtkFontSelection *fontsel = (GtkFontSelection*)data; - PangoFontFamily *font; - - if (fontsel->priv->ignore_font) - { - fontsel->priv->ignore_font = FALSE; - return; - } - - tv = gtk_bin_get_child (GTK_BIN (fontsel->priv->font_list)); - gtk_tree_view_get_cursor (GTK_TREE_VIEW (tv), &path, NULL); - - if (!path) - return; - - gtk_tree_model_get_iter (GTK_TREE_MODEL (fontsel->priv->_font_model), - &iter, - path); - - gtk_tree_model_get (GTK_TREE_MODEL (fontsel->priv->_font_model), &iter, - 0, &font, - -1); - - gtk_font_selection_ref_family (fontsel, font); - update_face_model (fontsel, TRUE); - - fontsel->priv->ignore_font = TRUE; - select_family_and_face (fontsel); - - gtk_tree_path_free (path); - g_object_unref (font); -} - -static void -face_list_cursor_changed_cb (GtkTreeView *treeview, gpointer data) -{ - GtkWidget *tv; - GtkTreeIter iter; - GtkTreePath *path; - GtkFontSelection *fontsel = (GtkFontSelection*)data; - PangoFontFace *face; - - if (fontsel->priv->ignore_face) - { - fontsel->priv->ignore_face = FALSE; - return; - } - - tv = gtk_bin_get_child (GTK_BIN (fontsel->priv->face_list)); - gtk_tree_view_get_cursor (GTK_TREE_VIEW (tv), &path, NULL); - - if (!path) - return; - - gtk_tree_model_get_iter (GTK_TREE_MODEL (fontsel->priv->_face_model), - &iter, - path); - - gtk_tree_model_get (GTK_TREE_MODEL (fontsel->priv->_face_model), &iter, - 0, &face, - -1); + * gtkfontchooser.c - Abstract interface for font file selectors GUIs + * + * Copyright (C) 2006, Emmanuele Bassi + * Copyright (C) 2011 Alberto Ruiz + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ - gtk_font_selection_ref_face (fontsel, face); +#include "config.h" - fontsel->priv->ignore_face = TRUE; - select_family_and_face (fontsel); +#include "gtkfontchooser.h" +#include "gtkfontchooserprivate.h" +#include "gtkintl.h" +#include "gtktypebuiltins.h" +#include "gtkprivate.h" - gtk_tree_path_free (path); - g_object_unref (face); -} +/** + * SECTION:gtkfontchooser + * @Short_description: Interface implemented by widgets displaying fonts + * @Title: GtkFontChooser + * @See_also: #GtkFontChooserDialog, #GtkFontChooserWidget, #GtkFontButton + * + * #GtkFontChooser is an interface that can be implemented by widgets + * displaying the list of fonts. In GTK+, the main objects + * that implement this interface are #GtkFontChooserWidget, + * #GtkFontChooserDialog and #GtkFontButton. + * + * Since: 3.2 + */ -static void -size_list_cursor_changed_cb (GtkTreeView *treeview, gpointer data) +enum { - GtkWidget *tv; - GtkTreeIter iter; - GtkTreePath *path; - GtkFontSelection *fontsel = (GtkFontSelection*)data; - gint value; - - if (fontsel->priv->ignore_size) - { - fontsel->priv->ignore_size = FALSE; - return; - } - - tv = gtk_bin_get_child (GTK_BIN (fontsel->priv->size_list)); - gtk_tree_view_get_cursor (GTK_TREE_VIEW (tv), &path, NULL); - - if (!path) - return; + SIGNAL_FONT_ACTIVATED, + LAST_SIGNAL +}; - gtk_tree_model_get_iter (GTK_TREE_MODEL (fontsel->priv->_size_model), - &iter, - path); - - gtk_tree_model_get (GTK_TREE_MODEL (fontsel->priv->_size_model), &iter, - 0, &value, - -1); +static guint chooser_signals[LAST_SIGNAL]; - gtk_spin_button_set_value (GTK_SPIN_BUTTON (fontsel->priv->size_spin), value); - gtk_tree_path_free (path); -} +typedef GtkFontChooserIface GtkFontChooserInterface; +G_DEFINE_INTERFACE (GtkFontChooser, gtk_font_chooser, G_TYPE_OBJECT); static void -initialize_deprecated_widgets (GtkFontSelection *fontsel) -{ - GtkTreeViewColumn *col; - GtkFontSelectionPrivate *priv = fontsel->priv; - - GtkWidget *size_list; - GtkWidget *font_list; - GtkWidget *face_list; - - priv->_size_model = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING); - priv->_font_model = gtk_list_store_new (2, PANGO_TYPE_FONT_FAMILY, G_TYPE_STRING); - priv->_face_model = gtk_list_store_new (2, PANGO_TYPE_FONT_FACE, G_TYPE_STRING); - - size_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->_size_model)); - font_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->_font_model)); - face_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->_face_model)); - - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (size_list), FALSE); - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (font_list), FALSE); - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (face_list), FALSE); - - g_object_unref (priv->_size_model); - g_object_unref (priv->_font_model); - g_object_unref (priv->_face_model); - - col = gtk_tree_view_column_new_with_attributes ("Size", - gtk_cell_renderer_text_new (), - "text", 1, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (size_list), col); - - col = gtk_tree_view_column_new_with_attributes ("Family", - gtk_cell_renderer_text_new (), - "text", 1, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (font_list), col); - - col = gtk_tree_view_column_new_with_attributes ("Face", - gtk_cell_renderer_text_new (), - "text", 1, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (face_list), col); - - - priv->font_list = gtk_scrolled_window_new (NULL, NULL); - priv->face_list = gtk_scrolled_window_new (NULL, NULL); - priv->size_list = gtk_scrolled_window_new (NULL, NULL); - - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->font_list), - GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->face_list), - GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->size_list), - GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - - gtk_container_add (GTK_CONTAINER (priv->font_list), font_list); - gtk_container_add (GTK_CONTAINER (priv->face_list), face_list); - gtk_container_add (GTK_CONTAINER (priv->size_list), size_list); - - g_signal_connect (G_OBJECT (font_list), "cursor-changed", - G_CALLBACK (family_list_cursor_changed_cb), fontsel); - - g_signal_connect (G_OBJECT (face_list), "cursor-changed", - G_CALLBACK (face_list_cursor_changed_cb), fontsel); - - g_signal_connect (G_OBJECT (size_list), "cursor-changed", - G_CALLBACK (size_list_cursor_changed_cb), fontsel); - - populate_font_model (fontsel); - cursor_changed_cb (GTK_TREE_VIEW (priv->family_face_list), fontsel); +gtk_font_chooser_default_init (GtkFontChooserInterface *iface) +{ + /** + * GtkFontChooser:font: + * + * The font description as a string, e.g. "Sans Italic 12". + */ + g_object_interface_install_property + (iface, + g_param_spec_string ("font", + P_("Font"), + P_("Font description as a string, e.g. \"Sans Italic 12\""), + GTK_FONT_CHOOSER_DEFAULT_FONT_NAME, + GTK_PARAM_READWRITE)); + + /** + * GtkFontChooser:font-desc: + * + * The font description as a #PangoFontDescription. + */ + g_object_interface_install_property + (iface, + g_param_spec_boxed ("font-desc", + P_("Font description"), + P_("Font description as a PangoFontDescription struct"), + PANGO_TYPE_FONT_DESCRIPTION, + GTK_PARAM_READWRITE)); + + /** + * GtkFontChooser:preview-text: + * + * The string with which to preview the font. + */ + g_object_interface_install_property + (iface, + g_param_spec_string ("preview-text", + P_("Preview text"), + P_("The text to display in order to demonstrate the selected font"), + pango_language_get_sample_string (NULL), + GTK_PARAM_READWRITE)); + + /** + * GtkFontChooser:show-preview-entry: + * + * Whether to show an entry to change the preview text. + */ + g_object_interface_install_property + (iface, + g_param_spec_boolean ("show-preview-entry", + P_("Show preview text entry"), + P_("Whether the preview text entry is shown or not"), + TRUE, + GTK_PARAM_READWRITE)); + + /** + * GtkFontChooser::font-activated: + * @self: the object which received the signal + * @fontname: the font name + * + * Emitted when a font is activated. + * This usually happens when the user double clicks an item, + * or an item is selected and the user presses one of the keys + * Space, Shift+Space, Return or Enter. + */ + chooser_signals[SIGNAL_FONT_ACTIVATED] = + g_signal_new ("font-activated", + GTK_TYPE_FONT_CHOOSER, + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GtkFontChooserIface, font_activated), + NULL, NULL, + NULL, + G_TYPE_NONE, + 1, G_TYPE_STRING); } -#endif /* GTK_DISABLE_DEPRECATED */ - -/***************************************************************************** - * These functions are the main public interface for getting/setting the font. - *****************************************************************************/ - /** - * gtk_font_selection_get_family: - * @fontsel: a #GtkFontSelection + * gtk_font_chooser_get_font_family: + * @fontchooser: a #GtkFontChooser * * Gets the #PangoFontFamily representing the selected font family. + * Font families are a collection of font faces. + * + * If the selected font is not installed, returns %NULL. * * Return value: (transfer none): A #PangoFontFamily representing the - * selected font family. Font families are a collection of font - * faces. The returned object is owned by @fontsel and must not - * be modified or freed. + * selected font family, or %NULL. The returned object is owned by @fontchooser + * and must not be modified or freed. * - * Since: 2.14 + * Since: 3.2 */ PangoFontFamily * -gtk_font_selection_get_family (GtkFontSelection *fontsel) +gtk_font_chooser_get_font_family (GtkFontChooser *fontchooser) { - g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL); + g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); - return fontsel->priv->family; + return GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->get_font_family (fontchooser); } /** - * gtk_font_selection_get_face: - * @fontsel: a #GtkFontSelection + * gtk_font_chooser_get_font_face: + * @fontchooser: a #GtkFontChooser * * Gets the #PangoFontFace representing the selected font group * details (i.e. family, slant, weight, width, etc). * + * If the selected font is not installed, returns %NULL. + * * Return value: (transfer none): A #PangoFontFace representing the - * selected font group details. The returned object is owned by - * @fontsel and must not be modified or freed. + * selected font group details, or %NULL. The returned object is owned by + * @fontchooser and must not be modified or freed. * - * Since: 2.14 + * Since: 3.2 */ PangoFontFace * -gtk_font_selection_get_face (GtkFontSelection *fontsel) +gtk_font_chooser_get_font_face (GtkFontChooser *fontchooser) { - g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL); + g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); - return fontsel->priv->face; + return GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->get_font_face (fontchooser); } /** - * gtk_font_selection_get_size: - * @fontsel: a #GtkFontSelection + * gtk_font_chooser_get_font_size: + * @fontchooser: a #GtkFontChooser * * The selected font size. * * Return value: A n integer representing the selected font size, * or -1 if no font size is selected. * - * Since: 2.14 - **/ + * Since: 3.2 + */ gint -gtk_font_selection_get_size (GtkFontSelection *fontsel) +gtk_font_chooser_get_font_size (GtkFontChooser *fontchooser) { - g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), -1); + g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), -1); - return fontsel->priv->size; + return GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->get_font_size (fontchooser); } /** - * gtk_font_selection_get_font_name: - * @fontsel: a #GtkFontSelection - * - * Gets the currently-selected font name. + * gtk_font_chooser_get_font: + * @fontchooser: a #GtkFontChooser * - * Note that this can be a different string than what you set with - * gtk_font_selection_set_font_name(), as the font selection widget may - * normalize font names and thus return a string with a different structure. - * For example, "Helvetica Italic Bold 12" could be normalized to - * "Helvetica Bold Italic 12". Use pango_font_description_equal() - * if you want to compare two font descriptions. - * - * Return value: (transfer full) (allow-none): A string with the name of the - * current font, or %NULL if no font is selected. You must free this - * string with g_free(). - */ -gchar * -gtk_font_selection_get_font_name (GtkFontSelection *fontsel) -{ - gchar *font_name; - PangoFontDescription *desc; - - if (!fontsel->priv->face) - return NULL; - - desc = pango_font_face_describe (fontsel->priv->face); - font_name = pango_font_description_to_string (desc); - pango_font_description_free (desc); - return font_name; -} - -/* This sets the current font, then selecting the appropriate list rows. */ - -/** - * gtk_font_selection_set_font_name: - * @fontsel: a #GtkFontSelection - * @fontname: a font name like "Helvetica 12" or "Times Bold 18" - * - * Sets the currently-selected font. + * Gets the currently-selected font name. * - * Note that the @fontsel needs to know the screen in which it will appear - * for this to work; this can be guaranteed by simply making sure that the - * @fontsel is inserted in a toplevel window before you call this function. - * - * Return value: %TRUE if the font could be set successfully; %FALSE if no - * such font exists or if the @fontsel doesn't belong to a particular - * screen yet. - */ -gboolean -gtk_font_selection_set_font_name (GtkFontSelection *fontsel, - const gchar *fontname) -{ - GtkFontSelectionPrivate *priv = fontsel->priv; - GtkTreeIter iter; - gboolean valid; - gchar *family_name; - PangoFontDescription *desc; - gboolean found = FALSE; - - g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), FALSE); - g_return_val_if_fail (fontname != NULL, FALSE); - - if (!gtk_widget_has_screen (GTK_WIDGET (fontsel))) - return FALSE; - - desc = pango_font_description_from_string (fontname); - family_name = (gchar*)pango_font_description_get_family (desc); - - if (!family_name) - { - pango_font_description_free (desc); - return FALSE; - } - - /* We make sure the filter is clear */ - gtk_entry_set_text (GTK_ENTRY (priv->search_entry), ""); - - /* We find the matching family/face */ - for (valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->filter), &iter); - valid; - valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->filter), &iter)) - { - PangoFontFace *face; - PangoFontDescription *tmp_desc; - - gtk_tree_model_get (GTK_TREE_MODEL (priv->filter), &iter, - FACE_COLUMN, &face, - -1); - - tmp_desc = pango_font_face_describe (face); - if (pango_font_description_get_size_is_absolute (desc)) - pango_font_description_set_absolute_size (tmp_desc, - pango_font_description_get_size (desc)); - else - pango_font_description_set_size (tmp_desc, - pango_font_description_get_size (desc)); - - - if (pango_font_description_equal (desc, tmp_desc)) - { - GtkTreePath *path; - gint size = pango_font_description_get_size (desc); - - if (size) - { - if (pango_font_description_get_size_is_absolute (desc)) - size = size * PANGO_SCALE; - gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->size_spin), - size / PANGO_SCALE); - } - - path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->filter), - &iter); - - if (path) - { - gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->family_face_list), - path, - NULL, - FALSE); - gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->family_face_list), - path, - NULL, - TRUE, - 0.5, - 0.5); - gtk_tree_path_free (path); - } - - found = TRUE; - } - - g_object_unref (face); - pango_font_description_free (tmp_desc); - - if (found) - break; - } - - pango_font_description_free (desc); - g_object_notify (G_OBJECT (fontsel), "font-name"); - - return found; -} - -/** - * gtk_font_selection_get_preview_text: - * @fontsel: a #GtkFontSelection + * Note that this can be a different string than what you set with + * gtk_font_chooser_set_font(), as the font chooser widget may + * normalize font names and thus return a string with a different + * structure. For example, "Helvetica Italic Bold 12" could be + * normalized to "Helvetica Bold Italic 12". * - * Gets the text displayed in the preview area. - * - * Return value: (transfer none): the text displayed in the - * preview area. This string is owned by the widget and - * should not be modified or freed - */ -G_CONST_RETURN gchar* -gtk_font_selection_get_preview_text (GtkFontSelection *fontsel) -{ - g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL); - return (const gchar*)fontsel->priv->preview_text; -} - - -/** - * gtk_font_selection_set_preview_text: - * @fontsel: a #GtkFontSelection - * @text: (transfer none): the text to display in the preview area + * Use pango_font_description_equal() if you want to compare two + * font descriptions. * - * Sets the text displayed in the preview area. - * The @text is used to show how the selected font looks. - */ -void -gtk_font_selection_set_preview_text (GtkFontSelection *fontsel, - const gchar *text) -{ - g_return_if_fail (GTK_IS_FONT_SELECTION (fontsel)); - g_return_if_fail (text != NULL); - - g_free (fontsel->priv->preview_text); - fontsel->priv->preview_text = g_strdup (text); - - populate_list (fontsel, - GTK_TREE_VIEW (fontsel->priv->family_face_list), - fontsel->priv->model); - - gtk_entry_set_text (GTK_ENTRY (fontsel->priv->preview), text); - - g_object_notify (G_OBJECT (fontsel), "preview-text"); -} - -/** - * gtk_font_selection_get_show_preview_entry: - * @fontsel: a #GtkFontSelection + * Return value: (transfer full) (allow-none): A string with the name + * of the current font, or %NULL if no font is selected. You must + * free this string with g_free(). * - * Return value: %TRUE if the preview entry is shown or %FALSE if - * it is hidden. * Since: 3.2 */ -gboolean -gtk_font_selection_get_show_preview_entry (GtkFontSelection *fontsel) +gchar * +gtk_font_chooser_get_font (GtkFontChooser *fontchooser) { - g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), FALSE); + gchar *fontname; - return fontsel->priv->show_preview_entry; -} + g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); -/** - * gtk_font_selection_set_show_preview_entry: - * @fontsel: a #GtkFontSelection - * @show_preview_entry: whether to show the editable preview entry or not - * - * Shows or hides the editable preview entry. - * Since: 3.2 - */ -void -gtk_font_selection_set_show_preview_entry (GtkFontSelection *fontsel, - gboolean show_preview_entry) -{ - g_return_if_fail (GTK_IS_FONT_SELECTION (fontsel)); + g_object_get (fontchooser, "font", &fontname, NULL); - if (show_preview_entry) - gtk_widget_show (fontsel->priv->preview_scrolled_window); - else - gtk_widget_hide (fontsel->priv->preview_scrolled_window); - fontsel->priv->show_preview_entry = show_preview_entry; - g_object_notify (G_OBJECT (fontsel), "show-preview-entry"); + return fontname; } -#ifndef GTK_DISABLE_DEPRECATED - /** - * gtk_font_selection_get_family_list: - * @fontsel: a #GtkFontSelection - * - * This returns the #GtkTreeView that lists font families, for - * example, 'Sans', 'Serif', etc. + * gtk_font_chooser_set_font: + * @fontchooser: a #GtkFontChooser + * @fontname: a font name like "Helvetica 12" or "Times Bold 18" * - * Return value: (transfer none): A #GtkWidget that is part of @fontsel + * Sets the currently-selected font. * - * Deprecated: 3.2 + * Since: 3.2 */ -GtkWidget * -gtk_font_selection_get_family_list (GtkFontSelection *fontsel) +void +gtk_font_chooser_set_font (GtkFontChooser *fontchooser, + const gchar *fontname) { - GtkFontSelectionPrivate *priv = fontsel->priv; - g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL); - if (!priv->font_list) - initialize_deprecated_widgets (fontsel); + g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); + g_return_if_fail (fontname != NULL); - return priv->font_list; + g_object_set (fontchooser, "font", fontname, NULL); } /** - * gtk_font_selection_get_face_list: - * @fontsel: a #GtkFontSelection + * gtk_font_chooser_get_font_desc: + * @fontchooser: a #GtkFontChooser * - * This returns the #GtkTreeView which lists all styles available for - * the selected font. For example, 'Regular', 'Bold', etc. - * - * Return value: (transfer none): A #GtkWidget that is part of @fontsel + * Gets the currently-selected font. * - * Deprecated: 3.2 - */ -GtkWidget * -gtk_font_selection_get_face_list (GtkFontSelection *fontsel) -{ - GtkFontSelectionPrivate *priv = fontsel->priv; - g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL); - if (!priv->face_list) - initialize_deprecated_widgets (fontsel); - - return priv->face_list; -} - -/** - * gtk_font_selection_get_size_entry: - * @fontsel: a #GtkFontSelection + * Note that this can be a different string than what you set with + * gtk_font_chooser_set_font(), as the font chooser widget may + * normalize font names and thus return a string with a different + * structure. For example, "Helvetica Italic Bold 12" could be + * normalized to "Helvetica Bold Italic 12". * - * This returns the #GtkEntry used to allow the user to edit the font - * number manually instead of selecting it from the list of font sizes. + * Use pango_font_description_equal() if you want to compare two + * font descriptions. * - * Return value: (transfer none): A #GtkWidget that is part of @fontsel + * Return value: (transfer full) (allow-none): A #PangoFontDescription for the + * current font, or %NULL if no font is selected. * - * Deprecated: 3.2 + * Since: 3.2 */ -GtkWidget * -gtk_font_selection_get_size_entry (GtkFontSelection *fontsel) +PangoFontDescription * +gtk_font_chooser_get_font_desc (GtkFontChooser *fontchooser) { - GtkFontSelectionPrivate *priv = fontsel->priv; - g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL); + PangoFontDescription *font_desc; - return priv->size_spin; -} + g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); -/** - * gtk_font_selection_get_size_list: - * @fontsel: a #GtkFontSelection - * - * This returns the #GtkTreeeView used to list font sizes. - * - * Return value: (transfer none): A #GtkWidget that is part of @fontsel - * - * Deprecated: 3.2 - */ -GtkWidget * -gtk_font_selection_get_size_list (GtkFontSelection *fontsel) -{ - GtkFontSelectionPrivate *priv = fontsel->priv; - g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL); - if (!priv->size_list) - initialize_deprecated_widgets (fontsel); + g_object_get (fontchooser, "font-desc", &font_desc, NULL); - return priv->size_list; + return font_desc; } /** - * gtk_font_selection_get_preview_entry: - * @fontsel: a #GtkFontSelection + * gtk_font_chooser_set_font_desc: + * @fontchooser: a #GtkFontChooser + * @font_desc: a #PangoFontDescription * - * This returns the #GtkEntry used to display the font as a preview. + * Sets the currently-selected font from @font_desc. * - * Return value: (transfer none): A #GtkWidget that is part of @fontsel - * - * Deprecated: 3.2 + * Since: 3.2 */ -GtkWidget * -gtk_font_selection_get_preview_entry (GtkFontSelection *fontsel) +void +gtk_font_chooser_set_font_desc (GtkFontChooser *fontchooser, + const PangoFontDescription *font_desc) { - GtkFontSelectionPrivate *priv = fontsel->priv; - g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL); + g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); + g_return_if_fail (font_desc != NULL); - return priv->preview; + g_object_set (fontchooser, "font-desc", font_desc, NULL); } -#endif /* GTK_DISABLE_DEPRECATED */ - /** - * SECTION:gtkfontseldlg - * @Short_description: A dialog box for selecting fonts - * @Title: GtkFontSelectionDialog - * @See_also: #GtkFontSelection, #GtkDialog - * - * The #GtkFontSelectionDialog widget is a dialog box for selecting a font. - * - * To set the font which is initially selected, use - * gtk_font_selection_dialog_set_font_name(). + * gtk_font_chooser_get_preview_text: + * @fontchooser: a #GtkFontChooser * - * To get the selected font use gtk_font_selection_dialog_get_font_name(). - * - * To change the text which is shown in the preview area, use - * gtk_font_selection_dialog_set_preview_text(). - * - * - * GtkFontSelectionDialog as GtkBuildable - * The GtkFontSelectionDialog implementation of the GtkBuildable interface - * exposes the embedded #GtkFontSelection as internal child with the - * name "font_selection". It also exposes the buttons with the names - * "select_button" and "cancel_button. The buttons with the names - * "ok_button" and "apply_button" are exposed but deprecated. - * - */ - -static void gtk_font_selection_dialog_buildable_interface_init (GtkBuildableIface *iface); -static GObject * gtk_font_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable, - GtkBuilder *builder, - const gchar *childname); - -G_DEFINE_TYPE_WITH_CODE (GtkFontSelectionDialog, gtk_font_selection_dialog, - GTK_TYPE_DIALOG, - G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, - gtk_font_selection_dialog_buildable_interface_init)) - -static GtkBuildableIface *parent_buildable_iface; - -static void -gtk_font_selection_dialog_class_init (GtkFontSelectionDialogClass *klass) -{ - g_type_class_add_private (klass, sizeof (GtkFontSelectionDialogPrivate)); -} - -static void -gtk_font_selection_dialog_init (GtkFontSelectionDialog *fontseldiag) -{ - GtkFontSelectionDialogPrivate *priv; - GtkDialog *dialog = GTK_DIALOG (fontseldiag); - GtkWidget *action_area, *content_area; - - fontseldiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontseldiag, - GTK_TYPE_FONT_SELECTION_DIALOG, - GtkFontSelectionDialogPrivate); - priv = fontseldiag->priv; - - content_area = gtk_dialog_get_content_area (dialog); - action_area = gtk_dialog_get_action_area (dialog); - - gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); - gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */ - gtk_container_set_border_width (GTK_CONTAINER (action_area), 5); - gtk_box_set_spacing (GTK_BOX (action_area), 6); - - gtk_widget_push_composite_child (); - - gtk_window_set_resizable (GTK_WINDOW (fontseldiag), TRUE); - - /* Create the content area */ - priv->fontsel = gtk_font_selection_new (); - gtk_container_set_border_width (GTK_CONTAINER (priv->fontsel), 5); - gtk_widget_show (priv->fontsel); - gtk_box_pack_start (GTK_BOX (content_area), - priv->fontsel, TRUE, TRUE, 0); - - /* Create the action area */ - priv->cancel_button = gtk_dialog_add_button (dialog, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL); -#ifndef GTK_DISABLE_DEPRECATED - priv->apply_button = gtk_dialog_add_button (dialog, - GTK_STOCK_APPLY, - GTK_RESPONSE_APPLY); - gtk_widget_hide (priv->apply_button); -#endif - - priv->select_button = gtk_dialog_add_button (dialog, - _("Select"), - GTK_RESPONSE_OK); - gtk_widget_grab_default (priv->select_button); - - gtk_dialog_set_alternative_button_order (GTK_DIALOG (fontseldiag), - GTK_RESPONSE_OK, -#ifndef GTK_DISABLE_DEPRECATED - GTK_RESPONSE_APPLY, -#endif - GTK_RESPONSE_CANCEL, - -1); - - gtk_window_set_title (GTK_WINDOW (fontseldiag), - _("Font Selection")); - - gtk_widget_pop_composite_child (); -} - -/** - * gtk_font_selection_dialog_new: - * @title: (allow-none): the title of the dialog window + * Gets the text displayed in the preview area. * - * Creates a new #GtkFontSelectionDialog. + * Return value: (transfer full): the text displayed in the + * preview area * - * Return value: a new #GtkFontSelectionDialog + * Since: 3.2 */ -GtkWidget* -gtk_font_selection_dialog_new (const gchar *title) +gchar * +gtk_font_chooser_get_preview_text (GtkFontChooser *fontchooser) { - GtkFontSelectionDialog *fontseldiag; - - fontseldiag = g_object_new (GTK_TYPE_FONT_SELECTION_DIALOG, NULL); + char *text; - if (title) - gtk_window_set_title (GTK_WINDOW (fontseldiag), title); - - return GTK_WIDGET (fontseldiag); -} + g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); -/** - * gtk_font_selection_dialog_get_font_selection: - * @fsd: a #GtkFontSelectionDialog - * - * Retrieves the #GtkFontSelection widget embedded in the dialog. - * - * Returns: (transfer none): the embedded #GtkFontSelection - * - * Since: 2.22 - **/ -GtkWidget* -gtk_font_selection_dialog_get_font_selection (GtkFontSelectionDialog *fsd) -{ - g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL); + g_object_get (fontchooser, "preview-text", &text, NULL); - return fsd->priv->fontsel; + return text; } - /** - * gtk_font_selection_dialog_get_select_button: - * @fsd: a #GtkFontSelectionDialog - * - * Gets the 'Select' button. + * gtk_font_chooser_set_preview_text: + * @fontchooser: a #GtkFontChooser + * @text: (transfer none): the text to display in the preview area * - * Return value: (transfer none): the #GtkWidget used in the dialog - * for the 'Select' button. + * Sets the text displayed in the preview area. + * The @text is used to show how the selected font looks. * * Since: 3.2 */ -GtkWidget * -gtk_font_selection_dialog_get_select_button (GtkFontSelectionDialog *fsd) +void +gtk_font_chooser_set_preview_text (GtkFontChooser *fontchooser, + const gchar *text) { - g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL); + g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); + g_return_if_fail (text != NULL); - return fsd->priv->select_button; + g_object_set (fontchooser, "preview-text", text, NULL); } /** - * gtk_font_selection_dialog_get_cancel_button: - * @fsd: a #GtkFontSelectionDialog + * gtk_font_chooser_get_show_preview_entry: + * @fontchooser: a #GtkFontChooser * - * Gets the 'Cancel' button. + * Returns whether the preview entry is shown or not. * - * Return value: (transfer none): the #GtkWidget used in the dialog - * for the 'Cancel' button. + * Return value: %TRUE if the preview entry is shown + * or %FALSE if it is hidden. * - * Since: 2.14 + * Since: 3.2 */ -GtkWidget * -gtk_font_selection_dialog_get_cancel_button (GtkFontSelectionDialog *fsd) -{ - g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL); - - return fsd->priv->cancel_button; -} - -static void -gtk_font_selection_dialog_buildable_interface_init (GtkBuildableIface *iface) -{ - parent_buildable_iface = g_type_interface_peek_parent (iface); - iface->get_internal_child = gtk_font_selection_dialog_buildable_get_internal_child; -} - -static GObject * -gtk_font_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable, - GtkBuilder *builder, - const gchar *childname) +gboolean +gtk_font_chooser_get_show_preview_entry (GtkFontChooser *fontchooser) { - GtkFontSelectionDialogPrivate *priv; + gboolean show; - priv = GTK_FONT_SELECTION_DIALOG (buildable)->priv; + g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), FALSE); - if (g_strcmp0 (childname, "select_button") == 0) - return G_OBJECT (priv->select_button); - else if (g_strcmp0 (childname, "cancel_button") == 0) - return G_OBJECT (priv->cancel_button); - else if (g_strcmp0 (childname, "font_selection") == 0) - return G_OBJECT (priv->fontsel); -#ifndef GTK_DISABLE_DEPRECATED - else if (g_strcmp0 (childname, "ok_button") == 0) - return G_OBJECT (priv->select_button); - else if (g_strcmp0 (childname, "apply_button") == 0) - return G_OBJECT (priv->apply_button); -#endif + g_object_get (fontchooser, "show-preview-entry", &show, NULL); - return parent_buildable_iface->get_internal_child (buildable, builder, childname); + return show; } /** - * gtk_font_selection_dialog_get_font_name: - * @fsd: a #GtkFontSelectionDialog - * - * Gets the currently-selected font name. + * gtk_font_chooser_set_show_preview_entry: + * @fontchooser: a #GtkFontChooser + * @show_preview_entry: whether to show the editable preview entry or not * - * Note that this can be a different string than what you set with - * gtk_font_selection_dialog_set_font_name(), as the font selection widget - * may normalize font names and thus return a string with a different - * structure. For example, "Helvetica Italic Bold 12" could be normalized - * to "Helvetica Bold Italic 12". Use pango_font_description_equal() - * if you want to compare two font descriptions. - * - * Return value: A string with the name of the current font, or %NULL if no - * font is selected. You must free this string with g_free(). - */ -gchar* -gtk_font_selection_dialog_get_font_name (GtkFontSelectionDialog *fsd) -{ - GtkFontSelectionDialogPrivate *priv; - - g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL); - - priv = fsd->priv; - - return gtk_font_selection_get_font_name (GTK_FONT_SELECTION (priv->fontsel)); -} - -/** - * gtk_font_selection_dialog_set_font_name: - * @fsd: a #GtkFontSelectionDialog - * @fontname: a font name like "Helvetica 12" or "Times Bold 18" + * Shows or hides the editable preview entry. * - * Sets the currently selected font. - * - * Return value: %TRUE if the font selected in @fsd is now the - * @fontname specified, %FALSE otherwise. + * Since: 3.2 */ -gboolean -gtk_font_selection_dialog_set_font_name (GtkFontSelectionDialog *fsd, - const gchar *fontname) +void +gtk_font_chooser_set_show_preview_entry (GtkFontChooser *fontchooser, + gboolean show_preview_entry) { - GtkFontSelectionDialogPrivate *priv; - - g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), FALSE); - g_return_val_if_fail (fontname, FALSE); + g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); - priv = fsd->priv; - - return gtk_font_selection_set_font_name (GTK_FONT_SELECTION (priv->fontsel), fontname); + show_preview_entry = show_preview_entry != FALSE; + g_object_set (fontchooser, "show-preview-entry", show_preview_entry, NULL); } /** - * gtk_font_selection_dialog_get_preview_text: - * @fsd: a #GtkFontSelectionDialog + * gtk_font_chooser_set_filter_func: + * @fontchooser: a #GtkFontChooser + * @filter: (allow-none): a #GtkFontFilterFunc, or %NULL + * @user_data: data to pass to @filter + * @destroy: function to call to free @data when it is no longer needed * - * Gets the text displayed in the preview area. - * - * Return value: the text displayed in the preview area. - * This string is owned by the widget and should not be - * modified or freed - */ -G_CONST_RETURN gchar* -gtk_font_selection_dialog_get_preview_text (GtkFontSelectionDialog *fsd) -{ - GtkFontSelectionDialogPrivate *priv; - - g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL); - - priv = fsd->priv; - - return gtk_font_selection_get_preview_text (GTK_FONT_SELECTION (priv->fontsel)); -} - -/** - * gtk_font_selection_dialog_set_preview_text: - * @fsd: a #GtkFontSelectionDialog - * @text: the text to display in the preview area + * Adds a filter function that decides which fonts to display + * in the font chooser. * - * Sets the text displayed in the preview area. + * Since: 3.2 */ void -gtk_font_selection_dialog_set_preview_text (GtkFontSelectionDialog *fsd, - const gchar *text) +gtk_font_chooser_set_filter_func (GtkFontChooser *fontchooser, + GtkFontFilterFunc filter, + gpointer user_data, + GDestroyNotify destroy) { - GtkFontSelectionDialogPrivate *priv; - - g_return_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd)); - g_return_if_fail (text != NULL); - - priv = fsd->priv; + g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); - gtk_font_selection_set_preview_text (GTK_FONT_SELECTION (priv->fontsel), text); + GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->set_filter_func (fontchooser, + filter, + user_data, + destroy); } -#ifndef GTK_DISABLE_DEPRECATED -/** - * gtk_font_selection_dialog_get_ok_button: - * @fsd: a #GtkFontSelectionDialog - * - * Gets the 'OK' button. - * - * Return value: (transfer none): the #GtkWidget used in the dialog - * for the 'OK' button. - * - * Since: 3.2: Use gtk_font_selection_dialog_get_select_button instead. - */ -GtkWidget * -gtk_font_selection_dialog_get_ok_button (GtkFontSelectionDialog *fsd) +void +_gtk_font_chooser_font_activated (GtkFontChooser *chooser, + const gchar *fontname) { - g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL); + g_return_if_fail (GTK_IS_FONT_CHOOSER (chooser)); - return fsd->priv->select_button; + g_signal_emit (chooser, chooser_signals[SIGNAL_FONT_ACTIVATED], 0, fontname); } -#endif /* GTK_DISABLE_DEPRECATED */