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.
23 #include "gtkbuildable.h"
24 #include "gtktypeutils.h"
29 gtk_buildable_get_type (void)
31 static GType buildable_type = 0;
35 g_type_register_static_simple (G_TYPE_INTERFACE, I_("GtkBuildable"),
36 sizeof (GtkBuildableIface),
39 return buildable_type;
43 * gtk_buildable_set_name:
44 * @buildable: a #GtkBuildable
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.
50 * #GtkWidget implements this to map the buildable name to the widget name
55 gtk_buildable_set_name (GtkBuildable *buildable,
58 GtkBuildableIface *iface;
60 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
61 g_return_if_fail (name != NULL);
63 iface = GTK_BUILDABLE_GET_IFACE (buildable);
66 (* iface->set_name) (buildable, name);
68 g_object_set_data_full (G_OBJECT (buildable),
75 * gtk_buildable_get_name:
76 * @buildable: a #GtkBuildable
78 * Returns: the buildable name, the name which was set in
79 * the <link linkend="BUILDER-UI">GtkBuilder UI definition</link> used to
80 * construct the @buildable.
82 * #GtkWidget implements this to map the buildable name to the widget name
87 gtk_buildable_get_name (GtkBuildable *buildable)
89 GtkBuildableIface *iface;
91 g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), NULL);
93 iface = GTK_BUILDABLE_GET_IFACE (buildable);
96 return (* iface->get_name) (buildable);
98 return (const gchar*)g_object_get_data (G_OBJECT (buildable),
104 * @buildable: a #GtkBuildable
105 * @builder: a #GtkBuilder
106 * @child: child to add
107 * @type: kind of child or %NULL
109 * Add a child to a buildable. type is an optional string
110 * describing how the child should be added.
112 * #GtkContainer implements this to be able to add a child widget
113 * to the container. #GtkNotebook uses the @type to distinguish between
114 * page labels (@type = "page-label") and normal children.
119 gtk_buildable_add (GtkBuildable *buildable,
124 GtkBuildableIface *iface;
126 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
127 g_return_if_fail (GTK_IS_BUILDER (builder));
129 iface = GTK_BUILDABLE_GET_IFACE (buildable);
130 g_return_if_fail (iface->add != NULL);
132 (* iface->add) (buildable, builder, child, type);
136 * gtk_buildable_set_property:
137 * @buildable: a #GtkBuildable
138 * @builder: a #GtkBuilder
139 * @name: name of property
140 * @value: value of property
142 * Sets the property name @name to @value on the buildable object @buildable
143 * which is created by the @builder.
145 * This is optional to implement and is normally not needed.
146 * g_object_set_property() is used as a fallback.
148 * #GtkWindow implements this to delay showing (::visible) itself until
149 * the whole interface is fully created.
154 gtk_buildable_set_property (GtkBuildable *buildable,
159 GtkBuildableIface *iface;
161 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
162 g_return_if_fail (GTK_IS_BUILDER (builder));
163 g_return_if_fail (name != NULL);
164 g_return_if_fail (value != NULL);
166 iface = GTK_BUILDABLE_GET_IFACE (buildable);
167 if (iface->set_property)
168 (* iface->set_property) (buildable, builder, name, value);
170 g_object_set_property (G_OBJECT (buildable), name, value);
174 * gtk_buildable_parser_finished:
175 * @buildable: a #GtkBuildable
176 * @builder: a #GtkBuilder
178 * Finish the parsing of a <link linkend="BUILDER-UI">GtkBuilder UI definition</link>
179 * snippet. Note that this will be called once for each time gtk_builder_add_from_file or
180 * gtk_builder_add_from_string is called on a builder.
182 * #GtkWindow implements this to delay showing (::visible) itself until
183 * the whole interface is fully created.
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 * Construct a child of @buildable with the name @name.
209 * #GtkUIManager implements this to reference to a widget created in a <ui> tag
210 * which is outside of the normal <link linkend="BUILDER-UI">GtkBuilder UI definition</link>
216 gtk_buildable_construct_child (GtkBuildable *buildable,
220 GtkBuildableIface *iface;
222 g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), NULL);
223 g_return_val_if_fail (GTK_IS_BUILDER (builder), NULL);
224 g_return_val_if_fail (name != NULL, NULL);
226 iface = GTK_BUILDABLE_GET_IFACE (buildable);
227 g_return_val_if_fail (iface->construct_child != NULL, NULL);
229 return (* iface->construct_child) (buildable, builder, name);
233 * gtk_buildable_custom_tag_start
234 * @buildable: a #GtkBuildable
235 * @builder: a #GtkBuilder used to construct this object
236 * @child: child object or %NULL for non-child tags
237 * @tagname: name of tag
238 * @parser: a #GMarkupParser structure
239 * @data: user data that will be passed in to parser functions
241 * This is called when an unknown tag under <child> tag is found.
243 * Called when an unknown tag is present under a <child> tag.
244 * If the buildable implementation wishes to handle the tag it should
245 * return %TRUE and fill in the @parser structure. Remember to either
246 * implement custom_tag_end or custom_tag_finish to free
247 * the user data allocated here.
249 * #GtkWidget implements this and parsers all <accelerator> tags to
250 * keyboard accelerators.
251 * #GtkContainer implements this to map properties defined under
252 * <packing> tag to child properties.
254 * Returns: %TRUE if a object has a custom implementation, %FALSE
260 gtk_buildable_custom_tag_start (GtkBuildable *buildable,
263 const gchar *tagname,
264 GMarkupParser *parser,
267 GtkBuildableIface *iface;
269 g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), FALSE);
270 g_return_val_if_fail (GTK_IS_BUILDER (builder), FALSE);
271 g_return_val_if_fail (tagname != NULL, FALSE);
273 iface = GTK_BUILDABLE_GET_IFACE (buildable);
274 g_return_val_if_fail (iface->custom_tag_start != NULL, FALSE);
276 return (* iface->custom_tag_start) (buildable, builder, child,
277 tagname, parser, data);
281 * gtk_buildable_custom_tag_end
282 * @buildable: A #GtkBuildable
283 * @builder: #GtkBuilder used to construct this object
284 * @child: child object or %NULL for non-child tags
285 * @tagname: name of tag
286 * @data: user data that will be passed in to parser functions
288 * This is called for each custom tag handled by the buildable.
289 * It will be called when the end of the tag is reached.
294 gtk_buildable_custom_tag_end (GtkBuildable *buildable,
297 const gchar *tagname,
300 GtkBuildableIface *iface;
302 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
303 g_return_if_fail (GTK_IS_BUILDER (builder));
304 g_return_if_fail (tagname != NULL);
306 iface = GTK_BUILDABLE_GET_IFACE (buildable);
307 if (iface->custom_tag_end)
308 (* iface->custom_tag_end) (buildable, builder, child, tagname, data);
312 * gtk_buildable_custom_finished:
313 * @buildable: a #GtkBuildable
314 * @builder: a #GtkBuilder
315 * @child: child object or %NULL for non-child tags
316 * @tagname: the name of the tag
317 * @data: user data created in custom_tag_start
319 * This is similar to gtk_buildable_parser_finished() but is
320 * called once for each custom tag handled by the @buildable.
325 gtk_buildable_custom_finished (GtkBuildable *buildable,
328 const gchar *tagname,
331 GtkBuildableIface *iface;
333 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
334 g_return_if_fail (GTK_IS_BUILDER (builder));
336 iface = GTK_BUILDABLE_GET_IFACE (buildable);
337 if (iface->custom_finished)
338 (* iface->custom_finished) (buildable, builder, child, tagname, data);
342 * gtk_buildable_get_internal_child
343 * @buildable: a #GtkBuildable
344 * @builder: a #GtkBuilder
345 * @childname: name of child
347 * Get the internal child called @child of the @buildable object.
349 * Return: the internal child of the buildable object
354 gtk_buildable_get_internal_child (GtkBuildable *buildable,
356 const gchar *childname)
358 GtkBuildableIface *iface;
360 g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), NULL);
361 g_return_val_if_fail (GTK_IS_BUILDER (builder), NULL);
362 g_return_val_if_fail (childname != NULL, NULL);
364 iface = GTK_BUILDABLE_GET_IFACE (buildable);
365 if (!iface->get_internal_child)
368 return (* iface->get_internal_child) (buildable, builder, childname);
371 #define __GTK_BUILDABLE_C__
372 #include "gtkaliasdef.c"