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 ()
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).
73 atk_component_add_focus_handler (AtkComponent *component,
74 AtkFocusHandler handler)
76 AtkComponentIface *iface = NULL;
77 g_return_val_if_fail (ATK_IS_COMPONENT (component), 0);
79 iface = ATK_COMPONENT_GET_IFACE (component);
81 if (iface->add_focus_handler)
82 return (iface->add_focus_handler) (component, handler);
88 * atk_component_remove_focus_handler:
89 * @component: the #AtkComponent to remove the focus handler from
90 * @handler_id: the handler id of the focus handler to be removed
93 * Remove the handler specified by @handler_id from the list of
94 * functions to be executed when this object receives focus events
98 atk_component_remove_focus_handler (AtkComponent *component,
101 AtkComponentIface *iface = NULL;
102 g_return_if_fail (ATK_IS_COMPONENT (component));
104 iface = ATK_COMPONENT_GET_IFACE (component);
106 if (iface->remove_focus_handler)
107 (iface->remove_focus_handler) (component, handler_id);
111 * atk_component_contains:
112 * @component: the #AtkComponent
115 * @coord_type: specifies whether the coordinates are relative to the screen
116 * or to the components top level window
118 * Checks whether the specified point is within the extent of the @component.
120 * Returns: %TRUE or %FALSE indicating whether the specified point is within
121 * the extent of the @component or not
124 atk_component_contains (AtkComponent *component,
127 AtkCoordType coord_type)
129 AtkComponentIface *iface = NULL;
130 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
132 iface = ATK_COMPONENT_GET_IFACE (component);
135 return (iface->contains) (component, x, y, coord_type);
139 * if this method is not overridden use the default implementation.
141 return atk_component_real_contains (component, x, y, coord_type);
146 * atk_component_ref_accessible_at_point:
147 * @component: the #AtkComponent
150 * @coord_type: specifies whether the coordinates are relative to the screen
151 * or to the components top level window
153 * Gets a reference to the accessible child, if one exists, at the
154 * coordinate point specified by @x and @y.
156 * Returns: a reference to the accessible child, if one exists
159 atk_component_ref_accessible_at_point (AtkComponent *component,
162 AtkCoordType coord_type)
164 AtkComponentIface *iface = NULL;
165 g_return_val_if_fail (ATK_IS_COMPONENT (component), NULL);
167 iface = ATK_COMPONENT_GET_IFACE (component);
169 if (iface->ref_accessible_at_point)
170 return (iface->ref_accessible_at_point) (component, x, y, coord_type);
174 * if this method is not overridden use the default implementation.
176 return atk_component_real_ref_accessible_at_point (component, x, y, coord_type);
181 * atk_component_get_extents:
182 * @component: an #AtkComponent
183 * @x: address of #gint to put x coordinate
184 * @y: address of #gint to put y coordinate
185 * @width: address of #gint to put width
186 * @height: address of #gint to put height
187 * @coord_type: specifies whether the coordinates are relative to the screen
188 * or to the components top level window
190 * Gets the rectangle which gives the extent of the @component.
194 atk_component_get_extents (AtkComponent *component,
199 AtkCoordType coord_type)
201 AtkComponentIface *iface = NULL;
202 gint local_x, local_y, local_width, local_height;
203 gint *real_x, *real_y, *real_width, *real_height;
205 g_return_if_fail (ATK_IS_COMPONENT (component));
218 real_width = &local_width;
220 real_height = height;
222 real_height = &local_height;
224 iface = ATK_COMPONENT_GET_IFACE (component);
226 if (iface->get_extents)
227 (iface->get_extents) (component, real_x, real_y, real_width, real_height, coord_type);
231 * atk_component_get_position:
232 * @component: an #AtkComponent
233 * @x: address of #gint to put x coordinate position
234 * @y: address of #gint to put y coordinate position
235 * @coord_type: specifies whether the coordinates are relative to the screen
236 * or to the components top level window
238 * Gets the position of @component in the form of
239 * a point specifying @component's top-left corner.
242 atk_component_get_position (AtkComponent *component,
245 AtkCoordType coord_type)
247 AtkComponentIface *iface = NULL;
248 gint local_x, local_y;
249 gint *real_x, *real_y;
251 g_return_if_fail (ATK_IS_COMPONENT (component));
262 iface = ATK_COMPONENT_GET_IFACE (component);
264 if (iface->get_position)
265 (iface->get_position) (component, real_x, real_y, coord_type);
269 * if this method is not overridden use the default implementation.
271 atk_component_real_get_position (component, real_x, real_y, coord_type);
276 * atk_component_get_size:
277 * @component: an #AtkComponent
278 * @width: address of #gint to put width of @component
279 * @height: address of #gint to put height of @component
281 * Gets the size of the @component in terms of width and height.
284 atk_component_get_size (AtkComponent *component,
288 AtkComponentIface *iface = NULL;
289 gint local_width, local_height;
290 gint *real_width, *real_height;
292 g_return_if_fail (ATK_IS_COMPONENT (component));
297 real_width = &local_width;
299 real_height = height;
301 real_height = &local_height;
303 iface = ATK_COMPONENT_GET_IFACE (component);
304 g_return_if_fail (ATK_IS_COMPONENT (component));
306 iface = ATK_COMPONENT_GET_IFACE (component);
309 (iface->get_size) (component, real_width, real_height);
313 * if this method is not overridden use the default implementation.
315 atk_component_real_get_size (component, real_width, real_height);
320 * atk_component_grab_focus:
321 * @component: an #AtkComponent
323 * Grabs focus for this @component.
325 * Returns: %TRUE if successful, %FALSE otherwise.
328 atk_component_grab_focus (AtkComponent *component)
330 AtkComponentIface *iface = NULL;
331 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
333 iface = ATK_COMPONENT_GET_IFACE (component);
335 if (iface->grab_focus)
336 return (iface->grab_focus) (component);
342 * atk_component_set_extents:
343 * @component: an #AtkComponent
346 * @width: width to set for @component
347 * @height: height to set for @component
348 * @coord_type: specifies whether the coordinates are relative to the screen
349 * or to the components top level window
351 * Sets the extents of @component.
353 * Returns: %TRUE or %FALSE whether the extents were set or not
356 atk_component_set_extents (AtkComponent *component,
361 AtkCoordType coord_type)
363 AtkComponentIface *iface = NULL;
364 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
366 iface = ATK_COMPONENT_GET_IFACE (component);
368 if (iface->set_extents)
369 return (iface->set_extents) (component, x, y, width, height, coord_type);
375 * atk_component_set_position:
376 * @component: an #AtkComponent
379 * @coord_type: specifies whether the coordinates are relative to the screen
380 * or to the components top level window
382 * Sets the postition of @component.
384 * Returns: %TRUE or %FALSE whether or not the position was set or not
387 atk_component_set_position (AtkComponent *component,
390 AtkCoordType coord_type)
392 AtkComponentIface *iface = NULL;
393 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
395 iface = ATK_COMPONENT_GET_IFACE (component);
397 if (iface->set_position)
398 return (iface->set_position) (component, x, y, coord_type);
404 * atk_component_set_size:
405 * @component: an #AtkComponent
406 * @width: width to set for @component
407 * @height: height to set for @component
409 * Set the size of the @component in terms of width and height.
411 * Returns: %TRUE or %FALSE whether the size was set or not
414 atk_component_set_size (AtkComponent *component,
418 AtkComponentIface *iface = NULL;
419 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
421 iface = ATK_COMPONENT_GET_IFACE (component);
424 return (iface->set_size) (component, x, y);
430 atk_component_real_contains (AtkComponent *component,
433 AtkCoordType coord_type)
435 gint real_x, real_y, width, height;
437 real_x = real_y = width = height = 0;
439 atk_component_get_extents (component, &real_x, &real_y, &width, &height, coord_type);
442 (x < real_x + width) &&
444 (y < real_y + height))
451 atk_component_real_ref_accessible_at_point (AtkComponent *component,
454 AtkCoordType coord_type)
458 count = atk_object_get_n_accessible_children (ATK_OBJECT (component));
460 g_return_val_if_fail (count != 0, NULL);
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);