1 /* gtkfontchooserutils.h - Private utility functions for implementing a
2 * GtkFontChooser interface
4 * Copyright (C) 2006 Emmanuele Bassi
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.
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.
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/>.
21 * Based on gtkfilechooserutils.c:
22 * Copyright (C) 2003 Red Hat, Inc.
27 #include "gtkfontchooserutils.h"
29 static GtkFontChooser *
30 get_delegate (GtkFontChooser *receiver)
32 return g_object_get_qdata (G_OBJECT (receiver),
33 GTK_FONT_CHOOSER_DELEGATE_QUARK);
36 static PangoFontFamily *
37 delegate_get_font_family (GtkFontChooser *chooser)
39 return gtk_font_chooser_get_font_family (get_delegate (chooser));
42 static PangoFontFace *
43 delegate_get_font_face (GtkFontChooser *chooser)
45 return gtk_font_chooser_get_font_face (get_delegate (chooser));
49 delegate_get_font_size (GtkFontChooser *chooser)
51 return gtk_font_chooser_get_font_size (get_delegate (chooser));
55 delegate_set_filter_func (GtkFontChooser *chooser,
56 GtkFontFilterFunc filter_func,
58 GDestroyNotify data_destroy)
60 gtk_font_chooser_set_filter_func (get_delegate (chooser),
67 delegate_notify (GObject *object,
73 iface = g_type_interface_peek (g_type_class_peek (G_OBJECT_TYPE (object)),
74 GTK_TYPE_FONT_CHOOSER);
75 if (g_object_interface_find_property (iface, pspec->name))
76 g_object_notify_by_pspec (user_data, pspec);
80 delegate_font_activated (GtkFontChooser *receiver,
81 const gchar *fontname,
82 GtkFontChooser *delegate)
84 _gtk_font_chooser_font_activated (delegate, fontname);
88 _gtk_font_chooser_delegate_get_quark (void)
90 static GQuark quark = 0;
92 if (G_UNLIKELY (quark == 0))
93 quark = g_quark_from_static_string ("gtk-font-chooser-delegate");
99 * _gtk_font_chooser_install_properties:
100 * @klass: the class structure for a type deriving from #GObject
102 * Installs the necessary properties for a class implementing
103 * #GtkFontChooser. A #GtkParamSpecOverride property is installed
104 * for each property, using the values from the #GtkFontChooserProp
105 * enumeration. The caller must make sure itself that the enumeration
106 * values don't collide with some other property values they
110 _gtk_font_chooser_install_properties (GObjectClass *klass)
112 g_object_class_override_property (klass,
113 GTK_FONT_CHOOSER_PROP_FONT,
115 g_object_class_override_property (klass,
116 GTK_FONT_CHOOSER_PROP_FONT_DESC,
118 g_object_class_override_property (klass,
119 GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT,
121 g_object_class_override_property (klass,
122 GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY,
123 "show-preview-entry");
127 * _gtk_font_chooser_delegate_iface_init:
128 * @iface: a #GtkFontChooserIface
130 * An interface-initialization function for use in cases where
131 * an object is simply delegating the methods, signals of
132 * the #GtkFontChooser interface to another object.
133 * _gtk_font_chooser_set_delegate() must be called on each
134 * instance of the object so that the delegate object can
138 _gtk_font_chooser_delegate_iface_init (GtkFontChooserIface *iface)
140 iface->get_font_family = delegate_get_font_family;
141 iface->get_font_face = delegate_get_font_face;
142 iface->get_font_size = delegate_get_font_size;
143 iface->set_filter_func = delegate_set_filter_func;
147 * _gtk_font_chooser_set_delegate:
148 * @receiver: a #GObject implementing #GtkFontChooser
149 * @delegate: another #GObject implementing #GtkFontChooser
151 * Establishes that calls on @receiver for #GtkFontChooser
152 * methods should be delegated to @delegate, and that
153 * #GtkFontChooser signals emitted on @delegate should be
154 * forwarded to @receiver. Must be used in conjunction with
155 * _gtk_font_chooser_delegate_iface_init().
158 _gtk_font_chooser_set_delegate (GtkFontChooser *receiver,
159 GtkFontChooser *delegate)
161 g_return_if_fail (GTK_IS_FONT_CHOOSER (receiver));
162 g_return_if_fail (GTK_IS_FONT_CHOOSER (delegate));
164 g_object_set_qdata (G_OBJECT (receiver),
165 GTK_FONT_CHOOSER_DELEGATE_QUARK,
168 g_signal_connect (delegate, "notify",
169 G_CALLBACK (delegate_notify), receiver);
170 g_signal_connect (delegate, "font-activated",
171 G_CALLBACK (delegate_font_activated), receiver);