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 * Returns: a handler id which can be used in atk_component_remove_focus_handler
108 * or zero if the handler was already added.
111 atk_component_add_focus_handler (AtkComponent
*component
,
112 AtkFocusHandler handler
)
114 AtkComponentIface
*iface
= NULL
;
115 g_return_val_if_fail (ATK_IS_COMPONENT (component
), 0);
117 iface
= ATK_COMPONENT_GET_IFACE (component
);
119 if (iface
->add_focus_handler
)
120 return (iface
->add_focus_handler
) (component
, handler
);
126 * atk_component_remove_focus_handler:
127 * @component: the #AtkComponent to remove the focus handler from
128 * @handler_id: the handler id of the focus handler to be removed
131 * Remove the handler specified by @handler_id from the list of
132 * functions to be executed when this object receives focus events
136 atk_component_remove_focus_handler (AtkComponent
*component
,
139 AtkComponentIface
*iface
= NULL
;
140 g_return_if_fail (ATK_IS_COMPONENT (component
));
142 iface
= ATK_COMPONENT_GET_IFACE (component
);
144 if (iface
->remove_focus_handler
)
145 (iface
->remove_focus_handler
) (component
, handler_id
);
149 * atk_component_contains:
150 * @component: the #AtkComponent
153 * @coord_type: specifies whether the coordinates are relative to the screen
154 * or to the components top level window
156 * Checks whether the specified point is within the extent of the @component.
158 * Returns: %TRUE or %FALSE indicating whether the specified point is within
159 * the extent of the @component or not
162 atk_component_contains (AtkComponent
*component
,
165 AtkCoordType coord_type
)
167 AtkComponentIface
*iface
= NULL
;
168 g_return_val_if_fail (ATK_IS_COMPONENT (component
), FALSE
);
170 iface
= ATK_COMPONENT_GET_IFACE (component
);
173 return (iface
->contains
) (component
, x
, y
, coord_type
);
179 * atk_component_ref_accessible_at_point:
180 * @component: the #AtkComponent
183 * @coord_type: specifies whether the coordinates are relative to the screen
184 * or to the components top level window
186 * Gets a reference to the accessible child, if one exists, at the
187 * coordinate point specified by @x and @y.
189 * Returns: a reference to the accessible child, if one exists
192 atk_component_ref_accessible_at_point (AtkComponent
*component
,
195 AtkCoordType coord_type
)
197 AtkComponentIface
*iface
= NULL
;
198 g_return_val_if_fail (ATK_IS_COMPONENT (component
), NULL
);
200 iface
= ATK_COMPONENT_GET_IFACE (component
);
202 if (iface
->ref_accessible_at_point
)
203 return (iface
->ref_accessible_at_point
) (component
, x
, y
, coord_type
);
209 * atk_component_get_extents:
210 * @component: an #AtkComponent
211 * @x: address of #gint to put x coordinate
212 * @y: address of #gint to put y coordinate
213 * @width: address of #gint to put width
214 * @height: address of #gint to put height
215 * @coord_type: specifies whether the coordinates are relative to the screen
216 * or to the components top level window
218 * Gets the rectangle which gives the extent of the @component.
222 atk_component_get_extents (AtkComponent
*component
,
227 AtkCoordType coord_type
)
229 AtkComponentIface
*iface
= NULL
;
230 gint local_x
, local_y
, local_width
, local_height
;
231 gint
*real_x
, *real_y
, *real_width
, *real_height
;
233 g_return_if_fail (ATK_IS_COMPONENT (component
));
246 real_width
= &local_width
;
248 real_height
= height
;
250 real_height
= &local_height
;
252 iface
= ATK_COMPONENT_GET_IFACE (component
);
254 if (iface
->get_extents
)
255 (iface
->get_extents
) (component
, real_x
, real_y
, real_width
, real_height
, coord_type
);
259 * atk_component_get_position:
260 * @component: an #AtkComponent
261 * @x: address of #gint to put x coordinate position
262 * @y: address of #gint to put y coordinate position
263 * @coord_type: specifies whether the coordinates are relative to the screen
264 * or to the components top level window
266 * Gets the position of @component in the form of
267 * a point specifying @component's top-left corner.
270 atk_component_get_position (AtkComponent
*component
,
273 AtkCoordType coord_type
)
275 AtkComponentIface
*iface
= NULL
;
276 gint local_x
, local_y
;
277 gint
*real_x
, *real_y
;
279 g_return_if_fail (ATK_IS_COMPONENT (component
));
290 iface
= ATK_COMPONENT_GET_IFACE (component
);
292 if (iface
->get_position
)
293 (iface
->get_position
) (component
, real_x
, real_y
, coord_type
);
297 * atk_component_get_size:
298 * @component: an #AtkComponent
299 * @width: address of #gint to put width of @component
300 * @height: address of #gint to put height of @component
302 * Gets the size of the @component in terms of width and height.
305 atk_component_get_size (AtkComponent
*component
,
309 AtkComponentIface
*iface
= NULL
;
310 gint local_width
, local_height
;
311 gint
*real_width
, *real_height
;
313 g_return_if_fail (ATK_IS_COMPONENT (component
));
318 real_width
= &local_width
;
320 real_height
= height
;
322 real_height
= &local_height
;
324 g_return_if_fail (ATK_IS_COMPONENT (component
));
326 iface
= ATK_COMPONENT_GET_IFACE (component
);
329 (iface
->get_size
) (component
, real_width
, real_height
);
333 * atk_component_get_layer:
334 * @component: an #AtkComponent
336 * Gets the layer of the component.
338 * Returns: an #AtkLayer which is the layer of the component
341 atk_component_get_layer (AtkComponent
*component
)
343 AtkComponentIface
*iface
;
345 g_return_val_if_fail (ATK_IS_COMPONENT (component
), ATK_LAYER_INVALID
);
347 iface
= ATK_COMPONENT_GET_IFACE (component
);
348 if (iface
->get_layer
)
349 return (iface
->get_layer
) (component
);
351 return ATK_LAYER_WIDGET
;
355 * atk_component_get_mdi_zorder:
356 * @component: an #AtkComponent
358 * Gets the zorder of the component. The value G_MININT will be returned
359 * if the layer of the component is not ATK_LAYER_MDI or ATK_LAYER_WINDOW.
361 * Returns: a gint which is the zorder of the component, i.e. the depth at
362 * which the component is shown in relation to other components in the same
366 atk_component_get_mdi_zorder (AtkComponent
*component
)
368 AtkComponentIface
*iface
;
370 g_return_val_if_fail (ATK_IS_COMPONENT (component
), G_MININT
);
372 iface
= ATK_COMPONENT_GET_IFACE (component
);
373 if (iface
->get_mdi_zorder
)
374 return (iface
->get_mdi_zorder
) (component
);
380 * atk_component_grab_focus:
381 * @component: an #AtkComponent
383 * Grabs focus for this @component.
385 * Returns: %TRUE if successful, %FALSE otherwise.
388 atk_component_grab_focus (AtkComponent
*component
)
390 AtkComponentIface
*iface
= NULL
;
391 g_return_val_if_fail (ATK_IS_COMPONENT (component
), FALSE
);
393 iface
= ATK_COMPONENT_GET_IFACE (component
);
395 if (iface
->grab_focus
)
396 return (iface
->grab_focus
) (component
);
402 * atk_component_set_extents:
403 * @component: an #AtkComponent
406 * @width: width to set for @component
407 * @height: height to set for @component
408 * @coord_type: specifies whether the coordinates are relative to the screen
409 * or to the components top level window
411 * Sets the extents of @component.
413 * Returns: %TRUE or %FALSE whether the extents were set or not
416 atk_component_set_extents (AtkComponent
*component
,
421 AtkCoordType coord_type
)
423 AtkComponentIface
*iface
= NULL
;
424 g_return_val_if_fail (ATK_IS_COMPONENT (component
), FALSE
);
426 iface
= ATK_COMPONENT_GET_IFACE (component
);
428 if (iface
->set_extents
)
429 return (iface
->set_extents
) (component
, x
, y
, width
, height
, coord_type
);
435 * atk_component_set_position:
436 * @component: an #AtkComponent
439 * @coord_type: specifies whether the coordinates are relative to the screen
440 * or to the components top level window
442 * Sets the postition of @component.
444 * Returns: %TRUE or %FALSE whether or not the position was set or not
447 atk_component_set_position (AtkComponent
*component
,
450 AtkCoordType coord_type
)
452 AtkComponentIface
*iface
= NULL
;
453 g_return_val_if_fail (ATK_IS_COMPONENT (component
), FALSE
);
455 iface
= ATK_COMPONENT_GET_IFACE (component
);
457 if (iface
->set_position
)
458 return (iface
->set_position
) (component
, x
, y
, coord_type
);
464 * atk_component_set_size:
465 * @component: an #AtkComponent
466 * @width: width to set for @component
467 * @height: height to set for @component
469 * Set the size of the @component in terms of width and height.
471 * Returns: %TRUE or %FALSE whether the size was set or not
474 atk_component_set_size (AtkComponent
*component
,
478 AtkComponentIface
*iface
= NULL
;
479 g_return_val_if_fail (ATK_IS_COMPONENT (component
), FALSE
);
481 iface
= ATK_COMPONENT_GET_IFACE (component
);
484 return (iface
->set_size
) (component
, x
, y
);
490 atk_component_real_contains (AtkComponent
*component
,
493 AtkCoordType coord_type
)
495 gint real_x
, real_y
, width
, height
;
497 real_x
= real_y
= width
= height
= 0;
499 atk_component_get_extents (component
, &real_x
, &real_y
, &width
, &height
, coord_type
);
502 (x
< real_x
+ width
) &&
504 (y
< real_y
+ height
))
511 atk_component_real_ref_accessible_at_point (AtkComponent
*component
,
514 AtkCoordType coord_type
)
518 count
= atk_object_get_n_accessible_children (ATK_OBJECT (component
));
520 for (i
= 0; i
< count
; i
++)
524 obj
= atk_object_ref_accessible_child (ATK_OBJECT (component
), i
);
528 if (atk_component_contains (ATK_COMPONENT (obj
), x
, y
, coord_type
))
534 g_object_unref (obj
);
542 atk_component_real_get_position (AtkComponent
*component
,
545 AtkCoordType coord_type
)
549 atk_component_get_extents (component
, x
, y
, &width
, &height
, coord_type
);
553 atk_component_real_get_size (AtkComponent
*component
,
558 AtkCoordType coord_type
;
561 * Pick one coordinate type; it does not matter for size
563 coord_type
= ATK_XY_WINDOW
;
565 atk_component_get_extents (component
, &x
, &y
, width
, height
, coord_type
);
568 static AtkRectangle
*
569 atk_rectangle_copy (const AtkRectangle
*rectangle
)
571 AtkRectangle
*result
= g_new (AtkRectangle
, 1);
572 *result
= *rectangle
;
578 atk_rectangle_get_type (void)
580 static GType our_type
= 0;
583 our_type
= g_boxed_type_register_static ("AtkRectangle",
584 (GBoxedCopyFunc
)atk_rectangle_copy
,
585 (GBoxedFreeFunc
)g_free
);