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
29 static GtkFontChooser *
get_delegate(GtkFontChooser * receiver)30 get_delegate (GtkFontChooser *receiver)
31 {
32 return g_object_get_qdata (G_OBJECT (receiver),
33 GTK_FONT_CHOOSER_DELEGATE_QUARK);
34 }
35
36 static PangoFontFamily *
delegate_get_font_family(GtkFontChooser * chooser)37 delegate_get_font_family (GtkFontChooser *chooser)
38 {
39 return gtk_font_chooser_get_font_family (get_delegate (chooser));
40 }
41
42 static PangoFontFace *
delegate_get_font_face(GtkFontChooser * chooser)43 delegate_get_font_face (GtkFontChooser *chooser)
44 {
45 return gtk_font_chooser_get_font_face (get_delegate (chooser));
46 }
47
48 static int
delegate_get_font_size(GtkFontChooser * chooser)49 delegate_get_font_size (GtkFontChooser *chooser)
50 {
51 return gtk_font_chooser_get_font_size (get_delegate (chooser));
52 }
53
54 static void
delegate_set_filter_func(GtkFontChooser * chooser,GtkFontFilterFunc filter_func,gpointer filter_data,GDestroyNotify data_destroy)55 delegate_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 (get_delegate (chooser),
61 filter_func,
62 filter_data,
63 data_destroy);
64 }
65
66 static void
delegate_set_font_map(GtkFontChooser * chooser,PangoFontMap * map)67 delegate_set_font_map (GtkFontChooser *chooser,
68 PangoFontMap *map)
69 {
70 gtk_font_chooser_set_font_map (get_delegate (chooser), map);
71 }
72
73 static PangoFontMap *
delegate_get_font_map(GtkFontChooser * chooser)74 delegate_get_font_map (GtkFontChooser *chooser)
75 {
76 return gtk_font_chooser_get_font_map (get_delegate (chooser));
77 }
78
79 static void
delegate_notify(GObject * object,GParamSpec * pspec,gpointer user_data)80 delegate_notify (GObject *object,
81 GParamSpec *pspec,
82 gpointer user_data)
83 {
84 gpointer iface;
85
86 iface = g_type_interface_peek (g_type_class_peek (G_OBJECT_TYPE (object)),
87 GTK_TYPE_FONT_CHOOSER);
88 if (g_object_interface_find_property (iface, pspec->name))
89 g_object_notify_by_pspec (user_data, pspec);
90 }
91
92 static void
delegate_font_activated(GtkFontChooser * receiver,const gchar * fontname,GtkFontChooser * delegate)93 delegate_font_activated (GtkFontChooser *receiver,
94 const gchar *fontname,
95 GtkFontChooser *delegate)
96 {
97 _gtk_font_chooser_font_activated (delegate, fontname);
98 }
99
100 GQuark
_gtk_font_chooser_delegate_get_quark(void)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 ("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. A #GtkParamSpecOverride property is installed
117 * for each property, using the values from the #GtkFontChooserProp
118 * enumeration. The caller must make sure itself that the enumeration
119 * values don’t collide with some other property values they
120 * are using.
121 */
122 void
_gtk_font_chooser_install_properties(GObjectClass * klass)123 _gtk_font_chooser_install_properties (GObjectClass *klass)
124 {
125 g_object_class_override_property (klass,
126 GTK_FONT_CHOOSER_PROP_FONT,
127 "font");
128 g_object_class_override_property (klass,
129 GTK_FONT_CHOOSER_PROP_FONT_DESC,
130 "font-desc");
131 g_object_class_override_property (klass,
132 GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT,
133 "preview-text");
134 g_object_class_override_property (klass,
135 GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY,
136 "show-preview-entry");
137 g_object_class_override_property (klass,
138 GTK_FONT_CHOOSER_PROP_LEVEL,
139 "level");
140 g_object_class_override_property (klass,
141 GTK_FONT_CHOOSER_PROP_FONT_FEATURES,
142 "font-features");
143 g_object_class_override_property (klass,
144 GTK_FONT_CHOOSER_PROP_LANGUAGE,
145 "language");
146 }
147
148 /**
149 * _gtk_font_chooser_delegate_iface_init:
150 * @iface: a #GtkFontChooserIface
151 *
152 * An interface-initialization function for use in cases where
153 * an object is simply delegating the methods, signals of
154 * the #GtkFontChooser interface to another object.
155 * _gtk_font_chooser_set_delegate() must be called on each
156 * instance of the object so that the delegate object can
157 * be found.
158 */
159 void
_gtk_font_chooser_delegate_iface_init(GtkFontChooserIface * iface)160 _gtk_font_chooser_delegate_iface_init (GtkFontChooserIface *iface)
161 {
162 iface->get_font_family = delegate_get_font_family;
163 iface->get_font_face = delegate_get_font_face;
164 iface->get_font_size = delegate_get_font_size;
165 iface->set_filter_func = delegate_set_filter_func;
166 iface->set_font_map = delegate_set_font_map;
167 iface->get_font_map = delegate_get_font_map;
168 }
169
170 /**
171 * _gtk_font_chooser_set_delegate:
172 * @receiver: a #GObject implementing #GtkFontChooser
173 * @delegate: another #GObject implementing #GtkFontChooser
174 *
175 * Establishes that calls on @receiver for #GtkFontChooser
176 * methods should be delegated to @delegate, and that
177 * #GtkFontChooser signals emitted on @delegate should be
178 * forwarded to @receiver. Must be used in conjunction with
179 * _gtk_font_chooser_delegate_iface_init().
180 */
181 void
_gtk_font_chooser_set_delegate(GtkFontChooser * receiver,GtkFontChooser * delegate)182 _gtk_font_chooser_set_delegate (GtkFontChooser *receiver,
183 GtkFontChooser *delegate)
184 {
185 g_return_if_fail (GTK_IS_FONT_CHOOSER (receiver));
186 g_return_if_fail (GTK_IS_FONT_CHOOSER (delegate));
187
188 g_object_set_qdata (G_OBJECT (receiver),
189 GTK_FONT_CHOOSER_DELEGATE_QUARK,
190 delegate);
191
192 g_signal_connect (delegate, "notify",
193 G_CALLBACK (delegate_notify), receiver);
194 g_signal_connect (delegate, "font-activated",
195 G_CALLBACK (delegate_font_activated), receiver);
196 }
197