Merged Michael's branch back into HEAD, and fixed a number of reference counting...
[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 /* desktop.c: implements SpiDesktop.idl */
24
25 #include <config.h>
26 #include <stdio.h>
27 #include <libbonobo.h>
28 #include <libspi/desktop.h>
29
30 /* Our parent Gtk object type */
31 #define PARENT_TYPE SPI_ACCESSIBLE_TYPE
32
33 /* A pointer to our parent object class */
34 static SpiAccessibleClass *parent_class;
35
36 static void
37 spi_desktop_init (SpiDesktop  *desktop)
38 {
39   SPI_ACCESSIBLE (desktop)->atko = g_object_new (ATK_TYPE_OBJECT, NULL);
40   desktop->applications = NULL;
41   atk_object_set_name (ATK_OBJECT (SPI_ACCESSIBLE (desktop)->atko), "main");
42 }
43
44 static void
45 spi_desktop_finalize (GObject *object)
46 {
47   (G_OBJECT_CLASS (parent_class))->finalize (object); 
48 }
49
50 static CORBA_long
51 impl_desktop_get_child_count (PortableServer_Servant servant,
52                               CORBA_Environment * ev)
53 {
54   SpiDesktop *desktop = SPI_DESKTOP (bonobo_object_from_servant (servant));
55   if (desktop->applications)
56     {
57       return g_list_length (desktop->applications);
58     }
59   else
60     {
61       return 0;
62     }
63 }
64
65 static Accessibility_Accessible
66 impl_desktop_get_child_at_index (PortableServer_Servant servant,
67                                  const CORBA_long index,
68                                  CORBA_Environment * ev)
69 {
70   SpiDesktop *desktop = SPI_DESKTOP (bonobo_object_from_servant (servant));
71   CORBA_Object retval;
72   if ((desktop->applications) && (index < g_list_length (desktop->applications)))
73     {
74       fprintf (stderr, "getting application %ld\n", (long) index);
75       /* */
76       fprintf (stderr, "object address %p\n",
77                g_list_nth_data (desktop->applications, index));
78       retval =  bonobo_object_dup_ref (
79               (CORBA_Object) g_list_nth_data (desktop->applications, index), ev);
80     }
81   else
82     {
83       fprintf (stderr, "no %ldth child\n", (long) index);
84       retval = CORBA_OBJECT_NIL;
85     }
86   return (Accessibility_Accessible) retval;
87 }
88
89 static void
90 spi_desktop_class_init (SpiDesktopClass  *klass)
91 {
92         GObjectClass * object_class = (GObjectClass *) klass;
93         SpiAccessibleClass * spi_accessible_class = (SpiAccessibleClass *) klass;
94         POA_Accessibility_Accessible__epv *epv = &spi_accessible_class->epv;
95
96         object_class->finalize = spi_desktop_finalize;
97
98         parent_class = g_type_class_ref (SPI_ACCESSIBLE_TYPE);
99
100         epv->_get_childCount = impl_desktop_get_child_count;
101         epv->getChildAtIndex = impl_desktop_get_child_at_index;
102 }
103
104 BONOBO_TYPE_FUNC_FULL (SpiDesktop,
105                        Accessibility_Desktop,
106                        PARENT_TYPE,
107                        spi_desktop);
108
109 SpiDesktop *
110 spi_desktop_new (void)
111 {
112     SpiDesktop *retval = g_object_new (SPI_DESKTOP_TYPE, NULL);
113
114     return retval;
115 }