[gtk+] a11y: Add _gtk_cell_accessible_set_cell_data()



commit bcafd9ba3cadd03d1a8f1d5775f39099201c8007
Author: Benjamin Otte <otte redhat com>
Date:   Wed Nov 23 17:35:00 2011 +0100

    a11y: Add _gtk_cell_accessible_set_cell_data()
    
    See the function documentation for details.
    
    Also included is the implementation for the treeview, but no users yet.

 gtk/a11y/gtkcellaccessible.c       |   24 ++++++++++++++++++
 gtk/a11y/gtkcellaccessible.h       |    2 +
 gtk/a11y/gtkcellaccessibleparent.c |   16 ++++++++++++
 gtk/a11y/gtkcellaccessibleparent.h |    5 ++++
 gtk/a11y/gtktreeviewaccessible.c   |   46 ++++++++++++++++++++++++++++++++++++
 5 files changed, 93 insertions(+), 0 deletions(-)
---
diff --git a/gtk/a11y/gtkcellaccessible.c b/gtk/a11y/gtkcellaccessible.c
index fdccd19..bc503a9 100644
--- a/gtk/a11y/gtkcellaccessible.c
+++ b/gtk/a11y/gtkcellaccessible.c
@@ -421,3 +421,27 @@ atk_component_interface_init (AtkComponentIface *iface)
   iface->get_extents = gtk_cell_accessible_get_extents;
   iface->grab_focus = gtk_cell_accessible_grab_focus;
 }
+
+/**
+ * _gtk_cell_accessible_set_cell_data:
+ * @cell: a #GtkCellAccessible
+ *
+ * Sets the cell data to the row used by @cell. This is useful in
+ * particular if you want to work with cell renderers.
+ *
+ * Note that this function is potentially slow, so be careful.
+ **/
+void
+_gtk_cell_accessible_set_cell_data (GtkCellAccessible *cell)
+{
+  AtkObject *parent;
+
+  g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (cell));
+
+  parent = gtk_widget_get_accessible (cell->widget);
+  if (parent == NULL)
+    return;
+
+  _gtk_cell_accessible_parent_set_cell_data (GTK_CELL_ACCESSIBLE_PARENT (parent), cell);
+}
+
diff --git a/gtk/a11y/gtkcellaccessible.h b/gtk/a11y/gtkcellaccessible.h
index ceab222..823ae8d 100644
--- a/gtk/a11y/gtkcellaccessible.h
+++ b/gtk/a11y/gtkcellaccessible.h
@@ -50,6 +50,8 @@ struct _GtkCellAccessibleClass
 
 GType    _gtk_cell_accessible_get_type      (void);
 
+void     _gtk_cell_accessible_set_cell_data (GtkCellAccessible *cell);
+
 void     _gtk_cell_accessible_initialise    (GtkCellAccessible *cell,
                                              GtkWidget         *widget,
                                              AtkObject         *parent);
diff --git a/gtk/a11y/gtkcellaccessibleparent.c b/gtk/a11y/gtkcellaccessibleparent.c
index a05aaa1..76c6b76 100644
--- a/gtk/a11y/gtkcellaccessibleparent.c
+++ b/gtk/a11y/gtkcellaccessibleparent.c
@@ -111,3 +111,19 @@ _gtk_cell_accessible_parent_get_child_index (GtkCellAccessibleParent *parent,
   else
     return -1;
 }
+
+void
+_gtk_cell_accessible_parent_set_cell_data (GtkCellAccessibleParent *parent,
+                                           GtkCellAccessible       *cell)
+{
+  GtkCellAccessibleParentIface *iface;
+
+  g_return_if_fail (GTK_IS_CELL_ACCESSIBLE_PARENT (parent));
+  g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (cell));
+
+  iface = GTK_CELL_ACCESSIBLE_PARENT_GET_IFACE (parent);
+
+  if (iface->set_cell_data)
+    (iface->set_cell_data) (parent, cell);
+}
+
diff --git a/gtk/a11y/gtkcellaccessibleparent.h b/gtk/a11y/gtkcellaccessibleparent.h
index f4e1ea2..797a784 100644
--- a/gtk/a11y/gtkcellaccessibleparent.h
+++ b/gtk/a11y/gtkcellaccessibleparent.h
@@ -60,6 +60,9 @@ struct _GtkCellAccessibleParentIface
                                  GtkCellAccessible       *cell);
   int      ( *get_child_index)  (GtkCellAccessibleParent *parent,
                                  GtkCellAccessible       *cell);
+  void     ( *set_cell_data)    (GtkCellAccessibleParent *parent,
+                                 GtkCellAccessible       *cell);
+
 };
 
 GType    _gtk_cell_accessible_parent_get_type         (void);
@@ -78,6 +81,8 @@ gboolean _gtk_cell_accessible_parent_grab_focus       (GtkCellAccessibleParent *
                                                        GtkCellAccessible       *cell);
 int      _gtk_cell_accessible_parent_get_child_index  (GtkCellAccessibleParent *parent,
                                                        GtkCellAccessible       *cell);
+void     _gtk_cell_accessible_parent_set_cell_data    (GtkCellAccessibleParent *parent,
+                                                       GtkCellAccessible       *cell);
 
 G_END_DECLS
 
diff --git a/gtk/a11y/gtktreeviewaccessible.c b/gtk/a11y/gtktreeviewaccessible.c
index 0589c4a..d8bf3d6 100644
--- a/gtk/a11y/gtktreeviewaccessible.c
+++ b/gtk/a11y/gtktreeviewaccessible.c
@@ -1517,12 +1517,58 @@ gtk_tree_view_accessible_get_child_index (GtkCellAccessibleParent *parent,
 }
 
 static void
+gtk_tree_view_accessible_set_cell_data (GtkCellAccessibleParent *parent,
+                                        GtkCellAccessible       *cell)
+{
+  GtkTreeViewAccessibleCellInfo *cell_info;
+  GtkTreeView *treeview;
+  gboolean is_expander, is_expanded;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  GtkTreePath *path;
+
+  cell_info = find_cell_info (GTK_TREE_VIEW_ACCESSIBLE (parent), cell);
+  if (!cell_info)
+    return;
+
+  treeview = GTK_TREE_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (parent)));
+  model = gtk_tree_view_get_model (treeview);
+
+  if (GTK_RBNODE_FLAG_SET (cell_info->node, GTK_RBNODE_IS_PARENT) &&
+      cell_info->cell_col_ref == gtk_tree_view_get_expander_column (treeview))
+    {
+      is_expander = TRUE;
+      is_expanded = cell_info->node->children != NULL;
+    }
+  else
+    {
+      is_expander = FALSE;
+      is_expanded = FALSE;
+    }
+
+  path = cell_info_get_path (cell_info);
+  if (path == NULL ||
+      !gtk_tree_model_get_iter (model, &iter, path))
+    {
+      /* We only track valid cells, this should never happen */
+      g_return_if_reached ();
+    }
+
+  gtk_tree_view_column_cell_set_cell_data (cell_info->cell_col_ref,
+                                           model,
+                                           &iter,
+                                           is_expander,
+                                           is_expanded);
+}
+
+static void
 gtk_cell_accessible_parent_interface_init (GtkCellAccessibleParentIface *iface)
 {
   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;
   iface->get_child_index = gtk_tree_view_accessible_get_child_index;
+  iface->set_cell_data = gtk_tree_view_accessible_set_cell_data;
 }
 
 /* signal handling */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]