1 | /* GTK - The GIMP Toolkit |
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, see <http://www.gnu.org/licenses/>. |
17 | */ |
18 | |
19 | #ifndef __GTK_BUILDABLE_H__ |
20 | #define __GTK_BUILDABLE_H__ |
21 | |
22 | #if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) |
23 | #error "Only <gtk/gtk.h> can be included directly." |
24 | #endif |
25 | |
26 | #include <gtk/gtkbuilder.h> |
27 | |
28 | G_BEGIN_DECLS |
29 | |
30 | #define GTK_TYPE_BUILDABLE (gtk_buildable_get_type ()) |
31 | #define GTK_BUILDABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_BUILDABLE, GtkBuildable)) |
32 | #define GTK_IS_BUILDABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_BUILDABLE)) |
33 | #define GTK_BUILDABLE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GTK_TYPE_BUILDABLE, GtkBuildableIface)) |
34 | |
35 | typedef struct _GtkBuildable GtkBuildable; /* Dummy typedef */ |
36 | typedef struct _GtkBuildableIface GtkBuildableIface; |
37 | |
38 | typedef struct _GtkBuildableParseContext GtkBuildableParseContext; |
39 | typedef struct _GtkBuildableParser GtkBuildableParser; |
40 | |
41 | /** |
42 | * GtkBuildableParseContext: |
43 | * |
44 | * An opaque context struct for `GtkBuildableParser`. |
45 | */ |
46 | |
47 | /** |
48 | * GtkBuildableParser: |
49 | * @start_element: function called for open elements |
50 | * @end_element: function called for close elements |
51 | * @text: function called for character data |
52 | * @error: function called on error |
53 | * |
54 | * A sub-parser for `GtkBuildable` implementations. |
55 | */ |
56 | struct _GtkBuildableParser |
57 | { |
58 | /* Called for open tags <foo bar="baz"> */ |
59 | void (*start_element) (GtkBuildableParseContext *context, |
60 | const char *element_name, |
61 | const char **attribute_names, |
62 | const char **attribute_values, |
63 | gpointer user_data, |
64 | GError **error); |
65 | |
66 | /* Called for close tags </foo> */ |
67 | void (*end_element) (GtkBuildableParseContext *context, |
68 | const char *element_name, |
69 | gpointer user_data, |
70 | GError **error); |
71 | |
72 | /* Called for character data */ |
73 | /* text is not nul-terminated */ |
74 | void (*text) (GtkBuildableParseContext *context, |
75 | const char *text, |
76 | gsize text_len, |
77 | gpointer user_data, |
78 | GError **error); |
79 | |
80 | /* Called on error, including one set by other |
81 | * methods in the vtable. The GError should not be freed. |
82 | */ |
83 | void (*error) (GtkBuildableParseContext *context, |
84 | GError *error, |
85 | gpointer user_data); |
86 | |
87 | /*< private >*/ |
88 | gpointer padding[4]; |
89 | }; |
90 | |
91 | /** |
92 | * GtkBuildableIface: |
93 | * @g_iface: the parent class |
94 | * @set_id: Stores the id attribute given in the `GtkBuilder` UI definition. |
95 | * `GtkWidget` stores the name as object data. Implement this method if your |
96 | * object has some notion of “ID” and it makes sense to map the XML id |
97 | * attribute to it. |
98 | * @get_id: The getter corresponding to @set_id. Implement this |
99 | * if you implement @set_id. |
100 | * @add_child: Adds a child. The @type parameter can be used to |
101 | * differentiate the kind of child. `GtkWidget` implements this |
102 | * to add event controllers to the widget, `GtkNotebook` uses |
103 | * the @type to distinguish between page labels (of type "page-label") |
104 | * and normal children. |
105 | * @set_buildable_property: Sets a property of a buildable object. |
106 | * It is normally not necessary to implement this, g_object_set_property() |
107 | * is used by default. `GtkWindow` implements this to delay showing itself |
108 | * (i.e. setting the [property@GtkWidget:visible] property) until the whole |
109 | * interface is created. |
110 | * @construct_child: Constructs a child of a buildable that has been |
111 | * specified as “constructor” in the UI definition. This can be used to |
112 | * reference a widget created in a <ui> tag which is outside |
113 | * of the normal GtkBuilder UI definition hierarchy. A reference to the |
114 | * constructed object is returned and becomes owned by the caller. |
115 | * @custom_tag_start: Implement this if the buildable needs to parse |
116 | * content below <child>. To handle an element, the implementation |
117 | * must fill in the @parser and @user_data and return %TRUE. |
118 | * `GtkWidget` implements this to parse accessible attributes specified |
119 | * in <accessibility> elements. |
120 | * Note that @user_data must be freed in @custom_tag_end or @custom_finished. |
121 | * @custom_tag_end: Called for the end tag of each custom element that is |
122 | * handled by the buildable (see @custom_tag_start). |
123 | * @custom_finished: Called for each custom tag handled by the buildable |
124 | * when the builder finishes parsing (see @custom_tag_start) |
125 | * @parser_finished: Called when a builder finishes the parsing |
126 | * of a UI definition. It is normally not necessary to implement this, |
127 | * unless you need to perform special cleanup actions. `GtkWindow` sets |
128 | * the `GtkWidget:visible` property here. |
129 | * @get_internal_child: Returns an internal child of a buildable. |
130 | * `GtkDialog` implements this to give access to its @vbox, making |
131 | * it possible to add children to the vbox in a UI definition. |
132 | * Implement this if the buildable has internal children that may |
133 | * need to be accessed from a UI definition. |
134 | * |
135 | * The `GtkBuildableIface` interface contains methods that are |
136 | * necessary to allow `GtkBuilder` to construct an object from |
137 | * a `GtkBuilder` UI definition. |
138 | */ |
139 | struct _GtkBuildableIface |
140 | { |
141 | GTypeInterface g_iface; |
142 | |
143 | /* virtual table */ |
144 | void (* set_id) (GtkBuildable *buildable, |
145 | const char *id); |
146 | const char * (* get_id) (GtkBuildable *buildable); |
147 | |
148 | /** |
149 | * GtkBuildableIface::add_child: |
150 | * @buildable: a `GtkBuildable` |
151 | * @builder: a `GtkBuilder` |
152 | * @child: child to add |
153 | * @type: (nullable): kind of child or %NULL |
154 | * |
155 | * Adds a child to @buildable. @type is an optional string |
156 | * describing how the child should be added. |
157 | */ |
158 | void (* add_child) (GtkBuildable *buildable, |
159 | GtkBuilder *builder, |
160 | GObject *child, |
161 | const char *type); |
162 | void (* set_buildable_property) (GtkBuildable *buildable, |
163 | GtkBuilder *builder, |
164 | const char *name, |
165 | const GValue *value); |
166 | GObject * (* construct_child) (GtkBuildable *buildable, |
167 | GtkBuilder *builder, |
168 | const char *name); |
169 | |
170 | /** |
171 | * GtkBuildableIface::custom_tag_start: |
172 | * @buildable: a `GtkBuildable` |
173 | * @builder: a `GtkBuilder` used to construct this object |
174 | * @child: (nullable): child object or %NULL for non-child tags |
175 | * @tagname: name of tag |
176 | * @parser: (out): a `GtkBuildableParser` to fill in |
177 | * @data: (out): return location for user data that will be passed in |
178 | * to parser functions |
179 | * |
180 | * Called for each unknown element under `<child>`. |
181 | * |
182 | * Returns: %TRUE if an object has a custom implementation, %FALSE |
183 | * if it doesn't. |
184 | */ |
185 | gboolean (* custom_tag_start) (GtkBuildable *buildable, |
186 | GtkBuilder *builder, |
187 | GObject *child, |
188 | const char *tagname, |
189 | GtkBuildableParser *parser, |
190 | gpointer *data); |
191 | /** |
192 | * GtkBuildableIface::custom_tag_end: |
193 | * @buildable: A `GtkBuildable` |
194 | * @builder: `GtkBuilder` used to construct this object |
195 | * @child: (nullable): child object or %NULL for non-child tags |
196 | * @tagname: name of tag |
197 | * @data: user data that will be passed in to parser functions |
198 | * |
199 | * Called at the end of each custom element handled by |
200 | * the buildable. |
201 | */ |
202 | void (* custom_tag_end) (GtkBuildable *buildable, |
203 | GtkBuilder *builder, |
204 | GObject *child, |
205 | const char *tagname, |
206 | gpointer data); |
207 | /** |
208 | * GtkBuildableIface::custom_finished: |
209 | * @buildable: a `GtkBuildable` |
210 | * @builder: a `GtkBuilder` |
211 | * @child: (nullable): child object or %NULL for non-child tags |
212 | * @tagname: the name of the tag |
213 | * @data: user data created in custom_tag_start |
214 | * |
215 | * Similar to gtk_buildable_parser_finished() but is |
216 | * called once for each custom tag handled by the @buildable. |
217 | */ |
218 | void (* custom_finished) (GtkBuildable *buildable, |
219 | GtkBuilder *builder, |
220 | GObject *child, |
221 | const char *tagname, |
222 | gpointer data); |
223 | void (* parser_finished) (GtkBuildable *buildable, |
224 | GtkBuilder *builder); |
225 | |
226 | /** |
227 | * GtkBuildableIface::get_internal_child: |
228 | * @buildable: a `GtkBuildable` |
229 | * @builder: a `GtkBuilder` |
230 | * @childname: name of child |
231 | * |
232 | * Retrieves the internal child called @childname of the @buildable object. |
233 | * |
234 | * Returns: (transfer none): the internal child of the buildable object |
235 | */ |
236 | GObject * (* get_internal_child) (GtkBuildable *buildable, |
237 | GtkBuilder *builder, |
238 | const char *childname); |
239 | }; |
240 | |
241 | |
242 | GDK_AVAILABLE_IN_ALL |
243 | GType gtk_buildable_get_type (void) G_GNUC_CONST; |
244 | |
245 | GDK_AVAILABLE_IN_ALL |
246 | const char * gtk_buildable_get_buildable_id (GtkBuildable *buildable); |
247 | |
248 | GDK_AVAILABLE_IN_ALL |
249 | void gtk_buildable_parse_context_push (GtkBuildableParseContext *context, |
250 | const GtkBuildableParser *parser, |
251 | gpointer user_data); |
252 | GDK_AVAILABLE_IN_ALL |
253 | gpointer gtk_buildable_parse_context_pop (GtkBuildableParseContext *context); |
254 | GDK_AVAILABLE_IN_ALL |
255 | const char * gtk_buildable_parse_context_get_element (GtkBuildableParseContext *context); |
256 | GDK_AVAILABLE_IN_ALL |
257 | GPtrArray *gtk_buildable_parse_context_get_element_stack (GtkBuildableParseContext *context); |
258 | GDK_AVAILABLE_IN_ALL |
259 | void gtk_buildable_parse_context_get_position (GtkBuildableParseContext *context, |
260 | int *line_number, |
261 | int *char_number); |
262 | |
263 | G_END_DECLS |
264 | |
265 | #endif /* __GTK_BUILDABLE_H__ */ |
266 | |