2001-11-20 Michael Meeks <michael@ximian.com>
[platform/core/uifw/at-spi2-atk.git] / libspi / 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_object_get_type(), NULL);
40   desktop->applications = NULL;
41   atk_object_set_name (ATK_OBJECT (SPI_ACCESSIBLE (desktop)->atko), "main");
42 }
43
44 static CORBA_long
45 impl_desktop_get_child_count (PortableServer_Servant servant,
46                               CORBA_Environment * ev)
47 {
48   SpiDesktop *desktop = SPI_DESKTOP (bonobo_object_from_servant (servant));
49   if (desktop->applications)
50     {
51       return g_list_length (desktop->applications);
52     }
53   else
54     {
55       return 0;
56     }
57 }
58
59 static Accessibility_Accessible
60 impl_desktop_get_child_at_index (PortableServer_Servant servant,
61                                  const CORBA_long index,
62                                  CORBA_Environment * ev)
63 {
64   SpiDesktop *desktop = SPI_DESKTOP (bonobo_object_from_servant (servant));
65   CORBA_Object retval;
66   if ((desktop->applications) && (index < g_list_length (desktop->applications)))
67     {
68       fprintf (stderr, "getting application %ld\n", (long) index);
69       /* */
70       fprintf (stderr, "object address %p\n",
71                g_list_nth_data (desktop->applications, index));
72       retval =  CORBA_Object_duplicate (
73               (CORBA_Object) g_list_nth_data (desktop->applications, index), ev);
74     }
75   else
76     {
77       fprintf (stderr, "no %ldth child\n", (long) index);
78       retval = CORBA_OBJECT_NIL;
79     }
80   return (Accessibility_Accessible) retval;
81 }
82
83 static void
84 spi_desktop_class_init (SpiDesktopClass  *klass)
85 {
86         SpiAccessibleClass * spi_accessible_class = (SpiAccessibleClass *) klass;
87         POA_Accessibility_Accessible__epv *epv = &spi_accessible_class->epv;
88
89         parent_class = g_type_class_ref (SPI_ACCESSIBLE_TYPE);
90
91         epv->_get_childCount = impl_desktop_get_child_count;
92         epv->getChildAtIndex = impl_desktop_get_child_at_index;
93 }
94
95 BONOBO_TYPE_FUNC_FULL (SpiDesktop,
96                        Accessibility_Desktop,
97                        PARENT_TYPE,
98                        spi_desktop);
99
100 SpiDesktop *
101 spi_desktop_new (void)
102 {
103     SpiDesktop *retval = SPI_DESKTOP (g_object_new (SPI_DESKTOP_TYPE, NULL));
104
105     return retval;
106 }