]> Pileus Git - ~andy/gtk/blob - modules/other/gail/tests/teststatusbar.c
97d6abb59d0f4764a32c08642a193b4a5b275b42
[~andy/gtk] / modules / other / gail / tests / teststatusbar.c
1 #include <string.h>
2 #include <glib-object.h>
3 #include <atk/atk.h>
4
5 /*
6  * To use this test module, run the test program testgtk and click on 
7  * statusbar
8  */
9
10 static void _check_statusbar (AtkObject *obj);
11 static AtkObject* _find_object (AtkObject* obj, AtkRole role);
12 static void _notify_handler (GObject *obj, GParamSpec *pspec);
13 static void _property_change_handler (AtkObject   *obj,
14                                       AtkPropertyValues *values);
15
16 static AtkObject*
17 _find_object (AtkObject *obj,
18               AtkRole   role)
19 {
20   /*
21    * Find the first object which is a descendant of the specified object
22    * which matches the specified role.
23    *
24    * This function returns a reference to the AtkObject which should be
25    * removed when finished with the object.
26    */
27   gint i;
28   gint n_children;
29   AtkObject *child;
30
31   n_children = atk_object_get_n_accessible_children (obj);
32   for (i = 0; i < n_children; i++)
33   {
34     AtkObject* found_obj;
35
36     child = atk_object_ref_accessible_child (obj, i);
37     if (atk_object_get_role (child) == role)
38     {
39       return child;
40     }
41     found_obj = _find_object (child, role);
42     g_object_unref (child);
43     if (found_obj)
44     {
45       return found_obj;
46     }
47   }
48   return NULL;
49 }
50
51 static void _property_change_handler (AtkObject   *obj,
52                                       AtkPropertyValues   *values)
53 {
54   G_CONST_RETURN gchar *type_name = g_type_name (G_TYPE_FROM_INSTANCE (obj));
55   G_CONST_RETURN gchar *name = atk_object_get_name (obj);
56
57   g_print ("_property_change_handler: Accessible Type: %s\n",
58            type_name ? type_name : "NULL");
59   g_print ("_property_change_handler: Accessible name: %s\n",
60            name ? name : "NULL");
61   g_print ("_property_change_handler: PropertyName: %s\n",
62            values->property_name ? values->property_name: "NULL");
63   if (G_VALUE_HOLDS_STRING (&values->new_value))
64     g_print ("_property_change_handler: PropertyValue: %s\n",
65              g_value_get_string (&values->new_value));
66 }
67
68 static void _check_statusbar (AtkObject *obj)
69 {
70   AtkRole role;
71   AtkObject *statusbar, *label;
72
73   role = atk_object_get_role (obj);
74   if (role != ATK_ROLE_FRAME)
75     return;
76
77   statusbar = _find_object (obj, ATK_ROLE_STATUSBAR); 
78   if (!statusbar)
79     return;
80   g_print ("_check_statusbar\n");
81   label = atk_object_ref_accessible_child (statusbar, 0);
82   g_return_if_fail (label == NULL);
83
84   /*
85    * We get notified of changes to the label
86    */
87   g_signal_connect_closure_by_id (statusbar,
88                                   g_signal_lookup ("notify", 
89                                                    G_OBJECT_TYPE (statusbar)),
90                                   0,
91                                   g_cclosure_new (G_CALLBACK (_notify_handler),
92                                                  NULL, NULL),
93                                   FALSE);
94   atk_object_connect_property_change_handler (statusbar,
95                    (AtkPropertyChangeHandler*) _property_change_handler);
96
97 }
98
99 static void 
100 _notify_handler (GObject *obj, GParamSpec *pspec)
101 {
102   AtkObject *atk_obj = ATK_OBJECT (obj);
103   G_CONST_RETURN gchar *name;
104
105   g_print ("_notify_handler: property: %s\n", pspec->name);
106   if (strcmp (pspec->name, "accessible-name") == 0)
107   {
108     name = atk_object_get_name (atk_obj);
109     g_print ("_notify_handler: value: |%s|\n", name ? name : "<NULL>");
110   }
111 }
112
113 static void
114 _create_event_watcher (void)
115 {
116   atk_add_focus_tracker (_check_statusbar);
117 }
118
119 int
120 gtk_module_init(gint argc, char* argv[])
121 {
122   g_print("teststatusbar Module loaded\n");
123
124   _create_event_watcher();
125
126   return 0;
127 }