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