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_expanded_cb (GtkTreeView *tree_view,
53 static gboolean row_collapsed_cb (GtkTreeView *tree_view,
56 static void selection_changed_cb (GtkTreeSelection *selection,
59 static void cursor_changed (GtkTreeView *tree_view,
60 GtkTreeViewAccessible *accessible);
61 static gboolean focus_in (GtkWidget *widget);
62 static gboolean focus_out (GtkWidget *widget);
64 static void destroy_count_func (GtkTreeView *tree_view,
71 static void set_iter_nth_row (GtkTreeView *tree_view,
74 static gint get_row_from_tree_path (GtkTreeView *tree_view,
76 static void iterate_thru_children (GtkTreeView *tree_view,
77 GtkTreeModel *tree_model,
78 GtkTreePath *tree_path,
82 static int cell_info_get_index (GtkTreeView *tree_view,
83 GtkTreeViewAccessibleCellInfo *info);
84 static gboolean update_cell_value (GtkRendererCellAccessible *renderer_cell,
85 GtkTreeViewAccessible *accessible,
86 gboolean emit_change_signal);
87 static gboolean is_cell_showing (GtkTreeView *tree_view,
88 GdkRectangle *cell_rect);
89 static void set_expand_state (GtkTreeView *tree_view,
90 GtkTreeModel *tree_model,
91 GtkTreeViewAccessible *accessible,
92 GtkTreePath *tree_path,
93 gboolean set_on_ancestor);
94 static void set_cell_expandable (GtkCellAccessible *cell);
95 static void add_cell_actions (GtkCellAccessible *cell,
98 static void toggle_cell_toggled (GtkCellAccessible *cell);
99 static void edit_cell (GtkCellAccessible *cell);
100 static void activate_cell (GtkCellAccessible *cell);
101 static void cell_destroyed (gpointer data);
102 static void cell_info_new (GtkTreeViewAccessible *accessible,
103 GtkTreeModel *tree_model,
106 GtkTreeViewColumn *tv_col,
107 GtkCellAccessible *cell);
108 static GtkCellAccessible *find_cell (GtkTreeViewAccessible *accessible,
110 static void connect_model_signals (GtkTreeView *view,
111 GtkTreeViewAccessible *accessible);
112 static void disconnect_model_signals (GtkTreeViewAccessible *accessible);
113 static gint get_column_number (GtkTreeView *tree_view,
114 GtkTreeViewColumn *column);
115 static gint get_focus_index (GtkTreeView *tree_view);
116 static gint get_index (GtkTreeView *tree_view,
119 static void count_rows (GtkTreeModel *model,
121 GtkTreePath *end_path,
126 static gboolean get_rbtree_column_from_index (GtkTreeView *tree_view,
130 GtkTreeViewColumn **column);
132 static GtkTreeViewAccessibleCellInfo* find_cell_info (GtkTreeViewAccessible *view,
133 GtkCellAccessible *cell);
134 static AtkObject * get_header_from_column (GtkTreeViewColumn *tv_col);
137 static void atk_table_interface_init (AtkTableIface *iface);
138 static void atk_selection_interface_init (AtkSelectionIface *iface);
139 static void atk_component_interface_init (AtkComponentIface *iface);
140 static void gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface);
142 G_DEFINE_TYPE_WITH_CODE (GtkTreeViewAccessible, _gtk_tree_view_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
143 G_IMPLEMENT_INTERFACE (ATK_TYPE_TABLE, atk_table_interface_init)
144 G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init)
145 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init)
146 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_ACCESSIBLE_PARENT, gtk_cell_accessible_parent_interface_init))
150 gtk_tree_view_accessible_get_data_quark (void)
152 static GQuark quark = 0;
154 if (G_UNLIKELY (quark == 0))
155 quark = g_quark_from_static_string ("gtk-tree-view-accessible-data");
161 cell_info_free (GtkTreeViewAccessibleCellInfo *cell_info)
165 g_object_steal_qdata (G_OBJECT (cell_info->cell),
166 gtk_tree_view_accessible_get_data_quark ());
167 _gtk_cell_accessible_add_state (cell_info->cell, ATK_STATE_DEFUNCT, FALSE);
174 cell_info_get_path (GtkTreeViewAccessibleCellInfo *cell_info)
176 return _gtk_tree_path_new_from_rbtree (cell_info->tree, cell_info->node);
180 cell_info_hash (gconstpointer info)
182 const GtkTreeViewAccessibleCellInfo *cell_info = info;
185 node = GPOINTER_TO_UINT (cell_info->node);
186 col = GPOINTER_TO_UINT (cell_info->cell_col_ref);
188 return ((node << sizeof (guint) / 2) | (node >> sizeof (guint) / 2)) ^ col;
192 cell_info_equal (gconstpointer a, gconstpointer b)
194 const GtkTreeViewAccessibleCellInfo *cell_info_a = a;
195 const GtkTreeViewAccessibleCellInfo *cell_info_b = b;
197 return cell_info_a->node == cell_info_b->node &&
198 cell_info_a->cell_col_ref == cell_info_b->cell_col_ref;
202 gtk_tree_view_accessible_initialize (AtkObject *obj,
205 GtkTreeViewAccessible *accessible;
206 GtkTreeView *tree_view;
207 GtkTreeModel *tree_model;
209 GtkTreeSelection *selection;
211 ATK_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->initialize (obj, data);
213 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
214 accessible->focus_cell = NULL;
215 accessible->idle_expand_id = 0;
216 accessible->idle_expand_path = NULL;
217 accessible->n_children_deleted = 0;
219 accessible->cell_infos = g_hash_table_new_full (cell_info_hash,
220 cell_info_equal, NULL, (GDestroyNotify) cell_info_free);
222 widget = GTK_WIDGET (data);
223 tree_view = GTK_TREE_VIEW (widget);
224 tree_model = gtk_tree_view_get_model (tree_view);
225 selection = gtk_tree_view_get_selection (tree_view);
227 g_signal_connect_after (widget, "row-collapsed",
228 G_CALLBACK (row_collapsed_cb), NULL);
229 g_signal_connect (widget, "row-expanded",
230 G_CALLBACK (row_expanded_cb), NULL);
231 g_signal_connect (selection, "changed",
232 G_CALLBACK (selection_changed_cb), obj);
234 g_signal_connect (tree_view, "cursor-changed",
235 G_CALLBACK (cursor_changed), accessible);
236 g_signal_connect (tree_view, "focus-in-event",
237 G_CALLBACK (focus_in), NULL);
238 g_signal_connect (tree_view, "focus-out-event",
239 G_CALLBACK (focus_out), NULL);
241 accessible->tree_model = tree_model;
244 g_object_add_weak_pointer (G_OBJECT (accessible->tree_model), (gpointer *)&accessible->tree_model);
245 connect_model_signals (tree_view, accessible);
247 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
248 obj->role = ATK_ROLE_TABLE;
250 obj->role = ATK_ROLE_TREE_TABLE;
253 gtk_tree_view_set_destroy_count_func (tree_view,
259 gtk_tree_view_accessible_finalize (GObject *object)
261 GtkTreeViewAccessible *accessible = GTK_TREE_VIEW_ACCESSIBLE (object);
263 /* remove any idle handlers still pending */
264 if (accessible->idle_expand_id)
265 g_source_remove (accessible->idle_expand_id);
267 if (accessible->tree_model)
268 disconnect_model_signals (accessible);
270 if (accessible->cell_infos)
271 g_hash_table_destroy (accessible->cell_infos);
273 G_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->finalize (object);
277 gtk_tree_view_accessible_notify_gtk (GObject *obj,
281 GtkTreeView *tree_view;
282 GtkTreeViewAccessible *accessible;
284 widget = GTK_WIDGET (obj);
285 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
286 tree_view = GTK_TREE_VIEW (widget);
288 if (g_strcmp0 (pspec->name, "model") == 0)
290 GtkTreeModel *tree_model;
293 tree_model = gtk_tree_view_get_model (tree_view);
294 if (accessible->tree_model)
295 disconnect_model_signals (accessible);
296 g_hash_table_remove_all (accessible->cell_infos);
297 accessible->tree_model = tree_model;
301 g_object_add_weak_pointer (G_OBJECT (accessible->tree_model), (gpointer *)&accessible->tree_model);
302 connect_model_signals (tree_view, accessible);
304 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
305 role = ATK_ROLE_TABLE;
307 role = ATK_ROLE_TREE_TABLE;
311 role = ATK_ROLE_UNKNOWN;
313 atk_object_set_role (ATK_OBJECT (accessible), role);
314 g_object_freeze_notify (G_OBJECT (accessible));
315 g_signal_emit_by_name (accessible, "model-changed");
316 g_signal_emit_by_name (accessible, "visible-data-changed");
317 g_object_thaw_notify (G_OBJECT (accessible));
320 GTK_WIDGET_ACCESSIBLE_CLASS (_gtk_tree_view_accessible_parent_class)->notify_gtk (obj, pspec);
324 gtk_tree_view_accessible_destroyed (GtkWidget *widget,
325 GtkAccessible *gtk_accessible)
327 GtkTreeViewAccessible *accessible;
329 if (!GTK_IS_TREE_VIEW (widget))
332 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_accessible);
334 if (accessible->tree_model)
336 disconnect_model_signals (accessible);
337 accessible->tree_model = NULL;
339 if (accessible->focus_cell)
341 g_object_unref (accessible->focus_cell);
342 accessible->focus_cell = NULL;
344 if (accessible->idle_expand_id)
346 g_source_remove (accessible->idle_expand_id);
347 accessible->idle_expand_id = 0;
352 gtk_tree_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
356 widget = gtk_accessible_get_widget (accessible);
358 g_signal_connect_after (widget, "destroy",
359 G_CALLBACK (gtk_tree_view_accessible_destroyed), accessible);
361 GTK_ACCESSIBLE_CLASS (_gtk_tree_view_accessible_parent_class)->connect_widget_destroyed (accessible);
365 get_n_rows (GtkTreeView *tree_view)
369 tree = _gtk_tree_view_get_rbtree (tree_view);
374 return tree->root->total_count;
378 get_n_columns (GtkTreeView *tree_view)
380 guint i, visible_columns;
384 for (i = 0; i < gtk_tree_view_get_n_columns (tree_view); i++)
386 GtkTreeViewColumn *column = gtk_tree_view_get_column (tree_view, i);
388 if (gtk_tree_view_column_get_visible (column))
392 return visible_columns;
395 gtk_tree_view_accessible_get_n_children (AtkObject *obj)
398 GtkTreeView *tree_view;
400 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
404 tree_view = GTK_TREE_VIEW (widget);
405 return (get_n_rows (tree_view) + 1) * get_n_columns (tree_view);
408 static GtkTreeViewColumn *
409 get_visible_column (GtkTreeView *tree_view,
414 for (i = 0; i < gtk_tree_view_get_n_columns (tree_view); i++)
416 GtkTreeViewColumn *column = gtk_tree_view_get_column (tree_view, i);
418 if (!gtk_tree_view_column_get_visible (column))
427 g_return_val_if_reached (NULL);
431 gtk_tree_view_accessible_ref_child (AtkObject *obj,
435 GtkTreeViewAccessible *accessible;
436 GtkCellAccessible *cell;
437 GtkTreeView *tree_view;
438 GtkTreeModel *tree_model;
439 GtkCellRenderer *renderer;
441 GtkTreeViewColumn *tv_col;
442 GtkTreeSelection *selection;
448 GtkTreeViewColumn *expander_tv;
449 GList *renderer_list;
451 GtkContainerCellAccessible *container = NULL;
452 GtkRendererCellAccessible *renderer_cell;
453 gboolean is_expander, is_expanded, retval;
454 gboolean editable = FALSE;
457 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
461 if (i >= gtk_tree_view_accessible_get_n_children (obj))
464 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
465 tree_view = GTK_TREE_VIEW (widget);
466 if (i < get_n_columns (tree_view))
468 tv_col = get_visible_column (tree_view, i);
469 child = get_header_from_column (tv_col);
471 g_object_ref (child);
475 /* Check whether the child is cached */
476 cell = find_cell (accessible, i);
480 return ATK_OBJECT (cell);
483 if (accessible->focus_cell == NULL)
484 focus_index = get_focus_index (tree_view);
488 /* Find the RBTree and GtkTreeViewColumn for the index */
489 if (!get_rbtree_column_from_index (tree_view, i, &tree, &node, &tv_col))
492 path = _gtk_tree_path_new_from_rbtree (tree, node);
493 tree_model = gtk_tree_view_get_model (tree_view);
494 retval = gtk_tree_model_get_iter (tree_model, &iter, path);
498 expander_tv = gtk_tree_view_get_expander_column (tree_view);
501 if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_PARENT))
503 if (expander_tv == tv_col)
506 is_expanded = node->children != NULL;
509 gtk_tree_view_column_cell_set_cell_data (tv_col, tree_model, &iter,
510 is_expander, is_expanded);
512 renderer_list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
514 /* If there is not exactly one renderer in the list,
517 if (renderer_list == NULL || renderer_list->next)
519 GtkCellAccessible *container_cell;
521 container = _gtk_container_cell_accessible_new ();
523 container_cell = GTK_CELL_ACCESSIBLE (container);
524 _gtk_cell_accessible_initialise (container_cell, widget, ATK_OBJECT (accessible));
526 /* The GtkTreeViewAccessibleCellInfo structure for the container will
527 * be before the ones for the cells so that the first one we find for
528 * a position will be for the container
530 cell_info_new (accessible, tree_model, tree, node, tv_col, container_cell);
531 parent = ATK_OBJECT (container);
534 parent = ATK_OBJECT (accessible);
538 for (l = renderer_list; l; l = l->next)
540 renderer = GTK_CELL_RENDERER (l->data);
542 if (GTK_IS_CELL_RENDERER_TEXT (renderer))
544 g_object_get (G_OBJECT (renderer), "editable", &editable, NULL);
545 child = _gtk_text_cell_accessible_new ();
547 else if (GTK_IS_CELL_RENDERER_TOGGLE (renderer))
548 child = _gtk_boolean_cell_accessible_new ();
549 else if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
550 child = _gtk_image_cell_accessible_new ();
552 child = _gtk_renderer_cell_accessible_new ();
554 cell = GTK_CELL_ACCESSIBLE (child);
555 renderer_cell = GTK_RENDERER_CELL_ACCESSIBLE (child);
557 /* Create the GtkTreeViewAccessibleCellInfo for this cell */
558 if (parent == ATK_OBJECT (accessible))
559 cell_info_new (accessible, tree_model, tree, node, tv_col, cell);
561 _gtk_cell_accessible_initialise (cell, widget, parent);
564 _gtk_container_cell_accessible_add_child (container, cell);
566 update_cell_value (renderer_cell, accessible, FALSE);
568 /* Add the actions appropriate for this cell */
569 add_cell_actions (cell, editable);
571 /* Set state if it is expandable */
574 set_cell_expandable (cell);
576 _gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, FALSE);
579 /* If the row is selected, all cells on the row are selected */
580 selection = gtk_tree_view_get_selection (tree_view);
582 if (gtk_tree_selection_path_is_selected (selection, path))
583 _gtk_cell_accessible_add_state (cell, ATK_STATE_SELECTED, FALSE);
585 _gtk_cell_accessible_add_state (cell, ATK_STATE_FOCUSABLE, FALSE);
586 if (focus_index == i)
588 accessible->focus_cell = g_object_ref (cell);
589 _gtk_cell_accessible_add_state (cell, ATK_STATE_FOCUSED, FALSE);
590 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
593 g_list_free (renderer_list);
595 child = ATK_OBJECT (container);
597 if (expander_tv == tv_col)
599 AtkRelationSet *relation_set;
600 AtkObject *accessible_array[1];
601 AtkRelation* relation;
602 AtkObject *parent_node;
604 relation_set = atk_object_ref_relation_set (ATK_OBJECT (child));
606 gtk_tree_path_up (path);
607 if (gtk_tree_path_get_depth (path) == 0)
613 parent_index = get_index (tree_view, path, i % get_n_columns (tree_view));
614 parent_node = atk_object_ref_accessible_child (obj, parent_index);
616 accessible_array[0] = parent_node;
617 relation = atk_relation_new (accessible_array, 1,
618 ATK_RELATION_NODE_CHILD_OF);
619 atk_relation_set_add (relation_set, relation);
620 atk_object_add_relationship (parent_node, ATK_RELATION_NODE_PARENT_OF, child);
621 g_object_unref (relation);
622 g_object_unref (relation_set);
624 gtk_tree_path_free (path);
626 /* We do not increase the reference count here; when g_object_unref()
627 * is called for the cell then cell_destroyed() is called and this
628 * removes the cell from the cache.
634 gtk_tree_view_accessible_ref_state_set (AtkObject *obj)
636 AtkStateSet *state_set;
639 state_set = ATK_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->ref_state_set (obj);
640 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
643 atk_state_set_add_state (state_set, ATK_STATE_MANAGES_DESCENDANTS);
649 _gtk_tree_view_accessible_class_init (GtkTreeViewAccessibleClass *klass)
651 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
652 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
653 GtkAccessibleClass *accessible_class = (GtkAccessibleClass*)klass;
654 GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
655 GtkContainerAccessibleClass *container_class = (GtkContainerAccessibleClass*)klass;
657 class->get_n_children = gtk_tree_view_accessible_get_n_children;
658 class->ref_child = gtk_tree_view_accessible_ref_child;
659 class->ref_state_set = gtk_tree_view_accessible_ref_state_set;
660 class->initialize = gtk_tree_view_accessible_initialize;
662 widget_class->notify_gtk = gtk_tree_view_accessible_notify_gtk;
664 accessible_class->connect_widget_destroyed = gtk_tree_view_accessible_connect_widget_destroyed;
666 /* The children of a GtkTreeView are the buttons at the top of the columns
667 * we do not represent these as children so we do not want to report
668 * children added or deleted when these changed.
670 container_class->add_gtk = NULL;
671 container_class->remove_gtk = NULL;
673 gobject_class->finalize = gtk_tree_view_accessible_finalize;
677 _gtk_tree_view_accessible_init (GtkTreeViewAccessible *view)
682 get_focus_index (GtkTreeView *tree_view)
684 GtkTreePath *focus_path;
685 GtkTreeViewColumn *focus_column;
688 gtk_tree_view_get_cursor (tree_view, &focus_path, &focus_column);
689 if (focus_path && focus_column)
690 index = get_index (tree_view, focus_path,
691 get_column_number (tree_view, focus_column));
696 gtk_tree_path_free (focus_path);
701 /* This function returns a reference to the accessible object
702 * for the cell in the treeview which has focus, if any
705 gtk_tree_view_accessible_ref_focus_cell (GtkTreeView *tree_view)
707 AtkObject *focus_cell = NULL;
711 focus_index = get_focus_index (tree_view);
712 if (focus_index >= 0)
714 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
715 focus_cell = atk_object_ref_accessible_child (atk_obj, focus_index);
724 gtk_tree_view_accessible_ref_accessible_at_point (AtkComponent *component,
727 AtkCoordType coord_type)
730 GtkTreeView *tree_view;
732 GtkTreeViewColumn *tv_column;
737 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
741 tree_view = GTK_TREE_VIEW (widget);
743 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
744 gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, x, y, &bx, &by);
745 ret_val = gtk_tree_view_get_path_at_pos (tree_view,
746 bx - x_pos, by - y_pos,
747 &path, &tv_column, NULL, NULL);
752 column = get_column_number (tree_view, tv_column);
753 index = get_index (tree_view, path, column);
754 gtk_tree_path_free (path);
756 return gtk_tree_view_accessible_ref_child (ATK_OBJECT (component), index);
763 atk_component_interface_init (AtkComponentIface *iface)
765 iface->ref_accessible_at_point = gtk_tree_view_accessible_ref_accessible_at_point;
771 gtk_tree_view_accessible_get_index_at (AtkTable *table,
778 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
782 n_cols = atk_table_get_n_columns (table);
783 n_rows = atk_table_get_n_rows (table);
785 if (row >= n_rows || column >= n_cols)
788 return (row + 1) * n_cols + column;
792 gtk_tree_view_accessible_get_column_at_index (AtkTable *table,
798 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
802 if (index >= gtk_tree_view_accessible_get_n_children (ATK_OBJECT (table)))
805 n_columns = get_n_columns (GTK_TREE_VIEW (widget));
807 /* checked by the n_children() check above */
808 g_assert (n_columns > 0);
810 return index % n_columns;
814 gtk_tree_view_accessible_get_row_at_index (AtkTable *table,
818 GtkTreeView *tree_view;
820 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
824 tree_view = GTK_TREE_VIEW (widget);
826 index /= get_n_columns (tree_view);
828 if (index >= get_n_rows (tree_view))
835 gtk_tree_view_accessible_table_ref_at (AtkTable *table,
841 index = gtk_tree_view_accessible_get_index_at (table, row, column);
845 return gtk_tree_view_accessible_ref_child (ATK_OBJECT (table), index);
849 gtk_tree_view_accessible_get_n_rows (AtkTable *table)
853 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
857 return get_n_rows (GTK_TREE_VIEW (widget));
861 gtk_tree_view_accessible_get_n_columns (AtkTable *table)
865 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
869 return get_n_columns (GTK_TREE_VIEW (widget));
873 gtk_tree_view_accessible_is_row_selected (AtkTable *table,
877 GtkTreeView *tree_view;
878 GtkTreeSelection *selection;
881 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
888 tree_view = GTK_TREE_VIEW (widget);
889 selection = gtk_tree_view_get_selection (tree_view);
891 set_iter_nth_row (tree_view, &iter, row);
892 return gtk_tree_selection_iter_is_selected (selection, &iter);
896 gtk_tree_view_accessible_is_selected (AtkTable *table,
900 return gtk_tree_view_accessible_is_row_selected (table, row);
904 get_selected_rows (GtkTreeModel *model,
909 GPtrArray *array = (GPtrArray *)data;
911 g_ptr_array_add (array, gtk_tree_path_copy (path));
915 gtk_tree_view_accessible_get_selected_rows (AtkTable *table,
916 gint **rows_selected)
919 GtkTreeView *tree_view;
920 GtkTreeModel *tree_model;
922 GtkTreeSelection *selection;
923 GtkTreePath *tree_path;
926 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
930 tree_view = GTK_TREE_VIEW (widget);
931 selection = gtk_tree_view_get_selection (tree_view);
933 switch (gtk_tree_selection_get_mode (selection))
935 case GTK_SELECTION_SINGLE:
936 case GTK_SELECTION_BROWSE:
937 if (gtk_tree_selection_get_selected (selection, &tree_model, &iter))
943 *rows_selected = g_new (gint, 1);
944 tree_path = gtk_tree_model_get_path (tree_model, &iter);
945 row = get_row_from_tree_path (tree_view, tree_path);
946 gtk_tree_path_free (tree_path);
948 /* shouldn't ever happen */
949 g_return_val_if_fail (row != -1, 0);
951 *rows_selected[0] = row;
956 case GTK_SELECTION_MULTIPLE:
958 GPtrArray *array = g_ptr_array_new();
960 gtk_tree_selection_selected_foreach (selection, get_selected_rows, array);
961 ret_val = array->len;
963 if (rows_selected && ret_val)
967 *rows_selected = g_new (gint, ret_val);
968 for (i = 0; i < ret_val; i++)
972 tree_path = (GtkTreePath *) g_ptr_array_index (array, i);
973 row = get_row_from_tree_path (tree_view, tree_path);
974 gtk_tree_path_free (tree_path);
975 (*rows_selected)[i] = row;
978 g_ptr_array_free (array, FALSE);
981 case GTK_SELECTION_NONE:
988 gtk_tree_view_accessible_add_row_selection (AtkTable *table,
992 GtkTreeView *tree_view;
993 GtkTreeModel *tree_model;
994 GtkTreeSelection *selection;
995 GtkTreePath *tree_path;
996 GtkTreeIter iter_to_row;
998 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1002 if (!gtk_tree_view_accessible_is_row_selected (table, row))
1004 tree_view = GTK_TREE_VIEW (widget);
1005 tree_model = gtk_tree_view_get_model (tree_view);
1006 selection = gtk_tree_view_get_selection (tree_view);
1008 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
1010 tree_path = gtk_tree_path_new ();
1011 gtk_tree_path_append_index (tree_path, row);
1012 gtk_tree_selection_select_path (selection,tree_path);
1013 gtk_tree_path_free (tree_path);
1017 set_iter_nth_row (tree_view, &iter_to_row, row);
1018 gtk_tree_selection_select_iter (selection, &iter_to_row);
1022 return gtk_tree_view_accessible_is_row_selected (table, row);
1026 gtk_tree_view_accessible_remove_row_selection (AtkTable *table,
1030 GtkTreeView *tree_view;
1031 GtkTreeSelection *selection;
1033 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1037 tree_view = GTK_TREE_VIEW (widget);
1038 selection = gtk_tree_view_get_selection (tree_view);
1040 if (gtk_tree_view_accessible_is_row_selected (table, row))
1042 gtk_tree_selection_unselect_all (selection);
1050 gtk_tree_view_accessible_get_column_header (AtkTable *table,
1054 GtkTreeView *tree_view;
1055 GtkTreeViewColumn *tv_col;
1057 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1061 tree_view = GTK_TREE_VIEW (widget);
1062 if (in_col < 0 || in_col >= get_n_columns (tree_view))
1065 tv_col = get_visible_column (tree_view, in_col);
1066 return get_header_from_column (tv_col);
1069 static const gchar *
1070 gtk_tree_view_accessible_get_column_description (AtkTable *table,
1074 GtkTreeView *tree_view;
1075 GtkTreeViewColumn *tv_col;
1077 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1081 tree_view = GTK_TREE_VIEW (widget);
1082 if (in_col < 0 || in_col >= get_n_columns (tree_view))
1085 tv_col = get_visible_column (tree_view, in_col);
1086 return gtk_tree_view_column_get_title (tv_col);
1090 atk_table_interface_init (AtkTableIface *iface)
1092 iface->ref_at = gtk_tree_view_accessible_table_ref_at;
1093 iface->get_n_rows = gtk_tree_view_accessible_get_n_rows;
1094 iface->get_n_columns = gtk_tree_view_accessible_get_n_columns;
1095 iface->get_index_at = gtk_tree_view_accessible_get_index_at;
1096 iface->get_column_at_index = gtk_tree_view_accessible_get_column_at_index;
1097 iface->get_row_at_index = gtk_tree_view_accessible_get_row_at_index;
1098 iface->is_row_selected = gtk_tree_view_accessible_is_row_selected;
1099 iface->is_selected = gtk_tree_view_accessible_is_selected;
1100 iface->get_selected_rows = gtk_tree_view_accessible_get_selected_rows;
1101 iface->add_row_selection = gtk_tree_view_accessible_add_row_selection;
1102 iface->remove_row_selection = gtk_tree_view_accessible_remove_row_selection;
1103 iface->get_column_extent_at = NULL;
1104 iface->get_row_extent_at = NULL;
1105 iface->get_column_header = gtk_tree_view_accessible_get_column_header;
1106 iface->get_column_description = gtk_tree_view_accessible_get_column_description;
1109 /* atkselection.h */
1112 gtk_tree_view_accessible_add_selection (AtkSelection *selection,
1119 table = ATK_TABLE (selection);
1120 n_columns = gtk_tree_view_accessible_get_n_columns (table);
1124 row = gtk_tree_view_accessible_get_row_at_index (table, i);
1125 return gtk_tree_view_accessible_add_row_selection (table, row);
1129 gtk_tree_view_accessible_clear_selection (AtkSelection *selection)
1132 GtkTreeView *tree_view;
1133 GtkTreeSelection *tree_selection;
1135 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
1139 tree_view = GTK_TREE_VIEW (widget);
1140 tree_selection = gtk_tree_view_get_selection (tree_view);
1142 gtk_tree_selection_unselect_all (tree_selection);
1147 gtk_tree_view_accessible_ref_selection (AtkSelection *selection,
1156 table = ATK_TABLE (selection);
1157 n_columns = gtk_tree_view_accessible_get_n_columns (table);
1158 n_selected = gtk_tree_view_accessible_get_selected_rows (table, &selected);
1159 if (i >= n_columns * n_selected)
1162 row = selected[i / n_columns];
1165 return gtk_tree_view_accessible_table_ref_at (table, row, i % n_columns);
1169 gtk_tree_view_accessible_get_selection_count (AtkSelection *selection)
1174 table = ATK_TABLE (selection);
1175 n_selected = gtk_tree_view_accessible_get_selected_rows (table, NULL);
1177 n_selected *= gtk_tree_view_accessible_get_n_columns (table);
1182 gtk_tree_view_accessible_is_child_selected (AtkSelection *selection,
1188 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
1192 row = atk_table_get_row_at_index (ATK_TABLE (selection), i);
1194 return gtk_tree_view_accessible_is_row_selected (ATK_TABLE (selection), row);
1197 static void atk_selection_interface_init (AtkSelectionIface *iface)
1199 iface->add_selection = gtk_tree_view_accessible_add_selection;
1200 iface->clear_selection = gtk_tree_view_accessible_clear_selection;
1201 iface->ref_selection = gtk_tree_view_accessible_ref_selection;
1202 iface->get_selection_count = gtk_tree_view_accessible_get_selection_count;
1203 iface->is_child_selected = gtk_tree_view_accessible_is_child_selected;
1206 #define EXTRA_EXPANDER_PADDING 4
1209 gtk_tree_view_accessible_get_cell_area (GtkCellAccessibleParent *parent,
1210 GtkCellAccessible *cell,
1211 GdkRectangle *cell_rect)
1214 GtkTreeView *tree_view;
1215 GtkTreeViewColumn *tv_col;
1217 AtkObject *parent_cell;
1218 GtkTreeViewAccessibleCellInfo *cell_info;
1219 GtkCellAccessible *top_cell;
1221 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1225 tree_view = GTK_TREE_VIEW (widget);
1226 parent_cell = atk_object_get_parent (ATK_OBJECT (cell));
1227 if (parent_cell != ATK_OBJECT (parent))
1228 top_cell = GTK_CELL_ACCESSIBLE (parent_cell);
1231 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), top_cell);
1234 path = cell_info_get_path (cell_info);
1235 tv_col = cell_info->cell_col_ref;
1238 GtkTreeViewColumn *expander_column;
1239 gint focus_line_width;
1241 gtk_tree_view_get_cell_area (tree_view, path, tv_col, cell_rect);
1242 expander_column = gtk_tree_view_get_expander_column (tree_view);
1243 if (expander_column == tv_col)
1246 gtk_widget_style_get (widget,
1247 "expander-size", &expander_size,
1249 cell_rect->x += expander_size + EXTRA_EXPANDER_PADDING;
1250 cell_rect->width -= expander_size + EXTRA_EXPANDER_PADDING;
1252 gtk_widget_style_get (widget,
1253 "focus-line-width", &focus_line_width,
1256 cell_rect->x += focus_line_width;
1257 cell_rect->width -= 2 * focus_line_width;
1259 gtk_tree_path_free (path);
1261 /* A column has more than one renderer so we find the position
1264 if (top_cell != cell)
1271 GtkCellRenderer *renderer;
1273 cell_index = atk_object_get_index_in_parent (ATK_OBJECT (cell));
1274 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
1275 renderer = g_list_nth_data (renderers, cell_index);
1277 found = gtk_tree_view_column_cell_get_position (tv_col, renderer, &cell_start, &cell_width);
1280 cell_rect->x += cell_start;
1281 cell_rect->width = cell_width;
1283 g_list_free (renderers);
1290 gtk_tree_view_accessible_get_cell_extents (GtkCellAccessibleParent *parent,
1291 GtkCellAccessible *cell,
1296 AtkCoordType coord_type)
1299 GtkTreeView *tree_view;
1300 GdkWindow *bin_window;
1301 GdkRectangle cell_rect;
1304 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1308 tree_view = GTK_TREE_VIEW (widget);
1309 gtk_tree_view_accessible_get_cell_area (parent, cell, &cell_rect);
1310 bin_window = gtk_tree_view_get_bin_window (tree_view);
1311 gdk_window_get_origin (bin_window, &w_x, &w_y);
1313 if (coord_type == ATK_XY_WINDOW)
1316 gint x_toplevel, y_toplevel;
1318 window = gdk_window_get_toplevel (bin_window);
1319 gdk_window_get_origin (window, &x_toplevel, &y_toplevel);
1325 *width = cell_rect.width;
1326 *height = cell_rect.height;
1327 if (is_cell_showing (tree_view, &cell_rect))
1329 *x = cell_rect.x + w_x;
1330 *y = cell_rect.y + w_y;
1340 gtk_tree_view_accessible_grab_cell_focus (GtkCellAccessibleParent *parent,
1341 GtkCellAccessible *cell)
1344 GtkTreeView *tree_view;
1345 GtkTreeViewColumn *tv_col;
1347 AtkObject *parent_cell;
1348 AtkObject *cell_object;
1349 GtkTreeViewAccessibleCellInfo *cell_info;
1350 GtkCellRenderer *renderer = NULL;
1351 GtkWidget *toplevel;
1354 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1358 tree_view = GTK_TREE_VIEW (widget);
1360 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
1363 cell_object = ATK_OBJECT (cell);
1364 parent_cell = atk_object_get_parent (cell_object);
1365 tv_col = cell_info->cell_col_ref;
1366 if (parent_cell != ATK_OBJECT (parent))
1368 /* GtkCellAccessible is in a GtkContainerCellAccessible.
1369 * The GtkTreeViewColumn has multiple renderers;
1370 * find the corresponding one.
1374 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
1375 index = atk_object_get_index_in_parent (cell_object);
1376 renderer = g_list_nth_data (renderers, index);
1377 g_list_free (renderers);
1379 path = cell_info_get_path (cell_info);
1383 gtk_tree_view_set_cursor_on_cell (tree_view, path, tv_col, renderer, FALSE);
1385 gtk_tree_view_set_cursor (tree_view, path, tv_col, FALSE);
1387 gtk_tree_path_free (path);
1388 gtk_widget_grab_focus (widget);
1389 toplevel = gtk_widget_get_toplevel (widget);
1390 if (gtk_widget_is_toplevel (toplevel))
1392 #ifdef GDK_WINDOWING_X11
1393 gtk_window_present_with_time (GTK_WINDOW (toplevel),
1394 gdk_x11_get_server_time (gtk_widget_get_window (widget)));
1396 gtk_window_present (GTK_WINDOW (toplevel));
1407 gtk_tree_view_accessible_get_child_index (GtkCellAccessibleParent *parent,
1408 GtkCellAccessible *cell)
1410 GtkTreeViewAccessibleCellInfo *cell_info;
1411 GtkTreeView *tree_view;
1413 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
1417 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
1419 return cell_info_get_index (tree_view, cell_info);
1422 static GtkCellRendererState
1423 gtk_tree_view_accessible_get_renderer_state (GtkCellAccessibleParent *parent,
1424 GtkCellAccessible *cell)
1426 GtkTreeViewAccessibleCellInfo *cell_info;
1427 GtkTreeView *treeview;
1428 GtkCellRendererState flags;
1430 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
1436 if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_SELECTED))
1437 flags |= GTK_CELL_RENDERER_SELECTED;
1439 if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_PRELIT))
1440 flags |= GTK_CELL_RENDERER_PRELIT;
1442 if (gtk_tree_view_column_get_sort_indicator (cell_info->cell_col_ref))
1443 flags |= GTK_CELL_RENDERER_SORTED;
1445 treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
1447 if (cell_info->cell_col_ref == gtk_tree_view_get_expander_column (treeview))
1449 if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_PARENT))
1450 flags |= GTK_CELL_RENDERER_EXPANDABLE;
1452 if (cell_info->node->children)
1453 flags |= GTK_CELL_RENDERER_EXPANDED;
1456 if (gtk_widget_has_focus (GTK_WIDGET (treeview)))
1458 GtkTreeViewColumn *column;
1463 gtk_tree_view_get_cursor (treeview, &path, &column);
1466 _gtk_tree_view_find_node (treeview, path, &tree, &node);
1467 gtk_tree_path_free (path);
1472 if (cell_info->cell_col_ref == column
1473 && cell_info->tree == tree
1474 && cell_info->node == node)
1475 flags |= GTK_CELL_RENDERER_FOCUSED;
1482 gtk_tree_view_accessible_set_cell_data (GtkCellAccessibleParent *parent,
1483 GtkCellAccessible *cell)
1485 GtkTreeViewAccessibleCellInfo *cell_info;
1486 GtkTreeView *treeview;
1487 gboolean is_expander, is_expanded;
1488 GtkTreeModel *model;
1492 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
1496 treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
1497 model = gtk_tree_view_get_model (treeview);
1499 if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_PARENT) &&
1500 cell_info->cell_col_ref == gtk_tree_view_get_expander_column (treeview))
1503 is_expanded = cell_info->node->children != NULL;
1507 is_expander = FALSE;
1508 is_expanded = FALSE;
1511 path = cell_info_get_path (cell_info);
1513 !gtk_tree_model_get_iter (model, &iter, path))
1515 /* We only track valid cells, this should never happen */
1516 g_return_if_reached ();
1519 gtk_tree_view_column_cell_set_cell_data (cell_info->cell_col_ref,
1527 gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface)
1529 iface->get_cell_extents = gtk_tree_view_accessible_get_cell_extents;
1530 iface->get_cell_area = gtk_tree_view_accessible_get_cell_area;
1531 iface->grab_focus = gtk_tree_view_accessible_grab_cell_focus;
1532 iface->get_child_index = gtk_tree_view_accessible_get_child_index;
1533 iface->get_renderer_state = gtk_tree_view_accessible_get_renderer_state;
1534 iface->set_cell_data = gtk_tree_view_accessible_set_cell_data;
1537 /* signal handling */
1540 idle_expand_row (gpointer data)
1542 GtkTreeViewAccessible *accessible = data;
1544 GtkTreeView *tree_view;
1546 GtkTreeModel *tree_model;
1547 gint n_inserted, row;
1549 accessible->idle_expand_id = 0;
1551 path = accessible->idle_expand_path;
1552 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
1554 tree_model = gtk_tree_view_get_model (tree_view);
1558 if (!path || !gtk_tree_model_get_iter (tree_model, &iter, path))
1561 /* Figure out number of visible children, the following test
1564 if (gtk_tree_model_iter_has_child (tree_model, &iter))
1566 GtkTreePath *path_copy;
1568 /* By passing path into this function, we find the number of
1569 * visible children of path.
1571 path_copy = gtk_tree_path_copy (path);
1572 gtk_tree_path_append_index (path_copy, 0);
1575 iterate_thru_children (tree_view, tree_model,
1576 path_copy, NULL, &n_inserted, 0);
1577 gtk_tree_path_free (path_copy);
1581 /* We can get here if the row expanded callback deleted the row */
1585 /* Set expand state */
1586 set_expand_state (tree_view, tree_model, accessible, path, TRUE);
1588 row = get_row_from_tree_path (tree_view, path);
1590 /* shouldn't ever happen */
1592 g_assert_not_reached ();
1594 /* Must add 1 because the "added rows" are below the row being expanded */
1597 g_signal_emit_by_name (accessible, "row-inserted", row, n_inserted);
1599 accessible->idle_expand_path = NULL;
1601 gtk_tree_path_free (path);
1607 row_expanded_cb (GtkTreeView *tree_view,
1612 GtkTreeViewAccessible *accessible;
1614 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
1615 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1618 * The visible rectangle has not been updated when this signal is emitted
1619 * so we process the signal when the GTK processing is completed
1621 /* this seems wrong since it overwrites any other pending expand handlers... */
1622 accessible->idle_expand_path = gtk_tree_path_copy (path);
1623 if (accessible->idle_expand_id)
1624 g_source_remove (accessible->idle_expand_id);
1625 accessible->idle_expand_id = gdk_threads_add_idle (idle_expand_row, accessible);
1631 row_collapsed_cb (GtkTreeView *tree_view,
1635 GtkTreeModel *tree_model;
1637 GtkTreeViewAccessible *accessible;
1640 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
1641 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1642 tree_model = gtk_tree_view_get_model (tree_view);
1644 /* Set collapse state */
1645 set_expand_state (tree_view, tree_model, accessible, path, FALSE);
1646 if (accessible->n_children_deleted == 0)
1648 row = get_row_from_tree_path (tree_view, path);
1651 g_signal_emit_by_name (atk_obj, "row-deleted", row,
1652 accessible->n_children_deleted);
1653 accessible->n_children_deleted = 0;
1658 selection_changed_cb (GtkTreeSelection *selection,
1661 GtkTreeViewAccessible *accessible;
1662 GtkTreeView *tree_view;
1664 GtkTreeViewAccessibleCellInfo *info;
1665 GtkTreeSelection *tree_selection;
1667 GHashTableIter iter;
1669 accessible = GTK_TREE_VIEW_ACCESSIBLE (data);
1670 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
1674 tree_view = GTK_TREE_VIEW (widget);
1675 tree_selection = gtk_tree_view_get_selection (tree_view);
1677 /* FIXME: clean rows iterates through all cells too */
1678 g_hash_table_iter_init (&iter, accessible->cell_infos);
1679 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&info))
1681 _gtk_cell_accessible_remove_state (info->cell, ATK_STATE_SELECTED, TRUE);
1683 path = cell_info_get_path (info);
1684 if (path && gtk_tree_selection_path_is_selected (tree_selection, path))
1685 _gtk_cell_accessible_add_state (info->cell, ATK_STATE_SELECTED, TRUE);
1686 gtk_tree_path_free (path);
1688 if (gtk_widget_get_realized (widget))
1689 g_signal_emit_by_name (accessible, "selection-changed");
1693 cursor_changed (GtkTreeView *tree_view,
1694 GtkTreeViewAccessible *accessible)
1698 cell = gtk_tree_view_accessible_ref_focus_cell (tree_view);
1701 if (cell != accessible->focus_cell)
1703 if (accessible->focus_cell)
1705 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_ACTIVE, FALSE);
1706 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_FOCUSED, FALSE);
1707 g_object_unref (accessible->focus_cell);
1708 accessible->focus_cell = cell;
1711 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
1713 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_ACTIVE, FALSE);
1714 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_FOCUSED, FALSE);
1717 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
1720 g_object_unref (cell);
1725 focus_in (GtkWidget *widget)
1727 GtkTreeView *tree_view;
1728 GtkTreeViewAccessible *accessible;
1729 AtkStateSet *state_set;
1732 tree_view = GTK_TREE_VIEW (widget);
1733 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
1735 if (accessible->focus_cell == NULL)
1737 cell = gtk_tree_view_accessible_ref_focus_cell (tree_view);
1740 state_set = atk_object_ref_state_set (cell);
1743 if (!atk_state_set_contains_state (state_set, ATK_STATE_FOCUSED))
1745 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_ACTIVE, FALSE);
1746 accessible->focus_cell = cell;
1747 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_FOCUSED, FALSE);
1748 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
1750 g_object_unref (state_set);
1758 focus_out (GtkWidget *widget)
1760 GtkTreeViewAccessible *accessible;
1762 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
1763 if (accessible->focus_cell)
1765 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_ACTIVE, FALSE);
1766 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_FOCUSED, FALSE);
1767 g_object_unref (accessible->focus_cell);
1768 accessible->focus_cell = NULL;
1774 model_row_changed (GtkTreeModel *tree_model,
1779 GtkTreeView *tree_view = GTK_TREE_VIEW (user_data);
1780 GtkTreeViewAccessible *accessible;
1781 GtkTreePath *cell_path;
1782 GtkTreeViewAccessibleCellInfo *cell_info;
1783 GHashTableIter hash_iter;
1785 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (tree_view)));
1787 /* Loop through our cached cells */
1788 /* Must loop through them all */
1789 g_hash_table_iter_init (&hash_iter, accessible->cell_infos);
1790 while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer *)&cell_info))
1792 cell_path = cell_info_get_path (cell_info);
1794 if (cell_path != NULL)
1796 if (path && gtk_tree_path_compare (cell_path, path) == 0)
1798 if (GTK_IS_RENDERER_CELL_ACCESSIBLE (cell_info->cell))
1799 update_cell_value (GTK_RENDERER_CELL_ACCESSIBLE (cell_info->cell),
1802 gtk_tree_path_free (cell_path);
1805 g_signal_emit_by_name (accessible, "visible-data-changed");
1809 model_row_inserted (GtkTreeModel *tree_model,
1814 GtkTreeView *tree_view = (GtkTreeView *)user_data;
1816 GtkTreeViewAccessible *accessible;
1817 GtkTreePath *path_copy;
1818 gint row, n_inserted, child_row;
1820 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
1821 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1823 if (accessible->idle_expand_id)
1825 g_source_remove (accessible->idle_expand_id);
1826 accessible->idle_expand_id = 0;
1828 /* don't do this if the insertion precedes the idle path,
1829 * since it will now be invalid
1831 if (path && accessible->idle_expand_path &&
1832 (gtk_tree_path_compare (path, accessible->idle_expand_path) > 0))
1833 set_expand_state (tree_view, tree_model, accessible, accessible->idle_expand_path, FALSE);
1834 if (accessible->idle_expand_path)
1835 gtk_tree_path_free (accessible->idle_expand_path);
1837 /* Check to see if row is visible */
1838 row = get_row_from_tree_path (tree_view, path);
1840 /* A row insert is not necessarily visible. For example,
1841 * a row can be draged & dropped into another row, which
1842 * causes an insert on the model that isn't visible in the
1843 * view. Only generate a signal if the inserted row is
1848 GtkTreeIter tmp_iter;
1851 gtk_tree_model_get_iter (tree_model, &tmp_iter, path);
1853 /* Figure out number of visible children. */
1854 if (gtk_tree_model_iter_has_child (tree_model, &tmp_iter))
1858 * By passing path into this function, we find the number of
1859 * visible children of path.
1862 /* iterate_thru_children modifies path, we don't want that, so give
1864 path2 = gtk_tree_path_copy (path);
1865 iterate_thru_children (tree_view, tree_model,
1866 path2, NULL, &n_inserted, 0);
1867 gtk_tree_path_free (path2);
1869 /* Must add one to include the row that is being added */
1875 /* Generate row-inserted signal */
1876 g_signal_emit_by_name (atk_obj, "row-inserted", row, n_inserted);
1878 /* Generate children-changed signals */
1879 n_cols = get_n_columns (tree_view);
1880 for (child_row = row; child_row < (row + n_inserted); child_row++)
1882 for (col = 0; col < n_cols; col++)
1884 /* Pass NULL as the child object, i.e. 4th argument */
1885 g_signal_emit_by_name (atk_obj, "children-changed::add",
1886 ((row * n_cols) + col), NULL, NULL);
1892 /* The row has been inserted inside another row. This can
1893 * cause a row that previously couldn't be expanded to now
1896 path_copy = gtk_tree_path_copy (path);
1897 gtk_tree_path_up (path_copy);
1898 set_expand_state (tree_view, tree_model, accessible, path_copy, TRUE);
1899 gtk_tree_path_free (path_copy);
1904 model_row_deleted (GtkTreeModel *tree_model,
1908 GtkTreeView *tree_view = (GtkTreeView *)user_data;
1909 GtkTreePath *path_copy;
1911 GtkTreeViewAccessible *accessible;
1914 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
1915 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1917 if (accessible->idle_expand_id)
1919 g_source_remove (accessible->idle_expand_id);
1920 gtk_tree_path_free (accessible->idle_expand_path);
1921 accessible->idle_expand_id = 0;
1924 /* If deleting a row with a depth > 1, then this may affect the
1925 * expansion/contraction of its parent(s). Make sure this is
1928 if (gtk_tree_path_get_depth (path) > 1)
1930 path_copy = gtk_tree_path_copy (path);
1931 gtk_tree_path_up (path_copy);
1932 set_expand_state (tree_view, tree_model, accessible, path_copy, TRUE);
1933 gtk_tree_path_free (path_copy);
1935 row = get_row_from_tree_path (tree_view, path);
1937 /* If the row which is deleted is not visible because it is a child of
1938 * a collapsed row then row will be -1
1941 g_signal_emit_by_name (atk_obj, "row-deleted", row,
1942 accessible->n_children_deleted + 1);
1943 accessible->n_children_deleted = 0;
1945 /* Generate children-changed signals */
1946 for (col = 0; col < get_n_columns (tree_view); col++)
1948 /* Pass NULL as the child object, 4th argument */
1949 g_signal_emit_by_name (atk_obj, "children-changed::remove",
1950 ((row * get_n_columns (tree_view)) + col), NULL, NULL);
1954 /* This function gets called when a row is deleted or when rows are
1955 * removed from the view due to a collapse event. Note that the
1956 * count is the number of visible *children* of the deleted row,
1957 * so it does not include the row being deleted.
1959 * As this function is called before the rows are removed we just note
1960 * the number of rows and then deal with it when we get a notification
1961 * that rows were deleted or collapsed.
1964 destroy_count_func (GtkTreeView *tree_view,
1970 GtkTreeViewAccessible *accessible;
1972 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
1973 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1975 if (accessible->n_children_deleted != 0)
1978 accessible->n_children_deleted = count;
1982 _gtk_tree_view_accessible_reorder (GtkTreeView *treeview)
1984 GtkTreeViewAccessible *accessible;
1986 accessible = GTK_TREE_VIEW_ACCESSIBLE (_gtk_widget_peek_accessible (GTK_WIDGET (treeview)));
1987 if (accessible == NULL)
1990 if (accessible->idle_expand_id)
1992 g_source_remove (accessible->idle_expand_id);
1993 gtk_tree_path_free (accessible->idle_expand_path);
1994 accessible->idle_expand_id = 0;
1997 g_signal_emit_by_name (accessible, "row-reordered");
2001 is_cell_showing (GtkTreeView *tree_view,
2002 GdkRectangle *cell_rect)
2004 GdkRectangle rect, *visible_rect;
2005 GdkRectangle rect1, *tree_cell_rect;
2007 gboolean is_showing;
2009 /* A cell is considered "SHOWING" if any part of the cell is
2010 * in the visible area. Other ways we could do this is by a
2011 * cell's midpoint or if the cell is fully in the visible range.
2012 * Since we have the cell_rect x, y, width, height of the cell,
2013 * any of these is easy to compute.
2015 * It is assumed that cell's rectangle is in widget coordinates
2016 * so we must transform to tree cordinates.
2018 visible_rect = ▭
2019 tree_cell_rect = &rect1;
2020 tree_cell_rect->x = cell_rect->x;
2021 tree_cell_rect->y = cell_rect->y;
2022 tree_cell_rect->width = cell_rect->width;
2023 tree_cell_rect->height = cell_rect->height;
2025 gtk_tree_view_get_visible_rect (tree_view, visible_rect);
2026 gtk_tree_view_convert_tree_to_bin_window_coords (tree_view, visible_rect->x,
2027 visible_rect->y, &bx, &by);
2029 if (((tree_cell_rect->x + tree_cell_rect->width) < bx) ||
2030 ((tree_cell_rect->y + tree_cell_rect->height) < by) ||
2031 (tree_cell_rect->x > (bx + visible_rect->width)) ||
2032 (tree_cell_rect->y > (by + visible_rect->height)))
2042 /* This function is called when a cell's flyweight is created in
2043 * gtk_tree_view_accessible_table_ref_at with emit_change_signal
2044 * set to FALSE and in model_row_changed() on receipt of "row-changed"
2045 * signal when emit_change_signal is set to TRUE
2048 update_cell_value (GtkRendererCellAccessible *renderer_cell,
2049 GtkTreeViewAccessible *accessible,
2050 gboolean emit_change_signal)
2052 GtkTreeViewAccessibleCellInfo *cell_info;
2053 GtkTreeView *tree_view;
2054 GtkTreeModel *tree_model;
2057 GList *renderers, *cur_renderer;
2059 GtkRendererCellAccessibleClass *renderer_cell_class;
2060 GtkCellRendererClass *gtk_cell_renderer_class;
2061 GtkCellAccessible *cell;
2064 gboolean is_expander, is_expanded;
2066 renderer_cell_class = GTK_RENDERER_CELL_ACCESSIBLE_GET_CLASS (renderer_cell);
2067 if (renderer_cell->renderer)
2068 gtk_cell_renderer_class = GTK_CELL_RENDERER_GET_CLASS (renderer_cell->renderer);
2070 gtk_cell_renderer_class = NULL;
2072 prop_list = renderer_cell_class->property_list;
2074 cell = GTK_CELL_ACCESSIBLE (renderer_cell);
2075 cell_info = find_cell_info (accessible, cell);
2079 if (emit_change_signal)
2081 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
2082 tree_model = gtk_tree_view_get_model (tree_view);
2083 path = cell_info_get_path (cell_info);
2087 gtk_tree_model_get_iter (tree_model, &iter, path);
2088 is_expander = FALSE;
2089 is_expanded = FALSE;
2090 if (gtk_tree_model_iter_has_child (tree_model, &iter))
2092 GtkTreeViewColumn *expander_tv;
2094 expander_tv = gtk_tree_view_get_expander_column (tree_view);
2095 if (expander_tv == cell_info->cell_col_ref)
2098 is_expanded = gtk_tree_view_row_expanded (tree_view, path);
2101 gtk_tree_path_free (path);
2102 gtk_tree_view_column_cell_set_cell_data (cell_info->cell_col_ref,
2104 is_expander, is_expanded);
2106 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_info->cell_col_ref));
2110 /* If the cell is in a container, its index is used to find the renderer
2111 * in the list. Otherwise, we assume that the cell is represented
2112 * by the first renderer in the list
2114 parent = atk_object_get_parent (ATK_OBJECT (cell));
2116 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
2117 cur_renderer = g_list_nth (renderers, atk_object_get_index_in_parent (ATK_OBJECT (cell)));
2119 cur_renderer = renderers;
2121 if (cur_renderer == NULL)
2124 if (gtk_cell_renderer_class)
2128 spec = g_object_class_find_property
2129 (G_OBJECT_CLASS (gtk_cell_renderer_class), *prop_list);
2133 GValue value = G_VALUE_INIT;
2135 g_value_init (&value, spec->value_type);
2136 g_object_get_property (cur_renderer->data, *prop_list, &value);
2137 g_object_set_property (G_OBJECT (renderer_cell->renderer),
2138 *prop_list, &value);
2139 g_value_unset (&value);
2142 g_warning ("Invalid property: %s\n", *prop_list);
2146 g_list_free (renderers);
2148 return _gtk_renderer_cell_accessible_update_cache (renderer_cell, emit_change_signal);
2152 get_row_from_tree_path (GtkTreeView *tree_view,
2155 GtkTreeModel *tree_model;
2156 GtkTreePath *root_tree;
2159 tree_model = gtk_tree_view_get_model (tree_view);
2161 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
2162 row = gtk_tree_path_get_indices (path)[0];
2165 root_tree = gtk_tree_path_new_first ();
2167 iterate_thru_children (tree_view, tree_model, root_tree, path, &row, 0);
2168 gtk_tree_path_free (root_tree);
2176 /* Helper recursive function that returns an iter to nth row
2178 static GtkTreeIter *
2179 return_iter_nth_row (GtkTreeView *tree_view,
2180 GtkTreeModel *tree_model,
2185 GtkTreePath *current_path;
2186 GtkTreeIter new_iter;
2187 gboolean row_expanded;
2189 current_path = gtk_tree_model_get_path (tree_model, iter);
2190 if (increment == row)
2192 gtk_tree_path_free (current_path);
2196 row_expanded = gtk_tree_view_row_expanded (tree_view, current_path);
2197 gtk_tree_path_free (current_path);
2200 if ((row_expanded && gtk_tree_model_iter_children (tree_model, iter, &new_iter)) ||
2201 (gtk_tree_model_iter_next (tree_model, iter)) ||
2202 (gtk_tree_model_iter_parent (tree_model, iter, &new_iter) &&
2203 (gtk_tree_model_iter_next (tree_model, iter))))
2204 return return_iter_nth_row (tree_view, tree_model, iter,
2211 set_iter_nth_row (GtkTreeView *tree_view,
2215 GtkTreeModel *tree_model;
2217 tree_model = gtk_tree_view_get_model (tree_view);
2218 gtk_tree_model_get_iter_first (tree_model, iter);
2219 iter = return_iter_nth_row (tree_view, tree_model, iter, 0, row);
2222 /* Recursively called until the row specified by orig is found.
2224 * *count will be set to the visible row number of the child
2225 * relative to the row that was initially passed in as tree_path.
2226 * tree_path could be modified by this function.
2228 * *count will be -1 if orig is not found as a child (a row that is
2229 * not visible will not be found, e.g. if the row is inside a
2230 * collapsed row). If NULL is passed in as orig, *count will
2231 * be a count of the visible children.
2233 * NOTE: the value for depth must be 0 when this recursive function
2234 * is initially called, or it may not function as expected.
2237 iterate_thru_children (GtkTreeView *tree_view,
2238 GtkTreeModel *tree_model,
2239 GtkTreePath *tree_path,
2246 if (!gtk_tree_model_get_iter (tree_model, &iter, tree_path))
2249 if (tree_path && orig && !gtk_tree_path_compare (tree_path, orig))
2253 if (tree_path && orig && gtk_tree_path_compare (tree_path, orig) > 0)
2255 /* Past it, so return -1 */
2259 else if (gtk_tree_view_row_expanded (tree_view, tree_path) &&
2260 gtk_tree_model_iter_has_child (tree_model, &iter))
2263 gtk_tree_path_append_index (tree_path, 0);
2264 iterate_thru_children (tree_view, tree_model, tree_path,
2265 orig, count, (depth + 1));
2268 else if (gtk_tree_model_iter_next (tree_model, &iter))
2271 tree_path = gtk_tree_model_get_path (tree_model, &iter);
2274 iterate_thru_children (tree_view, tree_model, tree_path,
2275 orig, count, depth);
2276 gtk_tree_path_free (tree_path);
2280 else if (gtk_tree_path_up (tree_path))
2282 GtkTreeIter temp_iter;
2283 gboolean exit_loop = FALSE;
2284 gint new_depth = depth - 1;
2288 /* Make sure that we back up until we find a row
2289 * where gtk_tree_path_next does not return NULL.
2293 if (gtk_tree_path_get_depth (tree_path) == 0)
2294 /* depth is now zero so */
2296 gtk_tree_path_next (tree_path);
2298 /* Verify that the next row is a valid row! */
2299 exit_loop = gtk_tree_model_get_iter (tree_model, &temp_iter, tree_path);
2303 /* Keep going up until we find a row that has a valid next */
2304 if (gtk_tree_path_get_depth(tree_path) > 1)
2307 gtk_tree_path_up (tree_path);
2311 /* If depth is 1 and gtk_tree_model_get_iter returns FALSE,
2312 * then we are at the last row, so just return.
2322 /* This guarantees that we will stop when we hit the end of the
2328 iterate_thru_children (tree_view, tree_model, tree_path,
2329 orig, count, new_depth);
2333 /* If it gets here, then the path wasn't found. Situations
2334 * that would cause this would be if the path passed in is
2335 * invalid or contained within the last row, but not visible
2336 * because the last row is not expanded. If NULL was passed
2337 * in then a row count is desired, so only set count to -1
2338 * if orig is not NULL.
2346 /* If the tree_path passed in has children, then
2347 * ATK_STATE_EXPANDABLE is set. If the row is expanded
2348 * ATK_STATE_EXPANDED is turned on. If the row is
2349 * collapsed, then ATK_STATE_EXPANDED is removed.
2351 * If the tree_path passed in has no children, then
2352 * ATK_STATE_EXPANDABLE and ATK_STATE_EXPANDED are removed.
2354 * If set_on_ancestor is TRUE, then this function will also
2355 * update all cells that are ancestors of the tree_path.
2358 set_expand_state (GtkTreeView *tree_view,
2359 GtkTreeModel *tree_model,
2360 GtkTreeViewAccessible *accessible,
2361 GtkTreePath *tree_path,
2362 gboolean set_on_ancestor)
2364 GtkTreeViewColumn *expander_tv;
2365 GtkTreeViewAccessibleCellInfo *cell_info;
2366 GtkTreePath *cell_path;
2369 GHashTableIter hash_iter;
2371 g_hash_table_iter_init (&hash_iter, accessible->cell_infos);
2372 while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer *) &cell_info))
2374 cell_path = cell_info_get_path (cell_info);
2377 if (cell_path != NULL)
2379 GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (cell_info->cell);
2381 expander_tv = gtk_tree_view_get_expander_column (tree_view);
2383 /* Only set state for the cell that is in the column with the
2386 if (expander_tv == cell_info->cell_col_ref)
2388 if (tree_path && gtk_tree_path_compare (cell_path, tree_path) == 0)
2390 else if (set_on_ancestor &&
2391 gtk_tree_path_get_depth (cell_path) <
2392 gtk_tree_path_get_depth (tree_path) &&
2393 gtk_tree_path_is_ancestor (cell_path, tree_path) == 1)
2394 /* Only set if set_on_ancestor was passed in as TRUE */
2398 /* Set ATK_STATE_EXPANDABLE and ATK_STATE_EXPANDED
2399 * for ancestors and found cells.
2403 /* Must check against cell_path since cell_path
2404 * can be equal to or an ancestor of tree_path.
2406 gtk_tree_model_get_iter (tree_model, &iter, cell_path);
2408 /* Set or unset ATK_STATE_EXPANDABLE as appropriate */
2409 if (gtk_tree_model_iter_has_child (tree_model, &iter))
2411 set_cell_expandable (cell);
2413 if (gtk_tree_view_row_expanded (tree_view, cell_path))
2414 _gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, TRUE);
2416 _gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDED, TRUE);
2420 _gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDED, TRUE);
2421 if (_gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDABLE, TRUE))
2422 /* The state may have been propagated to the container cell */
2423 if (!GTK_IS_CONTAINER_CELL_ACCESSIBLE (cell))
2424 _gtk_cell_accessible_remove_action_by_name (cell,
2425 "expand or contract");
2428 /* We assume that each cell in the cache once and
2429 * a container cell is before its child cells so we are
2430 * finished if set_on_ancestor is not set to TRUE.
2432 if (!set_on_ancestor)
2436 gtk_tree_path_free (cell_path);
2441 add_cell_actions (GtkCellAccessible *cell,
2444 if (GTK_IS_BOOLEAN_CELL_ACCESSIBLE (cell))
2445 _gtk_cell_accessible_add_action (cell,
2446 "toggle", "toggles the cell",
2447 NULL, toggle_cell_toggled);
2449 _gtk_cell_accessible_add_action (cell,
2450 "edit", "creates a widget in which the contents of the cell can be edited",
2452 _gtk_cell_accessible_add_action (cell,
2453 "activate", "activate the cell",
2454 NULL, activate_cell);
2458 toggle_cell_expanded (GtkCellAccessible *cell)
2460 GtkTreeViewAccessibleCellInfo *cell_info;
2461 GtkTreeView *tree_view;
2464 AtkStateSet *stateset;
2466 parent = atk_object_get_parent (ATK_OBJECT (cell));
2467 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
2468 parent = atk_object_get_parent (parent);
2470 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
2474 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
2475 path = cell_info_get_path (cell_info);
2479 stateset = atk_object_ref_state_set (ATK_OBJECT (cell));
2480 if (atk_state_set_contains_state (stateset, ATK_STATE_EXPANDED))
2481 gtk_tree_view_collapse_row (tree_view, path);
2483 gtk_tree_view_expand_row (tree_view, path, TRUE);
2484 g_object_unref (stateset);
2485 gtk_tree_path_free (path);
2489 toggle_cell_toggled (GtkCellAccessible *cell)
2491 GtkTreeViewAccessibleCellInfo *cell_info;
2494 GList *renderers, *cur_renderer;
2496 gboolean is_container_cell = FALSE;
2498 parent = atk_object_get_parent (ATK_OBJECT (cell));
2499 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
2501 is_container_cell = TRUE;
2502 parent = atk_object_get_parent (parent);
2505 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
2509 path = cell_info_get_path (cell_info);
2513 /* If the cell is in a container, its index is used to find the
2514 * renderer in the list. Otherwise, we assume that the cell is
2515 * represented by the first renderer in the list
2517 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_info->cell_col_ref));
2518 if (is_container_cell)
2519 cur_renderer = g_list_nth (renderers, atk_object_get_index_in_parent (ATK_OBJECT (cell)));
2521 cur_renderer = renderers;
2525 pathstring = gtk_tree_path_to_string (path);
2526 g_signal_emit_by_name (cur_renderer->data, "toggled", pathstring);
2527 g_free (pathstring);
2530 g_list_free (renderers);
2531 gtk_tree_path_free (path);
2535 edit_cell (GtkCellAccessible *cell)
2537 GtkTreeViewAccessibleCellInfo *cell_info;
2538 GtkTreeView *tree_view;
2542 parent = atk_object_get_parent (ATK_OBJECT (cell));
2543 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
2544 parent = atk_object_get_parent (parent);
2546 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
2550 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
2551 path = cell_info_get_path (cell_info);
2554 gtk_tree_view_set_cursor (tree_view, path, cell_info->cell_col_ref, TRUE);
2555 gtk_tree_path_free (path);
2559 activate_cell (GtkCellAccessible *cell)
2561 GtkTreeViewAccessibleCellInfo *cell_info;
2562 GtkTreeView *tree_view;
2566 parent = atk_object_get_parent (ATK_OBJECT (cell));
2567 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
2568 parent = atk_object_get_parent (parent);
2570 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
2574 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
2575 path = cell_info_get_path (cell_info);
2578 gtk_tree_view_row_activated (tree_view, path, cell_info->cell_col_ref);
2579 gtk_tree_path_free (path);
2583 cell_destroyed (gpointer data)
2585 GtkTreeViewAccessibleCellInfo *cell_info = data;
2587 cell_info->cell = NULL;
2589 g_hash_table_remove (cell_info->view->cell_infos, cell_info);
2593 cell_info_get_index (GtkTreeView *tree_view,
2594 GtkTreeViewAccessibleCellInfo *info)
2598 index = _gtk_rbtree_node_get_index (info->tree, info->node) + 1;
2599 index *= get_n_columns (tree_view);
2600 index += get_column_number (tree_view, info->cell_col_ref);
2606 cell_info_new (GtkTreeViewAccessible *accessible,
2607 GtkTreeModel *tree_model,
2610 GtkTreeViewColumn *tv_col,
2611 GtkCellAccessible *cell)
2613 GtkTreeViewAccessibleCellInfo *cell_info;
2615 cell_info = g_new (GtkTreeViewAccessibleCellInfo, 1);
2617 cell_info->tree = tree;
2618 cell_info->node = node;
2619 cell_info->cell_col_ref = tv_col;
2620 cell_info->cell = cell;
2621 cell_info->view = accessible;
2623 g_object_set_qdata_full (G_OBJECT (cell),
2624 gtk_tree_view_accessible_get_data_quark (),
2628 g_hash_table_replace (accessible->cell_infos, cell_info, cell_info);
2631 static GtkCellAccessible *
2632 peek_cell (GtkTreeViewAccessible *accessible,
2635 GtkTreeViewColumn *column)
2637 GtkTreeViewAccessibleCellInfo lookup, *cell_info;
2641 lookup.cell_col_ref = column;
2643 cell_info = g_hash_table_lookup (accessible->cell_infos, &lookup);
2644 if (cell_info == NULL)
2647 return cell_info->cell;
2650 static GtkCellAccessible *
2651 find_cell (GtkTreeViewAccessible *accessible,
2654 GtkTreeView *tree_view;
2658 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
2660 if (!_gtk_rbtree_find_index (_gtk_tree_view_get_rbtree (tree_view),
2661 index / get_n_columns (tree_view) - 1,
2665 g_assert_not_reached ();
2668 return peek_cell (accessible,
2670 get_visible_column (tree_view, index % get_n_columns (tree_view)));
2674 connect_model_signals (GtkTreeView *view,
2675 GtkTreeViewAccessible *accessible)
2679 obj = G_OBJECT (accessible->tree_model);
2680 g_signal_connect_data (obj, "row-changed",
2681 G_CALLBACK (model_row_changed), view, NULL, 0);
2682 g_signal_connect_data (obj, "row-inserted",
2683 G_CALLBACK (model_row_inserted), view, NULL,
2685 g_signal_connect_data (obj, "row-deleted",
2686 G_CALLBACK (model_row_deleted), view, NULL,
2691 disconnect_model_signals (GtkTreeViewAccessible *accessible)
2696 obj = G_OBJECT (accessible->tree_model);
2697 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2698 g_signal_handlers_disconnect_by_func (obj, model_row_changed, widget);
2699 g_signal_handlers_disconnect_by_func (obj, model_row_inserted, widget);
2700 g_signal_handlers_disconnect_by_func (obj, model_row_deleted, widget);
2703 /* Returns the column number of the specified GtkTreeViewColumn
2704 * The column must be visible.
2707 get_column_number (GtkTreeView *treeview,
2708 GtkTreeViewColumn *column)
2710 GtkTreeViewColumn *cur;
2715 for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++)
2717 cur = gtk_tree_view_get_column (treeview, i);
2719 if (!gtk_tree_view_column_get_visible (cur))
2728 g_return_val_if_fail (i < gtk_tree_view_get_n_columns (treeview), 0);
2734 get_index (GtkTreeView *tree_view,
2740 gint *indices = NULL;
2744 depth = gtk_tree_path_get_depth (path);
2745 indices = gtk_tree_path_get_indices (path);
2750 GtkTreePath *copy_path;
2751 GtkTreeModel *model;
2753 model = gtk_tree_view_get_model (tree_view);
2754 copy_path = gtk_tree_path_copy (path);
2755 gtk_tree_path_up (copy_path);
2756 count_rows (model, NULL, copy_path, &index, 0, depth);
2757 gtk_tree_path_free (copy_path);
2761 index += indices[depth - 1];
2762 index *= get_n_columns (tree_view);
2763 index += actual_column;
2767 /* The function count_rows counts the number of rows starting at iter
2768 * and ending at end_path. The value of level is the depth of iter and
2769 * the value of depth is the depth of end_path. Rows at depth before
2770 * end_path are counted. This functions counts rows which are not visible
2771 * because an ancestor is collapsed.
2774 count_rows (GtkTreeModel *model,
2776 GtkTreePath *end_path,
2781 GtkTreeIter child_iter;
2787 *count += gtk_tree_model_iter_n_children (model, iter);
2789 if (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY)
2795 if (gtk_tree_model_iter_children (model, &child_iter, iter))
2797 gboolean ret_val = TRUE;
2801 if (level == depth - 1)
2803 GtkTreePath *iter_path;
2804 gboolean finished = FALSE;
2806 iter_path = gtk_tree_model_get_path (model, &child_iter);
2807 if (end_path && gtk_tree_path_compare (iter_path, end_path) >= 0)
2809 gtk_tree_path_free (iter_path);
2813 if (gtk_tree_model_iter_has_child (model, &child_iter))
2814 count_rows (model, &child_iter, end_path, count, level, depth);
2815 ret_val = gtk_tree_model_iter_next (model, &child_iter);
2821 get_rbtree_column_from_index (GtkTreeView *tree_view,
2825 GtkTreeViewColumn **column)
2827 guint n_columns = get_n_columns (tree_view);
2831 /* First row is the column headers */
2838 g_return_val_if_fail (node != NULL, FALSE);
2840 if (!_gtk_rbtree_find_index (_gtk_tree_view_get_rbtree (tree_view),
2849 *column = get_visible_column (tree_view, index % n_columns);
2850 if (*column == NULL)
2857 set_cell_expandable (GtkCellAccessible *cell)
2859 if (_gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDABLE, FALSE))
2860 _gtk_cell_accessible_add_action (cell,
2861 "expand or contract",
2862 "expands or contracts the row in the tree view containing this cell",
2863 NULL, toggle_cell_expanded);
2866 static GtkTreeViewAccessibleCellInfo *
2867 find_cell_info (GtkTreeViewAccessible *accessible,
2868 GtkCellAccessible *cell)
2872 parent = atk_object_get_parent (ATK_OBJECT (cell));
2873 while (parent != ATK_OBJECT (accessible))
2875 cell = GTK_CELL_ACCESSIBLE (parent);
2876 parent = atk_object_get_parent (ATK_OBJECT (cell));
2879 return g_object_get_qdata (G_OBJECT (cell),
2880 gtk_tree_view_accessible_get_data_quark ());
2884 get_header_from_column (GtkTreeViewColumn *tv_col)
2887 GtkWidget *header_widget;
2892 header_widget = gtk_tree_view_column_get_button (tv_col);
2895 rc = gtk_widget_get_accessible (header_widget);
2903 _gtk_tree_view_accessible_remove (GtkTreeView *treeview,
2907 GtkTreeViewAccessibleCellInfo *cell_info;
2908 GHashTableIter iter;
2909 GtkTreeViewAccessible *accessible;
2911 accessible = GTK_TREE_VIEW_ACCESSIBLE (_gtk_widget_peek_accessible (GTK_WIDGET (treeview)));
2912 if (accessible == NULL)
2915 /* if this shows up in profiles, special-case node->children == NULL */
2918 tree = node->children;
2920 g_hash_table_iter_init (&iter, accessible->cell_infos);
2921 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
2923 if (node == cell_info->node ||
2924 tree == cell_info->tree ||
2925 (tree && _gtk_rbtree_contains (tree, cell_info->tree)))
2926 g_hash_table_iter_remove (&iter);
2930 /* NB: id is not checked, only columns < id are.
2931 * This is important so the function works for notification of removal of a column */
2933 to_visible_column_id (GtkTreeView *treeview,
2941 for (i = 0; i < id; i++)
2943 GtkTreeViewColumn *column = gtk_tree_view_get_column (treeview, i);
2945 if (!gtk_tree_view_column_get_visible (column))
2949 return id - invisible;
2953 _gtk_tree_view_accessible_do_add_column (GtkTreeViewAccessible *accessible,
2954 GtkTreeView *treeview,
2955 GtkTreeViewColumn *column,
2958 guint row, n_rows, n_cols;
2960 /* Generate column-inserted signal */
2961 g_signal_emit_by_name (accessible, "column-inserted", id, 1);
2963 n_rows = get_n_rows (treeview);
2964 n_cols = get_n_columns (treeview);
2966 /* Generate children-changed signals */
2967 for (row = 0; row <= n_rows; row++)
2969 /* Pass NULL as the child object, i.e. 4th argument */
2970 g_signal_emit_by_name (accessible, "children-changed::add",
2971 (row * n_cols) + id, NULL, NULL);
2976 _gtk_tree_view_accessible_add_column (GtkTreeView *treeview,
2977 GtkTreeViewColumn *column,
2982 if (!gtk_tree_view_column_get_visible (column))
2985 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
2989 _gtk_tree_view_accessible_do_add_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
2992 to_visible_column_id (treeview, id));
2996 _gtk_tree_view_accessible_do_remove_column (GtkTreeViewAccessible *accessible,
2997 GtkTreeView *treeview,
2998 GtkTreeViewColumn *column,
3001 GtkTreeViewAccessibleCellInfo *cell_info;
3002 GHashTableIter iter;
3004 guint row, n_rows, n_cols;
3006 /* Clean column from cache */
3007 g_hash_table_iter_init (&iter, accessible->cell_infos);
3008 while (g_hash_table_iter_next (&iter, NULL, &value))
3011 if (cell_info->cell_col_ref == column)
3012 g_hash_table_iter_remove (&iter);
3015 /* Generate column-deleted signal */
3016 g_signal_emit_by_name (accessible, "column-deleted", id, 1);
3018 n_rows = get_n_rows (treeview);
3019 n_cols = get_n_columns (treeview);
3021 /* Generate children-changed signals */
3022 for (row = 0; row <= n_rows; row++)
3024 /* Pass NULL as the child object, 4th argument */
3025 g_signal_emit_by_name (accessible, "children-changed::remove",
3026 (row * n_cols) + id, NULL, NULL);
3031 _gtk_tree_view_accessible_remove_column (GtkTreeView *treeview,
3032 GtkTreeViewColumn *column,
3037 if (!gtk_tree_view_column_get_visible (column))
3040 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
3044 _gtk_tree_view_accessible_do_remove_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
3047 to_visible_column_id (treeview, id));
3051 _gtk_tree_view_accessible_reorder_column (GtkTreeView *treeview,
3052 GtkTreeViewColumn *column)
3056 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
3060 g_signal_emit_by_name (obj, "column-reordered");
3064 _gtk_tree_view_accessible_toggle_visibility (GtkTreeView *treeview,
3065 GtkTreeViewColumn *column)
3070 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
3074 id = get_column_number (treeview, column);
3076 if (gtk_tree_view_column_get_visible (column))
3077 _gtk_tree_view_accessible_do_add_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
3082 _gtk_tree_view_accessible_do_remove_column (GTK_TREE_VIEW_ACCESSIBLE (obj),
3089 _gtk_tree_view_accessible_add_state (GtkTreeView *treeview,
3092 GtkCellRendererState state)
3094 GtkTreeViewAccessible *accessible;
3098 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
3102 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
3104 for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++)
3106 GtkCellAccessible *cell = peek_cell (accessible,
3108 gtk_tree_view_get_column (treeview, i));
3113 _gtk_cell_accessible_state_changed (cell, state, 0);
3118 _gtk_tree_view_accessible_remove_state (GtkTreeView *treeview,
3121 GtkCellRendererState state)
3123 GtkTreeViewAccessible *accessible;
3127 obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview));
3131 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
3133 for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++)
3135 GtkCellAccessible *cell = peek_cell (accessible,
3137 gtk_tree_view_get_column (treeview, i));
3142 _gtk_cell_accessible_state_changed (cell, 0, state);