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"
47 typedef GtkBuildableIface GtkBuildableInterface;
48 G_DEFINE_INTERFACE (GtkBuildable, gtk_buildable, G_TYPE_OBJECT)
51 gtk_buildable_default_init (GtkBuildableInterface *iface)
56 * gtk_buildable_set_name:
57 * @buildable: a #GtkBuildable
60 * Sets the name of the @buildable object.
65 gtk_buildable_set_name (GtkBuildable *buildable,
68 GtkBuildableIface *iface;
70 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
71 g_return_if_fail (name != NULL);
73 iface = GTK_BUILDABLE_GET_IFACE (buildable);
76 (* iface->set_name) (buildable, name);
78 g_object_set_data_full (G_OBJECT (buildable),
85 * gtk_buildable_get_name:
86 * @buildable: a #GtkBuildable
88 * Gets the name of the @buildable object.
90 * #GtkBuilder sets the name based on the the
91 * <link linkend="BUILDER-UI">GtkBuilder UI definition</link>
92 * used to construct the @buildable.
94 * Returns: the name set with gtk_buildable_set_name()
99 gtk_buildable_get_name (GtkBuildable *buildable)
101 GtkBuildableIface *iface;
103 g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), NULL);
105 iface = GTK_BUILDABLE_GET_IFACE (buildable);
108 return (* iface->get_name) (buildable);
110 return (const gchar*)g_object_get_data (G_OBJECT (buildable),
115 * gtk_buildable_add_child:
116 * @buildable: a #GtkBuildable
117 * @builder: a #GtkBuilder
118 * @child: child to add
119 * @type: (allow-none): kind of child or %NULL
121 * Adds a child to @buildable. @type is an optional string
122 * describing how the child should be added.
127 gtk_buildable_add_child (GtkBuildable *buildable,
132 GtkBuildableIface *iface;
134 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
135 g_return_if_fail (GTK_IS_BUILDER (builder));
137 iface = GTK_BUILDABLE_GET_IFACE (buildable);
138 g_return_if_fail (iface->add_child != NULL);
140 (* iface->add_child) (buildable, builder, child, type);
144 * gtk_buildable_set_buildable_property:
145 * @buildable: a #GtkBuildable
146 * @builder: a #GtkBuilder
147 * @name: name of property
148 * @value: value of property
150 * Sets the property name @name to @value on the @buildable object.
155 gtk_buildable_set_buildable_property (GtkBuildable *buildable,
160 GtkBuildableIface *iface;
162 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
163 g_return_if_fail (GTK_IS_BUILDER (builder));
164 g_return_if_fail (name != NULL);
165 g_return_if_fail (value != NULL);
167 iface = GTK_BUILDABLE_GET_IFACE (buildable);
168 if (iface->set_buildable_property)
169 (* iface->set_buildable_property) (buildable, builder, name, value);
171 g_object_set_property (G_OBJECT (buildable), name, value);
175 * gtk_buildable_parser_finished:
176 * @buildable: a #GtkBuildable
177 * @builder: a #GtkBuilder
179 * Called when the builder finishes the parsing of a
180 * <link linkend="BUILDER-UI">GtkBuilder UI definition</link>.
181 * Note that this will be called once for each time
182 * gtk_builder_add_from_file() or gtk_builder_add_from_string()
183 * is called on a builder.
188 gtk_buildable_parser_finished (GtkBuildable *buildable,
191 GtkBuildableIface *iface;
193 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
194 g_return_if_fail (GTK_IS_BUILDER (builder));
196 iface = GTK_BUILDABLE_GET_IFACE (buildable);
197 if (iface->parser_finished)
198 (* iface->parser_finished) (buildable, builder);
202 * gtk_buildable_construct_child:
203 * @buildable: A #GtkBuildable
204 * @builder: #GtkBuilder used to construct this object
205 * @name: name of child to construct
207 * Constructs a child of @buildable with the name @name.
209 * #GtkBuilder calls this function if a "constructor" has been
210 * specified in the UI definition.
212 * Returns: (transfer full): the constructed child
217 gtk_buildable_construct_child (GtkBuildable *buildable,
221 GtkBuildableIface *iface;
223 g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), NULL);
224 g_return_val_if_fail (GTK_IS_BUILDER (builder), NULL);
225 g_return_val_if_fail (name != NULL, NULL);
227 iface = GTK_BUILDABLE_GET_IFACE (buildable);
228 g_return_val_if_fail (iface->construct_child != NULL, NULL);
230 return (* iface->construct_child) (buildable, builder, name);
234 * gtk_buildable_custom_tag_start:
235 * @buildable: a #GtkBuildable
236 * @builder: a #GtkBuilder used to construct this object
237 * @child: (allow-none): child object or %NULL for non-child tags
238 * @tagname: name of tag
239 * @parser: a #GMarkupParser structure to fill in
240 * @data: return location for user data that will be passed in
241 * to parser functions
243 * This is called for each unknown element under <child>.
245 * Returns: %TRUE if a object has a custom implementation, %FALSE
251 gtk_buildable_custom_tag_start (GtkBuildable *buildable,
254 const gchar *tagname,
255 GMarkupParser *parser,
258 GtkBuildableIface *iface;
260 g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), FALSE);
261 g_return_val_if_fail (GTK_IS_BUILDER (builder), FALSE);
262 g_return_val_if_fail (tagname != NULL, FALSE);
264 iface = GTK_BUILDABLE_GET_IFACE (buildable);
265 g_return_val_if_fail (iface->custom_tag_start != NULL, FALSE);
267 return (* iface->custom_tag_start) (buildable, builder, child,
268 tagname, parser, data);
272 * gtk_buildable_custom_tag_end:
273 * @buildable: A #GtkBuildable
274 * @builder: #GtkBuilder used to construct this object
275 * @child: (allow-none): child object or %NULL for non-child tags
276 * @tagname: name of tag
277 * @data: user data that will be passed in to parser functions
279 * This is called at the end of each custom element handled by
285 gtk_buildable_custom_tag_end (GtkBuildable *buildable,
288 const gchar *tagname,
291 GtkBuildableIface *iface;
293 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
294 g_return_if_fail (GTK_IS_BUILDER (builder));
295 g_return_if_fail (tagname != NULL);
297 iface = GTK_BUILDABLE_GET_IFACE (buildable);
298 if (iface->custom_tag_end)
299 (* iface->custom_tag_end) (buildable, builder, child, tagname, data);
303 * gtk_buildable_custom_finished:
304 * @buildable: a #GtkBuildable
305 * @builder: a #GtkBuilder
306 * @child: (allow-none): child object or %NULL for non-child tags
307 * @tagname: the name of the tag
308 * @data: user data created in custom_tag_start
310 * This is similar to gtk_buildable_parser_finished() but is
311 * called once for each custom tag handled by the @buildable.
316 gtk_buildable_custom_finished (GtkBuildable *buildable,
319 const gchar *tagname,
322 GtkBuildableIface *iface;
324 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
325 g_return_if_fail (GTK_IS_BUILDER (builder));
327 iface = GTK_BUILDABLE_GET_IFACE (buildable);
328 if (iface->custom_finished)
329 (* iface->custom_finished) (buildable, builder, child, tagname, data);
333 * gtk_buildable_get_internal_child:
334 * @buildable: a #GtkBuildable
335 * @builder: a #GtkBuilder
336 * @childname: name of child
338 * Get the internal child called @childname of the @buildable object.
340 * Returns: (transfer none): the internal child of the buildable object
345 gtk_buildable_get_internal_child (GtkBuildable *buildable,
347 const gchar *childname)
349 GtkBuildableIface *iface;
351 g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), NULL);
352 g_return_val_if_fail (GTK_IS_BUILDER (builder), NULL);
353 g_return_val_if_fail (childname != NULL, NULL);
355 iface = GTK_BUILDABLE_GET_IFACE (buildable);
356 if (!iface->get_internal_child)
359 return (* iface->get_internal_child) (buildable, builder, childname);