Cleaned up 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
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       (GBaseInitFunc) NULL,
37       (GBaseFinalizeFunc) 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 events (in or out).
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 events 
81  * (in or out).
82  **/
83 void
84 atk_component_remove_focus_handler (AtkComponent    *component,
85                                     guint           handler_id)
86 {
87   AtkComponentIface *iface = NULL;
88   g_return_if_fail (component != NULL);
89   g_return_if_fail (ATK_IS_COMPONENT (component));
90
91   iface = ATK_COMPONENT_GET_IFACE (component);
92
93   if (iface->remove_focus_handler)
94     (iface->remove_focus_handler) (component, handler_id);
95 }
96
97 /**
98  * atk_component_contains:
99  * @component: the #AtkComponent
100  * @x: x coordinate relative to the coordinate system of @component
101  * @y: y coordinate relative to the coordinate system of @component
102  *
103  * Checks whether the specified point is within the extent of the @component,
104  * the x and y coordinates are defined to be relative to the 
105  * coordinate system of the @component.
106  *
107  * Returns: %TRUE or %FALSE indicating whether the specified point is within
108  * the extent of the @component or not
109  **/
110 gboolean
111 atk_component_contains (AtkComponent    *component,
112                         gint            x,
113                         gint            y)
114 {
115   AtkComponentIface *iface = NULL;
116   g_return_val_if_fail (component != NULL, FALSE);
117   g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
118
119   iface = ATK_COMPONENT_GET_IFACE (component);
120
121   if (iface->contains)
122     return (iface->contains) (component, x, y);
123   else
124     return FALSE;
125 }
126
127 /**
128  * atk_component_get_accessible_at_point:
129  * @component: the #AtkComponent
130  * @x: local x coordinate
131  * @y: local y coordinate
132  *
133  * Gets the accessible child, if one exists, contained at the local
134  * coordinate point specified by @x and @y.
135  *
136  * Returns: the accessible child, if one exists
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 void
171 atk_component_get_extents    (AtkComponent    *component,
172                               gint            *x,
173                               gint            *y,
174                               gint            *width,
175                               gint            *height)
176 {
177   AtkComponentIface *iface = NULL;
178   g_return_if_fail (component != NULL);
179   g_return_if_fail (ATK_IS_COMPONENT (component));
180
181   iface = ATK_COMPONENT_GET_IFACE (component);
182
183   if (iface->get_extents)
184     (iface->get_extents) (component, x, y, width, height);
185 }
186
187 /**
188  * atk_component_get_position:
189  * @component: an #AtkComponent
190  * @x: address of #gint to put x coordinate position
191  * @y: address of #gint to put y coordinate position
192  *
193  * Gets the position of @component relative to the parent in the form of 
194  * a point specifying @component's top-left corner in the screen's
195  * coordinate space.
196  **/
197 void
198 atk_component_get_position   (AtkComponent    *component,
199                               gint            *x,
200                               gint            *y)
201 {
202   AtkComponentIface *iface = NULL;
203   g_return_if_fail (component != NULL);
204   g_return_if_fail (ATK_IS_COMPONENT (component));
205
206   iface = ATK_COMPONENT_GET_IFACE (component);
207
208   if (iface->get_position)
209     (iface->get_position) (component, x, y);
210 }
211
212 /**
213  * atk_component_get_position_on_screen:
214  * @component: an #AtkComponent
215  * @x: address of #gint to put x coordinate position
216  * @y: address of #gint to put y coordinate position
217  *
218  * Gets the position of the @component on the screen.
219  **/
220 void
221 atk_component_get_position_on_screen (AtkComponent    *component,
222                                       gint            *x,
223                                       gint            *y)
224 {
225   AtkComponentIface *iface = NULL;
226   g_return_if_fail (component != NULL);
227   g_return_if_fail (ATK_IS_COMPONENT (component));
228
229   iface = ATK_COMPONENT_GET_IFACE (component);
230
231   if (iface->get_position_on_screen)
232     (iface->get_position_on_screen) (component, x, y);
233 }
234
235 /**
236  * atk_component_get_size:
237  * @component: an #AtkComponent
238  * @width: address of #gint to put width of @component
239  * @height: address of #gint to put height of @component
240  *
241  * Gets the size of the @component in terms of width and height.
242  **/
243 void
244 atk_component_get_size       (AtkComponent    *component,
245                               gint            *x,
246                               gint            *y)
247 {
248   AtkComponentIface *iface = NULL;
249   g_return_if_fail (component != NULL);
250   g_return_if_fail (ATK_IS_COMPONENT (component));
251
252   iface = ATK_COMPONENT_GET_IFACE (component);
253
254   if (iface->get_size)
255     (iface->get_size) (component, x, y);
256 }
257
258 /**
259  * atk_component_grab_focus:
260  * @component: an #AtkComponent
261  *
262  * Grabs focus for this @component.
263  **/
264 void
265 atk_component_grab_focus (AtkComponent    *component)
266 {
267   AtkComponentIface *iface = NULL;
268   g_return_if_fail (component != NULL);
269   g_return_if_fail (ATK_IS_COMPONENT (component));
270
271   iface = ATK_COMPONENT_GET_IFACE (component);
272
273   if (iface->grab_focus)
274     (iface->grab_focus) (component);
275 }
276
277 /**
278  * atk_component_set_extents:
279  * @component: an #AtkComponent
280  * @x: x coordinate
281  * @y: y coordinate
282  * @width: width to set for @component
283  * @height: height to set for @component
284  *
285  * Sets the extents of @component.
286  **/
287 void
288 atk_component_set_extents   (AtkComponent    *component,
289                              gint            x,
290                              gint            y,
291                              gint            width,
292                              gint            height)
293 {
294   AtkComponentIface *iface = NULL;
295   g_return_if_fail (component != NULL);
296   g_return_if_fail (ATK_IS_COMPONENT (component));
297
298   iface = ATK_COMPONENT_GET_IFACE (component);
299
300   if (iface->set_extents)
301     (iface->set_extents) (component, x, y, width, height);
302 }
303
304 /**
305  * atk_component_set_position:
306  * @component: an #AtkComponent
307  * @x: x coordinate
308  * @y: y coordinate
309  *
310  * Sets the position of @component.
311  **/
312 void
313 atk_component_set_position   (AtkComponent    *component,
314                               gint            x,
315                               gint            y)
316 {
317   AtkComponentIface *iface = NULL;
318   g_return_if_fail (component != NULL);
319   g_return_if_fail (ATK_IS_COMPONENT (component));
320
321   iface = ATK_COMPONENT_GET_IFACE (component);
322
323   if (iface->set_position)
324     (iface->set_position) (component, x, y);
325 }
326
327 /**
328  * atk_component_set_size:
329  * @component: an #AtkComponent
330  * @width: width to set for @component
331  * @height: height to set for @component
332  *
333  * Set the size of the @component in terms of width and height.
334  **/
335 void
336 atk_component_set_size       (AtkComponent    *component,
337                               gint            x,
338                               gint            y)
339 {
340   AtkComponentIface *iface = NULL;
341   g_return_if_fail (component != NULL);
342   g_return_if_fail (ATK_IS_COMPONENT (component));
343
344   iface = ATK_COMPONENT_GET_IFACE (component);
345
346   if (iface->set_size)
347     (iface->set_size) (component, x, y);
348 }
349
350 static AtkObject* 
351 atk_component_real_get_accessible_at_point (AtkComponent *component,
352                                             gint         x,
353                                             gint         y)
354 {
355   gint count, i;
356
357   count = atk_object_get_n_accessible_children (ATK_OBJECT (component));
358
359   g_return_val_if_fail (count != 0, NULL);
360
361   for (i = 0; i < count; i++)
362   {
363     AtkObject *obj;
364
365     obj = atk_object_ref_accessible_child (ATK_OBJECT (component), i);
366
367     if (obj != NULL)
368     {
369       if (atk_component_contains (ATK_COMPONENT (obj), x, y))
370       {
371         g_object_unref (obj);
372         return obj;
373       }
374       else
375       {
376         g_object_unref (obj);
377       }
378     }
379   }
380   return NULL;
381 }