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