2011-05-11 20:52:39 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2011 Alberto Ruiz <aruiz@gnome.org>
|
|
|
|
*
|
|
|
|
* 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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2011-05-11 20:52:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <glib/gprintf.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2022-10-29 03:58:50 +00:00
|
|
|
#include "gtkfontchooserdialogprivate.h"
|
2022-10-27 02:58:21 +00:00
|
|
|
#include "deprecated/gtkfontchooser.h"
|
|
|
|
#include "deprecated/gtkfontchooserwidget.h"
|
2017-12-27 22:21:30 +00:00
|
|
|
#include "gtkfontchooserwidgetprivate.h"
|
2011-09-11 23:49:26 +00:00
|
|
|
#include "gtkfontchooserutils.h"
|
|
|
|
#include "gtkbox.h"
|
2022-09-24 13:07:56 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2011-05-11 20:52:39 +00:00
|
|
|
#include "gtkbuildable.h"
|
|
|
|
#include "gtkprivate.h"
|
|
|
|
#include "gtkwidget.h"
|
2013-12-08 14:09:46 +00:00
|
|
|
#include "gtksettings.h"
|
|
|
|
#include "gtkdialogprivate.h"
|
2018-01-03 03:52:05 +00:00
|
|
|
#include "gtktogglebutton.h"
|
|
|
|
#include "gtkheaderbar.h"
|
|
|
|
#include "gtkactionable.h"
|
2018-06-06 22:49:04 +00:00
|
|
|
#include "gtkeventcontrollerkey.h"
|
2011-05-11 20:52:39 +00:00
|
|
|
|
2022-10-27 02:58:21 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
2020-04-26 19:26:50 +00:00
|
|
|
typedef struct _GtkFontChooserDialogClass GtkFontChooserDialogClass;
|
2019-05-28 00:57:47 +00:00
|
|
|
|
|
|
|
struct _GtkFontChooserDialog
|
|
|
|
{
|
|
|
|
GtkDialog parent_instance;
|
|
|
|
|
2011-05-11 20:52:39 +00:00
|
|
|
GtkWidget *fontchooser;
|
|
|
|
GtkWidget *select_button;
|
|
|
|
GtkWidget *cancel_button;
|
2018-01-03 03:52:05 +00:00
|
|
|
GtkWidget *tweak_button;
|
2011-05-11 20:52:39 +00:00
|
|
|
};
|
|
|
|
|
2020-04-26 19:26:50 +00:00
|
|
|
struct _GtkFontChooserDialogClass
|
|
|
|
{
|
|
|
|
GtkDialogClass parent_class;
|
|
|
|
};
|
|
|
|
|
2011-05-11 20:52:39 +00:00
|
|
|
/**
|
2021-02-26 21:11:15 +00:00
|
|
|
* GtkFontChooserDialog:
|
2011-05-11 20:52:39 +00:00
|
|
|
*
|
2021-02-26 21:11:15 +00:00
|
|
|
* The `GtkFontChooserDialog` widget is a dialog for selecting a font.
|
|
|
|
*
|
|
|
|
* ![An example GtkFontChooserDialog](fontchooser.png)
|
|
|
|
*
|
|
|
|
* `GtkFontChooserDialog` implements the [iface@Gtk.FontChooser] interface
|
|
|
|
* and does not provide much API of its own.
|
|
|
|
*
|
|
|
|
* To create a `GtkFontChooserDialog`, use [ctor@Gtk.FontChooserDialog.new].
|
2011-05-11 20:52:39 +00:00
|
|
|
*
|
2014-02-05 02:00:58 +00:00
|
|
|
* # GtkFontChooserDialog as GtkBuildable
|
2014-02-02 05:29:00 +00:00
|
|
|
*
|
2021-02-26 21:11:15 +00:00
|
|
|
* The `GtkFontChooserDialog` implementation of the `GtkBuildable`
|
2014-02-05 18:07:34 +00:00
|
|
|
* interface exposes the buttons with the names “select_button”
|
|
|
|
* and “cancel_button”.
|
2022-10-27 02:58:21 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 4.10: Use [class@Gtk.FontDialog] instead
|
2011-05-11 20:52:39 +00:00
|
|
|
*/
|
|
|
|
|
2011-08-08 22:10:00 +00:00
|
|
|
static void gtk_font_chooser_dialog_buildable_interface_init (GtkBuildableIface *iface);
|
|
|
|
static GObject *gtk_font_chooser_dialog_buildable_get_internal_child (GtkBuildable *buildable,
|
2011-05-11 20:52:39 +00:00
|
|
|
GtkBuilder *builder,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *childname);
|
2011-05-11 20:52:39 +00:00
|
|
|
|
2011-08-08 22:10:00 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkFontChooserDialog, gtk_font_chooser_dialog, GTK_TYPE_DIALOG,
|
2011-09-11 23:49:26 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_FONT_CHOOSER,
|
|
|
|
_gtk_font_chooser_delegate_iface_init)
|
2011-05-11 20:52:39 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
2011-09-11 23:49:26 +00:00
|
|
|
gtk_font_chooser_dialog_buildable_interface_init))
|
2011-05-11 20:52:39 +00:00
|
|
|
|
|
|
|
static GtkBuildableIface *parent_buildable_iface;
|
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_dialog_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkFontChooserDialog *dialog = GTK_FONT_CHOOSER_DIALOG (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
default:
|
2020-04-26 19:26:50 +00:00
|
|
|
g_object_set_property (G_OBJECT (dialog->fontchooser), pspec->name, value);
|
2011-09-11 23:49:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_dialog_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkFontChooserDialog *dialog = GTK_FONT_CHOOSER_DIALOG (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
default:
|
2020-04-26 19:26:50 +00:00
|
|
|
g_object_get_property (G_OBJECT (dialog->fontchooser), pspec->name, value);
|
2011-09-11 23:49:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-26 10:13:12 +00:00
|
|
|
static void
|
|
|
|
font_activated_cb (GtkFontChooser *fontchooser,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *fontname,
|
2013-03-26 10:13:12 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkDialog *dialog = user_data;
|
|
|
|
|
|
|
|
gtk_dialog_response (dialog, GTK_RESPONSE_OK);
|
|
|
|
}
|
|
|
|
|
2017-12-27 22:21:30 +00:00
|
|
|
static gboolean
|
2018-06-06 22:49:04 +00:00
|
|
|
dialog_forward_key (GtkEventControllerKey *controller,
|
|
|
|
guint keyval,
|
|
|
|
guint keycode,
|
|
|
|
GdkModifierType modifiers,
|
|
|
|
GtkWidget *widget)
|
2017-12-27 22:21:30 +00:00
|
|
|
{
|
2019-05-28 02:37:41 +00:00
|
|
|
GtkFontChooserDialog *dialog = GTK_FONT_CHOOSER_DIALOG (widget);
|
2017-12-27 22:21:30 +00:00
|
|
|
|
2020-04-26 19:26:50 +00:00
|
|
|
return gtk_event_controller_key_forward (controller, dialog->fontchooser);
|
2017-12-27 22:21:30 +00:00
|
|
|
}
|
|
|
|
|
2018-03-31 22:57:06 +00:00
|
|
|
static void
|
|
|
|
update_tweak_button (GtkFontChooserDialog *dialog)
|
|
|
|
{
|
|
|
|
GtkFontChooserLevel level;
|
|
|
|
|
2020-04-26 19:26:50 +00:00
|
|
|
if (!dialog->tweak_button)
|
2018-03-31 22:57:06 +00:00
|
|
|
return;
|
|
|
|
|
2020-04-26 19:26:50 +00:00
|
|
|
g_object_get (dialog->fontchooser, "level", &level, NULL);
|
2018-03-31 22:57:06 +00:00
|
|
|
if ((level & (GTK_FONT_CHOOSER_LEVEL_FEATURES | GTK_FONT_CHOOSER_LEVEL_VARIATIONS)) != 0)
|
2020-04-26 19:26:50 +00:00
|
|
|
gtk_widget_show (dialog->tweak_button);
|
2018-03-31 22:57:06 +00:00
|
|
|
else
|
2020-04-26 19:26:50 +00:00
|
|
|
gtk_widget_hide (dialog->tweak_button);
|
2018-03-31 22:57:06 +00:00
|
|
|
}
|
|
|
|
|
2018-01-03 03:52:05 +00:00
|
|
|
static void
|
|
|
|
setup_tweak_button (GtkFontChooserDialog *dialog)
|
|
|
|
{
|
|
|
|
gboolean use_header;
|
|
|
|
|
2020-04-26 19:26:50 +00:00
|
|
|
if (dialog->tweak_button)
|
2018-01-03 03:52:05 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
g_object_get (dialog, "use-header-bar", &use_header, NULL);
|
|
|
|
if (use_header)
|
|
|
|
{
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *header;
|
|
|
|
GActionGroup *actions;
|
|
|
|
|
|
|
|
actions = G_ACTION_GROUP (g_simple_action_group_new ());
|
2020-04-26 19:26:50 +00:00
|
|
|
g_action_map_add_action (G_ACTION_MAP (actions), gtk_font_chooser_widget_get_tweak_action (dialog->fontchooser));
|
2018-01-03 03:52:05 +00:00
|
|
|
gtk_widget_insert_action_group (GTK_WIDGET (dialog), "font", actions);
|
|
|
|
g_object_unref (actions);
|
|
|
|
|
|
|
|
button = gtk_toggle_button_new ();
|
|
|
|
gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "font.tweak");
|
|
|
|
gtk_widget_set_focus_on_click (button, FALSE);
|
|
|
|
gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
|
|
|
|
gtk_button_set_icon_name (GTK_BUTTON (button), "emblem-system-symbolic");
|
2022-08-29 16:13:32 +00:00
|
|
|
gtk_widget_set_tooltip_text (button, _("Change Font Features"));
|
2018-01-03 03:52:05 +00:00
|
|
|
|
|
|
|
header = gtk_dialog_get_header_bar (GTK_DIALOG (dialog));
|
|
|
|
gtk_header_bar_pack_end (GTK_HEADER_BAR (header), button);
|
|
|
|
|
2020-04-26 19:26:50 +00:00
|
|
|
dialog->tweak_button = button;
|
2020-09-20 14:55:54 +00:00
|
|
|
|
|
|
|
update_tweak_button (dialog);
|
2018-01-03 03:52:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_dialog_map (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkFontChooserDialog *dialog = GTK_FONT_CHOOSER_DIALOG (widget);
|
|
|
|
|
|
|
|
setup_tweak_button (dialog);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_font_chooser_dialog_parent_class)->map (widget);
|
|
|
|
}
|
|
|
|
|
2020-05-09 18:10:38 +00:00
|
|
|
static void
|
|
|
|
update_button (GtkFontChooserDialog *dialog)
|
|
|
|
{
|
|
|
|
PangoFontDescription *desc;
|
|
|
|
|
|
|
|
desc = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (dialog->fontchooser));
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (dialog->select_button, desc != NULL);
|
|
|
|
|
|
|
|
if (desc)
|
|
|
|
pango_font_description_free (desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_dialog_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkFontChooserDialog *dialog = GTK_FONT_CHOOSER_DIALOG (object);
|
|
|
|
|
|
|
|
if (dialog->fontchooser)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (dialog->fontchooser,
|
|
|
|
update_button,
|
|
|
|
dialog);
|
|
|
|
g_signal_handlers_disconnect_by_func (dialog->fontchooser,
|
|
|
|
update_tweak_button,
|
|
|
|
dialog);
|
|
|
|
}
|
|
|
|
|
2022-07-07 12:59:18 +00:00
|
|
|
/* tweak_button is not a template child */
|
2020-05-09 18:10:38 +00:00
|
|
|
g_clear_pointer (&dialog->tweak_button, gtk_widget_unparent);
|
2022-07-07 12:59:18 +00:00
|
|
|
|
2022-07-07 13:09:35 +00:00
|
|
|
gtk_widget_dispose_template (GTK_WIDGET (dialog), GTK_TYPE_FONT_CHOOSER_DIALOG);
|
2020-05-09 18:10:38 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_font_chooser_dialog_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2011-05-11 20:52:39 +00:00
|
|
|
static void
|
|
|
|
gtk_font_chooser_dialog_class_init (GtkFontChooserDialogClass *klass)
|
|
|
|
{
|
2011-09-11 23:49:26 +00:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2013-03-26 10:13:12 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2011-09-11 23:49:26 +00:00
|
|
|
|
2020-05-09 18:10:38 +00:00
|
|
|
gobject_class->dispose = gtk_font_chooser_dialog_dispose;
|
2011-09-11 23:49:26 +00:00
|
|
|
gobject_class->get_property = gtk_font_chooser_dialog_get_property;
|
|
|
|
gobject_class->set_property = gtk_font_chooser_dialog_set_property;
|
|
|
|
|
2018-01-03 03:52:05 +00:00
|
|
|
widget_class->map = gtk_font_chooser_dialog_map;
|
2017-12-27 22:21:30 +00:00
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
_gtk_font_chooser_install_properties (gobject_class);
|
|
|
|
|
2013-03-26 10:13:12 +00:00
|
|
|
/* Bind class to template
|
|
|
|
*/
|
|
|
|
gtk_widget_class_set_template_from_resource (widget_class,
|
2018-04-02 17:34:22 +00:00
|
|
|
"/org/gtk/libgtk/ui/gtkfontchooserdialog.ui");
|
2011-05-11 20:52:39 +00:00
|
|
|
|
2020-04-26 19:26:50 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserDialog, fontchooser);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserDialog, select_button);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFontChooserDialog, cancel_button);
|
2013-07-26 17:49:49 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, font_activated_cb);
|
2018-06-06 22:49:04 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, dialog_forward_key);
|
2011-08-24 04:49:59 +00:00
|
|
|
}
|
|
|
|
|
2011-05-11 20:52:39 +00:00
|
|
|
static void
|
2020-04-26 19:26:50 +00:00
|
|
|
gtk_font_chooser_dialog_init (GtkFontChooserDialog *dialog)
|
2011-05-11 20:52:39 +00:00
|
|
|
{
|
2020-04-26 19:26:50 +00:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (dialog));
|
|
|
|
gtk_dialog_set_use_header_bar_from_setting (GTK_DIALOG (dialog));
|
2014-07-09 23:43:20 +00:00
|
|
|
|
2020-04-26 19:26:50 +00:00
|
|
|
_gtk_font_chooser_set_delegate (GTK_FONT_CHOOSER (dialog),
|
|
|
|
GTK_FONT_CHOOSER (dialog->fontchooser));
|
2018-01-03 03:52:05 +00:00
|
|
|
|
2020-04-26 19:26:50 +00:00
|
|
|
g_signal_connect_swapped (dialog->fontchooser, "notify::font-desc",
|
|
|
|
G_CALLBACK (update_button), dialog);
|
|
|
|
update_button (dialog);
|
|
|
|
g_signal_connect_swapped (dialog->fontchooser, "notify::level",
|
|
|
|
G_CALLBACK (update_tweak_button), dialog);
|
2011-05-11 20:52:39 +00:00
|
|
|
}
|
|
|
|
|
2011-12-16 03:55:06 +00:00
|
|
|
/**
|
|
|
|
* gtk_font_chooser_dialog_new:
|
2021-05-21 00:45:06 +00:00
|
|
|
* @title: (nullable): Title of the dialog
|
|
|
|
* @parent: (nullable): Transient parent of the dialog
|
2011-05-11 20:52:39 +00:00
|
|
|
*
|
2021-02-26 21:11:15 +00:00
|
|
|
* Creates a new `GtkFontChooserDialog`.
|
2011-05-11 20:52:39 +00:00
|
|
|
*
|
2021-02-26 21:11:15 +00:00
|
|
|
* Returns: a new `GtkFontChooserDialog`
|
2022-10-27 02:58:21 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 4.10: Use [class@Gtk.FontDialog] instead
|
2011-05-11 20:52:39 +00:00
|
|
|
*/
|
|
|
|
GtkWidget*
|
2020-07-24 18:40:36 +00:00
|
|
|
gtk_font_chooser_dialog_new (const char *title,
|
2011-07-25 16:14:49 +00:00
|
|
|
GtkWindow *parent)
|
2011-05-11 20:52:39 +00:00
|
|
|
{
|
2011-07-25 15:08:23 +00:00
|
|
|
GtkFontChooserDialog *dialog;
|
|
|
|
|
2011-07-25 16:14:49 +00:00
|
|
|
dialog = g_object_new (GTK_TYPE_FONT_CHOOSER_DIALOG,
|
|
|
|
"title", title,
|
|
|
|
"transient-for", parent,
|
|
|
|
NULL);
|
2011-07-25 15:08:23 +00:00
|
|
|
|
|
|
|
return GTK_WIDGET (dialog);
|
2011-05-11 20:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_font_chooser_dialog_buildable_interface_init (GtkBuildableIface *iface)
|
|
|
|
{
|
|
|
|
parent_buildable_iface = g_type_interface_peek_parent (iface);
|
|
|
|
iface->get_internal_child = gtk_font_chooser_dialog_buildable_get_internal_child;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GObject *
|
|
|
|
gtk_font_chooser_dialog_buildable_get_internal_child (GtkBuildable *buildable,
|
2011-08-08 22:10:00 +00:00
|
|
|
GtkBuilder *builder,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *childname)
|
2011-05-11 20:52:39 +00:00
|
|
|
{
|
2019-05-28 02:37:41 +00:00
|
|
|
GtkFontChooserDialog *dialog = GTK_FONT_CHOOSER_DIALOG (buildable);
|
2011-05-11 20:52:39 +00:00
|
|
|
|
|
|
|
if (g_strcmp0 (childname, "select_button") == 0)
|
2020-04-26 19:26:50 +00:00
|
|
|
return G_OBJECT (dialog->select_button);
|
2011-05-11 20:52:39 +00:00
|
|
|
else if (g_strcmp0 (childname, "cancel_button") == 0)
|
2020-04-26 19:26:50 +00:00
|
|
|
return G_OBJECT (dialog->cancel_button);
|
2011-05-11 20:52:39 +00:00
|
|
|
|
|
|
|
return parent_buildable_iface->get_internal_child (buildable, builder, childname);
|
|
|
|
}
|
2022-10-29 03:58:50 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gtk_font_chooser_dialog_set_filter (GtkFontChooserDialog *dialog,
|
|
|
|
GtkFilter *filter)
|
|
|
|
{
|
|
|
|
gtk_font_chooser_widget_set_filter (GTK_FONT_CHOOSER_WIDGET (dialog->fontchooser), filter);
|
|
|
|
}
|