Support sending data with events
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / adaptors / component-adaptor.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2008 Novell, Inc.
6  * Copyright 2001, 2002 Sun Microsystems Inc.,
7  * Copyright 2001, 2002 Ximian, Inc.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24
25 #include <atk/atk.h>
26 #include <droute/droute.h>
27 #include "bridge.h"
28 #include <string.h>
29
30 #include "spi-dbus.h"
31 #include "object.h"
32 #include "introspection.h"
33
34 static DBusMessage *
35 impl_Contains (DBusConnection * bus, DBusMessage * message, void *user_data)
36 {
37   AtkComponent *component = (AtkComponent *) user_data;
38   dbus_int32_t x, y;
39   dbus_uint32_t coord_type;
40   dbus_bool_t retval;
41   DBusMessage *reply;
42
43   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
44                         droute_not_yet_handled_error (message));
45
46   if (!dbus_message_get_args
47       (message, NULL, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y,
48        DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
49     {
50       return droute_invalid_arguments_error (message);
51     }
52   retval =
53     atk_component_contains (component, x, y, (AtkCoordType) coord_type);
54   reply = dbus_message_new_method_return (message);
55   if (reply)
56     {
57       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &retval,
58                                 DBUS_TYPE_INVALID);
59     }
60   return reply;
61 }
62
63 static DBusMessage *
64 impl_GetAccessibleAtPoint (DBusConnection * bus, DBusMessage * message,
65                            void *user_data)
66 {
67   AtkComponent *component = (AtkComponent *) user_data;
68   dbus_int32_t x, y;
69   dbus_uint32_t coord_type;
70   DBusMessage *reply;
71   AtkObject *child;
72
73   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
74                         droute_not_yet_handled_error (message));
75
76   if (!dbus_message_get_args
77       (message, NULL, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y,
78        DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
79     {
80       return droute_invalid_arguments_error (message);
81     }
82   child =
83     atk_component_ref_accessible_at_point (component, x, y,
84                                            (AtkCoordType) coord_type);
85   reply = spi_object_return_reference (message, child);
86   if (child)
87     g_object_unref (child);
88
89   return reply;
90 }
91
92 static DBusMessage *
93 impl_GetExtents (DBusConnection * bus, DBusMessage * message, void *user_data)
94 {
95   AtkComponent *component = (AtkComponent *) user_data;
96   dbus_uint32_t coord_type;
97   gint ix, iy, iwidth, iheight;
98
99   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
100                         droute_not_yet_handled_error (message));
101
102   if (!dbus_message_get_args
103       (message, NULL, DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
104     {
105       return droute_invalid_arguments_error (message);
106     }
107   atk_component_get_extents (component, &ix, &iy, &iwidth, &iheight,
108                              (AtkCoordType) coord_type);
109   return spi_dbus_return_rect (message, ix, iy, iwidth, iheight);
110 }
111
112 static DBusMessage *
113 impl_GetPosition (DBusConnection * bus, DBusMessage * message,
114                   void *user_data)
115 {
116   AtkComponent *component = (AtkComponent *) user_data;
117   dbus_uint32_t coord_type;
118   gint ix = 0, iy = 0;
119   dbus_int32_t x, y;
120   DBusMessage *reply;
121
122   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
123                         droute_not_yet_handled_error (message));
124
125   if (!dbus_message_get_args
126       (message, NULL, DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
127     {
128       return droute_invalid_arguments_error (message);
129     }
130   atk_component_get_position (component, &ix, &iy, (AtkCoordType) coord_type);
131   x = ix;
132   y = iy;
133   reply = dbus_message_new_method_return (message);
134   if (reply)
135     {
136       dbus_message_append_args (reply, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32,
137                                 &y, DBUS_TYPE_INVALID);
138     }
139   return reply;
140 }
141
142 static DBusMessage *
143 impl_GetSize (DBusConnection * bus, DBusMessage * message, void *user_data)
144 {
145   AtkComponent *component = (AtkComponent *) user_data;
146   gint iwidth = 0, iheight = 0;
147   dbus_int32_t width, height;
148   DBusMessage *reply;
149
150   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
151                         droute_not_yet_handled_error (message));
152
153   atk_component_get_size (component, &iwidth, &iheight);
154   width = iwidth;
155   height = iheight;
156   reply = dbus_message_new_method_return (message);
157   if (reply)
158     {
159       dbus_message_append_args (reply, DBUS_TYPE_INT32, &width,
160                                 DBUS_TYPE_INT32, &height, DBUS_TYPE_INVALID);
161     }
162   return reply;
163 }
164
165 static DBusMessage *
166 impl_GetLayer (DBusConnection * bus, DBusMessage * message, void *user_data)
167 {
168   AtkComponent *component = (AtkComponent *) user_data;
169   AtkLayer atklayer;
170   dbus_uint32_t rv;
171   DBusMessage *reply;
172
173   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
174                         droute_not_yet_handled_error (message));
175
176   atklayer = atk_component_get_layer (component);
177
178   switch (atklayer)
179     {
180     case ATK_LAYER_BACKGROUND:
181       rv = ATSPI_LAYER_BACKGROUND;
182       break;
183     case ATK_LAYER_CANVAS:
184       rv = ATSPI_LAYER_CANVAS;
185       break;
186     case ATK_LAYER_WIDGET:
187       rv = ATSPI_LAYER_WIDGET;
188       break;
189     case ATK_LAYER_MDI:
190       rv = ATSPI_LAYER_MDI;
191       break;
192     case ATK_LAYER_POPUP:
193       rv = ATSPI_LAYER_POPUP;
194       break;
195     case ATK_LAYER_OVERLAY:
196       rv = ATSPI_LAYER_OVERLAY;
197       break;
198     case ATK_LAYER_WINDOW:
199       rv = ATSPI_LAYER_WINDOW;
200       break;
201     default:
202       rv = ATSPI_LAYER_INVALID;
203       break;
204     }
205   reply = dbus_message_new_method_return (message);
206   if (reply)
207     {
208       dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv,
209                                 DBUS_TYPE_INVALID);
210     }
211   return reply;
212 }
213
214 static DBusMessage *
215 impl_GetMDIZOrder (DBusConnection * bus, DBusMessage * message,
216                    void *user_data)
217 {
218   AtkComponent *component = (AtkComponent *) user_data;
219   dbus_int16_t rv;
220   DBusMessage *reply;
221
222   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
223                         droute_not_yet_handled_error (message));
224
225   rv = atk_component_get_mdi_zorder (component);
226   reply = dbus_message_new_method_return (message);
227   if (reply)
228     {
229       dbus_message_append_args (reply, DBUS_TYPE_INT16, &rv,
230                                 DBUS_TYPE_INVALID);
231     }
232   return reply;
233 }
234
235 static DBusMessage *
236 impl_GrabFocus (DBusConnection * bus, DBusMessage * message, void *user_data)
237 {
238   AtkComponent *component = (AtkComponent *) user_data;
239   dbus_bool_t rv;
240   DBusMessage *reply;
241
242   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
243                         droute_not_yet_handled_error (message));
244
245   rv = atk_component_grab_focus (component);
246   reply = dbus_message_new_method_return (message);
247   if (reply)
248     {
249       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
250                                 DBUS_TYPE_INVALID);
251     }
252   return reply;
253 }
254
255 #if 0
256 static DBusMessage *
257 impl_registerFocusHandler (DBusConnection * bus, DBusMessage * message,
258                            void *user_data)
259 {
260 }
261
262 static DBusMessage *
263 impl_deregisterFocusHandler (DBusConnection * bus, DBusMessage * message,
264                              void *user_data)
265 {
266 }
267 #endif
268
269 static DBusMessage *
270 impl_GetAlpha (DBusConnection * bus, DBusMessage * message, void *user_data)
271 {
272   AtkComponent *component = (AtkComponent *) user_data;
273   double rv;
274   DBusMessage *reply;
275
276   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
277                         droute_not_yet_handled_error (message));
278
279   rv = atk_component_get_alpha (component);
280   reply = dbus_message_new_method_return (message);
281   if (reply)
282     {
283       dbus_message_append_args (reply, DBUS_TYPE_DOUBLE, &rv,
284                                 DBUS_TYPE_INVALID);
285     }
286   return reply;
287 }
288
289 static DBusMessage *
290 impl_SetExtents (DBusConnection * bus, DBusMessage * message, void *user_data)
291 {
292   AtkComponent *component = (AtkComponent *) user_data;
293   DBusMessageIter iter, iter_struct;
294   dbus_uint32_t coord_type;
295   dbus_int32_t x, y, width, height;
296   dbus_bool_t ret;
297   DBusMessage *reply;
298
299   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
300                         droute_not_yet_handled_error (message));
301
302   if (strcmp (dbus_message_get_signature (message), "(iiii)u") != 0)
303     {
304       return droute_invalid_arguments_error (message);
305     }
306
307   dbus_message_iter_init (message, &iter);
308   dbus_message_iter_recurse (&iter, &iter_struct);
309   dbus_message_iter_get_basic (&iter_struct, &x);
310   dbus_message_iter_next (&iter_struct);
311   dbus_message_iter_get_basic (&iter_struct, &y);
312   dbus_message_iter_next (&iter_struct);
313   dbus_message_iter_get_basic (&iter_struct, &width);
314   dbus_message_iter_next (&iter_struct);
315   dbus_message_iter_get_basic (&iter_struct, &height);
316   dbus_message_iter_next (&iter_struct);
317   dbus_message_iter_next (&iter);
318   dbus_message_iter_get_basic (&iter, &coord_type);
319
320   ret = atk_component_set_extents (component, x, y, width, height, coord_type);
321
322   reply = dbus_message_new_method_return (message);
323   if (reply)
324     {
325       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &ret,
326                                 DBUS_TYPE_INVALID);
327     }
328
329   return reply;
330 }
331
332 static DBusMessage *
333 impl_SetPosition (DBusConnection * bus, DBusMessage * message, void *user_data)
334 {
335   AtkComponent *component = (AtkComponent *) user_data;
336   dbus_uint32_t coord_type;
337   dbus_int32_t x, y;
338   dbus_bool_t ret;
339   DBusMessage *reply;
340
341   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
342                         droute_not_yet_handled_error (message));
343
344   if (!dbus_message_get_args
345       (message, NULL, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y,
346        DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
347     {
348       return droute_invalid_arguments_error (message);
349     }
350
351   ret = atk_component_set_position (component, x, y, coord_type);
352
353   reply = dbus_message_new_method_return (message);
354   if (reply)
355     {
356       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &ret,
357                                 DBUS_TYPE_INVALID);
358     }
359
360   return reply;
361 }
362
363 static dbus_bool_t
364 impl_get_ScreenExtents (DBusMessageIter * iter, void *user_data)
365 {
366   AtkComponent *component = (AtkComponent *) user_data;
367   DBusMessageIter iter_variant, iter_struct;
368   gint ix = -1, iy = -1, iwidth = -1, iheight = -1;
369   dbus_uint32_t x, y, width, height;
370
371   g_return_val_if_fail (ATK_IS_COMPONENT (user_data), FALSE);
372
373   atk_component_get_extents (component, &ix, &iy, &iwidth, &iheight, ATK_XY_SCREEN);
374   x = ix;
375   y = iy;
376   width = iwidth;
377   height = iheight;
378   dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "(uuuu)",
379                                     &iter_variant);
380   dbus_message_iter_open_container (&iter_variant, DBUS_TYPE_STRUCT, NULL,
381                                     &iter_struct);
382   dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &x);
383   dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &y);
384   dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &width);
385   dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &height);
386   dbus_message_iter_close_container (&iter_variant, &iter_struct);
387   dbus_message_iter_close_container (iter, &iter_variant);
388   return TRUE;
389 }
390
391 static DBusMessage *
392 impl_SetSize (DBusConnection * bus, DBusMessage * message, void *user_data)
393 {
394   AtkComponent *component = (AtkComponent *) user_data;
395   dbus_int32_t width, height;
396   dbus_bool_t ret;
397   DBusMessage *reply;
398
399   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
400                         droute_not_yet_handled_error (message));
401
402   if (!dbus_message_get_args
403       (message, NULL, DBUS_TYPE_INT32, &width, DBUS_TYPE_INT32, &height,
404        DBUS_TYPE_INVALID))
405     {
406       return droute_invalid_arguments_error (message);
407     }
408
409   ret = atk_component_set_size (component, width, height);
410
411   reply = dbus_message_new_method_return (message);
412   if (reply)
413     {
414       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &ret,
415                                 DBUS_TYPE_INVALID);
416     }
417
418   return reply;
419 }
420
421 static DRouteMethod methods[] = {
422   {impl_Contains, "Contains"},
423   {impl_GetAccessibleAtPoint, "GetAccessibleAtPoint"},
424   {impl_GetExtents, "GetExtents"},
425   {impl_GetPosition, "GetPosition"},
426   {impl_GetSize, "GetSize"},
427   {impl_GetLayer, "GetLayer"},
428   {impl_GetMDIZOrder, "GetMDIZOrder"},
429   {impl_GrabFocus, "GrabFocus"},
430   //{impl_registerFocusHandler, "registerFocusHandler"},
431   //{impl_deregisterFocusHandler, "deregisterFocusHandler"},
432   {impl_GetAlpha, "GetAlpha"},
433   {impl_SetExtents, "SetExtents"},
434   {impl_SetPosition, "SetPosition"},
435   {impl_SetSize, "SetSize"},
436   {NULL, NULL}
437 };
438
439 static DRouteProperty properties[] = {
440   {impl_get_ScreenExtents, NULL, "ScreenExtents"},
441   {NULL, NULL, NULL}
442 };
443 void
444 spi_initialize_component (DRoutePath * path)
445 {
446   spi_atk_add_interface (path,
447                          ATSPI_DBUS_INTERFACE_COMPONENT, spi_org_a11y_atspi_Component, methods, properties);
448 };