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.
23 #include "gailcontainercell.h"
25 static void gail_container_cell_class_init (GailContainerCellClass *klass);
26 static void gail_container_cell_init (GailContainerCell *cell);
27 static void gail_container_cell_finalize (GObject *obj);
30 static void _gail_container_cell_recompute_child_indices
31 (GailContainerCell *container);
33 static void gail_container_cell_refresh_child_index (GailCell *cell);
35 static gint gail_container_cell_get_n_children (AtkObject *obj);
37 static AtkObject* gail_container_cell_ref_child (AtkObject *obj,
40 G_DEFINE_TYPE (GailContainerCell, gail_container_cell, GAIL_TYPE_CELL)
43 gail_container_cell_class_init (GailContainerCellClass *klass)
45 AtkObjectClass *class = ATK_OBJECT_CLASS(klass);
46 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
48 g_object_class->finalize = gail_container_cell_finalize;
50 class->get_n_children = gail_container_cell_get_n_children;
51 class->ref_child = gail_container_cell_ref_child;
55 gail_container_cell_init (GailContainerCell *cell)
60 gail_container_cell_new (void)
63 AtkObject *atk_object;
64 GailContainerCell *container;
66 object = g_object_new (GAIL_TYPE_CONTAINER_CELL, NULL);
68 g_return_val_if_fail (object != NULL, NULL);
70 atk_object = ATK_OBJECT (object);
71 atk_object->role = ATK_ROLE_TABLE_CELL;
73 container = GAIL_CONTAINER_CELL(object);
74 container->children = NULL;
75 container->NChildren = 0;
80 gail_container_cell_finalize (GObject *obj)
82 GailContainerCell *container = GAIL_CONTAINER_CELL (obj);
85 list = container->children;
88 g_object_unref (list->data);
91 g_list_free (container->children);
93 G_OBJECT_CLASS (gail_container_cell_parent_class)->finalize (obj);
98 gail_container_cell_add_child (GailContainerCell *container,
103 g_return_if_fail (GAIL_IS_CONTAINER_CELL(container));
104 g_return_if_fail (GAIL_IS_CELL(child));
106 child_index = container->NChildren++;
107 container->children = g_list_append (container->children, (gpointer) child);
108 child->index = child_index;
109 atk_object_set_parent (ATK_OBJECT (child), ATK_OBJECT (container));
110 child->refresh_index = gail_container_cell_refresh_child_index;
115 gail_container_cell_remove_child (GailContainerCell *container,
118 g_return_if_fail (GAIL_IS_CONTAINER_CELL(container));
119 g_return_if_fail (GAIL_IS_CELL(child));
120 g_return_if_fail (container->NChildren > 0);
122 container->children = g_list_remove (container->children, (gpointer) child);
123 _gail_container_cell_recompute_child_indices (container);
124 container->NChildren--;
129 _gail_container_cell_recompute_child_indices (GailContainerCell *container)
134 g_return_if_fail (GAIL_IS_CONTAINER_CELL(container));
136 for (temp_list = container->children; temp_list; temp_list = temp_list->next)
138 GAIL_CELL(temp_list->data)->index = cur_index;
145 gail_container_cell_refresh_child_index (GailCell *cell)
147 GailContainerCell *container;
148 g_return_if_fail (GAIL_IS_CELL(cell));
149 container = GAIL_CONTAINER_CELL (atk_object_get_parent (ATK_OBJECT(cell)));
150 g_return_if_fail (GAIL_IS_CONTAINER_CELL (container));
151 _gail_container_cell_recompute_child_indices (container);
157 gail_container_cell_get_n_children (AtkObject *obj)
159 GailContainerCell *cell;
160 g_return_val_if_fail (GAIL_IS_CONTAINER_CELL(obj), 0);
161 cell = GAIL_CONTAINER_CELL(obj);
162 return cell->NChildren;
167 gail_container_cell_ref_child (AtkObject *obj,
170 GailContainerCell *cell;
173 g_return_val_if_fail (GAIL_IS_CONTAINER_CELL(obj), NULL);
174 cell = GAIL_CONTAINER_CELL(obj);
176 list_node = g_list_nth (cell->children, child);
180 return g_object_ref (ATK_OBJECT (list_node->data));