Integrate leasing scheme in-to atk-bridge.
[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
31 static DBusMessage *
32 impl_contains (DBusConnection * bus, DBusMessage * message, void *user_data)
33 {
34   AtkComponent *component = (AtkComponent *) user_data;
35   dbus_int32_t x, y;
36   dbus_uint32_t coord_type;
37   DBusError error;
38   dbus_bool_t retval;
39   DBusMessage *reply;
40
41   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
42                         droute_not_yet_handled_error (message));
43
44   dbus_error_init (&error);
45   if (!dbus_message_get_args
46       (message, &error, 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   DBusError error;
70   AtkObject *child;
71
72   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
73                         droute_not_yet_handled_error (message));
74
75   dbus_error_init (&error);
76   if (!dbus_message_get_args
77       (message, &error, 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   return spi_object_return_reference (message, child);
86 }
87
88 static DBusMessage *
89 impl_GetExtents (DBusConnection * bus, DBusMessage * message, void *user_data)
90 {
91   AtkComponent *component = (AtkComponent *) user_data;
92   DBusError error;
93   dbus_uint32_t coord_type;
94   gint ix, iy, iwidth, iheight;
95
96   g_return_val_if_fail (ATK_IS_COMPONENT (user_data),
97                         droute_not_yet_handled_error (message));
98
99   dbus_error_init (&error);
100   if (!dbus_message_get_args
101       (message, &error, DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
102     {
103       return droute_invalid_arguments_error (message);
104     }
105   atk_component_get_extents (component, &ix, &iy, &iwidth, &iheight,
106                              (AtkCoordType) coord_type);
107   return spi_dbus_return_rect (message, ix, iy, iwidth, iheight);
108 }
109
110 static DBusMessage *
111 impl_GetPosition (DBusConnection * bus, DBusMessage * message,
112                   void *user_data)
113 {
114   AtkComponent *component = (AtkComponent *) user_data;
115   DBusError error;
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   dbus_error_init (&error);
125   if (!dbus_message_get_args
126       (message, &error, 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 = Accessibility_LAYER_BACKGROUND;
182       break;
183     case ATK_LAYER_CANVAS:
184       rv = Accessibility_LAYER_CANVAS;
185       break;
186     case ATK_LAYER_WIDGET:
187       rv = Accessibility_LAYER_WIDGET;
188       break;
189     case ATK_LAYER_MDI:
190       rv = Accessibility_LAYER_MDI;
191       break;
192     case ATK_LAYER_POPUP:
193       rv = Accessibility_LAYER_POPUP;
194       break;
195     case ATK_LAYER_OVERLAY:
196       rv = Accessibility_LAYER_OVERLAY;
197       break;
198     case ATK_LAYER_WINDOW:
199       rv = Accessibility_LAYER_WINDOW;
200       break;
201     default:
202       rv = Accessibility_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_UINT32, &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 DRouteMethod methods[] = {
290   {impl_contains, "contains"},
291   {impl_GetAccessibleAtPoint, "GetAccessibleAtPoint"},
292   {impl_GetExtents, "GetExtents"},
293   {impl_GetPosition, "GetPosition"},
294   {impl_GetSize, "GetSize"},
295   {impl_GetLayer, "GetLayer"},
296   {impl_GetMDIZOrder, "GetMDIZOrder"},
297   {impl_GrabFocus, "GrabFocus"},
298   //{impl_registerFocusHandler, "registerFocusHandler"},
299   //{impl_deregisterFocusHandler, "deregisterFocusHandler"},
300   {impl_GetAlpha, "GetAlpha"},
301   {NULL, NULL}
302 };
303
304 void
305 spi_initialize_component (DRoutePath * path)
306 {
307   droute_path_add_interface (path,
308                              SPI_DBUS_INTERFACE_COMPONENT, methods, NULL);
309 };