packaging: exclude on non X11 configuration
[platform/core/uifw/at-spi2-core.git] / atspi / atspi-component.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001, 2002 Sun Microsystems Inc.,
6  * Copyright 2001, 2002 Ximian, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 /*
25  *
26  * AtspiComponent function implementations
27  *
28  */
29
30 #include "atspi-private.h"
31
32 void
33 atspi_rect_free (AtspiRect *rect)
34 {
35   g_free (rect);
36 }
37
38 AtspiRect *
39 atspi_rect_copy (AtspiRect *src)
40 {
41   AtspiRect *dst = g_new (AtspiRect, 1);
42   dst->x = src->x;
43   dst->y = src->y;
44   dst->height = src->height;
45   dst->width = src->width;
46   return dst;
47 }
48
49 G_DEFINE_BOXED_TYPE (AtspiRect, atspi_rect, atspi_rect_copy, atspi_rect_free)
50
51 AtspiPoint *
52 atspi_point_copy (AtspiPoint *src)
53 {
54   AtspiPoint *dst = g_new (AtspiPoint, 1);
55   dst->x = src->x;
56   dst->y = src->y;
57   return dst;
58 }
59
60 G_DEFINE_BOXED_TYPE (AtspiPoint, atspi_point, atspi_point_copy, g_free)
61
62 /**
63  * atspi_component_contains:
64  * @obj: a pointer to the #AtspiComponent to query.
65  * @x: a #gint specifying the x coordinate in question.
66  * @y: a #gint specifying the y coordinate in question.
67  * @ctype: the desired coordinate system of the point (@x, @y)
68  *         (e.g. CSPI_COORD_TYPE_WINDOW, CSPI_COORD_TYPE_SCREEN).
69  *
70  * Queries whether a given #AtspiComponent contains a particular point.
71  *
72  * Returns: #TRUE if the specified component contains the point (@x, @y),
73  *          #FALSE otherwise.
74  **/
75 gboolean
76 atspi_component_contains (AtspiComponent *obj,
77                               gint x,
78                               gint y,
79                               AtspiCoordType ctype, GError **error)
80 {
81   dbus_bool_t retval = FALSE;
82   dbus_int32_t d_x = x, d_y = y;
83   dbus_uint32_t d_ctype = ctype;
84
85   g_return_val_if_fail (obj != NULL, FALSE);
86
87   _atspi_dbus_call (obj, atspi_interface_component, "Contains", error, "iin=>b", d_x, d_y, d_ctype, &retval);
88
89   return retval;
90 }
91
92 /**
93  * atspi_component_get_accessible_at_point:
94  * @obj: a pointer to the #AtspiComponent to query.
95  * @x: a #gint specifying the x coordinate of the point in question.
96  * @y: a #gint specifying the y coordinate of the point in question.
97  * @ctype: the coordinate system of the point (@x, @y)
98  *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
99  *
100  * Gets the accessible child at a given coordinate within an #AtspiComponent.
101  *
102  * Returns: (transfer full): a pointer to an #AtspiAccessible child of the
103  *          specified component which contains the point (@x, @y), or NULL if
104  *         no child contains the point.
105  **/
106 AtspiAccessible *
107 atspi_component_get_accessible_at_point (AtspiComponent *obj,
108                                           gint x,
109                                           gint y,
110                                           AtspiCoordType ctype, GError **error)
111 {
112   dbus_int32_t d_x = x, d_y = y;
113   dbus_uint32_t d_ctype = ctype;
114   DBusMessage *reply;
115
116   g_return_val_if_fail (obj != NULL, FALSE);
117
118   reply = _atspi_dbus_call_partial (obj, atspi_interface_component, "GetAccessibleAtPoint", error, "iiu", d_x, d_y, d_ctype);
119
120   return _atspi_dbus_return_accessible_from_message (reply);
121 }
122
123 /**
124  * atspi_component_get_extents:
125  * @obj: a pointer to the #AtspiComponent to query.
126  * @ctype: the desired coordinate system into which to return the results,
127  *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
128  *
129  * Gets the bounding box of the specified #AtspiComponent.
130  *
131  * Returns: An #AtspiRect giving the accessible's extents.
132  **/
133 AtspiRect *
134 atspi_component_get_extents (AtspiComponent *obj,
135                                 AtspiCoordType ctype, GError **error)
136 {
137   dbus_uint32_t d_ctype = ctype;
138   AtspiRect bbox;
139
140   bbox.x = bbox.y = bbox.width = bbox.height = -1;
141   g_return_val_if_fail (obj != NULL, atspi_rect_copy (&bbox));
142
143   _atspi_dbus_call (obj, atspi_interface_component, "GetExtents", error, "u=>(iiii)", d_ctype, &bbox);
144   return atspi_rect_copy (&bbox);
145 }
146
147 /**
148  * atspi_component_get_position:
149  * @obj: a pointer to the #AtspiComponent to query.
150  * @ctype: the desired coordinate system into which to return the results,
151  *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
152  *
153  * Gets the minimum x and y coordinates of the specified #AtspiComponent.
154  *
155  * returns: An #AtspiPoint giving the @obj's position.
156  **/
157 AtspiPoint *
158 atspi_component_get_position (AtspiComponent *obj,
159                                  AtspiCoordType ctype, GError **error)
160 {
161   dbus_int32_t d_x, d_y;
162   dbus_uint32_t d_ctype = ctype;
163   AtspiPoint ret;
164
165   ret.x = ret.y = -1;
166
167   if (!obj)
168     return atspi_point_copy (&ret);
169
170   _atspi_dbus_call (obj, atspi_interface_component, "GetPosition", error, "u=>ii", d_ctype, &d_x, &d_y);
171
172   ret.x = d_x;
173   ret.y = d_y;
174   return atspi_point_copy (&ret);
175 }
176
177 /**
178  * atspi_component_get_size:
179  * @obj: a pointer to the #AtspiComponent to query.
180  *
181  * Gets the size of the specified #AtspiComponent.
182  *
183  * returns: An #AtspiPoint giving the @obj's size.
184  **/
185 AtspiPoint *
186 atspi_component_get_size (AtspiComponent *obj, GError **error)
187 {
188   dbus_int32_t d_w, d_h;
189   AtspiPoint ret;
190
191   ret.x = ret.y = -1;
192   if (!obj)
193     return atspi_point_copy (&ret);
194
195   _atspi_dbus_call (obj, atspi_interface_component, "GetSize", error, "=>ii", &d_w, &d_h);
196   ret.x = d_w;
197   ret.y = d_h;
198   return atspi_point_copy (&ret);
199 }
200
201 /**
202  * atspi_component_get_layer:
203  * @obj: a pointer to the #AtspiComponent to query.
204  *
205  * Queries which layer the component is painted into, to help determine its 
206  *      visibility in terms of stacking order.
207  *
208  * Returns: the #AtspiComponentLayer into which this component is painted.
209  **/
210 AtspiComponentLayer
211 atspi_component_get_layer (AtspiComponent *obj, GError **error)
212 {
213   dbus_uint32_t zlayer = -1;
214
215   _atspi_dbus_call (obj, atspi_interface_component, "GetLayer", error, "=>u", &zlayer);
216
217   return zlayer;
218 }
219
220 /**
221  * atspi_component_get_mdi_z_order:
222  * @obj: a pointer to the #AtspiComponent to query.
223  *
224  * Queries the z stacking order of a component which is in the MDI or window
225  *       layer. (Bigger z-order numbers mean nearer the top)
226  *
227  * Returns: a #gshort indicating the stacking order of the component 
228  *       in the MDI layer, or -1 if the component is not in the MDI layer.
229  **/
230 gshort
231 atspi_component_get_mdi_z_order (AtspiComponent *obj, GError **error)
232 {
233   dbus_uint16_t retval = -1;
234
235   _atspi_dbus_call (obj, atspi_interface_component, "GetMDIZOrder", error, "=>n", &retval);
236
237   return retval;
238 }
239
240 /**
241  * atspi_component_grab_focus:
242  * @obj: a pointer to the #AtspiComponent on which to operate.
243  *
244  * Attempts to set the keyboard input focus to the specified
245  *         #AtspiComponent.
246  *
247  * Returns: #TRUE if successful, #FALSE otherwise.
248  *
249  **/
250 gboolean
251 atspi_component_grab_focus (AtspiComponent *obj, GError **error)
252 {
253   dbus_bool_t retval = FALSE;
254
255   _atspi_dbus_call (obj, atspi_interface_component, "GrabFocus", error, "=>b", &retval);
256
257   return retval;
258 }
259
260 /**
261  * atspi_component_get_alpha:
262  * @obj: The #AtspiComponent to be queried.
263  *
264  * Gets the opacity/alpha value of a component, if alpha blending is in use.
265  *
266  * Returns: the opacity value of a component, as a #gdouble between 0.0 and 1.0. 
267  **/
268 gdouble      
269 atspi_component_get_alpha    (AtspiComponent *obj, GError **error)
270 {
271   double retval = 1;
272
273   _atspi_dbus_call (obj, atspi_interface_component, "GetAlpha", error, "=>d", &retval);
274
275   return retval;
276 }
277
278 /**
279  * atspi_component_set_extents:
280  * @obj: a pointer to the #AtspiComponent to move.
281  * @x: the new vertical position to which the component should be moved.
282  * @y: the new horizontal position to which the component should be moved.
283  * @width: the width to which the component should be resized.
284  * @height: the height to which the component should be resized.
285  * @ctype: the coordinate system in which the position is specified.
286  *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
287  *
288  * Moves and resizes the specified component.
289  *
290  * Returns: #TRUE if successful; #FALSE otherwise.
291  **/
292 gboolean
293 atspi_component_set_extents (AtspiComponent *obj,
294                              gint x,
295                              gint y,
296                              gint width,
297                              gint height,
298                              AtspiCoordType ctype,
299                              GError **error)
300 {
301   dbus_int32_t d_x = x, d_y = y, d_width = width, d_height = height;
302   dbus_uint32_t d_ctype = ctype;
303   DBusMessageIter iter, iter_struct;
304   DBusMessage *message, *reply;
305   dbus_bool_t retval = FALSE;
306   AtspiAccessible *aobj = ATSPI_ACCESSIBLE (obj);
307
308   g_return_val_if_fail (obj != NULL, FALSE);
309
310   if (!aobj->parent.app || !aobj->parent.app->bus_name)
311   {
312     g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_APPLICATION_GONE,
313                           _("The application no longer exists"));
314     return FALSE;
315   }
316
317   message = dbus_message_new_method_call (aobj->parent.app->bus_name,
318                                           aobj->parent.path,
319                                           atspi_interface_component,
320                                           "SetExtents");
321   if (!message)
322     return FALSE;
323
324   dbus_message_iter_init_append (message, &iter);
325   if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &iter_struct))
326   {
327     dbus_message_unref (message);
328     return FALSE;
329   }
330   dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &d_x);
331   dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &d_y);
332   dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &d_width);
333   dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &d_height);
334   dbus_message_iter_close_container (&iter, &iter_struct);
335   dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &d_ctype);
336
337   reply = _atspi_dbus_send_with_reply_and_block (message, error);
338   dbus_message_get_args (reply, NULL, DBUS_TYPE_BOOLEAN, &retval,
339                               DBUS_TYPE_INVALID);
340   dbus_message_unref (reply);
341   return retval;
342 }
343
344 /**
345  * atspi_component_set_position:
346  * @obj: a pointer to the #AtspiComponent to move.
347  * @x: the new vertical position to which the component should be moved.
348  * @y: the new horizontal position to which the component should be moved.
349  * @ctype: the coordinate system in which the position is specified.
350  *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
351  *
352  * Returns: #TRUE if successful; #FALSE otherwise.
353  *
354  * Moves the component to the specified position.
355  **/
356 gboolean
357 atspi_component_set_position (AtspiComponent *obj,
358                               gint x,
359                               gint y,
360                               AtspiCoordType ctype,
361                               GError **error)
362 {
363   dbus_int32_t d_x = x, d_y = y;
364   dbus_uint32_t d_ctype = ctype;
365   dbus_bool_t ret = FALSE;
366
367   g_return_val_if_fail (obj != NULL, FALSE);
368
369   _atspi_dbus_call (obj, atspi_interface_component, "SetPosition", error,
370                     "iiu=>b", d_x, d_y, d_ctype, &ret);
371
372   return ret;
373 }
374
375 /**
376  * atspi_component_set_size:
377  * @obj: a pointer to the #AtspiComponent to query.
378  * @width: the width to which the component should be resized.
379  * @height: the height to which the component should be resized.
380  *
381  * Returns: #TRUE if successful; #FALSE otherwise.
382  *
383  * Resizes the specified component to the given coordinates.
384  **/
385 gboolean
386 atspi_component_set_size (AtspiComponent *obj,
387                           gint width,
388                           gint height,
389                           GError **error)
390 {
391   dbus_int32_t d_width = width, d_height = height;
392   dbus_bool_t ret = FALSE;
393
394   g_return_val_if_fail (obj != NULL, FALSE);
395
396   _atspi_dbus_call (obj, atspi_interface_component, "SetSize", error, "ii=>b",
397                     d_width, d_height, &ret);
398
399   return ret;
400 }
401
402 static void
403 atspi_component_base_init (AtspiComponent *klass)
404 {
405 }
406
407 GType
408 atspi_component_get_type (void)
409 {
410   static GType type = 0;
411
412   if (!type) {
413     static const GTypeInfo tinfo =
414     {
415       sizeof (AtspiComponent),
416       (GBaseInitFunc) atspi_component_base_init,
417       (GBaseFinalizeFunc) NULL,
418     };
419
420     type = g_type_register_static (G_TYPE_INTERFACE, "AtspiComponent", &tinfo, 0);
421
422   }
423   return type;
424 }