Minor cleanup of initial checkin.
[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 "Accessible.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_X_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_free (accessible->atko);
62
63         printf("atko freed, calling parent finalize\n");
64         accessible_parent_class->finalize (object);
65 }
66
67 /*
68  * CORBA Accessibility::Accessible::get_name method implementation
69  */
70 static CORBA_char *
71 impl_accessibility_accessible_get_name (PortableServer_Servant servant,
72                                         CORBA_Environment     *ev)
73 {
74   CORBA_char * retval;
75   Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
76   retval = CORBA_string_dup (atk_object_get_name (accessible->atko));
77   fprintf (stderr, "Accessible get_name called: %s\n", retval);
78   return retval;
79 }
80
81 /*
82  * CORBA Accessibility::Accessible::set_name method implementation
83  */
84 static void
85 impl_accessibility_accessible_set_name (PortableServer_Servant servant,
86                                         const CORBA_char      *name,
87                                         CORBA_Environment     *ev)
88 {
89   Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
90   atk_object_set_name (accessible->atko, name);
91   printf ("Accessible set_name called: %s\n", name);
92 }
93
94 static void
95 accessible_class_init (AccessibleClass *klass)
96 {
97         GObjectClass * object_class = (GObjectClass *) klass;
98         POA_Accessibility_Accessible__epv *epv = &klass->epv;
99         accessible_parent_class = g_type_class_ref (BONOBO_X_OBJECT_TYPE);
100         /*accessible_parent_class = g_type_class_peek_parent (klass);*/
101
102         object_class->finalize = accessible_object_finalize;
103
104         epv->_get_name = impl_accessibility_accessible_get_name;
105         epv->_set_name = impl_accessibility_accessible_set_name;
106 }
107
108 static void
109 accessible_init (Accessible *accessible)
110 {
111 }
112
113 GType
114 accessible_get_type (void)
115 {
116         static GType type = 0;
117
118         if (!type) {
119                 static const GTypeInfo tinfo = {
120                         sizeof (AccessibleClass),
121                         (GBaseInitFunc) NULL,
122                         (GBaseFinalizeFunc) NULL,
123                         (GClassInitFunc) accessible_class_init,
124                         (GClassFinalizeFunc) NULL,
125                         NULL, /* class data */
126                         sizeof (Accessible),
127                         0, /* n preallocs */
128                         (GInstanceInitFunc) accessible_init,
129                         NULL /* value table */
130                 };
131                 /*
132                  *   Here we use bonobo_x_type_unique instead of
133                  * gtk_type_unique, this auto-generates a load of
134                  * CORBA structures for us. All derived types must
135                  * use bonobo_x_type_unique.
136                  */
137                 type = bonobo_x_type_unique (
138                         PARENT_TYPE,
139                         POA_Accessibility_Accessible__init,
140                         NULL,
141                         G_STRUCT_OFFSET (AccessibleClass, epv),
142                         &tinfo,
143                         "Accessible");
144         }
145
146         return type;
147 }
148
149 Accessible *
150 accessible_new (AtkObject *o)
151 {
152     Accessible *retval =
153                ACCESSIBLE (g_object_new (accessible_get_type (), NULL));
154     retval->atko = ATK_OBJECT (o);
155     return retval;
156 }