Some work on event support; many bug fixes
[platform/upstream/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 /**
33  * atspi_component_contains:
34  * @obj: a pointer to the #AtspiComponent to query.
35  * @x: a #long specifying the x coordinate in question.
36  * @y: a #long specifying the y coordinate in question.
37  * @ctype: the desired coordinate system of the point (@x, @y)
38  *         (e.g. CSPI_COORD_TYPE_WINDOW, CSPI_COORD_TYPE_SCREEN).
39  *
40  * Query whether a given #AtspiComponent contains a particular point.
41  *
42  * Returns: a #TRUE if the specified component contains the point (@x, @y),
43  *          otherwise #FALSE.
44  **/
45 gboolean
46 atspi_component_contains (AtspiComponent *obj,
47                               gint x,
48                               gint y,
49                               AtspiCoordType ctype, GError **error)
50 {
51   dbus_bool_t retval = FALSE;
52   dbus_int32_t d_x = x, d_y = y;
53   dbus_uint16_t d_ctype = ctype;
54
55   g_return_val_if_fail (obj != NULL, FALSE);
56
57   _atspi_dbus_call (obj, atspi_interface_component, "Contains", error, "iin=>b", d_x, d_y, d_ctype, &retval);
58
59   return retval;
60 }
61
62 /**
63  * atspi_component_ref_accessible_at_point:
64  * @obj: a pointer to the #AtspiComponent to query.
65  * @x: a #gint specifying the x coordinate of the point in question.
66  * @y: a #gint specifying the y coordinate of the point in question.
67  * @ctype: the coordinate system of the point (@x, @y)
68  *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
69  *
70  * Get the accessible child at a given coordinate within an #AtspiComponent.
71  *
72  * Returns: a pointer to an #AtspiAccessible child of the specified component
73  *          which contains the point (@x, @y), or NULL of no child contains
74  *         the point.
75  **/
76 AtspiAccessible *
77 atspi_component_ref_accessible_at_point (AtspiComponent *obj,
78                                           gint x,
79                                           gint y,
80                                           AtspiCoordType ctype, GError **error)
81 {
82   dbus_int32_t d_x = x, d_y = y;
83   dbus_uint16_t d_ctype = ctype;
84   DBusMessage *reply;
85   char *path = NULL;
86   AtspiAccessible *retval = NULL;
87
88   g_return_val_if_fail (obj != NULL, FALSE);
89
90   reply = _atspi_dbus_call_partial (obj, atspi_interface_component, "GetAccessibleAtPoint", error, "iin", d_x, d_y, d_ctype);
91
92   return _atspi_dbus_return_accessible_from_message (reply);
93 }
94
95 /**
96  * atspi_component_get_extents:
97  * @obj: a pointer to the #AtspiComponent to query.
98  * @x: a pointer to a #int into which the minimum x coordinate will be returned.
99  * @y: a pointer to a #int into which the minimum y coordinate will be returned.
100  * @width: a pointer to a #int into which the x extents (width) will be returned.
101  * @height: a pointer to a #int into which the y extents (height) will be returned.
102  * @ctype: the desired coordinate system into which to return the results,
103  *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
104  *
105  * Get the bounding box of the specified #AtspiComponent.
106  *
107  **/
108 AtspiRect
109 atspi_component_get_extents (AtspiComponent *obj,
110                                 gint *x,
111                                 gint *y,
112                                 gint *width,
113                                 gint *height,
114                                 AtspiCoordType ctype, GError **error)
115 {
116   dbus_int16_t d_ctype = ctype;
117   AtspiRect bbox;
118
119   g_return_if_fail (obj != NULL);
120
121   _atspi_dbus_call (obj, atspi_interface_component, "GetExtents", error, "n=>(iiii)", d_ctype, &bbox);
122   return bbox;
123 }
124
125 /**
126  * atspi_component_get_position:
127  * @obj: a pointer to the #AtspiComponent to query.
128  * @ctype: the desired coordinate system into which to return the results,
129  *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
130  *
131  * returns: A #AtspiPoint giving the position.
132  * Get the minimum x and y coordinates of the specified #AtspiComponent.
133  *
134  **/
135 AtspiPoint
136 atspi_component_get_position (AtspiComponent *obj,
137                                  AtspiCoordType ctype, GError **error)
138 {
139   dbus_int32_t d_x, d_y;
140   dbus_uint16_t d_ctype = ctype;
141   AtspiPoint ret;
142
143   ret.x = ret.y = 0;
144
145   if (!obj)
146     return ret;
147
148   _atspi_dbus_call (obj, atspi_interface_component, "GetPosition", error, "n=>ii", d_ctype, &d_x, &d_y);
149
150   ret.x = d_x;
151   ret.y = d_y;
152   return ret;
153 }
154
155 /**
156  * atspi_component_get_size:
157  * @obj: a pointer to the #AtspiComponent to query.
158  * returns: A #AtspiPoint giving the siize.
159  *
160  * Get the size of the specified #AtspiComponent.
161  *
162  **/
163 AtspiPoint
164 atspi_component_get_size (AtspiComponent *obj, GError **error)
165 {
166   dbus_int32_t d_w, d_h;
167   AtspiPoint ret;
168
169   ret.x = ret.y = 0;
170   if (!obj)
171     return ret;
172
173   _atspi_dbus_call (obj, atspi_interface_component, "GetSize", error, "=>ii", &d_w, &d_h);
174   ret.x = d_w;
175   ret.y = d_h;
176   return ret;
177 }
178
179 /**
180  * atspi_component_get_layer:
181  * @obj: a pointer to the #AtspiComponent to query.
182  *
183  * Query which layer the component is painted into, to help determine its 
184  *      visibility in terms of stacking order.
185  *
186  * Returns: the #AtspiComponentLayer into which this component is painted.
187  **/
188 AtspiComponentLayer
189 atspi_component_get_layer (AtspiComponent *obj, GError **error)
190 {
191   dbus_uint32_t zlayer = 0;
192
193   _atspi_dbus_call (obj, atspi_interface_component, "GetLayer", error, "=>u", &zlayer);
194
195   return zlayer;
196 }
197
198 /**
199  * atspi_component_get_mdi_z_order:
200  * @obj: a pointer to the #AtspiComponent to query.
201  *
202  * Query the z stacking order of a component which is in the MDI or window
203  *       layer. (Bigger z-order numbers mean nearer the top)
204  *
205  * Returns: a short integer indicating the stacking order of the component 
206  *       in the MDI layer, or -1 if the component is not in the MDI layer.
207  **/
208 gshort
209 atspi_component_get_mdi_z_order (AtspiComponent *obj, GError **error)
210 {
211   dbus_uint16_t retval = -1;
212
213   _atspi_dbus_call (obj, atspi_interface_component, "GetMDIZOrder", error, "=>n", &retval);
214
215   return retval;
216 }
217
218 /**
219  * atspi_component_grab_focus:
220  * @obj: a pointer to the #AtspiComponent on which to operate.
221  *
222  * Attempt to set the keyboard input focus to the specified
223  *         #AtspiComponent.
224  *
225  * Returns: #TRUE if successful, #FALSE otherwise.
226  *
227  **/
228 gboolean
229 atspi_component_grab_focus (AtspiComponent *obj, GError **error)
230 {
231   dbus_bool_t retval = FALSE;
232
233   _atspi_dbus_call (obj, atspi_interface_component, "GrabFocus", error, "=>b", &retval);
234
235   return retval;
236 }
237
238 /**
239  * atspi_component_get_alpha:
240  * @obj: The #AtspiComponent to be queried.
241  *
242  * Get the opacity/alpha value of a component, if alpha blending is in use.
243  *
244  * Returns: the opacity value of a component, as a double between 0.0 and 1.0. 
245  **/
246 gdouble      
247 atspi_component_get_alpha    (AtspiComponent *obj, GError **error)
248 {
249   double retval = 1;
250
251   _atspi_dbus_call (obj, atspi_interface_component, "GetAlpha", error, "=>d", &retval);
252
253   return retval;
254 }
255
256 static void
257 atspi_component_base_init (AtspiComponentIface *klass)
258 {
259   static gboolean initialized = FALSE;
260
261   if (! initialized)
262     {
263       klass->contains = atspi_component_contains;
264       klass->ref_accessible_at_point = atspi_component_ref_accessible_at_point;
265   klass->get_extents = atspi_component_get_extents;
266       klass->get_position = atspi_component_get_position;
267       klass->get_size = atspi_component_get_size;
268       klass->get_layer = atspi_component_get_layer;
269       klass->get_mdi_z_order = atspi_component_get_mdi_z_order;
270       klass->grab_focus = atspi_component_grab_focus;
271       klass->get_alpha = atspi_component_get_alpha;
272
273       initialized = TRUE;
274     }
275 }
276
277 GType
278 atspi_component_get_type (void)
279 {
280   static GType type = 0;
281
282   if (!type) {
283     static const GTypeInfo tinfo =
284     {
285       sizeof (AtspiComponentIface),
286       (GBaseInitFunc) atspi_component_base_init,
287       (GBaseFinalizeFunc) NULL,
288
289     };
290
291     type = g_type_register_static (G_TYPE_INTERFACE, "AtspiComponent", &tinfo, 0);
292
293   }
294   return type;
295 }