Revved to 1.10.3, to fix previous bad dist due to libtool bug.
[atk.git] / atk / atkcomponent.c
blob65659a22fcf1b7103a7b6bf022ca156c708da759
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 enum {
24 BOUNDS_CHANGED,
25 LAST_SIGNAL
28 static void atk_component_base_init (AtkComponentIface *class);
30 static gboolean atk_component_real_contains (AtkComponent *component,
31 gint x,
32 gint y,
33 AtkCoordType coord_type);
35 static AtkObject* atk_component_real_ref_accessible_at_point (AtkComponent *component,
36 gint x,
37 gint y,
38 AtkCoordType coord_type);
40 static void atk_component_real_get_position (AtkComponent *component,
41 gint *x,
42 gint *y,
43 AtkCoordType coord_type);
45 static void atk_component_real_get_size (AtkComponent *component,
46 gint *width,
47 gint *height);
49 static guint atk_component_signals[LAST_SIGNAL] = { 0 };
51 GType
52 atk_component_get_type (void)
54 static GType type = 0;
56 if (!type) {
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);
68 return type;
71 static void
72 atk_component_base_init (AtkComponentIface *class)
74 static gboolean initialized = FALSE;
76 if (! initialized)
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",
85 ATK_TYPE_COMPONENT,
86 G_SIGNAL_RUN_LAST,
87 G_STRUCT_OFFSET (AtkComponentIface, bounds_changed),
88 (GSignalAccumulator) NULL, NULL,
89 g_cclosure_marshal_VOID__BOXED,
90 G_TYPE_NONE, 1,
91 ATK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
93 initialized = TRUE;
98 /**
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.
110 guint
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);
121 else
122 return 0;
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
129 * from @component
131 * Remove the handler specified by @handler_id from the list of
132 * functions to be executed when this object receives focus events
133 * (in or out).
135 void
136 atk_component_remove_focus_handler (AtkComponent *component,
137 guint handler_id)
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
151 * @x: x coordinate
152 * @y: y coordinate
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
161 gboolean
162 atk_component_contains (AtkComponent *component,
163 gint x,
164 gint y,
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);
172 if (iface->contains)
173 return (iface->contains) (component, x, y, coord_type);
174 else
175 return FALSE;
179 * atk_component_ref_accessible_at_point:
180 * @component: the #AtkComponent
181 * @x: x coordinate
182 * @y: y coordinate
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
191 AtkObject*
192 atk_component_ref_accessible_at_point (AtkComponent *component,
193 gint x,
194 gint y,
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);
204 else
205 return NULL;
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.
221 void
222 atk_component_get_extents (AtkComponent *component,
223 gint *x,
224 gint *y,
225 gint *width,
226 gint *height,
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));
235 if (x)
236 real_x = x;
237 else
238 real_x = &local_x;
239 if (y)
240 real_y = y;
241 else
242 real_y = &local_y;
243 if (width)
244 real_width = width;
245 else
246 real_width = &local_width;
247 if (height)
248 real_height = height;
249 else
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.
269 void
270 atk_component_get_position (AtkComponent *component,
271 gint *x,
272 gint *y,
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));
281 if (x)
282 real_x = x;
283 else
284 real_x = &local_x;
285 if (y)
286 real_y = y;
287 else
288 real_y = &local_y;
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.
304 void
305 atk_component_get_size (AtkComponent *component,
306 gint *width,
307 gint *height)
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));
315 if (width)
316 real_width = width;
317 else
318 real_width = &local_width;
319 if (height)
320 real_height = height;
321 else
322 real_height = &local_height;
324 g_return_if_fail (ATK_IS_COMPONENT (component));
326 iface = ATK_COMPONENT_GET_IFACE (component);
328 if (iface->get_size)
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
340 AtkLayer
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);
350 else
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
363 * container.
365 gint
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);
375 else
376 return G_MININT;
380 * atk_component_grab_focus:
381 * @component: an #AtkComponent
383 * Grabs focus for this @component.
385 * Returns: %TRUE if successful, %FALSE otherwise.
387 gboolean
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);
397 else
398 return FALSE;
402 * atk_component_set_extents:
403 * @component: an #AtkComponent
404 * @x: x coordinate
405 * @y: y coordinate
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
415 gboolean
416 atk_component_set_extents (AtkComponent *component,
417 gint x,
418 gint y,
419 gint width,
420 gint height,
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);
430 else
431 return FALSE;
435 * atk_component_set_position:
436 * @component: an #AtkComponent
437 * @x: x coordinate
438 * @y: y coordinate
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
446 gboolean
447 atk_component_set_position (AtkComponent *component,
448 gint x,
449 gint y,
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);
459 else
460 return FALSE;
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
473 gboolean
474 atk_component_set_size (AtkComponent *component,
475 gint x,
476 gint y)
478 AtkComponentIface *iface = NULL;
479 g_return_val_if_fail (ATK_IS_COMPONENT (component), FALSE);
481 iface = ATK_COMPONENT_GET_IFACE (component);
483 if (iface->set_size)
484 return (iface->set_size) (component, x, y);
485 else
486 return FALSE;
489 static gboolean
490 atk_component_real_contains (AtkComponent *component,
491 gint x,
492 gint y,
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);
501 if ((x >= real_x) &&
502 (x < real_x + width) &&
503 (y >= real_y) &&
504 (y < real_y + height))
505 return TRUE;
506 else
507 return FALSE;
510 static AtkObject*
511 atk_component_real_ref_accessible_at_point (AtkComponent *component,
512 gint x,
513 gint y,
514 AtkCoordType coord_type)
516 gint count, i;
518 count = atk_object_get_n_accessible_children (ATK_OBJECT (component));
520 for (i = 0; i < count; i++)
522 AtkObject *obj;
524 obj = atk_object_ref_accessible_child (ATK_OBJECT (component), i);
526 if (obj != NULL)
528 if (atk_component_contains (ATK_COMPONENT (obj), x, y, coord_type))
530 return obj;
532 else
534 g_object_unref (obj);
538 return NULL;
541 static void
542 atk_component_real_get_position (AtkComponent *component,
543 gint *x,
544 gint *y,
545 AtkCoordType coord_type)
547 gint width, height;
549 atk_component_get_extents (component, x, y, &width, &height, coord_type);
552 static void
553 atk_component_real_get_size (AtkComponent *component,
554 gint *width,
555 gint *height)
557 gint x, y;
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;
574 return result;
577 GType
578 atk_rectangle_get_type (void)
580 static GType our_type = 0;
582 if (our_type == 0)
583 our_type = g_boxed_type_register_static ("AtkRectangle",
584 (GBoxedCopyFunc)atk_rectangle_copy,
585 (GBoxedFreeFunc)g_free);
586 return our_type;