]> Pileus Git - ~andy/gtk/blob - modules/other/gail/tests/testnotebook.c
9b8f9e3e5af0dd6cac37dc8b7c64187f4d5c7768
[~andy/gtk] / modules / other / gail / tests / testnotebook.c
1 #include <stdio.h>
2
3 #include <glib.h>
4 #include <atk/atk.h>
5 #include <gtk/gtk.h>
6 #include "testlib.h"
7
8 #define NUM_VALID_ROLES 1
9
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);
14
15 static void _print_type (AtkObject *obj)
16 {
17   const gchar *typename = NULL;
18   const gchar *name = NULL;
19   const gchar *description = NULL;
20   AtkRole role;
21
22   if (GTK_IS_ACCESSIBLE (obj))
23   {
24     GtkWidget* widget = NULL;
25
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");
29   }
30
31   typename = g_type_name (G_OBJECT_TYPE (obj));
32   g_print ("\tAccessible type name: %s\n", typename ? typename : "NULL");
33   
34   name = atk_object_get_name (obj);
35   g_print("\tAccessible Name: %s\n", (name) ? name : "NULL");
36   
37   role = atk_object_get_role(obj);
38   g_print ("\tAccessible Role: %d\n", role);
39   
40   description = atk_object_get_description (obj);
41   g_print ("\tAccessible Description: %s\n", (description) ? description : "NULL");
42   if (role ==  ATK_ROLE_PAGE_TAB)
43   {
44     AtkObject *parent, *child;
45     gint x, y, width, height;
46
47     x = y = width = height = 0;
48     atk_component_get_extents (ATK_COMPONENT (obj), &x, &y, &width, &height,
49                                ATK_XY_SCREEN);
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,
53                                ATK_XY_WINDOW);
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,
58                                ATK_XY_SCREEN);
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,
62                                ATK_XY_WINDOW);
63     g_print ("parent: x: %d y: %d width: %d height: %d\n", x, y, width, height);
64
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,
68                                ATK_XY_SCREEN);
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,
72                                ATK_XY_WINDOW);
73     g_print ("child: x: %d y: %d width: %d height: %d\n", x, y, width, height);
74
75     g_object_unref (child);
76   }
77 }
78
79
80 static void
81 _do_selection (AtkObject *obj)
82 {
83   gint i;
84   gint n_children;
85   AtkRole role;
86   AtkObject *selection_obj;
87   static gboolean done_selection = FALSE;
88   
89   if (done_selection)
90     return;
91
92   role = atk_object_get_role (obj);
93
94   if (role == ATK_ROLE_FRAME)
95   {
96     AtkRole roles[NUM_VALID_ROLES];
97
98     roles[0] = ATK_ROLE_PAGE_TAB_LIST;
99
100     selection_obj = find_object_by_role (obj, roles, NUM_VALID_ROLES);
101
102     if (selection_obj)
103     {
104       done_selection = TRUE;
105     }
106     else
107       return;
108   }
109   else
110   {
111     return;
112   }
113
114   g_print ("*** Start do_selection ***\n");
115   
116   n_children = atk_object_get_n_accessible_children (selection_obj);
117   g_print ("*** Number of notebook pages: %d\n", n_children); 
118
119   for (i = 0; i < n_children; i++)
120   {
121     if (atk_selection_is_child_selected (ATK_SELECTION (selection_obj), i))
122     {
123       g_print ("%d page selected\n", i);
124     }
125     else
126     {
127       g_print ("%d page not selected\n", i);
128     }
129   }
130   /*
131    * Should not be able to select all items in a notebook.
132    */
133   atk_selection_select_all_selection (ATK_SELECTION (selection_obj));
134   i = atk_selection_get_selection_count (ATK_SELECTION (selection_obj));
135   if ( i != 1)
136   {
137     g_print ("Unexpected selection count: %d, expected 1\n", i);
138     g_print ("\t value of i is: %d\n", i);
139     return;
140   }
141
142   for (i = 0; i < n_children; i++)
143   {
144     atk_selection_add_selection (ATK_SELECTION (selection_obj), i);
145         
146     if (atk_selection_is_child_selected (ATK_SELECTION (selection_obj), i))
147     {
148       g_print ("Page %d: successfully selected\n", i);
149       _finish_selection (selection_obj);
150     }
151     else
152     {
153       g_print ("ERROR: child %d: selection failed\n", i);
154     }
155   }
156   g_print ("*** End _do_selection ***\n");
157   g_timeout_add (5000, _remove_page, selection_obj);
158
159
160 static gint _remove_page (gpointer data)
161 {
162   AtkObject *obj = ATK_OBJECT (data);
163   GtkWidget *widget = NULL;
164
165   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
166
167   g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
168   gtk_notebook_remove_page (GTK_NOTEBOOK (widget), 4);
169   return FALSE;
170 }
171
172 static gint _finish_selection (gpointer data)
173 {
174   AtkObject *obj = ATK_OBJECT (data);
175   AtkObject *selected;
176   AtkObject *parent_object;
177   GtkWidget *parent_widget;
178   gint      i, index;
179
180   g_print ("\t*** Start Finish selection ***\n");
181   
182   i = atk_selection_get_selection_count (ATK_SELECTION (obj));
183   if (i != 1)
184   {
185     g_print ("\tUnexpected selection count: %d, expected 1\n", i);
186     return FALSE;
187   }
188   selected = atk_selection_ref_selection (ATK_SELECTION (obj), 0);
189   g_return_val_if_fail (selected != NULL, FALSE);
190   
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);
194   
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);
200   
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");
206   return FALSE;
207 }
208   
209   
210 static void
211 _create_event_watcher (void)
212 {
213   atk_add_focus_tracker (_do_selection);
214 }
215
216 int
217 gtk_module_init(gint argc, char* argv[])
218 {
219   g_print("testnotebook Module loaded\n");
220
221   _create_event_watcher();
222
223   return 0;
224 }