276c2c3280638ed832c2d46bec73ca1bc62db36d
[platform/core/uifw/at-spi2-atk.git] / libspi / accessible.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  * accessible.c: test for accessibility implementation
25  *
26  */
27 #include <config.h>
28 #include <bonobo/Bonobo.h>
29
30 #include <stdio.h>
31
32 /*
33  * This pulls the CORBA definitions for the "Accessibility::Accessible" server
34  */
35 #include <libspi/Accessibility.h>
36
37 /*
38  * This pulls the definition for the BonoboObject (Gtk Type)
39  */
40 #include "accessible.h"
41
42 /*
43  * Our parent Gtk object type
44  */
45 #define PARENT_TYPE BONOBO_OBJECT_TYPE
46
47 /*
48  * A pointer to our parent object class
49  */
50 static GObjectClass *accessible_parent_class;
51
52 /*
53  * Implemented GObject::finalize
54  */
55 static void
56 accessible_object_finalize (GObject *object)
57 {
58         Accessible *accessible = ACCESSIBLE (object);
59
60         printf("accessible_object_finalize called\n");
61         g_object_unref (accessible->atko);
62         accessible->atko = NULL;
63
64         printf("atko freed, calling parent finalize\n");
65         accessible_parent_class->finalize (object);
66 }
67
68 /*
69  * CORBA Accessibility::Accessible::get_name method implementation
70  */
71 static CORBA_char *
72 impl_accessibility_accessible_get_name (PortableServer_Servant servant,
73                                         CORBA_Environment     *ev)
74 {
75   CORBA_char * retval;
76   Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
77   retval = CORBA_string_dup (atk_object_get_name (accessible->atko));
78   fprintf (stderr, "Accessible get_name called: %s\n", retval);
79   return retval;
80 }
81
82 /*
83  * CORBA Accessibility::Accessible::set_name method implementation
84  */
85 static void
86 impl_accessibility_accessible_set_name (PortableServer_Servant servant,
87                                         const CORBA_char      *name,
88                                         CORBA_Environment     *ev)
89 {
90   Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
91   atk_object_set_name (accessible->atko, name);
92   printf ("Accessible set_name called: %s\n", name);
93 }
94
95 /*
96  * CORBA Accessibility::Accessible::get_description method implementation
97  */
98 static CORBA_char *
99 impl_accessibility_accessible_get_description (PortableServer_Servant servant,
100                                                CORBA_Environment     *ev)
101 {
102   CORBA_char * retval;
103   Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
104   retval = CORBA_string_dup (atk_object_get_description (accessible->atko));
105   fprintf (stderr, "Accessible get_description called: %s\n", retval);
106   return retval;
107 }
108
109 /*
110  * CORBA Accessibility::Accessible::set_description method implementation
111  */
112 static void
113 impl_accessibility_accessible_set_description (PortableServer_Servant servant,
114                                                const CORBA_char      *name,
115                                                CORBA_Environment     *ev)
116 {
117   Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
118   atk_object_set_description (accessible->atko, name);
119   printf ("Accessible set_description called: %s\n", name);
120 }
121
122 static void
123 accessible_class_init (AccessibleClass *klass)
124 {
125         GObjectClass * object_class = (GObjectClass *) klass;
126         POA_Accessibility_Accessible__epv *epv = &klass->epv;
127         accessible_parent_class = g_type_class_peek_parent (klass);
128
129         object_class->finalize = accessible_object_finalize;
130
131         epv->_get_name = impl_accessibility_accessible_get_name;
132         epv->_set_name = impl_accessibility_accessible_set_name;
133         epv->_get_description = impl_accessibility_accessible_get_description;
134         epv->_set_description = impl_accessibility_accessible_set_description;
135
136         /* epv->_get_parent = impl_accessibility_accessible_get_parent;               */
137         /* epv->_get_childCount = impl_accessibility_accessible_get_child_count;      */
138         /* epv->getChildAtIndex = impl_accessibility_accessible_get_child_at_index;   */
139         /* epv->getIndexInParent = impl_accessibility_accessible_get_index_in_parent; */
140         /* epv->getRelationSet = impl_accessibility_accessible_get_relation_set;      */
141         /* epv->getState = impl_accessibility_accessible_get_state;                   */
142         /* epv->getRole = impl_accessibility_accessible_get_role;                     */
143 }
144
145 static void
146 accessible_init (Accessible *accessible)
147 {
148 }
149
150 GType
151 accessible_get_type (void)
152 {
153         static GType type = 0;
154
155         if (!type) {
156                 static const GTypeInfo tinfo = {
157                         sizeof (AccessibleClass),
158                         (GBaseInitFunc) NULL,
159                         (GBaseFinalizeFunc) NULL,
160                         (GClassInitFunc) accessible_class_init,
161                         (GClassFinalizeFunc) NULL,
162                         NULL, /* class data */
163                         sizeof (Accessible),
164                         0, /* n preallocs */
165                         (GInstanceInitFunc) accessible_init,
166                         NULL /* value table */
167                 };
168                 /*
169                  * Bonobo_type_unique auto-generates a load of
170                  * CORBA structures for us. All derived types must
171                  * use bonobo_type_unique.
172                  */
173                 type = bonobo_type_unique (
174                         PARENT_TYPE,
175                         POA_Accessibility_Accessible__init,
176                         NULL,
177                         G_STRUCT_OFFSET (AccessibleClass, epv),
178                         &tinfo,
179                         "Accessible");
180         }
181
182         return type;
183 }
184
185 Accessible *
186 accessible_new (AtkObject *o)
187 {
188     Accessible *retval =
189                ACCESSIBLE (g_object_new (accessible_get_type (), NULL));
190     retval->atko = ATK_OBJECT (o);
191     return retval;
192 }