]> Pileus Git - ~andy/gtk/blob - modules/other/gail/tests/testnotebook.c
Deprecate flag macros for toplevel, state, no window and composite child
[~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   G_CONST_RETURN gchar *typename = NULL;
18   G_CONST_RETURN gchar *name = NULL;
19   G_CONST_RETURN gchar *description = NULL;
20   AtkRole role;
21
22   if (GTK_IS_ACCESSIBLE (obj))
23   {
24     GtkWidget* widget = NULL;
25
26     widget = GTK_ACCESSIBLE (obj)->widget;
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   if (GTK_IS_ACCESSIBLE (obj))
166     widget = GTK_ACCESSIBLE (obj)->widget;
167      
168   g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE);
169   gtk_notebook_remove_page (GTK_NOTEBOOK (widget), 4);
170   return FALSE;
171 }
172
173 static gint _finish_selection (gpointer data)
174 {
175   AtkObject *obj = ATK_OBJECT (data);
176   AtkObject *selected;
177   AtkObject *parent_object;
178   GtkWidget *parent_widget;
179   gint      i, index;
180
181   g_print ("\t*** Start Finish selection ***\n");
182   
183   i = atk_selection_get_selection_count (ATK_SELECTION (obj));
184   if (i != 1)
185   {
186     g_print ("\tUnexpected selection count: %d, expected 1\n", i);
187     return FALSE;
188   }
189   selected = atk_selection_ref_selection (ATK_SELECTION (obj), 0);
190   g_return_val_if_fail (selected != NULL, FALSE);
191   
192   g_print ("\t*** Selected Item ***\n");
193   index = atk_object_get_index_in_parent (selected);
194   g_print ("\tIndex in parent is: %d\n", index);
195   
196   parent_object = atk_object_get_parent (selected);
197   g_return_val_if_fail (ATK_IS_OBJECT (parent_object), FALSE);
198   g_return_val_if_fail (parent_object == obj, FALSE);
199   parent_widget = GTK_ACCESSIBLE (parent_object)->widget;
200   g_return_val_if_fail (GTK_IS_NOTEBOOK (parent_widget), FALSE);
201   
202   _print_type (selected);
203   i = atk_selection_get_selection_count (ATK_SELECTION (obj));
204   g_return_val_if_fail (i == 1, FALSE);
205   g_object_unref (selected);
206   g_print ("\t*** End Finish selection ***\n");
207   return FALSE;
208 }
209   
210   
211 static void
212 _create_event_watcher (void)
213 {
214   atk_add_focus_tracker (_do_selection);
215 }
216
217 int
218 gtk_module_init(gint argc, char* argv[])
219 {
220   g_print("testnotebook Module loaded\n");
221
222   _create_event_watcher();
223
224   return 0;
225 }