1 #include <dazzle.h>
2 
3 static void
load_css(void)4 load_css (void)
5 {
6   g_autoptr(GtkCssProvider) provider = NULL;
7 
8   provider = dzl_css_provider_new ("resource:///org/gnome/dazzle/themes");
9   gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
10                                              GTK_STYLE_PROVIDER (provider),
11                                              GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
12 }
13 
14 gint
main(gint argc,gchar * argv[])15 main (gint argc,
16       gchar *argv[])
17 {
18   GtkWidget *window;
19   GtkWidget *menu_button;
20   g_autoptr(DzlMenuManager) manager = NULL;
21   g_autoptr(DzlJoinedMenu) joined = NULL;
22   g_autoptr(GError) error = NULL;
23   g_autofree gchar *filename1 = g_build_filename (TEST_DATA_DIR, "menus/joined1.ui", NULL);
24   g_autofree gchar *filename2 = g_build_filename (TEST_DATA_DIR, "menus/joined2.ui", NULL);
25   GMenu *menu1;
26   GMenu *menu2;
27 
28   gtk_init (&argc, &argv);
29 
30   load_css ();
31 
32   manager = dzl_menu_manager_new ();
33 
34   dzl_menu_manager_add_filename (manager, filename1, &error);
35   g_assert_no_error (error);
36   menu1 = dzl_menu_manager_get_menu_by_id (manager, "document-menu");
37 
38   {
39     g_autofree gchar *icon = NULL;
40     g_autoptr(GMenuModel) section = NULL;
41     gboolean r;
42 
43     section = g_menu_model_get_item_link (G_MENU_MODEL (menu1), 0, "section");
44     g_assert (section != NULL);
45     g_assert_cmpint (g_menu_model_get_n_items (section), ==, 3);
46 
47     r = g_menu_model_get_item_attribute (section, 0, "verb-icon-name", "s", &icon);
48     g_assert_true (r);
49     g_assert_cmpstr (icon, ==, "document-open-symbolic");
50   }
51 
52   dzl_menu_manager_add_filename (manager, filename2, &error);
53   g_assert_no_error (error);
54   menu2 = dzl_menu_manager_get_menu_by_id (manager, "frame-menu");
55 
56   joined = dzl_joined_menu_new ();
57   dzl_joined_menu_append_menu (joined, G_MENU_MODEL (menu1));
58   dzl_joined_menu_append_menu (joined, G_MENU_MODEL (menu2));
59 
60   {
61     g_autofree gchar *icon = NULL;
62     g_autoptr(GMenuModel) section = NULL;
63     gboolean r;
64 
65     section = g_menu_model_get_item_link (G_MENU_MODEL (joined), 0, "section");
66     g_assert (section != NULL);
67     g_assert_cmpint (g_menu_model_get_n_items (section), ==, 3);
68 
69     r = g_menu_model_get_item_attribute (section, 0, "verb-icon-name", "s", &icon);
70     g_assert_true (r);
71     g_assert_cmpstr (icon, ==, "document-open-symbolic");
72   }
73 
74   window = g_object_new (GTK_TYPE_WINDOW,
75                          "default-width", 100,
76                          "default-height", 100,
77                          "border-width", 32,
78                          "title", "Joined Menu Test",
79                          NULL);
80   menu_button = g_object_new (DZL_TYPE_MENU_BUTTON,
81                               "show-arrow", TRUE,
82                               "show-accels", TRUE,
83                               "show-icons", TRUE,
84                               "icon-name", "document-open-symbolic",
85                               "model", joined,
86                               "visible", TRUE,
87                               NULL);
88   gtk_container_add (GTK_CONTAINER (window), menu_button);
89   g_signal_connect (window, "delete-event", gtk_main_quit, NULL);
90   gtk_window_present (GTK_WINDOW (window));
91 
92   gtk_main ();
93 
94   return 0;
95 }
96