From: Matthias Clasen Date: Thu, 27 Oct 2022 02:58:21 +0000 (-0400) Subject: Deprecate GtkFontChooser and implementations X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~9^2~132^2~3 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=15572b01833910a3b65edcc28eaa28968847fe71;p=gtk4.git Deprecate GtkFontChooser and implementations These are being replaced by GtkFontDialog and GtkFontDialogButton This commit only moves the headers for GtkFontChooserWidget and GtkFontChooserDialog to deprecated/, and keeps the implementations in gtk/, since they will eventually be salvaged into a private GtkFontChooserWindow. --- diff --git a/demos/gtk-demo/fishbowl.c b/demos/gtk-demo/fishbowl.c index 8c39ef6014..eb5a35309f 100644 --- a/demos/gtk-demo/fishbowl.c +++ b/demos/gtk-demo/fishbowl.c @@ -68,11 +68,13 @@ create_blurred_button (void) return w; } +G_GNUC_BEGIN_IGNORE_DEPRECATIONS static GtkWidget * create_font_button (void) { return gtk_font_button_new (); } +G_GNUC_END_IGNORE_DEPRECATIONS static GtkWidget * create_level_bar (void) diff --git a/gtk/deprecated/gtkfontbutton.c b/gtk/deprecated/gtkfontbutton.c new file mode 100644 index 0000000000..2a6f037e3c --- /dev/null +++ b/gtk/deprecated/gtkfontbutton.c @@ -0,0 +1,1213 @@ +/* + * GTK - The GIMP Toolkit + * Copyright (C) 1998 David Abilleira Freijeiro + * All rights reserved. + * + * Based on gnome-color-picker by Federico Mena + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library. If not, see . + */ +/* + * Modified by the GTK+ Team and others 2003. 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 "gtkfontbutton.h" + +#include "gtkbinlayout.h" +#include "gtkbox.h" +#include "gtkfontchooser.h" +#include "gtkfontchooserdialog.h" +#include "gtkfontchooserutils.h" +#include +#include "gtklabel.h" +#include "gtkmarshalers.h" +#include "gtkprivate.h" +#include "gtkseparator.h" +#include "gtkwidgetprivate.h" + +#include +#include + + +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + +/** + * GtkFontButton: + * + * The `GtkFontButton` allows to open a font chooser dialog to change + * the font. + * + * ![An example GtkFontButton](font-button.png) + * + * It is suitable widget for selecting a font in a preference dialog. + * + * # CSS nodes + * + * ``` + * fontbutton + * ╰── button.font + * ╰── [content] + * ``` + * + * `GtkFontButton` has a single CSS node with name fontbutton which + * contains a button node with the .font style class. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead + */ + +typedef struct _GtkFontButtonClass GtkFontButtonClass; + +struct _GtkFontButton +{ + GtkWidget parent_instance; + + char *title; + char *fontname; + + guint use_font : 1; + guint use_size : 1; + guint show_preview_entry : 1; + guint modal : 1; + + GtkFontChooserLevel level; + + GtkWidget *button; + GtkWidget *font_dialog; + GtkWidget *font_label; + GtkWidget *size_label; + GtkWidget *font_size_box; + + int font_size; + PangoFontDescription *font_desc; + PangoFontFamily *font_family; + PangoFontFace *font_face; + PangoFontMap *font_map; + char *font_features; + PangoLanguage *language; + char *preview_text; + GtkFontFilterFunc font_filter; + gpointer font_filter_data; + GDestroyNotify font_filter_data_destroy; +}; + +struct _GtkFontButtonClass +{ + GtkWidgetClass parent_class; + + void (* font_set) (GtkFontButton *gfp); + void (* activate) (GtkFontButton *self); +}; + +/* Signals */ +enum +{ + FONT_SET, + ACTIVATE, + LAST_SIGNAL +}; + +enum +{ + PROP_0, + PROP_TITLE, + PROP_MODAL, + PROP_USE_FONT, + PROP_USE_SIZE +}; + +/* Prototypes */ +static void gtk_font_button_finalize (GObject *object); +static void gtk_font_button_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec); +static void gtk_font_button_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec); + +static void gtk_font_button_clicked (GtkButton *button, + gpointer user_data); + +/* Dialog response functions */ +static void response_cb (GtkDialog *dialog, + int response_id, + gpointer data); +static void dialog_destroy (GtkWidget *widget, + gpointer data); + +/* Auxiliary functions */ +static void gtk_font_button_label_use_font (GtkFontButton *gfs); +static void gtk_font_button_update_font_info (GtkFontButton *gfs); + +static void gtk_font_button_set_font_name (GtkFontButton *button, + const char *fontname); +static const char *gtk_font_button_get_font_name (GtkFontButton *button); +static void gtk_font_button_set_level (GtkFontButton *font_button, + GtkFontChooserLevel level); +static void gtk_font_button_set_language (GtkFontButton *button, + const char *language); + +static guint font_button_signals[LAST_SIGNAL] = { 0 }; + +static PangoFontFamily * gtk_font_button_font_chooser_get_font_family (GtkFontChooser *chooser); +static PangoFontFace * gtk_font_button_font_chooser_get_font_face (GtkFontChooser *chooser); +static int gtk_font_button_font_chooser_get_font_size (GtkFontChooser *chooser); +static void gtk_font_button_font_chooser_set_filter_func (GtkFontChooser *chooser, + GtkFontFilterFunc filter_func, + gpointer filter_data, + GDestroyNotify data_destroy); +static void gtk_font_button_font_chooser_set_font_map (GtkFontChooser *chooser, + PangoFontMap *font_map); +static PangoFontMap * gtk_font_button_font_chooser_get_font_map (GtkFontChooser *chooser); + + +static void +gtk_font_button_font_chooser_iface_init (GtkFontChooserIface *iface) +{ + iface->get_font_family = gtk_font_button_font_chooser_get_font_family; + iface->get_font_face = gtk_font_button_font_chooser_get_font_face; + iface->get_font_size = gtk_font_button_font_chooser_get_font_size; + iface->set_filter_func = gtk_font_button_font_chooser_set_filter_func; + iface->set_font_map = gtk_font_button_font_chooser_set_font_map; + iface->get_font_map = gtk_font_button_font_chooser_get_font_map; +} + +G_DEFINE_TYPE_WITH_CODE (GtkFontButton, gtk_font_button, GTK_TYPE_WIDGET, + G_IMPLEMENT_INTERFACE (GTK_TYPE_FONT_CHOOSER, + gtk_font_button_font_chooser_iface_init)) + +static void +clear_font_data (GtkFontButton *font_button) +{ + g_clear_object (&font_button->font_family); + g_clear_object (&font_button->font_face); + g_clear_pointer (&font_button->font_desc, pango_font_description_free); + g_clear_pointer (&font_button->fontname, g_free); + g_clear_pointer (&font_button->font_features, g_free); +} + +static void +clear_font_filter_data (GtkFontButton *font_button) +{ + if (font_button->font_filter_data_destroy) + font_button->font_filter_data_destroy (font_button->font_filter_data); + font_button->font_filter = NULL; + font_button->font_filter_data = NULL; + font_button->font_filter_data_destroy = NULL; +} + +static gboolean +font_description_style_equal (const PangoFontDescription *a, + const PangoFontDescription *b) +{ + return (pango_font_description_get_weight (a) == pango_font_description_get_weight (b) && + pango_font_description_get_style (a) == pango_font_description_get_style (b) && + pango_font_description_get_stretch (a) == pango_font_description_get_stretch (b) && + pango_font_description_get_variant (a) == pango_font_description_get_variant (b)); +} + +static void +gtk_font_button_update_font_data (GtkFontButton *font_button) +{ + PangoFontFamily **families; + PangoFontFace **faces; + int n_families, n_faces, i; + const char *family; + + g_assert (font_button->font_desc != NULL); + + font_button->fontname = pango_font_description_to_string (font_button->font_desc); + + family = pango_font_description_get_family (font_button->font_desc); + if (family == NULL) + return; + + n_families = 0; + families = NULL; + pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (font_button)), + &families, &n_families); + n_faces = 0; + faces = NULL; + for (i = 0; i < n_families; i++) + { + const char *name = pango_font_family_get_name (families[i]); + + if (!g_ascii_strcasecmp (name, family)) + { + font_button->font_family = g_object_ref (families[i]); + + pango_font_family_list_faces (families[i], &faces, &n_faces); + break; + } + } + g_free (families); + + for (i = 0; i < n_faces; i++) + { + PangoFontDescription *tmp_desc = pango_font_face_describe (faces[i]); + + if (font_description_style_equal (tmp_desc, font_button->font_desc)) + { + font_button->font_face = g_object_ref (faces[i]); + + pango_font_description_free (tmp_desc); + break; + } + else + pango_font_description_free (tmp_desc); + } + + g_free (faces); +} + +static char * +gtk_font_button_get_preview_text (GtkFontButton *font_button) +{ + if (font_button->font_dialog) + return gtk_font_chooser_get_preview_text (GTK_FONT_CHOOSER (font_button->font_dialog)); + + return g_strdup (font_button->preview_text); +} + +static void +gtk_font_button_set_preview_text (GtkFontButton *font_button, + const char *preview_text) +{ + if (font_button->font_dialog) + { + gtk_font_chooser_set_preview_text (GTK_FONT_CHOOSER (font_button->font_dialog), + preview_text); + return; + } + + g_free (font_button->preview_text); + font_button->preview_text = g_strdup (preview_text); +} + + +static gboolean +gtk_font_button_get_show_preview_entry (GtkFontButton *font_button) +{ + if (font_button->font_dialog) + return gtk_font_chooser_get_show_preview_entry (GTK_FONT_CHOOSER (font_button->font_dialog)); + + return font_button->show_preview_entry; +} + +static void +gtk_font_button_set_show_preview_entry (GtkFontButton *font_button, + gboolean show) +{ + show = show != FALSE; + + if (font_button->show_preview_entry != show) + { + font_button->show_preview_entry = show; + if (font_button->font_dialog) + gtk_font_chooser_set_show_preview_entry (GTK_FONT_CHOOSER (font_button->font_dialog), show); + g_object_notify (G_OBJECT (font_button), "show-preview-entry"); + } +} + +static PangoFontFamily * +gtk_font_button_font_chooser_get_font_family (GtkFontChooser *chooser) +{ + GtkFontButton *font_button = GTK_FONT_BUTTON (chooser); + + return font_button->font_family; +} + +static PangoFontFace * +gtk_font_button_font_chooser_get_font_face (GtkFontChooser *chooser) +{ + GtkFontButton *font_button = GTK_FONT_BUTTON (chooser); + + return font_button->font_face; +} + +static int +gtk_font_button_font_chooser_get_font_size (GtkFontChooser *chooser) +{ + GtkFontButton *font_button = GTK_FONT_BUTTON (chooser); + + return font_button->font_size; +} + +static void +gtk_font_button_font_chooser_set_filter_func (GtkFontChooser *chooser, + GtkFontFilterFunc filter_func, + gpointer filter_data, + GDestroyNotify data_destroy) +{ + GtkFontButton *font_button = GTK_FONT_BUTTON (chooser); + + if (font_button->font_dialog) + { + gtk_font_chooser_set_filter_func (GTK_FONT_CHOOSER (font_button->font_dialog), + filter_func, + filter_data, + data_destroy); + return; + } + + clear_font_filter_data (font_button); + font_button->font_filter = filter_func; + font_button->font_filter_data = filter_data; + font_button->font_filter_data_destroy = data_destroy; +} + +static void +gtk_font_button_take_font_desc (GtkFontButton *font_button, + PangoFontDescription *font_desc) +{ + GObject *object = G_OBJECT (font_button); + + if (font_button->font_desc && font_desc && + pango_font_description_equal (font_button->font_desc, font_desc)) + { + pango_font_description_free (font_desc); + return; + } + + g_object_freeze_notify (object); + + clear_font_data (font_button); + + if (font_desc) + font_button->font_desc = font_desc; /* adopted */ + else + font_button->font_desc = pango_font_description_from_string (_("Sans 12")); + + if (pango_font_description_get_size_is_absolute (font_button->font_desc)) + font_button->font_size = pango_font_description_get_size (font_button->font_desc); + else + font_button->font_size = pango_font_description_get_size (font_button->font_desc) / PANGO_SCALE; + + gtk_font_button_update_font_data (font_button); + gtk_font_button_update_font_info (font_button); + + if (font_button->font_dialog) + gtk_font_chooser_set_font_desc (GTK_FONT_CHOOSER (font_button->font_dialog), + font_button->font_desc); + + g_object_notify (G_OBJECT (font_button), "font"); + g_object_notify (G_OBJECT (font_button), "font-desc"); + + g_object_thaw_notify (object); +} + +static const PangoFontDescription * +gtk_font_button_get_font_desc (GtkFontButton *font_button) +{ + return font_button->font_desc; +} + +static void +gtk_font_button_font_chooser_set_font_map (GtkFontChooser *chooser, + PangoFontMap *font_map) +{ + GtkFontButton *font_button = GTK_FONT_BUTTON (chooser); + + if (g_set_object (&font_button->font_map, font_map)) + { + PangoContext *context; + + if (!font_map) + font_map = pango_cairo_font_map_get_default (); + + context = gtk_widget_get_pango_context (font_button->font_label); + pango_context_set_font_map (context, font_map); + if (font_button->font_dialog) + gtk_font_chooser_set_font_map (GTK_FONT_CHOOSER (font_button->font_dialog), font_map); + } +} + +static PangoFontMap * +gtk_font_button_font_chooser_get_font_map (GtkFontChooser *chooser) +{ + GtkFontButton *font_button = GTK_FONT_BUTTON (chooser); + + return font_button->font_map; +} + +static void +gtk_font_button_font_chooser_notify (GObject *object, + GParamSpec *pspec, + gpointer user_data) +{ + /* We do not forward the notification of the "font" property to the dialog! */ + if (pspec->name == I_("preview-text") || + pspec->name == I_("show-preview-entry")) + g_object_notify_by_pspec (user_data, pspec); +} + +static void +gtk_font_button_activate (GtkFontButton *self) +{ + gtk_widget_activate (self->button); +} + +static void +gtk_font_button_unrealize (GtkWidget *widget) +{ + GtkFontButton *font_button = GTK_FONT_BUTTON (widget); + + g_clear_pointer ((GtkWindow **) &font_button->font_dialog, gtk_window_destroy); + + GTK_WIDGET_CLASS (gtk_font_button_parent_class)->unrealize (widget); +} + +static void +gtk_font_button_class_init (GtkFontButtonClass *klass) +{ + GObjectClass *gobject_class; + GtkWidgetClass *widget_class; + + gobject_class = (GObjectClass *) klass; + widget_class = (GtkWidgetClass *) klass; + + gobject_class->finalize = gtk_font_button_finalize; + gobject_class->set_property = gtk_font_button_set_property; + gobject_class->get_property = gtk_font_button_get_property; + + widget_class->grab_focus = gtk_widget_grab_focus_child; + widget_class->focus = gtk_widget_focus_child; + widget_class->unrealize = gtk_font_button_unrealize; + + klass->font_set = NULL; + klass->activate = gtk_font_button_activate; + + _gtk_font_chooser_install_properties (gobject_class); + + /** + * GtkFontButton:title: (attributes org.gtk.Property.get=gtk_font_button_get_title org.gtk.Property.set=gtk_font_button_set_title) + * + * The title of the font chooser dialog. + */ + g_object_class_install_property (gobject_class, + PROP_TITLE, + g_param_spec_string ("title", NULL, NULL, + _("Pick a Font"), + GTK_PARAM_READWRITE)); + + /** + * GtkFontButton:use-font: (attributes org.gtk.Property.get=gtk_font_button_get_use_font org.gtk.Property.set=gtk_font_button_set_use_font) + * + * Whether the buttons label will be drawn in the selected font. + */ + g_object_class_install_property (gobject_class, + PROP_USE_FONT, + g_param_spec_boolean ("use-font", NULL, NULL, + FALSE, + GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); + + /** + * GtkFontButton:use-size: (attributes org.gtk.Property.get=gtk_font_button_get_use_size org.gtk.Property.set=gtk_font_button_set_use_size) + * + * Whether the buttons label will use the selected font size. + */ + g_object_class_install_property (gobject_class, + PROP_USE_SIZE, + g_param_spec_boolean ("use-size", NULL, NULL, + FALSE, + GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); + + /** + * GtkFontButton:modal: (attributes org.gtk.Property.get=gtk_font_button_get_modal org.gtk.Property.set=gtk_font_button_set_modal) + * + * Whether the font chooser dialog should be modal. + */ + g_object_class_install_property (gobject_class, + PROP_MODAL, + g_param_spec_boolean ("modal", NULL, NULL, + TRUE, + GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); + + /** + * GtkFontButton::font-set: + * @widget: the object which received the signal + * + * Emitted when the user selects a font. + * + * When handling this signal, use [method@Gtk.FontChooser.get_font] + * to find out which font was just selected. + * + * Note that this signal is only emitted when the user changes the font. + * If you need to react to programmatic font changes as well, use + * the notify::font signal. + */ + font_button_signals[FONT_SET] = g_signal_new (I_("font-set"), + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GtkFontButtonClass, font_set), + NULL, NULL, + NULL, + G_TYPE_NONE, 0); + + /** + * GtkFontButton::activate: + * @widget: the object which received the signal. + * + * Emitted to when the font button is activated. + * + * The `::activate` signal on `GtkFontButton` is an action signal and + * emitting it causes the button to present its dialog. + * + * Since: 4.4 + */ + font_button_signals[ACTIVATE] = + g_signal_new (I_ ("activate"), + G_OBJECT_CLASS_TYPE (gobject_class), + G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (GtkFontButtonClass, activate), + NULL, NULL, + NULL, + G_TYPE_NONE, 0); + + gtk_widget_class_set_activate_signal (widget_class, font_button_signals[ACTIVATE]); + + gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); + gtk_widget_class_set_css_name (widget_class, I_("fontbutton")); +} + +static void +gtk_font_button_init (GtkFontButton *font_button) +{ + GtkWidget *box; + + font_button->button = gtk_button_new (); + g_signal_connect (font_button->button, "clicked", G_CALLBACK (gtk_font_button_clicked), font_button); + font_button->font_label = gtk_label_new (_("Font")); + gtk_widget_set_hexpand (font_button->font_label, TRUE); + font_button->size_label = gtk_label_new ("14"); + font_button->font_size_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_box_append (GTK_BOX (box), font_button->font_label); + + gtk_box_append (GTK_BOX (font_button->font_size_box), gtk_separator_new (GTK_ORIENTATION_VERTICAL)); + gtk_box_append (GTK_BOX (font_button->font_size_box), font_button->size_label); + gtk_box_append (GTK_BOX (box), font_button->font_size_box); + + gtk_button_set_child (GTK_BUTTON (font_button->button), box); + gtk_widget_set_parent (font_button->button, GTK_WIDGET (font_button)); + + /* Initialize fields */ + font_button->modal = TRUE; + font_button->use_font = FALSE; + font_button->use_size = FALSE; + font_button->show_preview_entry = TRUE; + font_button->font_dialog = NULL; + font_button->font_family = NULL; + font_button->font_face = NULL; + font_button->font_size = -1; + font_button->title = g_strdup (_("Pick a Font")); + font_button->level = GTK_FONT_CHOOSER_LEVEL_FAMILY | + GTK_FONT_CHOOSER_LEVEL_STYLE | + GTK_FONT_CHOOSER_LEVEL_SIZE; + font_button->language = pango_language_get_default (); + + gtk_font_button_take_font_desc (font_button, NULL); + + gtk_widget_add_css_class (font_button->button, "font"); +} + +static void +gtk_font_button_finalize (GObject *object) +{ + GtkFontButton *font_button = GTK_FONT_BUTTON (object); + + g_free (font_button->title); + + clear_font_data (font_button); + clear_font_filter_data (font_button); + + g_free (font_button->preview_text); + + gtk_widget_unparent (font_button->button); + + G_OBJECT_CLASS (gtk_font_button_parent_class)->finalize (object); +} + +static void +gtk_font_button_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec) +{ + GtkFontButton *font_button = GTK_FONT_BUTTON (object); + + switch (param_id) + { + case GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT: + gtk_font_button_set_preview_text (font_button, g_value_get_string (value)); + break; + case GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY: + gtk_font_button_set_show_preview_entry (font_button, g_value_get_boolean (value)); + break; + case PROP_TITLE: + gtk_font_button_set_title (font_button, g_value_get_string (value)); + break; + case PROP_MODAL: + gtk_font_button_set_modal (font_button, g_value_get_boolean (value)); + break; + case GTK_FONT_CHOOSER_PROP_FONT_DESC: + gtk_font_button_take_font_desc (font_button, g_value_dup_boxed (value)); + break; + case GTK_FONT_CHOOSER_PROP_LANGUAGE: + gtk_font_button_set_language (font_button, g_value_get_string (value)); + break; + case GTK_FONT_CHOOSER_PROP_LEVEL: + gtk_font_button_set_level (font_button, g_value_get_flags (value)); + break; + case GTK_FONT_CHOOSER_PROP_FONT: + gtk_font_button_set_font_name (font_button, g_value_get_string (value)); + break; + case PROP_USE_FONT: + gtk_font_button_set_use_font (font_button, g_value_get_boolean (value)); + break; + case PROP_USE_SIZE: + gtk_font_button_set_use_size (font_button, g_value_get_boolean (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + } +} + +static void +gtk_font_button_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec) +{ + GtkFontButton *font_button = GTK_FONT_BUTTON (object); + + switch (param_id) + { + case GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT: + g_value_set_string (value, gtk_font_button_get_preview_text (font_button)); + break; + case GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY: + g_value_set_boolean (value, gtk_font_button_get_show_preview_entry (font_button)); + break; + case PROP_TITLE: + g_value_set_string (value, gtk_font_button_get_title (font_button)); + break; + case PROP_MODAL: + g_value_set_boolean (value, gtk_font_button_get_modal (font_button)); + break; + case GTK_FONT_CHOOSER_PROP_FONT_DESC: + g_value_set_boxed (value, gtk_font_button_get_font_desc (font_button)); + break; + case GTK_FONT_CHOOSER_PROP_FONT_FEATURES: + g_value_set_string (value, font_button->font_features); + break; + case GTK_FONT_CHOOSER_PROP_LANGUAGE: + g_value_set_string (value, pango_language_to_string (font_button->language)); + break; + case GTK_FONT_CHOOSER_PROP_LEVEL: + g_value_set_flags (value, font_button->level); + break; + case GTK_FONT_CHOOSER_PROP_FONT: + g_value_set_string (value, gtk_font_button_get_font_name (font_button)); + break; + case PROP_USE_FONT: + g_value_set_boolean (value, gtk_font_button_get_use_font (font_button)); + break; + case PROP_USE_SIZE: + g_value_set_boolean (value, gtk_font_button_get_use_size (font_button)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + } +} + + +/** + * gtk_font_button_new: + * + * Creates a new font picker widget. + * + * Returns: a new font picker widget. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead + */ +GtkWidget * +gtk_font_button_new (void) +{ + return g_object_new (GTK_TYPE_FONT_BUTTON, NULL); +} + +/** + * gtk_font_button_new_with_font: + * @fontname: Name of font to display in font chooser dialog + * + * Creates a new font picker widget showing the given font. + * + * Returns: a new font picker widget. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead + */ +GtkWidget * +gtk_font_button_new_with_font (const char *fontname) +{ + return g_object_new (GTK_TYPE_FONT_BUTTON, "font", fontname, NULL); +} + +/** + * gtk_font_button_set_title: (attributes org.gtk.Method.set_property=title) + * @font_button: a `GtkFontButton` + * @title: a string containing the font chooser dialog title + * + * Sets the title for the font chooser dialog. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead + */ +void +gtk_font_button_set_title (GtkFontButton *font_button, + const char *title) +{ + char *old_title; + g_return_if_fail (GTK_IS_FONT_BUTTON (font_button)); + + old_title = font_button->title; + font_button->title = g_strdup (title); + g_free (old_title); + + if (font_button->font_dialog) + gtk_window_set_title (GTK_WINDOW (font_button->font_dialog), font_button->title); + + g_object_notify (G_OBJECT (font_button), "title"); +} + +/** + * gtk_font_button_get_title: (attributes org.gtk.Method.get_property=title) + * @font_button: a `GtkFontButton` + * + * Retrieves the title of the font chooser dialog. + * + * Returns: an internal copy of the title string + * which must not be freed. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead + */ +const char * +gtk_font_button_get_title (GtkFontButton *font_button) +{ + g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), NULL); + + return font_button->title; +} + +/** + * gtk_font_button_set_modal: (attributes org.gtk.Method.set_property=modal) + * @font_button: a `GtkFontButton` + * @modal: %TRUE to make the dialog modal + * + * Sets whether the dialog should be modal. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead + */ +void +gtk_font_button_set_modal (GtkFontButton *font_button, + gboolean modal) +{ + g_return_if_fail (GTK_IS_FONT_BUTTON (font_button)); + + if (font_button->modal == modal) + return; + + font_button->modal = modal; + + if (font_button->font_dialog) + gtk_window_set_modal (GTK_WINDOW (font_button->font_dialog), font_button->modal); + + g_object_notify (G_OBJECT (font_button), "modal"); +} + +/** + * gtk_font_button_get_modal: (attributes org.gtk.Method.get_property=modal) + * @font_button: a `GtkFontButton` + * + * Gets whether the dialog is modal. + * + * Returns: %TRUE if the dialog is modal + * + * Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead + */ +gboolean +gtk_font_button_get_modal (GtkFontButton *font_button) +{ + g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), FALSE); + + return font_button->modal; +} + +/** + * gtk_font_button_get_use_font: (attributes org.gtk.Method.get_property=use-font) + * @font_button: a `GtkFontButton` + * + * Returns whether the selected font is used in the label. + * + * Returns: whether the selected font is used in the label. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead + */ +gboolean +gtk_font_button_get_use_font (GtkFontButton *font_button) +{ + g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), FALSE); + + return font_button->use_font; +} + +/** + * gtk_font_button_set_use_font: (attributes org.gtk.Method.set_property=use-font) + * @font_button: a `GtkFontButton` + * @use_font: If %TRUE, font name will be written using font chosen. + * + * If @use_font is %TRUE, the font name will be written + * using the selected font. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead + */ +void +gtk_font_button_set_use_font (GtkFontButton *font_button, + gboolean use_font) +{ + g_return_if_fail (GTK_IS_FONT_BUTTON (font_button)); + + use_font = (use_font != FALSE); + + if (font_button->use_font != use_font) + { + font_button->use_font = use_font; + + gtk_font_button_label_use_font (font_button); + + g_object_notify (G_OBJECT (font_button), "use-font"); + } +} + + +/** + * gtk_font_button_get_use_size: (attributes org.gtk.Method.get_property=use-size) + * @font_button: a `GtkFontButton` + * + * Returns whether the selected size is used in the label. + * + * Returns: whether the selected size is used in the label. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead + */ +gboolean +gtk_font_button_get_use_size (GtkFontButton *font_button) +{ + g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), FALSE); + + return font_button->use_size; +} + +/** + * gtk_font_button_set_use_size: (attributes org.gtk.Method.set_property=use-size) + * @font_button: a `GtkFontButton` + * @use_size: If %TRUE, font name will be written using the + * selected size. + * + * If @use_size is %TRUE, the font name will be written using + * the selected size. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead + */ +void +gtk_font_button_set_use_size (GtkFontButton *font_button, + gboolean use_size) +{ + g_return_if_fail (GTK_IS_FONT_BUTTON (font_button)); + + use_size = (use_size != FALSE); + if (font_button->use_size != use_size) + { + font_button->use_size = use_size; + + gtk_font_button_label_use_font (font_button); + + g_object_notify (G_OBJECT (font_button), "use-size"); + } +} + +static const char * +gtk_font_button_get_font_name (GtkFontButton *font_button) +{ + g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), NULL); + + return font_button->fontname; +} + +static void +gtk_font_button_set_font_name (GtkFontButton *font_button, + const char *fontname) +{ + PangoFontDescription *font_desc; + + font_desc = pango_font_description_from_string (fontname); + gtk_font_button_take_font_desc (font_button, font_desc); +} + +static void +gtk_font_button_clicked (GtkButton *button, + gpointer user_data) +{ + GtkFontChooser *font_dialog; + GtkFontButton *font_button = user_data; + + if (!font_button->font_dialog) + { + GtkWidget *parent; + + parent = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (font_button))); + + font_button->font_dialog = gtk_font_chooser_dialog_new (font_button->title, NULL); + gtk_window_set_hide_on_close (GTK_WINDOW (font_button->font_dialog), TRUE); + gtk_window_set_modal (GTK_WINDOW (font_button->font_dialog), font_button->modal); + gtk_window_set_display (GTK_WINDOW (font_button->font_dialog), gtk_widget_get_display (GTK_WIDGET (button))); + + font_dialog = GTK_FONT_CHOOSER (font_button->font_dialog); + + if (font_button->font_map) + gtk_font_chooser_set_font_map (font_dialog, font_button->font_map); + + gtk_font_chooser_set_show_preview_entry (font_dialog, font_button->show_preview_entry); + gtk_font_chooser_set_level (GTK_FONT_CHOOSER (font_dialog), font_button->level); + gtk_font_chooser_set_language (GTK_FONT_CHOOSER (font_dialog), pango_language_to_string (font_button->language)); + + if (font_button->preview_text) + { + gtk_font_chooser_set_preview_text (font_dialog, font_button->preview_text); + g_free (font_button->preview_text); + font_button->preview_text = NULL; + } + + if (font_button->font_filter) + { + gtk_font_chooser_set_filter_func (font_dialog, + font_button->font_filter, + font_button->font_filter_data, + font_button->font_filter_data_destroy); + font_button->font_filter = NULL; + font_button->font_filter_data = NULL; + font_button->font_filter_data_destroy = NULL; + } + + if (GTK_IS_WINDOW (parent)) + { + if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (font_dialog))) + gtk_window_set_transient_for (GTK_WINDOW (font_dialog), GTK_WINDOW (parent)); + + if (gtk_window_get_modal (GTK_WINDOW (parent))) + gtk_window_set_modal (GTK_WINDOW (font_dialog), TRUE); + } + + g_signal_connect (font_dialog, "notify", + G_CALLBACK (gtk_font_button_font_chooser_notify), button); + + g_signal_connect (font_dialog, "response", + G_CALLBACK (response_cb), font_button); + + g_signal_connect (font_dialog, "destroy", + G_CALLBACK (dialog_destroy), font_button); + } + + if (!gtk_widget_get_visible (font_button->font_dialog)) + { + font_dialog = GTK_FONT_CHOOSER (font_button->font_dialog); + gtk_font_chooser_set_font_desc (font_dialog, font_button->font_desc); + } + + gtk_window_present (GTK_WINDOW (font_button->font_dialog)); +} + + +static void +response_cb (GtkDialog *dialog, + int response_id, + gpointer data) +{ + GtkFontButton *font_button = GTK_FONT_BUTTON (data); + GtkFontChooser *font_chooser; + GObject *object; + + gtk_widget_hide (font_button->font_dialog); + + if (response_id != GTK_RESPONSE_OK) + return; + + font_chooser = GTK_FONT_CHOOSER (font_button->font_dialog); + object = G_OBJECT (font_chooser); + + g_object_freeze_notify (object); + + clear_font_data (font_button); + + font_button->font_desc = gtk_font_chooser_get_font_desc (font_chooser); + if (font_button->font_desc) + font_button->fontname = pango_font_description_to_string (font_button->font_desc); + font_button->font_family = gtk_font_chooser_get_font_family (font_chooser); + if (font_button->font_family) + g_object_ref (font_button->font_family); + font_button->font_face = gtk_font_chooser_get_font_face (font_chooser); + if (font_button->font_face) + g_object_ref (font_button->font_face); + font_button->font_size = gtk_font_chooser_get_font_size (font_chooser); + g_free (font_button->font_features); + font_button->font_features = gtk_font_chooser_get_font_features (font_chooser); + font_button->language = pango_language_from_string (gtk_font_chooser_get_language (font_chooser)); + + /* Set label font */ + gtk_font_button_update_font_info (font_button); + + g_object_notify (G_OBJECT (font_button), "font"); + g_object_notify (G_OBJECT (font_button), "font-desc"); + g_object_notify (G_OBJECT (font_button), "font-features"); + + g_object_thaw_notify (object); + + /* Emit font_set signal */ + g_signal_emit (font_button, font_button_signals[FONT_SET], 0); +} + +static void +dialog_destroy (GtkWidget *widget, + gpointer data) +{ + GtkFontButton *font_button = GTK_FONT_BUTTON (data); + + /* Dialog will get destroyed so reference is not valid now */ + font_button->font_dialog = NULL; +} + +static void +gtk_font_button_label_use_font (GtkFontButton *font_button) +{ + if (!font_button->use_font) + gtk_label_set_attributes (GTK_LABEL (font_button->font_label), NULL); + else + { + PangoFontDescription *desc; + PangoAttrList *attrs; + + desc = pango_font_description_copy (font_button->font_desc); + + if (!font_button->use_size) + pango_font_description_unset_fields (desc, PANGO_FONT_MASK_SIZE); + + attrs = pango_attr_list_new (); + + /* Prevent font fallback */ + pango_attr_list_insert (attrs, pango_attr_fallback_new (FALSE)); + + /* Force current font and features */ + pango_attr_list_insert (attrs, pango_attr_font_desc_new (desc)); + if (font_button->font_features) + pango_attr_list_insert (attrs, pango_attr_font_features_new (font_button->font_features)); + if (font_button->language) + pango_attr_list_insert (attrs, pango_attr_language_new (font_button->language)); + + gtk_label_set_attributes (GTK_LABEL (font_button->font_label), attrs); + + pango_attr_list_unref (attrs); + pango_font_description_free (desc); + } +} + +static void +gtk_font_button_update_font_info (GtkFontButton *font_button) +{ + const char *fam_name; + const char *face_name; + char *family_style; + + if (font_button->font_family) + fam_name = pango_font_family_get_name (font_button->font_family); + else + fam_name = C_("font", "None"); + if (font_button->font_face) + face_name = pango_font_face_get_face_name (font_button->font_face); + else + face_name = ""; + + if ((font_button->level & GTK_FONT_CHOOSER_LEVEL_STYLE) != 0) + family_style = g_strconcat (fam_name, " ", face_name, NULL); + else + family_style = g_strdup (fam_name); + + gtk_label_set_text (GTK_LABEL (font_button->font_label), family_style); + g_free (family_style); + + if ((font_button->level & GTK_FONT_CHOOSER_LEVEL_SIZE) != 0) + { + /* mirror Pango, which doesn't translate this either */ + char *size = g_strdup_printf ("%2.4g%s", + pango_font_description_get_size (font_button->font_desc) / (double)PANGO_SCALE, + pango_font_description_get_size_is_absolute (font_button->font_desc) ? "px" : ""); + + gtk_label_set_text (GTK_LABEL (font_button->size_label), size); + + g_free (size); + + gtk_widget_show (font_button->font_size_box); + } + else + gtk_widget_hide (font_button->font_size_box); + + + gtk_font_button_label_use_font (font_button); +} + +static void +gtk_font_button_set_level (GtkFontButton *font_button, + GtkFontChooserLevel level) +{ + if (font_button->level == level) + return; + + font_button->level = level; + + if (font_button->font_dialog) + gtk_font_chooser_set_level (GTK_FONT_CHOOSER (font_button->font_dialog), level); + + gtk_font_button_update_font_info (font_button); + + g_object_notify (G_OBJECT (font_button), "level"); +} + +static void +gtk_font_button_set_language (GtkFontButton *font_button, + const char *language) +{ + font_button->language = pango_language_from_string (language); + + if (font_button->font_dialog) + gtk_font_chooser_set_language (GTK_FONT_CHOOSER (font_button->font_dialog), language); + + g_object_notify (G_OBJECT (font_button), "language"); +} diff --git a/gtk/deprecated/gtkfontbutton.h b/gtk/deprecated/gtkfontbutton.h new file mode 100644 index 0000000000..e1a449506a --- /dev/null +++ b/gtk/deprecated/gtkfontbutton.h @@ -0,0 +1,77 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 1998 David Abilleira Freijeiro + * All rights reserved + * Based on gnome-color-picker by Federico Mena + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library. If not, see . + */ +/* + * Modified by the GTK+ Team and others 2003. 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/. + */ + +#ifndef __GTK_FONT_BUTTON_H__ +#define __GTK_FONT_BUTTON_H__ + +#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only can be included directly." +#endif + +#include + + +G_BEGIN_DECLS + +#define GTK_TYPE_FONT_BUTTON (gtk_font_button_get_type ()) +#define GTK_FONT_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FONT_BUTTON, GtkFontButton)) +#define GTK_IS_FONT_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FONT_BUTTON)) + +typedef struct _GtkFontButton GtkFontButton; + +GDK_AVAILABLE_IN_ALL +GType gtk_font_button_get_type (void) G_GNUC_CONST; +GDK_DEPRECATED_IN_4_10 +GtkWidget *gtk_font_button_new (void); +GDK_DEPRECATED_IN_4_10 +GtkWidget *gtk_font_button_new_with_font (const char *fontname); + +GDK_DEPRECATED_IN_4_10 +const char * gtk_font_button_get_title (GtkFontButton *font_button); +GDK_DEPRECATED_IN_4_10 +void gtk_font_button_set_title (GtkFontButton *font_button, + const char *title); +GDK_DEPRECATED_IN_4_10 +gboolean gtk_font_button_get_modal (GtkFontButton *font_button); +GDK_DEPRECATED_IN_4_10 +void gtk_font_button_set_modal (GtkFontButton *font_button, + gboolean modal); +GDK_DEPRECATED_IN_4_10 +gboolean gtk_font_button_get_use_font (GtkFontButton *font_button); +GDK_DEPRECATED_IN_4_10 +void gtk_font_button_set_use_font (GtkFontButton *font_button, + gboolean use_font); +GDK_DEPRECATED_IN_4_10 +gboolean gtk_font_button_get_use_size (GtkFontButton *font_button); +GDK_DEPRECATED_IN_4_10 +void gtk_font_button_set_use_size (GtkFontButton *font_button, + gboolean use_size); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkFontButton, g_object_unref) + +G_END_DECLS + + +#endif /* __GTK_FONT_BUTTON_H__ */ diff --git a/gtk/deprecated/gtkfontchooser.c b/gtk/deprecated/gtkfontchooser.c new file mode 100644 index 0000000000..94fccd3f45 --- /dev/null +++ b/gtk/deprecated/gtkfontchooser.c @@ -0,0 +1,640 @@ +/* GTK - The GIMP Toolkit + * 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 . + */ + +#include "config.h" + +#include "gtkfontchooser.h" +#include "gtkfontchooserprivate.h" +#include "gtktypebuiltins.h" +#include "gtkprivate.h" + +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + +/** + * GtkFontChooser: + * + * `GtkFontChooser` is an interface that can be implemented by widgets + * for choosing fonts. + * + * In GTK, the main objects that implement this interface are + * [class@Gtk.FontChooserWidget], [class@Gtk.FontChooserDialog] and + * [class@Gtk.FontButton]. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ + +enum +{ + SIGNAL_FONT_ACTIVATED, + LAST_SIGNAL +}; + +static guint chooser_signals[LAST_SIGNAL]; + +typedef GtkFontChooserIface GtkFontChooserInterface; +G_DEFINE_INTERFACE (GtkFontChooser, gtk_font_chooser, G_TYPE_OBJECT); + +static void +gtk_font_chooser_default_init (GtkFontChooserInterface *iface) +{ + /** + * GtkFontChooser:font: (attributes org.gtk.Property.get=gtk_font_chooser_get_font org.gtk.Property.set=gtk_font_chooser_set_font) + * + * The font description as a string, e.g. "Sans Italic 12". + */ + g_object_interface_install_property + (iface, + g_param_spec_string ("font", NULL, NULL, + GTK_FONT_CHOOSER_DEFAULT_FONT_NAME, + GTK_PARAM_READWRITE)); + + /** + * GtkFontChooser:font-desc: (attributes org.gtk.Property.get=gtk_font_chooser_get_font_desc org.gtk.Property.set=gtk_font_chooser_set_font_desc) + * + * The font description as a `PangoFontDescription`. + */ + g_object_interface_install_property + (iface, + g_param_spec_boxed ("font-desc", NULL, NULL, + PANGO_TYPE_FONT_DESCRIPTION, + GTK_PARAM_READWRITE)); + + /** + * GtkFontChooser:preview-text: (attributes org.gtk.Property.get=gtk_font_chooser_get_preview_text org.gtk.Property.set=gtk_font_chooser_set_preview_text) + * + * The string with which to preview the font. + */ + g_object_interface_install_property + (iface, + g_param_spec_string ("preview-text", NULL, NULL, + pango_language_get_sample_string (NULL), + GTK_PARAM_READWRITE)); + + /** + * GtkFontChooser:show-preview-entry: (attributes org.gtk.Property.get=gtk_font_chooser_get_show_preview_entry org.gtk.Property.set=gtk_font_chooser_set_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", NULL, NULL, + TRUE, + GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); + + /** + * GtkFontChooser:level: (attributes org.gtk.Property.get=gtk_font_chooser_get_level org.gtk.Property.set=gtk_font_chooser_set_level) + * + * The level of granularity to offer for selecting fonts. + */ + g_object_interface_install_property + (iface, + g_param_spec_flags ("level", NULL, NULL, + GTK_TYPE_FONT_CHOOSER_LEVEL, + GTK_FONT_CHOOSER_LEVEL_FAMILY | + GTK_FONT_CHOOSER_LEVEL_STYLE | + GTK_FONT_CHOOSER_LEVEL_SIZE, + GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); + + /** + * GtkFontChooser:font-features: (attributes org.gtk.Property.get=gtk_font_chooser_get_font_features) + * + * The selected font features. + * + * The format of the string is compatible with + * CSS and with Pango attributes. + */ + g_object_interface_install_property + (iface, + g_param_spec_string ("font-features", NULL, NULL, + "", + GTK_PARAM_READABLE)); + + /** + * GtkFontChooser:language: (attributes org.gtk.Property.get=gtk_font_chooser_get_language org.gtk.Property.set=gtk_font_chooser_set_language) + * + * The language for which the font features were selected. + */ + g_object_interface_install_property + (iface, + g_param_spec_string ("language", NULL, NULL, + "", + GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); + + /** + * 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 (I_("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); +} + +/** + * 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. + * + * Returns: (nullable) (transfer none): A `PangoFontFamily` representing the + * selected font family + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +PangoFontFamily * +gtk_font_chooser_get_font_family (GtkFontChooser *fontchooser) +{ + g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); + + return GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->get_font_family (fontchooser); +} + +/** + * 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. + * + * Returns: (nullable) (transfer none): A `PangoFontFace` representing the + * selected font group details + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +PangoFontFace * +gtk_font_chooser_get_font_face (GtkFontChooser *fontchooser) +{ + g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); + + return GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->get_font_face (fontchooser); +} + +/** + * gtk_font_chooser_get_font_size: + * @fontchooser: a `GtkFontChooser` + * + * The selected font size. + * + * Returns: A n integer representing the selected font size, + * or -1 if no font size is selected. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +int +gtk_font_chooser_get_font_size (GtkFontChooser *fontchooser) +{ + g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), -1); + + return GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->get_font_size (fontchooser); +} + +/** + * gtk_font_chooser_get_font: (attributes org.gtk.Method.get_property=font) + * @fontchooser: a `GtkFontChooser` + * + * Gets the currently-selected font name. + * + * Note that this can be a different string than what you set with + * [method@Gtk.FontChooser.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”. + * + * Use [method@Pango.FontDescription.equal] if you want to compare two + * font descriptions. + * + * Returns: (nullable) (transfer full): A string with the name + * of the current font + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +char * +gtk_font_chooser_get_font (GtkFontChooser *fontchooser) +{ + char *fontname; + + g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); + + g_object_get (fontchooser, "font", &fontname, NULL); + + + return fontname; +} + +/** + * gtk_font_chooser_set_font: (attributes org.gtk.Method.set_property=font) + * @fontchooser: a `GtkFontChooser` + * @fontname: a font name like “Helvetica 12” or “Times Bold 18” + * + * Sets the currently-selected font. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +void +gtk_font_chooser_set_font (GtkFontChooser *fontchooser, + const char *fontname) +{ + g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); + g_return_if_fail (fontname != NULL); + + g_object_set (fontchooser, "font", fontname, NULL); +} + +/** + * gtk_font_chooser_get_font_desc: (attributes org.gtk.Method.get_property=font-desc) + * @fontchooser: a `GtkFontChooser` + * + * Gets the currently-selected font. + * + * Note that this can be a different string than what you set with + * [method@Gtk.FontChooser.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”. + * + * Use [method@Pango.FontDescription.equal] if you want to compare two + * font descriptions. + * + * Returns: (nullable) (transfer full): A `PangoFontDescription` for the + * current font + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +PangoFontDescription * +gtk_font_chooser_get_font_desc (GtkFontChooser *fontchooser) +{ + PangoFontDescription *font_desc; + + g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); + + g_object_get (fontchooser, "font-desc", &font_desc, NULL); + + return font_desc; +} + +/** + * gtk_font_chooser_set_font_desc: (attributes org.gtk.Method.set_property=font-desc) + * @fontchooser: a `GtkFontChooser` + * @font_desc: a `PangoFontDescription` + * + * Sets the currently-selected font from @font_desc. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +void +gtk_font_chooser_set_font_desc (GtkFontChooser *fontchooser, + const PangoFontDescription *font_desc) +{ + g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); + g_return_if_fail (font_desc != NULL); + + g_object_set (fontchooser, "font-desc", font_desc, NULL); +} + +/** + * gtk_font_chooser_get_preview_text: (attributes org.gtk.Method.get_property=preview-text) + * @fontchooser: a `GtkFontChooser` + * + * Gets the text displayed in the preview area. + * + * Returns: (transfer full): the text displayed in the preview area + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +char * +gtk_font_chooser_get_preview_text (GtkFontChooser *fontchooser) +{ + char *text; + + g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); + + g_object_get (fontchooser, "preview-text", &text, NULL); + + return text; +} + +/** + * gtk_font_chooser_set_preview_text: (attributes org.gtk.Method.set_property=preview-text) + * @fontchooser: a `GtkFontChooser` + * @text: (transfer none): the text to display in the preview area + * + * Sets the text displayed in the preview area. + * + * The @text is used to show how the selected font looks. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +void +gtk_font_chooser_set_preview_text (GtkFontChooser *fontchooser, + const char *text) +{ + g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); + g_return_if_fail (text != NULL); + + g_object_set (fontchooser, "preview-text", text, NULL); +} + +/** + * gtk_font_chooser_get_show_preview_entry: (attributes org.gtk.Method.get_property=show-preview-entry) + * @fontchooser: a `GtkFontChooser` + * + * Returns whether the preview entry is shown or not. + * + * Returns: %TRUE if the preview entry is shown or %FALSE if it is hidden. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +gboolean +gtk_font_chooser_get_show_preview_entry (GtkFontChooser *fontchooser) +{ + gboolean show; + + g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), FALSE); + + g_object_get (fontchooser, "show-preview-entry", &show, NULL); + + return show; +} + +/** + * gtk_font_chooser_set_show_preview_entry: (attributes org.gtk.Method.set_property=show-preview-entry) + * @fontchooser: a `GtkFontChooser` + * @show_preview_entry: whether to show the editable preview entry or not + * + * Shows or hides the editable preview entry. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +void +gtk_font_chooser_set_show_preview_entry (GtkFontChooser *fontchooser, + gboolean show_preview_entry) +{ + g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); + + show_preview_entry = show_preview_entry != FALSE; + g_object_set (fontchooser, "show-preview-entry", show_preview_entry, NULL); +} + +/** + * gtk_font_chooser_set_filter_func: + * @fontchooser: a `GtkFontChooser` + * @filter: (nullable): a `GtkFontFilterFunc` + * @user_data: (closure): data to pass to @filter + * @destroy: function to call to free @data when it is no longer needed + * + * Adds a filter function that decides which fonts to display + * in the font chooser. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +void +gtk_font_chooser_set_filter_func (GtkFontChooser *fontchooser, + GtkFontFilterFunc filter, + gpointer user_data, + GDestroyNotify destroy) +{ + g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); + + GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->set_filter_func (fontchooser, + filter, + user_data, + destroy); +} + +void +_gtk_font_chooser_font_activated (GtkFontChooser *chooser, + const char *fontname) +{ + g_return_if_fail (GTK_IS_FONT_CHOOSER (chooser)); + + g_signal_emit (chooser, chooser_signals[SIGNAL_FONT_ACTIVATED], 0, fontname); +} + +/** + * gtk_font_chooser_set_font_map: + * @fontchooser: a `GtkFontChooser` + * @fontmap: (nullable): a `PangoFontMap` + * + * Sets a custom font map to use for this font chooser widget. + * + * A custom font map can be used to present application-specific + * fonts instead of or in addition to the normal system fonts. + * + * ```c + * FcConfig *config; + * PangoFontMap *fontmap; + * + * config = FcInitLoadConfigAndFonts (); + * FcConfigAppFontAddFile (config, my_app_font_file); + * + * fontmap = pango_cairo_font_map_new_for_font_type (CAIRO_FONT_TYPE_FT); + * pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (fontmap), config); + * + * gtk_font_chooser_set_font_map (font_chooser, fontmap); + * ``` + * + * Note that other GTK widgets will only be able to use the + * application-specific font if it is present in the font map they use: + * + * ```c + * context = gtk_widget_get_pango_context (label); + * pango_context_set_font_map (context, fontmap); + * ``` + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +void +gtk_font_chooser_set_font_map (GtkFontChooser *fontchooser, + PangoFontMap *fontmap) +{ + g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); + g_return_if_fail (fontmap == NULL || PANGO_IS_FONT_MAP (fontmap)); + + if (GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->set_font_map) + GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->set_font_map (fontchooser, fontmap); +} + +/** + * gtk_font_chooser_get_font_map: + * @fontchooser: a `GtkFontChooser` + * + * Gets the custom font map of this font chooser widget, + * or %NULL if it does not have one. + * + * Returns: (nullable) (transfer full): a `PangoFontMap` + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +PangoFontMap * +gtk_font_chooser_get_font_map (GtkFontChooser *fontchooser) +{ + PangoFontMap *fontmap = NULL; + + g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); + + if (GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->get_font_map) + fontmap = GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->get_font_map (fontchooser); + + return fontmap; +} + +/** + * gtk_font_chooser_set_level: (attributes org.gtk.Method.set_property=level) + * @fontchooser: a `GtkFontChooser` + * @level: the desired level of granularity + * + * Sets the desired level of granularity for selecting fonts. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +void +gtk_font_chooser_set_level (GtkFontChooser *fontchooser, + GtkFontChooserLevel level) +{ + g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); + + g_object_set (fontchooser, "level", level, NULL); +} + +/** + * gtk_font_chooser_get_level: (attributes org.gtk.Method.get_property=level) + * @fontchooser: a `GtkFontChooser` + * + * Returns the current level of granularity for selecting fonts. + * + * Returns: the current granularity level + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +GtkFontChooserLevel +gtk_font_chooser_get_level (GtkFontChooser *fontchooser) +{ + GtkFontChooserLevel level; + + g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), 0); + + g_object_get (fontchooser, "level", &level, NULL); + + return level; +} + +/** + * gtk_font_chooser_get_font_features: (attributes org.gtk.Method.get_property=font-features) + * @fontchooser: a `GtkFontChooser` + * + * Gets the currently-selected font features. + * + * The format of the returned string is compatible with the + * [CSS font-feature-settings property](https://www.w3.org/TR/css-fonts-4/#font-rend-desc). + * It can be passed to [func@Pango.AttrFontFeatures.new]. + * + * Returns: the currently selected font features + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +char * +gtk_font_chooser_get_font_features (GtkFontChooser *fontchooser) +{ + char *text; + + g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); + + g_object_get (fontchooser, "font-features", &text, NULL); + + return text; +} + +/** + * gtk_font_chooser_get_language: (attributes org.gtk.Method.get_property=language) + * @fontchooser: a `GtkFontChooser` + * + * Gets the language that is used for font features. + * + * Returns: the currently selected language + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +char * +gtk_font_chooser_get_language (GtkFontChooser *fontchooser) +{ + char *text; + + g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); + + g_object_get (fontchooser, "language", &text, NULL); + + return text; +} + +/** + * gtk_font_chooser_set_language: (attributes org.gtk.Method.set_property=language) + * @fontchooser: a `GtkFontChooser` + * @language: a language + * + * Sets the language to use for font features. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton] + * instead + */ +void +gtk_font_chooser_set_language (GtkFontChooser *fontchooser, + const char *language) +{ + g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); + + g_object_set (fontchooser, "language", language, NULL); +} diff --git a/gtk/deprecated/gtkfontchooser.h b/gtk/deprecated/gtkfontchooser.h new file mode 100644 index 0000000000..09b3e79cd0 --- /dev/null +++ b/gtk/deprecated/gtkfontchooser.h @@ -0,0 +1,168 @@ +/* GTK - The GIMP Toolkit + * gtkfontchooser.h - 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 . + */ + +#ifndef __GTK_FONT_CHOOSER_H__ +#define __GTK_FONT_CHOOSER_H__ + +#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only can be included directly." +#endif + +#include + +G_BEGIN_DECLS + +/** + * GtkFontFilterFunc: + * @family: a `PangoFontFamily` + * @face: a `PangoFontFace` belonging to @family + * @data: (closure): user data passed to gtk_font_chooser_set_filter_func() + * + * The type of function that is used for deciding what fonts get + * shown in a `GtkFontChooser`. + * + * See [method@Gtk.FontChooser.set_filter_func]. + * + * Returns: %TRUE if the font should be displayed + */ +typedef gboolean (*GtkFontFilterFunc) (const PangoFontFamily *family, + const PangoFontFace *face, + gpointer data); + +/** + * GtkFontChooserLevel: + * @GTK_FONT_CHOOSER_LEVEL_FAMILY: Allow selecting a font family + * @GTK_FONT_CHOOSER_LEVEL_STYLE: Allow selecting a specific font face + * @GTK_FONT_CHOOSER_LEVEL_SIZE: Allow selecting a specific font size + * @GTK_FONT_CHOOSER_LEVEL_VARIATIONS: Allow changing OpenType font variation axes + * @GTK_FONT_CHOOSER_LEVEL_FEATURES: Allow selecting specific OpenType font features + * + * Specifies the granularity of font selection + * that is desired in a `GtkFontChooser`. + * + * This enumeration may be extended in the future; applications should + * ignore unknown values. + */ +typedef enum { + GTK_FONT_CHOOSER_LEVEL_FAMILY = 0, + GTK_FONT_CHOOSER_LEVEL_STYLE = 1 << 0, + GTK_FONT_CHOOSER_LEVEL_SIZE = 1 << 1, + GTK_FONT_CHOOSER_LEVEL_VARIATIONS = 1 << 2, + GTK_FONT_CHOOSER_LEVEL_FEATURES = 1 << 3 +} GtkFontChooserLevel; + +#define GTK_TYPE_FONT_CHOOSER (gtk_font_chooser_get_type ()) +#define GTK_FONT_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FONT_CHOOSER, GtkFontChooser)) +#define GTK_IS_FONT_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FONT_CHOOSER)) +#define GTK_FONT_CHOOSER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FONT_CHOOSER, GtkFontChooserIface)) + +typedef struct _GtkFontChooser GtkFontChooser; /* dummy */ +typedef struct _GtkFontChooserIface GtkFontChooserIface; + +struct _GtkFontChooserIface +{ + GTypeInterface base_iface; + + /* Methods */ + PangoFontFamily * (* get_font_family) (GtkFontChooser *fontchooser); + PangoFontFace * (* get_font_face) (GtkFontChooser *fontchooser); + int (* get_font_size) (GtkFontChooser *fontchooser); + + void (* set_filter_func) (GtkFontChooser *fontchooser, + GtkFontFilterFunc filter, + gpointer user_data, + GDestroyNotify destroy); + + /* Signals */ + void (* font_activated) (GtkFontChooser *chooser, + const char *fontname); + + /* More methods */ + void (* set_font_map) (GtkFontChooser *fontchooser, + PangoFontMap *fontmap); + PangoFontMap * (* get_font_map) (GtkFontChooser *fontchooser); + + /*< private >*/ + /* Padding; remove in GTK-next */ + gpointer padding[10]; +}; + +GDK_AVAILABLE_IN_ALL +GType gtk_font_chooser_get_type (void) G_GNUC_CONST; + +GDK_DEPRECATED_IN_4_10 +PangoFontFamily *gtk_font_chooser_get_font_family (GtkFontChooser *fontchooser); +GDK_DEPRECATED_IN_4_10 +PangoFontFace *gtk_font_chooser_get_font_face (GtkFontChooser *fontchooser); +GDK_DEPRECATED_IN_4_10 +int gtk_font_chooser_get_font_size (GtkFontChooser *fontchooser); + +GDK_DEPRECATED_IN_4_10 +PangoFontDescription * + gtk_font_chooser_get_font_desc (GtkFontChooser *fontchooser); +GDK_DEPRECATED_IN_4_10 +void gtk_font_chooser_set_font_desc (GtkFontChooser *fontchooser, + const PangoFontDescription *font_desc); + +GDK_DEPRECATED_IN_4_10 +char * gtk_font_chooser_get_font (GtkFontChooser *fontchooser); + +GDK_DEPRECATED_IN_4_10 +void gtk_font_chooser_set_font (GtkFontChooser *fontchooser, + const char *fontname); +GDK_DEPRECATED_IN_4_10 +char * gtk_font_chooser_get_preview_text (GtkFontChooser *fontchooser); +GDK_DEPRECATED_IN_4_10 +void gtk_font_chooser_set_preview_text (GtkFontChooser *fontchooser, + const char *text); +GDK_DEPRECATED_IN_4_10 +gboolean gtk_font_chooser_get_show_preview_entry (GtkFontChooser *fontchooser); +GDK_DEPRECATED_IN_4_10 +void gtk_font_chooser_set_show_preview_entry (GtkFontChooser *fontchooser, + gboolean show_preview_entry); +GDK_DEPRECATED_IN_4_10 +void gtk_font_chooser_set_filter_func (GtkFontChooser *fontchooser, + GtkFontFilterFunc filter, + gpointer user_data, + GDestroyNotify destroy); +GDK_DEPRECATED_IN_4_10 +void gtk_font_chooser_set_font_map (GtkFontChooser *fontchooser, + PangoFontMap *fontmap); +GDK_DEPRECATED_IN_4_10 +PangoFontMap * gtk_font_chooser_get_font_map (GtkFontChooser *fontchooser); +GDK_DEPRECATED_IN_4_10 +void gtk_font_chooser_set_level (GtkFontChooser *fontchooser, + GtkFontChooserLevel level); +GDK_DEPRECATED_IN_4_10 +GtkFontChooserLevel + gtk_font_chooser_get_level (GtkFontChooser *fontchooser); +GDK_DEPRECATED_IN_4_10 +char * gtk_font_chooser_get_font_features (GtkFontChooser *fontchooser); +GDK_DEPRECATED_IN_4_10 +char * gtk_font_chooser_get_language (GtkFontChooser *fontchooser); +GDK_DEPRECATED_IN_4_10 +void gtk_font_chooser_set_language (GtkFontChooser *fontchooser, + const char *language); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkFontChooser, g_object_unref) + +G_END_DECLS + +#endif /* __GTK_FONT_CHOOSER_H__ */ diff --git a/gtk/deprecated/gtkfontchooserdialog.h b/gtk/deprecated/gtkfontchooserdialog.h new file mode 100644 index 0000000000..ca1d9e4a1f --- /dev/null +++ b/gtk/deprecated/gtkfontchooserdialog.h @@ -0,0 +1,45 @@ +/* GTK - The GIMP Toolkit + * 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 . + */ + +#ifndef __GTK_FONT_CHOOSER_DIALOG_H__ +#define __GTK_FONT_CHOOSER_DIALOG_H__ + +#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only can be included directly." +#endif + +#include + +G_BEGIN_DECLS + +#define GTK_TYPE_FONT_CHOOSER_DIALOG (gtk_font_chooser_dialog_get_type ()) +#define GTK_FONT_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FONT_CHOOSER_DIALOG, GtkFontChooserDialog)) +#define GTK_IS_FONT_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FONT_CHOOSER_DIALOG)) + +typedef struct _GtkFontChooserDialog GtkFontChooserDialog; + +GDK_AVAILABLE_IN_ALL +GType gtk_font_chooser_dialog_get_type (void) G_GNUC_CONST; +GDK_DEPRECATED_IN_4_10 +GtkWidget* gtk_font_chooser_dialog_new (const char *title, + GtkWindow *parent); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkFontChooserDialog, g_object_unref) + +G_END_DECLS + +#endif /* __GTK_FONT_CHOOSER_DIALOG_H__ */ diff --git a/gtk/deprecated/gtkfontchooserprivate.h b/gtk/deprecated/gtkfontchooserprivate.h new file mode 100644 index 0000000000..480351ead2 --- /dev/null +++ b/gtk/deprecated/gtkfontchooserprivate.h @@ -0,0 +1,35 @@ +/* gtkfontprivatechooser.h - Interface definitions for font selectors UI + * + * Copyright (C) 2006 Emmanuele Bassi + * + * All rights reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library. If not, see . + */ + +#ifndef __GTK_FONT_CHOOSER_PRIVATE_H__ +#define __GTK_FONT_CHOOSER_PRIVATE_H__ + +#include "gtkfontchooser.h" + +#define GTK_FONT_CHOOSER_DEFAULT_FONT_NAME "Sans 10" + +G_BEGIN_DECLS + +void _gtk_font_chooser_font_activated (GtkFontChooser *chooser, + const char *fontname); + +G_END_DECLS + +#endif /* ! __GTK_FONT_CHOOSER_PRIVATE_H__ */ diff --git a/gtk/deprecated/gtkfontchooserwidget.h b/gtk/deprecated/gtkfontchooserwidget.h new file mode 100644 index 0000000000..f0d1c49099 --- /dev/null +++ b/gtk/deprecated/gtkfontchooserwidget.h @@ -0,0 +1,45 @@ +/* GTK - The GIMP Toolkit + * 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 . + */ + +#ifndef __GTK_FONT_CHOOSER_WIDGET_H__ +#define __GTK_FONT_CHOOSER_WIDGET_H__ + +#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only can be included directly." +#endif + +#include + +G_BEGIN_DECLS + +#define GTK_TYPE_FONT_CHOOSER_WIDGET (gtk_font_chooser_widget_get_type ()) +#define GTK_FONT_CHOOSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FONT_CHOOSER_WIDGET, GtkFontChooserWidget)) +#define GTK_IS_FONT_CHOOSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FONT_CHOOSER_WIDGET)) + +typedef struct _GtkFontChooserWidget GtkFontChooserWidget; + +GDK_AVAILABLE_IN_ALL +GType gtk_font_chooser_widget_get_type (void) G_GNUC_CONST; + +GDK_DEPRECATED_IN_4_10 +GtkWidget* gtk_font_chooser_widget_new (void); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkFontChooserWidget, g_object_unref) + +G_END_DECLS + +#endif /* __GTK_FONT_CHOOSER_WIDGET_H__ */ diff --git a/gtk/deprecated/meson.build b/gtk/deprecated/meson.build index ae5012bb5b..3e1051825d 100644 --- a/gtk/deprecated/meson.build +++ b/gtk/deprecated/meson.build @@ -24,6 +24,8 @@ gtk_deprecated_sources = [ 'deprecated/gtkcombobox.c', 'deprecated/gtkcomboboxtext.c', 'deprecated/gtkentrycompletion.c', + 'deprecated/gtkfontbutton.c', + 'deprecated/gtkfontchooser.c', 'deprecated/gtkiconview.c', 'deprecated/gtkliststore.c', 'deprecated/gtkrender.c', @@ -69,6 +71,10 @@ gtk_deprecated_headers = [ 'deprecated/gtkcombobox.h', 'deprecated/gtkcomboboxtext.h', 'deprecated/gtkentrycompletion.h', + 'deprecated/gtkfontbutton.h', + 'deprecated/gtkfontchooser.h', + 'deprecated/gtkfontchooserdialog.h', + 'deprecated/gtkfontchooserwidget.h', 'deprecated/gtkiconview.h', 'deprecated/gtkliststore.h', 'deprecated/gtkrender.h', diff --git a/gtk/gtk.h b/gtk/gtk.h index a33ad62bc9..1444da20ed 100644 --- a/gtk/gtk.h +++ b/gtk/gtk.h @@ -135,10 +135,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include diff --git a/gtk/gtkfontbutton.c b/gtk/gtkfontbutton.c deleted file mode 100644 index ef8f64c2b5..0000000000 --- a/gtk/gtkfontbutton.c +++ /dev/null @@ -1,1189 +0,0 @@ -/* - * GTK - The GIMP Toolkit - * Copyright (C) 1998 David Abilleira Freijeiro - * All rights reserved. - * - * Based on gnome-color-picker by Federico Mena - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library. If not, see . - */ -/* - * Modified by the GTK+ Team and others 2003. 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 "gtkfontbutton.h" - -#include "gtkbinlayout.h" -#include "gtkbox.h" -#include "gtkfontchooser.h" -#include "gtkfontchooserdialog.h" -#include "gtkfontchooserutils.h" -#include -#include "gtklabel.h" -#include "gtkmarshalers.h" -#include "gtkprivate.h" -#include "gtkseparator.h" -#include "gtkwidgetprivate.h" - -#include -#include - - -/** - * GtkFontButton: - * - * The `GtkFontButton` allows to open a font chooser dialog to change - * the font. - * - * ![An example GtkFontButton](font-button.png) - * - * It is suitable widget for selecting a font in a preference dialog. - * - * # CSS nodes - * - * ``` - * fontbutton - * ╰── button.font - * ╰── [content] - * ``` - * - * `GtkFontButton` has a single CSS node with name fontbutton which - * contains a button node with the .font style class. - */ - -typedef struct _GtkFontButtonClass GtkFontButtonClass; - -struct _GtkFontButton -{ - GtkWidget parent_instance; - - char *title; - char *fontname; - - guint use_font : 1; - guint use_size : 1; - guint show_preview_entry : 1; - guint modal : 1; - - GtkFontChooserLevel level; - - GtkWidget *button; - GtkWidget *font_dialog; - GtkWidget *font_label; - GtkWidget *size_label; - GtkWidget *font_size_box; - - int font_size; - PangoFontDescription *font_desc; - PangoFontFamily *font_family; - PangoFontFace *font_face; - PangoFontMap *font_map; - char *font_features; - PangoLanguage *language; - char *preview_text; - GtkFontFilterFunc font_filter; - gpointer font_filter_data; - GDestroyNotify font_filter_data_destroy; -}; - -struct _GtkFontButtonClass -{ - GtkWidgetClass parent_class; - - void (* font_set) (GtkFontButton *gfp); - void (* activate) (GtkFontButton *self); -}; - -/* Signals */ -enum -{ - FONT_SET, - ACTIVATE, - LAST_SIGNAL -}; - -enum -{ - PROP_0, - PROP_TITLE, - PROP_MODAL, - PROP_USE_FONT, - PROP_USE_SIZE -}; - -/* Prototypes */ -static void gtk_font_button_finalize (GObject *object); -static void gtk_font_button_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); -static void gtk_font_button_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); - -static void gtk_font_button_clicked (GtkButton *button, - gpointer user_data); - -/* Dialog response functions */ -static void response_cb (GtkDialog *dialog, - int response_id, - gpointer data); -static void dialog_destroy (GtkWidget *widget, - gpointer data); - -/* Auxiliary functions */ -static void gtk_font_button_label_use_font (GtkFontButton *gfs); -static void gtk_font_button_update_font_info (GtkFontButton *gfs); - -static void gtk_font_button_set_font_name (GtkFontButton *button, - const char *fontname); -static const char *gtk_font_button_get_font_name (GtkFontButton *button); -static void gtk_font_button_set_level (GtkFontButton *font_button, - GtkFontChooserLevel level); -static void gtk_font_button_set_language (GtkFontButton *button, - const char *language); - -static guint font_button_signals[LAST_SIGNAL] = { 0 }; - -static PangoFontFamily * gtk_font_button_font_chooser_get_font_family (GtkFontChooser *chooser); -static PangoFontFace * gtk_font_button_font_chooser_get_font_face (GtkFontChooser *chooser); -static int gtk_font_button_font_chooser_get_font_size (GtkFontChooser *chooser); -static void gtk_font_button_font_chooser_set_filter_func (GtkFontChooser *chooser, - GtkFontFilterFunc filter_func, - gpointer filter_data, - GDestroyNotify data_destroy); -static void gtk_font_button_font_chooser_set_font_map (GtkFontChooser *chooser, - PangoFontMap *font_map); -static PangoFontMap * gtk_font_button_font_chooser_get_font_map (GtkFontChooser *chooser); - - -static void -gtk_font_button_font_chooser_iface_init (GtkFontChooserIface *iface) -{ - iface->get_font_family = gtk_font_button_font_chooser_get_font_family; - iface->get_font_face = gtk_font_button_font_chooser_get_font_face; - iface->get_font_size = gtk_font_button_font_chooser_get_font_size; - iface->set_filter_func = gtk_font_button_font_chooser_set_filter_func; - iface->set_font_map = gtk_font_button_font_chooser_set_font_map; - iface->get_font_map = gtk_font_button_font_chooser_get_font_map; -} - -G_DEFINE_TYPE_WITH_CODE (GtkFontButton, gtk_font_button, GTK_TYPE_WIDGET, - G_IMPLEMENT_INTERFACE (GTK_TYPE_FONT_CHOOSER, - gtk_font_button_font_chooser_iface_init)) - -static void -clear_font_data (GtkFontButton *font_button) -{ - g_clear_object (&font_button->font_family); - g_clear_object (&font_button->font_face); - g_clear_pointer (&font_button->font_desc, pango_font_description_free); - g_clear_pointer (&font_button->fontname, g_free); - g_clear_pointer (&font_button->font_features, g_free); -} - -static void -clear_font_filter_data (GtkFontButton *font_button) -{ - if (font_button->font_filter_data_destroy) - font_button->font_filter_data_destroy (font_button->font_filter_data); - font_button->font_filter = NULL; - font_button->font_filter_data = NULL; - font_button->font_filter_data_destroy = NULL; -} - -static gboolean -font_description_style_equal (const PangoFontDescription *a, - const PangoFontDescription *b) -{ - return (pango_font_description_get_weight (a) == pango_font_description_get_weight (b) && - pango_font_description_get_style (a) == pango_font_description_get_style (b) && - pango_font_description_get_stretch (a) == pango_font_description_get_stretch (b) && - pango_font_description_get_variant (a) == pango_font_description_get_variant (b)); -} - -static void -gtk_font_button_update_font_data (GtkFontButton *font_button) -{ - PangoFontFamily **families; - PangoFontFace **faces; - int n_families, n_faces, i; - const char *family; - - g_assert (font_button->font_desc != NULL); - - font_button->fontname = pango_font_description_to_string (font_button->font_desc); - - family = pango_font_description_get_family (font_button->font_desc); - if (family == NULL) - return; - - n_families = 0; - families = NULL; - pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (font_button)), - &families, &n_families); - n_faces = 0; - faces = NULL; - for (i = 0; i < n_families; i++) - { - const char *name = pango_font_family_get_name (families[i]); - - if (!g_ascii_strcasecmp (name, family)) - { - font_button->font_family = g_object_ref (families[i]); - - pango_font_family_list_faces (families[i], &faces, &n_faces); - break; - } - } - g_free (families); - - for (i = 0; i < n_faces; i++) - { - PangoFontDescription *tmp_desc = pango_font_face_describe (faces[i]); - - if (font_description_style_equal (tmp_desc, font_button->font_desc)) - { - font_button->font_face = g_object_ref (faces[i]); - - pango_font_description_free (tmp_desc); - break; - } - else - pango_font_description_free (tmp_desc); - } - - g_free (faces); -} - -static char * -gtk_font_button_get_preview_text (GtkFontButton *font_button) -{ - if (font_button->font_dialog) - return gtk_font_chooser_get_preview_text (GTK_FONT_CHOOSER (font_button->font_dialog)); - - return g_strdup (font_button->preview_text); -} - -static void -gtk_font_button_set_preview_text (GtkFontButton *font_button, - const char *preview_text) -{ - if (font_button->font_dialog) - { - gtk_font_chooser_set_preview_text (GTK_FONT_CHOOSER (font_button->font_dialog), - preview_text); - return; - } - - g_free (font_button->preview_text); - font_button->preview_text = g_strdup (preview_text); -} - - -static gboolean -gtk_font_button_get_show_preview_entry (GtkFontButton *font_button) -{ - if (font_button->font_dialog) - return gtk_font_chooser_get_show_preview_entry (GTK_FONT_CHOOSER (font_button->font_dialog)); - - return font_button->show_preview_entry; -} - -static void -gtk_font_button_set_show_preview_entry (GtkFontButton *font_button, - gboolean show) -{ - show = show != FALSE; - - if (font_button->show_preview_entry != show) - { - font_button->show_preview_entry = show; - if (font_button->font_dialog) - gtk_font_chooser_set_show_preview_entry (GTK_FONT_CHOOSER (font_button->font_dialog), show); - g_object_notify (G_OBJECT (font_button), "show-preview-entry"); - } -} - -static PangoFontFamily * -gtk_font_button_font_chooser_get_font_family (GtkFontChooser *chooser) -{ - GtkFontButton *font_button = GTK_FONT_BUTTON (chooser); - - return font_button->font_family; -} - -static PangoFontFace * -gtk_font_button_font_chooser_get_font_face (GtkFontChooser *chooser) -{ - GtkFontButton *font_button = GTK_FONT_BUTTON (chooser); - - return font_button->font_face; -} - -static int -gtk_font_button_font_chooser_get_font_size (GtkFontChooser *chooser) -{ - GtkFontButton *font_button = GTK_FONT_BUTTON (chooser); - - return font_button->font_size; -} - -static void -gtk_font_button_font_chooser_set_filter_func (GtkFontChooser *chooser, - GtkFontFilterFunc filter_func, - gpointer filter_data, - GDestroyNotify data_destroy) -{ - GtkFontButton *font_button = GTK_FONT_BUTTON (chooser); - - if (font_button->font_dialog) - { - gtk_font_chooser_set_filter_func (GTK_FONT_CHOOSER (font_button->font_dialog), - filter_func, - filter_data, - data_destroy); - return; - } - - clear_font_filter_data (font_button); - font_button->font_filter = filter_func; - font_button->font_filter_data = filter_data; - font_button->font_filter_data_destroy = data_destroy; -} - -static void -gtk_font_button_take_font_desc (GtkFontButton *font_button, - PangoFontDescription *font_desc) -{ - GObject *object = G_OBJECT (font_button); - - if (font_button->font_desc && font_desc && - pango_font_description_equal (font_button->font_desc, font_desc)) - { - pango_font_description_free (font_desc); - return; - } - - g_object_freeze_notify (object); - - clear_font_data (font_button); - - if (font_desc) - font_button->font_desc = font_desc; /* adopted */ - else - font_button->font_desc = pango_font_description_from_string (_("Sans 12")); - - if (pango_font_description_get_size_is_absolute (font_button->font_desc)) - font_button->font_size = pango_font_description_get_size (font_button->font_desc); - else - font_button->font_size = pango_font_description_get_size (font_button->font_desc) / PANGO_SCALE; - - gtk_font_button_update_font_data (font_button); - gtk_font_button_update_font_info (font_button); - - if (font_button->font_dialog) - gtk_font_chooser_set_font_desc (GTK_FONT_CHOOSER (font_button->font_dialog), - font_button->font_desc); - - g_object_notify (G_OBJECT (font_button), "font"); - g_object_notify (G_OBJECT (font_button), "font-desc"); - - g_object_thaw_notify (object); -} - -static const PangoFontDescription * -gtk_font_button_get_font_desc (GtkFontButton *font_button) -{ - return font_button->font_desc; -} - -static void -gtk_font_button_font_chooser_set_font_map (GtkFontChooser *chooser, - PangoFontMap *font_map) -{ - GtkFontButton *font_button = GTK_FONT_BUTTON (chooser); - - if (g_set_object (&font_button->font_map, font_map)) - { - PangoContext *context; - - if (!font_map) - font_map = pango_cairo_font_map_get_default (); - - context = gtk_widget_get_pango_context (font_button->font_label); - pango_context_set_font_map (context, font_map); - if (font_button->font_dialog) - gtk_font_chooser_set_font_map (GTK_FONT_CHOOSER (font_button->font_dialog), font_map); - } -} - -static PangoFontMap * -gtk_font_button_font_chooser_get_font_map (GtkFontChooser *chooser) -{ - GtkFontButton *font_button = GTK_FONT_BUTTON (chooser); - - return font_button->font_map; -} - -static void -gtk_font_button_font_chooser_notify (GObject *object, - GParamSpec *pspec, - gpointer user_data) -{ - /* We do not forward the notification of the "font" property to the dialog! */ - if (pspec->name == I_("preview-text") || - pspec->name == I_("show-preview-entry")) - g_object_notify_by_pspec (user_data, pspec); -} - -static void -gtk_font_button_activate (GtkFontButton *self) -{ - gtk_widget_activate (self->button); -} - -static void -gtk_font_button_unrealize (GtkWidget *widget) -{ - GtkFontButton *font_button = GTK_FONT_BUTTON (widget); - - g_clear_pointer ((GtkWindow **) &font_button->font_dialog, gtk_window_destroy); - - GTK_WIDGET_CLASS (gtk_font_button_parent_class)->unrealize (widget); -} - -static void -gtk_font_button_class_init (GtkFontButtonClass *klass) -{ - GObjectClass *gobject_class; - GtkWidgetClass *widget_class; - - gobject_class = (GObjectClass *) klass; - widget_class = (GtkWidgetClass *) klass; - - gobject_class->finalize = gtk_font_button_finalize; - gobject_class->set_property = gtk_font_button_set_property; - gobject_class->get_property = gtk_font_button_get_property; - - widget_class->grab_focus = gtk_widget_grab_focus_child; - widget_class->focus = gtk_widget_focus_child; - widget_class->unrealize = gtk_font_button_unrealize; - - klass->font_set = NULL; - klass->activate = gtk_font_button_activate; - - _gtk_font_chooser_install_properties (gobject_class); - - /** - * GtkFontButton:title: (attributes org.gtk.Property.get=gtk_font_button_get_title org.gtk.Property.set=gtk_font_button_set_title) - * - * The title of the font chooser dialog. - */ - g_object_class_install_property (gobject_class, - PROP_TITLE, - g_param_spec_string ("title", NULL, NULL, - _("Pick a Font"), - GTK_PARAM_READWRITE)); - - /** - * GtkFontButton:use-font: (attributes org.gtk.Property.get=gtk_font_button_get_use_font org.gtk.Property.set=gtk_font_button_set_use_font) - * - * Whether the buttons label will be drawn in the selected font. - */ - g_object_class_install_property (gobject_class, - PROP_USE_FONT, - g_param_spec_boolean ("use-font", NULL, NULL, - FALSE, - GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); - - /** - * GtkFontButton:use-size: (attributes org.gtk.Property.get=gtk_font_button_get_use_size org.gtk.Property.set=gtk_font_button_set_use_size) - * - * Whether the buttons label will use the selected font size. - */ - g_object_class_install_property (gobject_class, - PROP_USE_SIZE, - g_param_spec_boolean ("use-size", NULL, NULL, - FALSE, - GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); - - /** - * GtkFontButton:modal: (attributes org.gtk.Property.get=gtk_font_button_get_modal org.gtk.Property.set=gtk_font_button_set_modal) - * - * Whether the font chooser dialog should be modal. - */ - g_object_class_install_property (gobject_class, - PROP_MODAL, - g_param_spec_boolean ("modal", NULL, NULL, - TRUE, - GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); - - /** - * GtkFontButton::font-set: - * @widget: the object which received the signal - * - * Emitted when the user selects a font. - * - * When handling this signal, use [method@Gtk.FontChooser.get_font] - * to find out which font was just selected. - * - * Note that this signal is only emitted when the user changes the font. - * If you need to react to programmatic font changes as well, use - * the notify::font signal. - */ - font_button_signals[FONT_SET] = g_signal_new (I_("font-set"), - G_TYPE_FROM_CLASS (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GtkFontButtonClass, font_set), - NULL, NULL, - NULL, - G_TYPE_NONE, 0); - - /** - * GtkFontButton::activate: - * @widget: the object which received the signal. - * - * Emitted to when the font button is activated. - * - * The `::activate` signal on `GtkFontButton` is an action signal and - * emitting it causes the button to present its dialog. - * - * Since: 4.4 - */ - font_button_signals[ACTIVATE] = - g_signal_new (I_ ("activate"), - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (GtkFontButtonClass, activate), - NULL, NULL, - NULL, - G_TYPE_NONE, 0); - - gtk_widget_class_set_activate_signal (widget_class, font_button_signals[ACTIVATE]); - - gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); - gtk_widget_class_set_css_name (widget_class, I_("fontbutton")); -} - -static void -gtk_font_button_init (GtkFontButton *font_button) -{ - GtkWidget *box; - - font_button->button = gtk_button_new (); - g_signal_connect (font_button->button, "clicked", G_CALLBACK (gtk_font_button_clicked), font_button); - font_button->font_label = gtk_label_new (_("Font")); - gtk_widget_set_hexpand (font_button->font_label, TRUE); - font_button->size_label = gtk_label_new ("14"); - font_button->font_size_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - - box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_append (GTK_BOX (box), font_button->font_label); - - gtk_box_append (GTK_BOX (font_button->font_size_box), gtk_separator_new (GTK_ORIENTATION_VERTICAL)); - gtk_box_append (GTK_BOX (font_button->font_size_box), font_button->size_label); - gtk_box_append (GTK_BOX (box), font_button->font_size_box); - - gtk_button_set_child (GTK_BUTTON (font_button->button), box); - gtk_widget_set_parent (font_button->button, GTK_WIDGET (font_button)); - - /* Initialize fields */ - font_button->modal = TRUE; - font_button->use_font = FALSE; - font_button->use_size = FALSE; - font_button->show_preview_entry = TRUE; - font_button->font_dialog = NULL; - font_button->font_family = NULL; - font_button->font_face = NULL; - font_button->font_size = -1; - font_button->title = g_strdup (_("Pick a Font")); - font_button->level = GTK_FONT_CHOOSER_LEVEL_FAMILY | - GTK_FONT_CHOOSER_LEVEL_STYLE | - GTK_FONT_CHOOSER_LEVEL_SIZE; - font_button->language = pango_language_get_default (); - - gtk_font_button_take_font_desc (font_button, NULL); - - gtk_widget_add_css_class (font_button->button, "font"); -} - -static void -gtk_font_button_finalize (GObject *object) -{ - GtkFontButton *font_button = GTK_FONT_BUTTON (object); - - g_free (font_button->title); - - clear_font_data (font_button); - clear_font_filter_data (font_button); - - g_free (font_button->preview_text); - - gtk_widget_unparent (font_button->button); - - G_OBJECT_CLASS (gtk_font_button_parent_class)->finalize (object); -} - -static void -gtk_font_button_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - GtkFontButton *font_button = GTK_FONT_BUTTON (object); - - switch (param_id) - { - case GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT: - gtk_font_button_set_preview_text (font_button, g_value_get_string (value)); - break; - case GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY: - gtk_font_button_set_show_preview_entry (font_button, g_value_get_boolean (value)); - break; - case PROP_TITLE: - gtk_font_button_set_title (font_button, g_value_get_string (value)); - break; - case PROP_MODAL: - gtk_font_button_set_modal (font_button, g_value_get_boolean (value)); - break; - case GTK_FONT_CHOOSER_PROP_FONT_DESC: - gtk_font_button_take_font_desc (font_button, g_value_dup_boxed (value)); - break; - case GTK_FONT_CHOOSER_PROP_LANGUAGE: - gtk_font_button_set_language (font_button, g_value_get_string (value)); - break; - case GTK_FONT_CHOOSER_PROP_LEVEL: - gtk_font_button_set_level (font_button, g_value_get_flags (value)); - break; - case GTK_FONT_CHOOSER_PROP_FONT: - gtk_font_button_set_font_name (font_button, g_value_get_string (value)); - break; - case PROP_USE_FONT: - gtk_font_button_set_use_font (font_button, g_value_get_boolean (value)); - break; - case PROP_USE_SIZE: - gtk_font_button_set_use_size (font_button, g_value_get_boolean (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - -static void -gtk_font_button_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - GtkFontButton *font_button = GTK_FONT_BUTTON (object); - - switch (param_id) - { - case GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT: - g_value_set_string (value, gtk_font_button_get_preview_text (font_button)); - break; - case GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY: - g_value_set_boolean (value, gtk_font_button_get_show_preview_entry (font_button)); - break; - case PROP_TITLE: - g_value_set_string (value, gtk_font_button_get_title (font_button)); - break; - case PROP_MODAL: - g_value_set_boolean (value, gtk_font_button_get_modal (font_button)); - break; - case GTK_FONT_CHOOSER_PROP_FONT_DESC: - g_value_set_boxed (value, gtk_font_button_get_font_desc (font_button)); - break; - case GTK_FONT_CHOOSER_PROP_FONT_FEATURES: - g_value_set_string (value, font_button->font_features); - break; - case GTK_FONT_CHOOSER_PROP_LANGUAGE: - g_value_set_string (value, pango_language_to_string (font_button->language)); - break; - case GTK_FONT_CHOOSER_PROP_LEVEL: - g_value_set_flags (value, font_button->level); - break; - case GTK_FONT_CHOOSER_PROP_FONT: - g_value_set_string (value, gtk_font_button_get_font_name (font_button)); - break; - case PROP_USE_FONT: - g_value_set_boolean (value, gtk_font_button_get_use_font (font_button)); - break; - case PROP_USE_SIZE: - g_value_set_boolean (value, gtk_font_button_get_use_size (font_button)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - - -/** - * gtk_font_button_new: - * - * Creates a new font picker widget. - * - * Returns: a new font picker widget. - */ -GtkWidget * -gtk_font_button_new (void) -{ - return g_object_new (GTK_TYPE_FONT_BUTTON, NULL); -} - -/** - * gtk_font_button_new_with_font: - * @fontname: Name of font to display in font chooser dialog - * - * Creates a new font picker widget showing the given font. - * - * Returns: a new font picker widget. - */ -GtkWidget * -gtk_font_button_new_with_font (const char *fontname) -{ - return g_object_new (GTK_TYPE_FONT_BUTTON, "font", fontname, NULL); -} - -/** - * gtk_font_button_set_title: (attributes org.gtk.Method.set_property=title) - * @font_button: a `GtkFontButton` - * @title: a string containing the font chooser dialog title - * - * Sets the title for the font chooser dialog. - */ -void -gtk_font_button_set_title (GtkFontButton *font_button, - const char *title) -{ - char *old_title; - g_return_if_fail (GTK_IS_FONT_BUTTON (font_button)); - - old_title = font_button->title; - font_button->title = g_strdup (title); - g_free (old_title); - - if (font_button->font_dialog) - gtk_window_set_title (GTK_WINDOW (font_button->font_dialog), font_button->title); - - g_object_notify (G_OBJECT (font_button), "title"); -} - -/** - * gtk_font_button_get_title: (attributes org.gtk.Method.get_property=title) - * @font_button: a `GtkFontButton` - * - * Retrieves the title of the font chooser dialog. - * - * Returns: an internal copy of the title string - * which must not be freed. - */ -const char * -gtk_font_button_get_title (GtkFontButton *font_button) -{ - g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), NULL); - - return font_button->title; -} - -/** - * gtk_font_button_set_modal: (attributes org.gtk.Method.set_property=modal) - * @font_button: a `GtkFontButton` - * @modal: %TRUE to make the dialog modal - * - * Sets whether the dialog should be modal. - */ -void -gtk_font_button_set_modal (GtkFontButton *font_button, - gboolean modal) -{ - g_return_if_fail (GTK_IS_FONT_BUTTON (font_button)); - - if (font_button->modal == modal) - return; - - font_button->modal = modal; - - if (font_button->font_dialog) - gtk_window_set_modal (GTK_WINDOW (font_button->font_dialog), font_button->modal); - - g_object_notify (G_OBJECT (font_button), "modal"); -} - -/** - * gtk_font_button_get_modal: (attributes org.gtk.Method.get_property=modal) - * @font_button: a `GtkFontButton` - * - * Gets whether the dialog is modal. - * - * Returns: %TRUE if the dialog is modal - */ -gboolean -gtk_font_button_get_modal (GtkFontButton *font_button) -{ - g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), FALSE); - - return font_button->modal; -} - -/** - * gtk_font_button_get_use_font: (attributes org.gtk.Method.get_property=use-font) - * @font_button: a `GtkFontButton` - * - * Returns whether the selected font is used in the label. - * - * Returns: whether the selected font is used in the label. - */ -gboolean -gtk_font_button_get_use_font (GtkFontButton *font_button) -{ - g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), FALSE); - - return font_button->use_font; -} - -/** - * gtk_font_button_set_use_font: (attributes org.gtk.Method.set_property=use-font) - * @font_button: a `GtkFontButton` - * @use_font: If %TRUE, font name will be written using font chosen. - * - * If @use_font is %TRUE, the font name will be written - * using the selected font. - */ -void -gtk_font_button_set_use_font (GtkFontButton *font_button, - gboolean use_font) -{ - g_return_if_fail (GTK_IS_FONT_BUTTON (font_button)); - - use_font = (use_font != FALSE); - - if (font_button->use_font != use_font) - { - font_button->use_font = use_font; - - gtk_font_button_label_use_font (font_button); - - g_object_notify (G_OBJECT (font_button), "use-font"); - } -} - - -/** - * gtk_font_button_get_use_size: (attributes org.gtk.Method.get_property=use-size) - * @font_button: a `GtkFontButton` - * - * Returns whether the selected size is used in the label. - * - * Returns: whether the selected size is used in the label. - */ -gboolean -gtk_font_button_get_use_size (GtkFontButton *font_button) -{ - g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), FALSE); - - return font_button->use_size; -} - -/** - * gtk_font_button_set_use_size: (attributes org.gtk.Method.set_property=use-size) - * @font_button: a `GtkFontButton` - * @use_size: If %TRUE, font name will be written using the - * selected size. - * - * If @use_size is %TRUE, the font name will be written using - * the selected size. - */ -void -gtk_font_button_set_use_size (GtkFontButton *font_button, - gboolean use_size) -{ - g_return_if_fail (GTK_IS_FONT_BUTTON (font_button)); - - use_size = (use_size != FALSE); - if (font_button->use_size != use_size) - { - font_button->use_size = use_size; - - gtk_font_button_label_use_font (font_button); - - g_object_notify (G_OBJECT (font_button), "use-size"); - } -} - -static const char * -gtk_font_button_get_font_name (GtkFontButton *font_button) -{ - g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), NULL); - - return font_button->fontname; -} - -static void -gtk_font_button_set_font_name (GtkFontButton *font_button, - const char *fontname) -{ - PangoFontDescription *font_desc; - - font_desc = pango_font_description_from_string (fontname); - gtk_font_button_take_font_desc (font_button, font_desc); -} - -static void -gtk_font_button_clicked (GtkButton *button, - gpointer user_data) -{ - GtkFontChooser *font_dialog; - GtkFontButton *font_button = user_data; - - if (!font_button->font_dialog) - { - GtkWidget *parent; - - parent = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (font_button))); - - font_button->font_dialog = gtk_font_chooser_dialog_new (font_button->title, NULL); - gtk_window_set_hide_on_close (GTK_WINDOW (font_button->font_dialog), TRUE); - gtk_window_set_modal (GTK_WINDOW (font_button->font_dialog), font_button->modal); - gtk_window_set_display (GTK_WINDOW (font_button->font_dialog), gtk_widget_get_display (GTK_WIDGET (button))); - - font_dialog = GTK_FONT_CHOOSER (font_button->font_dialog); - - if (font_button->font_map) - gtk_font_chooser_set_font_map (font_dialog, font_button->font_map); - - gtk_font_chooser_set_show_preview_entry (font_dialog, font_button->show_preview_entry); - gtk_font_chooser_set_level (GTK_FONT_CHOOSER (font_dialog), font_button->level); - gtk_font_chooser_set_language (GTK_FONT_CHOOSER (font_dialog), pango_language_to_string (font_button->language)); - - if (font_button->preview_text) - { - gtk_font_chooser_set_preview_text (font_dialog, font_button->preview_text); - g_free (font_button->preview_text); - font_button->preview_text = NULL; - } - - if (font_button->font_filter) - { - gtk_font_chooser_set_filter_func (font_dialog, - font_button->font_filter, - font_button->font_filter_data, - font_button->font_filter_data_destroy); - font_button->font_filter = NULL; - font_button->font_filter_data = NULL; - font_button->font_filter_data_destroy = NULL; - } - - if (GTK_IS_WINDOW (parent)) - { - if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (font_dialog))) - gtk_window_set_transient_for (GTK_WINDOW (font_dialog), GTK_WINDOW (parent)); - - if (gtk_window_get_modal (GTK_WINDOW (parent))) - gtk_window_set_modal (GTK_WINDOW (font_dialog), TRUE); - } - - g_signal_connect (font_dialog, "notify", - G_CALLBACK (gtk_font_button_font_chooser_notify), button); - - g_signal_connect (font_dialog, "response", - G_CALLBACK (response_cb), font_button); - - g_signal_connect (font_dialog, "destroy", - G_CALLBACK (dialog_destroy), font_button); - } - - if (!gtk_widget_get_visible (font_button->font_dialog)) - { - font_dialog = GTK_FONT_CHOOSER (font_button->font_dialog); - gtk_font_chooser_set_font_desc (font_dialog, font_button->font_desc); - } - - gtk_window_present (GTK_WINDOW (font_button->font_dialog)); -} - - -static void -response_cb (GtkDialog *dialog, - int response_id, - gpointer data) -{ - GtkFontButton *font_button = GTK_FONT_BUTTON (data); - GtkFontChooser *font_chooser; - GObject *object; - - gtk_widget_hide (font_button->font_dialog); - - if (response_id != GTK_RESPONSE_OK) - return; - - font_chooser = GTK_FONT_CHOOSER (font_button->font_dialog); - object = G_OBJECT (font_chooser); - - g_object_freeze_notify (object); - - clear_font_data (font_button); - - font_button->font_desc = gtk_font_chooser_get_font_desc (font_chooser); - if (font_button->font_desc) - font_button->fontname = pango_font_description_to_string (font_button->font_desc); - font_button->font_family = gtk_font_chooser_get_font_family (font_chooser); - if (font_button->font_family) - g_object_ref (font_button->font_family); - font_button->font_face = gtk_font_chooser_get_font_face (font_chooser); - if (font_button->font_face) - g_object_ref (font_button->font_face); - font_button->font_size = gtk_font_chooser_get_font_size (font_chooser); - g_free (font_button->font_features); - font_button->font_features = gtk_font_chooser_get_font_features (font_chooser); - font_button->language = pango_language_from_string (gtk_font_chooser_get_language (font_chooser)); - - /* Set label font */ - gtk_font_button_update_font_info (font_button); - - g_object_notify (G_OBJECT (font_button), "font"); - g_object_notify (G_OBJECT (font_button), "font-desc"); - g_object_notify (G_OBJECT (font_button), "font-features"); - - g_object_thaw_notify (object); - - /* Emit font_set signal */ - g_signal_emit (font_button, font_button_signals[FONT_SET], 0); -} - -static void -dialog_destroy (GtkWidget *widget, - gpointer data) -{ - GtkFontButton *font_button = GTK_FONT_BUTTON (data); - - /* Dialog will get destroyed so reference is not valid now */ - font_button->font_dialog = NULL; -} - -static void -gtk_font_button_label_use_font (GtkFontButton *font_button) -{ - if (!font_button->use_font) - gtk_label_set_attributes (GTK_LABEL (font_button->font_label), NULL); - else - { - PangoFontDescription *desc; - PangoAttrList *attrs; - - desc = pango_font_description_copy (font_button->font_desc); - - if (!font_button->use_size) - pango_font_description_unset_fields (desc, PANGO_FONT_MASK_SIZE); - - attrs = pango_attr_list_new (); - - /* Prevent font fallback */ - pango_attr_list_insert (attrs, pango_attr_fallback_new (FALSE)); - - /* Force current font and features */ - pango_attr_list_insert (attrs, pango_attr_font_desc_new (desc)); - if (font_button->font_features) - pango_attr_list_insert (attrs, pango_attr_font_features_new (font_button->font_features)); - if (font_button->language) - pango_attr_list_insert (attrs, pango_attr_language_new (font_button->language)); - - gtk_label_set_attributes (GTK_LABEL (font_button->font_label), attrs); - - pango_attr_list_unref (attrs); - pango_font_description_free (desc); - } -} - -static void -gtk_font_button_update_font_info (GtkFontButton *font_button) -{ - const char *fam_name; - const char *face_name; - char *family_style; - - if (font_button->font_family) - fam_name = pango_font_family_get_name (font_button->font_family); - else - fam_name = C_("font", "None"); - if (font_button->font_face) - face_name = pango_font_face_get_face_name (font_button->font_face); - else - face_name = ""; - - if ((font_button->level & GTK_FONT_CHOOSER_LEVEL_STYLE) != 0) - family_style = g_strconcat (fam_name, " ", face_name, NULL); - else - family_style = g_strdup (fam_name); - - gtk_label_set_text (GTK_LABEL (font_button->font_label), family_style); - g_free (family_style); - - if ((font_button->level & GTK_FONT_CHOOSER_LEVEL_SIZE) != 0) - { - /* mirror Pango, which doesn't translate this either */ - char *size = g_strdup_printf ("%2.4g%s", - pango_font_description_get_size (font_button->font_desc) / (double)PANGO_SCALE, - pango_font_description_get_size_is_absolute (font_button->font_desc) ? "px" : ""); - - gtk_label_set_text (GTK_LABEL (font_button->size_label), size); - - g_free (size); - - gtk_widget_show (font_button->font_size_box); - } - else - gtk_widget_hide (font_button->font_size_box); - - - gtk_font_button_label_use_font (font_button); -} - -static void -gtk_font_button_set_level (GtkFontButton *font_button, - GtkFontChooserLevel level) -{ - if (font_button->level == level) - return; - - font_button->level = level; - - if (font_button->font_dialog) - gtk_font_chooser_set_level (GTK_FONT_CHOOSER (font_button->font_dialog), level); - - gtk_font_button_update_font_info (font_button); - - g_object_notify (G_OBJECT (font_button), "level"); -} - -static void -gtk_font_button_set_language (GtkFontButton *font_button, - const char *language) -{ - font_button->language = pango_language_from_string (language); - - if (font_button->font_dialog) - gtk_font_chooser_set_language (GTK_FONT_CHOOSER (font_button->font_dialog), language); - - g_object_notify (G_OBJECT (font_button), "language"); -} diff --git a/gtk/gtkfontbutton.h b/gtk/gtkfontbutton.h deleted file mode 100644 index 58fc881f5b..0000000000 --- a/gtk/gtkfontbutton.h +++ /dev/null @@ -1,77 +0,0 @@ -/* GTK - The GIMP Toolkit - * Copyright (C) 1998 David Abilleira Freijeiro - * All rights reserved - * Based on gnome-color-picker by Federico Mena - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library. If not, see . - */ -/* - * Modified by the GTK+ Team and others 2003. 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/. - */ - -#ifndef __GTK_FONT_BUTTON_H__ -#define __GTK_FONT_BUTTON_H__ - -#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) -#error "Only can be included directly." -#endif - -#include - - -G_BEGIN_DECLS - -#define GTK_TYPE_FONT_BUTTON (gtk_font_button_get_type ()) -#define GTK_FONT_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FONT_BUTTON, GtkFontButton)) -#define GTK_IS_FONT_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FONT_BUTTON)) - -typedef struct _GtkFontButton GtkFontButton; - -GDK_AVAILABLE_IN_ALL -GType gtk_font_button_get_type (void) G_GNUC_CONST; -GDK_AVAILABLE_IN_ALL -GtkWidget *gtk_font_button_new (void); -GDK_AVAILABLE_IN_ALL -GtkWidget *gtk_font_button_new_with_font (const char *fontname); - -GDK_AVAILABLE_IN_ALL -const char * gtk_font_button_get_title (GtkFontButton *font_button); -GDK_AVAILABLE_IN_ALL -void gtk_font_button_set_title (GtkFontButton *font_button, - const char *title); -GDK_AVAILABLE_IN_ALL -gboolean gtk_font_button_get_modal (GtkFontButton *font_button); -GDK_AVAILABLE_IN_ALL -void gtk_font_button_set_modal (GtkFontButton *font_button, - gboolean modal); -GDK_AVAILABLE_IN_ALL -gboolean gtk_font_button_get_use_font (GtkFontButton *font_button); -GDK_AVAILABLE_IN_ALL -void gtk_font_button_set_use_font (GtkFontButton *font_button, - gboolean use_font); -GDK_AVAILABLE_IN_ALL -gboolean gtk_font_button_get_use_size (GtkFontButton *font_button); -GDK_AVAILABLE_IN_ALL -void gtk_font_button_set_use_size (GtkFontButton *font_button, - gboolean use_size); - -G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkFontButton, g_object_unref) - -G_END_DECLS - - -#endif /* __GTK_FONT_BUTTON_H__ */ diff --git a/gtk/gtkfontchooser.c b/gtk/gtkfontchooser.c deleted file mode 100644 index bf79f229c5..0000000000 --- a/gtk/gtkfontchooser.c +++ /dev/null @@ -1,578 +0,0 @@ -/* GTK - The GIMP Toolkit - * 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 . - */ - -#include "config.h" - -#include "gtkfontchooser.h" -#include "gtkfontchooserprivate.h" -#include "gtktypebuiltins.h" -#include "gtkprivate.h" - -/** - * GtkFontChooser: - * - * `GtkFontChooser` is an interface that can be implemented by widgets - * for choosing fonts. - * - * In GTK, the main objects that implement this interface are - * [class@Gtk.FontChooserWidget], [class@Gtk.FontChooserDialog] and - * [class@Gtk.FontButton]. - */ - -enum -{ - SIGNAL_FONT_ACTIVATED, - LAST_SIGNAL -}; - -static guint chooser_signals[LAST_SIGNAL]; - -typedef GtkFontChooserIface GtkFontChooserInterface; -G_DEFINE_INTERFACE (GtkFontChooser, gtk_font_chooser, G_TYPE_OBJECT); - -static void -gtk_font_chooser_default_init (GtkFontChooserInterface *iface) -{ - /** - * GtkFontChooser:font: (attributes org.gtk.Property.get=gtk_font_chooser_get_font org.gtk.Property.set=gtk_font_chooser_set_font) - * - * The font description as a string, e.g. "Sans Italic 12". - */ - g_object_interface_install_property - (iface, - g_param_spec_string ("font", NULL, NULL, - GTK_FONT_CHOOSER_DEFAULT_FONT_NAME, - GTK_PARAM_READWRITE)); - - /** - * GtkFontChooser:font-desc: (attributes org.gtk.Property.get=gtk_font_chooser_get_font_desc org.gtk.Property.set=gtk_font_chooser_set_font_desc) - * - * The font description as a `PangoFontDescription`. - */ - g_object_interface_install_property - (iface, - g_param_spec_boxed ("font-desc", NULL, NULL, - PANGO_TYPE_FONT_DESCRIPTION, - GTK_PARAM_READWRITE)); - - /** - * GtkFontChooser:preview-text: (attributes org.gtk.Property.get=gtk_font_chooser_get_preview_text org.gtk.Property.set=gtk_font_chooser_set_preview_text) - * - * The string with which to preview the font. - */ - g_object_interface_install_property - (iface, - g_param_spec_string ("preview-text", NULL, NULL, - pango_language_get_sample_string (NULL), - GTK_PARAM_READWRITE)); - - /** - * GtkFontChooser:show-preview-entry: (attributes org.gtk.Property.get=gtk_font_chooser_get_show_preview_entry org.gtk.Property.set=gtk_font_chooser_set_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", NULL, NULL, - TRUE, - GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); - - /** - * GtkFontChooser:level: (attributes org.gtk.Property.get=gtk_font_chooser_get_level org.gtk.Property.set=gtk_font_chooser_set_level) - * - * The level of granularity to offer for selecting fonts. - */ - g_object_interface_install_property - (iface, - g_param_spec_flags ("level", NULL, NULL, - GTK_TYPE_FONT_CHOOSER_LEVEL, - GTK_FONT_CHOOSER_LEVEL_FAMILY | - GTK_FONT_CHOOSER_LEVEL_STYLE | - GTK_FONT_CHOOSER_LEVEL_SIZE, - GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); - - /** - * GtkFontChooser:font-features: (attributes org.gtk.Property.get=gtk_font_chooser_get_font_features) - * - * The selected font features. - * - * The format of the string is compatible with - * CSS and with Pango attributes. - */ - g_object_interface_install_property - (iface, - g_param_spec_string ("font-features", NULL, NULL, - "", - GTK_PARAM_READABLE)); - - /** - * GtkFontChooser:language: (attributes org.gtk.Property.get=gtk_font_chooser_get_language org.gtk.Property.set=gtk_font_chooser_set_language) - * - * The language for which the font features were selected. - */ - g_object_interface_install_property - (iface, - g_param_spec_string ("language", NULL, NULL, - "", - GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); - - /** - * 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 (I_("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); -} - -/** - * 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. - * - * Returns: (nullable) (transfer none): A `PangoFontFamily` representing the - * selected font family - */ -PangoFontFamily * -gtk_font_chooser_get_font_family (GtkFontChooser *fontchooser) -{ - g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); - - return GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->get_font_family (fontchooser); -} - -/** - * 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. - * - * Returns: (nullable) (transfer none): A `PangoFontFace` representing the - * selected font group details - */ -PangoFontFace * -gtk_font_chooser_get_font_face (GtkFontChooser *fontchooser) -{ - g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); - - return GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->get_font_face (fontchooser); -} - -/** - * gtk_font_chooser_get_font_size: - * @fontchooser: a `GtkFontChooser` - * - * The selected font size. - * - * Returns: A n integer representing the selected font size, - * or -1 if no font size is selected. - */ -int -gtk_font_chooser_get_font_size (GtkFontChooser *fontchooser) -{ - g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), -1); - - return GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->get_font_size (fontchooser); -} - -/** - * gtk_font_chooser_get_font: (attributes org.gtk.Method.get_property=font) - * @fontchooser: a `GtkFontChooser` - * - * Gets the currently-selected font name. - * - * Note that this can be a different string than what you set with - * [method@Gtk.FontChooser.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”. - * - * Use [method@Pango.FontDescription.equal] if you want to compare two - * font descriptions. - * - * Returns: (nullable) (transfer full): A string with the name - * of the current font - */ -char * -gtk_font_chooser_get_font (GtkFontChooser *fontchooser) -{ - char *fontname; - - g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); - - g_object_get (fontchooser, "font", &fontname, NULL); - - - return fontname; -} - -/** - * gtk_font_chooser_set_font: (attributes org.gtk.Method.set_property=font) - * @fontchooser: a `GtkFontChooser` - * @fontname: a font name like “Helvetica 12” or “Times Bold 18” - * - * Sets the currently-selected font. - */ -void -gtk_font_chooser_set_font (GtkFontChooser *fontchooser, - const char *fontname) -{ - g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); - g_return_if_fail (fontname != NULL); - - g_object_set (fontchooser, "font", fontname, NULL); -} - -/** - * gtk_font_chooser_get_font_desc: (attributes org.gtk.Method.get_property=font-desc) - * @fontchooser: a `GtkFontChooser` - * - * Gets the currently-selected font. - * - * Note that this can be a different string than what you set with - * [method@Gtk.FontChooser.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”. - * - * Use [method@Pango.FontDescription.equal] if you want to compare two - * font descriptions. - * - * Returns: (nullable) (transfer full): A `PangoFontDescription` for the - * current font - */ -PangoFontDescription * -gtk_font_chooser_get_font_desc (GtkFontChooser *fontchooser) -{ - PangoFontDescription *font_desc; - - g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); - - g_object_get (fontchooser, "font-desc", &font_desc, NULL); - - return font_desc; -} - -/** - * gtk_font_chooser_set_font_desc: (attributes org.gtk.Method.set_property=font-desc) - * @fontchooser: a `GtkFontChooser` - * @font_desc: a `PangoFontDescription` - * - * Sets the currently-selected font from @font_desc. - */ -void -gtk_font_chooser_set_font_desc (GtkFontChooser *fontchooser, - const PangoFontDescription *font_desc) -{ - g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); - g_return_if_fail (font_desc != NULL); - - g_object_set (fontchooser, "font-desc", font_desc, NULL); -} - -/** - * gtk_font_chooser_get_preview_text: (attributes org.gtk.Method.get_property=preview-text) - * @fontchooser: a `GtkFontChooser` - * - * Gets the text displayed in the preview area. - * - * Returns: (transfer full): the text displayed in the preview area - */ -char * -gtk_font_chooser_get_preview_text (GtkFontChooser *fontchooser) -{ - char *text; - - g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); - - g_object_get (fontchooser, "preview-text", &text, NULL); - - return text; -} - -/** - * gtk_font_chooser_set_preview_text: (attributes org.gtk.Method.set_property=preview-text) - * @fontchooser: a `GtkFontChooser` - * @text: (transfer none): the text to display in the preview area - * - * Sets the text displayed in the preview area. - * - * The @text is used to show how the selected font looks. - */ -void -gtk_font_chooser_set_preview_text (GtkFontChooser *fontchooser, - const char *text) -{ - g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); - g_return_if_fail (text != NULL); - - g_object_set (fontchooser, "preview-text", text, NULL); -} - -/** - * gtk_font_chooser_get_show_preview_entry: (attributes org.gtk.Method.get_property=show-preview-entry) - * @fontchooser: a `GtkFontChooser` - * - * Returns whether the preview entry is shown or not. - * - * Returns: %TRUE if the preview entry is shown or %FALSE if it is hidden. - */ -gboolean -gtk_font_chooser_get_show_preview_entry (GtkFontChooser *fontchooser) -{ - gboolean show; - - g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), FALSE); - - g_object_get (fontchooser, "show-preview-entry", &show, NULL); - - return show; -} - -/** - * gtk_font_chooser_set_show_preview_entry: (attributes org.gtk.Method.set_property=show-preview-entry) - * @fontchooser: a `GtkFontChooser` - * @show_preview_entry: whether to show the editable preview entry or not - * - * Shows or hides the editable preview entry. - */ -void -gtk_font_chooser_set_show_preview_entry (GtkFontChooser *fontchooser, - gboolean show_preview_entry) -{ - g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); - - show_preview_entry = show_preview_entry != FALSE; - g_object_set (fontchooser, "show-preview-entry", show_preview_entry, NULL); -} - -/** - * gtk_font_chooser_set_filter_func: - * @fontchooser: a `GtkFontChooser` - * @filter: (nullable): a `GtkFontFilterFunc` - * @user_data: (closure): data to pass to @filter - * @destroy: function to call to free @data when it is no longer needed - * - * Adds a filter function that decides which fonts to display - * in the font chooser. - */ -void -gtk_font_chooser_set_filter_func (GtkFontChooser *fontchooser, - GtkFontFilterFunc filter, - gpointer user_data, - GDestroyNotify destroy) -{ - g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); - - GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->set_filter_func (fontchooser, - filter, - user_data, - destroy); -} - -void -_gtk_font_chooser_font_activated (GtkFontChooser *chooser, - const char *fontname) -{ - g_return_if_fail (GTK_IS_FONT_CHOOSER (chooser)); - - g_signal_emit (chooser, chooser_signals[SIGNAL_FONT_ACTIVATED], 0, fontname); -} - -/** - * gtk_font_chooser_set_font_map: - * @fontchooser: a `GtkFontChooser` - * @fontmap: (nullable): a `PangoFontMap` - * - * Sets a custom font map to use for this font chooser widget. - * - * A custom font map can be used to present application-specific - * fonts instead of or in addition to the normal system fonts. - * - * ```c - * FcConfig *config; - * PangoFontMap *fontmap; - * - * config = FcInitLoadConfigAndFonts (); - * FcConfigAppFontAddFile (config, my_app_font_file); - * - * fontmap = pango_cairo_font_map_new_for_font_type (CAIRO_FONT_TYPE_FT); - * pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (fontmap), config); - * - * gtk_font_chooser_set_font_map (font_chooser, fontmap); - * ``` - * - * Note that other GTK widgets will only be able to use the - * application-specific font if it is present in the font map they use: - * - * ```c - * context = gtk_widget_get_pango_context (label); - * pango_context_set_font_map (context, fontmap); - * ``` - */ -void -gtk_font_chooser_set_font_map (GtkFontChooser *fontchooser, - PangoFontMap *fontmap) -{ - g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); - g_return_if_fail (fontmap == NULL || PANGO_IS_FONT_MAP (fontmap)); - - if (GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->set_font_map) - GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->set_font_map (fontchooser, fontmap); -} - -/** - * gtk_font_chooser_get_font_map: - * @fontchooser: a `GtkFontChooser` - * - * Gets the custom font map of this font chooser widget, - * or %NULL if it does not have one. - * - * Returns: (nullable) (transfer full): a `PangoFontMap` - */ -PangoFontMap * -gtk_font_chooser_get_font_map (GtkFontChooser *fontchooser) -{ - PangoFontMap *fontmap = NULL; - - g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); - - if (GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->get_font_map) - fontmap = GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->get_font_map (fontchooser); - - return fontmap; -} - -/** - * gtk_font_chooser_set_level: (attributes org.gtk.Method.set_property=level) - * @fontchooser: a `GtkFontChooser` - * @level: the desired level of granularity - * - * Sets the desired level of granularity for selecting fonts. - */ -void -gtk_font_chooser_set_level (GtkFontChooser *fontchooser, - GtkFontChooserLevel level) -{ - g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); - - g_object_set (fontchooser, "level", level, NULL); -} - -/** - * gtk_font_chooser_get_level: (attributes org.gtk.Method.get_property=level) - * @fontchooser: a `GtkFontChooser` - * - * Returns the current level of granularity for selecting fonts. - * - * Returns: the current granularity level - */ -GtkFontChooserLevel -gtk_font_chooser_get_level (GtkFontChooser *fontchooser) -{ - GtkFontChooserLevel level; - - g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), 0); - - g_object_get (fontchooser, "level", &level, NULL); - - return level; -} - -/** - * gtk_font_chooser_get_font_features: (attributes org.gtk.Method.get_property=font-features) - * @fontchooser: a `GtkFontChooser` - * - * Gets the currently-selected font features. - * - * The format of the returned string is compatible with the - * [CSS font-feature-settings property](https://www.w3.org/TR/css-fonts-4/#font-rend-desc). - * It can be passed to [func@Pango.AttrFontFeatures.new]. - * - * Returns: the currently selected font features - */ -char * -gtk_font_chooser_get_font_features (GtkFontChooser *fontchooser) -{ - char *text; - - g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); - - g_object_get (fontchooser, "font-features", &text, NULL); - - return text; -} - -/** - * gtk_font_chooser_get_language: (attributes org.gtk.Method.get_property=language) - * @fontchooser: a `GtkFontChooser` - * - * Gets the language that is used for font features. - * - * Returns: the currently selected language - */ -char * -gtk_font_chooser_get_language (GtkFontChooser *fontchooser) -{ - char *text; - - g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL); - - g_object_get (fontchooser, "language", &text, NULL); - - return text; -} - -/** - * gtk_font_chooser_set_language: (attributes org.gtk.Method.set_property=language) - * @fontchooser: a `GtkFontChooser` - * @language: a language - * - * Sets the language to use for font features. - */ -void -gtk_font_chooser_set_language (GtkFontChooser *fontchooser, - const char *language) -{ - g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser)); - - g_object_set (fontchooser, "language", language, NULL); -} diff --git a/gtk/gtkfontchooser.h b/gtk/gtkfontchooser.h deleted file mode 100644 index 95aa518b3f..0000000000 --- a/gtk/gtkfontchooser.h +++ /dev/null @@ -1,168 +0,0 @@ -/* GTK - The GIMP Toolkit - * gtkfontchooser.h - 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 . - */ - -#ifndef __GTK_FONT_CHOOSER_H__ -#define __GTK_FONT_CHOOSER_H__ - -#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) -#error "Only can be included directly." -#endif - -#include - -G_BEGIN_DECLS - -/** - * GtkFontFilterFunc: - * @family: a `PangoFontFamily` - * @face: a `PangoFontFace` belonging to @family - * @data: (closure): user data passed to gtk_font_chooser_set_filter_func() - * - * The type of function that is used for deciding what fonts get - * shown in a `GtkFontChooser`. - * - * See [method@Gtk.FontChooser.set_filter_func]. - * - * Returns: %TRUE if the font should be displayed - */ -typedef gboolean (*GtkFontFilterFunc) (const PangoFontFamily *family, - const PangoFontFace *face, - gpointer data); - -/** - * GtkFontChooserLevel: - * @GTK_FONT_CHOOSER_LEVEL_FAMILY: Allow selecting a font family - * @GTK_FONT_CHOOSER_LEVEL_STYLE: Allow selecting a specific font face - * @GTK_FONT_CHOOSER_LEVEL_SIZE: Allow selecting a specific font size - * @GTK_FONT_CHOOSER_LEVEL_VARIATIONS: Allow changing OpenType font variation axes - * @GTK_FONT_CHOOSER_LEVEL_FEATURES: Allow selecting specific OpenType font features - * - * Specifies the granularity of font selection - * that is desired in a `GtkFontChooser`. - * - * This enumeration may be extended in the future; applications should - * ignore unknown values. - */ -typedef enum { - GTK_FONT_CHOOSER_LEVEL_FAMILY = 0, - GTK_FONT_CHOOSER_LEVEL_STYLE = 1 << 0, - GTK_FONT_CHOOSER_LEVEL_SIZE = 1 << 1, - GTK_FONT_CHOOSER_LEVEL_VARIATIONS = 1 << 2, - GTK_FONT_CHOOSER_LEVEL_FEATURES = 1 << 3 -} GtkFontChooserLevel; - -#define GTK_TYPE_FONT_CHOOSER (gtk_font_chooser_get_type ()) -#define GTK_FONT_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FONT_CHOOSER, GtkFontChooser)) -#define GTK_IS_FONT_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FONT_CHOOSER)) -#define GTK_FONT_CHOOSER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FONT_CHOOSER, GtkFontChooserIface)) - -typedef struct _GtkFontChooser GtkFontChooser; /* dummy */ -typedef struct _GtkFontChooserIface GtkFontChooserIface; - -struct _GtkFontChooserIface -{ - GTypeInterface base_iface; - - /* Methods */ - PangoFontFamily * (* get_font_family) (GtkFontChooser *fontchooser); - PangoFontFace * (* get_font_face) (GtkFontChooser *fontchooser); - int (* get_font_size) (GtkFontChooser *fontchooser); - - void (* set_filter_func) (GtkFontChooser *fontchooser, - GtkFontFilterFunc filter, - gpointer user_data, - GDestroyNotify destroy); - - /* Signals */ - void (* font_activated) (GtkFontChooser *chooser, - const char *fontname); - - /* More methods */ - void (* set_font_map) (GtkFontChooser *fontchooser, - PangoFontMap *fontmap); - PangoFontMap * (* get_font_map) (GtkFontChooser *fontchooser); - - /*< private >*/ - /* Padding; remove in GTK-next */ - gpointer padding[10]; -}; - -GDK_AVAILABLE_IN_ALL -GType gtk_font_chooser_get_type (void) G_GNUC_CONST; - -GDK_AVAILABLE_IN_ALL -PangoFontFamily *gtk_font_chooser_get_font_family (GtkFontChooser *fontchooser); -GDK_AVAILABLE_IN_ALL -PangoFontFace *gtk_font_chooser_get_font_face (GtkFontChooser *fontchooser); -GDK_AVAILABLE_IN_ALL -int gtk_font_chooser_get_font_size (GtkFontChooser *fontchooser); - -GDK_AVAILABLE_IN_ALL -PangoFontDescription * - gtk_font_chooser_get_font_desc (GtkFontChooser *fontchooser); -GDK_AVAILABLE_IN_ALL -void gtk_font_chooser_set_font_desc (GtkFontChooser *fontchooser, - const PangoFontDescription *font_desc); - -GDK_AVAILABLE_IN_ALL -char * gtk_font_chooser_get_font (GtkFontChooser *fontchooser); - -GDK_AVAILABLE_IN_ALL -void gtk_font_chooser_set_font (GtkFontChooser *fontchooser, - const char *fontname); -GDK_AVAILABLE_IN_ALL -char * gtk_font_chooser_get_preview_text (GtkFontChooser *fontchooser); -GDK_AVAILABLE_IN_ALL -void gtk_font_chooser_set_preview_text (GtkFontChooser *fontchooser, - const char *text); -GDK_AVAILABLE_IN_ALL -gboolean gtk_font_chooser_get_show_preview_entry (GtkFontChooser *fontchooser); -GDK_AVAILABLE_IN_ALL -void gtk_font_chooser_set_show_preview_entry (GtkFontChooser *fontchooser, - gboolean show_preview_entry); -GDK_AVAILABLE_IN_ALL -void gtk_font_chooser_set_filter_func (GtkFontChooser *fontchooser, - GtkFontFilterFunc filter, - gpointer user_data, - GDestroyNotify destroy); -GDK_AVAILABLE_IN_ALL -void gtk_font_chooser_set_font_map (GtkFontChooser *fontchooser, - PangoFontMap *fontmap); -GDK_AVAILABLE_IN_ALL -PangoFontMap * gtk_font_chooser_get_font_map (GtkFontChooser *fontchooser); -GDK_AVAILABLE_IN_ALL -void gtk_font_chooser_set_level (GtkFontChooser *fontchooser, - GtkFontChooserLevel level); -GDK_AVAILABLE_IN_ALL -GtkFontChooserLevel - gtk_font_chooser_get_level (GtkFontChooser *fontchooser); -GDK_AVAILABLE_IN_ALL -char * gtk_font_chooser_get_font_features (GtkFontChooser *fontchooser); -GDK_AVAILABLE_IN_ALL -char * gtk_font_chooser_get_language (GtkFontChooser *fontchooser); -GDK_AVAILABLE_IN_ALL -void gtk_font_chooser_set_language (GtkFontChooser *fontchooser, - const char *language); - -G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkFontChooser, g_object_unref) - -G_END_DECLS - -#endif /* __GTK_FONT_CHOOSER_H__ */ diff --git a/gtk/gtkfontchooserdialog.c b/gtk/gtkfontchooserdialog.c index c10c214bb2..fc640ce540 100644 --- a/gtk/gtkfontchooserdialog.c +++ b/gtk/gtkfontchooserdialog.c @@ -22,8 +22,8 @@ #include #include "gtkfontchooserdialogprivate.h" -#include "gtkfontchooser.h" -#include "gtkfontchooserwidget.h" +#include "deprecated/gtkfontchooser.h" +#include "deprecated/gtkfontchooserwidget.h" #include "gtkfontchooserwidgetprivate.h" #include "gtkfontchooserutils.h" #include "gtkbox.h" @@ -38,6 +38,8 @@ #include "gtkactionable.h" #include "gtkeventcontrollerkey.h" +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + typedef struct _GtkFontChooserDialogClass GtkFontChooserDialogClass; struct _GtkFontChooserDialog @@ -72,6 +74,8 @@ struct _GtkFontChooserDialogClass * The `GtkFontChooserDialog` implementation of the `GtkBuildable` * interface exposes the buttons with the names “select_button” * and “cancel_button”. + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] instead */ static void gtk_font_chooser_dialog_buildable_interface_init (GtkBuildableIface *iface); @@ -288,6 +292,8 @@ gtk_font_chooser_dialog_init (GtkFontChooserDialog *dialog) * Creates a new `GtkFontChooserDialog`. * * Returns: a new `GtkFontChooserDialog` + * + * Deprecated: 4.10: Use [class@Gtk.FontDialog] instead */ GtkWidget* gtk_font_chooser_dialog_new (const char *title, diff --git a/gtk/gtkfontchooserdialog.h b/gtk/gtkfontchooserdialog.h deleted file mode 100644 index b14ee81c2d..0000000000 --- a/gtk/gtkfontchooserdialog.h +++ /dev/null @@ -1,45 +0,0 @@ -/* GTK - The GIMP Toolkit - * 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 . - */ - -#ifndef __GTK_FONT_CHOOSER_DIALOG_H__ -#define __GTK_FONT_CHOOSER_DIALOG_H__ - -#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) -#error "Only can be included directly." -#endif - -#include - -G_BEGIN_DECLS - -#define GTK_TYPE_FONT_CHOOSER_DIALOG (gtk_font_chooser_dialog_get_type ()) -#define GTK_FONT_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FONT_CHOOSER_DIALOG, GtkFontChooserDialog)) -#define GTK_IS_FONT_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FONT_CHOOSER_DIALOG)) - -typedef struct _GtkFontChooserDialog GtkFontChooserDialog; - -GDK_AVAILABLE_IN_ALL -GType gtk_font_chooser_dialog_get_type (void) G_GNUC_CONST; -GDK_AVAILABLE_IN_ALL -GtkWidget* gtk_font_chooser_dialog_new (const char *title, - GtkWindow *parent); - -G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkFontChooserDialog, g_object_unref) - -G_END_DECLS - -#endif /* __GTK_FONT_CHOOSER_DIALOG_H__ */ diff --git a/gtk/gtkfontchooserdialogprivate.h b/gtk/gtkfontchooserdialogprivate.h index e57685e9ec..5020714a58 100644 --- a/gtk/gtkfontchooserdialogprivate.h +++ b/gtk/gtkfontchooserdialogprivate.h @@ -18,7 +18,7 @@ #ifndef __GTK_FONT_CHOOSER_DIALOG_PRIVATE_H__ #define __GTK_FONT_CHOOSER_DIALOG_PRIVATE_H__ -#include "gtkfontchooserdialog.h" +#include "deprecated/gtkfontchooserdialog.h" #include "gtkfilter.h" G_BEGIN_DECLS diff --git a/gtk/gtkfontchooserprivate.h b/gtk/gtkfontchooserprivate.h deleted file mode 100644 index 480351ead2..0000000000 --- a/gtk/gtkfontchooserprivate.h +++ /dev/null @@ -1,35 +0,0 @@ -/* gtkfontprivatechooser.h - Interface definitions for font selectors UI - * - * Copyright (C) 2006 Emmanuele Bassi - * - * All rights reserved - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library. If not, see . - */ - -#ifndef __GTK_FONT_CHOOSER_PRIVATE_H__ -#define __GTK_FONT_CHOOSER_PRIVATE_H__ - -#include "gtkfontchooser.h" - -#define GTK_FONT_CHOOSER_DEFAULT_FONT_NAME "Sans 10" - -G_BEGIN_DECLS - -void _gtk_font_chooser_font_activated (GtkFontChooser *chooser, - const char *fontname); - -G_END_DECLS - -#endif /* ! __GTK_FONT_CHOOSER_PRIVATE_H__ */ diff --git a/gtk/gtkfontchooserutils.c b/gtk/gtkfontchooserutils.c index 6dd2a3fd9d..d0d70bd7cb 100644 --- a/gtk/gtkfontchooserutils.c +++ b/gtk/gtkfontchooserutils.c @@ -26,6 +26,8 @@ #include "gtkfontchooserutils.h" +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + static GtkFontChooser * get_delegate (GtkFontChooser *receiver) { diff --git a/gtk/gtkfontchooserutils.h b/gtk/gtkfontchooserutils.h index ac7bf18558..7ddade5126 100644 --- a/gtk/gtkfontchooserutils.h +++ b/gtk/gtkfontchooserutils.h @@ -25,7 +25,7 @@ #ifndef __GTK_FONT_CHOOSER_UTILS_H__ #define __GTK_FONT_CHOOSER_UTILS_H__ -#include "gtkfontchooserprivate.h" +#include "deprecated/gtkfontchooserprivate.h" G_BEGIN_DECLS diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c index dcacae2e10..fb73a5376a 100644 --- a/gtk/gtkfontchooserwidget.c +++ b/gtk/gtkfontchooserwidget.c @@ -21,7 +21,7 @@ #include #include -#include "gtkfontchooserwidget.h" +#include "deprecated/gtkfontchooserwidget.h" #include "gtkfontchooserwidgetprivate.h" #include "gtkadjustment.h" @@ -34,7 +34,7 @@ #include "gtkfilter.h" #include "gtkframe.h" #include "gtkgrid.h" -#include "gtkfontchooser.h" +#include "deprecated/gtkfontchooser.h" #include "gtkfontchooserutils.h" #include #include "gtklabel.h" @@ -70,6 +70,8 @@ #include "language-names.h" #include "open-type-layout.h" +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + /** * GtkFontChooserWidget: * @@ -90,6 +92,8 @@ * # CSS nodes * * `GtkFontChooserWidget` has a single CSS node with name fontchooser. + * + * Deprecated: 4.10: Direct use of `GtkFontChooserWidget` is deprecated. */ typedef struct _GtkFontChooserWidgetClass GtkFontChooserWidgetClass; @@ -1299,6 +1303,8 @@ gtk_font_chooser_widget_init (GtkFontChooserWidget *self) * Creates a new `GtkFontChooserWidget`. * * Returns: a new `GtkFontChooserWidget` + * + * Deprecated: 4.10: Direct use of `GtkFontChooserWidget` is deprecated. */ GtkWidget * gtk_font_chooser_widget_new (void) diff --git a/gtk/gtkfontchooserwidget.h b/gtk/gtkfontchooserwidget.h deleted file mode 100644 index d3f668049b..0000000000 --- a/gtk/gtkfontchooserwidget.h +++ /dev/null @@ -1,45 +0,0 @@ -/* GTK - The GIMP Toolkit - * 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 . - */ - -#ifndef __GTK_FONT_CHOOSER_WIDGET_H__ -#define __GTK_FONT_CHOOSER_WIDGET_H__ - -#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) -#error "Only can be included directly." -#endif - -#include - -G_BEGIN_DECLS - -#define GTK_TYPE_FONT_CHOOSER_WIDGET (gtk_font_chooser_widget_get_type ()) -#define GTK_FONT_CHOOSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FONT_CHOOSER_WIDGET, GtkFontChooserWidget)) -#define GTK_IS_FONT_CHOOSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FONT_CHOOSER_WIDGET)) - -typedef struct _GtkFontChooserWidget GtkFontChooserWidget; - -GDK_AVAILABLE_IN_ALL -GType gtk_font_chooser_widget_get_type (void) G_GNUC_CONST; - -GDK_AVAILABLE_IN_ALL -GtkWidget* gtk_font_chooser_widget_new (void); - -G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkFontChooserWidget, g_object_unref) - -G_END_DECLS - -#endif /* __GTK_FONT_CHOOSER_WIDGET_H__ */ diff --git a/gtk/gtkfontchooserwidgetprivate.h b/gtk/gtkfontchooserwidgetprivate.h index ac8e7dc7c0..80d1400c58 100644 --- a/gtk/gtkfontchooserwidgetprivate.h +++ b/gtk/gtkfontchooserwidgetprivate.h @@ -18,7 +18,7 @@ #ifndef __GTK_FONT_CHOOSER_WIDGET_PRIVATE_H__ #define __GTK_FONT_CHOOSER_WIDGET_PRIVATE_H__ -#include "gtkfontchooserwidget.h" +#include "deprecated/gtkfontchooserwidget.h" #include "gtkfilter.h" G_BEGIN_DECLS diff --git a/gtk/gtkfontdialog.c b/gtk/gtkfontdialog.c index bcbdc9371e..44d8757159 100644 --- a/gtk/gtkfontdialog.c +++ b/gtk/gtkfontdialog.c @@ -21,7 +21,7 @@ #include "gtkfontdialog.h" -#include "gtkfontchooser.h" +#include "deprecated/gtkfontchooser.h" #include "gtkfontchooserdialogprivate.h" #include "gtkbutton.h" #include "gtkdialogerror.h" @@ -502,6 +502,7 @@ typedef struct PangoLanguage *language; } FontResult; +G_GNUC_BEGIN_IGNORE_DEPRECATIONS static void response_cb (GTask *task, int response) @@ -568,6 +569,7 @@ response_cb (GTask *task, g_object_unref (task); } +G_GNUC_END_IGNORE_DEPRECATIONS static void dialog_response (GtkDialog *dialog, @@ -577,6 +579,7 @@ dialog_response (GtkDialog *dialog, response_cb (task, response); } +G_GNUC_BEGIN_IGNORE_DEPRECATIONS static GtkWidget * create_font_chooser (GtkFontDialog *self, GtkWindow *parent, @@ -605,6 +608,7 @@ create_font_chooser (GtkFontDialog *self, return window; } +G_GNUC_END_IGNORE_DEPRECATIONS /* }}} */ /* {{{ Async API */ diff --git a/gtk/meson.build b/gtk/meson.build index d5849712d6..7b294cbaa4 100644 --- a/gtk/meson.build +++ b/gtk/meson.build @@ -235,8 +235,6 @@ gtk_public_sources = files([ 'gtkfixedlayout.c', 'gtkflattenlistmodel.c', 'gtkflowbox.c', - 'gtkfontbutton.c', - 'gtkfontchooser.c', 'gtkfontchooserdialog.c', 'gtkfontchooserutils.c', 'gtkfontchooserwidget.c', @@ -494,10 +492,6 @@ gtk_public_headers = files([ 'gtkfixedlayout.h', 'gtkflattenlistmodel.h', 'gtkflowbox.h', - 'gtkfontbutton.h', - 'gtkfontchooser.h', - 'gtkfontchooserdialog.h', - 'gtkfontchooserwidget.h', 'gtkfontdialog.h', 'gtkfontdialogbutton.h', 'gtkframe.h', diff --git a/tests/testfontchooserdialog.c b/tests/testfontchooserdialog.c index 0ff1f389ad..78b70969c7 100644 --- a/tests/testfontchooserdialog.c +++ b/tests/testfontchooserdialog.c @@ -24,6 +24,8 @@ #include +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + static gboolean monospace_filter (const PangoFontFamily *family, const PangoFontFace *face,