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 */
32 static Accessibility_SValue
33 gvalue_to_svalue (GValue *gvalue);
35 spi_value_class_init (SpiValueClass *klass);
37 spi_value_init (SpiValue *value);
38 static Accessibility_SValue
39 impl__get_minimumValue (PortableServer_Servant _servant,
40 CORBA_Environment * ev);
41 static Accessibility_SValue
42 impl__get_maximumValue (PortableServer_Servant _servant,
43 CORBA_Environment * ev);
44 static Accessibility_SValue
45 impl__get_currentValue (PortableServer_Servant _servant,
46 CORBA_Environment * ev);
48 impl__set_currentValue (PortableServer_Servant _servant,
49 const Accessibility_SValue * value,
50 CORBA_Environment * ev);
53 BONOBO_TYPE_FUNC_FULL (SpiValue,
60 spi_value_class_init (SpiValueClass *klass)
62 POA_Accessibility_Value__epv *epv = &klass->epv;
64 /* Initialize epv table */
66 epv->_get_minimumValue = impl__get_minimumValue;
67 epv->_get_maximumValue = impl__get_maximumValue;
68 epv->_get_currentValue = impl__get_currentValue;
69 epv->_set_currentValue = impl__set_currentValue;
74 spi_value_init (SpiValue *value)
80 spi_value_interface_new (AtkObject *obj)
82 SpiValue *new_value = g_object_new (SPI_VALUE_TYPE, NULL);
84 spi_base_construct (SPI_BASE (new_value), obj);
91 get_value_from_servant (PortableServer_Servant servant)
93 SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
100 return ATK_VALUE (object->atko);
103 static Accessibility_SValue
104 gvalue_to_svalue (GValue *gvalue)
106 Accessibility_SValue sval;
107 if (G_VALUE_HOLDS_DOUBLE (gvalue))
109 sval._d = Accessibility_DOUBLEVAL;
110 sval._u.val_double = g_value_get_double (gvalue);
112 else if (G_VALUE_HOLDS_FLOAT (gvalue))
114 sval._d = Accessibility_FLOATVAL;
115 sval._u.val_float = g_value_get_float (gvalue);
117 else if (G_VALUE_HOLDS_ULONG (gvalue))
119 sval._d = Accessibility_ULONGVAL;
120 sval._u.val_ulong = g_value_get_ulong (gvalue);
122 else if (G_VALUE_HOLDS_LONG (gvalue))
124 sval._d = Accessibility_LONGVAL;
125 sval._u.val_long = g_value_get_long (gvalue);
127 else if (G_VALUE_HOLDS_UINT (gvalue))
129 sval._d = Accessibility_USHORTVAL;
130 sval._u.val_ushort = CLAMP (g_value_get_uint (gvalue), 0, G_MAXUSHORT);
132 else if (G_VALUE_HOLDS_INT (gvalue))
134 sval._d = Accessibility_SHORTVAL;
135 sval._u.val_short = CLAMP (g_value_get_int (gvalue), G_MINSHORT, G_MAXSHORT);
139 sval._d = Accessibility_SHORTVAL;
140 sval._u.val_short = 0;
146 gvalue_set_from_svalue (GValue *gvalue, Accessibility_SValue *sval)
150 case Accessibility_DOUBLEVAL:
151 g_value_init (gvalue, G_TYPE_DOUBLE);
152 g_value_set_double (gvalue, sval->_u.val_double);
154 case Accessibility_FLOATVAL:
155 g_value_init (gvalue, G_TYPE_FLOAT);
156 g_value_set_float (gvalue, sval->_u.val_float);
158 case Accessibility_ULONGVAL:
159 g_value_init (gvalue, G_TYPE_ULONG);
160 g_value_set_ulong (gvalue, sval->_u.val_ulong);
162 case Accessibility_LONGVAL:
163 g_value_init (gvalue, G_TYPE_LONG);
164 g_value_set_long (gvalue, sval->_u.val_long);
166 case Accessibility_USHORTVAL:
167 g_value_init (gvalue, G_TYPE_UINT);
168 g_value_set_uint (gvalue, sval->_u.val_ushort);
170 case Accessibility_SHORTVAL:
171 g_value_init (gvalue, G_TYPE_INT);
172 g_value_set_int (gvalue, sval->_u.val_short);
175 g_value_init (gvalue, G_TYPE_INT);
176 g_value_set_int (gvalue, 0);
180 static Accessibility_SValue
181 impl__get_minimumValue (PortableServer_Servant servant,
182 CORBA_Environment *ev)
184 GValue gvalue = {0, };
185 AtkValue *value = get_value_from_servant (servant);
187 g_return_val_if_fail (value != NULL, gvalue_to_svalue (&gvalue));
189 g_value_init (&gvalue, G_TYPE_DOUBLE);
190 atk_value_get_minimum_value (value, &gvalue);
192 return gvalue_to_svalue (&gvalue);
196 static Accessibility_SValue
197 impl__get_maximumValue (PortableServer_Servant servant,
198 CORBA_Environment *ev)
200 GValue gvalue = {0, };
201 AtkValue *value = get_value_from_servant (servant);
203 g_return_val_if_fail (value != NULL, gvalue_to_svalue (&gvalue));
205 g_value_init (&gvalue, G_TYPE_DOUBLE);
206 atk_value_get_maximum_value (value, &gvalue);
208 return gvalue_to_svalue (&gvalue);
212 static Accessibility_SValue
213 impl__get_currentValue (PortableServer_Servant servant,
214 CORBA_Environment *ev)
216 GValue gvalue = {0, };
217 AtkValue *value = get_value_from_servant (servant);
219 g_return_val_if_fail (value != NULL, gvalue_to_svalue (&gvalue));
221 g_value_init (&gvalue, G_TYPE_DOUBLE);
222 atk_value_get_current_value (value, &gvalue);
224 return gvalue_to_svalue (&gvalue);
229 impl__set_currentValue (PortableServer_Servant servant,
230 const Accessibility_SValue *value,
231 CORBA_Environment *ev)
233 GValue gvalue = {0, };
234 AtkValue *avalue = get_value_from_servant (servant);
236 g_return_if_fail (avalue != NULL);
238 gvalue_set_from_svalue (&gvalue, value);
240 atk_value_set_current_value (avalue, &gvalue);