]> Pileus Git - ~andy/gtk/blob - gtk/gtkfontchooserutils.c
418442f2b6c4f71e14617f329f9085f23d0b954e
[~andy/gtk] / gtk / gtkfontchooserutils.c
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, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  * Based on gtkfilechooserutils.c:
24  *      Copyright (C) 2003 Red Hat, Inc.
25  */
26
27 #include "config.h"
28
29 #include "gtkfontchooserutils.h"
30
31 static GtkFontChooser *
32 get_delegate (GtkFontChooser *receiver)
33 {
34   return g_object_get_qdata (G_OBJECT (receiver),
35                              GTK_FONT_CHOOSER_DELEGATE_QUARK);
36 }
37
38 static gchar *
39 delegate_get_font (GtkFontChooser *chooser)
40 {
41   return gtk_font_chooser_get_font (get_delegate (chooser));
42 }
43
44 static void
45 delegate_set_font (GtkFontChooser *chooser,
46                         const gchar    *fontname)
47 {
48   gtk_font_chooser_set_font (get_delegate (chooser), fontname);
49 }
50
51 static PangoFontFamily *
52 delegate_get_font_family (GtkFontChooser *chooser)
53 {
54   return gtk_font_chooser_get_family (get_delegate (chooser));
55 }
56
57 static PangoFontFace *
58 delegate_get_font_face (GtkFontChooser *chooser)
59 {
60   return gtk_font_chooser_get_face (get_delegate (chooser));
61 }
62
63 static int
64 delegate_get_font_size (GtkFontChooser *chooser)
65 {
66   return gtk_font_chooser_get_size (get_delegate (chooser));
67 }
68
69 static void
70 delegate_set_filter_func (GtkFontChooser    *chooser,
71                           GtkFontFilterFunc  filter_func,
72                           gpointer           filter_data,
73                           GDestroyNotify     data_destroy)
74 {
75   gtk_font_chooser_set_filter_func (get_delegate (chooser),
76                                     filter_func,
77                                     filter_data,
78                                     data_destroy);
79 }
80
81 static void
82 delegate_notify (GObject    *object,
83                  GParamSpec *pspec,
84                  gpointer    user_data)
85 {
86   gpointer iface;
87
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);
92 }
93
94 static void
95 delegate_font_activated (GtkFontChooser *receiver,
96                          const gchar    *fontname,
97                          GtkFontChooser *delegate)
98 {
99   _gtk_font_chooser_font_activated (delegate, fontname);
100 }
101
102 GQuark
103 _gtk_font_chooser_delegate_get_quark (void)
104 {
105   static GQuark quark = 0;
106
107   if (G_UNLIKELY (quark == 0))
108     quark = g_quark_from_static_string ("gtk-font-chooser-delegate");
109
110   return quark;
111 }
112
113 /**
114  * _gtk_font_chooser_install_properties:
115  * @klass: the class structure for a type deriving from #GObject
116  *
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
122  * are using.
123  */
124 void
125 _gtk_font_chooser_install_properties (GObjectClass *klass)
126 {
127   g_object_class_override_property (klass,
128                                     GTK_FONT_CHOOSER_PROP_FONT,
129                                     "font");
130   g_object_class_override_property (klass,
131                                     GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT,
132                                     "preview-text");
133   g_object_class_override_property (klass,
134                                     GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY,
135                                     "show-preview-entry");
136 }
137
138 /**
139  * _gtk_font_chooser_delegate_iface_init:
140  * @iface: a #GtkFontChooserIface
141  *
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
147  * be found.
148  */
149 void
150 _gtk_font_chooser_delegate_iface_init (GtkFontChooserIface *iface)
151 {
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;
158 }
159
160 /**
161  * _gtk_font_chooser_set_delegate:
162  * @receiver: a #GObject implementing #GtkFontChooser
163  * @delegate: another #GObject implementing #GtkFontChooser
164  *
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().
170  */
171 void
172 _gtk_font_chooser_set_delegate (GtkFontChooser *receiver,
173                                 GtkFontChooser *delegate)
174 {
175   g_return_if_fail (GTK_IS_FONT_CHOOSER (receiver));
176   g_return_if_fail (GTK_IS_FONT_CHOOSER (delegate));
177   
178   g_object_set_qdata (G_OBJECT (receiver),
179                       GTK_FONT_CHOOSER_DELEGATE_QUARK,
180                       delegate);
181   
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);
186 }