Add missing header.
[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 <string.h>
28
29 #include "common/spi-dbus.h"
30 #include "object.h"
31 #include "introspection.h"
32
33 static DBusMessage *
34 impl_contains (DBusConnection * bus, DBusMessage * message, void *user_data)
35 {
36   AtkComponent *component = (AtkComponent *) user_data;
37   dbus_int32_t x, y;
38   dbus_uint32_t coord_type;
39   DBusError error;
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   dbus_error_init (&error);
47   if (!dbus_message_get_args
48       (message, &error, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y,
49        DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
50     {
51       return droute_invalid_arguments_error (message);
52     }
53   retval =
54     atk_component_contains (component, x, y, (AtkCoordType) coord_type);
55   reply = dbus_message_new_method_return (message);
56   if (reply)
57     {
58       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &retval,
59                                 DBUS_TYPE_INVALID);
60     }
61   return reply;
62 }
63
64 static DBusMessage *
65 impl_GetAccessibleAtPoint (DBusConnection * bus, DBusMessage * message,
66                            void *user_data)
67 {
68   AtkComponent *component = (AtkComponent *) user_data;
69   dbus_int32_t x, y;
70   dbus_uint32_t coord_type;
71   DBusMessage *reply;
72   DBusError error;
73   AtkObject *child;
74
75   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
76                         droute_not_yet_handled_error (message));
77
78   dbus_error_init (&error);
79   if (!dbus_message_get_args
80       (message, &error, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y,
81        DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
82     {
83       return droute_invalid_arguments_error (message);
84     }
85   child =
86     atk_component_ref_accessible_at_point (component, x, y,
87                                            (AtkCoordType) coord_type);
88   reply = spi_object_return_reference (message, child);
89   g_object_unref (child);
90
91   return reply;
92 }
93
94 static DBusMessage *
95 impl_GetExtents (DBusConnection * bus, DBusMessage * message, void *user_data)
96 {
97   AtkComponent *component = (AtkComponent *) user_data;
98   DBusError error;
99   dbus_uint32_t coord_type;
100   gint ix, iy, iwidth, iheight;
101
102   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
103                         droute_not_yet_handled_error (message));
104
105   dbus_error_init (&error);
106   if (!dbus_message_get_args
107       (message, &error, DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
108     {
109       return droute_invalid_arguments_error (message);
110     }
111   atk_component_get_extents (component, &ix, &iy, &iwidth, &iheight,
112                              (AtkCoordType) coord_type);
113   return spi_dbus_return_rect (message, ix, iy, iwidth, iheight);
114 }
115
116 static DBusMessage *
117 impl_GetPosition (DBusConnection * bus, DBusMessage * message,
118                   void *user_data)
119 {
120   AtkComponent *component = (AtkComponent *) user_data;
121   DBusError error;
122   dbus_uint32_t coord_type;
123   gint ix = 0, iy = 0;
124   dbus_int32_t x, y;
125   DBusMessage *reply;
126
127   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
128                         droute_not_yet_handled_error (message));
129
130   dbus_error_init (&error);
131   if (!dbus_message_get_args
132       (message, &error, DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
133     {
134       return droute_invalid_arguments_error (message);
135     }
136   atk_component_get_position (component, &ix, &iy, (AtkCoordType) coord_type);
137   x = ix;
138   y = iy;
139   reply = dbus_message_new_method_return (message);
140   if (reply)
141     {
142       dbus_message_append_args (reply, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32,
143                                 &y, DBUS_TYPE_INVALID);
144     }
145   return reply;
146 }
147
148 static DBusMessage *
149 impl_GetSize (DBusConnection * bus, DBusMessage * message, void *user_data)
150 {
151   AtkComponent *component = (AtkComponent *) user_data;
152   gint iwidth = 0, iheight = 0;
153   dbus_int32_t width, height;
154   DBusMessage *reply;
155
156   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
157                         droute_not_yet_handled_error (message));
158
159   atk_component_get_size (component, &iwidth, &iheight);
160   width = iwidth;
161   height = iheight;
162   reply = dbus_message_new_method_return (message);
163   if (reply)
164     {
165       dbus_message_append_args (reply, DBUS_TYPE_INT32, &width,
166                                 DBUS_TYPE_INT32, &height, DBUS_TYPE_INVALID);
167     }
168   return reply;
169 }
170
171 static DBusMessage *
172 impl_GetLayer (DBusConnection * bus, DBusMessage * message, void *user_data)
173 {
174   AtkComponent *component = (AtkComponent *) user_data;
175   AtkLayer atklayer;
176   dbus_uint32_t rv;
177   DBusMessage *reply;
178
179   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
180                         droute_not_yet_handled_error (message));
181
182   atklayer = atk_component_get_layer (component);
183
184   switch (atklayer)
185     {
186     case ATK_LAYER_BACKGROUND:
187       rv = Accessibility_LAYER_BACKGROUND;
188       break;
189     case ATK_LAYER_CANVAS:
190       rv = Accessibility_LAYER_CANVAS;
191       break;
192     case ATK_LAYER_WIDGET:
193       rv = Accessibility_LAYER_WIDGET;
194       break;
195     case ATK_LAYER_MDI:
196       rv = Accessibility_LAYER_MDI;
197       break;
198     case ATK_LAYER_POPUP:
199       rv = Accessibility_LAYER_POPUP;
200       break;
201     case ATK_LAYER_OVERLAY:
202       rv = Accessibility_LAYER_OVERLAY;
203       break;
204     case ATK_LAYER_WINDOW:
205       rv = Accessibility_LAYER_WINDOW;
206       break;
207     default:
208       rv = Accessibility_LAYER_INVALID;
209       break;
210     }
211   reply = dbus_message_new_method_return (message);
212   if (reply)
213     {
214       dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv,
215                                 DBUS_TYPE_INVALID);
216     }
217   return reply;
218 }
219
220 static DBusMessage *
221 impl_GetMDIZOrder (DBusConnection * bus, DBusMessage * message,
222                    void *user_data)
223 {
224   AtkComponent *component = (AtkComponent *) user_data;
225   dbus_int16_t rv;
226   DBusMessage *reply;
227
228   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
229                         droute_not_yet_handled_error (message));
230
231   rv = atk_component_get_mdi_zorder (component);
232   reply = dbus_message_new_method_return (message);
233   if (reply)
234     {
235       dbus_message_append_args (reply, DBUS_TYPE_INT16, &rv,
236                                 DBUS_TYPE_INVALID);
237     }
238   return reply;
239 }
240
241 static DBusMessage *
242 impl_GrabFocus (DBusConnection * bus, DBusMessage * message, void *user_data)
243 {
244   AtkComponent *component = (AtkComponent *) user_data;
245   dbus_bool_t rv;
246   DBusMessage *reply;
247
248   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
249                         droute_not_yet_handled_error (message));
250
251   rv = atk_component_grab_focus (component);
252   reply = dbus_message_new_method_return (message);
253   if (reply)
254     {
255       dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv,
256                                 DBUS_TYPE_INVALID);
257     }
258   return reply;
259 }
260
261 #if 0
262 static DBusMessage *
263 impl_registerFocusHandler (DBusConnection * bus, DBusMessage * message,
264                            void *user_data)
265 {
266 }
267
268 static DBusMessage *
269 impl_deregisterFocusHandler (DBusConnection * bus, DBusMessage * message,
270                              void *user_data)
271 {
272 }
273 #endif
274
275 static DBusMessage *
276 impl_GetAlpha (DBusConnection * bus, DBusMessage * message, void *user_data)
277 {
278   AtkComponent *component = (AtkComponent *) user_data;
279   double rv;
280   DBusMessage *reply;
281
282   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
283                         droute_not_yet_handled_error (message));
284
285   rv = atk_component_get_alpha (component);
286   reply = dbus_message_new_method_return (message);
287   if (reply)
288     {
289       dbus_message_append_args (reply, DBUS_TYPE_DOUBLE, &rv,
290                                 DBUS_TYPE_INVALID);
291     }
292   return reply;
293 }
294
295 static DBusMessage *
296 impl_SetExtents (DBusConnection * bus, DBusMessage * message, void *user_data)
297 {
298   AtkComponent *component = (AtkComponent *) user_data;
299   DBusMessageIter iter, iter_struct;
300   dbus_uint32_t coord_type;
301   dbus_int32_t x, y, width, height;
302   dbus_bool_t ret;
303   DBusMessage *reply;
304
305   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
306                         droute_not_yet_handled_error (message));
307
308   if (strcmp (dbus_message_get_signature (message), "(iiii)u") != 0)
309     {
310       return droute_invalid_arguments_error (message);
311     }
312
313   dbus_message_iter_init (message, &iter);
314   dbus_message_iter_recurse (&iter, &iter_struct);
315   dbus_message_iter_get_basic (&iter_struct, &x);
316   dbus_message_iter_next (&iter_struct);
317   dbus_message_iter_get_basic (&iter_struct, &y);
318   dbus_message_iter_next (&iter_struct);
319   dbus_message_iter_get_basic (&iter_struct, &width);
320   dbus_message_iter_next (&iter_struct);
321   dbus_message_iter_get_basic (&iter_struct, &height);
322   dbus_message_iter_next (&iter_struct);
323   dbus_message_iter_next (&iter);
324   dbus_message_iter_get_basic (&iter, &coord_type);
325
326   ret = atk_component_set_extents (component, x, y, width, height, coord_type);
327
328   reply = dbus_message_new_method_return (message);
329   if (reply)
330     {
331       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &ret,
332                                 DBUS_TYPE_INVALID);
333     }
334
335   return reply;
336 }
337
338 static DBusMessage *
339 impl_SetPosition (DBusConnection * bus, DBusMessage * message, void *user_data)
340 {
341   AtkComponent *component = (AtkComponent *) user_data;
342   dbus_uint32_t coord_type;
343   dbus_int32_t x, y;
344   dbus_bool_t ret;
345   DBusMessage *reply;
346
347   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
348                         droute_not_yet_handled_error (message));
349
350   if (!dbus_message_get_args
351       (message, NULL, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y,
352        DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
353     {
354       return droute_invalid_arguments_error (message);
355     }
356
357   ret = atk_component_set_position (component, x, y, coord_type);
358
359   reply = dbus_message_new_method_return (message);
360   if (reply)
361     {
362       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &ret,
363                                 DBUS_TYPE_INVALID);
364     }
365
366   return reply;
367 }
368
369 static DBusMessage *
370 impl_SetSize (DBusConnection * bus, DBusMessage * message, void *user_data)
371 {
372   AtkComponent *component = (AtkComponent *) user_data;
373   dbus_int32_t width, height;
374   dbus_bool_t ret;
375   DBusMessage *reply;
376
377   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
378                         droute_not_yet_handled_error (message));
379
380   if (!dbus_message_get_args
381       (message, NULL, DBUS_TYPE_INT32, &width, DBUS_TYPE_INT32, &height,
382        DBUS_TYPE_INVALID))
383     {
384       return droute_invalid_arguments_error (message);
385     }
386
387   ret = atk_component_set_size (component, width, height);
388
389   reply = dbus_message_new_method_return (message);
390   if (reply)
391     {
392       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &ret,
393                                 DBUS_TYPE_INVALID);
394     }
395
396   return reply;
397 }
398
399 static DRouteMethod methods[] = {
400   {impl_contains, "contains"},
401   {impl_GetAccessibleAtPoint, "GetAccessibleAtPoint"},
402   {impl_GetExtents, "GetExtents"},
403   {impl_GetPosition, "GetPosition"},
404   {impl_GetSize, "GetSize"},
405   {impl_GetLayer, "GetLayer"},
406   {impl_GetMDIZOrder, "GetMDIZOrder"},
407   {impl_GrabFocus, "GrabFocus"},
408   //{impl_registerFocusHandler, "registerFocusHandler"},
409   //{impl_deregisterFocusHandler, "deregisterFocusHandler"},
410   {impl_GetAlpha, "GetAlpha"},
411   {impl_SetExtents, "SetExtents"},
412   {impl_SetPosition, "SetPosition"},
413   {impl_SetSize, "SetSize"},
414   {NULL, NULL}
415 };
416
417 void
418 spi_initialize_component (DRoutePath * path)
419 {
420   droute_path_add_interface (path,
421                              SPI_DBUS_INTERFACE_COMPONENT, spi_org_a11y_atspi_Component, methods, NULL);
422 };