]> Pileus Git - ~andy/gtk/blobdiff - gtk/a11y/gtktreeviewaccessible.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / a11y / gtktreeviewaccessible.c
index 08901a5088576ac15b107a4d56642798eb2e8ddb..31032b230558c43fbb1beb331f789df57121fd3f 100644 (file)
@@ -1,4 +1,4 @@
-/* GAIL - The GNOME Accessibility Implementation Library
+/* GTK+ - accessibility implementations
  * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
  *
  * This library is free software; you can redistribute it and/or
@@ -12,9 +12,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "config.h"
 #include "gtktreeprivate.h"
 #include "gtkwidgetprivate.h"
 
-#include "gtktreeviewaccessible.h"
+#include "gtktreeviewaccessibleprivate.h"
+
 #include "gtkrenderercellaccessible.h"
 #include "gtkbooleancellaccessible.h"
 #include "gtkimagecellaccessible.h"
 #include "gtkcontainercellaccessible.h"
 #include "gtktextcellaccessible.h"
 #include "gtkcellaccessibleparent.h"
+#include "gtkcellaccessibleprivate.h"
+
+struct _GtkTreeViewAccessiblePrivate
+{
+  GHashTable *cell_infos;
+};
 
 typedef struct _GtkTreeViewAccessibleCellInfo  GtkTreeViewAccessibleCellInfo;
 struct _GtkTreeViewAccessibleCellInfo
@@ -45,61 +50,20 @@ struct _GtkTreeViewAccessibleCellInfo
   GtkTreeViewAccessible *view;
 };
 
-/* signal handling */
-
-static void     selection_changed_cb (GtkTreeSelection *selection,
-                                      gpointer          data);
-
-static void     cursor_changed       (GtkTreeView      *tree_view,
-                                      GtkTreeViewAccessible *accessible);
-static gboolean focus_in             (GtkWidget        *widget);
-static gboolean focus_out            (GtkWidget        *widget);
-
 /* Misc */
 
-static void             set_iter_nth_row                (GtkTreeView            *tree_view,
-                                                         GtkTreeIter            *iter,
-                                                         gint                   row);
-static gint             get_row_from_tree_path          (GtkTreeView            *tree_view,
-                                                         GtkTreePath            *path);
-static void             iterate_thru_children           (GtkTreeView            *tree_view,
-                                                         GtkTreeModel           *tree_model,
-                                                         GtkTreePath            *tree_path,
-                                                         GtkTreePath            *orig,
-                                                         gint                   *count,
-                                                         gint                   depth);
 static int              cell_info_get_index             (GtkTreeView                     *tree_view,
                                                          GtkTreeViewAccessibleCellInfo   *info);
-static gboolean         update_cell_value               (GtkRendererCellAccessible       *renderer_cell,
-                                                         GtkTreeViewAccessible           *accessible,
-                                                         gboolean               emit_change_signal);
 static gboolean         is_cell_showing                 (GtkTreeView            *tree_view,
                                                          GdkRectangle           *cell_rect);
 
-static void             cell_destroyed                  (gpointer               data);
-static void             cell_info_new                   (GtkTreeViewAccessible           *accessible,
-                                                         GtkTreeModel           *tree_model,
+static void             cell_info_new                   (GtkTreeViewAccessible  *accessible,
                                                          GtkRBTree              *tree,
                                                          GtkRBNode              *node,
                                                          GtkTreeViewColumn      *tv_col,
                                                          GtkCellAccessible      *cell);
-static GtkCellAccessible *find_cell                       (GtkTreeViewAccessible           *accessible,
-                                                         gint                   index);
-static void             connect_model_signals           (GtkTreeView            *view,
-                                                         GtkTreeViewAccessible           *accessible);
-static void             disconnect_model_signals        (GtkTreeViewAccessible           *accessible);
 static gint             get_column_number               (GtkTreeView            *tree_view,
                                                          GtkTreeViewColumn      *column);
-static gint             get_focus_index                 (GtkTreeView            *tree_view);
-static gint             get_index                       (GtkTreeView            *tree_view,
-                                                         GtkTreePath            *path,
-                                                         gint                   actual_column);
-static void             count_rows                      (GtkTreeModel           *model,
-                                                         GtkTreeIter            *iter,
-                                                         GtkTreePath            *end_path,
-                                                         gint                   *count,
-                                                         gint                   level,
-                                                         gint                   depth);
 
 static gboolean         get_rbtree_column_from_index    (GtkTreeView            *tree_view,
                                                          gint                   index,
@@ -117,7 +81,7 @@ static void atk_selection_interface_init              (AtkSelectionIface
 static void atk_component_interface_init              (AtkComponentIface            *iface);
 static void gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface);
 
-G_DEFINE_TYPE_WITH_CODE (GtkTreeViewAccessible, _gtk_tree_view_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
+G_DEFINE_TYPE_WITH_CODE (GtkTreeViewAccessible, gtk_tree_view_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
                          G_IMPLEMENT_INTERFACE (ATK_TYPE_TABLE, atk_table_interface_init)
                          G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init)
                          G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init)
@@ -138,12 +102,8 @@ gtk_tree_view_accessible_get_data_quark (void)
 static void
 cell_info_free (GtkTreeViewAccessibleCellInfo *cell_info)
 {
-  if (cell_info->cell)
-    {
-      g_object_steal_qdata (G_OBJECT (cell_info->cell),
-                            gtk_tree_view_accessible_get_data_quark ());
-      _gtk_cell_accessible_add_state (cell_info->cell, ATK_STATE_DEFUNCT, FALSE);
-    }
+  gtk_accessible_set_widget (GTK_ACCESSIBLE (cell_info->cell), NULL);
+  g_object_unref (cell_info->cell);
 
   g_free (cell_info);
 }
@@ -184,37 +144,20 @@ gtk_tree_view_accessible_initialize (AtkObject *obj,
   GtkTreeView *tree_view;
   GtkTreeModel *tree_model;
   GtkWidget *widget;
-  GtkTreeSelection *selection;
 
-  ATK_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->initialize (obj, data);
+  ATK_OBJECT_CLASS (gtk_tree_view_accessible_parent_class)->initialize (obj, data);
 
   accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
-  accessible->focus_cell = NULL;
 
-  accessible->cell_infos = g_hash_table_new_full (cell_info_hash,
+  accessible->priv->cell_infos = g_hash_table_new_full (cell_info_hash,
       cell_info_equal, NULL, (GDestroyNotify) cell_info_free);
 
   widget = GTK_WIDGET (data);
   tree_view = GTK_TREE_VIEW (widget);
   tree_model = gtk_tree_view_get_model (tree_view);
-  selection = gtk_tree_view_get_selection (tree_view);
-
-  g_signal_connect (selection, "changed",
-                    G_CALLBACK (selection_changed_cb), obj);
 
-  g_signal_connect (tree_view, "cursor-changed",
-                    G_CALLBACK (cursor_changed), accessible);
-  g_signal_connect (tree_view, "focus-in-event",
-                    G_CALLBACK (focus_in), NULL);
-  g_signal_connect (tree_view, "focus-out-event",
-                    G_CALLBACK (focus_out), NULL);
-
-  accessible->tree_model = tree_model;
   if (tree_model)
     {
-      g_object_add_weak_pointer (G_OBJECT (accessible->tree_model), (gpointer *)&accessible->tree_model);
-      connect_model_signals (tree_view, accessible);
-
       if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
         obj->role = ATK_ROLE_TABLE;
       else
@@ -227,13 +170,10 @@ gtk_tree_view_accessible_finalize (GObject *object)
 {
   GtkTreeViewAccessible *accessible = GTK_TREE_VIEW_ACCESSIBLE (object);
 
-  if (accessible->tree_model)
-    disconnect_model_signals (accessible);
+  if (accessible->priv->cell_infos)
+    g_hash_table_destroy (accessible->priv->cell_infos);
 
-  if (accessible->cell_infos)
-    g_hash_table_destroy (accessible->cell_infos);
-
-  G_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->finalize (object);
+  G_OBJECT_CLASS (gtk_tree_view_accessible_parent_class)->finalize (object);
 }
 
 static void
@@ -254,16 +194,10 @@ gtk_tree_view_accessible_notify_gtk (GObject    *obj,
       AtkRole role;
 
       tree_model = gtk_tree_view_get_model (tree_view);
-      if (accessible->tree_model)
-        disconnect_model_signals (accessible);
-      g_hash_table_remove_all (accessible->cell_infos);
-      accessible->tree_model = tree_model;
+      g_hash_table_remove_all (accessible->priv->cell_infos);
 
       if (tree_model)
         {
-          g_object_add_weak_pointer (G_OBJECT (accessible->tree_model), (gpointer *)&accessible->tree_model);
-          connect_model_signals (tree_view, accessible);
-
           if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
             role = ATK_ROLE_TABLE;
           else
@@ -280,43 +214,17 @@ gtk_tree_view_accessible_notify_gtk (GObject    *obj,
       g_object_thaw_notify (G_OBJECT (accessible));
     }
   else
-    GTK_WIDGET_ACCESSIBLE_CLASS (_gtk_tree_view_accessible_parent_class)->notify_gtk (obj, pspec);
-}
-
-static void
-gtk_tree_view_accessible_destroyed (GtkWidget     *widget,
-                                    GtkAccessible *gtk_accessible)
-{
-  GtkTreeViewAccessible *accessible;
-
-  if (!GTK_IS_TREE_VIEW (widget))
-    return;
-
-  accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_accessible);
-
-  if (accessible->tree_model)
-    {
-      disconnect_model_signals (accessible);
-      accessible->tree_model = NULL;
-    }
-  if (accessible->focus_cell)
-    {
-      g_object_unref (accessible->focus_cell);
-      accessible->focus_cell = NULL;
-    }
+    GTK_WIDGET_ACCESSIBLE_CLASS (gtk_tree_view_accessible_parent_class)->notify_gtk (obj, pspec);
 }
 
 static void
-gtk_tree_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
+gtk_tree_view_accessible_widget_unset (GtkAccessible *gtkaccessible)
 {
-  GtkWidget *widget;
+  GtkTreeViewAccessible *accessible = GTK_TREE_VIEW_ACCESSIBLE (gtkaccessible);
 
-  widget = gtk_accessible_get_widget (accessible);
-  if (widget)
-    g_signal_connect_after (widget, "destroy",
-                            G_CALLBACK (gtk_tree_view_accessible_destroyed), accessible);
+  g_hash_table_remove_all (accessible->priv->cell_infos);
 
-  GTK_ACCESSIBLE_CLASS (_gtk_tree_view_accessible_parent_class)->connect_widget_destroyed (accessible);
+  GTK_ACCESSIBLE_CLASS (gtk_tree_view_accessible_parent_class)->widget_unset (gtkaccessible);
 }
 
 static gint
@@ -349,6 +257,7 @@ get_n_columns (GtkTreeView *tree_view)
 
   return visible_columns;
 }
+
 static gint
 gtk_tree_view_accessible_get_n_children (AtkObject *obj)
 {
@@ -385,89 +294,85 @@ get_visible_column (GtkTreeView *tree_view,
   g_return_val_if_reached (NULL);
 }
 
-static AtkObject *
-gtk_tree_view_accessible_ref_child (AtkObject *obj,
-                                    gint       i)
+static void
+set_cell_data (GtkTreeView           *treeview,
+               GtkTreeViewAccessible *accessible,
+               GtkCellAccessible     *cell)
 {
-  GtkWidget *widget;
-  GtkTreeViewAccessible *accessible;
-  GtkCellAccessible *cell;
-  GtkTreeView *tree_view;
-  GtkTreeModel *tree_model;
-  GtkCellRenderer *renderer;
+  GtkTreeViewAccessibleCellInfo *cell_info;
+  gboolean is_expander, is_expanded;
+  GtkTreeModel *model;
   GtkTreeIter iter;
-  GtkTreeViewColumn *tv_col;
-  GtkTreeSelection *selection;
   GtkTreePath *path;
-  GtkRBTree *tree;
-  GtkRBNode *node;
-  AtkObject *child;
-  AtkObject *parent;
-  GtkTreeViewColumn *expander_tv;
-  GList *renderer_list;
-  GList *l;
-  GtkContainerCellAccessible *container = NULL;
-  GtkRendererCellAccessible *renderer_cell;
-  gboolean is_expander, is_expanded, retval;
-  gboolean editable = FALSE;
-  gint focus_index;
 
-  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
-  if (widget == NULL)
-    return NULL;
+  cell_info = find_cell_info (accessible, cell);
+  if (!cell_info)
+    return;
 
-  if (i >= gtk_tree_view_accessible_get_n_children (obj))
-    return NULL;
+  model = gtk_tree_view_get_model (treeview);
 
-  accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
-  tree_view = GTK_TREE_VIEW (widget);
-  if (i < get_n_columns (tree_view))
+  if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_PARENT) &&
+      cell_info->cell_col_ref == gtk_tree_view_get_expander_column (treeview))
     {
-      tv_col = get_visible_column (tree_view, i);
-      child = get_header_from_column (tv_col);
-      if (child)
-        g_object_ref (child);
-      return child;
+      is_expander = TRUE;
+      is_expanded = cell_info->node->children != NULL;
+    }
+  else
+    {
+      is_expander = FALSE;
+      is_expanded = FALSE;
     }
 
-  /* Check whether the child is cached */
-  cell = find_cell (accessible, i);
-  if (cell)
+  path = cell_info_get_path (cell_info);
+  if (path == NULL ||
+      !gtk_tree_model_get_iter (model, &iter, path))
     {
-      g_object_ref (cell);
-      return ATK_OBJECT (cell);
+      /* We only track valid cells, this should never happen */
+      g_return_if_reached ();
     }
+  gtk_tree_path_free (path);
 
-  if (accessible->focus_cell == NULL)
-      focus_index = get_focus_index (tree_view);
-  else
-      focus_index = -1;
+  gtk_tree_view_column_cell_set_cell_data (cell_info->cell_col_ref,
+                                           model,
+                                           &iter,
+                                           is_expander,
+                                           is_expanded);
+}
 
-  /* Find the RBTree and GtkTreeViewColumn for the index */
-  if (!get_rbtree_column_from_index (tree_view, i, &tree, &node, &tv_col))
-    return NULL;
+static GtkCellAccessible *
+peek_cell (GtkTreeViewAccessible *accessible,
+           GtkRBTree             *tree,
+           GtkRBNode             *node,
+           GtkTreeViewColumn     *column)
+{
+  GtkTreeViewAccessibleCellInfo lookup, *cell_info;
 
-  path = _gtk_tree_path_new_from_rbtree (tree, node);
-  tree_model = gtk_tree_view_get_model (tree_view);
-  retval = gtk_tree_model_get_iter (tree_model, &iter, path);
-  if (!retval)
+  lookup.tree = tree;
+  lookup.node = node;
+  lookup.cell_col_ref = column;
+
+  cell_info = g_hash_table_lookup (accessible->priv->cell_infos, &lookup);
+  if (cell_info == NULL)
     return NULL;
 
-  expander_tv = gtk_tree_view_get_expander_column (tree_view);
-  is_expander = FALSE;
-  is_expanded = FALSE;
-  if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_PARENT))
-    {
-      if (expander_tv == tv_col)
-        {
-          is_expander = TRUE;
-          is_expanded = node->children != NULL;
-        }
-    }
-  gtk_tree_view_column_cell_set_cell_data (tv_col, tree_model, &iter,
-                                           is_expander, is_expanded);
+  return cell_info->cell;
+}
+
+static GtkCellAccessible *
+create_cell (GtkTreeView           *treeview,
+             GtkTreeViewAccessible *accessible,
+             GtkRBTree             *tree,
+             GtkRBNode             *node,
+             GtkTreeViewColumn     *column)
+{
+  GtkCellRenderer *renderer;
+  AtkObject *parent;
+  GList *renderer_list;
+  GList *l;
+  GtkContainerCellAccessible *container = NULL;
+  GtkCellAccessible *cell;
 
-  renderer_list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
+  renderer_list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
 
   /* If there is not exactly one renderer in the list,
    * make a container
@@ -476,105 +381,111 @@ gtk_tree_view_accessible_ref_child (AtkObject *obj,
     {
       GtkCellAccessible *container_cell;
 
-      container = _gtk_container_cell_accessible_new ();
+      container = gtk_container_cell_accessible_new ();
 
       container_cell = GTK_CELL_ACCESSIBLE (container);
-      _gtk_cell_accessible_initialise (container_cell, widget, ATK_OBJECT (accessible));
+      _gtk_cell_accessible_initialize (container_cell, GTK_WIDGET (treeview), ATK_OBJECT (accessible));
 
       /* The GtkTreeViewAccessibleCellInfo structure for the container will
        * be before the ones for the cells so that the first one we find for
        * a position will be for the container
        */
-      cell_info_new (accessible, tree_model, tree, node, tv_col, container_cell);
+      cell_info_new (accessible, tree, node, column, container_cell);
       parent = ATK_OBJECT (container);
     }
   else
     parent = ATK_OBJECT (accessible);
 
-  child = NULL;
+  cell = NULL;
 
   for (l = renderer_list; l; l = l->next)
     {
       renderer = GTK_CELL_RENDERER (l->data);
 
-      if (GTK_IS_CELL_RENDERER_TEXT (renderer))
-        {
-          g_object_get (G_OBJECT (renderer), "editable", &editable, NULL);
-          child = _gtk_text_cell_accessible_new ();
-        }
-      else if (GTK_IS_CELL_RENDERER_TOGGLE (renderer))
-        child = _gtk_boolean_cell_accessible_new ();
-      else if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
-        child = _gtk_image_cell_accessible_new ();
-      else
-        child = _gtk_renderer_cell_accessible_new ();
-
-      cell = GTK_CELL_ACCESSIBLE (child);
-      renderer_cell = GTK_RENDERER_CELL_ACCESSIBLE (child);
+      cell = GTK_CELL_ACCESSIBLE (gtk_renderer_cell_accessible_new (renderer));
 
       /* Create the GtkTreeViewAccessibleCellInfo for this cell */
       if (parent == ATK_OBJECT (accessible))
-        cell_info_new (accessible, tree_model, tree, node, tv_col, cell);
+        cell_info_new (accessible, tree, node, column, cell);
 
-      _gtk_cell_accessible_initialise (cell, widget, parent);
+      _gtk_cell_accessible_initialize (cell, GTK_WIDGET (treeview), parent);
 
       if (container)
-        _gtk_container_cell_accessible_add_child (container, cell);
-
-      update_cell_value (renderer_cell, accessible, FALSE);
-
-      /* If the row is selected, all cells on the row are selected */
-      selection = gtk_tree_view_get_selection (tree_view);
-
-      if (gtk_tree_selection_path_is_selected (selection, path))
-        _gtk_cell_accessible_add_state (cell, ATK_STATE_SELECTED, FALSE);
-
-      _gtk_cell_accessible_add_state (cell, ATK_STATE_FOCUSABLE, FALSE);
-      if (focus_index == i)
-        {
-          accessible->focus_cell = g_object_ref (cell);
-          _gtk_cell_accessible_add_state (cell, ATK_STATE_FOCUSED, FALSE);
-          g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
-        }
+        gtk_container_cell_accessible_add_child (container, cell);
     }
   g_list_free (renderer_list);
   if (container)
-    child = ATK_OBJECT (container);
+    cell = GTK_CELL_ACCESSIBLE (container);
+
+  set_cell_data (treeview, accessible, cell);
+  _gtk_cell_accessible_update_cache (cell);
 
-  if (expander_tv == tv_col)
+  if (gtk_tree_view_get_expander_column (treeview) == column)
     {
       AtkRelationSet *relation_set;
-      AtkObject *accessible_array[1];
       AtkRelation* relation;
       AtkObject *parent_node;
 
-      relation_set = atk_object_ref_relation_set (ATK_OBJECT (child));
+      relation_set = atk_object_ref_relation_set (ATK_OBJECT (cell));
 
-      gtk_tree_path_up (path);
-      if (gtk_tree_path_get_depth (path) == 0)
-        parent_node = obj;
-      else
+      if (tree->parent_tree)
         {
-          gint parent_index;
-
-          parent_index = get_index (tree_view, path, i % get_n_columns (tree_view));
-          parent_node = atk_object_ref_accessible_child (obj, parent_index);
+          parent_node = ATK_OBJECT (peek_cell (accessible, tree->parent_tree, tree->parent_node, column));
+          if (parent_node == NULL)
+            parent_node = ATK_OBJECT (create_cell (treeview, accessible, tree->parent_tree, tree->parent_node, column));
         }
-      accessible_array[0] = parent_node;
-      relation = atk_relation_new (accessible_array, 1,
-                                   ATK_RELATION_NODE_CHILD_OF);
+      else
+        parent_node = ATK_OBJECT (accessible);
+      relation = atk_relation_new (&parent_node, 1, ATK_RELATION_NODE_CHILD_OF);
       atk_relation_set_add (relation_set, relation);
-      atk_object_add_relationship (parent_node, ATK_RELATION_NODE_PARENT_OF, child);
+      atk_object_add_relationship (parent_node, ATK_RELATION_NODE_PARENT_OF, ATK_OBJECT (cell));
       g_object_unref (relation);
       g_object_unref (relation_set);
     }
-  gtk_tree_path_free (path);
 
-  /* We do not increase the reference count here; when g_object_unref()
-   * is called for the cell then cell_destroyed() is called and this
-   * removes the cell from the cache.
-   */
-  return child;
+  return cell;
+}
+
+static AtkObject *
+gtk_tree_view_accessible_ref_child (AtkObject *obj,
+                                    gint       i)
+{
+  GtkWidget *widget;
+  GtkTreeViewAccessible *accessible;
+  GtkCellAccessible *cell;
+  GtkTreeView *tree_view;
+  GtkTreeViewColumn *tv_col;
+  GtkRBTree *tree;
+  GtkRBNode *node;
+  AtkObject *child;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
+  if (widget == NULL)
+    return NULL;
+
+  if (i >= gtk_tree_view_accessible_get_n_children (obj))
+    return NULL;
+
+  accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
+  tree_view = GTK_TREE_VIEW (widget);
+  if (i < get_n_columns (tree_view))
+    {
+      tv_col = get_visible_column (tree_view, i);
+      child = get_header_from_column (tv_col);
+      if (child)
+        g_object_ref (child);
+      return child;
+    }
+
+  /* Find the RBTree and GtkTreeViewColumn for the index */
+  if (!get_rbtree_column_from_index (tree_view, i, &tree, &node, &tv_col))
+    return NULL;
+
+  cell = peek_cell (accessible, tree, node, tv_col);
+  if (cell == NULL)
+    cell = create_cell (tree_view, accessible, tree, node, tv_col);
+
+  return g_object_ref (cell);
 }
 
 static AtkStateSet*
@@ -583,7 +494,7 @@ gtk_tree_view_accessible_ref_state_set (AtkObject *obj)
   AtkStateSet *state_set;
   GtkWidget *widget;
 
-  state_set = ATK_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->ref_state_set (obj);
+  state_set = ATK_OBJECT_CLASS (gtk_tree_view_accessible_parent_class)->ref_state_set (obj);
   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
 
   if (widget != NULL)
@@ -593,7 +504,7 @@ gtk_tree_view_accessible_ref_state_set (AtkObject *obj)
 }
 
 static void
-_gtk_tree_view_accessible_class_init (GtkTreeViewAccessibleClass *klass)
+gtk_tree_view_accessible_class_init (GtkTreeViewAccessibleClass *klass)
 {
   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
@@ -608,7 +519,7 @@ _gtk_tree_view_accessible_class_init (GtkTreeViewAccessibleClass *klass)
 
   widget_class->notify_gtk = gtk_tree_view_accessible_notify_gtk;
 
-  accessible_class->connect_widget_destroyed = gtk_tree_view_accessible_connect_widget_destroyed;
+  accessible_class->widget_unset = gtk_tree_view_accessible_widget_unset;
 
   /* The children of a GtkTreeView are the buttons at the top of the columns
    * we do not represent these as children so we do not want to report
@@ -618,51 +529,16 @@ _gtk_tree_view_accessible_class_init (GtkTreeViewAccessibleClass *klass)
   container_class->remove_gtk = NULL;
 
   gobject_class->finalize = gtk_tree_view_accessible_finalize;
-}
-
-static void
-_gtk_tree_view_accessible_init (GtkTreeViewAccessible *view)
-{
-}
-
-gint
-get_focus_index (GtkTreeView *tree_view)
-{
-  GtkTreePath *focus_path;
-  GtkTreeViewColumn *focus_column;
-  gint index;
-
-  gtk_tree_view_get_cursor (tree_view, &focus_path, &focus_column);
-  if (focus_path && focus_column)
-    index = get_index (tree_view, focus_path,
-                       get_column_number (tree_view, focus_column));
-  else
-    index = -1;
-
-  if (focus_path)
-    gtk_tree_path_free (focus_path);
 
-  return index;
+  g_type_class_add_private (klass, sizeof (GtkTreeViewAccessiblePrivate));
 }
 
-/* This function returns a reference to the accessible object
- * for the cell in the treeview which has focus, if any
- */
-static AtkObject *
-gtk_tree_view_accessible_ref_focus_cell (GtkTreeView *tree_view)
+static void
+gtk_tree_view_accessible_init (GtkTreeViewAccessible *view)
 {
-  AtkObject *focus_cell = NULL;
-  AtkObject *atk_obj;
-  gint focus_index;
-
-  focus_index = get_focus_index (tree_view);
-  if (focus_index >= 0)
-    {
-      atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
-      focus_cell = atk_object_ref_accessible_child (atk_obj, focus_index);
-    }
-
-  return focus_cell;
+  view->priv = G_TYPE_INSTANCE_GET_PRIVATE (view,
+                                            GTK_TYPE_TREE_VIEW_ACCESSIBLE,
+                                            GtkTreeViewAccessiblePrivate);
 }
 
 /* atkcomponent.h */
@@ -676,10 +552,12 @@ gtk_tree_view_accessible_ref_accessible_at_point (AtkComponent *component,
   GtkWidget *widget;
   GtkTreeView *tree_view;
   GtkTreePath *path;
-  GtkTreeViewColumn *tv_column;
+  GtkTreeViewColumn *column;
   gint x_pos, y_pos;
   gint bx, by;
-  gboolean ret_val;
+  GtkCellAccessible *cell;
+  GtkRBTree *tree;
+  GtkRBNode *node;
 
   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
   if (widget == NULL)
@@ -689,21 +567,22 @@ gtk_tree_view_accessible_ref_accessible_at_point (AtkComponent *component,
 
   atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
   gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, x, y, &bx, &by);
-  ret_val = gtk_tree_view_get_path_at_pos (tree_view,
-                                           bx - x_pos, by - y_pos,
-                                           &path, &tv_column, NULL, NULL);
-  if (ret_val)
-    {
-      gint index, column;
+  if (!gtk_tree_view_get_path_at_pos (tree_view,
+                                      bx - x_pos, by - y_pos,
+                                      &path, &column, NULL, NULL))
+    return NULL;
 
-      column = get_column_number (tree_view, tv_column);
-      index = get_index (tree_view, path, column);
+  if (_gtk_tree_view_find_node (tree_view, path, &tree, &node))
+    {
       gtk_tree_path_free (path);
-
-      return gtk_tree_view_accessible_ref_child (ATK_OBJECT (component), index);
+      return NULL;
     }
 
-  return NULL;
+  cell = peek_cell (GTK_TREE_VIEW_ACCESSIBLE (component), tree, node, column);
+  if (cell == NULL)
+    cell = create_cell (tree_view, GTK_TREE_VIEW_ACCESSIBLE (component), tree, node, column);
+
+  return g_object_ref (cell);
 }
 
 static void
@@ -821,22 +700,23 @@ gtk_tree_view_accessible_is_row_selected (AtkTable *table,
                                           gint      row)
 {
   GtkWidget *widget;
-  GtkTreeView *tree_view;
-  GtkTreeSelection *selection;
-  GtkTreeIter iter;
+  GtkRBTree *tree;
+  GtkRBNode *node;
+
+  if (row < 0)
+    return FALSE;
 
   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
   if (widget == NULL)
     return FALSE;
 
-  if (row < 0)
+  if (!_gtk_rbtree_find_index (_gtk_tree_view_get_rbtree (GTK_TREE_VIEW (widget)),
+                               row,
+                               &tree,
+                               &node))
     return FALSE;
 
-  tree_view = GTK_TREE_VIEW (widget);
-  selection = gtk_tree_view_get_selection (tree_view);
-
-  set_iter_nth_row (tree_view, &iter, row);
-  return gtk_tree_selection_iter_is_selected (selection, &iter);
+  return GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED);
 }
 
 static gboolean
@@ -847,150 +727,124 @@ gtk_tree_view_accessible_is_selected (AtkTable *table,
   return gtk_tree_view_accessible_is_row_selected (table, row);
 }
 
+typedef struct {
+  GArray *array;
+  GtkTreeView *treeview;
+} SelectedRowsData;
+
 static void
 get_selected_rows (GtkTreeModel *model,
                    GtkTreePath  *path,
                    GtkTreeIter  *iter,
-                   gpointer      data)
+                   gpointer      datap)
 {
-  GPtrArray *array = (GPtrArray *)data;
+  SelectedRowsData *data = datap;
+  GtkRBTree *tree;
+  GtkRBNode *node;
+  int id;
+
+  if (_gtk_tree_view_find_node (data->treeview,
+                                path,
+                                &tree, &node))
+    {
+      g_assert_not_reached ();
+    }
 
-  g_ptr_array_add (array, gtk_tree_path_copy (path));
+  id = _gtk_rbtree_node_get_index (tree, node);
+
+  g_array_append_val (data->array, id);
 }
 
 static gint
 gtk_tree_view_accessible_get_selected_rows (AtkTable  *table,
                                             gint     **rows_selected)
 {
+  SelectedRowsData data;
   GtkWidget *widget;
-  GtkTreeView *tree_view;
-  GtkTreeModel *tree_model;
-  GtkTreeIter iter;
-  GtkTreeSelection *selection;
-  GtkTreePath *tree_path;
-  gint ret_val = 0;
+  gint n_rows;
 
   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
   if (widget == NULL)
     return 0;
 
-  tree_view = GTK_TREE_VIEW (widget);
-  selection = gtk_tree_view_get_selection (tree_view);
-
-  switch (gtk_tree_selection_get_mode (selection))
-    {
-    case GTK_SELECTION_SINGLE:
-    case GTK_SELECTION_BROWSE:
-      if (gtk_tree_selection_get_selected (selection, &tree_model, &iter))
-        {
-          gint row;
-
-          if (rows_selected)
-            {
-              *rows_selected = g_new (gint, 1);
-              tree_path = gtk_tree_model_get_path (tree_model, &iter);
-              row = get_row_from_tree_path (tree_view, tree_path);
-              gtk_tree_path_free (tree_path);
+  data.treeview = GTK_TREE_VIEW (widget);
+  data.array = g_array_new (FALSE, FALSE, sizeof (gint));
 
-              /* shouldn't ever happen */
-              g_return_val_if_fail (row != -1, 0);
+  gtk_tree_selection_selected_foreach (gtk_tree_view_get_selection (data.treeview),
+                                       get_selected_rows,
+                                       &data);
 
-              *rows_selected[0] = row;
-            }
-          ret_val = 1;
-        }
-      break;
-    case GTK_SELECTION_MULTIPLE:
-      {
-        GPtrArray *array = g_ptr_array_new();
-
-        gtk_tree_selection_selected_foreach (selection, get_selected_rows, array);
-        ret_val = array->len;
-
-        if (rows_selected && ret_val)
-          {
-            gint i;
-
-            *rows_selected = g_new (gint, ret_val);
-            for (i = 0; i < ret_val; i++)
-              {
-                gint row;
-
-                tree_path = (GtkTreePath *) g_ptr_array_index (array, i);
-                row = get_row_from_tree_path (tree_view, tree_path);
-                gtk_tree_path_free (tree_path);
-                (*rows_selected)[i] = row;
-              }
-          }
-        g_ptr_array_free (array, FALSE);
-      }
-      break;
-    case GTK_SELECTION_NONE:
-      break;
-    }
-  return ret_val;
+  n_rows = data.array->len;
+  if (rows_selected)
+    *rows_selected = (gint *) g_array_free (data.array, FALSE);
+  else
+    g_array_free (data.array, TRUE);
+  
+  return n_rows;
 }
 
 static gboolean
 gtk_tree_view_accessible_add_row_selection (AtkTable *table,
                                             gint      row)
 {
-  GtkWidget *widget;
-  GtkTreeView *tree_view;
-  GtkTreeModel *tree_model;
-  GtkTreeSelection *selection;
-  GtkTreePath *tree_path;
-  GtkTreeIter iter_to_row;
+  GtkTreeView *treeview;
+  GtkTreePath *path;
+  GtkRBTree *tree;
+  GtkRBNode *node;
 
-  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
-  if (widget == NULL)
+  if (row < 0)
     return FALSE;
 
-  if (!gtk_tree_view_accessible_is_row_selected (table, row))
-    {
-      tree_view = GTK_TREE_VIEW (widget);
-      tree_model = gtk_tree_view_get_model (tree_view);
-      selection = gtk_tree_view_get_selection (tree_view);
+  treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (table)));
+  if (treeview == NULL)
+    return FALSE;
 
-      if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
-        {
-          tree_path = gtk_tree_path_new ();
-          gtk_tree_path_append_index (tree_path, row);
-          gtk_tree_selection_select_path (selection,tree_path);
-          gtk_tree_path_free (tree_path);
-        }
-      else
-        {
-          set_iter_nth_row (tree_view, &iter_to_row, row);
-          gtk_tree_selection_select_iter (selection, &iter_to_row);
-        }
-    }
+  if (!_gtk_rbtree_find_index (_gtk_tree_view_get_rbtree (treeview),
+                               row,
+                               &tree,
+                               &node))
+    return FALSE;
 
-  return gtk_tree_view_accessible_is_row_selected (table, row);
+  if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
+    return FALSE;
+
+  path = _gtk_tree_path_new_from_rbtree (tree, node);
+  gtk_tree_selection_select_path (gtk_tree_view_get_selection (treeview), path);
+  gtk_tree_path_free (path);
+
+  return TRUE;
 }
 
 static gboolean
 gtk_tree_view_accessible_remove_row_selection (AtkTable *table,
                                                gint      row)
 {
-  GtkWidget *widget;
-  GtkTreeView *tree_view;
-  GtkTreeSelection *selection;
+  GtkTreeView *treeview;
+  GtkTreePath *path;
+  GtkRBTree *tree;
+  GtkRBNode *node;
 
-  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
-  if (widget == NULL)
+  if (row < 0)
     return FALSE;
 
-  tree_view = GTK_TREE_VIEW (widget);
-  selection = gtk_tree_view_get_selection (tree_view);
+  treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (table)));
+  if (treeview == NULL)
+    return FALSE;
 
-  if (gtk_tree_view_accessible_is_row_selected (table, row))
-    {
-      gtk_tree_selection_unselect_all (selection);
-      return TRUE;
-    }
+  if (!_gtk_rbtree_find_index (_gtk_tree_view_get_rbtree (treeview),
+                               row,
+                               &tree,
+                               &node))
+    return FALSE;
 
-  return FALSE;
+  if (! GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED))
+    return FALSE;
+
+  path = _gtk_tree_path_new_from_rbtree (tree, node);
+  gtk_tree_selection_unselect_path (gtk_tree_view_get_selection (treeview), path);
+  gtk_tree_path_free (path);
+
+  return TRUE;
 }
 
 static AtkObject *
@@ -1425,51 +1279,6 @@ gtk_tree_view_accessible_get_renderer_state (GtkCellAccessibleParent *parent,
   return flags;
 }
 
-static void
-gtk_tree_view_accessible_set_cell_data (GtkCellAccessibleParent *parent,
-                                        GtkCellAccessible       *cell)
-{
-  GtkTreeViewAccessibleCellInfo *cell_info;
-  GtkTreeView *treeview;
-  gboolean is_expander, is_expanded;
-  GtkTreeModel *model;
-  GtkTreeIter iter;
-  GtkTreePath *path;
-
-  cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
-  if (!cell_info)
-    return;
-
-  treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
-  model = gtk_tree_view_get_model (treeview);
-
-  if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_PARENT) &&
-      cell_info->cell_col_ref == gtk_tree_view_get_expander_column (treeview))
-    {
-      is_expander = TRUE;
-      is_expanded = cell_info->node->children != NULL;
-    }
-  else
-    {
-      is_expander = FALSE;
-      is_expanded = FALSE;
-    }
-
-  path = cell_info_get_path (cell_info);
-  if (path == NULL ||
-      !gtk_tree_model_get_iter (model, &iter, path))
-    {
-      /* We only track valid cells, this should never happen */
-      g_return_if_reached ();
-    }
-
-  gtk_tree_view_column_cell_set_cell_data (cell_info->cell_col_ref,
-                                           model,
-                                           &iter,
-                                           is_expander,
-                                           is_expanded);
-}
-
 static void
 gtk_tree_view_accessible_expand_collapse (GtkCellAccessibleParent *parent,
                                           GtkCellAccessible       *cell)
@@ -1540,165 +1349,11 @@ gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface)
   iface->grab_focus = gtk_tree_view_accessible_grab_cell_focus;
   iface->get_child_index = gtk_tree_view_accessible_get_child_index;
   iface->get_renderer_state = gtk_tree_view_accessible_get_renderer_state;
-  iface->set_cell_data = gtk_tree_view_accessible_set_cell_data;
   iface->expand_collapse = gtk_tree_view_accessible_expand_collapse;
   iface->activate = gtk_tree_view_accessible_activate;
   iface->edit = gtk_tree_view_accessible_edit;
 }
 
-/* signal handling */
-
-static void
-selection_changed_cb (GtkTreeSelection *selection,
-                      gpointer          data)
-{
-  GtkTreeViewAccessible *accessible;
-  GtkTreeView *tree_view;
-  GtkWidget *widget;
-  GtkTreeViewAccessibleCellInfo *info;
-  GtkTreeSelection *tree_selection;
-  GtkTreePath *path;
-  GHashTableIter iter;
-
-  accessible = GTK_TREE_VIEW_ACCESSIBLE (data);
-  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
-  if (widget == NULL)
-    return;
-
-  tree_view = GTK_TREE_VIEW (widget);
-  tree_selection = gtk_tree_view_get_selection (tree_view);
-
-  /* FIXME: clean rows iterates through all cells too */
-  g_hash_table_iter_init (&iter, accessible->cell_infos);
-  while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&info))
-    {
-      _gtk_cell_accessible_remove_state (info->cell, ATK_STATE_SELECTED, TRUE);
-
-      path = cell_info_get_path (info);
-      if (path && gtk_tree_selection_path_is_selected (tree_selection, path))
-        _gtk_cell_accessible_add_state (info->cell, ATK_STATE_SELECTED, TRUE);
-      gtk_tree_path_free (path);
-    }
-  if (gtk_widget_get_realized (widget))
-    g_signal_emit_by_name (accessible, "selection-changed");
-}
-
-static void
-cursor_changed (GtkTreeView           *tree_view,
-                GtkTreeViewAccessible *accessible)
-{
-  AtkObject *cell;
-
-  cell = gtk_tree_view_accessible_ref_focus_cell (tree_view);
-  if (cell)
-    {
-      if (cell != accessible->focus_cell)
-        {
-          if (accessible->focus_cell)
-            {
-              _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_ACTIVE, FALSE);
-              _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_FOCUSED, FALSE);
-              g_object_unref (accessible->focus_cell);
-              accessible->focus_cell = cell;
-            }
-
-          if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
-            {
-              _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_ACTIVE, FALSE);
-              _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_FOCUSED, FALSE);
-            }
-
-          g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
-        }
-      else
-        g_object_unref (cell);
-    }
-}
-
-static gboolean
-focus_in (GtkWidget *widget)
-{
-  GtkTreeView *tree_view;
-  GtkTreeViewAccessible *accessible;
-  AtkStateSet *state_set;
-  AtkObject *cell;
-
-  tree_view = GTK_TREE_VIEW (widget);
-  accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
-
-  if (accessible->focus_cell == NULL)
-    {
-      cell = gtk_tree_view_accessible_ref_focus_cell (tree_view);
-      if (cell)
-        {
-          state_set = atk_object_ref_state_set (cell);
-          if (state_set)
-            {
-              if (!atk_state_set_contains_state (state_set, ATK_STATE_FOCUSED))
-                {
-                  _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_ACTIVE, FALSE);
-                  accessible->focus_cell = cell;
-                  _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_FOCUSED, FALSE);
-                  g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
-                }
-              g_object_unref (state_set);
-            }
-        }
-    }
-  return FALSE;
-}
-
-static gboolean
-focus_out (GtkWidget *widget)
-{
-  GtkTreeViewAccessible *accessible;
-
-  accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
-  if (accessible->focus_cell)
-    {
-      _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_ACTIVE, FALSE);
-      _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_FOCUSED, FALSE);
-      g_object_unref (accessible->focus_cell);
-      accessible->focus_cell = NULL;
-    }
-  return FALSE;
-}
-
-static void
-model_row_changed (GtkTreeModel *tree_model,
-                   GtkTreePath  *path,
-                   GtkTreeIter  *iter,
-                   gpointer      user_data)
-{
-  GtkTreeView *tree_view = GTK_TREE_VIEW (user_data);
-  GtkTreeViewAccessible *accessible;
-  GtkTreePath *cell_path;
-  GtkTreeViewAccessibleCellInfo *cell_info;
-  GHashTableIter hash_iter;
-
-  accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (tree_view)));
-
-  /* Loop through our cached cells */
-  /* Must loop through them all */
-  g_hash_table_iter_init (&hash_iter, accessible->cell_infos);
-  while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer *)&cell_info))
-    {
-      cell_path = cell_info_get_path (cell_info);
-
-      if (cell_path != NULL)
-        {
-          if (path && gtk_tree_path_compare (cell_path, path) == 0)
-            {
-              if (GTK_IS_RENDERER_CELL_ACCESSIBLE (cell_info->cell))
-                update_cell_value (GTK_RENDERER_CELL_ACCESSIBLE (cell_info->cell),
-                                   accessible, TRUE);
-            }
-          gtk_tree_path_free (cell_path);
-        }
-    }
-  g_signal_emit_by_name (accessible, "visible-data-changed");
-}
-
 void
 _gtk_tree_view_accessible_reorder (GtkTreeView *treeview)
 {
@@ -1751,322 +1406,8 @@ is_cell_showing (GtkTreeView  *tree_view,
   return is_showing;
 }
 
-/* Misc Public */
-
-/* This function is called when a cell's flyweight is created in
- * gtk_tree_view_accessible_table_ref_at with emit_change_signal
- * set to FALSE and in model_row_changed() on receipt of "row-changed"
- * signal when emit_change_signal is set to TRUE
- */
-static gboolean
-update_cell_value (GtkRendererCellAccessible      *renderer_cell,
-                   GtkTreeViewAccessible *accessible,
-                   gboolean               emit_change_signal)
-{
-  GtkTreeViewAccessibleCellInfo *cell_info;
-  GtkTreeView *tree_view;
-  GtkTreeModel *tree_model;
-  GtkTreePath *path;
-  GtkTreeIter iter;
-  GList *renderers, *cur_renderer;
-  GParamSpec *spec;
-  GtkRendererCellAccessibleClass *renderer_cell_class;
-  GtkCellRendererClass *gtk_cell_renderer_class;
-  GtkCellAccessible *cell;
-  gchar **prop_list;
-  AtkObject *parent;
-  gboolean is_expander, is_expanded;
-
-  renderer_cell_class = GTK_RENDERER_CELL_ACCESSIBLE_GET_CLASS (renderer_cell);
-  if (renderer_cell->renderer)
-    gtk_cell_renderer_class = GTK_CELL_RENDERER_GET_CLASS (renderer_cell->renderer);
-  else
-    gtk_cell_renderer_class = NULL;
-
-  prop_list = renderer_cell_class->property_list;
-
-  cell = GTK_CELL_ACCESSIBLE (renderer_cell);
-  cell_info = find_cell_info (accessible, cell);
-  if (!cell_info)
-    return FALSE;
-
-  if (emit_change_signal)
-    {
-      tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
-      tree_model = gtk_tree_view_get_model (tree_view);
-      path = cell_info_get_path (cell_info);
-      if (path == NULL)
-        return FALSE;
-
-      gtk_tree_model_get_iter (tree_model, &iter, path);
-      is_expander = FALSE;
-      is_expanded = FALSE;
-      if (gtk_tree_model_iter_has_child (tree_model, &iter))
-        {
-          GtkTreeViewColumn *expander_tv;
-
-          expander_tv = gtk_tree_view_get_expander_column (tree_view);
-          if (expander_tv == cell_info->cell_col_ref)
-            {
-              is_expander = TRUE;
-              is_expanded = gtk_tree_view_row_expanded (tree_view, path);
-            }
-        }
-      gtk_tree_path_free (path);
-      gtk_tree_view_column_cell_set_cell_data (cell_info->cell_col_ref,
-                                               tree_model, &iter,
-                                               is_expander, is_expanded);
-    }
-  renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_info->cell_col_ref));
-  if (!renderers)
-    return FALSE;
-
-  /* If the cell is in a container, its index is used to find the renderer
-   * in the list. Otherwise, we assume that the cell is represented
-   * by the first renderer in the list
-   */
-  parent = atk_object_get_parent (ATK_OBJECT (cell));
-
-  if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
-    cur_renderer = g_list_nth (renderers, atk_object_get_index_in_parent (ATK_OBJECT (cell)));
-  else
-    cur_renderer = renderers;
-
-  if (cur_renderer == NULL)
-    return FALSE;
-
-  if (gtk_cell_renderer_class)
-    {
-      while (*prop_list)
-        {
-          spec = g_object_class_find_property
-                           (G_OBJECT_CLASS (gtk_cell_renderer_class), *prop_list);
-
-          if (spec != NULL)
-            {
-              GValue value = G_VALUE_INIT;
-
-              g_value_init (&value, spec->value_type);
-              g_object_get_property (cur_renderer->data, *prop_list, &value);
-              g_object_set_property (G_OBJECT (renderer_cell->renderer),
-                                     *prop_list, &value);
-              g_value_unset (&value);
-            }
-          else
-            g_warning ("Invalid property: %s\n", *prop_list);
-          prop_list++;
-        }
-    }
-  g_list_free (renderers);
-
-  return _gtk_renderer_cell_accessible_update_cache (renderer_cell, emit_change_signal);
-}
-
-static gint
-get_row_from_tree_path (GtkTreeView *tree_view,
-                        GtkTreePath *path)
-{
-  GtkTreeModel *tree_model;
-  GtkTreePath *root_tree;
-  gint row;
-
-  tree_model = gtk_tree_view_get_model (tree_view);
-
-  if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
-    row = gtk_tree_path_get_indices (path)[0];
-  else
-    {
-      root_tree = gtk_tree_path_new_first ();
-      row = 0;
-      iterate_thru_children (tree_view, tree_model, root_tree, path, &row, 0);
-      gtk_tree_path_free (root_tree);
-    }
-
-  return row;
-}
-
 /* Misc Private */
 
-/* Helper recursive function that returns an iter to nth row
- */
-static GtkTreeIter *
-return_iter_nth_row (GtkTreeView  *tree_view,
-                     GtkTreeModel *tree_model,
-                     GtkTreeIter  *iter,
-                     gint          increment,
-                     gint          row)
-{
-  GtkTreePath *current_path;
-  GtkTreeIter new_iter;
-  gboolean row_expanded;
-
-  current_path = gtk_tree_model_get_path (tree_model, iter);
-  if (increment == row)
-    {
-      gtk_tree_path_free (current_path);
-      return iter;
-    }
-
-  row_expanded = gtk_tree_view_row_expanded (tree_view, current_path);
-  gtk_tree_path_free (current_path);
-
-  new_iter = *iter;
-  if ((row_expanded && gtk_tree_model_iter_children (tree_model, iter, &new_iter)) ||
-      (gtk_tree_model_iter_next (tree_model, iter)) ||
-      (gtk_tree_model_iter_parent (tree_model, iter, &new_iter) &&
-          (gtk_tree_model_iter_next (tree_model, iter))))
-    return return_iter_nth_row (tree_view, tree_model, iter,
-      ++increment, row);
-
-  return NULL;
-}
-
-static void
-set_iter_nth_row (GtkTreeView *tree_view,
-                  GtkTreeIter *iter,
-                  gint         row)
-{
-  GtkTreeModel *tree_model;
-
-  tree_model = gtk_tree_view_get_model (tree_view);
-  gtk_tree_model_get_iter_first (tree_model, iter);
-  iter = return_iter_nth_row (tree_view, tree_model, iter, 0, row);
-}
-
-/* Recursively called until the row specified by orig is found.
- *
- * *count will be set to the visible row number of the child
- * relative to the row that was initially passed in as tree_path.
- * tree_path could be modified by this function.
- *
- * *count will be -1 if orig is not found as a child (a row that is
- * not visible will not be found, e.g. if the row is inside a
- * collapsed row).  If NULL is passed in as orig, *count will
- * be a count of the visible children.
- *
- * NOTE: the value for depth must be 0 when this recursive function
- * is initially called, or it may not function as expected.
- */
-static void
-iterate_thru_children (GtkTreeView  *tree_view,
-                       GtkTreeModel *tree_model,
-                       GtkTreePath  *tree_path,
-                       GtkTreePath  *orig,
-                       gint         *count,
-                       gint          depth)
-{
-  GtkTreeIter iter;
-
-  if (!gtk_tree_model_get_iter (tree_model, &iter, tree_path))
-    return;
-
-  if (tree_path && orig && !gtk_tree_path_compare (tree_path, orig))
-    /* Found it! */
-    return;
-
-  if (tree_path && orig && gtk_tree_path_compare (tree_path, orig) > 0)
-    {
-      /* Past it, so return -1 */
-      *count = -1;
-      return;
-    }
-  else if (gtk_tree_view_row_expanded (tree_view, tree_path) &&
-    gtk_tree_model_iter_has_child (tree_model, &iter))
-    {
-      (*count)++;
-      gtk_tree_path_append_index (tree_path, 0);
-      iterate_thru_children (tree_view, tree_model, tree_path,
-                             orig, count, (depth + 1));
-      return;
-    }
-  else if (gtk_tree_model_iter_next (tree_model, &iter))
-    {
-      (*count)++;
-      tree_path = gtk_tree_model_get_path (tree_model, &iter);
-       if (tree_path)
-         {
-           iterate_thru_children (tree_view, tree_model, tree_path,
-                                 orig, count, depth);
-           gtk_tree_path_free (tree_path);
-         }
-      return;
-  }
-  else if (gtk_tree_path_up (tree_path))
-    {
-      GtkTreeIter temp_iter;
-      gboolean exit_loop = FALSE;
-      gint new_depth = depth - 1;
-
-      (*count)++;
-
-     /* Make sure that we back up until we find a row
-      * where gtk_tree_path_next does not return NULL.
-      */
-      while (!exit_loop)
-        {
-          if (gtk_tree_path_get_depth (tree_path) == 0)
-              /* depth is now zero so */
-            return;
-          gtk_tree_path_next (tree_path);
-
-          /* Verify that the next row is a valid row! */
-          exit_loop = gtk_tree_model_get_iter (tree_model, &temp_iter, tree_path);
-
-          if (!exit_loop)
-            {
-              /* Keep going up until we find a row that has a valid next */
-              if (gtk_tree_path_get_depth(tree_path) > 1)
-                {
-                  new_depth--;
-                  gtk_tree_path_up (tree_path);
-                }
-              else
-                {
-                 /* If depth is 1 and gtk_tree_model_get_iter returns FALSE,
-                  * then we are at the last row, so just return.
-                  */
-                  if (orig != NULL)
-                    *count = -1;
-
-                  return;
-                }
-            }
-        }
-
-     /* This guarantees that we will stop when we hit the end of the
-      * children.
-      */
-      if (new_depth < 0)
-        return;
-
-      iterate_thru_children (tree_view, tree_model, tree_path,
-                             orig, count, new_depth);
-      return;
-    }
-
- /* If it gets here, then the path wasn't found.  Situations
-  * that would cause this would be if the path passed in is
-  * invalid or contained within the last row, but not visible
-  * because the last row is not expanded.  If NULL was passed
-  * in then a row count is desired, so only set count to -1
-  * if orig is not NULL.
-  */
-  if (orig != NULL)
-    *count = -1;
-
-  return;
-}
-
-static void
-cell_destroyed (gpointer data)
-{
-  GtkTreeViewAccessibleCellInfo *cell_info = data;
-
-  cell_info->cell = NULL;
-
-  g_hash_table_remove (cell_info->view->cell_infos, cell_info);
-}
-
 static int
 cell_info_get_index (GtkTreeView                     *tree_view,
                      GtkTreeViewAccessibleCellInfo   *info)
@@ -2082,7 +1423,6 @@ cell_info_get_index (GtkTreeView                     *tree_view,
 
 static void
 cell_info_new (GtkTreeViewAccessible *accessible,
-               GtkTreeModel          *tree_model,
                GtkRBTree             *tree,
                GtkRBNode             *node,
                GtkTreeViewColumn     *tv_col,
@@ -2095,79 +1435,14 @@ cell_info_new (GtkTreeViewAccessible *accessible,
   cell_info->tree = tree;
   cell_info->node = node;
   cell_info->cell_col_ref = tv_col;
-  cell_info->cell = cell;
+  cell_info->cell = g_object_ref (cell);
   cell_info->view = accessible;
 
-  g_object_set_qdata_full (G_OBJECT (cell), 
-                           gtk_tree_view_accessible_get_data_quark (),
-                           cell_info,
-                           cell_destroyed);
-
-  g_hash_table_replace (accessible->cell_infos, cell_info, cell_info);
-}
-
-static GtkCellAccessible *
-peek_cell (GtkTreeViewAccessible *accessible,
-           GtkRBTree             *tree,
-           GtkRBNode             *node,
-           GtkTreeViewColumn     *column)
-{
-  GtkTreeViewAccessibleCellInfo lookup, *cell_info;
+  g_object_set_qdata (G_OBJECT (cell), 
+                      gtk_tree_view_accessible_get_data_quark (),
+                      cell_info);
 
-  lookup.tree = tree;
-  lookup.node = node;
-  lookup.cell_col_ref = column;
-
-  cell_info = g_hash_table_lookup (accessible->cell_infos, &lookup);
-  if (cell_info == NULL)
-    return NULL;
-
-  return cell_info->cell;
-}
-
-static GtkCellAccessible *
-find_cell (GtkTreeViewAccessible *accessible,
-           gint                   index)
-{
-  GtkTreeView *tree_view;
-  GtkRBTree *tree;
-  GtkRBNode *node;
-
-  tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
-
-  if (!_gtk_rbtree_find_index (_gtk_tree_view_get_rbtree (tree_view),
-                               index / get_n_columns (tree_view) - 1,
-                               &tree,
-                               &node))
-    {
-      g_assert_not_reached ();
-    }
-
-  return peek_cell (accessible,
-                    tree, node, 
-                    get_visible_column (tree_view, index % get_n_columns (tree_view)));
-}
-
-static void
-connect_model_signals (GtkTreeView           *view,
-                       GtkTreeViewAccessible *accessible)
-{
-  GObject *obj;
-
-  obj = G_OBJECT (accessible->tree_model);
-  g_signal_connect_data (obj, "row-changed",
-                         G_CALLBACK (model_row_changed), view, NULL, 0);
-}
-
-static void
-disconnect_model_signals (GtkTreeViewAccessible *accessible)
-{
-  GObject *obj;
-  GtkWidget *widget;
-
-  obj = G_OBJECT (accessible->tree_model);
-  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
-  g_signal_handlers_disconnect_by_func (obj, model_row_changed, widget);
+  g_hash_table_replace (accessible->priv->cell_infos, cell_info, cell_info);
 }
 
 /* Returns the column number of the specified GtkTreeViewColumn
@@ -2200,93 +1475,6 @@ get_column_number (GtkTreeView       *treeview,
   return number;
 }
 
-static gint
-get_index (GtkTreeView *tree_view,
-           GtkTreePath *path,
-           gint         actual_column)
-{
-  gint depth = 0;
-  gint index = 1;
-  gint *indices = NULL;
-
-  if (path)
-    {
-      depth = gtk_tree_path_get_depth (path);
-      indices = gtk_tree_path_get_indices (path);
-    }
-
-  if (depth > 1)
-    {
-      GtkTreePath *copy_path;
-      GtkTreeModel *model;
-
-      model = gtk_tree_view_get_model (tree_view);
-      copy_path = gtk_tree_path_copy (path);
-      gtk_tree_path_up (copy_path);
-      count_rows (model, NULL, copy_path, &index, 0, depth);
-      gtk_tree_path_free (copy_path);
-    }
-
-  if (path)
-    index += indices[depth - 1];
-  index *= get_n_columns (tree_view);
-  index +=  actual_column;
-  return index;
-}
-
-/* The function count_rows counts the number of rows starting at iter
- * and ending at end_path. The value of level is the depth of iter and
- * the value of depth is the depth of end_path. Rows at depth before
- * end_path are counted. This functions counts rows which are not visible
- * because an ancestor is collapsed.
- */
-static void
-count_rows (GtkTreeModel *model,
-            GtkTreeIter  *iter,
-            GtkTreePath  *end_path,
-            gint         *count,
-            gint          level,
-            gint          depth)
-{
-  GtkTreeIter child_iter;
-
-  if (!model)
-    return;
-
-  level++;
-  *count += gtk_tree_model_iter_n_children (model, iter);
-
-  if (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY)
-    return;
-
-  if (level >= depth)
-    return;
-
-  if (gtk_tree_model_iter_children (model, &child_iter, iter))
-    {
-      gboolean ret_val = TRUE;
-
-      while (ret_val)
-        {
-          if (level == depth - 1)
-            {
-              GtkTreePath *iter_path;
-              gboolean finished = FALSE;
-
-              iter_path = gtk_tree_model_get_path (model, &child_iter);
-              if (end_path && gtk_tree_path_compare (iter_path, end_path) >= 0)
-                finished = TRUE;
-              gtk_tree_path_free (iter_path);
-              if (finished)
-                break;
-            }
-          if (gtk_tree_model_iter_has_child (model, &child_iter))
-            count_rows (model, &child_iter, end_path, count, level, depth);
-          ret_val = gtk_tree_model_iter_next (model, &child_iter);
-        }
-    }
-}
-
 static gboolean
 get_rbtree_column_from_index (GtkTreeView        *tree_view,
                               gint                index,
@@ -2385,10 +1573,13 @@ _gtk_tree_view_accessible_add (GtkTreeView *treeview,
   g_signal_emit_by_name (accessible, "row-inserted", row, n_rows);
 
   n_cols = get_n_columns (treeview);
-  for (i = (row + 1) * n_cols; i < (row + n_rows + 1) * n_cols; i++)
+  if (n_cols)
     {
-     /* Pass NULL as the child object, i.e. 4th argument */
-      g_signal_emit_by_name (accessible, "children-changed::add", i, NULL, NULL);
+      for (i = (row + 1) * n_cols; i < (row + n_rows + 1) * n_cols; i++)
+        {
+         /* Pass NULL as the child object, i.e. 4th argument */
+          g_signal_emit_by_name (accessible, "children-changed::add", i, NULL, NULL);
+        }
     }
 }
 
@@ -2424,20 +1615,49 @@ _gtk_tree_view_accessible_remove (GtkTreeView *treeview,
   g_signal_emit_by_name (accessible, "row-deleted", row, n_rows);
 
   n_cols = get_n_columns (treeview);
-  for (i = (n_rows + row + 1) * n_cols - 1; i >= (row + 1) * n_cols; i--)
+  if (n_cols)
     {
-     /* Pass NULL as the child object, i.e. 4th argument */
-      g_signal_emit_by_name (accessible, "children-changed::remove", i, NULL, NULL);
+      for (i = (n_rows + row + 1) * n_cols - 1; i >= (row + 1) * n_cols; i--)
+        {
+         /* Pass NULL as the child object, i.e. 4th argument */
+          g_signal_emit_by_name (accessible, "children-changed::remove", i, NULL, NULL);
+        }
+
+      g_hash_table_iter_init (&iter, accessible->priv->cell_infos);
+      while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
+        {
+          if (node == cell_info->node ||
+              tree == cell_info->tree ||
+              (tree && _gtk_rbtree_contains (tree, cell_info->tree)))
+            g_hash_table_iter_remove (&iter);
+        }
     }
+}
+
+void
+_gtk_tree_view_accessible_changed (GtkTreeView *treeview,
+                                   GtkRBTree   *tree,
+                                   GtkRBNode   *node)
+{
+  GtkTreeViewAccessible *accessible;
+  guint i;
 
-  g_hash_table_iter_init (&iter, accessible->cell_infos);
-  while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
+  accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (treeview)));
+
+  for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++)
     {
-      if (node == cell_info->node ||
-          tree == cell_info->tree ||
-          (tree && _gtk_rbtree_contains (tree, cell_info->tree)))
-        g_hash_table_iter_remove (&iter);
+      GtkCellAccessible *cell = peek_cell (accessible,
+                                           tree, node,
+                                           gtk_tree_view_get_column (treeview, i));
+
+      if (cell == NULL)
+        continue;
+
+      set_cell_data (treeview, accessible, cell);
+      _gtk_cell_accessible_update_cache (cell);
     }
+
+  g_signal_emit_by_name (accessible, "visible-data-changed");
 }
 
 /* NB: id is not checked, only columns < id are.
@@ -2462,11 +1682,11 @@ to_visible_column_id (GtkTreeView *treeview,
   return id - invisible;
 }
 
-void
-_gtk_tree_view_accessible_do_add_column (GtkTreeViewAccessible *accessible,
-                                         GtkTreeView           *treeview,
-                                         GtkTreeViewColumn     *column,
-                                         guint                  id)
+static void
+gtk_tree_view_accessible_do_add_column (GtkTreeViewAccessible *accessible,
+                                        GtkTreeView           *treeview,
+                                        GtkTreeViewColumn     *column,
+                                        guint                  id)
 {
   guint row, n_rows, n_cols;
 
@@ -2499,17 +1719,17 @@ _gtk_tree_view_accessible_add_column (GtkTreeView       *treeview,
   if (obj == NULL)
     return;
 
-  _gtk_tree_view_accessible_do_add_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
-                                           treeview,
-                                           column,
-                                           to_visible_column_id (treeview, id));
+  gtk_tree_view_accessible_do_add_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
+                                          treeview,
+                                          column,
+                                          to_visible_column_id (treeview, id));
 }
 
-void
-_gtk_tree_view_accessible_do_remove_column (GtkTreeViewAccessible *accessible,
-                                            GtkTreeView           *treeview,
-                                            GtkTreeViewColumn     *column,
-                                            guint                  id)
+static void
+gtk_tree_view_accessible_do_remove_column (GtkTreeViewAccessible *accessible,
+                                           GtkTreeView           *treeview,
+                                           GtkTreeViewColumn     *column,
+                                           guint                  id)
 {
   GtkTreeViewAccessibleCellInfo *cell_info;
   GHashTableIter iter;
@@ -2517,7 +1737,7 @@ _gtk_tree_view_accessible_do_remove_column (GtkTreeViewAccessible *accessible,
   guint row, n_rows, n_cols;
 
   /* Clean column from cache */
-  g_hash_table_iter_init (&iter, accessible->cell_infos);
+  g_hash_table_iter_init (&iter, accessible->priv->cell_infos);
   while (g_hash_table_iter_next (&iter, NULL, &value))
     {
       cell_info = value;
@@ -2554,10 +1774,10 @@ _gtk_tree_view_accessible_remove_column (GtkTreeView       *treeview,
   if (obj == NULL)
     return;
 
-  _gtk_tree_view_accessible_do_remove_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
-                                              treeview,
-                                              column,
-                                              to_visible_column_id (treeview, id));
+  gtk_tree_view_accessible_do_remove_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
+                                             treeview,
+                                             column,
+                                             to_visible_column_id (treeview, id));
 }
 
 void
@@ -2578,24 +1798,95 @@ _gtk_tree_view_accessible_toggle_visibility (GtkTreeView       *treeview,
                                              GtkTreeViewColumn *column)
 {
   AtkObject *obj;
-  guint id;
+  guint i, id;
 
   obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
   if (obj == NULL)
     return;
 
-  id = get_column_number (treeview, column);
-
   if (gtk_tree_view_column_get_visible (column))
-    _gtk_tree_view_accessible_do_add_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
-                                             treeview,
-                                             column,
-                                             id);
+    {
+      id = get_column_number (treeview, column);
+
+      gtk_tree_view_accessible_do_add_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
+                                              treeview,
+                                              column,
+                                              id);
+    }
   else
-    _gtk_tree_view_accessible_do_remove_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
-                                                treeview,
-                                                column,
-                                                id);
+    {
+      id = 0;
+
+      for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++)
+        {
+          GtkTreeViewColumn *cur = gtk_tree_view_get_column (treeview, i);
+          
+          if (gtk_tree_view_column_get_visible (cur))
+            id++;
+
+          if (cur == column)
+            break;
+        }
+
+      gtk_tree_view_accessible_do_remove_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
+                                                 treeview,
+                                                 column,
+                                                 id);
+    }
+}
+
+static GtkTreeViewColumn *
+get_effective_focus_column (GtkTreeView       *treeview,
+                            GtkTreeViewColumn *column)
+{
+  if (column == NULL)
+    column = get_visible_column (treeview, 0);
+
+  return column;
+}
+
+void
+_gtk_tree_view_accessible_update_focus_column (GtkTreeView       *treeview,
+                                               GtkTreeViewColumn *old_focus,
+                                               GtkTreeViewColumn *new_focus)
+{
+  GtkTreeViewAccessible *accessible;
+  AtkObject *obj;
+  GtkRBTree *cursor_tree;
+  GtkRBNode *cursor_node;
+  GtkCellAccessible *cell;
+
+  old_focus = get_effective_focus_column (treeview, old_focus);
+  new_focus = get_effective_focus_column (treeview, new_focus);
+  if (old_focus == new_focus)
+    return;
+
+  obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
+  if (obj == NULL)
+    return;
+
+  accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
+
+  if (!_gtk_tree_view_get_cursor_node (treeview, &cursor_tree, &cursor_node))
+    return;
+
+  if (old_focus)
+    {
+      cell = peek_cell (accessible, cursor_tree, cursor_node, old_focus);
+      if (cell != NULL)
+        _gtk_cell_accessible_state_changed (cell, GTK_CELL_RENDERER_FOCUSED, 0);
+    }
+
+  if (new_focus)
+    {
+      cell = peek_cell (accessible, cursor_tree, cursor_node, new_focus);
+      if (cell != NULL)
+        _gtk_cell_accessible_state_changed (cell, 0, GTK_CELL_RENDERER_FOCUSED);
+      else
+        cell = create_cell (treeview, accessible, cursor_tree, cursor_node, new_focus);
+
+      g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
+    }
 }
 
 void
@@ -2605,6 +1896,7 @@ _gtk_tree_view_accessible_add_state (GtkTreeView          *treeview,
                                      GtkCellRendererState  state)
 {
   GtkTreeViewAccessible *accessible;
+  GtkTreeViewColumn *single_column;
   AtkObject *obj;
   guint i;
 
@@ -2614,17 +1906,52 @@ _gtk_tree_view_accessible_add_state (GtkTreeView          *treeview,
 
   accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
 
-  for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++)
+  if (state == GTK_CELL_RENDERER_FOCUSED)
+    {
+      single_column = get_effective_focus_column (treeview, _gtk_tree_view_get_focus_column (treeview));
+    }
+  else if (state == GTK_CELL_RENDERER_EXPANDED ||
+           state == GTK_CELL_RENDERER_EXPANDABLE)
+    {
+      single_column = gtk_tree_view_get_expander_column (treeview);
+    }
+  else
+    single_column = NULL;
+
+  if (single_column)
     {
       GtkCellAccessible *cell = peek_cell (accessible,
                                            tree, node,
-                                           gtk_tree_view_get_column (treeview, i));
+                                           single_column);
 
-      if (cell == NULL)
-        continue;
+      if (cell != NULL)
+        _gtk_cell_accessible_state_changed (cell, state, 0);
 
-      _gtk_cell_accessible_state_changed (cell, state, 0);
+      if (state == GTK_CELL_RENDERER_FOCUSED)
+        {
+          if (cell == NULL)
+            cell = create_cell (treeview, accessible, tree, node, single_column);
+          
+          g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
+        }
     }
+  else
+    {
+      for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++)
+        {
+          GtkCellAccessible *cell = peek_cell (accessible,
+                                               tree, node,
+                                               gtk_tree_view_get_column (treeview, i));
+
+          if (cell == NULL)
+            continue;
+
+          _gtk_cell_accessible_state_changed (cell, state, 0);
+        }
+    }
+
+  if (state == GTK_CELL_RENDERER_SELECTED)
+    g_signal_emit_by_name (accessible, "selection-changed");
 }
 
 void
@@ -2634,6 +1961,7 @@ _gtk_tree_view_accessible_remove_state (GtkTreeView          *treeview,
                                         GtkCellRendererState  state)
 {
   GtkTreeViewAccessible *accessible;
+  GtkTreeViewColumn *single_column;
   AtkObject *obj;
   guint i;
 
@@ -2643,15 +1971,42 @@ _gtk_tree_view_accessible_remove_state (GtkTreeView          *treeview,
 
   accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
 
-  for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++)
+  if (state == GTK_CELL_RENDERER_FOCUSED)
+    {
+      single_column = get_effective_focus_column (treeview, _gtk_tree_view_get_focus_column (treeview));
+    }
+  else if (state == GTK_CELL_RENDERER_EXPANDED ||
+           state == GTK_CELL_RENDERER_EXPANDABLE)
+    {
+      single_column = gtk_tree_view_get_expander_column (treeview);
+    }
+  else
+    single_column = NULL;
+
+  if (single_column)
     {
       GtkCellAccessible *cell = peek_cell (accessible,
                                            tree, node,
-                                           gtk_tree_view_get_column (treeview, i));
+                                           single_column);
 
-      if (cell == NULL)
-        continue;
+      if (cell != NULL)
+        _gtk_cell_accessible_state_changed (cell, 0, state);
+    }
+  else
+    {
+      for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++)
+        {
+          GtkCellAccessible *cell = peek_cell (accessible,
+                                               tree, node,
+                                               gtk_tree_view_get_column (treeview, i));
+
+          if (cell == NULL)
+            continue;
 
-      _gtk_cell_accessible_state_changed (cell, 0, state);
+          _gtk_cell_accessible_state_changed (cell, 0, state);
+        }
     }
+
+  if (state == GTK_CELL_RENDERER_SELECTED)
+    g_signal_emit_by_name (accessible, "selection-changed");
 }