]> Pileus Git - ~andy/gtk/blob - gtk/a11y/tests/testtoplevel.c
gail: Move from modules/other/gail to gtk/a11y
[~andy/gtk] / gtk / a11y / tests / testtoplevel.c
1 #include <atk/atk.h>
2 #include <gtk/gtk.h>
3 #include "testlib.h"
4
5 static void _notify_toplevel_child_added (GObject *obj,
6   guint index, AtkObject *child, gpointer user_data);
7 static void _notify_toplevel_child_removed (GObject *obj,
8   guint index, AtkObject *child, gpointer user_data);
9 static gboolean _button_press_event_watcher (GSignalInvocationHint *ihint,
10   guint n_param_values, const GValue *param_values, gpointer data);
11
12 static guint id;
13 static gboolean g_register_listener = FALSE;
14 static guint g_signal_listener = 0;
15 static gint g_press_count = 0;
16
17 static void
18 _check_toplevel (AtkObject *obj)
19 {
20   AtkObject *root_obj;
21   const gchar *name_string, *version_string;
22   gint max_depth;
23
24   g_print ("Start of _check_toplevel\n");
25   root_obj = atk_get_root();
26
27   if (!already_accessed_atk_object(root_obj))
28     {
29       g_signal_connect_closure (root_obj, "children_changed::add",
30                 g_cclosure_new (G_CALLBACK (_notify_toplevel_child_added),
31                 NULL, NULL),
32                 FALSE);
33
34       g_signal_connect_closure (root_obj, "children_changed::remove",
35                 g_cclosure_new (G_CALLBACK (_notify_toplevel_child_removed),
36                 NULL, NULL),
37                 FALSE);
38     }
39
40   name_string = atk_get_toolkit_name();
41   version_string = atk_get_toolkit_version();
42   g_print ("Toolkit name <%s> version <%s>\n", name_string,
43     version_string);
44
45   if (g_getenv("TEST_ACCESSIBLE_DEPTH") != NULL)
46     max_depth = string_to_int(g_getenv("TEST_ACCESSIBLE_DEPTH"));
47   else
48     max_depth = 2;
49
50   display_children_to_depth(root_obj, max_depth, 0, 0);
51   g_print ("End of _check_toplevel\n");
52
53   if (!g_register_listener)
54     {
55       g_print("Adding global event listener on buttons\n");
56       g_register_listener = TRUE;
57       g_signal_listener = atk_add_global_event_listener(_button_press_event_watcher,
58         "Gtk:GtkButton:pressed");
59     }
60 }
61
62 static void
63 _create_event_watcher (void)
64 {
65   id = atk_add_focus_tracker (_check_toplevel);
66 }
67
68 int
69 gtk_module_init(gint argc, char* argv[])
70 {
71   g_print("testtoplevel Module loaded\n");
72
73   _create_event_watcher();
74
75   return 0;
76 }
77
78 static void _notify_toplevel_child_added (GObject *obj,
79   guint child_index, AtkObject *child, gpointer user_data)
80 {
81    g_print ("SIGNAL - Child added - index %d\n", child_index);
82 }
83
84 static void _notify_toplevel_child_removed (GObject *obj,
85   guint child_index, AtkObject *child, gpointer user_data)
86 {
87    g_print ("SIGNAL - Child removed - index %d\n", child_index);
88 }
89
90 static gboolean
91 _button_press_event_watcher (GSignalInvocationHint *ihint,
92                     guint                  n_param_values,
93                     const GValue          *param_values,
94                     gpointer               data)
95 {
96   GObject *object;
97   gchar * button_name = (gchar *) data;
98
99   object = g_value_get_object (param_values + 0);
100
101   if (ATK_IS_IMPLEMENTOR(object))
102     {
103       AtkObject * atk_obj =
104         atk_implementor_ref_accessible(ATK_IMPLEMENTOR(object));
105
106       g_print("Button <%s> pressed %d times!\n", button_name,
107         (g_press_count + 1));
108       g_print("Displaying children of Button pressed!\n");
109       display_children(atk_obj, 0, 0);
110
111       if (g_press_count >= 5)
112         {
113           g_print("Removing global event listener on buttons\n");
114           atk_remove_global_event_listener(g_signal_listener);
115           g_signal_listener = 0;
116           g_press_count = 0;
117           g_register_listener = FALSE;
118         }
119       else
120         {
121           g_press_count++;
122         }
123     }
124
125   return TRUE;
126 }
127