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>
31 * Our parent Gtk object type
33 #define PARENT_TYPE SPI_ACCESSIBLE_TYPE
36 * A pointer to our parent object class
38 static SpiAccessibleClass *spi_application_parent_class;
40 static SpiApplication *the_app;
44 static void notify_listeners (GList *listeners,
45 Accessibility_Event *e,
46 CORBA_Environment *ev);
48 static char *reverse_lookup_name_for_toolkit_event (char *toolkit_name);
51 lookup_toolkit_event_for_name (const char *generic_name)
53 char *toolkit_specific_name;
54 SpiApplicationClass *klass = g_type_class_peek (SPI_APPLICATION_TYPE);
56 fprintf (stderr, "looking for %s in hash table.\n", generic_name);
58 toolkit_specific_name =
59 (char *) g_hash_table_lookup (klass->toolkit_event_names, generic_name);
61 fprintf (stderr, "generic event %s converted to %s\n", generic_name, toolkit_specific_name);
63 return toolkit_specific_name;
67 * Implemented GObject::finalize
70 spi_accessible_application_finalize (GObject *object)
72 /* TODO: any necessary cleanup */
73 g_print ("application finalize called\n");
74 (G_OBJECT_CLASS (spi_application_parent_class))->finalize (object);
78 impl_accessibility_application_get_toolkit_name (PortableServer_Servant servant,
79 CORBA_Environment *ev)
81 return CORBA_string_dup (atk_get_toolkit_name ());
85 impl_accessibility_application_get_version (PortableServer_Servant servant,
86 CORBA_Environment *ev)
88 return CORBA_string_dup (atk_get_toolkit_version ());
92 impl_accessibility_application_get_id (PortableServer_Servant servant,
93 CORBA_Environment *ev)
95 SpiApplication *application = SPI_APPLICATION (
96 bonobo_object_from_servant (servant));
97 return application->id;
101 impl_accessibility_application_set_id (PortableServer_Servant servant,
103 CORBA_Environment *ev)
105 SpiApplication *application = SPI_APPLICATION (
106 bonobo_object_from_servant (servant));
107 application->id = id;
110 #define APP_STATIC_BUFF_SZ 64
113 spi_application_object_event_listener (GSignalInvocationHint *signal_hint,
114 guint n_param_values,
115 const GValue *param_values,
118 Accessibility_Event *e = Accessibility_Event__alloc();
121 SpiAccessible *source;
122 CORBA_Environment ev;
123 GSignalQuery signal_query;
125 char sbuf[APP_STATIC_BUFF_SZ];
128 g_signal_query (signal_hint->signal_id, &signal_query);
129 name = signal_query.signal_name;
130 fprintf (stderr, "Received (object) signal %s:%s\n",
131 g_type_name (signal_query.itype), name);
133 /* TODO: move GTK dependency out of app.c into bridge */
134 snprintf(sbuf, APP_STATIC_BUFF_SZ, "Gtk:%s:%s", g_type_name (signal_query.itype), name);
136 generic_name = reverse_lookup_name_for_toolkit_event (sbuf);
137 gobject = g_value_get_object (param_values + 0);
139 /* notify the actual listeners */
140 if (ATK_IS_IMPLEMENTOR (gobject))
142 aobject = atk_implementor_ref_accessible (ATK_IMPLEMENTOR (gobject));
144 else if (ATK_IS_OBJECT (gobject))
146 aobject = ATK_OBJECT (gobject);
147 g_object_ref (G_OBJECT (aobject));
152 g_error("received event from non-AtkImplementor");
155 g_return_val_if_fail (generic_name, FALSE);
158 source = spi_accessible_new (aobject);
159 e->type = CORBA_string_dup (generic_name);
160 e->source = BONOBO_OBJREF (source);
162 * no need to dup this ref, since it's inprocess
163 * and will be dup'ed by (inprocess) notify_listeners() call below
167 if (the_app) notify_listeners (the_app->toolkit_listeners, e, &ev);
168 /* unref because the in-process notify has called b_o_dup_ref (e->source) */
169 bonobo_object_release_unref (e->source, &ev);
171 /* and, decrement the refcount on atkobject, incremented moments ago:
172 * the call to spi_accessible_new() above should have added an extra ref */
173 g_object_unref (G_OBJECT (aobject));
180 spi_application_toolkit_event_listener (GSignalInvocationHint *signal_hint,
181 guint n_param_values,
182 const GValue *param_values,
185 Accessibility_Event *e = Accessibility_Event__alloc();
188 SpiAccessible *source;
189 CORBA_Environment ev;
190 GSignalQuery signal_query;
192 char sbuf[APP_STATIC_BUFF_SZ];
194 g_signal_query (signal_hint->signal_id, &signal_query);
195 name = signal_query.signal_name;
196 fprintf (stderr, "Received signal %s:%s\n", g_type_name (signal_query.itype), name);
198 /* TODO: move GTK dependency out of app.c into bridge */
199 snprintf(sbuf, APP_STATIC_BUFF_SZ, "Gtk:%s:%s", g_type_name (signal_query.itype), name);
201 gobject = g_value_get_object (param_values + 0);
202 /* notify the actual listeners */
203 if (ATK_IS_IMPLEMENTOR (gobject))
205 aobject = atk_implementor_ref_accessible (ATK_IMPLEMENTOR (gobject));
206 source = spi_accessible_new (aobject);
207 e->type = CORBA_string_dup (sbuf);
208 e->source = BONOBO_OBJREF (source);
211 if (the_app) notify_listeners (the_app->toolkit_listeners, e, &ev);
212 bonobo_object_unref (BONOBO_OBJECT (source));
213 g_object_unref (G_OBJECT (aobject));
219 impl_accessibility_application_register_toolkit_event_listener (PortableServer_Servant servant,
220 Accessibility_EventListener listener,
221 const CORBA_char *event_name,
222 CORBA_Environment *ev)
224 guint spi_listener_id;
226 atk_add_global_event_listener (spi_application_toolkit_event_listener, (char *) event_name);
227 the_app->toolkit_listeners = g_list_append (the_app->toolkit_listeners,
228 CORBA_Object_duplicate (listener, ev));
230 fprintf (stderr, "registered %d for toolkit events named: %s\n",
237 impl_accessibility_application_register_object_event_listener (PortableServer_Servant servant,
238 Accessibility_EventListener listener,
239 const CORBA_char *event_name,
240 CORBA_Environment *ev)
242 guint spi_listener_id = 0;
243 const char *toolkit_specific_event_name =
244 lookup_toolkit_event_for_name (event_name);
245 if (toolkit_specific_event_name)
248 atk_add_global_event_listener (spi_application_object_event_listener,
249 CORBA_string_dup (toolkit_specific_event_name));
250 the_app->toolkit_listeners = g_list_append (the_app->toolkit_listeners,
251 CORBA_Object_duplicate (listener, ev));
254 fprintf (stderr, "registered %d for object events named: %s\n",
261 notify_listeners (GList *listeners, Accessibility_Event *e, CORBA_Environment *ev)
265 if (listeners) n_listeners = g_list_length (listeners);
267 for (i=0; i<n_listeners; ++i) {
268 Accessibility_EventListener listener;
269 e->source = bonobo_object_dup_ref (e->source, ev);
270 listener = (Accessibility_EventListener) g_list_nth_data (listeners, i);
271 Accessibility_EventListener_notifyEvent (listener, e, ev);
273 * when this (oneway) call completes, the CORBA refcount and
274 * Bonobo_Unknown refcount will be decremented by the recipient
280 reverse_lookup_name_for_toolkit_event (char *toolkit_specific_name)
283 SpiApplicationClass *klass = g_type_class_peek (SPI_APPLICATION_TYPE);
285 fprintf (stderr, "(reverse lookup) looking for %s in hash table.\n", toolkit_specific_name);
288 (char *) g_hash_table_lookup (klass->generic_event_names, toolkit_specific_name);
290 fprintf (stderr, "toolkit event %s converted to %s\n", toolkit_specific_name, generic_name);
296 init_toolkit_names (GHashTable **generic_event_names, GHashTable **toolkit_event_names)
298 *toolkit_event_names = g_hash_table_new (g_str_hash, g_str_equal);
299 *generic_event_names = g_hash_table_new (g_str_hash, g_str_equal);
300 g_hash_table_insert (*toolkit_event_names,
301 "object:property-change",
302 "Gtk:AtkObject:property-change");
303 g_hash_table_insert (*generic_event_names,
304 "Gtk:AtkObject:property-change",
305 "object:property-change");
307 fprintf (stderr, "inserted spi_selection_changed hash\n");
312 spi_application_class_init (SpiApplicationClass *klass)
314 GObjectClass * object_class = (GObjectClass *) klass;
315 POA_Accessibility_Application__epv *epv = &klass->epv;
317 spi_application_parent_class = g_type_class_ref (SPI_ACCESSIBLE_TYPE);
319 object_class->finalize = spi_accessible_application_finalize;
321 epv->_get_toolkitName = impl_accessibility_application_get_toolkit_name;
322 epv->_get_version = impl_accessibility_application_get_version;
323 epv->_get_id = impl_accessibility_application_get_id;
324 epv->_set_id = impl_accessibility_application_set_id;
325 epv->registerToolkitEventListener = impl_accessibility_application_register_toolkit_event_listener;
326 init_toolkit_names (&klass->generic_event_names, &klass->toolkit_event_names);
330 spi_application_init (SpiApplication *application)
332 application->parent.atko = g_object_new (ATK_TYPE_OBJECT, NULL);
333 application->toolkit_listeners = NULL;
334 the_app = application;
337 BONOBO_TYPE_FUNC_FULL (SpiApplication,
338 Accessibility_Application,
339 PARENT_TYPE, spi_application);
342 spi_application_new (AtkObject *app_root)
344 SpiApplication *retval = g_object_new (SPI_APPLICATION_TYPE, NULL);
345 g_object_unref (retval->parent.atko);
346 retval->parent.atko = app_root;
347 g_object_ref (G_OBJECT (app_root));