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
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.
83 * #GtkWidget implements this to map the buildable name to the widget name
85 * Returns: the name set with gtk_buildable_set_name()
90 gtk_buildable_get_name (GtkBuildable *buildable)
92 GtkBuildableIface *iface;
94 g_return_val_if_fail (GTK_IS_BUILDABLE (buildable), NULL);
96 iface = GTK_BUILDABLE_GET_IFACE (buildable);
99 return (* iface->get_name) (buildable);
101 return (const gchar*)g_object_get_data (G_OBJECT (buildable),
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
112 * Add a child to a buildable. type is an optional string
113 * describing how the child should be added.
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.
122 gtk_buildable_add_child (GtkBuildable *buildable,
127 GtkBuildableIface *iface;
129 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
130 g_return_if_fail (GTK_IS_BUILDER (builder));
132 iface = GTK_BUILDABLE_GET_IFACE (buildable);
133 g_return_if_fail (iface->add_child != NULL);
135 (* iface->add_child) (buildable, builder, child, type);
139 * gtk_buildable_set_buildable_property:
140 * @buildable: a #GtkBuildable
141 * @builder: a #GtkBuilder
142 * @name: name of property
143 * @value: value of property
145 * Sets the property name @name to @value on the buildable object @buildable
146 * which is created by the @builder.
148 * This is optional to implement and is normally not needed.
149 * g_object_set_property() is used as a fallback.
151 * #GtkWindow implements this to delay showing (::visible) itself until
152 * the whole interface is fully created.
157 gtk_buildable_set_buildable_property (GtkBuildable *buildable,
162 GtkBuildableIface *iface;
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);
169 iface = GTK_BUILDABLE_GET_IFACE (buildable);
170 if (iface->set_buildable_property)
171 (* iface->set_buildable_property) (buildable, builder, name, value);
173 g_object_set_property (G_OBJECT (buildable), name, value);
177 * gtk_buildable_parser_finished:
178 * @buildable: a #GtkBuildable
179 * @builder: a #GtkBuilder
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.
185 * #GtkWindow implements this to delay showing (::visible) itself until
186 * the whole interface is fully created.
191 gtk_buildable_parser_finished (GtkBuildable *buildable,
194 GtkBuildableIface *iface;
196 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
197 g_return_if_fail (GTK_IS_BUILDER (builder));
199 iface = GTK_BUILDABLE_GET_IFACE (buildable);
200 if (iface->parser_finished)
201 (* iface->parser_finished) (buildable, builder);
205 * gtk_buildable_construct_child
206 * @buildable: A #GtkBuildable
207 * @builder: #GtkBuilder used to construct this object
208 * @name: name of child to construct
210 * Construct a child of @buildable with the name @name.
212 * #GtkUIManager implements this to reference to a widget created in a
213 * <ui> tag which is outside of the normal
214 * <link linkend="BUILDER-UI">GtkBuilder UI definition</link>
217 * Returns: the child with name @name
222 gtk_buildable_construct_child (GtkBuildable *buildable,
226 GtkBuildableIface *iface;
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);
232 iface = GTK_BUILDABLE_GET_IFACE (buildable);
233 g_return_val_if_fail (iface->construct_child != NULL, NULL);
235 return (* iface->construct_child) (buildable, builder, name);
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
247 * This is called when an unknown tag under <child> tag is found.
249 * Called when an unknown tag is present under a <child> 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.
255 * #GtkWidget implements this and parsers all <accelerator> tags to
256 * keyboard accelerators.
257 * #GtkContainer implements this to map properties defined under
258 * <packing> tag to child properties.
260 * Returns: %TRUE if a object has a custom implementation, %FALSE
266 gtk_buildable_custom_tag_start (GtkBuildable *buildable,
269 const gchar *tagname,
270 GMarkupParser *parser,
273 GtkBuildableIface *iface;
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);
279 iface = GTK_BUILDABLE_GET_IFACE (buildable);
280 g_return_val_if_fail (iface->custom_tag_start != NULL, FALSE);
282 return (* iface->custom_tag_start) (buildable, builder, child,
283 tagname, parser, data);
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
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.
300 gtk_buildable_custom_tag_end (GtkBuildable *buildable,
303 const gchar *tagname,
306 GtkBuildableIface *iface;
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);
312 iface = GTK_BUILDABLE_GET_IFACE (buildable);
313 if (iface->custom_tag_end)
314 (* iface->custom_tag_end) (buildable, builder, child, tagname, data);
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
325 * This is similar to gtk_buildable_parser_finished() but is
326 * called once for each custom tag handled by the @buildable.
331 gtk_buildable_custom_finished (GtkBuildable *buildable,
334 const gchar *tagname,
337 GtkBuildableIface *iface;
339 g_return_if_fail (GTK_IS_BUILDABLE (buildable));
340 g_return_if_fail (GTK_IS_BUILDER (builder));
342 iface = GTK_BUILDABLE_GET_IFACE (buildable);
343 if (iface->custom_finished)
344 (* iface->custom_finished) (buildable, builder, child, tagname, data);
348 * gtk_buildable_get_internal_child
349 * @buildable: a #GtkBuildable
350 * @builder: a #GtkBuilder
351 * @childname: name of child
353 * Get the internal child called @childname of the @buildable object.
355 * Returns: the internal child of the buildable object
360 gtk_buildable_get_internal_child (GtkBuildable *buildable,
362 const gchar *childname)
364 GtkBuildableIface *iface;
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);
370 iface = GTK_BUILDABLE_GET_IFACE (buildable);
371 if (!iface->get_internal_child)
374 return (* iface->get_internal_child) (buildable, builder, childname);
377 #define __GTK_BUILDABLE_C__
378 #include "gtkaliasdef.c"