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>
31 /* SpiDesktop signals */
37 static guint spi_desktop_signals[LAST_SIGNAL];
40 /* Our parent Gtk object type */
41 #define PARENT_TYPE SPI_ACCESSIBLE_TYPE
45 Accessibility_Application ref;
48 /* A pointer to our parent object class */
49 static SpiAccessibleClass *parent_class;
52 spi_desktop_init (SpiDesktop *desktop)
54 spi_base_construct (SPI_BASE (desktop), g_object_new (ATK_TYPE_OBJECT, NULL));
56 desktop->applications = NULL;
57 bonobo_object_set_immortal (BONOBO_OBJECT (desktop), TRUE);
59 atk_object_set_name (ATK_OBJECT (SPI_BASE (desktop)->gobj), "main");
63 spi_desktop_dispose (GObject *object)
65 SpiDesktop *desktop = (SpiDesktop *) object;
67 while (desktop->applications)
69 Application *app = desktop->applications->data;
70 g_assert (app->ref != CORBA_OBJECT_NIL);
71 spi_desktop_remove_application (desktop, app->ref);
74 G_OBJECT_CLASS (parent_class)->dispose (object);
78 impl_desktop_get_child_count (PortableServer_Servant servant,
79 CORBA_Environment *ev)
81 SpiDesktop *desktop = SPI_DESKTOP (bonobo_object_from_servant (servant));
83 if (desktop->applications)
85 return g_list_length (desktop->applications);
93 static Accessibility_Accessible
94 impl_desktop_get_child_at_index (PortableServer_Servant servant,
95 const CORBA_long index,
96 CORBA_Environment *ev)
98 SpiDesktop *desktop = SPI_DESKTOP (bonobo_object_from_servant (servant));
102 app = g_list_nth_data (desktop->applications, index);
106 retval = bonobo_object_dup_ref (app->ref, ev);
109 retval = CORBA_OBJECT_NIL;
114 retval = CORBA_OBJECT_NIL;
117 return (Accessibility_Accessible) retval;
121 spi_desktop_class_init (SpiDesktopClass *klass)
123 GObjectClass * object_class = (GObjectClass *) klass;
124 SpiAccessibleClass * spi_accessible_class = (SpiAccessibleClass *) klass;
125 POA_Accessibility_Accessible__epv *epv = &spi_accessible_class->epv;
127 object_class->dispose = spi_desktop_dispose;
129 parent_class = g_type_class_ref (SPI_ACCESSIBLE_TYPE);
131 spi_desktop_signals[APPLICATION_ADDED] =
132 g_signal_new ("application_added",
133 G_TYPE_FROM_CLASS (klass),
135 G_STRUCT_OFFSET (SpiDesktopClass, application_added),
137 g_cclosure_marshal_VOID__UINT,
140 spi_desktop_signals[APPLICATION_REMOVED] =
141 g_signal_new ("application_removed",
142 G_TYPE_FROM_CLASS (klass),
144 G_STRUCT_OFFSET (SpiDesktopClass, application_removed),
146 g_cclosure_marshal_VOID__UINT,
149 epv->_get_childCount = impl_desktop_get_child_count;
150 epv->getChildAtIndex = impl_desktop_get_child_at_index;
153 BONOBO_TYPE_FUNC_FULL (SpiDesktop,
154 Accessibility_Desktop,
159 spi_desktop_new (void)
161 SpiDesktop *retval = g_object_new (SPI_DESKTOP_TYPE, NULL);
167 abnormal_application_termination (gpointer object, Application *app)
169 g_return_if_fail (SPI_IS_DESKTOP (app->desktop));
171 spi_desktop_remove_application (app->desktop, app->ref);
175 spi_desktop_add_application (SpiDesktop *desktop,
176 const Accessibility_Application application)
178 CORBA_Environment ev;
180 Accessibility_Application ref;
182 g_return_if_fail (SPI_IS_DESKTOP (desktop));
184 spi_desktop_remove_application (desktop, application);
186 CORBA_exception_init (&ev);
188 ref = bonobo_object_dup_ref (application, &ev);
190 if (!BONOBO_EX (&ev))
192 app = g_new (Application, 1);
193 app->desktop = desktop;
196 desktop->applications = g_list_append (desktop->applications, app);
198 ORBit_small_listen_for_broken (
199 app->ref, G_CALLBACK (abnormal_application_termination), app);
201 g_signal_emit (G_OBJECT (desktop),
202 spi_desktop_signals[APPLICATION_ADDED], 0,
203 g_list_index (desktop->applications, app));
206 CORBA_exception_free (&ev);
210 spi_desktop_remove_application (SpiDesktop *desktop,
211 const Accessibility_Application app_ref)
215 CORBA_Environment ev;
217 g_return_if_fail (app_ref != CORBA_OBJECT_NIL);
218 g_return_if_fail (SPI_IS_DESKTOP (desktop));
220 CORBA_exception_init (&ev);
223 for (l = desktop->applications; l; l = l->next)
225 Application *app = (Application *) l->data;
227 if (CORBA_Object_is_equivalent (app->ref, app_ref, &ev))
234 CORBA_exception_free (&ev);
238 Application *app = (Application *) l->data;
240 desktop->applications = g_list_delete_link (desktop->applications, l);
242 ORBit_small_unlisten_for_broken (app->ref, G_CALLBACK (abnormal_application_termination));
243 bonobo_object_release_unref (app->ref, NULL);
246 g_signal_emit (G_OBJECT (desktop), spi_desktop_signals[APPLICATION_REMOVED], 0, idx);