Box some types, add missing header file, and other 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 static AtspiRect *
33 atspi_rect_copy (AtspiRect *src)
34 {
35   AtspiRect *dst = g_new (AtspiRect, 1);
36   dst->x = src->x;
37   dst->y = src->y;
38   dst->height = src->height;
39   dst->width = src->width;
40 }
41
42 G_DEFINE_BOXED_TYPE (AtspiRect, atspi_rect, atspi_rect_copy, g_free)
43
44 static AtspiPoint *
45 atspi_point_copy (AtspiPoint *src)
46 {
47   AtspiPoint *dst = g_new (AtspiPoint, 1);
48   dst->x = src->x;
49   dst->y = src->y;
50 }
51
52 G_DEFINE_BOXED_TYPE (AtspiPoint, atspi_point, atspi_point_copy, g_free)
53
54 /**
55  * atspi_component_contains:
56  * @obj: a pointer to the #AtspiComponent to query.
57  * @x: a #long specifying the x coordinate in question.
58  * @y: a #long specifying the y coordinate in question.
59  * @ctype: the desired coordinate system of the point (@x, @y)
60  *         (e.g. CSPI_COORD_TYPE_WINDOW, CSPI_COORD_TYPE_SCREEN).
61  *
62  * Query whether a given #AtspiComponent contains a particular point.
63  *
64  * Returns: a #TRUE if the specified component contains the point (@x, @y),
65  *          otherwise #FALSE.
66  **/
67 gboolean
68 atspi_component_contains (AtspiComponent *obj,
69                               gint x,
70                               gint y,
71                               AtspiCoordType ctype, GError **error)
72 {
73   dbus_bool_t retval = FALSE;
74   dbus_int32_t d_x = x, d_y = y;
75   dbus_uint16_t d_ctype = ctype;
76
77   g_return_val_if_fail (obj != NULL, FALSE);
78
79   _atspi_dbus_call (obj, atspi_interface_component, "Contains", error, "iin=>b", d_x, d_y, d_ctype, &retval);
80
81   return retval;
82 }
83
84 /**
85  * atspi_component_ref_accessible_at_point:
86  * @obj: a pointer to the #AtspiComponent to query.
87  * @x: a #gint specifying the x coordinate of the point in question.
88  * @y: a #gint specifying the y coordinate of the point in question.
89  * @ctype: the coordinate system of the point (@x, @y)
90  *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
91  *
92  * Get the accessible child at a given coordinate within an #AtspiComponent.
93  *
94  * Returns: a pointer to an #AtspiAccessible child of the specified component
95  *          which contains the point (@x, @y), or NULL of no child contains
96  *         the point.
97  **/
98 AtspiAccessible *
99 atspi_component_ref_accessible_at_point (AtspiComponent *obj,
100                                           gint x,
101                                           gint y,
102                                           AtspiCoordType ctype, GError **error)
103 {
104   dbus_int32_t d_x = x, d_y = y;
105   dbus_uint16_t d_ctype = ctype;
106   DBusMessage *reply;
107   char *path = NULL;
108   AtspiAccessible *retval = NULL;
109
110   g_return_val_if_fail (obj != NULL, FALSE);
111
112   reply = _atspi_dbus_call_partial (obj, atspi_interface_component, "GetAccessibleAtPoint", error, "iin", d_x, d_y, d_ctype);
113
114   return _atspi_dbus_return_accessible_from_message (reply);
115 }
116
117 /**
118  * atspi_component_get_extents:
119  * @obj: a pointer to the #AtspiComponent to query.
120  * @x: a pointer to a #int into which the minimum x coordinate will be returned.
121  * @y: a pointer to a #int into which the minimum y coordinate will be returned.
122  * @width: a pointer to a #int into which the x extents (width) will be returned.
123  * @height: a pointer to a #int into which the y extents (height) will be returned.
124  * @ctype: the desired coordinate system into which to return the results,
125  *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
126  *
127  * Get the bounding box of the specified #AtspiComponent.
128  *
129  **/
130 AtspiRect
131 atspi_component_get_extents (AtspiComponent *obj,
132                                 gint *x,
133                                 gint *y,
134                                 gint *width,
135                                 gint *height,
136                                 AtspiCoordType ctype, GError **error)
137 {
138   dbus_int16_t d_ctype = ctype;
139   AtspiRect bbox;
140
141   g_return_if_fail (obj != NULL);
142
143   _atspi_dbus_call (obj, atspi_interface_component, "GetExtents", error, "n=>(iiii)", d_ctype, &bbox);
144   return 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  * returns: A #AtspiPoint giving the position.
154  * Get the minimum x and y coordinates of the specified #AtspiComponent.
155  *
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_uint16_t d_ctype = ctype;
163   AtspiPoint ret;
164
165   ret.x = ret.y = 0;
166
167   if (!obj)
168     return ret;
169
170   _atspi_dbus_call (obj, atspi_interface_component, "GetPosition", error, "n=>ii", d_ctype, &d_x, &d_y);
171
172   ret.x = d_x;
173   ret.y = d_y;
174   return ret;
175 }
176
177 /**
178  * atspi_component_get_size:
179  * @obj: a pointer to the #AtspiComponent to query.
180  * returns: A #AtspiPoint giving the siize.
181  *
182  * Get the size of the specified #AtspiComponent.
183  *
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 = 0;
192   if (!obj)
193     return 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 ret;
199 }
200
201 /**
202  * atspi_component_get_layer:
203  * @obj: a pointer to the #AtspiComponent to query.
204  *
205  * Query 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 = 0;
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  * Query 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 short integer 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  * Attempt 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  * Get the opacity/alpha value of a component, if alpha blending is in use.
265  *
266  * Returns: the opacity value of a component, as a double 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 static void
279 atspi_component_base_init (AtspiComponent *klass)
280 {
281   static gboolean initialized = FALSE;
282
283   if (! initialized)
284     {
285       klass->contains = atspi_component_contains;
286       klass->ref_accessible_at_point = atspi_component_ref_accessible_at_point;
287   klass->get_extents = atspi_component_get_extents;
288       klass->get_position = atspi_component_get_position;
289       klass->get_size = atspi_component_get_size;
290       klass->get_layer = atspi_component_get_layer;
291       klass->get_mdi_z_order = atspi_component_get_mdi_z_order;
292       klass->grab_focus = atspi_component_grab_focus;
293       klass->get_alpha = atspi_component_get_alpha;
294
295       initialized = TRUE;
296     }
297 }
298
299 GType
300 atspi_component_get_type (void)
301 {
302   static GType type = 0;
303
304   if (!type) {
305     static const GTypeInfo tinfo =
306     {
307       sizeof (AtspiComponent),
308       (GBaseInitFunc) atspi_component_base_init,
309       (GBaseFinalizeFunc) NULL,
310
311     };
312
313     type = g_type_register_static (G_TYPE_INTERFACE, "AtspiComponent", &tinfo, 0);
314
315   }
316   return type;
317 }