]> Pileus Git - ~andy/gtk/blob - gtk/gtkfontchooserutils.c
8cf36606b907eb281eace970312cc33f80a8ee16
[~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 PangoFontFamily *
39 delegate_get_font_family (GtkFontChooser *chooser)
40 {
41   return gtk_font_chooser_get_font_family (get_delegate (chooser));
42 }
43
44 static PangoFontFace *
45 delegate_get_font_face (GtkFontChooser *chooser)
46 {
47   return gtk_font_chooser_get_font_face (get_delegate (chooser));
48 }
49
50 static int
51 delegate_get_font_size (GtkFontChooser *chooser)
52 {
53   return gtk_font_chooser_get_font_size (get_delegate (chooser));
54 }
55
56 static void
57 delegate_set_filter_func (GtkFontChooser    *chooser,
58                           GtkFontFilterFunc  filter_func,
59                           gpointer           filter_data,
60                           GDestroyNotify     data_destroy)
61 {
62   gtk_font_chooser_set_filter_func (get_delegate (chooser),
63                                     filter_func,
64                                     filter_data,
65                                     data_destroy);
66 }
67
68 static void
69 delegate_notify (GObject    *object,
70                  GParamSpec *pspec,
71                  gpointer    user_data)
72 {
73   gpointer iface;
74
75   iface = g_type_interface_peek (g_type_class_peek (G_OBJECT_TYPE (object)),
76                                  GTK_TYPE_FONT_CHOOSER);
77   if (g_object_interface_find_property (iface, pspec->name))
78     g_object_notify_by_pspec (user_data, pspec);
79 }
80
81 static void
82 delegate_font_activated (GtkFontChooser *receiver,
83                          const gchar    *fontname,
84                          GtkFontChooser *delegate)
85 {
86   _gtk_font_chooser_font_activated (delegate, fontname);
87 }
88
89 GQuark
90 _gtk_font_chooser_delegate_get_quark (void)
91 {
92   static GQuark quark = 0;
93
94   if (G_UNLIKELY (quark == 0))
95     quark = g_quark_from_static_string ("gtk-font-chooser-delegate");
96
97   return quark;
98 }
99
100 /**
101  * _gtk_font_chooser_install_properties:
102  * @klass: the class structure for a type deriving from #GObject
103  *
104  * Installs the necessary properties for a class implementing
105  * #GtkFontChooser. A #GtkParamSpecOverride property is installed
106  * for each property, using the values from the #GtkFontChooserProp
107  * enumeration. The caller must make sure itself that the enumeration
108  * values don't collide with some other property values they
109  * are using.
110  */
111 void
112 _gtk_font_chooser_install_properties (GObjectClass *klass)
113 {
114   g_object_class_override_property (klass,
115                                     GTK_FONT_CHOOSER_PROP_FONT,
116                                     "font");
117   g_object_class_override_property (klass,
118                                     GTK_FONT_CHOOSER_PROP_FONT_DESC,
119                                     "font-desc");
120   g_object_class_override_property (klass,
121                                     GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT,
122                                     "preview-text");
123   g_object_class_override_property (klass,
124                                     GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY,
125                                     "show-preview-entry");
126 }
127
128 /**
129  * _gtk_font_chooser_delegate_iface_init:
130  * @iface: a #GtkFontChooserIface
131  *
132  * An interface-initialization function for use in cases where
133  * an object is simply delegating the methods, signals of
134  * the #GtkFontChooser interface to another object.
135  * _gtk_font_chooser_set_delegate() must be called on each
136  * instance of the object so that the delegate object can
137  * be found.
138  */
139 void
140 _gtk_font_chooser_delegate_iface_init (GtkFontChooserIface *iface)
141 {
142   iface->get_font_family = delegate_get_font_family;
143   iface->get_font_face = delegate_get_font_face;
144   iface->get_font_size = delegate_get_font_size;
145   iface->set_filter_func = delegate_set_filter_func;
146 }
147
148 /**
149  * _gtk_font_chooser_set_delegate:
150  * @receiver: a #GObject implementing #GtkFontChooser
151  * @delegate: another #GObject implementing #GtkFontChooser
152  *
153  * Establishes that calls on @receiver for #GtkFontChooser
154  * methods should be delegated to @delegate, and that
155  * #GtkFontChooser signals emitted on @delegate should be
156  * forwarded to @receiver. Must be used in conjunction with
157  * _gtk_font_chooser_delegate_iface_init().
158  */
159 void
160 _gtk_font_chooser_set_delegate (GtkFontChooser *receiver,
161                                 GtkFontChooser *delegate)
162 {
163   g_return_if_fail (GTK_IS_FONT_CHOOSER (receiver));
164   g_return_if_fail (GTK_IS_FONT_CHOOSER (delegate));
165   
166   g_object_set_qdata (G_OBJECT (receiver),
167                       GTK_FONT_CHOOSER_DELEGATE_QUARK,
168                       delegate);
169   
170   g_signal_connect (delegate, "notify",
171                     G_CALLBACK (delegate_notify), receiver);
172   g_signal_connect (delegate, "font-activated",
173                     G_CALLBACK (delegate_font_activated), receiver);
174 }