Add two new relations ATK_RELATION_NODE_CHILDREN and
[atk.git] / atk / atkutil.c
blobd02a3c6d270d9a498b989145a23d7d06520b2441
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"
24 static void atk_util_class_init (AtkUtilClass *klass);
26 GType
27 atk_util_get_type (void)
29 static GType type = 0;
31 if (!type)
33 static const GTypeInfo typeInfo =
35 sizeof (AtkUtilClass),
36 (GBaseInitFunc) NULL,
37 (GBaseFinalizeFunc) NULL,
38 (GClassInitFunc) atk_util_class_init,
39 (GClassFinalizeFunc) NULL,
40 NULL,
41 sizeof (AtkUtil),
43 (GInstanceInitFunc) NULL,
44 } ;
45 type = g_type_register_static (G_TYPE_OBJECT, "AtkUtil", &typeInfo, 0) ;
47 return type;
50 static void
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 {
77 guint index;
78 AtkEventListener func;
81 /**
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
88 * focus tracking.
89 **/
90 void
91 atk_focus_tracker_init (AtkEventListenerInit init)
93 if (!focus_tracker_init)
94 focus_tracker_init = init;
97 /**
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.
107 guint
108 atk_add_focus_tracker (AtkEventListener focus_tracker)
110 g_return_val_if_fail (focus_tracker, 0);
112 if (!init_done)
114 if (focus_tracker_init)
116 focus_tracker_init ();
118 trackers = g_array_sized_new (FALSE, TRUE, sizeof (FocusTracker), 0);
119 init_done = TRUE;
121 if (init_done)
123 FocusTracker item;
125 item.index = ++index;
126 item.func = focus_tracker;
127 trackers = g_array_append_val (trackers, item);
128 return index;
130 else
132 return 0;
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.
143 void
144 atk_remove_focus_tracker (guint tracker_id)
146 FocusTracker *item;
147 guint i;
149 if (trackers == NULL)
150 return;
152 if (tracker_id == 0)
153 return;
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);
161 break;
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.
173 void
174 atk_focus_tracker_notify (AtkObject *object)
176 FocusTracker *item;
177 guint i;
179 if (trackers == NULL)
180 return;
182 for (i = 0; i < trackers->len; i++)
184 item = &g_array_index (trackers, FocusTracker, i);
185 g_return_if_fail (item != NULL);
186 item->func (object);
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.
200 guint
201 atk_add_global_event_listener (GSignalEmissionHook listener, gchar* event_type)
203 guint retval;
204 AtkUtilClass *klass = g_type_class_ref (ATK_TYPE_UTIL);
205 if (klass->add_global_event_listener)
207 retval = klass->add_global_event_listener (listener, event_type);
209 else
211 retval = -1;
213 g_type_class_unref (klass);
215 return retval;
219 * atk_remove_global_event_listener:
220 * @listener_id: the id of the event listener to remove
222 * Removes the specified event listener
224 void
225 atk_remove_global_event_listener (guint listener_id)
227 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
229 if (klass->remove_global_event_listener)
230 klass->remove_global_event_listener (listener_id);
234 * atk_get_root:
236 * Gets the root accessible container for the current application.
238 * Returns: the root accessible container for the current application
240 AtkObject*
241 atk_get_root(void)
243 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
244 if (klass->get_root)
246 return klass->get_root ();
248 else
250 return NULL;
255 * atk_get_toolkit_name:
257 * Gets name string for the GUI toolkit implementing ATK for this application.
259 * Returns: name string for the GUI toolkit implementing ATK for this application
261 gchar* atk_get_toolkit_name(void)
263 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
264 if (klass->get_toolkit_name)
266 return klass->get_toolkit_name ();
268 else
270 return NULL;
275 * atk_get_toolkit_version:
277 * Gets version string for the GUI toolkit implementing ATK for this application.
279 * Returns: version string for the GUI toolkit implementing ATK for this application
281 gchar*
282 atk_get_toolkit_version(void)
284 AtkUtilClass *klass = g_type_class_peek (ATK_TYPE_UTIL);
285 if (klass->get_toolkit_version)
287 return klass->get_toolkit_version ();
289 else
291 return NULL;