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.
26 #include "gtktypeutils.h"
27 #include "gtkbuilderprivate.h"
28 #include "gtkbuilder.h"
29 #include "gtkbuildable.h"
31 #include "gtkversion.h"
32 #include "gtktypeutils.h"
36 static void free_property_info (PropertyInfo *info);
37 static void free_object_info (ObjectInfo *info);
40 state_push (ParserData *data, gpointer info)
42 data->stack = g_slist_prepend (data->stack, info);
45 static inline gpointer
46 state_peek (ParserData *data)
51 return data->stack->data;
54 static inline gpointer
55 state_pop (ParserData *data)
62 old = data->stack->data;
63 data->stack = g_slist_delete_link (data->stack, data->stack);
66 #define state_peek_info(data, st) ((st*)state_peek(data))
67 #define state_pop_info(data, st) ((st*)state_pop(data))
70 error_missing_attribute (ParserData *data,
72 const gchar *attribute,
75 gint line_number, char_number;
77 g_markup_parse_context_get_position (data->ctx,
83 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
84 "%s:%d:%d <%s> requires attribute \"%s\"",
86 line_number, char_number, tag, attribute);
90 error_invalid_attribute (ParserData *data,
92 const gchar *attribute,
95 gint line_number, char_number;
97 g_markup_parse_context_get_position (data->ctx,
103 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
104 "%s:%d:%d '%s' is not a valid attribute of <%s>",
106 line_number, char_number, attribute, tag);
110 error_invalid_tag (ParserData *data,
112 const gchar *expected,
115 gint line_number, char_number;
117 g_markup_parse_context_get_position (data->ctx,
124 GTK_BUILDER_ERROR_INVALID_TAG,
125 "%s:%d:%d '%s' is not a valid tag here, expected a '%s' tag",
127 line_number, char_number, tag, expected);
131 GTK_BUILDER_ERROR_INVALID_TAG,
132 "%s:%d:%d '%s' is not a valid tag here",
134 line_number, char_number, tag);
138 _gtk_builder_boolean_from_string (const gchar *string,
142 gboolean retval = TRUE;
145 g_assert (string != NULL);
146 length = strlen (string);
150 else if (length == 1)
152 gchar c = g_ascii_tolower (string[0]);
153 if (c == 'y' || c == 't' || c == '1')
155 else if (c == 'n' || c == 'f' || c == '0')
162 gchar *lower = g_ascii_strdown (string, length);
164 if (strcmp (lower, "yes") == 0 || strcmp (lower, "true") == 0)
166 else if (strcmp (lower, "no") == 0 || strcmp (lower, "false") == 0)
176 GTK_BUILDER_ERROR_INVALID_VALUE,
177 "could not parse boolean `%s'",
184 builder_construct (ParserData *data,
185 ObjectInfo *object_info,
190 g_assert (object_info != NULL);
192 if (object_info->object)
193 return object_info->object;
195 object_info->properties = g_slist_reverse (object_info->properties);
197 object = _gtk_builder_construct (data->builder, object_info, error);
201 g_assert (G_IS_OBJECT (object));
203 object_info->object = object;
209 _get_type_by_symbol (const gchar* symbol)
211 static GModule *module = NULL;
216 module = g_module_open (NULL, 0);
218 if (!g_module_symbol (module, symbol, (gpointer)&func))
222 if (type == G_TYPE_INVALID)
225 return g_strdup (g_type_name (type));
229 parse_requires (ParserData *data,
230 const gchar *element_name,
232 const gchar **values,
235 RequiresInfo *req_info;
236 const gchar *library = NULL;
237 const gchar *version = NULL;
239 gint i, version_major = 0, version_minor = 0;
240 gint line_number, char_number;
242 g_markup_parse_context_get_position (data->ctx,
246 for (i = 0; names[i] != NULL; i++)
248 if (strcmp (names[i], "lib") == 0)
250 else if (strcmp (names[i], "version") == 0)
253 error_invalid_attribute (data, element_name, names[i], error);
256 if (!library || !version)
258 error_missing_attribute (data, element_name,
259 version ? "lib" : "version", error);
263 if (!(split = g_strsplit (version, ".", 2)) || !split[0] || !split[1])
267 GTK_BUILDER_ERROR_INVALID_VALUE,
268 "%s:%d:%d <%s> attribute has malformed value \"%s\"",
270 line_number, char_number, "version", version);
273 version_major = g_ascii_strtoll (split[0], NULL, 10);
274 version_minor = g_ascii_strtoll (split[1], NULL, 10);
277 req_info = g_slice_new0 (RequiresInfo);
278 req_info->library = g_strdup (library);
279 req_info->major = version_major;
280 req_info->minor = version_minor;
281 state_push (data, req_info);
282 req_info->tag.name = element_name;
286 is_requested_object (const gchar *object,
291 for (l = data->requested_objects; l; l = l->next)
293 if (strcmp (l->data, object) == 0)
301 parse_object (ParserData *data,
302 const gchar *element_name,
304 const gchar **values,
307 ObjectInfo *object_info;
308 ChildInfo* child_info;
310 gchar *object_class = NULL;
311 gchar *object_id = NULL;
312 gchar *constructor = NULL;
314 child_info = state_peek_info (data, ChildInfo);
315 if (child_info && strcmp (child_info->tag.name, "object") == 0)
317 error_invalid_tag (data, element_name, NULL, error);
321 for (i = 0; names[i] != NULL; i++)
323 if (strcmp (names[i], "class") == 0)
324 object_class = g_strdup (values[i]);
325 else if (strcmp (names[i], "id") == 0)
326 object_id = g_strdup (values[i]);
327 else if (strcmp (names[i], "constructor") == 0)
328 constructor = g_strdup (values[i]);
329 else if (strcmp (names[i], "type-func") == 0)
331 /* Call the GType function, and return the name of the GType,
332 * it's guaranteed afterwards that g_type_from_name on the name
333 * will return our GType
335 object_class = _get_type_by_symbol (values[i]);
338 g_set_error (error, GTK_BUILDER_ERROR,
339 GTK_BUILDER_ERROR_INVALID_TYPE_FUNCTION,
340 _("Invalid type function: `%s'"),
347 error_invalid_attribute (data, element_name, names[i], error);
354 error_missing_attribute (data, element_name, "class", error);
360 error_missing_attribute (data, element_name, "id", error);
364 ++data->cur_object_level;
366 /* check if we reached a requested object (if it is specified) */
367 if (data->requested_objects && !data->inside_requested_object)
369 if (is_requested_object (object_id, data))
371 data->requested_object_level = data->cur_object_level;
373 GTK_NOTE (BUILDER, g_print ("requested object \"%s\" found at level %d\n",
375 data->requested_object_level));
377 data->inside_requested_object = TRUE;
383 object_info = g_slice_new0 (ObjectInfo);
384 object_info->class_name = object_class;
385 object_info->id = object_id;
386 object_info->constructor = constructor;
387 state_push (data, object_info);
388 object_info->tag.name = element_name;
391 object_info->parent = (CommonInfo*)child_info;
395 free_object_info (ObjectInfo *info)
397 /* Do not free the signal items, which GtkBuilder takes ownership of */
398 g_slist_free (info->signals);
399 g_slist_foreach (info->properties,
400 (GFunc)free_property_info, NULL);
401 g_slist_free (info->properties);
402 g_free (info->constructor);
403 g_free (info->class_name);
405 g_slice_free (ObjectInfo, info);
409 parse_child (ParserData *data,
410 const gchar *element_name,
412 const gchar **values,
416 ObjectInfo* object_info;
417 ChildInfo *child_info;
420 object_info = state_peek_info (data, ObjectInfo);
421 if (!object_info || strcmp (object_info->tag.name, "object") != 0)
423 error_invalid_tag (data, element_name, NULL, error);
427 child_info = g_slice_new0 (ChildInfo);
428 state_push (data, child_info);
429 child_info->tag.name = element_name;
430 for (i = 0; names[i]; i++)
432 if (strcmp (names[i], "type") == 0)
433 child_info->type = g_strdup (values[i]);
434 else if (strcmp (names[i], "internal-child") == 0)
435 child_info->internal_child = g_strdup (values[i]);
437 error_invalid_attribute (data, element_name, names[i], error);
440 child_info->parent = (CommonInfo*)object_info;
442 object_info->object = builder_construct (data, object_info, error);
446 free_child_info (ChildInfo *info)
449 g_free (info->internal_child);
450 g_slice_free (ChildInfo, info);
454 parse_property (ParserData *data,
455 const gchar *element_name,
457 const gchar **values,
462 gchar *context = NULL;
463 gboolean translatable = FALSE;
464 ObjectInfo *object_info;
467 object_info = state_peek_info (data, ObjectInfo);
468 if (!object_info || strcmp (object_info->tag.name, "object") != 0)
470 error_invalid_tag (data, element_name, NULL, error);
474 for (i = 0; names[i] != NULL; i++)
476 if (strcmp (names[i], "name") == 0)
477 name = g_strdelimit (g_strdup (values[i]), "_", '-');
478 else if (strcmp (names[i], "translatable") == 0)
480 if (!_gtk_builder_boolean_from_string (values[i], &translatable,
484 else if (strcmp (names[i], "comments") == 0)
486 /* do nothing, comments are for translators */
488 else if (strcmp (names[i], "context") == 0)
490 context = g_strdup (values[i]);
494 error_invalid_attribute (data, element_name, names[i], error);
501 error_missing_attribute (data, element_name, "name", error);
505 info = g_slice_new0 (PropertyInfo);
507 info->translatable = translatable;
508 info->context = context;
509 info->text = g_string_new ("");
510 state_push (data, info);
512 info->tag.name = element_name;
516 free_property_info (PropertyInfo *info)
520 g_slice_free (PropertyInfo, info);
524 parse_signal (ParserData *data,
525 const gchar *element_name,
527 const gchar **values,
532 gchar *handler = NULL;
533 gchar *object = NULL;
534 gboolean after = FALSE;
535 gboolean swapped = FALSE;
536 gboolean swapped_set = FALSE;
537 ObjectInfo *object_info;
540 object_info = state_peek_info (data, ObjectInfo);
541 if (!object_info || strcmp (object_info->tag.name, "object") != 0)
543 error_invalid_tag (data, element_name, NULL, error);
547 for (i = 0; names[i] != NULL; i++)
549 if (strcmp (names[i], "name") == 0)
550 name = g_strdup (values[i]);
551 else if (strcmp (names[i], "handler") == 0)
552 handler = g_strdup (values[i]);
553 else if (strcmp (names[i], "after") == 0)
555 if (!_gtk_builder_boolean_from_string (values[i], &after, error))
558 else if (strcmp (names[i], "swapped") == 0)
560 if (!_gtk_builder_boolean_from_string (values[i], &swapped, error))
564 else if (strcmp (names[i], "object") == 0)
565 object = g_strdup (values[i]);
566 else if (strcmp (names[i], "last_modification_time") == 0)
567 /* parse but ignore */
571 error_invalid_attribute (data, element_name, names[i], error);
578 error_missing_attribute (data, element_name, "name", error);
583 error_missing_attribute (data, element_name, "handler", error);
587 /* Swapped defaults to FALSE except when object is set */
588 if (object && !swapped_set)
591 info = g_slice_new0 (SignalInfo);
593 info->handler = handler;
595 info->flags |= G_CONNECT_AFTER;
597 info->flags |= G_CONNECT_SWAPPED;
598 info->connect_object_name = object;
599 state_push (data, info);
601 info->tag.name = element_name;
604 /* Called by GtkBuilder */
606 _free_signal_info (SignalInfo *info,
610 g_free (info->handler);
611 g_free (info->connect_object_name);
612 g_free (info->object_name);
613 g_slice_free (SignalInfo, info);
617 _free_requires_info (RequiresInfo *info,
620 g_free (info->library);
621 g_slice_free (RequiresInfo, info);
625 parse_interface (ParserData *data,
626 const gchar *element_name,
628 const gchar **values,
633 for (i = 0; names[i] != NULL; i++)
635 if (strcmp (names[i], "domain") == 0)
637 g_free (data->domain);
638 data->domain = g_strdup (values[i]);
642 error_invalid_attribute (data, "interface", names[i], error);
647 create_subparser (GObject *object,
649 const gchar *element_name,
650 GMarkupParser *parser,
653 SubParser *subparser;
655 subparser = g_slice_new0 (SubParser);
656 subparser->object = object;
657 subparser->child = child;
658 subparser->tagname = g_strdup (element_name);
659 subparser->start = element_name;
660 subparser->parser = g_memdup (parser, sizeof (GMarkupParser));
661 subparser->data = user_data;
667 free_subparser (SubParser *subparser)
669 g_free (subparser->tagname);
670 g_slice_free (SubParser, subparser);
674 subparser_start (GMarkupParseContext *context,
675 const gchar *element_name,
677 const gchar **values,
681 SubParser *subparser = data->subparser;
683 if (!subparser->start &&
684 strcmp (element_name, subparser->tagname) == 0)
685 subparser->start = element_name;
687 if (subparser->start)
689 if (subparser->parser->start_element)
690 subparser->parser->start_element (context,
691 element_name, names, values,
692 subparser->data, error);
699 subparser_end (GMarkupParseContext *context,
700 const gchar *element_name,
704 if (data->subparser->parser->end_element)
705 data->subparser->parser->end_element (context, element_name,
706 data->subparser->data, error);
708 if (!strcmp (data->subparser->start, element_name) == 0)
711 gtk_buildable_custom_tag_end (GTK_BUILDABLE (data->subparser->object),
713 data->subparser->child,
715 data->subparser->data);
716 g_free (data->subparser->parser);
718 if (GTK_BUILDABLE_GET_IFACE (data->subparser->object)->custom_finished)
719 data->custom_finalizers = g_slist_prepend (data->custom_finalizers,
722 free_subparser (data->subparser);
724 data->subparser = NULL;
728 parse_custom (GMarkupParseContext *context,
729 const gchar *element_name,
731 const gchar **values,
735 CommonInfo* parent_info;
736 GMarkupParser parser;
737 gpointer subparser_data;
741 parent_info = state_peek_info (data, CommonInfo);
745 if (strcmp (parent_info->tag.name, "object") == 0)
747 ObjectInfo* object_info = (ObjectInfo*)parent_info;
748 if (!object_info->object)
750 object_info->properties = g_slist_reverse (object_info->properties);
751 object_info->object = _gtk_builder_construct (data->builder,
754 if (!object_info->object)
755 return TRUE; /* A GError is already set */
757 g_assert (object_info->object);
758 object = object_info->object;
761 else if (strcmp (parent_info->tag.name, "child") == 0)
763 ChildInfo* child_info = (ChildInfo*)parent_info;
765 _gtk_builder_add (data->builder, child_info);
767 object = ((ObjectInfo*)child_info->parent)->object;
768 child = child_info->object;
773 if (!gtk_buildable_custom_tag_start (GTK_BUILDABLE (object),
781 data->subparser = create_subparser (object, child, element_name,
782 &parser, subparser_data);
784 if (parser.start_element)
785 parser.start_element (context,
786 element_name, names, values,
787 subparser_data, error);
792 start_element (GMarkupParseContext *context,
793 const gchar *element_name,
795 const gchar **values,
799 ParserData *data = (ParserData*)user_data;
801 #ifdef GTK_ENABLE_DEBUG
802 if (gtk_debug_flags & GTK_DEBUG_BUILDER)
804 GString *tags = g_string_new ("");
806 for (i = 0; names[i]; i++)
807 g_string_append_printf (tags, "%s=\"%s\" ", names[i], values[i]);
811 g_string_insert_c (tags, 0, ' ');
812 g_string_truncate (tags, tags->len - 1);
814 g_print ("<%s%s>\n", element_name, tags->str);
815 g_string_free (tags, TRUE);
819 if (!data->last_element && strcmp (element_name, "interface") != 0)
821 g_set_error (error, GTK_BUILDER_ERROR,
822 GTK_BUILDER_ERROR_UNHANDLED_TAG,
823 _("Invalid root element: '%s'"),
827 data->last_element = element_name;
830 if (!subparser_start (context, element_name, names, values,
834 if (strcmp (element_name, "requires") == 0)
835 parse_requires (data, element_name, names, values, error);
836 else if (strcmp (element_name, "object") == 0)
837 parse_object (data, element_name, names, values, error);
838 else if (data->requested_objects && !data->inside_requested_object)
840 /* If outside a requested object, simply ignore this tag */
843 else if (strcmp (element_name, "child") == 0)
844 parse_child (data, element_name, names, values, error);
845 else if (strcmp (element_name, "property") == 0)
846 parse_property (data, element_name, names, values, error);
847 else if (strcmp (element_name, "signal") == 0)
848 parse_signal (data, element_name, names, values, error);
849 else if (strcmp (element_name, "interface") == 0)
850 parse_interface (data, element_name, names, values, error);
851 else if (strcmp (element_name, "placeholder") == 0)
853 /* placeholder has no special treatmeant, but it needs an
854 * if clause to avoid an error below.
858 if (!parse_custom (context, element_name, names, values,
860 g_set_error (error, GTK_BUILDER_ERROR,
861 GTK_BUILDER_ERROR_UNHANDLED_TAG,
862 _("Unhandled tag: '%s'"),
866 /* This function is taken from gettext.h
867 * GNU gettext uses '\004' to separate context and msgid in .mo files.
870 _dpgettext (const char *domain,
874 size_t msgctxt_len = strlen (msgctxt) + 1;
875 size_t msgid_len = strlen (msgid) + 1;
876 const char *translation;
879 msg_ctxt_id = g_alloca (msgctxt_len + msgid_len);
881 memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
882 msg_ctxt_id[msgctxt_len - 1] = '\004';
883 memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
885 translation = g_dgettext (domain, msg_ctxt_id);
887 if (translation == msg_ctxt_id)
889 /* try the old way of doing message contexts, too */
890 msg_ctxt_id[msgctxt_len - 1] = '|';
891 translation = g_dgettext (domain, msg_ctxt_id);
893 if (translation == msg_ctxt_id)
901 _gtk_builder_parser_translate (const gchar *domain,
902 const gchar *context,
908 s = _dpgettext (domain, context, text);
910 s = g_dgettext (domain, text);
915 /* Called for close tags </foo> */
917 end_element (GMarkupParseContext *context,
918 const gchar *element_name,
922 ParserData *data = (ParserData*)user_data;
924 GTK_NOTE (BUILDER, g_print ("</%s>\n", element_name));
926 if (data->subparser && data->subparser->start)
928 subparser_end (context, element_name, data, error);
932 if (strcmp (element_name, "requires") == 0)
934 RequiresInfo *req_info = state_pop_info (data, RequiresInfo);
936 /* TODO: Allow third party widget developers to check thier
937 * required versions, possibly throw a signal allowing them
938 * to check thier library versions here.
940 if (!strcmp (req_info->library, "gtk+"))
942 if (!GTK_CHECK_VERSION (req_info->major, req_info->minor, 0))
945 GTK_BUILDER_ERROR_VERSION_MISMATCH,
946 "%s: required %s version %d.%d, current version is %d.%d",
947 data->filename, req_info->library,
948 req_info->major, req_info->minor,
949 GTK_MAJOR_VERSION, GTK_MINOR_VERSION);
952 else if (strcmp (element_name, "interface") == 0)
955 else if (data->requested_objects && !data->inside_requested_object)
957 /* If outside a requested object, simply ignore this tag */
960 else if (strcmp (element_name, "object") == 0)
962 ObjectInfo *object_info = state_pop_info (data, ObjectInfo);
963 ChildInfo* child_info = state_peek_info (data, ChildInfo);
965 if (data->requested_objects && data->inside_requested_object &&
966 (data->cur_object_level == data->requested_object_level))
968 GTK_NOTE (BUILDER, g_print ("requested object end found at level %d\n",
969 data->requested_object_level));
971 data->inside_requested_object = FALSE;
974 --data->cur_object_level;
976 g_assert (data->cur_object_level >= 0);
978 object_info->object = builder_construct (data, object_info, error);
979 if (!object_info->object)
981 free_object_info (object_info);
985 child_info->object = object_info->object;
987 if (GTK_IS_BUILDABLE (object_info->object) &&
988 GTK_BUILDABLE_GET_IFACE (object_info->object)->parser_finished)
989 data->finalizers = g_slist_prepend (data->finalizers, object_info->object);
990 _gtk_builder_add_signals (data->builder, object_info->signals);
992 free_object_info (object_info);
994 else if (strcmp (element_name, "property") == 0)
996 PropertyInfo *prop_info = state_pop_info (data, PropertyInfo);
997 CommonInfo *info = state_peek_info (data, CommonInfo);
999 /* Normal properties */
1000 if (strcmp (info->tag.name, "object") == 0)
1002 ObjectInfo *object_info = (ObjectInfo*)info;
1004 if (prop_info->translatable && prop_info->text->len)
1006 prop_info->data = _gtk_builder_parser_translate (data->domain,
1008 prop_info->text->str);
1009 g_string_free (prop_info->text, TRUE);
1013 prop_info->data = g_string_free (prop_info->text, FALSE);
1017 object_info->properties =
1018 g_slist_prepend (object_info->properties, prop_info);
1021 g_assert_not_reached ();
1023 else if (strcmp (element_name, "child") == 0)
1025 ChildInfo *child_info = state_pop_info (data, ChildInfo);
1027 _gtk_builder_add (data->builder, child_info);
1029 free_child_info (child_info);
1031 else if (strcmp (element_name, "signal") == 0)
1033 SignalInfo *signal_info = state_pop_info (data, SignalInfo);
1034 ObjectInfo *object_info = (ObjectInfo*)state_peek_info (data, CommonInfo);
1035 signal_info->object_name = g_strdup (object_info->id);
1036 object_info->signals =
1037 g_slist_prepend (object_info->signals, signal_info);
1039 else if (strcmp (element_name, "placeholder") == 0)
1044 g_assert_not_reached ();
1048 /* Called for character data */
1049 /* text is not nul-terminated */
1051 text (GMarkupParseContext *context,
1057 ParserData *data = (ParserData*)user_data;
1060 if (data->subparser && data->subparser->start)
1062 GError *tmp_error = NULL;
1064 if (data->subparser->parser->text)
1065 data->subparser->parser->text (context, text, text_len,
1066 data->subparser->data, &tmp_error);
1068 g_propagate_error (error, tmp_error);
1075 info = state_peek_info (data, CommonInfo);
1076 g_assert (info != NULL);
1078 if (strcmp (g_markup_parse_context_get_element (context), "property") == 0)
1080 PropertyInfo *prop_info = (PropertyInfo*)info;
1082 g_string_append_len (prop_info->text, text, text_len);
1087 free_info (CommonInfo *info)
1089 if (strcmp (info->tag.name, "object") == 0)
1090 free_object_info ((ObjectInfo *)info);
1091 else if (strcmp (info->tag.name, "child") == 0)
1092 free_child_info ((ChildInfo *)info);
1093 else if (strcmp (info->tag.name, "property") == 0)
1094 free_property_info ((PropertyInfo *)info);
1095 else if (strcmp (info->tag.name, "signal") == 0)
1096 _free_signal_info ((SignalInfo *)info, NULL);
1097 else if (strcmp (info->tag.name, "requires") == 0)
1098 _free_requires_info ((RequiresInfo *)info, NULL);
1100 g_assert_not_reached ();
1103 static const GMarkupParser parser = {
1112 _gtk_builder_parser_parse_buffer (GtkBuilder *builder,
1113 const gchar *filename,
1114 const gchar *buffer,
1116 gchar **requested_objs,
1122 data = g_new0 (ParserData, 1);
1123 data->builder = builder;
1124 data->filename = filename;
1125 data->domain = g_strdup (gtk_builder_get_translation_domain (builder));
1127 data->requested_objects = NULL;
1132 data->inside_requested_object = FALSE;
1133 for (i = 0; requested_objs[i]; ++i)
1135 data->requested_objects = g_slist_prepend (data->requested_objects,
1136 g_strdup (requested_objs[i]));
1141 /* get all the objects */
1142 data->inside_requested_object = TRUE;
1145 data->ctx = g_markup_parse_context_new (&parser,
1146 G_MARKUP_TREAT_CDATA_AS_TEXT,
1149 if (!g_markup_parse_context_parse (data->ctx, buffer, length, error))
1152 _gtk_builder_finish (builder);
1154 /* Custom parser_finished */
1155 data->custom_finalizers = g_slist_reverse (data->custom_finalizers);
1156 for (l = data->custom_finalizers; l; l = l->next)
1158 SubParser *sub = (SubParser*)l->data;
1160 gtk_buildable_custom_finished (GTK_BUILDABLE (sub->object),
1167 /* Common parser_finished, for all created objects */
1168 data->finalizers = g_slist_reverse (data->finalizers);
1169 for (l = data->finalizers; l; l = l->next)
1171 GtkBuildable *buildable = (GtkBuildable*)l->data;
1172 gtk_buildable_parser_finished (GTK_BUILDABLE (buildable), builder);
1177 g_slist_foreach (data->stack, (GFunc)free_info, NULL);
1178 g_slist_free (data->stack);
1179 g_slist_foreach (data->custom_finalizers, (GFunc)free_subparser, NULL);
1180 g_slist_free (data->custom_finalizers);
1181 g_slist_free (data->finalizers);
1182 g_slist_foreach (data->requested_objects, (GFunc) g_free, NULL);
1183 g_slist_free (data->requested_objects);
1184 g_free (data->domain);
1185 g_markup_parse_context_free (data->ctx);