2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc., Ximian Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 /* desktop.c: implements SpiDesktop.idl */
28 #include <libbonobo.h>
30 #include <atk/atkcomponent.h>
31 #include <gdk/gdkscreen.h>
34 /* SpiDesktop signals */
40 static guint spi_desktop_signals[LAST_SIGNAL];
43 /* Our parent Gtk object type */
44 #define PARENT_TYPE SPI_ACCESSIBLE_TYPE
48 Accessibility_Application ref;
51 /* A pointer to our parent object class */
52 static SpiAccessibleClass *parent_class;
54 #define SPI_TYPE_ATK_DESKTOP (spi_atk_desktop_get_type ())
55 #define SPI_ATK_DESKTOP(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), SPI_TYPE_ATK_DESKTOP, SpiAtkDesktop))
56 #define SPI_IS_ATK_DESKTOP(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), SPI_TYPE_ATK_DESKTOP))
65 AtkObjectClass parent;
68 static void spi_atk_desktop_init (SpiAtkDesktop *desktop);
69 static void atk_component_interface_init (AtkComponentIface *iface);
70 static void spi_atk_desktop_get_extents (AtkComponent *component,
75 AtkCoordType coord_type);
78 spi_atk_desktop_get_type ()
80 static GType type = 0;
84 static const GTypeInfo typeInfo =
86 sizeof (SpiAtkDesktopClass),
88 (GBaseFinalizeFunc) NULL,
89 (GClassInitFunc) NULL,
90 (GClassFinalizeFunc) NULL,
92 sizeof (SpiAtkDesktop),
94 (GInstanceInitFunc) spi_atk_desktop_init,
96 static const GInterfaceInfo atk_component_info =
98 (GInterfaceInitFunc) atk_component_interface_init,
99 (GInterfaceFinalizeFunc) NULL,
103 type = g_type_register_static (ATK_TYPE_OBJECT,
104 "SpiAtkDesktop", &typeInfo, 0);
105 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
106 &atk_component_info);
112 spi_atk_desktop_init (SpiAtkDesktop *desktop)
116 atk_object_set_name (ATK_OBJECT (desktop), "main");
117 display = gdk_x11_lookup_xdisplay (GDK_DISPLAY ());
118 desktop->screen = gdk_display_get_default_screen (display);
122 atk_component_interface_init (AtkComponentIface *iface)
124 g_return_if_fail (iface != NULL);
126 iface->get_extents = spi_atk_desktop_get_extents;
130 spi_atk_desktop_get_extents (AtkComponent *component,
135 AtkCoordType coord_type)
137 SpiAtkDesktop *desktop;
139 g_return_if_fail (SPI_IS_ATK_DESKTOP (component));
140 desktop = SPI_ATK_DESKTOP (component);
143 *width = gdk_screen_get_width (desktop->screen);
144 *height = gdk_screen_get_height (desktop->screen);
148 spi_desktop_init (SpiDesktop *desktop)
150 desktop->applications = NULL;
151 bonobo_object_set_immortal (BONOBO_OBJECT (desktop), TRUE);
155 spi_desktop_dispose (GObject *object)
157 SpiDesktop *desktop = (SpiDesktop *) object;
159 while (desktop->applications)
161 Application *app = desktop->applications->data;
162 g_assert (app->ref != CORBA_OBJECT_NIL);
163 spi_desktop_remove_application (desktop, app->ref);
166 G_OBJECT_CLASS (parent_class)->dispose (object);
170 impl_desktop_get_child_count (PortableServer_Servant servant,
171 CORBA_Environment *ev)
173 SpiDesktop *desktop = SPI_DESKTOP (bonobo_object_from_servant (servant));
175 if (desktop->applications)
177 return g_list_length (desktop->applications);
185 static Accessibility_Accessible
186 impl_desktop_get_child_at_index (PortableServer_Servant servant,
187 const CORBA_long index,
188 CORBA_Environment *ev)
190 SpiDesktop *desktop = SPI_DESKTOP (bonobo_object_from_servant (servant));
194 app = g_list_nth_data (desktop->applications, index);
198 retval = bonobo_object_dup_ref (app->ref, ev);
201 retval = CORBA_OBJECT_NIL;
206 retval = CORBA_OBJECT_NIL;
209 return (Accessibility_Accessible) retval;
213 spi_desktop_class_init (SpiDesktopClass *klass)
215 GObjectClass * object_class = (GObjectClass *) klass;
216 SpiAccessibleClass * spi_accessible_class = (SpiAccessibleClass *) klass;
217 POA_Accessibility_Accessible__epv *epv = &spi_accessible_class->epv;
219 object_class->dispose = spi_desktop_dispose;
221 parent_class = g_type_class_ref (SPI_ACCESSIBLE_TYPE);
223 spi_desktop_signals[APPLICATION_ADDED] =
224 g_signal_new ("application_added",
225 G_TYPE_FROM_CLASS (klass),
227 G_STRUCT_OFFSET (SpiDesktopClass, application_added),
229 g_cclosure_marshal_VOID__UINT,
232 spi_desktop_signals[APPLICATION_REMOVED] =
233 g_signal_new ("application_removed",
234 G_TYPE_FROM_CLASS (klass),
236 G_STRUCT_OFFSET (SpiDesktopClass, application_removed),
238 g_cclosure_marshal_VOID__UINT,
241 epv->_get_childCount = impl_desktop_get_child_count;
242 epv->getChildAtIndex = impl_desktop_get_child_at_index;
245 BONOBO_TYPE_FUNC_FULL (SpiDesktop,
246 Accessibility_Desktop,
251 spi_desktop_new (void)
254 SpiAccessible *accessible;
256 accessible = spi_accessible_construct (SPI_DESKTOP_TYPE, g_object_new (SPI_TYPE_ATK_DESKTOP, NULL));
257 g_assert (SPI_IS_DESKTOP (accessible));
258 desktop = SPI_DESKTOP (accessible);
264 abnormal_application_termination (gpointer object, Application *app)
266 g_return_if_fail (SPI_IS_DESKTOP (app->desktop));
268 spi_desktop_remove_application (app->desktop, app->ref);
272 spi_desktop_add_application (SpiDesktop *desktop,
273 const Accessibility_Application application)
275 CORBA_Environment ev;
277 Accessibility_Application ref;
279 g_return_if_fail (SPI_IS_DESKTOP (desktop));
281 spi_desktop_remove_application (desktop, application);
283 CORBA_exception_init (&ev);
285 ref = bonobo_object_dup_ref (application, &ev);
287 if (!BONOBO_EX (&ev))
289 app = g_new (Application, 1);
290 app->desktop = desktop;
293 desktop->applications = g_list_append (desktop->applications, app);
295 ORBit_small_listen_for_broken (
296 app->ref, G_CALLBACK (abnormal_application_termination), app);
298 g_signal_emit (G_OBJECT (desktop),
299 spi_desktop_signals[APPLICATION_ADDED], 0,
300 g_list_index (desktop->applications, app));
303 CORBA_exception_free (&ev);
307 spi_desktop_remove_application (SpiDesktop *desktop,
308 const Accessibility_Application app_ref)
312 CORBA_Environment ev;
314 g_return_if_fail (app_ref != CORBA_OBJECT_NIL);
315 g_return_if_fail (SPI_IS_DESKTOP (desktop));
317 CORBA_exception_init (&ev);
320 for (l = desktop->applications; l; l = l->next)
322 Application *app = (Application *) l->data;
324 if (CORBA_Object_is_equivalent (app->ref, app_ref, &ev))
331 CORBA_exception_free (&ev);
335 Application *app = (Application *) l->data;
337 desktop->applications = g_list_delete_link (desktop->applications, l);
339 ORBit_small_unlisten_for_broken (app->ref, G_CALLBACK (abnormal_application_termination));
340 bonobo_object_release_unref (app->ref, NULL);
343 g_signal_emit (G_OBJECT (desktop), spi_desktop_signals[APPLICATION_REMOVED], 0, idx);