2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001 Sun Microsystems Inc.
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.
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.
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.
23 /* value.c : implements the Value interface */
26 #include <libspi/value.h>
28 #define PARENT_TYPE SPI_TYPE_BASE
30 /* Static function declarations */
33 get_double_from_gvalue (GValue *gvalue);
35 gvalue_set_from_double (GValue *gvalue, double value);
37 spi_value_class_init (SpiValueClass *klass);
39 spi_value_init (SpiValue *value);
41 impl__get_minimumValue (PortableServer_Servant _servant,
42 CORBA_Environment * ev);
44 impl__get_maximumValue (PortableServer_Servant _servant,
45 CORBA_Environment * ev);
47 impl__get_currentValue (PortableServer_Servant _servant,
48 CORBA_Environment * ev);
50 impl__set_currentValue (PortableServer_Servant _servant,
51 const CORBA_double value,
52 CORBA_Environment * ev);
55 BONOBO_TYPE_FUNC_FULL (SpiValue,
62 spi_value_class_init (SpiValueClass *klass)
64 POA_Accessibility_Value__epv *epv = &klass->epv;
66 /* Initialize epv table */
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;
76 spi_value_init (SpiValue *value)
82 spi_value_interface_new (AtkObject *obj)
84 SpiValue *new_value = g_object_new (SPI_VALUE_TYPE, NULL);
86 spi_base_construct (SPI_BASE (new_value), G_OBJECT(obj));
93 get_value_from_servant (PortableServer_Servant servant)
95 SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
97 g_return_val_if_fail (object, NULL);
98 g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL);
99 return ATK_VALUE (object->gobj);
103 get_double_from_gvalue (GValue *gvalue)
106 if (G_TYPE_IS_FUNDAMENTAL (G_VALUE_TYPE (gvalue)))
108 switch (gvalue->g_type)
111 retval = g_value_get_double (gvalue);
114 retval = g_value_get_float (gvalue);
117 retval = g_value_get_ulong (gvalue);
120 retval = g_value_get_long (gvalue);
123 retval = g_value_get_uint (gvalue);
126 retval = g_value_get_int (gvalue);
129 retval = g_value_get_uchar (gvalue);
132 retval = g_value_get_char (gvalue);
135 retval = g_value_get_boolean (gvalue);
141 g_warning ("SpiValue requested from a non-fundamental type\n");
147 gvalue_set_from_double (GValue *gvalue, double value)
149 if (G_TYPE_IS_FUNDAMENTAL (G_VALUE_TYPE (gvalue)))
151 switch (gvalue->g_type)
154 g_value_set_double (gvalue, value);
157 g_value_set_float (gvalue, value);
160 g_value_set_ulong (gvalue, value);
163 g_value_set_long (gvalue, value);
166 g_value_set_uint (gvalue, value);
169 g_value_set_int (gvalue, value);
172 g_value_set_uchar (gvalue, value);
175 g_value_set_char (gvalue, value);
178 g_value_set_boolean (gvalue, ((fabs (value) > 0.5) ? 1 : 0));
184 g_warning ("SpiValue change requested for a non-fundamental type\n");
189 impl__get_minimumValue (PortableServer_Servant servant,
190 CORBA_Environment *ev)
192 GValue gvalue = {0, };
193 AtkValue *value = get_value_from_servant (servant);
195 g_return_val_if_fail (value != NULL, 0.0);
197 atk_value_get_minimum_value (value, &gvalue);
199 return get_double_from_gvalue (&gvalue);
204 impl__get_maximumValue (PortableServer_Servant servant,
205 CORBA_Environment *ev)
207 GValue gvalue = {0, };
208 AtkValue *value = get_value_from_servant (servant);
210 g_return_val_if_fail (value != NULL, 0.0);
212 atk_value_get_maximum_value (value, &gvalue);
214 return get_double_from_gvalue (&gvalue);
219 impl__get_currentValue (PortableServer_Servant servant,
220 CORBA_Environment *ev)
222 GValue gvalue = {0, };
223 AtkValue *value = get_value_from_servant (servant);
225 g_return_val_if_fail (value != NULL, 0.0);
227 atk_value_get_current_value (value, &gvalue);
229 return get_double_from_gvalue (&gvalue);
234 impl__set_currentValue (PortableServer_Servant servant,
235 const CORBA_double value,
236 CORBA_Environment *ev)
238 GValue gvalue = { 0, };
239 AtkValue *avalue = get_value_from_servant (servant);
241 g_return_if_fail (avalue != NULL);
243 atk_value_get_current_value (avalue, &gvalue);
244 gvalue_set_from_double (&gvalue, value);
246 atk_value_set_current_value (avalue, &gvalue);