2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002, 2003 Sun Microsystems Inc.,
6 * Copyright 2001, 2002, 2003 Ximian, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
31 #include <libbonobo.h>
32 #include <orbit/orbit.h>
34 #include <atk/atkobject.h>
35 #include <atk/atknoopobject.h>
36 #include <libspi/Accessibility.h>
37 #include <libspi/spi-private.h>
38 #include "remoteobject.h"
39 #include "accessible.h"
40 #include "application.h"
41 #include <bonobo-activation/bonobo-activation-register.h>
43 #undef SPI_BRIDGE_DEBUG
45 #define DBG(a,b) if(_dbg>=(a))b
48 static CORBA_Environment ev;
49 static Accessibility_Registry registry = CORBA_OBJECT_NIL;
50 static Accessibility_DeviceEventController device_event_controller = CORBA_OBJECT_NIL;
51 static SpiApplication *this_app = NULL;
52 static gboolean registry_died = FALSE;
53 static gboolean atk_listeners_registered = FALSE;
54 static gint toplevels = 0;
55 static gboolean exiting = FALSE;
57 static guint atk_signal_text_changed;
58 static guint atk_signal_children_changed;
59 static guint atk_signal_active_descendant_changed;
60 static guint atk_signal_text_selection_changed;
63 static guint atk_signal_row_reordered;
64 static guint atk_signal_row_inserted;
65 static guint atk_signal_row_deleted;
66 static guint atk_signal_column_reordered;
67 static guint atk_signal_column_inserted;
68 static guint atk_signal_column_deleted;
71 static guint atk_signal_link_selected;
72 static guint atk_signal_bounds_changed;
74 static Accessibility_Registry spi_atk_bridge_get_registry (void);
75 static void spi_atk_bridge_do_registration (void);
76 static void spi_atk_bridge_toplevel_added (AtkObject *object,
79 static void spi_atk_bridge_toplevel_removed (AtkObject *object,
83 static void spi_atk_bridge_exit_func (void);
84 static void spi_atk_register_event_listeners (void);
85 static void spi_atk_bridge_focus_tracker (AtkObject *object);
86 static void spi_atk_bridge_register_application (Accessibility_Registry registry);
87 static gboolean spi_atk_bridge_property_event_listener (GSignalInvocationHint *signal_hint,
89 const GValue *param_values,
92 static void spi_atk_bridge_init_nil (CORBA_any *any,
94 static void spi_atk_bridge_init_object (CORBA_any *any,
97 static void spi_atk_bridge_init_string (CORBA_any *any,
100 static void spi_atk_bridge_init_rect (CORBA_any *any,
105 spi_atk_bridge_window_event_listener (GSignalInvocationHint *signal_hint,
106 guint n_param_values,
107 const GValue *param_values,
110 spi_atk_bridge_state_event_listener (GSignalInvocationHint *signal_hint,
111 guint n_param_values,
112 const GValue *param_values,
114 static gboolean spi_atk_bridge_signal_listener (GSignalInvocationHint *signal_hint,
115 guint n_param_values,
116 const GValue *param_values,
118 static gint spi_atk_bridge_key_listener (AtkKeyEventStruct *event,
120 static void spi_atk_tidy_windows (void);
121 static void deregister_application (BonoboObject *app);
122 static void reinit_register_vars (void);
124 /* For automatic libgnome init */
125 extern void gnome_accessibility_module_init (void);
126 extern void gnome_accessibility_module_shutdown (void);
128 static int atk_bridge_initialized = FALSE;
129 static pid_t atk_bridge_pid = 0;
130 static guint atk_bridge_focus_tracker_id = 0;
131 static guint atk_bridge_key_event_listener_id = 0;
132 static GArray *listener_ids = NULL;
135 * These exported symbols are hooked by gnome-program
136 * to provide automatic module initialization and shutdown.
138 extern void gnome_accessibility_module_init (void);
139 extern void gnome_accessibility_module_shutdown (void);
142 spi_atk_bridge_init_event_type_consts ()
144 static gboolean done = FALSE;
149 atk_signal_children_changed = g_signal_lookup ("children_changed",
151 atk_signal_text_changed = g_signal_lookup ("text_changed",
153 atk_signal_bounds_changed = g_signal_lookup ("bounds_changed",
155 atk_signal_active_descendant_changed =
156 g_signal_lookup ("active_descendant_changed",
158 atk_signal_link_selected = g_signal_lookup ("link_selected",
160 atk_signal_text_selection_changed = g_signal_lookup ("text_selection_changed",
166 atk_bridge_init (gint *argc, gchar **argv[])
168 const char *debug_env_string = g_getenv ("AT_SPI_DEBUG");
171 if (atk_bridge_initialized)
175 atk_bridge_initialized = TRUE;
176 atk_bridge_pid = getpid ();
178 if (g_getenv ("ATK_BRIDGE_REDIRECT_LOG"))
180 fname = g_strconcat ("/tmp/", g_get_prgname (), ".at-spi-log", NULL);
181 /* make sure we're not being redirected - security issue */
182 if (!g_file_test (fname, G_FILE_TEST_IS_SYMLINK))
183 freopen (fname, "w", stderr);
187 if (debug_env_string)
188 _dbg = (int) g_ascii_strtod (debug_env_string, NULL);
190 if (!bonobo_init (argc, argv ? *argv : NULL))
192 g_error ("Could not initialize Bonobo");
195 /* Create the accessible application server object */
196 this_app = spi_application_new (atk_get_root ());
198 * We only want to enable the bridge for top level
199 * applications, we detect bonobo components by seeing
200 * if they were activated with the intention of extracting
201 * an impl. by IID - very solid.
203 if (bonobo_activation_iid_get ())
205 DBG (1, g_message ("Found Bonobo component\n"));
206 g_signal_connect (atk_get_root (),
207 "children-changed::add",
208 (GCallback) spi_atk_bridge_toplevel_added,
210 g_signal_connect (atk_get_root (),
211 "children-changed::remove",
212 (GCallback) spi_atk_bridge_toplevel_removed,
217 spi_atk_bridge_do_registration ();
219 spi_atk_register_event_listeners ();
220 spi_atk_bridge_init_event_type_consts ();
227 spi_atk_bridge_do_registration (void)
229 CORBA_Environment ev;
231 CORBA_exception_init(&ev);
233 if (spi_atk_bridge_get_registry () == CORBA_OBJECT_NIL)
235 g_error ("Could not locate registry");
240 /* Create the accessible application server object */
241 if (this_app == NULL)
242 this_app = spi_application_new (atk_get_root ());
244 DBG (1, g_message ("About to register application\n"));
246 spi_atk_bridge_register_application (spi_atk_bridge_get_registry ());
248 g_atexit (spi_atk_bridge_exit_func);
250 DBG (1, g_message ("Application registered & listening\n"));
255 spi_atk_bridge_toplevel_added (AtkObject *object,
261 spi_atk_bridge_do_registration ();
267 spi_atk_bridge_toplevel_removed (AtkObject *object,
271 BonoboObject *app = (BonoboObject *) this_app;
276 deregister_application (app);
277 reinit_register_vars ();
281 g_warning ("More toplevels removed than added\n");
287 spi_atk_bridge_register_application (Accessibility_Registry registry)
289 Accessibility_Registry_registerApplication (spi_atk_bridge_get_registry (),
290 BONOBO_OBJREF (this_app),
295 * Returns a 'canonicalized' value for DISPLAY,
296 * with the screen number stripped off if present.
299 spi_display_name (void)
301 static const char *canonical_display_name = NULL;
302 if (!canonical_display_name)
304 const gchar *display_env = g_getenv ("AT_SPI_DISPLAY");
307 display_env = g_getenv ("DISPLAY");
308 if (!display_env || !display_env[0])
309 canonical_display_name = ":0";
312 gchar *display_p, *screen_p;
313 canonical_display_name = g_strdup (display_env);
314 display_p = strrchr (canonical_display_name, ':');
315 screen_p = strrchr (canonical_display_name, '.');
316 if (screen_p && display_p && (screen_p > display_p))
324 canonical_display_name = display_env;
327 return canonical_display_name;
330 static Accessibility_Registry
331 spi_atk_bridge_get_registry (void)
333 CORBA_Environment ev;
335 if (registry_died || (registry == CORBA_OBJECT_NIL)) {
336 CORBA_exception_init (&ev);
340 return CORBA_OBJECT_NIL;
342 DBG (1, g_warning ("registry died! restarting..."));
344 bonobo_activation_set_activation_env_value ("AT_SPI_DISPLAY", spi_display_name ());
346 registry = bonobo_activation_activate_from_id (
347 "OAFIID:Accessibility_Registry:1.0", 0, NULL, &ev);
349 if (ev._major != CORBA_NO_EXCEPTION)
351 g_error ("Accessibility app error: exception during "
352 "registry activation from id: %s\n",
353 CORBA_exception_id (&ev));
354 CORBA_exception_free (&ev);
357 if (registry_died && registry) {
358 registry_died = FALSE;
359 spi_atk_bridge_register_application (registry);
365 static Accessibility_DeviceEventController
366 spi_atk_bridget_get_dec (void)
368 CORBA_Environment ev;
370 if (device_event_controller != CORBA_OBJECT_NIL)
372 if (ORBit_small_get_connection_status (device_event_controller)
373 == ORBIT_CONNECTION_CONNECTED)
374 return device_event_controller;
377 CORBA_exception_init (&ev);
379 device_event_controller =
380 Accessibility_Registry_getDeviceEventController (
381 spi_atk_bridge_get_registry (), &ev);
385 g_warning (_("failure: no device event controller found.\n"));
386 registry_died = TRUE;
387 device_event_controller = CORBA_OBJECT_NIL;
390 return device_event_controller;
394 gtk_module_init (gint *argc, gchar **argv[])
396 return atk_bridge_init (argc, argv);
400 add_signal_listener (const char *signal_name)
404 id = atk_add_global_event_listener (
405 spi_atk_bridge_signal_listener, signal_name);
407 g_array_append_val (listener_ids, id);
411 spi_atk_register_event_listeners (void)
414 * kludge to make sure the Atk interface types are registered, otherwise
415 * the AtkText signal handlers below won't get registered
418 GObject *ao = g_object_new (ATK_TYPE_OBJECT, NULL);
419 AtkObject *bo = atk_no_op_object_new (ao);
422 if (atk_listeners_registered) return;
424 atk_listeners_registered = TRUE;
426 /* Register for focus event notifications, and register app with central registry */
428 listener_ids = g_array_sized_new (FALSE, TRUE, sizeof (guint), 16);
430 atk_bridge_focus_tracker_id = atk_add_focus_tracker (spi_atk_bridge_focus_tracker);
432 id = atk_add_global_event_listener (spi_atk_bridge_property_event_listener,
433 "Gtk:AtkObject:property-change");
434 g_array_append_val (listener_ids, id);
435 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
437 g_array_append_val (listener_ids, id);
438 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
440 g_array_append_val (listener_ids, id);
441 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
443 g_array_append_val (listener_ids, id);
444 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
446 g_array_append_val (listener_ids, id);
447 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
449 g_array_append_val (listener_ids, id);
450 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
452 g_array_append_val (listener_ids, id);
453 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
454 "window:deactivate");
455 g_array_append_val (listener_ids, id);
456 id = atk_add_global_event_listener (spi_atk_bridge_state_event_listener,
457 "Gtk:AtkObject:state-change");
458 g_array_append_val (listener_ids, id);
460 add_signal_listener ("Gtk:AtkObject:children-changed");
461 add_signal_listener ("Gtk:AtkObject:visible-data-changed");
462 add_signal_listener ("Gtk:AtkObject:active-descendant-changed");
463 add_signal_listener ("Gtk:AtkComponent:bounds-changed");
464 add_signal_listener ("Gtk:AtkSelection:selection-changed");
465 add_signal_listener ("Gtk:AtkText:text-selection-changed");
466 add_signal_listener ("Gtk:AtkText:text-changed");
467 add_signal_listener ("Gtk:AtkText:text-caret-moved");
468 add_signal_listener ("Gtk:AtkTable:row-inserted");
469 add_signal_listener ("Gtk:AtkTable:row-reordered");
470 add_signal_listener ("Gtk:AtkTable:row-deleted");
471 add_signal_listener ("Gtk:AtkTable:column-inserted");
472 add_signal_listener ("Gtk:AtkTable:column-reordered");
473 add_signal_listener ("Gtk:AtkTable:column-deleted");
474 add_signal_listener ("Gtk:AtkTable:model-changed");
475 add_signal_listener ("Gtk:AtkHypertext:link-selected");
477 * May add the following listeners to implement preemptive key listening for GTK+
479 * atk_add_global_event_listener (spi_atk_bridge_widgetkey_listener, "Gtk:GtkWidget:key-press-event");
480 * atk_add_global_event_listener (spi_atk_bridge_widgetkey_listener, "Gtk:GtkWidget:key-release-event");
482 atk_bridge_key_event_listener_id = atk_add_key_event_listener (
483 spi_atk_bridge_key_listener, NULL);
485 g_object_unref (G_OBJECT (bo));
490 deregister_application (BonoboObject *app)
492 Accessibility_Registry registry = spi_atk_bridge_get_registry ();
493 Accessibility_Registry_deregisterApplication (registry, BONOBO_OBJREF (app), &ev);
495 device_event_controller = bonobo_object_release_unref (device_event_controller, &ev);
496 registry = bonobo_object_release_unref (registry, &ev);
498 app = bonobo_object_unref (app);
502 spi_atk_bridge_exit_func (void)
504 BonoboObject *app = (BonoboObject *) this_app;
506 DBG (1, g_message ("exiting bridge\n"));
513 if (atk_bridge_pid != getpid ())
520 * Check whether we still have windows which have not been deleted.
522 spi_atk_tidy_windows ();
524 * FIXME: this may be incorrect for apps that do their own bonobo
525 * shutdown, until we can explicitly shutdown to get the ordering
528 if (!bonobo_is_initialized ())
530 DBG (1, g_warning ("Re-initializing bonobo\n"));
531 g_assert (bonobo_init (0, NULL));
532 g_assert (bonobo_activate ());
536 deregister_application (app);
538 DBG (1, g_message ("bridge exit func complete.\n"));
540 if (g_getenv ("AT_BRIDGE_SHUTDOWN"))
542 g_assert (!bonobo_debug_shutdown ());
547 gnome_accessibility_module_init (void)
549 atk_bridge_init (NULL, NULL);
551 if (g_getenv ("AT_BRIDGE_SHUTDOWN"))
553 g_print("Atk Accessibility bridge initialized\n");
558 gnome_accessibility_module_shutdown (void)
560 BonoboObject *app = (BonoboObject *) this_app;
562 GArray *ids = listener_ids;
564 if (!atk_bridge_initialized)
568 atk_bridge_initialized = FALSE;
571 if (g_getenv ("AT_BRIDGE_SHUTDOWN"))
573 g_print("Atk Accessibility bridge shutdown\n");
577 atk_remove_focus_tracker (atk_bridge_focus_tracker_id);
579 for (i = 0; ids && i < ids->len; i++)
581 atk_remove_global_event_listener (g_array_index (ids, guint, i));
584 atk_remove_key_event_listener (atk_bridge_key_event_listener_id);
586 deregister_application (app);
590 spi_atk_bridge_focus_tracker (AtkObject *object)
592 SpiAccessible *source;
593 Accessibility_Event e;
595 source = spi_accessible_new (object);
597 CORBA_exception_init (&ev);
600 e.source = BONOBO_OBJREF (source);
603 spi_atk_bridge_init_nil (&e.any_data, object);
605 registry_died = TRUE;
607 Accessibility_Registry_notifyEvent (spi_atk_bridge_get_registry (),
610 registry_died = TRUE;
612 bonobo_object_unref (source);
614 CORBA_exception_free (&ev);
618 spi_atk_emit_eventv (const GObject *gobject,
622 const char *format, ...)
625 Accessibility_Event e;
627 SpiAccessible *source = NULL;
628 Accessibility_Registry registry;
630 #ifdef SPI_BRIDGE_DEBUG
631 CORBA_string s = NULL;
634 va_start (args, format);
636 if (ATK_IS_IMPLEMENTOR (gobject))
638 aobject = atk_implementor_ref_accessible (ATK_IMPLEMENTOR (gobject));
639 source = spi_accessible_new (aobject);
640 g_object_unref (G_OBJECT (aobject));
642 else if (ATK_IS_OBJECT (gobject))
644 aobject = ATK_OBJECT (gobject);
645 if (SPI_IS_REMOTE_OBJECT (aobject))
646 e.source = spi_remote_object_get_accessible (SPI_REMOTE_OBJECT (aobject));
648 source = spi_accessible_new (aobject);
653 DBG (0, g_warning ("received property-change event from non-AtkImplementor"));
657 name = atk_object_get_name (aobject);
658 e.type = g_strdup_vprintf (format, args);
659 if (source) e.source = BONOBO_OBJREF (source);
662 if (any) e.any_data = *any;
663 else spi_atk_bridge_init_nil (&e.any_data, aobject);
665 #ifdef SPI_BRIDGE_DEBUG
666 if (e.source != CORBA_OBJECT_NIL)
667 s = Accessibility_Accessible__get_name (e.source, &ev);
668 g_message ("Emitting event '%s' (%lu, %lu) on %s",
669 e.type, e.detail1, e.detail2, s);
672 CORBA_exception_init (&ev);
673 registry = spi_atk_bridge_get_registry ();
678 Accessibility_Registry_notifyEvent (registry,
680 #ifdef SPI_BRIDGE_DEBUG
681 if (ev._major != CORBA_NO_EXCEPTION)
682 g_message ("error emitting event %s, (%d) %s",
685 CORBA_exception_id(&ev));
687 if (BONOBO_EX (&ev)) registry_died = TRUE;
690 bonobo_object_unref (BONOBO_OBJECT (source));
692 Bonobo_Unknown_unref (e.source, &ev);
694 CORBA_exception_free (&ev);
698 if (!any && e.any_data._release) CORBA_free (e.any_data._value);
705 spi_atk_bridge_property_event_listener (GSignalInvocationHint *signal_hint,
706 guint n_param_values,
707 const GValue *param_values,
710 AtkPropertyValues *values;
712 const gchar *prop_name;
714 const gchar *sp = NULL;
716 SpiAccessible *s_ao = NULL;
719 const gchar *name = NULL;
721 #ifdef SPI_BRIDGE_DEBUG
722 GSignalQuery signal_query;
723 const gchar *signame;
726 g_signal_query (signal_hint->signal_id, &signal_query);
727 signame = signal_query.signal_name;
729 s2 = g_type_name (G_OBJECT_TYPE (g_value_get_object (param_values + 0)));
730 s = atk_object_get_name (ATK_OBJECT (g_value_get_object (param_values + 0)));
731 values = (AtkPropertyValues*) g_value_get_pointer (param_values + 1);
732 DBG (2, g_message ("Received (property) signal %s:%s:%s from object %s (gail %s)\n",
733 g_type_name (signal_query.itype), signame, values->property_name, s, s2));
737 gobject = g_value_get_object (param_values + 0);
738 name = atk_object_get_name (ATK_OBJECT (gobject));
739 values = (AtkPropertyValues*) g_value_get_pointer (param_values + 1);
741 prop_name = values->property_name;
742 if (strcmp (prop_name, "accessible-name") == 0)
744 spi_atk_bridge_init_string (&any,
745 ATK_OBJECT (gobject),
748 else if (strcmp (prop_name, "accessible-description") == 0)
750 sp = atk_object_get_description (ATK_OBJECT (gobject));
751 spi_atk_bridge_init_string (&any,
752 ATK_OBJECT (gobject),
755 else if (strcmp (prop_name, "accessible-parent") == 0)
757 ao = atk_object_get_parent (ATK_OBJECT (gobject));
760 s_ao = spi_accessible_new (ao);
761 c_obj = BONOBO_OBJREF (s_ao);
762 spi_atk_bridge_init_object (&any,
763 ATK_OBJECT (gobject),
768 spi_atk_bridge_init_nil (&any,
769 ATK_OBJECT (gobject));
772 else if (strcmp (prop_name, "accessible-table-summary") == 0)
774 ao = atk_table_get_summary (ATK_TABLE (gobject));
777 s_ao = spi_accessible_new (ao);
778 c_obj = BONOBO_OBJREF (s_ao);
779 spi_atk_bridge_init_object (&any,
780 ATK_OBJECT (gobject),
785 spi_atk_bridge_init_nil (&any,
786 ATK_OBJECT (gobject));
789 else if (strcmp (prop_name, "accessible-table-column-header") == 0)
791 i = g_value_get_int (&(values->new_value));
792 ao = atk_table_get_column_header (ATK_TABLE (gobject), i);
795 s_ao = spi_accessible_new (ao);
796 c_obj = BONOBO_OBJREF (s_ao);
797 spi_atk_bridge_init_object (&any,
798 ATK_OBJECT (gobject),
803 spi_atk_bridge_init_nil (&any, ATK_OBJECT (gobject));
806 else if (strcmp (prop_name, "accessible-table-row-header") == 0)
808 i = g_value_get_int (&(values->new_value));
809 ao = atk_table_get_row_header (ATK_TABLE (gobject), i);
812 s_ao = spi_accessible_new (ao);
813 c_obj = BONOBO_OBJREF (s_ao);
814 spi_atk_bridge_init_object (&any, ATK_OBJECT (gobject), &c_obj);
818 spi_atk_bridge_init_nil (&any, ATK_OBJECT (gobject));
821 else if (strcmp (prop_name, "accessible-table-row-description") == 0)
823 i = g_value_get_int (&(values->new_value));
824 sp = atk_table_get_row_description (ATK_TABLE (gobject), i);
825 spi_atk_bridge_init_string (&any, ATK_OBJECT (gobject),
828 else if (strcmp (prop_name, "accessible-table-column-description") == 0)
830 i = g_value_get_int (&(values->new_value));
831 sp = atk_table_get_column_description (ATK_TABLE (gobject), i);
832 spi_atk_bridge_init_string (&any, ATK_OBJECT (gobject),
835 else if (strcmp (prop_name, "accessible-table-caption-object") == 0)
837 ao = atk_table_get_caption (ATK_TABLE (gobject));
838 sp = atk_object_get_name (ao);
839 spi_atk_bridge_init_string (&any, ATK_OBJECT (gobject),
844 spi_atk_bridge_init_nil (&any, ATK_OBJECT (gobject));
847 spi_atk_emit_eventv (gobject, 0, 0, &any,
848 "object:property-change:%s", prop_name);
855 spi_atk_bridge_state_event_listener (GSignalInvocationHint *signal_hint,
856 guint n_param_values,
857 const GValue *param_values,
861 gchar *property_name;
863 unsigned long detail1;
864 #ifdef SPI_BRIDGE_DEBUG
865 GSignalQuery signal_query;
868 g_signal_query (signal_hint->signal_id, &signal_query);
869 name = signal_query.signal_name;
870 fprintf (stderr, "Received (state) signal %s:%s\n",
871 g_type_name (signal_query.itype), name);
874 gobject = g_value_get_object (param_values + 0);
875 property_name = g_strdup (g_value_get_string (param_values + 1));
876 detail1 = (g_value_get_boolean (param_values + 2))
878 type = g_strdup_printf ("object:state-changed:%s", property_name);
879 spi_atk_emit_eventv (gobject,
884 g_free (property_name);
890 spi_init_keystroke_from_atk_key_event (Accessibility_DeviceEvent *keystroke,
891 AtkKeyEventStruct *event)
896 g_print ("event %c (%d)\n", (int) event->keyval, (int) event->keycode);
901 { /* this doesn't really need translating */
902 g_print (_("WARNING: NULL key event reported."));
905 keystroke->id = (CORBA_long) event->keyval;
906 keystroke->hw_code = (CORBA_short) event->keycode;
907 keystroke->timestamp = (CORBA_unsigned_long) event->timestamp;
908 keystroke->modifiers = (CORBA_unsigned_short) (event->state & 0xFFFF);
913 keystroke->event_string = CORBA_string_dup (event->string);
914 c = g_utf8_get_char_validated (event->string, -1);
915 if (c > 0 && g_unichar_isprint (c))
916 keystroke->is_text = CORBA_TRUE;
918 keystroke->is_text = CORBA_FALSE;
922 keystroke->event_string = CORBA_string_dup ("");
923 keystroke->is_text = CORBA_FALSE;
927 case (ATK_KEY_EVENT_PRESS):
928 keystroke->type = Accessibility_KEY_PRESSED_EVENT;
930 case (ATK_KEY_EVENT_RELEASE):
931 keystroke->type = Accessibility_KEY_RELEASED_EVENT;
938 g_print ("key_event type %d; val=%d code=%d modifiers=%x name=%s is_text=%d, time=%lx\n",
939 (int) keystroke->type, (int) keystroke->id, (int) keystroke->hw_code,
940 (int) keystroke->modifiers,
941 keystroke->event_string, (int) keystroke->is_text, (unsigned long) keystroke->timestamp);
946 spi_atk_bridge_key_listener (AtkKeyEventStruct *event, gpointer data)
948 CORBA_boolean result;
949 Accessibility_DeviceEvent key_event;
951 CORBA_exception_init (&ev);
953 spi_init_keystroke_from_atk_key_event (&key_event, event);
955 result = Accessibility_DeviceEventController_notifyListenersSync (
956 spi_atk_bridget_get_dec (), &key_event, &ev);
958 if (key_event.event_string) CORBA_free (key_event.event_string);
960 if (BONOBO_EX(&ev)) {
962 CORBA_exception_free (&ev);
969 spi_atk_bridge_signal_listener (GSignalInvocationHint *signal_hint,
970 guint n_param_values,
971 const GValue *param_values,
975 GSignalQuery signal_query;
982 gint detail1 = 0, detail2 = 0;
983 SpiAccessible *s_ao = NULL;
984 #ifdef SPI_BRIDGE_DEBUG
988 g_signal_query (signal_hint->signal_id, &signal_query);
990 name = signal_query.signal_name;
991 if (signal_hint->detail)
992 detail = g_quark_to_string (signal_hint->detail);
996 #ifdef SPI_BRIDGE_DEBUG
997 s2 = g_type_name (G_OBJECT_TYPE (g_value_get_object (param_values + 0)));
998 s = atk_object_get_name (ATK_OBJECT (g_value_get_object (param_values + 0)));
999 fprintf (stderr, "Received signal %s:%s detail: %s from object %s (gail %s)\n",
1000 g_type_name (signal_query.itype), name,
1001 detail ? detail : "<NULL>", s ? s : "<NULL>" , s2);
1004 gobject = g_value_get_object (param_values + 0);
1006 if (signal_query.signal_id == atk_signal_active_descendant_changed)
1008 gpointer child = g_value_get_pointer (param_values + 1);
1010 g_return_val_if_fail (ATK_IS_OBJECT (child), TRUE);
1012 ao = ATK_OBJECT (child);
1014 detail1 = atk_object_get_index_in_parent (ao);
1015 s_ao = spi_accessible_new (ao);
1016 c_obj = BONOBO_OBJREF (s_ao);
1017 spi_atk_bridge_init_object (&any, ATK_OBJECT (gobject), &c_obj);
1019 else if (signal_query.signal_id == atk_signal_link_selected)
1021 if (G_VALUE_TYPE (param_values + 1) == G_TYPE_INT)
1022 detail1 = g_value_get_int (param_values + 1);
1023 spi_atk_bridge_init_nil (&any, ATK_OBJECT (gobject));
1025 else if (signal_query.signal_id == atk_signal_bounds_changed)
1027 AtkRectangle *atk_rect = NULL;
1029 if (G_VALUE_HOLDS_BOXED (param_values + 1))
1030 atk_rect = g_value_get_boxed (param_values + 1);
1031 spi_atk_bridge_init_rect (&any, ATK_OBJECT (gobject), atk_rect);
1033 else if ((signal_query.signal_id == atk_signal_children_changed) && gobject)
1035 detail1 = g_value_get_uint (param_values + 1);
1036 ao = atk_object_ref_accessible_child (ATK_OBJECT (gobject),
1040 s_ao = spi_accessible_new (ao);
1041 c_obj = BONOBO_OBJREF (s_ao);
1042 spi_atk_bridge_init_object (&any, ATK_OBJECT (gobject), &c_obj);
1043 g_object_unref (ao);
1047 spi_atk_bridge_init_nil (&any, ATK_OBJECT (gobject));
1052 if (n_param_values >= 2)
1054 if (G_VALUE_TYPE (param_values + 1) == G_TYPE_INT)
1055 detail1 = g_value_get_int (param_values + 1);
1056 if (n_param_values >= 3)
1058 if (G_VALUE_TYPE (param_values + 2) == G_TYPE_INT)
1059 detail2 = g_value_get_int (param_values + 2);
1063 if (signal_query.signal_id == atk_signal_text_changed)
1065 sp = atk_text_get_text (ATK_TEXT (gobject),
1068 spi_atk_bridge_init_string (&any, ATK_OBJECT (gobject),
1071 else if (signal_query.signal_id == atk_signal_text_selection_changed)
1073 /* Return NULL as the selected string */
1074 spi_atk_bridge_init_nil (&any, ATK_OBJECT (gobject));
1078 spi_atk_bridge_init_nil (&any, ATK_OBJECT (gobject));
1083 spi_atk_emit_eventv (gobject, detail1, detail2, &any,
1084 "object:%s:%s", name, detail);
1086 spi_atk_emit_eventv (gobject, detail1, detail2, &any,
1096 spi_atk_bridge_window_event_listener (GSignalInvocationHint *signal_hint,
1097 guint n_param_values,
1098 const GValue *param_values,
1102 GSignalQuery signal_query;
1104 const gchar *name, *s;
1105 #ifdef SPI_BRIDGE_DEBUG
1109 g_signal_query (signal_hint->signal_id, &signal_query);
1111 name = signal_query.signal_name;
1113 #ifdef SPI_BRIDGE_DEBUG
1114 s2 = g_type_name (G_OBJECT_TYPE (g_value_get_object (param_values + 0)));
1115 s = atk_object_get_name (ATK_OBJECT (g_value_get_object (param_values + 0)));
1116 fprintf (stderr, "Received signal %s:%s from object %s (gail %s)\n",
1117 g_type_name (signal_query.itype), name, s ? s : "<NULL>" , s2);
1120 gobject = g_value_get_object (param_values + 0);
1122 s = atk_object_get_name (ATK_OBJECT (gobject));
1123 spi_atk_bridge_init_string (&any, ATK_OBJECT (gobject), (gchar **) &s);
1125 spi_atk_emit_eventv (gobject, 0, 0, &any,
1131 spi_atk_tidy_windows (void)
1137 root = atk_get_root ();
1138 n_children = atk_object_get_n_accessible_children (root);
1139 for (i = 0; i < n_children; i++)
1142 AtkStateSet *stateset;
1146 child = atk_object_ref_accessible_child (root, i);
1147 stateset = atk_object_ref_state_set (child);
1149 name = atk_object_get_name (child);
1150 spi_atk_bridge_init_string (&any, child, (gchar**) &name);
1151 if (atk_state_set_contains_state (stateset, ATK_STATE_ACTIVE))
1153 spi_atk_emit_eventv (G_OBJECT (child), 0, 0, &any, "window:deactivate");
1157 g_object_unref (stateset);
1159 spi_atk_emit_eventv (G_OBJECT (child), 0, 0, &any, "window:destroy");
1160 g_object_unref (child);
1165 reinit_register_vars (void)
1167 registry = CORBA_OBJECT_NIL;
1168 device_event_controller = CORBA_OBJECT_NIL;
1173 spi_atk_bridge_init_base (CORBA_any *any, AtkObject *obj,
1174 Accessibility_Application *app, Accessibility_Role *role,
1177 const gchar *s = atk_object_get_name (obj);
1178 *app = spi_accessible_new_return (atk_get_root (), FALSE, NULL);
1179 *role = spi_role_from_atk_role (atk_object_get_role (obj));
1180 *name = s ? s : ""; /* string gets dup-ed in util.c spi_init_any_* */
1184 spi_atk_bridge_init_nil (CORBA_any *any, AtkObject *obj)
1186 Accessibility_Application app = CORBA_OBJECT_NIL;
1187 Accessibility_Role role = Accessibility_ROLE_UNKNOWN;
1189 spi_atk_bridge_init_base (any, obj, &app, &role, &name);
1190 spi_init_any_nil (any, app, role, name);
1194 spi_atk_bridge_init_object (CORBA_any *any, AtkObject *obj, CORBA_Object *c_obj)
1196 Accessibility_Application app = CORBA_OBJECT_NIL;
1197 Accessibility_Role role = Accessibility_ROLE_UNKNOWN;
1199 spi_atk_bridge_init_base (any, obj, &app, &role, &name);
1200 spi_init_any_object (any, app, role, name, c_obj);
1204 spi_atk_bridge_init_string (CORBA_any *any, AtkObject *obj, gchar **string)
1206 Accessibility_Application app = CORBA_OBJECT_NIL;
1207 Accessibility_Role role = Accessibility_ROLE_UNKNOWN;
1209 spi_atk_bridge_init_base (any, obj, &app, &role, &name);
1210 spi_init_any_string (any, app, role, name, string);
1214 spi_atk_bridge_init_rect (CORBA_any *any, AtkObject *obj, AtkRectangle *rect)
1216 Accessibility_Application app = CORBA_OBJECT_NIL;
1217 Accessibility_Role role = Accessibility_ROLE_UNKNOWN;
1219 spi_atk_bridge_init_base (any, obj, &app, &role, &name);
1220 spi_init_any_rect (any, app, role, name, rect);