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
, gchar
* event_type
)
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
);
213 g_type_class_unref (klass
);
219 * atk_remove_global_event_listener:
220 * @listener_id: the id of the event listener to remove
222 * Removes the specified event listener
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
);
236 * Gets the root accessible container for the current application.
238 * Returns: the root accessible container for the current application
243 AtkUtilClass
*klass
= g_type_class_peek (ATK_TYPE_UTIL
);
246 return klass
->get_root ();
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 ();
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
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 ();