Initial revision
[platform/core/uifw/at-spi2-atk.git] / libspi / desktop.c
1 /*
2  * desktop.c: implements Desktop.idl
3  *
4  */
5
6 /* #include <config.h> */
7 #include <libbonobo.h>
8
9 #include <stdio.h>
10
11 /*
12  * This pulls the CORBA definitions for the "Accessibility::Accessible" server
13  */
14 #include "Desktop.h"
15
16 /*
17  * This pulls the definition for the BonoboObject (Gtk Type)
18  */
19 #include "desktop.h"
20
21 /*
22  * Our parent Gtk object type
23  */
24 #define PARENT_TYPE ACCESSIBLE_TYPE
25
26 /*
27  * A pointer to our parent object class
28  */
29 static AccessibleClass *parent_class;
30
31 static void
32 desktop_init (Desktop  *desktop)
33 {
34   ACCESSIBLE (desktop)->atko = atk_simple_object_new();
35   atk_object_set_name (ATK_OBJECT (ACCESSIBLE (desktop)->atko), "main");
36 }
37
38 static CORBA_long
39 impl_desktop_get_child_count (PortableServer_Servant servant,
40                               CORBA_Environment * ev)
41 {
42   Desktop *desktop = DESKTOP (bonobo_object_from_servant (servant));
43   if (desktop->applications)
44     {
45       return g_list_length (desktop->applications);
46     }
47   else
48     {
49       return 0;
50     }
51 }
52
53 static Accessibility_Accessible
54 impl_desktop_get_child_at_index (PortableServer_Servant servant,
55                                  const CORBA_long index,
56                                  CORBA_Environment * ev)
57 {
58   Desktop *desktop = DESKTOP (bonobo_object_from_servant (servant));
59   CORBA_Object retval;
60   if ((desktop->applications) && (index < g_list_length (desktop->applications)))
61     {
62       fprintf (stderr, "getting application %ld\n", (long) index);
63       /* */
64       fprintf (stderr, "object address %p\n",
65                g_list_nth_data (desktop->applications, index));
66       retval =  CORBA_Object_duplicate (
67               (CORBA_Object) g_list_nth_data (desktop->applications, index), ev);
68     }
69   else
70     {
71       fprintf (stderr, "no %ldth child\n", (long) index);
72       retval = CORBA_OBJECT_NIL;
73     }
74   return (Accessibility_Accessible) retval;
75 }
76
77 static void
78 desktop_class_init (DesktopClass  *klass)
79 {
80         AccessibleClass * accessible_class = (AccessibleClass *) klass;
81         POA_Accessibility_Accessible__epv *epv = &accessible_class->epv;
82
83         parent_class = g_type_class_ref (ACCESSIBLE_TYPE);
84
85         epv->_get_childCount = impl_desktop_get_child_count;
86         epv->getChildAtIndex = impl_desktop_get_child_at_index;
87 }
88
89 GType
90 desktop_get_type (void)
91 {
92         static GType type = 0;
93
94         if (!type) {
95                 static const GTypeInfo tinfo = {
96                         sizeof (DesktopClass),
97                         (GBaseInitFunc) NULL,
98                         (GBaseFinalizeFunc) NULL,
99                         (GClassInitFunc) desktop_class_init,
100                         (GClassFinalizeFunc) NULL,
101                         NULL, /* class data */
102                         sizeof (Desktop),
103                         0, /* n preallocs */
104                         (GInstanceInitFunc) desktop_init,
105                         NULL /* value table */
106                 };
107                 /*
108                  *   Here we use bonobo_x_type_unique instead of
109                  * gtk_type_unique, this auto-generates a load of
110                  * CORBA structures for us. All derived types must
111                  * use bonobo_x_type_unique.
112                  */
113                 type = bonobo_x_type_unique (
114                         PARENT_TYPE,
115                         POA_Accessibility_Desktop__init,
116                         NULL,
117                         G_STRUCT_OFFSET (DesktopClass, epv),
118                         &tinfo,
119                         "Desktop");
120         }
121
122         return type;
123 }
124
125 Desktop *
126 desktop_new (void)
127 {
128     Desktop *retval =
129                DESKTOP (g_object_new (desktop_get_type (), NULL));
130     return retval;
131 }