6 * This module is used to test the accessible implementation for menu items
8 * 1) When a menu item is clicked in testgtk, the action for the
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
14 #define NUM_VALID_ROLES 1
16 static void _create_event_watcher (void);
17 static void _check_object (AtkObject *obj);
18 static gint _do_menu_item_action (gpointer data);
21 _check_object (AtkObject *obj)
24 static const char *name = NULL;
25 static gboolean first_time = TRUE;
27 role = atk_object_get_role (obj);
28 if (role == ATK_ROLE_FRAME)
30 * Find the specified menu item
33 AtkRole valid_roles[NUM_VALID_ROLES];
34 AtkObject *atk_menu_item;
39 valid_roles[0] = ATK_ROLE_MENU_ITEM;
41 name = g_getenv ("TEST_ACCESSIBLE_NAME");
45 atk_menu_item = find_object_by_accessible_name_and_role (obj, name,
46 valid_roles, NUM_VALID_ROLES);
48 if (atk_menu_item == NULL)
50 g_print ("Object not found for %s\n", name);
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));
64 * This action opens the menu whose name is "foo" or whatever
65 * was specified in the environment variable TEST_ACCESSIBLE_NAME
67 atk_action_do_action (ATK_ACTION (atk_menu_item), 0);
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))
74 const char *keybinding;
75 const char *accessible_name;
77 accessible_name = atk_object_get_name (obj);
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);
83 g_print ("KeyBinding: %s\n", keybinding);
85 * Do the action associated with the menu item once, otherwise
88 if (strcmp (name, accessible_name) == 0)
94 if (g_getenv ("TEST_ACCESSIBLE_AUTO"))
96 g_idle_add (_do_menu_item_action, obj);
102 const char *accessible_name;
104 accessible_name = atk_object_get_name (obj);
106 g_print ("Name: %s\n", accessible_name);
107 else if (GTK_IS_ACCESSIBLE (obj))
111 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
112 g_print ("Type: %s\n", g_type_name (G_OBJECT_TYPE (widget)));
117 static gint _do_menu_item_action (gpointer data)
119 AtkObject *obj = ATK_OBJECT (data);
121 atk_action_do_action (ATK_ACTION (obj), 0);
127 _create_event_watcher (void)
129 atk_add_focus_tracker (_check_object);
133 gtk_module_init(gint argc, char* argv[])
135 g_print("testmenuitem Module loaded\n");
137 _create_event_watcher();