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