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>
28 #include <libspi/desktop.h>
30 /* Our parent Gtk object type */
31 #define PARENT_TYPE SPI_ACCESSIBLE_TYPE
35 Accessibility_Application ref;
38 /* A pointer to our parent object class */
39 static SpiAccessibleClass *parent_class;
42 spi_desktop_init (SpiDesktop *desktop)
44 spi_base_construct_default (SPI_BASE (desktop));
46 desktop->applications = NULL;
48 atk_object_set_name (SPI_BASE (desktop)->atko, "main");
52 spi_desktop_dispose (GObject *object)
54 SpiDesktop *desktop = (SpiDesktop *) object;
56 while (desktop->applications)
58 Application *app = (Application *) desktop->applications;
59 spi_desktop_remove_application (desktop, app->ref);
62 G_OBJECT_CLASS (parent_class)->dispose (object);
66 impl_desktop_get_child_count (PortableServer_Servant servant,
67 CORBA_Environment *ev)
69 SpiDesktop *desktop = SPI_DESKTOP (bonobo_object_from_servant (servant));
71 if (desktop->applications)
73 return g_list_length (desktop->applications);
81 static Accessibility_Accessible
82 impl_desktop_get_child_at_index (PortableServer_Servant servant,
83 const CORBA_long index,
84 CORBA_Environment *ev)
86 SpiDesktop *desktop = SPI_DESKTOP (bonobo_object_from_servant (servant));
90 app = g_list_nth_data (desktop->applications, index);
94 retval = bonobo_object_dup_ref (app->ref, ev);
97 retval = CORBA_OBJECT_NIL;
102 retval = CORBA_OBJECT_NIL;
105 return (Accessibility_Accessible) retval;
109 spi_desktop_class_init (SpiDesktopClass *klass)
111 GObjectClass * object_class = (GObjectClass *) klass;
112 SpiAccessibleClass * spi_accessible_class = (SpiAccessibleClass *) klass;
113 POA_Accessibility_Accessible__epv *epv = &spi_accessible_class->epv;
115 object_class->dispose = spi_desktop_dispose;
117 parent_class = g_type_class_ref (SPI_ACCESSIBLE_TYPE);
119 epv->_get_childCount = impl_desktop_get_child_count;
120 epv->getChildAtIndex = impl_desktop_get_child_at_index;
123 BONOBO_TYPE_FUNC_FULL (SpiDesktop,
124 Accessibility_Desktop,
129 spi_desktop_new (void)
131 SpiDesktop *retval = g_object_new (SPI_DESKTOP_TYPE, NULL);
137 abnormal_application_termination (gpointer object, Application *app)
139 g_return_if_fail (SPI_IS_DESKTOP (app->desktop));
141 spi_desktop_remove_application (app->desktop, app->ref);
145 spi_desktop_add_application (SpiDesktop *desktop,
146 const Accessibility_Application application)
148 CORBA_Environment ev;
150 Accessibility_Application ref;
152 g_return_if_fail (SPI_IS_DESKTOP (desktop));
154 spi_desktop_remove_application (desktop, application);
156 CORBA_exception_init (&ev);
158 ref = bonobo_object_dup_ref (application, &ev);
160 if (!BONOBO_EX (&ev))
162 app = g_new (Application, 1);
163 app->desktop = desktop;
166 desktop->applications = g_list_append (desktop->applications, app);
168 ORBit_small_listen_for_broken (app->ref, G_CALLBACK (abnormal_application_termination), app);
171 CORBA_exception_free (&ev);
175 spi_desktop_remove_application (SpiDesktop *desktop,
176 const Accessibility_Application app_ref)
179 CORBA_Environment ev;
181 g_return_if_fail (SPI_IS_DESKTOP (desktop));
183 CORBA_exception_init (&ev);
185 for (l = desktop->applications; l; l = l->next)
187 Application *app = (Application *) l->data;
189 if (CORBA_Object_is_equivalent (app->ref, app_ref, &ev))
195 CORBA_exception_free (&ev);
199 Application *app = (Application *) l->data;
201 desktop->applications = g_list_delete_link (desktop->applications, l);
203 ORBit_small_unlisten_for_broken (app->ref, G_CALLBACK (abnormal_application_termination));
204 bonobo_object_release_unref (app->ref, NULL);