X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git;a=blobdiff_plain;f=registryd%2Fdesktop.c;h=dec848740c0147d82748ef691f2b7c6e6da856c2;hp=86cb45b4a4d7e8a3d10a93eaf9296af76d52a4df;hb=d35cd400a36b0f1393c17ce47015bf753327ccae;hpb=66c4375c7cd9a0a01e79f562e1bb0326fc4dcd21 diff --git a/registryd/desktop.c b/registryd/desktop.c index 86cb45b..dec8487 100644 --- a/registryd/desktop.c +++ b/registryd/desktop.c @@ -2,7 +2,7 @@ * AT-SPI - Assistive Technology Service Provider Interface * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) * - * Copyright 2001 Sun Microsystems Inc. + * Copyright 2001 Sun Microsystems Inc., Ximian Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -20,49 +20,54 @@ * Boston, MA 02111-1307, USA. */ -/* - * desktop.c: implements SpiDesktop.idl - * - */ - -/* #include */ -#include +/* desktop.c: implements SpiDesktop.idl */ +#include #include +#include +#include -/* - * This pulls the CORBA definitions for the "Accessibility::Accessible" server - */ -#include - -/* - * This pulls the definition for the BonoboObject (Gtk Type) - */ -#include "desktop.h" - -/* - * Our parent Gtk object type - */ +/* Our parent Gtk object type */ #define PARENT_TYPE SPI_ACCESSIBLE_TYPE -/* - * A pointer to our parent object class - */ +typedef struct { + SpiDesktop *desktop; + Accessibility_Application ref; +} Application; + +/* A pointer to our parent object class */ static SpiAccessibleClass *parent_class; static void -spi_desktop_init (SpiDesktop *desktop) +spi_desktop_init (SpiDesktop *desktop) { - SPI_ACCESSIBLE (desktop)->atko = g_object_new (atk_object_get_type(), NULL); + spi_base_construct_default (SPI_BASE (desktop)); + desktop->applications = NULL; - atk_object_set_name (ATK_OBJECT (SPI_ACCESSIBLE (desktop)->atko), "main"); + + atk_object_set_name (SPI_BASE (desktop)->atko, "main"); +} + +static void +spi_desktop_dispose (GObject *object) +{ + SpiDesktop *desktop = (SpiDesktop *) object; + + while (desktop->applications) + { + Application *app = (Application *) desktop->applications; + spi_desktop_remove_application (desktop, app->ref); + } + + G_OBJECT_CLASS (parent_class)->dispose (object); } static CORBA_long impl_desktop_get_child_count (PortableServer_Servant servant, - CORBA_Environment * ev) + CORBA_Environment *ev) { SpiDesktop *desktop = SPI_DESKTOP (bonobo_object_from_servant (servant)); + if (desktop->applications) { return g_list_length (desktop->applications); @@ -75,80 +80,128 @@ impl_desktop_get_child_count (PortableServer_Servant servant, static Accessibility_Accessible impl_desktop_get_child_at_index (PortableServer_Servant servant, - const CORBA_long index, - CORBA_Environment * ev) + const CORBA_long index, + CORBA_Environment *ev) { - SpiDesktop *desktop = SPI_DESKTOP (bonobo_object_from_servant (servant)); + SpiDesktop *desktop = SPI_DESKTOP (bonobo_object_from_servant (servant)); CORBA_Object retval; - if ((desktop->applications) && (index < g_list_length (desktop->applications))) + Application *app; + + app = g_list_nth_data (desktop->applications, index); + + if (app) { - fprintf (stderr, "getting application %ld\n", (long) index); - /* */ - fprintf (stderr, "object address %p\n", - g_list_nth_data (desktop->applications, index)); - retval = CORBA_Object_duplicate ( - (CORBA_Object) g_list_nth_data (desktop->applications, index), ev); + retval = bonobo_object_dup_ref (app->ref, ev); + if (BONOBO_EX (ev)) + { + retval = CORBA_OBJECT_NIL; + } } else { - fprintf (stderr, "no %ldth child\n", (long) index); retval = CORBA_OBJECT_NIL; } + return (Accessibility_Accessible) retval; } static void -spi_desktop_class_init (SpiDesktopClass *klass) +spi_desktop_class_init (SpiDesktopClass *klass) { - SpiAccessibleClass * spi_accessible_class = (SpiAccessibleClass *) klass; - POA_Accessibility_Accessible__epv *epv = &spi_accessible_class->epv; + GObjectClass * object_class = (GObjectClass *) klass; + SpiAccessibleClass * spi_accessible_class = (SpiAccessibleClass *) klass; + POA_Accessibility_Accessible__epv *epv = &spi_accessible_class->epv; - parent_class = g_type_class_ref (SPI_ACCESSIBLE_TYPE); + object_class->dispose = spi_desktop_dispose; + + parent_class = g_type_class_ref (SPI_ACCESSIBLE_TYPE); - epv->_get_childCount = impl_desktop_get_child_count; - epv->getChildAtIndex = impl_desktop_get_child_at_index; + epv->_get_childCount = impl_desktop_get_child_count; + epv->getChildAtIndex = impl_desktop_get_child_at_index; } -GType -spi_desktop_get_type (void) -{ - static GType type = 0; - - if (!type) { - static const GTypeInfo tinfo = { - sizeof (SpiDesktopClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) spi_desktop_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class data */ - sizeof (SpiDesktop), - 0, /* n preallocs */ - (GInstanceInitFunc) spi_desktop_init, - NULL /* value table */ - }; - /* - * Here we use bonobo_type_unique instead of - * gtk_type_unique, this auto-generates a load of - * CORBA structures for us. All derived types must - * use bonobo_type_unique. - */ - type = bonobo_type_unique ( - PARENT_TYPE, - POA_Accessibility_Desktop__init, - NULL, - G_STRUCT_OFFSET (SpiDesktopClass, epv), - &tinfo, - "SpiDesktop"); - } - - return type; -} +BONOBO_TYPE_FUNC_FULL (SpiDesktop, + Accessibility_Desktop, + PARENT_TYPE, + spi_desktop); SpiDesktop * spi_desktop_new (void) { - SpiDesktop *retval = - SPI_DESKTOP (g_object_new (spi_desktop_get_type (), NULL)); - return retval; + SpiDesktop *retval = g_object_new (SPI_DESKTOP_TYPE, NULL); + + return retval; +} + +static void +abnormal_application_termination (gpointer object, Application *app) +{ + g_return_if_fail (SPI_IS_DESKTOP (app->desktop)); + + spi_desktop_remove_application (app->desktop, app->ref); +} + +void +spi_desktop_add_application (SpiDesktop *desktop, + const Accessibility_Application application) +{ + CORBA_Environment ev; + Application *app; + Accessibility_Application ref; + + g_return_if_fail (SPI_IS_DESKTOP (desktop)); + + spi_desktop_remove_application (desktop, application); + + CORBA_exception_init (&ev); + + ref = bonobo_object_dup_ref (application, &ev); + + if (!BONOBO_EX (&ev)) + { + app = g_new (Application, 1); + app->desktop = desktop; + app->ref = ref; + + desktop->applications = g_list_append (desktop->applications, app); + + ORBit_small_listen_for_broken (app->ref, G_CALLBACK (abnormal_application_termination), app); + } + + CORBA_exception_free (&ev); +} + +void +spi_desktop_remove_application (SpiDesktop *desktop, + const Accessibility_Application app_ref) +{ + GList *l; + CORBA_Environment ev; + + g_return_if_fail (SPI_IS_DESKTOP (desktop)); + + CORBA_exception_init (&ev); + + for (l = desktop->applications; l; l = l->next) + { + Application *app = (Application *) l->data; + + if (CORBA_Object_is_equivalent (app->ref, app_ref, &ev)) + { + break; + } + } + + CORBA_exception_free (&ev); + + if (l) + { + Application *app = (Application *) l->data; + + desktop->applications = g_list_delete_link (desktop->applications, l); + + ORBit_small_unlisten_for_broken (app->ref, G_CALLBACK (abnormal_application_termination)); + bonobo_object_release_unref (app->ref, NULL); + g_free (app); + } }