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 */
27 #include <libspi/value.h>
29 #define PARENT_TYPE SPI_TYPE_BASE
31 /* Static function declarations */
34 get_double_from_gvalue (GValue *gvalue);
36 gvalue_set_from_double (GValue *gvalue, double value);
38 spi_value_class_init (SpiValueClass *klass);
40 spi_value_init (SpiValue *value);
42 impl__get_minimumValue (PortableServer_Servant _servant,
43 CORBA_Environment * ev);
45 impl__get_maximumValue (PortableServer_Servant _servant,
46 CORBA_Environment * ev);
48 impl__get_currentValue (PortableServer_Servant _servant,
49 CORBA_Environment * ev);
51 impl__set_currentValue (PortableServer_Servant _servant,
52 const CORBA_double value,
53 CORBA_Environment * ev);
56 BONOBO_TYPE_FUNC_FULL (SpiValue,
63 spi_value_class_init (SpiValueClass *klass)
65 POA_Accessibility_Value__epv *epv = &klass->epv;
67 /* Initialize epv table */
69 epv->_get_minimumValue = impl__get_minimumValue;
70 epv->_get_maximumValue = impl__get_maximumValue;
71 epv->_get_currentValue = impl__get_currentValue;
72 epv->_set_currentValue = impl__set_currentValue;
77 spi_value_init (SpiValue *value)
83 spi_value_interface_new (AtkObject *obj)
85 SpiValue *new_value = g_object_new (SPI_VALUE_TYPE, NULL);
87 spi_base_construct (SPI_BASE (new_value), G_OBJECT(obj));
94 get_value_from_servant (PortableServer_Servant servant)
96 SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
98 g_return_val_if_fail (object, NULL);
99 g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL);
100 return ATK_VALUE (object->gobj);
104 get_double_from_gvalue (GValue *gvalue)
107 if (G_TYPE_IS_FUNDAMENTAL (G_VALUE_TYPE (gvalue)))
109 switch (gvalue->g_type)
112 retval = g_value_get_double (gvalue);
115 retval = g_value_get_float (gvalue);
118 retval = g_value_get_ulong (gvalue);
121 retval = g_value_get_long (gvalue);
124 retval = g_value_get_uint (gvalue);
127 retval = g_value_get_int (gvalue);
130 retval = g_value_get_uchar (gvalue);
133 retval = g_value_get_char (gvalue);
136 retval = g_value_get_boolean (gvalue);
142 g_warning ("SpiValue requested from a non-fundamental type\n");
148 gvalue_set_from_double (GValue *gvalue, double value)
150 if (G_TYPE_IS_FUNDAMENTAL (G_VALUE_TYPE (gvalue)))
152 switch (gvalue->g_type)
155 g_value_set_double (gvalue, value);
158 g_value_set_float (gvalue, value);
161 g_value_set_ulong (gvalue, value);
164 g_value_set_long (gvalue, value);
167 g_value_set_uint (gvalue, value);
170 g_value_set_int (gvalue, value);
173 g_value_set_uchar (gvalue, value);
176 g_value_set_char (gvalue, value);
179 g_value_set_boolean (gvalue, ((fabs (value) > 0.5) ? 1 : 0));
185 g_warning ("SpiValue change requested for a non-fundamental type\n");
190 impl__get_minimumValue (PortableServer_Servant servant,
191 CORBA_Environment *ev)
193 GValue gvalue = {0, };
194 AtkValue *value = get_value_from_servant (servant);
196 g_return_val_if_fail (value != NULL, 0.0);
198 atk_value_get_minimum_value (value, &gvalue);
200 return get_double_from_gvalue (&gvalue);
205 impl__get_maximumValue (PortableServer_Servant servant,
206 CORBA_Environment *ev)
208 GValue gvalue = {0, };
209 AtkValue *value = get_value_from_servant (servant);
211 g_return_val_if_fail (value != NULL, 0.0);
213 atk_value_get_maximum_value (value, &gvalue);
215 return get_double_from_gvalue (&gvalue);
220 impl__get_currentValue (PortableServer_Servant servant,
221 CORBA_Environment *ev)
223 GValue gvalue = {0, };
224 AtkValue *value = get_value_from_servant (servant);
226 g_return_val_if_fail (value != NULL, 0.0);
228 atk_value_get_current_value (value, &gvalue);
230 return get_double_from_gvalue (&gvalue);
235 impl__set_currentValue (PortableServer_Servant servant,
236 const CORBA_double value,
237 CORBA_Environment *ev)
239 GValue gvalue = { 0, };
240 AtkValue *avalue = get_value_from_servant (servant);
242 g_return_if_fail (avalue != NULL);
244 atk_value_get_current_value (avalue, &gvalue);
245 gvalue_set_from_double (&gvalue, value);
247 atk_value_set_current_value (avalue, &gvalue);