+static void
+spi_accessible_application_finalize (GObject *object)
+{
+ GList *l;
+ SpiApplication *application = (SpiApplication *) object;
+ CORBA_Environment ev;
+
+ CORBA_exception_init (&ev);
+
+ for (l = application->toolkit_listeners; l; l = l->next)
+ {
+ CORBA_Object_release ((CORBA_Object) l->data, &ev);
+ }
+
+ CORBA_exception_free (&ev);
+
+ g_list_free (application->toolkit_listeners);
+ application->toolkit_listeners = NULL;
+
+ g_print ("application finalize called\n");
+ (G_OBJECT_CLASS (spi_application_parent_class))->finalize (object);
+}
+
+static CORBA_string
+impl_accessibility_application_get_toolkit_name (PortableServer_Servant servant,
+ CORBA_Environment *ev)
+{
+ return CORBA_string_dup (atk_get_toolkit_name ());
+}
+
+static CORBA_string
+impl_accessibility_application_get_version (PortableServer_Servant servant,
+ CORBA_Environment *ev)
+{
+ return CORBA_string_dup (atk_get_toolkit_version ());
+}
+
+static CORBA_long
+impl_accessibility_application_get_id (PortableServer_Servant servant,
+ CORBA_Environment *ev)
+{
+ SpiApplication *application = SPI_APPLICATION (
+ bonobo_object_from_servant (servant));
+
+ return application->id;
+}
+
+static void
+impl_accessibility_application_set_id (PortableServer_Servant servant,
+ const CORBA_long id,
+ CORBA_Environment *ev)
+{
+ SpiApplication *application = SPI_APPLICATION (
+ bonobo_object_from_servant (servant));
+
+ application->id = id;
+}
+
+static AtkObject *
+get_atk_object_ref (GObject *gobject)
+{
+ AtkObject *aobject;
+
+ if (ATK_IS_IMPLEMENTOR (gobject))
+ {
+ aobject = atk_implementor_ref_accessible (ATK_IMPLEMENTOR (gobject));
+ }
+ else if (ATK_IS_OBJECT (gobject))
+ {
+ aobject = ATK_OBJECT (gobject);
+ g_object_ref (G_OBJECT (aobject));
+ }
+ else
+ {
+ aobject = NULL;
+ g_error ("received event from non-AtkImplementor");
+ }
+
+ return aobject;
+}
+
+static gboolean
+spi_application_object_event_listener (GSignalInvocationHint *signal_hint,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer data)
+{
+ Accessibility_Event e;
+ AtkObject *aobject;
+ SpiAccessible *source;
+ GSignalQuery signal_query;
+ gchar *event_name;
+ const char *generic_name;
+
+ g_return_val_if_fail (the_app != NULL, FALSE);
+
+ g_signal_query (signal_hint->signal_id, &signal_query);
+
+ /* TODO: move GTK reference out of app.c into bridge */
+ event_name = g_strdup_printf ("Gtk:%s:%s",
+ g_type_name (signal_query.itype),
+ signal_query.signal_name);
+
+ generic_name = reverse_lookup_name_for_toolkit_event (event_name);
+
+ fprintf (stderr, "Received (object) signal %s maps to '%s'\n",
+ event_name, generic_name);
+
+ g_free (event_name);
+
+ g_return_val_if_fail (generic_name, FALSE);
+
+ aobject = get_atk_object_ref (g_value_get_object (param_values + 0));
+
+ source = spi_accessible_new (aobject);
+ e.type = CORBA_string_dup (generic_name);
+ e.source = CORBA_OBJECT_NIL;
+ e.detail1 = 0;
+ e.detail2 = 0;
+
+ notify_listeners (the_app->toolkit_listeners, source, &e);
+
+ bonobo_object_unref (BONOBO_OBJECT (source));
+
+ g_object_unref (G_OBJECT (aobject));
+
+ return TRUE;
+}
+
+static gboolean
+spi_application_toolkit_event_listener (GSignalInvocationHint *signal_hint,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer data)
+{
+ Accessibility_Event e;
+ AtkObject *aobject;
+ SpiAccessible *source;
+ GSignalQuery signal_query;
+ char *event_name;
+
+ g_return_val_if_fail (the_app != NULL, FALSE);
+
+ g_signal_query (signal_hint->signal_id, &signal_query);
+
+ /* TODO: move GTK reference out of app.c into bridge */
+ event_name = g_strdup_printf ("Gtk:%s:%s",
+ g_type_name (signal_query.itype),
+ signal_query.signal_name);
+
+#ifdef SPI_DEBUG
+ fprintf (stderr, "Received signal %s\n", event_name);
+#endif
+
+ aobject = get_atk_object_ref (g_value_get_object (param_values + 0));
+
+ source = spi_accessible_new (aobject);
+ e.type = CORBA_string_dup (event_name);
+ e.source = CORBA_OBJECT_NIL;
+ e.detail1 = 0;
+ e.detail2 = 0;
+ notify_listeners (the_app->toolkit_listeners, source, &e);
+
+ bonobo_object_unref (BONOBO_OBJECT (source));
+ g_object_unref (G_OBJECT (aobject));
+
+ g_free (event_name);
+
+ return TRUE;
+}