93a30c5b6764607e0115417527d81dbb68d84c0f
[platform/core/uifw/at-spi2-atk.git] / cspi / spi-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  * AccessibleComponent function implementations
27  *
28  */
29
30 #include <cspi/spi-private.h>
31
32 /**
33  * AccessibleComponent_ref:
34  * @obj: a pointer to an object implementing #AccessibleComponent on which to operate.
35  *
36  * Increment the reference count for an #AccessibleComponent.
37  **/
38 void
39 AccessibleComponent_ref (AccessibleComponent *obj)
40 {
41   cspi_object_ref (obj);
42 }
43
44 /**
45  * AccessibleComponent_unref:
46  * @obj: a pointer to the object implementing #AccessibleComponent on which to operate.
47  *
48  * Decrement the reference count for an #AccessibleComponent.
49  **/
50 void
51 AccessibleComponent_unref (AccessibleComponent *obj)
52 {
53   cspi_object_unref (obj);
54 }
55
56 /**
57  * AccessibleComponent_contains:
58  * @obj: a pointer to the #AccessibleComponent to query.
59  * @x: a #long specifying the x coordinate in question.
60  * @y: a #long specifying the y coordinate in question.
61  * @ctype: the desired coordinate system of the point (@x, @y)
62  *         (e.g. CSPI_COORD_TYPE_WINDOW, CSPI_COORD_TYPE_SCREEN).
63  *
64  * Query whether a given #AccessibleComponent contains a particular point.
65  *
66  * Returns: a #TRUE if the specified component contains the point (@x, @y),
67  *          otherwise #FALSE.
68  **/
69 SPIBoolean
70 AccessibleComponent_contains (AccessibleComponent *obj,
71                               long int x,
72                               long int y,
73                               AccessibleCoordType ctype)
74 {
75   dbus_bool_t retval;
76   dbus_int32_t d_x = x, d_y = y;
77   dbus_uint16_t d_ctype = ctype;
78
79   cspi_return_val_if_fail (obj != NULL, FALSE);
80
81   cspi_dbus_call (obj, spi_interface_component, "contains", NULL, "iin=>b", d_x, d_y, d_ctype, &retval);
82
83   cspi_return_val_if_ev ("contains", FALSE);
84
85   return retval;
86 }
87
88 /**
89  * AccessibleComponent_getAccessibleAtPoint:
90  * @obj: a pointer to the #AccessibleComponent to query.
91  * @x: a #long specifying the x coordinate of the point in question.
92  * @y: a #long specifying the y coordinate of the point in question.
93  * @ctype: the coordinate system of the point (@x, @y)
94  *         (e.g. CSPI_COORD_TYPE_WINDOW, CSPI_COORD_TYPE_SCREEN).
95  *
96  * Get the accessible child at a given coordinate within an #AccessibleComponent.
97  *
98  * Returns: a pointer to an #Accessible child of the specified component which
99  *          contains the point (@x, @y), or NULL of no child contains the point.
100  **/
101 Accessible *
102 AccessibleComponent_getAccessibleAtPoint (AccessibleComponent *obj,
103                                           long int x,
104                                           long int y,
105                                           AccessibleCoordType ctype)
106 {
107   dbus_int32_t d_x = x, d_y = y;
108   dbus_uint16_t d_ctype = ctype;
109   char *path = NULL;
110   Accessible *retval;
111
112   cspi_return_val_if_fail (obj != NULL, FALSE);
113
114   cspi_dbus_call (obj, spi_interface_component, "getAccessibleAtPoint", NULL, "iin=>o", d_x, d_y, d_ctype, &path);
115
116   retval = cspi_ref_related_accessible (obj, path);
117   g_free (path);
118   return retval;
119 }
120
121 /**
122  * AccessibleComponent_getExtents:
123  * @obj: a pointer to the #AccessibleComponent to query.
124  * @x: a pointer to a #long into which the minimum x coordinate will be returned.
125  * @y: a pointer to a #long into which the minimum y coordinate will be returned.
126  * @width: a pointer to a #long into which the x extents (width) will be returned.
127  * @height: a pointer to a #long into which the y extents (height) will be returned.
128  * @ctype: the desired coordinate system into which to return the results,
129  *         (e.g. CSPI_COORD_TYPE_WINDOW, CSPI_COORD_TYPE_SCREEN).
130  *
131  * Get the bounding box of the specified #AccessibleComponent.
132  *
133  **/
134 void
135 AccessibleComponent_getExtents (AccessibleComponent *obj,
136                                 long int *x,
137                                 long int *y,
138                                 long int *width,
139                                 long int *height,
140                                 AccessibleCoordType ctype)
141 {
142   dbus_int16_t d_ctype = ctype;
143   Accessibility_BoundingBox bbox;
144
145   cspi_return_if_fail (obj != NULL);
146
147   cspi_dbus_call (obj, spi_interface_component, "getExtents", NULL, "n=>(iiii)", d_ctype, &bbox);
148   if (!cspi_check_ev ("getExtents"))
149     {
150       *x = *y = *width = *height = 0;    
151     }
152   else
153     {
154       *x = bbox.x;
155       *y = bbox.y;
156       *width = bbox.width;
157       *height = bbox.height;
158     }
159 }
160
161 /**
162  * AccessibleComponent_getPosition:
163  * @obj: a pointer to the #AccessibleComponent to query.
164  * @x: a pointer to a #long into which the minimum x coordinate will be returned.
165  * @y: a pointer to a #long into which the minimum y coordinate will be returned.
166  * @ctype: the desired coordinate system into which to return the results,
167  *         (e.g. CSPI_COORD_TYPE_WINDOW, CSPI_COORD_TYPE_SCREEN).
168  *
169  * Get the minimum x and y coordinates of the specified #AccessibleComponent.
170  *
171  **/
172 void
173 AccessibleComponent_getPosition (AccessibleComponent *obj,
174                                  long int *x,
175                                  long int *y,
176                                  AccessibleCoordType ctype)
177 {
178   dbus_int32_t d_x, d_y;
179   dbus_uint16_t d_ctype = ctype;
180
181   cspi_return_if_fail (obj != NULL);
182
183   cspi_dbus_call (obj, spi_interface_component, "getPosition", NULL, "n=>ii", d_ctype, &d_x, &d_y);
184
185   if (!cspi_check_ev ("getPosition"))
186     {
187       *x = *y = 0;
188     }
189   else
190     {
191       *x = d_x;
192       *y = d_y;
193     }
194 }
195
196 /**
197  * AccessibleComponent_getSize:
198  * @obj: a pointer to the #AccessibleComponent to query.
199  * @width: a pointer to a #long into which the x extents (width) will be returned.
200  * @height: a pointer to a #long into which the y extents (height) will be returned.
201  *
202  * Get the size of the specified #AccessibleComponent.
203  *
204  **/
205 void
206 AccessibleComponent_getSize (AccessibleComponent *obj,
207                              long int *width,
208                              long int *height)
209 {
210   dbus_int32_t d_w, d_h;
211
212   cspi_return_if_fail (obj != NULL);
213
214   cspi_dbus_call (obj, spi_interface_component, "getSize", NULL, "=>ii", &d_w, &d_h);
215   if (cspi_check_ev ("getSize"))
216   {
217     *width = *height = 0;
218   }
219   else
220   {
221     *width = d_w;
222     *height = d_h;
223   }
224 }
225
226 /**
227  * AccessibleComponent_getLayer:
228  * @obj: a pointer to the #AccessibleComponent to query.
229  *
230  * Query which layer the component is painted into, to help determine its 
231  *      visibility in terms of stacking order.
232  *
233  * Returns: the #AccessibleComponentLayer into which this component is painted.
234  **/
235 AccessibleComponentLayer
236 AccessibleComponent_getLayer (AccessibleComponent *obj)
237 {
238   AccessibleComponentLayer     retval;
239   dbus_uint32_t zlayer;
240
241   cspi_return_val_if_fail (obj != NULL, FALSE);
242
243   cspi_dbus_call (obj, spi_interface_component, "getLayer", NULL, "=>u", &zlayer);
244
245   cspi_return_val_if_ev ("getLayer", SPI_LAYER_INVALID);
246
247   switch (zlayer)
248     {
249     case Accessibility_LAYER_BACKGROUND:
250       retval = SPI_LAYER_BACKGROUND;
251       break;
252     case Accessibility_LAYER_CANVAS:      
253       retval = SPI_LAYER_CANVAS;
254       break;
255     case Accessibility_LAYER_WIDGET:      
256       retval = SPI_LAYER_WIDGET;
257       break;
258     case Accessibility_LAYER_MDI:         
259       retval = SPI_LAYER_MDI;
260       break;
261     case Accessibility_LAYER_POPUP:       
262       retval = SPI_LAYER_POPUP;
263       break;
264     case Accessibility_LAYER_OVERLAY:     
265       retval = SPI_LAYER_OVERLAY;
266       break;
267     case Accessibility_LAYER_WINDOW:      
268       retval = SPI_LAYER_WINDOW;
269       break;
270     default:
271       retval = SPI_LAYER_INVALID;
272       break;
273     }
274
275   return retval;
276 }
277
278 /**
279  * AccessibleComponent_getMDIZOrder:
280  * @obj: a pointer to the #AccessibleComponent to query.
281  *
282  * Query the z stacking order of a component which is in the MDI or window
283  *       layer. (Bigger z-order numbers mean nearer the top)
284  *
285  * Returns: a short integer indicating the stacking order of the component 
286  *       in the MDI layer, or -1 if the component is not in the MDI layer.
287  **/
288 short
289 AccessibleComponent_getMDIZOrder (AccessibleComponent *obj)
290 {
291   dbus_uint16_t retval;
292
293   cspi_return_val_if_fail (obj != NULL, FALSE);
294
295   cspi_dbus_call (obj, spi_interface_component, "getMDIZOrder", NULL, "=>n", &retval);
296
297   cspi_return_val_if_ev ("getMDIZOrder", FALSE);
298
299   return retval;
300 }
301
302 /**
303  * AccessibleComponent_grabFocus:
304  * @obj: a pointer to the #AccessibleComponent on which to operate.
305  *
306  * Attempt to set the keyboard input focus to the specified
307  *         #AccessibleComponent.
308  *
309  * Returns: #TRUE if successful, #FALSE otherwise.
310  *
311  **/
312 SPIBoolean
313 AccessibleComponent_grabFocus (AccessibleComponent *obj)
314 {
315   dbus_bool_t retval;
316
317   cspi_return_val_if_fail (obj != NULL, FALSE);
318
319   cspi_dbus_call (obj, spi_interface_component, "grabFocus", NULL, "=>b", &retval);
320
321   cspi_return_val_if_ev ("grabFocus", FALSE);
322
323   return retval;
324 }
325
326 /**
327  * AccessibleComponent_getAlpha:
328  * @obj: The #AccessibleComponent to be queried.
329  *
330  * Get the opacity/alpha value of a component, if alpha blending is in use.
331  *
332  * Returns: the opacity value of a component, as a double between 0.0 and 1.0. 
333  **/
334 double      
335 AccessibleComponent_getAlpha    (AccessibleComponent *obj)
336 {
337   double retval;
338
339   cspi_return_val_if_fail (obj != NULL, 1.0);
340
341   cspi_dbus_call (obj, spi_interface_component, "getAlpha", NULL, "=>d", &retval);
342
343   cspi_return_val_if_ev ("getAlpha", 1.0);
344
345   return retval;
346 }