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 void atk_component_base_init (AtkComponentIface *class);
25 static gboolean atk_component_real_contains (AtkComponent *component,
28 AtkCoordType coord_type);
30 static AtkObject* atk_component_real_ref_accessible_at_point (AtkComponent *component,
33 AtkCoordType coord_type);
35 static void atk_component_real_get_position (AtkComponent *component,
38 AtkCoordType coord_type);
40 static void atk_component_real_get_size (AtkComponent *component,
45 atk_component_get_type (void)
47 static GType type = 0;
50 static const GTypeInfo tinfo =
52 sizeof (AtkComponentIface),
53 (GBaseInitFunc) atk_component_base_init,
54 (GBaseFinalizeFunc) NULL,
58 type = g_type_register_static (G_TYPE_INTERFACE, "AtkComponent", &tinfo, 0);
65 atk_component_base_init (AtkComponentIface *class)
67 static gboolean initialized = FALSE;
71 class->ref_accessible_at_point = atk_component_real_ref_accessible_at_point;
72 class->contains = atk_component_real_contains;
73 class->get_position = atk_component_real_get_position;
74 class->get_size = atk_component_real_get_size;
80 * atk_component_add_focus_handler:
81 * @component: The #AtkComponent to attach the @handler to
82 * @handler: The #AtkFocusHandler to be attached to @component
84 * Add the specified handler to the set of functions to be called
85 * when this object receives focus events (in or out). If the handler is
86 * already added it is not added again
88 * Returns: a handler id which can be used in atk_component_remove_focus_handler
89 * or zero if the handler was already added.
92 atk_component_add_focus_handler (AtkComponent *component,
93 AtkFocusHandler handler)
95 AtkComponentIface *iface = NULL;
96 g_return_val_if_fail (ATK_IS_COMPONENT (component), 0);
98 iface = ATK_COMPONENT_GET_IFACE (component);
100 if (iface->add_focus_handler)
101 return (iface->add_focus_handler) (component, handler);
107 * atk_component_remove_focus_handler:
108 * @component: the #AtkComponent to remove the focus handler from
109 * @handler_id: the handler id of the focus handler to be removed
112 * Remove the handler specified by @handler_id from the list of
113 * functions to be executed when this object receives focus events
117 atk_component_remove_focus_handler (AtkComponent *component,
120 AtkComponentIface *iface = NULL;
121 g_return_if_fail (ATK_IS_COMPONENT (component));
123 iface = ATK_COMPONENT_GET_IFACE (component);
125 if (iface->remove_focus_handler)
126 (iface->remove_focus_handler) (component, handler_id);
130 * atk_component_contains:
131 * @component: the #AtkComponent
134 * @coord_type: specifies whether the coordinates are relative to the screen
135 * or to the components top level window
137 * Checks whether the specified point is within the extent of the @component.
139 * Returns: %TRUE or %FALSE indicating whether the specified point is within
140 * the extent of the @component or not
143 atk_component_contains (AtkComponent *component,
146 AtkCoordType coord_type)
148 AtkComponentIface *iface = NULL;
149 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
151 iface = ATK_COMPONENT_GET_IFACE (component);
154 return (iface->contains) (component, x, y, coord_type);
160 * atk_component_ref_accessible_at_point:
161 * @component: the #AtkComponent
164 * @coord_type: specifies whether the coordinates are relative to the screen
165 * or to the components top level window
167 * Gets a reference to the accessible child, if one exists, at the
168 * coordinate point specified by @x and @y.
170 * Returns: a reference to the accessible child, if one exists
173 atk_component_ref_accessible_at_point (AtkComponent *component,
176 AtkCoordType coord_type)
178 AtkComponentIface *iface = NULL;
179 g_return_val_if_fail (ATK_IS_COMPONENT (component), NULL);
181 iface = ATK_COMPONENT_GET_IFACE (component);
183 if (iface->ref_accessible_at_point)
184 return (iface->ref_accessible_at_point) (component, x, y, coord_type);
190 * atk_component_get_extents:
191 * @component: an #AtkComponent
192 * @x: address of #gint to put x coordinate
193 * @y: address of #gint to put y coordinate
194 * @width: address of #gint to put width
195 * @height: address of #gint to put height
196 * @coord_type: specifies whether the coordinates are relative to the screen
197 * or to the components top level window
199 * Gets the rectangle which gives the extent of the @component.
203 atk_component_get_extents (AtkComponent *component,
208 AtkCoordType coord_type)
210 AtkComponentIface *iface = NULL;
211 gint local_x, local_y, local_width, local_height;
212 gint *real_x, *real_y, *real_width, *real_height;
214 g_return_if_fail (ATK_IS_COMPONENT (component));
227 real_width = &local_width;
229 real_height = height;
231 real_height = &local_height;
233 iface = ATK_COMPONENT_GET_IFACE (component);
235 if (iface->get_extents)
236 (iface->get_extents) (component, real_x, real_y, real_width, real_height, coord_type);
240 * atk_component_get_position:
241 * @component: an #AtkComponent
242 * @x: address of #gint to put x coordinate position
243 * @y: address of #gint to put y coordinate position
244 * @coord_type: specifies whether the coordinates are relative to the screen
245 * or to the components top level window
247 * Gets the position of @component in the form of
248 * a point specifying @component's top-left corner.
251 atk_component_get_position (AtkComponent *component,
254 AtkCoordType coord_type)
256 AtkComponentIface *iface = NULL;
257 gint local_x, local_y;
258 gint *real_x, *real_y;
260 g_return_if_fail (ATK_IS_COMPONENT (component));
271 iface = ATK_COMPONENT_GET_IFACE (component);
273 if (iface->get_position)
274 (iface->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 g_return_if_fail (ATK_IS_COMPONENT (component));
307 iface = ATK_COMPONENT_GET_IFACE (component);
310 (iface->get_size) (component, real_width, real_height);
314 * atk_component_get_layer:
315 * @component: an #AtkComponent
317 * Gets the layer of the component.
319 * Returns: an #AtkLayer which is the layer of the component
322 atk_component_get_layer (AtkComponent *component)
324 AtkComponentIface *iface;
326 g_return_val_if_fail (ATK_IS_COMPONENT (component), ATK_LAYER_INVALID);
328 iface = ATK_COMPONENT_GET_IFACE (component);
329 if (iface->get_layer)
330 return (iface->get_layer) (component);
332 return ATK_LAYER_WIDGET;
336 * atk_component_get_mdi_zorder:
337 * @component: an #AtkComponent
339 * Gets the zorder of the component. The value G_MININT will be returned
340 * if the layer of the component is not ATK_LAYER_MDI or ATK_LAYER_WINDOW.
342 * Returns: a gint which is the zorder of the component, i.e. the depth at
343 * which the component is shown in relation to other components in the same
347 atk_component_get_mdi_zorder (AtkComponent *component)
349 AtkComponentIface *iface;
351 g_return_val_if_fail (ATK_IS_COMPONENT (component), G_MININT);
353 iface = ATK_COMPONENT_GET_IFACE (component);
354 if (iface->get_mdi_zorder)
355 return (iface->get_mdi_zorder) (component);
361 * atk_component_grab_focus:
362 * @component: an #AtkComponent
364 * Grabs focus for this @component.
366 * Returns: %TRUE if successful, %FALSE otherwise.
369 atk_component_grab_focus (AtkComponent *component)
371 AtkComponentIface *iface = NULL;
372 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
374 iface = ATK_COMPONENT_GET_IFACE (component);
376 if (iface->grab_focus)
377 return (iface->grab_focus) (component);
383 * atk_component_set_extents:
384 * @component: an #AtkComponent
387 * @width: width to set for @component
388 * @height: height to set for @component
389 * @coord_type: specifies whether the coordinates are relative to the screen
390 * or to the components top level window
392 * Sets the extents of @component.
394 * Returns: %TRUE or %FALSE whether the extents were set or not
397 atk_component_set_extents (AtkComponent *component,
402 AtkCoordType coord_type)
404 AtkComponentIface *iface = NULL;
405 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
407 iface = ATK_COMPONENT_GET_IFACE (component);
409 if (iface->set_extents)
410 return (iface->set_extents) (component, x, y, width, height, coord_type);
416 * atk_component_set_position:
417 * @component: an #AtkComponent
420 * @coord_type: specifies whether the coordinates are relative to the screen
421 * or to the components top level window
423 * Sets the postition of @component.
425 * Returns: %TRUE or %FALSE whether or not the position was set or not
428 atk_component_set_position (AtkComponent *component,
431 AtkCoordType coord_type)
433 AtkComponentIface *iface = NULL;
434 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
436 iface = ATK_COMPONENT_GET_IFACE (component);
438 if (iface->set_position)
439 return (iface->set_position) (component, x, y, coord_type);
445 * atk_component_set_size:
446 * @component: an #AtkComponent
447 * @width: width to set for @component
448 * @height: height to set for @component
450 * Set the size of the @component in terms of width and height.
452 * Returns: %TRUE or %FALSE whether the size was set or not
455 atk_component_set_size (AtkComponent *component,
459 AtkComponentIface *iface = NULL;
460 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
462 iface = ATK_COMPONENT_GET_IFACE (component);
465 return (iface->set_size) (component, x, y);
471 atk_component_real_contains (AtkComponent *component,
474 AtkCoordType coord_type)
476 gint real_x, real_y, width, height;
478 real_x = real_y = width = height = 0;
480 atk_component_get_extents (component, &real_x, &real_y, &width, &height, coord_type);
483 (x < real_x + width) &&
485 (y < real_y + height))
492 atk_component_real_ref_accessible_at_point (AtkComponent *component,
495 AtkCoordType coord_type)
499 count = atk_object_get_n_accessible_children (ATK_OBJECT (component));
501 for (i = 0; i < count; i++)
505 obj = atk_object_ref_accessible_child (ATK_OBJECT (component), i);
509 if (atk_component_contains (ATK_COMPONENT (obj), x, y, coord_type))
515 g_object_unref (obj);
523 atk_component_real_get_position (AtkComponent *component,
526 AtkCoordType coord_type)
530 atk_component_get_extents (component, x, y, &width, &height, coord_type);
534 atk_component_real_get_size (AtkComponent *component,
539 AtkCoordType coord_type;
542 * Pick one coordinate type; it does not matter for size
544 coord_type = ATK_XY_WINDOW;
546 atk_component_get_extents (component, &x, &y, width, height, coord_type);