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, see <http://www.gnu.org/licenses/>.
19 #include "atkcomponent.h"
22 * SECTION:atkcomponent
23 * @Short_description: The ATK interface provided by UI components
24 * which occupy a physical area on the screen.
25 * which the user can activate/interact with.
28 * #AtkComponent should be implemented by most if not all UI elements
29 * with an actual on-screen presence, i.e. components which can be
30 * said to have a screen-coordinate bounding box. Virtually all
31 * widgets will need to have #AtkComponent implementations provided
32 * for their corresponding #AtkObject class. In short, only UI
33 * elements which are *not* GUI elements will omit this ATK interface.
35 * A possible exception might be textual information with a
36 * transparent background, in which case text glyph bounding box
37 * information is provided by #AtkText.
45 static void atk_component_base_init (AtkComponentIface *class);
47 static gboolean atk_component_real_contains (AtkComponent *component,
50 AtkCoordType coord_type);
52 static AtkObject* atk_component_real_ref_accessible_at_point (AtkComponent *component,
55 AtkCoordType coord_type);
57 static void atk_component_real_get_position (AtkComponent *component,
60 AtkCoordType coord_type);
62 static void atk_component_real_get_size (AtkComponent *component,
66 static guint atk_component_signals[LAST_SIGNAL] = { 0 };
69 atk_component_get_type (void)
71 static GType type = 0;
74 static const GTypeInfo tinfo =
76 sizeof (AtkComponentIface),
77 (GBaseInitFunc) atk_component_base_init,
78 (GBaseFinalizeFunc) NULL,
82 type = g_type_register_static (G_TYPE_INTERFACE, "AtkComponent", &tinfo, 0);
89 atk_component_base_init (AtkComponentIface *class)
91 static gboolean initialized = FALSE;
95 class->ref_accessible_at_point = atk_component_real_ref_accessible_at_point;
96 class->contains = atk_component_real_contains;
97 class->get_position = atk_component_real_get_position;
98 class->get_size = atk_component_real_get_size;
102 * AtkComponent::bounds-changed:
103 * @atkcomponent: the object which received the signal.
104 * @arg1: The AtkRectangle giving the new position and size.
106 * The 'bounds-changed" signal is emitted when the bposition or
107 * size of the component changes.
109 atk_component_signals[BOUNDS_CHANGED] =
110 g_signal_new ("bounds_changed",
113 G_STRUCT_OFFSET (AtkComponentIface, bounds_changed),
114 (GSignalAccumulator) NULL, NULL,
115 g_cclosure_marshal_VOID__BOXED,
117 ATK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
125 * atk_component_add_focus_handler:
126 * @component: The #AtkComponent to attach the @handler to
127 * @handler: The #AtkFocusHandler to be attached to @component
129 * Add the specified handler to the set of functions to be called
130 * when this object receives focus events (in or out). If the handler is
131 * already added it is not added again
133 * Deprecated: This method is deprecated since ATK version 2.9.4. If
134 * you need to track when an object gains or lose the focus, use
135 * state-changed:focused notification instead.
137 * Returns: a handler id which can be used in atk_component_remove_focus_handler()
138 * or zero if the handler was already added.
141 atk_component_add_focus_handler (AtkComponent *component,
142 AtkFocusHandler handler)
144 AtkComponentIface *iface = NULL;
145 g_return_val_if_fail (ATK_IS_COMPONENT (component), 0);
147 iface = ATK_COMPONENT_GET_IFACE (component);
149 if (iface->add_focus_handler)
150 return (iface->add_focus_handler) (component, handler);
156 * atk_component_remove_focus_handler:
157 * @component: the #AtkComponent to remove the focus handler from
158 * @handler_id: the handler id of the focus handler to be removed
161 * Remove the handler specified by @handler_id from the list of
162 * functions to be executed when this object receives focus events
165 * Deprecated: This method is deprecated since ATK version 2.9.4. If
166 * you need to track when an object gains or lose the focus, use
167 * state-changed:focused notification instead.
171 atk_component_remove_focus_handler (AtkComponent *component,
174 AtkComponentIface *iface = NULL;
175 g_return_if_fail (ATK_IS_COMPONENT (component));
177 iface = ATK_COMPONENT_GET_IFACE (component);
179 if (iface->remove_focus_handler)
180 (iface->remove_focus_handler) (component, handler_id);
184 * atk_component_contains:
185 * @component: the #AtkComponent
188 * @coord_type: specifies whether the coordinates are relative to the screen
189 * or to the components top level window
191 * Checks whether the specified point is within the extent of the @component.
193 * Returns: %TRUE or %FALSE indicating whether the specified point is within
194 * the extent of the @component or not
197 atk_component_contains (AtkComponent *component,
200 AtkCoordType coord_type)
202 AtkComponentIface *iface = NULL;
203 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
205 iface = ATK_COMPONENT_GET_IFACE (component);
208 return (iface->contains) (component, x, y, coord_type);
214 * atk_component_ref_accessible_at_point:
215 * @component: the #AtkComponent
218 * @coord_type: specifies whether the coordinates are relative to the screen
219 * or to the components top level window
221 * Gets a reference to the accessible child, if one exists, at the
222 * coordinate point specified by @x and @y.
224 * Returns: (transfer full): a reference to the accessible child, if one exists
227 atk_component_ref_accessible_at_point (AtkComponent *component,
230 AtkCoordType coord_type)
232 AtkComponentIface *iface = NULL;
233 g_return_val_if_fail (ATK_IS_COMPONENT (component), NULL);
235 iface = ATK_COMPONENT_GET_IFACE (component);
237 if (iface->ref_accessible_at_point)
238 return (iface->ref_accessible_at_point) (component, x, y, coord_type);
244 * atk_component_get_extents:
245 * @component: an #AtkComponent
246 * @x: address of #gint to put x coordinate
247 * @y: address of #gint to put y coordinate
248 * @width: address of #gint to put width
249 * @height: address of #gint to put height
250 * @coord_type: specifies whether the coordinates are relative to the screen
251 * or to the components top level window
253 * Gets the rectangle which gives the extent of the @component.
257 atk_component_get_extents (AtkComponent *component,
262 AtkCoordType coord_type)
264 AtkComponentIface *iface = NULL;
265 gint local_x, local_y, local_width, local_height;
266 gint *real_x, *real_y, *real_width, *real_height;
268 g_return_if_fail (ATK_IS_COMPONENT (component));
281 real_width = &local_width;
283 real_height = height;
285 real_height = &local_height;
287 iface = ATK_COMPONENT_GET_IFACE (component);
289 if (iface->get_extents)
290 (iface->get_extents) (component, real_x, real_y, real_width, real_height, coord_type);
294 * atk_component_get_position:
295 * @component: an #AtkComponent
296 * @x: address of #gint to put x coordinate position
297 * @y: address of #gint to put y coordinate position
298 * @coord_type: specifies whether the coordinates are relative to the screen
299 * or to the components top level window
301 * Gets the position of @component in the form of
302 * a point specifying @component's top-left corner.
305 atk_component_get_position (AtkComponent *component,
308 AtkCoordType coord_type)
310 AtkComponentIface *iface = NULL;
311 gint local_x, local_y;
312 gint *real_x, *real_y;
314 g_return_if_fail (ATK_IS_COMPONENT (component));
325 iface = ATK_COMPONENT_GET_IFACE (component);
327 if (iface->get_position)
328 (iface->get_position) (component, real_x, real_y, coord_type);
332 * atk_component_get_size:
333 * @component: an #AtkComponent
334 * @width: address of #gint to put width of @component
335 * @height: address of #gint to put height of @component
337 * Gets the size of the @component in terms of width and height.
340 atk_component_get_size (AtkComponent *component,
344 AtkComponentIface *iface = NULL;
345 gint local_width, local_height;
346 gint *real_width, *real_height;
348 g_return_if_fail (ATK_IS_COMPONENT (component));
353 real_width = &local_width;
355 real_height = height;
357 real_height = &local_height;
359 g_return_if_fail (ATK_IS_COMPONENT (component));
361 iface = ATK_COMPONENT_GET_IFACE (component);
364 (iface->get_size) (component, real_width, real_height);
368 * atk_component_get_layer:
369 * @component: an #AtkComponent
371 * Gets the layer of the component.
373 * Returns: an #AtkLayer which is the layer of the component
376 atk_component_get_layer (AtkComponent *component)
378 AtkComponentIface *iface;
380 g_return_val_if_fail (ATK_IS_COMPONENT (component), ATK_LAYER_INVALID);
382 iface = ATK_COMPONENT_GET_IFACE (component);
383 if (iface->get_layer)
384 return (iface->get_layer) (component);
386 return ATK_LAYER_WIDGET;
390 * atk_component_get_mdi_zorder:
391 * @component: an #AtkComponent
393 * Gets the zorder of the component. The value G_MININT will be returned
394 * if the layer of the component is not ATK_LAYER_MDI or ATK_LAYER_WINDOW.
396 * Returns: a gint which is the zorder of the component, i.e. the depth at
397 * which the component is shown in relation to other components in the same
401 atk_component_get_mdi_zorder (AtkComponent *component)
403 AtkComponentIface *iface;
405 g_return_val_if_fail (ATK_IS_COMPONENT (component), G_MININT);
407 iface = ATK_COMPONENT_GET_IFACE (component);
408 if (iface->get_mdi_zorder)
409 return (iface->get_mdi_zorder) (component);
415 * atk_component_get_alpha:
416 * @component: an #AtkComponent
418 * Returns the alpha value (i.e. the opacity) for this
419 * @component, on a scale from 0 (fully transparent) to 1.0
422 * Returns: An alpha value from 0 to 1.0, inclusive.
426 atk_component_get_alpha (AtkComponent *component)
428 AtkComponentIface *iface;
430 g_return_val_if_fail (ATK_IS_COMPONENT (component), G_MININT);
432 iface = ATK_COMPONENT_GET_IFACE (component);
433 if (iface->get_alpha)
434 return (iface->get_alpha) (component);
436 return (gdouble) 1.0;
440 * atk_component_grab_focus:
441 * @component: an #AtkComponent
443 * Grabs focus for this @component.
445 * Returns: %TRUE if successful, %FALSE otherwise.
448 atk_component_grab_focus (AtkComponent *component)
450 AtkComponentIface *iface = NULL;
451 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
453 iface = ATK_COMPONENT_GET_IFACE (component);
455 if (iface->grab_focus)
456 return (iface->grab_focus) (component);
462 * atk_component_set_extents:
463 * @component: an #AtkComponent
466 * @width: width to set for @component
467 * @height: height to set for @component
468 * @coord_type: specifies whether the coordinates are relative to the screen
469 * or to the components top level window
471 * Sets the extents of @component.
473 * Returns: %TRUE or %FALSE whether the extents were set or not
476 atk_component_set_extents (AtkComponent *component,
481 AtkCoordType coord_type)
483 AtkComponentIface *iface = NULL;
484 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
486 iface = ATK_COMPONENT_GET_IFACE (component);
488 if (iface->set_extents)
489 return (iface->set_extents) (component, x, y, width, height, coord_type);
495 * atk_component_set_position:
496 * @component: an #AtkComponent
499 * @coord_type: specifies whether the coordinates are relative to the screen
500 * or to the components top level window
502 * Sets the postition of @component.
504 * Returns: %TRUE or %FALSE whether or not the position was set or not
507 atk_component_set_position (AtkComponent *component,
510 AtkCoordType coord_type)
512 AtkComponentIface *iface = NULL;
513 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
515 iface = ATK_COMPONENT_GET_IFACE (component);
517 if (iface->set_position)
518 return (iface->set_position) (component, x, y, coord_type);
524 * atk_component_set_size:
525 * @component: an #AtkComponent
526 * @width: width to set for @component
527 * @height: height to set for @component
529 * Set the size of the @component in terms of width and height.
531 * Returns: %TRUE or %FALSE whether the size was set or not
534 atk_component_set_size (AtkComponent *component,
538 AtkComponentIface *iface = NULL;
539 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
541 iface = ATK_COMPONENT_GET_IFACE (component);
544 return (iface->set_size) (component, x, y);
550 atk_component_real_contains (AtkComponent *component,
553 AtkCoordType coord_type)
555 gint real_x, real_y, width, height;
557 real_x = real_y = width = height = 0;
559 atk_component_get_extents (component, &real_x, &real_y, &width, &height, coord_type);
562 (x < real_x + width) &&
564 (y < real_y + height))
571 atk_component_real_ref_accessible_at_point (AtkComponent *component,
574 AtkCoordType coord_type)
578 count = atk_object_get_n_accessible_children (ATK_OBJECT (component));
580 for (i = 0; i < count; i++)
584 obj = atk_object_ref_accessible_child (ATK_OBJECT (component), i);
588 if (atk_component_contains (ATK_COMPONENT (obj), x, y, coord_type))
594 g_object_unref (obj);
602 atk_component_real_get_position (AtkComponent *component,
605 AtkCoordType coord_type)
609 atk_component_get_extents (component, x, y, &width, &height, coord_type);
613 atk_component_real_get_size (AtkComponent *component,
618 AtkCoordType coord_type;
621 * Pick one coordinate type; it does not matter for size
623 coord_type = ATK_XY_WINDOW;
625 atk_component_get_extents (component, &x, &y, width, height, coord_type);
628 static AtkRectangle *
629 atk_rectangle_copy (const AtkRectangle *rectangle)
631 AtkRectangle *result = g_new (AtkRectangle, 1);
632 *result = *rectangle;
638 atk_rectangle_get_type (void)
640 static GType our_type = 0;
643 our_type = g_boxed_type_register_static ("AtkRectangle",
644 (GBoxedCopyFunc)atk_rectangle_copy,
645 (GBoxedFreeFunc)g_free);