2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 /* value.c : implements the Value interface */
28 #include <libspi/value.h>
30 #define PARENT_TYPE SPI_TYPE_BASE
32 /* Static function declarations */
35 get_double_from_gvalue (GValue *gvalue);
37 gvalue_set_from_double (GValue *gvalue, double value);
39 spi_value_class_init (SpiValueClass *klass);
41 spi_value_init (SpiValue *value);
43 impl__get_minimumValue (PortableServer_Servant _servant,
44 CORBA_Environment * ev);
46 impl__get_maximumValue (PortableServer_Servant _servant,
47 CORBA_Environment * ev);
49 impl__get_currentValue (PortableServer_Servant _servant,
50 CORBA_Environment * ev);
52 impl__set_currentValue (PortableServer_Servant _servant,
53 const CORBA_double value,
54 CORBA_Environment * ev);
56 impl__get_minimumIncrement (PortableServer_Servant _servant,
57 CORBA_Environment * ev);
60 BONOBO_TYPE_FUNC_FULL (SpiValue,
67 spi_value_class_init (SpiValueClass *klass)
69 POA_Accessibility_Value__epv *epv = &klass->epv;
71 /* Initialize epv table */
73 epv->_get_minimumValue = impl__get_minimumValue;
74 epv->_get_maximumValue = impl__get_maximumValue;
75 epv->_get_currentValue = impl__get_currentValue;
76 epv->_set_currentValue = impl__set_currentValue;
77 epv->_get_minimumIncrement = impl__get_minimumIncrement;
82 spi_value_init (SpiValue *value)
88 spi_value_interface_new (AtkObject *obj)
90 SpiValue *new_value = g_object_new (SPI_VALUE_TYPE, NULL);
92 spi_base_construct (SPI_BASE (new_value), G_OBJECT(obj));
99 get_value_from_servant (PortableServer_Servant servant)
101 SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
103 g_return_val_if_fail (object, NULL);
104 g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL);
105 return ATK_VALUE (object->gobj);
109 get_double_from_gvalue (GValue *gvalue)
112 if (G_TYPE_IS_FUNDAMENTAL (G_VALUE_TYPE (gvalue)))
114 switch (gvalue->g_type)
117 retval = g_value_get_double (gvalue);
120 retval = g_value_get_float (gvalue);
123 retval = g_value_get_ulong (gvalue);
126 retval = g_value_get_long (gvalue);
129 retval = g_value_get_uint (gvalue);
132 retval = g_value_get_int (gvalue);
135 retval = g_value_get_uchar (gvalue);
138 retval = g_value_get_char (gvalue);
141 retval = g_value_get_boolean (gvalue);
147 g_warning ("SpiValue requested from a non-fundamental type\n");
153 gvalue_set_from_double (GValue *gvalue, double value)
155 if (G_TYPE_IS_FUNDAMENTAL (G_VALUE_TYPE (gvalue)))
157 switch (gvalue->g_type)
160 g_value_set_double (gvalue, value);
163 g_value_set_float (gvalue, value);
166 g_value_set_ulong (gvalue, value);
169 g_value_set_long (gvalue, value);
172 g_value_set_uint (gvalue, value);
175 g_value_set_int (gvalue, value);
178 g_value_set_uchar (gvalue, value);
181 g_value_set_char (gvalue, value);
184 g_value_set_boolean (gvalue, ((fabs (value) > 0.5) ? 1 : 0));
190 g_warning ("SpiValue change requested for a non-fundamental type\n");
195 impl__get_minimumValue (PortableServer_Servant servant,
196 CORBA_Environment *ev)
198 GValue gvalue = {0, };
199 AtkValue *value = get_value_from_servant (servant);
201 g_return_val_if_fail (value != NULL, 0.0);
203 atk_value_get_minimum_value (value, &gvalue);
205 return get_double_from_gvalue (&gvalue);
210 impl__get_maximumValue (PortableServer_Servant servant,
211 CORBA_Environment *ev)
213 GValue gvalue = {0, };
214 AtkValue *value = get_value_from_servant (servant);
216 g_return_val_if_fail (value != NULL, 0.0);
218 atk_value_get_maximum_value (value, &gvalue);
220 return get_double_from_gvalue (&gvalue);
225 impl__get_currentValue (PortableServer_Servant servant,
226 CORBA_Environment *ev)
228 GValue gvalue = {0, };
229 AtkValue *value = get_value_from_servant (servant);
231 g_return_val_if_fail (value != NULL, 0.0);
233 atk_value_get_current_value (value, &gvalue);
235 return get_double_from_gvalue (&gvalue);
240 impl__set_currentValue (PortableServer_Servant servant,
241 const CORBA_double value,
242 CORBA_Environment *ev)
244 GValue gvalue = { 0, };
245 AtkValue *avalue = get_value_from_servant (servant);
247 g_return_if_fail (avalue != NULL);
249 atk_value_get_current_value (avalue, &gvalue);
250 gvalue_set_from_double (&gvalue, value);
252 atk_value_set_current_value (avalue, &gvalue);
256 impl__get_minimumIncrement (PortableServer_Servant servant,
257 CORBA_Environment *ev)
259 GValue gvalue = {0, };
260 AtkValue *value = get_value_from_servant (servant);
262 g_return_val_if_fail (value != NULL, 0.0);
264 atk_value_get_minimum_increment (value, &gvalue);
266 return get_double_from_gvalue (&gvalue);