2007-12-18 13:51:12 +00:00
|
|
|
/* GAIL - The GNOME Accessibility Implementation Library
|
|
|
|
* Copyright 2001, 2002, 2003 Sun Microsystems Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2007-12-23 12:27:33 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#ifdef GDK_WINDOWING_X11
|
|
|
|
#include <gdk/x11/gdkx.h>
|
|
|
|
#endif
|
2011-06-30 00:50:50 +00:00
|
|
|
#include "gtktreeviewaccessible.h"
|
2011-07-09 23:19:38 +00:00
|
|
|
#include "gtkrenderercellaccessible.h"
|
2011-07-09 23:02:42 +00:00
|
|
|
#include "gtkbooleancellaccessible.h"
|
2011-07-10 02:59:15 +00:00
|
|
|
#include "gtkimagecellaccessible.h"
|
2011-07-09 22:51:27 +00:00
|
|
|
#include "gtkcontainercellaccessible.h"
|
2007-12-18 13:51:12 +00:00
|
|
|
#include "gailtextcell.h"
|
|
|
|
#include "gailcellparent.h"
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
typedef struct _GtkTreeViewAccessibleCellInfo GtkTreeViewAccessibleCellInfo;
|
|
|
|
struct _GtkTreeViewAccessibleCellInfo
|
|
|
|
{
|
2011-07-09 22:30:59 +00:00
|
|
|
GtkCellAccessible *cell;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeRowReference *cell_row_ref;
|
|
|
|
GtkTreeViewColumn *cell_col_ref;
|
|
|
|
GtkTreeViewAccessible *view;
|
|
|
|
gboolean in_use;
|
|
|
|
};
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
/* signal handling */
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static gboolean row_expanded_cb (GtkTreeView *tree_view,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreePath *path);
|
|
|
|
static gboolean row_collapsed_cb (GtkTreeView *tree_view,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreePath *path);
|
|
|
|
static void size_allocate_cb (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation);
|
|
|
|
static void selection_changed_cb (GtkTreeSelection *selection,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static void columns_changed (GtkTreeView *tree_view);
|
|
|
|
static void cursor_changed (GtkTreeView *tree_view);
|
|
|
|
static gboolean focus_in (GtkWidget *widget);
|
|
|
|
static gboolean focus_out (GtkWidget *widget);
|
|
|
|
|
|
|
|
static void column_visibility_changed
|
|
|
|
(GObject *object,
|
|
|
|
GParamSpec *param,
|
|
|
|
gpointer user_data);
|
|
|
|
static void destroy_count_func (GtkTreeView *tree_view,
|
|
|
|
GtkTreePath *path,
|
|
|
|
gint count,
|
|
|
|
gpointer user_data);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
/* Misc */
|
|
|
|
|
|
|
|
static void set_iter_nth_row (GtkTreeView *tree_view,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gint row);
|
|
|
|
static gint get_row_from_tree_path (GtkTreeView *tree_view,
|
|
|
|
GtkTreePath *path);
|
|
|
|
static GtkTreeViewColumn* get_column (GtkTreeView *tree_view,
|
|
|
|
gint in_col);
|
|
|
|
static gint get_actual_column_number (GtkTreeView *tree_view,
|
|
|
|
gint visible_column);
|
|
|
|
static gint get_visible_column_number (GtkTreeView *tree_view,
|
|
|
|
gint actual_column);
|
2011-06-30 00:50:50 +00:00
|
|
|
static void iterate_thru_children (GtkTreeView *tree_view,
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreePath *tree_path,
|
|
|
|
GtkTreePath *orig,
|
|
|
|
gint *count,
|
|
|
|
gint depth);
|
2011-06-30 00:50:50 +00:00
|
|
|
static void clean_rows (GtkTreeViewAccessible *tree_view);
|
|
|
|
static void clean_cols (GtkTreeViewAccessible *tree_view,
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeViewColumn *tv_col);
|
2011-06-30 00:50:50 +00:00
|
|
|
static void traverse_cells (GtkTreeViewAccessible *tree_view,
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreePath *tree_path,
|
|
|
|
gboolean set_stale,
|
|
|
|
gboolean inc_row);
|
2011-07-09 23:19:38 +00:00
|
|
|
static gboolean update_cell_value (GtkRendererCellAccessible *renderer_cell,
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible,
|
2007-12-18 13:51:12 +00:00
|
|
|
gboolean emit_change_signal);
|
|
|
|
static void set_cell_visibility (GtkTreeView *tree_view,
|
2011-07-09 22:30:59 +00:00
|
|
|
GtkCellAccessible *cell,
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeViewColumn *tv_col,
|
|
|
|
GtkTreePath *tree_path,
|
|
|
|
gboolean emit_signal);
|
|
|
|
static gboolean is_cell_showing (GtkTreeView *tree_view,
|
|
|
|
GdkRectangle *cell_rect);
|
|
|
|
static void set_expand_state (GtkTreeView *tree_view,
|
|
|
|
GtkTreeModel *tree_model,
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible,
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreePath *tree_path,
|
|
|
|
gboolean set_on_ancestor);
|
2011-07-09 22:30:59 +00:00
|
|
|
static void set_cell_expandable (GtkCellAccessible *cell);
|
|
|
|
static void add_cell_actions (GtkCellAccessible *cell,
|
2007-12-18 13:51:12 +00:00
|
|
|
gboolean editable);
|
|
|
|
|
2011-07-09 22:30:59 +00:00
|
|
|
static void toggle_cell_toggled (GtkCellAccessible *cell);
|
|
|
|
static void edit_cell (GtkCellAccessible *cell);
|
|
|
|
static void activate_cell (GtkCellAccessible *cell);
|
2007-12-18 13:51:12 +00:00
|
|
|
static void cell_destroyed (gpointer data);
|
2011-06-30 00:50:50 +00:00
|
|
|
static void cell_info_new (GtkTreeViewAccessible *accessible,
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeViewColumn *tv_col,
|
2011-07-09 22:30:59 +00:00
|
|
|
GtkCellAccessible *cell);
|
|
|
|
static GtkCellAccessible *find_cell (GtkTreeViewAccessible *accessible,
|
2007-12-18 13:51:12 +00:00
|
|
|
gint index);
|
2011-07-09 22:30:59 +00:00
|
|
|
static void refresh_cell_index (GtkCellAccessible *cell);
|
2007-12-18 13:51:12 +00:00
|
|
|
static void connect_model_signals (GtkTreeView *view,
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible);
|
|
|
|
static void disconnect_model_signals (GtkTreeViewAccessible *accessible);
|
|
|
|
static void clear_cached_data (GtkTreeViewAccessible *view);
|
2007-12-18 13:51:12 +00:00
|
|
|
static gint get_column_number (GtkTreeView *tree_view,
|
|
|
|
GtkTreeViewColumn *column,
|
2011-06-30 00:50:50 +00:00
|
|
|
gboolean visible);
|
2007-12-18 13:51:12 +00:00
|
|
|
static gint get_focus_index (GtkTreeView *tree_view);
|
|
|
|
static gint get_index (GtkTreeView *tree_view,
|
|
|
|
GtkTreePath *path,
|
|
|
|
gint actual_column);
|
|
|
|
static void count_rows (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreePath *end_path,
|
|
|
|
gint *count,
|
|
|
|
gint level,
|
|
|
|
gint depth);
|
|
|
|
|
|
|
|
static gboolean get_path_column_from_index (GtkTreeView *tree_view,
|
|
|
|
gint index,
|
|
|
|
GtkTreePath **path,
|
|
|
|
GtkTreeViewColumn **column);
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static GtkTreeViewAccessibleCellInfo* find_cell_info (GtkTreeViewAccessible *view,
|
2011-07-09 22:30:59 +00:00
|
|
|
GtkCellAccessible *cell,
|
2011-06-30 00:50:50 +00:00
|
|
|
gboolean live_only);
|
2007-12-18 13:51:12 +00:00
|
|
|
static AtkObject * get_header_from_column (GtkTreeViewColumn *tv_col);
|
|
|
|
static gboolean idle_garbage_collect_cell_data (gpointer data);
|
|
|
|
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static void atk_table_interface_init (AtkTableIface *iface);
|
|
|
|
static void atk_selection_interface_init (AtkSelectionIface *iface);
|
|
|
|
static void atk_component_interface_init (AtkComponentIface *iface);
|
|
|
|
static void gail_cell_parent_interface_init (GailCellParentIface *iface);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-07-09 20:32:40 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkTreeViewAccessible, _gtk_tree_view_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
|
2007-12-23 12:24:59 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (ATK_TYPE_TABLE, atk_table_interface_init)
|
|
|
|
G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init)
|
|
|
|
G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init)
|
|
|
|
G_IMPLEMENT_INTERFACE (GAIL_TYPE_CELL_PARENT, gail_cell_parent_interface_init))
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
|
2007-12-23 12:24:59 +00:00
|
|
|
static void
|
2011-06-30 00:50:50 +00:00
|
|
|
adjustment_changed (GtkAdjustment *adjustment,
|
|
|
|
GtkWidget *widget)
|
2007-12-23 12:24:59 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible;
|
|
|
|
|
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
|
|
|
|
traverse_cells (accessible, NULL, FALSE, FALSE);
|
2007-12-23 12:24:59 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 04:21:39 +00:00
|
|
|
static void
|
2011-06-30 00:50:50 +00:00
|
|
|
hadjustment_set_cb (GObject *widget,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer data)
|
2010-10-18 04:21:39 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible = data;
|
2010-10-18 04:21:39 +00:00
|
|
|
GtkAdjustment *adj;
|
|
|
|
|
|
|
|
g_object_get (widget, "hadjustment", &adj, NULL);
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible->old_hadj = adj;
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (accessible->old_hadj), (gpointer *)&accessible->old_hadj);
|
|
|
|
g_signal_connect (adj, "value-changed", G_CALLBACK (adjustment_changed), widget);
|
2010-10-18 04:21:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-30 00:50:50 +00:00
|
|
|
vadjustment_set_cb (GObject *widget,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer data)
|
2010-10-18 04:21:39 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible = data;
|
2010-10-18 04:21:39 +00:00
|
|
|
GtkAdjustment *adj;
|
|
|
|
|
|
|
|
g_object_get (widget, "vadjustment", &adj, NULL);
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible->old_vadj = adj;
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (accessible->old_vadj), (gpointer *)&accessible->old_vadj);
|
|
|
|
g_signal_connect (adj, "value-changed",
|
|
|
|
G_CALLBACK (adjustment_changed), widget);
|
2010-10-18 04:21:39 +00:00
|
|
|
}
|
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
static void
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_view_accessible_initialize (AtkObject *obj,
|
|
|
|
gpointer data)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeView *tree_view;
|
2010-10-22 17:28:32 +00:00
|
|
|
GtkTreeModel *tree_model;
|
2007-12-18 13:51:12 +00:00
|
|
|
GList *tv_cols, *tmp_list;
|
|
|
|
GtkWidget *widget;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeSelection *selection;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-07-09 20:32:40 +00:00
|
|
|
ATK_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->initialize (obj, data);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
|
|
|
|
accessible->col_data = NULL;
|
|
|
|
accessible->focus_cell = NULL;
|
|
|
|
accessible->old_hadj = NULL;
|
|
|
|
accessible->old_vadj = NULL;
|
|
|
|
accessible->idle_expand_id = 0;
|
|
|
|
accessible->idle_expand_path = NULL;
|
|
|
|
accessible->n_children_deleted = 0;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible->cell_info_by_index = g_hash_table_new (g_int_hash, g_int_equal);
|
2011-06-23 02:27:10 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
widget = GTK_WIDGET (data);
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
tree_model = gtk_tree_view_get_model (tree_view);
|
2011-06-30 00:50:50 +00:00
|
|
|
selection = gtk_tree_view_get_selection (tree_view);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
g_signal_connect_after (widget, "row-collapsed",
|
|
|
|
G_CALLBACK (row_collapsed_cb), NULL);
|
|
|
|
g_signal_connect (widget, "row-expanded",
|
|
|
|
G_CALLBACK (row_expanded_cb), NULL);
|
|
|
|
g_signal_connect (widget, "size-allocate",
|
|
|
|
G_CALLBACK (size_allocate_cb), NULL);
|
|
|
|
g_signal_connect (selection, "changed",
|
|
|
|
G_CALLBACK (selection_changed_cb), obj);
|
|
|
|
|
|
|
|
g_signal_connect (tree_view, "columns-changed",
|
|
|
|
G_CALLBACK (columns_changed), NULL);
|
|
|
|
g_signal_connect (tree_view, "cursor-changed",
|
|
|
|
G_CALLBACK (cursor_changed), NULL);
|
|
|
|
g_signal_connect (tree_view, "focus-in-event",
|
|
|
|
G_CALLBACK (focus_in), NULL);
|
|
|
|
g_signal_connect (tree_view, "focus-out-event",
|
|
|
|
G_CALLBACK (focus_out), NULL);
|
|
|
|
|
|
|
|
accessible->tree_model = tree_model;
|
|
|
|
accessible->n_rows = 0;
|
|
|
|
accessible->n_cols = 0;
|
2007-12-18 13:51:12 +00:00
|
|
|
if (tree_model)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (accessible->tree_model), (gpointer *)&accessible->tree_model);
|
|
|
|
count_rows (tree_model, NULL, NULL, &accessible->n_rows, 0, G_MAXINT);
|
|
|
|
connect_model_signals (tree_view, accessible);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2010-08-10 01:09:30 +00:00
|
|
|
if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
|
2007-12-18 13:51:12 +00:00
|
|
|
obj->role = ATK_ROLE_TABLE;
|
2010-08-10 01:09:30 +00:00
|
|
|
else
|
|
|
|
obj->role = ATK_ROLE_TREE_TABLE;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
hadjustment_set_cb (G_OBJECT (widget), NULL, accessible);
|
|
|
|
vadjustment_set_cb (G_OBJECT (widget), NULL, accessible);
|
|
|
|
g_signal_connect (widget, "notify::hadjustment",
|
|
|
|
G_CALLBACK (hadjustment_set_cb), accessible);
|
|
|
|
g_signal_connect (widget, "notify::vadjustment",
|
|
|
|
G_CALLBACK (vadjustment_set_cb), accessible);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible->col_data = g_array_sized_new (FALSE, TRUE,
|
|
|
|
sizeof (GtkTreeViewColumn *), 0);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
tv_cols = gtk_tree_view_get_columns (tree_view);
|
|
|
|
for (tmp_list = tv_cols; tmp_list; tmp_list = tmp_list->next)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible->n_cols++;
|
|
|
|
g_signal_connect (tmp_list->data, "notify::visible",
|
|
|
|
G_CALLBACK (column_visibility_changed), tree_view);
|
|
|
|
g_array_append_val (accessible->col_data, tmp_list->data);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2011-06-30 00:50:50 +00:00
|
|
|
g_list_free (tv_cols);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_view_set_destroy_count_func (tree_view,
|
2007-12-18 13:51:12 +00:00
|
|
|
destroy_count_func,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_view_accessible_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkTreeViewAccessible *accessible = GTK_TREE_VIEW_ACCESSIBLE (object);
|
|
|
|
|
|
|
|
clear_cached_data (accessible);
|
|
|
|
|
|
|
|
/* remove any idle handlers still pending */
|
|
|
|
if (accessible->idle_garbage_collect_id)
|
|
|
|
g_source_remove (accessible->idle_garbage_collect_id);
|
|
|
|
if (accessible->idle_cursor_changed_id)
|
|
|
|
g_source_remove (accessible->idle_cursor_changed_id);
|
|
|
|
if (accessible->idle_expand_id)
|
|
|
|
g_source_remove (accessible->idle_expand_id);
|
|
|
|
|
|
|
|
if (accessible->tree_model)
|
|
|
|
disconnect_model_signals (accessible);
|
|
|
|
|
|
|
|
if (accessible->cell_info_by_index)
|
|
|
|
g_hash_table_destroy (accessible->cell_info_by_index);
|
|
|
|
|
|
|
|
if (accessible->col_data)
|
|
|
|
{
|
|
|
|
GArray *array = accessible->col_data;
|
|
|
|
|
|
|
|
/* No need to free the contents of the array since it
|
|
|
|
* just contains pointers to the GtkTreeViewColumn
|
|
|
|
* objects that are in the GtkTreeView.
|
|
|
|
*/
|
|
|
|
g_array_free (array, TRUE);
|
|
|
|
}
|
|
|
|
|
2011-07-09 20:32:40 +00:00
|
|
|
G_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->finalize (object);
|
2011-06-30 00:50:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_view_accessible_notify_gtk (GObject *obj,
|
|
|
|
GParamSpec *pspec)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeView *tree_view;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkAdjustment *adj;
|
|
|
|
|
|
|
|
widget = GTK_WIDGET (obj);
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
|
2007-12-18 13:51:12 +00:00
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
|
|
|
|
if (strcmp (pspec->name, "model") == 0)
|
|
|
|
{
|
|
|
|
GtkTreeModel *tree_model;
|
|
|
|
AtkRole role;
|
|
|
|
|
|
|
|
tree_model = gtk_tree_view_get_model (tree_view);
|
2011-06-30 00:50:50 +00:00
|
|
|
if (accessible->tree_model)
|
|
|
|
disconnect_model_signals (accessible);
|
|
|
|
clear_cached_data (accessible);
|
|
|
|
accessible->tree_model = tree_model;
|
|
|
|
accessible->n_rows = 0;
|
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
if (tree_model)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (accessible->tree_model), (gpointer *)&accessible->tree_model);
|
|
|
|
count_rows (tree_model, NULL, NULL, &accessible->n_rows, 0, G_MAXINT);
|
|
|
|
connect_model_signals (tree_view, accessible);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2010-08-10 01:09:30 +00:00
|
|
|
if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
|
2007-12-18 13:51:12 +00:00
|
|
|
role = ATK_ROLE_TABLE;
|
2010-08-10 01:09:30 +00:00
|
|
|
else
|
|
|
|
role = ATK_ROLE_TREE_TABLE;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
role = ATK_ROLE_UNKNOWN;
|
|
|
|
}
|
2011-06-30 00:50:50 +00:00
|
|
|
atk_object_set_role (ATK_OBJECT (accessible), role);
|
|
|
|
g_object_freeze_notify (G_OBJECT (accessible));
|
|
|
|
g_signal_emit_by_name (accessible, "model_changed");
|
|
|
|
g_signal_emit_by_name (accessible, "visible_data_changed");
|
|
|
|
g_object_thaw_notify (G_OBJECT (accessible));
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2010-10-18 04:21:39 +00:00
|
|
|
else if (strcmp (pspec->name, "hadjustment") == 0)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2010-10-18 04:21:39 +00:00
|
|
|
g_object_get (tree_view, "hadjustment", &adj, NULL);
|
2011-06-30 00:50:50 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (accessible->old_hadj,
|
|
|
|
(gpointer) adjustment_changed,
|
|
|
|
widget);
|
|
|
|
accessible->old_hadj = adj;
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (accessible->old_hadj), (gpointer *)&accessible->old_hadj);
|
|
|
|
g_signal_connect (adj, "value-changed", G_CALLBACK (adjustment_changed), tree_view);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2010-10-18 04:21:39 +00:00
|
|
|
else if (strcmp (pspec->name, "vadjustment") == 0)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2010-10-18 04:21:39 +00:00
|
|
|
g_object_get (tree_view, "vadjustment", &adj, NULL);
|
2011-06-30 00:50:50 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (accessible->old_vadj,
|
|
|
|
(gpointer) adjustment_changed,
|
|
|
|
widget);
|
|
|
|
accessible->old_vadj = adj;
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (accessible->old_hadj), (gpointer *)&accessible->old_vadj);
|
|
|
|
g_signal_connect (adj, "value-changed", G_CALLBACK (adjustment_changed), tree_view);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
else
|
2011-07-09 20:32:40 +00:00
|
|
|
GTK_WIDGET_ACCESSIBLE_CLASS (_gtk_tree_view_accessible_parent_class)->notify_gtk (obj, pspec);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_view_accessible_destroyed (GtkWidget *widget,
|
|
|
|
GtkAccessible *gtk_accessible)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkAdjustment *adj;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-29 03:42:50 +00:00
|
|
|
if (!GTK_IS_TREE_VIEW (widget))
|
|
|
|
return;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_accessible);
|
|
|
|
adj = accessible->old_hadj;
|
2007-12-18 13:51:12 +00:00
|
|
|
if (adj)
|
2011-06-30 00:50:50 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (adj,
|
2007-12-18 13:51:12 +00:00
|
|
|
(gpointer) adjustment_changed,
|
|
|
|
widget);
|
2011-06-30 00:50:50 +00:00
|
|
|
adj = accessible->old_vadj;
|
2007-12-18 13:51:12 +00:00
|
|
|
if (adj)
|
2011-06-30 00:50:50 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (adj,
|
2007-12-18 13:51:12 +00:00
|
|
|
(gpointer) adjustment_changed,
|
|
|
|
widget);
|
2011-06-30 00:50:50 +00:00
|
|
|
if (accessible->tree_model)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
disconnect_model_signals (accessible);
|
|
|
|
accessible->tree_model = NULL;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2011-06-30 00:50:50 +00:00
|
|
|
if (accessible->focus_cell)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
g_object_unref (accessible->focus_cell);
|
|
|
|
accessible->focus_cell = NULL;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2011-06-30 00:50:50 +00:00
|
|
|
if (accessible->idle_expand_id)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
g_source_remove (accessible->idle_expand_id);
|
|
|
|
accessible->idle_expand_id = 0;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static void
|
|
|
|
gtk_tree_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkWidget *widget;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
widget = gtk_accessible_get_widget (accessible);
|
|
|
|
if (widget)
|
|
|
|
g_signal_connect_after (widget, "destroy",
|
|
|
|
G_CALLBACK (gtk_tree_view_accessible_destroyed), accessible);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-07-09 20:32:40 +00:00
|
|
|
GTK_ACCESSIBLE_CLASS (_gtk_tree_view_accessible_parent_class)->connect_widget_destroyed (accessible);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_view_accessible_get_n_children (AtkObject *obj)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
|
|
|
|
return (accessible->n_rows + 1) * accessible->n_cols;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static AtkObject *
|
|
|
|
gtk_tree_view_accessible_ref_child (AtkObject *obj,
|
|
|
|
gint i)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible;
|
2011-07-09 22:30:59 +00:00
|
|
|
GtkCellAccessible *cell;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeView *tree_view;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeModel *tree_model;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeViewColumn *tv_col;
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkTreePath *path;
|
|
|
|
AtkObject *child;
|
|
|
|
AtkObject *parent;
|
|
|
|
GtkTreeViewColumn *expander_tv;
|
|
|
|
GList *renderer_list;
|
|
|
|
GList *l;
|
2011-07-09 22:51:27 +00:00
|
|
|
GtkContainerCellAccessible *container = NULL;
|
2011-07-09 23:19:38 +00:00
|
|
|
GtkRendererCellAccessible *renderer_cell;
|
2007-12-18 13:51:12 +00:00
|
|
|
gboolean is_expander, is_expanded, retval;
|
|
|
|
gboolean editable = FALSE;
|
|
|
|
gint focus_index;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
if (i >= gtk_tree_view_accessible_get_n_children (obj))
|
2007-12-18 13:51:12 +00:00
|
|
|
return NULL;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (obj);
|
2007-12-18 13:51:12 +00:00
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
2011-06-30 00:50:50 +00:00
|
|
|
if (i < accessible->n_cols)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
tv_col = gtk_tree_view_get_column (tree_view, i);
|
|
|
|
child = get_header_from_column (tv_col);
|
|
|
|
if (child)
|
|
|
|
g_object_ref (child);
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Check whether the child is cached */
|
|
|
|
cell = find_cell (accessible, i);
|
2007-12-18 13:51:12 +00:00
|
|
|
if (cell)
|
|
|
|
{
|
|
|
|
g_object_ref (cell);
|
|
|
|
return ATK_OBJECT (cell);
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
if (accessible->focus_cell == NULL)
|
2007-12-18 13:51:12 +00:00
|
|
|
focus_index = get_focus_index (tree_view);
|
|
|
|
else
|
|
|
|
focus_index = -1;
|
2011-06-30 00:50:50 +00:00
|
|
|
|
|
|
|
/* Find the TreePath and GtkTreeViewColumn for the index */
|
2007-12-18 13:51:12 +00:00
|
|
|
if (!get_path_column_from_index (tree_view, i, &path, &tv_col))
|
|
|
|
return NULL;
|
2011-06-30 00:50:50 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
tree_model = gtk_tree_view_get_model (tree_view);
|
|
|
|
retval = gtk_tree_model_get_iter (tree_model, &iter, path);
|
2011-06-29 03:42:50 +00:00
|
|
|
if (!retval)
|
|
|
|
return NULL;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
expander_tv = gtk_tree_view_get_expander_column (tree_view);
|
|
|
|
is_expander = FALSE;
|
|
|
|
is_expanded = FALSE;
|
|
|
|
if (gtk_tree_model_iter_has_child (tree_model, &iter))
|
|
|
|
{
|
|
|
|
if (expander_tv == tv_col)
|
|
|
|
{
|
|
|
|
is_expander = TRUE;
|
|
|
|
is_expanded = gtk_tree_view_row_expanded (tree_view, path);
|
|
|
|
}
|
2011-06-30 00:50:50 +00:00
|
|
|
}
|
|
|
|
gtk_tree_view_column_cell_set_cell_data (tv_col, tree_model, &iter,
|
2007-12-18 13:51:12 +00:00
|
|
|
is_expander, is_expanded);
|
|
|
|
|
2009-06-16 15:48:16 +00:00
|
|
|
renderer_list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* If there are more than one renderer in the list,
|
|
|
|
* make a container
|
|
|
|
*/
|
2007-12-18 13:51:12 +00:00
|
|
|
if (renderer_list && renderer_list->next)
|
|
|
|
{
|
2011-07-09 22:30:59 +00:00
|
|
|
GtkCellAccessible *container_cell;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-07-09 22:51:27 +00:00
|
|
|
container = _gtk_container_cell_accessible_new ();
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-07-09 22:30:59 +00:00
|
|
|
container_cell = GTK_CELL_ACCESSIBLE (container);
|
|
|
|
_gtk_cell_accessible_initialise (container_cell, widget, ATK_OBJECT (accessible), i);
|
2011-06-30 00:50:50 +00:00
|
|
|
|
|
|
|
/* The GtkTreeViewAccessibleCellInfo structure for the container will
|
|
|
|
* be before the ones for the cells so that the first one we find for
|
|
|
|
* a position will be for the container
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
2011-06-30 00:50:50 +00:00
|
|
|
cell_info_new (accessible, tree_model, path, tv_col, container_cell);
|
2007-12-18 13:51:12 +00:00
|
|
|
container_cell->refresh_index = refresh_cell_index;
|
|
|
|
parent = ATK_OBJECT (container);
|
|
|
|
}
|
|
|
|
else
|
2011-06-30 00:50:50 +00:00
|
|
|
parent = ATK_OBJECT (accessible);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
child = NULL;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Now we make a fake cell_renderer if there is no cell
|
|
|
|
* in renderer_list
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
|
|
|
if (renderer_list == NULL)
|
2011-06-30 00:50:50 +00:00
|
|
|
{
|
|
|
|
GtkCellRenderer *fake_renderer;
|
|
|
|
|
|
|
|
fake_renderer = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, NULL);
|
2011-07-03 16:40:40 +00:00
|
|
|
child = gail_text_cell_new ();
|
2011-07-09 22:30:59 +00:00
|
|
|
cell = GTK_CELL_ACCESSIBLE (child);
|
2011-07-09 23:19:38 +00:00
|
|
|
renderer_cell = GTK_RENDERER_CELL_ACCESSIBLE (child);
|
2011-06-30 00:50:50 +00:00
|
|
|
renderer_cell->renderer = fake_renderer;
|
|
|
|
|
|
|
|
/* Create the GtkTreeViewAccessibleCellInfo structure for this cell */
|
|
|
|
cell_info_new (accessible, tree_model, path, tv_col, cell);
|
|
|
|
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_initialise (cell, widget, parent, i);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
cell->refresh_index = refresh_cell_index;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Set state if it is expandable */
|
|
|
|
if (is_expander)
|
|
|
|
{
|
|
|
|
set_cell_expandable (cell);
|
|
|
|
if (is_expanded)
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, FALSE);
|
2011-06-30 00:50:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (l = renderer_list; l; l = l->next)
|
|
|
|
{
|
|
|
|
renderer = GTK_CELL_RENDERER (l->data);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
if (GTK_IS_CELL_RENDERER_TEXT (renderer))
|
2011-07-03 16:40:40 +00:00
|
|
|
{
|
|
|
|
g_object_get (G_OBJECT (renderer), "editable", &editable, NULL);
|
|
|
|
child = gail_text_cell_new ();
|
|
|
|
}
|
|
|
|
else if (GTK_IS_CELL_RENDERER_TOGGLE (renderer))
|
2011-07-09 23:02:42 +00:00
|
|
|
child = _gtk_boolean_cell_accessible_new ();
|
2011-07-03 16:40:40 +00:00
|
|
|
else if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
|
2011-07-10 02:59:15 +00:00
|
|
|
child = _gtk_image_cell_accessible_new ();
|
2011-07-03 16:40:40 +00:00
|
|
|
else
|
2011-07-09 23:19:38 +00:00
|
|
|
child = _gtk_renderer_cell_accessible_new ();
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-07-09 22:30:59 +00:00
|
|
|
cell = GTK_CELL_ACCESSIBLE (child);
|
2011-07-09 23:19:38 +00:00
|
|
|
renderer_cell = GTK_RENDERER_CELL_ACCESSIBLE (child);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Create the GtkTreeViewAccessibleCellInfo for this cell */
|
|
|
|
cell_info_new (accessible, tree_model, path, tv_col, cell);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_initialise (cell, widget, parent, i);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
if (container)
|
2011-07-09 22:51:27 +00:00
|
|
|
_gtk_container_cell_accessible_add_child (container, cell);
|
2011-06-30 00:50:50 +00:00
|
|
|
else
|
|
|
|
cell->refresh_index = refresh_cell_index;
|
|
|
|
|
|
|
|
update_cell_value (renderer_cell, accessible, FALSE);
|
|
|
|
|
|
|
|
/* Add the actions appropriate for this cell */
|
|
|
|
add_cell_actions (cell, editable);
|
|
|
|
|
|
|
|
/* Set state if it is expandable */
|
|
|
|
if (is_expander)
|
|
|
|
{
|
|
|
|
set_cell_expandable (cell);
|
|
|
|
if (is_expanded)
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, FALSE);
|
2011-06-30 00:50:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If the column is visible, sets the cell's state */
|
|
|
|
if (gtk_tree_view_column_get_visible (tv_col))
|
|
|
|
set_cell_visibility (tree_view, cell, tv_col, path, FALSE);
|
|
|
|
|
|
|
|
/* If the row is selected, all cells on the row are selected */
|
|
|
|
selection = gtk_tree_view_get_selection (tree_view);
|
|
|
|
|
|
|
|
if (gtk_tree_selection_path_is_selected (selection, path))
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_add_state (cell, ATK_STATE_SELECTED, FALSE);
|
2011-06-30 00:50:50 +00:00
|
|
|
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_add_state (cell, ATK_STATE_FOCUSABLE, FALSE);
|
2011-06-30 00:50:50 +00:00
|
|
|
if (focus_index == i)
|
|
|
|
{
|
|
|
|
accessible->focus_cell = g_object_ref (cell);
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_add_state (cell, ATK_STATE_FOCUSED, FALSE);
|
2011-06-30 00:50:50 +00:00
|
|
|
g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_list_free (renderer_list);
|
|
|
|
if (container)
|
|
|
|
child = ATK_OBJECT (container);
|
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
if (expander_tv == tv_col)
|
|
|
|
{
|
|
|
|
AtkRelationSet *relation_set;
|
|
|
|
AtkObject *accessible_array[1];
|
|
|
|
AtkRelation* relation;
|
|
|
|
AtkObject *parent_node;
|
|
|
|
|
|
|
|
relation_set = atk_object_ref_relation_set (ATK_OBJECT (child));
|
|
|
|
|
|
|
|
gtk_tree_path_up (path);
|
|
|
|
if (gtk_tree_path_get_depth (path) == 0)
|
|
|
|
parent_node = obj;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gint parent_index;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
parent_index = get_index (tree_view, path, i % accessible->n_cols);
|
2007-12-18 13:51:12 +00:00
|
|
|
parent_node = atk_object_ref_accessible_child (obj, parent_index);
|
|
|
|
}
|
|
|
|
accessible_array[0] = parent_node;
|
|
|
|
relation = atk_relation_new (accessible_array, 1,
|
|
|
|
ATK_RELATION_NODE_CHILD_OF);
|
|
|
|
atk_relation_set_add (relation_set, relation);
|
2011-06-30 00:50:50 +00:00
|
|
|
atk_object_add_relationship (parent_node, ATK_RELATION_NODE_PARENT_OF, child);
|
2007-12-18 13:51:12 +00:00
|
|
|
g_object_unref (relation);
|
|
|
|
g_object_unref (relation_set);
|
|
|
|
}
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* We do not increase the reference count here; when g_object_unref()
|
|
|
|
* is called for the cell then cell_destroyed() is called and this
|
|
|
|
* removes the cell from the cache.
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
static AtkStateSet*
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_view_accessible_ref_state_set (AtkObject *obj)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
AtkStateSet *state_set;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
2011-07-09 20:32:40 +00:00
|
|
|
state_set = ATK_OBJECT_CLASS (_gtk_tree_view_accessible_parent_class)->ref_state_set (obj);
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
if (widget != NULL)
|
|
|
|
atk_state_set_add_state (state_set, ATK_STATE_MANAGES_DESCENDANTS);
|
|
|
|
|
|
|
|
return state_set;
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static void
|
2011-07-09 20:32:40 +00:00
|
|
|
_gtk_tree_view_accessible_class_init (GtkTreeViewAccessibleClass *klass)
|
2011-06-30 00:50:50 +00:00
|
|
|
{
|
|
|
|
AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2011-07-02 19:23:52 +00:00
|
|
|
GtkAccessibleClass *accessible_class = (GtkAccessibleClass*)klass;
|
|
|
|
GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
|
|
|
|
GtkContainerAccessibleClass *container_class = (GtkContainerAccessibleClass*)klass;
|
2011-06-30 00:50:50 +00:00
|
|
|
|
|
|
|
class->get_n_children = gtk_tree_view_accessible_get_n_children;
|
|
|
|
class->ref_child = gtk_tree_view_accessible_ref_child;
|
|
|
|
class->ref_state_set = gtk_tree_view_accessible_ref_state_set;
|
|
|
|
class->initialize = gtk_tree_view_accessible_initialize;
|
|
|
|
|
|
|
|
widget_class->notify_gtk = gtk_tree_view_accessible_notify_gtk;
|
|
|
|
|
|
|
|
accessible_class->connect_widget_destroyed = gtk_tree_view_accessible_connect_widget_destroyed;
|
|
|
|
|
|
|
|
/* The children of a GtkTreeView are the buttons at the top of the columns
|
|
|
|
* we do not represent these as children so we do not want to report
|
|
|
|
* children added or deleted when these changed.
|
|
|
|
*/
|
|
|
|
container_class->add_gtk = NULL;
|
|
|
|
container_class->remove_gtk = NULL;
|
|
|
|
|
|
|
|
gobject_class->finalize = gtk_tree_view_accessible_finalize;
|
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
static void
|
2011-07-09 20:32:40 +00:00
|
|
|
_gtk_tree_view_accessible_init (GtkTreeViewAccessible *view)
|
2011-06-30 00:50:50 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
get_focus_index (GtkTreeView *tree_view)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreePath *focus_path;
|
|
|
|
GtkTreeViewColumn *focus_column;
|
|
|
|
gint index;
|
|
|
|
|
|
|
|
gtk_tree_view_get_cursor (tree_view, &focus_path, &focus_column);
|
|
|
|
if (focus_path && focus_column)
|
|
|
|
index = get_index (tree_view, focus_path,
|
|
|
|
get_column_number (tree_view, focus_column, FALSE));
|
|
|
|
else
|
|
|
|
index = -1;
|
|
|
|
|
|
|
|
if (focus_path)
|
|
|
|
gtk_tree_path_free (focus_path);
|
|
|
|
|
|
|
|
return index;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* This function returns a reference to the accessible object
|
|
|
|
* for the cell in the treeview which has focus, if any
|
|
|
|
*/
|
2011-07-09 20:32:40 +00:00
|
|
|
static AtkObject *
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_view_accessible_ref_focus_cell (GtkTreeView *tree_view)
|
|
|
|
{
|
|
|
|
AtkObject *focus_cell = NULL;
|
|
|
|
AtkObject *atk_obj;
|
|
|
|
gint focus_index;
|
|
|
|
|
|
|
|
focus_index = get_focus_index (tree_view);
|
|
|
|
if (focus_index >= 0)
|
|
|
|
{
|
|
|
|
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
|
|
|
|
focus_cell = atk_object_ref_accessible_child (atk_obj, focus_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return focus_cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* atkcomponent.h */
|
|
|
|
|
|
|
|
static AtkObject *
|
|
|
|
gtk_tree_view_accessible_ref_accessible_at_point (AtkComponent *component,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
AtkCoordType coord_type)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeViewColumn *tv_column;
|
|
|
|
gint x_pos, y_pos;
|
2009-02-25 09:55:14 +00:00
|
|
|
gint bx, by;
|
2007-12-18 13:51:12 +00:00
|
|
|
gboolean ret_val;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
|
|
|
|
atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
|
2009-02-25 09:55:14 +00:00
|
|
|
gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, x, y, &bx, &by);
|
2011-06-30 00:50:50 +00:00
|
|
|
ret_val = gtk_tree_view_get_path_at_pos (tree_view,
|
|
|
|
bx - x_pos, by - y_pos,
|
2007-12-18 13:51:12 +00:00
|
|
|
&path, &tv_column, NULL, NULL);
|
|
|
|
if (ret_val)
|
|
|
|
{
|
|
|
|
gint index, column;
|
|
|
|
|
|
|
|
column = get_column_number (tree_view, tv_column, FALSE);
|
|
|
|
index = get_index (tree_view, path, column);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
return gtk_tree_view_accessible_ref_child (ATK_OBJECT (component), index);
|
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
else
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
g_warning ("gtk_tree_view_accessible_ref_accessible_at_point: gtk_tree_view_get_path_at_pos () failed\n");
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static void
|
|
|
|
atk_component_interface_init (AtkComponentIface *iface)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
iface->ref_accessible_at_point = gtk_tree_view_accessible_ref_accessible_at_point;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* atktable.h */
|
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
static gint
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_view_accessible_get_index_at (AtkTable *table,
|
|
|
|
gint row,
|
|
|
|
gint column)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
gint actual_column;
|
|
|
|
gint n_cols, n_rows;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *path;
|
|
|
|
gint index;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
|
|
|
|
if (widget == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
n_cols = atk_table_get_n_columns (table);
|
|
|
|
n_rows = atk_table_get_n_rows (table);
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
if (row >= n_rows || column >= n_cols)
|
2007-12-18 13:51:12 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
actual_column = get_actual_column_number (tree_view, column);
|
|
|
|
|
|
|
|
set_iter_nth_row (tree_view, &iter, row);
|
|
|
|
path = gtk_tree_model_get_path (gtk_tree_view_get_model (tree_view), &iter);
|
|
|
|
|
|
|
|
index = get_index (tree_view, path, actual_column);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_view_accessible_get_column_at_index (AtkTable *table,
|
|
|
|
gint index)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
gint n_columns;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
2011-06-30 00:50:50 +00:00
|
|
|
n_columns = GTK_TREE_VIEW_ACCESSIBLE (table)->n_cols;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
if (n_columns == 0)
|
|
|
|
return 0;
|
2011-06-30 00:50:50 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
index = index % n_columns;
|
|
|
|
|
|
|
|
return get_visible_column_number (tree_view, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_view_accessible_get_row_at_index (AtkTable *table,
|
|
|
|
gint index)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
if (get_path_column_from_index (tree_view, index, &path, NULL))
|
|
|
|
{
|
|
|
|
gint row = get_row_from_tree_path (tree_view, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static AtkObject *
|
|
|
|
gtk_tree_view_accessible_table_ref_at (AtkTable *table,
|
|
|
|
gint row,
|
|
|
|
gint column)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
gint index;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
index = gtk_tree_view_accessible_get_index_at (table, row, column);
|
2007-12-18 13:51:12 +00:00
|
|
|
if (index == -1)
|
|
|
|
return NULL;
|
2011-06-30 00:50:50 +00:00
|
|
|
|
|
|
|
return gtk_tree_view_accessible_ref_child (ATK_OBJECT (table), index);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static gint
|
|
|
|
gtk_tree_view_accessible_get_n_rows (AtkTable *table)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkTreeModel *tree_model;
|
|
|
|
gint n_rows;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
tree_model = gtk_tree_view_get_model (tree_view);
|
|
|
|
|
2011-06-21 22:53:06 +00:00
|
|
|
if (!tree_model)
|
|
|
|
n_rows = 0;
|
|
|
|
else if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
|
2011-06-30 00:50:50 +00:00
|
|
|
/* No collapsed rows in a list store */
|
|
|
|
n_rows = GTK_TREE_VIEW_ACCESSIBLE (table)->n_rows;
|
2007-12-18 13:51:12 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkTreePath *root_tree;
|
|
|
|
|
|
|
|
n_rows = 0;
|
2008-12-09 14:49:34 +00:00
|
|
|
root_tree = gtk_tree_path_new_first ();
|
2007-12-18 13:51:12 +00:00
|
|
|
iterate_thru_children (tree_view, tree_model,
|
|
|
|
root_tree, NULL, &n_rows, 0);
|
2008-01-11 09:22:25 +00:00
|
|
|
gtk_tree_path_free (root_tree);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return n_rows;
|
|
|
|
}
|
|
|
|
|
2011-06-23 02:27:10 +00:00
|
|
|
static gint
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_view_accessible_get_n_columns (AtkTable *table)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkTreeViewColumn *tv_col;
|
|
|
|
gint n_cols = 0;
|
|
|
|
gint i = 0;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
tv_col = gtk_tree_view_get_column (tree_view, i);
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
while (tv_col != NULL)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
if (gtk_tree_view_column_get_visible (tv_col))
|
2007-12-18 13:51:12 +00:00
|
|
|
n_cols++;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
tv_col = gtk_tree_view_get_column (tree_view, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return n_cols;
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_tree_view_accessible_is_row_selected (AtkTable *table,
|
|
|
|
gint row)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (row < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
selection = gtk_tree_view_get_selection (tree_view);
|
|
|
|
|
|
|
|
set_iter_nth_row (tree_view, &iter, row);
|
|
|
|
return gtk_tree_selection_iter_is_selected (selection, &iter);
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_tree_view_accessible_is_selected (AtkTable *table,
|
|
|
|
gint row,
|
|
|
|
gint column)
|
|
|
|
{
|
|
|
|
return gtk_tree_view_accessible_is_row_selected (table, row);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_selected_rows (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GPtrArray *array = (GPtrArray *)data;
|
|
|
|
|
|
|
|
g_ptr_array_add (array, gtk_tree_path_copy (path));
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static gint
|
|
|
|
gtk_tree_view_accessible_get_selected_rows (AtkTable *table,
|
|
|
|
gint **rows_selected)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkTreeModel *tree_model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkTreePath *tree_path;
|
|
|
|
gint ret_val = 0;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
selection = gtk_tree_view_get_selection (tree_view);
|
|
|
|
|
2010-12-20 11:51:39 +00:00
|
|
|
switch (gtk_tree_selection_get_mode (selection))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
case GTK_SELECTION_SINGLE:
|
|
|
|
case GTK_SELECTION_BROWSE:
|
|
|
|
if (gtk_tree_selection_get_selected (selection, &tree_model, &iter))
|
|
|
|
{
|
|
|
|
gint row;
|
|
|
|
|
|
|
|
if (rows_selected)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
*rows_selected = g_new (gint, 1);
|
2007-12-18 13:51:12 +00:00
|
|
|
tree_path = gtk_tree_model_get_path (tree_model, &iter);
|
|
|
|
row = get_row_from_tree_path (tree_view, tree_path);
|
|
|
|
gtk_tree_path_free (tree_path);
|
|
|
|
|
|
|
|
/* shouldn't ever happen */
|
|
|
|
g_return_val_if_fail (row != -1, 0);
|
|
|
|
|
|
|
|
*rows_selected[0] = row;
|
|
|
|
}
|
|
|
|
ret_val = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GTK_SELECTION_MULTIPLE:
|
|
|
|
{
|
|
|
|
GPtrArray *array = g_ptr_array_new();
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_selection_selected_foreach (selection, get_selected_rows, array);
|
2007-12-18 13:51:12 +00:00
|
|
|
ret_val = array->len;
|
|
|
|
|
|
|
|
if (rows_selected && ret_val)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
*rows_selected = g_new (gint, ret_val);
|
2007-12-18 13:51:12 +00:00
|
|
|
for (i = 0; i < ret_val; i++)
|
|
|
|
{
|
|
|
|
gint row;
|
|
|
|
|
|
|
|
tree_path = (GtkTreePath *) g_ptr_array_index (array, i);
|
|
|
|
row = get_row_from_tree_path (tree_view, tree_path);
|
|
|
|
gtk_tree_path_free (tree_path);
|
|
|
|
(*rows_selected)[i] = row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_ptr_array_free (array, FALSE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GTK_SELECTION_NONE:
|
2011-06-30 00:50:50 +00:00
|
|
|
break;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
return ret_val;
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_tree_view_accessible_add_row_selection (AtkTable *table,
|
|
|
|
gint row)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkTreeModel *tree_model;
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkTreePath *tree_path;
|
|
|
|
GtkTreeIter iter_to_row;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return FALSE;
|
2011-06-30 00:50:50 +00:00
|
|
|
|
|
|
|
if (!gtk_tree_view_accessible_is_row_selected (table, row))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
tree_model = gtk_tree_view_get_model (tree_view);
|
|
|
|
selection = gtk_tree_view_get_selection (tree_view);
|
|
|
|
|
|
|
|
if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
|
|
|
|
{
|
|
|
|
tree_path = gtk_tree_path_new ();
|
|
|
|
gtk_tree_path_append_index (tree_path, row);
|
|
|
|
gtk_tree_selection_select_path (selection,tree_path);
|
|
|
|
gtk_tree_path_free (tree_path);
|
|
|
|
}
|
|
|
|
else
|
2011-06-30 00:50:50 +00:00
|
|
|
{
|
2007-12-18 13:51:12 +00:00
|
|
|
set_iter_nth_row (tree_view, &iter_to_row, row);
|
2011-01-30 07:14:08 +00:00
|
|
|
gtk_tree_selection_select_iter (selection, &iter_to_row);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
return gtk_tree_view_accessible_is_row_selected (table, row);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_tree_view_accessible_remove_row_selection (AtkTable *table,
|
|
|
|
gint row)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
selection = gtk_tree_view_get_selection (tree_view);
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
if (gtk_tree_view_accessible_is_row_selected (table, row))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
gtk_tree_selection_unselect_all (selection);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2011-06-30 00:50:50 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static AtkObject *
|
|
|
|
gtk_tree_view_accessible_get_column_header (AtkTable *table,
|
|
|
|
gint in_col)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkTreeViewColumn *tv_col;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
tv_col = get_column (tree_view, in_col);
|
|
|
|
return get_header_from_column (tv_col);
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static const gchar *
|
|
|
|
gtk_tree_view_accessible_get_column_description (AtkTable *table,
|
|
|
|
gint in_col)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkTreeViewColumn *tv_col;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
tv_col = get_column (tree_view, in_col);
|
|
|
|
if (tv_col == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
return gtk_tree_view_column_get_title (tv_col);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static void
|
|
|
|
atk_table_interface_init (AtkTableIface *iface)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
iface->ref_at = gtk_tree_view_accessible_table_ref_at;
|
|
|
|
iface->get_n_rows = gtk_tree_view_accessible_get_n_rows;
|
|
|
|
iface->get_n_columns = gtk_tree_view_accessible_get_n_columns;
|
|
|
|
iface->get_index_at = gtk_tree_view_accessible_get_index_at;
|
|
|
|
iface->get_column_at_index = gtk_tree_view_accessible_get_column_at_index;
|
|
|
|
iface->get_row_at_index = gtk_tree_view_accessible_get_row_at_index;
|
|
|
|
iface->is_row_selected = gtk_tree_view_accessible_is_row_selected;
|
|
|
|
iface->is_selected = gtk_tree_view_accessible_is_selected;
|
|
|
|
iface->get_selected_rows = gtk_tree_view_accessible_get_selected_rows;
|
|
|
|
iface->add_row_selection = gtk_tree_view_accessible_add_row_selection;
|
|
|
|
iface->remove_row_selection = gtk_tree_view_accessible_remove_row_selection;
|
|
|
|
iface->get_column_extent_at = NULL;
|
|
|
|
iface->get_row_extent_at = NULL;
|
|
|
|
iface->get_column_header = gtk_tree_view_accessible_get_column_header;
|
|
|
|
iface->get_column_description = gtk_tree_view_accessible_get_column_description;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* atkselection.h */
|
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
static gboolean
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_view_accessible_add_selection (AtkSelection *selection,
|
|
|
|
gint i)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
AtkTable *table;
|
|
|
|
gint n_columns;
|
|
|
|
gint row;
|
|
|
|
|
|
|
|
table = ATK_TABLE (selection);
|
2011-06-30 00:50:50 +00:00
|
|
|
n_columns = gtk_tree_view_accessible_get_n_columns (table);
|
2007-12-18 13:51:12 +00:00
|
|
|
if (n_columns != 1)
|
|
|
|
return FALSE;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
row = gtk_tree_view_accessible_get_row_at_index (table, i);
|
|
|
|
return gtk_tree_view_accessible_add_row_selection (table, row);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_view_accessible_clear_selection (AtkSelection *selection)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkTreeSelection *tree_selection;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
2007-12-18 13:51:12 +00:00
|
|
|
tree_selection = gtk_tree_view_get_selection (tree_view);
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_selection_unselect_all (tree_selection);
|
2007-12-18 13:51:12 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static AtkObject *
|
|
|
|
gtk_tree_view_accessible_ref_selection (AtkSelection *selection,
|
|
|
|
gint i)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
AtkTable *table;
|
|
|
|
gint row;
|
|
|
|
gint n_selected;
|
|
|
|
gint n_columns;
|
|
|
|
gint *selected;
|
|
|
|
|
|
|
|
table = ATK_TABLE (selection);
|
2011-06-30 00:50:50 +00:00
|
|
|
n_columns = gtk_tree_view_accessible_get_n_columns (table);
|
|
|
|
n_selected = gtk_tree_view_accessible_get_selected_rows (table, &selected);
|
2007-12-18 13:51:12 +00:00
|
|
|
if (i >= n_columns * n_selected)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
row = selected[i / n_columns];
|
|
|
|
g_free (selected);
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
return gtk_tree_view_accessible_table_ref_at (table, row, i % n_columns);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_view_accessible_get_selection_count (AtkSelection *selection)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
AtkTable *table;
|
|
|
|
gint n_selected;
|
|
|
|
|
|
|
|
table = ATK_TABLE (selection);
|
2011-06-30 00:50:50 +00:00
|
|
|
n_selected = gtk_tree_view_accessible_get_selected_rows (table, NULL);
|
2007-12-18 13:51:12 +00:00
|
|
|
if (n_selected > 0)
|
2011-06-30 00:50:50 +00:00
|
|
|
n_selected *= gtk_tree_view_accessible_get_n_columns (table);
|
2007-12-18 13:51:12 +00:00
|
|
|
return n_selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_view_accessible_is_child_selected (AtkSelection *selection,
|
|
|
|
gint i)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
gint row;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
row = atk_table_get_row_at_index (ATK_TABLE (selection), i);
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
return gtk_tree_view_accessible_is_row_selected (ATK_TABLE (selection), row);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static void atk_selection_interface_init (AtkSelectionIface *iface)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
iface->add_selection = gtk_tree_view_accessible_add_selection;
|
|
|
|
iface->clear_selection = gtk_tree_view_accessible_clear_selection;
|
|
|
|
iface->ref_selection = gtk_tree_view_accessible_ref_selection;
|
|
|
|
iface->get_selection_count = gtk_tree_view_accessible_get_selection_count;
|
|
|
|
iface->is_child_selected = gtk_tree_view_accessible_is_child_selected;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define EXTRA_EXPANDER_PADDING 4
|
|
|
|
|
|
|
|
static void
|
2011-07-09 22:30:59 +00:00
|
|
|
gtk_tree_view_accessible_get_cell_area (GailCellParent *parent,
|
|
|
|
GtkCellAccessible *cell,
|
|
|
|
GdkRectangle *cell_rect)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkTreeViewColumn *tv_col;
|
|
|
|
GtkTreePath *path;
|
|
|
|
AtkObject *parent_cell;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info;
|
2011-07-09 22:30:59 +00:00
|
|
|
GtkCellAccessible *top_cell;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
parent_cell = atk_object_get_parent (ATK_OBJECT (cell));
|
|
|
|
if (parent_cell != ATK_OBJECT (parent))
|
2011-07-09 22:30:59 +00:00
|
|
|
top_cell = GTK_CELL_ACCESSIBLE (parent_cell);
|
2007-12-18 13:51:12 +00:00
|
|
|
else
|
2011-07-09 22:30:59 +00:00
|
|
|
top_cell = cell;
|
2011-06-30 00:50:50 +00:00
|
|
|
cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), top_cell, TRUE);
|
2011-06-29 03:42:50 +00:00
|
|
|
if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
|
|
|
|
return;
|
2007-12-18 13:51:12 +00:00
|
|
|
path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
|
|
|
|
tv_col = cell_info->cell_col_ref;
|
|
|
|
if (path && cell_info->in_use)
|
|
|
|
{
|
|
|
|
GtkTreeViewColumn *expander_column;
|
|
|
|
gint focus_line_width;
|
|
|
|
|
|
|
|
gtk_tree_view_get_cell_area (tree_view, path, tv_col, cell_rect);
|
|
|
|
expander_column = gtk_tree_view_get_expander_column (tree_view);
|
|
|
|
if (expander_column == tv_col)
|
|
|
|
{
|
|
|
|
gint expander_size;
|
|
|
|
gtk_widget_style_get (widget,
|
|
|
|
"expander_size", &expander_size,
|
|
|
|
NULL);
|
|
|
|
cell_rect->x += expander_size + EXTRA_EXPANDER_PADDING;
|
|
|
|
cell_rect->width -= expander_size + EXTRA_EXPANDER_PADDING;
|
|
|
|
}
|
|
|
|
gtk_widget_style_get (widget,
|
|
|
|
"focus-line-width", &focus_line_width,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
cell_rect->x += focus_line_width;
|
2011-06-30 00:50:50 +00:00
|
|
|
cell_rect->width -= 2 * focus_line_width;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* A column has more than one renderer so we find the position
|
|
|
|
* and width of each
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
|
|
|
if (top_cell != cell)
|
|
|
|
{
|
|
|
|
gint cell_index;
|
|
|
|
gboolean found;
|
|
|
|
gint cell_start;
|
|
|
|
gint cell_width;
|
|
|
|
GList *renderers;
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
cell_index = atk_object_get_index_in_parent (ATK_OBJECT (cell));
|
|
|
|
renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
|
|
|
|
renderer = g_list_nth_data (renderers, cell_index);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
found = gtk_tree_view_column_cell_get_position (tv_col, renderer, &cell_start, &cell_width);
|
2007-12-18 13:51:12 +00:00
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
cell_rect->x += cell_start;
|
|
|
|
cell_rect->width = cell_width;
|
|
|
|
}
|
2011-06-30 00:50:50 +00:00
|
|
|
g_list_free (renderers);
|
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static void
|
2011-07-09 22:30:59 +00:00
|
|
|
gtk_tree_view_accessible_get_cell_extents (GailCellParent *parent,
|
|
|
|
GtkCellAccessible *cell,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gint *width,
|
|
|
|
gint *height,
|
|
|
|
AtkCoordType coord_type)
|
2011-06-30 00:50:50 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GdkWindow *bin_window;
|
|
|
|
GdkRectangle cell_rect;
|
|
|
|
gint w_x, w_y;
|
|
|
|
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
|
|
|
|
if (widget == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
gtk_tree_view_accessible_get_cell_area (parent, cell, &cell_rect);
|
|
|
|
bin_window = gtk_tree_view_get_bin_window (tree_view);
|
|
|
|
gdk_window_get_origin (bin_window, &w_x, &w_y);
|
|
|
|
|
|
|
|
if (coord_type == ATK_XY_WINDOW)
|
|
|
|
{
|
|
|
|
GdkWindow *window;
|
|
|
|
gint x_toplevel, y_toplevel;
|
|
|
|
|
|
|
|
window = gdk_window_get_toplevel (bin_window);
|
|
|
|
gdk_window_get_origin (window, &x_toplevel, &y_toplevel);
|
|
|
|
|
|
|
|
w_x -= x_toplevel;
|
|
|
|
w_y -= y_toplevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
*width = cell_rect.width;
|
|
|
|
*height = cell_rect.height;
|
|
|
|
if (is_cell_showing (tree_view, &cell_rect))
|
|
|
|
{
|
|
|
|
*x = cell_rect.x + w_x;
|
|
|
|
*y = cell_rect.y + w_y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*x = G_MININT;
|
|
|
|
*y = G_MININT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
static gboolean
|
2011-07-09 22:30:59 +00:00
|
|
|
gtk_tree_view_accessible_grab_cell_focus (GailCellParent *parent,
|
|
|
|
GtkCellAccessible *cell)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkTreeViewColumn *tv_col;
|
|
|
|
GtkTreePath *path;
|
|
|
|
AtkObject *parent_cell;
|
|
|
|
AtkObject *cell_object;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkCellRenderer *renderer = NULL;
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
gint index;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
|
2011-06-29 03:42:50 +00:00
|
|
|
if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
|
|
|
|
return FALSE;
|
2007-12-18 13:51:12 +00:00
|
|
|
cell_object = ATK_OBJECT (cell);
|
|
|
|
parent_cell = atk_object_get_parent (cell_object);
|
|
|
|
tv_col = cell_info->cell_col_ref;
|
|
|
|
if (parent_cell != ATK_OBJECT (parent))
|
|
|
|
{
|
2011-07-09 22:51:27 +00:00
|
|
|
/* GtkCellAccessible is in a GtkContainerCellAccessible.
|
2011-06-30 00:50:50 +00:00
|
|
|
* The GtkTreeViewColumn has multiple renderers;
|
2007-12-18 13:51:12 +00:00
|
|
|
* find the corresponding one.
|
|
|
|
*/
|
|
|
|
GList *renderers;
|
|
|
|
|
2009-06-16 16:37:33 +00:00
|
|
|
renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col));
|
2011-06-30 00:50:50 +00:00
|
|
|
if (cell_info->in_use)
|
|
|
|
{
|
|
|
|
index = atk_object_get_index_in_parent (cell_object);
|
|
|
|
renderer = g_list_nth_data (renderers, index);
|
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
g_list_free (renderers);
|
|
|
|
}
|
|
|
|
path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
|
|
|
|
if (path && cell_info->in_use)
|
|
|
|
{
|
|
|
|
if (renderer)
|
|
|
|
gtk_tree_view_set_cursor_on_cell (tree_view, path, tv_col, renderer, FALSE);
|
|
|
|
else
|
|
|
|
gtk_tree_view_set_cursor (tree_view, path, tv_col, FALSE);
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
gtk_widget_grab_focus (widget);
|
|
|
|
toplevel = gtk_widget_get_toplevel (widget);
|
2010-01-04 06:49:26 +00:00
|
|
|
if (gtk_widget_is_toplevel (toplevel))
|
2011-06-30 00:50:50 +00:00
|
|
|
{
|
2007-12-18 13:51:12 +00:00
|
|
|
#ifdef GDK_WINDOWING_X11
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_window_present_with_time (GTK_WINDOW (toplevel),
|
2010-08-15 17:45:13 +00:00
|
|
|
gdk_x11_get_server_time (gtk_widget_get_window (widget)));
|
2007-12-18 13:51:12 +00:00
|
|
|
#else
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_window_present (GTK_WINDOW (toplevel));
|
2007-12-18 13:51:12 +00:00
|
|
|
#endif
|
2011-06-30 00:50:50 +00:00
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
2011-06-30 00:50:50 +00:00
|
|
|
return FALSE;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static void gail_cell_parent_interface_init (GailCellParentIface *iface)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
iface->get_cell_extents = gtk_tree_view_accessible_get_cell_extents;
|
|
|
|
iface->get_cell_area = gtk_tree_view_accessible_get_cell_area;
|
|
|
|
iface->grab_focus = gtk_tree_view_accessible_grab_cell_focus;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* signal handling */
|
|
|
|
|
|
|
|
static gboolean
|
2007-12-18 13:51:12 +00:00
|
|
|
idle_expand_row (gpointer data)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible = data;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeModel *tree_model;
|
|
|
|
gint n_inserted, row;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible->idle_expand_id = 0;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
path = accessible->idle_expand_path;
|
|
|
|
tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
tree_model = gtk_tree_view_get_model (tree_view);
|
2007-12-22 20:18:13 +00:00
|
|
|
if (!tree_model)
|
|
|
|
return FALSE;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
if (!path || !gtk_tree_model_get_iter (tree_model, &iter, path))
|
2007-12-22 20:18:13 +00:00
|
|
|
return FALSE;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Update visibility of cells below expansion row */
|
|
|
|
traverse_cells (accessible, path, FALSE, FALSE);
|
|
|
|
|
|
|
|
/* Figure out number of visible children, the following test
|
2007-12-18 13:51:12 +00:00
|
|
|
* should not fail
|
|
|
|
*/
|
|
|
|
if (gtk_tree_model_iter_has_child (tree_model, &iter))
|
|
|
|
{
|
|
|
|
GtkTreePath *path_copy;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* By passing path into this function, we find the number of
|
|
|
|
* visible children of path.
|
|
|
|
*/
|
2007-12-18 13:51:12 +00:00
|
|
|
path_copy = gtk_tree_path_copy (path);
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_path_append_index (path_copy, 0);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
n_inserted = 0;
|
|
|
|
iterate_thru_children (tree_view, tree_model,
|
|
|
|
path_copy, NULL, &n_inserted, 0);
|
|
|
|
gtk_tree_path_free (path_copy);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We can get here if the row expanded callback deleted the row */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set expand state */
|
2011-06-30 00:50:50 +00:00
|
|
|
set_expand_state (tree_view, tree_model, accessible, path, TRUE);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
row = get_row_from_tree_path (tree_view, path);
|
|
|
|
|
|
|
|
/* shouldn't ever happen */
|
|
|
|
if (row == -1)
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
|
|
|
/* Must add 1 because the "added rows" are below the row being expanded */
|
|
|
|
row += 1;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
g_signal_emit_by_name (accessible, "row_inserted", row, n_inserted);
|
|
|
|
|
|
|
|
accessible->idle_expand_path = NULL;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-06-30 00:50:50 +00:00
|
|
|
row_expanded_cb (GtkTreeView *tree_view,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreePath *path)
|
|
|
|
{
|
|
|
|
AtkObject *atk_obj;
|
|
|
|
GtkTreeViewAccessible *accessible;
|
|
|
|
|
|
|
|
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
|
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The visible rectangle has not been updated when this signal is emitted
|
|
|
|
* so we process the signal when the GTK processing is completed
|
|
|
|
*/
|
|
|
|
/* this seems wrong since it overwrites any other pending expand handlers... */
|
|
|
|
accessible->idle_expand_path = gtk_tree_path_copy (path);
|
|
|
|
if (accessible->idle_expand_id)
|
|
|
|
g_source_remove (accessible->idle_expand_id);
|
|
|
|
accessible->idle_expand_id = gdk_threads_add_idle (idle_expand_row, accessible);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
row_collapsed_cb (GtkTreeView *tree_view,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreePath *path)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkTreeModel *tree_model;
|
2011-06-30 00:50:50 +00:00
|
|
|
AtkObject *atk_obj;
|
|
|
|
GtkTreeViewAccessible *accessible;
|
2007-12-18 13:51:12 +00:00
|
|
|
gint row;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
|
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
|
2007-12-18 13:51:12 +00:00
|
|
|
tree_model = gtk_tree_view_get_model (tree_view);
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
clean_rows (accessible);
|
|
|
|
|
|
|
|
/* Update visibility of cells below collapsed row */
|
|
|
|
traverse_cells (accessible, path, FALSE, FALSE);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
/* Set collapse state */
|
2011-06-30 00:50:50 +00:00
|
|
|
set_expand_state (tree_view, tree_model, accessible, path, FALSE);
|
|
|
|
if (accessible->n_children_deleted == 0)
|
2011-06-29 03:42:50 +00:00
|
|
|
return FALSE;
|
2007-12-18 13:51:12 +00:00
|
|
|
row = get_row_from_tree_path (tree_view, path);
|
2011-06-29 03:42:50 +00:00
|
|
|
if (row == -1)
|
|
|
|
return FALSE;
|
2011-06-30 00:50:50 +00:00
|
|
|
g_signal_emit_by_name (atk_obj, "row_deleted", row,
|
|
|
|
accessible->n_children_deleted);
|
|
|
|
accessible->n_children_deleted = 0;
|
2007-12-18 13:51:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-30 00:50:50 +00:00
|
|
|
size_allocate_cb (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
AtkObject *atk_obj;
|
|
|
|
GtkTreeViewAccessible *accessible;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
atk_obj = gtk_widget_get_accessible (widget);
|
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
|
|
|
|
|
|
|
|
/* If the size allocation changes, the visibility of cells
|
|
|
|
* may change so update the cells visibility.
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
2011-06-30 00:50:50 +00:00
|
|
|
traverse_cells (accessible, NULL, FALSE, FALSE);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-30 00:50:50 +00:00
|
|
|
selection_changed_cb (GtkTreeSelection *selection,
|
|
|
|
gpointer data)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkWidget *widget;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessibleCellInfo *info;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeSelection *tree_selection;
|
|
|
|
GtkTreePath *path;
|
2011-06-23 02:27:10 +00:00
|
|
|
GHashTableIter iter;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (data);
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
2007-12-18 13:51:12 +00:00
|
|
|
tree_selection = gtk_tree_view_get_selection (tree_view);
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
clean_rows (accessible);
|
2008-12-12 06:12:27 +00:00
|
|
|
|
2011-06-23 02:27:10 +00:00
|
|
|
/* FIXME: clean rows iterates through all cells too */
|
2011-06-30 00:50:50 +00:00
|
|
|
g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
|
2011-06-23 02:27:10 +00:00
|
|
|
while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&info))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
if (info->in_use)
|
2011-06-30 00:50:50 +00:00
|
|
|
{
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_remove_state (info->cell, ATK_STATE_SELECTED, TRUE);
|
2011-06-30 00:50:50 +00:00
|
|
|
|
|
|
|
path = gtk_tree_row_reference_get_path (info->cell_row_ref);
|
|
|
|
if (path && gtk_tree_selection_path_is_selected (tree_selection, path))
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_add_state (info->cell, ATK_STATE_SELECTED, TRUE);
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2010-03-02 06:16:02 +00:00
|
|
|
if (gtk_widget_get_realized (widget))
|
2011-06-30 00:50:50 +00:00
|
|
|
g_signal_emit_by_name (accessible, "selection_changed");
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
columns_changed (GtkTreeView *tree_view)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
AtkObject *atk_obj;
|
|
|
|
GtkTreeViewAccessible *accessible;
|
2007-12-18 13:51:12 +00:00
|
|
|
GList *tv_cols, *tmp_list;
|
|
|
|
gboolean column_found;
|
|
|
|
gboolean move_found = FALSE;
|
|
|
|
gboolean stale_set = FALSE;
|
|
|
|
gint column_count = 0;
|
|
|
|
gint i;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
atk_obj = gtk_widget_get_accessible (GTK_WIDGET(tree_view));
|
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
|
|
|
|
|
|
|
|
/* This function must determine if the change is an add, delete
|
|
|
|
* or a move based upon its cache of TreeViewColumns in
|
|
|
|
* accessible->col_data
|
|
|
|
*/
|
2007-12-18 13:51:12 +00:00
|
|
|
tv_cols = gtk_tree_view_get_columns (tree_view);
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible->n_cols = g_list_length (tv_cols);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
/* check for adds or moves */
|
|
|
|
for (tmp_list = tv_cols; tmp_list; tmp_list = tmp_list->next)
|
|
|
|
{
|
|
|
|
column_found = FALSE;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
for (i = 0; i < accessible->col_data->len; i++)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if ((GtkTreeViewColumn *)tmp_list->data ==
|
2011-06-30 00:50:50 +00:00
|
|
|
(GtkTreeViewColumn *)g_array_index (accessible->col_data,
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeViewColumn *, i))
|
|
|
|
{
|
|
|
|
column_found = TRUE;
|
|
|
|
|
|
|
|
/* If the column isn't in the same position, a move happened */
|
|
|
|
if (!move_found && i != column_count)
|
|
|
|
{
|
|
|
|
if (!stale_set)
|
|
|
|
{
|
|
|
|
/* Set all rows to ATK_STATE_STALE */
|
2011-06-30 00:50:50 +00:00
|
|
|
traverse_cells (accessible, NULL, TRUE, FALSE);
|
2007-12-18 13:51:12 +00:00
|
|
|
stale_set = TRUE;
|
|
|
|
}
|
2011-06-30 00:50:50 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
/* Just emit one column reordered signal when a move happens */
|
|
|
|
g_signal_emit_by_name (atk_obj, "column_reordered");
|
|
|
|
move_found = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* If column_found is FALSE, then an insert happened for column
|
2007-12-18 13:51:12 +00:00
|
|
|
* number column_count
|
|
|
|
*/
|
|
|
|
if (!column_found)
|
|
|
|
{
|
2011-06-23 02:27:10 +00:00
|
|
|
gint row;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
if (!stale_set)
|
|
|
|
{
|
|
|
|
/* Set all rows to ATK_STATE_STALE */
|
2011-06-30 00:50:50 +00:00
|
|
|
traverse_cells (accessible, NULL, TRUE, FALSE);
|
2007-12-18 13:51:12 +00:00
|
|
|
stale_set = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate column-inserted signal */
|
|
|
|
g_signal_emit_by_name (atk_obj, "column_inserted", column_count, 1);
|
|
|
|
|
|
|
|
/* Generate children-changed signals */
|
2011-06-30 00:50:50 +00:00
|
|
|
for (row = 0; row < accessible->n_rows; row++)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Pass NULL as the child object, i.e. 4th argument */
|
2007-12-18 13:51:12 +00:00
|
|
|
g_signal_emit_by_name (atk_obj, "children_changed::add",
|
2011-06-30 00:50:50 +00:00
|
|
|
((row * accessible->n_cols) + column_count), NULL, NULL);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
column_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for deletes */
|
2011-06-30 00:50:50 +00:00
|
|
|
for (i = 0; i < accessible->col_data->len; i++)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
column_found = FALSE;
|
|
|
|
|
|
|
|
for (tmp_list = tv_cols; tmp_list; tmp_list = tmp_list->next)
|
|
|
|
{
|
|
|
|
if ((GtkTreeViewColumn *)tmp_list->data ==
|
2011-06-30 00:50:50 +00:00
|
|
|
(GtkTreeViewColumn *)g_array_index (accessible->col_data,
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeViewColumn *, i))
|
|
|
|
{
|
|
|
|
column_found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* If column_found is FALSE, then a delete happened for column
|
2007-12-18 13:51:12 +00:00
|
|
|
* number i
|
|
|
|
*/
|
|
|
|
if (!column_found)
|
|
|
|
{
|
2011-06-23 02:27:10 +00:00
|
|
|
gint row;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
clean_cols (accessible,
|
|
|
|
(GtkTreeViewColumn *)g_array_index (accessible->col_data,
|
|
|
|
GtkTreeViewColumn *, i));
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
if (!stale_set)
|
|
|
|
{
|
|
|
|
/* Set all rows to ATK_STATE_STALE */
|
2011-06-30 00:50:50 +00:00
|
|
|
traverse_cells (accessible, NULL, TRUE, FALSE);
|
2007-12-18 13:51:12 +00:00
|
|
|
stale_set = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate column-deleted signal */
|
|
|
|
g_signal_emit_by_name (atk_obj, "column_deleted", i, 1);
|
|
|
|
|
|
|
|
/* Generate children-changed signals */
|
2011-06-30 00:50:50 +00:00
|
|
|
for (row = 0; row < accessible->n_rows; row++)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Pass NULL as the child object, 4th argument */
|
2007-12-18 13:51:12 +00:00
|
|
|
g_signal_emit_by_name (atk_obj, "children_changed::remove",
|
2011-06-30 00:50:50 +00:00
|
|
|
((row * accessible->n_cols) + column_count), NULL, NULL);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* rebuild the array */
|
|
|
|
g_array_free (accessible->col_data, TRUE);
|
|
|
|
accessible->col_data = g_array_sized_new (FALSE, TRUE, sizeof (GtkTreeViewColumn *), 0);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
for (tmp_list = tv_cols; tmp_list; tmp_list = tmp_list->next)
|
2011-06-30 00:50:50 +00:00
|
|
|
g_array_append_val (accessible->col_data, tmp_list->data);
|
2007-12-18 13:51:12 +00:00
|
|
|
g_list_free (tv_cols);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
idle_cursor_changed (gpointer data)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible = GTK_TREE_VIEW_ACCESSIBLE (data);
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkWidget *widget;
|
|
|
|
AtkObject *cell;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible->idle_cursor_changed_id = 0;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
2007-12-22 20:18:13 +00:00
|
|
|
return FALSE;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
cell = gtk_tree_view_accessible_ref_focus_cell (tree_view);
|
2007-12-18 13:51:12 +00:00
|
|
|
if (cell)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
if (cell != accessible->focus_cell)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
if (accessible->focus_cell)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_ACTIVE, FALSE);
|
|
|
|
_gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_FOCUSED, FALSE);
|
2011-06-30 00:50:50 +00:00
|
|
|
g_object_unref (accessible->focus_cell);
|
|
|
|
accessible->focus_cell = cell;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2010-03-01 03:21:41 +00:00
|
|
|
if (gtk_widget_has_focus (widget))
|
2008-01-11 09:48:23 +00:00
|
|
|
{
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_ACTIVE, FALSE);
|
|
|
|
_gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_FOCUSED, FALSE);
|
2008-01-11 09:48:23 +00:00
|
|
|
}
|
2011-06-30 00:50:50 +00:00
|
|
|
|
|
|
|
g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
g_object_unref (cell);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static void
|
|
|
|
cursor_changed (GtkTreeView *tree_view)
|
|
|
|
{
|
|
|
|
GtkTreeViewAccessible *accessible;
|
|
|
|
|
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (tree_view)));
|
|
|
|
if (accessible->idle_cursor_changed_id != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* We notify the focus change in a idle handler so that the processing
|
|
|
|
* of the cursor change is completed when the focus handler is called.
|
|
|
|
* This will allow actions to be called in the focus handler
|
|
|
|
*/
|
|
|
|
accessible->idle_cursor_changed_id = gdk_threads_add_idle (idle_cursor_changed, accessible);
|
|
|
|
}
|
|
|
|
|
2010-03-04 08:30:00 +00:00
|
|
|
static gboolean
|
2008-01-11 09:58:34 +00:00
|
|
|
focus_in (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkTreeView *tree_view;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible;
|
2008-01-11 09:58:34 +00:00
|
|
|
AtkStateSet *state_set;
|
|
|
|
AtkObject *cell;
|
|
|
|
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
|
2008-01-11 09:58:34 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
if (accessible->focus_cell == NULL)
|
2008-01-11 09:58:34 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
cell = gtk_tree_view_accessible_ref_focus_cell (tree_view);
|
2008-01-11 09:58:34 +00:00
|
|
|
if (cell)
|
|
|
|
{
|
|
|
|
state_set = atk_object_ref_state_set (cell);
|
|
|
|
if (state_set)
|
|
|
|
{
|
|
|
|
if (!atk_state_set_contains_state (state_set, ATK_STATE_FOCUSED))
|
|
|
|
{
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_ACTIVE, FALSE);
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible->focus_cell = cell;
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_FOCUSED, FALSE);
|
2011-06-30 00:50:50 +00:00
|
|
|
g_signal_emit_by_name (accessible, "active-descendant-changed", cell);
|
2008-01-11 09:58:34 +00:00
|
|
|
}
|
|
|
|
g_object_unref (state_set);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-04 08:30:00 +00:00
|
|
|
return FALSE;
|
2008-01-11 09:58:34 +00:00
|
|
|
}
|
|
|
|
|
2010-03-04 08:30:00 +00:00
|
|
|
static gboolean
|
2008-01-11 09:58:34 +00:00
|
|
|
focus_out (GtkWidget *widget)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible;
|
2008-01-11 09:58:34 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget));
|
|
|
|
if (accessible->focus_cell)
|
2011-07-09 22:30:59 +00:00
|
|
|
{
|
|
|
|
_gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_ACTIVE, FALSE);
|
|
|
|
_gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (accessible->focus_cell), ATK_STATE_FOCUSED, FALSE);
|
|
|
|
g_object_unref (accessible->focus_cell);
|
|
|
|
accessible->focus_cell = NULL;
|
|
|
|
}
|
2010-03-04 08:30:00 +00:00
|
|
|
return FALSE;
|
2008-01-11 09:58:34 +00:00
|
|
|
}
|
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
static void
|
|
|
|
model_row_changed (GtkTreeModel *tree_model,
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreePath *path,
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeIter *iter,
|
2011-06-30 00:50:50 +00:00
|
|
|
gpointer user_data)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeView *tree_view = GTK_TREE_VIEW (user_data);
|
|
|
|
GtkTreeViewAccessible *accessible;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreePath *cell_path;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info;
|
2011-06-23 02:27:10 +00:00
|
|
|
GHashTableIter hash_iter;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (tree_view)));
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
/* Loop through our cached cells */
|
|
|
|
/* Must loop through them all */
|
2011-06-30 00:50:50 +00:00
|
|
|
g_hash_table_iter_init (&hash_iter, accessible->cell_info_by_index);
|
2011-06-23 02:27:10 +00:00
|
|
|
while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer *)&cell_info))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-23 02:27:10 +00:00
|
|
|
if (cell_info->in_use)
|
2011-06-30 00:50:50 +00:00
|
|
|
{
|
|
|
|
cell_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
|
|
|
|
|
|
|
|
if (cell_path != NULL)
|
|
|
|
{
|
|
|
|
if (path && gtk_tree_path_compare (cell_path, path) == 0)
|
|
|
|
{
|
2011-07-09 23:19:38 +00:00
|
|
|
if (GTK_IS_RENDERER_CELL_ACCESSIBLE (cell_info->cell))
|
|
|
|
update_cell_value (GTK_RENDERER_CELL_ACCESSIBLE (cell_info->cell),
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible, TRUE);
|
|
|
|
}
|
|
|
|
gtk_tree_path_free (cell_path);
|
|
|
|
}
|
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2011-06-30 00:50:50 +00:00
|
|
|
g_signal_emit_by_name (accessible, "visible-data-changed");
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
column_visibility_changed (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
2011-06-30 00:50:50 +00:00
|
|
|
gpointer user_data)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
if (strcmp (pspec->name, "visible") == 0)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
/* A column has been made visible or invisible
|
2007-12-18 13:51:12 +00:00
|
|
|
* We update our cache of cells and emit model_changed signal
|
2011-06-30 00:50:50 +00:00
|
|
|
*/
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeView *tree_view = (GtkTreeView *)user_data;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible;
|
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeViewColumn *this_col = GTK_TREE_VIEW_COLUMN (object);
|
|
|
|
GtkTreeViewColumn *tv_col;
|
2011-06-23 02:27:10 +00:00
|
|
|
GHashTableIter iter;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (tree_view))
|
2007-12-18 13:51:12 +00:00
|
|
|
);
|
2011-06-30 00:50:50 +00:00
|
|
|
g_signal_emit_by_name (accessible, "model_changed");
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
|
2011-06-23 02:27:10 +00:00
|
|
|
while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
if (cell_info->in_use)
|
|
|
|
{
|
|
|
|
tv_col = cell_info->cell_col_ref;
|
|
|
|
if (tv_col == this_col)
|
|
|
|
{
|
|
|
|
GtkTreePath *row_path;
|
|
|
|
row_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
|
2011-07-09 23:19:38 +00:00
|
|
|
if (GTK_IS_RENDERER_CELL_ACCESSIBLE (cell_info->cell))
|
2011-06-30 00:50:50 +00:00
|
|
|
{
|
|
|
|
if (gtk_tree_view_column_get_visible (tv_col))
|
|
|
|
set_cell_visibility (tree_view,
|
|
|
|
cell_info->cell,
|
|
|
|
tv_col, row_path, FALSE);
|
|
|
|
else
|
|
|
|
{
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_remove_state (cell_info->cell, ATK_STATE_VISIBLE, TRUE);
|
|
|
|
_gtk_cell_accessible_remove_state (cell_info->cell, ATK_STATE_SHOWING, TRUE);
|
2011-06-30 00:50:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
gtk_tree_path_free (row_path);
|
|
|
|
}
|
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
model_row_inserted (GtkTreeModel *tree_model,
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkTreeView *tree_view = (GtkTreeView *)user_data;
|
2011-06-30 00:50:50 +00:00
|
|
|
AtkObject *atk_obj;
|
|
|
|
GtkTreeViewAccessible *accessible;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreePath *path_copy;
|
|
|
|
gint row, n_inserted, child_row;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
|
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
|
|
|
|
accessible->n_rows++;
|
2011-06-23 02:27:10 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
if (accessible->idle_expand_id)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
g_source_remove (accessible->idle_expand_id);
|
|
|
|
accessible->idle_expand_id = 0;
|
2007-12-22 20:18:13 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* don't do this if the insertion precedes the idle path,
|
|
|
|
* since it will now be invalid
|
|
|
|
*/
|
|
|
|
if (path && accessible->idle_expand_path &&
|
|
|
|
(gtk_tree_path_compare (path, accessible->idle_expand_path) > 0))
|
|
|
|
set_expand_state (tree_view, tree_model, accessible, accessible->idle_expand_path, FALSE);
|
|
|
|
if (accessible->idle_expand_path)
|
|
|
|
gtk_tree_path_free (accessible->idle_expand_path);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
/* Check to see if row is visible */
|
|
|
|
row = get_row_from_tree_path (tree_view, path);
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* A row insert is not necessarily visible. For example,
|
2007-12-18 13:51:12 +00:00
|
|
|
* a row can be draged & dropped into another row, which
|
|
|
|
* causes an insert on the model that isn't visible in the
|
|
|
|
* view. Only generate a signal if the inserted row is
|
|
|
|
* visible.
|
|
|
|
*/
|
|
|
|
if (row != -1)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gint n_cols, col;
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (tree_model, &iter, path);
|
|
|
|
|
|
|
|
/* Figure out number of visible children. */
|
|
|
|
if (gtk_tree_model_iter_has_child (tree_model, &iter))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* By passing path into this function, we find the number of
|
|
|
|
* visible children of path.
|
|
|
|
*/
|
|
|
|
n_inserted = 0;
|
|
|
|
iterate_thru_children (tree_view, tree_model,
|
|
|
|
path, NULL, &n_inserted, 0);
|
|
|
|
|
|
|
|
/* Must add one to include the row that is being added */
|
|
|
|
n_inserted++;
|
|
|
|
}
|
|
|
|
else
|
2011-06-30 00:50:50 +00:00
|
|
|
n_inserted = 1;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
/* Set rows below the inserted row to ATK_STATE_STALE */
|
2011-06-30 00:50:50 +00:00
|
|
|
traverse_cells (accessible, path, TRUE, TRUE);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
/* Generate row-inserted signal */
|
|
|
|
g_signal_emit_by_name (atk_obj, "row_inserted", row, n_inserted);
|
|
|
|
|
|
|
|
/* Generate children-changed signals */
|
2011-06-30 00:50:50 +00:00
|
|
|
n_cols = gtk_tree_view_accessible_get_n_columns (ATK_TABLE (atk_obj));
|
2007-12-18 13:51:12 +00:00
|
|
|
for (child_row = row; child_row < (row + n_inserted); child_row++)
|
|
|
|
{
|
|
|
|
for (col = 0; col < n_cols; col++)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Pass NULL as the child object, i.e. 4th argument */
|
2007-12-18 13:51:12 +00:00
|
|
|
g_signal_emit_by_name (atk_obj, "children_changed::add",
|
|
|
|
((row * n_cols) + col), NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
/* The row has been inserted inside another row. This can
|
2007-12-18 13:51:12 +00:00
|
|
|
* cause a row that previously couldn't be expanded to now
|
|
|
|
* be expandable.
|
|
|
|
*/
|
|
|
|
path_copy = gtk_tree_path_copy (path);
|
|
|
|
gtk_tree_path_up (path_copy);
|
2011-06-30 00:50:50 +00:00
|
|
|
set_expand_state (tree_view, tree_model, accessible, path_copy, TRUE);
|
2007-12-18 13:51:12 +00:00
|
|
|
gtk_tree_path_free (path_copy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
model_row_deleted (GtkTreeModel *tree_model,
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreePath *path,
|
|
|
|
gpointer user_data)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeView *tree_view = (GtkTreeView *)user_data;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreePath *path_copy;
|
|
|
|
AtkObject *atk_obj;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible;
|
2011-06-23 02:27:10 +00:00
|
|
|
gint row, col;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible->n_rows--;
|
2011-06-23 02:27:10 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
if (accessible->idle_expand_id)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
g_source_remove (accessible->idle_expand_id);
|
|
|
|
gtk_tree_path_free (accessible->idle_expand_path);
|
|
|
|
accessible->idle_expand_id = 0;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2011-06-30 00:50:50 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
/* Check to see if row is visible */
|
2011-06-30 00:50:50 +00:00
|
|
|
clean_rows (accessible);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
/* Set rows at or below the specified row to ATK_STATE_STALE */
|
2011-06-30 00:50:50 +00:00
|
|
|
traverse_cells (accessible, path, TRUE, TRUE);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* If deleting a row with a depth > 1, then this may affect the
|
|
|
|
* expansion/contraction of its parent(s). Make sure this is
|
2007-12-18 13:51:12 +00:00
|
|
|
* handled.
|
|
|
|
*/
|
|
|
|
if (gtk_tree_path_get_depth (path) > 1)
|
|
|
|
{
|
|
|
|
path_copy = gtk_tree_path_copy (path);
|
|
|
|
gtk_tree_path_up (path_copy);
|
2011-06-30 00:50:50 +00:00
|
|
|
set_expand_state (tree_view, tree_model, accessible, path_copy, TRUE);
|
2007-12-18 13:51:12 +00:00
|
|
|
gtk_tree_path_free (path_copy);
|
|
|
|
}
|
|
|
|
row = get_row_from_tree_path (tree_view, path);
|
2011-06-30 00:50:50 +00:00
|
|
|
|
|
|
|
/* If the row which is deleted is not visible because it is a child of
|
2007-12-18 13:51:12 +00:00
|
|
|
* a collapsed row then row will be -1
|
|
|
|
*/
|
|
|
|
if (row > 0)
|
2011-06-30 00:50:50 +00:00
|
|
|
g_signal_emit_by_name (atk_obj, "row_deleted", row,
|
|
|
|
accessible->n_children_deleted + 1);
|
|
|
|
accessible->n_children_deleted = 0;
|
2008-08-21 05:28:58 +00:00
|
|
|
|
|
|
|
/* Generate children-changed signals */
|
2011-06-30 00:50:50 +00:00
|
|
|
for (col = 0; col < accessible->n_cols; col++)
|
|
|
|
{
|
|
|
|
/* Pass NULL as the child object, 4th argument */
|
|
|
|
g_signal_emit_by_name (atk_obj, "children_changed::remove",
|
|
|
|
((row * accessible->n_cols) + col), NULL, NULL);
|
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* This function gets called when a row is deleted or when rows are
|
|
|
|
* removed from the view due to a collapse event. Note that the
|
2007-12-18 13:51:12 +00:00
|
|
|
* count is the number of visible *children* of the deleted row,
|
|
|
|
* so it does not include the row being deleted.
|
|
|
|
*
|
2011-06-30 00:50:50 +00:00
|
|
|
* As this function is called before the rows are removed we just note
|
|
|
|
* the number of rows and then deal with it when we get a notification
|
|
|
|
* that rows were deleted or collapsed.
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
|
|
|
static void
|
2011-06-30 00:50:50 +00:00
|
|
|
destroy_count_func (GtkTreeView *tree_view,
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreePath *path,
|
2011-06-30 00:50:50 +00:00
|
|
|
gint count,
|
|
|
|
gpointer user_data)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
AtkObject *atk_obj;
|
|
|
|
GtkTreeViewAccessible *accessible;
|
|
|
|
|
|
|
|
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
|
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
if (accessible->n_children_deleted != 0)
|
2011-06-29 03:42:50 +00:00
|
|
|
return;
|
2011-06-30 00:50:50 +00:00
|
|
|
|
|
|
|
accessible->n_children_deleted = count;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static void
|
2007-12-18 13:51:12 +00:00
|
|
|
model_rows_reordered (GtkTreeModel *tree_model,
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreePath *path,
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeIter *iter,
|
2011-06-30 00:50:50 +00:00
|
|
|
gint *new_order,
|
|
|
|
gpointer user_data)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkTreeView *tree_view = (GtkTreeView *)user_data;
|
2011-06-30 00:50:50 +00:00
|
|
|
AtkObject *atk_obj;
|
|
|
|
GtkTreeViewAccessible *accessible;
|
|
|
|
|
|
|
|
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
|
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
if (accessible->idle_expand_id)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
g_source_remove (accessible->idle_expand_id);
|
|
|
|
gtk_tree_path_free (accessible->idle_expand_path);
|
|
|
|
accessible->idle_expand_id = 0;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2011-06-30 00:50:50 +00:00
|
|
|
traverse_cells (accessible, NULL, TRUE, FALSE);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
g_signal_emit_by_name (atk_obj, "row_reordered");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_cell_visibility (GtkTreeView *tree_view,
|
2011-07-09 22:30:59 +00:00
|
|
|
GtkCellAccessible *cell,
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeViewColumn *tv_col,
|
|
|
|
GtkTreePath *tree_path,
|
2011-06-30 00:50:50 +00:00
|
|
|
gboolean emit_signal)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GdkRectangle cell_rect;
|
|
|
|
|
|
|
|
/* Get these three values in tree coords */
|
2010-03-02 06:16:02 +00:00
|
|
|
if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
|
2007-12-18 13:51:12 +00:00
|
|
|
gtk_tree_view_get_cell_area (tree_view, tree_path, tv_col, &cell_rect);
|
|
|
|
else
|
|
|
|
cell_rect.height = 0;
|
|
|
|
|
|
|
|
if (cell_rect.height > 0)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
/* The height will be zero for a cell for which an antecedent
|
|
|
|
* is not expanded
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_add_state (cell, ATK_STATE_VISIBLE, emit_signal);
|
2007-12-18 13:51:12 +00:00
|
|
|
if (is_cell_showing (tree_view, &cell_rect))
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_add_state (cell, ATK_STATE_SHOWING, emit_signal);
|
2007-12-18 13:51:12 +00:00
|
|
|
else
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_remove_state (cell, ATK_STATE_SHOWING, emit_signal);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_remove_state (cell, ATK_STATE_VISIBLE, emit_signal);
|
|
|
|
_gtk_cell_accessible_remove_state (cell, ATK_STATE_SHOWING, emit_signal);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static gboolean
|
|
|
|
is_cell_showing (GtkTreeView *tree_view,
|
|
|
|
GdkRectangle *cell_rect)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GdkRectangle rect, *visible_rect;
|
|
|
|
GdkRectangle rect1, *tree_cell_rect;
|
2009-02-25 08:41:49 +00:00
|
|
|
gint bx, by;
|
2007-12-18 13:51:12 +00:00
|
|
|
gboolean is_showing;
|
2011-06-30 00:50:50 +00:00
|
|
|
|
|
|
|
/* A cell is considered "SHOWING" if any part of the cell is
|
|
|
|
* in the visible area. Other ways we could do this is by a
|
|
|
|
* cell's midpoint or if the cell is fully in the visible range.
|
|
|
|
* Since we have the cell_rect x, y, width, height of the cell,
|
|
|
|
* any of these is easy to compute.
|
2007-12-18 13:51:12 +00:00
|
|
|
*
|
2011-06-30 00:50:50 +00:00
|
|
|
* It is assumed that cell's rectangle is in widget coordinates
|
|
|
|
* so we must transform to tree cordinates.
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
|
|
|
visible_rect = ▭
|
|
|
|
tree_cell_rect = &rect1;
|
|
|
|
tree_cell_rect->x = cell_rect->x;
|
2009-02-25 08:41:49 +00:00
|
|
|
tree_cell_rect->y = cell_rect->y;
|
2007-12-18 13:51:12 +00:00
|
|
|
tree_cell_rect->width = cell_rect->width;
|
|
|
|
tree_cell_rect->height = cell_rect->height;
|
|
|
|
|
|
|
|
gtk_tree_view_get_visible_rect (tree_view, visible_rect);
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_view_convert_tree_to_bin_window_coords (tree_view, visible_rect->x,
|
2009-02-25 08:41:49 +00:00
|
|
|
visible_rect->y, &bx, &by);
|
|
|
|
|
|
|
|
if (((tree_cell_rect->x + tree_cell_rect->width) < bx) ||
|
|
|
|
((tree_cell_rect->y + tree_cell_rect->height) < by) ||
|
|
|
|
(tree_cell_rect->x > (bx + visible_rect->width)) ||
|
|
|
|
(tree_cell_rect->y > (by + visible_rect->height)))
|
2007-12-18 13:51:12 +00:00
|
|
|
is_showing = FALSE;
|
|
|
|
else
|
|
|
|
is_showing = TRUE;
|
|
|
|
|
|
|
|
return is_showing;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Misc Public */
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* This function is called when a cell's flyweight is created in
|
|
|
|
* gtk_tree_view_accessible_table_ref_at with emit_change_signal
|
|
|
|
* set to FALSE and in model_row_changed() on receipt of "row-changed"
|
|
|
|
* signal when emit_change_signal is set to TRUE
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
|
|
|
static gboolean
|
2011-07-09 23:19:38 +00:00
|
|
|
update_cell_value (GtkRendererCellAccessible *renderer_cell,
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible,
|
|
|
|
gboolean emit_change_signal)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkTreeModel *tree_model;
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GList *renderers, *cur_renderer;
|
|
|
|
GParamSpec *spec;
|
2011-07-09 23:19:38 +00:00
|
|
|
GtkRendererCellAccessibleClass *renderer_cell_class;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkCellRendererClass *gtk_cell_renderer_class;
|
2011-07-09 22:30:59 +00:00
|
|
|
GtkCellAccessible *cell;
|
2007-12-18 13:51:12 +00:00
|
|
|
gchar **prop_list;
|
|
|
|
AtkObject *parent;
|
|
|
|
gboolean is_expander, is_expanded;
|
2011-06-30 00:50:50 +00:00
|
|
|
|
2011-07-09 23:19:38 +00:00
|
|
|
renderer_cell_class = GTK_RENDERER_CELL_ACCESSIBLE_GET_CLASS (renderer_cell);
|
2007-12-18 13:51:12 +00:00
|
|
|
if (renderer_cell->renderer)
|
|
|
|
gtk_cell_renderer_class = GTK_CELL_RENDERER_GET_CLASS (renderer_cell->renderer);
|
|
|
|
else
|
|
|
|
gtk_cell_renderer_class = NULL;
|
|
|
|
|
2011-07-09 23:19:38 +00:00
|
|
|
prop_list = renderer_cell_class->property_list;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-07-09 22:30:59 +00:00
|
|
|
cell = GTK_CELL_ACCESSIBLE (renderer_cell);
|
2011-06-30 00:50:50 +00:00
|
|
|
cell_info = find_cell_info (accessible, cell, TRUE);
|
2011-06-29 03:42:50 +00:00
|
|
|
if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
|
|
|
|
return FALSE;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
if (emit_change_signal && cell_info->in_use)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
|
2007-12-18 13:51:12 +00:00
|
|
|
tree_model = gtk_tree_view_get_model (tree_view);
|
|
|
|
path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
|
|
|
|
if (path == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (tree_model, &iter, path);
|
|
|
|
is_expander = FALSE;
|
|
|
|
is_expanded = FALSE;
|
|
|
|
if (gtk_tree_model_iter_has_child (tree_model, &iter))
|
|
|
|
{
|
|
|
|
GtkTreeViewColumn *expander_tv;
|
|
|
|
|
|
|
|
expander_tv = gtk_tree_view_get_expander_column (tree_view);
|
|
|
|
if (expander_tv == cell_info->cell_col_ref)
|
|
|
|
{
|
|
|
|
is_expander = TRUE;
|
|
|
|
is_expanded = gtk_tree_view_row_expanded (tree_view, path);
|
|
|
|
}
|
2011-06-30 00:50:50 +00:00
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
gtk_tree_view_column_cell_set_cell_data (cell_info->cell_col_ref,
|
2011-06-30 00:50:50 +00:00
|
|
|
tree_model, &iter,
|
|
|
|
is_expander, is_expanded);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2009-06-17 08:28:03 +00:00
|
|
|
renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_info->cell_col_ref));
|
2011-06-29 03:42:50 +00:00
|
|
|
if (!renderers)
|
|
|
|
return FALSE;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* If the cell is in a container, its index is used to find the renderer
|
|
|
|
* in the list. Otherwise, we assume that the cell is represented
|
|
|
|
* by the first renderer in the list
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
if (cell_info->in_use)
|
|
|
|
{
|
2007-12-18 13:51:12 +00:00
|
|
|
parent = atk_object_get_parent (ATK_OBJECT (cell));
|
2011-06-30 00:50:50 +00:00
|
|
|
|
2011-07-09 22:51:27 +00:00
|
|
|
if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
|
2011-06-30 00:50:50 +00:00
|
|
|
cur_renderer = g_list_nth (renderers, cell->index);
|
2007-12-18 13:51:12 +00:00
|
|
|
else
|
2011-06-30 00:50:50 +00:00
|
|
|
cur_renderer = renderers;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
|
2011-06-29 03:42:50 +00:00
|
|
|
if (cur_renderer == NULL)
|
|
|
|
return FALSE;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
if (gtk_cell_renderer_class)
|
|
|
|
{
|
|
|
|
while (*prop_list)
|
|
|
|
{
|
|
|
|
spec = g_object_class_find_property
|
|
|
|
(G_OBJECT_CLASS (gtk_cell_renderer_class), *prop_list);
|
|
|
|
|
|
|
|
if (spec != NULL)
|
|
|
|
{
|
|
|
|
GValue value = { 0, };
|
|
|
|
|
|
|
|
g_value_init (&value, spec->value_type);
|
|
|
|
g_object_get_property (cur_renderer->data, *prop_list, &value);
|
|
|
|
g_object_set_property (G_OBJECT (renderer_cell->renderer),
|
|
|
|
*prop_list, &value);
|
2011-06-30 00:50:50 +00:00
|
|
|
g_value_unset (&value);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
g_warning ("Invalid property: %s\n", *prop_list);
|
|
|
|
prop_list++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_list_free (renderers);
|
|
|
|
|
2011-07-09 23:19:38 +00:00
|
|
|
return _gtk_renderer_cell_accessible_update_cache (renderer_cell, emit_change_signal);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static gint
|
2007-12-18 13:51:12 +00:00
|
|
|
get_row_from_tree_path (GtkTreeView *tree_view,
|
|
|
|
GtkTreePath *path)
|
|
|
|
{
|
|
|
|
GtkTreeModel *tree_model;
|
|
|
|
GtkTreePath *root_tree;
|
|
|
|
gint row;
|
|
|
|
|
|
|
|
tree_model = gtk_tree_view_get_model (tree_view);
|
|
|
|
|
|
|
|
if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY)
|
2010-06-28 18:15:10 +00:00
|
|
|
row = gtk_tree_path_get_indices (path)[0];
|
2007-12-18 13:51:12 +00:00
|
|
|
else
|
|
|
|
{
|
2008-12-09 14:49:34 +00:00
|
|
|
root_tree = gtk_tree_path_new_first ();
|
2007-12-18 13:51:12 +00:00
|
|
|
row = 0;
|
|
|
|
iterate_thru_children (tree_view, tree_model, root_tree, path, &row, 0);
|
|
|
|
gtk_tree_path_free (root_tree);
|
|
|
|
}
|
|
|
|
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Misc Private */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the specified GtkTreeViewColumn in the GtkTreeView.
|
|
|
|
* Only visible columns are considered.
|
|
|
|
*/
|
2011-06-30 00:50:50 +00:00
|
|
|
static GtkTreeViewColumn *
|
|
|
|
get_column (GtkTreeView *tree_view,
|
|
|
|
gint in_col)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkTreeViewColumn *tv_col;
|
|
|
|
gint n_cols = -1;
|
|
|
|
gint i = 0;
|
2011-06-30 00:50:50 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
if (in_col < 0)
|
|
|
|
{
|
|
|
|
g_warning ("Request for invalid column %d\n", in_col);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tv_col = gtk_tree_view_get_column (tree_view, i);
|
|
|
|
while (tv_col != NULL)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
if (gtk_tree_view_column_get_visible (tv_col))
|
2007-12-18 13:51:12 +00:00
|
|
|
n_cols++;
|
|
|
|
if (in_col == n_cols)
|
|
|
|
break;
|
|
|
|
tv_col = gtk_tree_view_get_column (tree_view, ++i);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_col != n_cols)
|
|
|
|
{
|
|
|
|
g_warning ("Request for invalid column %d\n", in_col);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return tv_col;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
get_actual_column_number (GtkTreeView *tree_view,
|
2011-06-30 00:50:50 +00:00
|
|
|
gint visible_column)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkTreeViewColumn *tv_col;
|
|
|
|
gint actual_column = 0;
|
|
|
|
gint visible_columns = -1;
|
2011-06-30 00:50:50 +00:00
|
|
|
|
|
|
|
/* This function calculates the column number which corresponds
|
|
|
|
* to the specified visible column number
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
|
|
|
tv_col = gtk_tree_view_get_column (tree_view, actual_column);
|
|
|
|
while (tv_col != NULL)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
if (gtk_tree_view_column_get_visible (tv_col))
|
2007-12-18 13:51:12 +00:00
|
|
|
visible_columns++;
|
|
|
|
if (visible_columns == visible_column)
|
|
|
|
return actual_column;
|
|
|
|
tv_col = gtk_tree_view_get_column (tree_view, ++actual_column);
|
|
|
|
}
|
|
|
|
g_warning ("get_actual_column_number failed for %d\n", visible_column);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
get_visible_column_number (GtkTreeView *tree_view,
|
2011-06-30 00:50:50 +00:00
|
|
|
gint actual_column)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkTreeViewColumn *tv_col;
|
|
|
|
gint column = 0;
|
|
|
|
gint visible_columns = -1;
|
2011-06-30 00:50:50 +00:00
|
|
|
|
|
|
|
/* This function calculates the visible column number
|
|
|
|
* which corresponds to the specified actual column number
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
|
|
|
tv_col = gtk_tree_view_get_column (tree_view, column);
|
|
|
|
|
|
|
|
while (tv_col != NULL)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
if (gtk_tree_view_column_get_visible (tv_col))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
visible_columns++;
|
|
|
|
if (actual_column == column)
|
|
|
|
return visible_columns;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (actual_column == column)
|
|
|
|
return -1;
|
|
|
|
tv_col = gtk_tree_view_get_column (tree_view, ++column);
|
|
|
|
}
|
|
|
|
g_warning ("get_visible_column_number failed for %d\n", actual_column);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Helper recursive function that returns an iter to nth row
|
|
|
|
*/
|
|
|
|
static GtkTreeIter *
|
|
|
|
return_iter_nth_row (GtkTreeView *tree_view,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gint increment,
|
|
|
|
gint row)
|
|
|
|
{
|
|
|
|
GtkTreePath *current_path;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeIter new_iter;
|
|
|
|
gboolean row_expanded;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
current_path = gtk_tree_model_get_path (tree_model, iter);
|
|
|
|
if (increment == row)
|
|
|
|
{
|
|
|
|
gtk_tree_path_free (current_path);
|
|
|
|
return iter;
|
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
row_expanded = gtk_tree_view_row_expanded (tree_view, current_path);
|
|
|
|
gtk_tree_path_free (current_path);
|
|
|
|
|
|
|
|
new_iter = *iter;
|
|
|
|
if ((row_expanded && gtk_tree_model_iter_children (tree_model, iter, &new_iter)) ||
|
|
|
|
(gtk_tree_model_iter_next (tree_model, iter)) ||
|
|
|
|
(gtk_tree_model_iter_parent (tree_model, iter, &new_iter) &&
|
|
|
|
(gtk_tree_model_iter_next (tree_model, iter))))
|
|
|
|
return return_iter_nth_row (tree_view, tree_model, iter,
|
|
|
|
++increment, row);
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_iter_nth_row (GtkTreeView *tree_view,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gint row)
|
|
|
|
{
|
|
|
|
GtkTreeModel *tree_model;
|
|
|
|
|
|
|
|
tree_model = gtk_tree_view_get_model (tree_view);
|
|
|
|
gtk_tree_model_get_iter_first (tree_model, iter);
|
|
|
|
iter = return_iter_nth_row (tree_view, tree_model, iter, 0, row);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Recursively called until the row specified by orig is found.
|
2007-12-18 13:51:12 +00:00
|
|
|
*
|
|
|
|
* *count will be set to the visible row number of the child
|
|
|
|
* relative to the row that was initially passed in as tree_path.
|
|
|
|
*
|
|
|
|
* *count will be -1 if orig is not found as a child (a row that is
|
|
|
|
* not visible will not be found, e.g. if the row is inside a
|
|
|
|
* collapsed row). If NULL is passed in as orig, *count will
|
|
|
|
* be a count of the visible children.
|
|
|
|
*
|
|
|
|
* NOTE: the value for depth must be 0 when this recursive function
|
|
|
|
* is initially called, or it may not function as expected.
|
2011-06-30 00:50:50 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
iterate_thru_children (GtkTreeView *tree_view,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreePath *tree_path,
|
|
|
|
GtkTreePath *orig,
|
|
|
|
gint *count,
|
|
|
|
gint depth)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
if (!gtk_tree_model_get_iter (tree_model, &iter, tree_path))
|
|
|
|
return;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
if (tree_path && orig && !gtk_tree_path_compare (tree_path, orig))
|
2007-12-18 13:51:12 +00:00
|
|
|
/* Found it! */
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (tree_path && orig && gtk_tree_path_compare (tree_path, orig) > 0)
|
|
|
|
{
|
|
|
|
/* Past it, so return -1 */
|
|
|
|
*count = -1;
|
|
|
|
return;
|
|
|
|
}
|
2011-06-30 00:50:50 +00:00
|
|
|
else if (gtk_tree_view_row_expanded (tree_view, tree_path) &&
|
|
|
|
gtk_tree_model_iter_has_child (tree_model, &iter))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
(*count)++;
|
|
|
|
gtk_tree_path_append_index (tree_path, 0);
|
|
|
|
iterate_thru_children (tree_view, tree_model, tree_path,
|
|
|
|
orig, count, (depth + 1));
|
|
|
|
return;
|
|
|
|
}
|
2011-06-30 00:50:50 +00:00
|
|
|
else if (gtk_tree_model_iter_next (tree_model, &iter))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
(*count)++;
|
|
|
|
tree_path = gtk_tree_model_get_path (tree_model, &iter);
|
|
|
|
if (tree_path)
|
|
|
|
{
|
|
|
|
iterate_thru_children (tree_view, tree_model, tree_path,
|
2011-06-30 00:50:50 +00:00
|
|
|
orig, count, depth);
|
2007-12-18 13:51:12 +00:00
|
|
|
gtk_tree_path_free (tree_path);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (gtk_tree_path_up (tree_path))
|
|
|
|
{
|
|
|
|
GtkTreeIter temp_iter;
|
|
|
|
gboolean exit_loop = FALSE;
|
|
|
|
gint new_depth = depth - 1;
|
|
|
|
|
|
|
|
(*count)++;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Make sure that we back up until we find a row
|
2007-12-18 13:51:12 +00:00
|
|
|
* where gtk_tree_path_next does not return NULL.
|
|
|
|
*/
|
|
|
|
while (!exit_loop)
|
|
|
|
{
|
|
|
|
if (gtk_tree_path_get_depth (tree_path) == 0)
|
|
|
|
/* depth is now zero so */
|
|
|
|
return;
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_path_next (tree_path);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
/* Verify that the next row is a valid row! */
|
|
|
|
exit_loop = gtk_tree_model_get_iter (tree_model, &temp_iter, tree_path);
|
|
|
|
|
|
|
|
if (!exit_loop)
|
|
|
|
{
|
|
|
|
/* Keep going up until we find a row that has a valid next */
|
|
|
|
if (gtk_tree_path_get_depth(tree_path) > 1)
|
|
|
|
{
|
|
|
|
new_depth--;
|
|
|
|
gtk_tree_path_up (tree_path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
/* If depth is 1 and gtk_tree_model_get_iter returns FALSE,
|
2007-12-18 13:51:12 +00:00
|
|
|
* then we are at the last row, so just return.
|
2011-06-30 00:50:50 +00:00
|
|
|
*/
|
2007-12-18 13:51:12 +00:00
|
|
|
if (orig != NULL)
|
|
|
|
*count = -1;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* This guarantees that we will stop when we hit the end of the
|
2007-12-18 13:51:12 +00:00
|
|
|
* children.
|
|
|
|
*/
|
|
|
|
if (new_depth < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
iterate_thru_children (tree_view, tree_model, tree_path,
|
2011-06-30 00:50:50 +00:00
|
|
|
orig, count, new_depth);
|
2007-12-18 13:51:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* If it gets here, then the path wasn't found. Situations
|
2007-12-18 13:51:12 +00:00
|
|
|
* that would cause this would be if the path passed in is
|
|
|
|
* invalid or contained within the last row, but not visible
|
|
|
|
* because the last row is not expanded. If NULL was passed
|
|
|
|
* in then a row count is desired, so only set count to -1
|
|
|
|
* if orig is not NULL.
|
|
|
|
*/
|
|
|
|
if (orig != NULL)
|
|
|
|
*count = -1;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-30 00:50:50 +00:00
|
|
|
clean_cell_info (GtkTreeViewAccessible *accessible,
|
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GObject *obj;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
if (cell_info->in_use)
|
|
|
|
{
|
2007-12-18 13:51:12 +00:00
|
|
|
obj = G_OBJECT (cell_info->cell);
|
2011-06-30 00:50:50 +00:00
|
|
|
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_add_state (cell_info->cell, ATK_STATE_DEFUNCT, FALSE);
|
2007-12-18 13:51:12 +00:00
|
|
|
g_object_weak_unref (obj, (GWeakNotify) cell_destroyed, cell_info);
|
2011-06-30 00:50:50 +00:00
|
|
|
cell_info->in_use = FALSE;
|
|
|
|
if (!accessible->garbage_collection_pending)
|
|
|
|
{
|
|
|
|
accessible->garbage_collection_pending = TRUE;
|
|
|
|
g_assert (accessible->idle_garbage_collect_id == 0);
|
|
|
|
accessible->idle_garbage_collect_id =
|
|
|
|
gdk_threads_add_idle (idle_garbage_collect_cell_data, accessible);
|
|
|
|
}
|
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static void
|
|
|
|
clean_rows (GtkTreeViewAccessible *accessible)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info;
|
2011-06-23 02:27:10 +00:00
|
|
|
GHashTableIter iter;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Clean GtkTreeViewAccessibleCellInfo data */
|
|
|
|
g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
|
2011-06-23 02:27:10 +00:00
|
|
|
while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *row_path;
|
|
|
|
|
2011-06-23 02:27:10 +00:00
|
|
|
row_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
|
2011-06-30 00:50:50 +00:00
|
|
|
|
|
|
|
/* If the cell has become invalid because the row has been removed,
|
2011-06-23 02:27:10 +00:00
|
|
|
* then set the cell's state to ATK_STATE_DEFUNCT and schedule
|
|
|
|
* its removal. If row_path is NULL then the row has
|
|
|
|
* been removed.
|
|
|
|
*/
|
|
|
|
if (row_path == NULL)
|
2011-06-30 00:50:50 +00:00
|
|
|
clean_cell_info (accessible, cell_info);
|
2011-06-23 02:27:10 +00:00
|
|
|
else
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_path_free (row_path);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-23 02:27:10 +00:00
|
|
|
static void
|
2011-06-30 00:50:50 +00:00
|
|
|
clean_cols (GtkTreeViewAccessible *accessible,
|
|
|
|
GtkTreeViewColumn *tv_col)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info;
|
2011-06-23 02:27:10 +00:00
|
|
|
GHashTableIter iter;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Clean GtkTreeViewAccessibleCellInfo data */
|
|
|
|
g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
|
2011-06-23 02:27:10 +00:00
|
|
|
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cell_info))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
/* If the cell has become invalid because the column tv_col
|
2011-06-23 02:27:10 +00:00
|
|
|
* has been removed, then set the cell's state to ATK_STATE_DEFUNCT
|
2011-06-30 00:50:50 +00:00
|
|
|
* and remove the cell from accessible->cell_data.
|
2011-06-23 02:27:10 +00:00
|
|
|
*/
|
|
|
|
if (cell_info->cell_col_ref == tv_col)
|
2011-06-30 00:50:50 +00:00
|
|
|
clean_cell_info (accessible, cell_info);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-06-30 00:50:50 +00:00
|
|
|
garbage_collect_cell_data (gpointer data)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible;
|
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info;
|
|
|
|
GHashTableIter iter;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible = (GtkTreeViewAccessible *)data;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible->garbage_collection_pending = FALSE;
|
|
|
|
if (accessible->idle_garbage_collect_id != 0)
|
|
|
|
{
|
|
|
|
g_source_remove (accessible->idle_garbage_collect_id);
|
|
|
|
accessible->idle_garbage_collect_id = 0;
|
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Must loop through them all */
|
|
|
|
g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
|
|
|
|
while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
|
|
|
|
{
|
|
|
|
if (!cell_info->in_use)
|
|
|
|
{
|
|
|
|
/* g_object_unref (cell_info->cell); */
|
|
|
|
if (cell_info->cell_row_ref)
|
|
|
|
gtk_tree_row_reference_free (cell_info->cell_row_ref);
|
|
|
|
g_free (cell_info);
|
|
|
|
g_hash_table_iter_remove (&iter);
|
|
|
|
}
|
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
return accessible->garbage_collection_pending;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-06-30 00:50:50 +00:00
|
|
|
idle_garbage_collect_cell_data (gpointer data)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible = (GtkTreeViewAccessible *)data;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* this is the idle handler (only one instance allowed), so
|
|
|
|
* we can safely delete it.
|
|
|
|
*/
|
|
|
|
accessible->garbage_collection_pending = FALSE;
|
|
|
|
accessible->idle_garbage_collect_id = 0;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible->garbage_collection_pending = garbage_collect_cell_data (data);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* N.B.: if for some reason another handler has re-enterantly been
|
|
|
|
* queued while this handler was being serviced, it has its own gsource,
|
|
|
|
* therefore this handler should always return FALSE.
|
|
|
|
*/
|
|
|
|
return FALSE;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* If tree_path is passed in as NULL, then all cells are acted on.
|
|
|
|
* Otherwise, just act on those cells that are on a row greater than
|
|
|
|
* the specified tree_path. If inc_row is passed in as TRUE, then rows
|
2007-12-18 13:51:12 +00:00
|
|
|
* greater and equal to the specified tree_path are acted on.
|
|
|
|
*
|
2011-06-30 00:50:50 +00:00
|
|
|
* If set_stale is set the ATK_STATE_STALE is set on cells which
|
|
|
|
* are to be acted on.
|
2007-12-18 13:51:12 +00:00
|
|
|
*
|
|
|
|
* The function set_cell_visibility() is called on all cells to be
|
|
|
|
* acted on to update the visibility of the cell.
|
2011-06-30 00:50:50 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
traverse_cells (GtkTreeViewAccessible *accessible,
|
|
|
|
GtkTreePath *tree_path,
|
|
|
|
gboolean set_stale,
|
|
|
|
gboolean inc_row)
|
|
|
|
{
|
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info;
|
2011-06-23 02:27:10 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
GHashTableIter iter;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
|
2011-06-23 02:27:10 +00:00
|
|
|
if (!widget)
|
|
|
|
return;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-23 02:27:10 +00:00
|
|
|
/* Must loop through them all */
|
2011-06-30 00:50:50 +00:00
|
|
|
g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
|
2011-06-23 02:27:10 +00:00
|
|
|
while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info))
|
|
|
|
{
|
|
|
|
GtkTreePath *row_path;
|
|
|
|
gboolean act_on_cell;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-23 02:27:10 +00:00
|
|
|
if (cell_info->in_use)
|
|
|
|
{
|
|
|
|
row_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
|
|
|
|
g_return_if_fail (row_path != NULL);
|
|
|
|
if (tree_path == NULL)
|
|
|
|
act_on_cell = TRUE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gint comparison;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-23 02:27:10 +00:00
|
|
|
comparison = gtk_tree_path_compare (row_path, tree_path);
|
|
|
|
if ((comparison > 0) ||
|
|
|
|
(comparison == 0 && inc_row))
|
|
|
|
act_on_cell = TRUE;
|
|
|
|
else
|
|
|
|
act_on_cell = FALSE;
|
|
|
|
}
|
2011-06-30 00:50:50 +00:00
|
|
|
|
|
|
|
if (!cell_info->in_use)
|
|
|
|
g_warning ("warning: cell info destroyed during traversal");
|
|
|
|
|
2011-06-23 02:27:10 +00:00
|
|
|
if (act_on_cell && cell_info->in_use)
|
|
|
|
{
|
|
|
|
if (set_stale)
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_add_state (cell_info->cell, ATK_STATE_STALE, TRUE);
|
2011-06-30 00:50:50 +00:00
|
|
|
set_cell_visibility (GTK_TREE_VIEW (widget),
|
2011-06-23 02:27:10 +00:00
|
|
|
cell_info->cell,
|
|
|
|
cell_info->cell_col_ref,
|
|
|
|
row_path, TRUE);
|
|
|
|
}
|
|
|
|
gtk_tree_path_free (row_path);
|
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2011-06-23 02:27:10 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
g_signal_emit_by_name (accessible, "visible-data-changed");
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* If the tree_path passed in has children, then
|
2007-12-18 13:51:12 +00:00
|
|
|
* ATK_STATE_EXPANDABLE is set. If the row is expanded
|
2011-06-30 00:50:50 +00:00
|
|
|
* ATK_STATE_EXPANDED is turned on. If the row is
|
2007-12-18 13:51:12 +00:00
|
|
|
* collapsed, then ATK_STATE_EXPANDED is removed.
|
2011-06-30 00:50:50 +00:00
|
|
|
*
|
2007-12-18 13:51:12 +00:00
|
|
|
* If the tree_path passed in has no children, then
|
|
|
|
* ATK_STATE_EXPANDABLE and ATK_STATE_EXPANDED are removed.
|
|
|
|
*
|
|
|
|
* If set_on_ancestor is TRUE, then this function will also
|
|
|
|
* update all cells that are ancestors of the tree_path.
|
|
|
|
*/
|
|
|
|
static void
|
2011-06-30 00:50:50 +00:00
|
|
|
set_expand_state (GtkTreeView *tree_view,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreeViewAccessible *accessible,
|
|
|
|
GtkTreePath *tree_path,
|
|
|
|
gboolean set_on_ancestor)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-23 02:27:10 +00:00
|
|
|
GtkTreeViewColumn *expander_tv;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info;
|
2011-06-23 02:27:10 +00:00
|
|
|
GtkTreePath *cell_path;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean found;
|
|
|
|
GHashTableIter hash_iter;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
g_hash_table_iter_init (&hash_iter, accessible->cell_info_by_index);
|
2011-06-23 02:27:10 +00:00
|
|
|
while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer *) &cell_info))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-23 02:27:10 +00:00
|
|
|
if (cell_info->in_use)
|
|
|
|
{
|
|
|
|
cell_path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
|
|
|
|
found = FALSE;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-23 02:27:10 +00:00
|
|
|
if (cell_path != NULL)
|
|
|
|
{
|
2011-07-09 22:30:59 +00:00
|
|
|
GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (cell_info->cell);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-23 02:27:10 +00:00
|
|
|
expander_tv = gtk_tree_view_get_expander_column (tree_view);
|
|
|
|
|
|
|
|
/* Only set state for the cell that is in the column with the
|
|
|
|
* expander toggle
|
|
|
|
*/
|
|
|
|
if (expander_tv == cell_info->cell_col_ref)
|
|
|
|
{
|
|
|
|
if (tree_path && gtk_tree_path_compare (cell_path, tree_path) == 0)
|
|
|
|
found = TRUE;
|
|
|
|
else if (set_on_ancestor &&
|
2011-06-30 00:50:50 +00:00
|
|
|
gtk_tree_path_get_depth (cell_path) <
|
|
|
|
gtk_tree_path_get_depth (tree_path) &&
|
|
|
|
gtk_tree_path_is_ancestor (cell_path, tree_path) == 1)
|
2011-06-23 02:27:10 +00:00
|
|
|
/* Only set if set_on_ancestor was passed in as TRUE */
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set ATK_STATE_EXPANDABLE and ATK_STATE_EXPANDED
|
|
|
|
* for ancestors and found cells.
|
|
|
|
*/
|
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
/* Must check against cell_path since cell_path
|
|
|
|
* can be equal to or an ancestor of tree_path.
|
|
|
|
*/
|
|
|
|
gtk_tree_model_get_iter (tree_model, &iter, cell_path);
|
|
|
|
|
|
|
|
/* Set or unset ATK_STATE_EXPANDABLE as appropriate */
|
|
|
|
if (gtk_tree_model_iter_has_child (tree_model, &iter))
|
|
|
|
{
|
|
|
|
set_cell_expandable (cell);
|
|
|
|
|
|
|
|
if (gtk_tree_view_row_expanded (tree_view, cell_path))
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDED, TRUE);
|
2011-06-23 02:27:10 +00:00
|
|
|
else
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDED, TRUE);
|
2011-06-23 02:27:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDED, TRUE);
|
|
|
|
if (_gtk_cell_accessible_remove_state (cell, ATK_STATE_EXPANDABLE, TRUE))
|
2011-06-23 02:27:10 +00:00
|
|
|
/* The state may have been propagated to the container cell */
|
2011-07-09 22:51:27 +00:00
|
|
|
if (!GTK_IS_CONTAINER_CELL_ACCESSIBLE (cell))
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_remove_action_by_name (cell,
|
|
|
|
"expand or contract");
|
2011-06-23 02:27:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We assume that each cell in the cache once and
|
|
|
|
* a container cell is before its child cells so we are
|
|
|
|
* finished if set_on_ancestor is not set to TRUE.
|
|
|
|
*/
|
|
|
|
if (!set_on_ancestor)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gtk_tree_path_free (cell_path);
|
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-07-09 22:30:59 +00:00
|
|
|
add_cell_actions (GtkCellAccessible *cell,
|
|
|
|
gboolean editable)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-07-09 23:02:42 +00:00
|
|
|
if (GTK_IS_BOOLEAN_CELL_ACCESSIBLE (cell))
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_add_action (cell,
|
|
|
|
"toggle", "toggles the cell",
|
|
|
|
NULL, toggle_cell_toggled);
|
2007-12-18 13:51:12 +00:00
|
|
|
if (editable)
|
2011-07-09 22:30:59 +00:00
|
|
|
_gtk_cell_accessible_add_action (cell,
|
|
|
|
"edit", "creates a widget in which the contents of the cell can be edited",
|
|
|
|
NULL, edit_cell);
|
|
|
|
_gtk_cell_accessible_add_action (cell,
|
|
|
|
"activate", "activate the cell",
|
|
|
|
NULL, activate_cell);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-07-09 22:30:59 +00:00
|
|
|
toggle_cell_expanded (GtkCellAccessible *cell)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkTreePath *path;
|
|
|
|
AtkObject *parent;
|
|
|
|
AtkStateSet *stateset;
|
2011-06-30 00:50:50 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
parent = atk_object_get_parent (ATK_OBJECT (cell));
|
2011-07-09 22:51:27 +00:00
|
|
|
if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
|
2007-12-18 13:51:12 +00:00
|
|
|
parent = atk_object_get_parent (parent);
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
|
2011-06-29 03:42:50 +00:00
|
|
|
if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
|
|
|
|
return;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
|
2007-12-18 13:51:12 +00:00
|
|
|
path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
|
2011-06-29 03:42:50 +00:00
|
|
|
if (!path)
|
|
|
|
return;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
stateset = atk_object_ref_state_set (ATK_OBJECT (cell));
|
|
|
|
if (atk_state_set_contains_state (stateset, ATK_STATE_EXPANDED))
|
|
|
|
gtk_tree_view_collapse_row (tree_view, path);
|
|
|
|
else
|
|
|
|
gtk_tree_view_expand_row (tree_view, path, TRUE);
|
|
|
|
g_object_unref (stateset);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-07-09 22:30:59 +00:00
|
|
|
toggle_cell_toggled (GtkCellAccessible *cell)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreePath *path;
|
|
|
|
gchar *pathstring;
|
|
|
|
GList *renderers, *cur_renderer;
|
|
|
|
AtkObject *parent;
|
|
|
|
gboolean is_container_cell = FALSE;
|
|
|
|
|
|
|
|
parent = atk_object_get_parent (ATK_OBJECT (cell));
|
2011-07-09 22:51:27 +00:00
|
|
|
if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
is_container_cell = TRUE;
|
|
|
|
parent = atk_object_get_parent (parent);
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
|
2011-06-29 03:42:50 +00:00
|
|
|
if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
|
|
|
|
return;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
|
2011-06-29 03:42:50 +00:00
|
|
|
if (!path)
|
|
|
|
return;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* If the cell is in a container, its index is used to find the
|
|
|
|
* renderer in the list. Otherwise, we assume that the cell is
|
|
|
|
* represented by the first renderer in the list
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
2011-06-30 00:50:50 +00:00
|
|
|
renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (cell_info->cell_col_ref));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (is_container_cell)
|
|
|
|
cur_renderer = g_list_nth (renderers, cell->index);
|
|
|
|
else
|
|
|
|
cur_renderer = renderers;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
if (cur_renderer)
|
|
|
|
{
|
|
|
|
pathstring = gtk_tree_path_to_string (path);
|
|
|
|
g_signal_emit_by_name (cur_renderer->data, "toggled", pathstring);
|
2011-07-06 13:36:29 +00:00
|
|
|
g_free (pathstring);
|
2011-06-30 00:50:50 +00:00
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
g_list_free (renderers);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-07-09 22:30:59 +00:00
|
|
|
edit_cell (GtkCellAccessible *cell)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkTreePath *path;
|
|
|
|
AtkObject *parent;
|
|
|
|
|
|
|
|
parent = atk_object_get_parent (ATK_OBJECT (cell));
|
2011-07-09 22:51:27 +00:00
|
|
|
if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
|
2011-01-30 07:14:08 +00:00
|
|
|
parent = atk_object_get_parent (parent);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
|
2011-06-29 03:42:50 +00:00
|
|
|
if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
|
|
|
|
return;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
|
2007-12-18 13:51:12 +00:00
|
|
|
path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
|
2011-06-29 03:42:50 +00:00
|
|
|
if (!path)
|
|
|
|
return;
|
2007-12-18 13:51:12 +00:00
|
|
|
gtk_tree_view_set_cursor (tree_view, path, cell_info->cell_col_ref, TRUE);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-07-09 22:30:59 +00:00
|
|
|
activate_cell (GtkCellAccessible *cell)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info;
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreeView *tree_view;
|
|
|
|
GtkTreePath *path;
|
|
|
|
AtkObject *parent;
|
|
|
|
|
|
|
|
parent = atk_object_get_parent (ATK_OBJECT (cell));
|
2011-07-09 22:51:27 +00:00
|
|
|
if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
|
2011-01-30 07:14:08 +00:00
|
|
|
parent = atk_object_get_parent (parent);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell, TRUE);
|
2011-06-29 03:42:50 +00:00
|
|
|
if (!cell_info || !cell_info->cell_col_ref || !cell_info->cell_row_ref)
|
|
|
|
return;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
|
2007-12-18 13:51:12 +00:00
|
|
|
path = gtk_tree_row_reference_get_path (cell_info->cell_row_ref);
|
2011-06-29 03:42:50 +00:00
|
|
|
if (!path)
|
|
|
|
return;
|
2007-12-18 13:51:12 +00:00
|
|
|
gtk_tree_view_row_activated (tree_view, path, cell_info->cell_col_ref);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cell_destroyed (gpointer data)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info = data;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-29 03:42:50 +00:00
|
|
|
if (!cell_info)
|
|
|
|
return;
|
2011-06-30 00:50:50 +00:00
|
|
|
if (cell_info->in_use)
|
|
|
|
{
|
2007-12-18 13:51:12 +00:00
|
|
|
cell_info->in_use = FALSE;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
if (!cell_info->view->garbage_collection_pending)
|
|
|
|
{
|
|
|
|
cell_info->view->garbage_collection_pending = TRUE;
|
|
|
|
cell_info->view->idle_garbage_collect_id =
|
|
|
|
gdk_threads_add_idle (idle_garbage_collect_cell_data, cell_info->view);
|
|
|
|
}
|
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-30 00:50:50 +00:00
|
|
|
cell_info_get_index (GtkTreeView *tree_view,
|
|
|
|
GtkTreeViewAccessibleCellInfo *info,
|
|
|
|
gint *index)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
gint column_number;
|
|
|
|
|
|
|
|
path = gtk_tree_row_reference_get_path (info->cell_row_ref);
|
2011-06-29 03:42:50 +00:00
|
|
|
if (!path)
|
|
|
|
return;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
column_number = get_column_number (tree_view, info->cell_col_ref, FALSE);
|
|
|
|
*index = get_index (tree_view, path, column_number);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-30 00:50:50 +00:00
|
|
|
cell_info_new (GtkTreeViewAccessible *accessible,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeViewColumn *tv_col,
|
2011-07-09 22:30:59 +00:00
|
|
|
GtkCellAccessible *cell)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
cell_info = g_new (GtkTreeViewAccessibleCellInfo, 1);
|
2007-12-18 13:51:12 +00:00
|
|
|
cell_info->cell_row_ref = gtk_tree_row_reference_new (tree_model, path);
|
|
|
|
|
|
|
|
cell_info->cell_col_ref = tv_col;
|
|
|
|
cell_info->cell = cell;
|
|
|
|
cell_info->in_use = TRUE; /* if we've created it, assume it's in use */
|
2011-06-30 00:50:50 +00:00
|
|
|
cell_info->view = accessible;
|
|
|
|
g_hash_table_insert (accessible->cell_info_by_index, &cell->index, cell_info);
|
2011-06-23 02:27:10 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
/* Setup weak reference notification */
|
2011-06-30 00:50:50 +00:00
|
|
|
g_object_weak_ref (G_OBJECT (cell), (GWeakNotify) cell_destroyed, cell_info);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-07-09 22:30:59 +00:00
|
|
|
static GtkCellAccessible *
|
2011-06-30 00:50:50 +00:00
|
|
|
find_cell (GtkTreeViewAccessible *accessible,
|
|
|
|
gint index)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessibleCellInfo *info;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
info = g_hash_table_lookup (accessible->cell_info_by_index, &index);
|
|
|
|
if (!info)
|
|
|
|
return NULL;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
return info->cell;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-07-09 22:30:59 +00:00
|
|
|
refresh_cell_index (GtkCellAccessible *cell)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessibleCellInfo *info;
|
2007-12-18 13:51:12 +00:00
|
|
|
AtkObject *parent;
|
|
|
|
GtkTreeView *tree_view;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible;
|
2007-12-18 13:51:12 +00:00
|
|
|
gint index;
|
|
|
|
|
|
|
|
parent = atk_object_get_parent (ATK_OBJECT (cell));
|
2011-06-30 00:50:50 +00:00
|
|
|
if (!GTK_IS_TREE_VIEW_ACCESSIBLE (parent))
|
2011-06-29 03:42:50 +00:00
|
|
|
return;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (parent);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Find this cell in the GtkTreeViewAccessible's cache */
|
|
|
|
info = find_cell_info (accessible, cell, TRUE);
|
2011-06-29 03:42:50 +00:00
|
|
|
if (!info)
|
|
|
|
return;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
cell_info_get_index (tree_view, info, &index);
|
|
|
|
cell->index = index;
|
|
|
|
g_hash_table_insert (accessible->cell_info_by_index, &index, info);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-30 00:50:50 +00:00
|
|
|
connect_model_signals (GtkTreeView *view,
|
|
|
|
GtkTreeViewAccessible *accessible)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GObject *obj;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
obj = G_OBJECT (accessible->tree_model);
|
2007-12-18 13:51:12 +00:00
|
|
|
g_signal_connect_data (obj, "row-changed",
|
2011-06-30 00:50:50 +00:00
|
|
|
G_CALLBACK (model_row_changed), view, NULL, 0);
|
2007-12-18 13:51:12 +00:00
|
|
|
g_signal_connect_data (obj, "row-inserted",
|
2011-06-30 00:50:50 +00:00
|
|
|
G_CALLBACK (model_row_inserted), view, NULL,
|
2007-12-18 13:51:12 +00:00
|
|
|
G_CONNECT_AFTER);
|
|
|
|
g_signal_connect_data (obj, "row-deleted",
|
2011-06-30 00:50:50 +00:00
|
|
|
G_CALLBACK (model_row_deleted), view, NULL,
|
2007-12-18 13:51:12 +00:00
|
|
|
G_CONNECT_AFTER);
|
|
|
|
g_signal_connect_data (obj, "rows-reordered",
|
2011-06-30 00:50:50 +00:00
|
|
|
G_CALLBACK (model_rows_reordered), view, NULL,
|
2007-12-18 13:51:12 +00:00
|
|
|
G_CONNECT_AFTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-30 00:50:50 +00:00
|
|
|
disconnect_model_signals (GtkTreeViewAccessible *accessible)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GObject *obj;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
obj = G_OBJECT (accessible->tree_model);
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
|
|
|
|
g_signal_handlers_disconnect_by_func (obj, model_row_changed, widget);
|
|
|
|
g_signal_handlers_disconnect_by_func (obj, model_row_inserted, widget);
|
|
|
|
g_signal_handlers_disconnect_by_func (obj, model_row_deleted, widget);
|
|
|
|
g_signal_handlers_disconnect_by_func (obj, model_rows_reordered, widget);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-30 00:50:50 +00:00
|
|
|
clear_cached_data (GtkTreeViewAccessible *accessible)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info;
|
2011-06-23 02:27:10 +00:00
|
|
|
GHashTableIter iter;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-23 02:27:10 +00:00
|
|
|
/* Must loop through them all */
|
2011-06-30 00:50:50 +00:00
|
|
|
g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
|
2011-06-23 02:27:10 +00:00
|
|
|
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cell_info))
|
2011-06-30 00:50:50 +00:00
|
|
|
clean_cell_info (accessible, cell_info);
|
2011-06-23 02:27:10 +00:00
|
|
|
|
|
|
|
/* FIXME: seems pretty inefficient to loop again here */
|
2011-06-30 00:50:50 +00:00
|
|
|
garbage_collect_cell_data (accessible);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Returns the column number of the specified GtkTreeViewColumn
|
2007-12-18 13:51:12 +00:00
|
|
|
*
|
2011-06-30 00:50:50 +00:00
|
|
|
* If visible is set, the value returned will be the visible column number,
|
2007-12-18 13:51:12 +00:00
|
|
|
* i.e. suitable for use in AtkTable function. If visible is not set, the
|
2011-06-30 00:50:50 +00:00
|
|
|
* value returned is the actual column number, which is suitable for use in
|
2007-12-18 13:51:12 +00:00
|
|
|
* getting an index value.
|
|
|
|
*/
|
|
|
|
static gint
|
|
|
|
get_column_number (GtkTreeView *tree_view,
|
|
|
|
GtkTreeViewColumn *column,
|
2011-06-30 00:50:50 +00:00
|
|
|
gboolean visible)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkTreeViewColumn *tv_column;
|
|
|
|
gint ret_val;
|
2011-06-23 02:27:10 +00:00
|
|
|
gint i;
|
|
|
|
AtkObject *atk_obj;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible;
|
2011-06-23 02:27:10 +00:00
|
|
|
|
|
|
|
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
ret_val = 0;
|
2011-06-30 00:50:50 +00:00
|
|
|
for (i = 0; i < accessible->col_data->len; i++)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
tv_column = g_array_index (accessible->col_data, GtkTreeViewColumn *, i);
|
2007-12-18 13:51:12 +00:00
|
|
|
if (tv_column == column)
|
|
|
|
break;
|
|
|
|
if (!visible || gtk_tree_view_column_get_visible (tv_column))
|
|
|
|
ret_val++;
|
|
|
|
}
|
2011-06-30 00:50:50 +00:00
|
|
|
if (i == accessible->col_data->len)
|
|
|
|
ret_val = -1;
|
2011-06-23 02:27:10 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
return ret_val;
|
2011-06-23 02:27:10 +00:00
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
static gint
|
2011-06-23 02:27:10 +00:00
|
|
|
get_index (GtkTreeView *tree_view,
|
|
|
|
GtkTreePath *path,
|
|
|
|
gint actual_column)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-23 02:27:10 +00:00
|
|
|
AtkObject *atk_obj;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible;
|
2007-12-18 13:51:12 +00:00
|
|
|
gint depth = 0;
|
|
|
|
gint index = 1;
|
|
|
|
gint *indices = NULL;
|
|
|
|
|
2011-06-23 02:27:10 +00:00
|
|
|
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
depth = gtk_tree_path_get_depth (path);
|
2010-06-28 18:15:10 +00:00
|
|
|
indices = gtk_tree_path_get_indices (path);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (depth > 1)
|
|
|
|
{
|
|
|
|
GtkTreePath *copy_path;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (tree_view);
|
|
|
|
copy_path = gtk_tree_path_copy (path);
|
|
|
|
gtk_tree_path_up (copy_path);
|
|
|
|
count_rows (model, NULL, copy_path, &index, 0, depth);
|
|
|
|
gtk_tree_path_free (copy_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path)
|
2011-06-30 00:50:50 +00:00
|
|
|
index += indices[depth - 1];
|
|
|
|
index *= accessible->n_cols;
|
2007-12-18 13:51:12 +00:00
|
|
|
index += actual_column;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* The function count_rows counts the number of rows starting at iter
|
|
|
|
* and ending at end_path. The value of level is the depth of iter and
|
|
|
|
* the value of depth is the depth of end_path. Rows at depth before
|
|
|
|
* end_path are counted. This functions counts rows which are not visible
|
|
|
|
* because an ancestor is collapsed.
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
2011-06-30 00:50:50 +00:00
|
|
|
static void
|
2007-12-18 13:51:12 +00:00
|
|
|
count_rows (GtkTreeModel *model,
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreePath *end_path,
|
|
|
|
gint *count,
|
|
|
|
gint level,
|
|
|
|
gint depth)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter child_iter;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
if (!model)
|
|
|
|
return;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
level++;
|
2007-12-18 13:51:12 +00:00
|
|
|
*count += gtk_tree_model_iter_n_children (model, iter);
|
|
|
|
|
2011-06-23 02:27:10 +00:00
|
|
|
if (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY)
|
|
|
|
return;
|
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
if (level >= depth)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (gtk_tree_model_iter_children (model, &child_iter, iter))
|
|
|
|
{
|
|
|
|
gboolean ret_val = TRUE;
|
|
|
|
|
|
|
|
while (ret_val)
|
|
|
|
{
|
|
|
|
if (level == depth - 1)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreePath *iter_path;
|
2007-12-18 13:51:12 +00:00
|
|
|
gboolean finished = FALSE;
|
|
|
|
|
|
|
|
iter_path = gtk_tree_model_get_path (model, &child_iter);
|
|
|
|
if (end_path && gtk_tree_path_compare (iter_path, end_path) >= 0)
|
|
|
|
finished = TRUE;
|
|
|
|
gtk_tree_path_free (iter_path);
|
|
|
|
if (finished)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (gtk_tree_model_iter_has_child (model, &child_iter))
|
|
|
|
count_rows (model, &child_iter, end_path, count, level, depth);
|
|
|
|
ret_val = gtk_tree_model_iter_next (model, &child_iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Find the next node, which has children, at the specified depth below
|
2007-12-18 13:51:12 +00:00
|
|
|
* the specified iter. The level is the depth of the current iter.
|
2011-06-30 00:50:50 +00:00
|
|
|
* The position of the node is returned in path and the return value
|
|
|
|
* of TRUE means that a node was found.
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static gboolean
|
|
|
|
get_next_node_with_child_at_depth (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreePath **path,
|
|
|
|
gint level,
|
|
|
|
gint depth)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter child_iter;
|
|
|
|
|
|
|
|
*path = NULL;
|
|
|
|
|
|
|
|
if (gtk_tree_model_iter_children (model, &child_iter, iter))
|
|
|
|
{
|
|
|
|
level++;
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
while (!gtk_tree_model_iter_has_child (model, &child_iter))
|
|
|
|
{
|
|
|
|
if (!gtk_tree_model_iter_next (model, &child_iter))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (level == depth)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
/* We have found what we were looking for */
|
2007-12-18 13:51:12 +00:00
|
|
|
*path = gtk_tree_model_get_path (model, &child_iter);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_next_node_with_child_at_depth (model, &child_iter, path,
|
|
|
|
level, depth))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (!gtk_tree_model_iter_next (model, &child_iter))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Find the next node, which has children, at the same depth
|
|
|
|
* as the specified GtkTreePath.
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
2011-06-30 00:50:50 +00:00
|
|
|
static gboolean
|
|
|
|
get_next_node_with_child (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreePath **return_path)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gint depth;
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (model, &iter, path);
|
|
|
|
|
|
|
|
while (gtk_tree_model_iter_next (model, &iter))
|
|
|
|
{
|
|
|
|
if (gtk_tree_model_iter_has_child (model, &iter))
|
|
|
|
{
|
|
|
|
*return_path = gtk_tree_model_get_path (model, &iter);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
depth = gtk_tree_path_get_depth (path);
|
|
|
|
while (gtk_tree_path_up (path))
|
|
|
|
{
|
|
|
|
if (gtk_tree_path_get_depth (path) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (model, &iter, path);
|
|
|
|
while (gtk_tree_model_iter_next (model, &iter))
|
|
|
|
if (get_next_node_with_child_at_depth (model, &iter, return_path,
|
|
|
|
gtk_tree_path_get_depth (path), depth))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
*return_path = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static gboolean
|
|
|
|
get_tree_path_from_row_index (GtkTreeModel *model,
|
|
|
|
gint row_index,
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreePath **tree_path)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gint count;
|
|
|
|
gint depth;
|
|
|
|
|
|
|
|
count = gtk_tree_model_iter_n_children (model, NULL);
|
|
|
|
if (count > row_index)
|
|
|
|
{
|
|
|
|
if (gtk_tree_model_iter_nth_child (model, &iter, NULL, row_index))
|
|
|
|
{
|
|
|
|
*tree_path = gtk_tree_model_get_path (model, &iter);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
row_index -= count;
|
|
|
|
|
|
|
|
depth = 0;
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
depth++;
|
|
|
|
|
|
|
|
if (get_next_node_with_child_at_depth (model, NULL, tree_path, 0, depth))
|
|
|
|
{
|
|
|
|
GtkTreePath *next_path;
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
gtk_tree_model_get_iter (model, &iter, *tree_path);
|
|
|
|
count = gtk_tree_model_iter_n_children (model, &iter);
|
|
|
|
if (count > row_index)
|
|
|
|
{
|
|
|
|
gtk_tree_path_append_index (*tree_path, row_index);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
row_index -= count;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
if (!get_next_node_with_child (model, *tree_path, &next_path))
|
2007-12-18 13:51:12 +00:00
|
|
|
break;
|
2011-06-30 00:50:50 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
gtk_tree_path_free (*tree_path);
|
|
|
|
*tree_path = next_path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("Index value is too large\n");
|
|
|
|
gtk_tree_path_free (*tree_path);
|
|
|
|
*tree_path = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-06-23 02:27:10 +00:00
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-06-30 00:50:50 +00:00
|
|
|
get_path_column_from_index (GtkTreeView *tree_view,
|
|
|
|
gint index,
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkTreePath **path,
|
|
|
|
GtkTreeViewColumn **column)
|
|
|
|
{
|
|
|
|
GtkTreeModel *tree_model;
|
2011-06-23 02:27:10 +00:00
|
|
|
AtkObject *atk_obj;
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessible *accessible;
|
2011-06-23 02:27:10 +00:00
|
|
|
|
|
|
|
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (tree_view));
|
2011-06-30 00:50:50 +00:00
|
|
|
accessible = GTK_TREE_VIEW_ACCESSIBLE (atk_obj);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
tree_model = gtk_tree_view_get_model (tree_view);
|
2011-06-30 00:50:50 +00:00
|
|
|
if (accessible->n_cols == 0)
|
2007-12-18 13:51:12 +00:00
|
|
|
return FALSE;
|
|
|
|
/* First row is the column headers */
|
2011-06-30 00:50:50 +00:00
|
|
|
index -= accessible->n_cols;
|
2007-12-18 13:51:12 +00:00
|
|
|
if (index < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
gint row_index;
|
|
|
|
gboolean retval;
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
row_index = index / accessible->n_cols;
|
2007-12-18 13:51:12 +00:00
|
|
|
retval = get_tree_path_from_row_index (tree_model, row_index, path);
|
2011-06-29 03:42:50 +00:00
|
|
|
if (!retval)
|
|
|
|
return FALSE;
|
2007-12-18 13:51:12 +00:00
|
|
|
if (*path == NULL)
|
|
|
|
return FALSE;
|
2011-06-30 00:50:50 +00:00
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
if (column)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
*column = gtk_tree_view_get_column (tree_view, index % accessible->n_cols);
|
2007-12-18 13:51:12 +00:00
|
|
|
if (*column == NULL)
|
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
if (path)
|
2007-12-18 13:51:12 +00:00
|
|
|
gtk_tree_path_free (*path);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-07-09 22:30:59 +00:00
|
|
|
set_cell_expandable (GtkCellAccessible *cell)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-07-09 22:30:59 +00:00
|
|
|
if (_gtk_cell_accessible_add_state (cell, ATK_STATE_EXPANDABLE, FALSE))
|
|
|
|
_gtk_cell_accessible_add_action (cell,
|
|
|
|
"expand or contract",
|
|
|
|
"expands or contracts the row in the tree view containing this cell",
|
|
|
|
NULL, toggle_cell_expanded);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
static GtkTreeViewAccessibleCellInfo *
|
|
|
|
find_cell_info (GtkTreeViewAccessible *accessible,
|
2011-07-09 22:30:59 +00:00
|
|
|
GtkCellAccessible *cell,
|
2011-06-30 00:50:50 +00:00
|
|
|
gboolean live_only)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-30 00:50:50 +00:00
|
|
|
GtkTreeViewAccessibleCellInfo *cell_info;
|
2011-06-23 02:27:10 +00:00
|
|
|
GHashTableIter iter;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-30 00:50:50 +00:00
|
|
|
/* Clean GtkTreeViewAccessibleCellInfo data */
|
|
|
|
g_hash_table_iter_init (&iter, accessible->cell_info_by_index);
|
2011-06-23 02:27:10 +00:00
|
|
|
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cell_info))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
if (cell_info->cell == cell && (!live_only || cell_info->in_use))
|
2011-06-23 02:27:10 +00:00
|
|
|
return cell_info;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static AtkObject *
|
|
|
|
get_header_from_column (GtkTreeViewColumn *tv_col)
|
|
|
|
{
|
|
|
|
AtkObject *rc;
|
|
|
|
GtkWidget *header_widget;
|
|
|
|
|
|
|
|
if (tv_col == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-06-23 21:45:36 +00:00
|
|
|
header_widget = gtk_tree_view_column_get_button (tv_col);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-23 21:45:36 +00:00
|
|
|
if (header_widget)
|
|
|
|
rc = gtk_widget_get_accessible (header_widget);
|
|
|
|
else
|
|
|
|
rc = NULL;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|