]> Pileus Git - ~andy/gtk/blob - gtk/gtkbuildable.c
documentation updates
[~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.
48  *
49  * Since: 2.12
50  **/
51 void
52 gtk_buildable_set_name (GtkBuildable *buildable,
53                         const gchar  *name)
54 {
55   GtkBuildableIface *iface;
56
57   g_return_if_fail (GTK_IS_BUILDABLE (buildable));
58   g_return_if_fail (name != NULL);
59
60   iface = GTK_BUILDABLE_GET_IFACE (buildable);
61
62   if (iface->set_name)
63     (* iface->set_name) (buildable, name);
64   else
65     g_object_set_data_full (G_OBJECT (buildable),
66                             "gtk-builder-name",
67                             g_strdup (name),
68                             g_free);
69 }
70
71 /**
72  * gtk_buildable_get_name:
73  * @buildable: a #GtkBuildable
74  *
75  * Gets the name of the @buildable object. 
76  * 
77  * #GtkBuilder sets the name based on the the 
78  * <link linkend="BUILDER-UI">GtkBuilder UI definition</link> 
79  * used to construct the @buildable.
80  *
81  * Returns: the name set with gtk_buildable_set_name()
82  *
83  * Since: 2.12
84  **/
85 const gchar *
86 gtk_buildable_get_name (GtkBuildable *buildable)
87 {
88   GtkBuildableIface *iface;
89
90   g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), NULL);
91
92   iface = GTK_BUILDABLE_GET_IFACE (buildable);
93
94   if (iface->get_name)
95     return (* iface->get_name) (buildable);
96   else
97     return (const gchar*)g_object_get_data (G_OBJECT (buildable),
98                                             "gtk-builder-name");
99 }
100
101 /**
102  * gtk_buildable_add_child:
103  * @buildable: a #GtkBuildable
104  * @builder: a #GtkBuilder
105  * @child: child to add
106  * @type: kind of child or %NULL
107  *
108  * Adds a child to @buildable. @type is an optional string
109  * describing how the child should be added.
110  *
111  * Since: 2.12
112  **/
113 void
114 gtk_buildable_add_child (GtkBuildable *buildable,
115                          GtkBuilder   *builder,
116                          GObject      *child,
117                          const gchar  *type)
118 {
119   GtkBuildableIface *iface;
120
121   g_return_if_fail (GTK_IS_BUILDABLE (buildable));
122   g_return_if_fail (GTK_IS_BUILDER (builder));
123
124   iface = GTK_BUILDABLE_GET_IFACE (buildable);
125   g_return_if_fail (iface->add_child != NULL);
126
127   (* iface->add_child) (buildable, builder, child, type);
128 }
129
130 /**
131  * gtk_buildable_set_buildable_property:
132  * @buildable: a #GtkBuildable
133  * @builder: a #GtkBuilder
134  * @name: name of property
135  * @value: value of property
136  *
137  * Sets the property name @name to @value on the @buildable object.
138  *
139  * Since: 2.12
140  **/
141 void
142 gtk_buildable_set_buildable_property (GtkBuildable *buildable,
143                                       GtkBuilder   *builder,
144                                       const gchar  *name,
145                                       const GValue *value)
146 {
147   GtkBuildableIface *iface;
148
149   g_return_if_fail (GTK_IS_BUILDABLE (buildable));
150   g_return_if_fail (GTK_IS_BUILDER (builder));
151   g_return_if_fail (name != NULL);
152   g_return_if_fail (value != NULL);
153
154   iface = GTK_BUILDABLE_GET_IFACE (buildable);
155   if (iface->set_buildable_property)
156     (* iface->set_buildable_property) (buildable, builder, name, value);
157   else
158     g_object_set_property (G_OBJECT (buildable), name, value);
159 }
160
161 /**
162  * gtk_buildable_parser_finished:
163  * @buildable: a #GtkBuildable
164  * @builder: a #GtkBuilder
165  *
166  * Called when the builder finishes the parsing of a 
167  * <link linkend="BUILDER-UI">GtkBuilder UI definition</link>. 
168  * Note that this will be called once for each time 
169  * gtk_builder_add_from_file() or gtk_builder_add_from_string() 
170  * is called on a builder.
171  *
172  * Since: 2.12
173  **/
174 void
175 gtk_buildable_parser_finished (GtkBuildable *buildable,
176                                GtkBuilder   *builder)
177 {
178   GtkBuildableIface *iface;
179
180   g_return_if_fail (GTK_IS_BUILDABLE (buildable));
181   g_return_if_fail (GTK_IS_BUILDER (builder));
182
183   iface = GTK_BUILDABLE_GET_IFACE (buildable);
184   if (iface->parser_finished)
185     (* iface->parser_finished) (buildable, builder);
186 }
187
188 /**
189  * gtk_buildable_construct_child:
190  * @buildable: A #GtkBuildable
191  * @builder: #GtkBuilder used to construct this object
192  * @name: name of child to construct
193  *
194  * Constructs a child of @buildable with the name @name. 
195  *
196  * #GtkBuilder calls this function if a "constructor" has been
197  * specified in the UI definition.
198  *
199  * Returns: the constructed child
200  *
201  * Since: 2.12
202  **/
203 GObject *
204 gtk_buildable_construct_child (GtkBuildable *buildable,
205                                GtkBuilder   *builder,
206                                const gchar  *name)
207 {
208   GtkBuildableIface *iface;
209
210   g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), NULL);
211   g_return_val_if_fail (GTK_IS_BUILDER (builder), NULL);
212   g_return_val_if_fail (name != NULL, NULL);
213
214   iface = GTK_BUILDABLE_GET_IFACE (buildable);
215   g_return_val_if_fail (iface->construct_child != NULL, NULL);
216
217   return (* iface->construct_child) (buildable, builder, name);
218 }
219
220 /**
221  * gtk_buildable_custom_tag_start:
222  * @buildable: a #GtkBuildable
223  * @builder: a #GtkBuilder used to construct this object
224  * @child: child object or %NULL for non-child tags
225  * @tagname: name of tag
226  * @parser: a #GMarkupParser structure to fill in
227  * @data: return location for user data that will be passed in 
228  *   to parser functions
229  *
230  * This is called for each unknown element under &lt;child&gt;.
231  * 
232  * Returns: %TRUE if a object has a custom implementation, %FALSE
233  *          if it doesn't.
234  *
235  * Since: 2.12
236  **/
237 gboolean
238 gtk_buildable_custom_tag_start (GtkBuildable  *buildable,
239                                 GtkBuilder    *builder,
240                                 GObject       *child,
241                                 const gchar   *tagname,
242                                 GMarkupParser *parser,
243                                 gpointer      *data)
244 {
245   GtkBuildableIface *iface;
246
247   g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), FALSE);
248   g_return_val_if_fail (GTK_IS_BUILDER (builder), FALSE);
249   g_return_val_if_fail (tagname != NULL, FALSE);
250
251   iface = GTK_BUILDABLE_GET_IFACE (buildable);
252   g_return_val_if_fail (iface->custom_tag_start != NULL, FALSE);
253
254   return (* iface->custom_tag_start) (buildable, builder, child,
255                                       tagname, parser, data);
256 }
257
258 /**
259  * gtk_buildable_custom_tag_end:
260  * @buildable: A #GtkBuildable
261  * @builder: #GtkBuilder used to construct this object
262  * @child: child object or %NULL for non-child tags
263  * @tagname: name of tag
264  * @data: user data that will be passed in to parser functions
265  *
266  * This is called at the end of each custom element handled by 
267  * the buildable.
268  *
269  * Since: 2.12
270  **/
271 void
272 gtk_buildable_custom_tag_end (GtkBuildable  *buildable,
273                               GtkBuilder    *builder,
274                               GObject       *child,
275                               const gchar   *tagname,
276                               gpointer      *data)
277 {
278   GtkBuildableIface *iface;
279
280   g_return_if_fail (GTK_IS_BUILDABLE (buildable));
281   g_return_if_fail (GTK_IS_BUILDER (builder));
282   g_return_if_fail (tagname != NULL);
283
284   iface = GTK_BUILDABLE_GET_IFACE (buildable);
285   if (iface->custom_tag_end)
286     (* iface->custom_tag_end) (buildable, builder, child, tagname, data);
287 }
288
289 /**
290  * gtk_buildable_custom_finished:
291  * @buildable: a #GtkBuildable
292  * @builder: a #GtkBuilder
293  * @child: child object or %NULL for non-child tags
294  * @tagname: the name of the tag
295  * @data: user data created in custom_tag_start
296  *
297  * This is similar to gtk_buildable_parser_finished() but is
298  * called once for each custom tag handled by the @buildable.
299  * 
300  * Since: 2.12
301  **/
302 void
303 gtk_buildable_custom_finished (GtkBuildable  *buildable,
304                                GtkBuilder    *builder,
305                                GObject       *child,
306                                const gchar   *tagname,
307                                gpointer       data)
308 {
309   GtkBuildableIface *iface;
310
311   g_return_if_fail (GTK_IS_BUILDABLE (buildable));
312   g_return_if_fail (GTK_IS_BUILDER (builder));
313
314   iface = GTK_BUILDABLE_GET_IFACE (buildable);
315   if (iface->custom_finished)
316     (* iface->custom_finished) (buildable, builder, child, tagname, data);
317 }
318
319 /**
320  * gtk_buildable_get_internal_child:
321  * @buildable: a #GtkBuildable
322  * @builder: a #GtkBuilder
323  * @childname: name of child
324  *
325  * Get the internal child called @childname of the @buildable object.
326  *
327  * Returns: the internal child of the buildable object 
328  *
329  * Since: 2.12
330  **/
331 GObject *
332 gtk_buildable_get_internal_child (GtkBuildable *buildable,
333                                   GtkBuilder   *builder,
334                                   const gchar  *childname)
335 {
336   GtkBuildableIface *iface;
337
338   g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), NULL);
339   g_return_val_if_fail (GTK_IS_BUILDER (builder), NULL);
340   g_return_val_if_fail (childname != NULL, NULL);
341
342   iface = GTK_BUILDABLE_GET_IFACE (buildable);
343   if (!iface->get_internal_child)
344     return NULL;
345
346   return (* iface->get_internal_child) (buildable, builder, childname);
347 }
348
349 #define __GTK_BUILDABLE_C__
350 #include "gtkaliasdef.c"