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 "gtkcellaccessibleprivate.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 GtkCellRendererState gtk_cell_accessible_get_state (GtkCellAccessible *cell);
41 static void atk_action_interface_init (AtkActionIface *iface);
42 static void atk_component_interface_init (AtkComponentIface *iface);
44 G_DEFINE_TYPE_WITH_CODE (GtkCellAccessible, gtk_cell_accessible, GTK_TYPE_ACCESSIBLE,
45 G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init)
46 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init))
49 gtk_cell_accessible_object_finalize (GObject *obj)
51 AtkRelationSet *relation_set;
52 AtkRelation *relation;
54 gpointer target_object;
57 relation_set = atk_object_ref_relation_set (ATK_OBJECT (obj));
58 if (ATK_IS_RELATION_SET (relation_set))
60 relation = atk_relation_set_get_relation_by_type (relation_set,
61 ATK_RELATION_NODE_CHILD_OF);
64 target = atk_relation_get_target (relation);
65 for (i = 0; i < target->len; i++)
67 target_object = g_ptr_array_index (target, i);
68 if (GTK_IS_CELL_ACCESSIBLE (target_object))
69 g_object_unref (target_object);
72 g_object_unref (relation_set);
74 G_OBJECT_CLASS (gtk_cell_accessible_parent_class)->finalize (obj);
78 gtk_cell_accessible_get_index_in_parent (AtkObject *obj)
80 GtkCellAccessible *cell;
83 cell = GTK_CELL_ACCESSIBLE (obj);
85 parent = atk_object_get_parent (obj);
86 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
87 return g_list_index (gtk_container_cell_accessible_get_children (GTK_CONTAINER_CELL_ACCESSIBLE (parent)), obj);
89 parent = gtk_widget_get_accessible (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell)));
93 return gtk_cell_accessible_parent_get_child_index (GTK_CELL_ACCESSIBLE_PARENT (parent), cell);
97 gtk_cell_accessible_ref_state_set (AtkObject *accessible)
99 GtkCellAccessible *cell_accessible;
100 AtkStateSet *state_set;
101 GtkCellRendererState flags;
104 cell_accessible = GTK_CELL_ACCESSIBLE (accessible);
106 state_set = atk_state_set_new ();
108 if (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell_accessible)) == NULL)
110 atk_state_set_add_state (state_set, ATK_STATE_DEFUNCT);
114 flags = gtk_cell_accessible_get_state (cell_accessible);
116 atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE);
117 atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE);
118 atk_state_set_add_state (state_set, ATK_STATE_TRANSIENT);
119 atk_state_set_add_state (state_set, ATK_STATE_VISIBLE);
121 for (i = 0; i < G_N_ELEMENTS (state_map); i++)
123 if (flags & state_map[i].renderer_state)
125 if (!state_map[i].invert)
126 atk_state_set_add_state (state_set, state_map[i].atk_state);
130 if (state_map[i].invert)
131 atk_state_set_add_state (state_set, state_map[i].atk_state);
135 if (gtk_widget_get_mapped (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell_accessible))))
136 atk_state_set_add_state (state_set, ATK_STATE_SHOWING);
143 gtk_cell_accessible_class_init (GtkCellAccessibleClass *klass)
145 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
146 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
148 g_object_class->finalize = gtk_cell_accessible_object_finalize;
150 class->get_index_in_parent = gtk_cell_accessible_get_index_in_parent;
151 class->ref_state_set = gtk_cell_accessible_ref_state_set;
155 gtk_cell_accessible_init (GtkCellAccessible *cell)
160 _gtk_cell_accessible_initialize (GtkCellAccessible *cell,
164 gtk_accessible_set_widget (GTK_ACCESSIBLE (cell), widget);
165 atk_object_set_parent (ATK_OBJECT (cell), parent);
169 _gtk_cell_accessible_add_state (GtkCellAccessible *cell,
170 AtkStateType state_type,
171 gboolean emit_signal)
175 /* The signal should only be generated if the value changed,
176 * not when the cell is set up. So states that are set
177 * initially should pass FALSE as the emit_signal argument.
181 atk_object_notify_state_change (ATK_OBJECT (cell), state_type, TRUE);
182 /* If state_type is ATK_STATE_VISIBLE, additional notification */
183 if (state_type == ATK_STATE_VISIBLE)
184 g_signal_emit_by_name (cell, "visible-data-changed");
187 /* If the parent is a flyweight container cell, propagate the state
190 parent = atk_object_get_parent (ATK_OBJECT (cell));
191 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
192 _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (parent), state_type, emit_signal);
198 _gtk_cell_accessible_remove_state (GtkCellAccessible *cell,
199 AtkStateType state_type,
200 gboolean emit_signal)
204 parent = atk_object_get_parent (ATK_OBJECT (cell));
206 /* The signal should only be generated if the value changed,
207 * not when the cell is set up. So states that are set
208 * initially should pass FALSE as the emit_signal argument.
212 atk_object_notify_state_change (ATK_OBJECT (cell), state_type, FALSE);
213 /* If state_type is ATK_STATE_VISIBLE, additional notification */
214 if (state_type == ATK_STATE_VISIBLE)
215 g_signal_emit_by_name (cell, "visible-data-changed");
218 /* If the parent is a flyweight container cell, propagate the state
221 if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (parent))
222 _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (parent), state_type, emit_signal);
228 gtk_cell_accessible_action_get_n_actions (AtkAction *action)
234 gtk_cell_accessible_action_get_name (AtkAction *action,
240 return "expand or contract";
251 gtk_cell_accessible_action_get_description (AtkAction *action,
257 return "expands or contracts the row in the tree view containing this cell";
259 return "creates a widget in which the contents of the cell can be edited";
261 return "activate the cell";
268 gtk_cell_accessible_action_get_keybinding (AtkAction *action,
275 gtk_cell_accessible_action_do_action (AtkAction *action,
278 GtkCellAccessible *cell = GTK_CELL_ACCESSIBLE (action);
279 GtkCellAccessibleParent *parent;
281 cell = GTK_CELL_ACCESSIBLE (action);
282 if (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell)) == NULL)
285 parent = GTK_CELL_ACCESSIBLE_PARENT (gtk_widget_get_accessible (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell))));
290 gtk_cell_accessible_parent_expand_collapse (parent, cell);
293 gtk_cell_accessible_parent_edit (parent, cell);
296 gtk_cell_accessible_parent_activate (parent, cell);
306 atk_action_interface_init (AtkActionIface *iface)
308 iface->get_n_actions = gtk_cell_accessible_action_get_n_actions;
309 iface->do_action = gtk_cell_accessible_action_do_action;
310 iface->get_name = gtk_cell_accessible_action_get_name;
311 iface->get_description = gtk_cell_accessible_action_get_description;
312 iface->get_keybinding = gtk_cell_accessible_action_get_keybinding;
316 gtk_cell_accessible_get_extents (AtkComponent *component,
321 AtkCoordType coord_type)
323 GtkCellAccessible *cell;
326 cell = GTK_CELL_ACCESSIBLE (component);
327 parent = gtk_widget_get_accessible (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell)));
329 gtk_cell_accessible_parent_get_cell_extents (GTK_CELL_ACCESSIBLE_PARENT (parent),
331 x, y, width, height, coord_type);
335 gtk_cell_accessible_grab_focus (AtkComponent *component)
337 GtkCellAccessible *cell;
340 cell = GTK_CELL_ACCESSIBLE (component);
341 parent = gtk_widget_get_accessible (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell)));
343 return gtk_cell_accessible_parent_grab_focus (GTK_CELL_ACCESSIBLE_PARENT (parent), cell);
347 atk_component_interface_init (AtkComponentIface *iface)
349 iface->get_extents = gtk_cell_accessible_get_extents;
350 iface->grab_focus = gtk_cell_accessible_grab_focus;
353 static GtkCellRendererState
354 gtk_cell_accessible_get_state (GtkCellAccessible *cell)
358 g_return_val_if_fail (GTK_IS_CELL_ACCESSIBLE (cell), 0);
360 parent = gtk_widget_get_accessible (gtk_accessible_get_widget (GTK_ACCESSIBLE (cell)));
364 return gtk_cell_accessible_parent_get_renderer_state (GTK_CELL_ACCESSIBLE_PARENT (parent), cell);
368 * gtk_cell_accessible_state_changed:
369 * @cell: a #GtkCellAccessible
370 * @added: the flags that were added from @cell
371 * @removed: the flags that were removed from @cell
373 * Notifies @cell of state changes. Multiple states may be added
374 * or removed at the same time. A state that is @added may not be
375 * @removed at the same time.
378 _gtk_cell_accessible_state_changed (GtkCellAccessible *cell,
379 GtkCellRendererState added,
380 GtkCellRendererState removed)
385 g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (cell));
386 g_return_if_fail ((added & removed) == 0);
388 object = ATK_OBJECT (cell);
390 for (i = 0; i < G_N_ELEMENTS (state_map); i++)
392 if (added & state_map[i].renderer_state)
393 atk_object_notify_state_change (object,
394 state_map[i].atk_state,
395 !state_map[i].invert);
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);
404 * gtk_cell_accessible_update_cache:
405 * @cell: the cell that is changed
407 * Notifies the cell that the values in the data in the row that
408 * is used to feed the cell renderer with has changed. The
409 * cell_changed function of @cell is called to send update
410 * notifications for the properties it takes from its cell
413 * Note that there is no higher granularity available about which
414 * properties changed, so you will need to make do with this
418 _gtk_cell_accessible_update_cache (GtkCellAccessible *cell)
420 GtkCellAccessibleClass *klass;
422 g_return_if_fail (GTK_CELL_ACCESSIBLE (cell));
424 klass = GTK_CELL_ACCESSIBLE_GET_CLASS (cell);
426 if (klass->update_cache)
427 klass->update_cache (cell);