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"
24 static void atk_util_class_init (AtkUtilClass *klass);
27 atk_util_get_type (void)
29 static GType type = 0;
33 static const GTypeInfo typeInfo =
35 sizeof (AtkUtilClass),
37 (GBaseFinalizeFunc) NULL,
38 (GClassInitFunc) atk_util_class_init,
39 (GClassFinalizeFunc) NULL,
43 (GInstanceInitFunc) NULL,
45 type = g_type_register_static (G_TYPE_OBJECT, "AtkUtil", &typeInfo, 0) ;
51 atk_util_class_init (AtkUtilClass *klass)
53 klass->add_global_event_listener = NULL;
54 klass->remove_global_event_listener = NULL;
55 klass->get_root = NULL;
56 klass->get_toolkit_name = NULL;
57 klass->get_toolkit_version = NULL;
61 * This file supports the addition and removal of multiple focus handlers
62 * as long as they are all called in the same thread.
64 static AtkEventListenerInit focus_tracker_init = (AtkEventListenerInit) NULL;
66 static gboolean init_done = FALSE;
69 * Array of FocusTracker structs
71 static GArray *trackers = NULL;
72 static guint index = 0;
74 typedef struct _FocusTracker FocusTracker;
76 struct _FocusTracker {
78 AtkEventListener func;
82 * atk_focus_tracker_init:
83 * @add_function: Function to be called for focus tracker initialization
85 * Specifies the function to be called for focus tracker initialization.
86 * This function should be called by an implementation of the
87 * ATK interface if any specific work needs to be done to enable
91 atk_focus_tracker_init (AtkEventListenerInit init)
93 if (!focus_tracker_init)
94 focus_tracker_init = init;
98 * atk_add_focus_tracker:
99 * @focus_tracker: Function to be added to the list of functions to be called
100 * when an object receives focus.
102 * Adds the specified function to the list of functions to be called
103 * when an object receives focus.
105 * Returns: added focus tracker id, or 0 on failure.
108 atk_add_focus_tracker (AtkEventListener focus_tracker)
110 g_return_val_if_fail (focus_tracker, 0);
114 if (focus_tracker_init)
116 focus_tracker_init ();
118 trackers = g_array_sized_new (FALSE, TRUE, sizeof (FocusTracker), 0);
125 item.index = ++index;
126 item.func = focus_tracker;
127 trackers = g_array_append_val (trackers, item);
137 * atk_remove_focus_tracker:
138 * @tracker_id: the id of the focus tracker to remove
140 * Removes the specified focus tracker from the list of functions
141 * to be called when any object receives focus.
144 atk_remove_focus_tracker (guint tracker_id)
149 if (trackers == NULL)
155 for (i = 0; i < trackers->len; i++)
157 item = &g_array_index (trackers, FocusTracker, i);
158 if (item->index == tracker_id)
160 trackers = g_array_remove_index (trackers, i);
167 * atk_focus_tracker_notify:
168 * @object: an #AtkObject
170 * Cause the focus tracker functions which have been specified to be
171 * executed for the object.
174 atk_focus_tracker_notify (AtkObject *object)
179 if (trackers == NULL)
182 for (i = 0; i < trackers->len; i++)
184 item = &g_array_index (trackers, FocusTracker, i);
185 g_return_if_fail (item != NULL);
191 * atk_add_global_event_listener:
192 * @listener: the listener to notify
193 * @event_type: the type of event for which notification is requested
195 * Adds the specified function to the list of functions to be called
196 * when an event of type event_type occurs.
198 * Returns: added event listener id, or 0 on failure.
201 atk_add_global_event_listener (GSignalEmissionHook listener,
202 const gchar *event_type)
205 AtkUtilClass *klass = g_type_class_ref (ATK_TYPE_UTIL);
207 if (klass->add_global_event_listener)
209 retval = klass->add_global_event_listener (listener, event_type);
215 g_type_class_unref (klass);
221 * atk_remove_global_event_listener:
222 * @listener_id: the id of the event listener to remove
224 * Removes the specified event listener
227 atk_remove_global_event_listener (guint listener_id)
229 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
231 if (klass->remove_global_event_listener)
232 klass->remove_global_event_listener (listener_id);
236 * atk_add_key_event_listener:
237 * @listener: the listener to notify
238 * @data: a #gpointer that points to a block of data that should be sent to the registered listeners,
239 * along with the event notification, when it occurs.
241 * Adds the specified function to the list of functions to be called
242 * when a key event occurs. The @data element will be passed to the
243 * #AtkKeySnoopFunc (@listener) as the @func_data param, on notification.
245 * Returns: added event listener id, or 0 on failure.
248 atk_add_key_event_listener (AtkKeySnoopFunc listener, gpointer data)
251 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
252 if (klass->add_key_event_listener)
254 retval = klass->add_key_event_listener (listener, data);
265 * atk_remove_key_event_listener:
266 * @listener_id: the id of the event listener to remove
268 * Removes the specified event listener
271 atk_remove_key_event_listener (guint listener_id)
273 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
275 if (klass->remove_key_event_listener)
276 klass->remove_key_event_listener (listener_id);
282 * Gets the root accessible container for the current application.
284 * Returns: the root accessible container for the current application
289 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
292 return klass->get_root ();
301 * atk_get_toolkit_name:
303 * Gets name string for the GUI toolkit implementing ATK for this application.
305 * Returns: name string for the GUI toolkit implementing ATK for this application
307 G_CONST_RETURN gchar*
308 atk_get_toolkit_name (void)
310 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
311 if (klass->get_toolkit_name)
313 return klass->get_toolkit_name ();
322 * atk_get_toolkit_version:
324 * Gets version string for the GUI toolkit implementing ATK for this application.
326 * Returns: version string for the GUI toolkit implementing ATK for this application
328 G_CONST_RETURN gchar*
329 atk_get_toolkit_version (void)
331 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
332 if (klass->get_toolkit_version)
334 return klass->get_toolkit_version ();