1 /* GAIL - The GNOME Accessibility Implementation Library
2 * Copyright 2001 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 #include "gtkcontainercellaccessible.h"
24 #include "gtkcellaccessible.h"
25 #include "gtkcellaccessibleparent.h"
27 typedef struct _ActionInfo ActionInfo;
32 void (*do_action_func) (GtkCellAccessible *cell);
36 static void atk_action_interface_init (AtkActionIface *iface);
37 static void atk_component_interface_init (AtkComponentIface *iface);
39 G_DEFINE_TYPE_WITH_CODE (GtkCellAccessible, _gtk_cell_accessible, ATK_TYPE_OBJECT,
40 G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init)
41 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init))
44 destroy_action_info (gpointer action_info)
46 ActionInfo *info = (ActionInfo *)action_info;
49 g_free (info->description);
50 g_free (info->keybinding);
55 gtk_cell_accessible_object_finalize (GObject *obj)
57 GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (obj);
58 AtkRelationSet *relation_set;
59 AtkRelation *relation;
61 gpointer target_object;
64 if (cell->action_list)
65 g_list_free_full (cell->action_list, destroy_action_info);
67 relation_set = atk_object_ref_relation_set (ATK_OBJECT (obj));
68 if (ATK_IS_RELATION_SET (relation_set))
70 relation = atk_relation_set_get_relation_by_type (relation_set,
71 ATK_RELATION_NODE_CHILD_OF);
74 target = atk_relation_get_target (relation);
75 for (i = 0; i < target->len; i++)
77 target_object = g_ptr_array_index (target, i);
78 if (GTK_IS_CELL_ACCESSIBLE (target_object))
79 g_object_unref (target_object);
82 g_object_unref (relation_set);
84 G_OBJECT_CLASS (_gtk_cell_accessible_parent_class)->finalize (obj);
88 gtk_cell_accessible_get_index_in_parent (AtkObject *obj)
90 GtkCellAccessible *cell;
93 cell = GTK_CELL_ACCESSIBLE (obj);
95 parent = atk_object_get_parent (obj);
96 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
97 return g_list_index (GTK_CONTAINER_CELL_ACCESSIBLE (parent)->children, obj);
99 parent = gtk_widget_get_accessible (cell->widget);
103 return _gtk_cell_accessible_parent_get_child_index (GTK_CELL_ACCESSIBLE_PARENT (parent), cell);
107 gtk_cell_accessible_ref_state_set (AtkObject *accessible)
109 GtkCellAccessible *cell_accessible;
110 AtkStateSet *state_set;
111 GtkCellRendererState flags;
113 cell_accessible = GTK_CELL_ACCESSIBLE (accessible);
115 state_set = atk_state_set_new ();
117 if (cell_accessible->widget == NULL)
119 atk_state_set_add_state (state_set, ATK_STATE_DEFUNCT);
123 flags = _gtk_cell_accessible_get_state (cell_accessible);
125 atk_state_set_add_state (state_set, ATK_STATE_TRANSIENT);
127 if (!(flags & GTK_CELL_RENDERER_INSENSITIVE))
129 atk_state_set_add_state (state_set, ATK_STATE_SENSITIVE);
130 atk_state_set_add_state (state_set, ATK_STATE_ENABLED);
133 atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE);
134 if (flags & GTK_CELL_RENDERER_SELECTED)
135 atk_state_set_add_state (state_set, ATK_STATE_SELECTED);
137 atk_state_set_add_state (state_set, ATK_STATE_VISIBLE);
138 if (gtk_widget_get_mapped (cell_accessible->widget))
139 atk_state_set_add_state (state_set, ATK_STATE_SHOWING);
141 /* This is not completely right. We should be tracking the
142 * focussed cell renderer, but that involves diving into
145 atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE);
146 if (flags & GTK_CELL_RENDERER_FOCUSED)
148 /* XXX: Why do we set ACTIVE here? */
149 atk_state_set_add_state (state_set, ATK_STATE_ACTIVE);
150 atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
153 if (flags & GTK_CELL_RENDERER_EXPANDABLE)
154 atk_state_set_add_state (state_set, ATK_STATE_EXPANDABLE);
155 if (flags & GTK_CELL_RENDERER_EXPANDED)
156 atk_state_set_add_state (state_set, ATK_STATE_EXPANDED);
163 _gtk_cell_accessible_class_init (GtkCellAccessibleClass *klass)
165 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
166 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
168 g_object_class->finalize = gtk_cell_accessible_object_finalize;
170 class->get_index_in_parent = gtk_cell_accessible_get_index_in_parent;
171 class->ref_state_set = gtk_cell_accessible_ref_state_set;
175 _gtk_cell_accessible_init (GtkCellAccessible *cell)
178 cell->action_list = NULL;
182 widget_destroyed (GtkWidget *widget,
183 GtkCellAccessible *cell)
189 _gtk_cell_accessible_initialise (GtkCellAccessible *cell,
193 cell->widget = widget;
194 atk_object_set_parent (ATK_OBJECT (cell), parent);
196 g_signal_connect_object (G_OBJECT (widget), "destroy",
197 G_CALLBACK (widget_destroyed), cell, 0);
201 _gtk_cell_accessible_add_state (GtkCellAccessible *cell,
202 AtkStateType state_type,
203 gboolean emit_signal)
207 /* The signal should only be generated if the value changed,
208 * not when the cell is set up. So states that are set
209 * initially should pass FALSE as the emit_signal argument.
213 atk_object_notify_state_change (ATK_OBJECT (cell), state_type, TRUE);
214 /* If state_type is ATK_STATE_VISIBLE, additional notification */
215 if (state_type == ATK_STATE_VISIBLE)
216 g_signal_emit_by_name (cell, "visible-data-changed");
219 /* If the parent is a flyweight container cell, propagate the state
222 parent = atk_object_get_parent (ATK_OBJECT (cell));
223 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
224 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (parent), state_type, emit_signal);
230 _gtk_cell_accessible_remove_state (GtkCellAccessible *cell,
231 AtkStateType state_type,
232 gboolean emit_signal)
236 parent = atk_object_get_parent (ATK_OBJECT (cell));
238 /* The signal should only be generated if the value changed,
239 * not when the cell is set up. So states that are set
240 * initially should pass FALSE as the emit_signal argument.
244 atk_object_notify_state_change (ATK_OBJECT (cell), state_type, FALSE);
245 /* If state_type is ATK_STATE_VISIBLE, additional notification */
246 if (state_type == ATK_STATE_VISIBLE)
247 g_signal_emit_by_name (cell, "visible-data-changed");
250 /* If the parent is a flyweight container cell, propagate the state
253 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
254 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (parent), state_type, emit_signal);
260 _gtk_cell_accessible_add_action (GtkCellAccessible *cell,
262 const gchar *description,
263 const gchar *keybinding,
264 void (*func) (GtkCellAccessible *))
268 info = g_new (ActionInfo, 1);
269 info->name = g_strdup (name);
270 info->description = g_strdup (description);
271 info->keybinding = g_strdup (keybinding);
272 info->do_action_func = func;
274 cell->action_list = g_list_append (cell->action_list, info);
280 _gtk_cell_accessible_remove_action (GtkCellAccessible *cell,
285 l = g_list_nth (cell->action_list, index);
289 destroy_action_info (l->data);
290 cell->action_list = g_list_remove_link (cell->action_list, l);
297 _gtk_cell_accessible_remove_action_by_name (GtkCellAccessible *cell,
302 for (l = cell->action_list; l; l = l->next)
304 ActionInfo *info = l->data;
306 if (g_strcmp0 (info->name, name) == 0)
313 destroy_action_info (l->data);
314 cell->action_list = g_list_remove_link (cell->action_list, l);
320 get_action_info (GtkCellAccessible *cell,
325 l = g_list_nth (cell->action_list, index);
329 return (ActionInfo *) (l->data);
333 gtk_cell_accessible_action_get_n_actions (AtkAction *action)
335 GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE(action);
336 if (cell->action_list != NULL)
337 return g_list_length (cell->action_list);
343 gtk_cell_accessible_action_get_name (AtkAction *action,
346 GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (action);
349 info = get_action_info (cell, index);
357 gtk_cell_accessible_action_get_description (AtkAction *action,
360 GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (action);
363 info = get_action_info (cell, index);
367 return info->description;
371 gtk_cell_accessible_action_get_keybinding (AtkAction *action,
374 GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (action);
377 info = get_action_info (cell, index);
381 return info->keybinding;
385 gtk_cell_accessible_action_do_action (AtkAction *action,
388 GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (action);
391 info = get_action_info (cell, index);
395 if (info->do_action_func == NULL)
398 info->do_action_func (cell);
404 atk_action_interface_init (AtkActionIface *iface)
406 iface->get_n_actions = gtk_cell_accessible_action_get_n_actions;
407 iface->do_action = gtk_cell_accessible_action_do_action;
408 iface->get_name = gtk_cell_accessible_action_get_name;
409 iface->get_description = gtk_cell_accessible_action_get_description;
410 iface->get_keybinding = gtk_cell_accessible_action_get_keybinding;
414 gtk_cell_accessible_get_extents (AtkComponent *component,
419 AtkCoordType coord_type)
421 GtkCellAccessible *cell;
424 cell = GTK_CELL_ACCESSIBLE (component);
425 parent = gtk_widget_get_accessible (cell->widget);
427 _gtk_cell_accessible_parent_get_cell_extents (GTK_CELL_ACCESSIBLE_PARENT (parent),
429 x, y, width, height, coord_type);
433 gtk_cell_accessible_grab_focus (AtkComponent *component)
435 GtkCellAccessible *cell;
438 cell = GTK_CELL_ACCESSIBLE (component);
439 parent = gtk_widget_get_accessible (cell->widget);
441 return _gtk_cell_accessible_parent_grab_focus (GTK_CELL_ACCESSIBLE_PARENT (parent), cell);
445 atk_component_interface_init (AtkComponentIface *iface)
447 iface->get_extents = gtk_cell_accessible_get_extents;
448 iface->grab_focus = gtk_cell_accessible_grab_focus;
452 * _gtk_cell_accessible_set_cell_data:
453 * @cell: a #GtkCellAccessible
455 * Sets the cell data to the row used by @cell. This is useful in
456 * particular if you want to work with cell renderers.
458 * Note that this function is potentially slow, so be careful.
461 _gtk_cell_accessible_set_cell_data (GtkCellAccessible *cell)
465 g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (cell));
467 parent = gtk_widget_get_accessible (cell->widget);
471 _gtk_cell_accessible_parent_set_cell_data (GTK_CELL_ACCESSIBLE_PARENT (parent), cell);
475 * _gtk_cell_accessible_get_state:
476 * @cell: a #GtkCellAccessible
478 * Gets the state that would be used to render the area referenced by @cell.
480 * Returns: the #GtkCellRendererState for cell
483 _gtk_cell_accessible_get_state (GtkCellAccessible *cell)
487 g_return_val_if_fail (GTK_IS_CELL_ACCESSIBLE (cell), 0);
489 parent = gtk_widget_get_accessible (cell->widget);
493 return _gtk_cell_accessible_parent_get_renderer_state (GTK_CELL_ACCESSIBLE_PARENT (parent), cell);