1 /* GAIL - The GNOME Accessibility Implementation Library
2 * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 #ifdef GDK_WINDOWING_X11
24 #include <gdk/x11/gdkx.h>
27 #include "gtktreeprivate.h"
29 #include "gtktreeviewaccessible.h"
30 #include "gtkrenderercellaccessible.h"
31 #include "gtkbooleancellaccessible.h"
32 #include "gtkimagecellaccessible.h"
33 #include "gtkcontainercellaccessible.h"
34 #include "gtktextcellaccessible.h"
35 #include "gtkcellaccessibleparent.h"
37 typedef struct _GtkTreeViewAccessibleCellInfo GtkTreeViewAccessibleCellInfo;
38 struct _GtkTreeViewAccessibleCellInfo
40 GtkCellAccessible *cell;
41 GtkTreeRowReference *cell_row_ref;
42 GtkTreeViewColumn *cell_col_ref;
43 GtkTreeViewAccessible *view;
49 static gboolean row_expanded_cb (GtkTreeView *tree_view,
52 static gboolean row_collapsed_cb (GtkTreeView *tree_view,
55 static void size_allocate_cb (GtkWidget *widget,
56 GtkAllocation *allocation);
57 static void selection_changed_cb (GtkTreeSelection *selection,
60 static void columns_changed (GtkTreeView *tree_view);
61 static void cursor_changed (GtkTreeView *tree_view,
62 GtkTreeViewAccessible *accessible);
63 static gboolean focus_in (GtkWidget *widget);
64 static gboolean focus_out (GtkWidget *widget);
66 static void column_visibility_changed
70 static void destroy_count_func (GtkTreeView *tree_view,
77 static void set_iter_nth_row (GtkTreeView *tree_view,
80 static gint get_row_from_tree_path (GtkTreeView *tree_view,
82 static GtkTreeViewColumn* get_column (GtkTreeView *tree_view,
84 static gint get_actual_column_number (GtkTreeView *tree_view,
86 static gint get_visible_column_number (GtkTreeView *tree_view,
88 static void iterate_thru_children (GtkTreeView *tree_view,
89 GtkTreeModel *tree_model,
90 GtkTreePath *tree_path,
94 static void clean_rows (GtkTreeViewAccessible *tree_view);
95 static void clean_cols (GtkTreeViewAccessible *tree_view,
96 GtkTreeViewColumn *tv_col);
97 static void traverse_cells (GtkTreeViewAccessible *tree_view,
98 GtkTreePath *tree_path,
101 static gboolean update_cell_value (GtkRendererCellAccessible *renderer_cell,
102 GtkTreeViewAccessible *accessible,
103 gboolean emit_change_signal);
104 static void set_cell_visibility (GtkTreeView *tree_view,
105 GtkCellAccessible *cell,
106 GtkTreeViewColumn *tv_col,
107 GtkTreePath *tree_path,
108 gboolean emit_signal);
109 static gboolean is_cell_showing (GtkTreeView *tree_view,
110 GdkRectangle *cell_rect);
111 static void set_expand_state (GtkTreeView *tree_view,
112 GtkTreeModel *tree_model,
113 GtkTreeViewAccessible *accessible,
114 GtkTreePath *tree_path,
115 gboolean set_on_ancestor);
116 static void set_cell_expandable (GtkCellAccessible *cell);
117 static void add_cell_actions (GtkCellAccessible *cell,
120 static void toggle_cell_toggled (GtkCellAccessible *cell);
121 static void edit_cell (GtkCellAccessible *cell);
122 static void activate_cell (GtkCellAccessible *cell);
123 static void cell_destroyed (gpointer data);
124 static void cell_info_new (GtkTreeViewAccessible *accessible,
125 GtkTreeModel *tree_model,
127 GtkTreeViewColumn *tv_col,
128 GtkCellAccessible *cell);
129 static GtkCellAccessible *find_cell (GtkTreeViewAccessible *accessible,
131 static void refresh_cell_index (GtkCellAccessible *cell);
132 static void connect_model_signals (GtkTreeView *view,
133 GtkTreeViewAccessible *accessible);
134 static void disconnect_model_signals (GtkTreeViewAccessible *accessible);
135 static void clear_cached_data (GtkTreeViewAccessible *view);
136 static gint get_column_number (GtkTreeView *tree_view,
137 GtkTreeViewColumn *column,
139 static gint get_focus_index (GtkTreeView *tree_view);
140 static gint get_index (GtkTreeView *tree_view,
143 static void count_rows (GtkTreeModel *model,
145 GtkTreePath *end_path,
150 static gboolean get_path_column_from_index (GtkTreeView *tree_view,
153 GtkTreeViewColumn **column);
155 static GtkTreeViewAccessibleCellInfo* find_cell_info (GtkTreeViewAccessible *view,
156 GtkCellAccessible *cell,
158 static AtkObject * get_header_from_column (GtkTreeViewColumn *tv_col);
159 static gboolean idle_garbage_collect_cell_data (gpointer data);
162 static void atk_table_interface_init (AtkTableIface *iface);
163 static void atk_selection_interface_init (AtkSelectionIface *iface);
164 static void atk_component_interface_init (AtkComponentIface *iface);
165 static void gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface);
167 G_DEFINE_TYPE_WITH_CODE (GtkTreeViewAccessible, _gtk_tree_view_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
168 G_IMPLEMENT_INTERFACE (ATK_TYPE_TABLE, atk_table_interface_init)
169 G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init)
170 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init)
171 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_ACCESSIBLE_PARENT, gtk_cell_accessible_parent_interface_init))
175 adjustment_changed (GtkAdjustment *adjustment,
178 GtkTreeViewAccessible *accessible;
180 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
181 traverse_cells (accessible, NULL, FALSE, FALSE);
185 hadjustment_set_cb (GObject *widget,
189 GtkTreeViewAccessible *accessible = data;
192 g_object_get (widget, "hadjustment", &adj, NULL);
193 accessible->old_hadj = adj;
194 g_object_add_weak_pointer (G_OBJECT (accessible->old_hadj), (gpointer *)&accessible->old_hadj);
195 g_signal_connect (adj, "value-changed", G_CALLBACK (adjustment_changed), widget);
199 vadjustment_set_cb (GObject *widget,
203 GtkTreeViewAccessible *accessible = data;
206 g_object_get (widget, "vadjustment", &adj, NULL);
207 accessible->old_vadj = adj;
208 g_object_add_weak_pointer (G_OBJECT (accessible->old_vadj), (gpointer *)&accessible->old_vadj);
209 g_signal_connect (adj, "value-changed",
210 G_CALLBACK (adjustment_changed), widget);
214 cell_info_free (GtkTreeViewAccessibleCellInfo *cell_info)
216 /* g_object_unref (cell_info->cell); */
217 if (cell_info->cell_row_ref)
218 gtk_tree_row_reference_free (cell_info->cell_row_ref);
223 gtk_tree_view_accessible_initialize (AtkObject *obj,
226 GtkTreeViewAccessible *accessible;
227 GtkTreeView *tree_view;
228 GtkTreeModel *tree_model;
229 GList *tv_cols, *tmp_list;
231 GtkTreeSelection *selection;
233 ATK_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->initialize (obj, data);
235 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
236 accessible->col_data = NULL;
237 accessible->focus_cell = NULL;
238 accessible->old_hadj = NULL;
239 accessible->old_vadj = NULL;
240 accessible->idle_expand_id = 0;
241 accessible->idle_expand_path = NULL;
242 accessible->n_children_deleted = 0;
244 accessible->cell_info_by_index = g_hash_table_new_full (g_int_hash,
245 g_int_equal, NULL, (GDestroyNotify) cell_info_free);
247 widget = GTK_WIDGET (data);
248 tree_view = GTK_TREE_VIEW (widget);
249 tree_model = gtk_tree_view_get_model (tree_view);
250 selection = gtk_tree_view_get_selection (tree_view);
252 g_signal_connect_after (widget, "row-collapsed",
253 G_CALLBACK (row_collapsed_cb), NULL);
254 g_signal_connect (widget, "row-expanded",
255 G_CALLBACK (row_expanded_cb), NULL);
256 g_signal_connect (widget, "size-allocate",
257 G_CALLBACK (size_allocate_cb), NULL);
258 g_signal_connect (selection, "changed",
259 G_CALLBACK (selection_changed_cb), obj);
261 g_signal_connect (tree_view, "columns-changed",
262 G_CALLBACK (columns_changed), NULL);
263 g_signal_connect (tree_view, "cursor-changed",
264 G_CALLBACK (cursor_changed), accessible);
265 g_signal_connect (tree_view, "focus-in-event",
266 G_CALLBACK (focus_in), NULL);
267 g_signal_connect (tree_view, "focus-out-event",
268 G_CALLBACK (focus_out), NULL);
270 accessible->tree_model = tree_model;
271 accessible->n_rows = 0;
272 accessible->n_cols = 0;
275 g_object_add_weak_pointer (G_OBJECT (accessible->tree_model), (gpointer *)&accessible->tree_model);
276 count_rows (tree_model, NULL, NULL, &accessible->n_rows, 0, G_MAXINT);
277 connect_model_signals (tree_view, accessible);
279 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
280 obj->role = ATK_ROLE_TABLE;
282 obj->role = ATK_ROLE_TREE_TABLE;
285 hadjustment_set_cb (G_OBJECT (widget), NULL, accessible);
286 vadjustment_set_cb (G_OBJECT (widget), NULL, accessible);
287 g_signal_connect (widget, "notify::hadjustment",
288 G_CALLBACK (hadjustment_set_cb), accessible);
289 g_signal_connect (widget, "notify::vadjustment",
290 G_CALLBACK (vadjustment_set_cb), accessible);
292 accessible->col_data = g_array_sized_new (FALSE, TRUE,
293 sizeof (GtkTreeViewColumn *), 0);
295 tv_cols = gtk_tree_view_get_columns (tree_view);
296 for (tmp_list = tv_cols; tmp_list; tmp_list = tmp_list->next)
298 accessible->n_cols++;
299 g_signal_connect (tmp_list->data, "notify::visible",
300 G_CALLBACK (column_visibility_changed), tree_view);
301 g_array_append_val (accessible->col_data, tmp_list->data);
303 g_list_free (tv_cols);
305 gtk_tree_view_set_destroy_count_func (tree_view,
311 gtk_tree_view_accessible_finalize (GObject *object)
313 GtkTreeViewAccessible *accessible = GTK_TREE_VIEW_ACCESSIBLE (object);
315 clear_cached_data (accessible);
317 /* remove any idle handlers still pending */
318 if (accessible->idle_garbage_collect_id)
319 g_source_remove (accessible->idle_garbage_collect_id);
320 if (accessible->idle_expand_id)
321 g_source_remove (accessible->idle_expand_id);
323 if (accessible->tree_model)
324 disconnect_model_signals (accessible);
326 if (accessible->cell_info_by_index)
327 g_hash_table_destroy (accessible->cell_info_by_index);
329 if (accessible->col_data)
331 GArray *array = accessible->col_data;
333 /* No need to free the contents of the array since it
334 * just contains pointers to the GtkTreeViewColumn
335 * objects that are in the GtkTreeView.
337 g_array_free (array, TRUE);
340 G_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->finalize (object);
344 gtk_tree_view_accessible_notify_gtk (GObject *obj,
348 GtkTreeView *tree_view;
349 GtkTreeViewAccessible *accessible;
352 widget = GTK_WIDGET (obj);
353 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
354 tree_view = GTK_TREE_VIEW (widget);
356 if (g_strcmp0 (pspec->name, "model") == 0)
358 GtkTreeModel *tree_model;
361 tree_model = gtk_tree_view_get_model (tree_view);
362 if (accessible->tree_model)
363 disconnect_model_signals (accessible);
364 clear_cached_data (accessible);
365 accessible->tree_model = tree_model;
366 accessible->n_rows = 0;
370 g_object_add_weak_pointer (G_OBJECT (accessible->tree_model), (gpointer *)&accessible->tree_model);
371 count_rows (tree_model, NULL, NULL, &accessible->n_rows, 0, G_MAXINT);
372 connect_model_signals (tree_view, accessible);
374 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
375 role = ATK_ROLE_TABLE;
377 role = ATK_ROLE_TREE_TABLE;
381 role = ATK_ROLE_UNKNOWN;
383 atk_object_set_role (ATK_OBJECT (accessible), role);
384 g_object_freeze_notify (G_OBJECT (accessible));
385 g_signal_emit_by_name (accessible, "model-changed");
386 g_signal_emit_by_name (accessible, "visible-data-changed");
387 g_object_thaw_notify (G_OBJECT (accessible));
389 else if (g_strcmp0 (pspec->name, "hadjustment") == 0)
391 g_object_get (tree_view, "hadjustment", &adj, NULL);
392 g_signal_handlers_disconnect_by_func (accessible->old_hadj,
393 (gpointer) adjustment_changed,
395 accessible->old_hadj = adj;
396 g_object_add_weak_pointer (G_OBJECT (accessible->old_hadj), (gpointer *)&accessible->old_hadj);
397 g_signal_connect (adj, "value-changed", G_CALLBACK (adjustment_changed), tree_view);
399 else if (g_strcmp0 (pspec->name, "vadjustment") == 0)
401 g_object_get (tree_view, "vadjustment", &adj, NULL);
402 g_signal_handlers_disconnect_by_func (accessible->old_vadj,
403 (gpointer) adjustment_changed,
405 accessible->old_vadj = adj;
406 g_object_add_weak_pointer (G_OBJECT (accessible->old_hadj), (gpointer *)&accessible->old_vadj);
407 g_signal_connect (adj, "value-changed", G_CALLBACK (adjustment_changed), tree_view);
410 GTK_WIDGET_ACCESSIBLE_CLASS (_gtk_tree_view_accessible_parent_class)->notify_gtk (obj, pspec);
414 gtk_tree_view_accessible_destroyed (GtkWidget *widget,
415 GtkAccessible *gtk_accessible)
418 GtkTreeViewAccessible *accessible;
420 if (!GTK_IS_TREE_VIEW (widget))
423 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_accessible);
424 adj = accessible->old_hadj;
426 g_signal_handlers_disconnect_by_func (adj,
427 (gpointer) adjustment_changed,
429 adj = accessible->old_vadj;
431 g_signal_handlers_disconnect_by_func (adj,
432 (gpointer) adjustment_changed,
434 if (accessible->tree_model)
436 disconnect_model_signals (accessible);
437 accessible->tree_model = NULL;
439 if (accessible->focus_cell)
441 g_object_unref (accessible->focus_cell);
442 accessible->focus_cell = NULL;
444 if (accessible->idle_expand_id)
446 g_source_remove (accessible->idle_expand_id);
447 accessible->idle_expand_id = 0;
452 gtk_tree_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
456 widget = gtk_accessible_get_widget (accessible);
458 g_signal_connect_after (widget, "destroy",
459 G_CALLBACK (gtk_tree_view_accessible_destroyed), accessible);
461 GTK_ACCESSIBLE_CLASS (_gtk_tree_view_accessible_parent_class)->connect_widget_destroyed (accessible);
465 gtk_tree_view_accessible_get_n_children (AtkObject *obj)
468 GtkTreeViewAccessible *accessible;
470 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
474 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
475 return (accessible->n_rows + 1) * accessible->n_cols;
479 gtk_tree_view_accessible_ref_child (AtkObject *obj,
483 GtkTreeViewAccessible *accessible;
484 GtkCellAccessible *cell;
485 GtkTreeView *tree_view;
486 GtkTreeModel *tree_model;
487 GtkCellRenderer *renderer;
489 GtkTreeViewColumn *tv_col;
490 GtkTreeSelection *selection;
494 GtkTreeViewColumn *expander_tv;
495 GList *renderer_list;
497 GtkContainerCellAccessible *container = NULL;
498 GtkRendererCellAccessible *renderer_cell;
499 gboolean is_expander, is_expanded, retval;
500 gboolean editable = FALSE;
503 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
507 if (i >= gtk_tree_view_accessible_get_n_children (obj))
510 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
511 tree_view = GTK_TREE_VIEW (widget);
512 if (i < accessible->n_cols)
514 tv_col = gtk_tree_view_get_column (tree_view, i);
515 child = get_header_from_column (tv_col);
517 g_object_ref (child);
521 /* Check whether the child is cached */
522 cell = find_cell (accessible, i);
526 return ATK_OBJECT (cell);
529 if (accessible->focus_cell == NULL)
530 focus_index = get_focus_index (tree_view);
534 /* Find the TreePath and GtkTreeViewColumn for the index */
535 if (!get_path_column_from_index (tree_view, i, &path, &tv_col))
538 tree_model = gtk_tree_view_get_model (tree_view);
539 retval = gtk_tree_model_get_iter (tree_model, &iter, path);
543 expander_tv = gtk_tree_view_get_expander_column (tree_view);
546 if (gtk_tree_model_iter_has_child (tree_model, &iter))
548 if (expander_tv == tv_col)
551 is_expanded = gtk_tree_view_row_expanded (tree_view, path);
554 gtk_tree_view_column_cell_set_cell_data (tv_col, tree_model, &iter,
555 is_expander, is_expanded);
557 renderer_list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
559 /* If there are more than one renderer in the list,
562 if (renderer_list && renderer_list->next)
564 GtkCellAccessible *container_cell;
566 container = _gtk_container_cell_accessible_new ();
568 container_cell = GTK_CELL_ACCESSIBLE (container);
569 _gtk_cell_accessible_initialise (container_cell, widget, ATK_OBJECT (accessible), i);
571 /* The GtkTreeViewAccessibleCellInfo structure for the container will
572 * be before the ones for the cells so that the first one we find for
573 * a position will be for the container
575 cell_info_new (accessible, tree_model, path, tv_col, container_cell);
576 container_cell->refresh_index = refresh_cell_index;
577 parent = ATK_OBJECT (container);
580 parent = ATK_OBJECT (accessible);
584 /* Now we make a fake cell_renderer if there is no cell
587 if (renderer_list == NULL)
589 GtkCellRenderer *fake_renderer;
591 fake_renderer = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, NULL);
592 child = _gtk_text_cell_accessible_new ();
593 cell = GTK_CELL_ACCESSIBLE (child);
594 renderer_cell = GTK_RENDERER_CELL_ACCESSIBLE (child);
595 renderer_cell->renderer = fake_renderer;
597 /* Create the GtkTreeViewAccessibleCellInfo structure for this cell */
598 cell_info_new (accessible, tree_model, path, tv_col, cell);
600 _gtk_cell_accessible_initialise (cell, widget, parent, i);
602 cell->refresh_index = refresh_cell_index;
604 /* Set state if it is expandable */
607 set_cell_expandable (cell);
609 _gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, FALSE);
614 for (l = renderer_list; l; l = l->next)
616 renderer = GTK_CELL_RENDERER (l->data);
618 if (GTK_IS_CELL_RENDERER_TEXT (renderer))
620 g_object_get (G_OBJECT (renderer), "editable", &editable, NULL);
621 child = _gtk_text_cell_accessible_new ();
623 else if (GTK_IS_CELL_RENDERER_TOGGLE (renderer))
624 child = _gtk_boolean_cell_accessible_new ();
625 else if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
626 child = _gtk_image_cell_accessible_new ();
628 child = _gtk_renderer_cell_accessible_new ();
630 cell = GTK_CELL_ACCESSIBLE (child);
631 renderer_cell = GTK_RENDERER_CELL_ACCESSIBLE (child);
633 /* Create the GtkTreeViewAccessibleCellInfo for this cell */
634 cell_info_new (accessible, tree_model, path, tv_col, cell);
636 _gtk_cell_accessible_initialise (cell, widget, parent, i);
639 _gtk_container_cell_accessible_add_child (container, cell);
641 cell->refresh_index = refresh_cell_index;
643 update_cell_value (renderer_cell, accessible, FALSE);
645 /* Add the actions appropriate for this cell */
646 add_cell_actions (cell, editable);
648 /* Set state if it is expandable */
651 set_cell_expandable (cell);
653 _gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, FALSE);
656 /* If the column is visible, sets the cell's state */
657 if (gtk_tree_view_column_get_visible (tv_col))
658 set_cell_visibility (tree_view, cell, tv_col, path, FALSE);
660 /* If the row is selected, all cells on the row are selected */
661 selection = gtk_tree_view_get_selection (tree_view);
663 if (gtk_tree_selection_path_is_selected (selection, path))
664 _gtk_cell_accessible_add_state (cell, ATK_STATE_SELECTED, FALSE);
666 _gtk_cell_accessible_add_state (cell, ATK_STATE_FOCUSABLE, FALSE);
667 if (focus_index == i)
669 accessible->focus_cell = g_object_ref (cell);
670 _gtk_cell_accessible_add_state (cell, ATK_STATE_FOCUSED, FALSE);
671 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
674 g_list_free (renderer_list);
676 child = ATK_OBJECT (container);
679 if (expander_tv == tv_col)
681 AtkRelationSet *relation_set;
682 AtkObject *accessible_array[1];
683 AtkRelation* relation;
684 AtkObject *parent_node;
686 relation_set = atk_object_ref_relation_set (ATK_OBJECT (child));
688 gtk_tree_path_up (path);
689 if (gtk_tree_path_get_depth (path) == 0)
695 parent_index = get_index (tree_view, path, i % accessible->n_cols);
696 parent_node = atk_object_ref_accessible_child (obj, parent_index);
698 accessible_array[0] = parent_node;
699 relation = atk_relation_new (accessible_array, 1,
700 ATK_RELATION_NODE_CHILD_OF);
701 atk_relation_set_add (relation_set, relation);
702 atk_object_add_relationship (parent_node, ATK_RELATION_NODE_PARENT_OF, child);
703 g_object_unref (relation);
704 g_object_unref (relation_set);
706 gtk_tree_path_free (path);
708 /* We do not increase the reference count here; when g_object_unref()
709 * is called for the cell then cell_destroyed() is called and this
710 * removes the cell from the cache.
716 gtk_tree_view_accessible_ref_state_set (AtkObject *obj)
718 AtkStateSet *state_set;
721 state_set = ATK_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->ref_state_set (obj);
722 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
725 atk_state_set_add_state (state_set, ATK_STATE_MANAGES_DESCENDANTS);
731 _gtk_tree_view_accessible_class_init (GtkTreeViewAccessibleClass *klass)
733 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
734 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
735 GtkAccessibleClass *accessible_class = (GtkAccessibleClass*)klass;
736 GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
737 GtkContainerAccessibleClass *container_class = (GtkContainerAccessibleClass*)klass;
739 class->get_n_children = gtk_tree_view_accessible_get_n_children;
740 class->ref_child = gtk_tree_view_accessible_ref_child;
741 class->ref_state_set = gtk_tree_view_accessible_ref_state_set;
742 class->initialize = gtk_tree_view_accessible_initialize;
744 widget_class->notify_gtk = gtk_tree_view_accessible_notify_gtk;
746 accessible_class->connect_widget_destroyed = gtk_tree_view_accessible_connect_widget_destroyed;
748 /* The children of a GtkTreeView are the buttons at the top of the columns
749 * we do not represent these as children so we do not want to report
750 * children added or deleted when these changed.
752 container_class->add_gtk = NULL;
753 container_class->remove_gtk = NULL;
755 gobject_class->finalize = gtk_tree_view_accessible_finalize;
759 _gtk_tree_view_accessible_init (GtkTreeViewAccessible *view)
764 get_focus_index (GtkTreeView *tree_view)
766 GtkTreePath *focus_path;
767 GtkTreeViewColumn *focus_column;
770 gtk_tree_view_get_cursor (tree_view, &focus_path, &focus_column);
771 if (focus_path && focus_column)
772 index = get_index (tree_view, focus_path,
773 get_column_number (tree_view, focus_column, FALSE));
778 gtk_tree_path_free (focus_path);
783 /* This function returns a reference to the accessible object
784 * for the cell in the treeview which has focus, if any
787 gtk_tree_view_accessible_ref_focus_cell (GtkTreeView *tree_view)
789 AtkObject *focus_cell = NULL;
793 focus_index = get_focus_index (tree_view);
794 if (focus_index >= 0)
796 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
797 focus_cell = atk_object_ref_accessible_child (atk_obj, focus_index);
806 gtk_tree_view_accessible_ref_accessible_at_point (AtkComponent *component,
809 AtkCoordType coord_type)
812 GtkTreeView *tree_view;
814 GtkTreeViewColumn *tv_column;
819 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
823 tree_view = GTK_TREE_VIEW (widget);
825 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
826 gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, x, y, &bx, &by);
827 ret_val = gtk_tree_view_get_path_at_pos (tree_view,
828 bx - x_pos, by - y_pos,
829 &path, &tv_column, NULL, NULL);
834 column = get_column_number (tree_view, tv_column, FALSE);
835 index = get_index (tree_view, path, column);
836 gtk_tree_path_free (path);
838 return gtk_tree_view_accessible_ref_child (ATK_OBJECT (component), index);
845 atk_component_interface_init (AtkComponentIface *iface)
847 iface->ref_accessible_at_point = gtk_tree_view_accessible_ref_accessible_at_point;
853 gtk_tree_view_accessible_get_index_at (AtkTable *table,
858 GtkTreeView *tree_view;
865 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
869 n_cols = atk_table_get_n_columns (table);
870 n_rows = atk_table_get_n_rows (table);
872 if (row >= n_rows || column >= n_cols)
875 tree_view = GTK_TREE_VIEW (widget);
876 actual_column = get_actual_column_number (tree_view, column);
878 set_iter_nth_row (tree_view, &iter, row);
879 path = gtk_tree_model_get_path (gtk_tree_view_get_model (tree_view), &iter);
881 index = get_index (tree_view, path, actual_column);
882 gtk_tree_path_free (path);
888 gtk_tree_view_accessible_get_column_at_index (AtkTable *table,
892 GtkTreeView *tree_view;
895 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
899 tree_view = GTK_TREE_VIEW (widget);
900 n_columns = GTK_TREE_VIEW_ACCESSIBLE (table)->n_cols;
905 index = index % n_columns;
907 return get_visible_column_number (tree_view, index);
911 gtk_tree_view_accessible_get_row_at_index (AtkTable *table,
915 GtkTreeView *tree_view;
918 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
922 tree_view = GTK_TREE_VIEW (widget);
923 if (get_path_column_from_index (tree_view, index, &path, NULL))
925 gint row = get_row_from_tree_path (tree_view, path);
926 gtk_tree_path_free (path);
934 gtk_tree_view_accessible_table_ref_at (AtkTable *table,
940 index = gtk_tree_view_accessible_get_index_at (table, row, column);
944 return gtk_tree_view_accessible_ref_child (ATK_OBJECT (table), index);
948 gtk_tree_view_accessible_get_n_rows (AtkTable *table)
951 GtkTreeView *tree_view;
954 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
958 tree_view = GTK_TREE_VIEW (widget);
959 tree = _gtk_tree_view_get_rbtree (tree_view);
964 return tree->root->parity;
968 gtk_tree_view_accessible_get_n_columns (AtkTable *table)
971 GtkTreeView *tree_view;
972 GtkTreeViewColumn *tv_col;
976 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
980 tree_view = GTK_TREE_VIEW (widget);
981 tv_col = gtk_tree_view_get_column (tree_view, i);
983 while (tv_col != NULL)
985 if (gtk_tree_view_column_get_visible (tv_col))
989 tv_col = gtk_tree_view_get_column (tree_view, i);
996 gtk_tree_view_accessible_is_row_selected (AtkTable *table,
1000 GtkTreeView *tree_view;
1001 GtkTreeSelection *selection;
1004 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1011 tree_view = GTK_TREE_VIEW (widget);
1012 selection = gtk_tree_view_get_selection (tree_view);
1014 set_iter_nth_row (tree_view, &iter, row);
1015 return gtk_tree_selection_iter_is_selected (selection, &iter);
1019 gtk_tree_view_accessible_is_selected (AtkTable *table,
1023 return gtk_tree_view_accessible_is_row_selected (table, row);
1027 get_selected_rows (GtkTreeModel *model,
1032 GPtrArray *array = (GPtrArray *)data;
1034 g_ptr_array_add (array, gtk_tree_path_copy (path));
1038 gtk_tree_view_accessible_get_selected_rows (AtkTable *table,
1039 gint **rows_selected)
1042 GtkTreeView *tree_view;
1043 GtkTreeModel *tree_model;
1045 GtkTreeSelection *selection;
1046 GtkTreePath *tree_path;
1049 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1053 tree_view = GTK_TREE_VIEW (widget);
1054 selection = gtk_tree_view_get_selection (tree_view);
1056 switch (gtk_tree_selection_get_mode (selection))
1058 case GTK_SELECTION_SINGLE:
1059 case GTK_SELECTION_BROWSE:
1060 if (gtk_tree_selection_get_selected (selection, &tree_model, &iter))
1066 *rows_selected = g_new (gint, 1);
1067 tree_path = gtk_tree_model_get_path (tree_model, &iter);
1068 row = get_row_from_tree_path (tree_view, tree_path);
1069 gtk_tree_path_free (tree_path);
1071 /* shouldn't ever happen */
1072 g_return_val_if_fail (row != -1, 0);
1074 *rows_selected[0] = row;
1079 case GTK_SELECTION_MULTIPLE:
1081 GPtrArray *array = g_ptr_array_new();
1083 gtk_tree_selection_selected_foreach (selection, get_selected_rows, array);
1084 ret_val = array->len;
1086 if (rows_selected && ret_val)
1090 *rows_selected = g_new (gint, ret_val);
1091 for (i = 0; i < ret_val; i++)
1095 tree_path = (GtkTreePath *) g_ptr_array_index (array, i);
1096 row = get_row_from_tree_path (tree_view, tree_path);
1097 gtk_tree_path_free (tree_path);
1098 (*rows_selected)[i] = row;
1101 g_ptr_array_free (array, FALSE);
1104 case GTK_SELECTION_NONE:
1111 gtk_tree_view_accessible_add_row_selection (AtkTable *table,
1115 GtkTreeView *tree_view;
1116 GtkTreeModel *tree_model;
1117 GtkTreeSelection *selection;
1118 GtkTreePath *tree_path;
1119 GtkTreeIter iter_to_row;
1121 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1125 if (!gtk_tree_view_accessible_is_row_selected (table, row))
1127 tree_view = GTK_TREE_VIEW (widget);
1128 tree_model = gtk_tree_view_get_model (tree_view);
1129 selection = gtk_tree_view_get_selection (tree_view);
1131 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
1133 tree_path = gtk_tree_path_new ();
1134 gtk_tree_path_append_index (tree_path, row);
1135 gtk_tree_selection_select_path (selection,tree_path);
1136 gtk_tree_path_free (tree_path);
1140 set_iter_nth_row (tree_view, &iter_to_row, row);
1141 gtk_tree_selection_select_iter (selection, &iter_to_row);
1145 return gtk_tree_view_accessible_is_row_selected (table, row);
1149 gtk_tree_view_accessible_remove_row_selection (AtkTable *table,
1153 GtkTreeView *tree_view;
1154 GtkTreeSelection *selection;
1156 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1160 tree_view = GTK_TREE_VIEW (widget);
1161 selection = gtk_tree_view_get_selection (tree_view);
1163 if (gtk_tree_view_accessible_is_row_selected (table, row))
1165 gtk_tree_selection_unselect_all (selection);
1173 gtk_tree_view_accessible_get_column_header (AtkTable *table,
1177 GtkTreeView *tree_view;
1178 GtkTreeViewColumn *tv_col;
1180 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1184 tree_view = GTK_TREE_VIEW (widget);
1185 tv_col = get_column (tree_view, in_col);
1186 return get_header_from_column (tv_col);
1189 static const gchar *
1190 gtk_tree_view_accessible_get_column_description (AtkTable *table,
1194 GtkTreeView *tree_view;
1195 GtkTreeViewColumn *tv_col;
1197 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1201 tree_view = GTK_TREE_VIEW (widget);
1202 tv_col = get_column (tree_view, in_col);
1206 return gtk_tree_view_column_get_title (tv_col);
1210 atk_table_interface_init (AtkTableIface *iface)
1212 iface->ref_at = gtk_tree_view_accessible_table_ref_at;
1213 iface->get_n_rows = gtk_tree_view_accessible_get_n_rows;
1214 iface->get_n_columns = gtk_tree_view_accessible_get_n_columns;
1215 iface->get_index_at = gtk_tree_view_accessible_get_index_at;
1216 iface->get_column_at_index = gtk_tree_view_accessible_get_column_at_index;
1217 iface->get_row_at_index = gtk_tree_view_accessible_get_row_at_index;
1218 iface->is_row_selected = gtk_tree_view_accessible_is_row_selected;
1219 iface->is_selected = gtk_tree_view_accessible_is_selected;
1220 iface->get_selected_rows = gtk_tree_view_accessible_get_selected_rows;
1221 iface->add_row_selection = gtk_tree_view_accessible_add_row_selection;
1222 iface->remove_row_selection = gtk_tree_view_accessible_remove_row_selection;
1223 iface->get_column_extent_at = NULL;
1224 iface->get_row_extent_at = NULL;
1225 iface->get_column_header = gtk_tree_view_accessible_get_column_header;
1226 iface->get_column_description = gtk_tree_view_accessible_get_column_description;
1229 /* atkselection.h */
1232 gtk_tree_view_accessible_add_selection (AtkSelection *selection,
1239 table = ATK_TABLE (selection);
1240 n_columns = gtk_tree_view_accessible_get_n_columns (table);
1244 row = gtk_tree_view_accessible_get_row_at_index (table, i);
1245 return gtk_tree_view_accessible_add_row_selection (table, row);
1249 gtk_tree_view_accessible_clear_selection (AtkSelection *selection)
1252 GtkTreeView *tree_view;
1253 GtkTreeSelection *tree_selection;
1255 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
1259 tree_view = GTK_TREE_VIEW (widget);
1260 tree_selection = gtk_tree_view_get_selection (tree_view);
1262 gtk_tree_selection_unselect_all (tree_selection);
1267 gtk_tree_view_accessible_ref_selection (AtkSelection *selection,
1276 table = ATK_TABLE (selection);
1277 n_columns = gtk_tree_view_accessible_get_n_columns (table);
1278 n_selected = gtk_tree_view_accessible_get_selected_rows (table, &selected);
1279 if (i >= n_columns * n_selected)
1282 row = selected[i / n_columns];
1285 return gtk_tree_view_accessible_table_ref_at (table, row, i % n_columns);
1289 gtk_tree_view_accessible_get_selection_count (AtkSelection *selection)
1294 table = ATK_TABLE (selection);
1295 n_selected = gtk_tree_view_accessible_get_selected_rows (table, NULL);
1297 n_selected *= gtk_tree_view_accessible_get_n_columns (table);
1302 gtk_tree_view_accessible_is_child_selected (AtkSelection *selection,
1308 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
1312 row = atk_table_get_row_at_index (ATK_TABLE (selection), i);
1314 return gtk_tree_view_accessible_is_row_selected (ATK_TABLE (selection), row);
1317 static void atk_selection_interface_init (AtkSelectionIface *iface)
1319 iface->add_selection = gtk_tree_view_accessible_add_selection;
1320 iface->clear_selection = gtk_tree_view_accessible_clear_selection;
1321 iface->ref_selection = gtk_tree_view_accessible_ref_selection;
1322 iface->get_selection_count = gtk_tree_view_accessible_get_selection_count;
1323 iface->is_child_selected = gtk_tree_view_accessible_is_child_selected;
1326 #define EXTRA_EXPANDER_PADDING 4
1329 gtk_tree_view_accessible_get_cell_area (GtkCellAccessibleParent *parent,
1330 GtkCellAccessible *cell,
1331 GdkRectangle *cell_rect)
1334 GtkTreeView *tree_view;
1335 GtkTreeViewColumn *tv_col;
1337 AtkObject *parent_cell;
1338 GtkTreeViewAccessibleCellInfo *cell_info;
1339 GtkCellAccessible *top_cell;
1341 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1345 tree_view = GTK_TREE_VIEW (widget);
1346 parent_cell = atk_object_get_parent (ATK_OBJECT (cell));
1347 if (parent_cell != ATK_OBJECT (parent))
1348 top_cell = GTK_CELL_ACCESSIBLE (parent_cell);
1351 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), top_cell, TRUE);
1352 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
1354 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
1355 tv_col = cell_info->cell_col_ref;
1356 if (path && cell_info->in_use)
1358 GtkTreeViewColumn *expander_column;
1359 gint focus_line_width;
1361 gtk_tree_view_get_cell_area (tree_view, path, tv_col, cell_rect);
1362 expander_column = gtk_tree_view_get_expander_column (tree_view);
1363 if (expander_column == tv_col)
1366 gtk_widget_style_get (widget,
1367 "expander-size", &expander_size,
1369 cell_rect->x += expander_size + EXTRA_EXPANDER_PADDING;
1370 cell_rect->width -= expander_size + EXTRA_EXPANDER_PADDING;
1372 gtk_widget_style_get (widget,
1373 "focus-line-width", &focus_line_width,
1376 cell_rect->x += focus_line_width;
1377 cell_rect->width -= 2 * focus_line_width;
1379 gtk_tree_path_free (path);
1381 /* A column has more than one renderer so we find the position
1384 if (top_cell != cell)
1391 GtkCellRenderer *renderer;
1393 cell_index = atk_object_get_index_in_parent (ATK_OBJECT (cell));
1394 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
1395 renderer = g_list_nth_data (renderers, cell_index);
1397 found = gtk_tree_view_column_cell_get_position (tv_col, renderer, &cell_start, &cell_width);
1400 cell_rect->x += cell_start;
1401 cell_rect->width = cell_width;
1403 g_list_free (renderers);
1410 gtk_tree_view_accessible_get_cell_extents (GtkCellAccessibleParent *parent,
1411 GtkCellAccessible *cell,
1416 AtkCoordType coord_type)
1419 GtkTreeView *tree_view;
1420 GdkWindow *bin_window;
1421 GdkRectangle cell_rect;
1424 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1428 tree_view = GTK_TREE_VIEW (widget);
1429 gtk_tree_view_accessible_get_cell_area (parent, cell, &cell_rect);
1430 bin_window = gtk_tree_view_get_bin_window (tree_view);
1431 gdk_window_get_origin (bin_window, &w_x, &w_y);
1433 if (coord_type == ATK_XY_WINDOW)
1436 gint x_toplevel, y_toplevel;
1438 window = gdk_window_get_toplevel (bin_window);
1439 gdk_window_get_origin (window, &x_toplevel, &y_toplevel);
1445 *width = cell_rect.width;
1446 *height = cell_rect.height;
1447 if (is_cell_showing (tree_view, &cell_rect))
1449 *x = cell_rect.x + w_x;
1450 *y = cell_rect.y + w_y;
1460 gtk_tree_view_accessible_grab_cell_focus (GtkCellAccessibleParent *parent,
1461 GtkCellAccessible *cell)
1464 GtkTreeView *tree_view;
1465 GtkTreeViewColumn *tv_col;
1467 AtkObject *parent_cell;
1468 AtkObject *cell_object;
1469 GtkTreeViewAccessibleCellInfo *cell_info;
1470 GtkCellRenderer *renderer = NULL;
1471 GtkWidget *toplevel;
1474 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1478 tree_view = GTK_TREE_VIEW (widget);
1480 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
1481 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
1483 cell_object = ATK_OBJECT (cell);
1484 parent_cell = atk_object_get_parent (cell_object);
1485 tv_col = cell_info->cell_col_ref;
1486 if (parent_cell != ATK_OBJECT (parent))
1488 /* GtkCellAccessible is in a GtkContainerCellAccessible.
1489 * The GtkTreeViewColumn has multiple renderers;
1490 * find the corresponding one.
1494 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
1495 if (cell_info->in_use)
1497 index = atk_object_get_index_in_parent (cell_object);
1498 renderer = g_list_nth_data (renderers, index);
1500 g_list_free (renderers);
1502 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
1503 if (path && cell_info->in_use)
1506 gtk_tree_view_set_cursor_on_cell (tree_view, path, tv_col, renderer, FALSE);
1508 gtk_tree_view_set_cursor (tree_view, path, tv_col, FALSE);
1510 gtk_tree_path_free (path);
1511 gtk_widget_grab_focus (widget);
1512 toplevel = gtk_widget_get_toplevel (widget);
1513 if (gtk_widget_is_toplevel (toplevel))
1515 #ifdef GDK_WINDOWING_X11
1516 gtk_window_present_with_time (GTK_WINDOW (toplevel),
1517 gdk_x11_get_server_time (gtk_widget_get_window (widget)));
1519 gtk_window_present (GTK_WINDOW (toplevel));
1530 gtk_cell_accessible_parent_get_child_index (GtkCellAccessibleParent *parent,
1531 GtkCellAccessible *cell)
1533 GtkTreeViewAccessibleCellInfo *cell_info;
1535 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
1536 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
1539 return cell_info_get_index (tree_view, info);
1543 gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface)
1545 iface->get_cell_extents = gtk_tree_view_accessible_get_cell_extents;
1546 iface->get_cell_area = gtk_tree_view_accessible_get_cell_area;
1547 iface->grab_focus = gtk_tree_view_accessible_grab_cell_focus;
1548 iface->get_child_index = gtk_tree_view_accessible_get_child_index;
1551 /* signal handling */
1554 idle_expand_row (gpointer data)
1556 GtkTreeViewAccessible *accessible = data;
1558 GtkTreeView *tree_view;
1560 GtkTreeModel *tree_model;
1561 gint n_inserted, row;
1563 accessible->idle_expand_id = 0;
1565 path = accessible->idle_expand_path;
1566 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
1568 tree_model = gtk_tree_view_get_model (tree_view);
1572 if (!path || !gtk_tree_model_get_iter (tree_model, &iter, path))
1575 /* Update visibility of cells below expansion row */
1576 traverse_cells (accessible, path, FALSE, FALSE);
1578 /* Figure out number of visible children, the following test
1581 if (gtk_tree_model_iter_has_child (tree_model, &iter))
1583 GtkTreePath *path_copy;
1585 /* By passing path into this function, we find the number of
1586 * visible children of path.
1588 path_copy = gtk_tree_path_copy (path);
1589 gtk_tree_path_append_index (path_copy, 0);
1592 iterate_thru_children (tree_view, tree_model,
1593 path_copy, NULL, &n_inserted, 0);
1594 gtk_tree_path_free (path_copy);
1598 /* We can get here if the row expanded callback deleted the row */
1602 /* Set expand state */
1603 set_expand_state (tree_view, tree_model, accessible, path, TRUE);
1605 row = get_row_from_tree_path (tree_view, path);
1607 /* shouldn't ever happen */
1609 g_assert_not_reached ();
1611 /* Must add 1 because the "added rows" are below the row being expanded */
1614 g_signal_emit_by_name (accessible, "row-inserted", row, n_inserted);
1616 accessible->idle_expand_path = NULL;
1618 gtk_tree_path_free (path);
1624 row_expanded_cb (GtkTreeView *tree_view,
1629 GtkTreeViewAccessible *accessible;
1631 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
1632 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1635 * The visible rectangle has not been updated when this signal is emitted
1636 * so we process the signal when the GTK processing is completed
1638 /* this seems wrong since it overwrites any other pending expand handlers... */
1639 accessible->idle_expand_path = gtk_tree_path_copy (path);
1640 if (accessible->idle_expand_id)
1641 g_source_remove (accessible->idle_expand_id);
1642 accessible->idle_expand_id = gdk_threads_add_idle (idle_expand_row, accessible);
1648 row_collapsed_cb (GtkTreeView *tree_view,
1652 GtkTreeModel *tree_model;
1654 GtkTreeViewAccessible *accessible;
1657 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
1658 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1659 tree_model = gtk_tree_view_get_model (tree_view);
1661 clean_rows (accessible);
1663 /* Update visibility of cells below collapsed row */
1664 traverse_cells (accessible, path, FALSE, FALSE);
1666 /* Set collapse state */
1667 set_expand_state (tree_view, tree_model, accessible, path, FALSE);
1668 if (accessible->n_children_deleted == 0)
1670 row = get_row_from_tree_path (tree_view, path);
1673 g_signal_emit_by_name (atk_obj, "row-deleted", row,
1674 accessible->n_children_deleted);
1675 accessible->n_children_deleted = 0;
1680 size_allocate_cb (GtkWidget *widget,
1681 GtkAllocation *allocation)
1684 GtkTreeViewAccessible *accessible;
1686 atk_obj = gtk_widget_get_accessible (widget);
1687 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1689 /* If the size allocation changes, the visibility of cells
1690 * may change so update the cells visibility.
1692 traverse_cells (accessible, NULL, FALSE, FALSE);
1696 selection_changed_cb (GtkTreeSelection *selection,
1699 GtkTreeViewAccessible *accessible;
1700 GtkTreeView *tree_view;
1702 GtkTreeViewAccessibleCellInfo *info;
1703 GtkTreeSelection *tree_selection;
1705 GHashTableIter iter;
1707 accessible = GTK_TREE_VIEW_ACCESSIBLE (data);
1708 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
1712 tree_view = GTK_TREE_VIEW (widget);
1713 tree_selection = gtk_tree_view_get_selection (tree_view);
1715 clean_rows (accessible);
1717 /* FIXME: clean rows iterates through all cells too */
1718 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
1719 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&info))
1723 _gtk_cell_accessible_remove_state (info->cell, ATK_STATE_SELECTED, TRUE);
1725 path = gtk_tree_row_reference_get_path (info->cell_row_ref);
1726 if (path && gtk_tree_selection_path_is_selected (tree_selection, path))
1727 _gtk_cell_accessible_add_state (info->cell, ATK_STATE_SELECTED, TRUE);
1728 gtk_tree_path_free (path);
1731 if (gtk_widget_get_realized (widget))
1732 g_signal_emit_by_name (accessible, "selection-changed");
1736 columns_changed (GtkTreeView *tree_view)
1739 GtkTreeViewAccessible *accessible;
1740 GList *tv_cols, *tmp_list;
1741 gboolean column_found;
1742 gboolean move_found = FALSE;
1743 gboolean stale_set = FALSE;
1744 gint column_count = 0;
1747 atk_obj = gtk_widget_get_accessible (GTK_WIDGET(tree_view));
1748 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1750 /* This function must determine if the change is an add, delete
1751 * or a move based upon its cache of TreeViewColumns in
1752 * accessible->col_data
1754 tv_cols = gtk_tree_view_get_columns (tree_view);
1755 accessible->n_cols = g_list_length (tv_cols);
1757 /* check for adds or moves */
1758 for (tmp_list = tv_cols; tmp_list; tmp_list = tmp_list->next)
1760 column_found = FALSE;
1762 for (i = 0; i < accessible->col_data->len; i++)
1765 if ((GtkTreeViewColumn *)tmp_list->data ==
1766 (GtkTreeViewColumn *)g_array_index (accessible->col_data,
1767 GtkTreeViewColumn *, i))
1769 column_found = TRUE;
1771 /* If the column isn't in the same position, a move happened */
1772 if (!move_found && i != column_count)
1776 /* Set all rows to ATK_STATE_STALE */
1777 traverse_cells (accessible, NULL, TRUE, FALSE);
1781 /* Just emit one column reordered signal when a move happens */
1782 g_signal_emit_by_name (atk_obj, "column-reordered");
1790 /* If column_found is FALSE, then an insert happened for column
1791 * number column_count
1799 /* Set all rows to ATK_STATE_STALE */
1800 traverse_cells (accessible, NULL, TRUE, FALSE);
1804 /* Generate column-inserted signal */
1805 g_signal_emit_by_name (atk_obj, "column-inserted", column_count, 1);
1807 /* Generate children-changed signals */
1808 for (row = 0; row < accessible->n_rows; row++)
1810 /* Pass NULL as the child object, i.e. 4th argument */
1811 g_signal_emit_by_name (atk_obj, "children-changed::add",
1812 ((row * accessible->n_cols) + column_count), NULL, NULL);
1819 /* check for deletes */
1820 for (i = 0; i < accessible->col_data->len; i++)
1822 column_found = FALSE;
1824 for (tmp_list = tv_cols; tmp_list; tmp_list = tmp_list->next)
1826 if ((GtkTreeViewColumn *)tmp_list->data ==
1827 (GtkTreeViewColumn *)g_array_index (accessible->col_data,
1828 GtkTreeViewColumn *, i))
1830 column_found = TRUE;
1835 /* If column_found is FALSE, then a delete happened for column
1842 clean_cols (accessible,
1843 (GtkTreeViewColumn *)g_array_index (accessible->col_data,
1844 GtkTreeViewColumn *, i));
1848 /* Set all rows to ATK_STATE_STALE */
1849 traverse_cells (accessible, NULL, TRUE, FALSE);
1853 /* Generate column-deleted signal */
1854 g_signal_emit_by_name (atk_obj, "column-deleted", i, 1);
1856 /* Generate children-changed signals */
1857 for (row = 0; row < accessible->n_rows; row++)
1859 /* Pass NULL as the child object, 4th argument */
1860 g_signal_emit_by_name (atk_obj, "children-changed::remove",
1861 ((row * accessible->n_cols) + column_count), NULL, NULL);
1866 /* rebuild the array */
1867 g_array_free (accessible->col_data, TRUE);
1868 accessible->col_data = g_array_sized_new (FALSE, TRUE, sizeof (GtkTreeViewColumn *), 0);
1870 for (tmp_list = tv_cols; tmp_list; tmp_list = tmp_list->next)
1871 g_array_append_val (accessible->col_data, tmp_list->data);
1872 g_list_free (tv_cols);
1876 cursor_changed (GtkTreeView *tree_view,
1877 GtkTreeViewAccessible *accessible)
1881 cell = gtk_tree_view_accessible_ref_focus_cell (tree_view);
1884 if (cell != accessible->focus_cell)
1886 if (accessible->focus_cell)
1888 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_ACTIVE, FALSE);
1889 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_FOCUSED, FALSE);
1890 g_object_unref (accessible->focus_cell);
1891 accessible->focus_cell = cell;
1894 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
1896 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_ACTIVE, FALSE);
1897 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_FOCUSED, FALSE);
1900 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
1903 g_object_unref (cell);
1908 focus_in (GtkWidget *widget)
1910 GtkTreeView *tree_view;
1911 GtkTreeViewAccessible *accessible;
1912 AtkStateSet *state_set;
1915 tree_view = GTK_TREE_VIEW (widget);
1916 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
1918 if (accessible->focus_cell == NULL)
1920 cell = gtk_tree_view_accessible_ref_focus_cell (tree_view);
1923 state_set = atk_object_ref_state_set (cell);
1926 if (!atk_state_set_contains_state (state_set, ATK_STATE_FOCUSED))
1928 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_ACTIVE, FALSE);
1929 accessible->focus_cell = cell;
1930 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_FOCUSED, FALSE);
1931 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
1933 g_object_unref (state_set);
1941 focus_out (GtkWidget *widget)
1943 GtkTreeViewAccessible *accessible;
1945 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
1946 if (accessible->focus_cell)
1948 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_ACTIVE, FALSE);
1949 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_FOCUSED, FALSE);
1950 g_object_unref (accessible->focus_cell);
1951 accessible->focus_cell = NULL;
1957 model_row_changed (GtkTreeModel *tree_model,
1962 GtkTreeView *tree_view = GTK_TREE_VIEW (user_data);
1963 GtkTreeViewAccessible *accessible;
1964 GtkTreePath *cell_path;
1965 GtkTreeViewAccessibleCellInfo *cell_info;
1966 GHashTableIter hash_iter;
1968 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (tree_view)));
1970 /* Loop through our cached cells */
1971 /* Must loop through them all */
1972 g_hash_table_iter_init (&hash_iter, accessible->cell_info_by_index);
1973 while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer *)&cell_info))
1975 if (cell_info->in_use)
1977 cell_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
1979 if (cell_path != NULL)
1981 if (path && gtk_tree_path_compare (cell_path, path) == 0)
1983 if (GTK_IS_RENDERER_CELL_ACCESSIBLE (cell_info->cell))
1984 update_cell_value (GTK_RENDERER_CELL_ACCESSIBLE (cell_info->cell),
1987 gtk_tree_path_free (cell_path);
1991 g_signal_emit_by_name (accessible, "visible-data-changed");
1995 column_visibility_changed (GObject *object,
1999 if (g_strcmp0 (pspec->name, "visible") == 0)
2001 /* A column has been made visible or invisible
2002 * We update our cache of cells and emit model_changed signal
2004 GtkTreeView *tree_view = (GtkTreeView *)user_data;
2005 GtkTreeViewAccessible *accessible;
2006 GtkTreeViewAccessibleCellInfo *cell_info;
2007 GtkTreeViewColumn *this_col = GTK_TREE_VIEW_COLUMN (object);
2008 GtkTreeViewColumn *tv_col;
2009 GHashTableIter iter;
2011 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (tree_view))
2013 g_signal_emit_by_name (accessible, "model-changed");
2015 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
2016 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
2018 if (cell_info->in_use)
2020 tv_col = cell_info->cell_col_ref;
2021 if (tv_col == this_col)
2023 GtkTreePath *row_path;
2024 row_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2025 if (GTK_IS_RENDERER_CELL_ACCESSIBLE (cell_info->cell))
2027 if (gtk_tree_view_column_get_visible (tv_col))
2028 set_cell_visibility (tree_view,
2030 tv_col, row_path, FALSE);
2033 _gtk_cell_accessible_remove_state (cell_info->cell, ATK_STATE_VISIBLE, TRUE);
2034 _gtk_cell_accessible_remove_state (cell_info->cell, ATK_STATE_SHOWING, TRUE);
2037 gtk_tree_path_free (row_path);
2045 model_row_inserted (GtkTreeModel *tree_model,
2050 GtkTreeView *tree_view = (GtkTreeView *)user_data;
2052 GtkTreeViewAccessible *accessible;
2053 GtkTreePath *path_copy;
2054 gint row, n_inserted, child_row;
2056 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
2057 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
2058 accessible->n_rows++;
2060 if (accessible->idle_expand_id)
2062 g_source_remove (accessible->idle_expand_id);
2063 accessible->idle_expand_id = 0;
2065 /* don't do this if the insertion precedes the idle path,
2066 * since it will now be invalid
2068 if (path && accessible->idle_expand_path &&
2069 (gtk_tree_path_compare (path, accessible->idle_expand_path) > 0))
2070 set_expand_state (tree_view, tree_model, accessible, accessible->idle_expand_path, FALSE);
2071 if (accessible->idle_expand_path)
2072 gtk_tree_path_free (accessible->idle_expand_path);
2074 /* Check to see if row is visible */
2075 row = get_row_from_tree_path (tree_view, path);
2077 /* A row insert is not necessarily visible. For example,
2078 * a row can be draged & dropped into another row, which
2079 * causes an insert on the model that isn't visible in the
2080 * view. Only generate a signal if the inserted row is
2085 GtkTreeIter tmp_iter;
2088 gtk_tree_model_get_iter (tree_model, &tmp_iter, path);
2090 /* Figure out number of visible children. */
2091 if (gtk_tree_model_iter_has_child (tree_model, &tmp_iter))
2095 * By passing path into this function, we find the number of
2096 * visible children of path.
2099 /* iterate_thru_children modifies path, we don't want that, so give
2101 path2 = gtk_tree_path_copy (path);
2102 iterate_thru_children (tree_view, tree_model,
2103 path2, NULL, &n_inserted, 0);
2104 gtk_tree_path_free (path2);
2106 /* Must add one to include the row that is being added */
2112 /* Set rows below the inserted row to ATK_STATE_STALE */
2113 traverse_cells (accessible, path, TRUE, TRUE);
2115 /* Generate row-inserted signal */
2116 g_signal_emit_by_name (atk_obj, "row-inserted", row, n_inserted);
2118 /* Generate children-changed signals */
2119 n_cols = gtk_tree_view_accessible_get_n_columns (ATK_TABLE (atk_obj));
2120 for (child_row = row; child_row < (row + n_inserted); child_row++)
2122 for (col = 0; col < n_cols; col++)
2124 /* Pass NULL as the child object, i.e. 4th argument */
2125 g_signal_emit_by_name (atk_obj, "children-changed::add",
2126 ((row * n_cols) + col), NULL, NULL);
2132 /* The row has been inserted inside another row. This can
2133 * cause a row that previously couldn't be expanded to now
2136 path_copy = gtk_tree_path_copy (path);
2137 gtk_tree_path_up (path_copy);
2138 set_expand_state (tree_view, tree_model, accessible, path_copy, TRUE);
2139 gtk_tree_path_free (path_copy);
2144 model_row_deleted (GtkTreeModel *tree_model,
2148 GtkTreeView *tree_view = (GtkTreeView *)user_data;
2149 GtkTreePath *path_copy;
2151 GtkTreeViewAccessible *accessible;
2154 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
2155 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
2157 accessible->n_rows--;
2159 if (accessible->idle_expand_id)
2161 g_source_remove (accessible->idle_expand_id);
2162 gtk_tree_path_free (accessible->idle_expand_path);
2163 accessible->idle_expand_id = 0;
2166 /* Check to see if row is visible */
2167 clean_rows (accessible);
2169 /* Set rows at or below the specified row to ATK_STATE_STALE */
2170 traverse_cells (accessible, path, TRUE, TRUE);
2172 /* If deleting a row with a depth > 1, then this may affect the
2173 * expansion/contraction of its parent(s). Make sure this is
2176 if (gtk_tree_path_get_depth (path) > 1)
2178 path_copy = gtk_tree_path_copy (path);
2179 gtk_tree_path_up (path_copy);
2180 set_expand_state (tree_view, tree_model, accessible, path_copy, TRUE);
2181 gtk_tree_path_free (path_copy);
2183 row = get_row_from_tree_path (tree_view, path);
2185 /* If the row which is deleted is not visible because it is a child of
2186 * a collapsed row then row will be -1
2189 g_signal_emit_by_name (atk_obj, "row-deleted", row,
2190 accessible->n_children_deleted + 1);
2191 accessible->n_children_deleted = 0;
2193 /* Generate children-changed signals */
2194 for (col = 0; col < accessible->n_cols; col++)
2196 /* Pass NULL as the child object, 4th argument */
2197 g_signal_emit_by_name (atk_obj, "children-changed::remove",
2198 ((row * accessible->n_cols) + col), NULL, NULL);
2202 /* This function gets called when a row is deleted or when rows are
2203 * removed from the view due to a collapse event. Note that the
2204 * count is the number of visible *children* of the deleted row,
2205 * so it does not include the row being deleted.
2207 * As this function is called before the rows are removed we just note
2208 * the number of rows and then deal with it when we get a notification
2209 * that rows were deleted or collapsed.
2212 destroy_count_func (GtkTreeView *tree_view,
2218 GtkTreeViewAccessible *accessible;
2220 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
2221 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
2223 if (accessible->n_children_deleted != 0)
2226 accessible->n_children_deleted = count;
2230 model_rows_reordered (GtkTreeModel *tree_model,
2236 GtkTreeView *tree_view = (GtkTreeView *)user_data;
2238 GtkTreeViewAccessible *accessible;
2240 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
2241 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
2243 if (accessible->idle_expand_id)
2245 g_source_remove (accessible->idle_expand_id);
2246 gtk_tree_path_free (accessible->idle_expand_path);
2247 accessible->idle_expand_id = 0;
2249 traverse_cells (accessible, NULL, TRUE, FALSE);
2251 g_signal_emit_by_name (atk_obj, "row-reordered");
2255 set_cell_visibility (GtkTreeView *tree_view,
2256 GtkCellAccessible *cell,
2257 GtkTreeViewColumn *tv_col,
2258 GtkTreePath *tree_path,
2259 gboolean emit_signal)
2261 GdkRectangle cell_rect;
2263 /* Get these three values in tree coords */
2264 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
2265 gtk_tree_view_get_cell_area (tree_view, tree_path, tv_col, &cell_rect);
2267 cell_rect.height = 0;
2269 if (cell_rect.height > 0)
2271 /* The height will be zero for a cell for which an antecedent
2274 _gtk_cell_accessible_add_state (cell, ATK_STATE_VISIBLE, emit_signal);
2275 if (is_cell_showing (tree_view, &cell_rect))
2276 _gtk_cell_accessible_add_state (cell, ATK_STATE_SHOWING, emit_signal);
2278 _gtk_cell_accessible_remove_state (cell, ATK_STATE_SHOWING, emit_signal);
2282 _gtk_cell_accessible_remove_state (cell, ATK_STATE_VISIBLE, emit_signal);
2283 _gtk_cell_accessible_remove_state (cell, ATK_STATE_SHOWING, emit_signal);
2288 is_cell_showing (GtkTreeView *tree_view,
2289 GdkRectangle *cell_rect)
2291 GdkRectangle rect, *visible_rect;
2292 GdkRectangle rect1, *tree_cell_rect;
2294 gboolean is_showing;
2296 /* A cell is considered "SHOWING" if any part of the cell is
2297 * in the visible area. Other ways we could do this is by a
2298 * cell's midpoint or if the cell is fully in the visible range.
2299 * Since we have the cell_rect x, y, width, height of the cell,
2300 * any of these is easy to compute.
2302 * It is assumed that cell's rectangle is in widget coordinates
2303 * so we must transform to tree cordinates.
2305 visible_rect = ▭
2306 tree_cell_rect = &rect1;
2307 tree_cell_rect->x = cell_rect->x;
2308 tree_cell_rect->y = cell_rect->y;
2309 tree_cell_rect->width = cell_rect->width;
2310 tree_cell_rect->height = cell_rect->height;
2312 gtk_tree_view_get_visible_rect (tree_view, visible_rect);
2313 gtk_tree_view_convert_tree_to_bin_window_coords (tree_view, visible_rect->x,
2314 visible_rect->y, &bx, &by);
2316 if (((tree_cell_rect->x + tree_cell_rect->width) < bx) ||
2317 ((tree_cell_rect->y + tree_cell_rect->height) < by) ||
2318 (tree_cell_rect->x > (bx + visible_rect->width)) ||
2319 (tree_cell_rect->y > (by + visible_rect->height)))
2329 /* This function is called when a cell's flyweight is created in
2330 * gtk_tree_view_accessible_table_ref_at with emit_change_signal
2331 * set to FALSE and in model_row_changed() on receipt of "row-changed"
2332 * signal when emit_change_signal is set to TRUE
2335 update_cell_value (GtkRendererCellAccessible *renderer_cell,
2336 GtkTreeViewAccessible *accessible,
2337 gboolean emit_change_signal)
2339 GtkTreeViewAccessibleCellInfo *cell_info;
2340 GtkTreeView *tree_view;
2341 GtkTreeModel *tree_model;
2344 GList *renderers, *cur_renderer;
2346 GtkRendererCellAccessibleClass *renderer_cell_class;
2347 GtkCellRendererClass *gtk_cell_renderer_class;
2348 GtkCellAccessible *cell;
2351 gboolean is_expander, is_expanded;
2353 renderer_cell_class = GTK_RENDERER_CELL_ACCESSIBLE_GET_CLASS (renderer_cell);
2354 if (renderer_cell->renderer)
2355 gtk_cell_renderer_class = GTK_CELL_RENDERER_GET_CLASS (renderer_cell->renderer);
2357 gtk_cell_renderer_class = NULL;
2359 prop_list = renderer_cell_class->property_list;
2361 cell = GTK_CELL_ACCESSIBLE (renderer_cell);
2362 cell_info = find_cell_info (accessible, cell, TRUE);
2363 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
2366 if (emit_change_signal && cell_info->in_use)
2368 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
2369 tree_model = gtk_tree_view_get_model (tree_view);
2370 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2374 gtk_tree_model_get_iter (tree_model, &iter, path);
2375 is_expander = FALSE;
2376 is_expanded = FALSE;
2377 if (gtk_tree_model_iter_has_child (tree_model, &iter))
2379 GtkTreeViewColumn *expander_tv;
2381 expander_tv = gtk_tree_view_get_expander_column (tree_view);
2382 if (expander_tv == cell_info->cell_col_ref)
2385 is_expanded = gtk_tree_view_row_expanded (tree_view, path);
2388 gtk_tree_path_free (path);
2389 gtk_tree_view_column_cell_set_cell_data (cell_info->cell_col_ref,
2391 is_expander, is_expanded);
2393 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_info->cell_col_ref));
2397 /* If the cell is in a container, its index is used to find the renderer
2398 * in the list. Otherwise, we assume that the cell is represented
2399 * by the first renderer in the list
2402 if (cell_info->in_use)
2404 parent = atk_object_get_parent (ATK_OBJECT (cell));
2406 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
2407 cur_renderer = g_list_nth (renderers, cell->index);
2409 cur_renderer = renderers;
2414 if (cur_renderer == NULL)
2417 if (gtk_cell_renderer_class)
2421 spec = g_object_class_find_property
2422 (G_OBJECT_CLASS (gtk_cell_renderer_class), *prop_list);
2426 GValue value = G_VALUE_INIT;
2428 g_value_init (&value, spec->value_type);
2429 g_object_get_property (cur_renderer->data, *prop_list, &value);
2430 g_object_set_property (G_OBJECT (renderer_cell->renderer),
2431 *prop_list, &value);
2432 g_value_unset (&value);
2435 g_warning ("Invalid property: %s\n", *prop_list);
2439 g_list_free (renderers);
2441 return _gtk_renderer_cell_accessible_update_cache (renderer_cell, emit_change_signal);
2445 get_row_from_tree_path (GtkTreeView *tree_view,
2448 GtkTreeModel *tree_model;
2449 GtkTreePath *root_tree;
2452 tree_model = gtk_tree_view_get_model (tree_view);
2454 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
2455 row = gtk_tree_path_get_indices (path)[0];
2458 root_tree = gtk_tree_path_new_first ();
2460 iterate_thru_children (tree_view, tree_model, root_tree, path, &row, 0);
2461 gtk_tree_path_free (root_tree);
2470 * Get the specified GtkTreeViewColumn in the GtkTreeView.
2471 * Only visible columns are considered.
2473 static GtkTreeViewColumn *
2474 get_column (GtkTreeView *tree_view,
2477 GtkTreeViewColumn *tv_col;
2483 g_warning ("Request for invalid column %d\n", in_col);
2487 tv_col = gtk_tree_view_get_column (tree_view, i);
2488 while (tv_col != NULL)
2490 if (gtk_tree_view_column_get_visible (tv_col))
2492 if (in_col == n_cols)
2494 tv_col = gtk_tree_view_get_column (tree_view, ++i);
2497 if (in_col != n_cols)
2499 g_warning ("Request for invalid column %d\n", in_col);
2506 get_actual_column_number (GtkTreeView *tree_view,
2507 gint visible_column)
2509 GtkTreeViewColumn *tv_col;
2510 gint actual_column = 0;
2511 gint visible_columns = -1;
2513 /* This function calculates the column number which corresponds
2514 * to the specified visible column number
2516 tv_col = gtk_tree_view_get_column (tree_view, actual_column);
2517 while (tv_col != NULL)
2519 if (gtk_tree_view_column_get_visible (tv_col))
2521 if (visible_columns == visible_column)
2522 return actual_column;
2523 tv_col = gtk_tree_view_get_column (tree_view, ++actual_column);
2525 g_warning ("get_actual_column_number failed for %d\n", visible_column);
2530 get_visible_column_number (GtkTreeView *tree_view,
2533 GtkTreeViewColumn *tv_col;
2535 gint visible_columns = -1;
2537 /* This function calculates the visible column number
2538 * which corresponds to the specified actual column number
2540 tv_col = gtk_tree_view_get_column (tree_view, column);
2542 while (tv_col != NULL)
2544 if (gtk_tree_view_column_get_visible (tv_col))
2547 if (actual_column == column)
2548 return visible_columns;
2551 if (actual_column == column)
2553 tv_col = gtk_tree_view_get_column (tree_view, ++column);
2555 g_warning ("get_visible_column_number failed for %d\n", actual_column);
2559 /* Helper recursive function that returns an iter to nth row
2561 static GtkTreeIter *
2562 return_iter_nth_row (GtkTreeView *tree_view,
2563 GtkTreeModel *tree_model,
2568 GtkTreePath *current_path;
2569 GtkTreeIter new_iter;
2570 gboolean row_expanded;
2572 current_path = gtk_tree_model_get_path (tree_model, iter);
2573 if (increment == row)
2575 gtk_tree_path_free (current_path);
2579 row_expanded = gtk_tree_view_row_expanded (tree_view, current_path);
2580 gtk_tree_path_free (current_path);
2583 if ((row_expanded && gtk_tree_model_iter_children (tree_model, iter, &new_iter)) ||
2584 (gtk_tree_model_iter_next (tree_model, iter)) ||
2585 (gtk_tree_model_iter_parent (tree_model, iter, &new_iter) &&
2586 (gtk_tree_model_iter_next (tree_model, iter))))
2587 return return_iter_nth_row (tree_view, tree_model, iter,
2594 set_iter_nth_row (GtkTreeView *tree_view,
2598 GtkTreeModel *tree_model;
2600 tree_model = gtk_tree_view_get_model (tree_view);
2601 gtk_tree_model_get_iter_first (tree_model, iter);
2602 iter = return_iter_nth_row (tree_view, tree_model, iter, 0, row);
2605 /* Recursively called until the row specified by orig is found.
2607 * *count will be set to the visible row number of the child
2608 * relative to the row that was initially passed in as tree_path.
2609 * tree_path could be modified by this function.
2611 * *count will be -1 if orig is not found as a child (a row that is
2612 * not visible will not be found, e.g. if the row is inside a
2613 * collapsed row). If NULL is passed in as orig, *count will
2614 * be a count of the visible children.
2616 * NOTE: the value for depth must be 0 when this recursive function
2617 * is initially called, or it may not function as expected.
2620 iterate_thru_children (GtkTreeView *tree_view,
2621 GtkTreeModel *tree_model,
2622 GtkTreePath *tree_path,
2629 if (!gtk_tree_model_get_iter (tree_model, &iter, tree_path))
2632 if (tree_path && orig && !gtk_tree_path_compare (tree_path, orig))
2636 if (tree_path && orig && gtk_tree_path_compare (tree_path, orig) > 0)
2638 /* Past it, so return -1 */
2642 else if (gtk_tree_view_row_expanded (tree_view, tree_path) &&
2643 gtk_tree_model_iter_has_child (tree_model, &iter))
2646 gtk_tree_path_append_index (tree_path, 0);
2647 iterate_thru_children (tree_view, tree_model, tree_path,
2648 orig, count, (depth + 1));
2651 else if (gtk_tree_model_iter_next (tree_model, &iter))
2654 tree_path = gtk_tree_model_get_path (tree_model, &iter);
2657 iterate_thru_children (tree_view, tree_model, tree_path,
2658 orig, count, depth);
2659 gtk_tree_path_free (tree_path);
2663 else if (gtk_tree_path_up (tree_path))
2665 GtkTreeIter temp_iter;
2666 gboolean exit_loop = FALSE;
2667 gint new_depth = depth - 1;
2671 /* Make sure that we back up until we find a row
2672 * where gtk_tree_path_next does not return NULL.
2676 if (gtk_tree_path_get_depth (tree_path) == 0)
2677 /* depth is now zero so */
2679 gtk_tree_path_next (tree_path);
2681 /* Verify that the next row is a valid row! */
2682 exit_loop = gtk_tree_model_get_iter (tree_model, &temp_iter, tree_path);
2686 /* Keep going up until we find a row that has a valid next */
2687 if (gtk_tree_path_get_depth(tree_path) > 1)
2690 gtk_tree_path_up (tree_path);
2694 /* If depth is 1 and gtk_tree_model_get_iter returns FALSE,
2695 * then we are at the last row, so just return.
2705 /* This guarantees that we will stop when we hit the end of the
2711 iterate_thru_children (tree_view, tree_model, tree_path,
2712 orig, count, new_depth);
2716 /* If it gets here, then the path wasn't found. Situations
2717 * that would cause this would be if the path passed in is
2718 * invalid or contained within the last row, but not visible
2719 * because the last row is not expanded. If NULL was passed
2720 * in then a row count is desired, so only set count to -1
2721 * if orig is not NULL.
2730 clean_cell_info (GtkTreeViewAccessible *accessible,
2731 GtkTreeViewAccessibleCellInfo *cell_info)
2735 if (cell_info->in_use)
2737 obj = G_OBJECT (cell_info->cell);
2739 _gtk_cell_accessible_add_state (cell_info->cell, ATK_STATE_DEFUNCT, FALSE);
2740 g_object_weak_unref (obj, (GWeakNotify) cell_destroyed, cell_info);
2741 cell_info->in_use = FALSE;
2742 if (!accessible->garbage_collection_pending)
2744 accessible->garbage_collection_pending = TRUE;
2745 g_assert (accessible->idle_garbage_collect_id == 0);
2746 accessible->idle_garbage_collect_id =
2747 gdk_threads_add_idle (idle_garbage_collect_cell_data, accessible);
2753 clean_rows (GtkTreeViewAccessible *accessible)
2755 GtkTreeViewAccessibleCellInfo *cell_info;
2756 GHashTableIter iter;
2758 /* Clean GtkTreeViewAccessibleCellInfo data */
2759 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
2760 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
2762 GtkTreePath *row_path;
2764 row_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2766 /* If the cell has become invalid because the row has been removed,
2767 * then set the cell's state to ATK_STATE_DEFUNCT and schedule
2768 * its removal. If row_path is NULL then the row has
2771 if (row_path == NULL)
2772 clean_cell_info (accessible, cell_info);
2774 gtk_tree_path_free (row_path);
2779 clean_cols (GtkTreeViewAccessible *accessible,
2780 GtkTreeViewColumn *tv_col)
2782 GtkTreeViewAccessibleCellInfo *cell_info;
2783 GHashTableIter iter;
2785 /* Clean GtkTreeViewAccessibleCellInfo data */
2786 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
2787 while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cell_info))
2789 /* If the cell has become invalid because the column tv_col
2790 * has been removed, then set the cell's state to ATK_STATE_DEFUNCT
2791 * and remove the cell from accessible->cell_data.
2793 if (cell_info->cell_col_ref == tv_col)
2794 clean_cell_info (accessible, cell_info);
2799 garbage_collect_cell_data (gpointer data)
2801 GtkTreeViewAccessible *accessible;
2802 GtkTreeViewAccessibleCellInfo *cell_info;
2803 GHashTableIter iter;
2805 accessible = (GtkTreeViewAccessible *)data;
2807 accessible->garbage_collection_pending = FALSE;
2808 if (accessible->idle_garbage_collect_id != 0)
2810 g_source_remove (accessible->idle_garbage_collect_id);
2811 accessible->idle_garbage_collect_id = 0;
2814 /* Must loop through them all */
2815 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
2816 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
2818 if (!cell_info->in_use)
2820 g_hash_table_iter_remove (&iter);
2824 return accessible->garbage_collection_pending;
2828 idle_garbage_collect_cell_data (gpointer data)
2830 GtkTreeViewAccessible *accessible;
2832 accessible = (GtkTreeViewAccessible *)data;
2834 /* this is the idle handler (only one instance allowed), so
2835 * we can safely delete it.
2837 accessible->garbage_collection_pending = FALSE;
2838 accessible->idle_garbage_collect_id = 0;
2840 accessible->garbage_collection_pending = garbage_collect_cell_data (data);
2842 /* N.B.: if for some reason another handler has re-enterantly been
2843 * queued while this handler was being serviced, it has its own gsource,
2844 * therefore this handler should always return FALSE.
2849 /* If tree_path is passed in as NULL, then all cells are acted on.
2850 * Otherwise, just act on those cells that are on a row greater than
2851 * the specified tree_path. If inc_row is passed in as TRUE, then rows
2852 * greater and equal to the specified tree_path are acted on.
2854 * If set_stale is set the ATK_STATE_STALE is set on cells which
2855 * are to be acted on.
2857 * The function set_cell_visibility() is called on all cells to be
2858 * acted on to update the visibility of the cell.
2861 traverse_cells (GtkTreeViewAccessible *accessible,
2862 GtkTreePath *tree_path,
2866 GtkTreeViewAccessibleCellInfo *cell_info;
2868 GHashTableIter iter;
2870 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2874 /* Must loop through them all */
2875 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
2876 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
2878 GtkTreePath *row_path;
2879 gboolean act_on_cell;
2881 if (cell_info->in_use)
2883 row_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2884 g_return_if_fail (row_path != NULL);
2885 if (tree_path == NULL)
2891 comparison = gtk_tree_path_compare (row_path, tree_path);
2892 if ((comparison > 0) ||
2893 (comparison == 0 && inc_row))
2896 act_on_cell = FALSE;
2899 if (!cell_info->in_use)
2900 g_warning ("warning: cell info destroyed during traversal");
2902 if (act_on_cell && cell_info->in_use)
2905 _gtk_cell_accessible_add_state (cell_info->cell, ATK_STATE_STALE, TRUE);
2906 set_cell_visibility (GTK_TREE_VIEW (widget),
2908 cell_info->cell_col_ref,
2911 gtk_tree_path_free (row_path);
2915 g_signal_emit_by_name (accessible, "visible-data-changed");
2918 /* If the tree_path passed in has children, then
2919 * ATK_STATE_EXPANDABLE is set. If the row is expanded
2920 * ATK_STATE_EXPANDED is turned on. If the row is
2921 * collapsed, then ATK_STATE_EXPANDED is removed.
2923 * If the tree_path passed in has no children, then
2924 * ATK_STATE_EXPANDABLE and ATK_STATE_EXPANDED are removed.
2926 * If set_on_ancestor is TRUE, then this function will also
2927 * update all cells that are ancestors of the tree_path.
2930 set_expand_state (GtkTreeView *tree_view,
2931 GtkTreeModel *tree_model,
2932 GtkTreeViewAccessible *accessible,
2933 GtkTreePath *tree_path,
2934 gboolean set_on_ancestor)
2936 GtkTreeViewColumn *expander_tv;
2937 GtkTreeViewAccessibleCellInfo *cell_info;
2938 GtkTreePath *cell_path;
2941 GHashTableIter hash_iter;
2943 g_hash_table_iter_init (&hash_iter, accessible->cell_info_by_index);
2944 while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer *) &cell_info))
2946 if (cell_info->in_use)
2948 cell_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2951 if (cell_path != NULL)
2953 GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (cell_info->cell);
2955 expander_tv = gtk_tree_view_get_expander_column (tree_view);
2957 /* Only set state for the cell that is in the column with the
2960 if (expander_tv == cell_info->cell_col_ref)
2962 if (tree_path && gtk_tree_path_compare (cell_path, tree_path) == 0)
2964 else if (set_on_ancestor &&
2965 gtk_tree_path_get_depth (cell_path) <
2966 gtk_tree_path_get_depth (tree_path) &&
2967 gtk_tree_path_is_ancestor (cell_path, tree_path) == 1)
2968 /* Only set if set_on_ancestor was passed in as TRUE */
2972 /* Set ATK_STATE_EXPANDABLE and ATK_STATE_EXPANDED
2973 * for ancestors and found cells.
2977 /* Must check against cell_path since cell_path
2978 * can be equal to or an ancestor of tree_path.
2980 gtk_tree_model_get_iter (tree_model, &iter, cell_path);
2982 /* Set or unset ATK_STATE_EXPANDABLE as appropriate */
2983 if (gtk_tree_model_iter_has_child (tree_model, &iter))
2985 set_cell_expandable (cell);
2987 if (gtk_tree_view_row_expanded (tree_view, cell_path))
2988 _gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, TRUE);
2990 _gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDED, TRUE);
2994 _gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDED, TRUE);
2995 if (_gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDABLE, TRUE))
2996 /* The state may have been propagated to the container cell */
2997 if (!GTK_IS_CONTAINER_CELL_ACCESSIBLE (cell))
2998 _gtk_cell_accessible_remove_action_by_name (cell,
2999 "expand or contract");
3002 /* We assume that each cell in the cache once and
3003 * a container cell is before its child cells so we are
3004 * finished if set_on_ancestor is not set to TRUE.
3006 if (!set_on_ancestor)
3010 gtk_tree_path_free (cell_path);
3016 add_cell_actions (GtkCellAccessible *cell,
3019 if (GTK_IS_BOOLEAN_CELL_ACCESSIBLE (cell))
3020 _gtk_cell_accessible_add_action (cell,
3021 "toggle", "toggles the cell",
3022 NULL, toggle_cell_toggled);
3024 _gtk_cell_accessible_add_action (cell,
3025 "edit", "creates a widget in which the contents of the cell can be edited",
3027 _gtk_cell_accessible_add_action (cell,
3028 "activate", "activate the cell",
3029 NULL, activate_cell);
3033 toggle_cell_expanded (GtkCellAccessible *cell)
3035 GtkTreeViewAccessibleCellInfo *cell_info;
3036 GtkTreeView *tree_view;
3039 AtkStateSet *stateset;
3041 parent = atk_object_get_parent (ATK_OBJECT (cell));
3042 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
3043 parent = atk_object_get_parent (parent);
3045 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
3046 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
3049 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
3050 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
3054 stateset = atk_object_ref_state_set (ATK_OBJECT (cell));
3055 if (atk_state_set_contains_state (stateset, ATK_STATE_EXPANDED))
3056 gtk_tree_view_collapse_row (tree_view, path);
3058 gtk_tree_view_expand_row (tree_view, path, TRUE);
3059 g_object_unref (stateset);
3060 gtk_tree_path_free (path);
3064 toggle_cell_toggled (GtkCellAccessible *cell)
3066 GtkTreeViewAccessibleCellInfo *cell_info;
3069 GList *renderers, *cur_renderer;
3071 gboolean is_container_cell = FALSE;
3073 parent = atk_object_get_parent (ATK_OBJECT (cell));
3074 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
3076 is_container_cell = TRUE;
3077 parent = atk_object_get_parent (parent);
3080 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
3081 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
3084 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
3088 /* If the cell is in a container, its index is used to find the
3089 * renderer in the list. Otherwise, we assume that the cell is
3090 * represented by the first renderer in the list
3092 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_info->cell_col_ref));
3093 if (is_container_cell)
3094 cur_renderer = g_list_nth (renderers, cell->index);
3096 cur_renderer = renderers;
3100 pathstring = gtk_tree_path_to_string (path);
3101 g_signal_emit_by_name (cur_renderer->data, "toggled", pathstring);
3102 g_free (pathstring);
3105 g_list_free (renderers);
3106 gtk_tree_path_free (path);
3110 edit_cell (GtkCellAccessible *cell)
3112 GtkTreeViewAccessibleCellInfo *cell_info;
3113 GtkTreeView *tree_view;
3117 parent = atk_object_get_parent (ATK_OBJECT (cell));
3118 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
3119 parent = atk_object_get_parent (parent);
3121 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
3122 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
3125 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
3126 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
3129 gtk_tree_view_set_cursor (tree_view, path, cell_info->cell_col_ref, TRUE);
3130 gtk_tree_path_free (path);
3134 activate_cell (GtkCellAccessible *cell)
3136 GtkTreeViewAccessibleCellInfo *cell_info;
3137 GtkTreeView *tree_view;
3141 parent = atk_object_get_parent (ATK_OBJECT (cell));
3142 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
3143 parent = atk_object_get_parent (parent);
3145 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
3146 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
3149 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
3150 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
3153 gtk_tree_view_row_activated (tree_view, path, cell_info->cell_col_ref);
3154 gtk_tree_path_free (path);
3158 cell_destroyed (gpointer data)
3160 GtkTreeViewAccessibleCellInfo *cell_info = data;
3164 if (cell_info->in_use)
3166 cell_info->in_use = FALSE;
3168 if (!cell_info->view->garbage_collection_pending)
3170 cell_info->view->garbage_collection_pending = TRUE;
3171 cell_info->view->idle_garbage_collect_id =
3172 gdk_threads_add_idle (idle_garbage_collect_cell_data, cell_info->view);
3178 cell_info_get_index (GtkTreeView *tree_view,
3179 GtkTreeViewAccessibleCellInfo *info)
3185 path = gtk_tree_row_reference_get_path (info->cell_row_ref);
3189 column_number = get_column_number (tree_view, info->cell_col_ref, FALSE);
3190 index = get_index (tree_view, path, column_number);
3191 gtk_tree_path_free (path);
3197 cell_info_new (GtkTreeViewAccessible *accessible,
3198 GtkTreeModel *tree_model,
3200 GtkTreeViewColumn *tv_col,
3201 GtkCellAccessible *cell)
3203 GtkTreeViewAccessibleCellInfo *cell_info;
3205 cell_info = g_new (GtkTreeViewAccessibleCellInfo, 1);
3206 cell_info->cell_row_ref = gtk_tree_row_reference_new (tree_model, path);
3208 cell_info->cell_col_ref = tv_col;
3209 cell_info->cell = cell;
3210 cell_info->in_use = TRUE; /* if we've created it, assume it's in use */
3211 cell_info->view = accessible;
3212 g_hash_table_insert (accessible->cell_info_by_index, &cell->index, cell_info);
3214 /* Setup weak reference notification */
3215 g_object_weak_ref (G_OBJECT (cell), (GWeakNotify) cell_destroyed, cell_info);
3218 static GtkCellAccessible *
3219 find_cell (GtkTreeViewAccessible *accessible,
3222 GtkTreeViewAccessibleCellInfo *info;
3223 GHashTableIter iter;
3224 GtkTreeView *tree_view;
3226 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
3228 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
3229 while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &info))
3231 if (index == cell_info_get_index (tree_view, info))
3239 refresh_cell_index (GtkCellAccessible *cell)
3241 GtkTreeViewAccessibleCellInfo *info;
3243 GtkTreeView *tree_view;
3244 GtkTreeViewAccessible *accessible;
3247 parent = atk_object_get_parent (ATK_OBJECT (cell));
3248 if (!GTK_IS_TREE_VIEW_ACCESSIBLE (parent))
3251 accessible = GTK_TREE_VIEW_ACCESSIBLE (parent);
3253 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
3255 /* Find this cell in the GtkTreeViewAccessible's cache */
3256 info = find_cell_info (accessible, cell, TRUE);
3260 index = cell_info_get_index (tree_view, info);
3261 cell->index = index;
3262 g_hash_table_insert (accessible->cell_info_by_index, &index, info);
3266 connect_model_signals (GtkTreeView *view,
3267 GtkTreeViewAccessible *accessible)
3271 obj = G_OBJECT (accessible->tree_model);
3272 g_signal_connect_data (obj, "row-changed",
3273 G_CALLBACK (model_row_changed), view, NULL, 0);
3274 g_signal_connect_data (obj, "row-inserted",
3275 G_CALLBACK (model_row_inserted), view, NULL,
3277 g_signal_connect_data (obj, "row-deleted",
3278 G_CALLBACK (model_row_deleted), view, NULL,
3280 g_signal_connect_data (obj, "rows-reordered",
3281 G_CALLBACK (model_rows_reordered), view, NULL,
3286 disconnect_model_signals (GtkTreeViewAccessible *accessible)
3291 obj = G_OBJECT (accessible->tree_model);
3292 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
3293 g_signal_handlers_disconnect_by_func (obj, model_row_changed, widget);
3294 g_signal_handlers_disconnect_by_func (obj, model_row_inserted, widget);
3295 g_signal_handlers_disconnect_by_func (obj, model_row_deleted, widget);
3296 g_signal_handlers_disconnect_by_func (obj, model_rows_reordered, widget);
3300 clear_cached_data (GtkTreeViewAccessible *accessible)
3302 GtkTreeViewAccessibleCellInfo *cell_info;
3303 GHashTableIter iter;
3305 /* Must loop through them all */
3306 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
3307 while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cell_info))
3308 clean_cell_info (accessible, cell_info);
3310 /* FIXME: seems pretty inefficient to loop again here */
3311 garbage_collect_cell_data (accessible);
3314 /* Returns the column number of the specified GtkTreeViewColumn
3316 * If visible is set, the value returned will be the visible column number,
3317 * i.e. suitable for use in AtkTable function. If visible is not set, the
3318 * value returned is the actual column number, which is suitable for use in
3319 * getting an index value.
3322 get_column_number (GtkTreeView *tree_view,
3323 GtkTreeViewColumn *column,
3326 GtkTreeViewColumn *tv_column;
3330 GtkTreeViewAccessible *accessible;
3332 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
3333 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
3336 for (i = 0; i < accessible->col_data->len; i++)
3338 tv_column = g_array_index (accessible->col_data, GtkTreeViewColumn *, i);
3339 if (tv_column == column)
3341 if (!visible || gtk_tree_view_column_get_visible (tv_column))
3344 if (i == accessible->col_data->len)
3351 get_index (GtkTreeView *tree_view,
3356 GtkTreeViewAccessible *accessible;
3359 gint *indices = NULL;
3361 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
3362 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
3366 depth = gtk_tree_path_get_depth (path);
3367 indices = gtk_tree_path_get_indices (path);
3372 GtkTreePath *copy_path;
3373 GtkTreeModel *model;
3375 model = gtk_tree_view_get_model (tree_view);
3376 copy_path = gtk_tree_path_copy (path);
3377 gtk_tree_path_up (copy_path);
3378 count_rows (model, NULL, copy_path, &index, 0, depth);
3379 gtk_tree_path_free (copy_path);
3383 index += indices[depth - 1];
3384 index *= accessible->n_cols;
3385 index += actual_column;
3389 /* The function count_rows counts the number of rows starting at iter
3390 * and ending at end_path. The value of level is the depth of iter and
3391 * the value of depth is the depth of end_path. Rows at depth before
3392 * end_path are counted. This functions counts rows which are not visible
3393 * because an ancestor is collapsed.
3396 count_rows (GtkTreeModel *model,
3398 GtkTreePath *end_path,
3403 GtkTreeIter child_iter;
3409 *count += gtk_tree_model_iter_n_children (model, iter);
3411 if (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY)
3417 if (gtk_tree_model_iter_children (model, &child_iter, iter))
3419 gboolean ret_val = TRUE;
3423 if (level == depth - 1)
3425 GtkTreePath *iter_path;
3426 gboolean finished = FALSE;
3428 iter_path = gtk_tree_model_get_path (model, &child_iter);
3429 if (end_path && gtk_tree_path_compare (iter_path, end_path) >= 0)
3431 gtk_tree_path_free (iter_path);
3435 if (gtk_tree_model_iter_has_child (model, &child_iter))
3436 count_rows (model, &child_iter, end_path, count, level, depth);
3437 ret_val = gtk_tree_model_iter_next (model, &child_iter);
3442 /* Find the next node, which has children, at the specified depth below
3443 * the specified iter. The level is the depth of the current iter.
3444 * The position of the node is returned in path and the return value
3445 * of TRUE means that a node was found.
3449 get_next_node_with_child_at_depth (GtkTreeModel *model,
3455 GtkTreeIter child_iter;
3459 if (gtk_tree_model_iter_children (model, &child_iter, iter))
3465 while (!gtk_tree_model_iter_has_child (model, &child_iter))
3467 if (!gtk_tree_model_iter_next (model, &child_iter))
3473 /* We have found what we were looking for */
3474 *path = gtk_tree_model_get_path (model, &child_iter);
3478 if (get_next_node_with_child_at_depth (model, &child_iter, path,
3482 if (!gtk_tree_model_iter_next (model, &child_iter))
3489 /* Find the next node, which has children, at the same depth
3490 * as the specified GtkTreePath.
3493 get_next_node_with_child (GtkTreeModel *model,
3495 GtkTreePath **return_path)
3500 gtk_tree_model_get_iter (model, &iter, path);
3502 while (gtk_tree_model_iter_next (model, &iter))
3504 if (gtk_tree_model_iter_has_child (model, &iter))
3506 *return_path = gtk_tree_model_get_path (model, &iter);
3510 depth = gtk_tree_path_get_depth (path);
3511 while (gtk_tree_path_up (path))
3513 if (gtk_tree_path_get_depth (path) == 0)
3516 gtk_tree_model_get_iter (model, &iter, path);
3517 while (gtk_tree_model_iter_next (model, &iter))
3518 if (get_next_node_with_child_at_depth (model, &iter, return_path,
3519 gtk_tree_path_get_depth (path), depth))
3522 *return_path = NULL;
3527 get_tree_path_from_row_index (GtkTreeModel *model,
3529 GtkTreePath **tree_path)
3535 count = gtk_tree_model_iter_n_children (model, NULL);
3536 if (count > row_index)
3538 if (gtk_tree_model_iter_nth_child (model, &iter, NULL, row_index))
3540 *tree_path = gtk_tree_model_get_path (model, &iter);
3554 if (get_next_node_with_child_at_depth (model, NULL, tree_path, 0, depth))
3556 GtkTreePath *next_path;
3560 gtk_tree_model_get_iter (model, &iter, *tree_path);
3561 count = gtk_tree_model_iter_n_children (model, &iter);
3562 if (count > row_index)
3564 gtk_tree_path_append_index (*tree_path, row_index);
3570 if (!get_next_node_with_child (model, *tree_path, &next_path))
3573 gtk_tree_path_free (*tree_path);
3574 *tree_path = next_path;
3579 g_warning ("Index value is too large\n");
3580 gtk_tree_path_free (*tree_path);
3588 get_path_column_from_index (GtkTreeView *tree_view,
3591 GtkTreeViewColumn **column)
3593 GtkTreeModel *tree_model;
3595 GtkTreeViewAccessible *accessible;
3597 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
3598 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
3600 tree_model = gtk_tree_view_get_model (tree_view);
3601 if (accessible->n_cols == 0)
3603 /* First row is the column headers */
3604 index -= accessible->n_cols;
3613 row_index = index / accessible->n_cols;
3614 retval = get_tree_path_from_row_index (tree_model, row_index, path);
3623 *column = gtk_tree_view_get_column (tree_view, index % accessible->n_cols);
3624 if (*column == NULL)
3627 gtk_tree_path_free (*path);
3635 set_cell_expandable (GtkCellAccessible *cell)
3637 if (_gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDABLE, FALSE))
3638 _gtk_cell_accessible_add_action (cell,
3639 "expand or contract",
3640 "expands or contracts the row in the tree view containing this cell",
3641 NULL, toggle_cell_expanded);
3644 static GtkTreeViewAccessibleCellInfo *
3645 find_cell_info (GtkTreeViewAccessible *accessible,
3646 GtkCellAccessible *cell,
3649 GtkTreeViewAccessibleCellInfo *cell_info;
3650 GHashTableIter iter;
3652 /* Clean GtkTreeViewAccessibleCellInfo data */
3653 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
3654 while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cell_info))
3656 if (cell_info->cell == cell && (!live_only || cell_info->in_use))
3663 get_header_from_column (GtkTreeViewColumn *tv_col)
3666 GtkWidget *header_widget;
3671 header_widget = gtk_tree_view_column_get_button (tv_col);
3674 rc = gtk_widget_get_accessible (header_widget);