No issues found
1 /* GAIL - The GNOME Accessibility Implementation Library
2 * Copyright 2001, 2002, 2003 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 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <gtk/gtk.h>
25 #include <libgnomecanvas/gnome-canvas.h>
26 #include <libgnomecanvas/gnome-canvas-text.h>
27 #include <libgnomecanvas/gnome-canvas-widget.h>
28 #include "gailcanvas.h"
29 #include "gailcanvasitem.h"
30 #include "gailcanvasgroupfactory.h"
31 #include "gailcanvastextfactory.h"
32 #include "gailcanvasitemfactory.h"
33 #include "gailcanvaswidgetfactory.h"
34
35 static void gail_canvas_class_init (GailCanvasClass *klass);
36 static void gail_canvas_real_initialize (AtkObject *obj,
37 gpointer data);
38
39 static gint gail_canvas_get_n_children (AtkObject *obj);
40 static AtkObject * gail_canvas_ref_child (AtkObject *obj,
41 gint i);
42
43 static void adjustment_changed (GtkAdjustment *adjustment,
44 GnomeCanvas *canvas);
45
46 static AtkObject * gail_canvas_factory_create_accessible (GObject *obj);
47
48 static GType gail_canvas_factory_get_accessible_type (void);
49
50 G_DEFINE_TYPE (GailCanvasFactory,
51 gail_canvas_factory,
52 ATK_TYPE_OBJECT_FACTORY);
53
54 static void
55 gail_canvas_factory_init (GailCanvasFactory *foo)
56 {
57 ;
58 }
59
60 static void
61 gail_canvas_factory_class_init (GailCanvasFactoryClass *klass)
62 {
63 AtkObjectFactoryClass *class = ATK_OBJECT_FACTORY_CLASS (klass);
64
65 class->create_accessible = gail_canvas_factory_create_accessible;
66 class->get_accessible_type = gail_canvas_factory_get_accessible_type;
67 }
68
69 static AtkObject *
70 gail_canvas_factory_create_accessible (GObject *obj)
71 {
72 return gail_canvas_new (GTK_WIDGET (obj));
73 }
74
75 static GType
76 gail_canvas_factory_get_accessible_type (void)
77 {
78 return GAIL_TYPE_CANVAS;
79 }
80
81 GType
82 gail_canvas_get_type (void)
83 {
84 static GType type = 0;
85
86 if (!type)
87 {
88 GType parent_type = g_type_parent (GNOME_TYPE_CANVAS);
89 AtkObjectFactory *factory = atk_registry_get_factory (
90 atk_get_default_registry (),
91 parent_type);
92 GType atkobject_parent_type = atk_object_factory_get_accessible_type (factory);
93 GTypeQuery query;
94 static GTypeInfo tinfo =
95 {
96 0, /* class size */
97 (GBaseInitFunc) NULL, /* base init */
98 (GBaseFinalizeFunc) NULL, /* base finalize */
99 (GClassInitFunc) gail_canvas_class_init, /* class init */
100 (GClassFinalizeFunc) NULL, /* class finalize */
101 NULL, /* class data */
102 0, /* instance size */
103 0, /* nb preallocs */
104 (GInstanceInitFunc) NULL, /* instance init */
105 NULL /* value table */
106 };
107 g_type_query (atkobject_parent_type, &query);
108 tinfo.class_size = query.class_size;
109 tinfo.instance_size = query.instance_size;
110
111 /* use the size obtained from the parent type factory */
112 type = g_type_register_static (atkobject_parent_type,
113 "GailCanvas", &tinfo, 0);
114 }
115
116 return type;
117 }
118
119 static AtkObjectClass *parent_atk_object_class;
120
121 /**
122 * Tell ATK how to create the appropriate AtkObject peers
123 **/
124 void
125 gail_canvas_init (void)
126 {
127 atk_registry_set_factory_type (atk_get_default_registry (),
128 GNOME_TYPE_CANVAS,
129 gail_canvas_factory_get_type ());
130 atk_registry_set_factory_type (atk_get_default_registry (),
131 GNOME_TYPE_CANVAS_GROUP,
132 gail_canvas_group_factory_get_type ());
133 atk_registry_set_factory_type (atk_get_default_registry (),
134 GNOME_TYPE_CANVAS_TEXT,
135 gail_canvas_text_factory_get_type ());
136 atk_registry_set_factory_type (atk_get_default_registry (),
137 GNOME_TYPE_CANVAS_WIDGET,
138 gail_canvas_widget_factory_get_type ());
139 atk_registry_set_factory_type (atk_get_default_registry (),
140 GNOME_TYPE_CANVAS_ITEM,
141 gail_canvas_item_factory_get_type ());
142 }
143
144 static void
145 gail_canvas_class_init (GailCanvasClass *klass)
146 {
147 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
148 parent_atk_object_class = g_type_class_peek_parent (klass);
149
150 class->get_n_children = gail_canvas_get_n_children;
151 class->ref_child = gail_canvas_ref_child;
152 class->initialize = gail_canvas_real_initialize;
153 }
154
155 AtkObject *
156 gail_canvas_new (GtkWidget *widget)
157 {
158 GObject *object;
159 AtkObject *accessible;
160
161 g_return_val_if_fail (GNOME_IS_CANVAS (widget), NULL);
162
163 object = g_object_new (GAIL_TYPE_CANVAS, NULL);
164
165 accessible = ATK_OBJECT (object);
166 atk_object_initialize (accessible, widget);
167
168 return accessible;
169 }
170
171 static void
172 gail_canvas_real_initialize (AtkObject *obj,
173 gpointer data)
174 {
175 GnomeCanvas *canvas;
176 GtkAdjustment *adj;
177
178 parent_atk_object_class->initialize (obj, data);
179
180 canvas = GNOME_CANVAS (data);
181
182 adj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
183 g_signal_connect (
184 adj, "value_changed",
185 G_CALLBACK (adjustment_changed), canvas);
186
187 adj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
188 g_signal_connect (
189 adj, "value_changed",
190 G_CALLBACK (adjustment_changed), canvas);
191
192 obj->role = ATK_ROLE_LAYERED_PANE;
193 }
194
195 static gint
196 gail_canvas_get_n_children (AtkObject *obj)
197 {
198 GtkAccessible *accessible;
199 GtkWidget *widget;
200 GnomeCanvas *canvas;
201 GnomeCanvasGroup *root_group;
202
203 g_return_val_if_fail (GAIL_IS_CANVAS (obj), 0);
204
205 accessible = GTK_ACCESSIBLE (obj);
206 widget = gtk_accessible_get_widget (accessible);
207 if (widget == NULL)
208 /* State is defunct */
209 return 0;
210
211 g_return_val_if_fail (GNOME_IS_CANVAS (widget), 0);
212
213 canvas = GNOME_CANVAS (widget);
214 root_group = gnome_canvas_root (canvas);
215 g_return_val_if_fail (root_group, 0);
216 return 1;
217 }
218
219 static AtkObject *
220 gail_canvas_ref_child (AtkObject *obj,
221 gint i)
222 {
223 GtkAccessible *accessible;
224 GtkWidget *widget;
225 GnomeCanvas *canvas;
226 GnomeCanvasGroup *root_group;
227 AtkObject *atk_object;
228
229 /* Canvas only has one child, so return NULL if anything else is requested */
230 if (i != 0)
231 return NULL;
232 g_return_val_if_fail (GAIL_IS_CANVAS (obj), NULL);
233
234 accessible = GTK_ACCESSIBLE (obj);
235 widget = gtk_accessible_get_widget (accessible);
236 if (widget == NULL)
237 /* State is defunct */
238 return NULL;
239 g_return_val_if_fail (GNOME_IS_CANVAS (widget), NULL);
240
241 canvas = GNOME_CANVAS (widget);
242 root_group = gnome_canvas_root (canvas);
243 g_return_val_if_fail (root_group, NULL);
244
245 atk_object = atk_gobject_accessible_for_object (G_OBJECT (root_group));
246 g_object_ref (atk_object);
247 return atk_object;
248 }
249
250 static void
251 adjustment_changed (GtkAdjustment *adjustment,
252 GnomeCanvas *canvas)
253 {
254 AtkObject *atk_obj;
255
256 /*
257 * The scrollbars have changed
258 */
259 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (canvas));
260
261 g_signal_emit_by_name (atk_obj, "visible_data_changed");
262 }