Added a new boolean parameter to allow specifying when a call to
[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
28 #include "common/spi-dbus.h"
29 #include "object.h"
30 #include "introspection.h"
31
32 static DBusMessage *
33 impl_contains (DBusConnection * bus, DBusMessage * message, void *user_data)
34 {
35   AtkComponent *component = (AtkComponent *) user_data;
36   dbus_int32_t x, y;
37   dbus_uint32_t coord_type;
38   DBusError error;
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   dbus_error_init (&error);
46   if (!dbus_message_get_args
47       (message, &error, 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   DBusError error;
71   AtkObject *child;
72
73   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
74                         droute_not_yet_handled_error (message));
75
76   dbus_error_init (&error);
77   if (!dbus_message_get_args
78       (message, &error, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y,
79        DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
80     {
81       return droute_invalid_arguments_error (message);
82     }
83   child =
84     atk_component_ref_accessible_at_point (component, x, y,
85                                            (AtkCoordType) coord_type);
86   return spi_object_return_reference (message, child, TRUE);
87 }
88
89 static DBusMessage *
90 impl_GetExtents (DBusConnection * bus, DBusMessage * message, void *user_data)
91 {
92   AtkComponent *component = (AtkComponent *) user_data;
93   DBusError error;
94   dbus_uint32_t coord_type;
95   gint ix, iy, iwidth, iheight;
96
97   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
98                         droute_not_yet_handled_error (message));
99
100   dbus_error_init (&error);
101   if (!dbus_message_get_args
102       (message, &error, 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   DBusError error;
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   dbus_error_init (&error);
126   if (!dbus_message_get_args
127       (message, &error, DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
128     {
129       return droute_invalid_arguments_error (message);
130     }
131   atk_component_get_position (component, &ix, &iy, (AtkCoordType) coord_type);
132   x = ix;
133   y = iy;
134   reply = dbus_message_new_method_return (message);
135   if (reply)
136     {
137       dbus_message_append_args (reply, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32,
138                                 &y, DBUS_TYPE_INVALID);
139     }
140   return reply;
141 }
142
143 static DBusMessage *
144 impl_GetSize (DBusConnection * bus, DBusMessage * message, void *user_data)
145 {
146   AtkComponent *component = (AtkComponent *) user_data;
147   gint iwidth = 0, iheight = 0;
148   dbus_int32_t width, height;
149   DBusMessage *reply;
150
151   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
152                         droute_not_yet_handled_error (message));
153
154   atk_component_get_size (component, &iwidth, &iheight);
155   width = iwidth;
156   height = iheight;
157   reply = dbus_message_new_method_return (message);
158   if (reply)
159     {
160       dbus_message_append_args (reply, DBUS_TYPE_INT32, &width,
161                                 DBUS_TYPE_INT32, &height, DBUS_TYPE_INVALID);
162     }
163   return reply;
164 }
165
166 static DBusMessage *
167 impl_GetLayer (DBusConnection * bus, DBusMessage * message, void *user_data)
168 {
169   AtkComponent *component = (AtkComponent *) user_data;
170   AtkLayer atklayer;
171   dbus_uint32_t rv;
172   DBusMessage *reply;
173
174   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
175                         droute_not_yet_handled_error (message));
176
177   atklayer = atk_component_get_layer (component);
178
179   switch (atklayer)
180     {
181     case ATK_LAYER_BACKGROUND:
182       rv = Accessibility_LAYER_BACKGROUND;
183       break;
184     case ATK_LAYER_CANVAS:
185       rv = Accessibility_LAYER_CANVAS;
186       break;
187     case ATK_LAYER_WIDGET:
188       rv = Accessibility_LAYER_WIDGET;
189       break;
190     case ATK_LAYER_MDI:
191       rv = Accessibility_LAYER_MDI;
192       break;
193     case ATK_LAYER_POPUP:
194       rv = Accessibility_LAYER_POPUP;
195       break;
196     case ATK_LAYER_OVERLAY:
197       rv = Accessibility_LAYER_OVERLAY;
198       break;
199     case ATK_LAYER_WINDOW:
200       rv = Accessibility_LAYER_WINDOW;
201       break;
202     default:
203       rv = Accessibility_LAYER_INVALID;
204       break;
205     }
206   reply = dbus_message_new_method_return (message);
207   if (reply)
208     {
209       dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv,
210                                 DBUS_TYPE_INVALID);
211     }
212   return reply;
213 }
214
215 static DBusMessage *
216 impl_GetMDIZOrder (DBusConnection * bus, DBusMessage * message,
217                    void *user_data)
218 {
219   AtkComponent *component = (AtkComponent *) user_data;
220   dbus_int16_t rv;
221   DBusMessage *reply;
222
223   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
224                         droute_not_yet_handled_error (message));
225
226   rv = atk_component_get_mdi_zorder (component);
227   reply = dbus_message_new_method_return (message);
228   if (reply)
229     {
230       dbus_message_append_args (reply, DBUS_TYPE_INT16, &rv,
231                                 DBUS_TYPE_INVALID);
232     }
233   return reply;
234 }
235
236 static DBusMessage *
237 impl_GrabFocus (DBusConnection * bus, DBusMessage * message, void *user_data)
238 {
239   AtkComponent *component = (AtkComponent *) user_data;
240   dbus_bool_t rv;
241   DBusMessage *reply;
242
243   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
244                         droute_not_yet_handled_error (message));
245
246   rv = atk_component_grab_focus (component);
247   reply = dbus_message_new_method_return (message);
248   if (reply)
249     {
250       dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv,
251                                 DBUS_TYPE_INVALID);
252     }
253   return reply;
254 }
255
256 #if 0
257 static DBusMessage *
258 impl_registerFocusHandler (DBusConnection * bus, DBusMessage * message,
259                            void *user_data)
260 {
261 }
262
263 static DBusMessage *
264 impl_deregisterFocusHandler (DBusConnection * bus, DBusMessage * message,
265                              void *user_data)
266 {
267 }
268 #endif
269
270 static DBusMessage *
271 impl_GetAlpha (DBusConnection * bus, DBusMessage * message, void *user_data)
272 {
273   AtkComponent *component = (AtkComponent *) user_data;
274   double rv;
275   DBusMessage *reply;
276
277   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
278                         droute_not_yet_handled_error (message));
279
280   rv = atk_component_get_alpha (component);
281   reply = dbus_message_new_method_return (message);
282   if (reply)
283     {
284       dbus_message_append_args (reply, DBUS_TYPE_DOUBLE, &rv,
285                                 DBUS_TYPE_INVALID);
286     }
287   return reply;
288 }
289
290 static DRouteMethod methods[] = {
291   {impl_contains, "contains"},
292   {impl_GetAccessibleAtPoint, "GetAccessibleAtPoint"},
293   {impl_GetExtents, "GetExtents"},
294   {impl_GetPosition, "GetPosition"},
295   {impl_GetSize, "GetSize"},
296   {impl_GetLayer, "GetLayer"},
297   {impl_GetMDIZOrder, "GetMDIZOrder"},
298   {impl_GrabFocus, "GrabFocus"},
299   //{impl_registerFocusHandler, "registerFocusHandler"},
300   //{impl_deregisterFocusHandler, "deregisterFocusHandler"},
301   {impl_GetAlpha, "GetAlpha"},
302   {NULL, NULL}
303 };
304
305 void
306 spi_initialize_component (DRoutePath * path)
307 {
308   droute_path_add_interface (path,
309                              SPI_DBUS_INTERFACE_COMPONENT, spi_org_a11y_atspi_Component, methods, NULL);
310 };