2011-09-11 23:49:26 +00:00
|
|
|
|
/* gtkfontchooserutils.h - Private utility functions for implementing a
|
|
|
|
|
* GtkFontChooser interface
|
|
|
|
|
*
|
|
|
|
|
* 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
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2011-09-11 23:49:26 +00:00
|
|
|
|
*
|
|
|
|
|
* Based on gtkfilechooserutils.c:
|
|
|
|
|
* Copyright (C) 2003 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include "gtkfontchooserutils.h"
|
|
|
|
|
|
|
|
|
|
static GtkFontChooser *
|
|
|
|
|
get_delegate (GtkFontChooser *receiver)
|
|
|
|
|
{
|
|
|
|
|
return g_object_get_qdata (G_OBJECT (receiver),
|
|
|
|
|
GTK_FONT_CHOOSER_DELEGATE_QUARK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PangoFontFamily *
|
|
|
|
|
delegate_get_font_family (GtkFontChooser *chooser)
|
|
|
|
|
{
|
2011-09-11 22:17:58 +00:00
|
|
|
|
return gtk_font_chooser_get_font_family (get_delegate (chooser));
|
2011-09-11 23:49:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PangoFontFace *
|
|
|
|
|
delegate_get_font_face (GtkFontChooser *chooser)
|
|
|
|
|
{
|
2011-09-11 22:17:58 +00:00
|
|
|
|
return gtk_font_chooser_get_font_face (get_delegate (chooser));
|
2011-09-11 23:49:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
delegate_get_font_size (GtkFontChooser *chooser)
|
|
|
|
|
{
|
2011-09-11 22:17:58 +00:00
|
|
|
|
return gtk_font_chooser_get_font_size (get_delegate (chooser));
|
2011-09-11 23:49:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
delegate_set_filter_func (GtkFontChooser *chooser,
|
|
|
|
|
GtkFontFilterFunc filter_func,
|
|
|
|
|
gpointer filter_data,
|
|
|
|
|
GDestroyNotify data_destroy)
|
|
|
|
|
{
|
|
|
|
|
gtk_font_chooser_set_filter_func (get_delegate (chooser),
|
|
|
|
|
filter_func,
|
|
|
|
|
filter_data,
|
|
|
|
|
data_destroy);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-13 03:55:30 +00:00
|
|
|
|
static void
|
|
|
|
|
delegate_set_font_map (GtkFontChooser *chooser,
|
|
|
|
|
PangoFontMap *map)
|
|
|
|
|
{
|
|
|
|
|
gtk_font_chooser_set_font_map (get_delegate (chooser), map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PangoFontMap *
|
|
|
|
|
delegate_get_font_map (GtkFontChooser *chooser)
|
|
|
|
|
{
|
|
|
|
|
return gtk_font_chooser_get_font_map (get_delegate (chooser));
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-11 23:49:26 +00:00
|
|
|
|
static void
|
|
|
|
|
delegate_notify (GObject *object,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
gpointer iface;
|
|
|
|
|
|
|
|
|
|
iface = g_type_interface_peek (g_type_class_peek (G_OBJECT_TYPE (object)),
|
|
|
|
|
GTK_TYPE_FONT_CHOOSER);
|
|
|
|
|
if (g_object_interface_find_property (iface, pspec->name))
|
|
|
|
|
g_object_notify_by_pspec (user_data, pspec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
delegate_font_activated (GtkFontChooser *receiver,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *fontname,
|
2011-09-11 23:49:26 +00:00
|
|
|
|
GtkFontChooser *delegate)
|
|
|
|
|
{
|
|
|
|
|
_gtk_font_chooser_font_activated (delegate, fontname);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GQuark
|
|
|
|
|
_gtk_font_chooser_delegate_get_quark (void)
|
|
|
|
|
{
|
|
|
|
|
static GQuark quark = 0;
|
|
|
|
|
|
|
|
|
|
if (G_UNLIKELY (quark == 0))
|
|
|
|
|
quark = g_quark_from_static_string ("gtk-font-chooser-delegate");
|
|
|
|
|
|
|
|
|
|
return quark;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* _gtk_font_chooser_install_properties:
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @klass: the class structure for a type deriving from `GObject`
|
2011-09-11 23:49:26 +00:00
|
|
|
|
*
|
|
|
|
|
* Installs the necessary properties for a class implementing
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* `GtkFontChooser`.
|
|
|
|
|
*
|
|
|
|
|
* A `GtkParamSpecOverride` property is installed for each property,
|
|
|
|
|
* using the values from the `GtkFontChooserProp` enumeration. The
|
|
|
|
|
* caller must make sure itself that the enumeration values don’t
|
|
|
|
|
* collide with some other property values they are using.
|
2011-09-11 23:49:26 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
_gtk_font_chooser_install_properties (GObjectClass *klass)
|
|
|
|
|
{
|
|
|
|
|
g_object_class_override_property (klass,
|
2011-09-05 11:26:49 +00:00
|
|
|
|
GTK_FONT_CHOOSER_PROP_FONT,
|
|
|
|
|
"font");
|
2011-09-11 22:13:26 +00:00
|
|
|
|
g_object_class_override_property (klass,
|
|
|
|
|
GTK_FONT_CHOOSER_PROP_FONT_DESC,
|
|
|
|
|
"font-desc");
|
2011-09-11 23:49:26 +00:00
|
|
|
|
g_object_class_override_property (klass,
|
|
|
|
|
GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT,
|
|
|
|
|
"preview-text");
|
|
|
|
|
g_object_class_override_property (klass,
|
|
|
|
|
GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY,
|
|
|
|
|
"show-preview-entry");
|
2017-12-21 15:51:04 +00:00
|
|
|
|
g_object_class_override_property (klass,
|
|
|
|
|
GTK_FONT_CHOOSER_PROP_LEVEL,
|
|
|
|
|
"level");
|
2018-01-03 04:52:24 +00:00
|
|
|
|
g_object_class_override_property (klass,
|
|
|
|
|
GTK_FONT_CHOOSER_PROP_FONT_FEATURES,
|
|
|
|
|
"font-features");
|
|
|
|
|
g_object_class_override_property (klass,
|
|
|
|
|
GTK_FONT_CHOOSER_PROP_LANGUAGE,
|
|
|
|
|
"language");
|
2011-09-11 23:49:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* _gtk_font_chooser_delegate_iface_init:
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @iface: a `GtkFontChooserIface`
|
2011-09-11 23:49:26 +00:00
|
|
|
|
*
|
|
|
|
|
* An interface-initialization function for use in cases where
|
|
|
|
|
* an object is simply delegating the methods, signals of
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* the `GtkFontChooser` interface to another object.
|
2011-09-11 23:49:26 +00:00
|
|
|
|
* _gtk_font_chooser_set_delegate() must be called on each
|
|
|
|
|
* instance of the object so that the delegate object can
|
|
|
|
|
* be found.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
_gtk_font_chooser_delegate_iface_init (GtkFontChooserIface *iface)
|
|
|
|
|
{
|
|
|
|
|
iface->get_font_family = delegate_get_font_family;
|
|
|
|
|
iface->get_font_face = delegate_get_font_face;
|
|
|
|
|
iface->get_font_size = delegate_get_font_size;
|
|
|
|
|
iface->set_filter_func = delegate_set_filter_func;
|
2015-06-13 03:55:30 +00:00
|
|
|
|
iface->set_font_map = delegate_set_font_map;
|
|
|
|
|
iface->get_font_map = delegate_get_font_map;
|
2011-09-11 23:49:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* _gtk_font_chooser_set_delegate:
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @receiver: a `GObject` implementing `GtkFontChooser`
|
|
|
|
|
* @delegate: another `GObject` implementing `GtkFontChooser`
|
2011-09-11 23:49:26 +00:00
|
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* Establishes that calls on @receiver for `GtkFontChooser`
|
2011-09-11 23:49:26 +00:00
|
|
|
|
* methods should be delegated to @delegate, and that
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* `GtkFontChooser` signals emitted on @delegate should be
|
2011-09-11 23:49:26 +00:00
|
|
|
|
* forwarded to @receiver. Must be used in conjunction with
|
|
|
|
|
* _gtk_font_chooser_delegate_iface_init().
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
_gtk_font_chooser_set_delegate (GtkFontChooser *receiver,
|
|
|
|
|
GtkFontChooser *delegate)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_FONT_CHOOSER (receiver));
|
|
|
|
|
g_return_if_fail (GTK_IS_FONT_CHOOSER (delegate));
|
|
|
|
|
|
|
|
|
|
g_object_set_qdata (G_OBJECT (receiver),
|
|
|
|
|
GTK_FONT_CHOOSER_DELEGATE_QUARK,
|
|
|
|
|
delegate);
|
|
|
|
|
|
|
|
|
|
g_signal_connect (delegate, "notify",
|
|
|
|
|
G_CALLBACK (delegate_notify), receiver);
|
|
|
|
|
g_signal_connect (delegate, "font-activated",
|
|
|
|
|
G_CALLBACK (delegate_font_activated), receiver);
|
|
|
|
|
}
|