8 #define NUM_VALID_ROLES 1
10 static void _print_type (AtkObject *obj);
11 static void _do_selection (AtkObject *obj);
12 static gint _finish_selection (gpointer data);
13 static gint _remove_page (gpointer data);
15 static void _print_type (AtkObject *obj)
17 const gchar *typename = NULL;
18 const gchar *name = NULL;
19 const gchar *description = NULL;
22 if (GTK_IS_ACCESSIBLE (obj))
24 GtkWidget* widget = NULL;
26 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
27 typename = g_type_name (G_OBJECT_TYPE (widget));
28 g_print ("\tWidget type name: %s\n", typename ? typename : "NULL");
31 typename = g_type_name (G_OBJECT_TYPE (obj));
32 g_print ("\tAccessible type name: %s\n", typename ? typename : "NULL");
34 name = atk_object_get_name (obj);
35 g_print("\tAccessible Name: %s\n", (name) ? name : "NULL");
37 role = atk_object_get_role(obj);
38 g_print ("\tAccessible Role: %d\n", role);
40 description = atk_object_get_description (obj);
41 g_print ("\tAccessible Description: %s\n", (description) ? description : "NULL");
42 if (role == ATK_ROLE_PAGE_TAB)
44 AtkObject *parent, *child;
45 gint x, y, width, height;
47 x = y = width = height = 0;
48 atk_component_get_extents (ATK_COMPONENT (obj), &x, &y, &width, &height,
50 g_print ("obj: x: %d y: %d width: %d height: %d\n", x, y, width, height);
51 x = y = width = height = 0;
52 atk_component_get_extents (ATK_COMPONENT (obj), &x, &y, &width, &height,
54 g_print ("obj: x: %d y: %d width: %d height: %d\n", x, y, width, height);
55 parent = atk_object_get_parent (obj);
56 x = y = width = height = 0;
57 atk_component_get_extents (ATK_COMPONENT (parent), &x, &y, &width, &height,
59 g_print ("parent: x: %d y: %d width: %d height: %d\n", x, y, width, height);
60 x = y = width = height = 0;
61 atk_component_get_extents (ATK_COMPONENT (parent), &x, &y, &width, &height,
63 g_print ("parent: x: %d y: %d width: %d height: %d\n", x, y, width, height);
65 child = atk_object_ref_accessible_child (obj, 0);
66 x = y = width = height = 0;
67 atk_component_get_extents (ATK_COMPONENT (child), &x, &y, &width, &height,
69 g_print ("child: x: %d y: %d width: %d height: %d\n", x, y, width, height);
70 x = y = width = height = 0;
71 atk_component_get_extents (ATK_COMPONENT (child), &x, &y, &width, &height,
73 g_print ("child: x: %d y: %d width: %d height: %d\n", x, y, width, height);
75 g_object_unref (child);
81 _do_selection (AtkObject *obj)
86 AtkObject *selection_obj;
87 static gboolean done_selection = FALSE;
92 role = atk_object_get_role (obj);
94 if (role == ATK_ROLE_FRAME)
96 AtkRole roles[NUM_VALID_ROLES];
98 roles[0] = ATK_ROLE_PAGE_TAB_LIST;
100 selection_obj = find_object_by_role (obj, roles, NUM_VALID_ROLES);
104 done_selection = TRUE;
114 g_print ("*** Start do_selection ***\n");
116 n_children = atk_object_get_n_accessible_children (selection_obj);
117 g_print ("*** Number of notebook pages: %d\n", n_children);
119 for (i = 0; i < n_children; i++)
121 if (atk_selection_is_child_selected (ATK_SELECTION (selection_obj), i))
123 g_print ("%d page selected\n", i);
127 g_print ("%d page not selected\n", i);
131 * Should not be able to select all items in a notebook.
133 atk_selection_select_all_selection (ATK_SELECTION (selection_obj));
134 i = atk_selection_get_selection_count (ATK_SELECTION (selection_obj));
137 g_print ("Unexpected selection count: %d, expected 1\n", i);
138 g_print ("\t value of i is: %d\n", i);
142 for (i = 0; i < n_children; i++)
144 atk_selection_add_selection (ATK_SELECTION (selection_obj), i);
146 if (atk_selection_is_child_selected (ATK_SELECTION (selection_obj), i))
148 g_print ("Page %d: successfully selected\n", i);
149 _finish_selection (selection_obj);
153 g_print ("ERROR: child %d: selection failed\n", i);
156 g_print ("*** End _do_selection ***\n");
157 g_timeout_add (5000, _remove_page, selection_obj);
160 static gint _remove_page (gpointer data)
162 AtkObject *obj = ATK_OBJECT (data);
163 GtkWidget *widget = NULL;
165 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
167 g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
168 gtk_notebook_remove_page (GTK_NOTEBOOK (widget), 4);
172 static gint _finish_selection (gpointer data)
174 AtkObject *obj = ATK_OBJECT (data);
176 AtkObject *parent_object;
177 GtkWidget *parent_widget;
180 g_print ("\t*** Start Finish selection ***\n");
182 i = atk_selection_get_selection_count (ATK_SELECTION (obj));
185 g_print ("\tUnexpected selection count: %d, expected 1\n", i);
188 selected = atk_selection_ref_selection (ATK_SELECTION (obj), 0);
189 g_return_val_if_fail (selected != NULL, FALSE);
191 g_print ("\t*** Selected Item ***\n");
192 index = atk_object_get_index_in_parent (selected);
193 g_print ("\tIndex in parent is: %d\n", index);
195 parent_object = atk_object_get_parent (selected);
196 g_return_val_if_fail (ATK_IS_OBJECT (parent_object), FALSE);
197 g_return_val_if_fail (parent_object == obj, FALSE);
198 parent_widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent_object));
199 g_return_val_if_fail (GTK_IS_NOTEBOOK (parent_widget), FALSE);
201 _print_type (selected);
202 i = atk_selection_get_selection_count (ATK_SELECTION (obj));
203 g_return_val_if_fail (i == 1, FALSE);
204 g_object_unref (selected);
205 g_print ("\t*** End Finish selection ***\n");
211 _create_event_watcher (void)
213 atk_add_focus_tracker (_do_selection);
217 gtk_module_init(gint argc, char* argv[])
219 g_print("testnotebook Module loaded\n");
221 _create_event_watcher();