*/
#include <atk/atk.h>
+#include <string.h>
#include "accessible-cache.h"
#include "accessible-register.h"
static void
add_subtree (SpiCache *cache, AtkObject * accessible);
+static gboolean
+add_pending_items (gpointer data);
+
/*---------------------------------------------------------------------------*/
static void
spi_cache_init (SpiCache * cache)
{
cache->objects = g_hash_table_new (g_direct_hash, g_direct_equal);
+ cache->add_traversal = g_queue_new ();
#ifdef SPI_ATK_DEBUG
if (g_thread_supported ())
{
SpiCache *cache = SPI_CACHE (object);
+ while (!g_queue_is_empty (cache->add_traversal))
+ g_object_unref (G_OBJECT (g_queue_pop_head (cache->add_traversal)));
+ g_queue_free (cache->add_traversal);
g_free (cache->objects);
G_OBJECT_CLASS (spi_cache_parent_class)->finalize (object);
if (spi_cache_in (cache, gobj))
{
+#ifdef SPI_ATK_DEBUG
+ g_debug ("CACHE REM - %s - %d - %s\n", atk_object_get_name (ATK_OBJECT (gobj)),
+ atk_object_get_role (ATK_OBJECT (gobj)),
+ spi_register_object_to_path (spi_global_register, gobj));
+#endif
g_signal_emit (cache, cache_signals [OBJECT_REMOVED], 0, gobj);
g_hash_table_remove (cache->objects, gobj);
}
g_hash_table_insert (cache->objects, gobj, NULL);
#ifdef SPI_ATK_DEBUG
- g_debug ("CACHE - %s - %d - %s", atk_object_get_name (ATK_OBJECT (gobj)),
+ g_debug ("CACHE ADD - %s - %d - %s\n", atk_object_get_name (ATK_OBJECT (gobj)),
atk_object_get_role (ATK_OBJECT (gobj)),
spi_register_object_to_path (spi_global_register, gobj));
#endif
static void
add_subtree (SpiCache *cache, AtkObject * accessible)
{
+ g_return_if_fail (ATK_IS_OBJECT (accessible));
+
+ g_object_ref (accessible);
+ g_queue_push_tail (cache->add_traversal, accessible);
+ add_pending_items (cache);
+}
+
+static gboolean
+add_pending_items (gpointer data)
+{
+ SpiCache *cache = SPI_CACHE (data);
AtkObject *current;
- GQueue *traversal;
GQueue *to_add;
- g_return_if_fail (ATK_IS_OBJECT (accessible));
-
- traversal = g_queue_new ();
to_add = g_queue_new ();
- g_object_ref (accessible);
- g_queue_push_tail (traversal, accessible);
-
- while (!g_queue_is_empty (traversal))
+ while (!g_queue_is_empty (cache->add_traversal))
{
AtkStateSet *set;
- current = g_queue_pop_head (traversal);
+ current = g_queue_pop_head (cache->add_traversal);
set = atk_object_ref_state_set (current);
if (!atk_state_set_contains_state (set, ATK_STATE_TRANSIENT))
if (!spi_cache_in (cache, G_OBJECT (current)) &&
!atk_state_set_contains_state (set, ATK_STATE_MANAGES_DESCENDANTS))
{
- append_children (current, traversal);
+ append_children (current, cache->add_traversal);
}
}
while (!g_queue_is_empty (to_add))
{
current = g_queue_pop_head (to_add);
+
+ /* Make sure object is registerd so we are notified if it goes away */
+ g_free (spi_register_object_to_path (spi_global_register,
+ G_OBJECT (current)));
+
add_object (cache, G_OBJECT(current));
g_object_unref (G_OBJECT (current));
}
- g_queue_free (traversal);
g_queue_free (to_add);
+ cache->add_pending_idle = 0;
+ return FALSE;
}
/*---------------------------------------------------------------------------*/
if (signal_hint->detail)
detail = g_quark_to_string (signal_hint->detail);
- if (!strcmp (detail, "add"))
+ if (!strncmp (detail, "add", 3))
{
gpointer child;
int index = g_value_get_uint (param_values + 1);
{
child = atk_object_ref_accessible_child (accessible, index);
}
- add_subtree (cache, child);
+ g_object_ref (child);
+ g_queue_push_tail (cache->add_traversal, child);
+
+ if (cache->add_pending_idle == 0)
+ cache->add_pending_idle = g_idle_add (add_pending_items, cache);
}
#ifdef SPI_ATK_DEBUG
recursion_check_unset ();
{
child = atk_object_ref_accessible_child (accessible, index);
}
- add_subtree (cache, child);
+ else
+ g_object_ref (child);
+
+ g_queue_push_tail (cache->add_traversal, child);
+
+ if (cache->add_pending_idle == 0)
+ cache->add_pending_idle = g_idle_add (add_pending_items, cache);
#ifdef SPI_ATK_DEBUG
recursion_check_unset ();
#endif