1 /* ATK - Accessibility Toolkit
2 * Copyright 2001 Sun Microsystems Inc.
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.
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.
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.
21 #include "atkcomponent.h"
23 static gboolean atk_component_real_contains (AtkComponent *component,
26 AtkCoordType coord_type);
28 static AtkObject* atk_component_real_ref_accessible_at_point (AtkComponent *component,
31 AtkCoordType coord_type);
33 static void atk_component_real_get_position (AtkComponent *component,
36 AtkCoordType coord_type);
38 static void atk_component_real_get_size (AtkComponent *component,
43 atk_component_get_type (void)
45 static GType type = 0;
48 static const GTypeInfo tinfo =
50 sizeof (AtkComponentIface),
52 (GBaseFinalizeFunc) NULL,
56 type = g_type_register_static (G_TYPE_INTERFACE, "AtkComponent", &tinfo, 0);
63 * atk_component_add_focus_handler:
64 * @component: The #AtkComponent to attach the @handler to
65 * @handler: The #AtkFocusHandler to be attached to @component
67 * Add the specified handler to the set of functions to be called
68 * when this object receives focus events (in or out). If the handler is
69 * already added it is not added again
71 * Returns: a handler id which can be used in atk_component_remove_focus_handler
72 * or zero if the handler was already added.
75 atk_component_add_focus_handler (AtkComponent *component,
76 AtkFocusHandler handler)
78 AtkComponentIface *iface = NULL;
79 g_return_val_if_fail (ATK_IS_COMPONENT (component), 0);
81 iface = ATK_COMPONENT_GET_IFACE (component);
83 if (iface->add_focus_handler)
84 return (iface->add_focus_handler) (component, handler);
90 * atk_component_remove_focus_handler:
91 * @component: the #AtkComponent to remove the focus handler from
92 * @handler_id: the handler id of the focus handler to be removed
95 * Remove the handler specified by @handler_id from the list of
96 * functions to be executed when this object receives focus events
100 atk_component_remove_focus_handler (AtkComponent *component,
103 AtkComponentIface *iface = NULL;
104 g_return_if_fail (ATK_IS_COMPONENT (component));
106 iface = ATK_COMPONENT_GET_IFACE (component);
108 if (iface->remove_focus_handler)
109 (iface->remove_focus_handler) (component, handler_id);
113 * atk_component_contains:
114 * @component: the #AtkComponent
117 * @coord_type: specifies whether the coordinates are relative to the screen
118 * or to the components top level window
120 * Checks whether the specified point is within the extent of the @component.
122 * Returns: %TRUE or %FALSE indicating whether the specified point is within
123 * the extent of the @component or not
126 atk_component_contains (AtkComponent *component,
129 AtkCoordType coord_type)
131 AtkComponentIface *iface = NULL;
132 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
134 iface = ATK_COMPONENT_GET_IFACE (component);
137 return (iface->contains) (component, x, y, coord_type);
141 * if this method is not overridden use the default implementation.
143 return atk_component_real_contains (component, x, y, coord_type);
148 * atk_component_ref_accessible_at_point:
149 * @component: the #AtkComponent
152 * @coord_type: specifies whether the coordinates are relative to the screen
153 * or to the components top level window
155 * Gets a reference to the accessible child, if one exists, at the
156 * coordinate point specified by @x and @y.
158 * Returns: a reference to the accessible child, if one exists
161 atk_component_ref_accessible_at_point (AtkComponent *component,
164 AtkCoordType coord_type)
166 AtkComponentIface *iface = NULL;
167 g_return_val_if_fail (ATK_IS_COMPONENT (component), NULL);
169 iface = ATK_COMPONENT_GET_IFACE (component);
171 if (iface->ref_accessible_at_point)
172 return (iface->ref_accessible_at_point) (component, x, y, coord_type);
176 * if this method is not overridden use the default implementation.
178 return atk_component_real_ref_accessible_at_point (component, x, y, coord_type);
183 * atk_component_get_extents:
184 * @component: an #AtkComponent
185 * @x: address of #gint to put x coordinate
186 * @y: address of #gint to put y coordinate
187 * @width: address of #gint to put width
188 * @height: address of #gint to put height
189 * @coord_type: specifies whether the coordinates are relative to the screen
190 * or to the components top level window
192 * Gets the rectangle which gives the extent of the @component.
196 atk_component_get_extents (AtkComponent *component,
201 AtkCoordType coord_type)
203 AtkComponentIface *iface = NULL;
204 gint local_x, local_y, local_width, local_height;
205 gint *real_x, *real_y, *real_width, *real_height;
207 g_return_if_fail (ATK_IS_COMPONENT (component));
220 real_width = &local_width;
222 real_height = height;
224 real_height = &local_height;
226 iface = ATK_COMPONENT_GET_IFACE (component);
228 if (iface->get_extents)
229 (iface->get_extents) (component, real_x, real_y, real_width, real_height, coord_type);
233 * atk_component_get_position:
234 * @component: an #AtkComponent
235 * @x: address of #gint to put x coordinate position
236 * @y: address of #gint to put y coordinate position
237 * @coord_type: specifies whether the coordinates are relative to the screen
238 * or to the components top level window
240 * Gets the position of @component in the form of
241 * a point specifying @component's top-left corner.
244 atk_component_get_position (AtkComponent *component,
247 AtkCoordType coord_type)
249 AtkComponentIface *iface = NULL;
250 gint local_x, local_y;
251 gint *real_x, *real_y;
253 g_return_if_fail (ATK_IS_COMPONENT (component));
264 iface = ATK_COMPONENT_GET_IFACE (component);
266 if (iface->get_position)
267 (iface->get_position) (component, real_x, real_y, coord_type);
271 * if this method is not overridden use the default implementation.
273 atk_component_real_get_position (component, real_x, real_y, coord_type);
278 * atk_component_get_size:
279 * @component: an #AtkComponent
280 * @width: address of #gint to put width of @component
281 * @height: address of #gint to put height of @component
283 * Gets the size of the @component in terms of width and height.
286 atk_component_get_size (AtkComponent *component,
290 AtkComponentIface *iface = NULL;
291 gint local_width, local_height;
292 gint *real_width, *real_height;
294 g_return_if_fail (ATK_IS_COMPONENT (component));
299 real_width = &local_width;
301 real_height = height;
303 real_height = &local_height;
305 iface = ATK_COMPONENT_GET_IFACE (component);
306 g_return_if_fail (ATK_IS_COMPONENT (component));
308 iface = ATK_COMPONENT_GET_IFACE (component);
311 (iface->get_size) (component, real_width, real_height);
315 * if this method is not overridden use the default implementation.
317 atk_component_real_get_size (component, real_width, real_height);
322 * atk_component_grab_focus:
323 * @component: an #AtkComponent
325 * Grabs focus for this @component.
327 * Returns: %TRUE if successful, %FALSE otherwise.
330 atk_component_grab_focus (AtkComponent *component)
332 AtkComponentIface *iface = NULL;
333 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
335 iface = ATK_COMPONENT_GET_IFACE (component);
337 if (iface->grab_focus)
338 return (iface->grab_focus) (component);
344 * atk_component_set_extents:
345 * @component: an #AtkComponent
348 * @width: width to set for @component
349 * @height: height to set for @component
350 * @coord_type: specifies whether the coordinates are relative to the screen
351 * or to the components top level window
353 * Sets the extents of @component.
355 * Returns: %TRUE or %FALSE whether the extents were set or not
358 atk_component_set_extents (AtkComponent *component,
363 AtkCoordType coord_type)
365 AtkComponentIface *iface = NULL;
366 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
368 iface = ATK_COMPONENT_GET_IFACE (component);
370 if (iface->set_extents)
371 return (iface->set_extents) (component, x, y, width, height, coord_type);
377 * atk_component_set_position:
378 * @component: an #AtkComponent
381 * @coord_type: specifies whether the coordinates are relative to the screen
382 * or to the components top level window
384 * Sets the postition of @component.
386 * Returns: %TRUE or %FALSE whether or not the position was set or not
389 atk_component_set_position (AtkComponent *component,
392 AtkCoordType coord_type)
394 AtkComponentIface *iface = NULL;
395 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
397 iface = ATK_COMPONENT_GET_IFACE (component);
399 if (iface->set_position)
400 return (iface->set_position) (component, x, y, coord_type);
406 * atk_component_set_size:
407 * @component: an #AtkComponent
408 * @width: width to set for @component
409 * @height: height to set for @component
411 * Set the size of the @component in terms of width and height.
413 * Returns: %TRUE or %FALSE whether the size was set or not
416 atk_component_set_size (AtkComponent *component,
420 AtkComponentIface *iface = NULL;
421 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
423 iface = ATK_COMPONENT_GET_IFACE (component);
426 return (iface->set_size) (component, x, y);
432 atk_component_real_contains (AtkComponent *component,
435 AtkCoordType coord_type)
437 gint real_x, real_y, width, height;
439 real_x = real_y = width = height = 0;
441 atk_component_get_extents (component, &real_x, &real_y, &width, &height, coord_type);
444 (x < real_x + width) &&
446 (y < real_y + height))
453 atk_component_real_ref_accessible_at_point (AtkComponent *component,
456 AtkCoordType coord_type)
460 count = atk_object_get_n_accessible_children (ATK_OBJECT (component));
462 for (i = 0; i < count; i++)
466 obj = atk_object_ref_accessible_child (ATK_OBJECT (component), i);
470 if (atk_component_contains (ATK_COMPONENT (obj), x, y, coord_type))
476 g_object_unref (obj);
484 atk_component_real_get_position (AtkComponent *component,
487 AtkCoordType coord_type)
491 atk_component_get_extents (component, x, y, &width, &height, coord_type);
495 atk_component_real_get_size (AtkComponent *component,
500 AtkCoordType coord_type;
503 * Pick one coordinate type; it does not matter for size
505 coord_type = ATK_XY_WINDOW;
507 atk_component_get_extents (component, &x, &y, width, height, coord_type);