1/* gtkfontchooserutils.h - Private utility functions for implementing a
2 * GtkFontChooser interface
3 *
4 * Copyright (C) 2006 Emmanuele Bassi
5 *
6 * All rights reserved
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * Based on gtkfilechooserutils.c:
22 * Copyright (C) 2003 Red Hat, Inc.
23 */
24
25#include "config.h"
26
27#include "gtkfontchooserutils.h"
28
29static GtkFontChooser *
30get_delegate (GtkFontChooser *receiver)
31{
32 return g_object_get_qdata (G_OBJECT (receiver),
33 GTK_FONT_CHOOSER_DELEGATE_QUARK);
34}
35
36static PangoFontFamily *
37delegate_get_font_family (GtkFontChooser *chooser)
38{
39 return gtk_font_chooser_get_font_family (fontchooser: get_delegate (receiver: chooser));
40}
41
42static PangoFontFace *
43delegate_get_font_face (GtkFontChooser *chooser)
44{
45 return gtk_font_chooser_get_font_face (fontchooser: get_delegate (receiver: chooser));
46}
47
48static int
49delegate_get_font_size (GtkFontChooser *chooser)
50{
51 return gtk_font_chooser_get_font_size (fontchooser: get_delegate (receiver: chooser));
52}
53
54static void
55delegate_set_filter_func (GtkFontChooser *chooser,
56 GtkFontFilterFunc filter_func,
57 gpointer filter_data,
58 GDestroyNotify data_destroy)
59{
60 gtk_font_chooser_set_filter_func (fontchooser: get_delegate (receiver: chooser),
61 filter: filter_func,
62 user_data: filter_data,
63 destroy: data_destroy);
64}
65
66static void
67delegate_set_font_map (GtkFontChooser *chooser,
68 PangoFontMap *map)
69{
70 gtk_font_chooser_set_font_map (fontchooser: get_delegate (receiver: chooser), fontmap: map);
71}
72
73static PangoFontMap *
74delegate_get_font_map (GtkFontChooser *chooser)
75{
76 return gtk_font_chooser_get_font_map (fontchooser: get_delegate (receiver: chooser));
77}
78
79static void
80delegate_notify (GObject *object,
81 GParamSpec *pspec,
82 gpointer user_data)
83{
84 gpointer iface;
85
86 iface = g_type_interface_peek (instance_class: g_type_class_peek (G_OBJECT_TYPE (object)),
87 GTK_TYPE_FONT_CHOOSER);
88 if (g_object_interface_find_property (g_iface: iface, property_name: pspec->name))
89 g_object_notify_by_pspec (object: user_data, pspec);
90}
91
92static void
93delegate_font_activated (GtkFontChooser *receiver,
94 const char *fontname,
95 GtkFontChooser *delegate)
96{
97 _gtk_font_chooser_font_activated (chooser: delegate, fontname);
98}
99
100GQuark
101_gtk_font_chooser_delegate_get_quark (void)
102{
103 static GQuark quark = 0;
104
105 if (G_UNLIKELY (quark == 0))
106 quark = g_quark_from_static_string (string: "gtk-font-chooser-delegate");
107
108 return quark;
109}
110
111/**
112 * _gtk_font_chooser_install_properties:
113 * @klass: the class structure for a type deriving from `GObject`
114 *
115 * Installs the necessary properties for a class implementing
116 * `GtkFontChooser`.
117 *
118 * A `GtkParamSpecOverride` property is installed for each property,
119 * using the values from the `GtkFontChooserProp` enumeration. The
120 * caller must make sure itself that the enumeration values don’t
121 * collide with some other property values they are using.
122 */
123void
124_gtk_font_chooser_install_properties (GObjectClass *klass)
125{
126 g_object_class_override_property (oclass: klass,
127 property_id: GTK_FONT_CHOOSER_PROP_FONT,
128 name: "font");
129 g_object_class_override_property (oclass: klass,
130 property_id: GTK_FONT_CHOOSER_PROP_FONT_DESC,
131 name: "font-desc");
132 g_object_class_override_property (oclass: klass,
133 property_id: GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT,
134 name: "preview-text");
135 g_object_class_override_property (oclass: klass,
136 property_id: GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY,
137 name: "show-preview-entry");
138 g_object_class_override_property (oclass: klass,
139 property_id: GTK_FONT_CHOOSER_PROP_LEVEL,
140 name: "level");
141 g_object_class_override_property (oclass: klass,
142 property_id: GTK_FONT_CHOOSER_PROP_FONT_FEATURES,
143 name: "font-features");
144 g_object_class_override_property (oclass: klass,
145 property_id: GTK_FONT_CHOOSER_PROP_LANGUAGE,
146 name: "language");
147}
148
149/**
150 * _gtk_font_chooser_delegate_iface_init:
151 * @iface: a `GtkFontChooserIface`
152 *
153 * An interface-initialization function for use in cases where
154 * an object is simply delegating the methods, signals of
155 * the `GtkFontChooser` interface to another object.
156 * _gtk_font_chooser_set_delegate() must be called on each
157 * instance of the object so that the delegate object can
158 * be found.
159 */
160void
161_gtk_font_chooser_delegate_iface_init (GtkFontChooserIface *iface)
162{
163 iface->get_font_family = delegate_get_font_family;
164 iface->get_font_face = delegate_get_font_face;
165 iface->get_font_size = delegate_get_font_size;
166 iface->set_filter_func = delegate_set_filter_func;
167 iface->set_font_map = delegate_set_font_map;
168 iface->get_font_map = delegate_get_font_map;
169}
170
171/**
172 * _gtk_font_chooser_set_delegate:
173 * @receiver: a `GObject` implementing `GtkFontChooser`
174 * @delegate: another `GObject` implementing `GtkFontChooser`
175 *
176 * Establishes that calls on @receiver for `GtkFontChooser`
177 * methods should be delegated to @delegate, and that
178 * `GtkFontChooser` signals emitted on @delegate should be
179 * forwarded to @receiver. Must be used in conjunction with
180 * _gtk_font_chooser_delegate_iface_init().
181 */
182void
183_gtk_font_chooser_set_delegate (GtkFontChooser *receiver,
184 GtkFontChooser *delegate)
185{
186 g_return_if_fail (GTK_IS_FONT_CHOOSER (receiver));
187 g_return_if_fail (GTK_IS_FONT_CHOOSER (delegate));
188
189 g_object_set_qdata (G_OBJECT (receiver),
190 GTK_FONT_CHOOSER_DELEGATE_QUARK,
191 data: delegate);
192
193 g_signal_connect (delegate, "notify",
194 G_CALLBACK (delegate_notify), receiver);
195 g_signal_connect (delegate, "font-activated",
196 G_CALLBACK (delegate_font_activated), receiver);
197}
198

source code of gtk/gtk/gtkfontchooserutils.c