1 /* GAIL - The GNOME Accessibility Implementation Library
2 * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 #ifdef GDK_WINDOWING_X11
24 #include <gdk/x11/gdkx.h>
27 #include "gtktreeprivate.h"
28 #include "gtkwidgetprivate.h"
30 #include "gtktreeviewaccessible.h"
31 #include "gtkrenderercellaccessible.h"
32 #include "gtkbooleancellaccessible.h"
33 #include "gtkimagecellaccessible.h"
34 #include "gtkcontainercellaccessible.h"
35 #include "gtktextcellaccessible.h"
36 #include "gtkcellaccessibleparent.h"
38 typedef struct _GtkTreeViewAccessibleCellInfo GtkTreeViewAccessibleCellInfo;
39 struct _GtkTreeViewAccessibleCellInfo
41 GtkCellAccessible *cell;
44 GtkTreeViewColumn *cell_col_ref;
45 GtkTreeViewAccessible *view;
50 static void selection_changed_cb (GtkTreeSelection *selection,
53 static void cursor_changed (GtkTreeView *tree_view,
54 GtkTreeViewAccessible *accessible);
55 static gboolean focus_in (GtkWidget *widget);
56 static gboolean focus_out (GtkWidget *widget);
60 static void set_iter_nth_row (GtkTreeView *tree_view,
63 static gint get_row_from_tree_path (GtkTreeView *tree_view,
65 static void iterate_thru_children (GtkTreeView *tree_view,
66 GtkTreeModel *tree_model,
67 GtkTreePath *tree_path,
71 static int cell_info_get_index (GtkTreeView *tree_view,
72 GtkTreeViewAccessibleCellInfo *info);
73 static gboolean update_cell_value (GtkRendererCellAccessible *renderer_cell,
74 GtkTreeViewAccessible *accessible,
75 gboolean emit_change_signal);
76 static gboolean is_cell_showing (GtkTreeView *tree_view,
77 GdkRectangle *cell_rect);
78 static void set_expand_state (GtkTreeView *tree_view,
79 GtkTreeModel *tree_model,
80 GtkTreeViewAccessible *accessible,
81 GtkTreePath *tree_path,
82 gboolean set_on_ancestor);
83 static void set_cell_expandable (GtkCellAccessible *cell);
84 static void add_cell_actions (GtkCellAccessible *cell,
87 static void edit_cell (GtkCellAccessible *cell);
88 static void activate_cell (GtkCellAccessible *cell);
89 static void cell_destroyed (gpointer data);
90 static void cell_info_new (GtkTreeViewAccessible *accessible,
91 GtkTreeModel *tree_model,
94 GtkTreeViewColumn *tv_col,
95 GtkCellAccessible *cell);
96 static GtkCellAccessible *find_cell (GtkTreeViewAccessible *accessible,
98 static void connect_model_signals (GtkTreeView *view,
99 GtkTreeViewAccessible *accessible);
100 static void disconnect_model_signals (GtkTreeViewAccessible *accessible);
101 static gint get_column_number (GtkTreeView *tree_view,
102 GtkTreeViewColumn *column);
103 static gint get_focus_index (GtkTreeView *tree_view);
104 static gint get_index (GtkTreeView *tree_view,
107 static void count_rows (GtkTreeModel *model,
109 GtkTreePath *end_path,
114 static gboolean get_rbtree_column_from_index (GtkTreeView *tree_view,
118 GtkTreeViewColumn **column);
120 static GtkTreeViewAccessibleCellInfo* find_cell_info (GtkTreeViewAccessible *view,
121 GtkCellAccessible *cell);
122 static AtkObject * get_header_from_column (GtkTreeViewColumn *tv_col);
125 static void atk_table_interface_init (AtkTableIface *iface);
126 static void atk_selection_interface_init (AtkSelectionIface *iface);
127 static void atk_component_interface_init (AtkComponentIface *iface);
128 static void gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface);
130 G_DEFINE_TYPE_WITH_CODE (GtkTreeViewAccessible, _gtk_tree_view_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
131 G_IMPLEMENT_INTERFACE (ATK_TYPE_TABLE, atk_table_interface_init)
132 G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init)
133 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init)
134 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_ACCESSIBLE_PARENT, gtk_cell_accessible_parent_interface_init))
138 gtk_tree_view_accessible_get_data_quark (void)
140 static GQuark quark = 0;
142 if (G_UNLIKELY (quark == 0))
143 quark = g_quark_from_static_string ("gtk-tree-view-accessible-data");
149 cell_info_free (GtkTreeViewAccessibleCellInfo *cell_info)
153 g_object_steal_qdata (G_OBJECT (cell_info->cell),
154 gtk_tree_view_accessible_get_data_quark ());
155 _gtk_cell_accessible_add_state (cell_info->cell, ATK_STATE_DEFUNCT, FALSE);
162 cell_info_get_path (GtkTreeViewAccessibleCellInfo *cell_info)
164 return _gtk_tree_path_new_from_rbtree (cell_info->tree, cell_info->node);
168 cell_info_hash (gconstpointer info)
170 const GtkTreeViewAccessibleCellInfo *cell_info = info;
173 node = GPOINTER_TO_UINT (cell_info->node);
174 col = GPOINTER_TO_UINT (cell_info->cell_col_ref);
176 return ((node << sizeof (guint) / 2) | (node >> sizeof (guint) / 2)) ^ col;
180 cell_info_equal (gconstpointer a, gconstpointer b)
182 const GtkTreeViewAccessibleCellInfo *cell_info_a = a;
183 const GtkTreeViewAccessibleCellInfo *cell_info_b = b;
185 return cell_info_a->node == cell_info_b->node &&
186 cell_info_a->cell_col_ref == cell_info_b->cell_col_ref;
190 gtk_tree_view_accessible_initialize (AtkObject *obj,
193 GtkTreeViewAccessible *accessible;
194 GtkTreeView *tree_view;
195 GtkTreeModel *tree_model;
197 GtkTreeSelection *selection;
199 ATK_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->initialize (obj, data);
201 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
202 accessible->focus_cell = NULL;
204 accessible->cell_infos = g_hash_table_new_full (cell_info_hash,
205 cell_info_equal, NULL, (GDestroyNotify) cell_info_free);
207 widget = GTK_WIDGET (data);
208 tree_view = GTK_TREE_VIEW (widget);
209 tree_model = gtk_tree_view_get_model (tree_view);
210 selection = gtk_tree_view_get_selection (tree_view);
212 g_signal_connect (selection, "changed",
213 G_CALLBACK (selection_changed_cb), obj);
215 g_signal_connect (tree_view, "cursor-changed",
216 G_CALLBACK (cursor_changed), accessible);
217 g_signal_connect (tree_view, "focus-in-event",
218 G_CALLBACK (focus_in), NULL);
219 g_signal_connect (tree_view, "focus-out-event",
220 G_CALLBACK (focus_out), NULL);
222 accessible->tree_model = tree_model;
225 g_object_add_weak_pointer (G_OBJECT (accessible->tree_model), (gpointer *)&accessible->tree_model);
226 connect_model_signals (tree_view, accessible);
228 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
229 obj->role = ATK_ROLE_TABLE;
231 obj->role = ATK_ROLE_TREE_TABLE;
236 gtk_tree_view_accessible_finalize (GObject *object)
238 GtkTreeViewAccessible *accessible = GTK_TREE_VIEW_ACCESSIBLE (object);
240 if (accessible->tree_model)
241 disconnect_model_signals (accessible);
243 if (accessible->cell_infos)
244 g_hash_table_destroy (accessible->cell_infos);
246 G_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->finalize (object);
250 gtk_tree_view_accessible_notify_gtk (GObject *obj,
254 GtkTreeView *tree_view;
255 GtkTreeViewAccessible *accessible;
257 widget = GTK_WIDGET (obj);
258 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
259 tree_view = GTK_TREE_VIEW (widget);
261 if (g_strcmp0 (pspec->name, "model") == 0)
263 GtkTreeModel *tree_model;
266 tree_model = gtk_tree_view_get_model (tree_view);
267 if (accessible->tree_model)
268 disconnect_model_signals (accessible);
269 g_hash_table_remove_all (accessible->cell_infos);
270 accessible->tree_model = tree_model;
274 g_object_add_weak_pointer (G_OBJECT (accessible->tree_model), (gpointer *)&accessible->tree_model);
275 connect_model_signals (tree_view, accessible);
277 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
278 role = ATK_ROLE_TABLE;
280 role = ATK_ROLE_TREE_TABLE;
284 role = ATK_ROLE_UNKNOWN;
286 atk_object_set_role (ATK_OBJECT (accessible), role);
287 g_object_freeze_notify (G_OBJECT (accessible));
288 g_signal_emit_by_name (accessible, "model-changed");
289 g_signal_emit_by_name (accessible, "visible-data-changed");
290 g_object_thaw_notify (G_OBJECT (accessible));
293 GTK_WIDGET_ACCESSIBLE_CLASS (_gtk_tree_view_accessible_parent_class)->notify_gtk (obj, pspec);
297 gtk_tree_view_accessible_destroyed (GtkWidget *widget,
298 GtkAccessible *gtk_accessible)
300 GtkTreeViewAccessible *accessible;
302 if (!GTK_IS_TREE_VIEW (widget))
305 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_accessible);
307 if (accessible->tree_model)
309 disconnect_model_signals (accessible);
310 accessible->tree_model = NULL;
312 if (accessible->focus_cell)
314 g_object_unref (accessible->focus_cell);
315 accessible->focus_cell = NULL;
320 gtk_tree_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
324 widget = gtk_accessible_get_widget (accessible);
326 g_signal_connect_after (widget, "destroy",
327 G_CALLBACK (gtk_tree_view_accessible_destroyed), accessible);
329 GTK_ACCESSIBLE_CLASS (_gtk_tree_view_accessible_parent_class)->connect_widget_destroyed (accessible);
333 get_n_rows (GtkTreeView *tree_view)
337 tree = _gtk_tree_view_get_rbtree (tree_view);
342 return tree->root->total_count;
346 get_n_columns (GtkTreeView *tree_view)
348 guint i, visible_columns;
352 for (i = 0; i < gtk_tree_view_get_n_columns (tree_view); i++)
354 GtkTreeViewColumn *column = gtk_tree_view_get_column (tree_view, i);
356 if (gtk_tree_view_column_get_visible (column))
360 return visible_columns;
363 gtk_tree_view_accessible_get_n_children (AtkObject *obj)
366 GtkTreeView *tree_view;
368 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
372 tree_view = GTK_TREE_VIEW (widget);
373 return (get_n_rows (tree_view) + 1) * get_n_columns (tree_view);
376 static GtkTreeViewColumn *
377 get_visible_column (GtkTreeView *tree_view,
382 for (i = 0; i < gtk_tree_view_get_n_columns (tree_view); i++)
384 GtkTreeViewColumn *column = gtk_tree_view_get_column (tree_view, i);
386 if (!gtk_tree_view_column_get_visible (column))
395 g_return_val_if_reached (NULL);
399 gtk_tree_view_accessible_ref_child (AtkObject *obj,
403 GtkTreeViewAccessible *accessible;
404 GtkCellAccessible *cell;
405 GtkTreeView *tree_view;
406 GtkTreeModel *tree_model;
407 GtkCellRenderer *renderer;
409 GtkTreeViewColumn *tv_col;
410 GtkTreeSelection *selection;
416 GtkTreeViewColumn *expander_tv;
417 GList *renderer_list;
419 GtkContainerCellAccessible *container = NULL;
420 GtkRendererCellAccessible *renderer_cell;
421 gboolean is_expander, is_expanded, retval;
422 gboolean editable = FALSE;
425 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
429 if (i >= gtk_tree_view_accessible_get_n_children (obj))
432 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
433 tree_view = GTK_TREE_VIEW (widget);
434 if (i < get_n_columns (tree_view))
436 tv_col = get_visible_column (tree_view, i);
437 child = get_header_from_column (tv_col);
439 g_object_ref (child);
443 /* Check whether the child is cached */
444 cell = find_cell (accessible, i);
448 return ATK_OBJECT (cell);
451 if (accessible->focus_cell == NULL)
452 focus_index = get_focus_index (tree_view);
456 /* Find the RBTree and GtkTreeViewColumn for the index */
457 if (!get_rbtree_column_from_index (tree_view, i, &tree, &node, &tv_col))
460 path = _gtk_tree_path_new_from_rbtree (tree, node);
461 tree_model = gtk_tree_view_get_model (tree_view);
462 retval = gtk_tree_model_get_iter (tree_model, &iter, path);
466 expander_tv = gtk_tree_view_get_expander_column (tree_view);
469 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_PARENT))
471 if (expander_tv == tv_col)
474 is_expanded = node->children != NULL;
477 gtk_tree_view_column_cell_set_cell_data (tv_col, tree_model, &iter,
478 is_expander, is_expanded);
480 renderer_list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
482 /* If there is not exactly one renderer in the list,
485 if (renderer_list == NULL || renderer_list->next)
487 GtkCellAccessible *container_cell;
489 container = _gtk_container_cell_accessible_new ();
491 container_cell = GTK_CELL_ACCESSIBLE (container);
492 _gtk_cell_accessible_initialise (container_cell, widget, ATK_OBJECT (accessible));
494 /* The GtkTreeViewAccessibleCellInfo structure for the container will
495 * be before the ones for the cells so that the first one we find for
496 * a position will be for the container
498 cell_info_new (accessible, tree_model, tree, node, tv_col, container_cell);
499 parent = ATK_OBJECT (container);
502 parent = ATK_OBJECT (accessible);
506 for (l = renderer_list; l; l = l->next)
508 renderer = GTK_CELL_RENDERER (l->data);
510 if (GTK_IS_CELL_RENDERER_TEXT (renderer))
512 g_object_get (G_OBJECT (renderer), "editable", &editable, NULL);
513 child = _gtk_text_cell_accessible_new ();
515 else if (GTK_IS_CELL_RENDERER_TOGGLE (renderer))
516 child = _gtk_boolean_cell_accessible_new ();
517 else if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
518 child = _gtk_image_cell_accessible_new ();
520 child = _gtk_renderer_cell_accessible_new ();
522 cell = GTK_CELL_ACCESSIBLE (child);
523 renderer_cell = GTK_RENDERER_CELL_ACCESSIBLE (child);
525 /* Create the GtkTreeViewAccessibleCellInfo for this cell */
526 if (parent == ATK_OBJECT (accessible))
527 cell_info_new (accessible, tree_model, tree, node, tv_col, cell);
529 _gtk_cell_accessible_initialise (cell, widget, parent);
532 _gtk_container_cell_accessible_add_child (container, cell);
534 update_cell_value (renderer_cell, accessible, FALSE);
536 /* Add the actions appropriate for this cell */
537 add_cell_actions (cell, editable);
539 /* Set state if it is expandable */
542 set_cell_expandable (cell);
545 /* If the row is selected, all cells on the row are selected */
546 selection = gtk_tree_view_get_selection (tree_view);
548 if (gtk_tree_selection_path_is_selected (selection, path))
549 _gtk_cell_accessible_add_state (cell, ATK_STATE_SELECTED, FALSE);
551 _gtk_cell_accessible_add_state (cell, ATK_STATE_FOCUSABLE, FALSE);
552 if (focus_index == i)
554 accessible->focus_cell = g_object_ref (cell);
555 _gtk_cell_accessible_add_state (cell, ATK_STATE_FOCUSED, FALSE);
556 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
559 g_list_free (renderer_list);
561 child = ATK_OBJECT (container);
563 if (expander_tv == tv_col)
565 AtkRelationSet *relation_set;
566 AtkObject *accessible_array[1];
567 AtkRelation* relation;
568 AtkObject *parent_node;
570 relation_set = atk_object_ref_relation_set (ATK_OBJECT (child));
572 gtk_tree_path_up (path);
573 if (gtk_tree_path_get_depth (path) == 0)
579 parent_index = get_index (tree_view, path, i % get_n_columns (tree_view));
580 parent_node = atk_object_ref_accessible_child (obj, parent_index);
582 accessible_array[0] = parent_node;
583 relation = atk_relation_new (accessible_array, 1,
584 ATK_RELATION_NODE_CHILD_OF);
585 atk_relation_set_add (relation_set, relation);
586 atk_object_add_relationship (parent_node, ATK_RELATION_NODE_PARENT_OF, child);
587 g_object_unref (relation);
588 g_object_unref (relation_set);
590 gtk_tree_path_free (path);
592 /* We do not increase the reference count here; when g_object_unref()
593 * is called for the cell then cell_destroyed() is called and this
594 * removes the cell from the cache.
600 gtk_tree_view_accessible_ref_state_set (AtkObject *obj)
602 AtkStateSet *state_set;
605 state_set = ATK_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->ref_state_set (obj);
606 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
609 atk_state_set_add_state (state_set, ATK_STATE_MANAGES_DESCENDANTS);
615 _gtk_tree_view_accessible_class_init (GtkTreeViewAccessibleClass *klass)
617 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
618 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
619 GtkAccessibleClass *accessible_class = (GtkAccessibleClass*)klass;
620 GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
621 GtkContainerAccessibleClass *container_class = (GtkContainerAccessibleClass*)klass;
623 class->get_n_children = gtk_tree_view_accessible_get_n_children;
624 class->ref_child = gtk_tree_view_accessible_ref_child;
625 class->ref_state_set = gtk_tree_view_accessible_ref_state_set;
626 class->initialize = gtk_tree_view_accessible_initialize;
628 widget_class->notify_gtk = gtk_tree_view_accessible_notify_gtk;
630 accessible_class->connect_widget_destroyed = gtk_tree_view_accessible_connect_widget_destroyed;
632 /* The children of a GtkTreeView are the buttons at the top of the columns
633 * we do not represent these as children so we do not want to report
634 * children added or deleted when these changed.
636 container_class->add_gtk = NULL;
637 container_class->remove_gtk = NULL;
639 gobject_class->finalize = gtk_tree_view_accessible_finalize;
643 _gtk_tree_view_accessible_init (GtkTreeViewAccessible *view)
648 get_focus_index (GtkTreeView *tree_view)
650 GtkTreePath *focus_path;
651 GtkTreeViewColumn *focus_column;
654 gtk_tree_view_get_cursor (tree_view, &focus_path, &focus_column);
655 if (focus_path && focus_column)
656 index = get_index (tree_view, focus_path,
657 get_column_number (tree_view, focus_column));
662 gtk_tree_path_free (focus_path);
667 /* This function returns a reference to the accessible object
668 * for the cell in the treeview which has focus, if any
671 gtk_tree_view_accessible_ref_focus_cell (GtkTreeView *tree_view)
673 AtkObject *focus_cell = NULL;
677 focus_index = get_focus_index (tree_view);
678 if (focus_index >= 0)
680 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
681 focus_cell = atk_object_ref_accessible_child (atk_obj, focus_index);
690 gtk_tree_view_accessible_ref_accessible_at_point (AtkComponent *component,
693 AtkCoordType coord_type)
696 GtkTreeView *tree_view;
698 GtkTreeViewColumn *tv_column;
703 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
707 tree_view = GTK_TREE_VIEW (widget);
709 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
710 gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, x, y, &bx, &by);
711 ret_val = gtk_tree_view_get_path_at_pos (tree_view,
712 bx - x_pos, by - y_pos,
713 &path, &tv_column, NULL, NULL);
718 column = get_column_number (tree_view, tv_column);
719 index = get_index (tree_view, path, column);
720 gtk_tree_path_free (path);
722 return gtk_tree_view_accessible_ref_child (ATK_OBJECT (component), index);
729 atk_component_interface_init (AtkComponentIface *iface)
731 iface->ref_accessible_at_point = gtk_tree_view_accessible_ref_accessible_at_point;
737 gtk_tree_view_accessible_get_index_at (AtkTable *table,
744 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
748 n_cols = atk_table_get_n_columns (table);
749 n_rows = atk_table_get_n_rows (table);
751 if (row >= n_rows || column >= n_cols)
754 return (row + 1) * n_cols + column;
758 gtk_tree_view_accessible_get_column_at_index (AtkTable *table,
764 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
768 if (index >= gtk_tree_view_accessible_get_n_children (ATK_OBJECT (table)))
771 n_columns = get_n_columns (GTK_TREE_VIEW (widget));
773 /* checked by the n_children() check above */
774 g_assert (n_columns > 0);
776 return index % n_columns;
780 gtk_tree_view_accessible_get_row_at_index (AtkTable *table,
784 GtkTreeView *tree_view;
786 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
790 tree_view = GTK_TREE_VIEW (widget);
792 index /= get_n_columns (tree_view);
794 if (index >= get_n_rows (tree_view))
801 gtk_tree_view_accessible_table_ref_at (AtkTable *table,
807 index = gtk_tree_view_accessible_get_index_at (table, row, column);
811 return gtk_tree_view_accessible_ref_child (ATK_OBJECT (table), index);
815 gtk_tree_view_accessible_get_n_rows (AtkTable *table)
819 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
823 return get_n_rows (GTK_TREE_VIEW (widget));
827 gtk_tree_view_accessible_get_n_columns (AtkTable *table)
831 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
835 return get_n_columns (GTK_TREE_VIEW (widget));
839 gtk_tree_view_accessible_is_row_selected (AtkTable *table,
843 GtkTreeView *tree_view;
844 GtkTreeSelection *selection;
847 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
854 tree_view = GTK_TREE_VIEW (widget);
855 selection = gtk_tree_view_get_selection (tree_view);
857 set_iter_nth_row (tree_view, &iter, row);
858 return gtk_tree_selection_iter_is_selected (selection, &iter);
862 gtk_tree_view_accessible_is_selected (AtkTable *table,
866 return gtk_tree_view_accessible_is_row_selected (table, row);
870 get_selected_rows (GtkTreeModel *model,
875 GPtrArray *array = (GPtrArray *)data;
877 g_ptr_array_add (array, gtk_tree_path_copy (path));
881 gtk_tree_view_accessible_get_selected_rows (AtkTable *table,
882 gint **rows_selected)
885 GtkTreeView *tree_view;
886 GtkTreeModel *tree_model;
888 GtkTreeSelection *selection;
889 GtkTreePath *tree_path;
892 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
896 tree_view = GTK_TREE_VIEW (widget);
897 selection = gtk_tree_view_get_selection (tree_view);
899 switch (gtk_tree_selection_get_mode (selection))
901 case GTK_SELECTION_SINGLE:
902 case GTK_SELECTION_BROWSE:
903 if (gtk_tree_selection_get_selected (selection, &tree_model, &iter))
909 *rows_selected = g_new (gint, 1);
910 tree_path = gtk_tree_model_get_path (tree_model, &iter);
911 row = get_row_from_tree_path (tree_view, tree_path);
912 gtk_tree_path_free (tree_path);
914 /* shouldn't ever happen */
915 g_return_val_if_fail (row != -1, 0);
917 *rows_selected[0] = row;
922 case GTK_SELECTION_MULTIPLE:
924 GPtrArray *array = g_ptr_array_new();
926 gtk_tree_selection_selected_foreach (selection, get_selected_rows, array);
927 ret_val = array->len;
929 if (rows_selected && ret_val)
933 *rows_selected = g_new (gint, ret_val);
934 for (i = 0; i < ret_val; i++)
938 tree_path = (GtkTreePath *) g_ptr_array_index (array, i);
939 row = get_row_from_tree_path (tree_view, tree_path);
940 gtk_tree_path_free (tree_path);
941 (*rows_selected)[i] = row;
944 g_ptr_array_free (array, FALSE);
947 case GTK_SELECTION_NONE:
954 gtk_tree_view_accessible_add_row_selection (AtkTable *table,
958 GtkTreeView *tree_view;
959 GtkTreeModel *tree_model;
960 GtkTreeSelection *selection;
961 GtkTreePath *tree_path;
962 GtkTreeIter iter_to_row;
964 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
968 if (!gtk_tree_view_accessible_is_row_selected (table, row))
970 tree_view = GTK_TREE_VIEW (widget);
971 tree_model = gtk_tree_view_get_model (tree_view);
972 selection = gtk_tree_view_get_selection (tree_view);
974 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
976 tree_path = gtk_tree_path_new ();
977 gtk_tree_path_append_index (tree_path, row);
978 gtk_tree_selection_select_path (selection,tree_path);
979 gtk_tree_path_free (tree_path);
983 set_iter_nth_row (tree_view, &iter_to_row, row);
984 gtk_tree_selection_select_iter (selection, &iter_to_row);
988 return gtk_tree_view_accessible_is_row_selected (table, row);
992 gtk_tree_view_accessible_remove_row_selection (AtkTable *table,
996 GtkTreeView *tree_view;
997 GtkTreeSelection *selection;
999 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1003 tree_view = GTK_TREE_VIEW (widget);
1004 selection = gtk_tree_view_get_selection (tree_view);
1006 if (gtk_tree_view_accessible_is_row_selected (table, row))
1008 gtk_tree_selection_unselect_all (selection);
1016 gtk_tree_view_accessible_get_column_header (AtkTable *table,
1020 GtkTreeView *tree_view;
1021 GtkTreeViewColumn *tv_col;
1023 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1027 tree_view = GTK_TREE_VIEW (widget);
1028 if (in_col < 0 || in_col >= get_n_columns (tree_view))
1031 tv_col = get_visible_column (tree_view, in_col);
1032 return get_header_from_column (tv_col);
1035 static const gchar *
1036 gtk_tree_view_accessible_get_column_description (AtkTable *table,
1040 GtkTreeView *tree_view;
1041 GtkTreeViewColumn *tv_col;
1043 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1047 tree_view = GTK_TREE_VIEW (widget);
1048 if (in_col < 0 || in_col >= get_n_columns (tree_view))
1051 tv_col = get_visible_column (tree_view, in_col);
1052 return gtk_tree_view_column_get_title (tv_col);
1056 atk_table_interface_init (AtkTableIface *iface)
1058 iface->ref_at = gtk_tree_view_accessible_table_ref_at;
1059 iface->get_n_rows = gtk_tree_view_accessible_get_n_rows;
1060 iface->get_n_columns = gtk_tree_view_accessible_get_n_columns;
1061 iface->get_index_at = gtk_tree_view_accessible_get_index_at;
1062 iface->get_column_at_index = gtk_tree_view_accessible_get_column_at_index;
1063 iface->get_row_at_index = gtk_tree_view_accessible_get_row_at_index;
1064 iface->is_row_selected = gtk_tree_view_accessible_is_row_selected;
1065 iface->is_selected = gtk_tree_view_accessible_is_selected;
1066 iface->get_selected_rows = gtk_tree_view_accessible_get_selected_rows;
1067 iface->add_row_selection = gtk_tree_view_accessible_add_row_selection;
1068 iface->remove_row_selection = gtk_tree_view_accessible_remove_row_selection;
1069 iface->get_column_extent_at = NULL;
1070 iface->get_row_extent_at = NULL;
1071 iface->get_column_header = gtk_tree_view_accessible_get_column_header;
1072 iface->get_column_description = gtk_tree_view_accessible_get_column_description;
1075 /* atkselection.h */
1078 gtk_tree_view_accessible_add_selection (AtkSelection *selection,
1085 table = ATK_TABLE (selection);
1086 n_columns = gtk_tree_view_accessible_get_n_columns (table);
1090 row = gtk_tree_view_accessible_get_row_at_index (table, i);
1091 return gtk_tree_view_accessible_add_row_selection (table, row);
1095 gtk_tree_view_accessible_clear_selection (AtkSelection *selection)
1098 GtkTreeView *tree_view;
1099 GtkTreeSelection *tree_selection;
1101 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
1105 tree_view = GTK_TREE_VIEW (widget);
1106 tree_selection = gtk_tree_view_get_selection (tree_view);
1108 gtk_tree_selection_unselect_all (tree_selection);
1113 gtk_tree_view_accessible_ref_selection (AtkSelection *selection,
1122 table = ATK_TABLE (selection);
1123 n_columns = gtk_tree_view_accessible_get_n_columns (table);
1124 n_selected = gtk_tree_view_accessible_get_selected_rows (table, &selected);
1125 if (i >= n_columns * n_selected)
1128 row = selected[i / n_columns];
1131 return gtk_tree_view_accessible_table_ref_at (table, row, i % n_columns);
1135 gtk_tree_view_accessible_get_selection_count (AtkSelection *selection)
1140 table = ATK_TABLE (selection);
1141 n_selected = gtk_tree_view_accessible_get_selected_rows (table, NULL);
1143 n_selected *= gtk_tree_view_accessible_get_n_columns (table);
1148 gtk_tree_view_accessible_is_child_selected (AtkSelection *selection,
1154 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
1158 row = atk_table_get_row_at_index (ATK_TABLE (selection), i);
1160 return gtk_tree_view_accessible_is_row_selected (ATK_TABLE (selection), row);
1163 static void atk_selection_interface_init (AtkSelectionIface *iface)
1165 iface->add_selection = gtk_tree_view_accessible_add_selection;
1166 iface->clear_selection = gtk_tree_view_accessible_clear_selection;
1167 iface->ref_selection = gtk_tree_view_accessible_ref_selection;
1168 iface->get_selection_count = gtk_tree_view_accessible_get_selection_count;
1169 iface->is_child_selected = gtk_tree_view_accessible_is_child_selected;
1172 #define EXTRA_EXPANDER_PADDING 4
1175 gtk_tree_view_accessible_get_cell_area (GtkCellAccessibleParent *parent,
1176 GtkCellAccessible *cell,
1177 GdkRectangle *cell_rect)
1180 GtkTreeView *tree_view;
1181 GtkTreeViewColumn *tv_col;
1183 AtkObject *parent_cell;
1184 GtkTreeViewAccessibleCellInfo *cell_info;
1185 GtkCellAccessible *top_cell;
1187 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1191 tree_view = GTK_TREE_VIEW (widget);
1192 parent_cell = atk_object_get_parent (ATK_OBJECT (cell));
1193 if (parent_cell != ATK_OBJECT (parent))
1194 top_cell = GTK_CELL_ACCESSIBLE (parent_cell);
1197 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), top_cell);
1200 path = cell_info_get_path (cell_info);
1201 tv_col = cell_info->cell_col_ref;
1204 GtkTreeViewColumn *expander_column;
1205 gint focus_line_width;
1207 gtk_tree_view_get_cell_area (tree_view, path, tv_col, cell_rect);
1208 expander_column = gtk_tree_view_get_expander_column (tree_view);
1209 if (expander_column == tv_col)
1212 gtk_widget_style_get (widget,
1213 "expander-size", &expander_size,
1215 cell_rect->x += expander_size + EXTRA_EXPANDER_PADDING;
1216 cell_rect->width -= expander_size + EXTRA_EXPANDER_PADDING;
1218 gtk_widget_style_get (widget,
1219 "focus-line-width", &focus_line_width,
1222 cell_rect->x += focus_line_width;
1223 cell_rect->width -= 2 * focus_line_width;
1225 gtk_tree_path_free (path);
1227 /* A column has more than one renderer so we find the position
1230 if (top_cell != cell)
1237 GtkCellRenderer *renderer;
1239 cell_index = atk_object_get_index_in_parent (ATK_OBJECT (cell));
1240 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
1241 renderer = g_list_nth_data (renderers, cell_index);
1243 found = gtk_tree_view_column_cell_get_position (tv_col, renderer, &cell_start, &cell_width);
1246 cell_rect->x += cell_start;
1247 cell_rect->width = cell_width;
1249 g_list_free (renderers);
1256 gtk_tree_view_accessible_get_cell_extents (GtkCellAccessibleParent *parent,
1257 GtkCellAccessible *cell,
1262 AtkCoordType coord_type)
1265 GtkTreeView *tree_view;
1266 GdkWindow *bin_window;
1267 GdkRectangle cell_rect;
1270 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1274 tree_view = GTK_TREE_VIEW (widget);
1275 gtk_tree_view_accessible_get_cell_area (parent, cell, &cell_rect);
1276 bin_window = gtk_tree_view_get_bin_window (tree_view);
1277 gdk_window_get_origin (bin_window, &w_x, &w_y);
1279 if (coord_type == ATK_XY_WINDOW)
1282 gint x_toplevel, y_toplevel;
1284 window = gdk_window_get_toplevel (bin_window);
1285 gdk_window_get_origin (window, &x_toplevel, &y_toplevel);
1291 *width = cell_rect.width;
1292 *height = cell_rect.height;
1293 if (is_cell_showing (tree_view, &cell_rect))
1295 *x = cell_rect.x + w_x;
1296 *y = cell_rect.y + w_y;
1306 gtk_tree_view_accessible_grab_cell_focus (GtkCellAccessibleParent *parent,
1307 GtkCellAccessible *cell)
1310 GtkTreeView *tree_view;
1311 GtkTreeViewColumn *tv_col;
1313 AtkObject *parent_cell;
1314 AtkObject *cell_object;
1315 GtkTreeViewAccessibleCellInfo *cell_info;
1316 GtkCellRenderer *renderer = NULL;
1317 GtkWidget *toplevel;
1320 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1324 tree_view = GTK_TREE_VIEW (widget);
1326 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
1329 cell_object = ATK_OBJECT (cell);
1330 parent_cell = atk_object_get_parent (cell_object);
1331 tv_col = cell_info->cell_col_ref;
1332 if (parent_cell != ATK_OBJECT (parent))
1334 /* GtkCellAccessible is in a GtkContainerCellAccessible.
1335 * The GtkTreeViewColumn has multiple renderers;
1336 * find the corresponding one.
1340 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
1341 index = atk_object_get_index_in_parent (cell_object);
1342 renderer = g_list_nth_data (renderers, index);
1343 g_list_free (renderers);
1345 path = cell_info_get_path (cell_info);
1349 gtk_tree_view_set_cursor_on_cell (tree_view, path, tv_col, renderer, FALSE);
1351 gtk_tree_view_set_cursor (tree_view, path, tv_col, FALSE);
1353 gtk_tree_path_free (path);
1354 gtk_widget_grab_focus (widget);
1355 toplevel = gtk_widget_get_toplevel (widget);
1356 if (gtk_widget_is_toplevel (toplevel))
1358 #ifdef GDK_WINDOWING_X11
1359 gtk_window_present_with_time (GTK_WINDOW (toplevel),
1360 gdk_x11_get_server_time (gtk_widget_get_window (widget)));
1362 gtk_window_present (GTK_WINDOW (toplevel));
1373 gtk_tree_view_accessible_get_child_index (GtkCellAccessibleParent *parent,
1374 GtkCellAccessible *cell)
1376 GtkTreeViewAccessibleCellInfo *cell_info;
1377 GtkTreeView *tree_view;
1379 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
1383 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
1385 return cell_info_get_index (tree_view, cell_info);
1388 static GtkCellRendererState
1389 gtk_tree_view_accessible_get_renderer_state (GtkCellAccessibleParent *parent,
1390 GtkCellAccessible *cell)
1392 GtkTreeViewAccessibleCellInfo *cell_info;
1393 GtkTreeView *treeview;
1394 GtkCellRendererState flags;
1396 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
1402 if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_SELECTED))
1403 flags |= GTK_CELL_RENDERER_SELECTED;
1405 if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_PRELIT))
1406 flags |= GTK_CELL_RENDERER_PRELIT;
1408 if (gtk_tree_view_column_get_sort_indicator (cell_info->cell_col_ref))
1409 flags |= GTK_CELL_RENDERER_SORTED;
1411 treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
1413 if (cell_info->cell_col_ref == gtk_tree_view_get_expander_column (treeview))
1415 if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_PARENT))
1416 flags |= GTK_CELL_RENDERER_EXPANDABLE;
1418 if (cell_info->node->children)
1419 flags |= GTK_CELL_RENDERER_EXPANDED;
1422 if (gtk_widget_has_focus (GTK_WIDGET (treeview)))
1424 GtkTreeViewColumn *column;
1429 gtk_tree_view_get_cursor (treeview, &path, &column);
1432 _gtk_tree_view_find_node (treeview, path, &tree, &node);
1433 gtk_tree_path_free (path);
1438 if (cell_info->cell_col_ref == column
1439 && cell_info->tree == tree
1440 && cell_info->node == node)
1441 flags |= GTK_CELL_RENDERER_FOCUSED;
1448 gtk_tree_view_accessible_set_cell_data (GtkCellAccessibleParent *parent,
1449 GtkCellAccessible *cell)
1451 GtkTreeViewAccessibleCellInfo *cell_info;
1452 GtkTreeView *treeview;
1453 gboolean is_expander, is_expanded;
1454 GtkTreeModel *model;
1458 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
1462 treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
1463 model = gtk_tree_view_get_model (treeview);
1465 if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_PARENT) &&
1466 cell_info->cell_col_ref == gtk_tree_view_get_expander_column (treeview))
1469 is_expanded = cell_info->node->children != NULL;
1473 is_expander = FALSE;
1474 is_expanded = FALSE;
1477 path = cell_info_get_path (cell_info);
1479 !gtk_tree_model_get_iter (model, &iter, path))
1481 /* We only track valid cells, this should never happen */
1482 g_return_if_reached ();
1485 gtk_tree_view_column_cell_set_cell_data (cell_info->cell_col_ref,
1493 gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface)
1495 iface->get_cell_extents = gtk_tree_view_accessible_get_cell_extents;
1496 iface->get_cell_area = gtk_tree_view_accessible_get_cell_area;
1497 iface->grab_focus = gtk_tree_view_accessible_grab_cell_focus;
1498 iface->get_child_index = gtk_tree_view_accessible_get_child_index;
1499 iface->get_renderer_state = gtk_tree_view_accessible_get_renderer_state;
1500 iface->set_cell_data = gtk_tree_view_accessible_set_cell_data;
1503 /* signal handling */
1506 selection_changed_cb (GtkTreeSelection *selection,
1509 GtkTreeViewAccessible *accessible;
1510 GtkTreeView *tree_view;
1512 GtkTreeViewAccessibleCellInfo *info;
1513 GtkTreeSelection *tree_selection;
1515 GHashTableIter iter;
1517 accessible = GTK_TREE_VIEW_ACCESSIBLE (data);
1518 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
1522 tree_view = GTK_TREE_VIEW (widget);
1523 tree_selection = gtk_tree_view_get_selection (tree_view);
1525 /* FIXME: clean rows iterates through all cells too */
1526 g_hash_table_iter_init (&iter, accessible->cell_infos);
1527 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&info))
1529 _gtk_cell_accessible_remove_state (info->cell, ATK_STATE_SELECTED, TRUE);
1531 path = cell_info_get_path (info);
1532 if (path && gtk_tree_selection_path_is_selected (tree_selection, path))
1533 _gtk_cell_accessible_add_state (info->cell, ATK_STATE_SELECTED, TRUE);
1534 gtk_tree_path_free (path);
1536 if (gtk_widget_get_realized (widget))
1537 g_signal_emit_by_name (accessible, "selection-changed");
1541 cursor_changed (GtkTreeView *tree_view,
1542 GtkTreeViewAccessible *accessible)
1546 cell = gtk_tree_view_accessible_ref_focus_cell (tree_view);
1549 if (cell != accessible->focus_cell)
1551 if (accessible->focus_cell)
1553 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_ACTIVE, FALSE);
1554 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_FOCUSED, FALSE);
1555 g_object_unref (accessible->focus_cell);
1556 accessible->focus_cell = cell;
1559 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
1561 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_ACTIVE, FALSE);
1562 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_FOCUSED, FALSE);
1565 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
1568 g_object_unref (cell);
1573 focus_in (GtkWidget *widget)
1575 GtkTreeView *tree_view;
1576 GtkTreeViewAccessible *accessible;
1577 AtkStateSet *state_set;
1580 tree_view = GTK_TREE_VIEW (widget);
1581 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
1583 if (accessible->focus_cell == NULL)
1585 cell = gtk_tree_view_accessible_ref_focus_cell (tree_view);
1588 state_set = atk_object_ref_state_set (cell);
1591 if (!atk_state_set_contains_state (state_set, ATK_STATE_FOCUSED))
1593 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_ACTIVE, FALSE);
1594 accessible->focus_cell = cell;
1595 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_FOCUSED, FALSE);
1596 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
1598 g_object_unref (state_set);
1606 focus_out (GtkWidget *widget)
1608 GtkTreeViewAccessible *accessible;
1610 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
1611 if (accessible->focus_cell)
1613 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_ACTIVE, FALSE);
1614 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_FOCUSED, FALSE);
1615 g_object_unref (accessible->focus_cell);
1616 accessible->focus_cell = NULL;
1622 model_row_changed (GtkTreeModel *tree_model,
1627 GtkTreeView *tree_view = GTK_TREE_VIEW (user_data);
1628 GtkTreeViewAccessible *accessible;
1629 GtkTreePath *cell_path;
1630 GtkTreeViewAccessibleCellInfo *cell_info;
1631 GHashTableIter hash_iter;
1633 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (tree_view)));
1635 /* Loop through our cached cells */
1636 /* Must loop through them all */
1637 g_hash_table_iter_init (&hash_iter, accessible->cell_infos);
1638 while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer *)&cell_info))
1640 cell_path = cell_info_get_path (cell_info);
1642 if (cell_path != NULL)
1644 if (path && gtk_tree_path_compare (cell_path, path) == 0)
1646 if (GTK_IS_RENDERER_CELL_ACCESSIBLE (cell_info->cell))
1647 update_cell_value (GTK_RENDERER_CELL_ACCESSIBLE (cell_info->cell),
1650 gtk_tree_path_free (cell_path);
1653 g_signal_emit_by_name (accessible, "visible-data-changed");
1657 model_row_inserted (GtkTreeModel *tree_model,
1662 GtkTreeView *tree_view = (GtkTreeView *)user_data;
1664 GtkTreeViewAccessible *accessible;
1665 GtkTreePath *path_copy;
1666 gint row, n_inserted, child_row;
1668 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
1669 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1671 /* Check to see if row is visible */
1672 row = get_row_from_tree_path (tree_view, path);
1674 /* A row insert is not necessarily visible. For example,
1675 * a row can be draged & dropped into another row, which
1676 * causes an insert on the model that isn't visible in the
1677 * view. Only generate a signal if the inserted row is
1682 GtkTreeIter tmp_iter;
1685 gtk_tree_model_get_iter (tree_model, &tmp_iter, path);
1687 /* Figure out number of visible children. */
1688 if (gtk_tree_model_iter_has_child (tree_model, &tmp_iter))
1692 * By passing path into this function, we find the number of
1693 * visible children of path.
1696 /* iterate_thru_children modifies path, we don't want that, so give
1698 path2 = gtk_tree_path_copy (path);
1699 iterate_thru_children (tree_view, tree_model,
1700 path2, NULL, &n_inserted, 0);
1701 gtk_tree_path_free (path2);
1703 /* Must add one to include the row that is being added */
1709 /* Generate row-inserted signal */
1710 g_signal_emit_by_name (atk_obj, "row-inserted", row, n_inserted);
1712 /* Generate children-changed signals */
1713 n_cols = get_n_columns (tree_view);
1714 for (child_row = row; child_row < (row + n_inserted); child_row++)
1716 for (col = 0; col < n_cols; col++)
1718 /* Pass NULL as the child object, i.e. 4th argument */
1719 g_signal_emit_by_name (atk_obj, "children-changed::add",
1720 ((row * n_cols) + col), NULL, NULL);
1726 /* The row has been inserted inside another row. This can
1727 * cause a row that previously couldn't be expanded to now
1730 path_copy = gtk_tree_path_copy (path);
1731 gtk_tree_path_up (path_copy);
1732 set_expand_state (tree_view, tree_model, accessible, path_copy, TRUE);
1733 gtk_tree_path_free (path_copy);
1738 model_row_deleted (GtkTreeModel *tree_model,
1742 GtkTreeView *tree_view = (GtkTreeView *)user_data;
1743 GtkTreePath *path_copy;
1745 GtkTreeViewAccessible *accessible;
1747 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
1748 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1750 /* If deleting a row with a depth > 1, then this may affect the
1751 * expansion/contraction of its parent(s). Make sure this is
1754 if (gtk_tree_path_get_depth (path) > 1)
1756 path_copy = gtk_tree_path_copy (path);
1757 gtk_tree_path_up (path_copy);
1758 set_expand_state (tree_view, tree_model, accessible, path_copy, TRUE);
1759 gtk_tree_path_free (path_copy);
1764 _gtk_tree_view_accessible_reorder (GtkTreeView *treeview)
1766 GtkTreeViewAccessible *accessible;
1768 accessible = GTK_TREE_VIEW_ACCESSIBLE (_gtk_widget_peek_accessible (GTK_WIDGET (treeview)));
1769 if (accessible == NULL)
1772 g_signal_emit_by_name (accessible, "row-reordered");
1776 is_cell_showing (GtkTreeView *tree_view,
1777 GdkRectangle *cell_rect)
1779 GdkRectangle rect, *visible_rect;
1780 GdkRectangle rect1, *tree_cell_rect;
1782 gboolean is_showing;
1784 /* A cell is considered "SHOWING" if any part of the cell is
1785 * in the visible area. Other ways we could do this is by a
1786 * cell's midpoint or if the cell is fully in the visible range.
1787 * Since we have the cell_rect x, y, width, height of the cell,
1788 * any of these is easy to compute.
1790 * It is assumed that cell's rectangle is in widget coordinates
1791 * so we must transform to tree cordinates.
1793 visible_rect = ▭
1794 tree_cell_rect = &rect1;
1795 tree_cell_rect->x = cell_rect->x;
1796 tree_cell_rect->y = cell_rect->y;
1797 tree_cell_rect->width = cell_rect->width;
1798 tree_cell_rect->height = cell_rect->height;
1800 gtk_tree_view_get_visible_rect (tree_view, visible_rect);
1801 gtk_tree_view_convert_tree_to_bin_window_coords (tree_view, visible_rect->x,
1802 visible_rect->y, &bx, &by);
1804 if (((tree_cell_rect->x + tree_cell_rect->width) < bx) ||
1805 ((tree_cell_rect->y + tree_cell_rect->height) < by) ||
1806 (tree_cell_rect->x > (bx + visible_rect->width)) ||
1807 (tree_cell_rect->y > (by + visible_rect->height)))
1817 /* This function is called when a cell's flyweight is created in
1818 * gtk_tree_view_accessible_table_ref_at with emit_change_signal
1819 * set to FALSE and in model_row_changed() on receipt of "row-changed"
1820 * signal when emit_change_signal is set to TRUE
1823 update_cell_value (GtkRendererCellAccessible *renderer_cell,
1824 GtkTreeViewAccessible *accessible,
1825 gboolean emit_change_signal)
1827 GtkTreeViewAccessibleCellInfo *cell_info;
1828 GtkTreeView *tree_view;
1829 GtkTreeModel *tree_model;
1832 GList *renderers, *cur_renderer;
1834 GtkRendererCellAccessibleClass *renderer_cell_class;
1835 GtkCellRendererClass *gtk_cell_renderer_class;
1836 GtkCellAccessible *cell;
1839 gboolean is_expander, is_expanded;
1841 renderer_cell_class = GTK_RENDERER_CELL_ACCESSIBLE_GET_CLASS (renderer_cell);
1842 if (renderer_cell->renderer)
1843 gtk_cell_renderer_class = GTK_CELL_RENDERER_GET_CLASS (renderer_cell->renderer);
1845 gtk_cell_renderer_class = NULL;
1847 prop_list = renderer_cell_class->property_list;
1849 cell = GTK_CELL_ACCESSIBLE (renderer_cell);
1850 cell_info = find_cell_info (accessible, cell);
1854 if (emit_change_signal)
1856 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
1857 tree_model = gtk_tree_view_get_model (tree_view);
1858 path = cell_info_get_path (cell_info);
1862 gtk_tree_model_get_iter (tree_model, &iter, path);
1863 is_expander = FALSE;
1864 is_expanded = FALSE;
1865 if (gtk_tree_model_iter_has_child (tree_model, &iter))
1867 GtkTreeViewColumn *expander_tv;
1869 expander_tv = gtk_tree_view_get_expander_column (tree_view);
1870 if (expander_tv == cell_info->cell_col_ref)
1873 is_expanded = gtk_tree_view_row_expanded (tree_view, path);
1876 gtk_tree_path_free (path);
1877 gtk_tree_view_column_cell_set_cell_data (cell_info->cell_col_ref,
1879 is_expander, is_expanded);
1881 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_info->cell_col_ref));
1885 /* If the cell is in a container, its index is used to find the renderer
1886 * in the list. Otherwise, we assume that the cell is represented
1887 * by the first renderer in the list
1889 parent = atk_object_get_parent (ATK_OBJECT (cell));
1891 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
1892 cur_renderer = g_list_nth (renderers, atk_object_get_index_in_parent (ATK_OBJECT (cell)));
1894 cur_renderer = renderers;
1896 if (cur_renderer == NULL)
1899 if (gtk_cell_renderer_class)
1903 spec = g_object_class_find_property
1904 (G_OBJECT_CLASS (gtk_cell_renderer_class), *prop_list);
1908 GValue value = G_VALUE_INIT;
1910 g_value_init (&value, spec->value_type);
1911 g_object_get_property (cur_renderer->data, *prop_list, &value);
1912 g_object_set_property (G_OBJECT (renderer_cell->renderer),
1913 *prop_list, &value);
1914 g_value_unset (&value);
1917 g_warning ("Invalid property: %s\n", *prop_list);
1921 g_list_free (renderers);
1923 return _gtk_renderer_cell_accessible_update_cache (renderer_cell, emit_change_signal);
1927 get_row_from_tree_path (GtkTreeView *tree_view,
1930 GtkTreeModel *tree_model;
1931 GtkTreePath *root_tree;
1934 tree_model = gtk_tree_view_get_model (tree_view);
1936 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
1937 row = gtk_tree_path_get_indices (path)[0];
1940 root_tree = gtk_tree_path_new_first ();
1942 iterate_thru_children (tree_view, tree_model, root_tree, path, &row, 0);
1943 gtk_tree_path_free (root_tree);
1951 /* Helper recursive function that returns an iter to nth row
1953 static GtkTreeIter *
1954 return_iter_nth_row (GtkTreeView *tree_view,
1955 GtkTreeModel *tree_model,
1960 GtkTreePath *current_path;
1961 GtkTreeIter new_iter;
1962 gboolean row_expanded;
1964 current_path = gtk_tree_model_get_path (tree_model, iter);
1965 if (increment == row)
1967 gtk_tree_path_free (current_path);
1971 row_expanded = gtk_tree_view_row_expanded (tree_view, current_path);
1972 gtk_tree_path_free (current_path);
1975 if ((row_expanded && gtk_tree_model_iter_children (tree_model, iter, &new_iter)) ||
1976 (gtk_tree_model_iter_next (tree_model, iter)) ||
1977 (gtk_tree_model_iter_parent (tree_model, iter, &new_iter) &&
1978 (gtk_tree_model_iter_next (tree_model, iter))))
1979 return return_iter_nth_row (tree_view, tree_model, iter,
1986 set_iter_nth_row (GtkTreeView *tree_view,
1990 GtkTreeModel *tree_model;
1992 tree_model = gtk_tree_view_get_model (tree_view);
1993 gtk_tree_model_get_iter_first (tree_model, iter);
1994 iter = return_iter_nth_row (tree_view, tree_model, iter, 0, row);
1997 /* Recursively called until the row specified by orig is found.
1999 * *count will be set to the visible row number of the child
2000 * relative to the row that was initially passed in as tree_path.
2001 * tree_path could be modified by this function.
2003 * *count will be -1 if orig is not found as a child (a row that is
2004 * not visible will not be found, e.g. if the row is inside a
2005 * collapsed row). If NULL is passed in as orig, *count will
2006 * be a count of the visible children.
2008 * NOTE: the value for depth must be 0 when this recursive function
2009 * is initially called, or it may not function as expected.
2012 iterate_thru_children (GtkTreeView *tree_view,
2013 GtkTreeModel *tree_model,
2014 GtkTreePath *tree_path,
2021 if (!gtk_tree_model_get_iter (tree_model, &iter, tree_path))
2024 if (tree_path && orig && !gtk_tree_path_compare (tree_path, orig))
2028 if (tree_path && orig && gtk_tree_path_compare (tree_path, orig) > 0)
2030 /* Past it, so return -1 */
2034 else if (gtk_tree_view_row_expanded (tree_view, tree_path) &&
2035 gtk_tree_model_iter_has_child (tree_model, &iter))
2038 gtk_tree_path_append_index (tree_path, 0);
2039 iterate_thru_children (tree_view, tree_model, tree_path,
2040 orig, count, (depth + 1));
2043 else if (gtk_tree_model_iter_next (tree_model, &iter))
2046 tree_path = gtk_tree_model_get_path (tree_model, &iter);
2049 iterate_thru_children (tree_view, tree_model, tree_path,
2050 orig, count, depth);
2051 gtk_tree_path_free (tree_path);
2055 else if (gtk_tree_path_up (tree_path))
2057 GtkTreeIter temp_iter;
2058 gboolean exit_loop = FALSE;
2059 gint new_depth = depth - 1;
2063 /* Make sure that we back up until we find a row
2064 * where gtk_tree_path_next does not return NULL.
2068 if (gtk_tree_path_get_depth (tree_path) == 0)
2069 /* depth is now zero so */
2071 gtk_tree_path_next (tree_path);
2073 /* Verify that the next row is a valid row! */
2074 exit_loop = gtk_tree_model_get_iter (tree_model, &temp_iter, tree_path);
2078 /* Keep going up until we find a row that has a valid next */
2079 if (gtk_tree_path_get_depth(tree_path) > 1)
2082 gtk_tree_path_up (tree_path);
2086 /* If depth is 1 and gtk_tree_model_get_iter returns FALSE,
2087 * then we are at the last row, so just return.
2097 /* This guarantees that we will stop when we hit the end of the
2103 iterate_thru_children (tree_view, tree_model, tree_path,
2104 orig, count, new_depth);
2108 /* If it gets here, then the path wasn't found. Situations
2109 * that would cause this would be if the path passed in is
2110 * invalid or contained within the last row, but not visible
2111 * because the last row is not expanded. If NULL was passed
2112 * in then a row count is desired, so only set count to -1
2113 * if orig is not NULL.
2121 /* If the tree_path passed in has children, then
2122 * ATK_STATE_EXPANDABLE is set.
2124 * If the tree_path passed in has no children, then
2125 * ATK_STATE_EXPANDABLE is removed.
2127 * If set_on_ancestor is TRUE, then this function will also
2128 * update all cells that are ancestors of the tree_path.
2131 set_expand_state (GtkTreeView *tree_view,
2132 GtkTreeModel *tree_model,
2133 GtkTreeViewAccessible *accessible,
2134 GtkTreePath *tree_path,
2135 gboolean set_on_ancestor)
2137 GtkTreeViewColumn *expander_tv;
2138 GtkTreeViewAccessibleCellInfo *cell_info;
2139 GtkTreePath *cell_path;
2142 GHashTableIter hash_iter;
2144 g_hash_table_iter_init (&hash_iter, accessible->cell_infos);
2145 while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer *) &cell_info))
2147 cell_path = cell_info_get_path (cell_info);
2150 if (cell_path != NULL)
2152 GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (cell_info->cell);
2154 expander_tv = gtk_tree_view_get_expander_column (tree_view);
2156 /* Only set state for the cell that is in the column with the
2159 if (expander_tv == cell_info->cell_col_ref)
2161 if (tree_path && gtk_tree_path_compare (cell_path, tree_path) == 0)
2163 else if (set_on_ancestor &&
2164 gtk_tree_path_get_depth (cell_path) <
2165 gtk_tree_path_get_depth (tree_path) &&
2166 gtk_tree_path_is_ancestor (cell_path, tree_path) == 1)
2167 /* Only set if set_on_ancestor was passed in as TRUE */
2171 /* Set ATK_STATE_EXPANDABLE
2172 * for ancestors and found cells.
2176 /* Must check against cell_path since cell_path
2177 * can be equal to or an ancestor of tree_path.
2179 gtk_tree_model_get_iter (tree_model, &iter, cell_path);
2181 /* Set or unset ATK_STATE_EXPANDABLE as appropriate */
2182 if (gtk_tree_model_iter_has_child (tree_model, &iter))
2184 set_cell_expandable (cell);
2188 if (_gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDABLE, TRUE))
2189 /* The state may have been propagated to the container cell */
2190 if (!GTK_IS_CONTAINER_CELL_ACCESSIBLE (cell))
2191 _gtk_cell_accessible_remove_action_by_name (cell,
2192 "expand or contract");
2195 /* We assume that each cell in the cache once and
2196 * a container cell is before its child cells so we are
2197 * finished if set_on_ancestor is not set to TRUE.
2199 if (!set_on_ancestor)
2203 gtk_tree_path_free (cell_path);
2208 add_cell_actions (GtkCellAccessible *cell,
2212 _gtk_cell_accessible_add_action (cell,
2213 "edit", "creates a widget in which the contents of the cell can be edited",
2215 _gtk_cell_accessible_add_action (cell,
2216 "activate", "activate the cell",
2217 NULL, activate_cell);
2221 toggle_cell_expanded (GtkCellAccessible *cell)
2223 GtkTreeViewAccessibleCellInfo *cell_info;
2224 GtkTreeView *tree_view;
2227 AtkStateSet *stateset;
2229 parent = atk_object_get_parent (ATK_OBJECT (cell));
2230 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
2231 parent = atk_object_get_parent (parent);
2233 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
2237 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
2238 path = cell_info_get_path (cell_info);
2242 stateset = atk_object_ref_state_set (ATK_OBJECT (cell));
2243 if (atk_state_set_contains_state (stateset, ATK_STATE_EXPANDED))
2244 gtk_tree_view_collapse_row (tree_view, path);
2246 gtk_tree_view_expand_row (tree_view, path, TRUE);
2247 g_object_unref (stateset);
2248 gtk_tree_path_free (path);
2252 edit_cell (GtkCellAccessible *cell)
2254 GtkTreeViewAccessibleCellInfo *cell_info;
2255 GtkTreeView *tree_view;
2259 parent = atk_object_get_parent (ATK_OBJECT (cell));
2260 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
2261 parent = atk_object_get_parent (parent);
2263 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
2267 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
2268 path = cell_info_get_path (cell_info);
2271 gtk_tree_view_set_cursor (tree_view, path, cell_info->cell_col_ref, TRUE);
2272 gtk_tree_path_free (path);
2276 activate_cell (GtkCellAccessible *cell)
2278 GtkTreeViewAccessibleCellInfo *cell_info;
2279 GtkTreeView *tree_view;
2283 parent = atk_object_get_parent (ATK_OBJECT (cell));
2284 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
2285 parent = atk_object_get_parent (parent);
2287 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
2291 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
2292 path = cell_info_get_path (cell_info);
2295 gtk_tree_view_row_activated (tree_view, path, cell_info->cell_col_ref);
2296 gtk_tree_path_free (path);
2300 cell_destroyed (gpointer data)
2302 GtkTreeViewAccessibleCellInfo *cell_info = data;
2304 cell_info->cell = NULL;
2306 g_hash_table_remove (cell_info->view->cell_infos, cell_info);
2310 cell_info_get_index (GtkTreeView *tree_view,
2311 GtkTreeViewAccessibleCellInfo *info)
2315 index = _gtk_rbtree_node_get_index (info->tree, info->node) + 1;
2316 index *= get_n_columns (tree_view);
2317 index += get_column_number (tree_view, info->cell_col_ref);
2323 cell_info_new (GtkTreeViewAccessible *accessible,
2324 GtkTreeModel *tree_model,
2327 GtkTreeViewColumn *tv_col,
2328 GtkCellAccessible *cell)
2330 GtkTreeViewAccessibleCellInfo *cell_info;
2332 cell_info = g_new (GtkTreeViewAccessibleCellInfo, 1);
2334 cell_info->tree = tree;
2335 cell_info->node = node;
2336 cell_info->cell_col_ref = tv_col;
2337 cell_info->cell = cell;
2338 cell_info->view = accessible;
2340 g_object_set_qdata_full (G_OBJECT (cell),
2341 gtk_tree_view_accessible_get_data_quark (),
2345 g_hash_table_replace (accessible->cell_infos, cell_info, cell_info);
2348 static GtkCellAccessible *
2349 peek_cell (GtkTreeViewAccessible *accessible,
2352 GtkTreeViewColumn *column)
2354 GtkTreeViewAccessibleCellInfo lookup, *cell_info;
2358 lookup.cell_col_ref = column;
2360 cell_info = g_hash_table_lookup (accessible->cell_infos, &lookup);
2361 if (cell_info == NULL)
2364 return cell_info->cell;
2367 static GtkCellAccessible *
2368 find_cell (GtkTreeViewAccessible *accessible,
2371 GtkTreeView *tree_view;
2375 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
2377 if (!_gtk_rbtree_find_index (_gtk_tree_view_get_rbtree (tree_view),
2378 index / get_n_columns (tree_view) - 1,
2382 g_assert_not_reached ();
2385 return peek_cell (accessible,
2387 get_visible_column (tree_view, index % get_n_columns (tree_view)));
2391 connect_model_signals (GtkTreeView *view,
2392 GtkTreeViewAccessible *accessible)
2396 obj = G_OBJECT (accessible->tree_model);
2397 g_signal_connect_data (obj, "row-changed",
2398 G_CALLBACK (model_row_changed), view, NULL, 0);
2399 g_signal_connect_data (obj, "row-inserted",
2400 G_CALLBACK (model_row_inserted), view, NULL,
2402 g_signal_connect_data (obj, "row-deleted",
2403 G_CALLBACK (model_row_deleted), view, NULL,
2408 disconnect_model_signals (GtkTreeViewAccessible *accessible)
2413 obj = G_OBJECT (accessible->tree_model);
2414 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2415 g_signal_handlers_disconnect_by_func (obj, model_row_changed, widget);
2416 g_signal_handlers_disconnect_by_func (obj, model_row_inserted, widget);
2417 g_signal_handlers_disconnect_by_func (obj, model_row_deleted, widget);
2420 /* Returns the column number of the specified GtkTreeViewColumn
2421 * The column must be visible.
2424 get_column_number (GtkTreeView *treeview,
2425 GtkTreeViewColumn *column)
2427 GtkTreeViewColumn *cur;
2432 for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++)
2434 cur = gtk_tree_view_get_column (treeview, i);
2436 if (!gtk_tree_view_column_get_visible (cur))
2445 g_return_val_if_fail (i < gtk_tree_view_get_n_columns (treeview), 0);
2451 get_index (GtkTreeView *tree_view,
2457 gint *indices = NULL;
2461 depth = gtk_tree_path_get_depth (path);
2462 indices = gtk_tree_path_get_indices (path);
2467 GtkTreePath *copy_path;
2468 GtkTreeModel *model;
2470 model = gtk_tree_view_get_model (tree_view);
2471 copy_path = gtk_tree_path_copy (path);
2472 gtk_tree_path_up (copy_path);
2473 count_rows (model, NULL, copy_path, &index, 0, depth);
2474 gtk_tree_path_free (copy_path);
2478 index += indices[depth - 1];
2479 index *= get_n_columns (tree_view);
2480 index += actual_column;
2484 /* The function count_rows counts the number of rows starting at iter
2485 * and ending at end_path. The value of level is the depth of iter and
2486 * the value of depth is the depth of end_path. Rows at depth before
2487 * end_path are counted. This functions counts rows which are not visible
2488 * because an ancestor is collapsed.
2491 count_rows (GtkTreeModel *model,
2493 GtkTreePath *end_path,
2498 GtkTreeIter child_iter;
2504 *count += gtk_tree_model_iter_n_children (model, iter);
2506 if (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY)
2512 if (gtk_tree_model_iter_children (model, &child_iter, iter))
2514 gboolean ret_val = TRUE;
2518 if (level == depth - 1)
2520 GtkTreePath *iter_path;
2521 gboolean finished = FALSE;
2523 iter_path = gtk_tree_model_get_path (model, &child_iter);
2524 if (end_path && gtk_tree_path_compare (iter_path, end_path) >= 0)
2526 gtk_tree_path_free (iter_path);
2530 if (gtk_tree_model_iter_has_child (model, &child_iter))
2531 count_rows (model, &child_iter, end_path, count, level, depth);
2532 ret_val = gtk_tree_model_iter_next (model, &child_iter);
2538 get_rbtree_column_from_index (GtkTreeView *tree_view,
2542 GtkTreeViewColumn **column)
2544 guint n_columns = get_n_columns (tree_view);
2548 /* First row is the column headers */
2555 g_return_val_if_fail (node != NULL, FALSE);
2557 if (!_gtk_rbtree_find_index (_gtk_tree_view_get_rbtree (tree_view),
2566 *column = get_visible_column (tree_view, index % n_columns);
2567 if (*column == NULL)
2574 set_cell_expandable (GtkCellAccessible *cell)
2576 if (_gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDABLE, FALSE))
2577 _gtk_cell_accessible_add_action (cell,
2578 "expand or contract",
2579 "expands or contracts the row in the tree view containing this cell",
2580 NULL, toggle_cell_expanded);
2583 static GtkTreeViewAccessibleCellInfo *
2584 find_cell_info (GtkTreeViewAccessible *accessible,
2585 GtkCellAccessible *cell)
2589 parent = atk_object_get_parent (ATK_OBJECT (cell));
2590 while (parent != ATK_OBJECT (accessible))
2592 cell = GTK_CELL_ACCESSIBLE (parent);
2593 parent = atk_object_get_parent (ATK_OBJECT (cell));
2596 return g_object_get_qdata (G_OBJECT (cell),
2597 gtk_tree_view_accessible_get_data_quark ());
2601 get_header_from_column (GtkTreeViewColumn *tv_col)
2604 GtkWidget *header_widget;
2609 header_widget = gtk_tree_view_column_get_button (tv_col);
2612 rc = gtk_widget_get_accessible (header_widget);
2620 _gtk_tree_view_accessible_remove (GtkTreeView *treeview,
2624 GtkTreeViewAccessibleCellInfo *cell_info;
2625 GHashTableIter iter;
2626 GtkTreeViewAccessible *accessible;
2629 accessible = GTK_TREE_VIEW_ACCESSIBLE (_gtk_widget_peek_accessible (GTK_WIDGET (treeview)));
2630 if (accessible == NULL)
2633 /* if this shows up in profiles, special-case node->children == NULL */
2637 row = tree->parent_tree ? _gtk_rbtree_node_get_index (tree->parent_tree, tree->parent_node) : 0;
2638 n_rows = tree->root->total_count + 1;
2642 row = _gtk_rbtree_node_get_index (tree, node);
2643 n_rows = 1 + (node->children ? node->children->root->total_count : 0);
2645 tree = node->children;
2648 g_signal_emit_by_name (accessible, "row-deleted", row, n_rows);
2650 g_hash_table_iter_init (&iter, accessible->cell_infos);
2651 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
2653 if (node == cell_info->node ||
2654 tree == cell_info->tree ||
2655 (tree && _gtk_rbtree_contains (tree, cell_info->tree)))
2656 g_hash_table_iter_remove (&iter);
2660 /* NB: id is not checked, only columns < id are.
2661 * This is important so the function works for notification of removal of a column */
2663 to_visible_column_id (GtkTreeView *treeview,
2671 for (i = 0; i < id; i++)
2673 GtkTreeViewColumn *column = gtk_tree_view_get_column (treeview, i);
2675 if (!gtk_tree_view_column_get_visible (column))
2679 return id - invisible;
2683 _gtk_tree_view_accessible_do_add_column (GtkTreeViewAccessible *accessible,
2684 GtkTreeView *treeview,
2685 GtkTreeViewColumn *column,
2688 guint row, n_rows, n_cols;
2690 /* Generate column-inserted signal */
2691 g_signal_emit_by_name (accessible, "column-inserted", id, 1);
2693 n_rows = get_n_rows (treeview);
2694 n_cols = get_n_columns (treeview);
2696 /* Generate children-changed signals */
2697 for (row = 0; row <= n_rows; row++)
2699 /* Pass NULL as the child object, i.e. 4th argument */
2700 g_signal_emit_by_name (accessible, "children-changed::add",
2701 (row * n_cols) + id, NULL, NULL);
2706 _gtk_tree_view_accessible_add_column (GtkTreeView *treeview,
2707 GtkTreeViewColumn *column,
2712 if (!gtk_tree_view_column_get_visible (column))
2715 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
2719 _gtk_tree_view_accessible_do_add_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
2722 to_visible_column_id (treeview, id));
2726 _gtk_tree_view_accessible_do_remove_column (GtkTreeViewAccessible *accessible,
2727 GtkTreeView *treeview,
2728 GtkTreeViewColumn *column,
2731 GtkTreeViewAccessibleCellInfo *cell_info;
2732 GHashTableIter iter;
2734 guint row, n_rows, n_cols;
2736 /* Clean column from cache */
2737 g_hash_table_iter_init (&iter, accessible->cell_infos);
2738 while (g_hash_table_iter_next (&iter, NULL, &value))
2741 if (cell_info->cell_col_ref == column)
2742 g_hash_table_iter_remove (&iter);
2745 /* Generate column-deleted signal */
2746 g_signal_emit_by_name (accessible, "column-deleted", id, 1);
2748 n_rows = get_n_rows (treeview);
2749 n_cols = get_n_columns (treeview);
2751 /* Generate children-changed signals */
2752 for (row = 0; row <= n_rows; row++)
2754 /* Pass NULL as the child object, 4th argument */
2755 g_signal_emit_by_name (accessible, "children-changed::remove",
2756 (row * n_cols) + id, NULL, NULL);
2761 _gtk_tree_view_accessible_remove_column (GtkTreeView *treeview,
2762 GtkTreeViewColumn *column,
2767 if (!gtk_tree_view_column_get_visible (column))
2770 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
2774 _gtk_tree_view_accessible_do_remove_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
2777 to_visible_column_id (treeview, id));
2781 _gtk_tree_view_accessible_reorder_column (GtkTreeView *treeview,
2782 GtkTreeViewColumn *column)
2786 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
2790 g_signal_emit_by_name (obj, "column-reordered");
2794 _gtk_tree_view_accessible_toggle_visibility (GtkTreeView *treeview,
2795 GtkTreeViewColumn *column)
2800 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
2804 id = get_column_number (treeview, column);
2806 if (gtk_tree_view_column_get_visible (column))
2807 _gtk_tree_view_accessible_do_add_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
2812 _gtk_tree_view_accessible_do_remove_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
2819 _gtk_tree_view_accessible_add_state (GtkTreeView *treeview,
2822 GtkCellRendererState state)
2824 GtkTreeViewAccessible *accessible;
2828 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
2832 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
2834 for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++)
2836 GtkCellAccessible *cell = peek_cell (accessible,
2838 gtk_tree_view_get_column (treeview, i));
2843 _gtk_cell_accessible_state_changed (cell, state, 0);
2848 _gtk_tree_view_accessible_remove_state (GtkTreeView *treeview,
2851 GtkCellRendererState state)
2853 GtkTreeViewAccessible *accessible;
2857 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
2861 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
2863 for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++)
2865 GtkCellAccessible *cell = peek_cell (accessible,
2867 gtk_tree_view_get_column (treeview, i));
2872 _gtk_cell_accessible_state_changed (cell, 0, state);
2877 _gtk_tree_view_accessible_expanded (GtkTreeView *treeview,
2883 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
2887 _gtk_tree_view_accessible_add_state (treeview,
2889 GTK_CELL_RENDERER_EXPANDED);
2891 g_signal_emit_by_name (obj,
2893 _gtk_rbtree_node_get_index (tree, node),
2894 node->children->root->total_count);