2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001 Sun Microsystems Inc., Ximian Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 /* desktop.c: implements SpiDesktop.idl */
27 #include <libbonobo.h>
30 /* SpiDesktop signals */
36 static guint spi_desktop_signals[LAST_SIGNAL];
39 /* Our parent Gtk object type */
40 #define PARENT_TYPE SPI_ACCESSIBLE_TYPE
44 Accessibility_Application ref;
47 /* A pointer to our parent object class */
48 static SpiAccessibleClass *parent_class;
51 spi_desktop_init (SpiDesktop *desktop)
53 spi_base_construct (SPI_BASE (desktop), g_object_new (ATK_TYPE_OBJECT, NULL));
55 desktop->applications = NULL;
56 bonobo_object_set_immortal (BONOBO_OBJECT (desktop), TRUE);
58 atk_object_set_name (ATK_OBJECT (SPI_BASE (desktop)->gobj), "main");
62 spi_desktop_dispose (GObject *object)
64 SpiDesktop *desktop = (SpiDesktop *) object;
66 while (desktop->applications)
68 Application *app = desktop->applications->data;
69 g_assert (app->ref != CORBA_OBJECT_NIL);
70 spi_desktop_remove_application (desktop, app->ref);
73 G_OBJECT_CLASS (parent_class)->dispose (object);
77 impl_desktop_get_child_count (PortableServer_Servant servant,
78 CORBA_Environment *ev)
80 SpiDesktop *desktop = SPI_DESKTOP (bonobo_object_from_servant (servant));
82 if (desktop->applications)
84 return g_list_length (desktop->applications);
92 static Accessibility_Accessible
93 impl_desktop_get_child_at_index (PortableServer_Servant servant,
94 const CORBA_long index,
95 CORBA_Environment *ev)
97 SpiDesktop *desktop = SPI_DESKTOP (bonobo_object_from_servant (servant));
101 app = g_list_nth_data (desktop->applications, index);
105 retval = bonobo_object_dup_ref (app->ref, ev);
108 retval = CORBA_OBJECT_NIL;
113 retval = CORBA_OBJECT_NIL;
116 return (Accessibility_Accessible) retval;
120 spi_desktop_class_init (SpiDesktopClass *klass)
122 GObjectClass * object_class = (GObjectClass *) klass;
123 SpiAccessibleClass * spi_accessible_class = (SpiAccessibleClass *) klass;
124 POA_Accessibility_Accessible__epv *epv = &spi_accessible_class->epv;
126 object_class->dispose = spi_desktop_dispose;
128 parent_class = g_type_class_ref (SPI_ACCESSIBLE_TYPE);
130 spi_desktop_signals[APPLICATION_ADDED] =
131 g_signal_new ("application_added",
132 G_TYPE_FROM_CLASS (klass),
134 G_STRUCT_OFFSET (SpiDesktopClass, application_added),
136 g_cclosure_marshal_VOID__UINT,
139 spi_desktop_signals[APPLICATION_REMOVED] =
140 g_signal_new ("application_removed",
141 G_TYPE_FROM_CLASS (klass),
143 G_STRUCT_OFFSET (SpiDesktopClass, application_removed),
145 g_cclosure_marshal_VOID__UINT,
148 epv->_get_childCount = impl_desktop_get_child_count;
149 epv->getChildAtIndex = impl_desktop_get_child_at_index;
152 BONOBO_TYPE_FUNC_FULL (SpiDesktop,
153 Accessibility_Desktop,
158 spi_desktop_new (void)
160 SpiDesktop *retval = g_object_new (SPI_DESKTOP_TYPE, NULL);
166 abnormal_application_termination (gpointer object, Application *app)
168 g_return_if_fail (SPI_IS_DESKTOP (app->desktop));
170 spi_desktop_remove_application (app->desktop, app->ref);
174 spi_desktop_add_application (SpiDesktop *desktop,
175 const Accessibility_Application application)
177 CORBA_Environment ev;
179 Accessibility_Application ref;
181 g_return_if_fail (SPI_IS_DESKTOP (desktop));
183 spi_desktop_remove_application (desktop, application);
185 CORBA_exception_init (&ev);
187 ref = bonobo_object_dup_ref (application, &ev);
189 if (!BONOBO_EX (&ev))
191 app = g_new (Application, 1);
192 app->desktop = desktop;
195 desktop->applications = g_list_append (desktop->applications, app);
197 ORBit_small_listen_for_broken (
198 app->ref, G_CALLBACK (abnormal_application_termination), app);
200 g_signal_emit (G_OBJECT (desktop),
201 spi_desktop_signals[APPLICATION_ADDED], 0,
202 g_list_index (desktop->applications, app));
205 CORBA_exception_free (&ev);
209 spi_desktop_remove_application (SpiDesktop *desktop,
210 const Accessibility_Application app_ref)
214 CORBA_Environment ev;
216 g_return_if_fail (app_ref != CORBA_OBJECT_NIL);
217 g_return_if_fail (SPI_IS_DESKTOP (desktop));
219 CORBA_exception_init (&ev);
222 for (l = desktop->applications; l; l = l->next)
224 Application *app = (Application *) l->data;
226 if (CORBA_Object_is_equivalent (app->ref, app_ref, &ev))
233 CORBA_exception_free (&ev);
237 Application *app = (Application *) l->data;
239 desktop->applications = g_list_delete_link (desktop->applications, l);
241 ORBit_small_unlisten_for_broken (app->ref, G_CALLBACK (abnormal_application_termination));
242 bonobo_object_release_unref (app->ref, NULL);
245 g_signal_emit (G_OBJECT (desktop), spi_desktop_signals[APPLICATION_REMOVED], 0, idx);