]> Pileus Git - ~andy/gtk/blob - gtk/gtkbuildable.c
Rename buildable methods to not clash with widget methods. (#448928,
[~andy/gtk] / gtk / gtkbuildable.c
1 /* gtkbuildable.c
2  * Copyright (C) 2006-2007 Async Open Source,
3  *                         Johan Dahlin <jdahlin@async.com.br>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21
22 #include <config.h>
23 #include "gtkbuildable.h"
24 #include "gtktypeutils.h"
25 #include "gtkintl.h"
26 #include "gtkalias.h"
27
28 GType
29 gtk_buildable_get_type (void)
30 {
31   static GType buildable_type = 0;
32
33   if (!buildable_type)
34     buildable_type =
35       g_type_register_static_simple (G_TYPE_INTERFACE, I_("GtkBuildable"),
36                                      sizeof (GtkBuildableIface),
37                                      NULL, 0, NULL, 0);
38
39   return buildable_type;
40 }
41
42 /**
43  * gtk_buildable_set_name:
44  * @buildable: a #GtkBuildable
45  * @name: name to set
46  *
47  * Sets the name of the buildable object, it's used to synchronize the name
48  * if the object already has it's own concept of name.
49  *
50  * #GtkWidget implements this to map the buildable name to the widget name
51  *
52  * Since: 2.12
53  **/
54 void
55 gtk_buildable_set_name (GtkBuildable *buildable,
56                         const gchar  *name)
57 {
58   GtkBuildableIface *iface;
59
60   g_return_if_fail (GTK_IS_BUILDABLE (buildable));
61   g_return_if_fail (name != NULL);
62
63   iface = GTK_BUILDABLE_GET_IFACE (buildable);
64
65   if (iface->set_name)
66     (* iface->set_name) (buildable, name);
67   else
68     g_object_set_data_full (G_OBJECT (buildable),
69                             "gtk-builder-name",
70                             g_strdup (name),
71                             g_free);
72 }
73
74 /**
75  * gtk_buildable_get_name:
76  * @buildable: a #GtkBuildable
77  *
78  *   
79  * Returns the buildable name. #GtkBuilder sets the name based on the 
80  * the <link linkend="BUILDER-UI">GtkBuilder UI definition</link> used 
81  * to construct the @buildable.
82  *
83  * #GtkWidget implements this to map the buildable name to the widget name
84  *
85  * Returns: the name set with gtk_buildable_set_name()
86  *
87  * Since: 2.12
88  **/
89 const gchar *
90 gtk_buildable_get_name (GtkBuildable *buildable)
91 {
92   GtkBuildableIface *iface;
93
94   g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), NULL);
95
96   iface = GTK_BUILDABLE_GET_IFACE (buildable);
97
98   if (iface->get_name)
99     return (* iface->get_name) (buildable);
100   else
101     return (const gchar*)g_object_get_data (G_OBJECT (buildable),
102                                             "gtk-builder-name");
103 }
104
105 /**
106  * gtk_buildable_add_child:
107  * @buildable: a #GtkBuildable
108  * @builder: a #GtkBuilder
109  * @child: child to add
110  * @type: kind of child or %NULL
111  *
112  * Add a child to a buildable. type is an optional string
113  * describing how the child should be added.
114  *
115  * #GtkContainer implements this to be able to add a child widget
116  * to the container. #GtkNotebook uses the @type to distinguish between
117  * page labels (@type = "page-label") and normal children.
118  *
119  * Since: 2.12
120  **/
121 void
122 gtk_buildable_add_child (GtkBuildable *buildable,
123                          GtkBuilder   *builder,
124                          GObject      *child,
125                          const gchar  *type)
126 {
127   GtkBuildableIface *iface;
128
129   g_return_if_fail (GTK_IS_BUILDABLE (buildable));
130   g_return_if_fail (GTK_IS_BUILDER (builder));
131
132   iface = GTK_BUILDABLE_GET_IFACE (buildable);
133   g_return_if_fail (iface->add_child != NULL);
134
135   (* iface->add_child) (buildable, builder, child, type);
136 }
137
138 /**
139  * gtk_buildable_set_buildable_property:
140  * @buildable: a #GtkBuildable
141  * @builder: a #GtkBuilder
142  * @name: name of property
143  * @value: value of property
144  *
145  * Sets the property name @name to @value on the buildable object @buildable
146  * which is created by the @builder.
147  *
148  * This is optional to implement and is normally not needed.
149  * g_object_set_property() is used as a fallback.
150  *
151  * #GtkWindow implements this to delay showing (::visible) itself until
152  * the whole interface is fully created.
153  *
154  * Since: 2.12
155  **/
156 void
157 gtk_buildable_set_buildable_property (GtkBuildable *buildable,
158                                       GtkBuilder   *builder,
159                                       const gchar  *name,
160                                       const GValue *value)
161 {
162   GtkBuildableIface *iface;
163
164   g_return_if_fail (GTK_IS_BUILDABLE (buildable));
165   g_return_if_fail (GTK_IS_BUILDER (builder));
166   g_return_if_fail (name != NULL);
167   g_return_if_fail (value != NULL);
168
169   iface = GTK_BUILDABLE_GET_IFACE (buildable);
170   if (iface->set_buildable_property)
171     (* iface->set_buildable_property) (buildable, builder, name, value);
172   else
173     g_object_set_property (G_OBJECT (buildable), name, value);
174 }
175
176 /**
177  * gtk_buildable_parser_finished:
178  * @buildable: a #GtkBuildable
179  * @builder: a #GtkBuilder
180  *
181  * Finish the parsing of a <link linkend="BUILDER-UI">GtkBuilder UI definition</link>
182  * snippet. Note that this will be called once for each time gtk_builder_add_from_file or
183  * gtk_builder_add_from_string is called on a builder.
184  *
185  * #GtkWindow implements this to delay showing (::visible) itself until
186  * the whole interface is fully created.
187  *
188  * Since: 2.12
189  **/
190 void
191 gtk_buildable_parser_finished (GtkBuildable *buildable,
192                                GtkBuilder   *builder)
193 {
194   GtkBuildableIface *iface;
195
196   g_return_if_fail (GTK_IS_BUILDABLE (buildable));
197   g_return_if_fail (GTK_IS_BUILDER (builder));
198
199   iface = GTK_BUILDABLE_GET_IFACE (buildable);
200   if (iface->parser_finished)
201     (* iface->parser_finished) (buildable, builder);
202 }
203
204 /**
205  * gtk_buildable_construct_child
206  * @buildable: A #GtkBuildable
207  * @builder: #GtkBuilder used to construct this object
208  * @name: name of child to construct
209  *
210  * Construct a child of @buildable with the name @name.
211  *
212  * #GtkUIManager implements this to reference to a widget created in a 
213  * &lt;ui&gt; tag which is outside of the normal 
214  * <link linkend="BUILDER-UI">GtkBuilder UI definition</link>
215  * hierarchy.
216  *
217  * Returns: the child with name @name
218  *
219  * Since: 2.12
220  **/
221 GObject *
222 gtk_buildable_construct_child (GtkBuildable *buildable,
223                                GtkBuilder   *builder,
224                                const gchar  *name)
225 {
226   GtkBuildableIface *iface;
227
228   g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), NULL);
229   g_return_val_if_fail (GTK_IS_BUILDER (builder), NULL);
230   g_return_val_if_fail (name != NULL, NULL);
231
232   iface = GTK_BUILDABLE_GET_IFACE (buildable);
233   g_return_val_if_fail (iface->construct_child != NULL, NULL);
234
235   return (* iface->construct_child) (buildable, builder, name);
236 }
237
238 /**
239  * gtk_buildable_custom_tag_start
240  * @buildable: a #GtkBuildable
241  * @builder: a #GtkBuilder used to construct this object
242  * @child: child object or %NULL for non-child tags
243  * @tagname: name of tag
244  * @parser: a #GMarkupParser structure
245  * @data: user data that will be passed in to parser functions
246  *
247  * This is called when an unknown tag under &lt;child&gt; tag is found.
248  * 
249  * Called when an unknown tag is present under a &lt;child&gt; tag.
250  * If the buildable implementation wishes to handle the tag it should
251  * return %TRUE and fill in the @parser structure. Remember to either
252  * implement custom_tag_end or custom_tag_finish to free
253  * the user data allocated here.
254  *
255  * #GtkWidget implements this and parsers all &lt;accelerator&gt; tags to
256  * keyboard accelerators.
257  * #GtkContainer implements this to map properties defined under
258  * &lt;packing&gt; tag to child properties.
259  *
260  * Returns: %TRUE if a object has a custom implementation, %FALSE
261  *          if it doesn't.
262  *
263  * Since: 2.12
264  **/
265 gboolean
266 gtk_buildable_custom_tag_start (GtkBuildable  *buildable,
267                                 GtkBuilder    *builder,
268                                 GObject       *child,
269                                 const gchar   *tagname,
270                                 GMarkupParser *parser,
271                                 gpointer      *data)
272 {
273   GtkBuildableIface *iface;
274
275   g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), FALSE);
276   g_return_val_if_fail (GTK_IS_BUILDER (builder), FALSE);
277   g_return_val_if_fail (tagname != NULL, FALSE);
278
279   iface = GTK_BUILDABLE_GET_IFACE (buildable);
280   g_return_val_if_fail (iface->custom_tag_start != NULL, FALSE);
281
282   return (* iface->custom_tag_start) (buildable, builder, child,
283                                       tagname, parser, data);
284 }
285
286 /**
287  * gtk_buildable_custom_tag_end
288  * @buildable: A #GtkBuildable
289  * @builder: #GtkBuilder used to construct this object
290  * @child: child object or %NULL for non-child tags
291  * @tagname: name of tag
292  * @data: user data that will be passed in to parser functions
293  *
294  * This is called for each custom tag handled by the buildable.
295  * It will be called when the end of the tag is reached.
296  *
297  * Since: 2.12
298  **/
299 void
300 gtk_buildable_custom_tag_end (GtkBuildable  *buildable,
301                               GtkBuilder    *builder,
302                               GObject       *child,
303                               const gchar   *tagname,
304                               gpointer      *data)
305 {
306   GtkBuildableIface *iface;
307
308   g_return_if_fail (GTK_IS_BUILDABLE (buildable));
309   g_return_if_fail (GTK_IS_BUILDER (builder));
310   g_return_if_fail (tagname != NULL);
311
312   iface = GTK_BUILDABLE_GET_IFACE (buildable);
313   if (iface->custom_tag_end)
314     (* iface->custom_tag_end) (buildable, builder, child, tagname, data);
315 }
316
317 /**
318  * gtk_buildable_custom_finished:
319  * @buildable: a #GtkBuildable
320  * @builder: a #GtkBuilder
321  * @child: child object or %NULL for non-child tags
322  * @tagname: the name of the tag
323  * @data: user data created in custom_tag_start
324  *
325  * This is similar to gtk_buildable_parser_finished() but is
326  * called once for each custom tag handled by the @buildable.
327  * 
328  * Since: 2.12
329  **/
330 void
331 gtk_buildable_custom_finished (GtkBuildable  *buildable,
332                                GtkBuilder    *builder,
333                                GObject       *child,
334                                const gchar   *tagname,
335                                gpointer       data)
336 {
337   GtkBuildableIface *iface;
338
339   g_return_if_fail (GTK_IS_BUILDABLE (buildable));
340   g_return_if_fail (GTK_IS_BUILDER (builder));
341
342   iface = GTK_BUILDABLE_GET_IFACE (buildable);
343   if (iface->custom_finished)
344     (* iface->custom_finished) (buildable, builder, child, tagname, data);
345 }
346
347 /**
348  * gtk_buildable_get_internal_child
349  * @buildable: a #GtkBuildable
350  * @builder: a #GtkBuilder
351  * @childname: name of child
352  *
353  * Get the internal child called @childname of the @buildable object.
354  *
355  * Returns: the internal child of the buildable object 
356  *
357  * Since: 2.12
358  **/
359 GObject *
360 gtk_buildable_get_internal_child (GtkBuildable *buildable,
361                                   GtkBuilder   *builder,
362                                   const gchar  *childname)
363 {
364   GtkBuildableIface *iface;
365
366   g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), NULL);
367   g_return_val_if_fail (GTK_IS_BUILDER (builder), NULL);
368   g_return_val_if_fail (childname != NULL, NULL);
369
370   iface = GTK_BUILDABLE_GET_IFACE (buildable);
371   if (!iface->get_internal_child)
372     return NULL;
373
374   return (* iface->get_internal_child) (buildable, builder, childname);
375 }
376
377 #define __GTK_BUILDABLE_C__
378 #include "gtkaliasdef.c"