]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtkcontainercellaccessible.c
ad90de29c29c65cd16d749c454e4a030891143d0
[~andy/gtk] / gtk / a11y / gtkcontainercellaccessible.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 "gtkcontainercellaccessible.h"
24
25
26 G_DEFINE_TYPE (GtkContainerCellAccessible, _gtk_container_cell_accessible, GTK_TYPE_CELL_ACCESSIBLE)
27
28
29 static void
30 gtk_container_cell_accessible_finalize (GObject *obj)
31 {
32   GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (obj);
33
34   g_list_free_full (container->children, g_object_unref);
35
36   G_OBJECT_CLASS (_gtk_container_cell_accessible_parent_class)->finalize (obj);
37 }
38
39
40 static gint
41 gtk_container_cell_accessible_get_n_children (AtkObject *obj)
42 {
43   GtkContainerCellAccessible *cell = GTK_CONTAINER_CELL_ACCESSIBLE (obj);
44
45   return cell->NChildren;
46 }
47
48 static AtkObject *
49 gtk_container_cell_accessible_ref_child (AtkObject *obj,
50                                          gint       child)
51 {
52   GtkContainerCellAccessible *cell = GTK_CONTAINER_CELL_ACCESSIBLE (obj);
53   GList *l;
54
55   l = g_list_nth (cell->children, child);
56   if (l == NULL)
57     return NULL;
58
59   return g_object_ref (ATK_OBJECT (l->data));
60 }
61
62 static void
63 gtk_container_cell_accessible_update_cache (GtkCellAccessible *cell)
64 {
65   GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (cell);
66   GList *l;
67
68   for (l = container->children; l; l = l->next)
69     {
70       _gtk_cell_accessible_update_cache (l->data);
71     }
72 }
73
74 static void
75 gtk_container_cell_widget_set (GtkAccessible *accessible)
76 {
77   GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (accessible);
78   GList *l;
79
80   for (l = container->children; l; l = l->next)
81     {
82       gtk_accessible_set_widget (l->data, gtk_accessible_get_widget (accessible));
83     }
84
85   GTK_ACCESSIBLE_CLASS (_gtk_container_cell_accessible_parent_class)->widget_unset (accessible);
86 }
87
88 static void
89 gtk_container_cell_widget_unset (GtkAccessible *accessible)
90 {
91   GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (accessible);
92   GList *l;
93
94   for (l = container->children; l; l = l->next)
95     {
96       gtk_accessible_set_widget (l->data, NULL);
97     }
98
99   GTK_ACCESSIBLE_CLASS (_gtk_container_cell_accessible_parent_class)->widget_unset (accessible);
100 }
101
102 static void
103 _gtk_container_cell_accessible_class_init (GtkContainerCellAccessibleClass *klass)
104 {
105   GtkCellAccessibleClass *cell_class = GTK_CELL_ACCESSIBLE_CLASS (klass);
106   GtkAccessibleClass *accessible_class = GTK_ACCESSIBLE_CLASS (klass);
107   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
108   GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
109
110   g_object_class->finalize = gtk_container_cell_accessible_finalize;
111
112   class->get_n_children = gtk_container_cell_accessible_get_n_children;
113   class->ref_child = gtk_container_cell_accessible_ref_child;
114
115   accessible_class->widget_unset = gtk_container_cell_widget_set;
116   accessible_class->widget_unset = gtk_container_cell_widget_unset;
117
118   cell_class->update_cache = gtk_container_cell_accessible_update_cache;
119 }
120
121 static void
122 _gtk_container_cell_accessible_init (GtkContainerCellAccessible *cell)
123 {
124 }
125
126 GtkContainerCellAccessible *
127 _gtk_container_cell_accessible_new (void)
128 {
129   GObject *object;
130   AtkObject *atk_object;
131   GtkContainerCellAccessible *container;
132
133   object = g_object_new (GTK_TYPE_CONTAINER_CELL_ACCESSIBLE, NULL);
134
135   g_return_val_if_fail (object != NULL, NULL);
136
137   atk_object = ATK_OBJECT (object);
138   atk_object->role = ATK_ROLE_TABLE_CELL;
139
140   container = GTK_CONTAINER_CELL_ACCESSIBLE (object);
141   container->children = NULL;
142   container->NChildren = 0;
143   return container;
144 }
145
146 void
147 _gtk_container_cell_accessible_add_child (GtkContainerCellAccessible *container,
148                                           GtkCellAccessible          *child)
149 {
150   g_return_if_fail (GTK_IS_CONTAINER_CELL_ACCESSIBLE (container));
151   g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (child));
152
153   container->NChildren++;
154   container->children = g_list_append (container->children, child);
155   atk_object_set_parent (ATK_OBJECT (child), ATK_OBJECT (container));
156 }
157
158 void
159 _gtk_container_cell_accessible_remove_child (GtkContainerCellAccessible *container,
160                                              GtkCellAccessible          *child)
161 {
162   g_return_if_fail (GTK_IS_CONTAINER_CELL_ACCESSIBLE (container));
163   g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (child));
164   g_return_if_fail (container->NChildren > 0);
165
166   container->children = g_list_remove (container->children, child);
167   container->NChildren--;
168 }