]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtkcontainercellaccessible.c
GtkImageCellAccessible: add a private struct
[~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, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include "config.h"
19
20 #include <gtk/gtk.h>
21 #include "gtkcontainercellaccessible.h"
22
23 struct _GtkContainerCellAccessiblePrivate
24 {
25   GList *children;
26   gint n_children;
27 };
28
29 G_DEFINE_TYPE (GtkContainerCellAccessible, _gtk_container_cell_accessible, GTK_TYPE_CELL_ACCESSIBLE)
30
31
32 static void
33 gtk_container_cell_accessible_finalize (GObject *obj)
34 {
35   GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (obj);
36
37   g_list_free_full (container->priv->children, g_object_unref);
38
39   G_OBJECT_CLASS (_gtk_container_cell_accessible_parent_class)->finalize (obj);
40 }
41
42
43 static gint
44 gtk_container_cell_accessible_get_n_children (AtkObject *obj)
45 {
46   GtkContainerCellAccessible *cell = GTK_CONTAINER_CELL_ACCESSIBLE (obj);
47
48   return cell->priv->n_children;
49 }
50
51 static AtkObject *
52 gtk_container_cell_accessible_ref_child (AtkObject *obj,
53                                          gint       child)
54 {
55   GtkContainerCellAccessible *cell = GTK_CONTAINER_CELL_ACCESSIBLE (obj);
56   GList *l;
57
58   l = g_list_nth (cell->priv->children, child);
59   if (l == NULL)
60     return NULL;
61
62   return g_object_ref (ATK_OBJECT (l->data));
63 }
64
65 static void
66 gtk_container_cell_accessible_update_cache (GtkCellAccessible *cell)
67 {
68   GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (cell);
69   GList *l;
70
71   for (l = container->priv->children; l; l = l->next)
72     {
73       _gtk_cell_accessible_update_cache (l->data);
74     }
75 }
76
77 static void
78 gtk_container_cell_widget_set (GtkAccessible *accessible)
79 {
80   GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (accessible);
81   GList *l;
82
83   for (l = container->priv->children; l; l = l->next)
84     {
85       gtk_accessible_set_widget (l->data, gtk_accessible_get_widget (accessible));
86     }
87
88   GTK_ACCESSIBLE_CLASS (_gtk_container_cell_accessible_parent_class)->widget_unset (accessible);
89 }
90
91 static void
92 gtk_container_cell_widget_unset (GtkAccessible *accessible)
93 {
94   GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (accessible);
95   GList *l;
96
97   for (l = container->priv->children; l; l = l->next)
98     {
99       gtk_accessible_set_widget (l->data, NULL);
100     }
101
102   GTK_ACCESSIBLE_CLASS (_gtk_container_cell_accessible_parent_class)->widget_unset (accessible);
103 }
104
105 static void
106 _gtk_container_cell_accessible_class_init (GtkContainerCellAccessibleClass *klass)
107 {
108   GtkCellAccessibleClass *cell_class = GTK_CELL_ACCESSIBLE_CLASS (klass);
109   GtkAccessibleClass *accessible_class = GTK_ACCESSIBLE_CLASS (klass);
110   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
111   GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
112
113   g_object_class->finalize = gtk_container_cell_accessible_finalize;
114
115   class->get_n_children = gtk_container_cell_accessible_get_n_children;
116   class->ref_child = gtk_container_cell_accessible_ref_child;
117
118   accessible_class->widget_unset = gtk_container_cell_widget_set;
119   accessible_class->widget_unset = gtk_container_cell_widget_unset;
120
121   cell_class->update_cache = gtk_container_cell_accessible_update_cache;
122
123   g_type_class_add_private (g_object_class, sizeof (GtkContainerCellAccessiblePrivate));
124 }
125
126 static void
127 _gtk_container_cell_accessible_init (GtkContainerCellAccessible *cell)
128 {
129   cell->priv = G_TYPE_INSTANCE_GET_PRIVATE (cell,
130                                             GTK_TYPE_CONTAINER_CELL_ACCESSIBLE,
131                                             GtkContainerCellAccessiblePrivate);
132 }
133
134 GtkContainerCellAccessible *
135 _gtk_container_cell_accessible_new (void)
136 {
137   GObject *object;
138
139   object = g_object_new (GTK_TYPE_CONTAINER_CELL_ACCESSIBLE, NULL);
140
141   ATK_OBJECT (object)->role = ATK_ROLE_TABLE_CELL;
142
143   return GTK_CONTAINER_CELL_ACCESSIBLE (object);
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->priv->n_children++;
154   container->priv->children = g_list_append (container->priv->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->priv->n_children > 0);
165
166   container->priv->children = g_list_remove (container->priv->children, child);
167   container->priv->n_children--;
168 }
169
170 GList *
171 _gtk_conainer_cell_accessible_get_children (GtkContainerCellAccessible *container)
172 {
173   g_return_val_if_fail (GTK_IS_CONTAINER_CELL_ACCESSIBLE (container), NULL);
174
175   return container->priv->children;
176 }