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"
28 static void atk_component_base_init (AtkComponentIface *class);
30 static gboolean atk_component_real_contains (AtkComponent *component,
33 AtkCoordType coord_type);
35 static AtkObject* atk_component_real_ref_accessible_at_point (AtkComponent *component,
38 AtkCoordType coord_type);
40 static void atk_component_real_get_position (AtkComponent *component,
43 AtkCoordType coord_type);
45 static void atk_component_real_get_size (AtkComponent *component,
49 static guint atk_component_signals[LAST_SIGNAL] = { 0 };
52 atk_component_get_type (void)
54 static GType type = 0;
57 static const GTypeInfo tinfo =
59 sizeof (AtkComponentIface),
60 (GBaseInitFunc) atk_component_base_init,
61 (GBaseFinalizeFunc) NULL,
65 type = g_type_register_static (G_TYPE_INTERFACE, "AtkComponent", &tinfo, 0);
72 atk_component_base_init (AtkComponentIface *class)
74 static gboolean initialized = FALSE;
78 class->ref_accessible_at_point = atk_component_real_ref_accessible_at_point;
79 class->contains = atk_component_real_contains;
80 class->get_position = atk_component_real_get_position;
81 class->get_size = atk_component_real_get_size;
83 atk_component_signals[BOUNDS_CHANGED] =
84 g_signal_new ("bounds_changed",
87 G_STRUCT_OFFSET (AtkComponentIface, bounds_changed),
88 (GSignalAccumulator) NULL, NULL,
89 g_cclosure_marshal_VOID__BOXED,
98 * atk_component_add_focus_handler:
99 * @component: The #AtkComponent to attach the @handler to
100 * @handler: The #AtkFocusHandler to be attached to @component
102 * Add the specified handler to the set of functions to be called
103 * when this object receives focus events (in or out). If the handler is
104 * already added it is not added again
106 * Returns: a handler id which can be used in atk_component_remove_focus_handler
107 * or zero if the handler was already added.
110 atk_component_add_focus_handler (AtkComponent *component,
111 AtkFocusHandler handler)
113 AtkComponentIface *iface = NULL;
114 g_return_val_if_fail (ATK_IS_COMPONENT (component), 0);
116 iface = ATK_COMPONENT_GET_IFACE (component);
118 if (iface->add_focus_handler)
119 return (iface->add_focus_handler) (component, handler);
125 * atk_component_remove_focus_handler:
126 * @component: the #AtkComponent to remove the focus handler from
127 * @handler_id: the handler id of the focus handler to be removed
130 * Remove the handler specified by @handler_id from the list of
131 * functions to be executed when this object receives focus events
135 atk_component_remove_focus_handler (AtkComponent *component,
138 AtkComponentIface *iface = NULL;
139 g_return_if_fail (ATK_IS_COMPONENT (component));
141 iface = ATK_COMPONENT_GET_IFACE (component);
143 if (iface->remove_focus_handler)
144 (iface->remove_focus_handler) (component, handler_id);
148 * atk_component_contains:
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 * Checks whether the specified point is within the extent of the @component.
157 * Returns: %TRUE or %FALSE indicating whether the specified point is within
158 * the extent of the @component or not
161 atk_component_contains (AtkComponent *component,
164 AtkCoordType coord_type)
166 AtkComponentIface *iface = NULL;
167 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
169 iface = ATK_COMPONENT_GET_IFACE (component);
172 return (iface->contains) (component, x, y, coord_type);
178 * atk_component_ref_accessible_at_point:
179 * @component: the #AtkComponent
182 * @coord_type: specifies whether the coordinates are relative to the screen
183 * or to the components top level window
185 * Gets a reference to the accessible child, if one exists, at the
186 * coordinate point specified by @x and @y.
188 * Returns: a reference to the accessible child, if one exists
191 atk_component_ref_accessible_at_point (AtkComponent *component,
194 AtkCoordType coord_type)
196 AtkComponentIface *iface = NULL;
197 g_return_val_if_fail (ATK_IS_COMPONENT (component), NULL);
199 iface = ATK_COMPONENT_GET_IFACE (component);
201 if (iface->ref_accessible_at_point)
202 return (iface->ref_accessible_at_point) (component, x, y, coord_type);
208 * atk_component_get_extents:
209 * @component: an #AtkComponent
210 * @x: address of #gint to put x coordinate
211 * @y: address of #gint to put y coordinate
212 * @width: address of #gint to put width
213 * @height: address of #gint to put height
214 * @coord_type: specifies whether the coordinates are relative to the screen
215 * or to the components top level window
217 * Gets the rectangle which gives the extent of the @component.
221 atk_component_get_extents (AtkComponent *component,
226 AtkCoordType coord_type)
228 AtkComponentIface *iface = NULL;
229 gint local_x, local_y, local_width, local_height;
230 gint *real_x, *real_y, *real_width, *real_height;
232 g_return_if_fail (ATK_IS_COMPONENT (component));
245 real_width = &local_width;
247 real_height = height;
249 real_height = &local_height;
251 iface = ATK_COMPONENT_GET_IFACE (component);
253 if (iface->get_extents)
254 (iface->get_extents) (component, real_x, real_y, real_width, real_height, coord_type);
258 * atk_component_get_position:
259 * @component: an #AtkComponent
260 * @x: address of #gint to put x coordinate position
261 * @y: address of #gint to put y coordinate position
262 * @coord_type: specifies whether the coordinates are relative to the screen
263 * or to the components top level window
265 * Gets the position of @component in the form of
266 * a point specifying @component's top-left corner.
269 atk_component_get_position (AtkComponent *component,
272 AtkCoordType coord_type)
274 AtkComponentIface *iface = NULL;
275 gint local_x, local_y;
276 gint *real_x, *real_y;
278 g_return_if_fail (ATK_IS_COMPONENT (component));
289 iface = ATK_COMPONENT_GET_IFACE (component);
291 if (iface->get_position)
292 (iface->get_position) (component, real_x, real_y, coord_type);
296 * atk_component_get_size:
297 * @component: an #AtkComponent
298 * @width: address of #gint to put width of @component
299 * @height: address of #gint to put height of @component
301 * Gets the size of the @component in terms of width and height.
304 atk_component_get_size (AtkComponent *component,
308 AtkComponentIface *iface = NULL;
309 gint local_width, local_height;
310 gint *real_width, *real_height;
312 g_return_if_fail (ATK_IS_COMPONENT (component));
317 real_width = &local_width;
319 real_height = height;
321 real_height = &local_height;
323 g_return_if_fail (ATK_IS_COMPONENT (component));
325 iface = ATK_COMPONENT_GET_IFACE (component);
328 (iface->get_size) (component, real_width, real_height);
332 * atk_component_get_layer:
333 * @component: an #AtkComponent
335 * Gets the layer of the component.
337 * Returns: an #AtkLayer which is the layer of the component
340 atk_component_get_layer (AtkComponent *component)
342 AtkComponentIface *iface;
344 g_return_val_if_fail (ATK_IS_COMPONENT (component), ATK_LAYER_INVALID);
346 iface = ATK_COMPONENT_GET_IFACE (component);
347 if (iface->get_layer)
348 return (iface->get_layer) (component);
350 return ATK_LAYER_WIDGET;
354 * atk_component_get_mdi_zorder:
355 * @component: an #AtkComponent
357 * Gets the zorder of the component. The value G_MININT will be returned
358 * if the layer of the component is not ATK_LAYER_MDI or ATK_LAYER_WINDOW.
360 * Returns: a gint which is the zorder of the component, i.e. the depth at
361 * which the component is shown in relation to other components in the same
365 atk_component_get_mdi_zorder (AtkComponent *component)
367 AtkComponentIface *iface;
369 g_return_val_if_fail (ATK_IS_COMPONENT (component), G_MININT);
371 iface = ATK_COMPONENT_GET_IFACE (component);
372 if (iface->get_mdi_zorder)
373 return (iface->get_mdi_zorder) (component);
379 * atk_component_grab_focus:
380 * @component: an #AtkComponent
382 * Grabs focus for this @component.
384 * Returns: %TRUE if successful, %FALSE otherwise.
387 atk_component_grab_focus (AtkComponent *component)
389 AtkComponentIface *iface = NULL;
390 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
392 iface = ATK_COMPONENT_GET_IFACE (component);
394 if (iface->grab_focus)
395 return (iface->grab_focus) (component);
401 * atk_component_set_extents:
402 * @component: an #AtkComponent
405 * @width: width to set for @component
406 * @height: height to set for @component
407 * @coord_type: specifies whether the coordinates are relative to the screen
408 * or to the components top level window
410 * Sets the extents of @component.
412 * Returns: %TRUE or %FALSE whether the extents were set or not
415 atk_component_set_extents (AtkComponent *component,
420 AtkCoordType coord_type)
422 AtkComponentIface *iface = NULL;
423 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
425 iface = ATK_COMPONENT_GET_IFACE (component);
427 if (iface->set_extents)
428 return (iface->set_extents) (component, x, y, width, height, coord_type);
434 * atk_component_set_position:
435 * @component: an #AtkComponent
438 * @coord_type: specifies whether the coordinates are relative to the screen
439 * or to the components top level window
441 * Sets the postition of @component.
443 * Returns: %TRUE or %FALSE whether or not the position was set or not
446 atk_component_set_position (AtkComponent *component,
449 AtkCoordType coord_type)
451 AtkComponentIface *iface = NULL;
452 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
454 iface = ATK_COMPONENT_GET_IFACE (component);
456 if (iface->set_position)
457 return (iface->set_position) (component, x, y, coord_type);
463 * atk_component_set_size:
464 * @component: an #AtkComponent
465 * @width: width to set for @component
466 * @height: height to set for @component
468 * Set the size of the @component in terms of width and height.
470 * Returns: %TRUE or %FALSE whether the size was set or not
473 atk_component_set_size (AtkComponent *component,
477 AtkComponentIface *iface = NULL;
478 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
480 iface = ATK_COMPONENT_GET_IFACE (component);
483 return (iface->set_size) (component, x, y);
489 atk_component_real_contains (AtkComponent *component,
492 AtkCoordType coord_type)
494 gint real_x, real_y, width, height;
496 real_x = real_y = width = height = 0;
498 atk_component_get_extents (component, &real_x, &real_y, &width, &height, coord_type);
501 (x < real_x + width) &&
503 (y < real_y + height))
510 atk_component_real_ref_accessible_at_point (AtkComponent *component,
513 AtkCoordType coord_type)
517 count = atk_object_get_n_accessible_children (ATK_OBJECT (component));
519 for (i = 0; i < count; i++)
523 obj = atk_object_ref_accessible_child (ATK_OBJECT (component), i);
527 if (atk_component_contains (ATK_COMPONENT (obj), x, y, coord_type))
533 g_object_unref (obj);
541 atk_component_real_get_position (AtkComponent *component,
544 AtkCoordType coord_type)
548 atk_component_get_extents (component, x, y, &width, &height, coord_type);
552 atk_component_real_get_size (AtkComponent *component,
557 AtkCoordType coord_type;
560 * Pick one coordinate type; it does not matter for size
562 coord_type = ATK_XY_WINDOW;
564 atk_component_get_extents (component, &x, &y, width, height, coord_type);