]> Pileus Git - ~andy/gtk/blob - modules/other/gail/tests/testpaned.c
748e955a774867477895b3000ef925dccd2b1a09
[~andy/gtk] / modules / other / gail / tests / testpaned.c
1 #include <string.h>
2 #include <stdlib.h>
3 #include <gtk/gtk.h>
4 #include <testlib.h>
5
6 static gint _test_paned (gpointer data);
7 static void _check_paned (AtkObject *obj);
8
9 static void _property_change_handler (AtkObject   *obj,
10                                       AtkPropertyValues *values);
11
12 #define NUM_VALID_ROLES 1
13 static gint last_position;
14
15 static void _property_change_handler (AtkObject   *obj,
16                                       AtkPropertyValues   *values)
17 {
18   G_CONST_RETURN gchar *type_name = g_type_name (G_TYPE_FROM_INSTANCE (obj));
19   G_CONST_RETURN gchar *name = atk_object_get_name (obj);
20
21   g_print ("_property_change_handler: Accessible Type: %s\n",
22            type_name ? type_name : "NULL");
23   g_print ("_property_change_handler: Accessible name: %s\n",
24            name ? name : "NULL");
25   g_print ("_property_change_handler: PropertyName: %s\n",
26            values->property_name ? values->property_name: "NULL");
27   if (strcmp (values->property_name, "accessible-value") == 0)
28   {
29     GValue *value, val;
30     int position;
31     value = &val;
32
33     memset (value, 0, sizeof (GValue));
34     atk_value_get_current_value (ATK_VALUE (obj), value);
35     g_return_if_fail (G_VALUE_HOLDS_INT (value));
36     position = g_value_get_int (value); 
37     g_print ("Position is  %d previous position was %d\n", 
38              position, last_position);
39     last_position = position;
40     atk_value_get_minimum_value (ATK_VALUE (obj), value);
41     g_return_if_fail (G_VALUE_HOLDS_INT (value));
42     position = g_value_get_int (value); 
43     g_print ("Minimum Value is  %d\n", position); 
44     atk_value_get_maximum_value (ATK_VALUE (obj), value);
45     g_return_if_fail (G_VALUE_HOLDS_INT (value));
46     position = g_value_get_int (value); 
47     g_print ("Maximum Value is  %d\n", position); 
48   }
49 }
50  
51 static gint _test_paned (gpointer data)
52 {
53   AtkObject *obj = ATK_OBJECT (data);
54   AtkRole role = atk_object_get_role (obj);
55   static gint times = 0;
56
57   if (role == ATK_ROLE_SPLIT_PANE)
58   {
59     GValue *value, val;
60     int position;
61     value = &val;
62
63     memset (value, 0, sizeof (GValue));
64     atk_value_get_current_value (ATK_VALUE (obj), value);
65     g_return_val_if_fail (G_VALUE_HOLDS_INT (value), FALSE);
66     position = g_value_get_int (value); 
67     g_print ("Position is : %d\n", position);
68     last_position = position;
69     position *= 2;
70     g_value_set_int (value, position);
71     atk_value_set_current_value (ATK_VALUE (obj), value);
72     times++;
73   }
74   if (times < 4)
75     return TRUE;
76   else
77     return FALSE;
78 }
79
80 static void _check_paned (AtkObject *obj)
81 {
82   static gboolean done_paned = FALSE;
83   AtkRole role;
84
85   role = atk_object_get_role (obj);
86
87   if (role == ATK_ROLE_FRAME)
88   {
89     AtkRole roles[NUM_VALID_ROLES];
90     AtkObject *paned_obj;
91
92     if (done_paned)
93       return;
94
95     roles[0] = ATK_ROLE_SPLIT_PANE;
96
97     paned_obj = find_object_by_role (obj, roles, NUM_VALID_ROLES);
98
99     if (paned_obj)
100     {
101       if (!done_paned)
102       {
103         done_paned = TRUE;
104       }
105       atk_object_connect_property_change_handler (paned_obj,
106                    (AtkPropertyChangeHandler*) _property_change_handler);
107       g_timeout_add (2000, _test_paned, paned_obj);
108     }
109
110     return;
111   }
112   if (role != ATK_ROLE_COMBO_BOX)
113     return;
114 }
115
116 static void
117 _create_event_watcher (void)
118 {
119   atk_add_focus_tracker (_check_paned);
120 }
121
122 int
123 gtk_module_init(gint argc, char* argv[])
124 {
125   g_print("testpaned Module loaded\n");
126
127   _create_event_watcher();
128
129   return 0;
130 }