2001-11-13 Michael Meeks <michael@ximian.com>
[platform/core/uifw/at-spi2-atk.git] / registryd / desktop.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001 Sun Microsystems Inc.
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 /*
24  * desktop.c: implements SpiDesktop.idl
25  *
26  */
27
28 /* #include <config.h> */
29 #include <libbonobo.h>
30
31 #include <stdio.h>
32
33 /*
34  * This pulls the CORBA definitions for the "Accessibility::Accessible" server
35  */
36 #include <libspi/Accessibility.h>
37
38 /*
39  * This pulls the definition for the BonoboObject (Gtk Type)
40  */
41 #include "desktop.h"
42
43 /*
44  * Our parent Gtk object type
45  */
46 #define PARENT_TYPE SPI_ACCESSIBLE_TYPE
47
48 /*
49  * A pointer to our parent object class
50  */
51 static SpiAccessibleClass *parent_class;
52
53 static void
54 spi_desktop_init (SpiDesktop  *desktop)
55 {
56   SPI_ACCESSIBLE (desktop)->atko = g_object_new (atk_object_get_type(), NULL);
57   desktop->applications = NULL;
58   atk_object_set_name (ATK_OBJECT (SPI_ACCESSIBLE (desktop)->atko), "main");
59 }
60
61 static CORBA_long
62 impl_desktop_get_child_count (PortableServer_Servant servant,
63                               CORBA_Environment * ev)
64 {
65   SpiDesktop *desktop = SPI_DESKTOP (bonobo_object_from_servant (servant));
66   if (desktop->applications)
67     {
68       return g_list_length (desktop->applications);
69     }
70   else
71     {
72       return 0;
73     }
74 }
75
76 static Accessibility_Accessible
77 impl_desktop_get_child_at_index (PortableServer_Servant servant,
78                                  const CORBA_long index,
79                                  CORBA_Environment * ev)
80 {
81   SpiDesktop *desktop = SPI_DESKTOP (bonobo_object_from_servant (servant));
82   CORBA_Object retval;
83   if ((desktop->applications) && (index < g_list_length (desktop->applications)))
84     {
85       fprintf (stderr, "getting application %ld\n", (long) index);
86       /* */
87       fprintf (stderr, "object address %p\n",
88                g_list_nth_data (desktop->applications, index));
89       retval =  CORBA_Object_duplicate (
90               (CORBA_Object) g_list_nth_data (desktop->applications, index), ev);
91     }
92   else
93     {
94       fprintf (stderr, "no %ldth child\n", (long) index);
95       retval = CORBA_OBJECT_NIL;
96     }
97   return (Accessibility_Accessible) retval;
98 }
99
100 static void
101 spi_desktop_class_init (SpiDesktopClass  *klass)
102 {
103         SpiAccessibleClass * spi_accessible_class = (SpiAccessibleClass *) klass;
104         POA_Accessibility_Accessible__epv *epv = &spi_accessible_class->epv;
105
106         parent_class = g_type_class_ref (SPI_ACCESSIBLE_TYPE);
107
108         epv->_get_childCount = impl_desktop_get_child_count;
109         epv->getChildAtIndex = impl_desktop_get_child_at_index;
110 }
111
112 GType
113 spi_desktop_get_type (void)
114 {
115         static GType type = 0;
116
117         if (!type) {
118                 static const GTypeInfo tinfo = {
119                         sizeof (SpiDesktopClass),
120                         (GBaseInitFunc) NULL,
121                         (GBaseFinalizeFunc) NULL,
122                         (GClassInitFunc) spi_desktop_class_init,
123                         (GClassFinalizeFunc) NULL,
124                         NULL, /* class data */
125                         sizeof (SpiDesktop),
126                         0, /* n preallocs */
127                         (GInstanceInitFunc) spi_desktop_init,
128                         NULL /* value table */
129                 };
130                 /*
131                  *   Here we use bonobo_type_unique instead of
132                  * gtk_type_unique, this auto-generates a load of
133                  * CORBA structures for us. All derived types must
134                  * use bonobo_type_unique.
135                  */
136                 type = bonobo_type_unique (
137                         PARENT_TYPE,
138                         POA_Accessibility_Desktop__init,
139                         NULL,
140                         G_STRUCT_OFFSET (SpiDesktopClass, epv),
141                         &tinfo,
142                         "SpiDesktop");
143         }
144
145         return type;
146 }
147
148 SpiDesktop *
149 spi_desktop_new (void)
150 {
151     SpiDesktop *retval =
152                SPI_DESKTOP (g_object_new (spi_desktop_get_type (), NULL));
153     return retval;
154 }