idl/Registry.idl : temporarily changed register_Application
[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 Desktop.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 ACCESSIBLE_TYPE
47
48 /*
49  * A pointer to our parent object class
50  */
51 static AccessibleClass *parent_class;
52
53 static void
54 desktop_init (Desktop  *desktop)
55 {
56   ACCESSIBLE (desktop)->atko = g_object_new (atk_object_get_type(), NULL);
57   atk_object_set_name (ATK_OBJECT (ACCESSIBLE (desktop)->atko), "main");
58 }
59
60 static CORBA_long
61 impl_desktop_get_child_count (PortableServer_Servant servant,
62                               CORBA_Environment * ev)
63 {
64   Desktop *desktop = DESKTOP (bonobo_object_from_servant (servant));
65   if (desktop->applications)
66     {
67       return g_list_length (desktop->applications);
68     }
69   else
70     {
71       return 0;
72     }
73 }
74
75 static Accessibility_Accessible
76 impl_desktop_get_child_at_index (PortableServer_Servant servant,
77                                  const CORBA_long index,
78                                  CORBA_Environment * ev)
79 {
80   Desktop *desktop = DESKTOP (bonobo_object_from_servant (servant));
81   CORBA_Object retval;
82   if ((desktop->applications) && (index < g_list_length (desktop->applications)))
83     {
84       fprintf (stderr, "getting application %ld\n", (long) index);
85       /* */
86       fprintf (stderr, "object address %p\n",
87                g_list_nth_data (desktop->applications, index));
88       retval =  CORBA_Object_duplicate (
89               (CORBA_Object) g_list_nth_data (desktop->applications, index), ev);
90     }
91   else
92     {
93       fprintf (stderr, "no %ldth child\n", (long) index);
94       retval = CORBA_OBJECT_NIL;
95     }
96   return (Accessibility_Accessible) retval;
97 }
98
99 static void
100 desktop_class_init (DesktopClass  *klass)
101 {
102         AccessibleClass * accessible_class = (AccessibleClass *) klass;
103         POA_Accessibility_Accessible__epv *epv = &accessible_class->epv;
104
105         parent_class = g_type_class_ref (ACCESSIBLE_TYPE);
106
107         epv->_get_childCount = impl_desktop_get_child_count;
108         epv->getChildAtIndex = impl_desktop_get_child_at_index;
109 }
110
111 GType
112 desktop_get_type (void)
113 {
114         static GType type = 0;
115
116         if (!type) {
117                 static const GTypeInfo tinfo = {
118                         sizeof (DesktopClass),
119                         (GBaseInitFunc) NULL,
120                         (GBaseFinalizeFunc) NULL,
121                         (GClassInitFunc) desktop_class_init,
122                         (GClassFinalizeFunc) NULL,
123                         NULL, /* class data */
124                         sizeof (Desktop),
125                         0, /* n preallocs */
126                         (GInstanceInitFunc) desktop_init,
127                         NULL /* value table */
128                 };
129                 /*
130                  *   Here we use bonobo_type_unique instead of
131                  * gtk_type_unique, this auto-generates a load of
132                  * CORBA structures for us. All derived types must
133                  * use bonobo_type_unique.
134                  */
135                 type = bonobo_type_unique (
136                         PARENT_TYPE,
137                         POA_Accessibility_Desktop__init,
138                         NULL,
139                         G_STRUCT_OFFSET (DesktopClass, epv),
140                         &tinfo,
141                         "Desktop");
142         }
143
144         return type;
145 }
146
147 Desktop *
148 desktop_new (void)
149 {
150     Desktop *retval =
151                DESKTOP (g_object_new (desktop_get_type (), NULL));
152     return retval;
153 }