]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtkcontainercellaccessible.c
GtkBubbleWindow: Use style border color to stroke the bubble shape
[~andy/gtk] / gtk / a11y / gtkcontainercellaccessible.c
1 /* GTK+ - accessibility implementations
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 #include "gtkcellaccessibleprivate.h"
23
24 struct _GtkContainerCellAccessiblePrivate
25 {
26   GList *children;
27   gint n_children;
28 };
29
30 G_DEFINE_TYPE (GtkContainerCellAccessible, gtk_container_cell_accessible, GTK_TYPE_CELL_ACCESSIBLE)
31
32
33 static void
34 gtk_container_cell_accessible_finalize (GObject *obj)
35 {
36   GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (obj);
37
38   g_list_free_full (container->priv->children, g_object_unref);
39
40   G_OBJECT_CLASS (gtk_container_cell_accessible_parent_class)->finalize (obj);
41 }
42
43
44 static gint
45 gtk_container_cell_accessible_get_n_children (AtkObject *obj)
46 {
47   GtkContainerCellAccessible *cell = GTK_CONTAINER_CELL_ACCESSIBLE (obj);
48
49   return cell->priv->n_children;
50 }
51
52 static AtkObject *
53 gtk_container_cell_accessible_ref_child (AtkObject *obj,
54                                          gint       child)
55 {
56   GtkContainerCellAccessible *cell = GTK_CONTAINER_CELL_ACCESSIBLE (obj);
57   GList *l;
58
59   l = g_list_nth (cell->priv->children, child);
60   if (l == NULL)
61     return NULL;
62
63   return g_object_ref (ATK_OBJECT (l->data));
64 }
65
66 static void
67 gtk_container_cell_accessible_update_cache (GtkCellAccessible *cell)
68 {
69   GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (cell);
70   GList *l;
71
72   for (l = container->priv->children; l; l = l->next)
73     _gtk_cell_accessible_update_cache (l->data);
74 }
75
76 static void
77 gtk_container_cell_widget_set (GtkAccessible *accessible)
78 {
79   GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (accessible);
80   GList *l;
81
82   for (l = container->priv->children; l; l = l->next)
83     gtk_accessible_set_widget (l->data, gtk_accessible_get_widget (accessible));
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->priv->children; l; l = l->next)
95     gtk_accessible_set_widget (l->data, NULL);
96
97   GTK_ACCESSIBLE_CLASS (gtk_container_cell_accessible_parent_class)->widget_unset (accessible);
98 }
99
100 static void
101 gtk_container_cell_accessible_class_init (GtkContainerCellAccessibleClass *klass)
102 {
103   GtkCellAccessibleClass *cell_class = GTK_CELL_ACCESSIBLE_CLASS (klass);
104   GtkAccessibleClass *accessible_class = GTK_ACCESSIBLE_CLASS (klass);
105   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
106   GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
107
108   g_object_class->finalize = gtk_container_cell_accessible_finalize;
109
110   class->get_n_children = gtk_container_cell_accessible_get_n_children;
111   class->ref_child = gtk_container_cell_accessible_ref_child;
112
113   accessible_class->widget_unset = gtk_container_cell_widget_set;
114   accessible_class->widget_unset = gtk_container_cell_widget_unset;
115
116   cell_class->update_cache = gtk_container_cell_accessible_update_cache;
117
118   g_type_class_add_private (g_object_class, sizeof (GtkContainerCellAccessiblePrivate));
119 }
120
121 static void
122 gtk_container_cell_accessible_init (GtkContainerCellAccessible *cell)
123 {
124   cell->priv = G_TYPE_INSTANCE_GET_PRIVATE (cell,
125                                             GTK_TYPE_CONTAINER_CELL_ACCESSIBLE,
126                                             GtkContainerCellAccessiblePrivate);
127 }
128
129 GtkContainerCellAccessible *
130 gtk_container_cell_accessible_new (void)
131 {
132   GObject *object;
133
134   object = g_object_new (GTK_TYPE_CONTAINER_CELL_ACCESSIBLE, NULL);
135
136   ATK_OBJECT (object)->role = ATK_ROLE_TABLE_CELL;
137
138   return GTK_CONTAINER_CELL_ACCESSIBLE (object);
139 }
140
141 void
142 gtk_container_cell_accessible_add_child (GtkContainerCellAccessible *container,
143                                           GtkCellAccessible          *child)
144 {
145   g_return_if_fail (GTK_IS_CONTAINER_CELL_ACCESSIBLE (container));
146   g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (child));
147
148   container->priv->n_children++;
149   container->priv->children = g_list_append (container->priv->children, child);
150   atk_object_set_parent (ATK_OBJECT (child), ATK_OBJECT (container));
151 }
152
153 void
154 gtk_container_cell_accessible_remove_child (GtkContainerCellAccessible *container,
155                                              GtkCellAccessible          *child)
156 {
157   g_return_if_fail (GTK_IS_CONTAINER_CELL_ACCESSIBLE (container));
158   g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (child));
159   g_return_if_fail (container->priv->n_children > 0);
160
161   container->priv->children = g_list_remove (container->priv->children, child);
162   container->priv->n_children--;
163 }
164
165 GList *
166 gtk_container_cell_accessible_get_children (GtkContainerCellAccessible *container)
167 {
168   g_return_val_if_fail (GTK_IS_CONTAINER_CELL_ACCESSIBLE (container), NULL);
169
170   return container->priv->children;
171 }