]> Pileus Git - ~andy/gtk/blob - gtk/a11y/tests/testmenuitem.c
gail: No need to include modules/other in CFLAGS anymore
[~andy/gtk] / gtk / a11y / tests / testmenuitem.c
1 #include <string.h>
2 #include <gtk/gtk.h>
3 #include "testlib.h"
4
5 /*
6  * This module is used to test the accessible implementation for menu items
7  *
8  * 1) When a menu item is clicked in testgtk, the action for the
9  * item is performed.
10  * 2) The name of the keybinding for the 'activate" action for a menu item
11  * is output, if it exists.
12  * 3) Execute the action for a menu item programatically
13  */
14 #define NUM_VALID_ROLES 1
15
16 static void _create_event_watcher (void);
17 static void _check_object (AtkObject *obj);
18 static gint _do_menu_item_action (gpointer data);
19
20 static void 
21 _check_object (AtkObject *obj)
22 {
23   AtkRole role;
24   static const char *name = NULL;
25   static gboolean first_time = TRUE;
26
27   role = atk_object_get_role (obj);
28   if (role == ATK_ROLE_FRAME)
29   /*
30    * Find the specified menu item
31    */
32   {
33     AtkRole valid_roles[NUM_VALID_ROLES];
34     AtkObject *atk_menu_item;
35     GtkWidget *widget;
36
37     if (name == NULL)
38     {
39       valid_roles[0] = ATK_ROLE_MENU_ITEM;
40
41       name = g_getenv ("TEST_ACCESSIBLE_NAME");
42       if (name == NULL)
43         name = "foo";
44     }
45     atk_menu_item = find_object_by_accessible_name_and_role (obj, name,
46                      valid_roles, NUM_VALID_ROLES);
47
48     if (atk_menu_item == NULL)
49     {
50       g_print ("Object not found for %s\n", name);
51       return;
52     }
53
54     g_assert (GTK_IS_ACCESSIBLE (atk_menu_item));
55     widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_menu_item));
56     g_assert (GTK_IS_MENU_ITEM (widget));
57
58     if (first_time)
59       first_time = FALSE;
60     else
61       return;
62
63     /*
64      * This action opens the menu whose name is "foo" or whatever
65      * was specified in the environment variable TEST_ACCESSIBLE_NAME
66      */
67     atk_action_do_action (ATK_ACTION (atk_menu_item), 0);
68   }
69   else if ((role == ATK_ROLE_MENU_ITEM) ||
70            (role == ATK_ROLE_CHECK_MENU_ITEM) ||
71            (role == ATK_ROLE_RADIO_MENU_ITEM) ||
72            (role == ATK_ROLE_TEAR_OFF_MENU_ITEM))
73   {
74     const char *keybinding;
75     const char *accessible_name;
76
77     accessible_name = atk_object_get_name (obj);
78     if (accessible_name)
79       g_print ("Name: %s\n", accessible_name);
80     g_print ("Action: %s\n", atk_action_get_name (ATK_ACTION (obj), 0));
81     keybinding = atk_action_get_keybinding (ATK_ACTION (obj), 0);
82     if (keybinding)
83       g_print ("KeyBinding: %s\n", keybinding);
84     /*
85      * Do the action associated with the menu item once, otherwise
86      * we get into a loop
87      */
88     if (strcmp (name, accessible_name) == 0)
89     {
90       if (first_time)
91         first_time = FALSE;
92       else
93         return;
94       if (g_getenv ("TEST_ACCESSIBLE_AUTO"))
95         {
96           g_idle_add (_do_menu_item_action, obj);
97         }
98     }
99   }
100   else
101   {
102     const char *accessible_name;
103
104     accessible_name = atk_object_get_name (obj);
105     if (accessible_name)
106       g_print ("Name: %s\n", accessible_name);
107     else if (GTK_IS_ACCESSIBLE (obj))
108     {
109       GtkWidget *widget;
110
111       widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
112       g_print ("Type: %s\n", g_type_name (G_OBJECT_TYPE (widget)));
113     } 
114   }
115 }
116
117 static gint _do_menu_item_action (gpointer data)
118 {
119   AtkObject *obj = ATK_OBJECT (data);
120
121   atk_action_do_action (ATK_ACTION (obj), 0);
122
123   return FALSE;
124 }
125
126 static void
127 _create_event_watcher (void)
128 {
129   atk_add_focus_tracker (_check_object);
130 }
131
132 int
133 gtk_module_init(gint argc, char* argv[])
134 {
135   g_print("testmenuitem Module loaded\n");
136
137   _create_event_watcher();
138
139   return 0;
140 }