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().
This commit is contained in:
Matthias Clasen 2004-01-08 23:37:34 +00:00 committed by Matthias Clasen
parent ecceb20a8b
commit f2bb20cc15
10 changed files with 168 additions and 11 deletions

View File

@ -1,3 +1,15 @@
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().
Wed Jan 7 23:20:06 2004 Matthias Clasen <maclas@gmx.de>
* demos/gtk-demo/Makefile.am (demos): Add entry_completion.c

View File

@ -1,3 +1,15 @@
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().
Wed Jan 7 23:20:06 2004 Matthias Clasen <maclas@gmx.de>
* demos/gtk-demo/Makefile.am (demos): Add entry_completion.c

View File

@ -1,3 +1,15 @@
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().
Wed Jan 7 23:20:06 2004 Matthias Clasen <maclas@gmx.de>
* demos/gtk-demo/Makefile.am (demos): Add entry_completion.c

View File

@ -1,3 +1,15 @@
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().
Wed Jan 7 23:20:06 2004 Matthias Clasen <maclas@gmx.de>
* demos/gtk-demo/Makefile.am (demos): Add entry_completion.c

View File

@ -1,3 +1,15 @@
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().
Wed Jan 7 23:20:06 2004 Matthias Clasen <maclas@gmx.de>
* demos/gtk-demo/Makefile.am (demos): Add entry_completion.c

View File

@ -1,3 +1,7 @@
Fri Jan 9 00:38:58 2004 Matthias Clasen <maclas@gmx.de>
* gtk/gtk-sections.txt: Add gtk_ui_manager_get_toplevels.
Thu Jan 8 00:14:02 2004 Matthias Clasen <maclas@gmx.de>
* gtk/tmpl/gtkmain.sgml (gtk_input_add_full): Fix link in deprecation

View File

@ -1951,6 +1951,7 @@ gtk_ui_manager_remove_action_group
gtk_ui_manager_get_action_groups
gtk_ui_manager_get_accel_group
gtk_ui_manager_get_widget
gtk_ui_manager_get_toplevels
gtk_ui_manager_get_action
gtk_ui_manager_add_ui_from_string
gtk_ui_manager_add_ui_from_file

View File

@ -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;

View File

@ -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,

View File

@ -34,6 +34,27 @@ dump_accels (void)
gtk_accel_map_save_fd (STDOUT_FILENO);
}
static void
print_toplevel (GtkWidget *widget, gpointer user_data)
{
g_print ("%s\n", G_OBJECT_TYPE_NAME (widget));
}
static void
dump_toplevels (GtkWidget *button,
GtkUIManager *merge)
{
GSList *toplevels;
toplevels = gtk_ui_manager_get_toplevels (merge,
GTK_UI_MANAGER_MENUBAR |
GTK_UI_MANAGER_TOOLBAR |
GTK_UI_MANAGER_POPUP);
g_slist_foreach (toplevels, print_toplevel, NULL);
g_slist_free (toplevels);
}
static void
toggle_tearoffs (GtkWidget *button,
GtkUIManager *merge)
@ -652,6 +673,10 @@ main (int argc, char **argv)
g_signal_connect (button, "clicked", G_CALLBACK (dump_tree), merge);
gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
button = gtk_button_new_with_label ("Dump Toplevels");
g_signal_connect (button, "clicked", G_CALLBACK (dump_toplevels), merge);
gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
button = gtk_button_new_with_label ("Dump Accels");
g_signal_connect (button, "clicked", G_CALLBACK (dump_accels), NULL);
gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);