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, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
23 * Based on gtkfilechooserutils.c:
24 * Copyright (C) 2003 Red Hat, Inc.
29 #include "gtkfontchooserutils.h"
31 static GtkFontChooser *
32 get_delegate (GtkFontChooser *receiver)
34 return g_object_get_qdata (G_OBJECT (receiver),
35 GTK_FONT_CHOOSER_DELEGATE_QUARK);
39 delegate_get_font (GtkFontChooser *chooser)
41 return gtk_font_chooser_get_font (get_delegate (chooser));
45 delegate_set_font (GtkFontChooser *chooser,
46 const gchar *fontname)
48 gtk_font_chooser_set_font (get_delegate (chooser), fontname);
51 static PangoFontFamily *
52 delegate_get_font_family (GtkFontChooser *chooser)
54 return gtk_font_chooser_get_family (get_delegate (chooser));
57 static PangoFontFace *
58 delegate_get_font_face (GtkFontChooser *chooser)
60 return gtk_font_chooser_get_face (get_delegate (chooser));
64 delegate_get_font_size (GtkFontChooser *chooser)
66 return gtk_font_chooser_get_size (get_delegate (chooser));
70 delegate_set_filter_func (GtkFontChooser *chooser,
71 GtkFontFilterFunc filter_func,
73 GDestroyNotify data_destroy)
75 gtk_font_chooser_set_filter_func (get_delegate (chooser),
82 delegate_notify (GObject *object,
88 iface = g_type_interface_peek (g_type_class_peek (G_OBJECT_TYPE (object)),
89 GTK_TYPE_FONT_CHOOSER);
90 if (g_object_interface_find_property (iface, pspec->name))
91 g_object_notify_by_pspec (user_data, pspec);
95 delegate_font_activated (GtkFontChooser *receiver,
96 const gchar *fontname,
97 GtkFontChooser *delegate)
99 _gtk_font_chooser_font_activated (delegate, fontname);
103 _gtk_font_chooser_delegate_get_quark (void)
105 static GQuark quark = 0;
107 if (G_UNLIKELY (quark == 0))
108 quark = g_quark_from_static_string ("gtk-font-chooser-delegate");
114 * _gtk_font_chooser_install_properties:
115 * @klass: the class structure for a type deriving from #GObject
117 * Installs the necessary properties for a class implementing
118 * #GtkFontChooser. A #GtkParamSpecOverride property is installed
119 * for each property, using the values from the #GtkFontChooserProp
120 * enumeration. The caller must make sure itself that the enumeration
121 * values don't collide with some other property values they
125 _gtk_font_chooser_install_properties (GObjectClass *klass)
127 g_object_class_override_property (klass,
128 GTK_FONT_CHOOSER_PROP_FONT,
130 g_object_class_override_property (klass,
131 GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT,
133 g_object_class_override_property (klass,
134 GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY,
135 "show-preview-entry");
139 * _gtk_font_chooser_delegate_iface_init:
140 * @iface: a #GtkFontChooserIface
142 * An interface-initialization function for use in cases where
143 * an object is simply delegating the methods, signals of
144 * the #GtkFontChooser interface to another object.
145 * _gtk_font_chooser_set_delegate() must be called on each
146 * instance of the object so that the delegate object can
150 _gtk_font_chooser_delegate_iface_init (GtkFontChooserIface *iface)
152 iface->get_font = delegate_get_font;
153 iface->set_font = delegate_set_font;
154 iface->get_font_family = delegate_get_font_family;
155 iface->get_font_face = delegate_get_font_face;
156 iface->get_font_size = delegate_get_font_size;
157 iface->set_filter_func = delegate_set_filter_func;
161 * _gtk_font_chooser_set_delegate:
162 * @receiver: a #GObject implementing #GtkFontChooser
163 * @delegate: another #GObject implementing #GtkFontChooser
165 * Establishes that calls on @receiver for #GtkFontChooser
166 * methods should be delegated to @delegate, and that
167 * #GtkFontChooser signals emitted on @delegate should be
168 * forwarded to @receiver. Must be used in conjunction with
169 * _gtk_font_chooser_delegate_iface_init().
172 _gtk_font_chooser_set_delegate (GtkFontChooser *receiver,
173 GtkFontChooser *delegate)
175 g_return_if_fail (GTK_IS_FONT_CHOOSER (receiver));
176 g_return_if_fail (GTK_IS_FONT_CHOOSER (delegate));
178 g_object_set_qdata (G_OBJECT (receiver),
179 GTK_FONT_CHOOSER_DELEGATE_QUARK,
182 g_signal_connect (delegate, "notify",
183 G_CALLBACK (delegate_notify), receiver);
184 g_signal_connect (delegate, "font-activated",
185 G_CALLBACK (delegate_font_activated), receiver);