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 (void)
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). If the handler is
69 * already added it is not added again
71 * Returns: a handler id which can be used in atk_component_remove_focus_handler
72 * or zero if the handler was already added.
75 atk_component_add_focus_handler (AtkComponent
*component
,
76 AtkFocusHandler handler
)
78 AtkComponentIface
*iface
= NULL
;
79 g_return_val_if_fail (ATK_IS_COMPONENT (component
), 0);
81 iface
= ATK_COMPONENT_GET_IFACE (component
);
83 if (iface
->add_focus_handler
)
84 return (iface
->add_focus_handler
) (component
, handler
);
90 * atk_component_remove_focus_handler:
91 * @component: the #AtkComponent to remove the focus handler from
92 * @handler_id: the handler id of the focus handler to be removed
95 * Remove the handler specified by @handler_id from the list of
96 * functions to be executed when this object receives focus events
100 atk_component_remove_focus_handler (AtkComponent
*component
,
103 AtkComponentIface
*iface
= NULL
;
104 g_return_if_fail (ATK_IS_COMPONENT (component
));
106 iface
= ATK_COMPONENT_GET_IFACE (component
);
108 if (iface
->remove_focus_handler
)
109 (iface
->remove_focus_handler
) (component
, handler_id
);
113 * atk_component_contains:
114 * @component: the #AtkComponent
117 * @coord_type: specifies whether the coordinates are relative to the screen
118 * or to the components top level window
120 * Checks whether the specified point is within the extent of the @component.
122 * Returns: %TRUE or %FALSE indicating whether the specified point is within
123 * the extent of the @component or not
126 atk_component_contains (AtkComponent
*component
,
129 AtkCoordType coord_type
)
131 AtkComponentIface
*iface
= NULL
;
132 g_return_val_if_fail (ATK_IS_COMPONENT (component
), FALSE
);
134 iface
= ATK_COMPONENT_GET_IFACE (component
);
137 return (iface
->contains
) (component
, x
, y
, coord_type
);
141 * if this method is not overridden use the default implementation.
143 return atk_component_real_contains (component
, x
, y
, coord_type
);
148 * atk_component_ref_accessible_at_point:
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 * Gets a reference to the accessible child, if one exists, at the
156 * coordinate point specified by @x and @y.
158 * Returns: a reference to the accessible child, if one exists
161 atk_component_ref_accessible_at_point (AtkComponent
*component
,
164 AtkCoordType coord_type
)
166 AtkComponentIface
*iface
= NULL
;
167 g_return_val_if_fail (ATK_IS_COMPONENT (component
), NULL
);
169 iface
= ATK_COMPONENT_GET_IFACE (component
);
171 if (iface
->ref_accessible_at_point
)
172 return (iface
->ref_accessible_at_point
) (component
, x
, y
, coord_type
);
176 * if this method is not overridden use the default implementation.
178 return atk_component_real_ref_accessible_at_point (component
, x
, y
, coord_type
);
183 * atk_component_get_extents:
184 * @component: an #AtkComponent
185 * @x: address of #gint to put x coordinate
186 * @y: address of #gint to put y coordinate
187 * @width: address of #gint to put width
188 * @height: address of #gint to put height
189 * @coord_type: specifies whether the coordinates are relative to the screen
190 * or to the components top level window
192 * Gets the rectangle which gives the extent of the @component.
196 atk_component_get_extents (AtkComponent
*component
,
201 AtkCoordType coord_type
)
203 AtkComponentIface
*iface
= NULL
;
204 gint local_x
, local_y
, local_width
, local_height
;
205 gint
*real_x
, *real_y
, *real_width
, *real_height
;
207 g_return_if_fail (ATK_IS_COMPONENT (component
));
220 real_width
= &local_width
;
222 real_height
= height
;
224 real_height
= &local_height
;
226 iface
= ATK_COMPONENT_GET_IFACE (component
);
228 if (iface
->get_extents
)
229 (iface
->get_extents
) (component
, real_x
, real_y
, real_width
, real_height
, coord_type
);
233 * atk_component_get_position:
234 * @component: an #AtkComponent
235 * @x: address of #gint to put x coordinate position
236 * @y: address of #gint to put y coordinate position
237 * @coord_type: specifies whether the coordinates are relative to the screen
238 * or to the components top level window
240 * Gets the position of @component in the form of
241 * a point specifying @component's top-left corner.
244 atk_component_get_position (AtkComponent
*component
,
247 AtkCoordType coord_type
)
249 AtkComponentIface
*iface
= NULL
;
250 gint local_x
, local_y
;
251 gint
*real_x
, *real_y
;
253 g_return_if_fail (ATK_IS_COMPONENT (component
));
264 iface
= ATK_COMPONENT_GET_IFACE (component
);
266 if (iface
->get_position
)
267 (iface
->get_position
) (component
, real_x
, real_y
, coord_type
);
271 * if this method is not overridden use the default implementation.
273 atk_component_real_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 * if this method is not overridden use the default implementation.
316 atk_component_real_get_size (component
, real_width
, real_height
);
321 * atk_component_get_layer:
322 * @accessible: an #AtkComponent
324 * Gets the layer of the accessible.
326 * Returns: an #AtkLayer which is the layer of the accessible
329 atk_component_get_layer (AtkComponent
*accessible
)
331 AtkComponentIface
*iface
;
333 g_return_val_if_fail (ATK_IS_COMPONENT (accessible
), ATK_LAYER_INVALID
);
335 iface
= ATK_COMPONENT_GET_IFACE (accessible
);
336 if (iface
->get_layer
)
337 return (iface
->get_layer
) (accessible
);
339 return ATK_LAYER_WIDGET
;
343 * atk_component_get_mdi_zorder:
344 * @accessible: an #AtkComponent
346 * Gets the zorder of the accessible. The value G_MININT will be returned
347 * if the layer of the accessible is not ATK_LAYER_MDI.
349 * Returns: a gint which is the zorder of the accessible, i.e. the depth at
350 * which the component is shown in relation to other components in the same
354 atk_component_get_mdi_zorder (AtkComponent
*accessible
)
356 AtkComponentIface
*iface
;
358 g_return_val_if_fail (ATK_IS_COMPONENT (accessible
), G_MININT
);
360 iface
= ATK_COMPONENT_GET_IFACE (accessible
);
361 if (iface
->get_mdi_zorder
)
362 return (iface
->get_mdi_zorder
) (accessible
);
368 * atk_component_grab_focus:
369 * @component: an #AtkComponent
371 * Grabs focus for this @component.
373 * Returns: %TRUE if successful, %FALSE otherwise.
376 atk_component_grab_focus (AtkComponent
*component
)
378 AtkComponentIface
*iface
= NULL
;
379 g_return_val_if_fail (ATK_IS_COMPONENT (component
), FALSE
);
381 iface
= ATK_COMPONENT_GET_IFACE (component
);
383 if (iface
->grab_focus
)
384 return (iface
->grab_focus
) (component
);
390 * atk_component_set_extents:
391 * @component: an #AtkComponent
394 * @width: width to set for @component
395 * @height: height to set for @component
396 * @coord_type: specifies whether the coordinates are relative to the screen
397 * or to the components top level window
399 * Sets the extents of @component.
401 * Returns: %TRUE or %FALSE whether the extents were set or not
404 atk_component_set_extents (AtkComponent
*component
,
409 AtkCoordType coord_type
)
411 AtkComponentIface
*iface
= NULL
;
412 g_return_val_if_fail (ATK_IS_COMPONENT (component
), FALSE
);
414 iface
= ATK_COMPONENT_GET_IFACE (component
);
416 if (iface
->set_extents
)
417 return (iface
->set_extents
) (component
, x
, y
, width
, height
, coord_type
);
423 * atk_component_set_position:
424 * @component: an #AtkComponent
427 * @coord_type: specifies whether the coordinates are relative to the screen
428 * or to the components top level window
430 * Sets the postition of @component.
432 * Returns: %TRUE or %FALSE whether or not the position was set or not
435 atk_component_set_position (AtkComponent
*component
,
438 AtkCoordType coord_type
)
440 AtkComponentIface
*iface
= NULL
;
441 g_return_val_if_fail (ATK_IS_COMPONENT (component
), FALSE
);
443 iface
= ATK_COMPONENT_GET_IFACE (component
);
445 if (iface
->set_position
)
446 return (iface
->set_position
) (component
, x
, y
, coord_type
);
452 * atk_component_set_size:
453 * @component: an #AtkComponent
454 * @width: width to set for @component
455 * @height: height to set for @component
457 * Set the size of the @component in terms of width and height.
459 * Returns: %TRUE or %FALSE whether the size was set or not
462 atk_component_set_size (AtkComponent
*component
,
466 AtkComponentIface
*iface
= NULL
;
467 g_return_val_if_fail (ATK_IS_COMPONENT (component
), FALSE
);
469 iface
= ATK_COMPONENT_GET_IFACE (component
);
472 return (iface
->set_size
) (component
, x
, y
);
478 atk_component_real_contains (AtkComponent
*component
,
481 AtkCoordType coord_type
)
483 gint real_x
, real_y
, width
, height
;
485 real_x
= real_y
= width
= height
= 0;
487 atk_component_get_extents (component
, &real_x
, &real_y
, &width
, &height
, coord_type
);
490 (x
< real_x
+ width
) &&
492 (y
< real_y
+ height
))
499 atk_component_real_ref_accessible_at_point (AtkComponent
*component
,
502 AtkCoordType coord_type
)
506 count
= atk_object_get_n_accessible_children (ATK_OBJECT (component
));
508 for (i
= 0; i
< count
; i
++)
512 obj
= atk_object_ref_accessible_child (ATK_OBJECT (component
), i
);
516 if (atk_component_contains (ATK_COMPONENT (obj
), x
, y
, coord_type
))
522 g_object_unref (obj
);
530 atk_component_real_get_position (AtkComponent
*component
,
533 AtkCoordType coord_type
)
537 atk_component_get_extents (component
, x
, y
, &width
, &height
, coord_type
);
541 atk_component_real_get_size (AtkComponent
*component
,
546 AtkCoordType coord_type
;
549 * Pick one coordinate type; it does not matter for size
551 coord_type
= ATK_XY_WINDOW
;
553 atk_component_get_extents (component
, &x
, &y
, width
, height
, coord_type
);