2 * GTK - The GIMP Toolkit
3 * Copyright (C) 1998, 1999 Red Hat, Inc.
6 * This Library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This Library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with the Gnome Library; see the file COPYING.LIB. If not,
18 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * Author: James Henstridge <james@daa.com.au>
25 * Modified by the GTK+ Team and others 2003. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
35 #include "gtkmarshalers.h"
37 #include "gtkmenubar.h"
38 #include "gtkmenushell.h"
39 #include "gtkmenutoolbutton.h"
40 #include "gtkseparatormenuitem.h"
41 #include "gtkseparatortoolitem.h"
42 #include "gtktearoffmenuitem.h"
43 #include "gtktoolbar.h"
44 #include "gtkuimanager.h"
45 #include "gtkprivate.h"
48 #undef DEBUG_UI_MANAGER
57 NODE_TYPE_MENU_PLACEHOLDER,
58 NODE_TYPE_TOOLBAR_PLACEHOLDER,
66 typedef struct _Node Node;
76 GtkWidget *extra; /* second separator for placeholders */
81 guint expand : 1; /* used for separators */
84 #define GTK_UI_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_UI_MANAGER, GtkUIManagerPrivate))
86 struct _GtkUIManagerPrivate
88 GtkAccelGroup *accel_group;
97 gboolean add_tearoffs;
100 #define NODE_INFO(node) ((Node *)node->data)
102 typedef struct _NodeUIReference NodeUIReference;
104 struct _NodeUIReference
110 static void gtk_ui_manager_class_init (GtkUIManagerClass *class);
111 static void gtk_ui_manager_init (GtkUIManager *self);
112 static void gtk_ui_manager_finalize (GObject *object);
113 static void gtk_ui_manager_set_property (GObject *object,
117 static void gtk_ui_manager_get_property (GObject *object,
121 static GtkWidget * gtk_ui_manager_real_get_widget (GtkUIManager *manager,
123 static GtkAction * gtk_ui_manager_real_get_action (GtkUIManager *manager,
125 static void queue_update (GtkUIManager *self);
126 static void dirty_all_nodes (GtkUIManager *self);
127 static void mark_node_dirty (GNode *node);
128 static GNode * get_child_node (GtkUIManager *self,
131 const gchar *childname,
132 gint childname_length,
136 static GNode * get_node (GtkUIManager *self,
140 static gboolean free_node (GNode *node);
141 static void node_prepend_ui_reference (GNode *node,
143 GQuark action_quark);
144 static void node_remove_ui_reference (GNode *node,
166 static GObjectClass *parent_class = NULL;
167 static guint ui_manager_signals[LAST_SIGNAL] = { 0 };
170 gtk_ui_manager_get_type (void)
172 static GtkType type = 0;
176 static const GTypeInfo type_info =
178 sizeof (GtkUIManagerClass),
179 (GBaseInitFunc) NULL,
180 (GBaseFinalizeFunc) NULL,
181 (GClassInitFunc) gtk_ui_manager_class_init,
182 (GClassFinalizeFunc) NULL,
185 sizeof (GtkUIManager),
187 (GInstanceInitFunc) gtk_ui_manager_init,
190 type = g_type_register_static (G_TYPE_OBJECT,
198 gtk_ui_manager_class_init (GtkUIManagerClass *klass)
200 GObjectClass *gobject_class;
202 parent_class = g_type_class_peek_parent (klass);
204 gobject_class = G_OBJECT_CLASS (klass);
206 gobject_class->finalize = gtk_ui_manager_finalize;
207 gobject_class->set_property = gtk_ui_manager_set_property;
208 gobject_class->get_property = gtk_ui_manager_get_property;
209 klass->get_widget = gtk_ui_manager_real_get_widget;
210 klass->get_action = gtk_ui_manager_real_get_action;
213 * GtkUIManager:add-tearoffs:
215 * The "add-tearoffs" property controls whether generated menus
216 * have tearoff menu items.
218 * Note that this only affects regular menus. Generated popup
219 * menus never have tearoff menu items.
223 g_object_class_install_property (gobject_class,
225 g_param_spec_boolean ("add-tearoffs",
226 P_("Add tearoffs to menus"),
227 P_("Whether tearoff menu items should be added to menus"),
229 GTK_PARAM_READWRITE));
231 g_object_class_install_property (gobject_class,
233 g_param_spec_string ("ui",
234 P_("Merged UI definition"),
235 P_("An XML string describing the merged UI"),
237 GTK_PARAM_READABLE));
241 * GtkUIManager::add-widget:
242 * @merge: a #GtkUIManager
243 * @widget: the added widget
245 * The add_widget signal is emitted for each generated menubar and toolbar.
246 * It is not emitted for generated popup menus, which can be obtained by
247 * gtk_ui_manager_get_widget().
251 ui_manager_signals[ADD_WIDGET] =
252 g_signal_new (I_("add_widget"),
253 G_OBJECT_CLASS_TYPE (klass),
254 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
255 G_STRUCT_OFFSET (GtkUIManagerClass, add_widget),
257 g_cclosure_marshal_VOID__OBJECT,
262 * GtkUIManager::actions-changed:
263 * @merge: a #GtkUIManager
265 * The "actions-changed" signal is emitted whenever the set of actions
270 ui_manager_signals[ACTIONS_CHANGED] =
271 g_signal_new (I_("actions_changed"),
272 G_OBJECT_CLASS_TYPE (klass),
273 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
274 G_STRUCT_OFFSET (GtkUIManagerClass, actions_changed),
276 g_cclosure_marshal_VOID__VOID,
280 * GtkUIManager::connect-proxy:
281 * @uimanager: the ui manager
282 * @action: the action
285 * The connect_proxy signal is emitted after connecting a proxy to
286 * an action in the group.
288 * This is intended for simple customizations for which a custom action
289 * class would be too clumsy, e.g. showing tooltips for menuitems in the
294 ui_manager_signals[CONNECT_PROXY] =
295 g_signal_new (I_("connect_proxy"),
296 G_OBJECT_CLASS_TYPE (klass),
297 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
298 G_STRUCT_OFFSET (GtkUIManagerClass, connect_proxy),
300 _gtk_marshal_VOID__OBJECT_OBJECT,
306 * GtkUIManager::disconnect-proxy:
307 * @uimanager: the ui manager
308 * @action: the action
311 * The disconnect_proxy signal is emitted after disconnecting a proxy
312 * from an action in the group.
316 ui_manager_signals[DISCONNECT_PROXY] =
317 g_signal_new (I_("disconnect_proxy"),
318 G_OBJECT_CLASS_TYPE (klass),
319 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
320 G_STRUCT_OFFSET (GtkUIManagerClass, disconnect_proxy),
322 _gtk_marshal_VOID__OBJECT_OBJECT,
328 * GtkUIManager::pre-activate:
329 * @uimanager: the ui manager
330 * @action: the action
332 * The pre_activate signal is emitted just before the @action
335 * This is intended for applications to get notification
336 * just before any action is activated.
340 ui_manager_signals[PRE_ACTIVATE] =
341 g_signal_new (I_("pre_activate"),
342 G_OBJECT_CLASS_TYPE (klass),
343 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
344 G_STRUCT_OFFSET (GtkUIManagerClass, pre_activate),
346 _gtk_marshal_VOID__OBJECT,
351 * GtkUIManager::post-activate:
352 * @uimanager: the ui manager
353 * @action: the action
355 * The post_activate signal is emitted just after the @action
358 * This is intended for applications to get notification
359 * just after any action is activated.
363 ui_manager_signals[POST_ACTIVATE] =
364 g_signal_new (I_("post_activate"),
365 G_OBJECT_CLASS_TYPE (klass),
366 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
367 G_STRUCT_OFFSET (GtkUIManagerClass, post_activate),
369 _gtk_marshal_VOID__OBJECT,
373 klass->add_widget = NULL;
374 klass->actions_changed = NULL;
375 klass->connect_proxy = NULL;
376 klass->disconnect_proxy = NULL;
377 klass->pre_activate = NULL;
378 klass->post_activate = NULL;
380 g_type_class_add_private (gobject_class, sizeof (GtkUIManagerPrivate));
385 gtk_ui_manager_init (GtkUIManager *self)
390 self->private_data = GTK_UI_MANAGER_GET_PRIVATE (self);
392 self->private_data->accel_group = gtk_accel_group_new ();
394 self->private_data->root_node = NULL;
395 self->private_data->action_groups = NULL;
397 self->private_data->last_merge_id = 0;
398 self->private_data->add_tearoffs = FALSE;
400 merge_id = gtk_ui_manager_new_merge_id (self);
401 node = get_child_node (self, NULL, NULL, "ui", 2,
402 NODE_TYPE_ROOT, TRUE, FALSE);
403 node_prepend_ui_reference (node, merge_id, 0);
407 gtk_ui_manager_finalize (GObject *object)
409 GtkUIManager *self = GTK_UI_MANAGER (object);
411 if (self->private_data->update_tag != 0)
413 g_source_remove (self->private_data->update_tag);
414 self->private_data->update_tag = 0;
417 g_node_traverse (self->private_data->root_node,
418 G_POST_ORDER, G_TRAVERSE_ALL, -1,
419 (GNodeTraverseFunc)free_node, NULL);
420 g_node_destroy (self->private_data->root_node);
421 self->private_data->root_node = NULL;
423 g_list_foreach (self->private_data->action_groups,
424 (GFunc) g_object_unref, NULL);
425 g_list_free (self->private_data->action_groups);
426 self->private_data->action_groups = NULL;
428 g_object_unref (self->private_data->accel_group);
429 self->private_data->accel_group = NULL;
431 G_OBJECT_CLASS (parent_class)->finalize (object);
435 gtk_ui_manager_set_property (GObject *object,
440 GtkUIManager *self = GTK_UI_MANAGER (object);
444 case PROP_ADD_TEAROFFS:
445 gtk_ui_manager_set_add_tearoffs (self, g_value_get_boolean (value));
448 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
454 gtk_ui_manager_get_property (GObject *object,
459 GtkUIManager *self = GTK_UI_MANAGER (object);
463 case PROP_ADD_TEAROFFS:
464 g_value_set_boolean (value, self->private_data->add_tearoffs);
467 g_value_take_string (value, gtk_ui_manager_get_ui (self));
470 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
476 gtk_ui_manager_real_get_widget (GtkUIManager *self,
481 /* ensure that there are no pending updates before we get the
483 gtk_ui_manager_ensure_update (self);
485 node = get_node (self, path, NODE_TYPE_UNDECIDED, FALSE);
490 return NODE_INFO (node)->proxy;
494 gtk_ui_manager_real_get_action (GtkUIManager *self,
499 /* ensure that there are no pending updates before we get
501 gtk_ui_manager_ensure_update (self);
503 node = get_node (self, path, NODE_TYPE_UNDECIDED, FALSE);
508 return NODE_INFO (node)->action;
513 * gtk_ui_manager_new:
515 * Creates a new ui manager object.
517 * Return value: a new ui manager object.
522 gtk_ui_manager_new (void)
524 return g_object_new (GTK_TYPE_UI_MANAGER, NULL);
529 * gtk_ui_manager_get_add_tearoffs:
530 * @self: a #GtkUIManager
532 * Returns whether menus generated by this #GtkUIManager
533 * will have tearoff menu items.
535 * Return value: whether tearoff menu items are added
540 gtk_ui_manager_get_add_tearoffs (GtkUIManager *self)
542 g_return_val_if_fail (GTK_IS_UI_MANAGER (self), FALSE);
544 return self->private_data->add_tearoffs;
549 * gtk_ui_manager_set_add_tearoffs:
550 * @self: a #GtkUIManager
551 * @add_tearoffs: whether tearoff menu items are added
553 * Sets the "add_tearoffs" property, which controls whether menus
554 * generated by this #GtkUIManager will have tearoff menu items.
556 * Note that this only affects regular menus. Generated popup
557 * menus never have tearoff menu items.
562 gtk_ui_manager_set_add_tearoffs (GtkUIManager *self,
563 gboolean add_tearoffs)
565 g_return_if_fail (GTK_IS_UI_MANAGER (self));
567 add_tearoffs = add_tearoffs != FALSE;
569 if (add_tearoffs != self->private_data->add_tearoffs)
571 self->private_data->add_tearoffs = add_tearoffs;
573 dirty_all_nodes (self);
575 g_object_notify (G_OBJECT (self), "add-tearoffs");
580 cb_proxy_connect_proxy (GtkActionGroup *group,
585 g_signal_emit (self, ui_manager_signals[CONNECT_PROXY], 0, action, proxy);
589 cb_proxy_disconnect_proxy (GtkActionGroup *group,
594 g_signal_emit (self, ui_manager_signals[DISCONNECT_PROXY], 0, action, proxy);
598 cb_proxy_pre_activate (GtkActionGroup *group,
602 g_signal_emit (self, ui_manager_signals[PRE_ACTIVATE], 0, action);
606 cb_proxy_post_activate (GtkActionGroup *group,
610 g_signal_emit (self, ui_manager_signals[POST_ACTIVATE], 0, action);
614 * gtk_ui_manager_insert_action_group:
615 * @self: a #GtkUIManager object
616 * @action_group: the action group to be inserted
617 * @pos: the position at which the group will be inserted.
619 * Inserts an action group into the list of action groups associated
620 * with @self. Actions in earlier groups hide actions with the same
621 * name in later groups.
626 gtk_ui_manager_insert_action_group (GtkUIManager *self,
627 GtkActionGroup *action_group,
630 g_return_if_fail (GTK_IS_UI_MANAGER (self));
631 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
632 g_return_if_fail (g_list_find (self->private_data->action_groups,
633 action_group) == NULL);
635 g_object_ref (action_group);
636 self->private_data->action_groups =
637 g_list_insert (self->private_data->action_groups, action_group, pos);
638 g_object_connect (action_group,
639 "object_signal::connect_proxy", G_CALLBACK (cb_proxy_connect_proxy), self,
640 "object_signal::disconnect_proxy", G_CALLBACK (cb_proxy_disconnect_proxy), self,
641 "object_signal::pre_activate", G_CALLBACK (cb_proxy_pre_activate), self,
642 "object_signal::post_activate", G_CALLBACK (cb_proxy_post_activate), self,
645 /* dirty all nodes, as action bindings may change */
646 dirty_all_nodes (self);
648 g_signal_emit (self, ui_manager_signals[ACTIONS_CHANGED], 0);
652 * gtk_ui_manager_remove_action_group:
653 * @self: a #GtkUIManager object
654 * @action_group: the action group to be removed
656 * Removes an action group from the list of action groups associated
662 gtk_ui_manager_remove_action_group (GtkUIManager *self,
663 GtkActionGroup *action_group)
665 g_return_if_fail (GTK_IS_UI_MANAGER (self));
666 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
667 g_return_if_fail (g_list_find (self->private_data->action_groups,
668 action_group) != NULL);
670 self->private_data->action_groups =
671 g_list_remove (self->private_data->action_groups, action_group);
673 g_object_disconnect (action_group,
674 "any_signal::connect_proxy", G_CALLBACK (cb_proxy_connect_proxy), self,
675 "any_signal::disconnect_proxy", G_CALLBACK (cb_proxy_disconnect_proxy), self,
676 "any_signal::pre_activate", G_CALLBACK (cb_proxy_pre_activate), self,
677 "any_signal::post_activate", G_CALLBACK (cb_proxy_post_activate), self,
679 g_object_unref (action_group);
681 /* dirty all nodes, as action bindings may change */
682 dirty_all_nodes (self);
684 g_signal_emit (self, ui_manager_signals[ACTIONS_CHANGED], 0);
688 * gtk_ui_manager_get_action_groups:
689 * @self: a #GtkUIManager object
691 * Returns the list of action groups associated with @self.
693 * Return value: a #GList of action groups. The list is owned by GTK+
694 * and should not be modified.
699 gtk_ui_manager_get_action_groups (GtkUIManager *self)
701 g_return_val_if_fail (GTK_IS_UI_MANAGER (self), NULL);
703 return self->private_data->action_groups;
707 * gtk_ui_manager_get_accel_group:
708 * @self: a #GtkUIManager object
710 * Returns the #GtkAccelGroup associated with @self.
712 * Return value: the #GtkAccelGroup.
717 gtk_ui_manager_get_accel_group (GtkUIManager *self)
719 g_return_val_if_fail (GTK_IS_UI_MANAGER (self), NULL);
721 return self->private_data->accel_group;
725 * gtk_ui_manager_get_widget:
726 * @self: a #GtkUIManager
729 * Looks up a widget by following a path.
730 * The path consists of the names specified in the XML description of the UI.
731 * separated by '/'. Elements which don't have a name or action attribute in
732 * the XML (e.g. <popup>) can be addressed by their XML element name
733 * (e.g. "popup"). The root element ("/ui") can be omitted in the path.
735 * Note that the widget found by following a path that ends in a <menu>
736 * element is the menuitem to which the menu is attached, not the menu itself.
738 * Also note that the widgets constructed by a ui manager are not tied to
739 * the lifecycle of the ui manager. If you add the widgets returned by this
740 * function to some container or explicitly ref them, they will survive the
741 * destruction of the ui manager.
743 * Return value: the widget found by following the path, or %NULL if no widget
749 gtk_ui_manager_get_widget (GtkUIManager *self,
752 g_return_val_if_fail (GTK_IS_UI_MANAGER (self), NULL);
753 g_return_val_if_fail (path != NULL, NULL);
755 return GTK_UI_MANAGER_GET_CLASS (self)->get_widget (self, path);
759 GtkUIManagerItemType types;
764 collect_toplevels (GNode *node,
767 ToplevelData *data = user_data;
769 if (NODE_INFO (node)->proxy)
771 switch (NODE_INFO (node)->type)
773 case NODE_TYPE_MENUBAR:
774 if (data->types & GTK_UI_MANAGER_MENUBAR)
775 data->list = g_slist_prepend (data->list, NODE_INFO (node)->proxy);
777 case NODE_TYPE_TOOLBAR:
778 if (data->types & GTK_UI_MANAGER_TOOLBAR)
779 data->list = g_slist_prepend (data->list, NODE_INFO (node)->proxy);
781 case NODE_TYPE_POPUP:
782 if (data->types & GTK_UI_MANAGER_POPUP)
783 data->list = g_slist_prepend (data->list, NODE_INFO (node)->proxy);
791 * gtk_ui_manager_get_toplevels:
792 * @self: a #GtkUIManager
793 * @types: specifies the types of toplevel widgets to include. Allowed
794 * types are #GTK_UI_MANAGER_MENUBAR, #GTK_UI_MANAGER_TOOLBAR and
795 * #GTK_UI_MANAGER_POPUP.
797 * Obtains a list of all toplevel widgets of the requested types.
799 * Return value: a newly-allocated of all toplevel widgets of the requested
805 gtk_ui_manager_get_toplevels (GtkUIManager *self,
806 GtkUIManagerItemType types)
810 g_return_val_if_fail (GTK_IS_UI_MANAGER (self), NULL);
811 g_return_val_if_fail ((~(GTK_UI_MANAGER_MENUBAR |
812 GTK_UI_MANAGER_TOOLBAR |
813 GTK_UI_MANAGER_POPUP) & types) == 0, NULL);
819 g_node_children_foreach (self->private_data->root_node,
821 collect_toplevels, &data);
828 * gtk_ui_manager_get_action:
829 * @self: a #GtkUIManager
832 * Looks up an action by following a path. See gtk_ui_manager_get_widget()
833 * for more information about paths.
835 * Return value: the action whose proxy widget is found by following the path,
836 * or %NULL if no widget was found.
841 gtk_ui_manager_get_action (GtkUIManager *self,
844 g_return_val_if_fail (GTK_IS_UI_MANAGER (self), NULL);
845 g_return_val_if_fail (path != NULL, NULL);
847 return GTK_UI_MANAGER_GET_CLASS (self)->get_action (self, path);
851 get_child_node (GtkUIManager *self,
854 const gchar *childname,
855 gint childname_length,
866 for (child = parent->children; child != NULL; child = child->next)
868 if (NODE_INFO (child)->name &&
869 strlen (NODE_INFO (child)->name) == childname_length &&
870 !strncmp (NODE_INFO (child)->name, childname, childname_length))
872 /* if undecided about node type, set it */
873 if (NODE_INFO (child)->type == NODE_TYPE_UNDECIDED)
874 NODE_INFO (child)->type = node_type;
876 /* warn about type mismatch */
877 if (NODE_INFO (child)->type != NODE_TYPE_UNDECIDED &&
878 node_type != NODE_TYPE_UNDECIDED &&
879 NODE_INFO (child)->type != node_type)
880 g_warning ("node type doesn't match %d (%s is type %d)",
882 NODE_INFO (child)->name,
883 NODE_INFO (child)->type);
889 if (!child && create)
893 mnode = g_slice_new0 (Node);
894 mnode->type = node_type;
895 mnode->name = g_strndup (childname, childname_length);
900 child = g_node_insert_before (parent, sibling,
903 child = g_node_insert_after (parent, sibling,
909 child = g_node_prepend_data (parent, mnode);
911 child = g_node_append_data (parent, mnode);
914 mark_node_dirty (child);
919 /* handle root node */
920 if (self->private_data->root_node)
922 child = self->private_data->root_node;
923 if (strncmp (NODE_INFO (child)->name, childname, childname_length) != 0)
924 g_warning ("root node name '%s' doesn't match '%s'",
925 childname, NODE_INFO (child)->name);
926 if (NODE_INFO (child)->type != NODE_TYPE_ROOT)
927 g_warning ("base element must be of type ROOT");
933 mnode = g_slice_new0 (Node);
934 mnode->type = node_type;
935 mnode->name = g_strndup (childname, childname_length);
938 child = self->private_data->root_node = g_node_new (mnode);
946 get_node (GtkUIManager *self,
951 const gchar *pos, *end;
952 GNode *parent, *node;
954 if (strncmp ("/ui", path, 3) == 0)
957 end = path + strlen (path);
959 parent = node = NULL;
965 slash = strchr (pos, '/');
967 length = slash - pos;
969 length = strlen (pos);
971 node = get_child_node (self, parent, NULL, pos, length, NODE_TYPE_UNDECIDED,
976 pos += length + 1; /* move past the node name and the slash too */
980 if (node != NULL && NODE_INFO (node)->type == NODE_TYPE_UNDECIDED)
981 NODE_INFO (node)->type = node_type;
987 node_ui_reference_free (gpointer data)
989 g_slice_free (NodeUIReference, data);
993 free_node (GNode *node)
995 Node *info = NODE_INFO (node);
997 g_list_foreach (info->uifiles, (GFunc) node_ui_reference_free, NULL);
998 g_list_free (info->uifiles);
1001 g_object_unref (info->action);
1003 g_object_unref (info->proxy);
1005 g_object_unref (info->extra);
1006 g_free (info->name);
1007 g_slice_free (Node, info);
1013 * gtk_ui_manager_new_merge_id:
1014 * @self: a #GtkUIManager
1016 * Returns an unused merge id, suitable for use with
1017 * gtk_ui_manager_add_ui().
1019 * Return value: an unused merge id.
1024 gtk_ui_manager_new_merge_id (GtkUIManager *self)
1026 self->private_data->last_merge_id++;
1028 return self->private_data->last_merge_id;
1032 node_prepend_ui_reference (GNode *gnode,
1034 GQuark action_quark)
1036 Node *node = NODE_INFO (gnode);
1037 NodeUIReference *reference = NULL;
1039 if (node->uifiles &&
1040 ((NodeUIReference *)node->uifiles->data)->merge_id == merge_id)
1041 reference = node->uifiles->data;
1044 reference = g_slice_new (NodeUIReference);
1045 node->uifiles = g_list_prepend (node->uifiles, reference);
1048 reference->merge_id = merge_id;
1049 reference->action_quark = action_quark;
1051 mark_node_dirty (gnode);
1055 node_remove_ui_reference (GNode *gnode,
1058 Node *node = NODE_INFO (gnode);
1061 for (p = node->uifiles; p != NULL; p = p->next)
1063 NodeUIReference *reference = p->data;
1065 if (reference->merge_id == merge_id)
1067 if (p == node->uifiles)
1068 mark_node_dirty (gnode);
1069 node->uifiles = g_list_delete_link (node->uifiles, p);
1070 g_slice_free (NodeUIReference, reference);
1077 /* -------------------- The UI file parser -------------------- */
1091 typedef struct _ParseContext ParseContext;
1092 struct _ParseContext
1095 ParseState prev_state;
1105 start_element_handler (GMarkupParseContext *context,
1106 const gchar *element_name,
1107 const gchar **attribute_names,
1108 const gchar **attribute_values,
1112 ParseContext *ctx = user_data;
1113 GtkUIManager *self = ctx->self;
1116 const gchar *node_name;
1117 const gchar *action;
1118 GQuark action_quark;
1120 gboolean expand = FALSE;
1122 gboolean raise_error = TRUE;
1129 for (i = 0; attribute_names[i] != NULL; i++)
1131 if (!strcmp (attribute_names[i], "name"))
1133 node_name = attribute_values[i];
1135 else if (!strcmp (attribute_names[i], "action"))
1137 action = attribute_values[i];
1138 action_quark = g_quark_from_string (attribute_values[i]);
1140 else if (!strcmp (attribute_names[i], "position"))
1142 top = !strcmp (attribute_values[i], "top");
1144 else if (!strcmp (attribute_names[i], "expand"))
1146 expand = !strcmp (attribute_values[i], "true");
1150 gint line_number, char_number;
1152 g_markup_parse_context_get_position (context,
1153 &line_number, &char_number);
1156 G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
1157 _("Unknown attribute '%s' on line %d char %d"),
1159 line_number, char_number);
1164 /* Work out a name for this node. Either the name attribute, or
1165 * the action, or the element name */
1166 if (node_name == NULL)
1171 node_name = element_name;
1174 switch (element_name[0])
1177 if (ctx->state == STATE_ROOT && !strcmp (element_name, "accelerator"))
1179 ctx->state = STATE_ACCELERATOR;
1180 ctx->current = get_child_node (self, ctx->current, NULL,
1181 node_name, strlen (node_name),
1182 NODE_TYPE_ACCELERATOR,
1184 if (NODE_INFO (ctx->current)->action_name == 0)
1185 NODE_INFO (ctx->current)->action_name = action_quark;
1187 node_prepend_ui_reference (ctx->current, ctx->merge_id, action_quark);
1189 raise_error = FALSE;
1193 if (ctx->state == STATE_START && !strcmp (element_name, "ui"))
1195 ctx->state = STATE_ROOT;
1196 ctx->current = self->private_data->root_node;
1197 raise_error = FALSE;
1199 node_prepend_ui_reference (ctx->current, ctx->merge_id, action_quark);
1203 if (ctx->state == STATE_ROOT && !strcmp (element_name, "menubar"))
1205 ctx->state = STATE_MENU;
1206 ctx->current = get_child_node (self, ctx->current, NULL,
1207 node_name, strlen (node_name),
1210 if (NODE_INFO (ctx->current)->action_name == 0)
1211 NODE_INFO (ctx->current)->action_name = action_quark;
1213 node_prepend_ui_reference (ctx->current, ctx->merge_id, action_quark);
1214 mark_node_dirty (ctx->current);
1216 raise_error = FALSE;
1218 else if (ctx->state == STATE_MENU && !strcmp (element_name, "menu"))
1220 ctx->current = get_child_node (self, ctx->current, NULL,
1221 node_name, strlen (node_name),
1224 if (NODE_INFO (ctx->current)->action_name == 0)
1225 NODE_INFO (ctx->current)->action_name = action_quark;
1227 node_prepend_ui_reference (ctx->current, ctx->merge_id, action_quark);
1229 raise_error = FALSE;
1231 else if (ctx->state == STATE_TOOLITEM && !strcmp (element_name, "menu"))
1233 ctx->state = STATE_MENU;
1235 ctx->current = get_child_node (self, g_node_last_child (ctx->current), NULL,
1236 node_name, strlen (node_name),
1239 if (NODE_INFO (ctx->current)->action_name == 0)
1240 NODE_INFO (ctx->current)->action_name = action_quark;
1242 node_prepend_ui_reference (ctx->current, ctx->merge_id, action_quark);
1244 raise_error = FALSE;
1246 else if (ctx->state == STATE_MENU && !strcmp (element_name, "menuitem"))
1250 ctx->state = STATE_MENUITEM;
1251 node = get_child_node (self, ctx->current, NULL,
1252 node_name, strlen (node_name),
1255 if (NODE_INFO (node)->action_name == 0)
1256 NODE_INFO (node)->action_name = action_quark;
1258 node_prepend_ui_reference (node, ctx->merge_id, action_quark);
1260 raise_error = FALSE;
1264 if (ctx->state == STATE_ROOT && !strcmp (element_name, "popup"))
1266 ctx->state = STATE_MENU;
1267 ctx->current = get_child_node (self, ctx->current, NULL,
1268 node_name, strlen (node_name),
1271 if (NODE_INFO (ctx->current)->action_name == 0)
1272 NODE_INFO (ctx->current)->action_name = action_quark;
1274 node_prepend_ui_reference (ctx->current, ctx->merge_id, action_quark);
1276 raise_error = FALSE;
1278 else if ((ctx->state == STATE_MENU || ctx->state == STATE_TOOLBAR) &&
1279 !strcmp (element_name, "placeholder"))
1281 if (ctx->state == STATE_TOOLBAR)
1282 ctx->current = get_child_node (self, ctx->current, NULL,
1283 node_name, strlen (node_name),
1284 NODE_TYPE_TOOLBAR_PLACEHOLDER,
1287 ctx->current = get_child_node (self, ctx->current, NULL,
1288 node_name, strlen (node_name),
1289 NODE_TYPE_MENU_PLACEHOLDER,
1292 node_prepend_ui_reference (ctx->current, ctx->merge_id, action_quark);
1294 raise_error = FALSE;
1298 if ((ctx->state == STATE_MENU || ctx->state == STATE_TOOLBAR) &&
1299 !strcmp (element_name, "separator"))
1304 if (ctx->state == STATE_TOOLBAR)
1305 ctx->state = STATE_TOOLITEM;
1307 ctx->state = STATE_MENUITEM;
1308 if (!strcmp (node_name, "separator"))
1314 length = strlen (node_name);
1315 node = get_child_node (self, ctx->current, NULL,
1317 NODE_TYPE_SEPARATOR,
1320 NODE_INFO (node)->expand = expand;
1322 if (NODE_INFO (node)->action_name == 0)
1323 NODE_INFO (node)->action_name = action_quark;
1325 node_prepend_ui_reference (node, ctx->merge_id, action_quark);
1327 raise_error = FALSE;
1331 if (ctx->state == STATE_ROOT && !strcmp (element_name, "toolbar"))
1333 ctx->state = STATE_TOOLBAR;
1334 ctx->current = get_child_node (self, ctx->current, NULL,
1335 node_name, strlen (node_name),
1338 if (NODE_INFO (ctx->current)->action_name == 0)
1339 NODE_INFO (ctx->current)->action_name = action_quark;
1341 node_prepend_ui_reference (ctx->current, ctx->merge_id, action_quark);
1343 raise_error = FALSE;
1345 else if (ctx->state == STATE_TOOLBAR && !strcmp (element_name, "toolitem"))
1349 ctx->state = STATE_TOOLITEM;
1350 node = get_child_node (self, ctx->current, NULL,
1351 node_name, strlen (node_name),
1354 if (NODE_INFO (node)->action_name == 0)
1355 NODE_INFO (node)->action_name = action_quark;
1357 node_prepend_ui_reference (node, ctx->merge_id, action_quark);
1359 raise_error = FALSE;
1367 gint line_number, char_number;
1369 g_markup_parse_context_get_position (context,
1370 &line_number, &char_number);
1373 G_MARKUP_ERROR_UNKNOWN_ELEMENT,
1374 _("Unexpected start tag '%s' on line %d char %d"),
1376 line_number, char_number);
1381 end_element_handler (GMarkupParseContext *context,
1382 const gchar *element_name,
1386 ParseContext *ctx = user_data;
1392 /* no need to GError here, GMarkup already catches this */
1395 ctx->current = NULL;
1396 ctx->state = STATE_END;
1400 case STATE_ACCELERATOR:
1401 ctx->current = ctx->current->parent;
1402 if (NODE_INFO (ctx->current)->type == NODE_TYPE_ROOT)
1403 ctx->state = STATE_ROOT;
1404 else if (NODE_INFO (ctx->current)->type == NODE_TYPE_TOOLITEM)
1406 ctx->current = ctx->current->parent;
1407 ctx->state = STATE_TOOLITEM;
1409 /* else, stay in same state */
1411 case STATE_MENUITEM:
1412 ctx->state = STATE_MENU;
1414 case STATE_TOOLITEM:
1415 ctx->state = STATE_TOOLBAR;
1421 cleanup (GMarkupParseContext *context,
1425 ParseContext *ctx = user_data;
1427 ctx->current = NULL;
1428 /* should also walk through the tree and get rid of nodes related to
1429 * this UI file's tag */
1431 gtk_ui_manager_remove_ui (ctx->self, ctx->merge_id);
1435 xml_isspace (char c)
1437 return c == ' ' || c == '\t' || c == '\n' || c == '\r';
1441 text_handler (GMarkupParseContext *context,
1451 end = text + text_len;
1452 while (p != end && xml_isspace (*p))
1457 gint line_number, char_number;
1459 g_markup_parse_context_get_position (context,
1460 &line_number, &char_number);
1463 G_MARKUP_ERROR_INVALID_CONTENT,
1464 _("Unexpected character data on line %d char %d"),
1465 line_number, char_number);
1470 static const GMarkupParser ui_parser = {
1471 start_element_handler,
1472 end_element_handler,
1479 add_ui_from_string (GtkUIManager *self,
1480 const gchar *buffer,
1482 gboolean needs_root,
1485 ParseContext ctx = { 0 };
1486 GMarkupParseContext *context;
1488 ctx.state = STATE_START;
1491 ctx.merge_id = gtk_ui_manager_new_merge_id (self);
1493 context = g_markup_parse_context_new (&ui_parser, 0, &ctx, NULL);
1496 if (!g_markup_parse_context_parse (context, "<ui>", -1, error))
1499 if (!g_markup_parse_context_parse (context, buffer, length, error))
1503 if (!g_markup_parse_context_parse (context, "</ui>", -1, error))
1506 if (!g_markup_parse_context_end_parse (context, error))
1509 g_markup_parse_context_free (context);
1511 queue_update (self);
1513 g_object_notify (G_OBJECT (self), "ui");
1515 return ctx.merge_id;
1519 g_markup_parse_context_free (context);
1525 * gtk_ui_manager_add_ui_from_string:
1526 * @self: a #GtkUIManager object
1527 * @buffer: the string to parse
1528 * @length: the length of @buffer (may be -1 if @buffer is nul-terminated)
1529 * @error: return location for an error
1531 * Parses a string containing a <link linkend="XML-UI">UI definition</link> and
1532 * merges it with the current contents of @self. An enclosing <ui>
1533 * element is added if it is missing.
1535 * Return value: The merge id for the merged UI. The merge id can be used
1536 * to unmerge the UI with gtk_ui_manager_remove_ui(). If an error occurred,
1537 * the return value is 0.
1542 gtk_ui_manager_add_ui_from_string (GtkUIManager *self,
1543 const gchar *buffer,
1547 gboolean needs_root = TRUE;
1551 g_return_val_if_fail (GTK_IS_UI_MANAGER (self), 0);
1552 g_return_val_if_fail (buffer != NULL, 0);
1555 length = strlen (buffer);
1558 end = buffer + length;
1559 while (p != end && xml_isspace (*p))
1562 if (end - p >= 4 && strncmp (p, "<ui>", 4) == 0)
1565 return add_ui_from_string (self, buffer, length, needs_root, error);
1569 * gtk_ui_manager_add_ui_from_file:
1570 * @self: a #GtkUIManager object
1571 * @filename: the name of the file to parse
1572 * @error: return location for an error
1574 * Parses a file containing a <link linkend="XML-UI">UI definition</link> and
1575 * merges it with the current contents of @self.
1577 * Return value: The merge id for the merged UI. The merge id can be used
1578 * to unmerge the UI with gtk_ui_manager_remove_ui(). If an error occurred,
1579 * the return value is 0.
1584 gtk_ui_manager_add_ui_from_file (GtkUIManager *self,
1585 const gchar *filename,
1592 g_return_val_if_fail (GTK_IS_UI_MANAGER (self), 0);
1594 if (!g_file_get_contents (filename, &buffer, &length, error))
1597 res = add_ui_from_string (self, buffer, length, FALSE, error);
1604 * gtk_ui_manager_add_ui:
1605 * @self: a #GtkUIManager
1606 * @merge_id: the merge id for the merged UI, see gtk_ui_manager_new_merge_id()
1608 * @name: the name for the added UI element
1609 * @action: the name of the action to be proxied, or %NULL to add a separator
1610 * @type: the type of UI element to add.
1611 * @top: if %TRUE, the UI element is added before its siblings, otherwise it
1612 * is added after its siblings.
1614 * Adds a UI element to the current contents of @self.
1616 * If @type is %GTK_UI_MANAGER_AUTO, GTK+ inserts a menuitem, toolitem or
1617 * separator if such an element can be inserted at the place determined by
1618 * @path. Otherwise @type must indicate an element that can be inserted at
1619 * the place determined by @path.
1621 * If @path points to a menuitem or toolitem, the new element will be inserted
1622 * before or after this item, depending on @top.
1627 gtk_ui_manager_add_ui (GtkUIManager *self,
1631 const gchar *action,
1632 GtkUIManagerItemType type,
1639 GQuark action_quark = 0;
1641 g_return_if_fail (GTK_IS_UI_MANAGER (self));
1642 g_return_if_fail (merge_id > 0);
1643 g_return_if_fail (name != NULL);
1645 node = get_node (self, path, NODE_TYPE_UNDECIDED, FALSE);
1651 node_type = NODE_TYPE_UNDECIDED;
1654 switch (NODE_INFO (node)->type)
1656 case NODE_TYPE_SEPARATOR:
1657 case NODE_TYPE_MENUITEM:
1658 case NODE_TYPE_TOOLITEM:
1660 node = node->parent;
1662 case NODE_TYPE_MENUBAR:
1663 case NODE_TYPE_MENU:
1664 case NODE_TYPE_POPUP:
1665 case NODE_TYPE_MENU_PLACEHOLDER:
1668 case GTK_UI_MANAGER_AUTO:
1670 node_type = NODE_TYPE_MENUITEM;
1672 node_type = NODE_TYPE_SEPARATOR;
1674 case GTK_UI_MANAGER_MENU:
1675 node_type = NODE_TYPE_MENU;
1677 case GTK_UI_MANAGER_MENUITEM:
1678 node_type = NODE_TYPE_MENUITEM;
1680 case GTK_UI_MANAGER_SEPARATOR:
1681 node_type = NODE_TYPE_SEPARATOR;
1683 case GTK_UI_MANAGER_PLACEHOLDER:
1684 node_type = NODE_TYPE_MENU_PLACEHOLDER;
1690 case NODE_TYPE_TOOLBAR:
1691 case NODE_TYPE_TOOLBAR_PLACEHOLDER:
1694 case GTK_UI_MANAGER_AUTO:
1696 node_type = NODE_TYPE_TOOLITEM;
1698 node_type = NODE_TYPE_SEPARATOR;
1700 case GTK_UI_MANAGER_TOOLITEM:
1701 node_type = NODE_TYPE_TOOLITEM;
1703 case GTK_UI_MANAGER_SEPARATOR:
1704 node_type = NODE_TYPE_SEPARATOR;
1706 case GTK_UI_MANAGER_PLACEHOLDER:
1707 node_type = NODE_TYPE_TOOLBAR_PLACEHOLDER;
1713 case NODE_TYPE_ROOT:
1716 case GTK_UI_MANAGER_MENUBAR:
1717 node_type = NODE_TYPE_MENUBAR;
1719 case GTK_UI_MANAGER_TOOLBAR:
1720 node_type = NODE_TYPE_TOOLBAR;
1722 case GTK_UI_MANAGER_POPUP:
1723 node_type = NODE_TYPE_POPUP;
1725 case GTK_UI_MANAGER_ACCELERATOR:
1726 node_type = NODE_TYPE_ACCELERATOR;
1736 if (node_type == NODE_TYPE_UNDECIDED)
1738 g_warning ("item type %d not suitable for adding at '%s'",
1743 child = get_child_node (self, node, sibling,
1744 name, strlen (name),
1745 node_type, TRUE, top);
1748 action_quark = g_quark_from_string (action);
1750 node_prepend_ui_reference (child, merge_id, action_quark);
1752 if (NODE_INFO (child)->action_name == 0)
1753 NODE_INFO (child)->action_name = action_quark;
1755 queue_update (self);
1757 g_object_notify (G_OBJECT (self), "ui");
1761 remove_ui (GNode *node,
1764 guint merge_id = GPOINTER_TO_UINT (user_data);
1766 node_remove_ui_reference (node, merge_id);
1768 return FALSE; /* continue */
1772 * gtk_ui_manager_remove_ui:
1773 * @self: a #GtkUIManager object
1774 * @merge_id: a merge id as returned by gtk_ui_manager_add_ui_from_string()
1776 * Unmerges the part of @self<!-- -->s content identified by @merge_id.
1781 gtk_ui_manager_remove_ui (GtkUIManager *self,
1784 g_node_traverse (self->private_data->root_node,
1785 G_POST_ORDER, G_TRAVERSE_ALL, -1,
1786 remove_ui, GUINT_TO_POINTER (merge_id));
1788 queue_update (self);
1790 g_object_notify (G_OBJECT (self), "ui");
1793 /* -------------------- Updates -------------------- */
1797 get_action_by_name (GtkUIManager *merge,
1798 const gchar *action_name)
1806 for (tmp = merge->private_data->action_groups; tmp != NULL; tmp = tmp->next)
1808 GtkActionGroup *action_group = tmp->data;
1811 action = gtk_action_group_get_action (action_group, action_name);
1821 find_menu_position (GNode *node,
1822 GtkWidget **menushell_p,
1825 GtkWidget *menushell;
1828 g_return_val_if_fail (node != NULL, FALSE);
1829 g_return_val_if_fail (NODE_INFO (node)->type == NODE_TYPE_MENU ||
1830 NODE_INFO (node)->type == NODE_TYPE_POPUP ||
1831 NODE_INFO (node)->type == NODE_TYPE_MENU_PLACEHOLDER ||
1832 NODE_INFO (node)->type == NODE_TYPE_MENUITEM ||
1833 NODE_INFO (node)->type == NODE_TYPE_SEPARATOR,
1836 /* first sibling -- look at parent */
1837 if (node->prev == NULL)
1842 parent = node->parent;
1843 switch (NODE_INFO (parent)->type)
1845 case NODE_TYPE_MENUBAR:
1846 case NODE_TYPE_POPUP:
1847 menushell = NODE_INFO (parent)->proxy;
1850 case NODE_TYPE_MENU:
1851 menushell = NODE_INFO (parent)->proxy;
1852 if (GTK_IS_MENU_ITEM (menushell))
1853 menushell = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menushell));
1854 siblings = gtk_container_get_children (GTK_CONTAINER (menushell));
1855 if (siblings != NULL && GTK_IS_TEAROFF_MENU_ITEM (siblings->data))
1859 g_list_free (siblings);
1861 case NODE_TYPE_MENU_PLACEHOLDER:
1862 menushell = gtk_widget_get_parent (NODE_INFO (parent)->proxy);
1863 g_return_val_if_fail (GTK_IS_MENU_SHELL (menushell), FALSE);
1864 pos = g_list_index (GTK_MENU_SHELL (menushell)->children,
1865 NODE_INFO (parent)->proxy) + 1;
1868 g_warning("%s: bad parent node type %d", G_STRLOC,
1869 NODE_INFO (parent)->type);
1875 GtkWidget *prev_child;
1878 sibling = node->prev;
1879 if (NODE_INFO (sibling)->type == NODE_TYPE_MENU_PLACEHOLDER)
1880 prev_child = NODE_INFO (sibling)->extra; /* second Separator */
1882 prev_child = NODE_INFO (sibling)->proxy;
1884 g_return_val_if_fail (GTK_IS_WIDGET (prev_child), FALSE);
1885 menushell = gtk_widget_get_parent (prev_child);
1886 g_return_val_if_fail (GTK_IS_MENU_SHELL (menushell), FALSE);
1888 pos = g_list_index (GTK_MENU_SHELL (menushell)->children, prev_child) + 1;
1892 *menushell_p = menushell;
1900 find_toolbar_position (GNode *node,
1901 GtkWidget **toolbar_p,
1907 g_return_val_if_fail (node != NULL, FALSE);
1908 g_return_val_if_fail (NODE_INFO (node)->type == NODE_TYPE_TOOLBAR ||
1909 NODE_INFO (node)->type == NODE_TYPE_TOOLBAR_PLACEHOLDER ||
1910 NODE_INFO (node)->type == NODE_TYPE_TOOLITEM ||
1911 NODE_INFO (node)->type == NODE_TYPE_SEPARATOR,
1914 /* first sibling -- look at parent */
1915 if (node->prev == NULL)
1919 parent = node->parent;
1920 switch (NODE_INFO (parent)->type)
1922 case NODE_TYPE_TOOLBAR:
1923 toolbar = NODE_INFO (parent)->proxy;
1926 case NODE_TYPE_TOOLBAR_PLACEHOLDER:
1927 toolbar = gtk_widget_get_parent (NODE_INFO (parent)->proxy);
1928 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
1929 pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (toolbar),
1930 GTK_TOOL_ITEM (NODE_INFO (parent)->proxy)) + 1;
1933 g_warning ("%s: bad parent node type %d", G_STRLOC,
1934 NODE_INFO (parent)->type);
1940 GtkWidget *prev_child;
1943 sibling = node->prev;
1944 if (NODE_INFO (sibling)->type == NODE_TYPE_TOOLBAR_PLACEHOLDER)
1945 prev_child = NODE_INFO (sibling)->extra; /* second Separator */
1947 prev_child = NODE_INFO (sibling)->proxy;
1949 g_return_val_if_fail (GTK_IS_WIDGET (prev_child), FALSE);
1950 toolbar = gtk_widget_get_parent (prev_child);
1951 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
1953 pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (toolbar),
1954 GTK_TOOL_ITEM (prev_child)) + 1;
1958 *toolbar_p = toolbar;
1966 * _gtk_menu_is_empty:
1967 * @menu: a #GtkMenu or %NULL
1969 * Determines whether @menu is empty. A menu is considered empty if it
1970 * the only visible children are tearoff menu items or "filler" menu
1971 * items which were inserted to mark the menu as empty.
1973 * This function is used by #GtkAction.
1975 * Return value: whether @menu is empty.
1978 _gtk_menu_is_empty (GtkWidget *menu)
1980 GList *children, *cur;
1982 g_return_val_if_fail (menu == NULL || GTK_IS_MENU (menu), TRUE);
1987 children = gtk_container_get_children (GTK_CONTAINER (menu));
1992 if (GTK_WIDGET_VISIBLE (cur->data))
1994 if (!GTK_IS_TEAROFF_MENU_ITEM (cur->data) &&
1995 !g_object_get_data (cur->data, "gtk-empty-menu-item"))
2000 g_list_free (children);
2006 SEPARATOR_MODE_SMART,
2007 SEPARATOR_MODE_VISIBLE,
2008 SEPARATOR_MODE_HIDDEN
2012 update_smart_separators (GtkWidget *proxy)
2014 GtkWidget *parent = NULL;
2016 if (GTK_IS_MENU (proxy) || GTK_IS_TOOLBAR (proxy))
2018 else if (GTK_IS_MENU_ITEM (proxy) || GTK_IS_TOOL_ITEM (proxy))
2019 parent = gtk_widget_get_parent (proxy);
2025 GList *children, *cur, *last;
2028 children = gtk_container_get_children (GTK_CONTAINER (parent));
2038 if (g_object_get_data (cur->data, "gtk-empty-menu-item"))
2042 else if (GTK_IS_SEPARATOR_MENU_ITEM (cur->data) ||
2043 GTK_IS_SEPARATOR_TOOL_ITEM (cur->data))
2046 GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cur->data),
2047 "gtk-separator-mode"));
2050 case SEPARATOR_MODE_VISIBLE:
2051 gtk_widget_show (GTK_WIDGET (cur->data));
2055 case SEPARATOR_MODE_HIDDEN:
2056 gtk_widget_hide (GTK_WIDGET (cur->data));
2058 case SEPARATOR_MODE_SMART:
2061 gtk_widget_show (GTK_WIDGET (cur->data));
2066 gtk_widget_hide (GTK_WIDGET (cur->data));
2070 else if (GTK_WIDGET_VISIBLE (cur->data))
2073 if (GTK_IS_TEAROFF_MENU_ITEM (cur->data) || cur->data == filler)
2086 gtk_widget_hide (GTK_WIDGET (last->data));
2088 if (GTK_IS_MENU (parent))
2092 item = gtk_menu_get_attach_widget (GTK_MENU (parent));
2093 if (GTK_IS_MENU_ITEM (item))
2094 _gtk_action_sync_menu_visible (NULL, item, empty);
2095 if (GTK_IS_WIDGET (filler))
2098 gtk_widget_show (filler);
2100 gtk_widget_hide (filler);
2104 g_list_free (children);
2109 update_node (GtkUIManager *self,
2116 const gchar *action_name;
2117 NodeUIReference *ref;
2119 #ifdef DEBUG_UI_MANAGER
2123 g_return_if_fail (node != NULL);
2124 g_return_if_fail (NODE_INFO (node) != NULL);
2126 info = NODE_INFO (node);
2131 in_popup = in_popup || (info->type == NODE_TYPE_POPUP);
2133 #ifdef DEBUG_UI_MANAGER
2134 g_print ("update_node name=%s dirty=%d popup %d (",
2135 info->name, info->dirty, in_popup);
2136 for (tmp = info->uifiles; tmp != NULL; tmp = tmp->next)
2138 NodeUIReference *ref = tmp->data;
2139 g_print("%s:%u", g_quark_to_string (ref->action_quark), ref->merge_id);
2146 if (info->uifiles == NULL) {
2147 /* We may need to remove this node.
2148 * This must be done in post order
2150 goto recurse_children;
2153 ref = info->uifiles->data;
2154 action_name = g_quark_to_string (ref->action_quark);
2155 action = get_action_by_name (self, action_name);
2157 info->dirty = FALSE;
2159 /* Check if the node doesn't have an action and must have an action */
2160 if (action == NULL &&
2161 info->type != NODE_TYPE_ROOT &&
2162 info->type != NODE_TYPE_MENUBAR &&
2163 info->type != NODE_TYPE_TOOLBAR &&
2164 info->type != NODE_TYPE_POPUP &&
2165 info->type != NODE_TYPE_SEPARATOR &&
2166 info->type != NODE_TYPE_MENU_PLACEHOLDER &&
2167 info->type != NODE_TYPE_TOOLBAR_PLACEHOLDER)
2169 g_warning ("%s: missing action", info->name);
2171 goto recurse_children;
2175 gtk_action_set_accel_group (action, self->private_data->accel_group);
2177 /* If the widget already has a proxy and the action hasn't changed, then
2178 * we only have to update the tearoff menu items.
2180 if (info->proxy != NULL && action == info->action)
2182 if (info->type == NODE_TYPE_MENU)
2187 if (GTK_IS_MENU (info->proxy))
2190 menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (info->proxy));
2191 siblings = gtk_container_get_children (GTK_CONTAINER (menu));
2192 if (siblings != NULL && GTK_IS_TEAROFF_MENU_ITEM (siblings->data))
2194 if (self->private_data->add_tearoffs && !in_popup)
2195 gtk_widget_show (GTK_WIDGET (siblings->data));
2197 gtk_widget_hide (GTK_WIDGET (siblings->data));
2199 g_list_free (siblings);
2202 goto recurse_children;
2207 case NODE_TYPE_MENUBAR:
2208 if (info->proxy == NULL)
2210 info->proxy = gtk_menu_bar_new ();
2211 g_object_ref_sink (info->proxy);
2212 gtk_widget_set_name (info->proxy, info->name);
2213 gtk_widget_show (info->proxy);
2214 g_signal_emit (self, ui_manager_signals[ADD_WIDGET], 0, info->proxy);
2217 case NODE_TYPE_POPUP:
2218 if (info->proxy == NULL)
2220 info->proxy = gtk_menu_new ();
2221 g_object_ref_sink (info->proxy);
2223 gtk_widget_set_name (info->proxy, info->name);
2225 case NODE_TYPE_MENU:
2227 GtkWidget *prev_submenu = NULL;
2230 /* remove the proxy if it is of the wrong type ... */
2232 G_OBJECT_TYPE (info->proxy) != GTK_ACTION_GET_CLASS (action)->menu_item_type)
2234 if (GTK_IS_MENU_ITEM (info->proxy))
2236 prev_submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (info->proxy));
2239 g_object_ref (prev_submenu);
2240 gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy), NULL);
2244 gtk_action_disconnect_proxy (info->action, info->proxy);
2245 gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
2247 g_object_unref (info->proxy);
2250 /* create proxy if needed ... */
2251 if (info->proxy == NULL)
2253 GtkWidget *menushell;
2256 if (NODE_INFO (node->parent)->type == NODE_TYPE_TOOLITEM ||
2257 find_menu_position (node, &menushell, &pos))
2262 menu = gtk_menu_new ();
2263 gtk_widget_set_name (menu, info->name);
2264 tearoff = gtk_tearoff_menu_item_new ();
2265 gtk_widget_set_no_show_all (tearoff, TRUE);
2266 gtk_menu_shell_append (GTK_MENU_SHELL (menu), tearoff);
2267 filler = gtk_menu_item_new_with_label (_("Empty"));
2268 g_object_set_data (G_OBJECT (filler),
2269 I_("gtk-empty-menu-item"),
2270 GINT_TO_POINTER (TRUE));
2271 gtk_widget_set_sensitive (filler, FALSE);
2272 gtk_widget_set_no_show_all (filler, TRUE);
2273 gtk_menu_shell_append (GTK_MENU_SHELL (menu), filler);
2275 if (NODE_INFO (node->parent)->type == NODE_TYPE_TOOLITEM)
2278 g_object_ref_sink (info->proxy);
2279 gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (NODE_INFO (node->parent)->proxy),
2284 info->proxy = gtk_action_create_menu_item (action);
2285 g_object_ref_sink (info->proxy);
2286 g_signal_connect (info->proxy, "notify::visible",
2287 G_CALLBACK (update_smart_separators), NULL);
2288 gtk_widget_set_name (info->proxy, info->name);
2290 gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy), menu);
2291 gtk_menu_shell_insert (GTK_MENU_SHELL (menushell), info->proxy, pos);
2296 gtk_action_connect_proxy (action, info->proxy);
2300 gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy),
2302 g_object_unref (prev_submenu);
2305 if (GTK_IS_MENU (info->proxy))
2308 menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (info->proxy));
2309 siblings = gtk_container_get_children (GTK_CONTAINER (menu));
2310 if (siblings != NULL && GTK_IS_TEAROFF_MENU_ITEM (siblings->data))
2312 if (self->private_data->add_tearoffs && !in_popup)
2313 gtk_widget_show (GTK_WIDGET (siblings->data));
2315 gtk_widget_hide (GTK_WIDGET (siblings->data));
2317 g_list_free (siblings);
2320 case NODE_TYPE_UNDECIDED:
2321 g_warning ("found undecided node!");
2323 case NODE_TYPE_ROOT:
2325 case NODE_TYPE_TOOLBAR:
2326 if (info->proxy == NULL)
2328 info->proxy = gtk_toolbar_new ();
2329 g_object_ref_sink (info->proxy);
2330 gtk_widget_set_name (info->proxy, info->name);
2331 gtk_widget_show (info->proxy);
2332 g_signal_emit (self, ui_manager_signals[ADD_WIDGET], 0, info->proxy);
2335 case NODE_TYPE_MENU_PLACEHOLDER:
2336 /* create menu items for placeholders if necessary ... */
2337 if (!GTK_IS_SEPARATOR_MENU_ITEM (info->proxy) ||
2338 !GTK_IS_SEPARATOR_MENU_ITEM (info->extra))
2342 gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
2344 g_object_unref (info->proxy);
2349 gtk_container_remove (GTK_CONTAINER (info->extra->parent),
2351 g_object_unref (info->extra);
2355 if (info->proxy == NULL)
2357 GtkWidget *menushell;
2360 if (find_menu_position (node, &menushell, &pos))
2362 info->proxy = gtk_separator_menu_item_new ();
2363 g_object_ref_sink (info->proxy);
2364 g_object_set_data (G_OBJECT (info->proxy),
2365 I_("gtk-separator-mode"),
2366 GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
2367 gtk_widget_set_no_show_all (info->proxy, TRUE);
2368 gtk_menu_shell_insert (GTK_MENU_SHELL (menushell),
2369 NODE_INFO (node)->proxy, pos);
2371 info->extra = gtk_separator_menu_item_new ();
2372 g_object_ref_sink (info->extra);
2373 g_object_set_data (G_OBJECT (info->extra),
2374 I_("gtk-separator-mode"),
2375 GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
2376 gtk_widget_set_no_show_all (info->extra, TRUE);
2377 gtk_menu_shell_insert (GTK_MENU_SHELL (menushell),
2378 NODE_INFO (node)->extra, pos+1);
2382 case NODE_TYPE_TOOLBAR_PLACEHOLDER:
2383 /* create toolbar items for placeholders if necessary ... */
2384 if (!GTK_IS_SEPARATOR_TOOL_ITEM (info->proxy) ||
2385 !GTK_IS_SEPARATOR_TOOL_ITEM (info->extra))
2389 gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
2391 g_object_unref (info->proxy);
2396 gtk_container_remove (GTK_CONTAINER (info->extra->parent),
2398 g_object_unref (info->extra);
2402 if (info->proxy == NULL)
2407 if (find_toolbar_position (node, &toolbar, &pos))
2411 item = gtk_separator_tool_item_new ();
2412 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, pos);
2413 info->proxy = GTK_WIDGET (item);
2414 g_object_ref_sink (info->proxy);
2415 g_object_set_data (G_OBJECT (info->proxy),
2416 I_("gtk-separator-mode"),
2417 GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
2418 gtk_widget_set_no_show_all (info->proxy, TRUE);
2420 item = gtk_separator_tool_item_new ();
2421 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, pos+1);
2422 info->extra = GTK_WIDGET (item);
2423 g_object_ref_sink (info->extra);
2424 g_object_set_data (G_OBJECT (info->extra),
2425 I_("gtk-separator-mode"),
2426 GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
2427 gtk_widget_set_no_show_all (info->extra, TRUE);
2431 case NODE_TYPE_MENUITEM:
2432 /* remove the proxy if it is of the wrong type ... */
2434 G_OBJECT_TYPE (info->proxy) != GTK_ACTION_GET_CLASS (action)->menu_item_type)
2436 g_signal_handlers_disconnect_by_func (info->proxy,
2437 G_CALLBACK (update_smart_separators),
2439 gtk_action_disconnect_proxy (info->action, info->proxy);
2440 gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
2442 g_object_unref (info->proxy);
2445 /* create proxy if needed ... */
2446 if (info->proxy == NULL)
2448 GtkWidget *menushell;
2451 if (find_menu_position (node, &menushell, &pos))
2453 info->proxy = gtk_action_create_menu_item (action);
2454 g_object_ref_sink (info->proxy);
2455 gtk_widget_set_name (info->proxy, info->name);
2457 gtk_menu_shell_insert (GTK_MENU_SHELL (menushell),
2463 g_signal_handlers_disconnect_by_func (info->proxy,
2464 G_CALLBACK (update_smart_separators),
2466 gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy), NULL);
2467 gtk_action_connect_proxy (action, info->proxy);
2469 g_signal_connect (info->proxy, "notify::visible",
2470 G_CALLBACK (update_smart_separators), NULL);
2473 /* don't show accels in popups */
2474 GtkWidget *label = GTK_BIN (info->proxy)->child;
2475 g_object_set (label,
2476 "accel_closure", NULL,
2481 case NODE_TYPE_TOOLITEM:
2482 /* remove the proxy if it is of the wrong type ... */
2484 G_OBJECT_TYPE (info->proxy) != GTK_ACTION_GET_CLASS (action)->toolbar_item_type)
2486 g_signal_handlers_disconnect_by_func (info->proxy,
2487 G_CALLBACK (update_smart_separators),
2489 gtk_action_disconnect_proxy (info->action, info->proxy);
2490 gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
2492 g_object_unref (info->proxy);
2495 /* create proxy if needed ... */
2496 if (info->proxy == NULL)
2501 if (find_toolbar_position (node, &toolbar, &pos))
2503 info->proxy = gtk_action_create_tool_item (action);
2504 g_object_ref_sink (info->proxy);
2505 gtk_widget_set_name (info->proxy, info->name);
2507 gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
2508 GTK_TOOL_ITEM (info->proxy), pos);
2513 g_signal_handlers_disconnect_by_func (info->proxy,
2514 G_CALLBACK (update_smart_separators),
2516 gtk_action_connect_proxy (action, info->proxy);
2519 /* FIXME: we must trigger the notify::tooltip handler, since
2520 * tooltips on toolitems can't be set before the toolitem
2521 * is added to the toolbar.
2523 g_object_notify (G_OBJECT (action), "tooltip");
2525 g_signal_connect (info->proxy, "notify::visible",
2526 G_CALLBACK (update_smart_separators), NULL);
2528 case NODE_TYPE_SEPARATOR:
2529 if (NODE_INFO (node->parent)->type == NODE_TYPE_TOOLBAR ||
2530 NODE_INFO (node->parent)->type == NODE_TYPE_TOOLBAR_PLACEHOLDER)
2534 gint separator_mode;
2536 if (GTK_IS_SEPARATOR_TOOL_ITEM (info->proxy))
2538 gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
2540 g_object_unref (info->proxy);
2544 if (find_toolbar_position (node, &toolbar, &pos))
2546 GtkToolItem *item = gtk_separator_tool_item_new ();
2547 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, pos);
2548 info->proxy = GTK_WIDGET (item);
2549 g_object_ref_sink (info->proxy);
2550 gtk_widget_set_no_show_all (info->proxy, TRUE);
2553 gtk_tool_item_set_expand (GTK_TOOL_ITEM (item), TRUE);
2554 gtk_separator_tool_item_set_draw
2555 (GTK_SEPARATOR_TOOL_ITEM (item), FALSE);
2556 separator_mode = SEPARATOR_MODE_VISIBLE;
2559 separator_mode = SEPARATOR_MODE_SMART;
2561 g_object_set_data (G_OBJECT (info->proxy),
2562 I_("gtk-separator-mode"),
2563 GINT_TO_POINTER (separator_mode));
2564 gtk_widget_show (info->proxy);
2569 GtkWidget *menushell;
2572 if (GTK_IS_SEPARATOR_MENU_ITEM (info->proxy))
2574 gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
2576 g_object_unref (info->proxy);
2580 if (find_menu_position (node, &menushell, &pos))
2582 info->proxy = gtk_separator_menu_item_new ();
2583 g_object_ref_sink (info->proxy);
2584 gtk_widget_set_no_show_all (info->proxy, TRUE);
2585 g_object_set_data (G_OBJECT (info->proxy),
2586 I_("gtk-separator-mode"),
2587 GINT_TO_POINTER (SEPARATOR_MODE_SMART));
2588 gtk_menu_shell_insert (GTK_MENU_SHELL (menushell),
2590 gtk_widget_show (info->proxy);
2594 case NODE_TYPE_ACCELERATOR:
2595 gtk_action_connect_accelerator (action);
2600 g_object_ref (action);
2602 g_object_unref (info->action);
2603 info->action = action;
2606 /* process children */
2607 child = node->children;
2613 child = current->next;
2614 update_node (self, current, in_popup);
2619 if (info->type == NODE_TYPE_MENU && GTK_IS_MENU_ITEM (info->proxy))
2620 update_smart_separators (gtk_menu_item_get_submenu (GTK_MENU_ITEM (info->proxy)));
2621 else if (info->type == NODE_TYPE_MENU ||
2622 info->type == NODE_TYPE_TOOLBAR ||
2623 info->type == NODE_TYPE_POPUP)
2624 update_smart_separators (info->proxy);
2627 /* handle cleanup of dead nodes */
2628 if (node->children == NULL && info->uifiles == NULL)
2631 gtk_widget_destroy (info->proxy);
2633 gtk_widget_destroy (info->extra);
2634 if (info->type == NODE_TYPE_ACCELERATOR)
2635 gtk_action_disconnect_accelerator (info->action);
2637 g_node_destroy (node);
2642 do_updates (GtkUIManager *self)
2644 /* this function needs to check through the tree for dirty nodes.
2645 * For such nodes, it needs to do the following:
2647 * 1) check if they are referenced by any loaded UI files anymore.
2648 * In which case, the proxy widget should be destroyed, unless
2649 * there are any subnodes.
2651 * 2) lookup the action for this node again. If it is different to
2652 * the current one (or if no previous action has been looked up),
2653 * the proxy is reconnected to the new action (or a new proxy widget
2654 * is created and added to the parent container).
2656 update_node (self, self->private_data->root_node, FALSE);
2658 self->private_data->update_tag = 0;
2664 do_updates_idle (GtkUIManager *self)
2666 GDK_THREADS_ENTER ();
2668 GDK_THREADS_LEAVE ();
2674 queue_update (GtkUIManager *self)
2676 if (self->private_data->update_tag != 0)
2679 self->private_data->update_tag = g_idle_add ((GSourceFunc)do_updates_idle,
2685 * gtk_ui_manager_ensure_update:
2686 * @self: a #GtkUIManager
2688 * Makes sure that all pending updates to the UI have been completed.
2690 * This may occasionally be necessary, since #GtkUIManager updates the
2691 * UI in an idle function. A typical example where this function is
2692 * useful is to enforce that the menubar and toolbar have been added to
2693 * the main window before showing it:
2696 * gtk_container_add (GTK_CONTAINER (window), vbox);
2697 * g_signal_connect (merge, "add_widget",
2698 * G_CALLBACK (add_widget), vbox);
2699 * gtk_ui_manager_add_ui_from_file (merge, "my-menus");
2700 * gtk_ui_manager_add_ui_from_file (merge, "my-toolbars");
2701 * gtk_ui_manager_ensure_update (merge);
2702 * gtk_widget_show (window);
2704 * </informalexample>
2709 gtk_ui_manager_ensure_update (GtkUIManager *self)
2711 if (self->private_data->update_tag != 0)
2713 g_source_remove (self->private_data->update_tag);
2719 dirty_traverse_func (GNode *node,
2722 NODE_INFO (node)->dirty = TRUE;
2727 dirty_all_nodes (GtkUIManager *self)
2729 g_node_traverse (self->private_data->root_node,
2730 G_PRE_ORDER, G_TRAVERSE_ALL, -1,
2731 dirty_traverse_func, NULL);
2732 queue_update (self);
2736 mark_node_dirty (GNode *node)
2740 /* FIXME could optimize this */
2741 for (p = node; p; p = p->parent)
2742 NODE_INFO (p)->dirty = TRUE;
2745 static const gchar *
2746 open_tag_format (NodeType type)
2750 case NODE_TYPE_UNDECIDED: return "%*s<UNDECIDED";
2751 case NODE_TYPE_ROOT: return "%*s<ui";
2752 case NODE_TYPE_MENUBAR: return "%*s<menubar";
2753 case NODE_TYPE_MENU: return "%*s<menu";
2754 case NODE_TYPE_TOOLBAR: return "%*s<toolbar";
2755 case NODE_TYPE_MENU_PLACEHOLDER:
2756 case NODE_TYPE_TOOLBAR_PLACEHOLDER: return "%*s<placeholder";
2757 case NODE_TYPE_POPUP: return "%*s<popup";
2758 case NODE_TYPE_MENUITEM: return "%*s<menuitem";
2759 case NODE_TYPE_TOOLITEM: return "%*s<toolitem";
2760 case NODE_TYPE_SEPARATOR: return "%*s<separator";
2761 case NODE_TYPE_ACCELERATOR: return "%*s<accelerator";
2762 default: return NULL;
2766 static const gchar *
2767 close_tag_format (NodeType type)
2771 case NODE_TYPE_UNDECIDED: return "%*s</UNDECIDED>\n";
2772 case NODE_TYPE_ROOT: return "%*s</ui>\n";
2773 case NODE_TYPE_MENUBAR: return "%*s</menubar>\n";
2774 case NODE_TYPE_MENU: return "%*s</menu>\n";
2775 case NODE_TYPE_TOOLBAR: return "%*s</toolbar>\n";
2776 case NODE_TYPE_MENU_PLACEHOLDER:
2777 case NODE_TYPE_TOOLBAR_PLACEHOLDER: return "%*s</placeholder>\n";
2778 case NODE_TYPE_POPUP: return "%*s</popup>\n";
2779 default: return NULL;
2784 print_node (GtkUIManager *self,
2791 const gchar *open_fmt;
2792 const gchar *close_fmt;
2796 open_fmt = open_tag_format (mnode->type);
2797 close_fmt = close_tag_format (mnode->type);
2799 g_string_append_printf (buffer, open_fmt, indent_level, "");
2801 if (mnode->type != NODE_TYPE_ROOT)
2804 g_string_append_printf (buffer, " name=\"%s\"", mnode->name);
2806 if (mnode->action_name)
2807 g_string_append_printf (buffer, " action=\"%s\"",
2808 g_quark_to_string (mnode->action_name));
2811 g_string_append (buffer, close_fmt ? ">\n" : "/>\n");
2813 for (child = node->children; child != NULL; child = child->next)
2814 print_node (self, child, indent_level + 2, buffer);
2817 g_string_append_printf (buffer, close_fmt, indent_level, "");
2821 * gtk_ui_manager_get_ui:
2822 * @self: a #GtkUIManager
2824 * Creates a <link linkend="XML-UI">UI definition</link> of the merged UI.
2826 * Return value: A newly allocated string containing an XML representation of
2832 gtk_ui_manager_get_ui (GtkUIManager *self)
2836 buffer = g_string_new (NULL);
2838 gtk_ui_manager_ensure_update (self);
2840 print_node (self, self->private_data->root_node, 0, buffer);
2842 return g_string_free (buffer, FALSE);
2847 #undef gtk_ui_manager_add_ui_from_file
2850 gtk_ui_manager_add_ui_from_file (GtkUIManager *self,
2851 const gchar *filename,
2854 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, error);
2857 if (utf8_filename == NULL)
2860 retval = gtk_ui_manager_add_ui_from_file_utf8 (self, utf8_filename, error);
2862 g_free (utf8_filename);
2869 #define __GTK_UI_MANAGER_C__
2870 #include "gtkaliasdef.c"