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 gboolean row_collapsed_cb (GtkTreeView *tree_view,
53 static void selection_changed_cb (GtkTreeSelection *selection,
56 static void cursor_changed (GtkTreeView *tree_view,
57 GtkTreeViewAccessible *accessible);
58 static gboolean focus_in (GtkWidget *widget);
59 static gboolean focus_out (GtkWidget *widget);
61 static void destroy_count_func (GtkTreeView *tree_view,
68 static void set_iter_nth_row (GtkTreeView *tree_view,
71 static gint get_row_from_tree_path (GtkTreeView *tree_view,
73 static void iterate_thru_children (GtkTreeView *tree_view,
74 GtkTreeModel *tree_model,
75 GtkTreePath *tree_path,
79 static int cell_info_get_index (GtkTreeView *tree_view,
80 GtkTreeViewAccessibleCellInfo *info);
81 static gboolean update_cell_value (GtkRendererCellAccessible *renderer_cell,
82 GtkTreeViewAccessible *accessible,
83 gboolean emit_change_signal);
84 static gboolean is_cell_showing (GtkTreeView *tree_view,
85 GdkRectangle *cell_rect);
86 static void set_expand_state (GtkTreeView *tree_view,
87 GtkTreeModel *tree_model,
88 GtkTreeViewAccessible *accessible,
89 GtkTreePath *tree_path,
90 gboolean set_on_ancestor);
91 static void set_cell_expandable (GtkCellAccessible *cell);
92 static void add_cell_actions (GtkCellAccessible *cell,
95 static void toggle_cell_toggled (GtkCellAccessible *cell);
96 static void edit_cell (GtkCellAccessible *cell);
97 static void activate_cell (GtkCellAccessible *cell);
98 static void cell_destroyed (gpointer data);
99 static void cell_info_new (GtkTreeViewAccessible *accessible,
100 GtkTreeModel *tree_model,
103 GtkTreeViewColumn *tv_col,
104 GtkCellAccessible *cell);
105 static GtkCellAccessible *find_cell (GtkTreeViewAccessible *accessible,
107 static void connect_model_signals (GtkTreeView *view,
108 GtkTreeViewAccessible *accessible);
109 static void disconnect_model_signals (GtkTreeViewAccessible *accessible);
110 static gint get_column_number (GtkTreeView *tree_view,
111 GtkTreeViewColumn *column);
112 static gint get_focus_index (GtkTreeView *tree_view);
113 static gint get_index (GtkTreeView *tree_view,
116 static void count_rows (GtkTreeModel *model,
118 GtkTreePath *end_path,
123 static gboolean get_rbtree_column_from_index (GtkTreeView *tree_view,
127 GtkTreeViewColumn **column);
129 static GtkTreeViewAccessibleCellInfo* find_cell_info (GtkTreeViewAccessible *view,
130 GtkCellAccessible *cell);
131 static AtkObject * get_header_from_column (GtkTreeViewColumn *tv_col);
134 static void atk_table_interface_init (AtkTableIface *iface);
135 static void atk_selection_interface_init (AtkSelectionIface *iface);
136 static void atk_component_interface_init (AtkComponentIface *iface);
137 static void gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface);
139 G_DEFINE_TYPE_WITH_CODE (GtkTreeViewAccessible, _gtk_tree_view_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
140 G_IMPLEMENT_INTERFACE (ATK_TYPE_TABLE, atk_table_interface_init)
141 G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init)
142 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init)
143 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_ACCESSIBLE_PARENT, gtk_cell_accessible_parent_interface_init))
147 gtk_tree_view_accessible_get_data_quark (void)
149 static GQuark quark = 0;
151 if (G_UNLIKELY (quark == 0))
152 quark = g_quark_from_static_string ("gtk-tree-view-accessible-data");
158 cell_info_free (GtkTreeViewAccessibleCellInfo *cell_info)
162 g_object_steal_qdata (G_OBJECT (cell_info->cell),
163 gtk_tree_view_accessible_get_data_quark ());
164 _gtk_cell_accessible_add_state (cell_info->cell, ATK_STATE_DEFUNCT, FALSE);
171 cell_info_get_path (GtkTreeViewAccessibleCellInfo *cell_info)
173 return _gtk_tree_path_new_from_rbtree (cell_info->tree, cell_info->node);
177 cell_info_hash (gconstpointer info)
179 const GtkTreeViewAccessibleCellInfo *cell_info = info;
182 node = GPOINTER_TO_UINT (cell_info->node);
183 col = GPOINTER_TO_UINT (cell_info->cell_col_ref);
185 return ((node << sizeof (guint) / 2) | (node >> sizeof (guint) / 2)) ^ col;
189 cell_info_equal (gconstpointer a, gconstpointer b)
191 const GtkTreeViewAccessibleCellInfo *cell_info_a = a;
192 const GtkTreeViewAccessibleCellInfo *cell_info_b = b;
194 return cell_info_a->node == cell_info_b->node &&
195 cell_info_a->cell_col_ref == cell_info_b->cell_col_ref;
199 gtk_tree_view_accessible_initialize (AtkObject *obj,
202 GtkTreeViewAccessible *accessible;
203 GtkTreeView *tree_view;
204 GtkTreeModel *tree_model;
206 GtkTreeSelection *selection;
208 ATK_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->initialize (obj, data);
210 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
211 accessible->focus_cell = NULL;
212 accessible->n_children_deleted = 0;
214 accessible->cell_infos = g_hash_table_new_full (cell_info_hash,
215 cell_info_equal, NULL, (GDestroyNotify) cell_info_free);
217 widget = GTK_WIDGET (data);
218 tree_view = GTK_TREE_VIEW (widget);
219 tree_model = gtk_tree_view_get_model (tree_view);
220 selection = gtk_tree_view_get_selection (tree_view);
222 g_signal_connect_after (widget, "row-collapsed",
223 G_CALLBACK (row_collapsed_cb), NULL);
224 g_signal_connect (selection, "changed",
225 G_CALLBACK (selection_changed_cb), obj);
227 g_signal_connect (tree_view, "cursor-changed",
228 G_CALLBACK (cursor_changed), accessible);
229 g_signal_connect (tree_view, "focus-in-event",
230 G_CALLBACK (focus_in), NULL);
231 g_signal_connect (tree_view, "focus-out-event",
232 G_CALLBACK (focus_out), NULL);
234 accessible->tree_model = tree_model;
237 g_object_add_weak_pointer (G_OBJECT (accessible->tree_model), (gpointer *)&accessible->tree_model);
238 connect_model_signals (tree_view, accessible);
240 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
241 obj->role = ATK_ROLE_TABLE;
243 obj->role = ATK_ROLE_TREE_TABLE;
246 gtk_tree_view_set_destroy_count_func (tree_view,
252 gtk_tree_view_accessible_finalize (GObject *object)
254 GtkTreeViewAccessible *accessible = GTK_TREE_VIEW_ACCESSIBLE (object);
256 if (accessible->tree_model)
257 disconnect_model_signals (accessible);
259 if (accessible->cell_infos)
260 g_hash_table_destroy (accessible->cell_infos);
262 G_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->finalize (object);
266 gtk_tree_view_accessible_notify_gtk (GObject *obj,
270 GtkTreeView *tree_view;
271 GtkTreeViewAccessible *accessible;
273 widget = GTK_WIDGET (obj);
274 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
275 tree_view = GTK_TREE_VIEW (widget);
277 if (g_strcmp0 (pspec->name, "model") == 0)
279 GtkTreeModel *tree_model;
282 tree_model = gtk_tree_view_get_model (tree_view);
283 if (accessible->tree_model)
284 disconnect_model_signals (accessible);
285 g_hash_table_remove_all (accessible->cell_infos);
286 accessible->tree_model = tree_model;
290 g_object_add_weak_pointer (G_OBJECT (accessible->tree_model), (gpointer *)&accessible->tree_model);
291 connect_model_signals (tree_view, accessible);
293 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
294 role = ATK_ROLE_TABLE;
296 role = ATK_ROLE_TREE_TABLE;
300 role = ATK_ROLE_UNKNOWN;
302 atk_object_set_role (ATK_OBJECT (accessible), role);
303 g_object_freeze_notify (G_OBJECT (accessible));
304 g_signal_emit_by_name (accessible, "model-changed");
305 g_signal_emit_by_name (accessible, "visible-data-changed");
306 g_object_thaw_notify (G_OBJECT (accessible));
309 GTK_WIDGET_ACCESSIBLE_CLASS (_gtk_tree_view_accessible_parent_class)->notify_gtk (obj, pspec);
313 gtk_tree_view_accessible_destroyed (GtkWidget *widget,
314 GtkAccessible *gtk_accessible)
316 GtkTreeViewAccessible *accessible;
318 if (!GTK_IS_TREE_VIEW (widget))
321 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_accessible);
323 if (accessible->tree_model)
325 disconnect_model_signals (accessible);
326 accessible->tree_model = NULL;
328 if (accessible->focus_cell)
330 g_object_unref (accessible->focus_cell);
331 accessible->focus_cell = NULL;
336 gtk_tree_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
340 widget = gtk_accessible_get_widget (accessible);
342 g_signal_connect_after (widget, "destroy",
343 G_CALLBACK (gtk_tree_view_accessible_destroyed), accessible);
345 GTK_ACCESSIBLE_CLASS (_gtk_tree_view_accessible_parent_class)->connect_widget_destroyed (accessible);
349 get_n_rows (GtkTreeView *tree_view)
353 tree = _gtk_tree_view_get_rbtree (tree_view);
358 return tree->root->total_count;
362 get_n_columns (GtkTreeView *tree_view)
364 guint i, visible_columns;
368 for (i = 0; i < gtk_tree_view_get_n_columns (tree_view); i++)
370 GtkTreeViewColumn *column = gtk_tree_view_get_column (tree_view, i);
372 if (gtk_tree_view_column_get_visible (column))
376 return visible_columns;
379 gtk_tree_view_accessible_get_n_children (AtkObject *obj)
382 GtkTreeView *tree_view;
384 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
388 tree_view = GTK_TREE_VIEW (widget);
389 return (get_n_rows (tree_view) + 1) * get_n_columns (tree_view);
392 static GtkTreeViewColumn *
393 get_visible_column (GtkTreeView *tree_view,
398 for (i = 0; i < gtk_tree_view_get_n_columns (tree_view); i++)
400 GtkTreeViewColumn *column = gtk_tree_view_get_column (tree_view, i);
402 if (!gtk_tree_view_column_get_visible (column))
411 g_return_val_if_reached (NULL);
415 gtk_tree_view_accessible_ref_child (AtkObject *obj,
419 GtkTreeViewAccessible *accessible;
420 GtkCellAccessible *cell;
421 GtkTreeView *tree_view;
422 GtkTreeModel *tree_model;
423 GtkCellRenderer *renderer;
425 GtkTreeViewColumn *tv_col;
426 GtkTreeSelection *selection;
432 GtkTreeViewColumn *expander_tv;
433 GList *renderer_list;
435 GtkContainerCellAccessible *container = NULL;
436 GtkRendererCellAccessible *renderer_cell;
437 gboolean is_expander, is_expanded, retval;
438 gboolean editable = FALSE;
441 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
445 if (i >= gtk_tree_view_accessible_get_n_children (obj))
448 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
449 tree_view = GTK_TREE_VIEW (widget);
450 if (i < get_n_columns (tree_view))
452 tv_col = get_visible_column (tree_view, i);
453 child = get_header_from_column (tv_col);
455 g_object_ref (child);
459 /* Check whether the child is cached */
460 cell = find_cell (accessible, i);
464 return ATK_OBJECT (cell);
467 if (accessible->focus_cell == NULL)
468 focus_index = get_focus_index (tree_view);
472 /* Find the RBTree and GtkTreeViewColumn for the index */
473 if (!get_rbtree_column_from_index (tree_view, i, &tree, &node, &tv_col))
476 path = _gtk_tree_path_new_from_rbtree (tree, node);
477 tree_model = gtk_tree_view_get_model (tree_view);
478 retval = gtk_tree_model_get_iter (tree_model, &iter, path);
482 expander_tv = gtk_tree_view_get_expander_column (tree_view);
485 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_PARENT))
487 if (expander_tv == tv_col)
490 is_expanded = node->children != NULL;
493 gtk_tree_view_column_cell_set_cell_data (tv_col, tree_model, &iter,
494 is_expander, is_expanded);
496 renderer_list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
498 /* If there is not exactly one renderer in the list,
501 if (renderer_list == NULL || renderer_list->next)
503 GtkCellAccessible *container_cell;
505 container = _gtk_container_cell_accessible_new ();
507 container_cell = GTK_CELL_ACCESSIBLE (container);
508 _gtk_cell_accessible_initialise (container_cell, widget, ATK_OBJECT (accessible));
510 /* The GtkTreeViewAccessibleCellInfo structure for the container will
511 * be before the ones for the cells so that the first one we find for
512 * a position will be for the container
514 cell_info_new (accessible, tree_model, tree, node, tv_col, container_cell);
515 parent = ATK_OBJECT (container);
518 parent = ATK_OBJECT (accessible);
522 for (l = renderer_list; l; l = l->next)
524 renderer = GTK_CELL_RENDERER (l->data);
526 if (GTK_IS_CELL_RENDERER_TEXT (renderer))
528 g_object_get (G_OBJECT (renderer), "editable", &editable, NULL);
529 child = _gtk_text_cell_accessible_new ();
531 else if (GTK_IS_CELL_RENDERER_TOGGLE (renderer))
532 child = _gtk_boolean_cell_accessible_new ();
533 else if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
534 child = _gtk_image_cell_accessible_new ();
536 child = _gtk_renderer_cell_accessible_new ();
538 cell = GTK_CELL_ACCESSIBLE (child);
539 renderer_cell = GTK_RENDERER_CELL_ACCESSIBLE (child);
541 /* Create the GtkTreeViewAccessibleCellInfo for this cell */
542 if (parent == ATK_OBJECT (accessible))
543 cell_info_new (accessible, tree_model, tree, node, tv_col, cell);
545 _gtk_cell_accessible_initialise (cell, widget, parent);
548 _gtk_container_cell_accessible_add_child (container, cell);
550 update_cell_value (renderer_cell, accessible, FALSE);
552 /* Add the actions appropriate for this cell */
553 add_cell_actions (cell, editable);
555 /* Set state if it is expandable */
558 set_cell_expandable (cell);
560 _gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, FALSE);
563 /* If the row is selected, all cells on the row are selected */
564 selection = gtk_tree_view_get_selection (tree_view);
566 if (gtk_tree_selection_path_is_selected (selection, path))
567 _gtk_cell_accessible_add_state (cell, ATK_STATE_SELECTED, FALSE);
569 _gtk_cell_accessible_add_state (cell, ATK_STATE_FOCUSABLE, FALSE);
570 if (focus_index == i)
572 accessible->focus_cell = g_object_ref (cell);
573 _gtk_cell_accessible_add_state (cell, ATK_STATE_FOCUSED, FALSE);
574 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
577 g_list_free (renderer_list);
579 child = ATK_OBJECT (container);
581 if (expander_tv == tv_col)
583 AtkRelationSet *relation_set;
584 AtkObject *accessible_array[1];
585 AtkRelation* relation;
586 AtkObject *parent_node;
588 relation_set = atk_object_ref_relation_set (ATK_OBJECT (child));
590 gtk_tree_path_up (path);
591 if (gtk_tree_path_get_depth (path) == 0)
597 parent_index = get_index (tree_view, path, i % get_n_columns (tree_view));
598 parent_node = atk_object_ref_accessible_child (obj, parent_index);
600 accessible_array[0] = parent_node;
601 relation = atk_relation_new (accessible_array, 1,
602 ATK_RELATION_NODE_CHILD_OF);
603 atk_relation_set_add (relation_set, relation);
604 atk_object_add_relationship (parent_node, ATK_RELATION_NODE_PARENT_OF, child);
605 g_object_unref (relation);
606 g_object_unref (relation_set);
608 gtk_tree_path_free (path);
610 /* We do not increase the reference count here; when g_object_unref()
611 * is called for the cell then cell_destroyed() is called and this
612 * removes the cell from the cache.
618 gtk_tree_view_accessible_ref_state_set (AtkObject *obj)
620 AtkStateSet *state_set;
623 state_set = ATK_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->ref_state_set (obj);
624 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
627 atk_state_set_add_state (state_set, ATK_STATE_MANAGES_DESCENDANTS);
633 _gtk_tree_view_accessible_class_init (GtkTreeViewAccessibleClass *klass)
635 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
636 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
637 GtkAccessibleClass *accessible_class = (GtkAccessibleClass*)klass;
638 GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
639 GtkContainerAccessibleClass *container_class = (GtkContainerAccessibleClass*)klass;
641 class->get_n_children = gtk_tree_view_accessible_get_n_children;
642 class->ref_child = gtk_tree_view_accessible_ref_child;
643 class->ref_state_set = gtk_tree_view_accessible_ref_state_set;
644 class->initialize = gtk_tree_view_accessible_initialize;
646 widget_class->notify_gtk = gtk_tree_view_accessible_notify_gtk;
648 accessible_class->connect_widget_destroyed = gtk_tree_view_accessible_connect_widget_destroyed;
650 /* The children of a GtkTreeView are the buttons at the top of the columns
651 * we do not represent these as children so we do not want to report
652 * children added or deleted when these changed.
654 container_class->add_gtk = NULL;
655 container_class->remove_gtk = NULL;
657 gobject_class->finalize = gtk_tree_view_accessible_finalize;
661 _gtk_tree_view_accessible_init (GtkTreeViewAccessible *view)
666 get_focus_index (GtkTreeView *tree_view)
668 GtkTreePath *focus_path;
669 GtkTreeViewColumn *focus_column;
672 gtk_tree_view_get_cursor (tree_view, &focus_path, &focus_column);
673 if (focus_path && focus_column)
674 index = get_index (tree_view, focus_path,
675 get_column_number (tree_view, focus_column));
680 gtk_tree_path_free (focus_path);
685 /* This function returns a reference to the accessible object
686 * for the cell in the treeview which has focus, if any
689 gtk_tree_view_accessible_ref_focus_cell (GtkTreeView *tree_view)
691 AtkObject *focus_cell = NULL;
695 focus_index = get_focus_index (tree_view);
696 if (focus_index >= 0)
698 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
699 focus_cell = atk_object_ref_accessible_child (atk_obj, focus_index);
708 gtk_tree_view_accessible_ref_accessible_at_point (AtkComponent *component,
711 AtkCoordType coord_type)
714 GtkTreeView *tree_view;
716 GtkTreeViewColumn *tv_column;
721 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
725 tree_view = GTK_TREE_VIEW (widget);
727 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
728 gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, x, y, &bx, &by);
729 ret_val = gtk_tree_view_get_path_at_pos (tree_view,
730 bx - x_pos, by - y_pos,
731 &path, &tv_column, NULL, NULL);
736 column = get_column_number (tree_view, tv_column);
737 index = get_index (tree_view, path, column);
738 gtk_tree_path_free (path);
740 return gtk_tree_view_accessible_ref_child (ATK_OBJECT (component), index);
747 atk_component_interface_init (AtkComponentIface *iface)
749 iface->ref_accessible_at_point = gtk_tree_view_accessible_ref_accessible_at_point;
755 gtk_tree_view_accessible_get_index_at (AtkTable *table,
762 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
766 n_cols = atk_table_get_n_columns (table);
767 n_rows = atk_table_get_n_rows (table);
769 if (row >= n_rows || column >= n_cols)
772 return (row + 1) * n_cols + column;
776 gtk_tree_view_accessible_get_column_at_index (AtkTable *table,
782 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
786 if (index >= gtk_tree_view_accessible_get_n_children (ATK_OBJECT (table)))
789 n_columns = get_n_columns (GTK_TREE_VIEW (widget));
791 /* checked by the n_children() check above */
792 g_assert (n_columns > 0);
794 return index % n_columns;
798 gtk_tree_view_accessible_get_row_at_index (AtkTable *table,
802 GtkTreeView *tree_view;
804 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
808 tree_view = GTK_TREE_VIEW (widget);
810 index /= get_n_columns (tree_view);
812 if (index >= get_n_rows (tree_view))
819 gtk_tree_view_accessible_table_ref_at (AtkTable *table,
825 index = gtk_tree_view_accessible_get_index_at (table, row, column);
829 return gtk_tree_view_accessible_ref_child (ATK_OBJECT (table), index);
833 gtk_tree_view_accessible_get_n_rows (AtkTable *table)
837 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
841 return get_n_rows (GTK_TREE_VIEW (widget));
845 gtk_tree_view_accessible_get_n_columns (AtkTable *table)
849 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
853 return get_n_columns (GTK_TREE_VIEW (widget));
857 gtk_tree_view_accessible_is_row_selected (AtkTable *table,
861 GtkTreeView *tree_view;
862 GtkTreeSelection *selection;
865 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
872 tree_view = GTK_TREE_VIEW (widget);
873 selection = gtk_tree_view_get_selection (tree_view);
875 set_iter_nth_row (tree_view, &iter, row);
876 return gtk_tree_selection_iter_is_selected (selection, &iter);
880 gtk_tree_view_accessible_is_selected (AtkTable *table,
884 return gtk_tree_view_accessible_is_row_selected (table, row);
888 get_selected_rows (GtkTreeModel *model,
893 GPtrArray *array = (GPtrArray *)data;
895 g_ptr_array_add (array, gtk_tree_path_copy (path));
899 gtk_tree_view_accessible_get_selected_rows (AtkTable *table,
900 gint **rows_selected)
903 GtkTreeView *tree_view;
904 GtkTreeModel *tree_model;
906 GtkTreeSelection *selection;
907 GtkTreePath *tree_path;
910 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
914 tree_view = GTK_TREE_VIEW (widget);
915 selection = gtk_tree_view_get_selection (tree_view);
917 switch (gtk_tree_selection_get_mode (selection))
919 case GTK_SELECTION_SINGLE:
920 case GTK_SELECTION_BROWSE:
921 if (gtk_tree_selection_get_selected (selection, &tree_model, &iter))
927 *rows_selected = g_new (gint, 1);
928 tree_path = gtk_tree_model_get_path (tree_model, &iter);
929 row = get_row_from_tree_path (tree_view, tree_path);
930 gtk_tree_path_free (tree_path);
932 /* shouldn't ever happen */
933 g_return_val_if_fail (row != -1, 0);
935 *rows_selected[0] = row;
940 case GTK_SELECTION_MULTIPLE:
942 GPtrArray *array = g_ptr_array_new();
944 gtk_tree_selection_selected_foreach (selection, get_selected_rows, array);
945 ret_val = array->len;
947 if (rows_selected && ret_val)
951 *rows_selected = g_new (gint, ret_val);
952 for (i = 0; i < ret_val; i++)
956 tree_path = (GtkTreePath *) g_ptr_array_index (array, i);
957 row = get_row_from_tree_path (tree_view, tree_path);
958 gtk_tree_path_free (tree_path);
959 (*rows_selected)[i] = row;
962 g_ptr_array_free (array, FALSE);
965 case GTK_SELECTION_NONE:
972 gtk_tree_view_accessible_add_row_selection (AtkTable *table,
976 GtkTreeView *tree_view;
977 GtkTreeModel *tree_model;
978 GtkTreeSelection *selection;
979 GtkTreePath *tree_path;
980 GtkTreeIter iter_to_row;
982 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
986 if (!gtk_tree_view_accessible_is_row_selected (table, row))
988 tree_view = GTK_TREE_VIEW (widget);
989 tree_model = gtk_tree_view_get_model (tree_view);
990 selection = gtk_tree_view_get_selection (tree_view);
992 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
994 tree_path = gtk_tree_path_new ();
995 gtk_tree_path_append_index (tree_path, row);
996 gtk_tree_selection_select_path (selection,tree_path);
997 gtk_tree_path_free (tree_path);
1001 set_iter_nth_row (tree_view, &iter_to_row, row);
1002 gtk_tree_selection_select_iter (selection, &iter_to_row);
1006 return gtk_tree_view_accessible_is_row_selected (table, row);
1010 gtk_tree_view_accessible_remove_row_selection (AtkTable *table,
1014 GtkTreeView *tree_view;
1015 GtkTreeSelection *selection;
1017 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1021 tree_view = GTK_TREE_VIEW (widget);
1022 selection = gtk_tree_view_get_selection (tree_view);
1024 if (gtk_tree_view_accessible_is_row_selected (table, row))
1026 gtk_tree_selection_unselect_all (selection);
1034 gtk_tree_view_accessible_get_column_header (AtkTable *table,
1038 GtkTreeView *tree_view;
1039 GtkTreeViewColumn *tv_col;
1041 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1045 tree_view = GTK_TREE_VIEW (widget);
1046 if (in_col < 0 || in_col >= get_n_columns (tree_view))
1049 tv_col = get_visible_column (tree_view, in_col);
1050 return get_header_from_column (tv_col);
1053 static const gchar *
1054 gtk_tree_view_accessible_get_column_description (AtkTable *table,
1058 GtkTreeView *tree_view;
1059 GtkTreeViewColumn *tv_col;
1061 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1065 tree_view = GTK_TREE_VIEW (widget);
1066 if (in_col < 0 || in_col >= get_n_columns (tree_view))
1069 tv_col = get_visible_column (tree_view, in_col);
1070 return gtk_tree_view_column_get_title (tv_col);
1074 atk_table_interface_init (AtkTableIface *iface)
1076 iface->ref_at = gtk_tree_view_accessible_table_ref_at;
1077 iface->get_n_rows = gtk_tree_view_accessible_get_n_rows;
1078 iface->get_n_columns = gtk_tree_view_accessible_get_n_columns;
1079 iface->get_index_at = gtk_tree_view_accessible_get_index_at;
1080 iface->get_column_at_index = gtk_tree_view_accessible_get_column_at_index;
1081 iface->get_row_at_index = gtk_tree_view_accessible_get_row_at_index;
1082 iface->is_row_selected = gtk_tree_view_accessible_is_row_selected;
1083 iface->is_selected = gtk_tree_view_accessible_is_selected;
1084 iface->get_selected_rows = gtk_tree_view_accessible_get_selected_rows;
1085 iface->add_row_selection = gtk_tree_view_accessible_add_row_selection;
1086 iface->remove_row_selection = gtk_tree_view_accessible_remove_row_selection;
1087 iface->get_column_extent_at = NULL;
1088 iface->get_row_extent_at = NULL;
1089 iface->get_column_header = gtk_tree_view_accessible_get_column_header;
1090 iface->get_column_description = gtk_tree_view_accessible_get_column_description;
1093 /* atkselection.h */
1096 gtk_tree_view_accessible_add_selection (AtkSelection *selection,
1103 table = ATK_TABLE (selection);
1104 n_columns = gtk_tree_view_accessible_get_n_columns (table);
1108 row = gtk_tree_view_accessible_get_row_at_index (table, i);
1109 return gtk_tree_view_accessible_add_row_selection (table, row);
1113 gtk_tree_view_accessible_clear_selection (AtkSelection *selection)
1116 GtkTreeView *tree_view;
1117 GtkTreeSelection *tree_selection;
1119 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
1123 tree_view = GTK_TREE_VIEW (widget);
1124 tree_selection = gtk_tree_view_get_selection (tree_view);
1126 gtk_tree_selection_unselect_all (tree_selection);
1131 gtk_tree_view_accessible_ref_selection (AtkSelection *selection,
1140 table = ATK_TABLE (selection);
1141 n_columns = gtk_tree_view_accessible_get_n_columns (table);
1142 n_selected = gtk_tree_view_accessible_get_selected_rows (table, &selected);
1143 if (i >= n_columns * n_selected)
1146 row = selected[i / n_columns];
1149 return gtk_tree_view_accessible_table_ref_at (table, row, i % n_columns);
1153 gtk_tree_view_accessible_get_selection_count (AtkSelection *selection)
1158 table = ATK_TABLE (selection);
1159 n_selected = gtk_tree_view_accessible_get_selected_rows (table, NULL);
1161 n_selected *= gtk_tree_view_accessible_get_n_columns (table);
1166 gtk_tree_view_accessible_is_child_selected (AtkSelection *selection,
1172 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
1176 row = atk_table_get_row_at_index (ATK_TABLE (selection), i);
1178 return gtk_tree_view_accessible_is_row_selected (ATK_TABLE (selection), row);
1181 static void atk_selection_interface_init (AtkSelectionIface *iface)
1183 iface->add_selection = gtk_tree_view_accessible_add_selection;
1184 iface->clear_selection = gtk_tree_view_accessible_clear_selection;
1185 iface->ref_selection = gtk_tree_view_accessible_ref_selection;
1186 iface->get_selection_count = gtk_tree_view_accessible_get_selection_count;
1187 iface->is_child_selected = gtk_tree_view_accessible_is_child_selected;
1190 #define EXTRA_EXPANDER_PADDING 4
1193 gtk_tree_view_accessible_get_cell_area (GtkCellAccessibleParent *parent,
1194 GtkCellAccessible *cell,
1195 GdkRectangle *cell_rect)
1198 GtkTreeView *tree_view;
1199 GtkTreeViewColumn *tv_col;
1201 AtkObject *parent_cell;
1202 GtkTreeViewAccessibleCellInfo *cell_info;
1203 GtkCellAccessible *top_cell;
1205 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1209 tree_view = GTK_TREE_VIEW (widget);
1210 parent_cell = atk_object_get_parent (ATK_OBJECT (cell));
1211 if (parent_cell != ATK_OBJECT (parent))
1212 top_cell = GTK_CELL_ACCESSIBLE (parent_cell);
1215 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), top_cell);
1218 path = cell_info_get_path (cell_info);
1219 tv_col = cell_info->cell_col_ref;
1222 GtkTreeViewColumn *expander_column;
1223 gint focus_line_width;
1225 gtk_tree_view_get_cell_area (tree_view, path, tv_col, cell_rect);
1226 expander_column = gtk_tree_view_get_expander_column (tree_view);
1227 if (expander_column == tv_col)
1230 gtk_widget_style_get (widget,
1231 "expander-size", &expander_size,
1233 cell_rect->x += expander_size + EXTRA_EXPANDER_PADDING;
1234 cell_rect->width -= expander_size + EXTRA_EXPANDER_PADDING;
1236 gtk_widget_style_get (widget,
1237 "focus-line-width", &focus_line_width,
1240 cell_rect->x += focus_line_width;
1241 cell_rect->width -= 2 * focus_line_width;
1243 gtk_tree_path_free (path);
1245 /* A column has more than one renderer so we find the position
1248 if (top_cell != cell)
1255 GtkCellRenderer *renderer;
1257 cell_index = atk_object_get_index_in_parent (ATK_OBJECT (cell));
1258 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
1259 renderer = g_list_nth_data (renderers, cell_index);
1261 found = gtk_tree_view_column_cell_get_position (tv_col, renderer, &cell_start, &cell_width);
1264 cell_rect->x += cell_start;
1265 cell_rect->width = cell_width;
1267 g_list_free (renderers);
1274 gtk_tree_view_accessible_get_cell_extents (GtkCellAccessibleParent *parent,
1275 GtkCellAccessible *cell,
1280 AtkCoordType coord_type)
1283 GtkTreeView *tree_view;
1284 GdkWindow *bin_window;
1285 GdkRectangle cell_rect;
1288 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1292 tree_view = GTK_TREE_VIEW (widget);
1293 gtk_tree_view_accessible_get_cell_area (parent, cell, &cell_rect);
1294 bin_window = gtk_tree_view_get_bin_window (tree_view);
1295 gdk_window_get_origin (bin_window, &w_x, &w_y);
1297 if (coord_type == ATK_XY_WINDOW)
1300 gint x_toplevel, y_toplevel;
1302 window = gdk_window_get_toplevel (bin_window);
1303 gdk_window_get_origin (window, &x_toplevel, &y_toplevel);
1309 *width = cell_rect.width;
1310 *height = cell_rect.height;
1311 if (is_cell_showing (tree_view, &cell_rect))
1313 *x = cell_rect.x + w_x;
1314 *y = cell_rect.y + w_y;
1324 gtk_tree_view_accessible_grab_cell_focus (GtkCellAccessibleParent *parent,
1325 GtkCellAccessible *cell)
1328 GtkTreeView *tree_view;
1329 GtkTreeViewColumn *tv_col;
1331 AtkObject *parent_cell;
1332 AtkObject *cell_object;
1333 GtkTreeViewAccessibleCellInfo *cell_info;
1334 GtkCellRenderer *renderer = NULL;
1335 GtkWidget *toplevel;
1338 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1342 tree_view = GTK_TREE_VIEW (widget);
1344 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
1347 cell_object = ATK_OBJECT (cell);
1348 parent_cell = atk_object_get_parent (cell_object);
1349 tv_col = cell_info->cell_col_ref;
1350 if (parent_cell != ATK_OBJECT (parent))
1352 /* GtkCellAccessible is in a GtkContainerCellAccessible.
1353 * The GtkTreeViewColumn has multiple renderers;
1354 * find the corresponding one.
1358 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
1359 index = atk_object_get_index_in_parent (cell_object);
1360 renderer = g_list_nth_data (renderers, index);
1361 g_list_free (renderers);
1363 path = cell_info_get_path (cell_info);
1367 gtk_tree_view_set_cursor_on_cell (tree_view, path, tv_col, renderer, FALSE);
1369 gtk_tree_view_set_cursor (tree_view, path, tv_col, FALSE);
1371 gtk_tree_path_free (path);
1372 gtk_widget_grab_focus (widget);
1373 toplevel = gtk_widget_get_toplevel (widget);
1374 if (gtk_widget_is_toplevel (toplevel))
1376 #ifdef GDK_WINDOWING_X11
1377 gtk_window_present_with_time (GTK_WINDOW (toplevel),
1378 gdk_x11_get_server_time (gtk_widget_get_window (widget)));
1380 gtk_window_present (GTK_WINDOW (toplevel));
1391 gtk_tree_view_accessible_get_child_index (GtkCellAccessibleParent *parent,
1392 GtkCellAccessible *cell)
1394 GtkTreeViewAccessibleCellInfo *cell_info;
1395 GtkTreeView *tree_view;
1397 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
1401 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
1403 return cell_info_get_index (tree_view, cell_info);
1406 static GtkCellRendererState
1407 gtk_tree_view_accessible_get_renderer_state (GtkCellAccessibleParent *parent,
1408 GtkCellAccessible *cell)
1410 GtkTreeViewAccessibleCellInfo *cell_info;
1411 GtkTreeView *treeview;
1412 GtkCellRendererState flags;
1414 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
1420 if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_SELECTED))
1421 flags |= GTK_CELL_RENDERER_SELECTED;
1423 if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_PRELIT))
1424 flags |= GTK_CELL_RENDERER_PRELIT;
1426 if (gtk_tree_view_column_get_sort_indicator (cell_info->cell_col_ref))
1427 flags |= GTK_CELL_RENDERER_SORTED;
1429 treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
1431 if (cell_info->cell_col_ref == gtk_tree_view_get_expander_column (treeview))
1433 if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_PARENT))
1434 flags |= GTK_CELL_RENDERER_EXPANDABLE;
1436 if (cell_info->node->children)
1437 flags |= GTK_CELL_RENDERER_EXPANDED;
1440 if (gtk_widget_has_focus (GTK_WIDGET (treeview)))
1442 GtkTreeViewColumn *column;
1447 gtk_tree_view_get_cursor (treeview, &path, &column);
1450 _gtk_tree_view_find_node (treeview, path, &tree, &node);
1451 gtk_tree_path_free (path);
1456 if (cell_info->cell_col_ref == column
1457 && cell_info->tree == tree
1458 && cell_info->node == node)
1459 flags |= GTK_CELL_RENDERER_FOCUSED;
1466 gtk_tree_view_accessible_set_cell_data (GtkCellAccessibleParent *parent,
1467 GtkCellAccessible *cell)
1469 GtkTreeViewAccessibleCellInfo *cell_info;
1470 GtkTreeView *treeview;
1471 gboolean is_expander, is_expanded;
1472 GtkTreeModel *model;
1476 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
1480 treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
1481 model = gtk_tree_view_get_model (treeview);
1483 if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_PARENT) &&
1484 cell_info->cell_col_ref == gtk_tree_view_get_expander_column (treeview))
1487 is_expanded = cell_info->node->children != NULL;
1491 is_expander = FALSE;
1492 is_expanded = FALSE;
1495 path = cell_info_get_path (cell_info);
1497 !gtk_tree_model_get_iter (model, &iter, path))
1499 /* We only track valid cells, this should never happen */
1500 g_return_if_reached ();
1503 gtk_tree_view_column_cell_set_cell_data (cell_info->cell_col_ref,
1511 gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface)
1513 iface->get_cell_extents = gtk_tree_view_accessible_get_cell_extents;
1514 iface->get_cell_area = gtk_tree_view_accessible_get_cell_area;
1515 iface->grab_focus = gtk_tree_view_accessible_grab_cell_focus;
1516 iface->get_child_index = gtk_tree_view_accessible_get_child_index;
1517 iface->get_renderer_state = gtk_tree_view_accessible_get_renderer_state;
1518 iface->set_cell_data = gtk_tree_view_accessible_set_cell_data;
1521 /* signal handling */
1524 row_collapsed_cb (GtkTreeView *tree_view,
1528 GtkTreeModel *tree_model;
1530 GtkTreeViewAccessible *accessible;
1533 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
1534 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1535 tree_model = gtk_tree_view_get_model (tree_view);
1537 /* Set collapse state */
1538 set_expand_state (tree_view, tree_model, accessible, path, FALSE);
1539 if (accessible->n_children_deleted == 0)
1541 row = get_row_from_tree_path (tree_view, path);
1544 g_signal_emit_by_name (atk_obj, "row-deleted", row,
1545 accessible->n_children_deleted);
1546 accessible->n_children_deleted = 0;
1551 selection_changed_cb (GtkTreeSelection *selection,
1554 GtkTreeViewAccessible *accessible;
1555 GtkTreeView *tree_view;
1557 GtkTreeViewAccessibleCellInfo *info;
1558 GtkTreeSelection *tree_selection;
1560 GHashTableIter iter;
1562 accessible = GTK_TREE_VIEW_ACCESSIBLE (data);
1563 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
1567 tree_view = GTK_TREE_VIEW (widget);
1568 tree_selection = gtk_tree_view_get_selection (tree_view);
1570 /* FIXME: clean rows iterates through all cells too */
1571 g_hash_table_iter_init (&iter, accessible->cell_infos);
1572 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&info))
1574 _gtk_cell_accessible_remove_state (info->cell, ATK_STATE_SELECTED, TRUE);
1576 path = cell_info_get_path (info);
1577 if (path && gtk_tree_selection_path_is_selected (tree_selection, path))
1578 _gtk_cell_accessible_add_state (info->cell, ATK_STATE_SELECTED, TRUE);
1579 gtk_tree_path_free (path);
1581 if (gtk_widget_get_realized (widget))
1582 g_signal_emit_by_name (accessible, "selection-changed");
1586 cursor_changed (GtkTreeView *tree_view,
1587 GtkTreeViewAccessible *accessible)
1591 cell = gtk_tree_view_accessible_ref_focus_cell (tree_view);
1594 if (cell != accessible->focus_cell)
1596 if (accessible->focus_cell)
1598 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_ACTIVE, FALSE);
1599 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_FOCUSED, FALSE);
1600 g_object_unref (accessible->focus_cell);
1601 accessible->focus_cell = cell;
1604 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
1606 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_ACTIVE, FALSE);
1607 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_FOCUSED, FALSE);
1610 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
1613 g_object_unref (cell);
1618 focus_in (GtkWidget *widget)
1620 GtkTreeView *tree_view;
1621 GtkTreeViewAccessible *accessible;
1622 AtkStateSet *state_set;
1625 tree_view = GTK_TREE_VIEW (widget);
1626 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
1628 if (accessible->focus_cell == NULL)
1630 cell = gtk_tree_view_accessible_ref_focus_cell (tree_view);
1633 state_set = atk_object_ref_state_set (cell);
1636 if (!atk_state_set_contains_state (state_set, ATK_STATE_FOCUSED))
1638 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_ACTIVE, FALSE);
1639 accessible->focus_cell = cell;
1640 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_FOCUSED, FALSE);
1641 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
1643 g_object_unref (state_set);
1651 focus_out (GtkWidget *widget)
1653 GtkTreeViewAccessible *accessible;
1655 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
1656 if (accessible->focus_cell)
1658 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_ACTIVE, FALSE);
1659 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_FOCUSED, FALSE);
1660 g_object_unref (accessible->focus_cell);
1661 accessible->focus_cell = NULL;
1667 model_row_changed (GtkTreeModel *tree_model,
1672 GtkTreeView *tree_view = GTK_TREE_VIEW (user_data);
1673 GtkTreeViewAccessible *accessible;
1674 GtkTreePath *cell_path;
1675 GtkTreeViewAccessibleCellInfo *cell_info;
1676 GHashTableIter hash_iter;
1678 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (tree_view)));
1680 /* Loop through our cached cells */
1681 /* Must loop through them all */
1682 g_hash_table_iter_init (&hash_iter, accessible->cell_infos);
1683 while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer *)&cell_info))
1685 cell_path = cell_info_get_path (cell_info);
1687 if (cell_path != NULL)
1689 if (path && gtk_tree_path_compare (cell_path, path) == 0)
1691 if (GTK_IS_RENDERER_CELL_ACCESSIBLE (cell_info->cell))
1692 update_cell_value (GTK_RENDERER_CELL_ACCESSIBLE (cell_info->cell),
1695 gtk_tree_path_free (cell_path);
1698 g_signal_emit_by_name (accessible, "visible-data-changed");
1702 model_row_inserted (GtkTreeModel *tree_model,
1707 GtkTreeView *tree_view = (GtkTreeView *)user_data;
1709 GtkTreeViewAccessible *accessible;
1710 GtkTreePath *path_copy;
1711 gint row, n_inserted, child_row;
1713 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
1714 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1716 /* Check to see if row is visible */
1717 row = get_row_from_tree_path (tree_view, path);
1719 /* A row insert is not necessarily visible. For example,
1720 * a row can be draged & dropped into another row, which
1721 * causes an insert on the model that isn't visible in the
1722 * view. Only generate a signal if the inserted row is
1727 GtkTreeIter tmp_iter;
1730 gtk_tree_model_get_iter (tree_model, &tmp_iter, path);
1732 /* Figure out number of visible children. */
1733 if (gtk_tree_model_iter_has_child (tree_model, &tmp_iter))
1737 * By passing path into this function, we find the number of
1738 * visible children of path.
1741 /* iterate_thru_children modifies path, we don't want that, so give
1743 path2 = gtk_tree_path_copy (path);
1744 iterate_thru_children (tree_view, tree_model,
1745 path2, NULL, &n_inserted, 0);
1746 gtk_tree_path_free (path2);
1748 /* Must add one to include the row that is being added */
1754 /* Generate row-inserted signal */
1755 g_signal_emit_by_name (atk_obj, "row-inserted", row, n_inserted);
1757 /* Generate children-changed signals */
1758 n_cols = get_n_columns (tree_view);
1759 for (child_row = row; child_row < (row + n_inserted); child_row++)
1761 for (col = 0; col < n_cols; col++)
1763 /* Pass NULL as the child object, i.e. 4th argument */
1764 g_signal_emit_by_name (atk_obj, "children-changed::add",
1765 ((row * n_cols) + col), NULL, NULL);
1771 /* The row has been inserted inside another row. This can
1772 * cause a row that previously couldn't be expanded to now
1775 path_copy = gtk_tree_path_copy (path);
1776 gtk_tree_path_up (path_copy);
1777 set_expand_state (tree_view, tree_model, accessible, path_copy, TRUE);
1778 gtk_tree_path_free (path_copy);
1783 model_row_deleted (GtkTreeModel *tree_model,
1787 GtkTreeView *tree_view = (GtkTreeView *)user_data;
1788 GtkTreePath *path_copy;
1790 GtkTreeViewAccessible *accessible;
1793 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
1794 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1796 /* If deleting a row with a depth > 1, then this may affect the
1797 * expansion/contraction of its parent(s). Make sure this is
1800 if (gtk_tree_path_get_depth (path) > 1)
1802 path_copy = gtk_tree_path_copy (path);
1803 gtk_tree_path_up (path_copy);
1804 set_expand_state (tree_view, tree_model, accessible, path_copy, TRUE);
1805 gtk_tree_path_free (path_copy);
1807 row = get_row_from_tree_path (tree_view, path);
1809 /* If the row which is deleted is not visible because it is a child of
1810 * a collapsed row then row will be -1
1813 g_signal_emit_by_name (atk_obj, "row-deleted", row,
1814 accessible->n_children_deleted + 1);
1815 accessible->n_children_deleted = 0;
1817 /* Generate children-changed signals */
1818 for (col = 0; col < get_n_columns (tree_view); col++)
1820 /* Pass NULL as the child object, 4th argument */
1821 g_signal_emit_by_name (atk_obj, "children-changed::remove",
1822 ((row * get_n_columns (tree_view)) + col), NULL, NULL);
1826 /* This function gets called when a row is deleted or when rows are
1827 * removed from the view due to a collapse event. Note that the
1828 * count is the number of visible *children* of the deleted row,
1829 * so it does not include the row being deleted.
1831 * As this function is called before the rows are removed we just note
1832 * the number of rows and then deal with it when we get a notification
1833 * that rows were deleted or collapsed.
1836 destroy_count_func (GtkTreeView *tree_view,
1842 GtkTreeViewAccessible *accessible;
1844 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
1845 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1847 if (accessible->n_children_deleted != 0)
1850 accessible->n_children_deleted = count;
1854 _gtk_tree_view_accessible_reorder (GtkTreeView *treeview)
1856 GtkTreeViewAccessible *accessible;
1858 accessible = GTK_TREE_VIEW_ACCESSIBLE (_gtk_widget_peek_accessible (GTK_WIDGET (treeview)));
1859 if (accessible == NULL)
1862 g_signal_emit_by_name (accessible, "row-reordered");
1866 is_cell_showing (GtkTreeView *tree_view,
1867 GdkRectangle *cell_rect)
1869 GdkRectangle rect, *visible_rect;
1870 GdkRectangle rect1, *tree_cell_rect;
1872 gboolean is_showing;
1874 /* A cell is considered "SHOWING" if any part of the cell is
1875 * in the visible area. Other ways we could do this is by a
1876 * cell's midpoint or if the cell is fully in the visible range.
1877 * Since we have the cell_rect x, y, width, height of the cell,
1878 * any of these is easy to compute.
1880 * It is assumed that cell's rectangle is in widget coordinates
1881 * so we must transform to tree cordinates.
1883 visible_rect = ▭
1884 tree_cell_rect = &rect1;
1885 tree_cell_rect->x = cell_rect->x;
1886 tree_cell_rect->y = cell_rect->y;
1887 tree_cell_rect->width = cell_rect->width;
1888 tree_cell_rect->height = cell_rect->height;
1890 gtk_tree_view_get_visible_rect (tree_view, visible_rect);
1891 gtk_tree_view_convert_tree_to_bin_window_coords (tree_view, visible_rect->x,
1892 visible_rect->y, &bx, &by);
1894 if (((tree_cell_rect->x + tree_cell_rect->width) < bx) ||
1895 ((tree_cell_rect->y + tree_cell_rect->height) < by) ||
1896 (tree_cell_rect->x > (bx + visible_rect->width)) ||
1897 (tree_cell_rect->y > (by + visible_rect->height)))
1907 /* This function is called when a cell's flyweight is created in
1908 * gtk_tree_view_accessible_table_ref_at with emit_change_signal
1909 * set to FALSE and in model_row_changed() on receipt of "row-changed"
1910 * signal when emit_change_signal is set to TRUE
1913 update_cell_value (GtkRendererCellAccessible *renderer_cell,
1914 GtkTreeViewAccessible *accessible,
1915 gboolean emit_change_signal)
1917 GtkTreeViewAccessibleCellInfo *cell_info;
1918 GtkTreeView *tree_view;
1919 GtkTreeModel *tree_model;
1922 GList *renderers, *cur_renderer;
1924 GtkRendererCellAccessibleClass *renderer_cell_class;
1925 GtkCellRendererClass *gtk_cell_renderer_class;
1926 GtkCellAccessible *cell;
1929 gboolean is_expander, is_expanded;
1931 renderer_cell_class = GTK_RENDERER_CELL_ACCESSIBLE_GET_CLASS (renderer_cell);
1932 if (renderer_cell->renderer)
1933 gtk_cell_renderer_class = GTK_CELL_RENDERER_GET_CLASS (renderer_cell->renderer);
1935 gtk_cell_renderer_class = NULL;
1937 prop_list = renderer_cell_class->property_list;
1939 cell = GTK_CELL_ACCESSIBLE (renderer_cell);
1940 cell_info = find_cell_info (accessible, cell);
1944 if (emit_change_signal)
1946 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
1947 tree_model = gtk_tree_view_get_model (tree_view);
1948 path = cell_info_get_path (cell_info);
1952 gtk_tree_model_get_iter (tree_model, &iter, path);
1953 is_expander = FALSE;
1954 is_expanded = FALSE;
1955 if (gtk_tree_model_iter_has_child (tree_model, &iter))
1957 GtkTreeViewColumn *expander_tv;
1959 expander_tv = gtk_tree_view_get_expander_column (tree_view);
1960 if (expander_tv == cell_info->cell_col_ref)
1963 is_expanded = gtk_tree_view_row_expanded (tree_view, path);
1966 gtk_tree_path_free (path);
1967 gtk_tree_view_column_cell_set_cell_data (cell_info->cell_col_ref,
1969 is_expander, is_expanded);
1971 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_info->cell_col_ref));
1975 /* If the cell is in a container, its index is used to find the renderer
1976 * in the list. Otherwise, we assume that the cell is represented
1977 * by the first renderer in the list
1979 parent = atk_object_get_parent (ATK_OBJECT (cell));
1981 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
1982 cur_renderer = g_list_nth (renderers, atk_object_get_index_in_parent (ATK_OBJECT (cell)));
1984 cur_renderer = renderers;
1986 if (cur_renderer == NULL)
1989 if (gtk_cell_renderer_class)
1993 spec = g_object_class_find_property
1994 (G_OBJECT_CLASS (gtk_cell_renderer_class), *prop_list);
1998 GValue value = G_VALUE_INIT;
2000 g_value_init (&value, spec->value_type);
2001 g_object_get_property (cur_renderer->data, *prop_list, &value);
2002 g_object_set_property (G_OBJECT (renderer_cell->renderer),
2003 *prop_list, &value);
2004 g_value_unset (&value);
2007 g_warning ("Invalid property: %s\n", *prop_list);
2011 g_list_free (renderers);
2013 return _gtk_renderer_cell_accessible_update_cache (renderer_cell, emit_change_signal);
2017 get_row_from_tree_path (GtkTreeView *tree_view,
2020 GtkTreeModel *tree_model;
2021 GtkTreePath *root_tree;
2024 tree_model = gtk_tree_view_get_model (tree_view);
2026 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
2027 row = gtk_tree_path_get_indices (path)[0];
2030 root_tree = gtk_tree_path_new_first ();
2032 iterate_thru_children (tree_view, tree_model, root_tree, path, &row, 0);
2033 gtk_tree_path_free (root_tree);
2041 /* Helper recursive function that returns an iter to nth row
2043 static GtkTreeIter *
2044 return_iter_nth_row (GtkTreeView *tree_view,
2045 GtkTreeModel *tree_model,
2050 GtkTreePath *current_path;
2051 GtkTreeIter new_iter;
2052 gboolean row_expanded;
2054 current_path = gtk_tree_model_get_path (tree_model, iter);
2055 if (increment == row)
2057 gtk_tree_path_free (current_path);
2061 row_expanded = gtk_tree_view_row_expanded (tree_view, current_path);
2062 gtk_tree_path_free (current_path);
2065 if ((row_expanded && gtk_tree_model_iter_children (tree_model, iter, &new_iter)) ||
2066 (gtk_tree_model_iter_next (tree_model, iter)) ||
2067 (gtk_tree_model_iter_parent (tree_model, iter, &new_iter) &&
2068 (gtk_tree_model_iter_next (tree_model, iter))))
2069 return return_iter_nth_row (tree_view, tree_model, iter,
2076 set_iter_nth_row (GtkTreeView *tree_view,
2080 GtkTreeModel *tree_model;
2082 tree_model = gtk_tree_view_get_model (tree_view);
2083 gtk_tree_model_get_iter_first (tree_model, iter);
2084 iter = return_iter_nth_row (tree_view, tree_model, iter, 0, row);
2087 /* Recursively called until the row specified by orig is found.
2089 * *count will be set to the visible row number of the child
2090 * relative to the row that was initially passed in as tree_path.
2091 * tree_path could be modified by this function.
2093 * *count will be -1 if orig is not found as a child (a row that is
2094 * not visible will not be found, e.g. if the row is inside a
2095 * collapsed row). If NULL is passed in as orig, *count will
2096 * be a count of the visible children.
2098 * NOTE: the value for depth must be 0 when this recursive function
2099 * is initially called, or it may not function as expected.
2102 iterate_thru_children (GtkTreeView *tree_view,
2103 GtkTreeModel *tree_model,
2104 GtkTreePath *tree_path,
2111 if (!gtk_tree_model_get_iter (tree_model, &iter, tree_path))
2114 if (tree_path && orig && !gtk_tree_path_compare (tree_path, orig))
2118 if (tree_path && orig && gtk_tree_path_compare (tree_path, orig) > 0)
2120 /* Past it, so return -1 */
2124 else if (gtk_tree_view_row_expanded (tree_view, tree_path) &&
2125 gtk_tree_model_iter_has_child (tree_model, &iter))
2128 gtk_tree_path_append_index (tree_path, 0);
2129 iterate_thru_children (tree_view, tree_model, tree_path,
2130 orig, count, (depth + 1));
2133 else if (gtk_tree_model_iter_next (tree_model, &iter))
2136 tree_path = gtk_tree_model_get_path (tree_model, &iter);
2139 iterate_thru_children (tree_view, tree_model, tree_path,
2140 orig, count, depth);
2141 gtk_tree_path_free (tree_path);
2145 else if (gtk_tree_path_up (tree_path))
2147 GtkTreeIter temp_iter;
2148 gboolean exit_loop = FALSE;
2149 gint new_depth = depth - 1;
2153 /* Make sure that we back up until we find a row
2154 * where gtk_tree_path_next does not return NULL.
2158 if (gtk_tree_path_get_depth (tree_path) == 0)
2159 /* depth is now zero so */
2161 gtk_tree_path_next (tree_path);
2163 /* Verify that the next row is a valid row! */
2164 exit_loop = gtk_tree_model_get_iter (tree_model, &temp_iter, tree_path);
2168 /* Keep going up until we find a row that has a valid next */
2169 if (gtk_tree_path_get_depth(tree_path) > 1)
2172 gtk_tree_path_up (tree_path);
2176 /* If depth is 1 and gtk_tree_model_get_iter returns FALSE,
2177 * then we are at the last row, so just return.
2187 /* This guarantees that we will stop when we hit the end of the
2193 iterate_thru_children (tree_view, tree_model, tree_path,
2194 orig, count, new_depth);
2198 /* If it gets here, then the path wasn't found. Situations
2199 * that would cause this would be if the path passed in is
2200 * invalid or contained within the last row, but not visible
2201 * because the last row is not expanded. If NULL was passed
2202 * in then a row count is desired, so only set count to -1
2203 * if orig is not NULL.
2211 /* If the tree_path passed in has children, then
2212 * ATK_STATE_EXPANDABLE is set. If the row is expanded
2213 * ATK_STATE_EXPANDED is turned on. If the row is
2214 * collapsed, then ATK_STATE_EXPANDED is removed.
2216 * If the tree_path passed in has no children, then
2217 * ATK_STATE_EXPANDABLE and ATK_STATE_EXPANDED are removed.
2219 * If set_on_ancestor is TRUE, then this function will also
2220 * update all cells that are ancestors of the tree_path.
2223 set_expand_state (GtkTreeView *tree_view,
2224 GtkTreeModel *tree_model,
2225 GtkTreeViewAccessible *accessible,
2226 GtkTreePath *tree_path,
2227 gboolean set_on_ancestor)
2229 GtkTreeViewColumn *expander_tv;
2230 GtkTreeViewAccessibleCellInfo *cell_info;
2231 GtkTreePath *cell_path;
2234 GHashTableIter hash_iter;
2236 g_hash_table_iter_init (&hash_iter, accessible->cell_infos);
2237 while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer *) &cell_info))
2239 cell_path = cell_info_get_path (cell_info);
2242 if (cell_path != NULL)
2244 GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (cell_info->cell);
2246 expander_tv = gtk_tree_view_get_expander_column (tree_view);
2248 /* Only set state for the cell that is in the column with the
2251 if (expander_tv == cell_info->cell_col_ref)
2253 if (tree_path && gtk_tree_path_compare (cell_path, tree_path) == 0)
2255 else if (set_on_ancestor &&
2256 gtk_tree_path_get_depth (cell_path) <
2257 gtk_tree_path_get_depth (tree_path) &&
2258 gtk_tree_path_is_ancestor (cell_path, tree_path) == 1)
2259 /* Only set if set_on_ancestor was passed in as TRUE */
2263 /* Set ATK_STATE_EXPANDABLE and ATK_STATE_EXPANDED
2264 * for ancestors and found cells.
2268 /* Must check against cell_path since cell_path
2269 * can be equal to or an ancestor of tree_path.
2271 gtk_tree_model_get_iter (tree_model, &iter, cell_path);
2273 /* Set or unset ATK_STATE_EXPANDABLE as appropriate */
2274 if (gtk_tree_model_iter_has_child (tree_model, &iter))
2276 set_cell_expandable (cell);
2278 if (gtk_tree_view_row_expanded (tree_view, cell_path))
2279 _gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, TRUE);
2281 _gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDED, TRUE);
2285 _gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDED, TRUE);
2286 if (_gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDABLE, TRUE))
2287 /* The state may have been propagated to the container cell */
2288 if (!GTK_IS_CONTAINER_CELL_ACCESSIBLE (cell))
2289 _gtk_cell_accessible_remove_action_by_name (cell,
2290 "expand or contract");
2293 /* We assume that each cell in the cache once and
2294 * a container cell is before its child cells so we are
2295 * finished if set_on_ancestor is not set to TRUE.
2297 if (!set_on_ancestor)
2301 gtk_tree_path_free (cell_path);
2306 add_cell_actions (GtkCellAccessible *cell,
2309 if (GTK_IS_BOOLEAN_CELL_ACCESSIBLE (cell))
2310 _gtk_cell_accessible_add_action (cell,
2311 "toggle", "toggles the cell",
2312 NULL, toggle_cell_toggled);
2314 _gtk_cell_accessible_add_action (cell,
2315 "edit", "creates a widget in which the contents of the cell can be edited",
2317 _gtk_cell_accessible_add_action (cell,
2318 "activate", "activate the cell",
2319 NULL, activate_cell);
2323 toggle_cell_expanded (GtkCellAccessible *cell)
2325 GtkTreeViewAccessibleCellInfo *cell_info;
2326 GtkTreeView *tree_view;
2329 AtkStateSet *stateset;
2331 parent = atk_object_get_parent (ATK_OBJECT (cell));
2332 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
2333 parent = atk_object_get_parent (parent);
2335 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
2339 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
2340 path = cell_info_get_path (cell_info);
2344 stateset = atk_object_ref_state_set (ATK_OBJECT (cell));
2345 if (atk_state_set_contains_state (stateset, ATK_STATE_EXPANDED))
2346 gtk_tree_view_collapse_row (tree_view, path);
2348 gtk_tree_view_expand_row (tree_view, path, TRUE);
2349 g_object_unref (stateset);
2350 gtk_tree_path_free (path);
2354 toggle_cell_toggled (GtkCellAccessible *cell)
2356 GtkTreeViewAccessibleCellInfo *cell_info;
2359 GList *renderers, *cur_renderer;
2361 gboolean is_container_cell = FALSE;
2363 parent = atk_object_get_parent (ATK_OBJECT (cell));
2364 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
2366 is_container_cell = TRUE;
2367 parent = atk_object_get_parent (parent);
2370 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
2374 path = cell_info_get_path (cell_info);
2378 /* If the cell is in a container, its index is used to find the
2379 * renderer in the list. Otherwise, we assume that the cell is
2380 * represented by the first renderer in the list
2382 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_info->cell_col_ref));
2383 if (is_container_cell)
2384 cur_renderer = g_list_nth (renderers, atk_object_get_index_in_parent (ATK_OBJECT (cell)));
2386 cur_renderer = renderers;
2390 pathstring = gtk_tree_path_to_string (path);
2391 g_signal_emit_by_name (cur_renderer->data, "toggled", pathstring);
2392 g_free (pathstring);
2395 g_list_free (renderers);
2396 gtk_tree_path_free (path);
2400 edit_cell (GtkCellAccessible *cell)
2402 GtkTreeViewAccessibleCellInfo *cell_info;
2403 GtkTreeView *tree_view;
2407 parent = atk_object_get_parent (ATK_OBJECT (cell));
2408 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
2409 parent = atk_object_get_parent (parent);
2411 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
2415 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
2416 path = cell_info_get_path (cell_info);
2419 gtk_tree_view_set_cursor (tree_view, path, cell_info->cell_col_ref, TRUE);
2420 gtk_tree_path_free (path);
2424 activate_cell (GtkCellAccessible *cell)
2426 GtkTreeViewAccessibleCellInfo *cell_info;
2427 GtkTreeView *tree_view;
2431 parent = atk_object_get_parent (ATK_OBJECT (cell));
2432 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
2433 parent = atk_object_get_parent (parent);
2435 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
2439 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
2440 path = cell_info_get_path (cell_info);
2443 gtk_tree_view_row_activated (tree_view, path, cell_info->cell_col_ref);
2444 gtk_tree_path_free (path);
2448 cell_destroyed (gpointer data)
2450 GtkTreeViewAccessibleCellInfo *cell_info = data;
2452 cell_info->cell = NULL;
2454 g_hash_table_remove (cell_info->view->cell_infos, cell_info);
2458 cell_info_get_index (GtkTreeView *tree_view,
2459 GtkTreeViewAccessibleCellInfo *info)
2463 index = _gtk_rbtree_node_get_index (info->tree, info->node) + 1;
2464 index *= get_n_columns (tree_view);
2465 index += get_column_number (tree_view, info->cell_col_ref);
2471 cell_info_new (GtkTreeViewAccessible *accessible,
2472 GtkTreeModel *tree_model,
2475 GtkTreeViewColumn *tv_col,
2476 GtkCellAccessible *cell)
2478 GtkTreeViewAccessibleCellInfo *cell_info;
2480 cell_info = g_new (GtkTreeViewAccessibleCellInfo, 1);
2482 cell_info->tree = tree;
2483 cell_info->node = node;
2484 cell_info->cell_col_ref = tv_col;
2485 cell_info->cell = cell;
2486 cell_info->view = accessible;
2488 g_object_set_qdata_full (G_OBJECT (cell),
2489 gtk_tree_view_accessible_get_data_quark (),
2493 g_hash_table_replace (accessible->cell_infos, cell_info, cell_info);
2496 static GtkCellAccessible *
2497 peek_cell (GtkTreeViewAccessible *accessible,
2500 GtkTreeViewColumn *column)
2502 GtkTreeViewAccessibleCellInfo lookup, *cell_info;
2506 lookup.cell_col_ref = column;
2508 cell_info = g_hash_table_lookup (accessible->cell_infos, &lookup);
2509 if (cell_info == NULL)
2512 return cell_info->cell;
2515 static GtkCellAccessible *
2516 find_cell (GtkTreeViewAccessible *accessible,
2519 GtkTreeView *tree_view;
2523 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
2525 if (!_gtk_rbtree_find_index (_gtk_tree_view_get_rbtree (tree_view),
2526 index / get_n_columns (tree_view) - 1,
2530 g_assert_not_reached ();
2533 return peek_cell (accessible,
2535 get_visible_column (tree_view, index % get_n_columns (tree_view)));
2539 connect_model_signals (GtkTreeView *view,
2540 GtkTreeViewAccessible *accessible)
2544 obj = G_OBJECT (accessible->tree_model);
2545 g_signal_connect_data (obj, "row-changed",
2546 G_CALLBACK (model_row_changed), view, NULL, 0);
2547 g_signal_connect_data (obj, "row-inserted",
2548 G_CALLBACK (model_row_inserted), view, NULL,
2550 g_signal_connect_data (obj, "row-deleted",
2551 G_CALLBACK (model_row_deleted), view, NULL,
2556 disconnect_model_signals (GtkTreeViewAccessible *accessible)
2561 obj = G_OBJECT (accessible->tree_model);
2562 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2563 g_signal_handlers_disconnect_by_func (obj, model_row_changed, widget);
2564 g_signal_handlers_disconnect_by_func (obj, model_row_inserted, widget);
2565 g_signal_handlers_disconnect_by_func (obj, model_row_deleted, widget);
2568 /* Returns the column number of the specified GtkTreeViewColumn
2569 * The column must be visible.
2572 get_column_number (GtkTreeView *treeview,
2573 GtkTreeViewColumn *column)
2575 GtkTreeViewColumn *cur;
2580 for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++)
2582 cur = gtk_tree_view_get_column (treeview, i);
2584 if (!gtk_tree_view_column_get_visible (cur))
2593 g_return_val_if_fail (i < gtk_tree_view_get_n_columns (treeview), 0);
2599 get_index (GtkTreeView *tree_view,
2605 gint *indices = NULL;
2609 depth = gtk_tree_path_get_depth (path);
2610 indices = gtk_tree_path_get_indices (path);
2615 GtkTreePath *copy_path;
2616 GtkTreeModel *model;
2618 model = gtk_tree_view_get_model (tree_view);
2619 copy_path = gtk_tree_path_copy (path);
2620 gtk_tree_path_up (copy_path);
2621 count_rows (model, NULL, copy_path, &index, 0, depth);
2622 gtk_tree_path_free (copy_path);
2626 index += indices[depth - 1];
2627 index *= get_n_columns (tree_view);
2628 index += actual_column;
2632 /* The function count_rows counts the number of rows starting at iter
2633 * and ending at end_path. The value of level is the depth of iter and
2634 * the value of depth is the depth of end_path. Rows at depth before
2635 * end_path are counted. This functions counts rows which are not visible
2636 * because an ancestor is collapsed.
2639 count_rows (GtkTreeModel *model,
2641 GtkTreePath *end_path,
2646 GtkTreeIter child_iter;
2652 *count += gtk_tree_model_iter_n_children (model, iter);
2654 if (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY)
2660 if (gtk_tree_model_iter_children (model, &child_iter, iter))
2662 gboolean ret_val = TRUE;
2666 if (level == depth - 1)
2668 GtkTreePath *iter_path;
2669 gboolean finished = FALSE;
2671 iter_path = gtk_tree_model_get_path (model, &child_iter);
2672 if (end_path && gtk_tree_path_compare (iter_path, end_path) >= 0)
2674 gtk_tree_path_free (iter_path);
2678 if (gtk_tree_model_iter_has_child (model, &child_iter))
2679 count_rows (model, &child_iter, end_path, count, level, depth);
2680 ret_val = gtk_tree_model_iter_next (model, &child_iter);
2686 get_rbtree_column_from_index (GtkTreeView *tree_view,
2690 GtkTreeViewColumn **column)
2692 guint n_columns = get_n_columns (tree_view);
2696 /* First row is the column headers */
2703 g_return_val_if_fail (node != NULL, FALSE);
2705 if (!_gtk_rbtree_find_index (_gtk_tree_view_get_rbtree (tree_view),
2714 *column = get_visible_column (tree_view, index % n_columns);
2715 if (*column == NULL)
2722 set_cell_expandable (GtkCellAccessible *cell)
2724 if (_gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDABLE, FALSE))
2725 _gtk_cell_accessible_add_action (cell,
2726 "expand or contract",
2727 "expands or contracts the row in the tree view containing this cell",
2728 NULL, toggle_cell_expanded);
2731 static GtkTreeViewAccessibleCellInfo *
2732 find_cell_info (GtkTreeViewAccessible *accessible,
2733 GtkCellAccessible *cell)
2737 parent = atk_object_get_parent (ATK_OBJECT (cell));
2738 while (parent != ATK_OBJECT (accessible))
2740 cell = GTK_CELL_ACCESSIBLE (parent);
2741 parent = atk_object_get_parent (ATK_OBJECT (cell));
2744 return g_object_get_qdata (G_OBJECT (cell),
2745 gtk_tree_view_accessible_get_data_quark ());
2749 get_header_from_column (GtkTreeViewColumn *tv_col)
2752 GtkWidget *header_widget;
2757 header_widget = gtk_tree_view_column_get_button (tv_col);
2760 rc = gtk_widget_get_accessible (header_widget);
2768 _gtk_tree_view_accessible_remove (GtkTreeView *treeview,
2772 GtkTreeViewAccessibleCellInfo *cell_info;
2773 GHashTableIter iter;
2774 GtkTreeViewAccessible *accessible;
2776 accessible = GTK_TREE_VIEW_ACCESSIBLE (_gtk_widget_peek_accessible (GTK_WIDGET (treeview)));
2777 if (accessible == NULL)
2780 /* if this shows up in profiles, special-case node->children == NULL */
2783 tree = node->children;
2785 g_hash_table_iter_init (&iter, accessible->cell_infos);
2786 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
2788 if (node == cell_info->node ||
2789 tree == cell_info->tree ||
2790 (tree && _gtk_rbtree_contains (tree, cell_info->tree)))
2791 g_hash_table_iter_remove (&iter);
2795 /* NB: id is not checked, only columns < id are.
2796 * This is important so the function works for notification of removal of a column */
2798 to_visible_column_id (GtkTreeView *treeview,
2806 for (i = 0; i < id; i++)
2808 GtkTreeViewColumn *column = gtk_tree_view_get_column (treeview, i);
2810 if (!gtk_tree_view_column_get_visible (column))
2814 return id - invisible;
2818 _gtk_tree_view_accessible_do_add_column (GtkTreeViewAccessible *accessible,
2819 GtkTreeView *treeview,
2820 GtkTreeViewColumn *column,
2823 guint row, n_rows, n_cols;
2825 /* Generate column-inserted signal */
2826 g_signal_emit_by_name (accessible, "column-inserted", id, 1);
2828 n_rows = get_n_rows (treeview);
2829 n_cols = get_n_columns (treeview);
2831 /* Generate children-changed signals */
2832 for (row = 0; row <= n_rows; row++)
2834 /* Pass NULL as the child object, i.e. 4th argument */
2835 g_signal_emit_by_name (accessible, "children-changed::add",
2836 (row * n_cols) + id, NULL, NULL);
2841 _gtk_tree_view_accessible_add_column (GtkTreeView *treeview,
2842 GtkTreeViewColumn *column,
2847 if (!gtk_tree_view_column_get_visible (column))
2850 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
2854 _gtk_tree_view_accessible_do_add_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
2857 to_visible_column_id (treeview, id));
2861 _gtk_tree_view_accessible_do_remove_column (GtkTreeViewAccessible *accessible,
2862 GtkTreeView *treeview,
2863 GtkTreeViewColumn *column,
2866 GtkTreeViewAccessibleCellInfo *cell_info;
2867 GHashTableIter iter;
2869 guint row, n_rows, n_cols;
2871 /* Clean column from cache */
2872 g_hash_table_iter_init (&iter, accessible->cell_infos);
2873 while (g_hash_table_iter_next (&iter, NULL, &value))
2876 if (cell_info->cell_col_ref == column)
2877 g_hash_table_iter_remove (&iter);
2880 /* Generate column-deleted signal */
2881 g_signal_emit_by_name (accessible, "column-deleted", id, 1);
2883 n_rows = get_n_rows (treeview);
2884 n_cols = get_n_columns (treeview);
2886 /* Generate children-changed signals */
2887 for (row = 0; row <= n_rows; row++)
2889 /* Pass NULL as the child object, 4th argument */
2890 g_signal_emit_by_name (accessible, "children-changed::remove",
2891 (row * n_cols) + id, NULL, NULL);
2896 _gtk_tree_view_accessible_remove_column (GtkTreeView *treeview,
2897 GtkTreeViewColumn *column,
2902 if (!gtk_tree_view_column_get_visible (column))
2905 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
2909 _gtk_tree_view_accessible_do_remove_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
2912 to_visible_column_id (treeview, id));
2916 _gtk_tree_view_accessible_reorder_column (GtkTreeView *treeview,
2917 GtkTreeViewColumn *column)
2921 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
2925 g_signal_emit_by_name (obj, "column-reordered");
2929 _gtk_tree_view_accessible_toggle_visibility (GtkTreeView *treeview,
2930 GtkTreeViewColumn *column)
2935 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
2939 id = get_column_number (treeview, column);
2941 if (gtk_tree_view_column_get_visible (column))
2942 _gtk_tree_view_accessible_do_add_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
2947 _gtk_tree_view_accessible_do_remove_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
2954 _gtk_tree_view_accessible_add_state (GtkTreeView *treeview,
2957 GtkCellRendererState state)
2959 GtkTreeViewAccessible *accessible;
2963 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
2967 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
2969 for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++)
2971 GtkCellAccessible *cell = peek_cell (accessible,
2973 gtk_tree_view_get_column (treeview, i));
2978 _gtk_cell_accessible_state_changed (cell, state, 0);
2983 _gtk_tree_view_accessible_remove_state (GtkTreeView *treeview,
2986 GtkCellRendererState state)
2988 GtkTreeViewAccessible *accessible;
2992 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
2996 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
2998 for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++)
3000 GtkCellAccessible *cell = peek_cell (accessible,
3002 gtk_tree_view_get_column (treeview, i));
3007 _gtk_cell_accessible_state_changed (cell, 0, state);
3012 _gtk_tree_view_accessible_expanded (GtkTreeView *treeview,
3018 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
3022 _gtk_tree_view_accessible_add_state (treeview,
3024 GTK_CELL_RENDERER_EXPANDED);
3026 g_signal_emit_by_name (obj,
3028 _gtk_rbtree_node_get_index (tree, node),
3029 node->children->root->total_count);