Added better gtk-doc comments.
[platform/upstream/atk.git] / atk / atkcomponent.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright 2001 Sun Microsystems Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20
21 #include "atkcomponent.h"
22
23 static AtkObject* atk_component_real_get_accessible_at_point (AtkComponent *component,
24                                                               gint         x,
25                                                               gint         y);
26
27 GType
28 atk_component_get_type ()
29 {
30   static GType type = 0;
31
32   if (!type) {
33     static const GTypeInfo tinfo =
34     {
35       sizeof (AtkComponentIface),
36       NULL,
37       NULL,
38
39     };
40
41     type = g_type_register_static (G_TYPE_INTERFACE, "AtkComponent", &tinfo, 0);
42   }
43
44   return type;
45 }
46
47 /**
48  *atk_component_add_focus_handler:
49  *@component: The #AtkComponent to attach the @handler to
50  *@handler: The #AtkFocusHandler to be attached to @component
51  *
52  * Add the specified handler to the set of functions to be called 
53  * when this object receives focus (in or out) events.
54  *
55  * Returns:
56  **/
57 guint
58 atk_component_add_focus_handler (AtkComponent    *component,
59                                  AtkFocusHandler handler)
60 {
61   AtkComponentIface *iface = NULL;
62   g_return_val_if_fail (component != NULL, 0);
63   g_return_val_if_fail (ATK_IS_COMPONENT (component), 0);
64
65   iface = ATK_COMPONENT_GET_IFACE (component);
66
67   if (iface->add_focus_handler)
68     return (iface->add_focus_handler) (component, handler);
69   else
70     return 0;
71 }
72
73 /**
74  *atk_component_remove_focus_handler:
75  *@component: the #AtkComponent to remove the focus handler from
76  *@handler_id: the handler id of the focus handler to be removed
77  * from @component
78  *
79  * Remove the handler specified by @handler_id from the list of
80  * functions to be executed when this object receives focus (in or out)
81  **/
82 void
83 atk_component_remove_focus_handler (AtkComponent    *component,
84                                     guint           handler_id)
85 {
86   AtkComponentIface *iface = NULL;
87   g_return_if_fail (component != NULL);
88   g_return_if_fail (ATK_IS_COMPONENT (component));
89
90   iface = ATK_COMPONENT_GET_IFACE (component);
91
92   if (iface->remove_focus_handler)
93     (iface->remove_focus_handler) (component, handler_id);
94 }
95
96 /**
97  *atk_component_contains:
98  *@component: the #AtkComponent
99  *@x: x coordinate relative to the coordinate system of @component
100  *@y: y coordinate relative to the coordinate system of @component
101  *
102  * Checks whether the specified point is within the extent of the @component,
103  * the points x and y coordinates are defined to be relative to the 
104  * coordinate system of the @component.
105  *
106  * Returns: a #gboolean indicating whether the specified point is within
107  *  the extent of the @component
108  **/
109 gboolean
110 atk_component_contains (AtkComponent    *component,
111                         gint            x,
112                         gint            y)
113 {
114   AtkComponentIface *iface = NULL;
115   g_return_val_if_fail (component != NULL, FALSE);
116   g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
117
118   iface = ATK_COMPONENT_GET_IFACE (component);
119
120   if (iface->contains)
121     return (iface->contains) (component, x, y);
122   else
123     return FALSE;
124 }
125
126 /**
127  *atk_component_get_accessible_at_point:
128  *@component: the #AtkComponent
129  *@x: local x coordinate
130  *@y: local y coordinate
131  *
132  * Gets the accessible child, if one exists, contained at the local
133  * coordinate point specified by @x and @y.
134  *
135  *Returns: the accessible child, if one exists, contained at the local
136  * coordinate point specified by @x and @y.
137  **/
138 AtkObject*
139 atk_component_get_accessible_at_point (AtkComponent    *component,
140                                        gint            x,
141                                        gint            y)
142 {
143   AtkComponentIface *iface = NULL;
144   g_return_val_if_fail (component != NULL, NULL);
145   g_return_val_if_fail (ATK_IS_COMPONENT (component), NULL);
146
147   iface = ATK_COMPONENT_GET_IFACE (component);
148
149   if (iface->get_accessible_at_point)
150     return (iface->get_accessible_at_point) (component, x, y);
151   else
152   {
153     /*
154      * if this method is not overridden use the default implementation.
155      */
156     return atk_component_real_get_accessible_at_point (component, x, y);
157   }
158 }
159
160 /**
161  *atk_component_get_extents:
162  *@component: an #AtkComponent
163  *@x: address of #gint to put x coordinate
164  *@y: address of #gint to put y coordinate
165  *@width: address of #gint to put width
166  *@height: address of #gint to put height
167  *
168  * Gets the rectangle which gives the extent of the @component.
169  *
170  **/
171 void
172 atk_component_get_extents    (AtkComponent    *component,
173                               gint            *x,
174                               gint            *y,
175                               gint            *width,
176                               gint            *height)
177 {
178   AtkComponentIface *iface = NULL;
179   g_return_if_fail (component != NULL);
180   g_return_if_fail (ATK_IS_COMPONENT (component));
181
182   iface = ATK_COMPONENT_GET_IFACE (component);
183
184   if (iface->get_extents)
185     (iface->get_extents) (component, x, y, width, height);
186 }
187
188 /**
189  *atk_component_get_position:
190  *@component: an #AtkComponent
191  *@x: address of #gint to put x coordinate position
192  *@y: address of #gint to put y coordinate position
193  *
194  * Gets the position of @component relative to the parent in the form of 
195  * a point specifying @component's top-left corner in the screen's
196  * coordinate space.
197  **/
198 void
199 atk_component_get_position   (AtkComponent    *component,
200                               gint            *x,
201                               gint            *y)
202 {
203   AtkComponentIface *iface = NULL;
204   g_return_if_fail (component != NULL);
205   g_return_if_fail (ATK_IS_COMPONENT (component));
206
207   iface = ATK_COMPONENT_GET_IFACE (component);
208
209   if (iface->get_position)
210     (iface->get_position) (component, x, y);
211 }
212
213 /**
214  *atk_component_get_position_on_screen:
215  *@component: an #AtkComponent
216  *@x: address of #gint to put x coordinate position
217  *@y: address of #gint to put y coordinate position
218  *
219  * Gets the position of the @component on the screen
220  **/
221 void
222 atk_component_get_position_on_screen (AtkComponent    *component,
223                                       gint            *x,
224                                       gint            *y)
225 {
226   AtkComponentIface *iface = NULL;
227   g_return_if_fail (component != NULL);
228   g_return_if_fail (ATK_IS_COMPONENT (component));
229
230   iface = ATK_COMPONENT_GET_IFACE (component);
231
232   if (iface->get_position_on_screen)
233     return (iface->get_position_on_screen) (component, x, y);
234 }
235
236 /**
237  *atk_component_get_size:
238  *@component: an #AtkComponent
239  *@width: address of #gint to put width of @component
240  *@height: address of #gint to put height of @component
241  *
242  * Gets the size of the @component.
243  **/
244 void
245 atk_component_get_size       (AtkComponent    *component,
246                               gint            *x,
247                               gint            *y)
248 {
249   AtkComponentIface *iface = NULL;
250   g_return_if_fail (component != NULL);
251   g_return_if_fail (ATK_IS_COMPONENT (component));
252
253   iface = ATK_COMPONENT_GET_IFACE (component);
254
255   if (iface->get_size)
256     (iface->get_size) (component, x, y);
257 }
258
259 /**
260  *atk_component_grab_focus:
261  *@component: an #AtkComponent
262  *
263  * Grabs focus for this @component
264  **/
265 void
266 atk_component_grab_focus (AtkComponent    *component)
267 {
268   AtkComponentIface *iface = NULL;
269   g_return_if_fail (component != NULL);
270   g_return_if_fail (ATK_IS_COMPONENT (component));
271
272   iface = ATK_COMPONENT_GET_IFACE (component);
273
274   if (iface->grab_focus)
275     (iface->grab_focus) (component);
276 }
277
278 /**
279  *atk_component_set_extents:
280  *@component: an #AtkComponent
281  *@x: x coordinate to set for @component
282  *@y: y coordinate to set for @component
283  *@width: width to set for @component
284  *@height: height to set for @component
285  *
286  * Sets the extents of @component
287  **/
288 void
289 atk_component_set_extents   (AtkComponent    *component,
290                              gint            x,
291                              gint            y,
292                              gint            width,
293                              gint            height)
294 {
295   AtkComponentIface *iface = NULL;
296   g_return_if_fail (component != NULL);
297   g_return_if_fail (ATK_IS_COMPONENT (component));
298
299   iface = ATK_COMPONENT_GET_IFACE (component);
300
301   if (iface->set_extents)
302     (iface->set_extents) (component, x, y, width, height);
303 }
304
305 /**
306  *atk_component_set_position:
307  *@component: an #AtkComponent
308  *@x: x coordinate
309  *@y: y coordinate
310  *
311  * Sets the postition of @component
312  **/
313 void
314 atk_component_set_position   (AtkComponent    *component,
315                               gint            x,
316                               gint            y)
317 {
318   AtkComponentIface *iface = NULL;
319   g_return_if_fail (component != NULL);
320   g_return_if_fail (ATK_IS_COMPONENT (component));
321
322   iface = ATK_COMPONENT_GET_IFACE (component);
323
324   if (iface->set_position)
325     (iface->set_position) (component, x, y);
326 }
327
328 /**
329  *atk_component_set_size:
330  *@component: an #AtkComponent
331  *@width: width to set for @component
332  *@height: height to set for @component
333  *
334  * Set the size of the @component
335  **/
336 void
337 atk_component_set_size       (AtkComponent    *component,
338                               gint            x,
339                               gint            y)
340 {
341   AtkComponentIface *iface = NULL;
342   g_return_if_fail (component != NULL);
343   g_return_if_fail (ATK_IS_COMPONENT (component));
344
345   iface = ATK_COMPONENT_GET_IFACE (component);
346
347   if (iface->set_size)
348     (iface->set_size) (component, x, y);
349 }
350
351 static AtkObject* 
352 atk_component_real_get_accessible_at_point (AtkComponent *component,
353                                             gint         x,
354                                             gint         y)
355 {
356   gint count, i;
357
358   count = atk_object_get_n_accessible_children (ATK_OBJECT (component));
359
360   g_return_val_if_fail (count != 0, NULL);
361
362   for (i = 0; i < count; i++)
363   {
364     AtkObject *obj;
365
366     obj = atk_object_ref_accessible_child (ATK_OBJECT (component), i);
367
368     if (obj != NULL)
369     {
370       if (atk_component_contains (ATK_COMPONENT (obj), x, y))
371       {
372         g_object_unref (obj);
373         return obj;
374       }
375       else
376       {
377         g_object_unref (obj);
378       }
379     }
380   }
381   return NULL;
382 }