| 1 |
/* GTK+ - accessibility implementations |
| 2 |
* Copyright 2001, 2002, 2003 Sun Microsystems Inc. |
| 3 |
* |
| 4 |
* This library is free software; you can redistribute it and/or |
| 5 |
* modify it under the terms of the GNU Lesser General Public |
| 6 |
* License as published by the Free Software Foundation; either |
| 7 |
* version 2 of the License, or (at your option) any later version. |
| 8 |
* |
| 9 |
* This library is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
* Lesser General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU Lesser General Public |
| 15 |
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
#include "config.h" |
| 19 |
|
| 20 |
#include <gtk/gtk.h> |
| 21 |
#ifdef GDK_WINDOWING_X11 |
| 22 |
#include <gdk/x11/gdkx.h> |
| 23 |
#endif |
| 24 |
|
| 25 |
#include "gtktreeprivate.h" |
| 26 |
#include "gtkwidgetprivate.h" |
| 27 |
|
| 28 |
#include "gtktreeviewaccessibleprivate.h" |
| 29 |
|
| 30 |
#include "gtkrenderercellaccessible.h" |
| 31 |
#include "gtkbooleancellaccessible.h" |
| 32 |
#include "gtkimagecellaccessible.h" |
| 33 |
#include "gtkcontainercellaccessible.h" |
| 34 |
#include "gtktextcellaccessible.h" |
| 35 |
#include "gtkcellaccessibleparent.h" |
| 36 |
#include "gtkcellaccessibleprivate.h" |
| 37 |
|
| 38 |
struct _GtkTreeViewAccessiblePrivate |
| 39 |
{ |
| 40 |
GHashTable *cell_infos; |
| 41 |
}; |
| 42 |
|
| 43 |
typedef struct _GtkTreeViewAccessibleCellInfo GtkTreeViewAccessibleCellInfo; |
| 44 |
struct _GtkTreeViewAccessibleCellInfo |
| 45 |
{ |
| 46 |
GtkCellAccessible *cell; |
| 47 |
GtkRBTree *tree; |
| 48 |
GtkRBNode *node; |
| 49 |
GtkTreeViewColumn *cell_col_ref; |
| 50 |
GtkTreeViewAccessible *view; |
| 51 |
}; |
| 52 |
|
| 53 |
/* Misc */ |
| 54 |
|
| 55 |
static int cell_info_get_index (GtkTreeView *tree_view, |
| 56 |
GtkTreeViewAccessibleCellInfo *info); |
| 57 |
static gboolean is_cell_showing (GtkTreeView *tree_view, |
| 58 |
GdkRectangle *cell_rect); |
| 59 |
|
| 60 |
static void cell_info_new (GtkTreeViewAccessible *accessible, |
| 61 |
GtkRBTree *tree, |
| 62 |
GtkRBNode *node, |
| 63 |
GtkTreeViewColumn *tv_col, |
| 64 |
GtkCellAccessible *cell); |
| 65 |
static gint get_column_number (GtkTreeView *tree_view, |
| 66 |
GtkTreeViewColumn *column); |
| 67 |
|
| 68 |
static gboolean get_rbtree_column_from_index (GtkTreeView *tree_view, |
| 69 |
gint index, |
| 70 |
GtkRBTree **tree, |
| 71 |
GtkRBNode **node, |
| 72 |
GtkTreeViewColumn **column); |
| 73 |
|
| 74 |
static GtkTreeViewAccessibleCellInfo* find_cell_info (GtkTreeViewAccessible *view, |
| 75 |
GtkCellAccessible *cell); |
| 76 |
static AtkObject * get_header_from_column (GtkTreeViewColumn *tv_col); |
| 77 |
|
| 78 |
|
| 79 |
static void atk_table_interface_init (AtkTableIface *iface); |
| 80 |
static void atk_selection_interface_init (AtkSelectionIface *iface); |
| 81 |
static void atk_component_interface_init (AtkComponentIface *iface); |
| 82 |
static void gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface); |
| 83 |
|
| 84 |
G_DEFINE_TYPE_WITH_CODE (GtkTreeViewAccessible, gtk_tree_view_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE, |
| 85 |
G_ADD_PRIVATE (GtkTreeViewAccessible) |
| 86 |
G_IMPLEMENT_INTERFACE (ATK_TYPE_TABLE, atk_table_interface_init) |
| 87 |
G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init) |
| 88 |
G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init) |
| 89 |
G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_ACCESSIBLE_PARENT, gtk_cell_accessible_parent_interface_init)) |
| 90 |
|
| 91 |
|
| 92 |
static GQuark |
| 93 |
gtk_tree_view_accessible_get_data_quark (void) |
| 94 |
{ |
| 95 |
static GQuark quark = 0; |
| 96 |
|
| 97 |
if (G_UNLIKELY (quark == 0)) |
| 98 |
quark = g_quark_from_static_string ("gtk-tree-view-accessible-data"); |
| 99 |
|
| 100 |
return quark; |
| 101 |
} |
| 102 |
|
| 103 |
static void |
| 104 |
cell_info_free (GtkTreeViewAccessibleCellInfo *cell_info) |
| 105 |
{ |
| 106 |
gtk_accessible_set_widget (GTK_ACCESSIBLE (cell_info->cell), NULL); |
| 107 |
if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (cell_info->cell)) |
| 108 |
{ |
| 109 |
GList *children; |
| 110 |
|
| 111 |
while ((children = gtk_container_cell_accessible_get_children (GTK_CONTAINER_CELL_ACCESSIBLE (cell_info->cell))) != NULL) |
| 112 |
{ |
| 113 |
GtkCellAccessible *child = children->data; |
| 114 |
gtk_container_cell_accessible_remove_child (GTK_CONTAINER_CELL_ACCESSIBLE (cell_info->cell), child); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
g_object_unref (cell_info->cell); |
| 119 |
|
| 120 |
g_free (cell_info); |
| 121 |
} |
| 122 |
|
| 123 |
static GtkTreePath * |
| 124 |
cell_info_get_path (GtkTreeViewAccessibleCellInfo *cell_info) |
| 125 |
{ |
| 126 |
return _gtk_tree_path_new_from_rbtree (cell_info->tree, cell_info->node); |
| 127 |
} |
| 128 |
|
| 129 |
static guint |
| 130 |
cell_info_hash (gconstpointer info) |
| 131 |
{ |
| 132 |
const GtkTreeViewAccessibleCellInfo *cell_info = info; |
| 133 |
guint node, col; |
| 134 |
|
| 135 |
node = GPOINTER_TO_UINT (cell_info->node); |
| 136 |
col = GPOINTER_TO_UINT (cell_info->cell_col_ref); |
| 137 |
|
| 138 |
return ((node << sizeof (guint) / 2) | (node >> sizeof (guint) / 2)) ^ col; |
| 139 |
} |
| 140 |
|
| 141 |
static gboolean |
| 142 |
cell_info_equal (gconstpointer a, gconstpointer b) |
| 143 |
{ |
| 144 |
const GtkTreeViewAccessibleCellInfo *cell_info_a = a; |
| 145 |
const GtkTreeViewAccessibleCellInfo *cell_info_b = b; |
| 146 |
|
| 147 |
return cell_info_a->node == cell_info_b->node && |
| 148 |
cell_info_a->cell_col_ref == cell_info_b->cell_col_ref; |
| 149 |
} |
| 150 |
|
| 151 |
static void |
| 152 |
gtk_tree_view_accessible_initialize (AtkObject *obj, |
| 153 |
gpointer data) |
| 154 |
{ |
| 155 |
GtkTreeViewAccessible *accessible; |
| 156 |
GtkTreeView *tree_view; |
| 157 |
GtkTreeModel *tree_model; |
| 158 |
GtkWidget *widget; |
| 159 |
|
| 160 |
ATK_OBJECT_CLASS (gtk_tree_view_accessible_parent_class)->initialize (obj, data); |
| 161 |
|
| 162 |
accessible = GTK_TREE_VIEW_ACCESSIBLE (obj); |
| 163 |
|
| 164 |
accessible->priv->cell_infos = g_hash_table_new_full (cell_info_hash, |
| 165 |
cell_info_equal, NULL, (GDestroyNotify) cell_info_free); |
| 166 |
|
| 167 |
widget = GTK_WIDGET (data); |
| 168 |
tree_view = GTK_TREE_VIEW (widget); |
| 169 |
tree_model = gtk_tree_view_get_model (tree_view); |
| 170 |
|
| 171 |
if (tree_model) |
| 172 |
{ |
| 173 |
if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY) |
| 174 |
obj->role = ATK_ROLE_TABLE; |
| 175 |
else |
| 176 |
obj->role = ATK_ROLE_TREE_TABLE; |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
static void |
| 181 |
gtk_tree_view_accessible_finalize (GObject *object) |
| 182 |
{ |
| 183 |
GtkTreeViewAccessible *accessible = GTK_TREE_VIEW_ACCESSIBLE (object); |
| 184 |
|
| 185 |
if (accessible->priv->cell_infos) |
| 186 |
g_hash_table_destroy (accessible->priv->cell_infos); |
| 187 |
|
| 188 |
G_OBJECT_CLASS (gtk_tree_view_accessible_parent_class)->finalize (object); |
| 189 |
} |
| 190 |
|
| 191 |
static void |
| 192 |
gtk_tree_view_accessible_notify_gtk (GObject *obj, |
| 193 |
GParamSpec *pspec) |
| 194 |
{ |
| 195 |
GtkWidget *widget; |
| 196 |
GtkTreeView *tree_view; |
| 197 |
GtkTreeViewAccessible *accessible; |
| 198 |
|
| 199 |
widget = GTK_WIDGET (obj); |
| 200 |
accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (widget)); |
| 201 |
tree_view = GTK_TREE_VIEW (widget); |
| 202 |
|
| 203 |
if (g_strcmp0 (pspec->name, "model") == 0) |
| 204 |
{ |
| 205 |
GtkTreeModel *tree_model; |
| 206 |
AtkRole role; |
| 207 |
|
| 208 |
tree_model = gtk_tree_view_get_model (tree_view); |
| 209 |
g_hash_table_remove_all (accessible->priv->cell_infos); |
| 210 |
|
| 211 |
if (tree_model) |
| 212 |
{ |
| 213 |
if (gtk_tree_model_get_flags (tree_model) & GTK_TREE_MODEL_LIST_ONLY) |
| 214 |
role = ATK_ROLE_TABLE; |
| 215 |
else |
| 216 |
role = ATK_ROLE_TREE_TABLE; |
| 217 |
} |
| 218 |
else |
| 219 |
{ |
| 220 |
role = ATK_ROLE_UNKNOWN; |
| 221 |
} |
| 222 |
atk_object_set_role (ATK_OBJECT (accessible), role); |
| 223 |
g_object_freeze_notify (G_OBJECT (accessible)); |
| 224 |
g_signal_emit_by_name (accessible, "model-changed"); |
| 225 |
g_signal_emit_by_name (accessible, "visible-data-changed"); |
| 226 |
g_object_thaw_notify (G_OBJECT (accessible)); |
| 227 |
} |
| 228 |
else |
| 229 |
GTK_WIDGET_ACCESSIBLE_CLASS (gtk_tree_view_accessible_parent_class)->notify_gtk (obj, pspec); |
| 230 |
} |
| 231 |
|
| 232 |
static void |
| 233 |
gtk_tree_view_accessible_widget_unset (GtkAccessible *gtkaccessible) |
| 234 |
{ |
| 235 |
GtkTreeViewAccessible *accessible = GTK_TREE_VIEW_ACCESSIBLE (gtkaccessible); |
| 236 |
|
| 237 |
g_hash_table_remove_all (accessible->priv->cell_infos); |
| 238 |
|
| 239 |
GTK_ACCESSIBLE_CLASS (gtk_tree_view_accessible_parent_class)->widget_unset (gtkaccessible); |
| 240 |
} |
| 241 |
|
| 242 |
static gint |
| 243 |
get_n_rows (GtkTreeView *tree_view) |
| 244 |
{ |
| 245 |
GtkRBTree *tree; |
| 246 |
|
| 247 |
tree = _gtk_tree_view_get_rbtree (tree_view); |
| 248 |
|
| 249 |
if (tree == NULL) |
| 250 |
return 0; |
| 251 |
|
| 252 |
return tree->root->total_count; |
| 253 |
} |
| 254 |
|
| 255 |
static gint |
| 256 |
get_n_columns (GtkTreeView *tree_view) |
| 257 |
{ |
| 258 |
guint i, visible_columns; |
| 259 |
|
| 260 |
visible_columns = 0; |
| 261 |
|
| 262 |
for (i = 0; i < gtk_tree_view_get_n_columns (tree_view); i++) |
| 263 |
{ |
| 264 |
GtkTreeViewColumn *column = gtk_tree_view_get_column (tree_view, i); |
| 265 |
|
| 266 |
if (gtk_tree_view_column_get_visible (column)) |
| 267 |
visible_columns++; |
| 268 |
} |
| 269 |
|
| 270 |
return visible_columns; |
| 271 |
} |
| 272 |
|
| 273 |
static gint |
| 274 |
gtk_tree_view_accessible_get_n_children (AtkObject *obj) |
| 275 |
{ |
| 276 |
GtkWidget *widget; |
| 277 |
GtkTreeView *tree_view; |
| 278 |
|
| 279 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); |
| 280 |
if (widget == NULL) |
| 281 |
return 0; |
| 282 |
|
| 283 |
tree_view = GTK_TREE_VIEW (widget); |
| 284 |
return (get_n_rows (tree_view) + 1) * get_n_columns (tree_view); |
| 285 |
} |
| 286 |
|
| 287 |
static GtkTreeViewColumn * |
| 288 |
get_visible_column (GtkTreeView *tree_view, |
| 289 |
guint id) |
| 290 |
{ |
| 291 |
guint i; |
| 292 |
|
| 293 |
for (i = 0; i < gtk_tree_view_get_n_columns (tree_view); i++) |
| 294 |
{ |
| 295 |
GtkTreeViewColumn *column = gtk_tree_view_get_column (tree_view, i); |
| 296 |
|
| 297 |
if (!gtk_tree_view_column_get_visible (column)) |
| 298 |
continue; |
| 299 |
|
| 300 |
if (id == 0) |
| 301 |
return column; |
| 302 |
|
| 303 |
id--; |
| 304 |
} |
| 305 |
|
| 306 |
g_return_val_if_reached (NULL); |
| 307 |
} |
| 308 |
|
| 309 |
static void |
| 310 |
set_cell_data (GtkTreeView *treeview, |
| 311 |
GtkTreeViewAccessible *accessible, |
| 312 |
GtkCellAccessible *cell) |
| 313 |
{ |
| 314 |
GtkTreeViewAccessibleCellInfo *cell_info; |
| 315 |
gboolean is_expander, is_expanded; |
| 316 |
GtkTreeModel *model; |
| 317 |
GtkTreeIter iter; |
| 318 |
GtkTreePath *path; |
| 319 |
|
| 320 |
cell_info = find_cell_info (accessible, cell); |
| 321 |
if (!cell_info) |
| 322 |
return; |
| 323 |
|
| 324 |
model = gtk_tree_view_get_model (treeview); |
| 325 |
|
| 326 |
if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_PARENT) && |
| 327 |
cell_info->cell_col_ref == gtk_tree_view_get_expander_column (treeview)) |
| 328 |
{ |
| 329 |
is_expander = TRUE; |
| 330 |
is_expanded = cell_info->node->children != NULL; |
| 331 |
} |
| 332 |
else |
| 333 |
{ |
| 334 |
is_expander = FALSE; |
| 335 |
is_expanded = FALSE; |
| 336 |
} |
| 337 |
|
| 338 |
path = cell_info_get_path (cell_info); |
| 339 |
if (path == NULL || |
| 340 |
!gtk_tree_model_get_iter (model, &iter, path)) |
| 341 |
{ |
| 342 |
/* We only track valid cells, this should never happen */ |
| 343 |
g_return_if_reached (); |
| 344 |
} |
| 345 |
gtk_tree_path_free (path); |
| 346 |
|
| 347 |
gtk_tree_view_column_cell_set_cell_data (cell_info->cell_col_ref, |
| 348 |
model, |
| 349 |
&iter, |
| 350 |
is_expander, |
| 351 |
is_expanded); |
| 352 |
} |
| 353 |
|
| 354 |
static GtkCellAccessible * |
| 355 |
peek_cell (GtkTreeViewAccessible *accessible, |
| 356 |
GtkRBTree *tree, |
| 357 |
GtkRBNode *node, |
| 358 |
GtkTreeViewColumn *column) |
| 359 |
{ |
| 360 |
GtkTreeViewAccessibleCellInfo lookup, *cell_info; |
| 361 |
|
| 362 |
lookup.tree = tree; |
| 363 |
lookup.node = node; |
| 364 |
lookup.cell_col_ref = column; |
| 365 |
|
| 366 |
cell_info = g_hash_table_lookup (accessible->priv->cell_infos, &lookup); |
| 367 |
if (cell_info == NULL) |
| 368 |
return NULL; |
| 369 |
|
| 370 |
return cell_info->cell; |
| 371 |
} |
| 372 |
|
| 373 |
static GtkCellAccessible * |
| 374 |
create_cell_accessible_for_renderer (GtkCellRenderer *renderer, |
| 375 |
GtkWidget *widget, |
| 376 |
AtkObject *parent) |
| 377 |
{ |
| 378 |
GtkCellAccessible *cell; |
| 379 |
|
| 380 |
cell = GTK_CELL_ACCESSIBLE (gtk_renderer_cell_accessible_new (renderer)); |
| 381 |
|
| 382 |
_gtk_cell_accessible_initialize (cell, widget, parent); |
| 383 |
|
| 384 |
return cell; |
| 385 |
} |
| 386 |
|
| 387 |
static GtkCellAccessible * |
| 388 |
create_cell_accessible (GtkTreeView *treeview, |
| 389 |
GtkTreeViewAccessible *accessible, |
| 390 |
GtkTreeViewColumn *column) |
| 391 |
{ |
| 392 |
GList *renderer_list; |
| 393 |
GList *l; |
| 394 |
GtkCellAccessible *cell; |
| 395 |
|
| 396 |
renderer_list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column)); |
| 397 |
|
| 398 |
/* If there is exactly one renderer in the list (which is a |
| 399 |
* common case), shortcut and don't make a container |
| 400 |
*/ |
| 401 |
if (g_list_length (renderer_list) == 1) |
| 402 |
{ |
| 403 |
cell = create_cell_accessible_for_renderer (renderer_list->data, GTK_WIDGET (treeview), ATK_OBJECT (accessible)); |
| 404 |
} |
| 405 |
else |
| 406 |
{ |
| 407 |
GtkContainerCellAccessible *container; |
| 408 |
|
| 409 |
container = gtk_container_cell_accessible_new (); |
| 410 |
_gtk_cell_accessible_initialize (GTK_CELL_ACCESSIBLE (container), GTK_WIDGET (treeview), ATK_OBJECT (accessible)); |
| 411 |
|
| 412 |
for (l = renderer_list; l; l = l->next) |
| 413 |
{ |
| 414 |
cell = create_cell_accessible_for_renderer (l->data, GTK_WIDGET (treeview), ATK_OBJECT (container)); |
| 415 |
gtk_container_cell_accessible_add_child (container, cell); |
| 416 |
g_object_unref (cell); |
| 417 |
} |
| 418 |
|
| 419 |
cell = GTK_CELL_ACCESSIBLE (container); |
| 420 |
} |
| 421 |
|
| 422 |
g_list_free (renderer_list); |
| 423 |
|
| 424 |
return cell; |
| 425 |
} |
| 426 |
|
| 427 |
static GtkCellAccessible * |
| 428 |
create_cell (GtkTreeView *treeview, |
| 429 |
GtkTreeViewAccessible *accessible, |
| 430 |
GtkRBTree *tree, |
| 431 |
GtkRBNode *node, |
| 432 |
GtkTreeViewColumn *column) |
| 433 |
{ |
| 434 |
GtkCellAccessible *cell; |
| 435 |
|
| 436 |
cell = create_cell_accessible (treeview, accessible, column); |
| 437 |
cell_info_new (accessible, tree, node, column, cell); |
| 438 |
|
| 439 |
set_cell_data (treeview, accessible, cell); |
| 440 |
_gtk_cell_accessible_update_cache (cell, FALSE); |
| 441 |
|
| 442 |
return cell; |
| 443 |
} |
| 444 |
|
| 445 |
static AtkObject * |
| 446 |
gtk_tree_view_accessible_ref_child (AtkObject *obj, |
| 447 |
gint i) |
| 448 |
{ |
| 449 |
GtkWidget *widget; |
| 450 |
GtkTreeViewAccessible *accessible; |
| 451 |
GtkCellAccessible *cell; |
| 452 |
GtkTreeView *tree_view; |
| 453 |
GtkTreeViewColumn *tv_col; |
| 454 |
GtkRBTree *tree; |
| 455 |
GtkRBNode *node; |
| 456 |
AtkObject *child; |
| 457 |
|
| 458 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); |
| 459 |
if (widget == NULL) |
| 460 |
return NULL; |
| 461 |
|
| 462 |
if (i >= gtk_tree_view_accessible_get_n_children (obj)) |
| 463 |
return NULL; |
| 464 |
|
| 465 |
accessible = GTK_TREE_VIEW_ACCESSIBLE (obj); |
| 466 |
tree_view = GTK_TREE_VIEW (widget); |
| 467 |
if (i < get_n_columns (tree_view)) |
| 468 |
{ |
| 469 |
tv_col = get_visible_column (tree_view, i); |
| 470 |
child = get_header_from_column (tv_col); |
| 471 |
if (child) |
| 472 |
g_object_ref (child); |
| 473 |
return child; |
| 474 |
} |
| 475 |
|
| 476 |
/* Find the RBTree and GtkTreeViewColumn for the index */ |
| 477 |
if (!get_rbtree_column_from_index (tree_view, i, &tree, &node, &tv_col)) |
| 478 |
return NULL; |
| 479 |
|
| 480 |
cell = peek_cell (accessible, tree, node, tv_col); |
| 481 |
if (cell == NULL) |
| 482 |
cell = create_cell (tree_view, accessible, tree, node, tv_col); |
| 483 |
|
| 484 |
return ATK_OBJECT (g_object_ref (cell)); |
| 485 |
} |
| 486 |
|
| 487 |
static AtkStateSet* |
| 488 |
gtk_tree_view_accessible_ref_state_set (AtkObject *obj) |
| 489 |
{ |
| 490 |
AtkStateSet *state_set; |
| 491 |
GtkWidget *widget; |
| 492 |
|
| 493 |
state_set = ATK_OBJECT_CLASS (gtk_tree_view_accessible_parent_class)->ref_state_set (obj); |
| 494 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); |
| 495 |
|
| 496 |
if (widget != NULL) |
| 497 |
atk_state_set_add_state (state_set, ATK_STATE_MANAGES_DESCENDANTS); |
| 498 |
|
| 499 |
return state_set; |
| 500 |
} |
| 501 |
|
| 502 |
static void |
| 503 |
gtk_tree_view_accessible_class_init (GtkTreeViewAccessibleClass *klass) |
| 504 |
{ |
| 505 |
AtkObjectClass *class = ATK_OBJECT_CLASS (klass); |
| 506 |
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); |
| 507 |
GtkAccessibleClass *accessible_class = (GtkAccessibleClass*)klass; |
| 508 |
GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass; |
| 509 |
GtkContainerAccessibleClass *container_class = (GtkContainerAccessibleClass*)klass; |
| 510 |
|
| 511 |
class->get_n_children = gtk_tree_view_accessible_get_n_children; |
| 512 |
class->ref_child = gtk_tree_view_accessible_ref_child; |
| 513 |
class->ref_state_set = gtk_tree_view_accessible_ref_state_set; |
| 514 |
class->initialize = gtk_tree_view_accessible_initialize; |
| 515 |
|
| 516 |
widget_class->notify_gtk = gtk_tree_view_accessible_notify_gtk; |
| 517 |
|
| 518 |
accessible_class->widget_unset = gtk_tree_view_accessible_widget_unset; |
| 519 |
|
| 520 |
/* The children of a GtkTreeView are the buttons at the top of the columns |
| 521 |
* we do not represent these as children so we do not want to report |
| 522 |
* children added or deleted when these changed. |
| 523 |
*/ |
| 524 |
container_class->add_gtk = NULL; |
| 525 |
container_class->remove_gtk = NULL; |
| 526 |
|
| 527 |
gobject_class->finalize = gtk_tree_view_accessible_finalize; |
| 528 |
} |
| 529 |
|
| 530 |
static void |
| 531 |
gtk_tree_view_accessible_init (GtkTreeViewAccessible *view) |
| 532 |
{ |
| 533 |
view->priv = gtk_tree_view_accessible_get_instance_private (view); |
| 534 |
} |
| 535 |
|
| 536 |
/* atkcomponent.h */ |
| 537 |
|
| 538 |
static AtkObject * |
| 539 |
gtk_tree_view_accessible_ref_accessible_at_point (AtkComponent *component, |
| 540 |
gint x, |
| 541 |
gint y, |
| 542 |
AtkCoordType coord_type) |
| 543 |
{ |
| 544 |
GtkWidget *widget; |
| 545 |
GtkTreeView *tree_view; |
| 546 |
GtkTreePath *path; |
| 547 |
GtkTreeViewColumn *column; |
| 548 |
gint x_pos, y_pos; |
| 549 |
gint bx, by; |
| 550 |
GtkCellAccessible *cell; |
| 551 |
GtkRBTree *tree; |
| 552 |
GtkRBNode *node; |
| 553 |
|
| 554 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component)); |
| 555 |
if (widget == NULL) |
| 556 |
return NULL; |
| 557 |
|
| 558 |
tree_view = GTK_TREE_VIEW (widget); |
| 559 |
|
| 560 |
atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type); |
| 561 |
gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, x, y, &bx, &by); |
| 562 |
if (!gtk_tree_view_get_path_at_pos (tree_view, |
| 563 |
bx - x_pos, by - y_pos, |
| 564 |
&path, &column, NULL, NULL)) |
| 565 |
return NULL; |
| 566 |
|
| 567 |
if (_gtk_tree_view_find_node (tree_view, path, &tree, &node)) |
| 568 |
{ |
| 569 |
gtk_tree_path_free (path); |
| 570 |
return NULL; |
| 571 |
} |
| 572 |
|
| 573 |
cell = peek_cell (GTK_TREE_VIEW_ACCESSIBLE (component), tree, node, column); |
| 574 |
if (cell == NULL) |
| 575 |
cell = create_cell (tree_view, GTK_TREE_VIEW_ACCESSIBLE (component), tree, node, column); |
| 576 |
|
| 577 |
return ATK_OBJECT (g_object_ref (cell)); |
| 578 |
} |
| 579 |
|
| 580 |
static void |
| 581 |
atk_component_interface_init (AtkComponentIface *iface) |
| 582 |
{ |
| 583 |
iface->ref_accessible_at_point = gtk_tree_view_accessible_ref_accessible_at_point; |
| 584 |
} |
| 585 |
|
| 586 |
/* atktable.h */ |
| 587 |
|
| 588 |
static gint |
| 589 |
gtk_tree_view_accessible_get_index_at (AtkTable *table, |
| 590 |
gint row, |
| 591 |
gint column) |
| 592 |
{ |
| 593 |
GtkWidget *widget; |
| 594 |
gint n_cols, n_rows; |
| 595 |
|
| 596 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table)); |
| 597 |
if (widget == NULL) |
| 598 |
return -1; |
| 599 |
|
| 600 |
n_cols = atk_table_get_n_columns (table); |
| 601 |
n_rows = atk_table_get_n_rows (table); |
| 602 |
|
| 603 |
if (row >= n_rows || column >= n_cols) |
| 604 |
return -1; |
| 605 |
|
| 606 |
return (row + 1) * n_cols + column; |
| 607 |
} |
| 608 |
|
| 609 |
static gint |
| 610 |
gtk_tree_view_accessible_get_column_at_index (AtkTable *table, |
| 611 |
gint index) |
| 612 |
{ |
| 613 |
GtkWidget *widget; |
| 614 |
gint n_columns; |
| 615 |
|
| 616 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table)); |
| 617 |
if (widget == NULL) |
| 618 |
return -1; |
| 619 |
|
| 620 |
if (index >= gtk_tree_view_accessible_get_n_children (ATK_OBJECT (table))) |
| 621 |
return -1; |
| 622 |
|
| 623 |
n_columns = get_n_columns (GTK_TREE_VIEW (widget)); |
| 624 |
|
| 625 |
/* checked by the n_children() check above */ |
| 626 |
g_assert (n_columns > 0); |
| 627 |
|
| 628 |
return index % n_columns; |
| 629 |
} |
| 630 |
|
| 631 |
static gint |
| 632 |
gtk_tree_view_accessible_get_row_at_index (AtkTable *table, |
| 633 |
gint index) |
| 634 |
{ |
| 635 |
GtkWidget *widget; |
| 636 |
GtkTreeView *tree_view; |
| 637 |
|
| 638 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table)); |
| 639 |
if (widget == NULL) |
| 640 |
return -1; |
| 641 |
|
| 642 |
tree_view = GTK_TREE_VIEW (widget); |
| 643 |
|
| 644 |
index /= get_n_columns (tree_view); |
| 645 |
index--; |
| 646 |
if (index >= get_n_rows (tree_view)) |
| 647 |
return -1; |
| 648 |
|
| 649 |
return index; |
| 650 |
} |
| 651 |
|
| 652 |
static AtkObject * |
| 653 |
gtk_tree_view_accessible_table_ref_at (AtkTable *table, |
| 654 |
gint row, |
| 655 |
gint column) |
| 656 |
{ |
| 657 |
gint index; |
| 658 |
|
| 659 |
index = gtk_tree_view_accessible_get_index_at (table, row, column); |
| 660 |
if (index == -1) |
| 661 |
return NULL; |
| 662 |
|
| 663 |
return gtk_tree_view_accessible_ref_child (ATK_OBJECT (table), index); |
| 664 |
} |
| 665 |
|
| 666 |
static gint |
| 667 |
gtk_tree_view_accessible_get_n_rows (AtkTable *table) |
| 668 |
{ |
| 669 |
GtkWidget *widget; |
| 670 |
|
| 671 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table)); |
| 672 |
if (widget == NULL) |
| 673 |
return 0; |
| 674 |
|
| 675 |
return get_n_rows (GTK_TREE_VIEW (widget)); |
| 676 |
} |
| 677 |
|
| 678 |
static gint |
| 679 |
gtk_tree_view_accessible_get_n_columns (AtkTable *table) |
| 680 |
{ |
| 681 |
GtkWidget *widget; |
| 682 |
|
| 683 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table)); |
| 684 |
if (widget == NULL) |
| 685 |
return 0; |
| 686 |
|
| 687 |
return get_n_columns (GTK_TREE_VIEW (widget)); |
| 688 |
} |
| 689 |
|
| 690 |
static gboolean |
| 691 |
gtk_tree_view_accessible_is_row_selected (AtkTable *table, |
| 692 |
gint row) |
| 693 |
{ |
| 694 |
GtkWidget *widget; |
| 695 |
GtkRBTree *tree; |
| 696 |
GtkRBNode *node; |
| 697 |
|
| 698 |
if (row < 0) |
| 699 |
return FALSE; |
| 700 |
|
| 701 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table)); |
| 702 |
if (widget == NULL) |
| 703 |
return FALSE; |
| 704 |
|
| 705 |
if (!_gtk_rbtree_find_index (_gtk_tree_view_get_rbtree (GTK_TREE_VIEW (widget)), |
| 706 |
row, |
| 707 |
&tree, |
| 708 |
&node)) |
| 709 |
return FALSE; |
| 710 |
|
| 711 |
return GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED); |
| 712 |
} |
| 713 |
|
| 714 |
static gboolean |
| 715 |
gtk_tree_view_accessible_is_selected (AtkTable *table, |
| 716 |
gint row, |
| 717 |
gint column) |
| 718 |
{ |
| 719 |
return gtk_tree_view_accessible_is_row_selected (table, row); |
| 720 |
} |
| 721 |
|
| 722 |
typedef struct { |
| 723 |
GArray *array; |
| 724 |
GtkTreeView *treeview; |
| 725 |
} SelectedRowsData; |
| 726 |
|
| 727 |
static void |
| 728 |
get_selected_rows (GtkTreeModel *model, |
| 729 |
GtkTreePath *path, |
| 730 |
GtkTreeIter *iter, |
| 731 |
gpointer datap) |
| 732 |
{ |
| 733 |
SelectedRowsData *data = datap; |
| 734 |
GtkRBTree *tree; |
| 735 |
GtkRBNode *node; |
| 736 |
int id; |
| 737 |
|
| 738 |
if (_gtk_tree_view_find_node (data->treeview, |
| 739 |
path, |
| 740 |
&tree, &node)) |
| 741 |
{ |
| 742 |
g_assert_not_reached (); |
| 743 |
} |
| 744 |
|
| 745 |
id = _gtk_rbtree_node_get_index (tree, node); |
| 746 |
|
| 747 |
g_array_append_val (data->array, id); |
| 748 |
} |
| 749 |
|
| 750 |
static gint |
| 751 |
gtk_tree_view_accessible_get_selected_rows (AtkTable *table, |
| 752 |
gint **rows_selected) |
| 753 |
{ |
| 754 |
SelectedRowsData data; |
| 755 |
GtkWidget *widget; |
| 756 |
gint n_rows; |
| 757 |
|
| 758 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table)); |
| 759 |
if (widget == NULL) |
| 760 |
{ |
| 761 |
if (rows_selected != NULL) |
| 762 |
*rows_selected = NULL; |
| 763 |
return 0; |
| 764 |
} |
| 765 |
|
| 766 |
data.treeview = GTK_TREE_VIEW (widget); |
| 767 |
data.array = g_array_new (FALSE, FALSE, sizeof (gint)); |
| 768 |
|
| 769 |
gtk_tree_selection_selected_foreach (gtk_tree_view_get_selection (data.treeview), |
| 770 |
get_selected_rows, |
| 771 |
&data); |
| 772 |
|
| 773 |
n_rows = data.array->len; |
| 774 |
if (rows_selected) |
| 775 |
*rows_selected = (gint *) g_array_free (data.array, FALSE); |
| 776 |
else |
| 777 |
g_array_free (data.array, TRUE); |
| 778 |
|
| 779 |
return n_rows; |
| 780 |
} |
| 781 |
|
| 782 |
static gboolean |
| 783 |
gtk_tree_view_accessible_add_row_selection (AtkTable *table, |
| 784 |
gint row) |
| 785 |
{ |
| 786 |
GtkTreeView *treeview; |
| 787 |
GtkTreePath *path; |
| 788 |
GtkRBTree *tree; |
| 789 |
GtkRBNode *node; |
| 790 |
|
| 791 |
if (row < 0) |
| 792 |
return FALSE; |
| 793 |
|
| 794 |
treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (table))); |
| 795 |
if (treeview == NULL) |
| 796 |
return FALSE; |
| 797 |
|
| 798 |
if (!_gtk_rbtree_find_index (_gtk_tree_view_get_rbtree (treeview), |
| 799 |
row, |
| 800 |
&tree, |
| 801 |
&node)) |
| 802 |
return FALSE; |
| 803 |
|
| 804 |
if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED)) |
| 805 |
return FALSE; |
| 806 |
|
| 807 |
path = _gtk_tree_path_new_from_rbtree (tree, node); |
| 808 |
gtk_tree_selection_select_path (gtk_tree_view_get_selection (treeview), path); |
| 809 |
gtk_tree_path_free (path); |
| 810 |
|
| 811 |
return TRUE; |
| 812 |
} |
| 813 |
|
| 814 |
static gboolean |
| 815 |
gtk_tree_view_accessible_remove_row_selection (AtkTable *table, |
| 816 |
gint row) |
| 817 |
{ |
| 818 |
GtkTreeView *treeview; |
| 819 |
GtkTreePath *path; |
| 820 |
GtkRBTree *tree; |
| 821 |
GtkRBNode *node; |
| 822 |
|
| 823 |
if (row < 0) |
| 824 |
return FALSE; |
| 825 |
|
| 826 |
treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (table))); |
| 827 |
if (treeview == NULL) |
| 828 |
return FALSE; |
| 829 |
|
| 830 |
if (!_gtk_rbtree_find_index (_gtk_tree_view_get_rbtree (treeview), |
| 831 |
row, |
| 832 |
&tree, |
| 833 |
&node)) |
| 834 |
return FALSE; |
| 835 |
|
| 836 |
if (! GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED)) |
| 837 |
return FALSE; |
| 838 |
|
| 839 |
path = _gtk_tree_path_new_from_rbtree (tree, node); |
| 840 |
gtk_tree_selection_unselect_path (gtk_tree_view_get_selection (treeview), path); |
| 841 |
gtk_tree_path_free (path); |
| 842 |
|
| 843 |
return TRUE; |
| 844 |
} |
| 845 |
|
| 846 |
static AtkObject * |
| 847 |
gtk_tree_view_accessible_get_column_header (AtkTable *table, |
| 848 |
gint in_col) |
| 849 |
{ |
| 850 |
GtkWidget *widget; |
| 851 |
GtkTreeView *tree_view; |
| 852 |
GtkTreeViewColumn *tv_col; |
| 853 |
|
| 854 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table)); |
| 855 |
if (widget == NULL) |
| 856 |
return NULL; |
| 857 |
|
| 858 |
tree_view = GTK_TREE_VIEW (widget); |
| 859 |
if (in_col < 0 || in_col >= get_n_columns (tree_view)) |
| 860 |
return NULL; |
| 861 |
|
| 862 |
tv_col = get_visible_column (tree_view, in_col); |
| 863 |
return get_header_from_column (tv_col); |
| 864 |
} |
| 865 |
|
| 866 |
static const gchar * |
| 867 |
gtk_tree_view_accessible_get_column_description (AtkTable *table, |
| 868 |
gint in_col) |
| 869 |
{ |
| 870 |
GtkWidget *widget; |
| 871 |
GtkTreeView *tree_view; |
| 872 |
GtkTreeViewColumn *tv_col; |
| 873 |
|
| 874 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (table)); |
| 875 |
if (widget == NULL) |
| 876 |
return NULL; |
| 877 |
|
| 878 |
tree_view = GTK_TREE_VIEW (widget); |
| 879 |
if (in_col < 0 || in_col >= get_n_columns (tree_view)) |
| 880 |
return NULL; |
| 881 |
|
| 882 |
tv_col = get_visible_column (tree_view, in_col); |
| 883 |
return gtk_tree_view_column_get_title (tv_col); |
| 884 |
} |
| 885 |
|
| 886 |
static void |
| 887 |
atk_table_interface_init (AtkTableIface *iface) |
| 888 |
{ |
| 889 |
iface->ref_at = gtk_tree_view_accessible_table_ref_at; |
| 890 |
iface->get_n_rows = gtk_tree_view_accessible_get_n_rows; |
| 891 |
iface->get_n_columns = gtk_tree_view_accessible_get_n_columns; |
| 892 |
iface->get_index_at = gtk_tree_view_accessible_get_index_at; |
| 893 |
iface->get_column_at_index = gtk_tree_view_accessible_get_column_at_index; |
| 894 |
iface->get_row_at_index = gtk_tree_view_accessible_get_row_at_index; |
| 895 |
iface->is_row_selected = gtk_tree_view_accessible_is_row_selected; |
| 896 |
iface->is_selected = gtk_tree_view_accessible_is_selected; |
| 897 |
iface->get_selected_rows = gtk_tree_view_accessible_get_selected_rows; |
| 898 |
iface->add_row_selection = gtk_tree_view_accessible_add_row_selection; |
| 899 |
iface->remove_row_selection = gtk_tree_view_accessible_remove_row_selection; |
| 900 |
iface->get_column_extent_at = NULL; |
| 901 |
iface->get_row_extent_at = NULL; |
| 902 |
iface->get_column_header = gtk_tree_view_accessible_get_column_header; |
| 903 |
iface->get_column_description = gtk_tree_view_accessible_get_column_description; |
| 904 |
} |
| 905 |
|
| 906 |
/* atkselection.h */ |
| 907 |
|
| 908 |
static gboolean |
| 909 |
gtk_tree_view_accessible_add_selection (AtkSelection *selection, |
| 910 |
gint i) |
| 911 |
{ |
| 912 |
AtkTable *table; |
| 913 |
gint n_columns; |
| 914 |
gint row; |
| 915 |
|
| 916 |
table = ATK_TABLE (selection); |
| 917 |
n_columns = gtk_tree_view_accessible_get_n_columns (table); |
| 918 |
if (n_columns != 1) |
| 919 |
return FALSE; |
| 920 |
|
| 921 |
row = gtk_tree_view_accessible_get_row_at_index (table, i); |
| 922 |
return gtk_tree_view_accessible_add_row_selection (table, row); |
| 923 |
} |
| 924 |
|
| 925 |
static gboolean |
| 926 |
gtk_tree_view_accessible_clear_selection (AtkSelection *selection) |
| 927 |
{ |
| 928 |
GtkWidget *widget; |
| 929 |
GtkTreeView *tree_view; |
| 930 |
GtkTreeSelection *tree_selection; |
| 931 |
|
| 932 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection)); |
| 933 |
if (widget == NULL) |
| 934 |
return FALSE; |
| 935 |
|
| 936 |
tree_view = GTK_TREE_VIEW (widget); |
| 937 |
tree_selection = gtk_tree_view_get_selection (tree_view); |
| 938 |
|
| 939 |
gtk_tree_selection_unselect_all (tree_selection); |
| 940 |
return TRUE; |
| 941 |
} |
| 942 |
|
| 943 |
static AtkObject * |
| 944 |
gtk_tree_view_accessible_ref_selection (AtkSelection *selection, |
| 945 |
gint i) |
| 946 |
{ |
| 947 |
AtkTable *table; |
| 948 |
gint row; |
| 949 |
gint n_selected; |
| 950 |
gint n_columns; |
| 951 |
gint *selected; |
| 952 |
|
| 953 |
table = ATK_TABLE (selection); |
| 954 |
n_columns = gtk_tree_view_accessible_get_n_columns (table); |
| 955 |
n_selected = gtk_tree_view_accessible_get_selected_rows (table, &selected); |
| 956 |
if (n_columns == 0 || i >= n_columns * n_selected) |
| 957 |
return NULL; |
| 958 |
|
| 959 |
row = selected[i / n_columns]; |
| 960 |
g_free (selected); |
| 961 |
|
| 962 |
return gtk_tree_view_accessible_table_ref_at (table, row, i % n_columns); |
| 963 |
} |
| 964 |
|
| 965 |
static gint |
| 966 |
gtk_tree_view_accessible_get_selection_count (AtkSelection *selection) |
| 967 |
{ |
| 968 |
AtkTable *table; |
| 969 |
gint n_selected; |
| 970 |
|
| 971 |
table = ATK_TABLE (selection); |
| 972 |
n_selected = gtk_tree_view_accessible_get_selected_rows (table, NULL); |
| 973 |
if (n_selected > 0) |
| 974 |
n_selected *= gtk_tree_view_accessible_get_n_columns (table); |
| 975 |
return n_selected; |
| 976 |
} |
| 977 |
|
| 978 |
static gboolean |
| 979 |
gtk_tree_view_accessible_is_child_selected (AtkSelection *selection, |
| 980 |
gint i) |
| 981 |
{ |
| 982 |
GtkWidget *widget; |
| 983 |
gint row; |
| 984 |
|
| 985 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection)); |
| 986 |
if (widget == NULL) |
| 987 |
return FALSE; |
| 988 |
|
| 989 |
row = gtk_tree_view_accessible_get_row_at_index (ATK_TABLE (selection), i); |
| 990 |
|
| 991 |
return gtk_tree_view_accessible_is_row_selected (ATK_TABLE (selection), row); |
| 992 |
} |
| 993 |
|
| 994 |
static void atk_selection_interface_init (AtkSelectionIface *iface) |
| 995 |
{ |
| 996 |
iface->add_selection = gtk_tree_view_accessible_add_selection; |
| 997 |
iface->clear_selection = gtk_tree_view_accessible_clear_selection; |
| 998 |
iface->ref_selection = gtk_tree_view_accessible_ref_selection; |
| 999 |
iface->get_selection_count = gtk_tree_view_accessible_get_selection_count; |
| 1000 |
iface->is_child_selected = gtk_tree_view_accessible_is_child_selected; |
| 1001 |
} |
| 1002 |
|
| 1003 |
#define EXTRA_EXPANDER_PADDING 4 |
| 1004 |
|
| 1005 |
static void |
| 1006 |
gtk_tree_view_accessible_get_cell_area (GtkCellAccessibleParent *parent, |
| 1007 |
GtkCellAccessible *cell, |
| 1008 |
GdkRectangle *cell_rect) |
| 1009 |
{ |
| 1010 |
GtkWidget *widget; |
| 1011 |
GtkTreeView *tree_view; |
| 1012 |
GtkTreeViewColumn *tv_col; |
| 1013 |
GtkTreePath *path; |
| 1014 |
AtkObject *parent_cell; |
| 1015 |
GtkTreeViewAccessibleCellInfo *cell_info; |
| 1016 |
GtkCellAccessible *top_cell; |
| 1017 |
|
| 1018 |
/* Default value. */ |
| 1019 |
cell_rect->x = 0; |
| 1020 |
cell_rect->y = 0; |
| 1021 |
cell_rect->width = 0; |
| 1022 |
cell_rect->height = 0; |
| 1023 |
|
| 1024 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)); |
| 1025 |
if (widget == NULL) |
| 1026 |
return; |
| 1027 |
|
| 1028 |
tree_view = GTK_TREE_VIEW (widget); |
| 1029 |
parent_cell = atk_object_get_parent (ATK_OBJECT (cell)); |
| 1030 |
if (parent_cell != ATK_OBJECT (parent)) |
| 1031 |
top_cell = GTK_CELL_ACCESSIBLE (parent_cell); |
| 1032 |
else |
| 1033 |
top_cell = cell; |
| 1034 |
cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), top_cell); |
| 1035 |
if (!cell_info) |
| 1036 |
return; |
| 1037 |
path = cell_info_get_path (cell_info); |
| 1038 |
tv_col = cell_info->cell_col_ref; |
| 1039 |
if (path) |
| 1040 |
{ |
| 1041 |
GtkTreeViewColumn *expander_column; |
| 1042 |
|
| 1043 |
gtk_tree_view_get_cell_area (tree_view, path, tv_col, cell_rect); |
| 1044 |
expander_column = gtk_tree_view_get_expander_column (tree_view); |
| 1045 |
if (expander_column == tv_col) |
| 1046 |
{ |
| 1047 |
gint expander_size; |
| 1048 |
gtk_widget_style_get (widget, |
| 1049 |
"expander-size", &expander_size, |
| 1050 |
NULL); |
| 1051 |
cell_rect->x += expander_size + EXTRA_EXPANDER_PADDING; |
| 1052 |
cell_rect->width -= expander_size + EXTRA_EXPANDER_PADDING; |
| 1053 |
} |
| 1054 |
|
| 1055 |
gtk_tree_path_free (path); |
| 1056 |
|
| 1057 |
/* A column has more than one renderer so we find the position |
| 1058 |
* and width of each |
| 1059 |
*/ |
| 1060 |
if (top_cell != cell) |
| 1061 |
{ |
| 1062 |
gint cell_index; |
| 1063 |
gboolean found; |
| 1064 |
gint cell_start; |
| 1065 |
gint cell_width; |
| 1066 |
GList *renderers; |
| 1067 |
GtkCellRenderer *renderer; |
| 1068 |
|
| 1069 |
cell_index = atk_object_get_index_in_parent (ATK_OBJECT (cell)); |
| 1070 |
renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col)); |
| 1071 |
renderer = g_list_nth_data (renderers, cell_index); |
| 1072 |
|
| 1073 |
found = gtk_tree_view_column_cell_get_position (tv_col, renderer, &cell_start, &cell_width); |
| 1074 |
if (found) |
| 1075 |
{ |
| 1076 |
cell_rect->x += cell_start; |
| 1077 |
cell_rect->width = cell_width; |
| 1078 |
} |
| 1079 |
g_list_free (renderers); |
| 1080 |
} |
| 1081 |
|
| 1082 |
} |
| 1083 |
} |
| 1084 |
|
| 1085 |
static void |
| 1086 |
gtk_tree_view_accessible_get_cell_extents (GtkCellAccessibleParent *parent, |
| 1087 |
GtkCellAccessible *cell, |
| 1088 |
gint *x, |
| 1089 |
gint *y, |
| 1090 |
gint *width, |
| 1091 |
gint *height, |
| 1092 |
AtkCoordType coord_type) |
| 1093 |
{ |
| 1094 |
GtkWidget *widget; |
| 1095 |
GtkTreeView *tree_view; |
| 1096 |
GdkWindow *bin_window; |
| 1097 |
GdkRectangle cell_rect; |
| 1098 |
gint w_x, w_y; |
| 1099 |
|
| 1100 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)); |
| 1101 |
if (widget == NULL) |
| 1102 |
return; |
| 1103 |
|
| 1104 |
tree_view = GTK_TREE_VIEW (widget); |
| 1105 |
gtk_tree_view_accessible_get_cell_area (parent, cell, &cell_rect); |
| 1106 |
bin_window = gtk_tree_view_get_bin_window (tree_view); |
| 1107 |
gdk_window_get_origin (bin_window, &w_x, &w_y); |
| 1108 |
|
| 1109 |
if (coord_type == ATK_XY_WINDOW) |
| 1110 |
{ |
| 1111 |
GdkWindow *window; |
| 1112 |
gint x_toplevel, y_toplevel; |
| 1113 |
|
| 1114 |
window = gdk_window_get_toplevel (bin_window); |
| 1115 |
gdk_window_get_origin (window, &x_toplevel, &y_toplevel); |
| 1116 |
|
| 1117 |
w_x -= x_toplevel; |
| 1118 |
w_y -= y_toplevel; |
| 1119 |
} |
| 1120 |
|
| 1121 |
*width = cell_rect.width; |
| 1122 |
*height = cell_rect.height; |
| 1123 |
if (is_cell_showing (tree_view, &cell_rect)) |
| 1124 |
{ |
| 1125 |
*x = cell_rect.x + w_x; |
| 1126 |
*y = cell_rect.y + w_y; |
| 1127 |
} |
| 1128 |
else |
| 1129 |
{ |
| 1130 |
*x = G_MININT; |
| 1131 |
*y = G_MININT; |
| 1132 |
} |
| 1133 |
} |
| 1134 |
|
| 1135 |
static gboolean |
| 1136 |
gtk_tree_view_accessible_grab_cell_focus (GtkCellAccessibleParent *parent, |
| 1137 |
GtkCellAccessible *cell) |
| 1138 |
{ |
| 1139 |
GtkWidget *widget; |
| 1140 |
GtkTreeView *tree_view; |
| 1141 |
GtkTreeViewColumn *tv_col; |
| 1142 |
GtkTreePath *path; |
| 1143 |
AtkObject *parent_cell; |
| 1144 |
AtkObject *cell_object; |
| 1145 |
GtkTreeViewAccessibleCellInfo *cell_info; |
| 1146 |
GtkCellRenderer *renderer = NULL; |
| 1147 |
GtkWidget *toplevel; |
| 1148 |
gint index; |
| 1149 |
|
| 1150 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)); |
| 1151 |
if (widget == NULL) |
| 1152 |
return FALSE; |
| 1153 |
|
| 1154 |
tree_view = GTK_TREE_VIEW (widget); |
| 1155 |
|
| 1156 |
cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell); |
| 1157 |
if (!cell_info) |
| 1158 |
return FALSE; |
| 1159 |
cell_object = ATK_OBJECT (cell); |
| 1160 |
parent_cell = atk_object_get_parent (cell_object); |
| 1161 |
tv_col = cell_info->cell_col_ref; |
| 1162 |
if (parent_cell != ATK_OBJECT (parent)) |
| 1163 |
{ |
| 1164 |
/* GtkCellAccessible is in a GtkContainerCellAccessible. |
| 1165 |
* The GtkTreeViewColumn has multiple renderers; |
| 1166 |
* find the corresponding one. |
| 1167 |
*/ |
| 1168 |
GList *renderers; |
| 1169 |
|
| 1170 |
renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (tv_col)); |
| 1171 |
index = atk_object_get_index_in_parent (cell_object); |
| 1172 |
renderer = g_list_nth_data (renderers, index); |
| 1173 |
g_list_free (renderers); |
| 1174 |
} |
| 1175 |
path = cell_info_get_path (cell_info); |
| 1176 |
if (path) |
| 1177 |
{ |
| 1178 |
if (renderer) |
| 1179 |
gtk_tree_view_set_cursor_on_cell (tree_view, path, tv_col, renderer, FALSE); |
| 1180 |
else |
| 1181 |
gtk_tree_view_set_cursor (tree_view, path, tv_col, FALSE); |
| 1182 |
|
| 1183 |
gtk_tree_path_free (path); |
| 1184 |
gtk_widget_grab_focus (widget); |
| 1185 |
toplevel = gtk_widget_get_toplevel (widget); |
| 1186 |
if (gtk_widget_is_toplevel (toplevel)) |
| 1187 |
{ |
| 1188 |
#ifdef GDK_WINDOWING_X11 |
| 1189 |
if (GDK_IS_X11_DISPLAY (gtk_widget_get_display (toplevel))) |
| 1190 |
gtk_window_present_with_time (GTK_WINDOW (toplevel), |
| 1191 |
gdk_x11_get_server_time (gtk_widget_get_window (widget))); |
| 1192 |
else |
| 1193 |
#endif |
| 1194 |
{ |
| 1195 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 1196 |
gtk_window_present (GTK_WINDOW (toplevel)); |
| 1197 |
G_GNUC_END_IGNORE_DEPRECATIONS |
| 1198 |
} |
| 1199 |
} |
| 1200 |
|
| 1201 |
return TRUE; |
| 1202 |
} |
| 1203 |
else |
| 1204 |
return FALSE; |
| 1205 |
} |
| 1206 |
|
| 1207 |
static int |
| 1208 |
gtk_tree_view_accessible_get_child_index (GtkCellAccessibleParent *parent, |
| 1209 |
GtkCellAccessible *cell) |
| 1210 |
{ |
| 1211 |
GtkTreeViewAccessibleCellInfo *cell_info; |
| 1212 |
GtkTreeView *tree_view; |
| 1213 |
|
| 1214 |
cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell); |
| 1215 |
if (!cell_info) |
| 1216 |
return -1; |
| 1217 |
|
| 1218 |
tree_view = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent))); |
| 1219 |
|
| 1220 |
return cell_info_get_index (tree_view, cell_info); |
| 1221 |
} |
| 1222 |
|
| 1223 |
static GtkCellRendererState |
| 1224 |
gtk_tree_view_accessible_get_renderer_state (GtkCellAccessibleParent *parent, |
| 1225 |
GtkCellAccessible *cell) |
| 1226 |
{ |
| 1227 |
GtkTreeViewAccessibleCellInfo *cell_info; |
| 1228 |
GtkTreeView *treeview; |
| 1229 |
GtkCellRendererState flags; |
| 1230 |
|
| 1231 |
cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell); |
| 1232 |
if (!cell_info) |
| 1233 |
return 0; |
| 1234 |
|
| 1235 |
flags = 0; |
| 1236 |
|
| 1237 |
if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_SELECTED)) |
| 1238 |
flags |= GTK_CELL_RENDERER_SELECTED; |
| 1239 |
|
| 1240 |
if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_PRELIT)) |
| 1241 |
flags |= GTK_CELL_RENDERER_PRELIT; |
| 1242 |
|
| 1243 |
if (gtk_tree_view_column_get_sort_indicator (cell_info->cell_col_ref)) |
| 1244 |
flags |= GTK_CELL_RENDERER_SORTED; |
| 1245 |
|
| 1246 |
treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent))); |
| 1247 |
|
| 1248 |
if (cell_info->cell_col_ref == gtk_tree_view_get_expander_column (treeview)) |
| 1249 |
{ |
| 1250 |
if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_PARENT)) |
| 1251 |
flags |= GTK_CELL_RENDERER_EXPANDABLE; |
| 1252 |
|
| 1253 |
if (cell_info->node->children) |
| 1254 |
flags |= GTK_CELL_RENDERER_EXPANDED; |
| 1255 |
} |
| 1256 |
|
| 1257 |
if (gtk_widget_has_focus (GTK_WIDGET (treeview))) |
| 1258 |
{ |
| 1259 |
GtkTreeViewColumn *column; |
| 1260 |
GtkTreePath *path; |
| 1261 |
GtkRBTree *tree; |
| 1262 |
GtkRBNode *node = NULL; |
| 1263 |
|
| 1264 |
gtk_tree_view_get_cursor (treeview, &path, &column); |
| 1265 |
if (path) |
| 1266 |
{ |
| 1267 |
_gtk_tree_view_find_node (treeview, path, &tree, &node); |
| 1268 |
gtk_tree_path_free (path); |
| 1269 |
} |
| 1270 |
else |
| 1271 |
tree = NULL; |
| 1272 |
|
| 1273 |
if (cell_info->cell_col_ref == column |
| 1274 |
&& cell_info->tree == tree |
| 1275 |
&& cell_info->node == node) |
| 1276 |
flags |= GTK_CELL_RENDERER_FOCUSED; |
| 1277 |
} |
| 1278 |
|
| 1279 |
return flags; |
| 1280 |
} |
| 1281 |
|
| 1282 |
static void |
| 1283 |
gtk_tree_view_accessible_expand_collapse (GtkCellAccessibleParent *parent, |
| 1284 |
GtkCellAccessible *cell) |
| 1285 |
{ |
| 1286 |
GtkTreeViewAccessibleCellInfo *cell_info; |
| 1287 |
GtkTreeView *treeview; |
| 1288 |
GtkTreePath *path; |
| 1289 |
|
| 1290 |
treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent))); |
| 1291 |
|
| 1292 |
cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell); |
| 1293 |
if (!cell_info || |
| 1294 |
cell_info->cell_col_ref != gtk_tree_view_get_expander_column (treeview)) |
| 1295 |
return; |
| 1296 |
|
| 1297 |
path = cell_info_get_path (cell_info); |
| 1298 |
|
| 1299 |
if (cell_info->node->children) |
| 1300 |
gtk_tree_view_collapse_row (treeview, path); |
| 1301 |
else |
| 1302 |
gtk_tree_view_expand_row (treeview, path, FALSE); |
| 1303 |
|
| 1304 |
gtk_tree_path_free (path); |
| 1305 |
} |
| 1306 |
|
| 1307 |
static void |
| 1308 |
gtk_tree_view_accessible_activate (GtkCellAccessibleParent *parent, |
| 1309 |
GtkCellAccessible *cell) |
| 1310 |
{ |
| 1311 |
GtkTreeViewAccessibleCellInfo *cell_info; |
| 1312 |
GtkTreeView *treeview; |
| 1313 |
GtkTreePath *path; |
| 1314 |
|
| 1315 |
treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent))); |
| 1316 |
|
| 1317 |
cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell); |
| 1318 |
if (!cell_info) |
| 1319 |
return; |
| 1320 |
|
| 1321 |
path = cell_info_get_path (cell_info); |
| 1322 |
|
| 1323 |
gtk_tree_view_row_activated (treeview, path, cell_info->cell_col_ref); |
| 1324 |
|
| 1325 |
gtk_tree_path_free (path); |
| 1326 |
} |
| 1327 |
|
| 1328 |
static void |
| 1329 |
gtk_tree_view_accessible_edit (GtkCellAccessibleParent *parent, |
| 1330 |
GtkCellAccessible *cell) |
| 1331 |
{ |
| 1332 |
GtkTreeView *treeview; |
| 1333 |
|
| 1334 |
if (!gtk_tree_view_accessible_grab_cell_focus (parent, cell)) |
| 1335 |
return; |
| 1336 |
|
| 1337 |
treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent))); |
| 1338 |
|
| 1339 |
g_signal_emit_by_name (treeview, |
| 1340 |
"real-select-cursor-row", |
| 1341 |
TRUE); |
| 1342 |
} |
| 1343 |
|
| 1344 |
static void |
| 1345 |
gtk_tree_view_accessible_update_relationset (GtkCellAccessibleParent *parent, |
| 1346 |
GtkCellAccessible *cell, |
| 1347 |
AtkRelationSet *relationset) |
| 1348 |
{ |
| 1349 |
GtkTreeViewAccessibleCellInfo *cell_info; |
| 1350 |
GtkTreeViewAccessible *accessible; |
| 1351 |
GtkTreeViewColumn *column; |
| 1352 |
GtkTreeView *treeview; |
| 1353 |
AtkRelation *relation; |
| 1354 |
GtkRBTree *tree; |
| 1355 |
GtkRBNode *node; |
| 1356 |
AtkObject *object; |
| 1357 |
|
| 1358 |
/* Don't set relations on cells that aren't direct descendants of the treeview. |
| 1359 |
* So only set it on the container, not on the renderer accessibles */ |
| 1360 |
if (atk_object_get_parent (ATK_OBJECT (cell)) != ATK_OBJECT (parent)) |
| 1361 |
return; |
| 1362 |
|
| 1363 |
accessible = GTK_TREE_VIEW_ACCESSIBLE (parent); |
| 1364 |
cell_info = find_cell_info (accessible, cell); |
| 1365 |
if (!cell_info) |
| 1366 |
return; |
| 1367 |
|
| 1368 |
/* only set parent/child rows on the expander column */ |
| 1369 |
treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent))); |
| 1370 |
column = gtk_tree_view_get_expander_column (treeview); |
| 1371 |
if (column != cell_info->cell_col_ref) |
| 1372 |
return; |
| 1373 |
|
| 1374 |
/* Update CHILD_OF relation to parent cell */ |
| 1375 |
relation = atk_relation_set_get_relation_by_type (relationset, ATK_RELATION_NODE_CHILD_OF); |
| 1376 |
if (relation) |
| 1377 |
atk_relation_set_remove (relationset, relation); |
| 1378 |
|
| 1379 |
if (cell_info->tree->parent_tree) |
| 1380 |
{ |
| 1381 |
object = ATK_OBJECT (peek_cell (accessible, cell_info->tree->parent_tree, cell_info->tree->parent_node, column)); |
| 1382 |
if (object == NULL) |
| 1383 |
object = ATK_OBJECT (create_cell (treeview, accessible, cell_info->tree->parent_tree, cell_info->tree->parent_node, column)); |
| 1384 |
} |
| 1385 |
else |
| 1386 |
object = ATK_OBJECT (accessible); |
| 1387 |
|
| 1388 |
atk_relation_set_add_relation_by_type (relationset, ATK_RELATION_NODE_CHILD_OF, object); |
| 1389 |
|
| 1390 |
/* Update PARENT_OF relation for all child cells */ |
| 1391 |
relation = atk_relation_set_get_relation_by_type (relationset, ATK_RELATION_NODE_PARENT_OF); |
| 1392 |
if (relation) |
| 1393 |
atk_relation_set_remove (relationset, relation); |
| 1394 |
|
| 1395 |
tree = cell_info->node->children; |
| 1396 |
if (tree) |
| 1397 |
{ |
| 1398 |
for (node = _gtk_rbtree_first (tree); |
| 1399 |
node != NULL; |
| 1400 |
node = _gtk_rbtree_next (tree, node)) |
| 1401 |
{ |
| 1402 |
object = ATK_OBJECT (peek_cell (accessible, tree, node, column)); |
| 1403 |
if (object == NULL) |
| 1404 |
object = ATK_OBJECT (create_cell (treeview, accessible, tree, node, column)); |
| 1405 |
|
| 1406 |
atk_relation_set_add_relation_by_type (relationset, ATK_RELATION_NODE_PARENT_OF, ATK_OBJECT (object)); |
| 1407 |
} |
| 1408 |
} |
| 1409 |
} |
| 1410 |
|
| 1411 |
static void |
| 1412 |
gtk_tree_view_accessible_get_cell_position (GtkCellAccessibleParent *parent, |
| 1413 |
GtkCellAccessible *cell, |
| 1414 |
gint *row, |
| 1415 |
gint *column) |
| 1416 |
{ |
| 1417 |
GtkWidget *widget; |
| 1418 |
GtkTreeView *tree_view; |
| 1419 |
GtkTreeViewAccessibleCellInfo *cell_info; |
| 1420 |
GtkTreeViewAccessible *accessible; |
| 1421 |
|
| 1422 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)); |
| 1423 |
if (widget == NULL) |
| 1424 |
return; |
| 1425 |
|
| 1426 |
tree_view = GTK_TREE_VIEW (widget); |
| 1427 |
accessible = GTK_TREE_VIEW_ACCESSIBLE (parent); |
| 1428 |
cell_info = find_cell_info (accessible, cell); |
| 1429 |
if (!cell_info) |
| 1430 |
return; |
| 1431 |
|
| 1432 |
if (row) |
| 1433 |
(*row) = _gtk_rbtree_node_get_index (cell_info->tree, cell_info->node); |
| 1434 |
if (column) |
| 1435 |
(*column) = get_column_number (tree_view, cell_info->cell_col_ref); |
| 1436 |
} |
| 1437 |
|
| 1438 |
static GPtrArray * |
| 1439 |
gtk_tree_view_accessible_get_column_header_cells (GtkCellAccessibleParent *parent, |
| 1440 |
GtkCellAccessible *cell) |
| 1441 |
{ |
| 1442 |
GtkWidget *widget; |
| 1443 |
GtkTreeViewAccessibleCellInfo *cell_info; |
| 1444 |
GtkTreeViewAccessible *accessible; |
| 1445 |
GPtrArray *array; |
| 1446 |
|
| 1447 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)); |
| 1448 |
if (widget == NULL) |
| 1449 |
return NULL; |
| 1450 |
|
| 1451 |
accessible = GTK_TREE_VIEW_ACCESSIBLE (parent); |
| 1452 |
cell_info = find_cell_info (accessible, cell); |
| 1453 |
if (!cell_info) |
| 1454 |
return NULL; |
| 1455 |
|
| 1456 |
array = g_ptr_array_new_full (1, g_object_unref); |
| 1457 |
g_ptr_array_add (array, g_object_ref (get_header_from_column ( (cell_info->cell_col_ref)))); |
| 1458 |
return array; |
| 1459 |
} |
| 1460 |
|
| 1461 |
static void |
| 1462 |
gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface) |
| 1463 |
{ |
| 1464 |
iface->get_cell_extents = gtk_tree_view_accessible_get_cell_extents; |
| 1465 |
iface->get_cell_area = gtk_tree_view_accessible_get_cell_area; |
| 1466 |
iface->grab_focus = gtk_tree_view_accessible_grab_cell_focus; |
| 1467 |
iface->get_child_index = gtk_tree_view_accessible_get_child_index; |
| 1468 |
iface->get_renderer_state = gtk_tree_view_accessible_get_renderer_state; |
| 1469 |
iface->expand_collapse = gtk_tree_view_accessible_expand_collapse; |
| 1470 |
iface->activate = gtk_tree_view_accessible_activate; |
| 1471 |
iface->edit = gtk_tree_view_accessible_edit; |
| 1472 |
iface->update_relationset = gtk_tree_view_accessible_update_relationset; |
| 1473 |
iface->get_cell_position = gtk_tree_view_accessible_get_cell_position; |
| 1474 |
iface->get_column_header_cells = gtk_tree_view_accessible_get_column_header_cells; |
| 1475 |
} |
| 1476 |
|
| 1477 |
void |
| 1478 |
_gtk_tree_view_accessible_reorder (GtkTreeView *treeview) |
| 1479 |
{ |
| 1480 |
GtkTreeViewAccessible *accessible; |
| 1481 |
|
| 1482 |
accessible = GTK_TREE_VIEW_ACCESSIBLE (_gtk_widget_peek_accessible (GTK_WIDGET (treeview))); |
| 1483 |
if (accessible == NULL) |
| 1484 |
return; |
| 1485 |
|
| 1486 |
g_signal_emit_by_name (accessible, "row-reordered"); |
| 1487 |
} |
| 1488 |
|
| 1489 |
static gboolean |
| 1490 |
is_cell_showing (GtkTreeView *tree_view, |
| 1491 |
GdkRectangle *cell_rect) |
| 1492 |
{ |
| 1493 |
GdkRectangle rect, *visible_rect; |
| 1494 |
GdkRectangle rect1, *tree_cell_rect; |
| 1495 |
gint bx, by; |
| 1496 |
gboolean is_showing; |
| 1497 |
|
| 1498 |
/* A cell is considered "SHOWING" if any part of the cell is |
| 1499 |
* in the visible area. Other ways we could do this is by a |
| 1500 |
* cell's midpoint or if the cell is fully in the visible range. |
| 1501 |
* Since we have the cell_rect x, y, width, height of the cell, |
| 1502 |
* any of these is easy to compute. |
| 1503 |
* |
| 1504 |
* It is assumed that cell's rectangle is in widget coordinates |
| 1505 |
* so we must transform to tree cordinates. |
| 1506 |
*/ |
| 1507 |
visible_rect = ▭ |
| 1508 |
tree_cell_rect = &rect1; |
| 1509 |
tree_cell_rect->x = cell_rect->x; |
| 1510 |
tree_cell_rect->y = cell_rect->y; |
| 1511 |
tree_cell_rect->width = cell_rect->width; |
| 1512 |
tree_cell_rect->height = cell_rect->height; |
| 1513 |
|
| 1514 |
gtk_tree_view_get_visible_rect (tree_view, visible_rect); |
| 1515 |
gtk_tree_view_convert_tree_to_bin_window_coords (tree_view, visible_rect->x, |
| 1516 |
visible_rect->y, &bx, &by); |
| 1517 |
|
| 1518 |
if (((tree_cell_rect->x + tree_cell_rect->width) < bx) || |
| 1519 |
((tree_cell_rect->y + tree_cell_rect->height) < by) || |
| 1520 |
(tree_cell_rect->x > (bx + visible_rect->width)) || |
| 1521 |
(tree_cell_rect->y > (by + visible_rect->height))) |
| 1522 |
is_showing = FALSE; |
| 1523 |
else |
| 1524 |
is_showing = TRUE; |
| 1525 |
|
| 1526 |
return is_showing; |
| 1527 |
} |
| 1528 |
|
| 1529 |
/* Misc Private */ |
| 1530 |
|
| 1531 |
static int |
| 1532 |
cell_info_get_index (GtkTreeView *tree_view, |
| 1533 |
GtkTreeViewAccessibleCellInfo *info) |
| 1534 |
{ |
| 1535 |
int index; |
| 1536 |
|
| 1537 |
index = _gtk_rbtree_node_get_index (info->tree, info->node) + 1; |
| 1538 |
index *= get_n_columns (tree_view); |
| 1539 |
index += get_column_number (tree_view, info->cell_col_ref); |
| 1540 |
|
| 1541 |
return index; |
| 1542 |
} |
| 1543 |
|
| 1544 |
static void |
| 1545 |
cell_info_new (GtkTreeViewAccessible *accessible, |
| 1546 |
GtkRBTree *tree, |
| 1547 |
GtkRBNode *node, |
| 1548 |
GtkTreeViewColumn *tv_col, |
| 1549 |
GtkCellAccessible *cell) |
| 1550 |
{ |
| 1551 |
GtkTreeViewAccessibleCellInfo *cell_info; |
| 1552 |
|
| 1553 |
cell_info = g_new (GtkTreeViewAccessibleCellInfo, 1); |
| 1554 |
|
| 1555 |
cell_info->tree = tree; |
| 1556 |
cell_info->node = node; |
| 1557 |
cell_info->cell_col_ref = tv_col; |
| 1558 |
cell_info->cell = cell; |
| 1559 |
cell_info->view = accessible; |
| 1560 |
|
| 1561 |
g_object_set_qdata (G_OBJECT (cell), |
| 1562 |
gtk_tree_view_accessible_get_data_quark (), |
| 1563 |
cell_info); |
| 1564 |
|
| 1565 |
g_hash_table_replace (accessible->priv->cell_infos, cell_info, cell_info); |
| 1566 |
} |
| 1567 |
|
| 1568 |
/* Returns the column number of the specified GtkTreeViewColumn |
| 1569 |
* The column must be visible. |
| 1570 |
*/ |
| 1571 |
static gint |
| 1572 |
get_column_number (GtkTreeView *treeview, |
| 1573 |
GtkTreeViewColumn *column) |
| 1574 |
{ |
| 1575 |
GtkTreeViewColumn *cur; |
| 1576 |
guint i, number; |
| 1577 |
|
| 1578 |
number = 0; |
| 1579 |
|
| 1580 |
for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++) |
| 1581 |
{ |
| 1582 |
cur = gtk_tree_view_get_column (treeview, i); |
| 1583 |
|
| 1584 |
if (!gtk_tree_view_column_get_visible (cur)) |
| 1585 |
continue; |
| 1586 |
|
| 1587 |
if (cur == column) |
| 1588 |
break; |
| 1589 |
|
| 1590 |
number++; |
| 1591 |
} |
| 1592 |
|
| 1593 |
g_return_val_if_fail (i < gtk_tree_view_get_n_columns (treeview), 0); |
| 1594 |
|
| 1595 |
return number; |
| 1596 |
} |
| 1597 |
|
| 1598 |
static gboolean |
| 1599 |
get_rbtree_column_from_index (GtkTreeView *tree_view, |
| 1600 |
gint index, |
| 1601 |
GtkRBTree **tree, |
| 1602 |
GtkRBNode **node, |
| 1603 |
GtkTreeViewColumn **column) |
| 1604 |
{ |
| 1605 |
guint n_columns = get_n_columns (tree_view); |
| 1606 |
|
| 1607 |
if (n_columns == 0) |
| 1608 |
return FALSE; |
| 1609 |
/* First row is the column headers */ |
| 1610 |
index -= n_columns; |
| 1611 |
if (index < 0) |
| 1612 |
return FALSE; |
| 1613 |
|
| 1614 |
if (tree) |
| 1615 |
{ |
| 1616 |
g_return_val_if_fail (node != NULL, FALSE); |
| 1617 |
|
| 1618 |
if (!_gtk_rbtree_find_index (_gtk_tree_view_get_rbtree (tree_view), |
| 1619 |
index / n_columns, |
| 1620 |
tree, |
| 1621 |
node)) |
| 1622 |
return FALSE; |
| 1623 |
} |
| 1624 |
|
| 1625 |
if (column) |
| 1626 |
{ |
| 1627 |
*column = get_visible_column (tree_view, index % n_columns); |
| 1628 |
if (*column == NULL) |
| 1629 |
return FALSE; |
| 1630 |
} |
| 1631 |
return TRUE; |
| 1632 |
} |
| 1633 |
|
| 1634 |
static GtkTreeViewAccessibleCellInfo * |
| 1635 |
find_cell_info (GtkTreeViewAccessible *accessible, |
| 1636 |
GtkCellAccessible *cell) |
| 1637 |
{ |
| 1638 |
AtkObject *parent; |
| 1639 |
|
| 1640 |
parent = atk_object_get_parent (ATK_OBJECT (cell)); |
| 1641 |
while (parent != ATK_OBJECT (accessible)) |
| 1642 |
{ |
| 1643 |
cell = GTK_CELL_ACCESSIBLE (parent); |
| 1644 |
parent = atk_object_get_parent (ATK_OBJECT (cell)); |
| 1645 |
} |
| 1646 |
|
| 1647 |
return g_object_get_qdata (G_OBJECT (cell), |
| 1648 |
gtk_tree_view_accessible_get_data_quark ()); |
| 1649 |
} |
| 1650 |
|
| 1651 |
static AtkObject * |
| 1652 |
get_header_from_column (GtkTreeViewColumn *tv_col) |
| 1653 |
{ |
| 1654 |
AtkObject *rc; |
| 1655 |
GtkWidget *header_widget; |
| 1656 |
|
| 1657 |
if (tv_col == NULL) |
| 1658 |
return NULL; |
| 1659 |
|
| 1660 |
header_widget = gtk_tree_view_column_get_button (tv_col); |
| 1661 |
|
| 1662 |
if (header_widget) |
| 1663 |
rc = gtk_widget_get_accessible (header_widget); |
| 1664 |
else |
| 1665 |
rc = NULL; |
| 1666 |
|
| 1667 |
return rc; |
| 1668 |
} |
| 1669 |
|
| 1670 |
void |
| 1671 |
_gtk_tree_view_accessible_add (GtkTreeView *treeview, |
| 1672 |
GtkRBTree *tree, |
| 1673 |
GtkRBNode *node) |
| 1674 |
{ |
| 1675 |
GtkTreeViewAccessible *accessible; |
| 1676 |
guint row, n_rows, n_cols, i; |
| 1677 |
|
| 1678 |
accessible = GTK_TREE_VIEW_ACCESSIBLE (_gtk_widget_peek_accessible (GTK_WIDGET (treeview))); |
| 1679 |
if (accessible == NULL) |
| 1680 |
return; |
| 1681 |
|
| 1682 |
if (node == NULL) |
| 1683 |
{ |
| 1684 |
row = tree->parent_tree ? _gtk_rbtree_node_get_index (tree->parent_tree, tree->parent_node) : 0; |
| 1685 |
n_rows = tree->root->total_count; |
| 1686 |
} |
| 1687 |
else |
| 1688 |
{ |
| 1689 |
row = _gtk_rbtree_node_get_index (tree, node); |
| 1690 |
n_rows = 1 + (node->children ? node->children->root->total_count : 0); |
| 1691 |
} |
| 1692 |
|
| 1693 |
g_signal_emit_by_name (accessible, "row-inserted", row, n_rows); |
| 1694 |
|
| 1695 |
n_cols = get_n_columns (treeview); |
| 1696 |
if (n_cols) |
| 1697 |
{ |
| 1698 |
for (i = (row + 1) * n_cols; i < (row + n_rows + 1) * n_cols; i++) |
| 1699 |
{ |
| 1700 |
/* Pass NULL as the child object, i.e. 4th argument */ |
| 1701 |
g_signal_emit_by_name (accessible, "children-changed::add", i, NULL, NULL); |
| 1702 |
} |
| 1703 |
} |
| 1704 |
} |
| 1705 |
|
| 1706 |
void |
| 1707 |
_gtk_tree_view_accessible_remove (GtkTreeView *treeview, |
| 1708 |
GtkRBTree *tree, |
| 1709 |
GtkRBNode *node) |
| 1710 |
{ |
| 1711 |
GtkTreeViewAccessibleCellInfo *cell_info; |
| 1712 |
GHashTableIter iter; |
| 1713 |
GtkTreeViewAccessible *accessible; |
| 1714 |
guint row, n_rows, n_cols, i; |
| 1715 |
|
| 1716 |
accessible = GTK_TREE_VIEW_ACCESSIBLE (_gtk_widget_peek_accessible (GTK_WIDGET (treeview))); |
| 1717 |
if (accessible == NULL) |
| 1718 |
return; |
| 1719 |
|
| 1720 |
/* if this shows up in profiles, special-case node->children == NULL */ |
| 1721 |
|
| 1722 |
if (node == NULL) |
| 1723 |
{ |
| 1724 |
row = tree->parent_tree ? _gtk_rbtree_node_get_index (tree->parent_tree, tree->parent_node) : 0; |
| 1725 |
n_rows = tree->root->total_count + 1; |
| 1726 |
} |
| 1727 |
else |
| 1728 |
{ |
| 1729 |
row = _gtk_rbtree_node_get_index (tree, node); |
| 1730 |
n_rows = 1 + (node->children ? node->children->root->total_count : 0); |
| 1731 |
|
| 1732 |
tree = node->children; |
| 1733 |
} |
| 1734 |
|
| 1735 |
g_signal_emit_by_name (accessible, "row-deleted", row, n_rows); |
| 1736 |
|
| 1737 |
n_cols = get_n_columns (treeview); |
| 1738 |
if (n_cols) |
| 1739 |
{ |
| 1740 |
for (i = (n_rows + row + 1) * n_cols - 1; i >= (row + 1) * n_cols; i--) |
| 1741 |
{ |
| 1742 |
/* Pass NULL as the child object, i.e. 4th argument */ |
| 1743 |
g_signal_emit_by_name (accessible, "children-changed::remove", i, NULL, NULL); |
| 1744 |
} |
| 1745 |
|
| 1746 |
g_hash_table_iter_init (&iter, accessible->priv->cell_infos); |
| 1747 |
while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&cell_info)) |
| 1748 |
{ |
| 1749 |
if (node == cell_info->node || |
| 1750 |
tree == cell_info->tree || |
| 1751 |
(tree && _gtk_rbtree_contains (tree, cell_info->tree))) |
| 1752 |
g_hash_table_iter_remove (&iter); |
| 1753 |
} |
| 1754 |
} |
| 1755 |
} |
| 1756 |
|
| 1757 |
void |
| 1758 |
_gtk_tree_view_accessible_changed (GtkTreeView *treeview, |
| 1759 |
GtkRBTree *tree, |
| 1760 |
GtkRBNode *node) |
| 1761 |
{ |
| 1762 |
GtkTreeViewAccessible *accessible; |
| 1763 |
guint i; |
| 1764 |
|
| 1765 |
accessible = GTK_TREE_VIEW_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (treeview))); |
| 1766 |
|
| 1767 |
for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++) |
| 1768 |
{ |
| 1769 |
GtkCellAccessible *cell = peek_cell (accessible, |
| 1770 |
tree, node, |
| 1771 |
gtk_tree_view_get_column (treeview, i)); |
| 1772 |
|
| 1773 |
if (cell == NULL) |
| 1774 |
continue; |
| 1775 |
|
| 1776 |
set_cell_data (treeview, accessible, cell); |
| 1777 |
_gtk_cell_accessible_update_cache (cell, TRUE); |
| 1778 |
} |
| 1779 |
|
| 1780 |
g_signal_emit_by_name (accessible, "visible-data-changed"); |
| 1781 |
} |
| 1782 |
|
| 1783 |
/* NB: id is not checked, only columns < id are. |
| 1784 |
* This is important so the function works for notification of removal of a column */ |
| 1785 |
static guint |
| 1786 |
to_visible_column_id (GtkTreeView *treeview, |
| 1787 |
guint id) |
| 1788 |
{ |
| 1789 |
guint i; |
| 1790 |
guint invisible; |
| 1791 |
|
| 1792 |
invisible = 0; |
| 1793 |
|
| 1794 |
for (i = 0; i < id; i++) |
| 1795 |
{ |
| 1796 |
GtkTreeViewColumn *column = gtk_tree_view_get_column (treeview, i); |
| 1797 |
|
| 1798 |
if (!gtk_tree_view_column_get_visible (column)) |
| 1799 |
invisible++; |
| 1800 |
} |
| 1801 |
|
| 1802 |
return id - invisible; |
| 1803 |
} |
| 1804 |
|
| 1805 |
static void |
| 1806 |
gtk_tree_view_accessible_do_add_column (GtkTreeViewAccessible *accessible, |
| 1807 |
GtkTreeView *treeview, |
| 1808 |
GtkTreeViewColumn *column, |
| 1809 |
guint id) |
| 1810 |
{ |
| 1811 |
guint row, n_rows, n_cols; |
| 1812 |
|
| 1813 |
/* Generate column-inserted signal */ |
| 1814 |
g_signal_emit_by_name (accessible, "column-inserted", id, 1); |
| 1815 |
|
| 1816 |
n_rows = get_n_rows (treeview); |
| 1817 |
n_cols = get_n_columns (treeview); |
| 1818 |
|
| 1819 |
/* Generate children-changed signals */ |
| 1820 |
for (row = 0; row <= n_rows; row++) |
| 1821 |
{ |
| 1822 |
/* Pass NULL as the child object, i.e. 4th argument */ |
| 1823 |
g_signal_emit_by_name (accessible, "children-changed::add", |
| 1824 |
(row * n_cols) + id, NULL, NULL); |
| 1825 |
} |
| 1826 |
} |
| 1827 |
|
| 1828 |
void |
| 1829 |
_gtk_tree_view_accessible_add_column (GtkTreeView *treeview, |
| 1830 |
GtkTreeViewColumn *column, |
| 1831 |
guint id) |
| 1832 |
{ |
| 1833 |
AtkObject *obj; |
| 1834 |
|
| 1835 |
if (!gtk_tree_view_column_get_visible (column)) |
| 1836 |
return; |
| 1837 |
|
| 1838 |
obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview)); |
| 1839 |
if (obj == NULL) |
| 1840 |
return; |
| 1841 |
|
| 1842 |
gtk_tree_view_accessible_do_add_column (GTK_TREE_VIEW_ACCESSIBLE (obj), |
| 1843 |
treeview, |
| 1844 |
column, |
| 1845 |
to_visible_column_id (treeview, id)); |
| 1846 |
} |
| 1847 |
|
| 1848 |
static void |
| 1849 |
gtk_tree_view_accessible_do_remove_column (GtkTreeViewAccessible *accessible, |
| 1850 |
GtkTreeView *treeview, |
| 1851 |
GtkTreeViewColumn *column, |
| 1852 |
guint id) |
| 1853 |
{ |
| 1854 |
GtkTreeViewAccessibleCellInfo *cell_info; |
| 1855 |
GHashTableIter iter; |
| 1856 |
gpointer value; |
| 1857 |
guint row, n_rows, n_cols; |
| 1858 |
|
| 1859 |
/* Clean column from cache */ |
| 1860 |
g_hash_table_iter_init (&iter, accessible->priv->cell_infos); |
| 1861 |
while (g_hash_table_iter_next (&iter, NULL, &value)) |
| 1862 |
{ |
| 1863 |
cell_info = value; |
| 1864 |
if (cell_info->cell_col_ref == column) |
| 1865 |
g_hash_table_iter_remove (&iter); |
| 1866 |
} |
| 1867 |
|
| 1868 |
/* Generate column-deleted signal */ |
| 1869 |
g_signal_emit_by_name (accessible, "column-deleted", id, 1); |
| 1870 |
|
| 1871 |
n_rows = get_n_rows (treeview); |
| 1872 |
n_cols = get_n_columns (treeview); |
| 1873 |
|
| 1874 |
/* Generate children-changed signals */ |
| 1875 |
for (row = 0; row <= n_rows; row++) |
| 1876 |
{ |
| 1877 |
/* Pass NULL as the child object, 4th argument */ |
| 1878 |
g_signal_emit_by_name (accessible, "children-changed::remove", |
| 1879 |
(row * n_cols) + id, NULL, NULL); |
| 1880 |
} |
| 1881 |
} |
| 1882 |
|
| 1883 |
void |
| 1884 |
_gtk_tree_view_accessible_remove_column (GtkTreeView *treeview, |
| 1885 |
GtkTreeViewColumn *column, |
| 1886 |
guint id) |
| 1887 |
{ |
| 1888 |
AtkObject *obj; |
| 1889 |
|
| 1890 |
if (!gtk_tree_view_column_get_visible (column)) |
| 1891 |
return; |
| 1892 |
|
| 1893 |
obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview)); |
| 1894 |
if (obj == NULL) |
| 1895 |
return; |
| 1896 |
|
| 1897 |
gtk_tree_view_accessible_do_remove_column (GTK_TREE_VIEW_ACCESSIBLE (obj), |
| 1898 |
treeview, |
| 1899 |
column, |
| 1900 |
to_visible_column_id (treeview, id)); |
| 1901 |
} |
| 1902 |
|
| 1903 |
void |
| 1904 |
_gtk_tree_view_accessible_reorder_column (GtkTreeView *treeview, |
| 1905 |
GtkTreeViewColumn *column) |
| 1906 |
{ |
| 1907 |
AtkObject *obj; |
| 1908 |
|
| 1909 |
obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview)); |
| 1910 |
if (obj == NULL) |
| 1911 |
return; |
| 1912 |
|
| 1913 |
g_signal_emit_by_name (obj, "column-reordered"); |
| 1914 |
} |
| 1915 |
|
| 1916 |
void |
| 1917 |
_gtk_tree_view_accessible_toggle_visibility (GtkTreeView *treeview, |
| 1918 |
GtkTreeViewColumn *column) |
| 1919 |
{ |
| 1920 |
AtkObject *obj; |
| 1921 |
guint i, id; |
| 1922 |
|
| 1923 |
obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview)); |
| 1924 |
if (obj == NULL) |
| 1925 |
return; |
| 1926 |
|
| 1927 |
if (gtk_tree_view_column_get_visible (column)) |
| 1928 |
{ |
| 1929 |
id = get_column_number (treeview, column); |
| 1930 |
|
| 1931 |
gtk_tree_view_accessible_do_add_column (GTK_TREE_VIEW_ACCESSIBLE (obj), |
| 1932 |
treeview, |
| 1933 |
column, |
| 1934 |
id); |
| 1935 |
} |
| 1936 |
else |
| 1937 |
{ |
| 1938 |
id = 0; |
| 1939 |
|
| 1940 |
for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++) |
| 1941 |
{ |
| 1942 |
GtkTreeViewColumn *cur = gtk_tree_view_get_column (treeview, i); |
| 1943 |
|
| 1944 |
if (gtk_tree_view_column_get_visible (cur)) |
| 1945 |
id++; |
| 1946 |
|
| 1947 |
if (cur == column) |
| 1948 |
break; |
| 1949 |
} |
| 1950 |
|
| 1951 |
gtk_tree_view_accessible_do_remove_column (GTK_TREE_VIEW_ACCESSIBLE (obj), |
| 1952 |
treeview, |
| 1953 |
column, |
| 1954 |
id); |
| 1955 |
} |
| 1956 |
} |
| 1957 |
|
| 1958 |
static GtkTreeViewColumn * |
| 1959 |
get_effective_focus_column (GtkTreeView *treeview, |
| 1960 |
GtkTreeViewColumn *column) |
| 1961 |
{ |
| 1962 |
if (column == NULL && get_n_columns (treeview) > 0) |
| 1963 |
column = get_visible_column (treeview, 0); |
| 1964 |
|
| 1965 |
return column; |
| 1966 |
} |
| 1967 |
|
| 1968 |
void |
| 1969 |
_gtk_tree_view_accessible_update_focus_column (GtkTreeView *treeview, |
| 1970 |
GtkTreeViewColumn *old_focus, |
| 1971 |
GtkTreeViewColumn *new_focus) |
| 1972 |
{ |
| 1973 |
GtkTreeViewAccessible *accessible; |
| 1974 |
AtkObject *obj; |
| 1975 |
GtkRBTree *cursor_tree; |
| 1976 |
GtkRBNode *cursor_node; |
| 1977 |
GtkCellAccessible *cell; |
| 1978 |
|
| 1979 |
old_focus = get_effective_focus_column (treeview, old_focus); |
| 1980 |
new_focus = get_effective_focus_column (treeview, new_focus); |
| 1981 |
if (old_focus == new_focus) |
| 1982 |
return; |
| 1983 |
|
| 1984 |
obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview)); |
| 1985 |
if (obj == NULL) |
| 1986 |
return; |
| 1987 |
|
| 1988 |
accessible = GTK_TREE_VIEW_ACCESSIBLE (obj); |
| 1989 |
|
| 1990 |
if (!_gtk_tree_view_get_cursor_node (treeview, &cursor_tree, &cursor_node)) |
| 1991 |
return; |
| 1992 |
|
| 1993 |
if (old_focus) |
| 1994 |
{ |
| 1995 |
cell = peek_cell (accessible, cursor_tree, cursor_node, old_focus); |
| 1996 |
if (cell != NULL) |
| 1997 |
_gtk_cell_accessible_state_changed (cell, GTK_CELL_RENDERER_FOCUSED, 0); |
| 1998 |
} |
| 1999 |
|
| 2000 |
if (new_focus) |
| 2001 |
{ |
| 2002 |
cell = peek_cell (accessible, cursor_tree, cursor_node, new_focus); |
| 2003 |
if (cell != NULL) |
| 2004 |
_gtk_cell_accessible_state_changed (cell, 0, GTK_CELL_RENDERER_FOCUSED); |
| 2005 |
else |
| 2006 |
cell = create_cell (treeview, accessible, cursor_tree, cursor_node, new_focus); |
| 2007 |
|
| 2008 |
g_signal_emit_by_name (accessible, "active-descendant-changed", cell); |
| 2009 |
} |
| 2010 |
} |
| 2011 |
|
| 2012 |
void |
| 2013 |
_gtk_tree_view_accessible_add_state (GtkTreeView *treeview, |
| 2014 |
GtkRBTree *tree, |
| 2015 |
GtkRBNode *node, |
| 2016 |
GtkCellRendererState state) |
| 2017 |
{ |
| 2018 |
GtkTreeViewAccessible *accessible; |
| 2019 |
GtkTreeViewColumn *single_column; |
| 2020 |
AtkObject *obj; |
| 2021 |
guint i; |
| 2022 |
|
| 2023 |
obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview)); |
| 2024 |
if (obj == NULL) |
| 2025 |
return; |
| 2026 |
|
| 2027 |
accessible = GTK_TREE_VIEW_ACCESSIBLE (obj); |
| 2028 |
|
| 2029 |
if (state == GTK_CELL_RENDERER_FOCUSED) |
| 2030 |
{ |
| 2031 |
if (!gtk_widget_has_focus (GTK_WIDGET (treeview))) |
| 2032 |
return; |
| 2033 |
|
| 2034 |
single_column = get_effective_focus_column (treeview, _gtk_tree_view_get_focus_column (treeview)); |
| 2035 |
} |
| 2036 |
else if (state == GTK_CELL_RENDERER_EXPANDED || |
| 2037 |
state == GTK_CELL_RENDERER_EXPANDABLE) |
| 2038 |
{ |
| 2039 |
single_column = gtk_tree_view_get_expander_column (treeview); |
| 2040 |
} |
| 2041 |
else |
| 2042 |
single_column = NULL; |
| 2043 |
|
| 2044 |
if (single_column) |
| 2045 |
{ |
| 2046 |
GtkCellAccessible *cell = peek_cell (accessible, |
| 2047 |
tree, node, |
| 2048 |
single_column); |
| 2049 |
|
| 2050 |
if (cell != NULL) |
| 2051 |
_gtk_cell_accessible_state_changed (cell, state, 0); |
| 2052 |
|
| 2053 |
if (state == GTK_CELL_RENDERER_FOCUSED) |
| 2054 |
{ |
| 2055 |
if (cell == NULL) |
| 2056 |
cell = create_cell (treeview, accessible, tree, node, single_column); |
| 2057 |
|
| 2058 |
g_signal_emit_by_name (accessible, "active-descendant-changed", cell); |
| 2059 |
} |
| 2060 |
} |
| 2061 |
else |
| 2062 |
{ |
| 2063 |
for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++) |
| 2064 |
{ |
| 2065 |
GtkCellAccessible *cell = peek_cell (accessible, |
| 2066 |
tree, node, |
| 2067 |
gtk_tree_view_get_column (treeview, i)); |
| 2068 |
|
| 2069 |
if (cell == NULL) |
| 2070 |
continue; |
| 2071 |
|
| 2072 |
_gtk_cell_accessible_state_changed (cell, state, 0); |
| 2073 |
} |
| 2074 |
} |
| 2075 |
|
| 2076 |
if (state == GTK_CELL_RENDERER_SELECTED) |
| 2077 |
g_signal_emit_by_name (accessible, "selection-changed"); |
| 2078 |
} |
| 2079 |
|
| 2080 |
void |
| 2081 |
_gtk_tree_view_accessible_remove_state (GtkTreeView *treeview, |
| 2082 |
GtkRBTree *tree, |
| 2083 |
GtkRBNode *node, |
| 2084 |
GtkCellRendererState state) |
| 2085 |
{ |
| 2086 |
GtkTreeViewAccessible *accessible; |
| 2087 |
GtkTreeViewColumn *single_column; |
| 2088 |
AtkObject *obj; |
| 2089 |
guint i; |
| 2090 |
|
| 2091 |
obj = _gtk_widget_peek_accessible (GTK_WIDGET (treeview)); |
| 2092 |
if (obj == NULL) |
| 2093 |
return; |
| 2094 |
|
| 2095 |
accessible = GTK_TREE_VIEW_ACCESSIBLE (obj); |
| 2096 |
|
| 2097 |
if (state == GTK_CELL_RENDERER_FOCUSED) |
| 2098 |
{ |
| 2099 |
single_column = get_effective_focus_column (treeview, _gtk_tree_view_get_focus_column (treeview)); |
| 2100 |
} |
| 2101 |
else if (state == GTK_CELL_RENDERER_EXPANDED || |
| 2102 |
state == GTK_CELL_RENDERER_EXPANDABLE) |
| 2103 |
{ |
| 2104 |
single_column = gtk_tree_view_get_expander_column (treeview); |
| 2105 |
} |
| 2106 |
else |
| 2107 |
single_column = NULL; |
| 2108 |
|
| 2109 |
if (single_column) |
| 2110 |
{ |
| 2111 |
GtkCellAccessible *cell = peek_cell (accessible, |
| 2112 |
tree, node, |
| 2113 |
single_column); |
| 2114 |
|
| 2115 |
if (cell != NULL) |
| 2116 |
_gtk_cell_accessible_state_changed (cell, 0, state); |
| 2117 |
} |
| 2118 |
else |
| 2119 |
{ |
| 2120 |
for (i = 0; i < gtk_tree_view_get_n_columns (treeview); i++) |
| 2121 |
{ |
| 2122 |
GtkCellAccessible *cell = peek_cell (accessible, |
| 2123 |
tree, node, |
| 2124 |
gtk_tree_view_get_column (treeview, i)); |
| 2125 |
|
| 2126 |
if (cell == NULL) |
| 2127 |
continue; |
| 2128 |
|
| 2129 |
_gtk_cell_accessible_state_changed (cell, 0, state); |
| 2130 |
} |
| 2131 |
} |
| 2132 |
|
| 2133 |
if (state == GTK_CELL_RENDERER_SELECTED) |
| 2134 |
g_signal_emit_by_name (accessible, "selection-changed"); |
| 2135 |
} |