]> Pileus Git - ~andy/gtk/blob - modules/other/gail/gailcontainercell.c
gail: No need to include modules/other in CFLAGS anymore
[~andy/gtk] / modules / other / gail / gailcontainercell.c
1 /* GAIL - The GNOME Accessibility Enabling Library
2  * Copyright 2001 Sun Microsystems Inc.
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include "config.h"
21
22 #include <gtk/gtk.h>
23 #include "gailcontainercell.h"
24
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);
28
29
30 static void       _gail_container_cell_recompute_child_indices 
31                                                           (GailContainerCell *container);
32
33 static void       gail_container_cell_refresh_child_index (GailCell *cell);
34
35 static gint       gail_container_cell_get_n_children      (AtkObject *obj);
36
37 static AtkObject* gail_container_cell_ref_child           (AtkObject *obj,
38                                                            gint      child);
39
40 G_DEFINE_TYPE (GailContainerCell, gail_container_cell, GAIL_TYPE_CELL)
41
42 static void 
43 gail_container_cell_class_init (GailContainerCellClass *klass)
44 {
45   AtkObjectClass *class = ATK_OBJECT_CLASS(klass);
46   GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
47
48   g_object_class->finalize = gail_container_cell_finalize;
49
50   class->get_n_children = gail_container_cell_get_n_children;
51   class->ref_child = gail_container_cell_ref_child;
52 }
53
54 static void
55 gail_container_cell_init (GailContainerCell   *cell)
56 {
57 }
58
59 GailContainerCell * 
60 gail_container_cell_new (void)
61 {
62   GObject *object;
63   AtkObject *atk_object;
64   GailContainerCell *container;
65
66   object = g_object_new (GAIL_TYPE_CONTAINER_CELL, NULL);
67
68   g_return_val_if_fail (object != NULL, NULL);
69
70   atk_object = ATK_OBJECT (object);
71   atk_object->role = ATK_ROLE_TABLE_CELL;
72
73   container = GAIL_CONTAINER_CELL(object);
74   container->children = NULL;
75   container->NChildren = 0;
76   return container;
77 }
78
79 static void
80 gail_container_cell_finalize (GObject *obj)
81 {
82   GailContainerCell *container = GAIL_CONTAINER_CELL (obj);
83   GList *list;
84
85   list = container->children;
86   while (list)
87   {
88     g_object_unref (list->data);
89     list = list->next;
90   }
91   g_list_free (container->children);
92   
93   G_OBJECT_CLASS (gail_container_cell_parent_class)->finalize (obj);
94 }
95
96
97 void
98 gail_container_cell_add_child (GailContainerCell *container,
99                                GailCell *child)
100 {
101   gint child_index;
102
103   g_return_if_fail (GAIL_IS_CONTAINER_CELL(container));
104   g_return_if_fail (GAIL_IS_CELL(child));
105
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;
111 }
112
113
114 void
115 gail_container_cell_remove_child (GailContainerCell *container,
116                                   GailCell *child)
117 {
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);
121
122   container->children = g_list_remove (container->children, (gpointer) child);
123   _gail_container_cell_recompute_child_indices (container);
124   container->NChildren--;
125 }
126
127
128 static void
129 _gail_container_cell_recompute_child_indices (GailContainerCell *container)
130 {
131   gint cur_index = 0;
132   GList *temp_list;
133
134   g_return_if_fail (GAIL_IS_CONTAINER_CELL(container));
135
136   for (temp_list = container->children; temp_list; temp_list = temp_list->next)
137     {
138       GAIL_CELL(temp_list->data)->index = cur_index;
139       cur_index++;
140     }
141 }
142
143
144 static void
145 gail_container_cell_refresh_child_index (GailCell *cell)
146 {
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);
152 }
153
154
155
156 static gint
157 gail_container_cell_get_n_children (AtkObject *obj)
158 {
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;
163 }
164
165
166 static AtkObject *
167 gail_container_cell_ref_child (AtkObject *obj,
168                                gint       child)
169 {
170   GailContainerCell *cell;
171   GList *list_node;
172
173   g_return_val_if_fail (GAIL_IS_CONTAINER_CELL(obj), NULL);
174   cell = GAIL_CONTAINER_CELL(obj);
175   
176   list_node = g_list_nth (cell->children, child);
177   if (!list_node)
178     return NULL;
179
180   return g_object_ref (ATK_OBJECT (list_node->data));
181 }