]> Pileus Git - ~andy/gtk/blob - gtk/gtkfontchooserutils.c
stylecontext: Do invalidation on first resize container
[~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, see <http://www.gnu.org/licenses/>.
20  *
21  * Based on gtkfilechooserutils.c:
22  *      Copyright (C) 2003 Red Hat, Inc.
23  */
24
25 #include "config.h"
26
27 #include "gtkfontchooserutils.h"
28
29 static GtkFontChooser *
30 get_delegate (GtkFontChooser *receiver)
31 {
32   return g_object_get_qdata (G_OBJECT (receiver),
33                              GTK_FONT_CHOOSER_DELEGATE_QUARK);
34 }
35
36 static PangoFontFamily *
37 delegate_get_font_family (GtkFontChooser *chooser)
38 {
39   return gtk_font_chooser_get_font_family (get_delegate (chooser));
40 }
41
42 static PangoFontFace *
43 delegate_get_font_face (GtkFontChooser *chooser)
44 {
45   return gtk_font_chooser_get_font_face (get_delegate (chooser));
46 }
47
48 static int
49 delegate_get_font_size (GtkFontChooser *chooser)
50 {
51   return gtk_font_chooser_get_font_size (get_delegate (chooser));
52 }
53
54 static void
55 delegate_set_filter_func (GtkFontChooser    *chooser,
56                           GtkFontFilterFunc  filter_func,
57                           gpointer           filter_data,
58                           GDestroyNotify     data_destroy)
59 {
60   gtk_font_chooser_set_filter_func (get_delegate (chooser),
61                                     filter_func,
62                                     filter_data,
63                                     data_destroy);
64 }
65
66 static void
67 delegate_notify (GObject    *object,
68                  GParamSpec *pspec,
69                  gpointer    user_data)
70 {
71   gpointer iface;
72
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);
77 }
78
79 static void
80 delegate_font_activated (GtkFontChooser *receiver,
81                          const gchar    *fontname,
82                          GtkFontChooser *delegate)
83 {
84   _gtk_font_chooser_font_activated (delegate, fontname);
85 }
86
87 GQuark
88 _gtk_font_chooser_delegate_get_quark (void)
89 {
90   static GQuark quark = 0;
91
92   if (G_UNLIKELY (quark == 0))
93     quark = g_quark_from_static_string ("gtk-font-chooser-delegate");
94
95   return quark;
96 }
97
98 /**
99  * _gtk_font_chooser_install_properties:
100  * @klass: the class structure for a type deriving from #GObject
101  *
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
107  * are using.
108  */
109 void
110 _gtk_font_chooser_install_properties (GObjectClass *klass)
111 {
112   g_object_class_override_property (klass,
113                                     GTK_FONT_CHOOSER_PROP_FONT,
114                                     "font");
115   g_object_class_override_property (klass,
116                                     GTK_FONT_CHOOSER_PROP_FONT_DESC,
117                                     "font-desc");
118   g_object_class_override_property (klass,
119                                     GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT,
120                                     "preview-text");
121   g_object_class_override_property (klass,
122                                     GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY,
123                                     "show-preview-entry");
124 }
125
126 /**
127  * _gtk_font_chooser_delegate_iface_init:
128  * @iface: a #GtkFontChooserIface
129  *
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
135  * be found.
136  */
137 void
138 _gtk_font_chooser_delegate_iface_init (GtkFontChooserIface *iface)
139 {
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;
144 }
145
146 /**
147  * _gtk_font_chooser_set_delegate:
148  * @receiver: a #GObject implementing #GtkFontChooser
149  * @delegate: another #GObject implementing #GtkFontChooser
150  *
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().
156  */
157 void
158 _gtk_font_chooser_set_delegate (GtkFontChooser *receiver,
159                                 GtkFontChooser *delegate)
160 {
161   g_return_if_fail (GTK_IS_FONT_CHOOSER (receiver));
162   g_return_if_fail (GTK_IS_FONT_CHOOSER (delegate));
163   
164   g_object_set_qdata (G_OBJECT (receiver),
165                       GTK_FONT_CHOOSER_DELEGATE_QUARK,
166                       delegate);
167   
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);
172 }