Minor fixes to docs.
[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                                                               AtkCoordType coord_type);
27
28 GType
29 atk_component_get_type ()
30 {
31   static GType type = 0;
32
33   if (!type) {
34     static const GTypeInfo tinfo =
35     {
36       sizeof (AtkComponentIface),
37       (GBaseInitFunc) NULL,
38       (GBaseFinalizeFunc) NULL,
39
40     };
41
42     type = g_type_register_static (G_TYPE_INTERFACE, "AtkComponent", &tinfo, 0);
43   }
44
45   return type;
46 }
47
48 /**
49  * atk_component_add_focus_handler:
50  * @component: The #AtkComponent to attach the @handler to
51  * @handler: The #AtkFocusHandler to be attached to @component
52  *
53  * Add the specified handler to the set of functions to be called 
54  * when this object receives focus events (in or out).
55  *
56  * Returns:
57  **/
58 guint
59 atk_component_add_focus_handler (AtkComponent    *component,
60                                  AtkFocusHandler handler)
61 {
62   AtkComponentIface *iface = NULL;
63   g_return_val_if_fail (component != NULL, 0);
64   g_return_val_if_fail (ATK_IS_COMPONENT (component), 0);
65
66   iface = ATK_COMPONENT_GET_IFACE (component);
67
68   if (iface->add_focus_handler)
69     return (iface->add_focus_handler) (component, handler);
70   else
71     return 0;
72 }
73
74 /**
75  * atk_component_remove_focus_handler:
76  * @component: the #AtkComponent to remove the focus handler from
77  * @handler_id: the handler id of the focus handler to be removed
78  * from @component
79  *
80  * Remove the handler specified by @handler_id from the list of
81  * functions to be executed when this object receives focus events 
82  * (in or out).
83  **/
84 void
85 atk_component_remove_focus_handler (AtkComponent    *component,
86                                     guint           handler_id)
87 {
88   AtkComponentIface *iface = NULL;
89   g_return_if_fail (component != NULL);
90   g_return_if_fail (ATK_IS_COMPONENT (component));
91
92   iface = ATK_COMPONENT_GET_IFACE (component);
93
94   if (iface->remove_focus_handler)
95     (iface->remove_focus_handler) (component, handler_id);
96 }
97
98 /**
99  * atk_component_contains:
100  * @component: the #AtkComponent
101  * @x: x coordinate
102  * @y: y coordinate
103  * @coord_type: specifies whether the coordinates are relative to the screen
104  * or to the components top level window
105  *
106  * Checks whether the specified point is within the extent of the @component.
107  *
108  * Returns: %TRUE or %FALSE indicating whether the specified point is within
109  * the extent of the @component or not
110  **/
111 gboolean
112 atk_component_contains (AtkComponent    *component,
113                         gint            x,
114                         gint            y,
115                         AtkCoordType    coord_type)
116 {
117   AtkComponentIface *iface = NULL;
118   g_return_val_if_fail (component != NULL, FALSE);
119   g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
120
121   iface = ATK_COMPONENT_GET_IFACE (component);
122
123   if (iface->contains)
124     return (iface->contains) (component, x, y, coord_type);
125   else
126     return FALSE;
127 }
128
129 /**
130  * atk_component_get_accessible_at_point:
131  * @component: the #AtkComponent
132  * @x: x coordinate
133  * @y: y coordinate
134  * @coord_type: specifies whether the coordinates are relative to the screen
135  * or to the components top level window
136  *
137  * Gets the accessible child, if one exists, contained at the
138  * coordinate point specified by @x and @y.
139  *
140  * Returns: the accessible child, if one exists
141  **/
142 AtkObject*
143 atk_component_get_accessible_at_point (AtkComponent    *component,
144                                        gint            x,
145                                        gint            y,
146                                        AtkCoordType    coord_type)
147 {
148   AtkComponentIface *iface = NULL;
149   g_return_val_if_fail (component != NULL, NULL);
150   g_return_val_if_fail (ATK_IS_COMPONENT (component), NULL);
151
152   iface = ATK_COMPONENT_GET_IFACE (component);
153
154   if (iface->get_accessible_at_point)
155     return (iface->get_accessible_at_point) (component, x, y, coord_type);
156   else
157   {
158     /*
159      * if this method is not overridden use the default implementation.
160      */
161     return atk_component_real_get_accessible_at_point (component, x, y, coord_type);
162   }
163 }
164
165 /**
166  * atk_component_get_extents:
167  * @component: an #AtkComponent
168  * @x: address of #gint to put x coordinate
169  * @y: address of #gint to put y coordinate
170  * @width: address of #gint to put width
171  * @height: address of #gint to put height
172  * @coord_type: specifies whether the coordinates are relative to the screen
173  * or to the components top level window
174  *
175  * Gets the rectangle which gives the extent of the @component.
176  *
177  **/
178 void
179 atk_component_get_extents    (AtkComponent    *component,
180                               gint            *x,
181                               gint            *y,
182                               gint            *width,
183                               gint            *height,
184                               AtkCoordType    coord_type)
185 {
186   AtkComponentIface *iface = NULL;
187   g_return_if_fail (component != NULL);
188   g_return_if_fail (ATK_IS_COMPONENT (component));
189
190   iface = ATK_COMPONENT_GET_IFACE (component);
191
192   if (iface->get_extents)
193     (iface->get_extents) (component, x, y, width, height, coord_type);
194 }
195
196 /**
197  * atk_component_get_position:
198  * @component: an #AtkComponent
199  * @x: address of #gint to put x coordinate position
200  * @y: address of #gint to put y coordinate position
201  * @coord_type: specifies whether the coordinates are relative to the screen
202  * or to the components top level window
203  *
204  * Gets the position of @component in the form of 
205  * a point specifying @component's top-left corner.
206  **/
207 void
208 atk_component_get_position   (AtkComponent    *component,
209                               gint            *x,
210                               gint            *y,
211                               AtkCoordType    coord_type)
212 {
213   AtkComponentIface *iface = NULL;
214   g_return_if_fail (component != NULL);
215   g_return_if_fail (ATK_IS_COMPONENT (component));
216
217   iface = ATK_COMPONENT_GET_IFACE (component);
218
219   if (iface->get_position)
220     (iface->get_position) (component, x, y, coord_type);
221 }
222
223 /**
224  * atk_component_get_size:
225  * @component: an #AtkComponent
226  * @width: address of #gint to put width of @component
227  * @height: address of #gint to put height of @component
228  *
229  * Gets the size of the @component in terms of width and height.
230  **/
231 void
232 atk_component_get_size       (AtkComponent    *component,
233                               gint            *x,
234                               gint            *y)
235 {
236   AtkComponentIface *iface = NULL;
237   g_return_if_fail (component != NULL);
238   g_return_if_fail (ATK_IS_COMPONENT (component));
239
240   iface = ATK_COMPONENT_GET_IFACE (component);
241
242   if (iface->get_size)
243     (iface->get_size) (component, x, y);
244 }
245
246 /**
247  * atk_component_grab_focus:
248  * @component: an #AtkComponent
249  *
250  * Grabs focus for this @component.
251  *
252  * Returns: %TRUE if successful, %FALSE otherwise.
253  **/
254 gboolean
255 atk_component_grab_focus (AtkComponent    *component)
256 {
257   AtkComponentIface *iface = NULL;
258   g_return_val_if_fail (component != NULL, FALSE);
259   g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
260
261   iface = ATK_COMPONENT_GET_IFACE (component);
262
263   if (iface->grab_focus)
264     return (iface->grab_focus) (component);
265   else
266     return FALSE;
267 }
268
269 /**
270  * atk_component_set_extents:
271  * @component: an #AtkComponent
272  * @x: x coordinate
273  * @y: y coordinate
274  * @width: width to set for @component
275  * @height: height to set for @component
276  * @coord_type: specifies whether the coordinates are relative to the screen
277  * or to the components top level window
278  *
279  * Sets the extents of @component.
280  *
281  * Returns: %TRUE or %FALSE whether the extents were set or not
282  **/
283 gboolean
284 atk_component_set_extents   (AtkComponent    *component,
285                              gint            x,
286                              gint            y,
287                              gint            width,
288                              gint            height,
289                              AtkCoordType    coord_type)
290 {
291   AtkComponentIface *iface = NULL;
292   g_return_val_if_fail (component != NULL, FALSE);
293   g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
294
295   iface = ATK_COMPONENT_GET_IFACE (component);
296
297   if (iface->set_extents)
298     return (iface->set_extents) (component, x, y, width, height, coord_type);
299   else
300     return FALSE;
301 }
302
303 /**
304  * atk_component_set_position:
305  * @component: an #AtkComponent
306  * @x: x coordinate
307  * @y: y coordinate
308  * @coord_type: specifies whether the coordinates are relative to the screen
309  * or to the components top level window
310  *
311  * Sets the postition of @component.
312  * 
313  * Returns: %TRUE or %FALSE whether or not the position was set or not
314  **/
315 gboolean
316 atk_component_set_position   (AtkComponent    *component,
317                               gint            x,
318                               gint            y,
319                               AtkCoordType    coord_type)
320 {
321   AtkComponentIface *iface = NULL;
322   g_return_val_if_fail (component != NULL, FALSE);
323   g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
324
325   iface = ATK_COMPONENT_GET_IFACE (component);
326
327   if (iface->set_position)
328     return (iface->set_position) (component, x, y, coord_type);
329   else
330     return FALSE;
331 }
332
333 /**
334  * atk_component_set_size:
335  * @component: an #AtkComponent
336  * @width: width to set for @component
337  * @height: height to set for @component
338  *
339  * Set the size of the @component in terms of width and height.
340  *
341  * Returns: %TRUE or %FALSE whether the size was set or not
342  **/
343 gboolean
344 atk_component_set_size       (AtkComponent    *component,
345                               gint            x,
346                               gint            y)
347 {
348   AtkComponentIface *iface = NULL;
349   g_return_val_if_fail (component != NULL, FALSE);
350   g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
351
352   iface = ATK_COMPONENT_GET_IFACE (component);
353
354   if (iface->set_size)
355     return (iface->set_size) (component, x, y);
356   else
357     return FALSE;
358 }
359
360 static AtkObject* 
361 atk_component_real_get_accessible_at_point (AtkComponent *component,
362                                             gint         x,
363                                             gint         y,
364                                             AtkCoordType coord_type)
365 {
366   gint count, i;
367
368   count = atk_object_get_n_accessible_children (ATK_OBJECT (component));
369
370   g_return_val_if_fail (count != 0, NULL);
371
372   for (i = 0; i < count; i++)
373   {
374     AtkObject *obj;
375
376     obj = atk_object_ref_accessible_child (ATK_OBJECT (component), i);
377
378     if (obj != NULL)
379     {
380       if (atk_component_contains (ATK_COMPONENT (obj), x, y, coord_type))
381       {
382         g_object_unref (obj);
383         return obj;
384       }
385       else
386       {
387         g_object_unref (obj);
388       }
389     }
390   }
391   return NULL;
392 }