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.
26 #include <libbonobo.h>
27 #include <orbit/orbit.h>
29 #include <atk/atkobject.h>
30 #include <atk/atknoopobject.h>
31 #include <libspi/Accessibility.h>
32 #include "accessible.h"
33 #include "application.h"
35 #undef SPI_BRIDGE_DEBUG
37 static CORBA_Environment ev;
38 static Accessibility_Registry registry;
39 static SpiApplication *this_app = NULL;
41 static gboolean bridge_idle_init (gpointer user_data);
42 static void bridge_focus_tracker (AtkObject *object);
43 static void bridge_exit_func (void);
44 static void register_atk_event_listeners (void);
45 static gboolean bridge_property_event_listener (GSignalInvocationHint *signal_hint,
47 const GValue *param_values,
49 static gboolean bridge_state_event_listener (GSignalInvocationHint *signal_hint,
51 const GValue *param_values,
53 static gboolean bridge_signal_listener (GSignalInvocationHint *signal_hint,
55 const GValue *param_values,
58 static gint bridge_key_listener (AtkKeyEventStruct *event,
62 gtk_module_init (gint *argc, gchar **argv[])
66 if (!bonobo_init (argc, *argv))
68 g_error ("Could not initialize Bonobo");
71 CORBA_exception_init(&ev);
73 registry = bonobo_activation_activate_from_id (
74 "OAFIID:Accessibility_Registry:proto0.1", 0, NULL, &ev);
76 if (ev._major != CORBA_NO_EXCEPTION)
78 g_error ("Accessibility app error: exception during "
79 "registry activation from id: %s\n",
80 CORBA_exception_id (&ev));
81 CORBA_exception_free (&ev);
84 if (CORBA_Object_is_nil (registry, &ev))
86 g_error ("Could not locate registry");
91 /* Create the accessible application server object */
93 this_app = spi_application_new (atk_get_root ());
95 fprintf (stderr, "About to register application\n");
97 Accessibility_Registry_registerApplication (registry,
98 BONOBO_OBJREF (this_app),
101 g_atexit (bridge_exit_func);
103 g_idle_add (bridge_idle_init, NULL);
109 bridge_idle_init (gpointer user_data)
111 register_atk_event_listeners ();
113 fprintf (stderr, "Application registered & listening\n");
119 register_atk_event_listeners (void)
122 * kludge to make sure the Atk interface types are registered, otherwise
123 * the AtkText signal handlers below won't get registered
125 GObject *ao = g_object_new (ATK_TYPE_OBJECT, NULL);
126 AtkObject *bo = atk_no_op_object_new (ao);
128 /* Register for focus event notifications, and register app with central registry */
130 atk_add_focus_tracker (bridge_focus_tracker);
131 atk_add_global_event_listener (bridge_property_event_listener, "Gtk:AtkObject:property-change");
132 atk_add_global_event_listener (bridge_signal_listener, "Gtk:AtkObject:children-changed");
133 atk_add_global_event_listener (bridge_signal_listener, "Gtk:AtkObject:visible-data-changed");
134 atk_add_global_event_listener (bridge_signal_listener, "Gtk:AtkSelection:selection-changed");
135 atk_add_global_event_listener (bridge_signal_listener, "Gtk:AtkText:text-selection-changed");
136 atk_add_global_event_listener (bridge_signal_listener, "Gtk:AtkText:text-changed");
137 atk_add_global_event_listener (bridge_signal_listener, "Gtk:AtkText:text-caret-moved");
138 atk_add_global_event_listener (bridge_signal_listener, "Gtk:AtkTable:row-inserted");
139 atk_add_global_event_listener (bridge_signal_listener, "Gtk:AtkTable:row-reordered");
140 atk_add_global_event_listener (bridge_signal_listener, "Gtk:AtkTable:row-deleted");
141 atk_add_global_event_listener (bridge_signal_listener, "Gtk:AtkTable:column-inserted");
142 atk_add_global_event_listener (bridge_signal_listener, "Gtk:AtkTable:column-reordered");
143 atk_add_global_event_listener (bridge_signal_listener, "Gtk:AtkTable:column-deleted");
144 atk_add_global_event_listener (bridge_signal_listener, "Gtk:AtkTable:model-changed");
145 atk_add_key_event_listener (bridge_key_listener, NULL);
147 g_object_unref (G_OBJECT (bo));
152 bridge_exit_func (void)
154 BonoboObject *app = (BonoboObject *) this_app;
156 fprintf (stderr, "exiting bridge\n");
165 * FIXME: this may be incorrect for apps that do their own bonobo
166 * shutdown, until we can explicitly shutdown to get the ordering
169 if (!bonobo_is_initialized ())
171 fprintf (stderr, "Re-initializing bonobo\n");
172 g_assert (bonobo_init (0, NULL));
173 g_assert (bonobo_activate ());
176 Accessibility_Registry_deregisterApplication (
177 registry, BONOBO_OBJREF (app), &ev);
179 bonobo_object_release_unref (registry, &ev);
181 bonobo_object_unref (app);
183 fprintf (stderr, "bridge exit func complete.\n");
185 if (g_getenv ("AT_BRIDGE_SHUTDOWN"))
187 g_assert (!bonobo_debug_shutdown ());
192 bridge_focus_tracker (AtkObject *object)
194 SpiAccessible *source;
195 Accessibility_Event e;
197 source = spi_accessible_new (object);
200 e.source = BONOBO_OBJREF (source);
204 Accessibility_Registry_notifyEvent (registry, &e, &ev);
206 CORBA_exception_free (&ev);
210 emit_eventv (GObject *gobject,
211 unsigned long detail1,
212 unsigned long detail2,
213 const char *format, ...)
216 Accessibility_Event e;
217 SpiAccessible *source;
220 va_start (args, format);
222 if (ATK_IS_IMPLEMENTOR (gobject))
224 aobject = atk_implementor_ref_accessible (ATK_IMPLEMENTOR (gobject));
225 source = spi_accessible_new (aobject);
226 g_object_unref (G_OBJECT (aobject));
228 else if (ATK_IS_OBJECT (gobject))
230 aobject = ATK_OBJECT (gobject);
231 source = spi_accessible_new (aobject);
237 g_error ("received property-change event from non-AtkImplementor");
242 e.type = g_strdup_vprintf (format, args);
243 e.source = BONOBO_OBJREF (source);
247 #ifdef SPI_BRIDGE_DEBUG
248 g_warning ("Emitting event '%s' (%d, %d) on %p",
249 e.type, e.detail1, e.detail2, source);
252 Accessibility_Registry_notifyEvent (registry, &e, &ev);
254 CORBA_exception_free (&ev);
263 bridge_property_event_listener (GSignalInvocationHint *signal_hint,
264 guint n_param_values,
265 const GValue *param_values,
268 AtkPropertyValues *values;
271 #ifdef SPI_BRIDGE_DEBUG
272 GSignalQuery signal_query;
275 g_signal_query (signal_hint->signal_id, &signal_query);
276 name = signal_query.signal_name;
278 fprintf (stderr, "Received (property) signal %s:%s\n",
279 g_type_name (signal_query.itype), name);
282 gobject = g_value_get_object (param_values + 0);
283 values = (AtkPropertyValues*) g_value_get_pointer (param_values + 1);
285 emit_eventv (gobject, 0, 0, "object:property-change:%s", values->property_name);
291 bridge_state_event_listener (GSignalInvocationHint *signal_hint,
292 guint n_param_values,
293 const GValue *param_values,
297 AtkPropertyValues *values;
298 #ifdef SPI_BRIDGE_DEBUG
299 GSignalQuery signal_query;
302 g_signal_query (signal_hint->signal_id, &signal_query);
303 name = signal_query.signal_name;
304 fprintf (stderr, "Received (state) signal %s:%s\n",
305 g_type_name (signal_query.itype), name);
308 gobject = g_value_get_object (param_values + 0);
309 values = (AtkPropertyValues*) g_value_get_pointer (param_values + 1);
311 emit_eventv (gobject,
312 (unsigned long) values->old_value.data[0].v_ulong,
313 (unsigned long) values->new_value.data[0].v_ulong,
314 "object:%s:?", values->property_name);
320 accessibility_init_keystroke_from_atk_key_event (Accessibility_KeyStroke *keystroke,
321 AtkKeyEventStruct *event)
326 g_print ("event %c (%d)\n", (int) event->keyval, (int) event->keycode);
332 g_print ("WARNING: NULL key event!");
335 keystroke->keyID = (CORBA_long) event->keyval;
336 keystroke->keycode = (CORBA_short) event->keycode;
337 keystroke->timestamp = (CORBA_unsigned_long) event->timestamp;
338 keystroke->modifiers = (CORBA_unsigned_short) (event->state & 0xFFFF);
342 case (ATK_KEY_EVENT_PRESS):
343 keystroke->type = Accessibility_KEY_PRESSED;
345 case (ATK_KEY_EVENT_RELEASE):
346 keystroke->type = Accessibility_KEY_RELEASED;
355 bridge_key_listener (AtkKeyEventStruct *event, gpointer data)
357 CORBA_boolean result;
358 Accessibility_KeyStroke key_event;
359 Accessibility_DeviceEventController controller =
360 Accessibility_Registry_getDeviceEventController (registry, &ev);
364 CORBA_exception_free (&ev);
370 accessibility_init_keystroke_from_atk_key_event (&key_event, event);
372 /* FIXME: this casting is just totaly bogus */
373 result = Accessibility_DeviceEventController_notifyListenersSync (
374 controller, (Accessibility_DeviceEvent *) &key_event, &ev);
376 CORBA_exception_free (&ev);
383 bridge_signal_listener (GSignalInvocationHint *signal_hint,
384 guint n_param_values,
385 const GValue *param_values,
389 GSignalQuery signal_query;
392 g_signal_query (signal_hint->signal_id, &signal_query);
394 name = signal_query.signal_name;
396 #ifdef SPI_BRIDGE_DEBUG
397 fprintf (stderr, "Received signal %s:%s\n",
398 g_type_name (signal_query.itype), name);
401 gobject = g_value_get_object (param_values + 0);
403 emit_eventv (gobject, 0, 0, "%s:%s", name, g_type_name (signal_query.itype));