2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2008 Novell, Inc.
6 * Copyright 2001, 2002 Sun Microsystems Inc.,
7 * Copyright 2001, 2002 Ximian, Inc.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
25 #include "accessible.h"
29 get_value_from_path (const char *path, void *user_data)
31 AtkObject *obj = spi_dbus_get_object (path);
34 return ATK_VALUE (obj);
38 get_double_from_gvalue (GValue * gvalue)
41 if (G_TYPE_IS_FUNDAMENTAL (G_VALUE_TYPE (gvalue)))
43 switch (gvalue->g_type)
46 retval = g_value_get_double (gvalue);
49 retval = g_value_get_float (gvalue);
52 retval = g_value_get_ulong (gvalue);
55 retval = g_value_get_long (gvalue);
58 retval = g_value_get_uint (gvalue);
61 retval = g_value_get_int (gvalue);
64 retval = g_value_get_uchar (gvalue);
67 retval = g_value_get_char (gvalue);
70 retval = g_value_get_boolean (gvalue);
76 g_warning ("SpiValue requested from a non-fundamental type\n");
82 get_double_from_variant (DBusMessageIter * iter, double *out)
86 dbus_message_iter_recurse (iter, &sub);
87 switch (dbus_message_iter_get_arg_type (&sub))
89 case DBUS_TYPE_DOUBLE:
91 dbus_message_iter_get_basic (&sub, out);
94 case DBUS_TYPE_UINT32:
97 dbus_message_iter_get_basic (&sub, &v);
101 case DBUS_TYPE_INT32:
104 dbus_message_iter_get_basic (&sub, &v);
108 case DBUS_TYPE_UINT16:
111 dbus_message_iter_get_basic (&sub, &v);
115 case DBUS_TYPE_INT16:
118 dbus_message_iter_get_basic (&sub, &v);
125 dbus_message_iter_get_basic (&sub, &v);
129 case DBUS_TYPE_BOOLEAN:
132 dbus_message_iter_get_basic (&sub, &v);
142 gvalue_set_from_double (GValue * gvalue, double value)
144 if (G_TYPE_IS_FUNDAMENTAL (G_VALUE_TYPE (gvalue)))
146 switch (gvalue->g_type)
149 g_value_set_double (gvalue, value);
152 g_value_set_float (gvalue, value);
155 g_value_set_ulong (gvalue, value);
158 g_value_set_long (gvalue, value);
161 g_value_set_uint (gvalue, value);
164 g_value_set_int (gvalue, value);
167 g_value_set_uchar (gvalue, value);
170 g_value_set_char (gvalue, value);
173 g_value_set_boolean (gvalue, ((fabs (value) > 0.5) ? 1 : 0));
179 g_warning ("SpiValue change requested for a non-fundamental type\n");
184 impl_get_minimumValue (const char *path, DBusMessageIter * iter,
187 AtkValue *value = get_value_from_path (path, user_data);
188 GValue gvalue = { 0, };
191 atk_value_get_minimum_value (value, &gvalue);
192 return droute_return_v_double (iter, get_double_from_gvalue (&gvalue));
196 impl_get_minimumValue_str (void *datum)
198 AtkValue *value = (AtkValue *) datum;
199 GValue gvalue = { 0, };
202 atk_value_get_minimum_value (value, &gvalue);
203 return g_strdup_printf ("%lf", get_double_from_gvalue (&gvalue));
207 impl_get_maximumValue (const char *path, DBusMessageIter * iter,
210 AtkValue *value = get_value_from_path (path, user_data);
211 GValue gvalue = { 0, };
214 atk_value_get_maximum_value (value, &gvalue);
215 return droute_return_v_double (iter, get_double_from_gvalue (&gvalue));
219 impl_get_maximumValue_str (void *datum)
221 AtkValue *value = (AtkValue *) datum;
222 GValue gvalue = { 0, };
225 atk_value_get_maximum_value (value, &gvalue);
226 return g_strdup_printf ("%lf", get_double_from_gvalue (&gvalue));
230 impl_get_minimumIncrement (const char *path, DBusMessageIter * iter,
233 AtkValue *value = get_value_from_path (path, user_data);
234 GValue gvalue = { 0, };
237 atk_value_get_minimum_value (value, &gvalue);
238 return droute_return_v_double (iter, get_double_from_gvalue (&gvalue));
242 impl_get_minimumIncrement_str (void *datum)
244 AtkValue *value = (AtkValue *) datum;
245 GValue gvalue = { 0, };
248 atk_value_get_minimum_value (value, &gvalue);
249 return g_strdup_printf ("%lf", get_double_from_gvalue (&gvalue));
253 impl_get_currentValue (const char *path, DBusMessageIter * iter,
256 AtkValue *value = get_value_from_path (path, user_data);
257 GValue gvalue = { 0, };
260 atk_value_get_current_value (value, &gvalue);
261 return droute_return_v_double (iter, get_double_from_gvalue (&gvalue));
265 impl_get_currentValue_str (void *datum)
267 AtkValue *value = (AtkValue *) datum;
268 GValue gvalue = { 0, };
271 atk_value_get_current_value (value, &gvalue);
272 return g_strdup_printf ("%lf", get_double_from_gvalue (&gvalue));
276 impl_set_currentValue (const char *path, DBusMessageIter * iter,
279 AtkValue *value = get_value_from_path (path, user_data);
280 GValue gvalue = { 0, };
285 if (!get_double_from_variant (iter, &dbl))
287 atk_value_get_current_value (value, &gvalue);
288 gvalue_set_from_double (&gvalue, dbl);
292 static DRouteProperty properties[] = {
293 {impl_get_minimumValue, impl_get_minimumValue_str, NULL, NULL,
294 "minimumValue", "d"},
295 {impl_get_maximumValue, impl_get_maximumValue_str, NULL, NULL,
296 "maximumValue", "d"},
297 {impl_get_minimumIncrement, impl_get_minimumIncrement_str, NULL, NULL,
298 "minimumIncrement", "d"},
299 {impl_get_currentValue, impl_get_currentValue_str, impl_set_currentValue,
300 NULL, "currentValue", "d"},
301 {NULL, NULL, NULL, NULL, NULL, NULL}
305 spi_initialize_value (DRouteData * data)
307 droute_add_interface (data, "org.freedesktop.accessibility.Value", NULL,
309 (DRouteGetDatumFunction) get_value_from_path, NULL);