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, see <http://www.gnu.org/licenses/>.
21 #include "gtkcontainercellaccessible.h"
22 #include "gtkcellaccessible.h"
23 #include "gtkcellaccessibleparent.h"
27 GtkCellRendererState renderer_state;
30 { ATK_STATE_SENSITIVE, GTK_CELL_RENDERER_INSENSITIVE, TRUE },
31 { ATK_STATE_ENABLED, GTK_CELL_RENDERER_INSENSITIVE, TRUE },
32 { ATK_STATE_SELECTED, GTK_CELL_RENDERER_SELECTED, FALSE },
33 /* XXX: why do we map ACTIVE here? */
34 { ATK_STATE_ACTIVE, GTK_CELL_RENDERER_FOCUSED, FALSE },
35 { ATK_STATE_FOCUSED, GTK_CELL_RENDERER_FOCUSED, FALSE },
36 { ATK_STATE_EXPANDABLE,GTK_CELL_RENDERER_EXPANDABLE, FALSE },
37 { ATK_STATE_EXPANDED, GTK_CELL_RENDERER_EXPANDED, FALSE },
40 static void atk_action_interface_init (AtkActionIface *iface);
41 static void atk_component_interface_init (AtkComponentIface *iface);
43 G_DEFINE_TYPE_WITH_CODE (GtkCellAccessible, _gtk_cell_accessible, GTK_TYPE_ACCESSIBLE,
44 G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init)
45 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init))
48 gtk_cell_accessible_object_finalize (GObject *obj)
50 AtkRelationSet *relation_set;
51 AtkRelation *relation;
53 gpointer target_object;
56 relation_set = atk_object_ref_relation_set (ATK_OBJECT (obj));
57 if (ATK_IS_RELATION_SET (relation_set))
59 relation = atk_relation_set_get_relation_by_type (relation_set,
60 ATK_RELATION_NODE_CHILD_OF);
63 target = atk_relation_get_target (relation);
64 for (i = 0; i < target->len; i++)
66 target_object = g_ptr_array_index (target, i);
67 if (GTK_IS_CELL_ACCESSIBLE (target_object))
68 g_object_unref (target_object);
71 g_object_unref (relation_set);
73 G_OBJECT_CLASS (_gtk_cell_accessible_parent_class)->finalize (obj);
77 gtk_cell_accessible_get_index_in_parent (AtkObject *obj)
79 GtkCellAccessible *cell;
82 cell = GTK_CELL_ACCESSIBLE (obj);
84 parent = atk_object_get_parent (obj);
85 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
86 return g_list_index (_gtk_container_cell_accessible_get_children (GTK_CONTAINER_CELL_ACCESSIBLE (parent)), obj);
88 parent = gtk_widget_get_accessible (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell)));
92 return _gtk_cell_accessible_parent_get_child_index (GTK_CELL_ACCESSIBLE_PARENT (parent), cell);
96 gtk_cell_accessible_ref_state_set (AtkObject *accessible)
98 GtkCellAccessible *cell_accessible;
99 AtkStateSet *state_set;
100 GtkCellRendererState flags;
103 cell_accessible = GTK_CELL_ACCESSIBLE (accessible);
105 state_set = atk_state_set_new ();
107 if (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell_accessible)) == NULL)
109 atk_state_set_add_state (state_set, ATK_STATE_DEFUNCT);
113 flags = _gtk_cell_accessible_get_state (cell_accessible);
115 atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE);
116 atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE);
117 atk_state_set_add_state (state_set, ATK_STATE_TRANSIENT);
118 atk_state_set_add_state (state_set, ATK_STATE_VISIBLE);
120 for (i = 0; i < G_N_ELEMENTS (state_map); i++)
122 if (flags & state_map[i].renderer_state)
124 if (!state_map[i].invert)
125 atk_state_set_add_state (state_set, state_map[i].atk_state);
129 if (state_map[i].invert)
130 atk_state_set_add_state (state_set, state_map[i].atk_state);
134 if (gtk_widget_get_mapped (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell_accessible))))
135 atk_state_set_add_state (state_set, ATK_STATE_SHOWING);
142 _gtk_cell_accessible_class_init (GtkCellAccessibleClass *klass)
144 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
145 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
147 g_object_class->finalize = gtk_cell_accessible_object_finalize;
149 class->get_index_in_parent = gtk_cell_accessible_get_index_in_parent;
150 class->ref_state_set = gtk_cell_accessible_ref_state_set;
154 _gtk_cell_accessible_init (GtkCellAccessible *cell)
159 _gtk_cell_accessible_initialise (GtkCellAccessible *cell,
163 gtk_accessible_set_widget (GTK_ACCESSIBLE (cell), widget);
164 atk_object_set_parent (ATK_OBJECT (cell), parent);
168 _gtk_cell_accessible_add_state (GtkCellAccessible *cell,
169 AtkStateType state_type,
170 gboolean emit_signal)
174 /* The signal should only be generated if the value changed,
175 * not when the cell is set up. So states that are set
176 * initially should pass FALSE as the emit_signal argument.
180 atk_object_notify_state_change (ATK_OBJECT (cell), state_type, TRUE);
181 /* If state_type is ATK_STATE_VISIBLE, additional notification */
182 if (state_type == ATK_STATE_VISIBLE)
183 g_signal_emit_by_name (cell, "visible-data-changed");
186 /* If the parent is a flyweight container cell, propagate the state
189 parent = atk_object_get_parent (ATK_OBJECT (cell));
190 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
191 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (parent), state_type, emit_signal);
197 _gtk_cell_accessible_remove_state (GtkCellAccessible *cell,
198 AtkStateType state_type,
199 gboolean emit_signal)
203 parent = atk_object_get_parent (ATK_OBJECT (cell));
205 /* The signal should only be generated if the value changed,
206 * not when the cell is set up. So states that are set
207 * initially should pass FALSE as the emit_signal argument.
211 atk_object_notify_state_change (ATK_OBJECT (cell), state_type, FALSE);
212 /* If state_type is ATK_STATE_VISIBLE, additional notification */
213 if (state_type == ATK_STATE_VISIBLE)
214 g_signal_emit_by_name (cell, "visible-data-changed");
217 /* If the parent is a flyweight container cell, propagate the state
220 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
221 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (parent), state_type, emit_signal);
227 gtk_cell_accessible_action_get_n_actions (AtkAction *action)
233 gtk_cell_accessible_action_get_name (AtkAction *action,
239 return "expand or contract";
250 gtk_cell_accessible_action_get_description (AtkAction *action,
256 return "expands or contracts the row in the tree view containing this cell";
258 return "creates a widget in which the contents of the cell can be edited";
260 return "activate the cell";
267 gtk_cell_accessible_action_get_keybinding (AtkAction *action,
274 gtk_cell_accessible_action_do_action (AtkAction *action,
277 GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (action);
278 GtkCellAccessibleParent *parent;
280 cell = GTK_CELL_ACCESSIBLE (action);
281 if (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell)) == NULL)
284 parent = GTK_CELL_ACCESSIBLE_PARENT (gtk_widget_get_accessible (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell))));
289 _gtk_cell_accessible_parent_expand_collapse (parent, cell);
291 _gtk_cell_accessible_parent_edit (parent, cell);
293 _gtk_cell_accessible_parent_activate (parent, cell);
302 atk_action_interface_init (AtkActionIface *iface)
304 iface->get_n_actions = gtk_cell_accessible_action_get_n_actions;
305 iface->do_action = gtk_cell_accessible_action_do_action;
306 iface->get_name = gtk_cell_accessible_action_get_name;
307 iface->get_description = gtk_cell_accessible_action_get_description;
308 iface->get_keybinding = gtk_cell_accessible_action_get_keybinding;
312 gtk_cell_accessible_get_extents (AtkComponent *component,
317 AtkCoordType coord_type)
319 GtkCellAccessible *cell;
322 cell = GTK_CELL_ACCESSIBLE (component);
323 parent = gtk_widget_get_accessible (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell)));
325 _gtk_cell_accessible_parent_get_cell_extents (GTK_CELL_ACCESSIBLE_PARENT (parent),
327 x, y, width, height, coord_type);
331 gtk_cell_accessible_grab_focus (AtkComponent *component)
333 GtkCellAccessible *cell;
336 cell = GTK_CELL_ACCESSIBLE (component);
337 parent = gtk_widget_get_accessible (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell)));
339 return _gtk_cell_accessible_parent_grab_focus (GTK_CELL_ACCESSIBLE_PARENT (parent), cell);
343 atk_component_interface_init (AtkComponentIface *iface)
345 iface->get_extents = gtk_cell_accessible_get_extents;
346 iface->grab_focus = gtk_cell_accessible_grab_focus;
350 * _gtk_cell_accessible_get_state:
351 * @cell: a #GtkCellAccessible
353 * Gets the state that would be used to render the area referenced by @cell.
355 * Returns: the #GtkCellRendererState for cell
358 _gtk_cell_accessible_get_state (GtkCellAccessible *cell)
362 g_return_val_if_fail (GTK_IS_CELL_ACCESSIBLE (cell), 0);
364 parent = gtk_widget_get_accessible (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell)));
368 return _gtk_cell_accessible_parent_get_renderer_state (GTK_CELL_ACCESSIBLE_PARENT (parent), cell);
372 * _gtk_cell_accessible_state_changed:
373 * @cell: a #GtkCellAccessible
374 * @added: the flags that were added from @cell
375 * @removed: the flags that were removed from @cell
377 * Notifies @cell of state changes. Multiple states may be added
378 * or removed at the same time. A state that is @added may not be
379 * @removed at the same time.
382 _gtk_cell_accessible_state_changed (GtkCellAccessible *cell,
383 GtkCellRendererState added,
384 GtkCellRendererState removed)
389 g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (cell));
390 g_return_if_fail ((added & removed) == 0);
392 object = ATK_OBJECT (cell);
394 for (i = 0; i < G_N_ELEMENTS (state_map); i++)
396 if (added & state_map[i].renderer_state)
397 atk_object_notify_state_change (object,
398 state_map[i].atk_state,
399 !state_map[i].invert);
400 if (added & state_map[i].renderer_state)
401 atk_object_notify_state_change (object,
402 state_map[i].atk_state,
403 state_map[i].invert);
408 * _gtk_cell_accessible_update_cache:
409 * @cell: the cell that is changed
411 * Notifies the cell that the values in the data in the row that
412 * is used to feed the cell renderer with has changed. The
413 * cell_changed function of @cell is called to send update
414 * notifications for the properties it takes from its cell
417 * Note that there is no higher granularity available about which
418 * properties changed, so you will need to make do with this
422 _gtk_cell_accessible_update_cache (GtkCellAccessible *cell)
424 GtkCellAccessibleClass *klass;
426 g_return_if_fail (GTK_CELL_ACCESSIBLE (cell));
428 klass = GTK_CELL_ACCESSIBLE_GET_CLASS (cell);
430 if (klass->update_cache)
431 klass->update_cache (cell);