2 * Copyright (C) 2006-2007 Async Open Source,
3 * Johan Dahlin <jdahlin@async.com.br>
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.
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.
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.
22 * SECTION:gtkbuildable
23 * @Short_description: Interface for objects that can be built by GtkBuilder
24 * @Title: GtkBuildable
26 * GtkBuildable allows objects to extend and customize thier deserialization
27 * from <link linkend="BUILDER-UI">GtkBuilder UI descriptions</link>.
28 * The interface includes methods for setting names and properties of objects,
29 * parsing custom tags and constructing child objects.
31 * The GtkBuildable interface is implemented by all widgets and
32 * many of the non-widget objects that are provided by GTK+. The
33 * main user of this interface is #GtkBuilder, there should be
34 * very little need for applications to call any
35 * <function>gtk_buildable_...</function> functions.
37 * <note><para>An object only needs to implement this interface if it needs
38 * to extend the #GtkBuilder format or run any extra routines at deserialization time</para></note>
42 #include "gtkbuildable.h"
43 #include "gtktypeutils.h"
48 typedef GtkBuildableIface GtkBuildableInterface;
49 G_DEFINE_INTERFACE (GtkBuildable, gtk_buildable, G_TYPE_OBJECT)
52 gtk_buildable_default_init (GtkBuildableInterface *iface)
57 * gtk_buildable_set_name:
58 * @buildable: a #GtkBuildable
61 * Sets the name of the @buildable object.
66 gtk_buildable_set_name (GtkBuildable *buildable,
69 GtkBuildableIface *iface;
71 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
72 g_return_if_fail (name != NULL);
74 iface = GTK_BUILDABLE_GET_IFACE (buildable);
77 (* iface->set_name) (buildable, name);
79 g_object_set_data_full (G_OBJECT (buildable),
86 * gtk_buildable_get_name:
87 * @buildable: a #GtkBuildable
89 * Gets the name of the @buildable object.
91 * #GtkBuilder sets the name based on the the
92 * <link linkend="BUILDER-UI">GtkBuilder UI definition</link>
93 * used to construct the @buildable.
95 * Returns: the name set with gtk_buildable_set_name()
100 gtk_buildable_get_name (GtkBuildable *buildable)
102 GtkBuildableIface *iface;
104 g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), NULL);
106 iface = GTK_BUILDABLE_GET_IFACE (buildable);
109 return (* iface->get_name) (buildable);
111 return (const gchar*)g_object_get_data (G_OBJECT (buildable),
116 * gtk_buildable_add_child:
117 * @buildable: a #GtkBuildable
118 * @builder: a #GtkBuilder
119 * @child: child to add
120 * @type: (allow-none): kind of child or %NULL
122 * Adds a child to @buildable. @type is an optional string
123 * describing how the child should be added.
128 gtk_buildable_add_child (GtkBuildable *buildable,
133 GtkBuildableIface *iface;
135 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
136 g_return_if_fail (GTK_IS_BUILDER (builder));
138 iface = GTK_BUILDABLE_GET_IFACE (buildable);
139 g_return_if_fail (iface->add_child != NULL);
141 (* iface->add_child) (buildable, builder, child, type);
145 * gtk_buildable_set_buildable_property:
146 * @buildable: a #GtkBuildable
147 * @builder: a #GtkBuilder
148 * @name: name of property
149 * @value: value of property
151 * Sets the property name @name to @value on the @buildable object.
156 gtk_buildable_set_buildable_property (GtkBuildable *buildable,
161 GtkBuildableIface *iface;
163 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
164 g_return_if_fail (GTK_IS_BUILDER (builder));
165 g_return_if_fail (name != NULL);
166 g_return_if_fail (value != NULL);
168 iface = GTK_BUILDABLE_GET_IFACE (buildable);
169 if (iface->set_buildable_property)
170 (* iface->set_buildable_property) (buildable, builder, name, value);
172 g_object_set_property (G_OBJECT (buildable), name, value);
176 * gtk_buildable_parser_finished:
177 * @buildable: a #GtkBuildable
178 * @builder: a #GtkBuilder
180 * Called when the builder finishes the parsing of a
181 * <link linkend="BUILDER-UI">GtkBuilder UI definition</link>.
182 * Note that this will be called once for each time
183 * gtk_builder_add_from_file() or gtk_builder_add_from_string()
184 * is called on a builder.
189 gtk_buildable_parser_finished (GtkBuildable *buildable,
192 GtkBuildableIface *iface;
194 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
195 g_return_if_fail (GTK_IS_BUILDER (builder));
197 iface = GTK_BUILDABLE_GET_IFACE (buildable);
198 if (iface->parser_finished)
199 (* iface->parser_finished) (buildable, builder);
203 * gtk_buildable_construct_child:
204 * @buildable: A #GtkBuildable
205 * @builder: #GtkBuilder used to construct this object
206 * @name: name of child to construct
208 * Constructs a child of @buildable with the name @name.
210 * #GtkBuilder calls this function if a "constructor" has been
211 * specified in the UI definition.
213 * Returns: the constructed child
218 gtk_buildable_construct_child (GtkBuildable *buildable,
222 GtkBuildableIface *iface;
224 g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), NULL);
225 g_return_val_if_fail (GTK_IS_BUILDER (builder), NULL);
226 g_return_val_if_fail (name != NULL, NULL);
228 iface = GTK_BUILDABLE_GET_IFACE (buildable);
229 g_return_val_if_fail (iface->construct_child != NULL, NULL);
231 return (* iface->construct_child) (buildable, builder, name);
235 * gtk_buildable_custom_tag_start:
236 * @buildable: a #GtkBuildable
237 * @builder: a #GtkBuilder used to construct this object
238 * @child: (allow-none): child object or %NULL for non-child tags
239 * @tagname: name of tag
240 * @parser: a #GMarkupParser structure to fill in
241 * @data: return location for user data that will be passed in
242 * to parser functions
244 * This is called for each unknown element under <child>.
246 * Returns: %TRUE if a object has a custom implementation, %FALSE
252 gtk_buildable_custom_tag_start (GtkBuildable *buildable,
255 const gchar *tagname,
256 GMarkupParser *parser,
259 GtkBuildableIface *iface;
261 g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), FALSE);
262 g_return_val_if_fail (GTK_IS_BUILDER (builder), FALSE);
263 g_return_val_if_fail (tagname != NULL, FALSE);
265 iface = GTK_BUILDABLE_GET_IFACE (buildable);
266 g_return_val_if_fail (iface->custom_tag_start != NULL, FALSE);
268 return (* iface->custom_tag_start) (buildable, builder, child,
269 tagname, parser, data);
273 * gtk_buildable_custom_tag_end:
274 * @buildable: A #GtkBuildable
275 * @builder: #GtkBuilder used to construct this object
276 * @child: (allow-none): child object or %NULL for non-child tags
277 * @tagname: name of tag
278 * @data: user data that will be passed in to parser functions
280 * This is called at the end of each custom element handled by
286 gtk_buildable_custom_tag_end (GtkBuildable *buildable,
289 const gchar *tagname,
292 GtkBuildableIface *iface;
294 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
295 g_return_if_fail (GTK_IS_BUILDER (builder));
296 g_return_if_fail (tagname != NULL);
298 iface = GTK_BUILDABLE_GET_IFACE (buildable);
299 if (iface->custom_tag_end)
300 (* iface->custom_tag_end) (buildable, builder, child, tagname, data);
304 * gtk_buildable_custom_finished:
305 * @buildable: a #GtkBuildable
306 * @builder: a #GtkBuilder
307 * @child: (allow-none): child object or %NULL for non-child tags
308 * @tagname: the name of the tag
309 * @data: user data created in custom_tag_start
311 * This is similar to gtk_buildable_parser_finished() but is
312 * called once for each custom tag handled by the @buildable.
317 gtk_buildable_custom_finished (GtkBuildable *buildable,
320 const gchar *tagname,
323 GtkBuildableIface *iface;
325 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
326 g_return_if_fail (GTK_IS_BUILDER (builder));
328 iface = GTK_BUILDABLE_GET_IFACE (buildable);
329 if (iface->custom_finished)
330 (* iface->custom_finished) (buildable, builder, child, tagname, data);
334 * gtk_buildable_get_internal_child:
335 * @buildable: a #GtkBuildable
336 * @builder: a #GtkBuilder
337 * @childname: name of child
339 * Get the internal child called @childname of the @buildable object.
341 * Returns: the internal child of the buildable object
346 gtk_buildable_get_internal_child (GtkBuildable *buildable,
348 const gchar *childname)
350 GtkBuildableIface *iface;
352 g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), NULL);
353 g_return_val_if_fail (GTK_IS_BUILDER (builder), NULL);
354 g_return_val_if_fail (childname != NULL, NULL);
356 iface = GTK_BUILDABLE_GET_IFACE (buildable);
357 if (!iface->get_internal_child)
360 return (* iface->get_internal_child) (buildable, builder, childname);
363 #define __GTK_BUILDABLE_C__
364 #include "gtkaliasdef.c"