Add atk-bridge
[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   SPIBoolean retval;
76
77   cspi_return_val_if_fail (obj != NULL, FALSE);
78
79   retval = Accessibility_Component_contains (CSPI_OBJREF (obj),
80                                              x,
81                                              y,
82                                              ctype,
83                                              cspi_ev ());
84   cspi_return_val_if_ev ("contains", FALSE);
85
86   return retval;
87 }
88
89 /**
90  * AccessibleComponent_getAccessibleAtPoint:
91  * @obj: a pointer to the #AccessibleComponent to query.
92  * @x: a #long specifying the x coordinate of the point in question.
93  * @y: a #long specifying the y coordinate of the point in question.
94  * @ctype: the coordinate system of the point (@x, @y)
95  *         (e.g. CSPI_COORD_TYPE_WINDOW, CSPI_COORD_TYPE_SCREEN).
96  *
97  * Get the accessible child at a given coordinate within an #AccessibleComponent.
98  *
99  * Returns: a pointer to an #Accessible child of the specified component which
100  *          contains the point (@x, @y), or NULL of no child contains the point.
101  **/
102 Accessible *
103 AccessibleComponent_getAccessibleAtPoint (AccessibleComponent *obj,
104                                           long int x,
105                                           long int y,
106                                           AccessibleCoordType ctype)
107 {
108   Accessibility_Accessible child;
109
110   cspi_return_val_if_fail (obj != NULL, NULL);
111
112   child = Accessibility_Component_getAccessibleAtPoint (CSPI_OBJREF (obj),
113                                                         x,
114                                                         y,
115                                                         ctype,
116                                                         cspi_ev ());
117   return cspi_object_add (child);
118 }
119
120 /**
121  * AccessibleComponent_getExtents:
122  * @obj: a pointer to the #AccessibleComponent to query.
123  * @x: a pointer to a #long into which the minimum x coordinate will be returned.
124  * @y: a pointer to a #long into which the minimum y coordinate will be returned.
125  * @width: a pointer to a #long into which the x extents (width) will be returned.
126  * @height: a pointer to a #long into which the y extents (height) will be returned.
127  * @ctype: the desired coordinate system into which to return the results,
128  *         (e.g. CSPI_COORD_TYPE_WINDOW, CSPI_COORD_TYPE_SCREEN).
129  *
130  * Get the bounding box of the specified #AccessibleComponent.
131  *
132  **/
133 void
134 AccessibleComponent_getExtents (AccessibleComponent *obj,
135                                 long int *x,
136                                 long int *y,
137                                 long int *width,
138                                 long int *height,
139                                 AccessibleCoordType ctype)
140 {
141   Accessibility_BoundingBox bbox;
142
143   cspi_return_if_fail (obj != NULL);
144
145   bbox = Accessibility_Component_getExtents (CSPI_OBJREF (obj),
146                                              ctype,
147                                              cspi_ev ());
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   CORBA_long cx, cy;
179
180   cspi_return_if_fail (obj != NULL);
181
182   Accessibility_Component_getPosition (CSPI_OBJREF (obj),
183                                        &cx, &cy, ctype, cspi_ev ());
184
185   if (!cspi_check_ev ("getPosition"))
186     {
187       *x = *y = 0;
188     }
189   else
190     {
191       *x = cx;
192       *y = cy;
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   CORBA_long cw, ch;
211
212   cspi_return_if_fail (obj != NULL);
213
214   Accessibility_Component_getSize (CSPI_OBJREF (obj),
215                                    &cw,
216                                    &ch,
217                                    cspi_ev ());
218   if (cspi_check_ev ("getSize"))
219   {
220     *width = *height = 0;
221   }
222   else
223   {
224     *width = cw;
225     *height = ch;
226   }
227 }
228
229 /**
230  * AccessibleComponent_getLayer:
231  * @obj: a pointer to the #AccessibleComponent to query.
232  *
233  * Query which layer the component is painted into, to help determine its 
234  *      visibility in terms of stacking order.
235  *
236  * Returns: the #AccessibleComponentLayer into which this component is painted.
237  **/
238 AccessibleComponentLayer
239 AccessibleComponent_getLayer (AccessibleComponent *obj)
240 {
241   AccessibleComponentLayer     retval;
242   Accessibility_ComponentLayer zlayer;
243
244   cspi_return_val_if_fail (obj != NULL, FALSE);
245
246   zlayer = Accessibility_Component_getLayer (CSPI_OBJREF (obj),
247                                              cspi_ev ());
248
249   cspi_return_val_if_ev ("getLayer", SPI_LAYER_INVALID);
250
251   switch (zlayer)
252     {
253     case Accessibility_LAYER_BACKGROUND:
254       retval = SPI_LAYER_BACKGROUND;
255       break;
256     case Accessibility_LAYER_CANVAS:      
257       retval = SPI_LAYER_CANVAS;
258       break;
259     case Accessibility_LAYER_WIDGET:      
260       retval = SPI_LAYER_WIDGET;
261       break;
262     case Accessibility_LAYER_MDI:         
263       retval = SPI_LAYER_MDI;
264       break;
265     case Accessibility_LAYER_POPUP:       
266       retval = SPI_LAYER_POPUP;
267       break;
268     case Accessibility_LAYER_OVERLAY:     
269       retval = SPI_LAYER_OVERLAY;
270       break;
271     case Accessibility_LAYER_WINDOW:      
272       retval = SPI_LAYER_WINDOW;
273       break;
274     default:
275       retval = SPI_LAYER_INVALID;
276       break;
277     }
278
279   return retval;
280 }
281
282 /**
283  * AccessibleComponent_getMDIZOrder:
284  * @obj: a pointer to the #AccessibleComponent to query.
285  *
286  * Query the z stacking order of a component which is in the MDI or window
287  *       layer. (Bigger z-order numbers mean nearer the top)
288  *
289  * Returns: a short integer indicating the stacking order of the component 
290  *       in the MDI layer, or -1 if the component is not in the MDI layer.
291  **/
292 short
293 AccessibleComponent_getMDIZOrder (AccessibleComponent *obj)
294 {
295   short retval;
296
297   cspi_return_val_if_fail (obj != NULL, FALSE);
298
299   retval = Accessibility_Component_getMDIZOrder (CSPI_OBJREF (obj),
300                                                  cspi_ev ());
301
302   cspi_return_val_if_ev ("getMDIZOrder", FALSE);
303
304   return retval;
305 }
306
307 /**
308  * AccessibleComponent_grabFocus:
309  * @obj: a pointer to the #AccessibleComponent on which to operate.
310  *
311  * Attempt to set the keyboard input focus to the specified
312  *         #AccessibleComponent.
313  *
314  * Returns: #TRUE if successful, #FALSE otherwise.
315  *
316  **/
317 SPIBoolean
318 AccessibleComponent_grabFocus (AccessibleComponent *obj)
319 {
320   SPIBoolean retval;
321
322   cspi_return_val_if_fail (obj != NULL, FALSE);
323
324   retval = Accessibility_Component_grabFocus (CSPI_OBJREF (obj),
325                                               cspi_ev ());
326
327   cspi_return_val_if_ev ("grabFocus", FALSE);
328
329   return retval;
330 }
331
332 /**
333  * AccessibleComponent_getAlpha:
334  * @obj: The #AccessibleComponent to be queried.
335  *
336  * Get the opacity/alpha value of a component, if alpha blending is in use.
337  *
338  * Returns: the opacity value of a component, as a double between 0.0 and 1.0. 
339  **/
340 double      
341 AccessibleComponent_getAlpha    (AccessibleComponent *obj)
342 {
343   SPIBoolean retval;
344
345   cspi_return_val_if_fail (obj != NULL, 1.0);
346
347   retval = Accessibility_Component_getAlpha (CSPI_OBJREF (obj),
348                                               cspi_ev ());
349
350   cspi_return_val_if_ev ("getAlpha", 1.0);
351
352   return retval;
353 }