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,
91 ATK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
99 * atk_component_add_focus_handler:
100 * @component: The #AtkComponent to attach the @handler to
101 * @handler: The #AtkFocusHandler to be attached to @component
103 * Add the specified handler to the set of functions to be called
104 * when this object receives focus events (in or out). If the handler is
105 * already added it is not added again
107 * Deprecated: This method is deprecated since ATK version 2.9.4. If
108 * you need to track when an object gains or lose the focus, use
109 * state-changed:focused notification instead.
111 * Returns: a handler id which can be used in atk_component_remove_focus_handler()
112 * or zero if the handler was already added.
115 atk_component_add_focus_handler (AtkComponent *component,
116 AtkFocusHandler handler)
118 AtkComponentIface *iface = NULL;
119 g_return_val_if_fail (ATK_IS_COMPONENT (component), 0);
121 iface = ATK_COMPONENT_GET_IFACE (component);
123 if (iface->add_focus_handler)
124 return (iface->add_focus_handler) (component, handler);
130 * atk_component_remove_focus_handler:
131 * @component: the #AtkComponent to remove the focus handler from
132 * @handler_id: the handler id of the focus handler to be removed
135 * Remove the handler specified by @handler_id from the list of
136 * functions to be executed when this object receives focus events
139 * Deprecated: This method is deprecated since ATK version 2.9.4. If
140 * you need to track when an object gains or lose the focus, use
141 * state-changed:focused notification instead.
145 atk_component_remove_focus_handler (AtkComponent *component,
148 AtkComponentIface *iface = NULL;
149 g_return_if_fail (ATK_IS_COMPONENT (component));
151 iface = ATK_COMPONENT_GET_IFACE (component);
153 if (iface->remove_focus_handler)
154 (iface->remove_focus_handler) (component, handler_id);
158 * atk_component_contains:
159 * @component: the #AtkComponent
162 * @coord_type: specifies whether the coordinates are relative to the screen
163 * or to the components top level window
165 * Checks whether the specified point is within the extent of the @component.
167 * Returns: %TRUE or %FALSE indicating whether the specified point is within
168 * the extent of the @component or not
171 atk_component_contains (AtkComponent *component,
174 AtkCoordType coord_type)
176 AtkComponentIface *iface = NULL;
177 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
179 iface = ATK_COMPONENT_GET_IFACE (component);
182 return (iface->contains) (component, x, y, coord_type);
188 * atk_component_ref_accessible_at_point:
189 * @component: the #AtkComponent
192 * @coord_type: specifies whether the coordinates are relative to the screen
193 * or to the components top level window
195 * Gets a reference to the accessible child, if one exists, at the
196 * coordinate point specified by @x and @y.
198 * Returns: (transfer full): a reference to the accessible child, if one exists
201 atk_component_ref_accessible_at_point (AtkComponent *component,
204 AtkCoordType coord_type)
206 AtkComponentIface *iface = NULL;
207 g_return_val_if_fail (ATK_IS_COMPONENT (component), NULL);
209 iface = ATK_COMPONENT_GET_IFACE (component);
211 if (iface->ref_accessible_at_point)
212 return (iface->ref_accessible_at_point) (component, x, y, coord_type);
218 * atk_component_get_extents:
219 * @component: an #AtkComponent
220 * @x: address of #gint to put x coordinate
221 * @y: address of #gint to put y coordinate
222 * @width: address of #gint to put width
223 * @height: address of #gint to put height
224 * @coord_type: specifies whether the coordinates are relative to the screen
225 * or to the components top level window
227 * Gets the rectangle which gives the extent of the @component.
231 atk_component_get_extents (AtkComponent *component,
236 AtkCoordType coord_type)
238 AtkComponentIface *iface = NULL;
239 gint local_x, local_y, local_width, local_height;
240 gint *real_x, *real_y, *real_width, *real_height;
242 g_return_if_fail (ATK_IS_COMPONENT (component));
255 real_width = &local_width;
257 real_height = height;
259 real_height = &local_height;
261 iface = ATK_COMPONENT_GET_IFACE (component);
263 if (iface->get_extents)
264 (iface->get_extents) (component, real_x, real_y, real_width, real_height, coord_type);
268 * atk_component_get_position:
269 * @component: an #AtkComponent
270 * @x: address of #gint to put x coordinate position
271 * @y: address of #gint to put y coordinate position
272 * @coord_type: specifies whether the coordinates are relative to the screen
273 * or to the components top level window
275 * Gets the position of @component in the form of
276 * a point specifying @component's top-left corner.
279 atk_component_get_position (AtkComponent *component,
282 AtkCoordType coord_type)
284 AtkComponentIface *iface = NULL;
285 gint local_x, local_y;
286 gint *real_x, *real_y;
288 g_return_if_fail (ATK_IS_COMPONENT (component));
299 iface = ATK_COMPONENT_GET_IFACE (component);
301 if (iface->get_position)
302 (iface->get_position) (component, real_x, real_y, coord_type);
306 * atk_component_get_size:
307 * @component: an #AtkComponent
308 * @width: address of #gint to put width of @component
309 * @height: address of #gint to put height of @component
311 * Gets the size of the @component in terms of width and height.
314 atk_component_get_size (AtkComponent *component,
318 AtkComponentIface *iface = NULL;
319 gint local_width, local_height;
320 gint *real_width, *real_height;
322 g_return_if_fail (ATK_IS_COMPONENT (component));
327 real_width = &local_width;
329 real_height = height;
331 real_height = &local_height;
333 g_return_if_fail (ATK_IS_COMPONENT (component));
335 iface = ATK_COMPONENT_GET_IFACE (component);
338 (iface->get_size) (component, real_width, real_height);
342 * atk_component_get_layer:
343 * @component: an #AtkComponent
345 * Gets the layer of the component.
347 * Returns: an #AtkLayer which is the layer of the component
350 atk_component_get_layer (AtkComponent *component)
352 AtkComponentIface *iface;
354 g_return_val_if_fail (ATK_IS_COMPONENT (component), ATK_LAYER_INVALID);
356 iface = ATK_COMPONENT_GET_IFACE (component);
357 if (iface->get_layer)
358 return (iface->get_layer) (component);
360 return ATK_LAYER_WIDGET;
364 * atk_component_get_mdi_zorder:
365 * @component: an #AtkComponent
367 * Gets the zorder of the component. The value G_MININT will be returned
368 * if the layer of the component is not ATK_LAYER_MDI or ATK_LAYER_WINDOW.
370 * Returns: a gint which is the zorder of the component, i.e. the depth at
371 * which the component is shown in relation to other components in the same
375 atk_component_get_mdi_zorder (AtkComponent *component)
377 AtkComponentIface *iface;
379 g_return_val_if_fail (ATK_IS_COMPONENT (component), G_MININT);
381 iface = ATK_COMPONENT_GET_IFACE (component);
382 if (iface->get_mdi_zorder)
383 return (iface->get_mdi_zorder) (component);
389 * atk_component_get_alpha:
390 * @component: an #AtkComponent
392 * Returns the alpha value (i.e. the opacity) for this
393 * @component, on a scale from 0 (fully transparent) to 1.0
396 * Returns: An alpha value from 0 to 1.0, inclusive.
400 atk_component_get_alpha (AtkComponent *component)
402 AtkComponentIface *iface;
404 g_return_val_if_fail (ATK_IS_COMPONENT (component), G_MININT);
406 iface = ATK_COMPONENT_GET_IFACE (component);
407 if (iface->get_alpha)
408 return (iface->get_alpha) (component);
410 return (gdouble) 1.0;
414 * atk_component_grab_focus:
415 * @component: an #AtkComponent
417 * Grabs focus for this @component.
419 * Returns: %TRUE if successful, %FALSE otherwise.
422 atk_component_grab_focus (AtkComponent *component)
424 AtkComponentIface *iface = NULL;
425 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
427 iface = ATK_COMPONENT_GET_IFACE (component);
429 if (iface->grab_focus)
430 return (iface->grab_focus) (component);
436 * atk_component_set_extents:
437 * @component: an #AtkComponent
440 * @width: width to set for @component
441 * @height: height to set for @component
442 * @coord_type: specifies whether the coordinates are relative to the screen
443 * or to the components top level window
445 * Sets the extents of @component.
447 * Returns: %TRUE or %FALSE whether the extents were set or not
450 atk_component_set_extents (AtkComponent *component,
455 AtkCoordType coord_type)
457 AtkComponentIface *iface = NULL;
458 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
460 iface = ATK_COMPONENT_GET_IFACE (component);
462 if (iface->set_extents)
463 return (iface->set_extents) (component, x, y, width, height, coord_type);
469 * atk_component_set_position:
470 * @component: an #AtkComponent
473 * @coord_type: specifies whether the coordinates are relative to the screen
474 * or to the components top level window
476 * Sets the postition of @component.
478 * Returns: %TRUE or %FALSE whether or not the position was set or not
481 atk_component_set_position (AtkComponent *component,
484 AtkCoordType coord_type)
486 AtkComponentIface *iface = NULL;
487 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
489 iface = ATK_COMPONENT_GET_IFACE (component);
491 if (iface->set_position)
492 return (iface->set_position) (component, x, y, coord_type);
498 * atk_component_set_size:
499 * @component: an #AtkComponent
500 * @width: width to set for @component
501 * @height: height to set for @component
503 * Set the size of the @component in terms of width and height.
505 * Returns: %TRUE or %FALSE whether the size was set or not
508 atk_component_set_size (AtkComponent *component,
512 AtkComponentIface *iface = NULL;
513 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
515 iface = ATK_COMPONENT_GET_IFACE (component);
518 return (iface->set_size) (component, x, y);
524 atk_component_real_contains (AtkComponent *component,
527 AtkCoordType coord_type)
529 gint real_x, real_y, width, height;
531 real_x = real_y = width = height = 0;
533 atk_component_get_extents (component, &real_x, &real_y, &width, &height, coord_type);
536 (x < real_x + width) &&
538 (y < real_y + height))
545 atk_component_real_ref_accessible_at_point (AtkComponent *component,
548 AtkCoordType coord_type)
552 count = atk_object_get_n_accessible_children (ATK_OBJECT (component));
554 for (i = 0; i < count; i++)
558 obj = atk_object_ref_accessible_child (ATK_OBJECT (component), i);
562 if (atk_component_contains (ATK_COMPONENT (obj), x, y, coord_type))
568 g_object_unref (obj);
576 atk_component_real_get_position (AtkComponent *component,
579 AtkCoordType coord_type)
583 atk_component_get_extents (component, x, y, &width, &height, coord_type);
587 atk_component_real_get_size (AtkComponent *component,
592 AtkCoordType coord_type;
595 * Pick one coordinate type; it does not matter for size
597 coord_type = ATK_XY_WINDOW;
599 atk_component_get_extents (component, &x, &y, width, height, coord_type);
602 static AtkRectangle *
603 atk_rectangle_copy (const AtkRectangle *rectangle)
605 AtkRectangle *result = g_new (AtkRectangle, 1);
606 *result = *rectangle;
612 atk_rectangle_get_type (void)
614 static GType our_type = 0;
617 our_type = g_boxed_type_register_static ("AtkRectangle",
618 (GBoxedCopyFunc)atk_rectangle_copy,
619 (GBoxedFreeFunc)g_free);