1 /* GAIL - The GNOME Accessibility Enabling 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.
21 #include "gailcontainercell.h"
23 static void gail_container_cell_class_init (GailContainerCellClass *klass);
24 static void gail_container_cell_init (GailContainerCell *cell);
25 static void gail_container_cell_finalize (GObject *obj);
28 static void _gail_container_cell_recompute_child_indices
29 (GailContainerCell *container);
31 static void gail_container_cell_refresh_child_index (GailCell *cell);
33 static gint gail_container_cell_get_n_children (AtkObject *obj);
35 static AtkObject* gail_container_cell_ref_child (AtkObject *obj,
38 G_DEFINE_TYPE (GailContainerCell, gail_container_cell, GAIL_TYPE_CELL)
41 gail_container_cell_class_init (GailContainerCellClass *klass)
43 AtkObjectClass *class = ATK_OBJECT_CLASS(klass);
44 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
46 g_object_class->finalize = gail_container_cell_finalize;
48 class->get_n_children = gail_container_cell_get_n_children;
49 class->ref_child = gail_container_cell_ref_child;
53 gail_container_cell_init (GailContainerCell *cell)
58 gail_container_cell_new (void)
61 AtkObject *atk_object;
62 GailContainerCell *container;
64 object = g_object_new (GAIL_TYPE_CONTAINER_CELL, NULL);
66 g_return_val_if_fail (object != NULL, NULL);
68 atk_object = ATK_OBJECT (object);
69 atk_object->role = ATK_ROLE_TABLE_CELL;
71 container = GAIL_CONTAINER_CELL(object);
72 container->children = NULL;
73 container->NChildren = 0;
78 gail_container_cell_finalize (GObject *obj)
80 GailContainerCell *container = GAIL_CONTAINER_CELL (obj);
83 list = container->children;
86 g_object_unref (list->data);
89 g_list_free (container->children);
91 G_OBJECT_CLASS (gail_container_cell_parent_class)->finalize (obj);
96 gail_container_cell_add_child (GailContainerCell *container,
101 g_return_if_fail (GAIL_IS_CONTAINER_CELL(container));
102 g_return_if_fail (GAIL_IS_CELL(child));
104 child_index = container->NChildren++;
105 container->children = g_list_append (container->children, (gpointer) child);
106 child->index = child_index;
107 atk_object_set_parent (ATK_OBJECT (child), ATK_OBJECT (container));
108 child->refresh_index = gail_container_cell_refresh_child_index;
113 gail_container_cell_remove_child (GailContainerCell *container,
116 g_return_if_fail (GAIL_IS_CONTAINER_CELL(container));
117 g_return_if_fail (GAIL_IS_CELL(child));
118 g_return_if_fail (container->NChildren > 0);
120 g_list_remove (container->children, (gpointer) child);
121 _gail_container_cell_recompute_child_indices (container);
122 container->NChildren--;
127 _gail_container_cell_recompute_child_indices (GailContainerCell *container)
132 g_return_if_fail (GAIL_IS_CONTAINER_CELL(container));
134 for (temp_list = container->children; temp_list; temp_list = temp_list->next)
136 GAIL_CELL(temp_list->data)->index = cur_index;
143 gail_container_cell_refresh_child_index (GailCell *cell)
145 GailContainerCell *container;
146 g_return_if_fail (GAIL_IS_CELL(cell));
147 container = GAIL_CONTAINER_CELL (atk_object_get_parent (ATK_OBJECT(cell)));
148 g_return_if_fail (GAIL_IS_CONTAINER_CELL (container));
149 _gail_container_cell_recompute_child_indices (container);
155 gail_container_cell_get_n_children (AtkObject *obj)
157 GailContainerCell *cell;
158 g_return_val_if_fail (GAIL_IS_CONTAINER_CELL(obj), 0);
159 cell = GAIL_CONTAINER_CELL(obj);
160 return cell->NChildren;
165 gail_container_cell_ref_child (AtkObject *obj,
168 GailContainerCell *cell;
171 g_return_val_if_fail (GAIL_IS_CONTAINER_CELL(obj), NULL);
172 cell = GAIL_CONTAINER_CELL(obj);
174 list_node = g_list_nth (cell->children, child);
178 return g_object_ref (ATK_OBJECT (list_node->data));