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
);
26 static AtkObject
*previous_focus_object
= NULL
;
29 atk_util_get_type (void)
31 static GType type
= 0;
35 static const GTypeInfo typeInfo
=
37 sizeof (AtkUtilClass
),
39 (GBaseFinalizeFunc
) NULL
,
40 (GClassInitFunc
) atk_util_class_init
,
41 (GClassFinalizeFunc
) NULL
,
45 (GInstanceInitFunc
) NULL
,
47 type
= g_type_register_static (G_TYPE_OBJECT
, "AtkUtil", &typeInfo
, 0) ;
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
{
80 AtkEventListener func
;
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
93 atk_focus_tracker_init (AtkEventListenerInit init
)
95 if (!focus_tracker_init
)
96 focus_tracker_init
= init
;
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.
110 atk_add_focus_tracker (AtkEventListener focus_tracker
)
112 g_return_val_if_fail (focus_tracker
, 0);
116 if (focus_tracker_init
)
118 focus_tracker_init ();
120 trackers
= g_array_sized_new (FALSE
, TRUE
, sizeof (FocusTracker
), 0);
127 item
.index
= ++index
;
128 item
.func
= focus_tracker
;
129 trackers
= g_array_append_val (trackers
, item
);
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.
146 atk_remove_focus_tracker (guint tracker_id
)
151 if (trackers
== NULL
)
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
);
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.
176 atk_focus_tracker_notify (AtkObject
*object
)
181 if (trackers
== NULL
)
184 if (object
== previous_focus_object
)
188 if (previous_focus_object
)
189 g_object_unref (previous_focus_object
);
191 previous_focus_object
= 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
);
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.
218 atk_add_global_event_listener (GSignalEmissionHook listener
,
219 const gchar
*event_type
)
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
);
232 g_type_class_unref (klass
);
238 * atk_remove_global_event_listener:
239 * @listener_id: the id of the event listener to remove
241 * Removes the specified event listener
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.
265 atk_add_key_event_listener (AtkKeySnoopFunc listener
, gpointer data
)
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
);
282 * atk_remove_key_event_listener:
283 * @listener_id: the id of the event listener to remove
285 * Removes the specified event listener
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
);
299 * Gets the root accessible container for the current application.
301 * Returns: (transfer none): the root accessible container for the current
307 AtkUtilClass
*klass
= g_type_class_ref (ATK_TYPE_UTIL
);
311 retval
= klass
->get_root ();
317 g_type_class_unref (klass
);
323 * atk_get_focus_object:
325 * Gets the currently focused object.
329 * Returns: (transfer none): the currently focused object for the current
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)
349 AtkUtilClass
*klass
= g_type_class_ref (ATK_TYPE_UTIL
);
350 if (klass
->get_toolkit_name
)
352 retval
= klass
->get_toolkit_name ();
358 g_type_class_unref (klass
);
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)
374 AtkUtilClass
*klass
= g_type_class_ref (ATK_TYPE_UTIL
);
375 if (klass
->get_toolkit_version
)
377 retval
= klass
->get_toolkit_version ();
383 g_type_class_unref (klass
);
391 * Gets the current version for ATK.
393 * Returns: version string for ATK
397 G_CONST_RETURN gchar
*
398 atk_get_version (void)