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 "atkmarshal.c"
23 static void atk_util_class_init (AtkUtilClass *klass);
25 static AtkObject *previous_focus_object = NULL;
28 atk_util_get_type (void)
30 static GType type = 0;
34 static const GTypeInfo typeInfo =
36 sizeof (AtkUtilClass),
38 (GBaseFinalizeFunc) NULL,
39 (GClassInitFunc) atk_util_class_init,
40 (GClassFinalizeFunc) NULL,
44 (GInstanceInitFunc) NULL,
46 type = g_type_register_static (G_TYPE_OBJECT, "AtkUtil", &typeInfo, 0) ;
52 atk_util_class_init (AtkUtilClass *klass)
54 klass->add_global_event_listener = NULL;
55 klass->remove_global_event_listener = NULL;
56 klass->get_root = NULL;
57 klass->get_toolkit_name = NULL;
58 klass->get_toolkit_version = NULL;
62 * This file supports the addition and removal of multiple focus handlers
63 * as long as they are all called in the same thread.
65 static AtkEventListenerInit focus_tracker_init = (AtkEventListenerInit) NULL;
67 static gboolean init_done = FALSE;
70 * Array of FocusTracker structs
72 static GArray *trackers = NULL;
73 static guint index = 0;
75 typedef struct _FocusTracker FocusTracker;
77 struct _FocusTracker {
79 AtkEventListener func;
83 * atk_focus_tracker_init:
84 * @init: Function to be called for focus tracker initialization
86 * Specifies the function to be called for focus tracker initialization.
87 * This function should be called by an implementation of the
88 * ATK interface if any specific work needs to be done to enable
92 atk_focus_tracker_init (AtkEventListenerInit init)
94 if (!focus_tracker_init)
95 focus_tracker_init = init;
99 * atk_add_focus_tracker:
100 * @focus_tracker: Function to be added to the list of functions to be called
101 * when an object receives focus.
103 * Adds the specified function to the list of functions to be called
104 * when an object receives focus.
106 * Returns: added focus tracker id, or 0 on failure.
109 atk_add_focus_tracker (AtkEventListener focus_tracker)
111 g_return_val_if_fail (focus_tracker, 0);
115 if (focus_tracker_init)
117 focus_tracker_init ();
119 trackers = g_array_sized_new (FALSE, TRUE, sizeof (FocusTracker), 0);
126 item.index = ++index;
127 item.func = focus_tracker;
128 trackers = g_array_append_val (trackers, item);
138 * atk_remove_focus_tracker:
139 * @tracker_id: the id of the focus tracker to remove
141 * Removes the specified focus tracker from the list of functions
142 * to be called when any object receives focus.
145 atk_remove_focus_tracker (guint tracker_id)
150 if (trackers == NULL)
156 for (i = 0; i < trackers->len; i++)
158 item = &g_array_index (trackers, FocusTracker, i);
159 if (item->index == tracker_id)
161 trackers = g_array_remove_index (trackers, i);
168 * atk_focus_tracker_notify:
169 * @object: an #AtkObject
171 * Cause the focus tracker functions which have been specified to be
172 * executed for the object.
175 atk_focus_tracker_notify (AtkObject *object)
180 if (trackers == NULL)
183 if (object == previous_focus_object)
187 if (previous_focus_object)
188 g_object_unref (previous_focus_object);
190 previous_focus_object = object;
193 g_object_ref (object);
195 for (i = 0; i < trackers->len; i++)
197 item = &g_array_index (trackers, FocusTracker, i);
198 g_return_if_fail (item != NULL);
207 * atk_add_global_event_listener:
208 * @listener: the listener to notify
209 * @event_type: the type of event for which notification is requested
211 * Adds the specified function to the list of functions to be called
212 * when an event of type event_type occurs.
214 * Returns: added event listener id, or 0 on failure.
217 atk_add_global_event_listener (GSignalEmissionHook listener,
218 const gchar *event_type)
221 AtkUtilClass *klass = g_type_class_ref (ATK_TYPE_UTIL);
223 if (klass->add_global_event_listener)
225 retval = klass->add_global_event_listener (listener, event_type);
231 g_type_class_unref (klass);
237 * atk_remove_global_event_listener:
238 * @listener_id: the id of the event listener to remove
240 * Removes the specified event listener
243 atk_remove_global_event_listener (guint listener_id)
245 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
247 if (klass && klass->remove_global_event_listener)
248 klass->remove_global_event_listener (listener_id);
252 * atk_add_key_event_listener:
253 * @listener: the listener to notify
254 * @data: a #gpointer that points to a block of data that should be sent to the registered listeners,
255 * along with the event notification, when it occurs.
257 * Adds the specified function to the list of functions to be called
258 * when a key event occurs. The @data element will be passed to the
259 * #AtkKeySnoopFunc (@listener) as the @func_data param, on notification.
261 * Returns: added event listener id, or 0 on failure.
264 atk_add_key_event_listener (AtkKeySnoopFunc listener, gpointer data)
267 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
268 if (klass && klass->add_key_event_listener)
270 retval = klass->add_key_event_listener (listener, data);
281 * atk_remove_key_event_listener:
282 * @listener_id: the id of the event listener to remove
284 * Removes the specified event listener
287 atk_remove_key_event_listener (guint listener_id)
289 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
291 if (klass->remove_key_event_listener)
292 klass->remove_key_event_listener (listener_id);
298 * Gets the root accessible container for the current application.
300 * Returns: the root accessible container for the current application
305 AtkUtilClass *klass = g_type_class_ref (ATK_TYPE_UTIL);
309 retval = klass->get_root ();
315 g_type_class_unref (klass);
321 * atk_get_focus_object:
323 * Gets the currently focused object.
325 * Returns: the currently focused object for the current application
328 atk_get_focus_object (void)
330 return previous_focus_object;
334 * atk_get_toolkit_name:
336 * Gets name string for the GUI toolkit implementing ATK for this application.
338 * Returns: name string for the GUI toolkit implementing ATK for this application
340 G_CONST_RETURN gchar*
341 atk_get_toolkit_name (void)
344 AtkUtilClass *klass = g_type_class_ref (ATK_TYPE_UTIL);
345 if (klass->get_toolkit_name)
347 retval = klass->get_toolkit_name ();
353 g_type_class_unref (klass);
359 * atk_get_toolkit_version:
361 * Gets version string for the GUI toolkit implementing ATK for this application.
363 * Returns: version string for the GUI toolkit implementing ATK for this application
365 G_CONST_RETURN gchar*
366 atk_get_toolkit_version (void)
369 AtkUtilClass *klass = g_type_class_ref (ATK_TYPE_UTIL);
370 if (klass->get_toolkit_version)
372 retval = klass->get_toolkit_version ();
378 g_type_class_unref (klass);