Bug 640574: gobject-introspection annotation and documentation fixes
[atk.git] / atk / atkutil.c
blobbd4e67a2426724953220fddadeb7ced7f1068369
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.
20 #include "atkutil.h"
21 #include "atkmarshal.c"
22 #include "config.h"
24 static void atk_util_class_init (AtkUtilClass *klass);
26 static AtkObject *previous_focus_object = NULL;
28 GType
29 atk_util_get_type (void)
31 static GType type = 0;
33 if (!type)
35 static const GTypeInfo typeInfo =
37 sizeof (AtkUtilClass),
38 (GBaseInitFunc) NULL,
39 (GBaseFinalizeFunc) NULL,
40 (GClassInitFunc) atk_util_class_init,
41 (GClassFinalizeFunc) NULL,
42 NULL,
43 sizeof (AtkUtil),
45 (GInstanceInitFunc) NULL,
46 } ;
47 type = g_type_register_static (G_TYPE_OBJECT, "AtkUtil", &typeInfo, 0) ;
49 return type;
52 static void
53 atk_util_class_init (AtkUtilClass *klass)
55 klass->add_global_event_listener = NULL;
56 klass->remove_global_event_listener = NULL;
57 klass->get_root = NULL;
58 klass->get_toolkit_name = NULL;
59 klass->get_toolkit_version = NULL;
63 * This file supports the addition and removal of multiple focus handlers
64 * as long as they are all called in the same thread.
66 static AtkEventListenerInit focus_tracker_init = (AtkEventListenerInit) NULL;
68 static gboolean init_done = FALSE;
71 * Array of FocusTracker structs
73 static GArray *trackers = NULL;
74 static guint index = 0;
76 typedef struct _FocusTracker FocusTracker;
78 struct _FocusTracker {
79 guint index;
80 AtkEventListener func;
83 /**
84 * atk_focus_tracker_init:
85 * @init: Function to be called for focus tracker initialization
87 * Specifies the function to be called for focus tracker initialization.
88 * This function should be called by an implementation of the
89 * ATK interface if any specific work needs to be done to enable
90 * focus tracking.
91 **/
92 void
93 atk_focus_tracker_init (AtkEventListenerInit init)
95 if (!focus_tracker_init)
96 focus_tracker_init = init;
99 /**
100 * atk_add_focus_tracker:
101 * @focus_tracker: Function to be added to the list of functions to be called
102 * when an object receives focus.
104 * Adds the specified function to the list of functions to be called
105 * when an object receives focus.
107 * Returns: added focus tracker id, or 0 on failure.
109 guint
110 atk_add_focus_tracker (AtkEventListener focus_tracker)
112 g_return_val_if_fail (focus_tracker, 0);
114 if (!init_done)
116 if (focus_tracker_init)
118 focus_tracker_init ();
120 trackers = g_array_sized_new (FALSE, TRUE, sizeof (FocusTracker), 0);
121 init_done = TRUE;
123 if (init_done)
125 FocusTracker item;
127 item.index = ++index;
128 item.func = focus_tracker;
129 trackers = g_array_append_val (trackers, item);
130 return index;
132 else
134 return 0;
139 * atk_remove_focus_tracker:
140 * @tracker_id: the id of the focus tracker to remove
142 * Removes the specified focus tracker from the list of functions
143 * to be called when any object receives focus.
145 void
146 atk_remove_focus_tracker (guint tracker_id)
148 FocusTracker *item;
149 guint i;
151 if (trackers == NULL)
152 return;
154 if (tracker_id == 0)
155 return;
157 for (i = 0; i < trackers->len; i++)
159 item = &g_array_index (trackers, FocusTracker, i);
160 if (item->index == tracker_id)
162 trackers = g_array_remove_index (trackers, i);
163 break;
169 * atk_focus_tracker_notify:
170 * @object: an #AtkObject
172 * Cause the focus tracker functions which have been specified to be
173 * executed for the object.
175 void
176 atk_focus_tracker_notify (AtkObject *object)
178 FocusTracker *item;
179 guint i;
181 if (trackers == NULL)
182 return;
184 if (object == previous_focus_object)
185 return;
186 else
188 if (previous_focus_object)
189 g_object_unref (previous_focus_object);
191 previous_focus_object = object;
192 if (object)
194 g_object_ref (object);
196 for (i = 0; i < trackers->len; i++)
198 item = &g_array_index (trackers, FocusTracker, i);
199 g_return_if_fail (item != NULL);
200 item->func (object);
208 * atk_add_global_event_listener:
209 * @listener: the listener to notify
210 * @event_type: the type of event for which notification is requested
212 * Adds the specified function to the list of functions to be called
213 * when an event of type event_type occurs.
215 * Returns: added event listener id, or 0 on failure.
217 guint
218 atk_add_global_event_listener (GSignalEmissionHook listener,
219 const gchar *event_type)
221 guint retval;
222 AtkUtilClass *klass = g_type_class_ref (ATK_TYPE_UTIL);
224 if (klass->add_global_event_listener)
226 retval = klass->add_global_event_listener (listener, event_type);
228 else
230 retval = 0;
232 g_type_class_unref (klass);
234 return retval;
238 * atk_remove_global_event_listener:
239 * @listener_id: the id of the event listener to remove
241 * Removes the specified event listener
243 void
244 atk_remove_global_event_listener (guint listener_id)
246 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
248 if (klass && klass->remove_global_event_listener)
249 klass->remove_global_event_listener (listener_id);
253 * atk_add_key_event_listener:
254 * @listener: the listener to notify
255 * @data: a #gpointer that points to a block of data that should be sent to the registered listeners,
256 * along with the event notification, when it occurs.
258 * Adds the specified function to the list of functions to be called
259 * when a key event occurs. The @data element will be passed to the
260 * #AtkKeySnoopFunc (@listener) as the @func_data param, on notification.
262 * Returns: added event listener id, or 0 on failure.
264 guint
265 atk_add_key_event_listener (AtkKeySnoopFunc listener, gpointer data)
267 guint retval;
268 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
269 if (klass && klass->add_key_event_listener)
271 retval = klass->add_key_event_listener (listener, data);
273 else
275 retval = 0;
278 return retval;
282 * atk_remove_key_event_listener:
283 * @listener_id: the id of the event listener to remove
285 * Removes the specified event listener
287 void
288 atk_remove_key_event_listener (guint listener_id)
290 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
292 if (klass->remove_key_event_listener)
293 klass->remove_key_event_listener (listener_id);
297 * atk_get_root:
299 * Gets the root accessible container for the current application.
301 * Returns: (transfer none): the root accessible container for the current
302 * application
304 AtkObject*
305 atk_get_root (void)
307 AtkUtilClass *klass = g_type_class_ref (ATK_TYPE_UTIL);
308 AtkObject *retval;
309 if (klass->get_root)
311 retval = klass->get_root ();
313 else
315 retval = NULL;
317 g_type_class_unref (klass);
319 return retval;
323 * atk_get_focus_object:
325 * Gets the currently focused object.
327 * Since: 1.6
329 * Returns: (transfer none): the currently focused object for the current
330 * application
332 AtkObject*
333 atk_get_focus_object (void)
335 return previous_focus_object;
339 * atk_get_toolkit_name:
341 * Gets name string for the GUI toolkit implementing ATK for this application.
343 * Returns: name string for the GUI toolkit implementing ATK for this application
345 G_CONST_RETURN gchar*
346 atk_get_toolkit_name (void)
348 const gchar *retval;
349 AtkUtilClass *klass = g_type_class_ref (ATK_TYPE_UTIL);
350 if (klass->get_toolkit_name)
352 retval = klass->get_toolkit_name ();
354 else
356 retval = NULL;
358 g_type_class_unref (klass);
360 return retval;
364 * atk_get_toolkit_version:
366 * Gets version string for the GUI toolkit implementing ATK for this application.
368 * Returns: version string for the GUI toolkit implementing ATK for this application
370 G_CONST_RETURN gchar*
371 atk_get_toolkit_version (void)
373 const gchar *retval;
374 AtkUtilClass *klass = g_type_class_ref (ATK_TYPE_UTIL);
375 if (klass->get_toolkit_version)
377 retval = klass->get_toolkit_version ();
379 else
381 retval = NULL;
383 g_type_class_unref (klass);
385 return retval;
389 * atk_get_version:
391 * Gets the current version for ATK.
393 * Returns: version string for ATK
395 * Since: 1.20
397 G_CONST_RETURN gchar *
398 atk_get_version (void)
400 return VERSION;