* atk-bridge/bridge.c:
[platform/core/uifw/at-spi2-atk.git] / atk-bridge / bridge.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001, 2002 Sun Microsystems Inc.,
6  * Copyright 2001, 2002 Ximian, Inc.
7  *
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.
12  *
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.
17  *
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.
22  */
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <libbonobo.h>
28 #include <orbit/orbit.h>
29 #include <atk/atk.h>
30 #include <atk/atkobject.h>
31 #include <atk/atknoopobject.h>
32 #include <libspi/Accessibility.h>
33 #include <libspi/spi-private.h>
34 #include "accessible.h"
35 #include "application.h"
36
37 #include <bonobo-activation/bonobo-activation-register.h>
38
39 #undef SPI_BRIDGE_DEBUG
40
41 #define DBG(a,b) if(_dbg>=(a))b
42
43 static int _dbg = 0;
44 static char *spi_nil_string = "";
45
46 static CORBA_Environment ev;
47 static Accessibility_Registry registry = NULL;
48 static SpiApplication *this_app = NULL;
49 static gboolean registry_died = FALSE;
50 static gboolean atk_listeners_registered = FALSE;
51 static guint toplevel_handler;
52
53 /* NOT YET USED
54    static GQuark atk_quark_property_changed_name;
55    static GQuark atk_quark_property_changed_description;
56    static GQuark atk_quark_property_changed_parent;
57    static GQuark atk_quark_property_changed_role;
58    static GQuark atk_quark_property_changed_table_caption;
59    static GQuark atk_quark_property_changed_table_column_description;
60    static GQuark atk_quark_property_changed_table_row_description;
61    static guint atk_signal_property_changed;
62 */
63
64 static guint atk_signal_text_changed;
65 static guint atk_signal_child_changed;
66 static guint atk_signal_active_descendant_changed;
67
68 /* NOT YET USED
69    static guint atk_signal_text_selection_changed;
70    static guint atk_signal_row_reordered;
71    static guint atk_signal_row_inserted;
72    static guint atk_signal_row_deleted;
73    static guint atk_signal_column_reordered;
74    static guint atk_signal_column_inserted;
75    static guint atk_signal_column_deleted;
76 */
77
78 static Accessibility_Registry spi_atk_bridge_get_registry (void);
79 static void     spi_atk_bridge_do_registration         (void);
80 static void     spi_atk_bridge_toplevel_added          (AtkObject             *object,
81                                                         guint                 index,
82                                                         AtkObject             *child);
83
84 static void     spi_atk_bridge_exit_func               (void);
85 static void     spi_atk_register_event_listeners       (void);
86 static void     spi_atk_bridge_focus_tracker           (AtkObject             *object);
87 static void     spi_atk_bridge_register_application    (Accessibility_Registry registry);
88 static gboolean spi_atk_bridge_property_event_listener (GSignalInvocationHint *signal_hint,
89                                                         guint                  n_param_values,
90                                                         const GValue          *param_values,
91                                                         gpointer               data);
92 static gboolean
93 spi_atk_bridge_window_event_listener (GSignalInvocationHint *signal_hint,
94                                 guint n_param_values,
95                                 const GValue *param_values,
96                                 gpointer data);
97 static gboolean
98 spi_atk_bridge_state_event_listener (GSignalInvocationHint *signal_hint,
99                                      guint n_param_values,
100                                      const GValue *param_values,
101                                      gpointer data);
102 static gboolean spi_atk_bridge_signal_listener         (GSignalInvocationHint *signal_hint,
103                                                         guint                  n_param_values,
104                                                         const GValue          *param_values,
105                                                         gpointer               data);
106 static gint     spi_atk_bridge_key_listener            (AtkKeyEventStruct     *event,
107                                                         gpointer               data);
108
109 /* For automatic libgnome init */
110 extern void gnome_accessibility_module_init     (void);
111 extern void gnome_accessibility_module_shutdown (void);
112
113 static int     atk_bridge_initialized = FALSE;
114 static guint   atk_bridge_focus_tracker_id = 0;
115 static guint   atk_bridge_key_event_listener_id = 0;
116 static GArray *listener_ids = NULL;
117
118 /*
119  *   These exported symbols are hooked by gnome-program
120  * to provide automatic module initialization and shutdown.
121  */
122 extern void gnome_accessibility_module_init     (void);
123 extern void gnome_accessibility_module_shutdown (void);
124
125 static void
126 spi_atk_bridge_init_event_type_consts ()
127 {
128   atk_signal_child_changed = g_signal_lookup ("child_changed", 
129                                               ATK_TYPE_OBJECT);
130   atk_signal_text_changed = g_signal_lookup ("text_changed", 
131                                              ATK_TYPE_TEXT);
132   atk_signal_active_descendant_changed = 
133          g_signal_lookup ("active_descendant_changed", 
134                           ATK_TYPE_OBJECT);
135 }
136
137 static int
138 atk_bridge_init (gint *argc, gchar **argv[])
139 {
140   const char *debug_env_string = g_getenv ("AT_SPI_DEBUG");
141
142   if (atk_bridge_initialized)
143     {
144       return 0;
145     }
146   atk_bridge_initialized = TRUE;
147
148   if (debug_env_string)
149     _dbg = (int) g_ascii_strtod (debug_env_string, NULL);
150
151   if (!bonobo_init (argc, argv ? *argv : NULL))
152     {
153       g_error ("Could not initialize Bonobo");
154     }
155
156   /*
157    * We only want to enable the bridge for top level
158    * applications, we detect bonobo components by seeing
159    * if they were activated with the intention of extracting
160    * an impl. by IID - very solid.
161    */
162   if (bonobo_activation_iid_get ())
163     {
164       DBG (1, g_message ("Found Bonobo component\n"));
165       toplevel_handler = g_signal_connect (atk_get_root (), 
166                                            "children-changed::add",
167                                            (GCallback) spi_atk_bridge_toplevel_added, 
168                                            NULL);
169     }
170   else
171     {
172       spi_atk_bridge_do_registration ();
173     }
174  
175   spi_atk_bridge_init_event_type_consts ();
176
177   return 0;
178 }
179
180
181 static void
182 spi_atk_bridge_do_registration (void)
183 {
184   CORBA_Environment ev;
185
186   CORBA_exception_init(&ev);
187
188   if (spi_atk_bridge_get_registry () == CORBA_OBJECT_NIL)
189     {
190       g_error ("Could not locate registry");
191     }
192
193   bonobo_activate ();
194
195   /* Create the accessible application server object */
196
197   this_app = spi_application_new (atk_get_root ());
198
199   DBG (1, g_message ("About to register application\n"));
200
201   spi_atk_bridge_register_application (spi_atk_bridge_get_registry ());
202   
203   g_atexit (spi_atk_bridge_exit_func);
204
205   DBG (1, g_message ("Application registered & listening\n"));
206
207 }
208
209 static void
210 spi_atk_bridge_toplevel_added (AtkObject *object,
211                                guint     index,
212                                AtkObject *child)
213 {
214   g_signal_handler_disconnect (object, toplevel_handler);
215   spi_atk_bridge_do_registration ();
216 }
217
218 static void
219 spi_atk_bridge_register_application (Accessibility_Registry registry)
220 {
221   Accessibility_Registry_registerApplication (spi_atk_bridge_get_registry (),
222                                               BONOBO_OBJREF (this_app),
223                                               &ev);
224   spi_atk_register_event_listeners ();
225 }
226
227 static Accessibility_Registry
228 spi_atk_bridge_get_registry ()
229 {
230   CORBA_Environment ev;
231
232   if (registry_died || (registry == NULL)) {
233           CORBA_exception_init (&ev);
234           if (registry_died) 
235             DBG (1, g_warning ("registry died! restarting..."));
236           registry = bonobo_activation_activate_from_id (
237                   "OAFIID:Accessibility_Registry:1.0", 0, NULL, &ev);
238           
239           if (ev._major != CORBA_NO_EXCEPTION)
240           {
241                   g_error ("Accessibility app error: exception during "
242                            "registry activation from id: %s\n",
243                            CORBA_exception_id (&ev));
244                   CORBA_exception_free (&ev);
245           }
246           
247           if (registry_died && registry) {
248                   registry_died = FALSE;
249                   spi_atk_bridge_register_application (registry);
250           }
251   }
252   return registry;
253 }
254
255 int
256 gtk_module_init (gint *argc, gchar **argv[])
257 {
258         return atk_bridge_init (argc, argv);
259 }
260
261 static void
262 add_signal_listener (const char *signal_name)
263 {
264   guint id;
265
266   id = atk_add_global_event_listener (
267     spi_atk_bridge_signal_listener, signal_name);
268
269   g_array_append_val (listener_ids, id);
270 }
271
272 static void
273 spi_atk_register_event_listeners (void)
274 {
275   /*
276    * kludge to make sure the Atk interface types are registered, otherwise
277    * the AtkText signal handlers below won't get registered
278    */
279   guint      id;
280   GObject   *ao = g_object_new (ATK_TYPE_OBJECT, NULL);
281   AtkObject *bo = atk_no_op_object_new (ao);
282
283
284   if (atk_listeners_registered) return;
285
286   atk_listeners_registered = TRUE;
287
288   /* Register for focus event notifications, and register app with central registry  */
289
290   listener_ids = g_array_sized_new (FALSE, TRUE, sizeof (guint), 16);
291
292   atk_bridge_focus_tracker_id = atk_add_focus_tracker (spi_atk_bridge_focus_tracker);
293
294   id = atk_add_global_event_listener (spi_atk_bridge_property_event_listener,
295                                       "Gtk:AtkObject:property-change");
296   g_array_append_val (listener_ids, id);
297   id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
298                                       "window:create");
299   g_array_append_val (listener_ids, id);
300   id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
301                                       "window:destroy");
302   g_array_append_val (listener_ids, id);
303   id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
304                                       "window:minimize");
305   g_array_append_val (listener_ids, id);
306   id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
307                                       "window:maximize");
308   g_array_append_val (listener_ids, id);
309   id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
310                                       "window:restore");
311   g_array_append_val (listener_ids, id);
312   id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
313                                       "window:activate");
314   g_array_append_val (listener_ids, id);
315   id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
316                                       "window:deactivate");
317   g_array_append_val (listener_ids, id);
318   id = atk_add_global_event_listener (spi_atk_bridge_state_event_listener,
319                                       "Gtk:AtkObject:state-change");
320   g_array_append_val (listener_ids, id);
321
322   add_signal_listener ("Gtk:AtkObject:children-changed");
323   add_signal_listener ("Gtk:AtkObject:visible-data-changed");
324   add_signal_listener ("Gtk:AtkObject:active-descendant-changed");
325   add_signal_listener ("Gtk:AtkSelection:selection-changed");
326   add_signal_listener ("Gtk:AtkText:text-selection-changed");
327   add_signal_listener ("Gtk:AtkText:text-changed");
328   add_signal_listener ("Gtk:AtkText:text-caret-moved");
329   add_signal_listener ("Gtk:AtkTable:row-inserted");
330   add_signal_listener ("Gtk:AtkTable:row-reordered");
331   add_signal_listener ("Gtk:AtkTable:row-deleted");
332   add_signal_listener ("Gtk:AtkTable:column-inserted");
333   add_signal_listener ("Gtk:AtkTable:column-reordered");
334   add_signal_listener ("Gtk:AtkTable:column-deleted");
335   add_signal_listener ("Gtk:AtkTable:model-changed");
336 /*
337  * May add the following listeners to implement preemptive key listening for GTK+
338  *
339  * atk_add_global_event_listener (spi_atk_bridge_widgetkey_listener, "Gtk:GtkWidget:key-press-event");
340  * atk_add_global_event_listener (spi_atk_bridge_widgetkey_listener, "Gtk:GtkWidget:key-release-event");
341  */
342   atk_bridge_key_event_listener_id = atk_add_key_event_listener (
343     spi_atk_bridge_key_listener, NULL);
344   
345   g_object_unref (G_OBJECT (bo));
346   g_object_unref (ao);
347 }
348
349 static void
350 deregister_application (BonoboObject *app)
351 {
352   Accessibility_Registry registry = spi_atk_bridge_get_registry ();     
353   Accessibility_Registry_deregisterApplication (registry, BONOBO_OBJREF (app), &ev);
354
355   registry = bonobo_object_release_unref (registry, &ev);
356   
357   app = bonobo_object_unref (app);
358 }
359
360 static void
361 spi_atk_bridge_exit_func (void)
362 {
363   BonoboObject *app = (BonoboObject *) this_app;
364
365   DBG (1, g_message ("exiting bridge\n"));
366
367   if (!app)
368     {
369       return;
370     }
371   this_app = NULL;
372
373   /*
374    *  FIXME: this may be incorrect for apps that do their own bonobo
375    *  shutdown, until we can explicitly shutdown to get the ordering
376    *  right.
377    */
378   if (!bonobo_is_initialized ())
379     {
380       DBG (1, g_warning ("Re-initializing bonobo\n"));
381       g_assert (bonobo_init (0, NULL));
382       g_assert (bonobo_activate ());
383     }
384   
385   deregister_application (app);
386
387   DBG (1, g_message ("bridge exit func complete.\n"));
388
389   if (g_getenv ("AT_BRIDGE_SHUTDOWN"))
390     {
391       g_assert (!bonobo_debug_shutdown ());
392     }
393 }
394
395 void
396 gnome_accessibility_module_init (void)
397 {
398   atk_bridge_init (NULL, NULL);
399
400   g_print("Atk Accessibilty bridge initialized\n");
401 }
402
403 void
404 gnome_accessibility_module_shutdown (void)
405 {
406   BonoboObject *app = (BonoboObject *) this_app;
407   int     i;
408   GArray *ids = listener_ids;
409   
410   if (!atk_bridge_initialized)
411     {
412       return;
413     }
414   atk_bridge_initialized = FALSE;
415   this_app = NULL;
416
417   g_print("Atk Accessibilty bridge shutdown\n");
418
419   listener_ids = NULL;
420   atk_remove_focus_tracker (atk_bridge_focus_tracker_id);
421   
422   for (i = 0; ids && i < ids->len; i++)
423   {
424           atk_remove_global_event_listener (g_array_index (ids, guint, i));
425   }
426   
427   atk_remove_key_event_listener (atk_bridge_key_event_listener_id);
428
429   deregister_application (app);
430 }
431
432 static void
433 spi_atk_bridge_focus_tracker (AtkObject *object)
434 {
435   SpiAccessible *source;
436   Accessibility_Event e;
437
438   source = spi_accessible_new (object);
439
440   e.type = "focus:";
441   e.source = BONOBO_OBJREF (source);
442   e.detail1 = 0;
443   e.detail2 = 0;
444   spi_init_any_nil (&e.any_data);
445   Accessibility_Registry_notifyEvent (spi_atk_bridge_get_registry (), &e, &ev);
446   if (BONOBO_EX (&ev)) registry_died = TRUE;
447   
448   Accessibility_Accessible_unref (e.source, &ev);
449   
450   CORBA_exception_free (&ev);
451 }
452
453 static void
454 spi_atk_emit_eventv (const GObject         *gobject,
455                      long                   detail1,
456                      long                   detail2,
457                      CORBA_any             *any,
458                      const char            *format, ...)
459 {
460   va_list             args;
461   Accessibility_Event e;
462   SpiAccessible      *source;
463   AtkObject          *aobject;
464 #ifdef SPI_BRIDGE_DEBUG
465   CORBA_string s;
466 #endif
467   
468   va_start (args, format);
469   
470   if (ATK_IS_IMPLEMENTOR (gobject))
471     {
472       aobject = atk_implementor_ref_accessible (ATK_IMPLEMENTOR (gobject));
473       source  = spi_accessible_new (aobject);
474       g_object_unref (G_OBJECT (aobject));
475     }
476   else if (ATK_IS_OBJECT (gobject))
477     {
478       aobject = ATK_OBJECT (gobject);
479       source  = spi_accessible_new (aobject);
480     }
481   else
482     {
483       aobject = NULL;
484       source  = NULL;
485       DBG (0, g_warning ("received property-change event from non-AtkImplementor"));
486     }
487
488   if (source) 
489     {
490       e.type = g_strdup_vprintf (format, args);
491       e.source = BONOBO_OBJREF (source);
492       e.detail1 = detail1;
493       e.detail2 = detail2;
494       if (any) e.any_data = *any;
495       else spi_init_any_nil (&e.any_data);
496
497 #ifdef SPI_BRIDGE_DEBUG
498       s = Accessibility_Accessible__get_name (BONOBO_OBJREF (source), &ev);
499       g_warning ("Emitting event '%s' (%lu, %lu) on %s",
500                  e.type, e.detail1, e.detail2, s);
501       CORBA_free (s);
502 #endif
503       CORBA_exception_init (&ev);
504       Accessibility_Registry_notifyEvent (spi_atk_bridge_get_registry (), 
505                                           &e, &ev);
506 #ifdef SPI_BRIDGE_DEBUG
507       if (ev._major != CORBA_NO_EXCEPTION)
508         g_warning ("error emitting event %s, (%d) %s",
509                    e.type,
510                    ev._major,
511                    CORBA_exception_id(&ev));
512 #endif        
513       if (BONOBO_EX (&ev)) registry_died = TRUE;
514       Accessibility_Accessible_unref (e.source, &ev);
515       
516       CORBA_exception_free (&ev);
517       
518       g_free (e.type);
519     }
520
521   va_end (args);
522
523 }
524
525 static gboolean
526 spi_atk_bridge_property_event_listener (GSignalInvocationHint *signal_hint,
527                                         guint n_param_values,
528                                         const GValue *param_values,
529                                         gpointer data)
530 {
531   AtkPropertyValues *values;
532   GObject *gobject;
533
534 #ifdef SPI_BRIDGE_DEBUG
535   GSignalQuery signal_query;
536   const gchar *name;
537   const gchar *s, *s2;
538   
539   g_signal_query (signal_hint->signal_id, &signal_query);
540   name = signal_query.signal_name;
541
542   s2 = g_type_name (G_OBJECT_TYPE (g_value_get_object (param_values + 0)));
543   s = atk_object_get_name (ATK_OBJECT (g_value_get_object (param_values + 0)));
544   values = (AtkPropertyValues*) g_value_get_pointer (param_values + 1);
545   DBG (2, g_message ("Received (property) signal %s:%s:%s from object %s (gail %s)\n",
546            g_type_name (signal_query.itype), name, values->property_name, s, s2));
547   
548 #endif
549
550   gobject = g_value_get_object (param_values + 0);
551   values = (AtkPropertyValues*) g_value_get_pointer (param_values + 1);
552
553   spi_atk_emit_eventv (gobject, 0, 0, NULL,
554                        "object:property-change:%s", values->property_name);
555
556   return TRUE;
557 }
558
559 static gboolean
560 spi_atk_bridge_state_event_listener (GSignalInvocationHint *signal_hint,
561                                      guint n_param_values,
562                                      const GValue *param_values,
563                                      gpointer data)
564 {
565   GObject *gobject;
566   gchar *property_name;
567   gchar *type;
568   unsigned long detail1;
569 #ifdef SPI_BRIDGE_DEBUG
570   GSignalQuery signal_query;
571   const gchar *name;
572   
573   g_signal_query (signal_hint->signal_id, &signal_query);
574   name = signal_query.signal_name;
575   fprintf (stderr, "Received (state) signal %s:%s\n",
576            g_type_name (signal_query.itype), name);
577 #endif
578
579   gobject = g_value_get_object (param_values + 0);
580   property_name = g_strdup (g_value_get_string (param_values + 1));
581   detail1 = (g_value_get_boolean (param_values + 2))
582     ? 1 : 0;
583   type = g_strdup_printf ("object:state-changed:%s", property_name);
584   spi_atk_emit_eventv (gobject, 
585                        detail1,
586                        0,
587                        NULL,
588                        type);
589   g_free (property_name);
590   g_free (type);
591   return TRUE;
592 }
593
594 static void
595 spi_init_keystroke_from_atk_key_event (Accessibility_DeviceEvent  *keystroke,
596                                        AtkKeyEventStruct          *event)
597 {
598 #ifdef SPI_DEBUG
599   if (event)
600     {
601       g_print ("event %c (%d)\n", (int) event->keyval, (int) event->keycode);
602     }
603   else
604 #endif
605   if (!event)
606     {
607       g_print ("WARNING: NULL key event!");
608     }
609   
610   keystroke->id        = (CORBA_long) event->keyval;
611   keystroke->hw_code   = (CORBA_short) event->keycode;
612   keystroke->timestamp = (CORBA_unsigned_long) event->timestamp;
613   keystroke->modifiers = (CORBA_unsigned_short) (event->state & 0xFFFF);
614   if (event->string)
615     {
616       keystroke->event_string = CORBA_string_dup (event->string);
617       keystroke->is_text = CORBA_TRUE;
618     }
619   else
620     {
621       keystroke->event_string = CORBA_string_dup ("");
622       keystroke->is_text = CORBA_FALSE;
623     }
624   switch (event->type)
625     {
626     case (ATK_KEY_EVENT_PRESS):
627       keystroke->type = Accessibility_KEY_PRESSED_EVENT;
628       break;
629     case (ATK_KEY_EVENT_RELEASE):
630       keystroke->type = Accessibility_KEY_RELEASED_EVENT;
631       break;
632     default:
633       keystroke->type = 0;
634       break;
635     }
636 #if 0  
637   g_print ("key_event type %d; val=%d code=%d modifiers=%x name=%s is_text=%d, time=%lx\n",
638            (int) keystroke->type, (int) keystroke->id, (int) keystroke->hw_code,
639            (int) keystroke->modifiers,
640            keystroke->event_string, (int) keystroke->is_text, (unsigned long) keystroke->timestamp);
641 #endif
642 }
643
644 static gint
645 spi_atk_bridge_key_listener (AtkKeyEventStruct *event, gpointer data)
646 {
647   CORBA_boolean             result;
648   Accessibility_DeviceEvent key_event;
649   Accessibility_DeviceEventController controller;
650         
651   if (BONOBO_EX (&ev))
652         g_warning ("failure: pre-listener get dec\n");
653
654   controller =
655     Accessibility_Registry_getDeviceEventController (
656             spi_atk_bridge_get_registry (), &ev);
657
658   if (BONOBO_EX (&ev))
659     {
660       g_warning ("failure: no deviceeventcontroller found\n");
661       CORBA_exception_free (&ev);
662       registry_died = TRUE;
663       result = FALSE;
664     }
665   else
666     {
667
668       spi_init_keystroke_from_atk_key_event (&key_event, event);
669
670       result = Accessibility_DeviceEventController_notifyListenersSync (
671         controller, &key_event, &ev);
672
673       bonobo_object_release_unref (controller, &ev);
674       CORBA_exception_free (&ev);
675     }
676
677   return result;
678 }
679
680 static gboolean
681 spi_atk_bridge_signal_listener (GSignalInvocationHint *signal_hint,
682                                 guint n_param_values,
683                                 const GValue *param_values,
684                                 gpointer data)
685 {
686   GObject *gobject;
687   GSignalQuery signal_query;
688   const gchar *name;
689   const gchar *detail;
690   CORBA_any any;
691   CORBA_Object c_obj;
692   char *sp = NULL;
693   AtkObject *ao;
694   gint detail1 = 0, detail2 = 0;
695   SpiAccessible *s_ao = NULL;
696 #ifdef SPI_BRIDGE_DEBUG
697   const gchar *s, *s2;
698 #endif 
699   
700   g_signal_query (signal_hint->signal_id, &signal_query);
701
702   name = signal_query.signal_name;
703   if (signal_hint->detail)
704     detail = g_quark_to_string (signal_hint->detail);
705   else
706     detail = NULL;
707
708 #ifdef SPI_BRIDGE_DEBUG
709   s2 = g_type_name (G_OBJECT_TYPE (g_value_get_object (param_values + 0)));
710   s = atk_object_get_name (ATK_OBJECT (g_value_get_object (param_values + 0)));
711   fprintf (stderr, "Received signal %s:%s detail: %s from object %s (gail %s)\n",
712            g_type_name (signal_query.itype), name, 
713            detail ? detail : "<NULL>", s ? s : "<NULL>" , s2);
714 #endif
715   
716   gobject = g_value_get_object (param_values + 0);
717
718   if (signal_query.signal_id == atk_signal_active_descendant_changed)
719     {
720       gpointer child = g_value_get_pointer (param_values + 1);
721
722       g_return_val_if_fail (ATK_IS_OBJECT (child), TRUE);
723
724       ao = ATK_OBJECT (child);
725
726       detail1 = atk_object_get_index_in_parent (ao);
727       s_ao = spi_accessible_new (ao);
728       c_obj = BONOBO_OBJREF (s_ao);
729       spi_init_any_object (&any, &c_obj);
730     }
731   else
732     {
733       if (G_VALUE_TYPE (param_values + 1) == G_TYPE_INT)
734         detail1 = g_value_get_int (param_values + 1);
735       if (G_VALUE_TYPE (param_values + 2) == G_TYPE_INT)
736         detail2 = g_value_get_int (param_values + 2);
737
738       if (signal_query.signal_id == atk_signal_text_changed)
739         {
740           sp = atk_text_get_text (ATK_TEXT (gobject),
741                                   detail1,
742                                   detail1+detail2);
743           spi_init_any_string (&any, &sp);
744         }
745       else if ((signal_query.signal_id == atk_signal_child_changed) && gobject)
746         {
747           ao = atk_object_ref_accessible_child (ATK_OBJECT (gobject), 
748                                                 detail1);
749           if (ao) 
750             {
751               s_ao = spi_accessible_new (ao);
752               c_obj = BONOBO_OBJREF (s_ao);
753               spi_init_any_object (&any, &c_obj);
754               g_object_unref (ao);
755             }
756           else
757             {
758               spi_init_any_nil (&any);
759             }
760         }
761       else
762         {
763           spi_init_any_nil (&any);
764         }
765     }
766
767   if (detail)
768     spi_atk_emit_eventv (gobject, detail1, detail2, &any,
769                          "object:%s:%s", name, detail);
770   else
771     spi_atk_emit_eventv (gobject, detail1, detail2, &any,
772                          "object:%s", name);
773
774   if (sp)
775     g_free (sp);
776
777   return TRUE;
778 }
779
780 static gboolean
781 spi_atk_bridge_window_event_listener (GSignalInvocationHint *signal_hint,
782                                       guint n_param_values,
783                                       const GValue *param_values,
784                                       gpointer data)
785 {
786   GObject *gobject;
787   GSignalQuery signal_query;
788   CORBA_any any;
789   const gchar *name, *s;
790 #ifdef SPI_BRIDGE_DEBUG
791   const gchar *s2;
792 #endif
793   
794   g_signal_query (signal_hint->signal_id, &signal_query);
795
796   name = signal_query.signal_name;
797
798 #ifdef SPI_BRIDGE_DEBUG
799   s2 = g_type_name (G_OBJECT_TYPE (g_value_get_object (param_values + 0)));
800   s = atk_object_get_name (ATK_OBJECT (g_value_get_object (param_values + 0)));
801   fprintf (stderr, "Received signal %s:%s from object %s (gail %s)\n",
802            g_type_name (signal_query.itype), name, s ? s : "<NULL>" , s2);
803 #endif
804   
805   gobject = g_value_get_object (param_values + 0);
806
807   s = atk_object_get_name (ATK_OBJECT (gobject));
808   spi_init_any_string (&any, (char **) &s);
809   
810   spi_atk_emit_eventv (gobject, 0, 0, &any,
811                        "window:%s", name);
812   return TRUE;
813 }