1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
/* 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
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* 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)
{
return gtk_font_chooser_get_font_family (get_delegate (chooser));
}
static PangoFontFace *
delegate_get_font_face (GtkFontChooser *chooser)
{
return gtk_font_chooser_get_font_face (get_delegate (chooser));
}
static int
delegate_get_font_size (GtkFontChooser *chooser)
{
return gtk_font_chooser_get_font_size (get_delegate (chooser));
}
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);
}
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,
const gchar *fontname,
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:
* @klass: the class structure for a type deriving from #GObject
*
* Installs the necessary properties for a class implementing
* #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.
*/
void
_gtk_font_chooser_install_properties (GObjectClass *klass)
{
g_object_class_override_property (klass,
GTK_FONT_CHOOSER_PROP_FONT,
"font");
g_object_class_override_property (klass,
GTK_FONT_CHOOSER_PROP_FONT_DESC,
"font-desc");
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");
}
/**
* _gtk_font_chooser_delegate_iface_init:
* @iface: a #GtkFontChooserIface
*
* An interface-initialization function for use in cases where
* an object is simply delegating the methods, signals of
* the #GtkFontChooser interface to another object.
* _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;
}
/**
* _gtk_font_chooser_set_delegate:
* @receiver: a #GObject implementing #GtkFontChooser
* @delegate: another #GObject implementing #GtkFontChooser
*
* Establishes that calls on @receiver for #GtkFontChooser
* methods should be delegated to @delegate, and that
* #GtkFontChooser signals emitted on @delegate should be
* 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);
}
|