2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001 Sun Microsystems Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 /* application.c: implements SpiApplication.idl */
27 #include <atk/atkutil.h>
28 #include <libspi/application.h>
30 /* Our parent Gtk object type */
31 #define PARENT_TYPE SPI_ACCESSIBLE_TYPE
33 /* A pointer to our parent object class */
34 static SpiAccessibleClass *spi_application_parent_class;
36 static SpiApplication *the_app;
40 static void notify_listeners (GList *listeners,
41 SpiAccessible *source,
42 Accessibility_Event *e);
44 static const char *reverse_lookup_name_for_toolkit_event (char *toolkit_name);
47 lookup_toolkit_event_for_name (const char *generic_name)
49 char *toolkit_specific_name;
50 SpiApplicationClass *klass = g_type_class_peek (SPI_APPLICATION_TYPE);
52 fprintf (stderr, "looking for %s in hash table.\n", generic_name);
54 toolkit_specific_name =
55 (char *) g_hash_table_lookup (klass->toolkit_event_names, generic_name);
57 fprintf (stderr, "generic event %s converted to %s\n", generic_name, toolkit_specific_name);
59 return toolkit_specific_name;
63 * Implemented GObject::finalize
66 spi_accessible_application_finalize (GObject *object)
69 SpiApplication *application = (SpiApplication *) object;
72 CORBA_exception_init (&ev);
74 for (l = application->toolkit_listeners; l; l = l->next)
76 CORBA_Object_release ((CORBA_Object) l->data, &ev);
79 CORBA_exception_free (&ev);
81 g_list_free (application->toolkit_listeners);
82 application->toolkit_listeners = NULL;
84 g_print ("application finalize called\n");
85 (G_OBJECT_CLASS (spi_application_parent_class))->finalize (object);
89 impl_accessibility_application_get_toolkit_name (PortableServer_Servant servant,
90 CORBA_Environment *ev)
92 return CORBA_string_dup (atk_get_toolkit_name ());
96 impl_accessibility_application_get_version (PortableServer_Servant servant,
97 CORBA_Environment *ev)
99 return CORBA_string_dup (atk_get_toolkit_version ());
103 impl_accessibility_application_get_id (PortableServer_Servant servant,
104 CORBA_Environment *ev)
106 SpiApplication *application = SPI_APPLICATION (
107 bonobo_object_from_servant (servant));
109 return application->id;
113 impl_accessibility_application_set_id (PortableServer_Servant servant,
115 CORBA_Environment *ev)
117 SpiApplication *application = SPI_APPLICATION (
118 bonobo_object_from_servant (servant));
120 application->id = id;
124 get_atk_object_ref (GObject *gobject)
128 if (ATK_IS_IMPLEMENTOR (gobject))
130 aobject = atk_implementor_ref_accessible (ATK_IMPLEMENTOR (gobject));
132 else if (ATK_IS_OBJECT (gobject))
134 aobject = ATK_OBJECT (gobject);
135 g_object_ref (G_OBJECT (aobject));
140 g_error ("received event from non-AtkImplementor");
147 spi_application_object_event_listener (GSignalInvocationHint *signal_hint,
148 guint n_param_values,
149 const GValue *param_values,
152 Accessibility_Event e;
154 SpiAccessible *source;
155 GSignalQuery signal_query;
157 const char *generic_name;
159 g_return_val_if_fail (the_app != NULL, FALSE);
161 g_signal_query (signal_hint->signal_id, &signal_query);
163 /* TODO: move GTK reference out of app.c into bridge */
164 event_name = g_strdup_printf ("Gtk:%s:%s",
165 g_type_name (signal_query.itype),
166 signal_query.signal_name);
168 generic_name = reverse_lookup_name_for_toolkit_event (event_name);
170 fprintf (stderr, "Received (object) signal %s maps to '%s'\n",
171 event_name, generic_name);
175 g_return_val_if_fail (generic_name, FALSE);
177 aobject = get_atk_object_ref (g_value_get_object (param_values + 0));
179 source = spi_accessible_new (aobject);
180 e.type = CORBA_string_dup (generic_name);
181 e.source = CORBA_OBJECT_NIL;
185 notify_listeners (the_app->toolkit_listeners, source, &e);
187 bonobo_object_unref (BONOBO_OBJECT (source));
189 g_object_unref (G_OBJECT (aobject));
195 spi_application_toolkit_event_listener (GSignalInvocationHint *signal_hint,
196 guint n_param_values,
197 const GValue *param_values,
200 Accessibility_Event e;
202 SpiAccessible *source;
203 GSignalQuery signal_query;
206 g_return_val_if_fail (the_app != NULL, FALSE);
208 g_signal_query (signal_hint->signal_id, &signal_query);
210 /* TODO: move GTK reference out of app.c into bridge */
211 event_name = g_strdup_printf ("Gtk:%s:%s",
212 g_type_name (signal_query.itype),
213 signal_query.signal_name);
216 fprintf (stderr, "Received signal %s\n", event_name);
219 aobject = get_atk_object_ref (g_value_get_object (param_values + 0));
221 source = spi_accessible_new (aobject);
222 e.type = CORBA_string_dup (event_name);
223 e.source = CORBA_OBJECT_NIL;
226 notify_listeners (the_app->toolkit_listeners, source, &e);
228 bonobo_object_unref (BONOBO_OBJECT (source));
229 g_object_unref (G_OBJECT (aobject));
237 impl_accessibility_application_register_toolkit_event_listener (PortableServer_Servant servant,
238 Accessibility_EventListener listener,
239 const CORBA_char *event_name,
240 CORBA_Environment *ev)
242 guint spi_listener_id;
244 atk_add_global_event_listener (spi_application_toolkit_event_listener, event_name);
245 the_app->toolkit_listeners = g_list_append (the_app->toolkit_listeners,
246 CORBA_Object_duplicate (listener, ev));
248 fprintf (stderr, "registered %d for toolkit events named: %s\n",
255 impl_accessibility_application_register_object_event_listener (PortableServer_Servant servant,
256 Accessibility_EventListener listener,
257 const CORBA_char *event_name,
258 CORBA_Environment *ev)
260 guint spi_listener_id = 0;
261 const char *toolkit_specific_event_name =
262 lookup_toolkit_event_for_name (event_name);
263 if (toolkit_specific_event_name)
266 atk_add_global_event_listener (spi_application_object_event_listener,
267 toolkit_specific_event_name);
268 the_app->toolkit_listeners = g_list_append (the_app->toolkit_listeners,
269 CORBA_Object_duplicate (listener, ev));
272 fprintf (stderr, "registered %d for object events named: %s\n",
279 notify_listeners (GList *listeners, SpiAccessible *source, Accessibility_Event *e)
282 CORBA_Environment ev;
284 CORBA_exception_init (&ev);
286 for (l = listeners; l; l = l->next)
288 Accessibility_EventListener listener = l->data;
290 e->source = bonobo_object_dup_ref (BONOBO_OBJREF (source), &ev);
292 Accessibility_EventListener_notifyEvent (listener, e, &ev);
294 * when this (oneway) call completes, the CORBA refcount and
295 * Bonobo_Unknown refcount will be decremented by the recipient
297 CORBA_exception_free (&ev);
302 reverse_lookup_name_for_toolkit_event (char *toolkit_specific_name)
304 const char *generic_name;
305 SpiApplicationClass *klass = g_type_class_peek (SPI_APPLICATION_TYPE);
307 fprintf (stderr, "(reverse lookup) looking for %s in hash table.\n", toolkit_specific_name);
310 (const char *) g_hash_table_lookup (klass->generic_event_names, toolkit_specific_name);
312 fprintf (stderr, "toolkit event %s converted to %s\n", toolkit_specific_name, generic_name);
318 init_toolkit_names (GHashTable **generic_event_names, GHashTable **toolkit_event_names)
320 *toolkit_event_names = g_hash_table_new (g_str_hash, g_str_equal);
321 *generic_event_names = g_hash_table_new (g_str_hash, g_str_equal);
322 g_hash_table_insert (*toolkit_event_names,
323 "object:property-change",
324 "Gtk:AtkObject:property-change");
325 g_hash_table_insert (*generic_event_names,
326 "Gtk:AtkObject:property-change",
327 "object:property-change");
329 fprintf (stderr, "inserted spi_selection_changed hash\n");
334 spi_application_class_init (SpiApplicationClass *klass)
336 GObjectClass * object_class = (GObjectClass *) klass;
337 POA_Accessibility_Application__epv *epv = &klass->epv;
339 spi_application_parent_class = g_type_class_ref (SPI_ACCESSIBLE_TYPE);
341 object_class->finalize = spi_accessible_application_finalize;
343 epv->_get_toolkitName = impl_accessibility_application_get_toolkit_name;
344 epv->_get_version = impl_accessibility_application_get_version;
345 epv->_get_id = impl_accessibility_application_get_id;
346 epv->_set_id = impl_accessibility_application_set_id;
347 epv->registerToolkitEventListener = impl_accessibility_application_register_toolkit_event_listener;
348 init_toolkit_names (&klass->generic_event_names, &klass->toolkit_event_names);
352 spi_application_init (SpiApplication *application)
354 application->toolkit_listeners = NULL;
355 the_app = application;
358 BONOBO_TYPE_FUNC_FULL (SpiApplication,
359 Accessibility_Application,
360 PARENT_TYPE, spi_application);
363 spi_application_new (AtkObject *app_root)
365 SpiApplication *retval = g_object_new (SPI_APPLICATION_TYPE, NULL);
367 spi_base_construct (SPI_BASE (retval), G_OBJECT(app_root));