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);
26 atk_util_get_type (void)
28 static GType type = 0;
32 static const GTypeInfo typeInfo =
34 sizeof (AtkUtilClass),
36 (GBaseFinalizeFunc) NULL,
37 (GClassInitFunc) atk_util_class_init,
38 (GClassFinalizeFunc) NULL,
42 (GInstanceInitFunc) NULL,
44 type = g_type_register_static (G_TYPE_OBJECT, "AtkUtil", &typeInfo, 0) ;
50 atk_util_class_init (AtkUtilClass *klass)
52 klass->add_global_event_listener = NULL;
53 klass->remove_global_event_listener = NULL;
54 klass->get_root = NULL;
55 klass->get_toolkit_name = NULL;
56 klass->get_toolkit_version = NULL;
60 * This file supports the addition and removal of multiple focus handlers
61 * as long as they are all called in the same thread.
63 static AtkEventListenerInit focus_tracker_init = (AtkEventListenerInit) NULL;
65 static gboolean init_done = FALSE;
68 * Array of FocusTracker structs
70 static GArray *trackers = NULL;
71 static guint index = 0;
73 typedef struct _FocusTracker FocusTracker;
75 struct _FocusTracker {
77 AtkEventListener func;
81 * atk_focus_tracker_init:
82 * @add_function: Function to be called for focus tracker initialization
84 * Specifies the function to be called for focus tracker initialization.
85 * This function should be called by an implementation of the
86 * ATK interface if any specific work needs to be done to enable
90 atk_focus_tracker_init (AtkEventListenerInit init)
92 if (!focus_tracker_init)
93 focus_tracker_init = init;
97 * atk_add_focus_tracker:
98 * @focus_tracker: Function to be added to the list of functions to be called
99 * when an object receives focus.
101 * Adds the specified function to the list of functions to be called
102 * when an object receives focus.
104 * Returns: added focus tracker id, or 0 on failure.
107 atk_add_focus_tracker (AtkEventListener focus_tracker)
109 g_return_val_if_fail (focus_tracker, 0);
113 if (focus_tracker_init)
115 focus_tracker_init ();
117 trackers = g_array_sized_new (FALSE, TRUE, sizeof (FocusTracker), 0);
124 item.index = ++index;
125 item.func = focus_tracker;
126 trackers = g_array_append_val (trackers, item);
136 * atk_remove_focus_tracker:
137 * @tracker_id: the id of the focus tracker to remove
139 * Removes the specified focus tracker from the list of functions
140 * to be called when any object receives focus.
143 atk_remove_focus_tracker (guint tracker_id)
148 if (trackers == NULL)
154 for (i = 0; i < trackers->len; i++)
156 item = &g_array_index (trackers, FocusTracker, i);
157 if (item->index == tracker_id)
159 trackers = g_array_remove_index (trackers, i);
166 * atk_focus_tracker_notify:
167 * @object: an #AtkObject
169 * Cause the focus tracker functions which have been specified to be
170 * executed for the object.
173 atk_focus_tracker_notify (AtkObject *object)
178 if (trackers == NULL)
181 for (i = 0; i < trackers->len; i++)
183 item = &g_array_index (trackers, FocusTracker, i);
184 g_return_if_fail (item != NULL);
190 * atk_add_global_event_listener:
191 * @listener: the listener to notify
192 * @event_type: the type of event for which notification is requested
194 * Adds the specified function to the list of functions to be called
195 * when an event of type event_type occurs.
197 * Returns: added event listener id, or 0 on failure.
200 atk_add_global_event_listener (GSignalEmissionHook listener, gchar* event_type)
203 AtkUtilClass *klass = g_type_class_ref (ATK_TYPE_UTIL);
204 if (klass->add_global_event_listener)
206 retval = klass->add_global_event_listener (listener, event_type);
212 g_type_class_unref (klass);
218 * atk_remove_global_event_listener:
219 * @listener_id: the id of the event listener to remove
221 * Removes the specified event listener
224 atk_remove_global_event_listener (guint listener_id)
226 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
228 if (klass->remove_global_event_listener)
229 klass->remove_global_event_listener (listener_id);
235 * Gets the root accessible container for the current application.
237 * Returns: the root accessible container for the current application
242 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
245 return klass->get_root ();
254 * atk_get_toolkit_name:
256 * Gets name string for the GUI toolkit implementing ATK for this application.
258 * Returns: name string for the GUI toolkit implementing ATK for this application
260 gchar* atk_get_toolkit_name(void)
262 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
263 if (klass->get_toolkit_name)
265 return klass->get_toolkit_name ();
274 * atk_get_toolkit_version:
276 * Gets version string for the GUI toolkit implementing ATK for this application.
278 * Returns: version string for the GUI toolkit implementing ATK for this application
281 atk_get_toolkit_version(void)
283 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
284 if (klass->get_toolkit_version)
286 return klass->get_toolkit_version ();