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.
22 #include "gailcontainercell.h"
24 #include "gailcellparent.h"
26 static void gail_cell_class_init (GailCellClass *klass);
27 static void gail_cell_destroyed (GtkWidget *widget,
30 static void gail_cell_init (GailCell *cell);
31 static void gail_cell_object_finalize (GObject *cell);
32 static AtkStateSet* gail_cell_ref_state_set (AtkObject *obj);
33 static gint gail_cell_get_index_in_parent (AtkObject *obj);
37 static void gail_cell_atk_action_interface_init
38 (AtkActionIface *iface);
39 static ActionInfo * _gail_cell_get_action_info (GailCell *cell,
41 static void _gail_cell_destroy_action_info
45 static gint gail_cell_action_get_n_actions
47 static G_CONST_RETURN gchar*
48 gail_cell_action_get_name (AtkAction *action,
50 static G_CONST_RETURN gchar *
51 gail_cell_action_get_description
54 static gboolean gail_cell_action_set_description
58 static G_CONST_RETURN gchar *
59 gail_cell_action_get_keybinding
62 static gboolean gail_cell_action_do_action (AtkAction *action,
64 static gboolean idle_do_action (gpointer data);
66 static void atk_component_interface_init (AtkComponentIface *iface);
67 static void gail_cell_get_extents (AtkComponent *component,
72 AtkCoordType coord_type);
73 static gboolean gail_cell_grab_focus (AtkComponent *component);
75 G_DEFINE_TYPE_WITH_CODE (GailCell, gail_cell, ATK_TYPE_OBJECT,
76 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init))
79 gail_cell_class_init (GailCellClass *klass)
81 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
82 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
84 g_object_class->finalize = gail_cell_object_finalize;
86 class->get_index_in_parent = gail_cell_get_index_in_parent;
87 class->ref_state_set = gail_cell_ref_state_set;
91 gail_cell_initialise (GailCell *cell,
96 g_return_if_fail (GAIL_IS_CELL (cell));
97 g_return_if_fail (GTK_IS_WIDGET (widget));
99 cell->widget = widget;
100 atk_object_set_parent (ATK_OBJECT (cell), parent);
103 g_signal_connect_object (G_OBJECT (widget),
105 G_CALLBACK (gail_cell_destroyed ),
110 gail_cell_destroyed (GtkWidget *widget,
114 * This is the signal handler for the "destroy" signal for the
115 * GtkWidget. We set the pointer location to NULL;
121 gail_cell_init (GailCell *cell)
123 cell->state_set = atk_state_set_new ();
125 cell->action_list = NULL;
127 atk_state_set_add_state (cell->state_set, ATK_STATE_TRANSIENT);
128 atk_state_set_add_state (cell->state_set, ATK_STATE_ENABLED);
129 atk_state_set_add_state (cell->state_set, ATK_STATE_SENSITIVE);
130 atk_state_set_add_state (cell->state_set, ATK_STATE_SELECTABLE);
131 cell->refresh_index = NULL;
135 gail_cell_object_finalize (GObject *obj)
137 GailCell *cell = GAIL_CELL (obj);
138 AtkRelationSet *relation_set;
139 AtkRelation *relation;
141 gpointer target_object;
145 g_object_unref (cell->state_set);
146 g_list_free (cell->action_list);
147 if (cell->action_idle_handler)
149 g_source_remove (cell->action_idle_handler);
150 cell->action_idle_handler = 0;
152 relation_set = atk_object_ref_relation_set (ATK_OBJECT (obj));
153 if (ATK_IS_RELATION_SET (relation_set))
155 relation = atk_relation_set_get_relation_by_type (relation_set,
156 ATK_RELATION_NODE_CHILD_OF);
159 target = atk_relation_get_target (relation);
160 for (i = 0; i < target->len; i++)
162 target_object = g_ptr_array_index (target, i);
163 if (GAIL_IS_CELL (target_object))
165 g_object_unref (target_object);
169 g_object_unref (relation_set);
171 G_OBJECT_CLASS (gail_cell_parent_class)->finalize (obj);
175 gail_cell_ref_state_set (AtkObject *obj)
177 GailCell *cell = GAIL_CELL (obj);
178 g_assert (cell->state_set);
180 g_object_ref(cell->state_set);
181 return cell->state_set;
185 gail_cell_add_state (GailCell *cell,
186 AtkStateType state_type,
187 gboolean emit_signal)
189 if (!atk_state_set_contains_state (cell->state_set, state_type))
194 rc = atk_state_set_add_state (cell->state_set, state_type);
196 * The signal should only be generated if the value changed,
197 * not when the cell is set up. So states that are set
198 * initially should pass FALSE as the emit_signal argument.
203 atk_object_notify_state_change (ATK_OBJECT (cell), state_type, TRUE);
204 /* If state_type is ATK_STATE_VISIBLE, additional notification */
205 if (state_type == ATK_STATE_VISIBLE)
206 g_signal_emit_by_name (cell, "visible_data_changed");
210 * If the parent is a flyweight container cell, propagate the state
214 parent = atk_object_get_parent (ATK_OBJECT (cell));
215 if (GAIL_IS_CONTAINER_CELL (parent))
216 gail_cell_add_state (GAIL_CELL (parent), state_type, emit_signal);
224 gail_cell_remove_state (GailCell *cell,
225 AtkStateType state_type,
226 gboolean emit_signal)
228 if (atk_state_set_contains_state (cell->state_set, state_type))
233 parent = atk_object_get_parent (ATK_OBJECT (cell));
235 rc = atk_state_set_remove_state (cell->state_set, state_type);
237 * The signal should only be generated if the value changed,
238 * not when the cell is set up. So states that are set
239 * 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");
251 * If the parent is a flyweight container cell, propagate the state
255 if (GAIL_IS_CONTAINER_CELL (parent))
256 gail_cell_remove_state (GAIL_CELL (parent), state_type, emit_signal);
264 gail_cell_get_index_in_parent (AtkObject *obj)
268 g_assert (GAIL_IS_CELL (obj));
270 cell = GAIL_CELL (obj);
271 if (atk_state_set_contains_state (cell->state_set, ATK_STATE_STALE))
272 if (cell->refresh_index)
274 cell->refresh_index (cell);
275 atk_state_set_remove_state (cell->state_set, ATK_STATE_STALE);
281 gail_cell_atk_action_interface_init (AtkActionIface *iface)
283 iface->get_n_actions = gail_cell_action_get_n_actions;
284 iface->do_action = gail_cell_action_do_action;
285 iface->get_name = gail_cell_action_get_name;
286 iface->get_description = gail_cell_action_get_description;
287 iface->set_description = gail_cell_action_set_description;
288 iface->get_keybinding = gail_cell_action_get_keybinding;
292 gail_cell_type_add_action_interface (GType type)
294 const GInterfaceInfo atk_action_info =
296 (GInterfaceInitFunc) gail_cell_atk_action_interface_init,
297 (GInterfaceFinalizeFunc) NULL,
300 g_type_add_interface_static (type, ATK_TYPE_ACTION,
305 gail_cell_add_action (GailCell *cell,
306 const gchar *action_name,
307 const gchar *action_description,
308 const gchar *action_keybinding,
309 ACTION_FUNC action_func)
312 g_return_val_if_fail (GAIL_IS_CELL (cell), FALSE);
313 info = g_new (ActionInfo, 1);
315 if (action_name != NULL)
316 info->name = g_strdup (action_name);
319 if (action_description != NULL)
320 info->description = g_strdup (action_description);
322 info->description = NULL;
323 if (action_keybinding != NULL)
324 info->keybinding = g_strdup (action_keybinding);
326 info->keybinding = NULL;
327 info->do_action_func = action_func;
329 cell->action_list = g_list_append (cell->action_list, (gpointer) info);
334 gail_cell_remove_action (GailCell *cell,
339 g_return_val_if_fail (GAIL_IS_CELL (cell), FALSE);
340 list_node = g_list_nth (cell->action_list, action_index);
343 _gail_cell_destroy_action_info (list_node->data, NULL);
344 cell->action_list = g_list_remove_link (cell->action_list, list_node);
350 gail_cell_remove_action_by_name (GailCell *cell,
351 const gchar *action_name)
354 gboolean action_found= FALSE;
356 g_return_val_if_fail (GAIL_IS_CELL (cell), FALSE);
357 for (list_node = cell->action_list; list_node && !action_found;
358 list_node = list_node->next)
360 if (!g_strcasecmp (((ActionInfo *)(list_node->data))->name, action_name))
368 _gail_cell_destroy_action_info (list_node->data, NULL);
369 cell->action_list = g_list_remove_link (cell->action_list, list_node);
374 _gail_cell_get_action_info (GailCell *cell,
379 g_return_val_if_fail (GAIL_IS_CELL (cell), NULL);
380 if (cell->action_list == NULL)
382 list_node = g_list_nth (cell->action_list, index);
385 return (ActionInfo *) (list_node->data);
390 _gail_cell_destroy_action_info (gpointer action_info,
393 ActionInfo *info = (ActionInfo *)action_info;
394 g_assert (info != NULL);
396 g_free (info->description);
397 g_free (info->keybinding);
401 gail_cell_action_get_n_actions (AtkAction *action)
403 GailCell *cell = GAIL_CELL(action);
404 if (cell->action_list != NULL)
405 return g_list_length (cell->action_list);
410 static G_CONST_RETURN gchar *
411 gail_cell_action_get_name (AtkAction *action,
414 GailCell *cell = GAIL_CELL(action);
415 ActionInfo *info = _gail_cell_get_action_info (cell, index);
422 static G_CONST_RETURN gchar *
423 gail_cell_action_get_description (AtkAction *action,
426 GailCell *cell = GAIL_CELL(action);
427 ActionInfo *info = _gail_cell_get_action_info (cell, index);
431 return info->description;
435 gail_cell_action_set_description (AtkAction *action,
439 GailCell *cell = GAIL_CELL(action);
440 ActionInfo *info = _gail_cell_get_action_info (cell, index);
444 g_free (info->description);
445 info->description = g_strdup (desc);
449 static G_CONST_RETURN gchar *
450 gail_cell_action_get_keybinding (AtkAction *action,
453 GailCell *cell = GAIL_CELL(action);
454 ActionInfo *info = _gail_cell_get_action_info (cell, index);
457 return info->keybinding;
461 gail_cell_action_do_action (AtkAction *action,
464 GailCell *cell = GAIL_CELL(action);
465 ActionInfo *info = _gail_cell_get_action_info (cell, index);
468 if (info->do_action_func == NULL)
470 if (cell->action_idle_handler)
472 cell->action_func = info->do_action_func;
473 cell->action_idle_handler = gdk_threads_add_idle (idle_do_action, cell);
478 idle_do_action (gpointer data)
482 cell = GAIL_CELL (data);
483 cell->action_idle_handler = 0;
484 cell->action_func (cell);
490 atk_component_interface_init (AtkComponentIface *iface)
492 iface->get_extents = gail_cell_get_extents;
493 iface->grab_focus = gail_cell_grab_focus;
497 gail_cell_get_extents (AtkComponent *component,
502 AtkCoordType coord_type)
505 AtkObject *cell_parent;
507 g_assert (GAIL_IS_CELL (component));
509 gailcell = GAIL_CELL (component);
511 cell_parent = gtk_widget_get_accessible (gailcell->widget);
513 gail_cell_parent_get_cell_extents (GAIL_CELL_PARENT (cell_parent),
514 gailcell, x, y, width, height, coord_type);
518 gail_cell_grab_focus (AtkComponent *component)
521 AtkObject *cell_parent;
523 g_assert (GAIL_IS_CELL (component));
525 gailcell = GAIL_CELL (component);
527 cell_parent = gtk_widget_get_accessible (gailcell->widget);
529 return gail_cell_parent_grab_focus (GAIL_CELL_PARENT (cell_parent),