summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2004-03-15 02:03:59 +0000
committerOwen Taylor <otaylor@src.gnome.org>2004-03-15 02:03:59 +0000
commit3895bea4df873c114689f8de97b5527a75657aaf (patch)
treed75941dfea3bec36383492d8f09c4f1312bfc648 /tests
parentf2e252a2c26c589a3fdd13bf0606a25f7ae076eb (diff)
downloadgtk+-3895bea4df873c114689f8de97b5527a75657aaf.tar.gz
#136672, reported by Christian Persch; fixes based on a patch by Soeren
Sun Mar 14 19:26:48 2004 Owen Taylor <otaylor@redhat.com> #136672, reported by Christian Persch; fixes based on a patch by Soeren Sandmann. * gtk/gtkmenu.c: Change the handling of mixed gridded and non-gridded menu items; the old method was causing major performance problems even with the "avoid relayout on destruction" hack put in recently. Now we first lay out the gridded items and then put the non-gridded items into empty rows / after the gridded items. Layout is done in a central menu_shell_ensure_layout(). Also avoid emitting property notifications when we initially insert or attach items. * gtk/gtkmenushell.[ch] gtk/gtkmenu.c: Stop setting the unused menu_shell->menu_flag, and document it as unused in the header. * tests/testactions.c: Add a test of creating/removing lots of items. * test/testgtk.c: Add some more cruft to the menu test.
Diffstat (limited to 'tests')
-rw-r--r--tests/testactions.c104
-rw-r--r--tests/testgtk.c33
2 files changed, 136 insertions, 1 deletions
diff --git a/tests/testactions.c b/tests/testactions.c
index 8acb5ca111..be8c78a282 100644
--- a/tests/testactions.c
+++ b/tests/testactions.c
@@ -94,6 +94,7 @@ toolbar_size_large (GtkAction *action)
static GtkActionEntry entries[] = {
{ "Menu1Action", NULL, "Menu _1" },
{ "Menu2Action", NULL, "Menu _2" },
+ { "Menu3Action", NULL, "_Dynamic Menu" },
{ "cut", GTK_STOCK_CUT, "C_ut", "<control>X",
"Cut the selected text to the clipboard", G_CALLBACK (activate_action) },
@@ -187,6 +188,7 @@ static const gchar *ui_info =
" <menuitem action=\"toolbar-small-icons\" />\n"
" <menuitem action=\"toolbar-large-icons\" />\n"
" </menu>\n"
+ " <menu name=\"DynamicMenu\" action=\"Menu3Action\" />\n"
" </menubar>\n"
" <toolbar name=\"toolbar\">\n"
" <toolitem name=\"cut\" action=\"cut\" />\n"
@@ -209,7 +211,7 @@ add_widget (GtkUIManager *merge,
GtkContainer *container)
{
- gtk_container_add (container, widget);
+ gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
gtk_widget_show (widget);
if (GTK_IS_TOOLBAR (widget))
@@ -219,12 +221,91 @@ add_widget (GtkUIManager *merge,
}
}
+static guint ui_id = 0;
+static GtkActionGroup *dag = NULL;
+
+static void
+ensure_update (GtkUIManager *manager)
+{
+ GTimer *timer;
+ double seconds;
+ gulong microsecs;
+
+ timer = g_timer_new ();
+ g_timer_start (timer);
+
+ gtk_ui_manager_ensure_update (manager);
+
+ g_timer_stop (timer);
+ seconds = g_timer_elapsed (timer, &microsecs);
+ g_timer_destroy (timer);
+
+ g_print ("Time: %fs\n", seconds);
+}
+
+static void
+add_cb (GtkWidget *button,
+ GtkUIManager *manager)
+{
+ GtkWidget *spinbutton;
+ GtkAction *action;
+ int i, num;
+ char *name, *label;
+
+ if (ui_id != 0 || dag != NULL)
+ return;
+
+ spinbutton = g_object_get_data (G_OBJECT (button), "spinbutton");
+ num = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinbutton));
+
+ dag = gtk_action_group_new ("DynamicActions");
+ gtk_ui_manager_insert_action_group (manager, dag, 0);
+
+ ui_id = gtk_ui_manager_new_merge_id (manager);
+
+ for (i = 0; i < num; i++)
+ {
+ name = g_strdup_printf ("DynAction%u", i);
+ label = g_strdup_printf ("Dynamic Item %d", i);
+
+ action = g_object_new (GTK_TYPE_ACTION,
+ "name", name,
+ "label", label,
+ NULL);
+ gtk_action_group_add_action (dag, action);
+ g_object_unref (action);
+
+ gtk_ui_manager_add_ui (manager, ui_id, "/menubar/DynamicMenu",
+ name, name,
+ GTK_UI_MANAGER_MENUITEM, FALSE);
+ }
+
+ ensure_update (manager);
+}
+
+static void
+remove_cb (GtkWidget *button,
+ GtkUIManager *manager)
+{
+ if (ui_id == 0 || dag == NULL)
+ return;
+
+ gtk_ui_manager_remove_ui (manager, ui_id);
+ ensure_update (manager);
+ ui_id = 0;
+
+ gtk_ui_manager_remove_action_group (manager, dag);
+ g_object_unref (dag);
+ dag = NULL;
+}
+
static void
create_window (GtkActionGroup *action_group)
{
GtkUIManager *merge;
GtkWidget *window;
GtkWidget *box;
+ GtkWidget *hbox, *spinbutton, *button;
GError *error = NULL;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
@@ -249,6 +330,27 @@ create_window (GtkActionGroup *action_group)
g_error_free (error);
}
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_end (GTK_BOX (box), hbox, FALSE, FALSE, 0);
+ gtk_widget_show (hbox);
+
+ spinbutton = gtk_spin_button_new_with_range (100, 10000, 100);
+ gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
+ gtk_widget_show (spinbutton);
+
+ button = gtk_button_new_with_label ("Add");
+ gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+ gtk_widget_show (button);
+
+ g_object_set_data (G_OBJECT (button), "spinbutton", spinbutton);
+ g_signal_connect (button, "clicked", G_CALLBACK (add_cb), merge);
+
+ button = gtk_button_new_with_label ("Remove");
+ gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+ gtk_widget_show (button);
+
+ g_signal_connect (button, "clicked", G_CALLBACK (remove_cb), merge);
+
gtk_widget_show (window);
}
diff --git a/tests/testgtk.c b/tests/testgtk.c
index f6d12898da..fb0e54409e 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -3551,6 +3551,23 @@ create_table_menu (GdkScreen *screen, gint cols, gint rows, gboolean tearoff)
menuitem = gtk_check_menu_item_new_with_label ("Check");
gtk_menu_attach (GTK_MENU (submenu), menuitem, 1, 2, 5, 6);
gtk_widget_show (menuitem);
+
+ menuitem = gtk_menu_item_new_with_label ("1. Inserted normally (8)");
+ gtk_widget_show (menuitem);
+ gtk_menu_shell_insert (GTK_MENU_SHELL (submenu), menuitem, 8);
+
+ menuitem = gtk_menu_item_new_with_label ("2. Inserted normally (2)");
+ gtk_widget_show (menuitem);
+ gtk_menu_shell_insert (GTK_MENU_SHELL (submenu), menuitem, 2);
+
+ menuitem = gtk_menu_item_new_with_label ("3. Inserted normally (0)");
+ gtk_widget_show (menuitem);
+ gtk_menu_shell_insert (GTK_MENU_SHELL (submenu), menuitem, 0);
+
+ menuitem = gtk_menu_item_new_with_label ("4. Inserted normally (-1)");
+ gtk_widget_show (menuitem);
+ gtk_menu_shell_insert (GTK_MENU_SHELL (submenu), menuitem, -1);
+
/* end of items submenu */
menuitem = gtk_menu_item_new_with_label ("spanning");
@@ -3593,6 +3610,9 @@ create_table_menu (GdkScreen *screen, gint cols, gint rows, gboolean tearoff)
menuitem = gtk_menu_item_new_with_label ("Empty");
gtk_menu_attach (GTK_MENU (submenu), menuitem, 0, 1, 0, 1);
+ submenu = gtk_menu_new ();
+ gtk_menu_set_screen (GTK_MENU (submenu), screen);
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
gtk_widget_show (menuitem);
menuitem = gtk_menu_item_new_with_label ("right");
@@ -3617,6 +3637,19 @@ create_table_menu (GdkScreen *screen, gint cols, gint rows, gboolean tearoff)
gtk_widget_show (menuitem);
}
+ menuitem = gtk_menu_item_new_with_label ("1. Inserted normally (8)");
+ gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menuitem, 8);
+ gtk_widget_show (menuitem);
+ menuitem = gtk_menu_item_new_with_label ("2. Inserted normally (2)");
+ gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menuitem, 2);
+ gtk_widget_show (menuitem);
+ menuitem = gtk_menu_item_new_with_label ("3. Inserted normally (0)");
+ gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menuitem, 0);
+ gtk_widget_show (menuitem);
+ menuitem = gtk_menu_item_new_with_label ("4. Inserted normally (-1)");
+ gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menuitem, -1);
+ gtk_widget_show (menuitem);
+
return menu;
}