diff options
author | Matthias Clasen <mclasen@redhat.com> | 2014-01-26 08:02:28 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2014-02-07 15:11:51 -0500 |
commit | 59099cd6e7abe620e02c08d746ec60ce3e07eeed (patch) | |
tree | 7be9936d33c22e1aded1203135000387faec7c57 /tests | |
parent | 2fea2d4dbd700a60c41f07e8bfc44e05d0ef1f26 (diff) | |
download | gtk+-59099cd6e7abe620e02c08d746ec60ce3e07eeed.tar.gz |
Add a test for model-based popovers
https://bugzilla.gnome.org/show_bug.cgi?id=723014
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 4 | ||||
-rw-r--r-- | tests/popover.ui | 118 | ||||
-rw-r--r-- | tests/testpopover.c | 71 |
3 files changed, 192 insertions, 1 deletions
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 @@ +<interface> + <menu id="menu"> + <section> + <item> + <attribute name="label">No action</attribute> + <attribute name="action">action1</attribute> + </item> + <item> + <attribute name="label">Toggle</attribute> + <attribute name="action">top.action2</attribute> + <attribute name="hidden-when">action-missing</attribute> + </item> + <item> + <attribute name="label">Another Toggle</attribute> + <attribute name="action">top.action2a</attribute> + </item> + </section> + <section> + <attribute name="label">Middle Section</attribute> + <item> + <attribute name="label">Radio 1</attribute> + <attribute name="action">top.action3</attribute> + <attribute name="target">three</attribute> + </item> + <item> + <attribute name="label">Radio 2</attribute> + <attribute name="action">top.action3</attribute> + <attribute name="target">four</attribute> + </item> + </section> + <submenu> + <attribute name="label">Submenu 1</attribute> + <section> + <attribute name="label">5555</attribute> + <item> + <attribute name="label">Item 5</attribute> + <attribute name="action">top.action5</attribute> + </item> + <item> + <attribute name="label">Item 5a</attribute> + <attribute name="action">top.action5</attribute> + </item> + <item> + <attribute name="label">Item 5b</attribute> + <attribute name="action">top.action5</attribute> + </item> + <item> + <attribute name="label">Item 5c</attribute> + <attribute name="action">top.action5</attribute> + </item> + <item> + <attribute name="label">Item 5d</attribute> + <attribute name="action">top.action5</attribute> + </item> + </section> + <section> + <attribute name="label">6666</attribute> + <item> + <attribute name="label">Item 6</attribute> + <attribute name="action">top.action6</attribute> + </item> + <item> + <attribute name="label">Item 6a</attribute> + <attribute name="action">top.action6</attribute> + </item> + <item> + <attribute name="label">Item 6b</attribute> + <attribute name="action">top.action6</attribute> + </item> + <item> + <attribute name="label">Item 6c</attribute> + <attribute name="action">top.action6</attribute> + </item> + <item> + <attribute name="label">Item 6d</attribute> + <attribute name="action">top.action6</attribute> + </item> + </section> + </submenu> + <submenu> + <attribute name="label">Submenu 2</attribute> + <item> + <attribute name="label">Item 7</attribute> + <attribute name="action">top.action7</attribute> + </item> + <submenu> + <attribute name="label">Subsubmenu</attribute> + <attribute name="icon">preferences-desktop-font</attribute> + <item> + <attribute name="label">Item 8</attribute> + <attribute name="action">action8</attribute> + </item> + <section> + <item> + <attribute name="label">Item 9</attribute> + <attribute name="action">top.action9</attribute> + </item> + <item> + <attribute name="label">Item 10</attribute> + <attribute name="action">top.action10</attribute> + </item> + </section> + </submenu> + </submenu> + <section> + <attribute name="label">End Section</attribute> + <item> + <attribute name="label">Another Item 9</attribute> + <attribute name="action">top.action9</attribute> + <attribute name="icon">preferences-desktop-font</attribute> + </item> + <item> + <attribute name="label">Another Item 10</attribute> + <attribute name="action">top.action10</attribute> + </item> + </section> + </menu> +</interface> 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 <gtk/gtk.h> + +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; +} |