]> Pileus Git - ~andy/gtk/blob - modules/other/gail/tests/testpaned.c
3b2a7cb75457629eb57ef67fe167e2e339efb13e
[~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   GtkWidget *widget;
56   static gint times = 0;
57
58   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
59
60   if (role == ATK_ROLE_SPLIT_PANE)
61   {
62     GValue *value, val;
63     int position;
64     value = &val;
65
66     memset (value, 0, sizeof (GValue));
67     atk_value_get_current_value (ATK_VALUE (obj), value);
68     g_return_val_if_fail (G_VALUE_HOLDS_INT (value), FALSE);
69     position = g_value_get_int (value); 
70     g_print ("Position is : %d\n", position);
71     last_position = position;
72     position *= 2;
73     g_value_set_int (value, position);
74     atk_value_set_current_value (ATK_VALUE (obj), value);
75     times++;
76   }
77   if (times < 4)
78     return TRUE;
79   else
80     return FALSE;
81 }
82
83 static void _check_paned (AtkObject *obj)
84 {
85   static gboolean done_paned = FALSE;
86   AtkRole role;
87
88   role = atk_object_get_role (obj);
89
90   if (role == ATK_ROLE_FRAME)
91   {
92     AtkRole roles[NUM_VALID_ROLES];
93     AtkObject *paned_obj;
94
95     if (done_paned)
96       return;
97
98     roles[0] = ATK_ROLE_SPLIT_PANE;
99
100     paned_obj = find_object_by_role (obj, roles, NUM_VALID_ROLES);
101
102     if (paned_obj)
103     {
104       if (!done_paned)
105       {
106         done_paned = TRUE;
107       }
108       atk_object_connect_property_change_handler (paned_obj,
109                    (AtkPropertyChangeHandler*) _property_change_handler);
110       g_timeout_add (2000, _test_paned, paned_obj);
111     }
112
113     return;
114   }
115   if (role != ATK_ROLE_COMBO_BOX)
116     return;
117 }
118
119 static void
120 _create_event_watcher (void)
121 {
122   atk_add_focus_tracker (_check_paned);
123 }
124
125 int
126 gtk_module_init(gint argc, char* argv[])
127 {
128   g_print("testpaned Module loaded\n");
129
130   _create_event_watcher();
131
132   return 0;
133 }