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>
26 #include "gtktreeviewaccessible.h"
27 #include "gtkrenderercellaccessible.h"
28 #include "gtkbooleancellaccessible.h"
29 #include "gtkimagecellaccessible.h"
30 #include "gtkcontainercellaccessible.h"
31 #include "gtktextcellaccessible.h"
32 #include "gtkcellaccessibleparent.h"
34 typedef struct _GtkTreeViewAccessibleCellInfo GtkTreeViewAccessibleCellInfo;
35 struct _GtkTreeViewAccessibleCellInfo
37 GtkCellAccessible *cell;
38 GtkTreeRowReference *cell_row_ref;
39 GtkTreeViewColumn *cell_col_ref;
40 GtkTreeViewAccessible *view;
46 static gboolean row_expanded_cb (GtkTreeView *tree_view,
49 static gboolean row_collapsed_cb (GtkTreeView *tree_view,
52 static void size_allocate_cb (GtkWidget *widget,
53 GtkAllocation *allocation);
54 static void selection_changed_cb (GtkTreeSelection *selection,
57 static void columns_changed (GtkTreeView *tree_view);
58 static void cursor_changed (GtkTreeView *tree_view);
59 static gboolean focus_in (GtkWidget *widget);
60 static gboolean focus_out (GtkWidget *widget);
62 static void column_visibility_changed
66 static void destroy_count_func (GtkTreeView *tree_view,
73 static void set_iter_nth_row (GtkTreeView *tree_view,
76 static gint get_row_from_tree_path (GtkTreeView *tree_view,
78 static GtkTreeViewColumn* get_column (GtkTreeView *tree_view,
80 static gint get_actual_column_number (GtkTreeView *tree_view,
82 static gint get_visible_column_number (GtkTreeView *tree_view,
84 static void iterate_thru_children (GtkTreeView *tree_view,
85 GtkTreeModel *tree_model,
86 GtkTreePath *tree_path,
90 static void clean_rows (GtkTreeViewAccessible *tree_view);
91 static void clean_cols (GtkTreeViewAccessible *tree_view,
92 GtkTreeViewColumn *tv_col);
93 static void traverse_cells (GtkTreeViewAccessible *tree_view,
94 GtkTreePath *tree_path,
97 static gboolean update_cell_value (GtkRendererCellAccessible *renderer_cell,
98 GtkTreeViewAccessible *accessible,
99 gboolean emit_change_signal);
100 static void set_cell_visibility (GtkTreeView *tree_view,
101 GtkCellAccessible *cell,
102 GtkTreeViewColumn *tv_col,
103 GtkTreePath *tree_path,
104 gboolean emit_signal);
105 static gboolean is_cell_showing (GtkTreeView *tree_view,
106 GdkRectangle *cell_rect);
107 static void set_expand_state (GtkTreeView *tree_view,
108 GtkTreeModel *tree_model,
109 GtkTreeViewAccessible *accessible,
110 GtkTreePath *tree_path,
111 gboolean set_on_ancestor);
112 static void set_cell_expandable (GtkCellAccessible *cell);
113 static void add_cell_actions (GtkCellAccessible *cell,
116 static void toggle_cell_toggled (GtkCellAccessible *cell);
117 static void edit_cell (GtkCellAccessible *cell);
118 static void activate_cell (GtkCellAccessible *cell);
119 static void cell_destroyed (gpointer data);
120 static void cell_info_new (GtkTreeViewAccessible *accessible,
121 GtkTreeModel *tree_model,
123 GtkTreeViewColumn *tv_col,
124 GtkCellAccessible *cell);
125 static GtkCellAccessible *find_cell (GtkTreeViewAccessible *accessible,
127 static void refresh_cell_index (GtkCellAccessible *cell);
128 static void connect_model_signals (GtkTreeView *view,
129 GtkTreeViewAccessible *accessible);
130 static void disconnect_model_signals (GtkTreeViewAccessible *accessible);
131 static void clear_cached_data (GtkTreeViewAccessible *view);
132 static gint get_column_number (GtkTreeView *tree_view,
133 GtkTreeViewColumn *column,
135 static gint get_focus_index (GtkTreeView *tree_view);
136 static gint get_index (GtkTreeView *tree_view,
139 static void count_rows (GtkTreeModel *model,
141 GtkTreePath *end_path,
146 static gboolean get_path_column_from_index (GtkTreeView *tree_view,
149 GtkTreeViewColumn **column);
151 static GtkTreeViewAccessibleCellInfo* find_cell_info (GtkTreeViewAccessible *view,
152 GtkCellAccessible *cell,
154 static AtkObject * get_header_from_column (GtkTreeViewColumn *tv_col);
155 static gboolean idle_garbage_collect_cell_data (gpointer data);
158 static void atk_table_interface_init (AtkTableIface *iface);
159 static void atk_selection_interface_init (AtkSelectionIface *iface);
160 static void atk_component_interface_init (AtkComponentIface *iface);
161 static void gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface);
163 G_DEFINE_TYPE_WITH_CODE (GtkTreeViewAccessible, _gtk_tree_view_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
164 G_IMPLEMENT_INTERFACE (ATK_TYPE_TABLE, atk_table_interface_init)
165 G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init)
166 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init)
167 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_ACCESSIBLE_PARENT, gtk_cell_accessible_parent_interface_init))
171 adjustment_changed (GtkAdjustment *adjustment,
174 GtkTreeViewAccessible *accessible;
176 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
177 traverse_cells (accessible, NULL, FALSE, FALSE);
181 hadjustment_set_cb (GObject *widget,
185 GtkTreeViewAccessible *accessible = data;
188 g_object_get (widget, "hadjustment", &adj, NULL);
189 accessible->old_hadj = adj;
190 g_object_add_weak_pointer (G_OBJECT (accessible->old_hadj), (gpointer *)&accessible->old_hadj);
191 g_signal_connect (adj, "value-changed", G_CALLBACK (adjustment_changed), widget);
195 vadjustment_set_cb (GObject *widget,
199 GtkTreeViewAccessible *accessible = data;
202 g_object_get (widget, "vadjustment", &adj, NULL);
203 accessible->old_vadj = adj;
204 g_object_add_weak_pointer (G_OBJECT (accessible->old_vadj), (gpointer *)&accessible->old_vadj);
205 g_signal_connect (adj, "value-changed",
206 G_CALLBACK (adjustment_changed), widget);
210 gtk_tree_view_accessible_initialize (AtkObject *obj,
213 GtkTreeViewAccessible *accessible;
214 GtkTreeView *tree_view;
215 GtkTreeModel *tree_model;
216 GList *tv_cols, *tmp_list;
218 GtkTreeSelection *selection;
220 ATK_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->initialize (obj, data);
222 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
223 accessible->col_data = NULL;
224 accessible->focus_cell = NULL;
225 accessible->old_hadj = NULL;
226 accessible->old_vadj = NULL;
227 accessible->idle_expand_id = 0;
228 accessible->idle_expand_path = NULL;
229 accessible->n_children_deleted = 0;
231 accessible->cell_info_by_index = g_hash_table_new (g_int_hash, g_int_equal);
233 widget = GTK_WIDGET (data);
234 tree_view = GTK_TREE_VIEW (widget);
235 tree_model = gtk_tree_view_get_model (tree_view);
236 selection = gtk_tree_view_get_selection (tree_view);
238 g_signal_connect_after (widget, "row-collapsed",
239 G_CALLBACK (row_collapsed_cb), NULL);
240 g_signal_connect (widget, "row-expanded",
241 G_CALLBACK (row_expanded_cb), NULL);
242 g_signal_connect (widget, "size-allocate",
243 G_CALLBACK (size_allocate_cb), NULL);
244 g_signal_connect (selection, "changed",
245 G_CALLBACK (selection_changed_cb), obj);
247 g_signal_connect (tree_view, "columns-changed",
248 G_CALLBACK (columns_changed), NULL);
249 g_signal_connect (tree_view, "cursor-changed",
250 G_CALLBACK (cursor_changed), NULL);
251 g_signal_connect (tree_view, "focus-in-event",
252 G_CALLBACK (focus_in), NULL);
253 g_signal_connect (tree_view, "focus-out-event",
254 G_CALLBACK (focus_out), NULL);
256 accessible->tree_model = tree_model;
257 accessible->n_rows = 0;
258 accessible->n_cols = 0;
261 g_object_add_weak_pointer (G_OBJECT (accessible->tree_model), (gpointer *)&accessible->tree_model);
262 count_rows (tree_model, NULL, NULL, &accessible->n_rows, 0, G_MAXINT);
263 connect_model_signals (tree_view, accessible);
265 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
266 obj->role = ATK_ROLE_TABLE;
268 obj->role = ATK_ROLE_TREE_TABLE;
271 hadjustment_set_cb (G_OBJECT (widget), NULL, accessible);
272 vadjustment_set_cb (G_OBJECT (widget), NULL, accessible);
273 g_signal_connect (widget, "notify::hadjustment",
274 G_CALLBACK (hadjustment_set_cb), accessible);
275 g_signal_connect (widget, "notify::vadjustment",
276 G_CALLBACK (vadjustment_set_cb), accessible);
278 accessible->col_data = g_array_sized_new (FALSE, TRUE,
279 sizeof (GtkTreeViewColumn *), 0);
281 tv_cols = gtk_tree_view_get_columns (tree_view);
282 for (tmp_list = tv_cols; tmp_list; tmp_list = tmp_list->next)
284 accessible->n_cols++;
285 g_signal_connect (tmp_list->data, "notify::visible",
286 G_CALLBACK (column_visibility_changed), tree_view);
287 g_array_append_val (accessible->col_data, tmp_list->data);
289 g_list_free (tv_cols);
291 gtk_tree_view_set_destroy_count_func (tree_view,
297 gtk_tree_view_accessible_finalize (GObject *object)
299 GtkTreeViewAccessible *accessible = GTK_TREE_VIEW_ACCESSIBLE (object);
301 clear_cached_data (accessible);
303 /* remove any idle handlers still pending */
304 if (accessible->idle_garbage_collect_id)
305 g_source_remove (accessible->idle_garbage_collect_id);
306 if (accessible->idle_cursor_changed_id)
307 g_source_remove (accessible->idle_cursor_changed_id);
308 if (accessible->idle_expand_id)
309 g_source_remove (accessible->idle_expand_id);
311 if (accessible->tree_model)
312 disconnect_model_signals (accessible);
314 if (accessible->cell_info_by_index)
315 g_hash_table_destroy (accessible->cell_info_by_index);
317 if (accessible->col_data)
319 GArray *array = accessible->col_data;
321 /* No need to free the contents of the array since it
322 * just contains pointers to the GtkTreeViewColumn
323 * objects that are in the GtkTreeView.
325 g_array_free (array, TRUE);
328 G_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->finalize (object);
332 gtk_tree_view_accessible_notify_gtk (GObject *obj,
336 GtkTreeView *tree_view;
337 GtkTreeViewAccessible *accessible;
340 widget = GTK_WIDGET (obj);
341 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
342 tree_view = GTK_TREE_VIEW (widget);
344 if (g_strcmp0 (pspec->name, "model") == 0)
346 GtkTreeModel *tree_model;
349 tree_model = gtk_tree_view_get_model (tree_view);
350 if (accessible->tree_model)
351 disconnect_model_signals (accessible);
352 clear_cached_data (accessible);
353 accessible->tree_model = tree_model;
354 accessible->n_rows = 0;
358 g_object_add_weak_pointer (G_OBJECT (accessible->tree_model), (gpointer *)&accessible->tree_model);
359 count_rows (tree_model, NULL, NULL, &accessible->n_rows, 0, G_MAXINT);
360 connect_model_signals (tree_view, accessible);
362 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
363 role = ATK_ROLE_TABLE;
365 role = ATK_ROLE_TREE_TABLE;
369 role = ATK_ROLE_UNKNOWN;
371 atk_object_set_role (ATK_OBJECT (accessible), role);
372 g_object_freeze_notify (G_OBJECT (accessible));
373 g_signal_emit_by_name (accessible, "model-changed");
374 g_signal_emit_by_name (accessible, "visible-data-changed");
375 g_object_thaw_notify (G_OBJECT (accessible));
377 else if (g_strcmp0 (pspec->name, "hadjustment") == 0)
379 g_object_get (tree_view, "hadjustment", &adj, NULL);
380 g_signal_handlers_disconnect_by_func (accessible->old_hadj,
381 (gpointer) adjustment_changed,
383 accessible->old_hadj = adj;
384 g_object_add_weak_pointer (G_OBJECT (accessible->old_hadj), (gpointer *)&accessible->old_hadj);
385 g_signal_connect (adj, "value-changed", G_CALLBACK (adjustment_changed), tree_view);
387 else if (g_strcmp0 (pspec->name, "vadjustment") == 0)
389 g_object_get (tree_view, "vadjustment", &adj, NULL);
390 g_signal_handlers_disconnect_by_func (accessible->old_vadj,
391 (gpointer) adjustment_changed,
393 accessible->old_vadj = adj;
394 g_object_add_weak_pointer (G_OBJECT (accessible->old_hadj), (gpointer *)&accessible->old_vadj);
395 g_signal_connect (adj, "value-changed", G_CALLBACK (adjustment_changed), tree_view);
398 GTK_WIDGET_ACCESSIBLE_CLASS (_gtk_tree_view_accessible_parent_class)->notify_gtk (obj, pspec);
402 gtk_tree_view_accessible_destroyed (GtkWidget *widget,
403 GtkAccessible *gtk_accessible)
406 GtkTreeViewAccessible *accessible;
408 if (!GTK_IS_TREE_VIEW (widget))
411 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_accessible);
412 adj = accessible->old_hadj;
414 g_signal_handlers_disconnect_by_func (adj,
415 (gpointer) adjustment_changed,
417 adj = accessible->old_vadj;
419 g_signal_handlers_disconnect_by_func (adj,
420 (gpointer) adjustment_changed,
422 if (accessible->tree_model)
424 disconnect_model_signals (accessible);
425 accessible->tree_model = NULL;
427 if (accessible->focus_cell)
429 g_object_unref (accessible->focus_cell);
430 accessible->focus_cell = NULL;
432 if (accessible->idle_expand_id)
434 g_source_remove (accessible->idle_expand_id);
435 accessible->idle_expand_id = 0;
440 gtk_tree_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
444 widget = gtk_accessible_get_widget (accessible);
446 g_signal_connect_after (widget, "destroy",
447 G_CALLBACK (gtk_tree_view_accessible_destroyed), accessible);
449 GTK_ACCESSIBLE_CLASS (_gtk_tree_view_accessible_parent_class)->connect_widget_destroyed (accessible);
453 gtk_tree_view_accessible_get_n_children (AtkObject *obj)
456 GtkTreeViewAccessible *accessible;
458 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
462 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
463 return (accessible->n_rows + 1) * accessible->n_cols;
467 gtk_tree_view_accessible_ref_child (AtkObject *obj,
471 GtkTreeViewAccessible *accessible;
472 GtkCellAccessible *cell;
473 GtkTreeView *tree_view;
474 GtkTreeModel *tree_model;
475 GtkCellRenderer *renderer;
477 GtkTreeViewColumn *tv_col;
478 GtkTreeSelection *selection;
482 GtkTreeViewColumn *expander_tv;
483 GList *renderer_list;
485 GtkContainerCellAccessible *container = NULL;
486 GtkRendererCellAccessible *renderer_cell;
487 gboolean is_expander, is_expanded, retval;
488 gboolean editable = FALSE;
491 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
495 if (i >= gtk_tree_view_accessible_get_n_children (obj))
498 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
499 tree_view = GTK_TREE_VIEW (widget);
500 if (i < accessible->n_cols)
502 tv_col = gtk_tree_view_get_column (tree_view, i);
503 child = get_header_from_column (tv_col);
505 g_object_ref (child);
509 /* Check whether the child is cached */
510 cell = find_cell (accessible, i);
514 return ATK_OBJECT (cell);
517 if (accessible->focus_cell == NULL)
518 focus_index = get_focus_index (tree_view);
522 /* Find the TreePath and GtkTreeViewColumn for the index */
523 if (!get_path_column_from_index (tree_view, i, &path, &tv_col))
526 tree_model = gtk_tree_view_get_model (tree_view);
527 retval = gtk_tree_model_get_iter (tree_model, &iter, path);
531 expander_tv = gtk_tree_view_get_expander_column (tree_view);
534 if (gtk_tree_model_iter_has_child (tree_model, &iter))
536 if (expander_tv == tv_col)
539 is_expanded = gtk_tree_view_row_expanded (tree_view, path);
542 gtk_tree_view_column_cell_set_cell_data (tv_col, tree_model, &iter,
543 is_expander, is_expanded);
545 renderer_list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
547 /* If there are more than one renderer in the list,
550 if (renderer_list && renderer_list->next)
552 GtkCellAccessible *container_cell;
554 container = _gtk_container_cell_accessible_new ();
556 container_cell = GTK_CELL_ACCESSIBLE (container);
557 _gtk_cell_accessible_initialise (container_cell, widget, ATK_OBJECT (accessible), i);
559 /* The GtkTreeViewAccessibleCellInfo structure for the container will
560 * be before the ones for the cells so that the first one we find for
561 * a position will be for the container
563 cell_info_new (accessible, tree_model, path, tv_col, container_cell);
564 container_cell->refresh_index = refresh_cell_index;
565 parent = ATK_OBJECT (container);
568 parent = ATK_OBJECT (accessible);
572 /* Now we make a fake cell_renderer if there is no cell
575 if (renderer_list == NULL)
577 GtkCellRenderer *fake_renderer;
579 fake_renderer = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, NULL);
580 child = _gtk_text_cell_accessible_new ();
581 cell = GTK_CELL_ACCESSIBLE (child);
582 renderer_cell = GTK_RENDERER_CELL_ACCESSIBLE (child);
583 renderer_cell->renderer = fake_renderer;
585 /* Create the GtkTreeViewAccessibleCellInfo structure for this cell */
586 cell_info_new (accessible, tree_model, path, tv_col, cell);
588 _gtk_cell_accessible_initialise (cell, widget, parent, i);
590 cell->refresh_index = refresh_cell_index;
592 /* Set state if it is expandable */
595 set_cell_expandable (cell);
597 _gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, FALSE);
602 for (l = renderer_list; l; l = l->next)
604 renderer = GTK_CELL_RENDERER (l->data);
606 if (GTK_IS_CELL_RENDERER_TEXT (renderer))
608 g_object_get (G_OBJECT (renderer), "editable", &editable, NULL);
609 child = _gtk_text_cell_accessible_new ();
611 else if (GTK_IS_CELL_RENDERER_TOGGLE (renderer))
612 child = _gtk_boolean_cell_accessible_new ();
613 else if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
614 child = _gtk_image_cell_accessible_new ();
616 child = _gtk_renderer_cell_accessible_new ();
618 cell = GTK_CELL_ACCESSIBLE (child);
619 renderer_cell = GTK_RENDERER_CELL_ACCESSIBLE (child);
621 /* Create the GtkTreeViewAccessibleCellInfo for this cell */
622 cell_info_new (accessible, tree_model, path, tv_col, cell);
624 _gtk_cell_accessible_initialise (cell, widget, parent, i);
627 _gtk_container_cell_accessible_add_child (container, cell);
629 cell->refresh_index = refresh_cell_index;
631 update_cell_value (renderer_cell, accessible, FALSE);
633 /* Add the actions appropriate for this cell */
634 add_cell_actions (cell, editable);
636 /* Set state if it is expandable */
639 set_cell_expandable (cell);
641 _gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, FALSE);
644 /* If the column is visible, sets the cell's state */
645 if (gtk_tree_view_column_get_visible (tv_col))
646 set_cell_visibility (tree_view, cell, tv_col, path, FALSE);
648 /* If the row is selected, all cells on the row are selected */
649 selection = gtk_tree_view_get_selection (tree_view);
651 if (gtk_tree_selection_path_is_selected (selection, path))
652 _gtk_cell_accessible_add_state (cell, ATK_STATE_SELECTED, FALSE);
654 _gtk_cell_accessible_add_state (cell, ATK_STATE_FOCUSABLE, FALSE);
655 if (focus_index == i)
657 accessible->focus_cell = g_object_ref (cell);
658 _gtk_cell_accessible_add_state (cell, ATK_STATE_FOCUSED, FALSE);
659 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
662 g_list_free (renderer_list);
664 child = ATK_OBJECT (container);
667 if (expander_tv == tv_col)
669 AtkRelationSet *relation_set;
670 AtkObject *accessible_array[1];
671 AtkRelation* relation;
672 AtkObject *parent_node;
674 relation_set = atk_object_ref_relation_set (ATK_OBJECT (child));
676 gtk_tree_path_up (path);
677 if (gtk_tree_path_get_depth (path) == 0)
683 parent_index = get_index (tree_view, path, i % accessible->n_cols);
684 parent_node = atk_object_ref_accessible_child (obj, parent_index);
686 accessible_array[0] = parent_node;
687 relation = atk_relation_new (accessible_array, 1,
688 ATK_RELATION_NODE_CHILD_OF);
689 atk_relation_set_add (relation_set, relation);
690 atk_object_add_relationship (parent_node, ATK_RELATION_NODE_PARENT_OF, child);
691 g_object_unref (relation);
692 g_object_unref (relation_set);
694 gtk_tree_path_free (path);
696 /* We do not increase the reference count here; when g_object_unref()
697 * is called for the cell then cell_destroyed() is called and this
698 * removes the cell from the cache.
704 gtk_tree_view_accessible_ref_state_set (AtkObject *obj)
706 AtkStateSet *state_set;
709 state_set = ATK_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->ref_state_set (obj);
710 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
713 atk_state_set_add_state (state_set, ATK_STATE_MANAGES_DESCENDANTS);
719 _gtk_tree_view_accessible_class_init (GtkTreeViewAccessibleClass *klass)
721 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
722 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
723 GtkAccessibleClass *accessible_class = (GtkAccessibleClass*)klass;
724 GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
725 GtkContainerAccessibleClass *container_class = (GtkContainerAccessibleClass*)klass;
727 class->get_n_children = gtk_tree_view_accessible_get_n_children;
728 class->ref_child = gtk_tree_view_accessible_ref_child;
729 class->ref_state_set = gtk_tree_view_accessible_ref_state_set;
730 class->initialize = gtk_tree_view_accessible_initialize;
732 widget_class->notify_gtk = gtk_tree_view_accessible_notify_gtk;
734 accessible_class->connect_widget_destroyed = gtk_tree_view_accessible_connect_widget_destroyed;
736 /* The children of a GtkTreeView are the buttons at the top of the columns
737 * we do not represent these as children so we do not want to report
738 * children added or deleted when these changed.
740 container_class->add_gtk = NULL;
741 container_class->remove_gtk = NULL;
743 gobject_class->finalize = gtk_tree_view_accessible_finalize;
747 _gtk_tree_view_accessible_init (GtkTreeViewAccessible *view)
752 get_focus_index (GtkTreeView *tree_view)
754 GtkTreePath *focus_path;
755 GtkTreeViewColumn *focus_column;
758 gtk_tree_view_get_cursor (tree_view, &focus_path, &focus_column);
759 if (focus_path && focus_column)
760 index = get_index (tree_view, focus_path,
761 get_column_number (tree_view, focus_column, FALSE));
766 gtk_tree_path_free (focus_path);
771 /* This function returns a reference to the accessible object
772 * for the cell in the treeview which has focus, if any
775 gtk_tree_view_accessible_ref_focus_cell (GtkTreeView *tree_view)
777 AtkObject *focus_cell = NULL;
781 focus_index = get_focus_index (tree_view);
782 if (focus_index >= 0)
784 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
785 focus_cell = atk_object_ref_accessible_child (atk_obj, focus_index);
794 gtk_tree_view_accessible_ref_accessible_at_point (AtkComponent *component,
797 AtkCoordType coord_type)
800 GtkTreeView *tree_view;
802 GtkTreeViewColumn *tv_column;
807 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
811 tree_view = GTK_TREE_VIEW (widget);
813 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
814 gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, x, y, &bx, &by);
815 ret_val = gtk_tree_view_get_path_at_pos (tree_view,
816 bx - x_pos, by - y_pos,
817 &path, &tv_column, NULL, NULL);
822 column = get_column_number (tree_view, tv_column, FALSE);
823 index = get_index (tree_view, path, column);
824 gtk_tree_path_free (path);
826 return gtk_tree_view_accessible_ref_child (ATK_OBJECT (component), index);
830 g_warning ("gtk_tree_view_accessible_ref_accessible_at_point: gtk_tree_view_get_path_at_pos () failed\n");
836 atk_component_interface_init (AtkComponentIface *iface)
838 iface->ref_accessible_at_point = gtk_tree_view_accessible_ref_accessible_at_point;
844 gtk_tree_view_accessible_get_index_at (AtkTable *table,
849 GtkTreeView *tree_view;
856 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
860 n_cols = atk_table_get_n_columns (table);
861 n_rows = atk_table_get_n_rows (table);
863 if (row >= n_rows || column >= n_cols)
866 tree_view = GTK_TREE_VIEW (widget);
867 actual_column = get_actual_column_number (tree_view, column);
869 set_iter_nth_row (tree_view, &iter, row);
870 path = gtk_tree_model_get_path (gtk_tree_view_get_model (tree_view), &iter);
872 index = get_index (tree_view, path, actual_column);
873 gtk_tree_path_free (path);
879 gtk_tree_view_accessible_get_column_at_index (AtkTable *table,
883 GtkTreeView *tree_view;
886 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
890 tree_view = GTK_TREE_VIEW (widget);
891 n_columns = GTK_TREE_VIEW_ACCESSIBLE (table)->n_cols;
896 index = index % n_columns;
898 return get_visible_column_number (tree_view, index);
902 gtk_tree_view_accessible_get_row_at_index (AtkTable *table,
906 GtkTreeView *tree_view;
909 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
913 tree_view = GTK_TREE_VIEW (widget);
914 if (get_path_column_from_index (tree_view, index, &path, NULL))
916 gint row = get_row_from_tree_path (tree_view, path);
917 gtk_tree_path_free (path);
925 gtk_tree_view_accessible_table_ref_at (AtkTable *table,
931 index = gtk_tree_view_accessible_get_index_at (table, row, column);
935 return gtk_tree_view_accessible_ref_child (ATK_OBJECT (table), index);
939 gtk_tree_view_accessible_get_n_rows (AtkTable *table)
942 GtkTreeView *tree_view;
943 GtkTreeModel *tree_model;
946 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
950 tree_view = GTK_TREE_VIEW (widget);
951 tree_model = gtk_tree_view_get_model (tree_view);
955 else if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
956 /* No collapsed rows in a list store */
957 n_rows = GTK_TREE_VIEW_ACCESSIBLE (table)->n_rows;
960 GtkTreePath *root_tree;
963 root_tree = gtk_tree_path_new_first ();
964 iterate_thru_children (tree_view, tree_model,
965 root_tree, NULL, &n_rows, 0);
966 gtk_tree_path_free (root_tree);
973 gtk_tree_view_accessible_get_n_columns (AtkTable *table)
976 GtkTreeView *tree_view;
977 GtkTreeViewColumn *tv_col;
981 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
985 tree_view = GTK_TREE_VIEW (widget);
986 tv_col = gtk_tree_view_get_column (tree_view, i);
988 while (tv_col != NULL)
990 if (gtk_tree_view_column_get_visible (tv_col))
994 tv_col = gtk_tree_view_get_column (tree_view, i);
1001 gtk_tree_view_accessible_is_row_selected (AtkTable *table,
1005 GtkTreeView *tree_view;
1006 GtkTreeSelection *selection;
1009 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1016 tree_view = GTK_TREE_VIEW (widget);
1017 selection = gtk_tree_view_get_selection (tree_view);
1019 set_iter_nth_row (tree_view, &iter, row);
1020 return gtk_tree_selection_iter_is_selected (selection, &iter);
1024 gtk_tree_view_accessible_is_selected (AtkTable *table,
1028 return gtk_tree_view_accessible_is_row_selected (table, row);
1032 get_selected_rows (GtkTreeModel *model,
1037 GPtrArray *array = (GPtrArray *)data;
1039 g_ptr_array_add (array, gtk_tree_path_copy (path));
1043 gtk_tree_view_accessible_get_selected_rows (AtkTable *table,
1044 gint **rows_selected)
1047 GtkTreeView *tree_view;
1048 GtkTreeModel *tree_model;
1050 GtkTreeSelection *selection;
1051 GtkTreePath *tree_path;
1054 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1058 tree_view = GTK_TREE_VIEW (widget);
1059 selection = gtk_tree_view_get_selection (tree_view);
1061 switch (gtk_tree_selection_get_mode (selection))
1063 case GTK_SELECTION_SINGLE:
1064 case GTK_SELECTION_BROWSE:
1065 if (gtk_tree_selection_get_selected (selection, &tree_model, &iter))
1071 *rows_selected = g_new (gint, 1);
1072 tree_path = gtk_tree_model_get_path (tree_model, &iter);
1073 row = get_row_from_tree_path (tree_view, tree_path);
1074 gtk_tree_path_free (tree_path);
1076 /* shouldn't ever happen */
1077 g_return_val_if_fail (row != -1, 0);
1079 *rows_selected[0] = row;
1084 case GTK_SELECTION_MULTIPLE:
1086 GPtrArray *array = g_ptr_array_new();
1088 gtk_tree_selection_selected_foreach (selection, get_selected_rows, array);
1089 ret_val = array->len;
1091 if (rows_selected && ret_val)
1095 *rows_selected = g_new (gint, ret_val);
1096 for (i = 0; i < ret_val; i++)
1100 tree_path = (GtkTreePath *) g_ptr_array_index (array, i);
1101 row = get_row_from_tree_path (tree_view, tree_path);
1102 gtk_tree_path_free (tree_path);
1103 (*rows_selected)[i] = row;
1106 g_ptr_array_free (array, FALSE);
1109 case GTK_SELECTION_NONE:
1116 gtk_tree_view_accessible_add_row_selection (AtkTable *table,
1120 GtkTreeView *tree_view;
1121 GtkTreeModel *tree_model;
1122 GtkTreeSelection *selection;
1123 GtkTreePath *tree_path;
1124 GtkTreeIter iter_to_row;
1126 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1130 if (!gtk_tree_view_accessible_is_row_selected (table, row))
1132 tree_view = GTK_TREE_VIEW (widget);
1133 tree_model = gtk_tree_view_get_model (tree_view);
1134 selection = gtk_tree_view_get_selection (tree_view);
1136 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
1138 tree_path = gtk_tree_path_new ();
1139 gtk_tree_path_append_index (tree_path, row);
1140 gtk_tree_selection_select_path (selection,tree_path);
1141 gtk_tree_path_free (tree_path);
1145 set_iter_nth_row (tree_view, &iter_to_row, row);
1146 gtk_tree_selection_select_iter (selection, &iter_to_row);
1150 return gtk_tree_view_accessible_is_row_selected (table, row);
1154 gtk_tree_view_accessible_remove_row_selection (AtkTable *table,
1158 GtkTreeView *tree_view;
1159 GtkTreeSelection *selection;
1161 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1165 tree_view = GTK_TREE_VIEW (widget);
1166 selection = gtk_tree_view_get_selection (tree_view);
1168 if (gtk_tree_view_accessible_is_row_selected (table, row))
1170 gtk_tree_selection_unselect_all (selection);
1178 gtk_tree_view_accessible_get_column_header (AtkTable *table,
1182 GtkTreeView *tree_view;
1183 GtkTreeViewColumn *tv_col;
1185 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1189 tree_view = GTK_TREE_VIEW (widget);
1190 tv_col = get_column (tree_view, in_col);
1191 return get_header_from_column (tv_col);
1194 static const gchar *
1195 gtk_tree_view_accessible_get_column_description (AtkTable *table,
1199 GtkTreeView *tree_view;
1200 GtkTreeViewColumn *tv_col;
1202 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1206 tree_view = GTK_TREE_VIEW (widget);
1207 tv_col = get_column (tree_view, in_col);
1211 return gtk_tree_view_column_get_title (tv_col);
1215 atk_table_interface_init (AtkTableIface *iface)
1217 iface->ref_at = gtk_tree_view_accessible_table_ref_at;
1218 iface->get_n_rows = gtk_tree_view_accessible_get_n_rows;
1219 iface->get_n_columns = gtk_tree_view_accessible_get_n_columns;
1220 iface->get_index_at = gtk_tree_view_accessible_get_index_at;
1221 iface->get_column_at_index = gtk_tree_view_accessible_get_column_at_index;
1222 iface->get_row_at_index = gtk_tree_view_accessible_get_row_at_index;
1223 iface->is_row_selected = gtk_tree_view_accessible_is_row_selected;
1224 iface->is_selected = gtk_tree_view_accessible_is_selected;
1225 iface->get_selected_rows = gtk_tree_view_accessible_get_selected_rows;
1226 iface->add_row_selection = gtk_tree_view_accessible_add_row_selection;
1227 iface->remove_row_selection = gtk_tree_view_accessible_remove_row_selection;
1228 iface->get_column_extent_at = NULL;
1229 iface->get_row_extent_at = NULL;
1230 iface->get_column_header = gtk_tree_view_accessible_get_column_header;
1231 iface->get_column_description = gtk_tree_view_accessible_get_column_description;
1234 /* atkselection.h */
1237 gtk_tree_view_accessible_add_selection (AtkSelection *selection,
1244 table = ATK_TABLE (selection);
1245 n_columns = gtk_tree_view_accessible_get_n_columns (table);
1249 row = gtk_tree_view_accessible_get_row_at_index (table, i);
1250 return gtk_tree_view_accessible_add_row_selection (table, row);
1254 gtk_tree_view_accessible_clear_selection (AtkSelection *selection)
1257 GtkTreeView *tree_view;
1258 GtkTreeSelection *tree_selection;
1260 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
1264 tree_view = GTK_TREE_VIEW (widget);
1265 tree_selection = gtk_tree_view_get_selection (tree_view);
1267 gtk_tree_selection_unselect_all (tree_selection);
1272 gtk_tree_view_accessible_ref_selection (AtkSelection *selection,
1281 table = ATK_TABLE (selection);
1282 n_columns = gtk_tree_view_accessible_get_n_columns (table);
1283 n_selected = gtk_tree_view_accessible_get_selected_rows (table, &selected);
1284 if (i >= n_columns * n_selected)
1287 row = selected[i / n_columns];
1290 return gtk_tree_view_accessible_table_ref_at (table, row, i % n_columns);
1294 gtk_tree_view_accessible_get_selection_count (AtkSelection *selection)
1299 table = ATK_TABLE (selection);
1300 n_selected = gtk_tree_view_accessible_get_selected_rows (table, NULL);
1302 n_selected *= gtk_tree_view_accessible_get_n_columns (table);
1307 gtk_tree_view_accessible_is_child_selected (AtkSelection *selection,
1313 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
1317 row = atk_table_get_row_at_index (ATK_TABLE (selection), i);
1319 return gtk_tree_view_accessible_is_row_selected (ATK_TABLE (selection), row);
1322 static void atk_selection_interface_init (AtkSelectionIface *iface)
1324 iface->add_selection = gtk_tree_view_accessible_add_selection;
1325 iface->clear_selection = gtk_tree_view_accessible_clear_selection;
1326 iface->ref_selection = gtk_tree_view_accessible_ref_selection;
1327 iface->get_selection_count = gtk_tree_view_accessible_get_selection_count;
1328 iface->is_child_selected = gtk_tree_view_accessible_is_child_selected;
1331 #define EXTRA_EXPANDER_PADDING 4
1334 gtk_tree_view_accessible_get_cell_area (GtkCellAccessibleParent *parent,
1335 GtkCellAccessible *cell,
1336 GdkRectangle *cell_rect)
1339 GtkTreeView *tree_view;
1340 GtkTreeViewColumn *tv_col;
1342 AtkObject *parent_cell;
1343 GtkTreeViewAccessibleCellInfo *cell_info;
1344 GtkCellAccessible *top_cell;
1346 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1350 tree_view = GTK_TREE_VIEW (widget);
1351 parent_cell = atk_object_get_parent (ATK_OBJECT (cell));
1352 if (parent_cell != ATK_OBJECT (parent))
1353 top_cell = GTK_CELL_ACCESSIBLE (parent_cell);
1356 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), top_cell, TRUE);
1357 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
1359 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
1360 tv_col = cell_info->cell_col_ref;
1361 if (path && cell_info->in_use)
1363 GtkTreeViewColumn *expander_column;
1364 gint focus_line_width;
1366 gtk_tree_view_get_cell_area (tree_view, path, tv_col, cell_rect);
1367 expander_column = gtk_tree_view_get_expander_column (tree_view);
1368 if (expander_column == tv_col)
1371 gtk_widget_style_get (widget,
1372 "expander-size", &expander_size,
1374 cell_rect->x += expander_size + EXTRA_EXPANDER_PADDING;
1375 cell_rect->width -= expander_size + EXTRA_EXPANDER_PADDING;
1377 gtk_widget_style_get (widget,
1378 "focus-line-width", &focus_line_width,
1381 cell_rect->x += focus_line_width;
1382 cell_rect->width -= 2 * focus_line_width;
1384 gtk_tree_path_free (path);
1386 /* A column has more than one renderer so we find the position
1389 if (top_cell != cell)
1396 GtkCellRenderer *renderer;
1398 cell_index = atk_object_get_index_in_parent (ATK_OBJECT (cell));
1399 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
1400 renderer = g_list_nth_data (renderers, cell_index);
1402 found = gtk_tree_view_column_cell_get_position (tv_col, renderer, &cell_start, &cell_width);
1405 cell_rect->x += cell_start;
1406 cell_rect->width = cell_width;
1408 g_list_free (renderers);
1415 gtk_tree_view_accessible_get_cell_extents (GtkCellAccessibleParent *parent,
1416 GtkCellAccessible *cell,
1421 AtkCoordType coord_type)
1424 GtkTreeView *tree_view;
1425 GdkWindow *bin_window;
1426 GdkRectangle cell_rect;
1429 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1433 tree_view = GTK_TREE_VIEW (widget);
1434 gtk_tree_view_accessible_get_cell_area (parent, cell, &cell_rect);
1435 bin_window = gtk_tree_view_get_bin_window (tree_view);
1436 gdk_window_get_origin (bin_window, &w_x, &w_y);
1438 if (coord_type == ATK_XY_WINDOW)
1441 gint x_toplevel, y_toplevel;
1443 window = gdk_window_get_toplevel (bin_window);
1444 gdk_window_get_origin (window, &x_toplevel, &y_toplevel);
1450 *width = cell_rect.width;
1451 *height = cell_rect.height;
1452 if (is_cell_showing (tree_view, &cell_rect))
1454 *x = cell_rect.x + w_x;
1455 *y = cell_rect.y + w_y;
1465 gtk_tree_view_accessible_grab_cell_focus (GtkCellAccessibleParent *parent,
1466 GtkCellAccessible *cell)
1469 GtkTreeView *tree_view;
1470 GtkTreeViewColumn *tv_col;
1472 AtkObject *parent_cell;
1473 AtkObject *cell_object;
1474 GtkTreeViewAccessibleCellInfo *cell_info;
1475 GtkCellRenderer *renderer = NULL;
1476 GtkWidget *toplevel;
1479 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1483 tree_view = GTK_TREE_VIEW (widget);
1485 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
1486 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
1488 cell_object = ATK_OBJECT (cell);
1489 parent_cell = atk_object_get_parent (cell_object);
1490 tv_col = cell_info->cell_col_ref;
1491 if (parent_cell != ATK_OBJECT (parent))
1493 /* GtkCellAccessible is in a GtkContainerCellAccessible.
1494 * The GtkTreeViewColumn has multiple renderers;
1495 * find the corresponding one.
1499 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
1500 if (cell_info->in_use)
1502 index = atk_object_get_index_in_parent (cell_object);
1503 renderer = g_list_nth_data (renderers, index);
1505 g_list_free (renderers);
1507 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
1508 if (path && cell_info->in_use)
1511 gtk_tree_view_set_cursor_on_cell (tree_view, path, tv_col, renderer, FALSE);
1513 gtk_tree_view_set_cursor (tree_view, path, tv_col, FALSE);
1515 gtk_tree_path_free (path);
1516 gtk_widget_grab_focus (widget);
1517 toplevel = gtk_widget_get_toplevel (widget);
1518 if (gtk_widget_is_toplevel (toplevel))
1520 #ifdef GDK_WINDOWING_X11
1521 gtk_window_present_with_time (GTK_WINDOW (toplevel),
1522 gdk_x11_get_server_time (gtk_widget_get_window (widget)));
1524 gtk_window_present (GTK_WINDOW (toplevel));
1535 gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface)
1537 iface->get_cell_extents = gtk_tree_view_accessible_get_cell_extents;
1538 iface->get_cell_area = gtk_tree_view_accessible_get_cell_area;
1539 iface->grab_focus = gtk_tree_view_accessible_grab_cell_focus;
1542 /* signal handling */
1545 idle_expand_row (gpointer data)
1547 GtkTreeViewAccessible *accessible = data;
1549 GtkTreeView *tree_view;
1551 GtkTreeModel *tree_model;
1552 gint n_inserted, row;
1554 accessible->idle_expand_id = 0;
1556 path = accessible->idle_expand_path;
1557 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
1559 tree_model = gtk_tree_view_get_model (tree_view);
1563 if (!path || !gtk_tree_model_get_iter (tree_model, &iter, path))
1566 /* Update visibility of cells below expansion row */
1567 traverse_cells (accessible, path, FALSE, FALSE);
1569 /* Figure out number of visible children, the following test
1572 if (gtk_tree_model_iter_has_child (tree_model, &iter))
1574 GtkTreePath *path_copy;
1576 /* By passing path into this function, we find the number of
1577 * visible children of path.
1579 path_copy = gtk_tree_path_copy (path);
1580 gtk_tree_path_append_index (path_copy, 0);
1583 iterate_thru_children (tree_view, tree_model,
1584 path_copy, NULL, &n_inserted, 0);
1585 gtk_tree_path_free (path_copy);
1589 /* We can get here if the row expanded callback deleted the row */
1593 /* Set expand state */
1594 set_expand_state (tree_view, tree_model, accessible, path, TRUE);
1596 row = get_row_from_tree_path (tree_view, path);
1598 /* shouldn't ever happen */
1600 g_assert_not_reached ();
1602 /* Must add 1 because the "added rows" are below the row being expanded */
1605 g_signal_emit_by_name (accessible, "row-inserted", row, n_inserted);
1607 accessible->idle_expand_path = NULL;
1609 gtk_tree_path_free (path);
1615 row_expanded_cb (GtkTreeView *tree_view,
1620 GtkTreeViewAccessible *accessible;
1622 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
1623 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1626 * The visible rectangle has not been updated when this signal is emitted
1627 * so we process the signal when the GTK processing is completed
1629 /* this seems wrong since it overwrites any other pending expand handlers... */
1630 accessible->idle_expand_path = gtk_tree_path_copy (path);
1631 if (accessible->idle_expand_id)
1632 g_source_remove (accessible->idle_expand_id);
1633 accessible->idle_expand_id = gdk_threads_add_idle (idle_expand_row, accessible);
1639 row_collapsed_cb (GtkTreeView *tree_view,
1643 GtkTreeModel *tree_model;
1645 GtkTreeViewAccessible *accessible;
1648 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
1649 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1650 tree_model = gtk_tree_view_get_model (tree_view);
1652 clean_rows (accessible);
1654 /* Update visibility of cells below collapsed row */
1655 traverse_cells (accessible, path, FALSE, FALSE);
1657 /* Set collapse state */
1658 set_expand_state (tree_view, tree_model, accessible, path, FALSE);
1659 if (accessible->n_children_deleted == 0)
1661 row = get_row_from_tree_path (tree_view, path);
1664 g_signal_emit_by_name (atk_obj, "row-deleted", row,
1665 accessible->n_children_deleted);
1666 accessible->n_children_deleted = 0;
1671 size_allocate_cb (GtkWidget *widget,
1672 GtkAllocation *allocation)
1675 GtkTreeViewAccessible *accessible;
1677 atk_obj = gtk_widget_get_accessible (widget);
1678 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1680 /* If the size allocation changes, the visibility of cells
1681 * may change so update the cells visibility.
1683 traverse_cells (accessible, NULL, FALSE, FALSE);
1687 selection_changed_cb (GtkTreeSelection *selection,
1690 GtkTreeViewAccessible *accessible;
1691 GtkTreeView *tree_view;
1693 GtkTreeViewAccessibleCellInfo *info;
1694 GtkTreeSelection *tree_selection;
1696 GHashTableIter iter;
1698 accessible = GTK_TREE_VIEW_ACCESSIBLE (data);
1699 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
1703 tree_view = GTK_TREE_VIEW (widget);
1704 tree_selection = gtk_tree_view_get_selection (tree_view);
1706 clean_rows (accessible);
1708 /* FIXME: clean rows iterates through all cells too */
1709 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
1710 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&info))
1714 _gtk_cell_accessible_remove_state (info->cell, ATK_STATE_SELECTED, TRUE);
1716 path = gtk_tree_row_reference_get_path (info->cell_row_ref);
1717 if (path && gtk_tree_selection_path_is_selected (tree_selection, path))
1718 _gtk_cell_accessible_add_state (info->cell, ATK_STATE_SELECTED, TRUE);
1719 gtk_tree_path_free (path);
1722 if (gtk_widget_get_realized (widget))
1723 g_signal_emit_by_name (accessible, "selection-changed");
1727 columns_changed (GtkTreeView *tree_view)
1730 GtkTreeViewAccessible *accessible;
1731 GList *tv_cols, *tmp_list;
1732 gboolean column_found;
1733 gboolean move_found = FALSE;
1734 gboolean stale_set = FALSE;
1735 gint column_count = 0;
1738 atk_obj = gtk_widget_get_accessible (GTK_WIDGET(tree_view));
1739 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1741 /* This function must determine if the change is an add, delete
1742 * or a move based upon its cache of TreeViewColumns in
1743 * accessible->col_data
1745 tv_cols = gtk_tree_view_get_columns (tree_view);
1746 accessible->n_cols = g_list_length (tv_cols);
1748 /* check for adds or moves */
1749 for (tmp_list = tv_cols; tmp_list; tmp_list = tmp_list->next)
1751 column_found = FALSE;
1753 for (i = 0; i < accessible->col_data->len; i++)
1756 if ((GtkTreeViewColumn *)tmp_list->data ==
1757 (GtkTreeViewColumn *)g_array_index (accessible->col_data,
1758 GtkTreeViewColumn *, i))
1760 column_found = TRUE;
1762 /* If the column isn't in the same position, a move happened */
1763 if (!move_found && i != column_count)
1767 /* Set all rows to ATK_STATE_STALE */
1768 traverse_cells (accessible, NULL, TRUE, FALSE);
1772 /* Just emit one column reordered signal when a move happens */
1773 g_signal_emit_by_name (atk_obj, "column-reordered");
1781 /* If column_found is FALSE, then an insert happened for column
1782 * number column_count
1790 /* Set all rows to ATK_STATE_STALE */
1791 traverse_cells (accessible, NULL, TRUE, FALSE);
1795 /* Generate column-inserted signal */
1796 g_signal_emit_by_name (atk_obj, "column-inserted", column_count, 1);
1798 /* Generate children-changed signals */
1799 for (row = 0; row < accessible->n_rows; row++)
1801 /* Pass NULL as the child object, i.e. 4th argument */
1802 g_signal_emit_by_name (atk_obj, "children-changed::add",
1803 ((row * accessible->n_cols) + column_count), NULL, NULL);
1810 /* check for deletes */
1811 for (i = 0; i < accessible->col_data->len; i++)
1813 column_found = FALSE;
1815 for (tmp_list = tv_cols; tmp_list; tmp_list = tmp_list->next)
1817 if ((GtkTreeViewColumn *)tmp_list->data ==
1818 (GtkTreeViewColumn *)g_array_index (accessible->col_data,
1819 GtkTreeViewColumn *, i))
1821 column_found = TRUE;
1826 /* If column_found is FALSE, then a delete happened for column
1833 clean_cols (accessible,
1834 (GtkTreeViewColumn *)g_array_index (accessible->col_data,
1835 GtkTreeViewColumn *, i));
1839 /* Set all rows to ATK_STATE_STALE */
1840 traverse_cells (accessible, NULL, TRUE, FALSE);
1844 /* Generate column-deleted signal */
1845 g_signal_emit_by_name (atk_obj, "column-deleted", i, 1);
1847 /* Generate children-changed signals */
1848 for (row = 0; row < accessible->n_rows; row++)
1850 /* Pass NULL as the child object, 4th argument */
1851 g_signal_emit_by_name (atk_obj, "children-changed::remove",
1852 ((row * accessible->n_cols) + column_count), NULL, NULL);
1857 /* rebuild the array */
1858 g_array_free (accessible->col_data, TRUE);
1859 accessible->col_data = g_array_sized_new (FALSE, TRUE, sizeof (GtkTreeViewColumn *), 0);
1861 for (tmp_list = tv_cols; tmp_list; tmp_list = tmp_list->next)
1862 g_array_append_val (accessible->col_data, tmp_list->data);
1863 g_list_free (tv_cols);
1867 idle_cursor_changed (gpointer data)
1869 GtkTreeViewAccessible *accessible = GTK_TREE_VIEW_ACCESSIBLE (data);
1870 GtkTreeView *tree_view;
1874 accessible->idle_cursor_changed_id = 0;
1876 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
1880 tree_view = GTK_TREE_VIEW (widget);
1882 cell = gtk_tree_view_accessible_ref_focus_cell (tree_view);
1885 if (cell != accessible->focus_cell)
1887 if (accessible->focus_cell)
1889 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_ACTIVE, FALSE);
1890 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_FOCUSED, FALSE);
1891 g_object_unref (accessible->focus_cell);
1892 accessible->focus_cell = cell;
1895 if (gtk_widget_has_focus (widget))
1897 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_ACTIVE, FALSE);
1898 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_FOCUSED, FALSE);
1901 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
1904 g_object_unref (cell);
1911 cursor_changed (GtkTreeView *tree_view)
1913 GtkTreeViewAccessible *accessible;
1915 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (tree_view)));
1916 if (accessible->idle_cursor_changed_id != 0)
1919 /* We notify the focus change in a idle handler so that the processing
1920 * of the cursor change is completed when the focus handler is called.
1921 * This will allow actions to be called in the focus handler
1923 accessible->idle_cursor_changed_id = gdk_threads_add_idle (idle_cursor_changed, accessible);
1927 focus_in (GtkWidget *widget)
1929 GtkTreeView *tree_view;
1930 GtkTreeViewAccessible *accessible;
1931 AtkStateSet *state_set;
1934 tree_view = GTK_TREE_VIEW (widget);
1935 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
1937 if (accessible->focus_cell == NULL)
1939 cell = gtk_tree_view_accessible_ref_focus_cell (tree_view);
1942 state_set = atk_object_ref_state_set (cell);
1945 if (!atk_state_set_contains_state (state_set, ATK_STATE_FOCUSED))
1947 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_ACTIVE, FALSE);
1948 accessible->focus_cell = cell;
1949 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_FOCUSED, FALSE);
1950 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
1952 g_object_unref (state_set);
1960 focus_out (GtkWidget *widget)
1962 GtkTreeViewAccessible *accessible;
1964 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
1965 if (accessible->focus_cell)
1967 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_ACTIVE, FALSE);
1968 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_FOCUSED, FALSE);
1969 g_object_unref (accessible->focus_cell);
1970 accessible->focus_cell = NULL;
1976 model_row_changed (GtkTreeModel *tree_model,
1981 GtkTreeView *tree_view = GTK_TREE_VIEW (user_data);
1982 GtkTreeViewAccessible *accessible;
1983 GtkTreePath *cell_path;
1984 GtkTreeViewAccessibleCellInfo *cell_info;
1985 GHashTableIter hash_iter;
1987 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (tree_view)));
1989 /* Loop through our cached cells */
1990 /* Must loop through them all */
1991 g_hash_table_iter_init (&hash_iter, accessible->cell_info_by_index);
1992 while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer *)&cell_info))
1994 if (cell_info->in_use)
1996 cell_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
1998 if (cell_path != NULL)
2000 if (path && gtk_tree_path_compare (cell_path, path) == 0)
2002 if (GTK_IS_RENDERER_CELL_ACCESSIBLE (cell_info->cell))
2003 update_cell_value (GTK_RENDERER_CELL_ACCESSIBLE (cell_info->cell),
2006 gtk_tree_path_free (cell_path);
2010 g_signal_emit_by_name (accessible, "visible-data-changed");
2014 column_visibility_changed (GObject *object,
2018 if (g_strcmp0 (pspec->name, "visible") == 0)
2020 /* A column has been made visible or invisible
2021 * We update our cache of cells and emit model_changed signal
2023 GtkTreeView *tree_view = (GtkTreeView *)user_data;
2024 GtkTreeViewAccessible *accessible;
2025 GtkTreeViewAccessibleCellInfo *cell_info;
2026 GtkTreeViewColumn *this_col = GTK_TREE_VIEW_COLUMN (object);
2027 GtkTreeViewColumn *tv_col;
2028 GHashTableIter iter;
2030 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (tree_view))
2032 g_signal_emit_by_name (accessible, "model-changed");
2034 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
2035 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
2037 if (cell_info->in_use)
2039 tv_col = cell_info->cell_col_ref;
2040 if (tv_col == this_col)
2042 GtkTreePath *row_path;
2043 row_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2044 if (GTK_IS_RENDERER_CELL_ACCESSIBLE (cell_info->cell))
2046 if (gtk_tree_view_column_get_visible (tv_col))
2047 set_cell_visibility (tree_view,
2049 tv_col, row_path, FALSE);
2052 _gtk_cell_accessible_remove_state (cell_info->cell, ATK_STATE_VISIBLE, TRUE);
2053 _gtk_cell_accessible_remove_state (cell_info->cell, ATK_STATE_SHOWING, TRUE);
2056 gtk_tree_path_free (row_path);
2064 model_row_inserted (GtkTreeModel *tree_model,
2069 GtkTreeView *tree_view = (GtkTreeView *)user_data;
2071 GtkTreeViewAccessible *accessible;
2072 GtkTreePath *path_copy;
2073 gint row, n_inserted, child_row;
2075 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
2076 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
2077 accessible->n_rows++;
2079 if (accessible->idle_expand_id)
2081 g_source_remove (accessible->idle_expand_id);
2082 accessible->idle_expand_id = 0;
2084 /* don't do this if the insertion precedes the idle path,
2085 * since it will now be invalid
2087 if (path && accessible->idle_expand_path &&
2088 (gtk_tree_path_compare (path, accessible->idle_expand_path) > 0))
2089 set_expand_state (tree_view, tree_model, accessible, accessible->idle_expand_path, FALSE);
2090 if (accessible->idle_expand_path)
2091 gtk_tree_path_free (accessible->idle_expand_path);
2093 /* Check to see if row is visible */
2094 row = get_row_from_tree_path (tree_view, path);
2096 /* A row insert is not necessarily visible. For example,
2097 * a row can be draged & dropped into another row, which
2098 * causes an insert on the model that isn't visible in the
2099 * view. Only generate a signal if the inserted row is
2104 GtkTreeIter tmp_iter;
2107 gtk_tree_model_get_iter (tree_model, &tmp_iter, path);
2109 /* Figure out number of visible children. */
2110 if (gtk_tree_model_iter_has_child (tree_model, &tmp_iter))
2114 * By passing path into this function, we find the number of
2115 * visible children of path.
2118 /* iterate_thru_children modifies path, we don't want that, so give
2120 path2 = gtk_tree_path_copy (path);
2121 iterate_thru_children (tree_view, tree_model,
2122 path2, NULL, &n_inserted, 0);
2123 gtk_tree_path_free (path2);
2125 /* Must add one to include the row that is being added */
2131 /* Set rows below the inserted row to ATK_STATE_STALE */
2132 traverse_cells (accessible, path, TRUE, TRUE);
2134 /* Generate row-inserted signal */
2135 g_signal_emit_by_name (atk_obj, "row-inserted", row, n_inserted);
2137 /* Generate children-changed signals */
2138 n_cols = gtk_tree_view_accessible_get_n_columns (ATK_TABLE (atk_obj));
2139 for (child_row = row; child_row < (row + n_inserted); child_row++)
2141 for (col = 0; col < n_cols; col++)
2143 /* Pass NULL as the child object, i.e. 4th argument */
2144 g_signal_emit_by_name (atk_obj, "children-changed::add",
2145 ((row * n_cols) + col), NULL, NULL);
2151 /* The row has been inserted inside another row. This can
2152 * cause a row that previously couldn't be expanded to now
2155 path_copy = gtk_tree_path_copy (path);
2156 gtk_tree_path_up (path_copy);
2157 set_expand_state (tree_view, tree_model, accessible, path_copy, TRUE);
2158 gtk_tree_path_free (path_copy);
2163 model_row_deleted (GtkTreeModel *tree_model,
2167 GtkTreeView *tree_view = (GtkTreeView *)user_data;
2168 GtkTreePath *path_copy;
2170 GtkTreeViewAccessible *accessible;
2173 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
2174 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
2176 accessible->n_rows--;
2178 if (accessible->idle_expand_id)
2180 g_source_remove (accessible->idle_expand_id);
2181 gtk_tree_path_free (accessible->idle_expand_path);
2182 accessible->idle_expand_id = 0;
2185 /* Check to see if row is visible */
2186 clean_rows (accessible);
2188 /* Set rows at or below the specified row to ATK_STATE_STALE */
2189 traverse_cells (accessible, path, TRUE, TRUE);
2191 /* If deleting a row with a depth > 1, then this may affect the
2192 * expansion/contraction of its parent(s). Make sure this is
2195 if (gtk_tree_path_get_depth (path) > 1)
2197 path_copy = gtk_tree_path_copy (path);
2198 gtk_tree_path_up (path_copy);
2199 set_expand_state (tree_view, tree_model, accessible, path_copy, TRUE);
2200 gtk_tree_path_free (path_copy);
2202 row = get_row_from_tree_path (tree_view, path);
2204 /* If the row which is deleted is not visible because it is a child of
2205 * a collapsed row then row will be -1
2208 g_signal_emit_by_name (atk_obj, "row-deleted", row,
2209 accessible->n_children_deleted + 1);
2210 accessible->n_children_deleted = 0;
2212 /* Generate children-changed signals */
2213 for (col = 0; col < accessible->n_cols; col++)
2215 /* Pass NULL as the child object, 4th argument */
2216 g_signal_emit_by_name (atk_obj, "children-changed::remove",
2217 ((row * accessible->n_cols) + col), NULL, NULL);
2221 /* This function gets called when a row is deleted or when rows are
2222 * removed from the view due to a collapse event. Note that the
2223 * count is the number of visible *children* of the deleted row,
2224 * so it does not include the row being deleted.
2226 * As this function is called before the rows are removed we just note
2227 * the number of rows and then deal with it when we get a notification
2228 * that rows were deleted or collapsed.
2231 destroy_count_func (GtkTreeView *tree_view,
2237 GtkTreeViewAccessible *accessible;
2239 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
2240 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
2242 if (accessible->n_children_deleted != 0)
2245 accessible->n_children_deleted = count;
2249 model_rows_reordered (GtkTreeModel *tree_model,
2255 GtkTreeView *tree_view = (GtkTreeView *)user_data;
2257 GtkTreeViewAccessible *accessible;
2259 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
2260 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
2262 if (accessible->idle_expand_id)
2264 g_source_remove (accessible->idle_expand_id);
2265 gtk_tree_path_free (accessible->idle_expand_path);
2266 accessible->idle_expand_id = 0;
2268 traverse_cells (accessible, NULL, TRUE, FALSE);
2270 g_signal_emit_by_name (atk_obj, "row-reordered");
2274 set_cell_visibility (GtkTreeView *tree_view,
2275 GtkCellAccessible *cell,
2276 GtkTreeViewColumn *tv_col,
2277 GtkTreePath *tree_path,
2278 gboolean emit_signal)
2280 GdkRectangle cell_rect;
2282 /* Get these three values in tree coords */
2283 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
2284 gtk_tree_view_get_cell_area (tree_view, tree_path, tv_col, &cell_rect);
2286 cell_rect.height = 0;
2288 if (cell_rect.height > 0)
2290 /* The height will be zero for a cell for which an antecedent
2293 _gtk_cell_accessible_add_state (cell, ATK_STATE_VISIBLE, emit_signal);
2294 if (is_cell_showing (tree_view, &cell_rect))
2295 _gtk_cell_accessible_add_state (cell, ATK_STATE_SHOWING, emit_signal);
2297 _gtk_cell_accessible_remove_state (cell, ATK_STATE_SHOWING, emit_signal);
2301 _gtk_cell_accessible_remove_state (cell, ATK_STATE_VISIBLE, emit_signal);
2302 _gtk_cell_accessible_remove_state (cell, ATK_STATE_SHOWING, emit_signal);
2307 is_cell_showing (GtkTreeView *tree_view,
2308 GdkRectangle *cell_rect)
2310 GdkRectangle rect, *visible_rect;
2311 GdkRectangle rect1, *tree_cell_rect;
2313 gboolean is_showing;
2315 /* A cell is considered "SHOWING" if any part of the cell is
2316 * in the visible area. Other ways we could do this is by a
2317 * cell's midpoint or if the cell is fully in the visible range.
2318 * Since we have the cell_rect x, y, width, height of the cell,
2319 * any of these is easy to compute.
2321 * It is assumed that cell's rectangle is in widget coordinates
2322 * so we must transform to tree cordinates.
2324 visible_rect = ▭
2325 tree_cell_rect = &rect1;
2326 tree_cell_rect->x = cell_rect->x;
2327 tree_cell_rect->y = cell_rect->y;
2328 tree_cell_rect->width = cell_rect->width;
2329 tree_cell_rect->height = cell_rect->height;
2331 gtk_tree_view_get_visible_rect (tree_view, visible_rect);
2332 gtk_tree_view_convert_tree_to_bin_window_coords (tree_view, visible_rect->x,
2333 visible_rect->y, &bx, &by);
2335 if (((tree_cell_rect->x + tree_cell_rect->width) < bx) ||
2336 ((tree_cell_rect->y + tree_cell_rect->height) < by) ||
2337 (tree_cell_rect->x > (bx + visible_rect->width)) ||
2338 (tree_cell_rect->y > (by + visible_rect->height)))
2348 /* This function is called when a cell's flyweight is created in
2349 * gtk_tree_view_accessible_table_ref_at with emit_change_signal
2350 * set to FALSE and in model_row_changed() on receipt of "row-changed"
2351 * signal when emit_change_signal is set to TRUE
2354 update_cell_value (GtkRendererCellAccessible *renderer_cell,
2355 GtkTreeViewAccessible *accessible,
2356 gboolean emit_change_signal)
2358 GtkTreeViewAccessibleCellInfo *cell_info;
2359 GtkTreeView *tree_view;
2360 GtkTreeModel *tree_model;
2363 GList *renderers, *cur_renderer;
2365 GtkRendererCellAccessibleClass *renderer_cell_class;
2366 GtkCellRendererClass *gtk_cell_renderer_class;
2367 GtkCellAccessible *cell;
2370 gboolean is_expander, is_expanded;
2372 renderer_cell_class = GTK_RENDERER_CELL_ACCESSIBLE_GET_CLASS (renderer_cell);
2373 if (renderer_cell->renderer)
2374 gtk_cell_renderer_class = GTK_CELL_RENDERER_GET_CLASS (renderer_cell->renderer);
2376 gtk_cell_renderer_class = NULL;
2378 prop_list = renderer_cell_class->property_list;
2380 cell = GTK_CELL_ACCESSIBLE (renderer_cell);
2381 cell_info = find_cell_info (accessible, cell, TRUE);
2382 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
2385 if (emit_change_signal && cell_info->in_use)
2387 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
2388 tree_model = gtk_tree_view_get_model (tree_view);
2389 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2393 gtk_tree_model_get_iter (tree_model, &iter, path);
2394 is_expander = FALSE;
2395 is_expanded = FALSE;
2396 if (gtk_tree_model_iter_has_child (tree_model, &iter))
2398 GtkTreeViewColumn *expander_tv;
2400 expander_tv = gtk_tree_view_get_expander_column (tree_view);
2401 if (expander_tv == cell_info->cell_col_ref)
2404 is_expanded = gtk_tree_view_row_expanded (tree_view, path);
2407 gtk_tree_path_free (path);
2408 gtk_tree_view_column_cell_set_cell_data (cell_info->cell_col_ref,
2410 is_expander, is_expanded);
2412 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_info->cell_col_ref));
2416 /* If the cell is in a container, its index is used to find the renderer
2417 * in the list. Otherwise, we assume that the cell is represented
2418 * by the first renderer in the list
2421 if (cell_info->in_use)
2423 parent = atk_object_get_parent (ATK_OBJECT (cell));
2425 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
2426 cur_renderer = g_list_nth (renderers, cell->index);
2428 cur_renderer = renderers;
2433 if (cur_renderer == NULL)
2436 if (gtk_cell_renderer_class)
2440 spec = g_object_class_find_property
2441 (G_OBJECT_CLASS (gtk_cell_renderer_class), *prop_list);
2445 GValue value = { 0, };
2447 g_value_init (&value, spec->value_type);
2448 g_object_get_property (cur_renderer->data, *prop_list, &value);
2449 g_object_set_property (G_OBJECT (renderer_cell->renderer),
2450 *prop_list, &value);
2451 g_value_unset (&value);
2454 g_warning ("Invalid property: %s\n", *prop_list);
2458 g_list_free (renderers);
2460 return _gtk_renderer_cell_accessible_update_cache (renderer_cell, emit_change_signal);
2464 get_row_from_tree_path (GtkTreeView *tree_view,
2467 GtkTreeModel *tree_model;
2468 GtkTreePath *root_tree;
2471 tree_model = gtk_tree_view_get_model (tree_view);
2473 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
2474 row = gtk_tree_path_get_indices (path)[0];
2477 root_tree = gtk_tree_path_new_first ();
2479 iterate_thru_children (tree_view, tree_model, root_tree, path, &row, 0);
2480 gtk_tree_path_free (root_tree);
2489 * Get the specified GtkTreeViewColumn in the GtkTreeView.
2490 * Only visible columns are considered.
2492 static GtkTreeViewColumn *
2493 get_column (GtkTreeView *tree_view,
2496 GtkTreeViewColumn *tv_col;
2502 g_warning ("Request for invalid column %d\n", in_col);
2506 tv_col = gtk_tree_view_get_column (tree_view, i);
2507 while (tv_col != NULL)
2509 if (gtk_tree_view_column_get_visible (tv_col))
2511 if (in_col == n_cols)
2513 tv_col = gtk_tree_view_get_column (tree_view, ++i);
2516 if (in_col != n_cols)
2518 g_warning ("Request for invalid column %d\n", in_col);
2525 get_actual_column_number (GtkTreeView *tree_view,
2526 gint visible_column)
2528 GtkTreeViewColumn *tv_col;
2529 gint actual_column = 0;
2530 gint visible_columns = -1;
2532 /* This function calculates the column number which corresponds
2533 * to the specified visible column number
2535 tv_col = gtk_tree_view_get_column (tree_view, actual_column);
2536 while (tv_col != NULL)
2538 if (gtk_tree_view_column_get_visible (tv_col))
2540 if (visible_columns == visible_column)
2541 return actual_column;
2542 tv_col = gtk_tree_view_get_column (tree_view, ++actual_column);
2544 g_warning ("get_actual_column_number failed for %d\n", visible_column);
2549 get_visible_column_number (GtkTreeView *tree_view,
2552 GtkTreeViewColumn *tv_col;
2554 gint visible_columns = -1;
2556 /* This function calculates the visible column number
2557 * which corresponds to the specified actual column number
2559 tv_col = gtk_tree_view_get_column (tree_view, column);
2561 while (tv_col != NULL)
2563 if (gtk_tree_view_column_get_visible (tv_col))
2566 if (actual_column == column)
2567 return visible_columns;
2570 if (actual_column == column)
2572 tv_col = gtk_tree_view_get_column (tree_view, ++column);
2574 g_warning ("get_visible_column_number failed for %d\n", actual_column);
2578 /* Helper recursive function that returns an iter to nth row
2580 static GtkTreeIter *
2581 return_iter_nth_row (GtkTreeView *tree_view,
2582 GtkTreeModel *tree_model,
2587 GtkTreePath *current_path;
2588 GtkTreeIter new_iter;
2589 gboolean row_expanded;
2591 current_path = gtk_tree_model_get_path (tree_model, iter);
2592 if (increment == row)
2594 gtk_tree_path_free (current_path);
2598 row_expanded = gtk_tree_view_row_expanded (tree_view, current_path);
2599 gtk_tree_path_free (current_path);
2602 if ((row_expanded && gtk_tree_model_iter_children (tree_model, iter, &new_iter)) ||
2603 (gtk_tree_model_iter_next (tree_model, iter)) ||
2604 (gtk_tree_model_iter_parent (tree_model, iter, &new_iter) &&
2605 (gtk_tree_model_iter_next (tree_model, iter))))
2606 return return_iter_nth_row (tree_view, tree_model, iter,
2613 set_iter_nth_row (GtkTreeView *tree_view,
2617 GtkTreeModel *tree_model;
2619 tree_model = gtk_tree_view_get_model (tree_view);
2620 gtk_tree_model_get_iter_first (tree_model, iter);
2621 iter = return_iter_nth_row (tree_view, tree_model, iter, 0, row);
2624 /* Recursively called until the row specified by orig is found.
2626 * *count will be set to the visible row number of the child
2627 * relative to the row that was initially passed in as tree_path.
2628 * tree_path could be modified by this function.
2630 * *count will be -1 if orig is not found as a child (a row that is
2631 * not visible will not be found, e.g. if the row is inside a
2632 * collapsed row). If NULL is passed in as orig, *count will
2633 * be a count of the visible children.
2635 * NOTE: the value for depth must be 0 when this recursive function
2636 * is initially called, or it may not function as expected.
2639 iterate_thru_children (GtkTreeView *tree_view,
2640 GtkTreeModel *tree_model,
2641 GtkTreePath *tree_path,
2648 if (!gtk_tree_model_get_iter (tree_model, &iter, tree_path))
2651 if (tree_path && orig && !gtk_tree_path_compare (tree_path, orig))
2655 if (tree_path && orig && gtk_tree_path_compare (tree_path, orig) > 0)
2657 /* Past it, so return -1 */
2661 else if (gtk_tree_view_row_expanded (tree_view, tree_path) &&
2662 gtk_tree_model_iter_has_child (tree_model, &iter))
2665 gtk_tree_path_append_index (tree_path, 0);
2666 iterate_thru_children (tree_view, tree_model, tree_path,
2667 orig, count, (depth + 1));
2670 else if (gtk_tree_model_iter_next (tree_model, &iter))
2673 tree_path = gtk_tree_model_get_path (tree_model, &iter);
2676 iterate_thru_children (tree_view, tree_model, tree_path,
2677 orig, count, depth);
2678 gtk_tree_path_free (tree_path);
2682 else if (gtk_tree_path_up (tree_path))
2684 GtkTreeIter temp_iter;
2685 gboolean exit_loop = FALSE;
2686 gint new_depth = depth - 1;
2690 /* Make sure that we back up until we find a row
2691 * where gtk_tree_path_next does not return NULL.
2695 if (gtk_tree_path_get_depth (tree_path) == 0)
2696 /* depth is now zero so */
2698 gtk_tree_path_next (tree_path);
2700 /* Verify that the next row is a valid row! */
2701 exit_loop = gtk_tree_model_get_iter (tree_model, &temp_iter, tree_path);
2705 /* Keep going up until we find a row that has a valid next */
2706 if (gtk_tree_path_get_depth(tree_path) > 1)
2709 gtk_tree_path_up (tree_path);
2713 /* If depth is 1 and gtk_tree_model_get_iter returns FALSE,
2714 * then we are at the last row, so just return.
2724 /* This guarantees that we will stop when we hit the end of the
2730 iterate_thru_children (tree_view, tree_model, tree_path,
2731 orig, count, new_depth);
2735 /* If it gets here, then the path wasn't found. Situations
2736 * that would cause this would be if the path passed in is
2737 * invalid or contained within the last row, but not visible
2738 * because the last row is not expanded. If NULL was passed
2739 * in then a row count is desired, so only set count to -1
2740 * if orig is not NULL.
2749 clean_cell_info (GtkTreeViewAccessible *accessible,
2750 GtkTreeViewAccessibleCellInfo *cell_info)
2754 if (cell_info->in_use)
2756 obj = G_OBJECT (cell_info->cell);
2758 _gtk_cell_accessible_add_state (cell_info->cell, ATK_STATE_DEFUNCT, FALSE);
2759 g_object_weak_unref (obj, (GWeakNotify) cell_destroyed, cell_info);
2760 cell_info->in_use = FALSE;
2761 if (!accessible->garbage_collection_pending)
2763 accessible->garbage_collection_pending = TRUE;
2764 g_assert (accessible->idle_garbage_collect_id == 0);
2765 accessible->idle_garbage_collect_id =
2766 gdk_threads_add_idle (idle_garbage_collect_cell_data, accessible);
2772 clean_rows (GtkTreeViewAccessible *accessible)
2774 GtkTreeViewAccessibleCellInfo *cell_info;
2775 GHashTableIter iter;
2777 /* Clean GtkTreeViewAccessibleCellInfo data */
2778 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
2779 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
2781 GtkTreePath *row_path;
2783 row_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2785 /* If the cell has become invalid because the row has been removed,
2786 * then set the cell's state to ATK_STATE_DEFUNCT and schedule
2787 * its removal. If row_path is NULL then the row has
2790 if (row_path == NULL)
2791 clean_cell_info (accessible, cell_info);
2793 gtk_tree_path_free (row_path);
2798 clean_cols (GtkTreeViewAccessible *accessible,
2799 GtkTreeViewColumn *tv_col)
2801 GtkTreeViewAccessibleCellInfo *cell_info;
2802 GHashTableIter iter;
2804 /* Clean GtkTreeViewAccessibleCellInfo data */
2805 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
2806 while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cell_info))
2808 /* If the cell has become invalid because the column tv_col
2809 * has been removed, then set the cell's state to ATK_STATE_DEFUNCT
2810 * and remove the cell from accessible->cell_data.
2812 if (cell_info->cell_col_ref == tv_col)
2813 clean_cell_info (accessible, cell_info);
2818 garbage_collect_cell_data (gpointer data)
2820 GtkTreeViewAccessible *accessible;
2821 GtkTreeViewAccessibleCellInfo *cell_info;
2822 GHashTableIter iter;
2824 accessible = (GtkTreeViewAccessible *)data;
2826 accessible->garbage_collection_pending = FALSE;
2827 if (accessible->idle_garbage_collect_id != 0)
2829 g_source_remove (accessible->idle_garbage_collect_id);
2830 accessible->idle_garbage_collect_id = 0;
2833 /* Must loop through them all */
2834 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
2835 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
2837 if (!cell_info->in_use)
2839 /* g_object_unref (cell_info->cell); */
2840 if (cell_info->cell_row_ref)
2841 gtk_tree_row_reference_free (cell_info->cell_row_ref);
2843 g_hash_table_iter_remove (&iter);
2847 return accessible->garbage_collection_pending;
2851 idle_garbage_collect_cell_data (gpointer data)
2853 GtkTreeViewAccessible *accessible;
2855 accessible = (GtkTreeViewAccessible *)data;
2857 /* this is the idle handler (only one instance allowed), so
2858 * we can safely delete it.
2860 accessible->garbage_collection_pending = FALSE;
2861 accessible->idle_garbage_collect_id = 0;
2863 accessible->garbage_collection_pending = garbage_collect_cell_data (data);
2865 /* N.B.: if for some reason another handler has re-enterantly been
2866 * queued while this handler was being serviced, it has its own gsource,
2867 * therefore this handler should always return FALSE.
2872 /* If tree_path is passed in as NULL, then all cells are acted on.
2873 * Otherwise, just act on those cells that are on a row greater than
2874 * the specified tree_path. If inc_row is passed in as TRUE, then rows
2875 * greater and equal to the specified tree_path are acted on.
2877 * If set_stale is set the ATK_STATE_STALE is set on cells which
2878 * are to be acted on.
2880 * The function set_cell_visibility() is called on all cells to be
2881 * acted on to update the visibility of the cell.
2884 traverse_cells (GtkTreeViewAccessible *accessible,
2885 GtkTreePath *tree_path,
2889 GtkTreeViewAccessibleCellInfo *cell_info;
2891 GHashTableIter iter;
2893 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2897 /* Must loop through them all */
2898 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
2899 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
2901 GtkTreePath *row_path;
2902 gboolean act_on_cell;
2904 if (cell_info->in_use)
2906 row_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2907 g_return_if_fail (row_path != NULL);
2908 if (tree_path == NULL)
2914 comparison = gtk_tree_path_compare (row_path, tree_path);
2915 if ((comparison > 0) ||
2916 (comparison == 0 && inc_row))
2919 act_on_cell = FALSE;
2922 if (!cell_info->in_use)
2923 g_warning ("warning: cell info destroyed during traversal");
2925 if (act_on_cell && cell_info->in_use)
2928 _gtk_cell_accessible_add_state (cell_info->cell, ATK_STATE_STALE, TRUE);
2929 set_cell_visibility (GTK_TREE_VIEW (widget),
2931 cell_info->cell_col_ref,
2934 gtk_tree_path_free (row_path);
2938 g_signal_emit_by_name (accessible, "visible-data-changed");
2941 /* If the tree_path passed in has children, then
2942 * ATK_STATE_EXPANDABLE is set. If the row is expanded
2943 * ATK_STATE_EXPANDED is turned on. If the row is
2944 * collapsed, then ATK_STATE_EXPANDED is removed.
2946 * If the tree_path passed in has no children, then
2947 * ATK_STATE_EXPANDABLE and ATK_STATE_EXPANDED are removed.
2949 * If set_on_ancestor is TRUE, then this function will also
2950 * update all cells that are ancestors of the tree_path.
2953 set_expand_state (GtkTreeView *tree_view,
2954 GtkTreeModel *tree_model,
2955 GtkTreeViewAccessible *accessible,
2956 GtkTreePath *tree_path,
2957 gboolean set_on_ancestor)
2959 GtkTreeViewColumn *expander_tv;
2960 GtkTreeViewAccessibleCellInfo *cell_info;
2961 GtkTreePath *cell_path;
2964 GHashTableIter hash_iter;
2966 g_hash_table_iter_init (&hash_iter, accessible->cell_info_by_index);
2967 while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer *) &cell_info))
2969 if (cell_info->in_use)
2971 cell_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2974 if (cell_path != NULL)
2976 GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (cell_info->cell);
2978 expander_tv = gtk_tree_view_get_expander_column (tree_view);
2980 /* Only set state for the cell that is in the column with the
2983 if (expander_tv == cell_info->cell_col_ref)
2985 if (tree_path && gtk_tree_path_compare (cell_path, tree_path) == 0)
2987 else if (set_on_ancestor &&
2988 gtk_tree_path_get_depth (cell_path) <
2989 gtk_tree_path_get_depth (tree_path) &&
2990 gtk_tree_path_is_ancestor (cell_path, tree_path) == 1)
2991 /* Only set if set_on_ancestor was passed in as TRUE */
2995 /* Set ATK_STATE_EXPANDABLE and ATK_STATE_EXPANDED
2996 * for ancestors and found cells.
3000 /* Must check against cell_path since cell_path
3001 * can be equal to or an ancestor of tree_path.
3003 gtk_tree_model_get_iter (tree_model, &iter, cell_path);
3005 /* Set or unset ATK_STATE_EXPANDABLE as appropriate */
3006 if (gtk_tree_model_iter_has_child (tree_model, &iter))
3008 set_cell_expandable (cell);
3010 if (gtk_tree_view_row_expanded (tree_view, cell_path))
3011 _gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, TRUE);
3013 _gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDED, TRUE);
3017 _gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDED, TRUE);
3018 if (_gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDABLE, TRUE))
3019 /* The state may have been propagated to the container cell */
3020 if (!GTK_IS_CONTAINER_CELL_ACCESSIBLE (cell))
3021 _gtk_cell_accessible_remove_action_by_name (cell,
3022 "expand or contract");
3025 /* We assume that each cell in the cache once and
3026 * a container cell is before its child cells so we are
3027 * finished if set_on_ancestor is not set to TRUE.
3029 if (!set_on_ancestor)
3033 gtk_tree_path_free (cell_path);
3039 add_cell_actions (GtkCellAccessible *cell,
3042 if (GTK_IS_BOOLEAN_CELL_ACCESSIBLE (cell))
3043 _gtk_cell_accessible_add_action (cell,
3044 "toggle", "toggles the cell",
3045 NULL, toggle_cell_toggled);
3047 _gtk_cell_accessible_add_action (cell,
3048 "edit", "creates a widget in which the contents of the cell can be edited",
3050 _gtk_cell_accessible_add_action (cell,
3051 "activate", "activate the cell",
3052 NULL, activate_cell);
3056 toggle_cell_expanded (GtkCellAccessible *cell)
3058 GtkTreeViewAccessibleCellInfo *cell_info;
3059 GtkTreeView *tree_view;
3062 AtkStateSet *stateset;
3064 parent = atk_object_get_parent (ATK_OBJECT (cell));
3065 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
3066 parent = atk_object_get_parent (parent);
3068 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
3069 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
3072 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
3073 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
3077 stateset = atk_object_ref_state_set (ATK_OBJECT (cell));
3078 if (atk_state_set_contains_state (stateset, ATK_STATE_EXPANDED))
3079 gtk_tree_view_collapse_row (tree_view, path);
3081 gtk_tree_view_expand_row (tree_view, path, TRUE);
3082 g_object_unref (stateset);
3083 gtk_tree_path_free (path);
3087 toggle_cell_toggled (GtkCellAccessible *cell)
3089 GtkTreeViewAccessibleCellInfo *cell_info;
3092 GList *renderers, *cur_renderer;
3094 gboolean is_container_cell = FALSE;
3096 parent = atk_object_get_parent (ATK_OBJECT (cell));
3097 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
3099 is_container_cell = TRUE;
3100 parent = atk_object_get_parent (parent);
3103 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
3104 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
3107 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
3111 /* If the cell is in a container, its index is used to find the
3112 * renderer in the list. Otherwise, we assume that the cell is
3113 * represented by the first renderer in the list
3115 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_info->cell_col_ref));
3116 if (is_container_cell)
3117 cur_renderer = g_list_nth (renderers, cell->index);
3119 cur_renderer = renderers;
3123 pathstring = gtk_tree_path_to_string (path);
3124 g_signal_emit_by_name (cur_renderer->data, "toggled", pathstring);
3125 g_free (pathstring);
3128 g_list_free (renderers);
3129 gtk_tree_path_free (path);
3133 edit_cell (GtkCellAccessible *cell)
3135 GtkTreeViewAccessibleCellInfo *cell_info;
3136 GtkTreeView *tree_view;
3140 parent = atk_object_get_parent (ATK_OBJECT (cell));
3141 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
3142 parent = atk_object_get_parent (parent);
3144 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
3145 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
3148 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
3149 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
3152 gtk_tree_view_set_cursor (tree_view, path, cell_info->cell_col_ref, TRUE);
3153 gtk_tree_path_free (path);
3157 activate_cell (GtkCellAccessible *cell)
3159 GtkTreeViewAccessibleCellInfo *cell_info;
3160 GtkTreeView *tree_view;
3164 parent = atk_object_get_parent (ATK_OBJECT (cell));
3165 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
3166 parent = atk_object_get_parent (parent);
3168 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
3169 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
3172 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
3173 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
3176 gtk_tree_view_row_activated (tree_view, path, cell_info->cell_col_ref);
3177 gtk_tree_path_free (path);
3181 cell_destroyed (gpointer data)
3183 GtkTreeViewAccessibleCellInfo *cell_info = data;
3187 if (cell_info->in_use)
3189 cell_info->in_use = FALSE;
3191 if (!cell_info->view->garbage_collection_pending)
3193 cell_info->view->garbage_collection_pending = TRUE;
3194 cell_info->view->idle_garbage_collect_id =
3195 gdk_threads_add_idle (idle_garbage_collect_cell_data, cell_info->view);
3201 cell_info_get_index (GtkTreeView *tree_view,
3202 GtkTreeViewAccessibleCellInfo *info,
3208 path = gtk_tree_row_reference_get_path (info->cell_row_ref);
3212 column_number = get_column_number (tree_view, info->cell_col_ref, FALSE);
3213 *index = get_index (tree_view, path, column_number);
3214 gtk_tree_path_free (path);
3218 cell_info_new (GtkTreeViewAccessible *accessible,
3219 GtkTreeModel *tree_model,
3221 GtkTreeViewColumn *tv_col,
3222 GtkCellAccessible *cell)
3224 GtkTreeViewAccessibleCellInfo *cell_info;
3226 cell_info = g_new (GtkTreeViewAccessibleCellInfo, 1);
3227 cell_info->cell_row_ref = gtk_tree_row_reference_new (tree_model, path);
3229 cell_info->cell_col_ref = tv_col;
3230 cell_info->cell = cell;
3231 cell_info->in_use = TRUE; /* if we've created it, assume it's in use */
3232 cell_info->view = accessible;
3233 g_hash_table_insert (accessible->cell_info_by_index, &cell->index, cell_info);
3235 /* Setup weak reference notification */
3236 g_object_weak_ref (G_OBJECT (cell), (GWeakNotify) cell_destroyed, cell_info);
3239 static GtkCellAccessible *
3240 find_cell (GtkTreeViewAccessible *accessible,
3243 GtkTreeViewAccessibleCellInfo *info;
3245 info = g_hash_table_lookup (accessible->cell_info_by_index, &index);
3253 refresh_cell_index (GtkCellAccessible *cell)
3255 GtkTreeViewAccessibleCellInfo *info;
3257 GtkTreeView *tree_view;
3258 GtkTreeViewAccessible *accessible;
3261 parent = atk_object_get_parent (ATK_OBJECT (cell));
3262 if (!GTK_IS_TREE_VIEW_ACCESSIBLE (parent))
3265 accessible = GTK_TREE_VIEW_ACCESSIBLE (parent);
3267 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
3269 /* Find this cell in the GtkTreeViewAccessible's cache */
3270 info = find_cell_info (accessible, cell, TRUE);
3274 cell_info_get_index (tree_view, info, &index);
3275 cell->index = index;
3276 g_hash_table_insert (accessible->cell_info_by_index, &index, info);
3280 connect_model_signals (GtkTreeView *view,
3281 GtkTreeViewAccessible *accessible)
3285 obj = G_OBJECT (accessible->tree_model);
3286 g_signal_connect_data (obj, "row-changed",
3287 G_CALLBACK (model_row_changed), view, NULL, 0);
3288 g_signal_connect_data (obj, "row-inserted",
3289 G_CALLBACK (model_row_inserted), view, NULL,
3291 g_signal_connect_data (obj, "row-deleted",
3292 G_CALLBACK (model_row_deleted), view, NULL,
3294 g_signal_connect_data (obj, "rows-reordered",
3295 G_CALLBACK (model_rows_reordered), view, NULL,
3300 disconnect_model_signals (GtkTreeViewAccessible *accessible)
3305 obj = G_OBJECT (accessible->tree_model);
3306 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
3307 g_signal_handlers_disconnect_by_func (obj, model_row_changed, widget);
3308 g_signal_handlers_disconnect_by_func (obj, model_row_inserted, widget);
3309 g_signal_handlers_disconnect_by_func (obj, model_row_deleted, widget);
3310 g_signal_handlers_disconnect_by_func (obj, model_rows_reordered, widget);
3314 clear_cached_data (GtkTreeViewAccessible *accessible)
3316 GtkTreeViewAccessibleCellInfo *cell_info;
3317 GHashTableIter iter;
3319 /* Must loop through them all */
3320 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
3321 while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cell_info))
3322 clean_cell_info (accessible, cell_info);
3324 /* FIXME: seems pretty inefficient to loop again here */
3325 garbage_collect_cell_data (accessible);
3328 /* Returns the column number of the specified GtkTreeViewColumn
3330 * If visible is set, the value returned will be the visible column number,
3331 * i.e. suitable for use in AtkTable function. If visible is not set, the
3332 * value returned is the actual column number, which is suitable for use in
3333 * getting an index value.
3336 get_column_number (GtkTreeView *tree_view,
3337 GtkTreeViewColumn *column,
3340 GtkTreeViewColumn *tv_column;
3344 GtkTreeViewAccessible *accessible;
3346 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
3347 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
3350 for (i = 0; i < accessible->col_data->len; i++)
3352 tv_column = g_array_index (accessible->col_data, GtkTreeViewColumn *, i);
3353 if (tv_column == column)
3355 if (!visible || gtk_tree_view_column_get_visible (tv_column))
3358 if (i == accessible->col_data->len)
3365 get_index (GtkTreeView *tree_view,
3370 GtkTreeViewAccessible *accessible;
3373 gint *indices = NULL;
3375 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
3376 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
3380 depth = gtk_tree_path_get_depth (path);
3381 indices = gtk_tree_path_get_indices (path);
3386 GtkTreePath *copy_path;
3387 GtkTreeModel *model;
3389 model = gtk_tree_view_get_model (tree_view);
3390 copy_path = gtk_tree_path_copy (path);
3391 gtk_tree_path_up (copy_path);
3392 count_rows (model, NULL, copy_path, &index, 0, depth);
3393 gtk_tree_path_free (copy_path);
3397 index += indices[depth - 1];
3398 index *= accessible->n_cols;
3399 index += actual_column;
3403 /* The function count_rows counts the number of rows starting at iter
3404 * and ending at end_path. The value of level is the depth of iter and
3405 * the value of depth is the depth of end_path. Rows at depth before
3406 * end_path are counted. This functions counts rows which are not visible
3407 * because an ancestor is collapsed.
3410 count_rows (GtkTreeModel *model,
3412 GtkTreePath *end_path,
3417 GtkTreeIter child_iter;
3423 *count += gtk_tree_model_iter_n_children (model, iter);
3425 if (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY)
3431 if (gtk_tree_model_iter_children (model, &child_iter, iter))
3433 gboolean ret_val = TRUE;
3437 if (level == depth - 1)
3439 GtkTreePath *iter_path;
3440 gboolean finished = FALSE;
3442 iter_path = gtk_tree_model_get_path (model, &child_iter);
3443 if (end_path && gtk_tree_path_compare (iter_path, end_path) >= 0)
3445 gtk_tree_path_free (iter_path);
3449 if (gtk_tree_model_iter_has_child (model, &child_iter))
3450 count_rows (model, &child_iter, end_path, count, level, depth);
3451 ret_val = gtk_tree_model_iter_next (model, &child_iter);
3456 /* Find the next node, which has children, at the specified depth below
3457 * the specified iter. The level is the depth of the current iter.
3458 * The position of the node is returned in path and the return value
3459 * of TRUE means that a node was found.
3463 get_next_node_with_child_at_depth (GtkTreeModel *model,
3469 GtkTreeIter child_iter;
3473 if (gtk_tree_model_iter_children (model, &child_iter, iter))
3479 while (!gtk_tree_model_iter_has_child (model, &child_iter))
3481 if (!gtk_tree_model_iter_next (model, &child_iter))
3487 /* We have found what we were looking for */
3488 *path = gtk_tree_model_get_path (model, &child_iter);
3492 if (get_next_node_with_child_at_depth (model, &child_iter, path,
3496 if (!gtk_tree_model_iter_next (model, &child_iter))
3503 /* Find the next node, which has children, at the same depth
3504 * as the specified GtkTreePath.
3507 get_next_node_with_child (GtkTreeModel *model,
3509 GtkTreePath **return_path)
3514 gtk_tree_model_get_iter (model, &iter, path);
3516 while (gtk_tree_model_iter_next (model, &iter))
3518 if (gtk_tree_model_iter_has_child (model, &iter))
3520 *return_path = gtk_tree_model_get_path (model, &iter);
3524 depth = gtk_tree_path_get_depth (path);
3525 while (gtk_tree_path_up (path))
3527 if (gtk_tree_path_get_depth (path) == 0)
3530 gtk_tree_model_get_iter (model, &iter, path);
3531 while (gtk_tree_model_iter_next (model, &iter))
3532 if (get_next_node_with_child_at_depth (model, &iter, return_path,
3533 gtk_tree_path_get_depth (path), depth))
3536 *return_path = NULL;
3541 get_tree_path_from_row_index (GtkTreeModel *model,
3543 GtkTreePath **tree_path)
3549 count = gtk_tree_model_iter_n_children (model, NULL);
3550 if (count > row_index)
3552 if (gtk_tree_model_iter_nth_child (model, &iter, NULL, row_index))
3554 *tree_path = gtk_tree_model_get_path (model, &iter);
3568 if (get_next_node_with_child_at_depth (model, NULL, tree_path, 0, depth))
3570 GtkTreePath *next_path;
3574 gtk_tree_model_get_iter (model, &iter, *tree_path);
3575 count = gtk_tree_model_iter_n_children (model, &iter);
3576 if (count > row_index)
3578 gtk_tree_path_append_index (*tree_path, row_index);
3584 if (!get_next_node_with_child (model, *tree_path, &next_path))
3587 gtk_tree_path_free (*tree_path);
3588 *tree_path = next_path;
3593 g_warning ("Index value is too large\n");
3594 gtk_tree_path_free (*tree_path);
3602 get_path_column_from_index (GtkTreeView *tree_view,
3605 GtkTreeViewColumn **column)
3607 GtkTreeModel *tree_model;
3609 GtkTreeViewAccessible *accessible;
3611 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
3612 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
3614 tree_model = gtk_tree_view_get_model (tree_view);
3615 if (accessible->n_cols == 0)
3617 /* First row is the column headers */
3618 index -= accessible->n_cols;
3627 row_index = index / accessible->n_cols;
3628 retval = get_tree_path_from_row_index (tree_model, row_index, path);
3637 *column = gtk_tree_view_get_column (tree_view, index % accessible->n_cols);
3638 if (*column == NULL)
3641 gtk_tree_path_free (*path);
3649 set_cell_expandable (GtkCellAccessible *cell)
3651 if (_gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDABLE, FALSE))
3652 _gtk_cell_accessible_add_action (cell,
3653 "expand or contract",
3654 "expands or contracts the row in the tree view containing this cell",
3655 NULL, toggle_cell_expanded);
3658 static GtkTreeViewAccessibleCellInfo *
3659 find_cell_info (GtkTreeViewAccessible *accessible,
3660 GtkCellAccessible *cell,
3663 GtkTreeViewAccessibleCellInfo *cell_info;
3664 GHashTableIter iter;
3666 /* Clean GtkTreeViewAccessibleCellInfo data */
3667 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
3668 while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cell_info))
3670 if (cell_info->cell == cell && (!live_only || cell_info->in_use))
3677 get_header_from_column (GtkTreeViewColumn *tv_col)
3680 GtkWidget *header_widget;
3685 header_widget = gtk_tree_view_column_get_button (tv_col);
3688 rc = gtk_widget_get_accessible (header_widget);