diff options
author | Matthias Clasen <maclas@gmx.de> | 2004-01-08 23:37:34 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2004-01-08 23:37:34 +0000 |
commit | f2bb20cc15438e6b8d1d7c979681de3cbefac4f6 (patch) | |
tree | 2215b4d866071dabb083aeb8b5647d96a0fcc356 /gtk | |
parent | ecceb20a8b13df9af33a052b75fab4fa3ae189ea (diff) | |
download | gtk+-f2bb20cc15438e6b8d1d7c979681de3cbefac4f6.tar.gz |
New function to obtain a list of toplevel widgets constructed by the ui
Fri Jan 9 00:34:57 2004 Matthias Clasen <maclas@gmx.de>
* gtk/gtkuimanager.h:
* gtk/gtkuimanager.c (gtk_ui_manager_get_toplevels): New function to
obtain a list of toplevel widgets constructed by the ui manager.
* gtk/gtkuimanager.h (GtkUIManagerItemType): Change to flags, so that
the values can be combined for gtk_ui_manager_get_toplevels().
* tests/testmerge.c: Add a "Dump toplevels" button to test
gtk_ui_manager_get_toplevels().
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkuimanager.c | 67 | ||||
-rw-r--r-- | gtk/gtkuimanager.h | 22 |
2 files changed, 78 insertions, 11 deletions
diff --git a/gtk/gtkuimanager.c b/gtk/gtkuimanager.c index 1178071343..953756e097 100644 --- a/gtk/gtkuimanager.c +++ b/gtk/gtkuimanager.c @@ -558,6 +558,70 @@ gtk_ui_manager_get_widget (GtkUIManager *self, return NODE_INFO (node)->proxy; } +static void +collect_toplevels (GNode *node, + gpointer user_data) +{ + struct { + GtkUIManagerItemType types; + GSList *list; + } *data = user_data; + + switch (NODE_INFO (node)->type) { + case NODE_TYPE_MENUBAR: + if (data->types & GTK_UI_MANAGER_MENUBAR) + data->list = g_slist_prepend (data->list, NODE_INFO (node)->proxy); + break; + case NODE_TYPE_TOOLBAR: + if (data->types & GTK_UI_MANAGER_TOOLBAR) + data->list = g_slist_prepend (data->list, NODE_INFO (node)->proxy); + break; + case NODE_TYPE_POPUP: + if (data->types & GTK_UI_MANAGER_POPUP) + data->list = g_slist_prepend (data->list, NODE_INFO (node)->proxy); + break; + default: ; + } +} + +/** + * gtk_ui_manager_get_toplevels: + * @self: a #GtkUIManager + * @types: specifies the types of toplevel widgets to include. Allowed + * types are #GTK_UI_MANAGER_MENUBAR, #GTK_UI_MANAGER_TOOLBAR and + * #GTK_UI_MANAGER_POPUP. + * + * Obtains a list of all toplevel widgets of the requested types. + * + * Return value: a list of all toplevel widgets of the requested types. + * + * Since: 2.4 + **/ +GSList * +gtk_ui_manager_get_toplevels (GtkUIManager *self, + GtkUIManagerItemType types) +{ + struct { + GtkUIManagerItemType types; + GSList *list; + } data; + + g_return_val_if_fail ((~(GTK_UI_MANAGER_MENUBAR | + GTK_UI_MANAGER_TOOLBAR | + GTK_UI_MANAGER_POPUP) & types) == 0, NULL); + + + data.types = types; + data.list = NULL; + + g_node_children_foreach (self->private_data->root_node, + G_TRAVERSE_ALL, + collect_toplevels, &data); + + return data.list; +} + + /** * gtk_ui_manager_get_action: * @self: a #GtkUIManager @@ -1697,12 +1761,13 @@ static void update_smart_separators (GtkWidget *proxy) { GtkWidget *parent = NULL; - + if (GTK_IS_MENU (proxy) || GTK_IS_TOOLBAR (proxy)) parent = proxy; else if (GTK_IS_MENU_ITEM (proxy) || GTK_IS_TOOL_ITEM (proxy)) parent = gtk_widget_get_parent (proxy); + if (parent) { gboolean visible; diff --git a/gtk/gtkuimanager.h b/gtk/gtkuimanager.h index d6f2c6a6e3..edf043a200 100644 --- a/gtk/gtkuimanager.h +++ b/gtk/gtkuimanager.h @@ -75,16 +75,16 @@ struct _GtkUIManagerClass { }; typedef enum { - GTK_UI_MANAGER_AUTO, - GTK_UI_MANAGER_MENUBAR, - GTK_UI_MANAGER_MENU, - GTK_UI_MANAGER_TOOLBAR, - GTK_UI_MANAGER_PLACEHOLDER, - GTK_UI_MANAGER_POPUP, - GTK_UI_MANAGER_MENUITEM, - GTK_UI_MANAGER_TOOLITEM, - GTK_UI_MANAGER_SEPARATOR, - GTK_UI_MANAGER_ACCELERATOR + GTK_UI_MANAGER_AUTO = 0, + GTK_UI_MANAGER_MENUBAR = 1 << 0, + GTK_UI_MANAGER_MENU = 1 << 1, + GTK_UI_MANAGER_TOOLBAR = 1 << 2, + GTK_UI_MANAGER_PLACEHOLDER = 1 << 3, + GTK_UI_MANAGER_POPUP = 1 << 4, + GTK_UI_MANAGER_MENUITEM = 1 << 5, + GTK_UI_MANAGER_TOOLITEM = 1 << 6, + GTK_UI_MANAGER_SEPARATOR = 1 << 7, + GTK_UI_MANAGER_ACCELERATOR = 1 << 8 } GtkUIManagerItemType; GType gtk_ui_manager_get_type (void); @@ -101,6 +101,8 @@ GList *gtk_ui_manager_get_action_groups (GtkUIManager *self); GtkAccelGroup *gtk_ui_manager_get_accel_group (GtkUIManager *self); GtkWidget *gtk_ui_manager_get_widget (GtkUIManager *self, const gchar *path); +GSList *gtk_ui_manager_get_toplevels (GtkUIManager *self, + GtkUIManagerItemType types); GtkAction *gtk_ui_manager_get_action (GtkUIManager *self, const gchar *path); guint gtk_ui_manager_add_ui_from_string (GtkUIManager *self, |