Updated role enumeration in Accessibility_Role.idl.
[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 /* value.c : implements the Value interface */
24 #include <config.h>
25 #include <stdio.h>
26 #include <libspi/value.h>
27
28 #define PARENT_TYPE SPI_TYPE_BASE
29
30 /* Static function declarations */
31
32 static double
33 get_double_from_gvalue (GValue *gvalue);
34 static void
35 gvalue_set_from_double (GValue *gvalue, double value);
36 static void
37 spi_value_class_init (SpiValueClass *klass);
38 static void
39 spi_value_init (SpiValue *value);
40 static double
41 impl__get_minimumValue (PortableServer_Servant _servant,
42                         CORBA_Environment *    ev);
43 static double
44 impl__get_maximumValue (PortableServer_Servant _servant,
45                         CORBA_Environment *    ev);
46 static double
47 impl__get_currentValue (PortableServer_Servant _servant,
48                         CORBA_Environment *    ev);
49 static void 
50 impl__set_currentValue (PortableServer_Servant _servant,
51                         const CORBA_double     value,
52                         CORBA_Environment *    ev);
53
54
55 BONOBO_TYPE_FUNC_FULL (SpiValue,
56                        Accessibility_Value,
57                        PARENT_TYPE,
58                        spi_value);
59
60
61 static void
62 spi_value_class_init (SpiValueClass *klass)
63 {
64   POA_Accessibility_Value__epv *epv = &klass->epv;
65
66   /* Initialize epv table */
67
68   epv->_get_minimumValue = impl__get_minimumValue;
69   epv->_get_maximumValue = impl__get_maximumValue;
70   epv->_get_currentValue = impl__get_currentValue;
71   epv->_set_currentValue = impl__set_currentValue;
72 }
73
74
75 static void
76 spi_value_init (SpiValue *value)
77 {
78 }
79
80
81 SpiValue *
82 spi_value_interface_new (AtkObject *obj)
83 {
84   SpiValue *new_value = g_object_new (SPI_VALUE_TYPE, NULL);
85
86   spi_base_construct (SPI_BASE (new_value), obj);
87
88   return new_value;
89 }
90
91
92 static AtkValue *
93 get_value_from_servant (PortableServer_Servant servant)
94 {
95   SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
96
97   if (!object)
98     {
99       return NULL;
100     }
101
102   return ATK_VALUE (object->atko);
103 }
104
105 static double
106 get_double_from_gvalue (GValue *gvalue)
107 {
108   double        retval = 0;
109   if (G_TYPE_IS_FUNDAMENTAL (G_VALUE_TYPE (gvalue)))
110     {
111       switch (gvalue->g_type)
112         {
113           case G_TYPE_DOUBLE:
114             retval = g_value_get_double (gvalue);
115             break;
116           case G_TYPE_FLOAT:
117             retval = g_value_get_float (gvalue);
118             break;
119           case G_TYPE_ULONG:
120             retval = g_value_get_ulong (gvalue);
121             break;
122           case G_TYPE_LONG:
123             retval = g_value_get_long (gvalue);
124             break;
125           case G_TYPE_UINT:
126             retval = g_value_get_uint (gvalue);
127             break;
128           case G_TYPE_INT:
129             retval = g_value_get_int (gvalue);
130             break;
131           case G_TYPE_UCHAR:
132             retval = g_value_get_uchar (gvalue);
133             break;
134           case G_TYPE_CHAR:
135             retval = g_value_get_char (gvalue);
136             break;
137           case G_TYPE_BOOLEAN:
138             retval = g_value_get_boolean (gvalue);
139             break;
140         }
141     }
142   else
143     {
144       g_warning ("SpiValue requested from a non-fundamental type\n");       
145     }
146   return retval;
147 }  
148
149 static void
150 gvalue_set_from_double (GValue *gvalue, double value)
151 {
152   if (G_TYPE_IS_FUNDAMENTAL (G_VALUE_TYPE (gvalue)))
153     {
154       switch (gvalue->g_type)
155         {
156           case G_TYPE_DOUBLE:
157             g_value_set_double (gvalue, value);
158             break;
159           case G_TYPE_FLOAT:
160             g_value_set_float (gvalue, value);
161             break;
162           case G_TYPE_ULONG:
163             g_value_set_ulong (gvalue, value);
164             break;
165           case G_TYPE_LONG:
166             g_value_set_long (gvalue, value);
167             break;
168           case G_TYPE_UINT:
169             g_value_set_uint (gvalue, value);
170             break;
171           case G_TYPE_INT:
172             g_value_set_int (gvalue, value);
173             break;
174           case G_TYPE_UCHAR:
175             g_value_set_uchar (gvalue, value);
176             break;
177           case G_TYPE_CHAR:
178             g_value_set_char (gvalue, value);
179             break;
180           case G_TYPE_BOOLEAN:
181             g_value_set_boolean (gvalue, ((fabs (value) > 0.5) ? 1 : 0));
182             break;
183         }
184     }
185   else
186     {
187       g_warning ("SpiValue change requested for a non-fundamental type\n");         
188     }
189 }
190
191 static double
192 impl__get_minimumValue (PortableServer_Servant servant,
193                         CORBA_Environment     *ev)
194 {
195   GValue    gvalue = {0, };
196   AtkValue *value = get_value_from_servant (servant);
197
198   g_return_val_if_fail (value != NULL, 0.0);
199
200   atk_value_get_minimum_value (value, &gvalue);
201
202   return get_double_from_gvalue (&gvalue);
203 }
204
205
206 static double
207 impl__get_maximumValue (PortableServer_Servant servant,
208                         CORBA_Environment     *ev)
209 {
210   GValue   gvalue = {0, };
211   AtkValue *value = get_value_from_servant (servant);
212
213   g_return_val_if_fail (value != NULL, 0.0);
214
215   atk_value_get_maximum_value (value, &gvalue);
216
217   return get_double_from_gvalue (&gvalue);
218 }
219
220
221 static double
222 impl__get_currentValue (PortableServer_Servant servant,
223                         CORBA_Environment     *ev)
224 {
225   GValue   gvalue = {0, };
226   AtkValue *value = get_value_from_servant (servant);
227
228   g_return_val_if_fail (value != NULL, 0.0);
229
230   atk_value_get_current_value (value, &gvalue);
231
232   return get_double_from_gvalue (&gvalue);
233 }
234
235
236 static void 
237 impl__set_currentValue (PortableServer_Servant servant,
238                         const CORBA_double     value,
239                         CORBA_Environment     *ev)
240 {
241   GValue    gvalue = { 0, };
242   AtkValue *avalue = get_value_from_servant (servant);
243
244   g_return_if_fail (avalue != NULL);
245
246   atk_value_get_current_value (avalue, &gvalue);
247   gvalue_set_from_double (&gvalue, value);
248
249   atk_value_set_current_value (avalue, &gvalue);
250 }
251
252