diff --git a/tests/Makefile.am b/tests/Makefile.am index ca43e6d954..08dabea434 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -143,7 +143,9 @@ noinst_PROGRAMS = $(TEST_PROGS) \ testtitlebar \ testsplitheaders \ testactionbar \ - testwindowsize + testwindowsize \ + testpopover \ + $(NULL) if USE_X11 noinst_PROGRAMS += testerrors diff --git a/tests/popover.ui b/tests/popover.ui new file mode 100644 index 0000000000..74ffdb9b9a --- /dev/null +++ b/tests/popover.ui @@ -0,0 +1,118 @@ + + +
+ + No action + action1 + + + Toggle + top.action2 + action-missing + + + Another Toggle + top.action2a + +
+
+ Middle Section + + Radio 1 + top.action3 + three + + + Radio 2 + top.action3 + four + +
+ + Submenu 1 +
+ 5555 + + Item 5 + top.action5 + + + Item 5a + top.action5 + + + Item 5b + top.action5 + + + Item 5c + top.action5 + + + Item 5d + top.action5 + +
+
+ 6666 + + Item 6 + top.action6 + + + Item 6a + top.action6 + + + Item 6b + top.action6 + + + Item 6c + top.action6 + + + Item 6d + top.action6 + +
+
+ + Submenu 2 + + Item 7 + top.action7 + + + Subsubmenu + preferences-desktop-font + + Item 8 + action8 + +
+ + Item 9 + top.action9 + + + Item 10 + top.action10 + +
+
+
+
+ End Section + + Another Item 9 + top.action9 + preferences-desktop-font + + + Another Item 10 + top.action10 + +
+
+
diff --git a/tests/testpopover.c b/tests/testpopover.c new file mode 100644 index 0000000000..c8e7d78ba8 --- /dev/null +++ b/tests/testpopover.c @@ -0,0 +1,71 @@ +#include + +static void +activate (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + g_print ("%s activated\n", g_action_get_name (G_ACTION (action))); +} + +static GActionEntry entries[] = { + { "action1", activate, NULL, NULL, NULL }, + { "action2", NULL, NULL, "true", NULL }, + { "action2a", NULL, NULL, "false", NULL }, + { "action3", NULL, "s", "'three'", NULL }, + { "action4", activate, NULL, NULL, NULL }, + { "action5", activate, NULL, NULL, NULL }, + { "action6", activate, NULL, NULL, NULL }, + { "action7", activate, NULL, NULL, NULL }, + { "action8", activate, NULL, NULL, NULL }, + { "action9", activate, NULL, NULL, NULL }, + { "action10", activate, NULL, NULL, NULL } +}; + +int main (int argc, char *argv[]) +{ + GtkWidget *win; + GtkWidget *button; + GtkBuilder *builder; + GMenuModel *model; + GtkWidget *popover; + GSimpleActionGroup *actions; + GtkWidget *box; + + gtk_init (&argc, &argv); + + win = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_default_size (GTK_WINDOW (win), 400, 600); + actions = g_simple_action_group_new (); + g_action_map_add_action_entries (G_ACTION_MAP (actions), entries, G_N_ELEMENTS (entries), NULL); + + gtk_widget_insert_action_group (win, "top", G_ACTION_GROUP (actions)); + + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_container_add (GTK_CONTAINER (win), box); + + button = gtk_button_new_with_label ("Pop"); + g_object_set (button, "margin", 10, NULL); + gtk_widget_set_halign (button, GTK_ALIGN_END); + gtk_widget_set_valign (button, GTK_ALIGN_START); + gtk_container_add (GTK_CONTAINER (box), button); + + builder = gtk_builder_new_from_file ("popover.ui"); + model = (GMenuModel *)gtk_builder_get_object (builder, "menu"); + popover = gtk_popover_new_from_model (button, model); + g_signal_connect_swapped (button, "clicked", + G_CALLBACK (gtk_widget_show), popover); + + button = gtk_menu_button_new (); + gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), model); + g_object_set (button, "margin", 10, NULL); + gtk_widget_set_halign (button, GTK_ALIGN_END); + gtk_widget_set_valign (button, GTK_ALIGN_START); + gtk_container_add (GTK_CONTAINER (box), button); + + gtk_widget_show_all (win); + + gtk_main (); + + return 0; +}