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 g_return_if_fail (ATK_IS_COMPONENT (component));
204 iface = ATK_COMPONENT_GET_IFACE (component);
206 if (iface->get_extents)
207 (iface->get_extents) (component, x, y, width, height, coord_type);
211 * atk_component_get_position:
212 * @component: an #AtkComponent
213 * @x: address of #gint to put x coordinate position
214 * @y: address of #gint to put y coordinate position
215 * @coord_type: specifies whether the coordinates are relative to the screen
216 * or to the components top level window
218 * Gets the position of @component in the form of
219 * a point specifying @component's top-left corner.
222 atk_component_get_position (AtkComponent *component,
225 AtkCoordType coord_type)
227 AtkComponentIface *iface = NULL;
228 g_return_if_fail (ATK_IS_COMPONENT (component));
230 iface = ATK_COMPONENT_GET_IFACE (component);
232 if (iface->get_position)
233 (iface->get_position) (component, x, y, coord_type);
237 * if this method is not overridden use the default implementation.
239 atk_component_real_get_position (component, x, y, coord_type);
244 * atk_component_get_size:
245 * @component: an #AtkComponent
246 * @width: address of #gint to put width of @component
247 * @height: address of #gint to put height of @component
249 * Gets the size of the @component in terms of width and height.
252 atk_component_get_size (AtkComponent *component,
256 AtkComponentIface *iface = NULL;
257 g_return_if_fail (ATK_IS_COMPONENT (component));
259 iface = ATK_COMPONENT_GET_IFACE (component);
262 (iface->get_size) (component, width, height);
266 * if this method is not overridden use the default implementation.
268 atk_component_real_get_size (component, width, height);
273 * atk_component_grab_focus:
274 * @component: an #AtkComponent
276 * Grabs focus for this @component.
278 * Returns: %TRUE if successful, %FALSE otherwise.
281 atk_component_grab_focus (AtkComponent *component)
283 AtkComponentIface *iface = NULL;
284 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
286 iface = ATK_COMPONENT_GET_IFACE (component);
288 if (iface->grab_focus)
289 return (iface->grab_focus) (component);
295 * atk_component_set_extents:
296 * @component: an #AtkComponent
299 * @width: width to set for @component
300 * @height: height to set for @component
301 * @coord_type: specifies whether the coordinates are relative to the screen
302 * or to the components top level window
304 * Sets the extents of @component.
306 * Returns: %TRUE or %FALSE whether the extents were set or not
309 atk_component_set_extents (AtkComponent *component,
314 AtkCoordType coord_type)
316 AtkComponentIface *iface = NULL;
317 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
319 iface = ATK_COMPONENT_GET_IFACE (component);
321 if (iface->set_extents)
322 return (iface->set_extents) (component, x, y, width, height, coord_type);
328 * atk_component_set_position:
329 * @component: an #AtkComponent
332 * @coord_type: specifies whether the coordinates are relative to the screen
333 * or to the components top level window
335 * Sets the postition of @component.
337 * Returns: %TRUE or %FALSE whether or not the position was set or not
340 atk_component_set_position (AtkComponent *component,
343 AtkCoordType coord_type)
345 AtkComponentIface *iface = NULL;
346 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
348 iface = ATK_COMPONENT_GET_IFACE (component);
350 if (iface->set_position)
351 return (iface->set_position) (component, x, y, coord_type);
357 * atk_component_set_size:
358 * @component: an #AtkComponent
359 * @width: width to set for @component
360 * @height: height to set for @component
362 * Set the size of the @component in terms of width and height.
364 * Returns: %TRUE or %FALSE whether the size was set or not
367 atk_component_set_size (AtkComponent *component,
371 AtkComponentIface *iface = NULL;
372 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
374 iface = ATK_COMPONENT_GET_IFACE (component);
377 return (iface->set_size) (component, x, y);
383 atk_component_real_contains (AtkComponent *component,
386 AtkCoordType coord_type)
388 gint real_x, real_y, width, height;
390 real_x = real_y = width = height = 0;
392 atk_component_get_extents (component, &real_x, &real_y, &width, &height, coord_type);
395 (x < real_x + width) &&
397 (y < real_y + height))
404 atk_component_real_ref_accessible_at_point (AtkComponent *component,
407 AtkCoordType coord_type)
411 count = atk_object_get_n_accessible_children (ATK_OBJECT (component));
413 g_return_val_if_fail (count != 0, NULL);
415 for (i = 0; i < count; i++)
419 obj = atk_object_ref_accessible_child (ATK_OBJECT (component), i);
423 if (atk_component_contains (ATK_COMPONENT (obj), x, y, coord_type))
429 g_object_unref (obj);
437 atk_component_real_get_position (AtkComponent *component,
440 AtkCoordType coord_type)
444 atk_component_get_extents (component, x, y, &width, &height, coord_type);
448 atk_component_real_get_size (AtkComponent *component,
453 AtkCoordType coord_type;
456 * Pick one coordinate type; it does not matter for size
458 coord_type = ATK_XY_WINDOW;
460 atk_component_get_extents (component, &x, &y, width, height, coord_type);