2003-06-25 Padraig O'Briain <padraig.obriain@sun.com>
authorpadraigo <padraigo@e2bd861d-eb25-0410-b326-f6ed22b6b98c>
Wed, 25 Jun 2003 14:36:15 +0000 (14:36 +0000)
committerpadraigo <padraigo@e2bd861d-eb25-0410-b326-f6ed22b6b98c>
Wed, 25 Jun 2003 14:36:15 +0000 (14:36 +0000)
* atk-bridge/bridge.c:
(atk_bridge_init): Add signal handler for children-changed:remove on
root when in a BonoboComponent.
(spi_atk_bridge_toplevel_added): Call spi_atk_bridge_do_registration
for first toplevel only other incrememt variable toplevels.
(spi_atk_bridge_toplevel_removed): For last toplevel deregister
application and remove listeners.
(spi_atk_bridge_get-registry): Change NULL to CORBA_OBJECT_NIL for
consistency.
(spi_atk_deregister_event_listeners): New function which removes
listeners.
(reinit_register_vars): New fuction which reinitializes variables.

This fixes bug #111578.

git-svn-id: http://svn.gnome.org/svn/at-spi/trunk@449 e2bd861d-eb25-0410-b326-f6ed22b6b98c

ChangeLog
atk-bridge/bridge.c

index 654adf5..66ba212 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2003-06-25  Padraig O'Briain <padraig.obriain@sun.com>
+
+       * atk-bridge/bridge.c:
+       (atk_bridge_init): Add signal handler for children-changed:remove on
+       root when in a BonoboComponent.
+       (spi_atk_bridge_toplevel_added): Call spi_atk_bridge_do_registration
+       for first toplevel only other incrememt variable toplevels.
+       (spi_atk_bridge_toplevel_removed): For last toplevel deregister 
+       application and remove listeners.
+       (spi_atk_bridge_get-registry): Change NULL to CORBA_OBJECT_NIL for
+       consistency.
+       (spi_atk_deregister_event_listeners): New function which removes
+       listeners.
+       (reinit_register_vars): New fuction which reinitializes variables.
+
+       This fixes bug #111578.
+
 2003-06-13  Bill Haneman <bill.haneman@sun.com>
 
        * configure.in: version 1.3.4.
index 7dccf4e..4065745 100644 (file)
@@ -48,7 +48,7 @@ static Accessibility_DeviceEventController device_event_controller = CORBA_OBJEC
 static SpiApplication *this_app = NULL;
 static gboolean registry_died = FALSE;
 static gboolean atk_listeners_registered = FALSE;
-static guint toplevel_handler;
+static gint toplevels = 0;
 
 static guint atk_signal_text_changed;
 static guint atk_signal_children_changed;
@@ -71,9 +71,13 @@ static void     spi_atk_bridge_do_registration         (void);
 static void     spi_atk_bridge_toplevel_added          (AtkObject             *object,
                                                         guint                 index,
                                                         AtkObject             *child);
+static void     spi_atk_bridge_toplevel_removed        (AtkObject             *object,
+                                                        guint                 index,
+                                                        AtkObject             *child);
 
 static void     spi_atk_bridge_exit_func               (void);
 static void     spi_atk_register_event_listeners       (void);
+static void     spi_atk_deregister_event_listeners     (void);
 static void     spi_atk_bridge_focus_tracker           (AtkObject             *object);
 static void     spi_atk_bridge_register_application    (Accessibility_Registry registry);
 static gboolean spi_atk_bridge_property_event_listener (GSignalInvocationHint *signal_hint,
@@ -97,6 +101,8 @@ static gboolean spi_atk_bridge_signal_listener         (GSignalInvocationHint *s
 static gint     spi_atk_bridge_key_listener            (AtkKeyEventStruct     *event,
                                                        gpointer               data);
 static void     spi_atk_tidy_windows                   (void);
+static void     deregister_application                 (BonoboObject          *app);
+static void     reinit_register_vars                   (void);
 
 /* For automatic libgnome init */
 extern void gnome_accessibility_module_init     (void);
@@ -158,10 +164,14 @@ atk_bridge_init (gint *argc, gchar **argv[])
   if (bonobo_activation_iid_get ())
     {
       DBG (1, g_message ("Found Bonobo component\n"));
-      toplevel_handler = g_signal_connect (atk_get_root (), 
-                                           "children-changed::add",
-                                           (GCallback) spi_atk_bridge_toplevel_added, 
-                                           NULL);
+      g_signal_connect (atk_get_root (), 
+                        "children-changed::add",
+                        (GCallback) spi_atk_bridge_toplevel_added, 
+                        NULL);
+      g_signal_connect (atk_get_root (), 
+                        "children-changed::remove",
+                        (GCallback) spi_atk_bridge_toplevel_removed, 
+                        NULL);
     }
   else
     {
@@ -207,8 +217,30 @@ spi_atk_bridge_toplevel_added (AtkObject *object,
                                guint     index,
                                AtkObject *child)
 {
-  g_signal_handler_disconnect (object, toplevel_handler);
-  spi_atk_bridge_do_registration ();
+  if (toplevels == 0)
+    spi_atk_bridge_do_registration ();
+  toplevels++;
+}
+
+static void
+spi_atk_bridge_toplevel_removed (AtkObject *object,
+                                 guint     index,
+                                 AtkObject *child)
+{
+  BonoboObject *app = (BonoboObject *) this_app;
+
+  toplevels--;
+  if (toplevels == 0)
+    {
+      deregister_application (app);
+      spi_atk_deregister_event_listeners ();
+      reinit_register_vars ();
+    }
+  if (toplevels < 0)
+    {
+      g_warning ("More toplevels removed than added\n");
+      toplevels = 0;
+    }
 }
 
 static void
@@ -225,7 +257,7 @@ spi_atk_bridge_get_registry (void)
 {
   CORBA_Environment ev;
 
-  if (registry_died || (registry == NULL)) {
+  if (registry_died || (registry == CORBA_OBJECT_NIL)) {
          CORBA_exception_init (&ev);
          if (registry_died) 
            DBG (1, g_warning ("registry died! restarting..."));
@@ -372,6 +404,32 @@ spi_atk_register_event_listeners (void)
 }
 
 static void
+spi_atk_deregister_event_listeners (void)
+{
+  gint i;
+  guint id;
+
+  if (!atk_listeners_registered)
+    return;
+
+  atk_listeners_registered = FALSE;
+
+  for (i = 0; i < listener_ids->len; i++)
+    {
+      id = g_array_index (listener_ids, guint, i);
+      atk_remove_global_event_listener (id);   
+    }
+  g_array_free (listener_ids, TRUE);
+  listener_ids = NULL;
+
+  atk_remove_focus_tracker (atk_bridge_focus_tracker_id);
+  atk_bridge_focus_tracker_id = 0;
+
+  atk_remove_key_event_listener (atk_bridge_key_event_listener_id);
+  atk_bridge_key_event_listener_id = 0;
+}
+
+static void
 deregister_application (BonoboObject *app)
 {
   Accessibility_Registry registry = spi_atk_bridge_get_registry ();    
@@ -984,3 +1042,12 @@ spi_atk_tidy_windows (void)
       g_object_unref (child);
     }
 }
+
+static void
+reinit_register_vars (void)
+{
+  registry = CORBA_OBJECT_NIL;
+  device_event_controller = CORBA_OBJECT_NIL;
+  this_app = NULL;
+}
+