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.
24 #ifdef GDK_WINDOWING_X11
25 #include <gdk/x11/gdkx.h>
27 #include "gtktreeviewaccessible.h"
28 #include "gtkrenderercellaccessible.h"
29 #include "gtkbooleancellaccessible.h"
30 #include "gtkimagecellaccessible.h"
31 #include "gtkcontainercellaccessible.h"
32 #include "gtktextcellaccessible.h"
33 #include "gailcellparent.h"
35 typedef struct _GtkTreeViewAccessibleCellInfo GtkTreeViewAccessibleCellInfo;
36 struct _GtkTreeViewAccessibleCellInfo
38 GtkCellAccessible *cell;
39 GtkTreeRowReference *cell_row_ref;
40 GtkTreeViewColumn *cell_col_ref;
41 GtkTreeViewAccessible *view;
47 static gboolean row_expanded_cb (GtkTreeView *tree_view,
50 static gboolean row_collapsed_cb (GtkTreeView *tree_view,
53 static void size_allocate_cb (GtkWidget *widget,
54 GtkAllocation *allocation);
55 static void selection_changed_cb (GtkTreeSelection *selection,
58 static void columns_changed (GtkTreeView *tree_view);
59 static void cursor_changed (GtkTreeView *tree_view);
60 static gboolean focus_in (GtkWidget *widget);
61 static gboolean focus_out (GtkWidget *widget);
63 static void column_visibility_changed
67 static void destroy_count_func (GtkTreeView *tree_view,
74 static void set_iter_nth_row (GtkTreeView *tree_view,
77 static gint get_row_from_tree_path (GtkTreeView *tree_view,
79 static GtkTreeViewColumn* get_column (GtkTreeView *tree_view,
81 static gint get_actual_column_number (GtkTreeView *tree_view,
83 static gint get_visible_column_number (GtkTreeView *tree_view,
85 static void iterate_thru_children (GtkTreeView *tree_view,
86 GtkTreeModel *tree_model,
87 GtkTreePath *tree_path,
91 static void clean_rows (GtkTreeViewAccessible *tree_view);
92 static void clean_cols (GtkTreeViewAccessible *tree_view,
93 GtkTreeViewColumn *tv_col);
94 static void traverse_cells (GtkTreeViewAccessible *tree_view,
95 GtkTreePath *tree_path,
98 static gboolean update_cell_value (GtkRendererCellAccessible *renderer_cell,
99 GtkTreeViewAccessible *accessible,
100 gboolean emit_change_signal);
101 static void set_cell_visibility (GtkTreeView *tree_view,
102 GtkCellAccessible *cell,
103 GtkTreeViewColumn *tv_col,
104 GtkTreePath *tree_path,
105 gboolean emit_signal);
106 static gboolean is_cell_showing (GtkTreeView *tree_view,
107 GdkRectangle *cell_rect);
108 static void set_expand_state (GtkTreeView *tree_view,
109 GtkTreeModel *tree_model,
110 GtkTreeViewAccessible *accessible,
111 GtkTreePath *tree_path,
112 gboolean set_on_ancestor);
113 static void set_cell_expandable (GtkCellAccessible *cell);
114 static void add_cell_actions (GtkCellAccessible *cell,
117 static void toggle_cell_toggled (GtkCellAccessible *cell);
118 static void edit_cell (GtkCellAccessible *cell);
119 static void activate_cell (GtkCellAccessible *cell);
120 static void cell_destroyed (gpointer data);
121 static void cell_info_new (GtkTreeViewAccessible *accessible,
122 GtkTreeModel *tree_model,
124 GtkTreeViewColumn *tv_col,
125 GtkCellAccessible *cell);
126 static GtkCellAccessible *find_cell (GtkTreeViewAccessible *accessible,
128 static void refresh_cell_index (GtkCellAccessible *cell);
129 static void connect_model_signals (GtkTreeView *view,
130 GtkTreeViewAccessible *accessible);
131 static void disconnect_model_signals (GtkTreeViewAccessible *accessible);
132 static void clear_cached_data (GtkTreeViewAccessible *view);
133 static gint get_column_number (GtkTreeView *tree_view,
134 GtkTreeViewColumn *column,
136 static gint get_focus_index (GtkTreeView *tree_view);
137 static gint get_index (GtkTreeView *tree_view,
140 static void count_rows (GtkTreeModel *model,
142 GtkTreePath *end_path,
147 static gboolean get_path_column_from_index (GtkTreeView *tree_view,
150 GtkTreeViewColumn **column);
152 static GtkTreeViewAccessibleCellInfo* find_cell_info (GtkTreeViewAccessible *view,
153 GtkCellAccessible *cell,
155 static AtkObject * get_header_from_column (GtkTreeViewColumn *tv_col);
156 static gboolean idle_garbage_collect_cell_data (gpointer data);
159 static void atk_table_interface_init (AtkTableIface *iface);
160 static void atk_selection_interface_init (AtkSelectionIface *iface);
161 static void atk_component_interface_init (AtkComponentIface *iface);
162 static void gail_cell_parent_interface_init (GailCellParentIface *iface);
164 G_DEFINE_TYPE_WITH_CODE (GtkTreeViewAccessible, _gtk_tree_view_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
165 G_IMPLEMENT_INTERFACE (ATK_TYPE_TABLE, atk_table_interface_init)
166 G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init)
167 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init)
168 G_IMPLEMENT_INTERFACE (GAIL_TYPE_CELL_PARENT, gail_cell_parent_interface_init))
172 adjustment_changed (GtkAdjustment *adjustment,
175 GtkTreeViewAccessible *accessible;
177 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
178 traverse_cells (accessible, NULL, FALSE, FALSE);
182 hadjustment_set_cb (GObject *widget,
186 GtkTreeViewAccessible *accessible = data;
189 g_object_get (widget, "hadjustment", &adj, NULL);
190 accessible->old_hadj = adj;
191 g_object_add_weak_pointer (G_OBJECT (accessible->old_hadj), (gpointer *)&accessible->old_hadj);
192 g_signal_connect (adj, "value-changed", G_CALLBACK (adjustment_changed), widget);
196 vadjustment_set_cb (GObject *widget,
200 GtkTreeViewAccessible *accessible = data;
203 g_object_get (widget, "vadjustment", &adj, NULL);
204 accessible->old_vadj = adj;
205 g_object_add_weak_pointer (G_OBJECT (accessible->old_vadj), (gpointer *)&accessible->old_vadj);
206 g_signal_connect (adj, "value-changed",
207 G_CALLBACK (adjustment_changed), widget);
211 gtk_tree_view_accessible_initialize (AtkObject *obj,
214 GtkTreeViewAccessible *accessible;
215 GtkTreeView *tree_view;
216 GtkTreeModel *tree_model;
217 GList *tv_cols, *tmp_list;
219 GtkTreeSelection *selection;
221 ATK_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->initialize (obj, data);
223 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
224 accessible->col_data = NULL;
225 accessible->focus_cell = NULL;
226 accessible->old_hadj = NULL;
227 accessible->old_vadj = NULL;
228 accessible->idle_expand_id = 0;
229 accessible->idle_expand_path = NULL;
230 accessible->n_children_deleted = 0;
232 accessible->cell_info_by_index = g_hash_table_new (g_int_hash, g_int_equal);
234 widget = GTK_WIDGET (data);
235 tree_view = GTK_TREE_VIEW (widget);
236 tree_model = gtk_tree_view_get_model (tree_view);
237 selection = gtk_tree_view_get_selection (tree_view);
239 g_signal_connect_after (widget, "row-collapsed",
240 G_CALLBACK (row_collapsed_cb), NULL);
241 g_signal_connect (widget, "row-expanded",
242 G_CALLBACK (row_expanded_cb), NULL);
243 g_signal_connect (widget, "size-allocate",
244 G_CALLBACK (size_allocate_cb), NULL);
245 g_signal_connect (selection, "changed",
246 G_CALLBACK (selection_changed_cb), obj);
248 g_signal_connect (tree_view, "columns-changed",
249 G_CALLBACK (columns_changed), NULL);
250 g_signal_connect (tree_view, "cursor-changed",
251 G_CALLBACK (cursor_changed), NULL);
252 g_signal_connect (tree_view, "focus-in-event",
253 G_CALLBACK (focus_in), NULL);
254 g_signal_connect (tree_view, "focus-out-event",
255 G_CALLBACK (focus_out), NULL);
257 accessible->tree_model = tree_model;
258 accessible->n_rows = 0;
259 accessible->n_cols = 0;
262 g_object_add_weak_pointer (G_OBJECT (accessible->tree_model), (gpointer *)&accessible->tree_model);
263 count_rows (tree_model, NULL, NULL, &accessible->n_rows, 0, G_MAXINT);
264 connect_model_signals (tree_view, accessible);
266 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
267 obj->role = ATK_ROLE_TABLE;
269 obj->role = ATK_ROLE_TREE_TABLE;
272 hadjustment_set_cb (G_OBJECT (widget), NULL, accessible);
273 vadjustment_set_cb (G_OBJECT (widget), NULL, accessible);
274 g_signal_connect (widget, "notify::hadjustment",
275 G_CALLBACK (hadjustment_set_cb), accessible);
276 g_signal_connect (widget, "notify::vadjustment",
277 G_CALLBACK (vadjustment_set_cb), accessible);
279 accessible->col_data = g_array_sized_new (FALSE, TRUE,
280 sizeof (GtkTreeViewColumn *), 0);
282 tv_cols = gtk_tree_view_get_columns (tree_view);
283 for (tmp_list = tv_cols; tmp_list; tmp_list = tmp_list->next)
285 accessible->n_cols++;
286 g_signal_connect (tmp_list->data, "notify::visible",
287 G_CALLBACK (column_visibility_changed), tree_view);
288 g_array_append_val (accessible->col_data, tmp_list->data);
290 g_list_free (tv_cols);
292 gtk_tree_view_set_destroy_count_func (tree_view,
298 gtk_tree_view_accessible_finalize (GObject *object)
300 GtkTreeViewAccessible *accessible = GTK_TREE_VIEW_ACCESSIBLE (object);
302 clear_cached_data (accessible);
304 /* remove any idle handlers still pending */
305 if (accessible->idle_garbage_collect_id)
306 g_source_remove (accessible->idle_garbage_collect_id);
307 if (accessible->idle_cursor_changed_id)
308 g_source_remove (accessible->idle_cursor_changed_id);
309 if (accessible->idle_expand_id)
310 g_source_remove (accessible->idle_expand_id);
312 if (accessible->tree_model)
313 disconnect_model_signals (accessible);
315 if (accessible->cell_info_by_index)
316 g_hash_table_destroy (accessible->cell_info_by_index);
318 if (accessible->col_data)
320 GArray *array = accessible->col_data;
322 /* No need to free the contents of the array since it
323 * just contains pointers to the GtkTreeViewColumn
324 * objects that are in the GtkTreeView.
326 g_array_free (array, TRUE);
329 G_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->finalize (object);
333 gtk_tree_view_accessible_notify_gtk (GObject *obj,
337 GtkTreeView *tree_view;
338 GtkTreeViewAccessible *accessible;
341 widget = GTK_WIDGET (obj);
342 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
343 tree_view = GTK_TREE_VIEW (widget);
345 if (strcmp (pspec->name, "model") == 0)
347 GtkTreeModel *tree_model;
350 tree_model = gtk_tree_view_get_model (tree_view);
351 if (accessible->tree_model)
352 disconnect_model_signals (accessible);
353 clear_cached_data (accessible);
354 accessible->tree_model = tree_model;
355 accessible->n_rows = 0;
359 g_object_add_weak_pointer (G_OBJECT (accessible->tree_model), (gpointer *)&accessible->tree_model);
360 count_rows (tree_model, NULL, NULL, &accessible->n_rows, 0, G_MAXINT);
361 connect_model_signals (tree_view, accessible);
363 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
364 role = ATK_ROLE_TABLE;
366 role = ATK_ROLE_TREE_TABLE;
370 role = ATK_ROLE_UNKNOWN;
372 atk_object_set_role (ATK_OBJECT (accessible), role);
373 g_object_freeze_notify (G_OBJECT (accessible));
374 g_signal_emit_by_name (accessible, "model_changed");
375 g_signal_emit_by_name (accessible, "visible_data_changed");
376 g_object_thaw_notify (G_OBJECT (accessible));
378 else if (strcmp (pspec->name, "hadjustment") == 0)
380 g_object_get (tree_view, "hadjustment", &adj, NULL);
381 g_signal_handlers_disconnect_by_func (accessible->old_hadj,
382 (gpointer) adjustment_changed,
384 accessible->old_hadj = adj;
385 g_object_add_weak_pointer (G_OBJECT (accessible->old_hadj), (gpointer *)&accessible->old_hadj);
386 g_signal_connect (adj, "value-changed", G_CALLBACK (adjustment_changed), tree_view);
388 else if (strcmp (pspec->name, "vadjustment") == 0)
390 g_object_get (tree_view, "vadjustment", &adj, NULL);
391 g_signal_handlers_disconnect_by_func (accessible->old_vadj,
392 (gpointer) adjustment_changed,
394 accessible->old_vadj = adj;
395 g_object_add_weak_pointer (G_OBJECT (accessible->old_hadj), (gpointer *)&accessible->old_vadj);
396 g_signal_connect (adj, "value-changed", G_CALLBACK (adjustment_changed), tree_view);
399 GTK_WIDGET_ACCESSIBLE_CLASS (_gtk_tree_view_accessible_parent_class)->notify_gtk (obj, pspec);
403 gtk_tree_view_accessible_destroyed (GtkWidget *widget,
404 GtkAccessible *gtk_accessible)
407 GtkTreeViewAccessible *accessible;
409 if (!GTK_IS_TREE_VIEW (widget))
412 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_accessible);
413 adj = accessible->old_hadj;
415 g_signal_handlers_disconnect_by_func (adj,
416 (gpointer) adjustment_changed,
418 adj = accessible->old_vadj;
420 g_signal_handlers_disconnect_by_func (adj,
421 (gpointer) adjustment_changed,
423 if (accessible->tree_model)
425 disconnect_model_signals (accessible);
426 accessible->tree_model = NULL;
428 if (accessible->focus_cell)
430 g_object_unref (accessible->focus_cell);
431 accessible->focus_cell = NULL;
433 if (accessible->idle_expand_id)
435 g_source_remove (accessible->idle_expand_id);
436 accessible->idle_expand_id = 0;
441 gtk_tree_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
445 widget = gtk_accessible_get_widget (accessible);
447 g_signal_connect_after (widget, "destroy",
448 G_CALLBACK (gtk_tree_view_accessible_destroyed), accessible);
450 GTK_ACCESSIBLE_CLASS (_gtk_tree_view_accessible_parent_class)->connect_widget_destroyed (accessible);
454 gtk_tree_view_accessible_get_n_children (AtkObject *obj)
457 GtkTreeViewAccessible *accessible;
459 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
463 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
464 return (accessible->n_rows + 1) * accessible->n_cols;
468 gtk_tree_view_accessible_ref_child (AtkObject *obj,
472 GtkTreeViewAccessible *accessible;
473 GtkCellAccessible *cell;
474 GtkTreeView *tree_view;
475 GtkTreeModel *tree_model;
476 GtkCellRenderer *renderer;
478 GtkTreeViewColumn *tv_col;
479 GtkTreeSelection *selection;
483 GtkTreeViewColumn *expander_tv;
484 GList *renderer_list;
486 GtkContainerCellAccessible *container = NULL;
487 GtkRendererCellAccessible *renderer_cell;
488 gboolean is_expander, is_expanded, retval;
489 gboolean editable = FALSE;
492 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
496 if (i >= gtk_tree_view_accessible_get_n_children (obj))
499 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
500 tree_view = GTK_TREE_VIEW (widget);
501 if (i < accessible->n_cols)
503 tv_col = gtk_tree_view_get_column (tree_view, i);
504 child = get_header_from_column (tv_col);
506 g_object_ref (child);
510 /* Check whether the child is cached */
511 cell = find_cell (accessible, i);
515 return ATK_OBJECT (cell);
518 if (accessible->focus_cell == NULL)
519 focus_index = get_focus_index (tree_view);
523 /* Find the TreePath and GtkTreeViewColumn for the index */
524 if (!get_path_column_from_index (tree_view, i, &path, &tv_col))
527 tree_model = gtk_tree_view_get_model (tree_view);
528 retval = gtk_tree_model_get_iter (tree_model, &iter, path);
532 expander_tv = gtk_tree_view_get_expander_column (tree_view);
535 if (gtk_tree_model_iter_has_child (tree_model, &iter))
537 if (expander_tv == tv_col)
540 is_expanded = gtk_tree_view_row_expanded (tree_view, path);
543 gtk_tree_view_column_cell_set_cell_data (tv_col, tree_model, &iter,
544 is_expander, is_expanded);
546 renderer_list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
548 /* If there are more than one renderer in the list,
551 if (renderer_list && renderer_list->next)
553 GtkCellAccessible *container_cell;
555 container = _gtk_container_cell_accessible_new ();
557 container_cell = GTK_CELL_ACCESSIBLE (container);
558 _gtk_cell_accessible_initialise (container_cell, widget, ATK_OBJECT (accessible), i);
560 /* The GtkTreeViewAccessibleCellInfo structure for the container will
561 * be before the ones for the cells so that the first one we find for
562 * a position will be for the container
564 cell_info_new (accessible, tree_model, path, tv_col, container_cell);
565 container_cell->refresh_index = refresh_cell_index;
566 parent = ATK_OBJECT (container);
569 parent = ATK_OBJECT (accessible);
573 /* Now we make a fake cell_renderer if there is no cell
576 if (renderer_list == NULL)
578 GtkCellRenderer *fake_renderer;
580 fake_renderer = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, NULL);
581 child = _gtk_text_cell_accessible_new ();
582 cell = GTK_CELL_ACCESSIBLE (child);
583 renderer_cell = GTK_RENDERER_CELL_ACCESSIBLE (child);
584 renderer_cell->renderer = fake_renderer;
586 /* Create the GtkTreeViewAccessibleCellInfo structure for this cell */
587 cell_info_new (accessible, tree_model, path, tv_col, cell);
589 _gtk_cell_accessible_initialise (cell, widget, parent, i);
591 cell->refresh_index = refresh_cell_index;
593 /* Set state if it is expandable */
596 set_cell_expandable (cell);
598 _gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, FALSE);
603 for (l = renderer_list; l; l = l->next)
605 renderer = GTK_CELL_RENDERER (l->data);
607 if (GTK_IS_CELL_RENDERER_TEXT (renderer))
609 g_object_get (G_OBJECT (renderer), "editable", &editable, NULL);
610 child = _gtk_text_cell_accessible_new ();
612 else if (GTK_IS_CELL_RENDERER_TOGGLE (renderer))
613 child = _gtk_boolean_cell_accessible_new ();
614 else if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
615 child = _gtk_image_cell_accessible_new ();
617 child = _gtk_renderer_cell_accessible_new ();
619 cell = GTK_CELL_ACCESSIBLE (child);
620 renderer_cell = GTK_RENDERER_CELL_ACCESSIBLE (child);
622 /* Create the GtkTreeViewAccessibleCellInfo for this cell */
623 cell_info_new (accessible, tree_model, path, tv_col, cell);
625 _gtk_cell_accessible_initialise (cell, widget, parent, i);
628 _gtk_container_cell_accessible_add_child (container, cell);
630 cell->refresh_index = refresh_cell_index;
632 update_cell_value (renderer_cell, accessible, FALSE);
634 /* Add the actions appropriate for this cell */
635 add_cell_actions (cell, editable);
637 /* Set state if it is expandable */
640 set_cell_expandable (cell);
642 _gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, FALSE);
645 /* If the column is visible, sets the cell's state */
646 if (gtk_tree_view_column_get_visible (tv_col))
647 set_cell_visibility (tree_view, cell, tv_col, path, FALSE);
649 /* If the row is selected, all cells on the row are selected */
650 selection = gtk_tree_view_get_selection (tree_view);
652 if (gtk_tree_selection_path_is_selected (selection, path))
653 _gtk_cell_accessible_add_state (cell, ATK_STATE_SELECTED, FALSE);
655 _gtk_cell_accessible_add_state (cell, ATK_STATE_FOCUSABLE, FALSE);
656 if (focus_index == i)
658 accessible->focus_cell = g_object_ref (cell);
659 _gtk_cell_accessible_add_state (cell, ATK_STATE_FOCUSED, FALSE);
660 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
663 g_list_free (renderer_list);
665 child = ATK_OBJECT (container);
668 if (expander_tv == tv_col)
670 AtkRelationSet *relation_set;
671 AtkObject *accessible_array[1];
672 AtkRelation* relation;
673 AtkObject *parent_node;
675 relation_set = atk_object_ref_relation_set (ATK_OBJECT (child));
677 gtk_tree_path_up (path);
678 if (gtk_tree_path_get_depth (path) == 0)
684 parent_index = get_index (tree_view, path, i % accessible->n_cols);
685 parent_node = atk_object_ref_accessible_child (obj, parent_index);
687 accessible_array[0] = parent_node;
688 relation = atk_relation_new (accessible_array, 1,
689 ATK_RELATION_NODE_CHILD_OF);
690 atk_relation_set_add (relation_set, relation);
691 atk_object_add_relationship (parent_node, ATK_RELATION_NODE_PARENT_OF, child);
692 g_object_unref (relation);
693 g_object_unref (relation_set);
695 gtk_tree_path_free (path);
697 /* We do not increase the reference count here; when g_object_unref()
698 * is called for the cell then cell_destroyed() is called and this
699 * removes the cell from the cache.
705 gtk_tree_view_accessible_ref_state_set (AtkObject *obj)
707 AtkStateSet *state_set;
710 state_set = ATK_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->ref_state_set (obj);
711 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
714 atk_state_set_add_state (state_set, ATK_STATE_MANAGES_DESCENDANTS);
720 _gtk_tree_view_accessible_class_init (GtkTreeViewAccessibleClass *klass)
722 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
723 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
724 GtkAccessibleClass *accessible_class = (GtkAccessibleClass*)klass;
725 GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
726 GtkContainerAccessibleClass *container_class = (GtkContainerAccessibleClass*)klass;
728 class->get_n_children = gtk_tree_view_accessible_get_n_children;
729 class->ref_child = gtk_tree_view_accessible_ref_child;
730 class->ref_state_set = gtk_tree_view_accessible_ref_state_set;
731 class->initialize = gtk_tree_view_accessible_initialize;
733 widget_class->notify_gtk = gtk_tree_view_accessible_notify_gtk;
735 accessible_class->connect_widget_destroyed = gtk_tree_view_accessible_connect_widget_destroyed;
737 /* The children of a GtkTreeView are the buttons at the top of the columns
738 * we do not represent these as children so we do not want to report
739 * children added or deleted when these changed.
741 container_class->add_gtk = NULL;
742 container_class->remove_gtk = NULL;
744 gobject_class->finalize = gtk_tree_view_accessible_finalize;
748 _gtk_tree_view_accessible_init (GtkTreeViewAccessible *view)
753 get_focus_index (GtkTreeView *tree_view)
755 GtkTreePath *focus_path;
756 GtkTreeViewColumn *focus_column;
759 gtk_tree_view_get_cursor (tree_view, &focus_path, &focus_column);
760 if (focus_path && focus_column)
761 index = get_index (tree_view, focus_path,
762 get_column_number (tree_view, focus_column, FALSE));
767 gtk_tree_path_free (focus_path);
772 /* This function returns a reference to the accessible object
773 * for the cell in the treeview which has focus, if any
776 gtk_tree_view_accessible_ref_focus_cell (GtkTreeView *tree_view)
778 AtkObject *focus_cell = NULL;
782 focus_index = get_focus_index (tree_view);
783 if (focus_index >= 0)
785 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
786 focus_cell = atk_object_ref_accessible_child (atk_obj, focus_index);
795 gtk_tree_view_accessible_ref_accessible_at_point (AtkComponent *component,
798 AtkCoordType coord_type)
801 GtkTreeView *tree_view;
803 GtkTreeViewColumn *tv_column;
808 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
812 tree_view = GTK_TREE_VIEW (widget);
814 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
815 gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, x, y, &bx, &by);
816 ret_val = gtk_tree_view_get_path_at_pos (tree_view,
817 bx - x_pos, by - y_pos,
818 &path, &tv_column, NULL, NULL);
823 column = get_column_number (tree_view, tv_column, FALSE);
824 index = get_index (tree_view, path, column);
825 gtk_tree_path_free (path);
827 return gtk_tree_view_accessible_ref_child (ATK_OBJECT (component), index);
831 g_warning ("gtk_tree_view_accessible_ref_accessible_at_point: gtk_tree_view_get_path_at_pos () failed\n");
837 atk_component_interface_init (AtkComponentIface *iface)
839 iface->ref_accessible_at_point = gtk_tree_view_accessible_ref_accessible_at_point;
845 gtk_tree_view_accessible_get_index_at (AtkTable *table,
850 GtkTreeView *tree_view;
857 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
861 n_cols = atk_table_get_n_columns (table);
862 n_rows = atk_table_get_n_rows (table);
864 if (row >= n_rows || column >= n_cols)
867 tree_view = GTK_TREE_VIEW (widget);
868 actual_column = get_actual_column_number (tree_view, column);
870 set_iter_nth_row (tree_view, &iter, row);
871 path = gtk_tree_model_get_path (gtk_tree_view_get_model (tree_view), &iter);
873 index = get_index (tree_view, path, actual_column);
874 gtk_tree_path_free (path);
880 gtk_tree_view_accessible_get_column_at_index (AtkTable *table,
884 GtkTreeView *tree_view;
887 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
891 tree_view = GTK_TREE_VIEW (widget);
892 n_columns = GTK_TREE_VIEW_ACCESSIBLE (table)->n_cols;
897 index = index % n_columns;
899 return get_visible_column_number (tree_view, index);
903 gtk_tree_view_accessible_get_row_at_index (AtkTable *table,
907 GtkTreeView *tree_view;
910 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
914 tree_view = GTK_TREE_VIEW (widget);
915 if (get_path_column_from_index (tree_view, index, &path, NULL))
917 gint row = get_row_from_tree_path (tree_view, path);
918 gtk_tree_path_free (path);
926 gtk_tree_view_accessible_table_ref_at (AtkTable *table,
932 index = gtk_tree_view_accessible_get_index_at (table, row, column);
936 return gtk_tree_view_accessible_ref_child (ATK_OBJECT (table), index);
940 gtk_tree_view_accessible_get_n_rows (AtkTable *table)
943 GtkTreeView *tree_view;
944 GtkTreeModel *tree_model;
947 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
951 tree_view = GTK_TREE_VIEW (widget);
952 tree_model = gtk_tree_view_get_model (tree_view);
956 else if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
957 /* No collapsed rows in a list store */
958 n_rows = GTK_TREE_VIEW_ACCESSIBLE (table)->n_rows;
961 GtkTreePath *root_tree;
964 root_tree = gtk_tree_path_new_first ();
965 iterate_thru_children (tree_view, tree_model,
966 root_tree, NULL, &n_rows, 0);
967 gtk_tree_path_free (root_tree);
974 gtk_tree_view_accessible_get_n_columns (AtkTable *table)
977 GtkTreeView *tree_view;
978 GtkTreeViewColumn *tv_col;
982 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
986 tree_view = GTK_TREE_VIEW (widget);
987 tv_col = gtk_tree_view_get_column (tree_view, i);
989 while (tv_col != NULL)
991 if (gtk_tree_view_column_get_visible (tv_col))
995 tv_col = gtk_tree_view_get_column (tree_view, i);
1002 gtk_tree_view_accessible_is_row_selected (AtkTable *table,
1006 GtkTreeView *tree_view;
1007 GtkTreeSelection *selection;
1010 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1017 tree_view = GTK_TREE_VIEW (widget);
1018 selection = gtk_tree_view_get_selection (tree_view);
1020 set_iter_nth_row (tree_view, &iter, row);
1021 return gtk_tree_selection_iter_is_selected (selection, &iter);
1025 gtk_tree_view_accessible_is_selected (AtkTable *table,
1029 return gtk_tree_view_accessible_is_row_selected (table, row);
1033 get_selected_rows (GtkTreeModel *model,
1038 GPtrArray *array = (GPtrArray *)data;
1040 g_ptr_array_add (array, gtk_tree_path_copy (path));
1044 gtk_tree_view_accessible_get_selected_rows (AtkTable *table,
1045 gint **rows_selected)
1048 GtkTreeView *tree_view;
1049 GtkTreeModel *tree_model;
1051 GtkTreeSelection *selection;
1052 GtkTreePath *tree_path;
1055 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1059 tree_view = GTK_TREE_VIEW (widget);
1060 selection = gtk_tree_view_get_selection (tree_view);
1062 switch (gtk_tree_selection_get_mode (selection))
1064 case GTK_SELECTION_SINGLE:
1065 case GTK_SELECTION_BROWSE:
1066 if (gtk_tree_selection_get_selected (selection, &tree_model, &iter))
1072 *rows_selected = g_new (gint, 1);
1073 tree_path = gtk_tree_model_get_path (tree_model, &iter);
1074 row = get_row_from_tree_path (tree_view, tree_path);
1075 gtk_tree_path_free (tree_path);
1077 /* shouldn't ever happen */
1078 g_return_val_if_fail (row != -1, 0);
1080 *rows_selected[0] = row;
1085 case GTK_SELECTION_MULTIPLE:
1087 GPtrArray *array = g_ptr_array_new();
1089 gtk_tree_selection_selected_foreach (selection, get_selected_rows, array);
1090 ret_val = array->len;
1092 if (rows_selected && ret_val)
1096 *rows_selected = g_new (gint, ret_val);
1097 for (i = 0; i < ret_val; i++)
1101 tree_path = (GtkTreePath *) g_ptr_array_index (array, i);
1102 row = get_row_from_tree_path (tree_view, tree_path);
1103 gtk_tree_path_free (tree_path);
1104 (*rows_selected)[i] = row;
1107 g_ptr_array_free (array, FALSE);
1110 case GTK_SELECTION_NONE:
1117 gtk_tree_view_accessible_add_row_selection (AtkTable *table,
1121 GtkTreeView *tree_view;
1122 GtkTreeModel *tree_model;
1123 GtkTreeSelection *selection;
1124 GtkTreePath *tree_path;
1125 GtkTreeIter iter_to_row;
1127 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1131 if (!gtk_tree_view_accessible_is_row_selected (table, row))
1133 tree_view = GTK_TREE_VIEW (widget);
1134 tree_model = gtk_tree_view_get_model (tree_view);
1135 selection = gtk_tree_view_get_selection (tree_view);
1137 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
1139 tree_path = gtk_tree_path_new ();
1140 gtk_tree_path_append_index (tree_path, row);
1141 gtk_tree_selection_select_path (selection,tree_path);
1142 gtk_tree_path_free (tree_path);
1146 set_iter_nth_row (tree_view, &iter_to_row, row);
1147 gtk_tree_selection_select_iter (selection, &iter_to_row);
1151 return gtk_tree_view_accessible_is_row_selected (table, row);
1155 gtk_tree_view_accessible_remove_row_selection (AtkTable *table,
1159 GtkTreeView *tree_view;
1160 GtkTreeSelection *selection;
1162 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1166 tree_view = GTK_TREE_VIEW (widget);
1167 selection = gtk_tree_view_get_selection (tree_view);
1169 if (gtk_tree_view_accessible_is_row_selected (table, row))
1171 gtk_tree_selection_unselect_all (selection);
1179 gtk_tree_view_accessible_get_column_header (AtkTable *table,
1183 GtkTreeView *tree_view;
1184 GtkTreeViewColumn *tv_col;
1186 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1190 tree_view = GTK_TREE_VIEW (widget);
1191 tv_col = get_column (tree_view, in_col);
1192 return get_header_from_column (tv_col);
1195 static const gchar *
1196 gtk_tree_view_accessible_get_column_description (AtkTable *table,
1200 GtkTreeView *tree_view;
1201 GtkTreeViewColumn *tv_col;
1203 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1207 tree_view = GTK_TREE_VIEW (widget);
1208 tv_col = get_column (tree_view, in_col);
1212 return gtk_tree_view_column_get_title (tv_col);
1216 atk_table_interface_init (AtkTableIface *iface)
1218 iface->ref_at = gtk_tree_view_accessible_table_ref_at;
1219 iface->get_n_rows = gtk_tree_view_accessible_get_n_rows;
1220 iface->get_n_columns = gtk_tree_view_accessible_get_n_columns;
1221 iface->get_index_at = gtk_tree_view_accessible_get_index_at;
1222 iface->get_column_at_index = gtk_tree_view_accessible_get_column_at_index;
1223 iface->get_row_at_index = gtk_tree_view_accessible_get_row_at_index;
1224 iface->is_row_selected = gtk_tree_view_accessible_is_row_selected;
1225 iface->is_selected = gtk_tree_view_accessible_is_selected;
1226 iface->get_selected_rows = gtk_tree_view_accessible_get_selected_rows;
1227 iface->add_row_selection = gtk_tree_view_accessible_add_row_selection;
1228 iface->remove_row_selection = gtk_tree_view_accessible_remove_row_selection;
1229 iface->get_column_extent_at = NULL;
1230 iface->get_row_extent_at = NULL;
1231 iface->get_column_header = gtk_tree_view_accessible_get_column_header;
1232 iface->get_column_description = gtk_tree_view_accessible_get_column_description;
1235 /* atkselection.h */
1238 gtk_tree_view_accessible_add_selection (AtkSelection *selection,
1245 table = ATK_TABLE (selection);
1246 n_columns = gtk_tree_view_accessible_get_n_columns (table);
1250 row = gtk_tree_view_accessible_get_row_at_index (table, i);
1251 return gtk_tree_view_accessible_add_row_selection (table, row);
1255 gtk_tree_view_accessible_clear_selection (AtkSelection *selection)
1258 GtkTreeView *tree_view;
1259 GtkTreeSelection *tree_selection;
1261 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
1265 tree_view = GTK_TREE_VIEW (widget);
1266 tree_selection = gtk_tree_view_get_selection (tree_view);
1268 gtk_tree_selection_unselect_all (tree_selection);
1273 gtk_tree_view_accessible_ref_selection (AtkSelection *selection,
1282 table = ATK_TABLE (selection);
1283 n_columns = gtk_tree_view_accessible_get_n_columns (table);
1284 n_selected = gtk_tree_view_accessible_get_selected_rows (table, &selected);
1285 if (i >= n_columns * n_selected)
1288 row = selected[i / n_columns];
1291 return gtk_tree_view_accessible_table_ref_at (table, row, i % n_columns);
1295 gtk_tree_view_accessible_get_selection_count (AtkSelection *selection)
1300 table = ATK_TABLE (selection);
1301 n_selected = gtk_tree_view_accessible_get_selected_rows (table, NULL);
1303 n_selected *= gtk_tree_view_accessible_get_n_columns (table);
1308 gtk_tree_view_accessible_is_child_selected (AtkSelection *selection,
1314 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
1318 row = atk_table_get_row_at_index (ATK_TABLE (selection), i);
1320 return gtk_tree_view_accessible_is_row_selected (ATK_TABLE (selection), row);
1323 static void atk_selection_interface_init (AtkSelectionIface *iface)
1325 iface->add_selection = gtk_tree_view_accessible_add_selection;
1326 iface->clear_selection = gtk_tree_view_accessible_clear_selection;
1327 iface->ref_selection = gtk_tree_view_accessible_ref_selection;
1328 iface->get_selection_count = gtk_tree_view_accessible_get_selection_count;
1329 iface->is_child_selected = gtk_tree_view_accessible_is_child_selected;
1332 #define EXTRA_EXPANDER_PADDING 4
1335 gtk_tree_view_accessible_get_cell_area (GailCellParent *parent,
1336 GtkCellAccessible *cell,
1337 GdkRectangle *cell_rect)
1340 GtkTreeView *tree_view;
1341 GtkTreeViewColumn *tv_col;
1343 AtkObject *parent_cell;
1344 GtkTreeViewAccessibleCellInfo *cell_info;
1345 GtkCellAccessible *top_cell;
1347 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1351 tree_view = GTK_TREE_VIEW (widget);
1352 parent_cell = atk_object_get_parent (ATK_OBJECT (cell));
1353 if (parent_cell != ATK_OBJECT (parent))
1354 top_cell = GTK_CELL_ACCESSIBLE (parent_cell);
1357 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), top_cell, TRUE);
1358 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
1360 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
1361 tv_col = cell_info->cell_col_ref;
1362 if (path && cell_info->in_use)
1364 GtkTreeViewColumn *expander_column;
1365 gint focus_line_width;
1367 gtk_tree_view_get_cell_area (tree_view, path, tv_col, cell_rect);
1368 expander_column = gtk_tree_view_get_expander_column (tree_view);
1369 if (expander_column == tv_col)
1372 gtk_widget_style_get (widget,
1373 "expander_size", &expander_size,
1375 cell_rect->x += expander_size + EXTRA_EXPANDER_PADDING;
1376 cell_rect->width -= expander_size + EXTRA_EXPANDER_PADDING;
1378 gtk_widget_style_get (widget,
1379 "focus-line-width", &focus_line_width,
1382 cell_rect->x += focus_line_width;
1383 cell_rect->width -= 2 * focus_line_width;
1385 gtk_tree_path_free (path);
1387 /* A column has more than one renderer so we find the position
1390 if (top_cell != cell)
1397 GtkCellRenderer *renderer;
1399 cell_index = atk_object_get_index_in_parent (ATK_OBJECT (cell));
1400 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
1401 renderer = g_list_nth_data (renderers, cell_index);
1403 found = gtk_tree_view_column_cell_get_position (tv_col, renderer, &cell_start, &cell_width);
1406 cell_rect->x += cell_start;
1407 cell_rect->width = cell_width;
1409 g_list_free (renderers);
1416 gtk_tree_view_accessible_get_cell_extents (GailCellParent *parent,
1417 GtkCellAccessible *cell,
1422 AtkCoordType coord_type)
1425 GtkTreeView *tree_view;
1426 GdkWindow *bin_window;
1427 GdkRectangle cell_rect;
1430 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1434 tree_view = GTK_TREE_VIEW (widget);
1435 gtk_tree_view_accessible_get_cell_area (parent, cell, &cell_rect);
1436 bin_window = gtk_tree_view_get_bin_window (tree_view);
1437 gdk_window_get_origin (bin_window, &w_x, &w_y);
1439 if (coord_type == ATK_XY_WINDOW)
1442 gint x_toplevel, y_toplevel;
1444 window = gdk_window_get_toplevel (bin_window);
1445 gdk_window_get_origin (window, &x_toplevel, &y_toplevel);
1451 *width = cell_rect.width;
1452 *height = cell_rect.height;
1453 if (is_cell_showing (tree_view, &cell_rect))
1455 *x = cell_rect.x + w_x;
1456 *y = cell_rect.y + w_y;
1466 gtk_tree_view_accessible_grab_cell_focus (GailCellParent *parent,
1467 GtkCellAccessible *cell)
1470 GtkTreeView *tree_view;
1471 GtkTreeViewColumn *tv_col;
1473 AtkObject *parent_cell;
1474 AtkObject *cell_object;
1475 GtkTreeViewAccessibleCellInfo *cell_info;
1476 GtkCellRenderer *renderer = NULL;
1477 GtkWidget *toplevel;
1480 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1484 tree_view = GTK_TREE_VIEW (widget);
1486 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
1487 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
1489 cell_object = ATK_OBJECT (cell);
1490 parent_cell = atk_object_get_parent (cell_object);
1491 tv_col = cell_info->cell_col_ref;
1492 if (parent_cell != ATK_OBJECT (parent))
1494 /* GtkCellAccessible is in a GtkContainerCellAccessible.
1495 * The GtkTreeViewColumn has multiple renderers;
1496 * find the corresponding one.
1500 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
1501 if (cell_info->in_use)
1503 index = atk_object_get_index_in_parent (cell_object);
1504 renderer = g_list_nth_data (renderers, index);
1506 g_list_free (renderers);
1508 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
1509 if (path && cell_info->in_use)
1512 gtk_tree_view_set_cursor_on_cell (tree_view, path, tv_col, renderer, FALSE);
1514 gtk_tree_view_set_cursor (tree_view, path, tv_col, FALSE);
1516 gtk_tree_path_free (path);
1517 gtk_widget_grab_focus (widget);
1518 toplevel = gtk_widget_get_toplevel (widget);
1519 if (gtk_widget_is_toplevel (toplevel))
1521 #ifdef GDK_WINDOWING_X11
1522 gtk_window_present_with_time (GTK_WINDOW (toplevel),
1523 gdk_x11_get_server_time (gtk_widget_get_window (widget)));
1525 gtk_window_present (GTK_WINDOW (toplevel));
1535 static void gail_cell_parent_interface_init (GailCellParentIface *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 (strcmp (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
2107 gtk_tree_model_get_iter (tree_model, &iter, path);
2109 /* Figure out number of visible children. */
2110 if (gtk_tree_model_iter_has_child (tree_model, &iter))
2113 * By passing path into this function, we find the number of
2114 * visible children of path.
2117 iterate_thru_children (tree_view, tree_model,
2118 path, NULL, &n_inserted, 0);
2120 /* Must add one to include the row that is being added */
2126 /* Set rows below the inserted row to ATK_STATE_STALE */
2127 traverse_cells (accessible, path, TRUE, TRUE);
2129 /* Generate row-inserted signal */
2130 g_signal_emit_by_name (atk_obj, "row_inserted", row, n_inserted);
2132 /* Generate children-changed signals */
2133 n_cols = gtk_tree_view_accessible_get_n_columns (ATK_TABLE (atk_obj));
2134 for (child_row = row; child_row < (row + n_inserted); child_row++)
2136 for (col = 0; col < n_cols; col++)
2138 /* Pass NULL as the child object, i.e. 4th argument */
2139 g_signal_emit_by_name (atk_obj, "children_changed::add",
2140 ((row * n_cols) + col), NULL, NULL);
2146 /* The row has been inserted inside another row. This can
2147 * cause a row that previously couldn't be expanded to now
2150 path_copy = gtk_tree_path_copy (path);
2151 gtk_tree_path_up (path_copy);
2152 set_expand_state (tree_view, tree_model, accessible, path_copy, TRUE);
2153 gtk_tree_path_free (path_copy);
2158 model_row_deleted (GtkTreeModel *tree_model,
2162 GtkTreeView *tree_view = (GtkTreeView *)user_data;
2163 GtkTreePath *path_copy;
2165 GtkTreeViewAccessible *accessible;
2168 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
2169 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
2171 accessible->n_rows--;
2173 if (accessible->idle_expand_id)
2175 g_source_remove (accessible->idle_expand_id);
2176 gtk_tree_path_free (accessible->idle_expand_path);
2177 accessible->idle_expand_id = 0;
2180 /* Check to see if row is visible */
2181 clean_rows (accessible);
2183 /* Set rows at or below the specified row to ATK_STATE_STALE */
2184 traverse_cells (accessible, path, TRUE, TRUE);
2186 /* If deleting a row with a depth > 1, then this may affect the
2187 * expansion/contraction of its parent(s). Make sure this is
2190 if (gtk_tree_path_get_depth (path) > 1)
2192 path_copy = gtk_tree_path_copy (path);
2193 gtk_tree_path_up (path_copy);
2194 set_expand_state (tree_view, tree_model, accessible, path_copy, TRUE);
2195 gtk_tree_path_free (path_copy);
2197 row = get_row_from_tree_path (tree_view, path);
2199 /* If the row which is deleted is not visible because it is a child of
2200 * a collapsed row then row will be -1
2203 g_signal_emit_by_name (atk_obj, "row_deleted", row,
2204 accessible->n_children_deleted + 1);
2205 accessible->n_children_deleted = 0;
2207 /* Generate children-changed signals */
2208 for (col = 0; col < accessible->n_cols; col++)
2210 /* Pass NULL as the child object, 4th argument */
2211 g_signal_emit_by_name (atk_obj, "children_changed::remove",
2212 ((row * accessible->n_cols) + col), NULL, NULL);
2216 /* This function gets called when a row is deleted or when rows are
2217 * removed from the view due to a collapse event. Note that the
2218 * count is the number of visible *children* of the deleted row,
2219 * so it does not include the row being deleted.
2221 * As this function is called before the rows are removed we just note
2222 * the number of rows and then deal with it when we get a notification
2223 * that rows were deleted or collapsed.
2226 destroy_count_func (GtkTreeView *tree_view,
2232 GtkTreeViewAccessible *accessible;
2234 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
2235 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
2237 if (accessible->n_children_deleted != 0)
2240 accessible->n_children_deleted = count;
2244 model_rows_reordered (GtkTreeModel *tree_model,
2250 GtkTreeView *tree_view = (GtkTreeView *)user_data;
2252 GtkTreeViewAccessible *accessible;
2254 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
2255 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
2257 if (accessible->idle_expand_id)
2259 g_source_remove (accessible->idle_expand_id);
2260 gtk_tree_path_free (accessible->idle_expand_path);
2261 accessible->idle_expand_id = 0;
2263 traverse_cells (accessible, NULL, TRUE, FALSE);
2265 g_signal_emit_by_name (atk_obj, "row_reordered");
2269 set_cell_visibility (GtkTreeView *tree_view,
2270 GtkCellAccessible *cell,
2271 GtkTreeViewColumn *tv_col,
2272 GtkTreePath *tree_path,
2273 gboolean emit_signal)
2275 GdkRectangle cell_rect;
2277 /* Get these three values in tree coords */
2278 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
2279 gtk_tree_view_get_cell_area (tree_view, tree_path, tv_col, &cell_rect);
2281 cell_rect.height = 0;
2283 if (cell_rect.height > 0)
2285 /* The height will be zero for a cell for which an antecedent
2288 _gtk_cell_accessible_add_state (cell, ATK_STATE_VISIBLE, emit_signal);
2289 if (is_cell_showing (tree_view, &cell_rect))
2290 _gtk_cell_accessible_add_state (cell, ATK_STATE_SHOWING, emit_signal);
2292 _gtk_cell_accessible_remove_state (cell, ATK_STATE_SHOWING, emit_signal);
2296 _gtk_cell_accessible_remove_state (cell, ATK_STATE_VISIBLE, emit_signal);
2297 _gtk_cell_accessible_remove_state (cell, ATK_STATE_SHOWING, emit_signal);
2302 is_cell_showing (GtkTreeView *tree_view,
2303 GdkRectangle *cell_rect)
2305 GdkRectangle rect, *visible_rect;
2306 GdkRectangle rect1, *tree_cell_rect;
2308 gboolean is_showing;
2310 /* A cell is considered "SHOWING" if any part of the cell is
2311 * in the visible area. Other ways we could do this is by a
2312 * cell's midpoint or if the cell is fully in the visible range.
2313 * Since we have the cell_rect x, y, width, height of the cell,
2314 * any of these is easy to compute.
2316 * It is assumed that cell's rectangle is in widget coordinates
2317 * so we must transform to tree cordinates.
2319 visible_rect = ▭
2320 tree_cell_rect = &rect1;
2321 tree_cell_rect->x = cell_rect->x;
2322 tree_cell_rect->y = cell_rect->y;
2323 tree_cell_rect->width = cell_rect->width;
2324 tree_cell_rect->height = cell_rect->height;
2326 gtk_tree_view_get_visible_rect (tree_view, visible_rect);
2327 gtk_tree_view_convert_tree_to_bin_window_coords (tree_view, visible_rect->x,
2328 visible_rect->y, &bx, &by);
2330 if (((tree_cell_rect->x + tree_cell_rect->width) < bx) ||
2331 ((tree_cell_rect->y + tree_cell_rect->height) < by) ||
2332 (tree_cell_rect->x > (bx + visible_rect->width)) ||
2333 (tree_cell_rect->y > (by + visible_rect->height)))
2343 /* This function is called when a cell's flyweight is created in
2344 * gtk_tree_view_accessible_table_ref_at with emit_change_signal
2345 * set to FALSE and in model_row_changed() on receipt of "row-changed"
2346 * signal when emit_change_signal is set to TRUE
2349 update_cell_value (GtkRendererCellAccessible *renderer_cell,
2350 GtkTreeViewAccessible *accessible,
2351 gboolean emit_change_signal)
2353 GtkTreeViewAccessibleCellInfo *cell_info;
2354 GtkTreeView *tree_view;
2355 GtkTreeModel *tree_model;
2358 GList *renderers, *cur_renderer;
2360 GtkRendererCellAccessibleClass *renderer_cell_class;
2361 GtkCellRendererClass *gtk_cell_renderer_class;
2362 GtkCellAccessible *cell;
2365 gboolean is_expander, is_expanded;
2367 renderer_cell_class = GTK_RENDERER_CELL_ACCESSIBLE_GET_CLASS (renderer_cell);
2368 if (renderer_cell->renderer)
2369 gtk_cell_renderer_class = GTK_CELL_RENDERER_GET_CLASS (renderer_cell->renderer);
2371 gtk_cell_renderer_class = NULL;
2373 prop_list = renderer_cell_class->property_list;
2375 cell = GTK_CELL_ACCESSIBLE (renderer_cell);
2376 cell_info = find_cell_info (accessible, cell, TRUE);
2377 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
2380 if (emit_change_signal && cell_info->in_use)
2382 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
2383 tree_model = gtk_tree_view_get_model (tree_view);
2384 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2388 gtk_tree_model_get_iter (tree_model, &iter, path);
2389 is_expander = FALSE;
2390 is_expanded = FALSE;
2391 if (gtk_tree_model_iter_has_child (tree_model, &iter))
2393 GtkTreeViewColumn *expander_tv;
2395 expander_tv = gtk_tree_view_get_expander_column (tree_view);
2396 if (expander_tv == cell_info->cell_col_ref)
2399 is_expanded = gtk_tree_view_row_expanded (tree_view, path);
2402 gtk_tree_path_free (path);
2403 gtk_tree_view_column_cell_set_cell_data (cell_info->cell_col_ref,
2405 is_expander, is_expanded);
2407 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_info->cell_col_ref));
2411 /* If the cell is in a container, its index is used to find the renderer
2412 * in the list. Otherwise, we assume that the cell is represented
2413 * by the first renderer in the list
2416 if (cell_info->in_use)
2418 parent = atk_object_get_parent (ATK_OBJECT (cell));
2420 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
2421 cur_renderer = g_list_nth (renderers, cell->index);
2423 cur_renderer = renderers;
2428 if (cur_renderer == NULL)
2431 if (gtk_cell_renderer_class)
2435 spec = g_object_class_find_property
2436 (G_OBJECT_CLASS (gtk_cell_renderer_class), *prop_list);
2440 GValue value = { 0, };
2442 g_value_init (&value, spec->value_type);
2443 g_object_get_property (cur_renderer->data, *prop_list, &value);
2444 g_object_set_property (G_OBJECT (renderer_cell->renderer),
2445 *prop_list, &value);
2446 g_value_unset (&value);
2449 g_warning ("Invalid property: %s\n", *prop_list);
2453 g_list_free (renderers);
2455 return _gtk_renderer_cell_accessible_update_cache (renderer_cell, emit_change_signal);
2459 get_row_from_tree_path (GtkTreeView *tree_view,
2462 GtkTreeModel *tree_model;
2463 GtkTreePath *root_tree;
2466 tree_model = gtk_tree_view_get_model (tree_view);
2468 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
2469 row = gtk_tree_path_get_indices (path)[0];
2472 root_tree = gtk_tree_path_new_first ();
2474 iterate_thru_children (tree_view, tree_model, root_tree, path, &row, 0);
2475 gtk_tree_path_free (root_tree);
2484 * Get the specified GtkTreeViewColumn in the GtkTreeView.
2485 * Only visible columns are considered.
2487 static GtkTreeViewColumn *
2488 get_column (GtkTreeView *tree_view,
2491 GtkTreeViewColumn *tv_col;
2497 g_warning ("Request for invalid column %d\n", in_col);
2501 tv_col = gtk_tree_view_get_column (tree_view, i);
2502 while (tv_col != NULL)
2504 if (gtk_tree_view_column_get_visible (tv_col))
2506 if (in_col == n_cols)
2508 tv_col = gtk_tree_view_get_column (tree_view, ++i);
2511 if (in_col != n_cols)
2513 g_warning ("Request for invalid column %d\n", in_col);
2520 get_actual_column_number (GtkTreeView *tree_view,
2521 gint visible_column)
2523 GtkTreeViewColumn *tv_col;
2524 gint actual_column = 0;
2525 gint visible_columns = -1;
2527 /* This function calculates the column number which corresponds
2528 * to the specified visible column number
2530 tv_col = gtk_tree_view_get_column (tree_view, actual_column);
2531 while (tv_col != NULL)
2533 if (gtk_tree_view_column_get_visible (tv_col))
2535 if (visible_columns == visible_column)
2536 return actual_column;
2537 tv_col = gtk_tree_view_get_column (tree_view, ++actual_column);
2539 g_warning ("get_actual_column_number failed for %d\n", visible_column);
2544 get_visible_column_number (GtkTreeView *tree_view,
2547 GtkTreeViewColumn *tv_col;
2549 gint visible_columns = -1;
2551 /* This function calculates the visible column number
2552 * which corresponds to the specified actual column number
2554 tv_col = gtk_tree_view_get_column (tree_view, column);
2556 while (tv_col != NULL)
2558 if (gtk_tree_view_column_get_visible (tv_col))
2561 if (actual_column == column)
2562 return visible_columns;
2565 if (actual_column == column)
2567 tv_col = gtk_tree_view_get_column (tree_view, ++column);
2569 g_warning ("get_visible_column_number failed for %d\n", actual_column);
2573 /* Helper recursive function that returns an iter to nth row
2575 static GtkTreeIter *
2576 return_iter_nth_row (GtkTreeView *tree_view,
2577 GtkTreeModel *tree_model,
2582 GtkTreePath *current_path;
2583 GtkTreeIter new_iter;
2584 gboolean row_expanded;
2586 current_path = gtk_tree_model_get_path (tree_model, iter);
2587 if (increment == row)
2589 gtk_tree_path_free (current_path);
2593 row_expanded = gtk_tree_view_row_expanded (tree_view, current_path);
2594 gtk_tree_path_free (current_path);
2597 if ((row_expanded && gtk_tree_model_iter_children (tree_model, iter, &new_iter)) ||
2598 (gtk_tree_model_iter_next (tree_model, iter)) ||
2599 (gtk_tree_model_iter_parent (tree_model, iter, &new_iter) &&
2600 (gtk_tree_model_iter_next (tree_model, iter))))
2601 return return_iter_nth_row (tree_view, tree_model, iter,
2608 set_iter_nth_row (GtkTreeView *tree_view,
2612 GtkTreeModel *tree_model;
2614 tree_model = gtk_tree_view_get_model (tree_view);
2615 gtk_tree_model_get_iter_first (tree_model, iter);
2616 iter = return_iter_nth_row (tree_view, tree_model, iter, 0, row);
2619 /* Recursively called until the row specified by orig is found.
2621 * *count will be set to the visible row number of the child
2622 * relative to the row that was initially passed in as tree_path.
2624 * *count will be -1 if orig is not found as a child (a row that is
2625 * not visible will not be found, e.g. if the row is inside a
2626 * collapsed row). If NULL is passed in as orig, *count will
2627 * be a count of the visible children.
2629 * NOTE: the value for depth must be 0 when this recursive function
2630 * is initially called, or it may not function as expected.
2633 iterate_thru_children (GtkTreeView *tree_view,
2634 GtkTreeModel *tree_model,
2635 GtkTreePath *tree_path,
2642 if (!gtk_tree_model_get_iter (tree_model, &iter, tree_path))
2645 if (tree_path && orig && !gtk_tree_path_compare (tree_path, orig))
2649 if (tree_path && orig && gtk_tree_path_compare (tree_path, orig) > 0)
2651 /* Past it, so return -1 */
2655 else if (gtk_tree_view_row_expanded (tree_view, tree_path) &&
2656 gtk_tree_model_iter_has_child (tree_model, &iter))
2659 gtk_tree_path_append_index (tree_path, 0);
2660 iterate_thru_children (tree_view, tree_model, tree_path,
2661 orig, count, (depth + 1));
2664 else if (gtk_tree_model_iter_next (tree_model, &iter))
2667 tree_path = gtk_tree_model_get_path (tree_model, &iter);
2670 iterate_thru_children (tree_view, tree_model, tree_path,
2671 orig, count, depth);
2672 gtk_tree_path_free (tree_path);
2676 else if (gtk_tree_path_up (tree_path))
2678 GtkTreeIter temp_iter;
2679 gboolean exit_loop = FALSE;
2680 gint new_depth = depth - 1;
2684 /* Make sure that we back up until we find a row
2685 * where gtk_tree_path_next does not return NULL.
2689 if (gtk_tree_path_get_depth (tree_path) == 0)
2690 /* depth is now zero so */
2692 gtk_tree_path_next (tree_path);
2694 /* Verify that the next row is a valid row! */
2695 exit_loop = gtk_tree_model_get_iter (tree_model, &temp_iter, tree_path);
2699 /* Keep going up until we find a row that has a valid next */
2700 if (gtk_tree_path_get_depth(tree_path) > 1)
2703 gtk_tree_path_up (tree_path);
2707 /* If depth is 1 and gtk_tree_model_get_iter returns FALSE,
2708 * then we are at the last row, so just return.
2718 /* This guarantees that we will stop when we hit the end of the
2724 iterate_thru_children (tree_view, tree_model, tree_path,
2725 orig, count, new_depth);
2729 /* If it gets here, then the path wasn't found. Situations
2730 * that would cause this would be if the path passed in is
2731 * invalid or contained within the last row, but not visible
2732 * because the last row is not expanded. If NULL was passed
2733 * in then a row count is desired, so only set count to -1
2734 * if orig is not NULL.
2743 clean_cell_info (GtkTreeViewAccessible *accessible,
2744 GtkTreeViewAccessibleCellInfo *cell_info)
2748 if (cell_info->in_use)
2750 obj = G_OBJECT (cell_info->cell);
2752 _gtk_cell_accessible_add_state (cell_info->cell, ATK_STATE_DEFUNCT, FALSE);
2753 g_object_weak_unref (obj, (GWeakNotify) cell_destroyed, cell_info);
2754 cell_info->in_use = FALSE;
2755 if (!accessible->garbage_collection_pending)
2757 accessible->garbage_collection_pending = TRUE;
2758 g_assert (accessible->idle_garbage_collect_id == 0);
2759 accessible->idle_garbage_collect_id =
2760 gdk_threads_add_idle (idle_garbage_collect_cell_data, accessible);
2766 clean_rows (GtkTreeViewAccessible *accessible)
2768 GtkTreeViewAccessibleCellInfo *cell_info;
2769 GHashTableIter iter;
2771 /* Clean GtkTreeViewAccessibleCellInfo data */
2772 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
2773 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
2775 GtkTreePath *row_path;
2777 row_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2779 /* If the cell has become invalid because the row has been removed,
2780 * then set the cell's state to ATK_STATE_DEFUNCT and schedule
2781 * its removal. If row_path is NULL then the row has
2784 if (row_path == NULL)
2785 clean_cell_info (accessible, cell_info);
2787 gtk_tree_path_free (row_path);
2792 clean_cols (GtkTreeViewAccessible *accessible,
2793 GtkTreeViewColumn *tv_col)
2795 GtkTreeViewAccessibleCellInfo *cell_info;
2796 GHashTableIter iter;
2798 /* Clean GtkTreeViewAccessibleCellInfo data */
2799 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
2800 while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cell_info))
2802 /* If the cell has become invalid because the column tv_col
2803 * has been removed, then set the cell's state to ATK_STATE_DEFUNCT
2804 * and remove the cell from accessible->cell_data.
2806 if (cell_info->cell_col_ref == tv_col)
2807 clean_cell_info (accessible, cell_info);
2812 garbage_collect_cell_data (gpointer data)
2814 GtkTreeViewAccessible *accessible;
2815 GtkTreeViewAccessibleCellInfo *cell_info;
2816 GHashTableIter iter;
2818 accessible = (GtkTreeViewAccessible *)data;
2820 accessible->garbage_collection_pending = FALSE;
2821 if (accessible->idle_garbage_collect_id != 0)
2823 g_source_remove (accessible->idle_garbage_collect_id);
2824 accessible->idle_garbage_collect_id = 0;
2827 /* Must loop through them all */
2828 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
2829 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
2831 if (!cell_info->in_use)
2833 /* g_object_unref (cell_info->cell); */
2834 if (cell_info->cell_row_ref)
2835 gtk_tree_row_reference_free (cell_info->cell_row_ref);
2837 g_hash_table_iter_remove (&iter);
2841 return accessible->garbage_collection_pending;
2845 idle_garbage_collect_cell_data (gpointer data)
2847 GtkTreeViewAccessible *accessible;
2849 accessible = (GtkTreeViewAccessible *)data;
2851 /* this is the idle handler (only one instance allowed), so
2852 * we can safely delete it.
2854 accessible->garbage_collection_pending = FALSE;
2855 accessible->idle_garbage_collect_id = 0;
2857 accessible->garbage_collection_pending = garbage_collect_cell_data (data);
2859 /* N.B.: if for some reason another handler has re-enterantly been
2860 * queued while this handler was being serviced, it has its own gsource,
2861 * therefore this handler should always return FALSE.
2866 /* If tree_path is passed in as NULL, then all cells are acted on.
2867 * Otherwise, just act on those cells that are on a row greater than
2868 * the specified tree_path. If inc_row is passed in as TRUE, then rows
2869 * greater and equal to the specified tree_path are acted on.
2871 * If set_stale is set the ATK_STATE_STALE is set on cells which
2872 * are to be acted on.
2874 * The function set_cell_visibility() is called on all cells to be
2875 * acted on to update the visibility of the cell.
2878 traverse_cells (GtkTreeViewAccessible *accessible,
2879 GtkTreePath *tree_path,
2883 GtkTreeViewAccessibleCellInfo *cell_info;
2885 GHashTableIter iter;
2887 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2891 /* Must loop through them all */
2892 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
2893 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
2895 GtkTreePath *row_path;
2896 gboolean act_on_cell;
2898 if (cell_info->in_use)
2900 row_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2901 g_return_if_fail (row_path != NULL);
2902 if (tree_path == NULL)
2908 comparison = gtk_tree_path_compare (row_path, tree_path);
2909 if ((comparison > 0) ||
2910 (comparison == 0 && inc_row))
2913 act_on_cell = FALSE;
2916 if (!cell_info->in_use)
2917 g_warning ("warning: cell info destroyed during traversal");
2919 if (act_on_cell && cell_info->in_use)
2922 _gtk_cell_accessible_add_state (cell_info->cell, ATK_STATE_STALE, TRUE);
2923 set_cell_visibility (GTK_TREE_VIEW (widget),
2925 cell_info->cell_col_ref,
2928 gtk_tree_path_free (row_path);
2932 g_signal_emit_by_name (accessible, "visible-data-changed");
2935 /* If the tree_path passed in has children, then
2936 * ATK_STATE_EXPANDABLE is set. If the row is expanded
2937 * ATK_STATE_EXPANDED is turned on. If the row is
2938 * collapsed, then ATK_STATE_EXPANDED is removed.
2940 * If the tree_path passed in has no children, then
2941 * ATK_STATE_EXPANDABLE and ATK_STATE_EXPANDED are removed.
2943 * If set_on_ancestor is TRUE, then this function will also
2944 * update all cells that are ancestors of the tree_path.
2947 set_expand_state (GtkTreeView *tree_view,
2948 GtkTreeModel *tree_model,
2949 GtkTreeViewAccessible *accessible,
2950 GtkTreePath *tree_path,
2951 gboolean set_on_ancestor)
2953 GtkTreeViewColumn *expander_tv;
2954 GtkTreeViewAccessibleCellInfo *cell_info;
2955 GtkTreePath *cell_path;
2958 GHashTableIter hash_iter;
2960 g_hash_table_iter_init (&hash_iter, accessible->cell_info_by_index);
2961 while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer *) &cell_info))
2963 if (cell_info->in_use)
2965 cell_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2968 if (cell_path != NULL)
2970 GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (cell_info->cell);
2972 expander_tv = gtk_tree_view_get_expander_column (tree_view);
2974 /* Only set state for the cell that is in the column with the
2977 if (expander_tv == cell_info->cell_col_ref)
2979 if (tree_path && gtk_tree_path_compare (cell_path, tree_path) == 0)
2981 else if (set_on_ancestor &&
2982 gtk_tree_path_get_depth (cell_path) <
2983 gtk_tree_path_get_depth (tree_path) &&
2984 gtk_tree_path_is_ancestor (cell_path, tree_path) == 1)
2985 /* Only set if set_on_ancestor was passed in as TRUE */
2989 /* Set ATK_STATE_EXPANDABLE and ATK_STATE_EXPANDED
2990 * for ancestors and found cells.
2994 /* Must check against cell_path since cell_path
2995 * can be equal to or an ancestor of tree_path.
2997 gtk_tree_model_get_iter (tree_model, &iter, cell_path);
2999 /* Set or unset ATK_STATE_EXPANDABLE as appropriate */
3000 if (gtk_tree_model_iter_has_child (tree_model, &iter))
3002 set_cell_expandable (cell);
3004 if (gtk_tree_view_row_expanded (tree_view, cell_path))
3005 _gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, TRUE);
3007 _gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDED, TRUE);
3011 _gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDED, TRUE);
3012 if (_gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDABLE, TRUE))
3013 /* The state may have been propagated to the container cell */
3014 if (!GTK_IS_CONTAINER_CELL_ACCESSIBLE (cell))
3015 _gtk_cell_accessible_remove_action_by_name (cell,
3016 "expand or contract");
3019 /* We assume that each cell in the cache once and
3020 * a container cell is before its child cells so we are
3021 * finished if set_on_ancestor is not set to TRUE.
3023 if (!set_on_ancestor)
3027 gtk_tree_path_free (cell_path);
3033 add_cell_actions (GtkCellAccessible *cell,
3036 if (GTK_IS_BOOLEAN_CELL_ACCESSIBLE (cell))
3037 _gtk_cell_accessible_add_action (cell,
3038 "toggle", "toggles the cell",
3039 NULL, toggle_cell_toggled);
3041 _gtk_cell_accessible_add_action (cell,
3042 "edit", "creates a widget in which the contents of the cell can be edited",
3044 _gtk_cell_accessible_add_action (cell,
3045 "activate", "activate the cell",
3046 NULL, activate_cell);
3050 toggle_cell_expanded (GtkCellAccessible *cell)
3052 GtkTreeViewAccessibleCellInfo *cell_info;
3053 GtkTreeView *tree_view;
3056 AtkStateSet *stateset;
3058 parent = atk_object_get_parent (ATK_OBJECT (cell));
3059 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
3060 parent = atk_object_get_parent (parent);
3062 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
3063 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
3066 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
3067 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
3071 stateset = atk_object_ref_state_set (ATK_OBJECT (cell));
3072 if (atk_state_set_contains_state (stateset, ATK_STATE_EXPANDED))
3073 gtk_tree_view_collapse_row (tree_view, path);
3075 gtk_tree_view_expand_row (tree_view, path, TRUE);
3076 g_object_unref (stateset);
3077 gtk_tree_path_free (path);
3081 toggle_cell_toggled (GtkCellAccessible *cell)
3083 GtkTreeViewAccessibleCellInfo *cell_info;
3086 GList *renderers, *cur_renderer;
3088 gboolean is_container_cell = FALSE;
3090 parent = atk_object_get_parent (ATK_OBJECT (cell));
3091 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
3093 is_container_cell = TRUE;
3094 parent = atk_object_get_parent (parent);
3097 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
3098 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
3101 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
3105 /* If the cell is in a container, its index is used to find the
3106 * renderer in the list. Otherwise, we assume that the cell is
3107 * represented by the first renderer in the list
3109 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_info->cell_col_ref));
3110 if (is_container_cell)
3111 cur_renderer = g_list_nth (renderers, cell->index);
3113 cur_renderer = renderers;
3117 pathstring = gtk_tree_path_to_string (path);
3118 g_signal_emit_by_name (cur_renderer->data, "toggled", pathstring);
3119 g_free (pathstring);
3122 g_list_free (renderers);
3123 gtk_tree_path_free (path);
3127 edit_cell (GtkCellAccessible *cell)
3129 GtkTreeViewAccessibleCellInfo *cell_info;
3130 GtkTreeView *tree_view;
3134 parent = atk_object_get_parent (ATK_OBJECT (cell));
3135 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
3136 parent = atk_object_get_parent (parent);
3138 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
3139 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
3142 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
3143 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
3146 gtk_tree_view_set_cursor (tree_view, path, cell_info->cell_col_ref, TRUE);
3147 gtk_tree_path_free (path);
3151 activate_cell (GtkCellAccessible *cell)
3153 GtkTreeViewAccessibleCellInfo *cell_info;
3154 GtkTreeView *tree_view;
3158 parent = atk_object_get_parent (ATK_OBJECT (cell));
3159 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
3160 parent = atk_object_get_parent (parent);
3162 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
3163 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
3166 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
3167 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
3170 gtk_tree_view_row_activated (tree_view, path, cell_info->cell_col_ref);
3171 gtk_tree_path_free (path);
3175 cell_destroyed (gpointer data)
3177 GtkTreeViewAccessibleCellInfo *cell_info = data;
3181 if (cell_info->in_use)
3183 cell_info->in_use = FALSE;
3185 if (!cell_info->view->garbage_collection_pending)
3187 cell_info->view->garbage_collection_pending = TRUE;
3188 cell_info->view->idle_garbage_collect_id =
3189 gdk_threads_add_idle (idle_garbage_collect_cell_data, cell_info->view);
3195 cell_info_get_index (GtkTreeView *tree_view,
3196 GtkTreeViewAccessibleCellInfo *info,
3202 path = gtk_tree_row_reference_get_path (info->cell_row_ref);
3206 column_number = get_column_number (tree_view, info->cell_col_ref, FALSE);
3207 *index = get_index (tree_view, path, column_number);
3208 gtk_tree_path_free (path);
3212 cell_info_new (GtkTreeViewAccessible *accessible,
3213 GtkTreeModel *tree_model,
3215 GtkTreeViewColumn *tv_col,
3216 GtkCellAccessible *cell)
3218 GtkTreeViewAccessibleCellInfo *cell_info;
3220 cell_info = g_new (GtkTreeViewAccessibleCellInfo, 1);
3221 cell_info->cell_row_ref = gtk_tree_row_reference_new (tree_model, path);
3223 cell_info->cell_col_ref = tv_col;
3224 cell_info->cell = cell;
3225 cell_info->in_use = TRUE; /* if we've created it, assume it's in use */
3226 cell_info->view = accessible;
3227 g_hash_table_insert (accessible->cell_info_by_index, &cell->index, cell_info);
3229 /* Setup weak reference notification */
3230 g_object_weak_ref (G_OBJECT (cell), (GWeakNotify) cell_destroyed, cell_info);
3233 static GtkCellAccessible *
3234 find_cell (GtkTreeViewAccessible *accessible,
3237 GtkTreeViewAccessibleCellInfo *info;
3239 info = g_hash_table_lookup (accessible->cell_info_by_index, &index);
3247 refresh_cell_index (GtkCellAccessible *cell)
3249 GtkTreeViewAccessibleCellInfo *info;
3251 GtkTreeView *tree_view;
3252 GtkTreeViewAccessible *accessible;
3255 parent = atk_object_get_parent (ATK_OBJECT (cell));
3256 if (!GTK_IS_TREE_VIEW_ACCESSIBLE (parent))
3259 accessible = GTK_TREE_VIEW_ACCESSIBLE (parent);
3261 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
3263 /* Find this cell in the GtkTreeViewAccessible's cache */
3264 info = find_cell_info (accessible, cell, TRUE);
3268 cell_info_get_index (tree_view, info, &index);
3269 cell->index = index;
3270 g_hash_table_insert (accessible->cell_info_by_index, &index, info);
3274 connect_model_signals (GtkTreeView *view,
3275 GtkTreeViewAccessible *accessible)
3279 obj = G_OBJECT (accessible->tree_model);
3280 g_signal_connect_data (obj, "row-changed",
3281 G_CALLBACK (model_row_changed), view, NULL, 0);
3282 g_signal_connect_data (obj, "row-inserted",
3283 G_CALLBACK (model_row_inserted), view, NULL,
3285 g_signal_connect_data (obj, "row-deleted",
3286 G_CALLBACK (model_row_deleted), view, NULL,
3288 g_signal_connect_data (obj, "rows-reordered",
3289 G_CALLBACK (model_rows_reordered), view, NULL,
3294 disconnect_model_signals (GtkTreeViewAccessible *accessible)
3299 obj = G_OBJECT (accessible->tree_model);
3300 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
3301 g_signal_handlers_disconnect_by_func (obj, model_row_changed, widget);
3302 g_signal_handlers_disconnect_by_func (obj, model_row_inserted, widget);
3303 g_signal_handlers_disconnect_by_func (obj, model_row_deleted, widget);
3304 g_signal_handlers_disconnect_by_func (obj, model_rows_reordered, widget);
3308 clear_cached_data (GtkTreeViewAccessible *accessible)
3310 GtkTreeViewAccessibleCellInfo *cell_info;
3311 GHashTableIter iter;
3313 /* Must loop through them all */
3314 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
3315 while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cell_info))
3316 clean_cell_info (accessible, cell_info);
3318 /* FIXME: seems pretty inefficient to loop again here */
3319 garbage_collect_cell_data (accessible);
3322 /* Returns the column number of the specified GtkTreeViewColumn
3324 * If visible is set, the value returned will be the visible column number,
3325 * i.e. suitable for use in AtkTable function. If visible is not set, the
3326 * value returned is the actual column number, which is suitable for use in
3327 * getting an index value.
3330 get_column_number (GtkTreeView *tree_view,
3331 GtkTreeViewColumn *column,
3334 GtkTreeViewColumn *tv_column;
3338 GtkTreeViewAccessible *accessible;
3340 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
3341 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
3344 for (i = 0; i < accessible->col_data->len; i++)
3346 tv_column = g_array_index (accessible->col_data, GtkTreeViewColumn *, i);
3347 if (tv_column == column)
3349 if (!visible || gtk_tree_view_column_get_visible (tv_column))
3352 if (i == accessible->col_data->len)
3359 get_index (GtkTreeView *tree_view,
3364 GtkTreeViewAccessible *accessible;
3367 gint *indices = NULL;
3369 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
3370 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
3374 depth = gtk_tree_path_get_depth (path);
3375 indices = gtk_tree_path_get_indices (path);
3380 GtkTreePath *copy_path;
3381 GtkTreeModel *model;
3383 model = gtk_tree_view_get_model (tree_view);
3384 copy_path = gtk_tree_path_copy (path);
3385 gtk_tree_path_up (copy_path);
3386 count_rows (model, NULL, copy_path, &index, 0, depth);
3387 gtk_tree_path_free (copy_path);
3391 index += indices[depth - 1];
3392 index *= accessible->n_cols;
3393 index += actual_column;
3397 /* The function count_rows counts the number of rows starting at iter
3398 * and ending at end_path. The value of level is the depth of iter and
3399 * the value of depth is the depth of end_path. Rows at depth before
3400 * end_path are counted. This functions counts rows which are not visible
3401 * because an ancestor is collapsed.
3404 count_rows (GtkTreeModel *model,
3406 GtkTreePath *end_path,
3411 GtkTreeIter child_iter;
3417 *count += gtk_tree_model_iter_n_children (model, iter);
3419 if (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY)
3425 if (gtk_tree_model_iter_children (model, &child_iter, iter))
3427 gboolean ret_val = TRUE;
3431 if (level == depth - 1)
3433 GtkTreePath *iter_path;
3434 gboolean finished = FALSE;
3436 iter_path = gtk_tree_model_get_path (model, &child_iter);
3437 if (end_path && gtk_tree_path_compare (iter_path, end_path) >= 0)
3439 gtk_tree_path_free (iter_path);
3443 if (gtk_tree_model_iter_has_child (model, &child_iter))
3444 count_rows (model, &child_iter, end_path, count, level, depth);
3445 ret_val = gtk_tree_model_iter_next (model, &child_iter);
3450 /* Find the next node, which has children, at the specified depth below
3451 * the specified iter. The level is the depth of the current iter.
3452 * The position of the node is returned in path and the return value
3453 * of TRUE means that a node was found.
3457 get_next_node_with_child_at_depth (GtkTreeModel *model,
3463 GtkTreeIter child_iter;
3467 if (gtk_tree_model_iter_children (model, &child_iter, iter))
3473 while (!gtk_tree_model_iter_has_child (model, &child_iter))
3475 if (!gtk_tree_model_iter_next (model, &child_iter))
3481 /* We have found what we were looking for */
3482 *path = gtk_tree_model_get_path (model, &child_iter);
3486 if (get_next_node_with_child_at_depth (model, &child_iter, path,
3490 if (!gtk_tree_model_iter_next (model, &child_iter))
3497 /* Find the next node, which has children, at the same depth
3498 * as the specified GtkTreePath.
3501 get_next_node_with_child (GtkTreeModel *model,
3503 GtkTreePath **return_path)
3508 gtk_tree_model_get_iter (model, &iter, path);
3510 while (gtk_tree_model_iter_next (model, &iter))
3512 if (gtk_tree_model_iter_has_child (model, &iter))
3514 *return_path = gtk_tree_model_get_path (model, &iter);
3518 depth = gtk_tree_path_get_depth (path);
3519 while (gtk_tree_path_up (path))
3521 if (gtk_tree_path_get_depth (path) == 0)
3524 gtk_tree_model_get_iter (model, &iter, path);
3525 while (gtk_tree_model_iter_next (model, &iter))
3526 if (get_next_node_with_child_at_depth (model, &iter, return_path,
3527 gtk_tree_path_get_depth (path), depth))
3530 *return_path = NULL;
3535 get_tree_path_from_row_index (GtkTreeModel *model,
3537 GtkTreePath **tree_path)
3543 count = gtk_tree_model_iter_n_children (model, NULL);
3544 if (count > row_index)
3546 if (gtk_tree_model_iter_nth_child (model, &iter, NULL, row_index))
3548 *tree_path = gtk_tree_model_get_path (model, &iter);
3562 if (get_next_node_with_child_at_depth (model, NULL, tree_path, 0, depth))
3564 GtkTreePath *next_path;
3568 gtk_tree_model_get_iter (model, &iter, *tree_path);
3569 count = gtk_tree_model_iter_n_children (model, &iter);
3570 if (count > row_index)
3572 gtk_tree_path_append_index (*tree_path, row_index);
3578 if (!get_next_node_with_child (model, *tree_path, &next_path))
3581 gtk_tree_path_free (*tree_path);
3582 *tree_path = next_path;
3587 g_warning ("Index value is too large\n");
3588 gtk_tree_path_free (*tree_path);
3596 get_path_column_from_index (GtkTreeView *tree_view,
3599 GtkTreeViewColumn **column)
3601 GtkTreeModel *tree_model;
3603 GtkTreeViewAccessible *accessible;
3605 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
3606 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
3608 tree_model = gtk_tree_view_get_model (tree_view);
3609 if (accessible->n_cols == 0)
3611 /* First row is the column headers */
3612 index -= accessible->n_cols;
3621 row_index = index / accessible->n_cols;
3622 retval = get_tree_path_from_row_index (tree_model, row_index, path);
3631 *column = gtk_tree_view_get_column (tree_view, index % accessible->n_cols);
3632 if (*column == NULL)
3635 gtk_tree_path_free (*path);
3643 set_cell_expandable (GtkCellAccessible *cell)
3645 if (_gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDABLE, FALSE))
3646 _gtk_cell_accessible_add_action (cell,
3647 "expand or contract",
3648 "expands or contracts the row in the tree view containing this cell",
3649 NULL, toggle_cell_expanded);
3652 static GtkTreeViewAccessibleCellInfo *
3653 find_cell_info (GtkTreeViewAccessible *accessible,
3654 GtkCellAccessible *cell,
3657 GtkTreeViewAccessibleCellInfo *cell_info;
3658 GHashTableIter iter;
3660 /* Clean GtkTreeViewAccessibleCellInfo data */
3661 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
3662 while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cell_info))
3664 if (cell_info->cell == cell && (!live_only || cell_info->in_use))
3671 get_header_from_column (GtkTreeViewColumn *tv_col)
3674 GtkWidget *header_widget;
3679 header_widget = gtk_tree_view_column_get_button (tv_col);
3682 rc = gtk_widget_get_accessible (header_widget);