Cleaned up some suspect int* casts, and added assertions to text calls in libspi
[platform/core/uifw/at-spi2-atk.git] / libspi / value.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  * component.c : bonobo wrapper for accessible component 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 of the Value bonobo object
39  */
40 #include "value.h"
41
42 /*
43  * Static function declarations
44  */
45
46 static void
47 value_class_init (ValueClass *klass);
48 static void
49 value_init (Value *value);
50 static void
51 value_finalize (GObject *obj);
52 static CORBA_float
53 impl__get_minimumValue (PortableServer_Servant _servant,
54                         CORBA_Environment * ev);
55 static        CORBA_float
56 impl__get_maximumValue (PortableServer_Servant _servant,
57                         CORBA_Environment * ev);
58 static CORBA_float
59 impl__get_currentValue (PortableServer_Servant _servant,
60                         CORBA_Environment * ev);
61 static void 
62 impl__set_currentValue (PortableServer_Servant _servant,
63                         const CORBA_float value,
64                         CORBA_Environment * ev);
65
66
67
68 static GObjectClass *parent_class;
69
70
71 GType
72 value_get_type (void)
73 {
74   static GType type = 0;
75
76   if (!type) {
77     static const GTypeInfo tinfo = {
78       sizeof (ValueClass),
79       (GBaseInitFunc) NULL,
80       (GBaseFinalizeFunc) NULL,
81       (GClassInitFunc) value_class_init,
82       (GClassFinalizeFunc) NULL,
83       NULL, /* class data */
84       sizeof (Value),
85       0, /* n preallocs */
86       (GInstanceInitFunc) value_init,
87                         NULL /* value table */
88     };
89
90     /*
91      * Bonobo_type_unique auto-generates a load of
92      * CORBA structures for us. All derived types must
93      * use bonobo_type_unique.
94      */
95     type = bonobo_type_unique (
96                                BONOBO_OBJECT_TYPE,
97                                POA_Accessibility_Value__init,
98                                NULL,
99                                G_STRUCT_OFFSET (ValueClass, epv),
100                                &tinfo,
101                                "AccessibleValue");
102   }
103
104   return type;
105 }
106
107 static void
108 value_class_init (ValueClass *klass)
109 {
110   GObjectClass * object_class = (GObjectClass *) klass;
111   POA_Accessibility_Value__epv *epv = &klass->epv;
112   parent_class = g_type_class_peek_parent (klass);
113
114   object_class->finalize = value_finalize;
115
116
117   /* Initialize epv table */
118
119   epv->_get_minimumValue = impl__get_minimumValue;
120   epv->_get_maximumValue = impl__get_maximumValue;
121   epv->_get_currentValue = impl__get_currentValue;
122   epv->_set_currentValue = impl__set_currentValue;
123 }
124
125 static void
126 value_init (Value *value)
127 {
128 }
129
130 static void
131 value_finalize (GObject *obj)
132 {
133   Value *value = VALUE (obj);
134   g_object_unref (value->atko);
135   value->atko = NULL;
136   parent_class->finalize (obj);
137 }
138
139 Value *
140 value_interface_new (AtkObject *obj)
141 {
142   Value *new_value = 
143     VALUE(g_object_new (VALUE_TYPE, NULL));
144   new_value->atko = obj;
145   g_object_ref (obj);
146   return new_value;
147 }
148
149
150
151 static CORBA_float
152 impl__get_minimumValue (PortableServer_Servant _servant,
153                        CORBA_Environment * ev)
154 {
155   Value *value = VALUE (bonobo_object_from_servant (_servant));
156   GValue gvalue = {0, };
157
158   g_value_init (&gvalue, G_TYPE_FLOAT);
159   atk_value_get_minimum_value (ATK_VALUE(value->atko), &gvalue);
160   return (CORBA_float) g_value_get_float (&gvalue);
161 }
162
163
164
165 static        CORBA_float
166 impl__get_maximumValue (PortableServer_Servant _servant,
167                         CORBA_Environment * ev)
168 {
169   Value *value = VALUE (bonobo_object_from_servant (_servant));
170   GValue gvalue = {0, };
171
172   g_value_init (&gvalue, G_TYPE_FLOAT);
173   atk_value_get_maximum_value (ATK_VALUE(value->atko), &gvalue);
174   return (CORBA_float) g_value_get_float (&gvalue);
175 }
176
177
178
179 static CORBA_float
180 impl__get_currentValue (PortableServer_Servant _servant,
181                         CORBA_Environment * ev)
182 {
183   Value *value = VALUE (bonobo_object_from_servant (_servant));
184   GValue gvalue = {0, };
185
186   g_value_init (&gvalue, G_TYPE_FLOAT);
187   atk_value_get_current_value (ATK_VALUE(value->atko), &gvalue);
188   return (CORBA_float) g_value_get_float (&gvalue);
189 }
190
191
192 static void 
193 impl__set_currentValue (PortableServer_Servant _servant,
194                         const CORBA_float value,
195                         CORBA_Environment * ev)
196 {
197   Value *val = VALUE (bonobo_object_from_servant (_servant));
198   GValue gvalue = {0, };
199
200   g_value_init (&gvalue, G_TYPE_FLOAT);
201   g_value_set_float (&gvalue, (gfloat) value);
202   atk_value_set_current_value (ATK_VALUE(val->atko), &gvalue);
203 }
204
205