6 * This module tests the selection interface on menu items.
7 * To use this module run the test program testgtk and use the menus
10 static void _do_selection (AtkObject *obj);
11 static gint _finish_selection (gpointer data);
12 static AtkObject* _find_object (AtkObject* obj, AtkRole role);
13 static void _print_type (AtkObject *obj);
16 _find_object (AtkObject *obj,
20 * Find the first object which is a descendant of the specified object
21 * which matches the specified role.
23 * This function returns a reference to the AtkObject which should be
24 * removed when finished with the object.
30 n_children = atk_object_get_n_accessible_children (obj);
31 for (i = 0; i < n_children; i++)
35 child = atk_object_ref_accessible_child (obj, i);
36 if (atk_object_get_role (child) == role)
40 found_obj = _find_object (child, role);
41 g_object_unref (child);
50 static void _print_type (AtkObject *obj)
52 const gchar * typename = NULL;
53 const gchar * name = NULL;
56 if (GTK_IS_ACCESSIBLE (obj))
58 GtkWidget* widget = NULL;
60 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
61 typename = g_type_name (G_OBJECT_TYPE (widget));
62 g_print ("Widget type name: %s\n", typename ? typename : "NULL");
64 typename = g_type_name (G_OBJECT_TYPE (obj));
65 g_print ("Accessible type name: %s\n", typename ? typename : "NULL");
66 name = atk_object_get_name (obj);
67 g_print("Accessible Name: %s\n", (name) ? name : "NULL");
68 role = atk_object_get_role(obj);
69 g_print ("Accessible Role: %d\n", role);
73 _do_selection (AtkObject *obj)
78 AtkObject *selection_obj;
80 role = atk_object_get_role (obj);
82 if ((role == ATK_ROLE_FRAME) &&
83 (strcmp (atk_object_get_name (obj), "menus") == 0))
85 selection_obj = _find_object (obj, ATK_ROLE_MENU_BAR);
88 g_object_unref (selection_obj);
91 else if (role == ATK_ROLE_COMBO_BOX)
98 g_print ("*** Start do_selection ***\n");
103 g_print ("no selection_obj\n");
107 i = atk_selection_get_selection_count (ATK_SELECTION (selection_obj));
110 for (i = 0; i < atk_object_get_n_accessible_children (selection_obj); i++)
112 if (atk_selection_is_child_selected (ATK_SELECTION (selection_obj), i))
114 g_print ("%d child selected\n", i);
118 g_print ("%d child not selected\n", i);
123 * Should not be able to select all items on a menu bar
125 atk_selection_select_all_selection (ATK_SELECTION (selection_obj));
126 i = atk_selection_get_selection_count (ATK_SELECTION (selection_obj));
129 g_print ("Unexpected selection count: %d, expected 0\n", i);
133 * There should not be any items selected
135 selected = atk_selection_ref_selection (ATK_SELECTION (selection_obj), 0);
136 if ( selected != NULL)
138 g_print ("Unexpected selection: %d, expected 0\n", i);
140 atk_selection_add_selection (ATK_SELECTION (selection_obj), 1);
141 g_timeout_add (2000, _finish_selection, selection_obj);
142 g_print ("*** End _do_selection ***\n");
145 static gint _finish_selection (gpointer data)
147 AtkObject *obj = ATK_OBJECT (data);
150 gboolean is_selected;
152 g_print ("*** Start Finish selection ***\n");
155 * If being run for for menus, at this point menu item foo should be
156 * selected which means that its submenu should be visible.
158 i = atk_selection_get_selection_count (ATK_SELECTION (obj));
161 g_print ("Unexpected selection count: %d, expected 1\n", i);
164 selected = atk_selection_ref_selection (ATK_SELECTION (obj), 0);
165 g_return_val_if_fail (selected != NULL, FALSE);
166 g_print ("*** Selected Item ***\n");
167 _print_type (selected);
168 g_object_unref (selected);
169 is_selected = atk_selection_is_child_selected (ATK_SELECTION (obj), 1);
170 g_return_val_if_fail (is_selected, FALSE);
171 is_selected = atk_selection_is_child_selected (ATK_SELECTION (obj), 0);
172 g_return_val_if_fail (!is_selected, FALSE);
173 selected = atk_selection_ref_selection (ATK_SELECTION (obj), 1);
174 g_return_val_if_fail (selected == NULL, FALSE);
175 atk_selection_remove_selection (ATK_SELECTION (obj), 0);
176 i = atk_selection_get_selection_count (ATK_SELECTION (obj));
177 g_return_val_if_fail (i == 0, FALSE);
178 selected = atk_selection_ref_selection (ATK_SELECTION (obj), 0);
179 g_return_val_if_fail (selected == NULL, FALSE);
180 g_print ("*** End Finish selection ***\n");
185 _create_event_watcher (void)
187 atk_add_focus_tracker (_do_selection);
191 gtk_module_init(gint argc, char* argv[])
193 g_print("testselection Module loaded\n");
195 _create_event_watcher();