2002-09-06 Mark McLoughlin <mark@skynet.ie>
[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 Sun Microsystems Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /*
24  *
25  * AccessibleComponent function implementations
26  *
27  */
28
29 #include <cspi/spi-private.h>
30
31 /**
32  * AccessibleComponent_ref:
33  * @obj: a pointer to an object implementing #AccessibleComponent on which to operate.
34  *
35  * Increment the reference count for an #AccessibleComponent.
36  **/
37 void
38 AccessibleComponent_ref (AccessibleComponent *obj)
39 {
40   cspi_object_ref (obj);
41 }
42
43 /**
44  * AccessibleComponent_unref:
45  * @obj: a pointer to the object implementing #AccessibleComponent on which to operate.
46  *
47  * Decrement the reference count for an #AccessibleComponent.
48  **/
49 void
50 AccessibleComponent_unref (AccessibleComponent *obj)
51 {
52   cspi_object_unref (obj);
53 }
54
55 /**
56  * AccessibleComponent_contains:
57  * @obj: a pointer to the #AccessibleComponent to query.
58  * @x: a #long specifying the x coordinate in question.
59  * @y: a #long specifying the y coordinate in question.
60  * @ctype: the desired coordinate system of the point (@x, @y)
61  *         (e.g. CSPI_COORD_TYPE_WINDOW, CSPI_COORD_TYPE_SCREEN).
62  *
63  * Query whether a given #AccessibleComponent contains a particular point.
64  *
65  * Returns: a #TRUE if the specified component contains the point (@x, @y),
66  *          otherwise #FALSE.
67  **/
68 SPIBoolean
69 AccessibleComponent_contains (AccessibleComponent *obj,
70                               long int x,
71                               long int y,
72                               AccessibleCoordType ctype)
73 {
74   SPIBoolean retval;
75
76   cspi_return_val_if_fail (obj != NULL, FALSE);
77
78   retval = Accessibility_Component_contains (CSPI_OBJREF (obj),
79                                              x,
80                                              y,
81                                              ctype,
82                                              cspi_ev ());
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   Accessibility_Accessible child;
108
109   cspi_return_val_if_fail (obj != NULL, NULL);
110
111   child = Accessibility_Component_getAccessibleAtPoint (CSPI_OBJREF (obj),
112                                                         x,
113                                                         y,
114                                                         ctype,
115                                                         cspi_ev ());
116   return cspi_object_add (child);
117 }
118
119 /**
120  * AccessibleComponent_getExtents:
121  * @obj: a pointer to the #AccessibleComponent to query.
122  * @x: a pointer to a #long into which the minimum x coordinate will be returned.
123  * @y: a pointer to a #long into which the minimum y coordinate will be returned.
124  * @width: a pointer to a #long into which the x extents (width) will be returned.
125  * @height: a pointer to a #long into which the y extents (height) will be returned.
126  * @ctype: the desired coordinate system into which to return the results,
127  *         (e.g. CSPI_COORD_TYPE_WINDOW, CSPI_COORD_TYPE_SCREEN).
128  *
129  * Get the bounding box of the specified #AccessibleComponent.
130  *
131  **/
132 void
133 AccessibleComponent_getExtents (AccessibleComponent *obj,
134                                 long int *x,
135                                 long int *y,
136                                 long int *width,
137                                 long int *height,
138                                 AccessibleCoordType ctype)
139 {
140   Accessibility_BoundingBox bbox;
141
142   cspi_return_if_fail (obj != NULL);
143
144   bbox = Accessibility_Component_getExtents (CSPI_OBJREF (obj),
145                                              ctype,
146                                              cspi_ev ());
147   if (!cspi_check_ev ("getExtents"))
148     {
149       *x = *y = *width = *height = 0;    
150     }
151   else
152     {
153       *x = bbox.x;
154       *y = bbox.y;
155       *width = bbox.width;
156       *height = bbox.height;
157     }
158 }
159
160 /**
161  * AccessibleComponent_getPosition:
162  * @obj: a pointer to the #AccessibleComponent to query.
163  * @x: a pointer to a #long into which the minimum x coordinate will be returned.
164  * @y: a pointer to a #long into which the minimum y coordinate will be returned.
165  * @ctype: the desired coordinate system into which to return the results,
166  *         (e.g. CSPI_COORD_TYPE_WINDOW, CSPI_COORD_TYPE_SCREEN).
167  *
168  * Get the minimum x and y coordinates of the specified #AccessibleComponent.
169  *
170  **/
171 void
172 AccessibleComponent_getPosition (AccessibleComponent *obj,
173                                  long int *x,
174                                  long int *y,
175                                  AccessibleCoordType ctype)
176 {
177   CORBA_long cx, cy;
178
179   cspi_return_if_fail (obj != NULL);
180
181   Accessibility_Component_getPosition (CSPI_OBJREF (obj),
182                                        &cx, &cy, ctype, cspi_ev ());
183
184   if (!cspi_check_ev ("getPosition"))
185     {
186       *x = *y = 0;
187     }
188   else
189     {
190       *x = cx;
191       *y = cy;
192     }
193 }
194
195 /**
196  * AccessibleComponent_getSize:
197  * @obj: a pointer to the #AccessibleComponent to query.
198  * @width: a pointer to a #long into which the x extents (width) will be returned.
199  * @height: a pointer to a #long into which the y extents (height) will be returned.
200  *
201  * Get the size of the specified #AccessibleComponent.
202  *
203  **/
204 void
205 AccessibleComponent_getSize (AccessibleComponent *obj,
206                              long int *width,
207                              long int *height)
208 {
209   CORBA_long cw, ch;
210
211   cspi_return_if_fail (obj != NULL);
212
213   Accessibility_Component_getSize (CSPI_OBJREF (obj),
214                                    &cw,
215                                    &ch,
216                                    cspi_ev ());
217   if (cspi_check_ev ("getSize"))
218   {
219     *width = *height = 0;
220   }
221   else
222   {
223     *width = cw;
224     *height = ch;
225   }
226 }
227
228 /**
229  * AccessibleComponent_getLayer:
230  * @obj: a pointer to the #AccessibleComponent to query.
231  *
232  * Query which layer the component is painted into, to help determine its 
233  *      visibility in terms of stacking order.
234  *
235  * Returns: the #AccessibleComponentLayer into which this component is painted.
236  **/
237 AccessibleComponentLayer
238 AccessibleComponent_getLayer (AccessibleComponent *obj)
239 {
240   AccessibleComponentLayer     retval;
241   Accessibility_ComponentLayer zlayer;
242
243   cspi_return_val_if_fail (obj != NULL, FALSE);
244
245   zlayer = Accessibility_Component_getLayer (CSPI_OBJREF (obj),
246                                              cspi_ev ());
247
248   cspi_return_val_if_ev ("getLayer", SPI_LAYER_INVALID);
249
250   switch (zlayer)
251     {
252     case Accessibility_LAYER_BACKGROUND:
253       retval = SPI_LAYER_BACKGROUND;
254       break;
255     case Accessibility_LAYER_CANVAS:      
256       retval = SPI_LAYER_CANVAS;
257       break;
258     case Accessibility_LAYER_WIDGET:      
259       retval = SPI_LAYER_WIDGET;
260       break;
261     case Accessibility_LAYER_MDI:         
262       retval = SPI_LAYER_MDI;
263       break;
264     case Accessibility_LAYER_POPUP:       
265       retval = SPI_LAYER_POPUP;
266       break;
267     case Accessibility_LAYER_OVERLAY:     
268       retval = SPI_LAYER_OVERLAY;
269       break;
270     case Accessibility_LAYER_WINDOW:      
271       retval = SPI_LAYER_WINDOW;
272       break;
273     default:
274       retval = SPI_LAYER_INVALID;
275       break;
276     }
277
278   return retval;
279 }
280
281 /**
282  * AccessibleComponent_getMDIZOrder:
283  * @obj: a pointer to the #AccessibleComponent to query.
284  *
285  * Query the z stacking order of a component which is in the MDI or window
286  *       layer. (Bigger z-order numbers mean nearer the top)
287  *
288  * Returns: a short integer indicating the stacking order of the component 
289  *       in the MDI layer, or -1 if the component is not in the MDI layer.
290  **/
291 short
292 AccessibleComponent_getMDIZOrder (AccessibleComponent *obj)
293 {
294   short retval;
295
296   cspi_return_val_if_fail (obj != NULL, FALSE);
297
298   retval = Accessibility_Component_getMDIZOrder (CSPI_OBJREF (obj),
299                                                  cspi_ev ());
300
301   cspi_return_val_if_ev ("getMDIZOrder", FALSE);
302
303   return retval;
304 }
305
306 /**
307  * AccessibleComponent_grabFocus:
308  * @obj: a pointer to the #AccessibleComponent on which to operate.
309  *
310  * Attempt to set the keyboard input focus to the specified
311  *         #AccessibleComponent.
312  *
313  * Returns: #TRUE if successful, #FALSE otherwise.
314  *
315  **/
316 SPIBoolean
317 AccessibleComponent_grabFocus (AccessibleComponent *obj)
318 {
319   SPIBoolean retval;
320
321   cspi_return_val_if_fail (obj != NULL, FALSE);
322
323   retval = Accessibility_Component_grabFocus (CSPI_OBJREF (obj),
324                                               cspi_ev ());
325
326   cspi_return_val_if_ev ("grabFocus", FALSE);
327
328   return retval;
329 }
330