1 /* GAIL - The GNOME Accessibility Implementation Library
2 * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 #ifdef GDK_WINDOWING_X11
24 #include <gdk/x11/gdkx.h>
26 #include "gtktreeviewaccessible.h"
27 #include "gtkrenderercellaccessible.h"
28 #include "gtkbooleancellaccessible.h"
29 #include "gtkimagecellaccessible.h"
30 #include "gtkcontainercellaccessible.h"
31 #include "gtktextcellaccessible.h"
32 #include "gtkcellaccessibleparent.h"
34 typedef struct _GtkTreeViewAccessibleCellInfo GtkTreeViewAccessibleCellInfo;
35 struct _GtkTreeViewAccessibleCellInfo
37 GtkCellAccessible *cell;
38 GtkTreeRowReference *cell_row_ref;
39 GtkTreeViewColumn *cell_col_ref;
40 GtkTreeViewAccessible *view;
46 static gboolean row_expanded_cb (GtkTreeView *tree_view,
49 static gboolean row_collapsed_cb (GtkTreeView *tree_view,
52 static void size_allocate_cb (GtkWidget *widget,
53 GtkAllocation *allocation);
54 static void selection_changed_cb (GtkTreeSelection *selection,
57 static void columns_changed (GtkTreeView *tree_view);
58 static void cursor_changed (GtkTreeView *tree_view);
59 static gboolean focus_in (GtkWidget *widget);
60 static gboolean focus_out (GtkWidget *widget);
62 static void column_visibility_changed
66 static void destroy_count_func (GtkTreeView *tree_view,
73 static void set_iter_nth_row (GtkTreeView *tree_view,
76 static gint get_row_from_tree_path (GtkTreeView *tree_view,
78 static GtkTreeViewColumn* get_column (GtkTreeView *tree_view,
80 static gint get_actual_column_number (GtkTreeView *tree_view,
82 static gint get_visible_column_number (GtkTreeView *tree_view,
84 static void iterate_thru_children (GtkTreeView *tree_view,
85 GtkTreeModel *tree_model,
86 GtkTreePath *tree_path,
90 static void clean_rows (GtkTreeViewAccessible *tree_view);
91 static void clean_cols (GtkTreeViewAccessible *tree_view,
92 GtkTreeViewColumn *tv_col);
93 static void traverse_cells (GtkTreeViewAccessible *tree_view,
94 GtkTreePath *tree_path,
97 static gboolean update_cell_value (GtkRendererCellAccessible *renderer_cell,
98 GtkTreeViewAccessible *accessible,
99 gboolean emit_change_signal);
100 static void set_cell_visibility (GtkTreeView *tree_view,
101 GtkCellAccessible *cell,
102 GtkTreeViewColumn *tv_col,
103 GtkTreePath *tree_path,
104 gboolean emit_signal);
105 static gboolean is_cell_showing (GtkTreeView *tree_view,
106 GdkRectangle *cell_rect);
107 static void set_expand_state (GtkTreeView *tree_view,
108 GtkTreeModel *tree_model,
109 GtkTreeViewAccessible *accessible,
110 GtkTreePath *tree_path,
111 gboolean set_on_ancestor);
112 static void set_cell_expandable (GtkCellAccessible *cell);
113 static void add_cell_actions (GtkCellAccessible *cell,
116 static void toggle_cell_toggled (GtkCellAccessible *cell);
117 static void edit_cell (GtkCellAccessible *cell);
118 static void activate_cell (GtkCellAccessible *cell);
119 static void cell_destroyed (gpointer data);
120 static void cell_info_new (GtkTreeViewAccessible *accessible,
121 GtkTreeModel *tree_model,
123 GtkTreeViewColumn *tv_col,
124 GtkCellAccessible *cell);
125 static GtkCellAccessible *find_cell (GtkTreeViewAccessible *accessible,
127 static void refresh_cell_index (GtkCellAccessible *cell);
128 static void connect_model_signals (GtkTreeView *view,
129 GtkTreeViewAccessible *accessible);
130 static void disconnect_model_signals (GtkTreeViewAccessible *accessible);
131 static void clear_cached_data (GtkTreeViewAccessible *view);
132 static gint get_column_number (GtkTreeView *tree_view,
133 GtkTreeViewColumn *column,
135 static gint get_focus_index (GtkTreeView *tree_view);
136 static gint get_index (GtkTreeView *tree_view,
139 static void count_rows (GtkTreeModel *model,
141 GtkTreePath *end_path,
146 static gboolean get_path_column_from_index (GtkTreeView *tree_view,
149 GtkTreeViewColumn **column);
151 static GtkTreeViewAccessibleCellInfo* find_cell_info (GtkTreeViewAccessible *view,
152 GtkCellAccessible *cell,
154 static AtkObject * get_header_from_column (GtkTreeViewColumn *tv_col);
155 static gboolean idle_garbage_collect_cell_data (gpointer data);
158 static void atk_table_interface_init (AtkTableIface *iface);
159 static void atk_selection_interface_init (AtkSelectionIface *iface);
160 static void atk_component_interface_init (AtkComponentIface *iface);
161 static void gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface);
163 G_DEFINE_TYPE_WITH_CODE (GtkTreeViewAccessible, _gtk_tree_view_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
164 G_IMPLEMENT_INTERFACE (ATK_TYPE_TABLE, atk_table_interface_init)
165 G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init)
166 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init)
167 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_ACCESSIBLE_PARENT, gtk_cell_accessible_parent_interface_init))
171 adjustment_changed (GtkAdjustment *adjustment,
174 GtkTreeViewAccessible *accessible;
176 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
177 traverse_cells (accessible, NULL, FALSE, FALSE);
181 hadjustment_set_cb (GObject *widget,
185 GtkTreeViewAccessible *accessible = data;
188 g_object_get (widget, "hadjustment", &adj, NULL);
189 accessible->old_hadj = adj;
190 g_object_add_weak_pointer (G_OBJECT (accessible->old_hadj), (gpointer *)&accessible->old_hadj);
191 g_signal_connect (adj, "value-changed", G_CALLBACK (adjustment_changed), widget);
195 vadjustment_set_cb (GObject *widget,
199 GtkTreeViewAccessible *accessible = data;
202 g_object_get (widget, "vadjustment", &adj, NULL);
203 accessible->old_vadj = adj;
204 g_object_add_weak_pointer (G_OBJECT (accessible->old_vadj), (gpointer *)&accessible->old_vadj);
205 g_signal_connect (adj, "value-changed",
206 G_CALLBACK (adjustment_changed), widget);
210 cell_info_free (GtkTreeViewAccessibleCellInfo *cell_info)
212 /* g_object_unref (cell_info->cell); */
213 if (cell_info->cell_row_ref)
214 gtk_tree_row_reference_free (cell_info->cell_row_ref);
219 gtk_tree_view_accessible_initialize (AtkObject *obj,
222 GtkTreeViewAccessible *accessible;
223 GtkTreeView *tree_view;
224 GtkTreeModel *tree_model;
225 GList *tv_cols, *tmp_list;
227 GtkTreeSelection *selection;
229 ATK_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->initialize (obj, data);
231 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
232 accessible->col_data = NULL;
233 accessible->focus_cell = NULL;
234 accessible->old_hadj = NULL;
235 accessible->old_vadj = NULL;
236 accessible->idle_expand_id = 0;
237 accessible->idle_expand_path = NULL;
238 accessible->n_children_deleted = 0;
240 accessible->cell_info_by_index = g_hash_table_new_full (g_int_hash,
241 g_int_equal, NULL, cell_info_free);
243 widget = GTK_WIDGET (data);
244 tree_view = GTK_TREE_VIEW (widget);
245 tree_model = gtk_tree_view_get_model (tree_view);
246 selection = gtk_tree_view_get_selection (tree_view);
248 g_signal_connect_after (widget, "row-collapsed",
249 G_CALLBACK (row_collapsed_cb), NULL);
250 g_signal_connect (widget, "row-expanded",
251 G_CALLBACK (row_expanded_cb), NULL);
252 g_signal_connect (widget, "size-allocate",
253 G_CALLBACK (size_allocate_cb), NULL);
254 g_signal_connect (selection, "changed",
255 G_CALLBACK (selection_changed_cb), obj);
257 g_signal_connect (tree_view, "columns-changed",
258 G_CALLBACK (columns_changed), NULL);
259 g_signal_connect (tree_view, "cursor-changed",
260 G_CALLBACK (cursor_changed), NULL);
261 g_signal_connect (tree_view, "focus-in-event",
262 G_CALLBACK (focus_in), NULL);
263 g_signal_connect (tree_view, "focus-out-event",
264 G_CALLBACK (focus_out), NULL);
266 accessible->tree_model = tree_model;
267 accessible->n_rows = 0;
268 accessible->n_cols = 0;
271 g_object_add_weak_pointer (G_OBJECT (accessible->tree_model), (gpointer *)&accessible->tree_model);
272 count_rows (tree_model, NULL, NULL, &accessible->n_rows, 0, G_MAXINT);
273 connect_model_signals (tree_view, accessible);
275 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
276 obj->role = ATK_ROLE_TABLE;
278 obj->role = ATK_ROLE_TREE_TABLE;
281 hadjustment_set_cb (G_OBJECT (widget), NULL, accessible);
282 vadjustment_set_cb (G_OBJECT (widget), NULL, accessible);
283 g_signal_connect (widget, "notify::hadjustment",
284 G_CALLBACK (hadjustment_set_cb), accessible);
285 g_signal_connect (widget, "notify::vadjustment",
286 G_CALLBACK (vadjustment_set_cb), accessible);
288 accessible->col_data = g_array_sized_new (FALSE, TRUE,
289 sizeof (GtkTreeViewColumn *), 0);
291 tv_cols = gtk_tree_view_get_columns (tree_view);
292 for (tmp_list = tv_cols; tmp_list; tmp_list = tmp_list->next)
294 accessible->n_cols++;
295 g_signal_connect (tmp_list->data, "notify::visible",
296 G_CALLBACK (column_visibility_changed), tree_view);
297 g_array_append_val (accessible->col_data, tmp_list->data);
299 g_list_free (tv_cols);
301 gtk_tree_view_set_destroy_count_func (tree_view,
307 gtk_tree_view_accessible_finalize (GObject *object)
309 GtkTreeViewAccessible *accessible = GTK_TREE_VIEW_ACCESSIBLE (object);
311 clear_cached_data (accessible);
313 /* remove any idle handlers still pending */
314 if (accessible->idle_garbage_collect_id)
315 g_source_remove (accessible->idle_garbage_collect_id);
316 if (accessible->idle_cursor_changed_id)
317 g_source_remove (accessible->idle_cursor_changed_id);
318 if (accessible->idle_expand_id)
319 g_source_remove (accessible->idle_expand_id);
321 if (accessible->tree_model)
322 disconnect_model_signals (accessible);
324 if (accessible->cell_info_by_index)
325 g_hash_table_destroy (accessible->cell_info_by_index);
327 if (accessible->col_data)
329 GArray *array = accessible->col_data;
331 /* No need to free the contents of the array since it
332 * just contains pointers to the GtkTreeViewColumn
333 * objects that are in the GtkTreeView.
335 g_array_free (array, TRUE);
338 G_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->finalize (object);
342 gtk_tree_view_accessible_notify_gtk (GObject *obj,
346 GtkTreeView *tree_view;
347 GtkTreeViewAccessible *accessible;
350 widget = GTK_WIDGET (obj);
351 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
352 tree_view = GTK_TREE_VIEW (widget);
354 if (g_strcmp0 (pspec->name, "model") == 0)
356 GtkTreeModel *tree_model;
359 tree_model = gtk_tree_view_get_model (tree_view);
360 if (accessible->tree_model)
361 disconnect_model_signals (accessible);
362 clear_cached_data (accessible);
363 accessible->tree_model = tree_model;
364 accessible->n_rows = 0;
368 g_object_add_weak_pointer (G_OBJECT (accessible->tree_model), (gpointer *)&accessible->tree_model);
369 count_rows (tree_model, NULL, NULL, &accessible->n_rows, 0, G_MAXINT);
370 connect_model_signals (tree_view, accessible);
372 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
373 role = ATK_ROLE_TABLE;
375 role = ATK_ROLE_TREE_TABLE;
379 role = ATK_ROLE_UNKNOWN;
381 atk_object_set_role (ATK_OBJECT (accessible), role);
382 g_object_freeze_notify (G_OBJECT (accessible));
383 g_signal_emit_by_name (accessible, "model-changed");
384 g_signal_emit_by_name (accessible, "visible-data-changed");
385 g_object_thaw_notify (G_OBJECT (accessible));
387 else if (g_strcmp0 (pspec->name, "hadjustment") == 0)
389 g_object_get (tree_view, "hadjustment", &adj, NULL);
390 g_signal_handlers_disconnect_by_func (accessible->old_hadj,
391 (gpointer) adjustment_changed,
393 accessible->old_hadj = adj;
394 g_object_add_weak_pointer (G_OBJECT (accessible->old_hadj), (gpointer *)&accessible->old_hadj);
395 g_signal_connect (adj, "value-changed", G_CALLBACK (adjustment_changed), tree_view);
397 else if (g_strcmp0 (pspec->name, "vadjustment") == 0)
399 g_object_get (tree_view, "vadjustment", &adj, NULL);
400 g_signal_handlers_disconnect_by_func (accessible->old_vadj,
401 (gpointer) adjustment_changed,
403 accessible->old_vadj = adj;
404 g_object_add_weak_pointer (G_OBJECT (accessible->old_hadj), (gpointer *)&accessible->old_vadj);
405 g_signal_connect (adj, "value-changed", G_CALLBACK (adjustment_changed), tree_view);
408 GTK_WIDGET_ACCESSIBLE_CLASS (_gtk_tree_view_accessible_parent_class)->notify_gtk (obj, pspec);
412 gtk_tree_view_accessible_destroyed (GtkWidget *widget,
413 GtkAccessible *gtk_accessible)
416 GtkTreeViewAccessible *accessible;
418 if (!GTK_IS_TREE_VIEW (widget))
421 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_accessible);
422 adj = accessible->old_hadj;
424 g_signal_handlers_disconnect_by_func (adj,
425 (gpointer) adjustment_changed,
427 adj = accessible->old_vadj;
429 g_signal_handlers_disconnect_by_func (adj,
430 (gpointer) adjustment_changed,
432 if (accessible->tree_model)
434 disconnect_model_signals (accessible);
435 accessible->tree_model = NULL;
437 if (accessible->focus_cell)
439 g_object_unref (accessible->focus_cell);
440 accessible->focus_cell = NULL;
442 if (accessible->idle_expand_id)
444 g_source_remove (accessible->idle_expand_id);
445 accessible->idle_expand_id = 0;
450 gtk_tree_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
454 widget = gtk_accessible_get_widget (accessible);
456 g_signal_connect_after (widget, "destroy",
457 G_CALLBACK (gtk_tree_view_accessible_destroyed), accessible);
459 GTK_ACCESSIBLE_CLASS (_gtk_tree_view_accessible_parent_class)->connect_widget_destroyed (accessible);
463 gtk_tree_view_accessible_get_n_children (AtkObject *obj)
466 GtkTreeViewAccessible *accessible;
468 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
472 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
473 return (accessible->n_rows + 1) * accessible->n_cols;
477 gtk_tree_view_accessible_ref_child (AtkObject *obj,
481 GtkTreeViewAccessible *accessible;
482 GtkCellAccessible *cell;
483 GtkTreeView *tree_view;
484 GtkTreeModel *tree_model;
485 GtkCellRenderer *renderer;
487 GtkTreeViewColumn *tv_col;
488 GtkTreeSelection *selection;
492 GtkTreeViewColumn *expander_tv;
493 GList *renderer_list;
495 GtkContainerCellAccessible *container = NULL;
496 GtkRendererCellAccessible *renderer_cell;
497 gboolean is_expander, is_expanded, retval;
498 gboolean editable = FALSE;
501 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
505 if (i >= gtk_tree_view_accessible_get_n_children (obj))
508 accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
509 tree_view = GTK_TREE_VIEW (widget);
510 if (i < accessible->n_cols)
512 tv_col = gtk_tree_view_get_column (tree_view, i);
513 child = get_header_from_column (tv_col);
515 g_object_ref (child);
519 /* Check whether the child is cached */
520 cell = find_cell (accessible, i);
524 return ATK_OBJECT (cell);
527 if (accessible->focus_cell == NULL)
528 focus_index = get_focus_index (tree_view);
532 /* Find the TreePath and GtkTreeViewColumn for the index */
533 if (!get_path_column_from_index (tree_view, i, &path, &tv_col))
536 tree_model = gtk_tree_view_get_model (tree_view);
537 retval = gtk_tree_model_get_iter (tree_model, &iter, path);
541 expander_tv = gtk_tree_view_get_expander_column (tree_view);
544 if (gtk_tree_model_iter_has_child (tree_model, &iter))
546 if (expander_tv == tv_col)
549 is_expanded = gtk_tree_view_row_expanded (tree_view, path);
552 gtk_tree_view_column_cell_set_cell_data (tv_col, tree_model, &iter,
553 is_expander, is_expanded);
555 renderer_list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
557 /* If there are more than one renderer in the list,
560 if (renderer_list && renderer_list->next)
562 GtkCellAccessible *container_cell;
564 container = _gtk_container_cell_accessible_new ();
566 container_cell = GTK_CELL_ACCESSIBLE (container);
567 _gtk_cell_accessible_initialise (container_cell, widget, ATK_OBJECT (accessible), i);
569 /* The GtkTreeViewAccessibleCellInfo structure for the container will
570 * be before the ones for the cells so that the first one we find for
571 * a position will be for the container
573 cell_info_new (accessible, tree_model, path, tv_col, container_cell);
574 container_cell->refresh_index = refresh_cell_index;
575 parent = ATK_OBJECT (container);
578 parent = ATK_OBJECT (accessible);
582 /* Now we make a fake cell_renderer if there is no cell
585 if (renderer_list == NULL)
587 GtkCellRenderer *fake_renderer;
589 fake_renderer = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, NULL);
590 child = _gtk_text_cell_accessible_new ();
591 cell = GTK_CELL_ACCESSIBLE (child);
592 renderer_cell = GTK_RENDERER_CELL_ACCESSIBLE (child);
593 renderer_cell->renderer = fake_renderer;
595 /* Create the GtkTreeViewAccessibleCellInfo structure for this cell */
596 cell_info_new (accessible, tree_model, path, tv_col, cell);
598 _gtk_cell_accessible_initialise (cell, widget, parent, i);
600 cell->refresh_index = refresh_cell_index;
602 /* Set state if it is expandable */
605 set_cell_expandable (cell);
607 _gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, FALSE);
612 for (l = renderer_list; l; l = l->next)
614 renderer = GTK_CELL_RENDERER (l->data);
616 if (GTK_IS_CELL_RENDERER_TEXT (renderer))
618 g_object_get (G_OBJECT (renderer), "editable", &editable, NULL);
619 child = _gtk_text_cell_accessible_new ();
621 else if (GTK_IS_CELL_RENDERER_TOGGLE (renderer))
622 child = _gtk_boolean_cell_accessible_new ();
623 else if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
624 child = _gtk_image_cell_accessible_new ();
626 child = _gtk_renderer_cell_accessible_new ();
628 cell = GTK_CELL_ACCESSIBLE (child);
629 renderer_cell = GTK_RENDERER_CELL_ACCESSIBLE (child);
631 /* Create the GtkTreeViewAccessibleCellInfo for this cell */
632 cell_info_new (accessible, tree_model, path, tv_col, cell);
634 _gtk_cell_accessible_initialise (cell, widget, parent, i);
637 _gtk_container_cell_accessible_add_child (container, cell);
639 cell->refresh_index = refresh_cell_index;
641 update_cell_value (renderer_cell, accessible, FALSE);
643 /* Add the actions appropriate for this cell */
644 add_cell_actions (cell, editable);
646 /* Set state if it is expandable */
649 set_cell_expandable (cell);
651 _gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, FALSE);
654 /* If the column is visible, sets the cell's state */
655 if (gtk_tree_view_column_get_visible (tv_col))
656 set_cell_visibility (tree_view, cell, tv_col, path, FALSE);
658 /* If the row is selected, all cells on the row are selected */
659 selection = gtk_tree_view_get_selection (tree_view);
661 if (gtk_tree_selection_path_is_selected (selection, path))
662 _gtk_cell_accessible_add_state (cell, ATK_STATE_SELECTED, FALSE);
664 _gtk_cell_accessible_add_state (cell, ATK_STATE_FOCUSABLE, FALSE);
665 if (focus_index == i)
667 accessible->focus_cell = g_object_ref (cell);
668 _gtk_cell_accessible_add_state (cell, ATK_STATE_FOCUSED, FALSE);
669 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
672 g_list_free (renderer_list);
674 child = ATK_OBJECT (container);
677 if (expander_tv == tv_col)
679 AtkRelationSet *relation_set;
680 AtkObject *accessible_array[1];
681 AtkRelation* relation;
682 AtkObject *parent_node;
684 relation_set = atk_object_ref_relation_set (ATK_OBJECT (child));
686 gtk_tree_path_up (path);
687 if (gtk_tree_path_get_depth (path) == 0)
693 parent_index = get_index (tree_view, path, i % accessible->n_cols);
694 parent_node = atk_object_ref_accessible_child (obj, parent_index);
696 accessible_array[0] = parent_node;
697 relation = atk_relation_new (accessible_array, 1,
698 ATK_RELATION_NODE_CHILD_OF);
699 atk_relation_set_add (relation_set, relation);
700 atk_object_add_relationship (parent_node, ATK_RELATION_NODE_PARENT_OF, child);
701 g_object_unref (relation);
702 g_object_unref (relation_set);
704 gtk_tree_path_free (path);
706 /* We do not increase the reference count here; when g_object_unref()
707 * is called for the cell then cell_destroyed() is called and this
708 * removes the cell from the cache.
714 gtk_tree_view_accessible_ref_state_set (AtkObject *obj)
716 AtkStateSet *state_set;
719 state_set = ATK_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->ref_state_set (obj);
720 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
723 atk_state_set_add_state (state_set, ATK_STATE_MANAGES_DESCENDANTS);
729 _gtk_tree_view_accessible_class_init (GtkTreeViewAccessibleClass *klass)
731 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
732 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
733 GtkAccessibleClass *accessible_class = (GtkAccessibleClass*)klass;
734 GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
735 GtkContainerAccessibleClass *container_class = (GtkContainerAccessibleClass*)klass;
737 class->get_n_children = gtk_tree_view_accessible_get_n_children;
738 class->ref_child = gtk_tree_view_accessible_ref_child;
739 class->ref_state_set = gtk_tree_view_accessible_ref_state_set;
740 class->initialize = gtk_tree_view_accessible_initialize;
742 widget_class->notify_gtk = gtk_tree_view_accessible_notify_gtk;
744 accessible_class->connect_widget_destroyed = gtk_tree_view_accessible_connect_widget_destroyed;
746 /* The children of a GtkTreeView are the buttons at the top of the columns
747 * we do not represent these as children so we do not want to report
748 * children added or deleted when these changed.
750 container_class->add_gtk = NULL;
751 container_class->remove_gtk = NULL;
753 gobject_class->finalize = gtk_tree_view_accessible_finalize;
757 _gtk_tree_view_accessible_init (GtkTreeViewAccessible *view)
762 get_focus_index (GtkTreeView *tree_view)
764 GtkTreePath *focus_path;
765 GtkTreeViewColumn *focus_column;
768 gtk_tree_view_get_cursor (tree_view, &focus_path, &focus_column);
769 if (focus_path && focus_column)
770 index = get_index (tree_view, focus_path,
771 get_column_number (tree_view, focus_column, FALSE));
776 gtk_tree_path_free (focus_path);
781 /* This function returns a reference to the accessible object
782 * for the cell in the treeview which has focus, if any
785 gtk_tree_view_accessible_ref_focus_cell (GtkTreeView *tree_view)
787 AtkObject *focus_cell = NULL;
791 focus_index = get_focus_index (tree_view);
792 if (focus_index >= 0)
794 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
795 focus_cell = atk_object_ref_accessible_child (atk_obj, focus_index);
804 gtk_tree_view_accessible_ref_accessible_at_point (AtkComponent *component,
807 AtkCoordType coord_type)
810 GtkTreeView *tree_view;
812 GtkTreeViewColumn *tv_column;
817 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
821 tree_view = GTK_TREE_VIEW (widget);
823 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
824 gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, x, y, &bx, &by);
825 ret_val = gtk_tree_view_get_path_at_pos (tree_view,
826 bx - x_pos, by - y_pos,
827 &path, &tv_column, NULL, NULL);
832 column = get_column_number (tree_view, tv_column, FALSE);
833 index = get_index (tree_view, path, column);
834 gtk_tree_path_free (path);
836 return gtk_tree_view_accessible_ref_child (ATK_OBJECT (component), index);
840 g_warning ("gtk_tree_view_accessible_ref_accessible_at_point: gtk_tree_view_get_path_at_pos () failed\n");
846 atk_component_interface_init (AtkComponentIface *iface)
848 iface->ref_accessible_at_point = gtk_tree_view_accessible_ref_accessible_at_point;
854 gtk_tree_view_accessible_get_index_at (AtkTable *table,
859 GtkTreeView *tree_view;
866 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
870 n_cols = atk_table_get_n_columns (table);
871 n_rows = atk_table_get_n_rows (table);
873 if (row >= n_rows || column >= n_cols)
876 tree_view = GTK_TREE_VIEW (widget);
877 actual_column = get_actual_column_number (tree_view, column);
879 set_iter_nth_row (tree_view, &iter, row);
880 path = gtk_tree_model_get_path (gtk_tree_view_get_model (tree_view), &iter);
882 index = get_index (tree_view, path, actual_column);
883 gtk_tree_path_free (path);
889 gtk_tree_view_accessible_get_column_at_index (AtkTable *table,
893 GtkTreeView *tree_view;
896 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
900 tree_view = GTK_TREE_VIEW (widget);
901 n_columns = GTK_TREE_VIEW_ACCESSIBLE (table)->n_cols;
906 index = index % n_columns;
908 return get_visible_column_number (tree_view, index);
912 gtk_tree_view_accessible_get_row_at_index (AtkTable *table,
916 GtkTreeView *tree_view;
919 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
923 tree_view = GTK_TREE_VIEW (widget);
924 if (get_path_column_from_index (tree_view, index, &path, NULL))
926 gint row = get_row_from_tree_path (tree_view, path);
927 gtk_tree_path_free (path);
935 gtk_tree_view_accessible_table_ref_at (AtkTable *table,
941 index = gtk_tree_view_accessible_get_index_at (table, row, column);
945 return gtk_tree_view_accessible_ref_child (ATK_OBJECT (table), index);
949 gtk_tree_view_accessible_get_n_rows (AtkTable *table)
952 GtkTreeView *tree_view;
953 GtkTreeModel *tree_model;
956 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
960 tree_view = GTK_TREE_VIEW (widget);
961 tree_model = gtk_tree_view_get_model (tree_view);
965 else if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
966 /* No collapsed rows in a list store */
967 n_rows = GTK_TREE_VIEW_ACCESSIBLE (table)->n_rows;
970 GtkTreePath *root_tree;
973 root_tree = gtk_tree_path_new_first ();
974 iterate_thru_children (tree_view, tree_model,
975 root_tree, NULL, &n_rows, 0);
976 gtk_tree_path_free (root_tree);
983 gtk_tree_view_accessible_get_n_columns (AtkTable *table)
986 GtkTreeView *tree_view;
987 GtkTreeViewColumn *tv_col;
991 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
995 tree_view = GTK_TREE_VIEW (widget);
996 tv_col = gtk_tree_view_get_column (tree_view, i);
998 while (tv_col != NULL)
1000 if (gtk_tree_view_column_get_visible (tv_col))
1004 tv_col = gtk_tree_view_get_column (tree_view, i);
1011 gtk_tree_view_accessible_is_row_selected (AtkTable *table,
1015 GtkTreeView *tree_view;
1016 GtkTreeSelection *selection;
1019 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1026 tree_view = GTK_TREE_VIEW (widget);
1027 selection = gtk_tree_view_get_selection (tree_view);
1029 set_iter_nth_row (tree_view, &iter, row);
1030 return gtk_tree_selection_iter_is_selected (selection, &iter);
1034 gtk_tree_view_accessible_is_selected (AtkTable *table,
1038 return gtk_tree_view_accessible_is_row_selected (table, row);
1042 get_selected_rows (GtkTreeModel *model,
1047 GPtrArray *array = (GPtrArray *)data;
1049 g_ptr_array_add (array, gtk_tree_path_copy (path));
1053 gtk_tree_view_accessible_get_selected_rows (AtkTable *table,
1054 gint **rows_selected)
1057 GtkTreeView *tree_view;
1058 GtkTreeModel *tree_model;
1060 GtkTreeSelection *selection;
1061 GtkTreePath *tree_path;
1064 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1068 tree_view = GTK_TREE_VIEW (widget);
1069 selection = gtk_tree_view_get_selection (tree_view);
1071 switch (gtk_tree_selection_get_mode (selection))
1073 case GTK_SELECTION_SINGLE:
1074 case GTK_SELECTION_BROWSE:
1075 if (gtk_tree_selection_get_selected (selection, &tree_model, &iter))
1081 *rows_selected = g_new (gint, 1);
1082 tree_path = gtk_tree_model_get_path (tree_model, &iter);
1083 row = get_row_from_tree_path (tree_view, tree_path);
1084 gtk_tree_path_free (tree_path);
1086 /* shouldn't ever happen */
1087 g_return_val_if_fail (row != -1, 0);
1089 *rows_selected[0] = row;
1094 case GTK_SELECTION_MULTIPLE:
1096 GPtrArray *array = g_ptr_array_new();
1098 gtk_tree_selection_selected_foreach (selection, get_selected_rows, array);
1099 ret_val = array->len;
1101 if (rows_selected && ret_val)
1105 *rows_selected = g_new (gint, ret_val);
1106 for (i = 0; i < ret_val; i++)
1110 tree_path = (GtkTreePath *) g_ptr_array_index (array, i);
1111 row = get_row_from_tree_path (tree_view, tree_path);
1112 gtk_tree_path_free (tree_path);
1113 (*rows_selected)[i] = row;
1116 g_ptr_array_free (array, FALSE);
1119 case GTK_SELECTION_NONE:
1126 gtk_tree_view_accessible_add_row_selection (AtkTable *table,
1130 GtkTreeView *tree_view;
1131 GtkTreeModel *tree_model;
1132 GtkTreeSelection *selection;
1133 GtkTreePath *tree_path;
1134 GtkTreeIter iter_to_row;
1136 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1140 if (!gtk_tree_view_accessible_is_row_selected (table, row))
1142 tree_view = GTK_TREE_VIEW (widget);
1143 tree_model = gtk_tree_view_get_model (tree_view);
1144 selection = gtk_tree_view_get_selection (tree_view);
1146 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
1148 tree_path = gtk_tree_path_new ();
1149 gtk_tree_path_append_index (tree_path, row);
1150 gtk_tree_selection_select_path (selection,tree_path);
1151 gtk_tree_path_free (tree_path);
1155 set_iter_nth_row (tree_view, &iter_to_row, row);
1156 gtk_tree_selection_select_iter (selection, &iter_to_row);
1160 return gtk_tree_view_accessible_is_row_selected (table, row);
1164 gtk_tree_view_accessible_remove_row_selection (AtkTable *table,
1168 GtkTreeView *tree_view;
1169 GtkTreeSelection *selection;
1171 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1175 tree_view = GTK_TREE_VIEW (widget);
1176 selection = gtk_tree_view_get_selection (tree_view);
1178 if (gtk_tree_view_accessible_is_row_selected (table, row))
1180 gtk_tree_selection_unselect_all (selection);
1188 gtk_tree_view_accessible_get_column_header (AtkTable *table,
1192 GtkTreeView *tree_view;
1193 GtkTreeViewColumn *tv_col;
1195 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1199 tree_view = GTK_TREE_VIEW (widget);
1200 tv_col = get_column (tree_view, in_col);
1201 return get_header_from_column (tv_col);
1204 static const gchar *
1205 gtk_tree_view_accessible_get_column_description (AtkTable *table,
1209 GtkTreeView *tree_view;
1210 GtkTreeViewColumn *tv_col;
1212 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
1216 tree_view = GTK_TREE_VIEW (widget);
1217 tv_col = get_column (tree_view, in_col);
1221 return gtk_tree_view_column_get_title (tv_col);
1225 atk_table_interface_init (AtkTableIface *iface)
1227 iface->ref_at = gtk_tree_view_accessible_table_ref_at;
1228 iface->get_n_rows = gtk_tree_view_accessible_get_n_rows;
1229 iface->get_n_columns = gtk_tree_view_accessible_get_n_columns;
1230 iface->get_index_at = gtk_tree_view_accessible_get_index_at;
1231 iface->get_column_at_index = gtk_tree_view_accessible_get_column_at_index;
1232 iface->get_row_at_index = gtk_tree_view_accessible_get_row_at_index;
1233 iface->is_row_selected = gtk_tree_view_accessible_is_row_selected;
1234 iface->is_selected = gtk_tree_view_accessible_is_selected;
1235 iface->get_selected_rows = gtk_tree_view_accessible_get_selected_rows;
1236 iface->add_row_selection = gtk_tree_view_accessible_add_row_selection;
1237 iface->remove_row_selection = gtk_tree_view_accessible_remove_row_selection;
1238 iface->get_column_extent_at = NULL;
1239 iface->get_row_extent_at = NULL;
1240 iface->get_column_header = gtk_tree_view_accessible_get_column_header;
1241 iface->get_column_description = gtk_tree_view_accessible_get_column_description;
1244 /* atkselection.h */
1247 gtk_tree_view_accessible_add_selection (AtkSelection *selection,
1254 table = ATK_TABLE (selection);
1255 n_columns = gtk_tree_view_accessible_get_n_columns (table);
1259 row = gtk_tree_view_accessible_get_row_at_index (table, i);
1260 return gtk_tree_view_accessible_add_row_selection (table, row);
1264 gtk_tree_view_accessible_clear_selection (AtkSelection *selection)
1267 GtkTreeView *tree_view;
1268 GtkTreeSelection *tree_selection;
1270 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
1274 tree_view = GTK_TREE_VIEW (widget);
1275 tree_selection = gtk_tree_view_get_selection (tree_view);
1277 gtk_tree_selection_unselect_all (tree_selection);
1282 gtk_tree_view_accessible_ref_selection (AtkSelection *selection,
1291 table = ATK_TABLE (selection);
1292 n_columns = gtk_tree_view_accessible_get_n_columns (table);
1293 n_selected = gtk_tree_view_accessible_get_selected_rows (table, &selected);
1294 if (i >= n_columns * n_selected)
1297 row = selected[i / n_columns];
1300 return gtk_tree_view_accessible_table_ref_at (table, row, i % n_columns);
1304 gtk_tree_view_accessible_get_selection_count (AtkSelection *selection)
1309 table = ATK_TABLE (selection);
1310 n_selected = gtk_tree_view_accessible_get_selected_rows (table, NULL);
1312 n_selected *= gtk_tree_view_accessible_get_n_columns (table);
1317 gtk_tree_view_accessible_is_child_selected (AtkSelection *selection,
1323 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
1327 row = atk_table_get_row_at_index (ATK_TABLE (selection), i);
1329 return gtk_tree_view_accessible_is_row_selected (ATK_TABLE (selection), row);
1332 static void atk_selection_interface_init (AtkSelectionIface *iface)
1334 iface->add_selection = gtk_tree_view_accessible_add_selection;
1335 iface->clear_selection = gtk_tree_view_accessible_clear_selection;
1336 iface->ref_selection = gtk_tree_view_accessible_ref_selection;
1337 iface->get_selection_count = gtk_tree_view_accessible_get_selection_count;
1338 iface->is_child_selected = gtk_tree_view_accessible_is_child_selected;
1341 #define EXTRA_EXPANDER_PADDING 4
1344 gtk_tree_view_accessible_get_cell_area (GtkCellAccessibleParent *parent,
1345 GtkCellAccessible *cell,
1346 GdkRectangle *cell_rect)
1349 GtkTreeView *tree_view;
1350 GtkTreeViewColumn *tv_col;
1352 AtkObject *parent_cell;
1353 GtkTreeViewAccessibleCellInfo *cell_info;
1354 GtkCellAccessible *top_cell;
1356 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1360 tree_view = GTK_TREE_VIEW (widget);
1361 parent_cell = atk_object_get_parent (ATK_OBJECT (cell));
1362 if (parent_cell != ATK_OBJECT (parent))
1363 top_cell = GTK_CELL_ACCESSIBLE (parent_cell);
1366 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), top_cell, TRUE);
1367 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
1369 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
1370 tv_col = cell_info->cell_col_ref;
1371 if (path && cell_info->in_use)
1373 GtkTreeViewColumn *expander_column;
1374 gint focus_line_width;
1376 gtk_tree_view_get_cell_area (tree_view, path, tv_col, cell_rect);
1377 expander_column = gtk_tree_view_get_expander_column (tree_view);
1378 if (expander_column == tv_col)
1381 gtk_widget_style_get (widget,
1382 "expander-size", &expander_size,
1384 cell_rect->x += expander_size + EXTRA_EXPANDER_PADDING;
1385 cell_rect->width -= expander_size + EXTRA_EXPANDER_PADDING;
1387 gtk_widget_style_get (widget,
1388 "focus-line-width", &focus_line_width,
1391 cell_rect->x += focus_line_width;
1392 cell_rect->width -= 2 * focus_line_width;
1394 gtk_tree_path_free (path);
1396 /* A column has more than one renderer so we find the position
1399 if (top_cell != cell)
1406 GtkCellRenderer *renderer;
1408 cell_index = atk_object_get_index_in_parent (ATK_OBJECT (cell));
1409 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
1410 renderer = g_list_nth_data (renderers, cell_index);
1412 found = gtk_tree_view_column_cell_get_position (tv_col, renderer, &cell_start, &cell_width);
1415 cell_rect->x += cell_start;
1416 cell_rect->width = cell_width;
1418 g_list_free (renderers);
1425 gtk_tree_view_accessible_get_cell_extents (GtkCellAccessibleParent *parent,
1426 GtkCellAccessible *cell,
1431 AtkCoordType coord_type)
1434 GtkTreeView *tree_view;
1435 GdkWindow *bin_window;
1436 GdkRectangle cell_rect;
1439 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1443 tree_view = GTK_TREE_VIEW (widget);
1444 gtk_tree_view_accessible_get_cell_area (parent, cell, &cell_rect);
1445 bin_window = gtk_tree_view_get_bin_window (tree_view);
1446 gdk_window_get_origin (bin_window, &w_x, &w_y);
1448 if (coord_type == ATK_XY_WINDOW)
1451 gint x_toplevel, y_toplevel;
1453 window = gdk_window_get_toplevel (bin_window);
1454 gdk_window_get_origin (window, &x_toplevel, &y_toplevel);
1460 *width = cell_rect.width;
1461 *height = cell_rect.height;
1462 if (is_cell_showing (tree_view, &cell_rect))
1464 *x = cell_rect.x + w_x;
1465 *y = cell_rect.y + w_y;
1475 gtk_tree_view_accessible_grab_cell_focus (GtkCellAccessibleParent *parent,
1476 GtkCellAccessible *cell)
1479 GtkTreeView *tree_view;
1480 GtkTreeViewColumn *tv_col;
1482 AtkObject *parent_cell;
1483 AtkObject *cell_object;
1484 GtkTreeViewAccessibleCellInfo *cell_info;
1485 GtkCellRenderer *renderer = NULL;
1486 GtkWidget *toplevel;
1489 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
1493 tree_view = GTK_TREE_VIEW (widget);
1495 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
1496 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
1498 cell_object = ATK_OBJECT (cell);
1499 parent_cell = atk_object_get_parent (cell_object);
1500 tv_col = cell_info->cell_col_ref;
1501 if (parent_cell != ATK_OBJECT (parent))
1503 /* GtkCellAccessible is in a GtkContainerCellAccessible.
1504 * The GtkTreeViewColumn has multiple renderers;
1505 * find the corresponding one.
1509 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
1510 if (cell_info->in_use)
1512 index = atk_object_get_index_in_parent (cell_object);
1513 renderer = g_list_nth_data (renderers, index);
1515 g_list_free (renderers);
1517 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
1518 if (path && cell_info->in_use)
1521 gtk_tree_view_set_cursor_on_cell (tree_view, path, tv_col, renderer, FALSE);
1523 gtk_tree_view_set_cursor (tree_view, path, tv_col, FALSE);
1525 gtk_tree_path_free (path);
1526 gtk_widget_grab_focus (widget);
1527 toplevel = gtk_widget_get_toplevel (widget);
1528 if (gtk_widget_is_toplevel (toplevel))
1530 #ifdef GDK_WINDOWING_X11
1531 gtk_window_present_with_time (GTK_WINDOW (toplevel),
1532 gdk_x11_get_server_time (gtk_widget_get_window (widget)));
1534 gtk_window_present (GTK_WINDOW (toplevel));
1545 gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface)
1547 iface->get_cell_extents = gtk_tree_view_accessible_get_cell_extents;
1548 iface->get_cell_area = gtk_tree_view_accessible_get_cell_area;
1549 iface->grab_focus = gtk_tree_view_accessible_grab_cell_focus;
1552 /* signal handling */
1555 idle_expand_row (gpointer data)
1557 GtkTreeViewAccessible *accessible = data;
1559 GtkTreeView *tree_view;
1561 GtkTreeModel *tree_model;
1562 gint n_inserted, row;
1564 accessible->idle_expand_id = 0;
1566 path = accessible->idle_expand_path;
1567 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
1569 tree_model = gtk_tree_view_get_model (tree_view);
1573 if (!path || !gtk_tree_model_get_iter (tree_model, &iter, path))
1576 /* Update visibility of cells below expansion row */
1577 traverse_cells (accessible, path, FALSE, FALSE);
1579 /* Figure out number of visible children, the following test
1582 if (gtk_tree_model_iter_has_child (tree_model, &iter))
1584 GtkTreePath *path_copy;
1586 /* By passing path into this function, we find the number of
1587 * visible children of path.
1589 path_copy = gtk_tree_path_copy (path);
1590 gtk_tree_path_append_index (path_copy, 0);
1593 iterate_thru_children (tree_view, tree_model,
1594 path_copy, NULL, &n_inserted, 0);
1595 gtk_tree_path_free (path_copy);
1599 /* We can get here if the row expanded callback deleted the row */
1603 /* Set expand state */
1604 set_expand_state (tree_view, tree_model, accessible, path, TRUE);
1606 row = get_row_from_tree_path (tree_view, path);
1608 /* shouldn't ever happen */
1610 g_assert_not_reached ();
1612 /* Must add 1 because the "added rows" are below the row being expanded */
1615 g_signal_emit_by_name (accessible, "row-inserted", row, n_inserted);
1617 accessible->idle_expand_path = NULL;
1619 gtk_tree_path_free (path);
1625 row_expanded_cb (GtkTreeView *tree_view,
1630 GtkTreeViewAccessible *accessible;
1632 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
1633 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1636 * The visible rectangle has not been updated when this signal is emitted
1637 * so we process the signal when the GTK processing is completed
1639 /* this seems wrong since it overwrites any other pending expand handlers... */
1640 accessible->idle_expand_path = gtk_tree_path_copy (path);
1641 if (accessible->idle_expand_id)
1642 g_source_remove (accessible->idle_expand_id);
1643 accessible->idle_expand_id = gdk_threads_add_idle (idle_expand_row, accessible);
1649 row_collapsed_cb (GtkTreeView *tree_view,
1653 GtkTreeModel *tree_model;
1655 GtkTreeViewAccessible *accessible;
1658 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
1659 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1660 tree_model = gtk_tree_view_get_model (tree_view);
1662 clean_rows (accessible);
1664 /* Update visibility of cells below collapsed row */
1665 traverse_cells (accessible, path, FALSE, FALSE);
1667 /* Set collapse state */
1668 set_expand_state (tree_view, tree_model, accessible, path, FALSE);
1669 if (accessible->n_children_deleted == 0)
1671 row = get_row_from_tree_path (tree_view, path);
1674 g_signal_emit_by_name (atk_obj, "row-deleted", row,
1675 accessible->n_children_deleted);
1676 accessible->n_children_deleted = 0;
1681 size_allocate_cb (GtkWidget *widget,
1682 GtkAllocation *allocation)
1685 GtkTreeViewAccessible *accessible;
1687 atk_obj = gtk_widget_get_accessible (widget);
1688 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1690 /* If the size allocation changes, the visibility of cells
1691 * may change so update the cells visibility.
1693 traverse_cells (accessible, NULL, FALSE, FALSE);
1697 selection_changed_cb (GtkTreeSelection *selection,
1700 GtkTreeViewAccessible *accessible;
1701 GtkTreeView *tree_view;
1703 GtkTreeViewAccessibleCellInfo *info;
1704 GtkTreeSelection *tree_selection;
1706 GHashTableIter iter;
1708 accessible = GTK_TREE_VIEW_ACCESSIBLE (data);
1709 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
1713 tree_view = GTK_TREE_VIEW (widget);
1714 tree_selection = gtk_tree_view_get_selection (tree_view);
1716 clean_rows (accessible);
1718 /* FIXME: clean rows iterates through all cells too */
1719 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
1720 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&info))
1724 _gtk_cell_accessible_remove_state (info->cell, ATK_STATE_SELECTED, TRUE);
1726 path = gtk_tree_row_reference_get_path (info->cell_row_ref);
1727 if (path && gtk_tree_selection_path_is_selected (tree_selection, path))
1728 _gtk_cell_accessible_add_state (info->cell, ATK_STATE_SELECTED, TRUE);
1729 gtk_tree_path_free (path);
1732 if (gtk_widget_get_realized (widget))
1733 g_signal_emit_by_name (accessible, "selection-changed");
1737 columns_changed (GtkTreeView *tree_view)
1740 GtkTreeViewAccessible *accessible;
1741 GList *tv_cols, *tmp_list;
1742 gboolean column_found;
1743 gboolean move_found = FALSE;
1744 gboolean stale_set = FALSE;
1745 gint column_count = 0;
1748 atk_obj = gtk_widget_get_accessible (GTK_WIDGET(tree_view));
1749 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
1751 /* This function must determine if the change is an add, delete
1752 * or a move based upon its cache of TreeViewColumns in
1753 * accessible->col_data
1755 tv_cols = gtk_tree_view_get_columns (tree_view);
1756 accessible->n_cols = g_list_length (tv_cols);
1758 /* check for adds or moves */
1759 for (tmp_list = tv_cols; tmp_list; tmp_list = tmp_list->next)
1761 column_found = FALSE;
1763 for (i = 0; i < accessible->col_data->len; i++)
1766 if ((GtkTreeViewColumn *)tmp_list->data ==
1767 (GtkTreeViewColumn *)g_array_index (accessible->col_data,
1768 GtkTreeViewColumn *, i))
1770 column_found = TRUE;
1772 /* If the column isn't in the same position, a move happened */
1773 if (!move_found && i != column_count)
1777 /* Set all rows to ATK_STATE_STALE */
1778 traverse_cells (accessible, NULL, TRUE, FALSE);
1782 /* Just emit one column reordered signal when a move happens */
1783 g_signal_emit_by_name (atk_obj, "column-reordered");
1791 /* If column_found is FALSE, then an insert happened for column
1792 * number column_count
1800 /* Set all rows to ATK_STATE_STALE */
1801 traverse_cells (accessible, NULL, TRUE, FALSE);
1805 /* Generate column-inserted signal */
1806 g_signal_emit_by_name (atk_obj, "column-inserted", column_count, 1);
1808 /* Generate children-changed signals */
1809 for (row = 0; row < accessible->n_rows; row++)
1811 /* Pass NULL as the child object, i.e. 4th argument */
1812 g_signal_emit_by_name (atk_obj, "children-changed::add",
1813 ((row * accessible->n_cols) + column_count), NULL, NULL);
1820 /* check for deletes */
1821 for (i = 0; i < accessible->col_data->len; i++)
1823 column_found = FALSE;
1825 for (tmp_list = tv_cols; tmp_list; tmp_list = tmp_list->next)
1827 if ((GtkTreeViewColumn *)tmp_list->data ==
1828 (GtkTreeViewColumn *)g_array_index (accessible->col_data,
1829 GtkTreeViewColumn *, i))
1831 column_found = TRUE;
1836 /* If column_found is FALSE, then a delete happened for column
1843 clean_cols (accessible,
1844 (GtkTreeViewColumn *)g_array_index (accessible->col_data,
1845 GtkTreeViewColumn *, i));
1849 /* Set all rows to ATK_STATE_STALE */
1850 traverse_cells (accessible, NULL, TRUE, FALSE);
1854 /* Generate column-deleted signal */
1855 g_signal_emit_by_name (atk_obj, "column-deleted", i, 1);
1857 /* Generate children-changed signals */
1858 for (row = 0; row < accessible->n_rows; row++)
1860 /* Pass NULL as the child object, 4th argument */
1861 g_signal_emit_by_name (atk_obj, "children-changed::remove",
1862 ((row * accessible->n_cols) + column_count), NULL, NULL);
1867 /* rebuild the array */
1868 g_array_free (accessible->col_data, TRUE);
1869 accessible->col_data = g_array_sized_new (FALSE, TRUE, sizeof (GtkTreeViewColumn *), 0);
1871 for (tmp_list = tv_cols; tmp_list; tmp_list = tmp_list->next)
1872 g_array_append_val (accessible->col_data, tmp_list->data);
1873 g_list_free (tv_cols);
1877 idle_cursor_changed (gpointer data)
1879 GtkTreeViewAccessible *accessible = GTK_TREE_VIEW_ACCESSIBLE (data);
1880 GtkTreeView *tree_view;
1884 accessible->idle_cursor_changed_id = 0;
1886 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
1890 tree_view = GTK_TREE_VIEW (widget);
1892 cell = gtk_tree_view_accessible_ref_focus_cell (tree_view);
1895 if (cell != accessible->focus_cell)
1897 if (accessible->focus_cell)
1899 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_ACTIVE, FALSE);
1900 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_FOCUSED, FALSE);
1901 g_object_unref (accessible->focus_cell);
1902 accessible->focus_cell = cell;
1905 if (gtk_widget_has_focus (widget))
1907 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_ACTIVE, FALSE);
1908 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_FOCUSED, FALSE);
1911 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
1914 g_object_unref (cell);
1921 cursor_changed (GtkTreeView *tree_view)
1923 GtkTreeViewAccessible *accessible;
1925 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (tree_view)));
1926 if (accessible->idle_cursor_changed_id != 0)
1929 /* We notify the focus change in a idle handler so that the processing
1930 * of the cursor change is completed when the focus handler is called.
1931 * This will allow actions to be called in the focus handler
1933 accessible->idle_cursor_changed_id = gdk_threads_add_idle (idle_cursor_changed, accessible);
1937 focus_in (GtkWidget *widget)
1939 GtkTreeView *tree_view;
1940 GtkTreeViewAccessible *accessible;
1941 AtkStateSet *state_set;
1944 tree_view = GTK_TREE_VIEW (widget);
1945 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
1947 if (accessible->focus_cell == NULL)
1949 cell = gtk_tree_view_accessible_ref_focus_cell (tree_view);
1952 state_set = atk_object_ref_state_set (cell);
1955 if (!atk_state_set_contains_state (state_set, ATK_STATE_FOCUSED))
1957 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_ACTIVE, FALSE);
1958 accessible->focus_cell = cell;
1959 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_FOCUSED, FALSE);
1960 g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
1962 g_object_unref (state_set);
1970 focus_out (GtkWidget *widget)
1972 GtkTreeViewAccessible *accessible;
1974 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
1975 if (accessible->focus_cell)
1977 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_ACTIVE, FALSE);
1978 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_FOCUSED, FALSE);
1979 g_object_unref (accessible->focus_cell);
1980 accessible->focus_cell = NULL;
1986 model_row_changed (GtkTreeModel *tree_model,
1991 GtkTreeView *tree_view = GTK_TREE_VIEW (user_data);
1992 GtkTreeViewAccessible *accessible;
1993 GtkTreePath *cell_path;
1994 GtkTreeViewAccessibleCellInfo *cell_info;
1995 GHashTableIter hash_iter;
1997 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (tree_view)));
1999 /* Loop through our cached cells */
2000 /* Must loop through them all */
2001 g_hash_table_iter_init (&hash_iter, accessible->cell_info_by_index);
2002 while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer *)&cell_info))
2004 if (cell_info->in_use)
2006 cell_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2008 if (cell_path != NULL)
2010 if (path && gtk_tree_path_compare (cell_path, path) == 0)
2012 if (GTK_IS_RENDERER_CELL_ACCESSIBLE (cell_info->cell))
2013 update_cell_value (GTK_RENDERER_CELL_ACCESSIBLE (cell_info->cell),
2016 gtk_tree_path_free (cell_path);
2020 g_signal_emit_by_name (accessible, "visible-data-changed");
2024 column_visibility_changed (GObject *object,
2028 if (g_strcmp0 (pspec->name, "visible") == 0)
2030 /* A column has been made visible or invisible
2031 * We update our cache of cells and emit model_changed signal
2033 GtkTreeView *tree_view = (GtkTreeView *)user_data;
2034 GtkTreeViewAccessible *accessible;
2035 GtkTreeViewAccessibleCellInfo *cell_info;
2036 GtkTreeViewColumn *this_col = GTK_TREE_VIEW_COLUMN (object);
2037 GtkTreeViewColumn *tv_col;
2038 GHashTableIter iter;
2040 accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (tree_view))
2042 g_signal_emit_by_name (accessible, "model-changed");
2044 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
2045 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
2047 if (cell_info->in_use)
2049 tv_col = cell_info->cell_col_ref;
2050 if (tv_col == this_col)
2052 GtkTreePath *row_path;
2053 row_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2054 if (GTK_IS_RENDERER_CELL_ACCESSIBLE (cell_info->cell))
2056 if (gtk_tree_view_column_get_visible (tv_col))
2057 set_cell_visibility (tree_view,
2059 tv_col, row_path, FALSE);
2062 _gtk_cell_accessible_remove_state (cell_info->cell, ATK_STATE_VISIBLE, TRUE);
2063 _gtk_cell_accessible_remove_state (cell_info->cell, ATK_STATE_SHOWING, TRUE);
2066 gtk_tree_path_free (row_path);
2074 model_row_inserted (GtkTreeModel *tree_model,
2079 GtkTreeView *tree_view = (GtkTreeView *)user_data;
2081 GtkTreeViewAccessible *accessible;
2082 GtkTreePath *path_copy;
2083 gint row, n_inserted, child_row;
2085 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
2086 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
2087 accessible->n_rows++;
2089 if (accessible->idle_expand_id)
2091 g_source_remove (accessible->idle_expand_id);
2092 accessible->idle_expand_id = 0;
2094 /* don't do this if the insertion precedes the idle path,
2095 * since it will now be invalid
2097 if (path && accessible->idle_expand_path &&
2098 (gtk_tree_path_compare (path, accessible->idle_expand_path) > 0))
2099 set_expand_state (tree_view, tree_model, accessible, accessible->idle_expand_path, FALSE);
2100 if (accessible->idle_expand_path)
2101 gtk_tree_path_free (accessible->idle_expand_path);
2103 /* Check to see if row is visible */
2104 row = get_row_from_tree_path (tree_view, path);
2106 /* A row insert is not necessarily visible. For example,
2107 * a row can be draged & dropped into another row, which
2108 * causes an insert on the model that isn't visible in the
2109 * view. Only generate a signal if the inserted row is
2114 GtkTreeIter tmp_iter;
2117 gtk_tree_model_get_iter (tree_model, &tmp_iter, path);
2119 /* Figure out number of visible children. */
2120 if (gtk_tree_model_iter_has_child (tree_model, &tmp_iter))
2124 * By passing path into this function, we find the number of
2125 * visible children of path.
2128 /* iterate_thru_children modifies path, we don't want that, so give
2130 path2 = gtk_tree_path_copy (path);
2131 iterate_thru_children (tree_view, tree_model,
2132 path2, NULL, &n_inserted, 0);
2133 gtk_tree_path_free (path2);
2135 /* Must add one to include the row that is being added */
2141 /* Set rows below the inserted row to ATK_STATE_STALE */
2142 traverse_cells (accessible, path, TRUE, TRUE);
2144 /* Generate row-inserted signal */
2145 g_signal_emit_by_name (atk_obj, "row-inserted", row, n_inserted);
2147 /* Generate children-changed signals */
2148 n_cols = gtk_tree_view_accessible_get_n_columns (ATK_TABLE (atk_obj));
2149 for (child_row = row; child_row < (row + n_inserted); child_row++)
2151 for (col = 0; col < n_cols; col++)
2153 /* Pass NULL as the child object, i.e. 4th argument */
2154 g_signal_emit_by_name (atk_obj, "children-changed::add",
2155 ((row * n_cols) + col), NULL, NULL);
2161 /* The row has been inserted inside another row. This can
2162 * cause a row that previously couldn't be expanded to now
2165 path_copy = gtk_tree_path_copy (path);
2166 gtk_tree_path_up (path_copy);
2167 set_expand_state (tree_view, tree_model, accessible, path_copy, TRUE);
2168 gtk_tree_path_free (path_copy);
2173 model_row_deleted (GtkTreeModel *tree_model,
2177 GtkTreeView *tree_view = (GtkTreeView *)user_data;
2178 GtkTreePath *path_copy;
2180 GtkTreeViewAccessible *accessible;
2183 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
2184 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
2186 accessible->n_rows--;
2188 if (accessible->idle_expand_id)
2190 g_source_remove (accessible->idle_expand_id);
2191 gtk_tree_path_free (accessible->idle_expand_path);
2192 accessible->idle_expand_id = 0;
2195 /* Check to see if row is visible */
2196 clean_rows (accessible);
2198 /* Set rows at or below the specified row to ATK_STATE_STALE */
2199 traverse_cells (accessible, path, TRUE, TRUE);
2201 /* If deleting a row with a depth > 1, then this may affect the
2202 * expansion/contraction of its parent(s). Make sure this is
2205 if (gtk_tree_path_get_depth (path) > 1)
2207 path_copy = gtk_tree_path_copy (path);
2208 gtk_tree_path_up (path_copy);
2209 set_expand_state (tree_view, tree_model, accessible, path_copy, TRUE);
2210 gtk_tree_path_free (path_copy);
2212 row = get_row_from_tree_path (tree_view, path);
2214 /* If the row which is deleted is not visible because it is a child of
2215 * a collapsed row then row will be -1
2218 g_signal_emit_by_name (atk_obj, "row-deleted", row,
2219 accessible->n_children_deleted + 1);
2220 accessible->n_children_deleted = 0;
2222 /* Generate children-changed signals */
2223 for (col = 0; col < accessible->n_cols; col++)
2225 /* Pass NULL as the child object, 4th argument */
2226 g_signal_emit_by_name (atk_obj, "children-changed::remove",
2227 ((row * accessible->n_cols) + col), NULL, NULL);
2231 /* This function gets called when a row is deleted or when rows are
2232 * removed from the view due to a collapse event. Note that the
2233 * count is the number of visible *children* of the deleted row,
2234 * so it does not include the row being deleted.
2236 * As this function is called before the rows are removed we just note
2237 * the number of rows and then deal with it when we get a notification
2238 * that rows were deleted or collapsed.
2241 destroy_count_func (GtkTreeView *tree_view,
2247 GtkTreeViewAccessible *accessible;
2249 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
2250 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
2252 if (accessible->n_children_deleted != 0)
2255 accessible->n_children_deleted = count;
2259 model_rows_reordered (GtkTreeModel *tree_model,
2265 GtkTreeView *tree_view = (GtkTreeView *)user_data;
2267 GtkTreeViewAccessible *accessible;
2269 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
2270 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
2272 if (accessible->idle_expand_id)
2274 g_source_remove (accessible->idle_expand_id);
2275 gtk_tree_path_free (accessible->idle_expand_path);
2276 accessible->idle_expand_id = 0;
2278 traverse_cells (accessible, NULL, TRUE, FALSE);
2280 g_signal_emit_by_name (atk_obj, "row-reordered");
2284 set_cell_visibility (GtkTreeView *tree_view,
2285 GtkCellAccessible *cell,
2286 GtkTreeViewColumn *tv_col,
2287 GtkTreePath *tree_path,
2288 gboolean emit_signal)
2290 GdkRectangle cell_rect;
2292 /* Get these three values in tree coords */
2293 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
2294 gtk_tree_view_get_cell_area (tree_view, tree_path, tv_col, &cell_rect);
2296 cell_rect.height = 0;
2298 if (cell_rect.height > 0)
2300 /* The height will be zero for a cell for which an antecedent
2303 _gtk_cell_accessible_add_state (cell, ATK_STATE_VISIBLE, emit_signal);
2304 if (is_cell_showing (tree_view, &cell_rect))
2305 _gtk_cell_accessible_add_state (cell, ATK_STATE_SHOWING, emit_signal);
2307 _gtk_cell_accessible_remove_state (cell, ATK_STATE_SHOWING, emit_signal);
2311 _gtk_cell_accessible_remove_state (cell, ATK_STATE_VISIBLE, emit_signal);
2312 _gtk_cell_accessible_remove_state (cell, ATK_STATE_SHOWING, emit_signal);
2317 is_cell_showing (GtkTreeView *tree_view,
2318 GdkRectangle *cell_rect)
2320 GdkRectangle rect, *visible_rect;
2321 GdkRectangle rect1, *tree_cell_rect;
2323 gboolean is_showing;
2325 /* A cell is considered "SHOWING" if any part of the cell is
2326 * in the visible area. Other ways we could do this is by a
2327 * cell's midpoint or if the cell is fully in the visible range.
2328 * Since we have the cell_rect x, y, width, height of the cell,
2329 * any of these is easy to compute.
2331 * It is assumed that cell's rectangle is in widget coordinates
2332 * so we must transform to tree cordinates.
2334 visible_rect = ▭
2335 tree_cell_rect = &rect1;
2336 tree_cell_rect->x = cell_rect->x;
2337 tree_cell_rect->y = cell_rect->y;
2338 tree_cell_rect->width = cell_rect->width;
2339 tree_cell_rect->height = cell_rect->height;
2341 gtk_tree_view_get_visible_rect (tree_view, visible_rect);
2342 gtk_tree_view_convert_tree_to_bin_window_coords (tree_view, visible_rect->x,
2343 visible_rect->y, &bx, &by);
2345 if (((tree_cell_rect->x + tree_cell_rect->width) < bx) ||
2346 ((tree_cell_rect->y + tree_cell_rect->height) < by) ||
2347 (tree_cell_rect->x > (bx + visible_rect->width)) ||
2348 (tree_cell_rect->y > (by + visible_rect->height)))
2358 /* This function is called when a cell's flyweight is created in
2359 * gtk_tree_view_accessible_table_ref_at with emit_change_signal
2360 * set to FALSE and in model_row_changed() on receipt of "row-changed"
2361 * signal when emit_change_signal is set to TRUE
2364 update_cell_value (GtkRendererCellAccessible *renderer_cell,
2365 GtkTreeViewAccessible *accessible,
2366 gboolean emit_change_signal)
2368 GtkTreeViewAccessibleCellInfo *cell_info;
2369 GtkTreeView *tree_view;
2370 GtkTreeModel *tree_model;
2373 GList *renderers, *cur_renderer;
2375 GtkRendererCellAccessibleClass *renderer_cell_class;
2376 GtkCellRendererClass *gtk_cell_renderer_class;
2377 GtkCellAccessible *cell;
2380 gboolean is_expander, is_expanded;
2382 renderer_cell_class = GTK_RENDERER_CELL_ACCESSIBLE_GET_CLASS (renderer_cell);
2383 if (renderer_cell->renderer)
2384 gtk_cell_renderer_class = GTK_CELL_RENDERER_GET_CLASS (renderer_cell->renderer);
2386 gtk_cell_renderer_class = NULL;
2388 prop_list = renderer_cell_class->property_list;
2390 cell = GTK_CELL_ACCESSIBLE (renderer_cell);
2391 cell_info = find_cell_info (accessible, cell, TRUE);
2392 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
2395 if (emit_change_signal && cell_info->in_use)
2397 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
2398 tree_model = gtk_tree_view_get_model (tree_view);
2399 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2403 gtk_tree_model_get_iter (tree_model, &iter, path);
2404 is_expander = FALSE;
2405 is_expanded = FALSE;
2406 if (gtk_tree_model_iter_has_child (tree_model, &iter))
2408 GtkTreeViewColumn *expander_tv;
2410 expander_tv = gtk_tree_view_get_expander_column (tree_view);
2411 if (expander_tv == cell_info->cell_col_ref)
2414 is_expanded = gtk_tree_view_row_expanded (tree_view, path);
2417 gtk_tree_path_free (path);
2418 gtk_tree_view_column_cell_set_cell_data (cell_info->cell_col_ref,
2420 is_expander, is_expanded);
2422 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_info->cell_col_ref));
2426 /* If the cell is in a container, its index is used to find the renderer
2427 * in the list. Otherwise, we assume that the cell is represented
2428 * by the first renderer in the list
2431 if (cell_info->in_use)
2433 parent = atk_object_get_parent (ATK_OBJECT (cell));
2435 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
2436 cur_renderer = g_list_nth (renderers, cell->index);
2438 cur_renderer = renderers;
2443 if (cur_renderer == NULL)
2446 if (gtk_cell_renderer_class)
2450 spec = g_object_class_find_property
2451 (G_OBJECT_CLASS (gtk_cell_renderer_class), *prop_list);
2455 GValue value = G_VALUE_INIT;
2457 g_value_init (&value, spec->value_type);
2458 g_object_get_property (cur_renderer->data, *prop_list, &value);
2459 g_object_set_property (G_OBJECT (renderer_cell->renderer),
2460 *prop_list, &value);
2461 g_value_unset (&value);
2464 g_warning ("Invalid property: %s\n", *prop_list);
2468 g_list_free (renderers);
2470 return _gtk_renderer_cell_accessible_update_cache (renderer_cell, emit_change_signal);
2474 get_row_from_tree_path (GtkTreeView *tree_view,
2477 GtkTreeModel *tree_model;
2478 GtkTreePath *root_tree;
2481 tree_model = gtk_tree_view_get_model (tree_view);
2483 if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
2484 row = gtk_tree_path_get_indices (path)[0];
2487 root_tree = gtk_tree_path_new_first ();
2489 iterate_thru_children (tree_view, tree_model, root_tree, path, &row, 0);
2490 gtk_tree_path_free (root_tree);
2499 * Get the specified GtkTreeViewColumn in the GtkTreeView.
2500 * Only visible columns are considered.
2502 static GtkTreeViewColumn *
2503 get_column (GtkTreeView *tree_view,
2506 GtkTreeViewColumn *tv_col;
2512 g_warning ("Request for invalid column %d\n", in_col);
2516 tv_col = gtk_tree_view_get_column (tree_view, i);
2517 while (tv_col != NULL)
2519 if (gtk_tree_view_column_get_visible (tv_col))
2521 if (in_col == n_cols)
2523 tv_col = gtk_tree_view_get_column (tree_view, ++i);
2526 if (in_col != n_cols)
2528 g_warning ("Request for invalid column %d\n", in_col);
2535 get_actual_column_number (GtkTreeView *tree_view,
2536 gint visible_column)
2538 GtkTreeViewColumn *tv_col;
2539 gint actual_column = 0;
2540 gint visible_columns = -1;
2542 /* This function calculates the column number which corresponds
2543 * to the specified visible column number
2545 tv_col = gtk_tree_view_get_column (tree_view, actual_column);
2546 while (tv_col != NULL)
2548 if (gtk_tree_view_column_get_visible (tv_col))
2550 if (visible_columns == visible_column)
2551 return actual_column;
2552 tv_col = gtk_tree_view_get_column (tree_view, ++actual_column);
2554 g_warning ("get_actual_column_number failed for %d\n", visible_column);
2559 get_visible_column_number (GtkTreeView *tree_view,
2562 GtkTreeViewColumn *tv_col;
2564 gint visible_columns = -1;
2566 /* This function calculates the visible column number
2567 * which corresponds to the specified actual column number
2569 tv_col = gtk_tree_view_get_column (tree_view, column);
2571 while (tv_col != NULL)
2573 if (gtk_tree_view_column_get_visible (tv_col))
2576 if (actual_column == column)
2577 return visible_columns;
2580 if (actual_column == column)
2582 tv_col = gtk_tree_view_get_column (tree_view, ++column);
2584 g_warning ("get_visible_column_number failed for %d\n", actual_column);
2588 /* Helper recursive function that returns an iter to nth row
2590 static GtkTreeIter *
2591 return_iter_nth_row (GtkTreeView *tree_view,
2592 GtkTreeModel *tree_model,
2597 GtkTreePath *current_path;
2598 GtkTreeIter new_iter;
2599 gboolean row_expanded;
2601 current_path = gtk_tree_model_get_path (tree_model, iter);
2602 if (increment == row)
2604 gtk_tree_path_free (current_path);
2608 row_expanded = gtk_tree_view_row_expanded (tree_view, current_path);
2609 gtk_tree_path_free (current_path);
2612 if ((row_expanded && gtk_tree_model_iter_children (tree_model, iter, &new_iter)) ||
2613 (gtk_tree_model_iter_next (tree_model, iter)) ||
2614 (gtk_tree_model_iter_parent (tree_model, iter, &new_iter) &&
2615 (gtk_tree_model_iter_next (tree_model, iter))))
2616 return return_iter_nth_row (tree_view, tree_model, iter,
2623 set_iter_nth_row (GtkTreeView *tree_view,
2627 GtkTreeModel *tree_model;
2629 tree_model = gtk_tree_view_get_model (tree_view);
2630 gtk_tree_model_get_iter_first (tree_model, iter);
2631 iter = return_iter_nth_row (tree_view, tree_model, iter, 0, row);
2634 /* Recursively called until the row specified by orig is found.
2636 * *count will be set to the visible row number of the child
2637 * relative to the row that was initially passed in as tree_path.
2638 * tree_path could be modified by this function.
2640 * *count will be -1 if orig is not found as a child (a row that is
2641 * not visible will not be found, e.g. if the row is inside a
2642 * collapsed row). If NULL is passed in as orig, *count will
2643 * be a count of the visible children.
2645 * NOTE: the value for depth must be 0 when this recursive function
2646 * is initially called, or it may not function as expected.
2649 iterate_thru_children (GtkTreeView *tree_view,
2650 GtkTreeModel *tree_model,
2651 GtkTreePath *tree_path,
2658 if (!gtk_tree_model_get_iter (tree_model, &iter, tree_path))
2661 if (tree_path && orig && !gtk_tree_path_compare (tree_path, orig))
2665 if (tree_path && orig && gtk_tree_path_compare (tree_path, orig) > 0)
2667 /* Past it, so return -1 */
2671 else if (gtk_tree_view_row_expanded (tree_view, tree_path) &&
2672 gtk_tree_model_iter_has_child (tree_model, &iter))
2675 gtk_tree_path_append_index (tree_path, 0);
2676 iterate_thru_children (tree_view, tree_model, tree_path,
2677 orig, count, (depth + 1));
2680 else if (gtk_tree_model_iter_next (tree_model, &iter))
2683 tree_path = gtk_tree_model_get_path (tree_model, &iter);
2686 iterate_thru_children (tree_view, tree_model, tree_path,
2687 orig, count, depth);
2688 gtk_tree_path_free (tree_path);
2692 else if (gtk_tree_path_up (tree_path))
2694 GtkTreeIter temp_iter;
2695 gboolean exit_loop = FALSE;
2696 gint new_depth = depth - 1;
2700 /* Make sure that we back up until we find a row
2701 * where gtk_tree_path_next does not return NULL.
2705 if (gtk_tree_path_get_depth (tree_path) == 0)
2706 /* depth is now zero so */
2708 gtk_tree_path_next (tree_path);
2710 /* Verify that the next row is a valid row! */
2711 exit_loop = gtk_tree_model_get_iter (tree_model, &temp_iter, tree_path);
2715 /* Keep going up until we find a row that has a valid next */
2716 if (gtk_tree_path_get_depth(tree_path) > 1)
2719 gtk_tree_path_up (tree_path);
2723 /* If depth is 1 and gtk_tree_model_get_iter returns FALSE,
2724 * then we are at the last row, so just return.
2734 /* This guarantees that we will stop when we hit the end of the
2740 iterate_thru_children (tree_view, tree_model, tree_path,
2741 orig, count, new_depth);
2745 /* If it gets here, then the path wasn't found. Situations
2746 * that would cause this would be if the path passed in is
2747 * invalid or contained within the last row, but not visible
2748 * because the last row is not expanded. If NULL was passed
2749 * in then a row count is desired, so only set count to -1
2750 * if orig is not NULL.
2759 clean_cell_info (GtkTreeViewAccessible *accessible,
2760 GtkTreeViewAccessibleCellInfo *cell_info)
2764 if (cell_info->in_use)
2766 obj = G_OBJECT (cell_info->cell);
2768 _gtk_cell_accessible_add_state (cell_info->cell, ATK_STATE_DEFUNCT, FALSE);
2769 g_object_weak_unref (obj, (GWeakNotify) cell_destroyed, cell_info);
2770 cell_info->in_use = FALSE;
2771 if (!accessible->garbage_collection_pending)
2773 accessible->garbage_collection_pending = TRUE;
2774 g_assert (accessible->idle_garbage_collect_id == 0);
2775 accessible->idle_garbage_collect_id =
2776 gdk_threads_add_idle (idle_garbage_collect_cell_data, accessible);
2782 clean_rows (GtkTreeViewAccessible *accessible)
2784 GtkTreeViewAccessibleCellInfo *cell_info;
2785 GHashTableIter iter;
2787 /* Clean GtkTreeViewAccessibleCellInfo data */
2788 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
2789 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
2791 GtkTreePath *row_path;
2793 row_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2795 /* If the cell has become invalid because the row has been removed,
2796 * then set the cell's state to ATK_STATE_DEFUNCT and schedule
2797 * its removal. If row_path is NULL then the row has
2800 if (row_path == NULL)
2801 clean_cell_info (accessible, cell_info);
2803 gtk_tree_path_free (row_path);
2808 clean_cols (GtkTreeViewAccessible *accessible,
2809 GtkTreeViewColumn *tv_col)
2811 GtkTreeViewAccessibleCellInfo *cell_info;
2812 GHashTableIter iter;
2814 /* Clean GtkTreeViewAccessibleCellInfo data */
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 the cell has become invalid because the column tv_col
2819 * has been removed, then set the cell's state to ATK_STATE_DEFUNCT
2820 * and remove the cell from accessible->cell_data.
2822 if (cell_info->cell_col_ref == tv_col)
2823 clean_cell_info (accessible, cell_info);
2828 garbage_collect_cell_data (gpointer data)
2830 GtkTreeViewAccessible *accessible;
2831 GtkTreeViewAccessibleCellInfo *cell_info;
2832 GHashTableIter iter;
2834 accessible = (GtkTreeViewAccessible *)data;
2836 accessible->garbage_collection_pending = FALSE;
2837 if (accessible->idle_garbage_collect_id != 0)
2839 g_source_remove (accessible->idle_garbage_collect_id);
2840 accessible->idle_garbage_collect_id = 0;
2843 /* Must loop through them all */
2844 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
2845 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
2847 if (!cell_info->in_use)
2849 g_hash_table_iter_remove (&iter);
2853 return accessible->garbage_collection_pending;
2857 idle_garbage_collect_cell_data (gpointer data)
2859 GtkTreeViewAccessible *accessible;
2861 accessible = (GtkTreeViewAccessible *)data;
2863 /* this is the idle handler (only one instance allowed), so
2864 * we can safely delete it.
2866 accessible->garbage_collection_pending = FALSE;
2867 accessible->idle_garbage_collect_id = 0;
2869 accessible->garbage_collection_pending = garbage_collect_cell_data (data);
2871 /* N.B.: if for some reason another handler has re-enterantly been
2872 * queued while this handler was being serviced, it has its own gsource,
2873 * therefore this handler should always return FALSE.
2878 /* If tree_path is passed in as NULL, then all cells are acted on.
2879 * Otherwise, just act on those cells that are on a row greater than
2880 * the specified tree_path. If inc_row is passed in as TRUE, then rows
2881 * greater and equal to the specified tree_path are acted on.
2883 * If set_stale is set the ATK_STATE_STALE is set on cells which
2884 * are to be acted on.
2886 * The function set_cell_visibility() is called on all cells to be
2887 * acted on to update the visibility of the cell.
2890 traverse_cells (GtkTreeViewAccessible *accessible,
2891 GtkTreePath *tree_path,
2895 GtkTreeViewAccessibleCellInfo *cell_info;
2897 GHashTableIter iter;
2899 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2903 /* Must loop through them all */
2904 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
2905 while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
2907 GtkTreePath *row_path;
2908 gboolean act_on_cell;
2910 if (cell_info->in_use)
2912 row_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2913 g_return_if_fail (row_path != NULL);
2914 if (tree_path == NULL)
2920 comparison = gtk_tree_path_compare (row_path, tree_path);
2921 if ((comparison > 0) ||
2922 (comparison == 0 && inc_row))
2925 act_on_cell = FALSE;
2928 if (!cell_info->in_use)
2929 g_warning ("warning: cell info destroyed during traversal");
2931 if (act_on_cell && cell_info->in_use)
2934 _gtk_cell_accessible_add_state (cell_info->cell, ATK_STATE_STALE, TRUE);
2935 set_cell_visibility (GTK_TREE_VIEW (widget),
2937 cell_info->cell_col_ref,
2940 gtk_tree_path_free (row_path);
2944 g_signal_emit_by_name (accessible, "visible-data-changed");
2947 /* If the tree_path passed in has children, then
2948 * ATK_STATE_EXPANDABLE is set. If the row is expanded
2949 * ATK_STATE_EXPANDED is turned on. If the row is
2950 * collapsed, then ATK_STATE_EXPANDED is removed.
2952 * If the tree_path passed in has no children, then
2953 * ATK_STATE_EXPANDABLE and ATK_STATE_EXPANDED are removed.
2955 * If set_on_ancestor is TRUE, then this function will also
2956 * update all cells that are ancestors of the tree_path.
2959 set_expand_state (GtkTreeView *tree_view,
2960 GtkTreeModel *tree_model,
2961 GtkTreeViewAccessible *accessible,
2962 GtkTreePath *tree_path,
2963 gboolean set_on_ancestor)
2965 GtkTreeViewColumn *expander_tv;
2966 GtkTreeViewAccessibleCellInfo *cell_info;
2967 GtkTreePath *cell_path;
2970 GHashTableIter hash_iter;
2972 g_hash_table_iter_init (&hash_iter, accessible->cell_info_by_index);
2973 while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer *) &cell_info))
2975 if (cell_info->in_use)
2977 cell_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
2980 if (cell_path != NULL)
2982 GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (cell_info->cell);
2984 expander_tv = gtk_tree_view_get_expander_column (tree_view);
2986 /* Only set state for the cell that is in the column with the
2989 if (expander_tv == cell_info->cell_col_ref)
2991 if (tree_path && gtk_tree_path_compare (cell_path, tree_path) == 0)
2993 else if (set_on_ancestor &&
2994 gtk_tree_path_get_depth (cell_path) <
2995 gtk_tree_path_get_depth (tree_path) &&
2996 gtk_tree_path_is_ancestor (cell_path, tree_path) == 1)
2997 /* Only set if set_on_ancestor was passed in as TRUE */
3001 /* Set ATK_STATE_EXPANDABLE and ATK_STATE_EXPANDED
3002 * for ancestors and found cells.
3006 /* Must check against cell_path since cell_path
3007 * can be equal to or an ancestor of tree_path.
3009 gtk_tree_model_get_iter (tree_model, &iter, cell_path);
3011 /* Set or unset ATK_STATE_EXPANDABLE as appropriate */
3012 if (gtk_tree_model_iter_has_child (tree_model, &iter))
3014 set_cell_expandable (cell);
3016 if (gtk_tree_view_row_expanded (tree_view, cell_path))
3017 _gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, TRUE);
3019 _gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDED, TRUE);
3023 _gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDED, TRUE);
3024 if (_gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDABLE, TRUE))
3025 /* The state may have been propagated to the container cell */
3026 if (!GTK_IS_CONTAINER_CELL_ACCESSIBLE (cell))
3027 _gtk_cell_accessible_remove_action_by_name (cell,
3028 "expand or contract");
3031 /* We assume that each cell in the cache once and
3032 * a container cell is before its child cells so we are
3033 * finished if set_on_ancestor is not set to TRUE.
3035 if (!set_on_ancestor)
3039 gtk_tree_path_free (cell_path);
3045 add_cell_actions (GtkCellAccessible *cell,
3048 if (GTK_IS_BOOLEAN_CELL_ACCESSIBLE (cell))
3049 _gtk_cell_accessible_add_action (cell,
3050 "toggle", "toggles the cell",
3051 NULL, toggle_cell_toggled);
3053 _gtk_cell_accessible_add_action (cell,
3054 "edit", "creates a widget in which the contents of the cell can be edited",
3056 _gtk_cell_accessible_add_action (cell,
3057 "activate", "activate the cell",
3058 NULL, activate_cell);
3062 toggle_cell_expanded (GtkCellAccessible *cell)
3064 GtkTreeViewAccessibleCellInfo *cell_info;
3065 GtkTreeView *tree_view;
3068 AtkStateSet *stateset;
3070 parent = atk_object_get_parent (ATK_OBJECT (cell));
3071 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
3072 parent = atk_object_get_parent (parent);
3074 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
3075 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
3078 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
3079 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
3083 stateset = atk_object_ref_state_set (ATK_OBJECT (cell));
3084 if (atk_state_set_contains_state (stateset, ATK_STATE_EXPANDED))
3085 gtk_tree_view_collapse_row (tree_view, path);
3087 gtk_tree_view_expand_row (tree_view, path, TRUE);
3088 g_object_unref (stateset);
3089 gtk_tree_path_free (path);
3093 toggle_cell_toggled (GtkCellAccessible *cell)
3095 GtkTreeViewAccessibleCellInfo *cell_info;
3098 GList *renderers, *cur_renderer;
3100 gboolean is_container_cell = FALSE;
3102 parent = atk_object_get_parent (ATK_OBJECT (cell));
3103 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
3105 is_container_cell = TRUE;
3106 parent = atk_object_get_parent (parent);
3109 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
3110 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
3113 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
3117 /* If the cell is in a container, its index is used to find the
3118 * renderer in the list. Otherwise, we assume that the cell is
3119 * represented by the first renderer in the list
3121 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_info->cell_col_ref));
3122 if (is_container_cell)
3123 cur_renderer = g_list_nth (renderers, cell->index);
3125 cur_renderer = renderers;
3129 pathstring = gtk_tree_path_to_string (path);
3130 g_signal_emit_by_name (cur_renderer->data, "toggled", pathstring);
3131 g_free (pathstring);
3134 g_list_free (renderers);
3135 gtk_tree_path_free (path);
3139 edit_cell (GtkCellAccessible *cell)
3141 GtkTreeViewAccessibleCellInfo *cell_info;
3142 GtkTreeView *tree_view;
3146 parent = atk_object_get_parent (ATK_OBJECT (cell));
3147 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
3148 parent = atk_object_get_parent (parent);
3150 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
3151 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
3154 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
3155 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
3158 gtk_tree_view_set_cursor (tree_view, path, cell_info->cell_col_ref, TRUE);
3159 gtk_tree_path_free (path);
3163 activate_cell (GtkCellAccessible *cell)
3165 GtkTreeViewAccessibleCellInfo *cell_info;
3166 GtkTreeView *tree_view;
3170 parent = atk_object_get_parent (ATK_OBJECT (cell));
3171 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
3172 parent = atk_object_get_parent (parent);
3174 cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
3175 if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
3178 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
3179 path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
3182 gtk_tree_view_row_activated (tree_view, path, cell_info->cell_col_ref);
3183 gtk_tree_path_free (path);
3187 cell_destroyed (gpointer data)
3189 GtkTreeViewAccessibleCellInfo *cell_info = data;
3193 if (cell_info->in_use)
3195 cell_info->in_use = FALSE;
3197 if (!cell_info->view->garbage_collection_pending)
3199 cell_info->view->garbage_collection_pending = TRUE;
3200 cell_info->view->idle_garbage_collect_id =
3201 gdk_threads_add_idle (idle_garbage_collect_cell_data, cell_info->view);
3207 cell_info_get_index (GtkTreeView *tree_view,
3208 GtkTreeViewAccessibleCellInfo *info,
3214 path = gtk_tree_row_reference_get_path (info->cell_row_ref);
3218 column_number = get_column_number (tree_view, info->cell_col_ref, FALSE);
3219 *index = get_index (tree_view, path, column_number);
3220 gtk_tree_path_free (path);
3224 cell_info_new (GtkTreeViewAccessible *accessible,
3225 GtkTreeModel *tree_model,
3227 GtkTreeViewColumn *tv_col,
3228 GtkCellAccessible *cell)
3230 GtkTreeViewAccessibleCellInfo *cell_info;
3232 cell_info = g_new (GtkTreeViewAccessibleCellInfo, 1);
3233 cell_info->cell_row_ref = gtk_tree_row_reference_new (tree_model, path);
3235 cell_info->cell_col_ref = tv_col;
3236 cell_info->cell = cell;
3237 cell_info->in_use = TRUE; /* if we've created it, assume it's in use */
3238 cell_info->view = accessible;
3239 g_hash_table_insert (accessible->cell_info_by_index, &cell->index, cell_info);
3241 /* Setup weak reference notification */
3242 g_object_weak_ref (G_OBJECT (cell), (GWeakNotify) cell_destroyed, cell_info);
3245 static GtkCellAccessible *
3246 find_cell (GtkTreeViewAccessible *accessible,
3249 GtkTreeViewAccessibleCellInfo *info;
3251 info = g_hash_table_lookup (accessible->cell_info_by_index, &index);
3259 refresh_cell_index (GtkCellAccessible *cell)
3261 GtkTreeViewAccessibleCellInfo *info;
3263 GtkTreeView *tree_view;
3264 GtkTreeViewAccessible *accessible;
3267 parent = atk_object_get_parent (ATK_OBJECT (cell));
3268 if (!GTK_IS_TREE_VIEW_ACCESSIBLE (parent))
3271 accessible = GTK_TREE_VIEW_ACCESSIBLE (parent);
3273 tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
3275 /* Find this cell in the GtkTreeViewAccessible's cache */
3276 info = find_cell_info (accessible, cell, TRUE);
3280 cell_info_get_index (tree_view, info, &index);
3281 cell->index = index;
3282 g_hash_table_insert (accessible->cell_info_by_index, &index, info);
3286 connect_model_signals (GtkTreeView *view,
3287 GtkTreeViewAccessible *accessible)
3291 obj = G_OBJECT (accessible->tree_model);
3292 g_signal_connect_data (obj, "row-changed",
3293 G_CALLBACK (model_row_changed), view, NULL, 0);
3294 g_signal_connect_data (obj, "row-inserted",
3295 G_CALLBACK (model_row_inserted), view, NULL,
3297 g_signal_connect_data (obj, "row-deleted",
3298 G_CALLBACK (model_row_deleted), view, NULL,
3300 g_signal_connect_data (obj, "rows-reordered",
3301 G_CALLBACK (model_rows_reordered), view, NULL,
3306 disconnect_model_signals (GtkTreeViewAccessible *accessible)
3311 obj = G_OBJECT (accessible->tree_model);
3312 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
3313 g_signal_handlers_disconnect_by_func (obj, model_row_changed, widget);
3314 g_signal_handlers_disconnect_by_func (obj, model_row_inserted, widget);
3315 g_signal_handlers_disconnect_by_func (obj, model_row_deleted, widget);
3316 g_signal_handlers_disconnect_by_func (obj, model_rows_reordered, widget);
3320 clear_cached_data (GtkTreeViewAccessible *accessible)
3322 GtkTreeViewAccessibleCellInfo *cell_info;
3323 GHashTableIter iter;
3325 /* Must loop through them all */
3326 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
3327 while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cell_info))
3328 clean_cell_info (accessible, cell_info);
3330 /* FIXME: seems pretty inefficient to loop again here */
3331 garbage_collect_cell_data (accessible);
3334 /* Returns the column number of the specified GtkTreeViewColumn
3336 * If visible is set, the value returned will be the visible column number,
3337 * i.e. suitable for use in AtkTable function. If visible is not set, the
3338 * value returned is the actual column number, which is suitable for use in
3339 * getting an index value.
3342 get_column_number (GtkTreeView *tree_view,
3343 GtkTreeViewColumn *column,
3346 GtkTreeViewColumn *tv_column;
3350 GtkTreeViewAccessible *accessible;
3352 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
3353 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
3356 for (i = 0; i < accessible->col_data->len; i++)
3358 tv_column = g_array_index (accessible->col_data, GtkTreeViewColumn *, i);
3359 if (tv_column == column)
3361 if (!visible || gtk_tree_view_column_get_visible (tv_column))
3364 if (i == accessible->col_data->len)
3371 get_index (GtkTreeView *tree_view,
3376 GtkTreeViewAccessible *accessible;
3379 gint *indices = NULL;
3381 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
3382 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
3386 depth = gtk_tree_path_get_depth (path);
3387 indices = gtk_tree_path_get_indices (path);
3392 GtkTreePath *copy_path;
3393 GtkTreeModel *model;
3395 model = gtk_tree_view_get_model (tree_view);
3396 copy_path = gtk_tree_path_copy (path);
3397 gtk_tree_path_up (copy_path);
3398 count_rows (model, NULL, copy_path, &index, 0, depth);
3399 gtk_tree_path_free (copy_path);
3403 index += indices[depth - 1];
3404 index *= accessible->n_cols;
3405 index += actual_column;
3409 /* The function count_rows counts the number of rows starting at iter
3410 * and ending at end_path. The value of level is the depth of iter and
3411 * the value of depth is the depth of end_path. Rows at depth before
3412 * end_path are counted. This functions counts rows which are not visible
3413 * because an ancestor is collapsed.
3416 count_rows (GtkTreeModel *model,
3418 GtkTreePath *end_path,
3423 GtkTreeIter child_iter;
3429 *count += gtk_tree_model_iter_n_children (model, iter);
3431 if (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY)
3437 if (gtk_tree_model_iter_children (model, &child_iter, iter))
3439 gboolean ret_val = TRUE;
3443 if (level == depth - 1)
3445 GtkTreePath *iter_path;
3446 gboolean finished = FALSE;
3448 iter_path = gtk_tree_model_get_path (model, &child_iter);
3449 if (end_path && gtk_tree_path_compare (iter_path, end_path) >= 0)
3451 gtk_tree_path_free (iter_path);
3455 if (gtk_tree_model_iter_has_child (model, &child_iter))
3456 count_rows (model, &child_iter, end_path, count, level, depth);
3457 ret_val = gtk_tree_model_iter_next (model, &child_iter);
3462 /* Find the next node, which has children, at the specified depth below
3463 * the specified iter. The level is the depth of the current iter.
3464 * The position of the node is returned in path and the return value
3465 * of TRUE means that a node was found.
3469 get_next_node_with_child_at_depth (GtkTreeModel *model,
3475 GtkTreeIter child_iter;
3479 if (gtk_tree_model_iter_children (model, &child_iter, iter))
3485 while (!gtk_tree_model_iter_has_child (model, &child_iter))
3487 if (!gtk_tree_model_iter_next (model, &child_iter))
3493 /* We have found what we were looking for */
3494 *path = gtk_tree_model_get_path (model, &child_iter);
3498 if (get_next_node_with_child_at_depth (model, &child_iter, path,
3502 if (!gtk_tree_model_iter_next (model, &child_iter))
3509 /* Find the next node, which has children, at the same depth
3510 * as the specified GtkTreePath.
3513 get_next_node_with_child (GtkTreeModel *model,
3515 GtkTreePath **return_path)
3520 gtk_tree_model_get_iter (model, &iter, path);
3522 while (gtk_tree_model_iter_next (model, &iter))
3524 if (gtk_tree_model_iter_has_child (model, &iter))
3526 *return_path = gtk_tree_model_get_path (model, &iter);
3530 depth = gtk_tree_path_get_depth (path);
3531 while (gtk_tree_path_up (path))
3533 if (gtk_tree_path_get_depth (path) == 0)
3536 gtk_tree_model_get_iter (model, &iter, path);
3537 while (gtk_tree_model_iter_next (model, &iter))
3538 if (get_next_node_with_child_at_depth (model, &iter, return_path,
3539 gtk_tree_path_get_depth (path), depth))
3542 *return_path = NULL;
3547 get_tree_path_from_row_index (GtkTreeModel *model,
3549 GtkTreePath **tree_path)
3555 count = gtk_tree_model_iter_n_children (model, NULL);
3556 if (count > row_index)
3558 if (gtk_tree_model_iter_nth_child (model, &iter, NULL, row_index))
3560 *tree_path = gtk_tree_model_get_path (model, &iter);
3574 if (get_next_node_with_child_at_depth (model, NULL, tree_path, 0, depth))
3576 GtkTreePath *next_path;
3580 gtk_tree_model_get_iter (model, &iter, *tree_path);
3581 count = gtk_tree_model_iter_n_children (model, &iter);
3582 if (count > row_index)
3584 gtk_tree_path_append_index (*tree_path, row_index);
3590 if (!get_next_node_with_child (model, *tree_path, &next_path))
3593 gtk_tree_path_free (*tree_path);
3594 *tree_path = next_path;
3599 g_warning ("Index value is too large\n");
3600 gtk_tree_path_free (*tree_path);
3608 get_path_column_from_index (GtkTreeView *tree_view,
3611 GtkTreeViewColumn **column)
3613 GtkTreeModel *tree_model;
3615 GtkTreeViewAccessible *accessible;
3617 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
3618 accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
3620 tree_model = gtk_tree_view_get_model (tree_view);
3621 if (accessible->n_cols == 0)
3623 /* First row is the column headers */
3624 index -= accessible->n_cols;
3633 row_index = index / accessible->n_cols;
3634 retval = get_tree_path_from_row_index (tree_model, row_index, path);
3643 *column = gtk_tree_view_get_column (tree_view, index % accessible->n_cols);
3644 if (*column == NULL)
3647 gtk_tree_path_free (*path);
3655 set_cell_expandable (GtkCellAccessible *cell)
3657 if (_gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDABLE, FALSE))
3658 _gtk_cell_accessible_add_action (cell,
3659 "expand or contract",
3660 "expands or contracts the row in the tree view containing this cell",
3661 NULL, toggle_cell_expanded);
3664 static GtkTreeViewAccessibleCellInfo *
3665 find_cell_info (GtkTreeViewAccessible *accessible,
3666 GtkCellAccessible *cell,
3669 GtkTreeViewAccessibleCellInfo *cell_info;
3670 GHashTableIter iter;
3672 /* Clean GtkTreeViewAccessibleCellInfo data */
3673 g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
3674 while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cell_info))
3676 if (cell_info->cell == cell && (!live_only || cell_info->in_use))
3683 get_header_from_column (GtkTreeViewColumn *tv_col)
3686 GtkWidget *header_widget;
3691 header_widget = gtk_tree_view_column_get_button (tv_col);
3694 rc = gtk_widget_get_accessible (header_widget);