68631de93e075a4c40570d354bac4f89e3602638
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / value-adaptor.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2008 Novell, Inc.
6  * Copyright 2001, 2002 Sun Microsystems Inc.,
7  * Copyright 2001, 2002 Ximian, Inc.
8  *
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.
13  *
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.
18  *
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.
23  */
24
25 #include <math.h>
26
27 #include <atk/atk.h>
28 #include <droute/droute.h>
29
30 #include "spi-common/spi-dbus.h"
31
32 static dbus_bool_t
33 impl_get_minimumValue (DBusMessageIter * iter,
34                        void *user_data)
35 {
36   AtkValue *value = (AtkValue *) user_data;
37   GValue src = {0};
38   GValue dest = {0};
39   gdouble dub;
40
41   g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
42
43   atk_value_get_minimum_value (value, &src);
44   g_value_init (&dest, G_TYPE_DOUBLE);
45
46   if (g_value_transform (&src, &dest))
47     {
48       dub = g_value_get_double (&dest);
49       return droute_return_v_double (iter, dub);
50     }
51   else
52     {
53       return FALSE;
54     }
55 }
56
57 static dbus_bool_t
58 impl_get_maximumValue (DBusMessageIter * iter,
59                        void *user_data)
60 {
61   AtkValue *value = (AtkValue *) user_data;
62   GValue src = {0};
63   GValue dest = {0};
64   gdouble dub;
65
66   g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
67
68   atk_value_get_maximum_value (value, &src);
69   g_value_init (&dest, G_TYPE_DOUBLE);
70
71   if (g_value_transform (&src, &dest))
72     {
73       dub = g_value_get_double (&dest);
74       return droute_return_v_double (iter, dub);
75     }
76   else
77     {
78       return FALSE;
79     }
80 }
81
82 static dbus_bool_t
83 impl_get_minimumIncrement (DBusMessageIter * iter,
84                            void *user_data)
85 {
86   AtkValue *value = (AtkValue *) user_data;
87   GValue src = {0};
88   GValue dest = {0};
89   gdouble dub;
90
91   g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
92
93   atk_value_get_minimum_increment (value, &src);
94   g_value_init (&dest, G_TYPE_DOUBLE);
95
96   if (g_value_transform (&src, &dest))
97     {
98       dub = g_value_get_double (&dest);
99       return droute_return_v_double (iter, dub);
100     }
101   else
102     {
103       return FALSE;
104     }
105 }
106
107 static dbus_bool_t
108 impl_get_currentValue (DBusMessageIter * iter,
109                        void *user_data)
110 {
111   AtkValue *value = (AtkValue *) user_data;
112   GValue src = {0};
113   GValue dest = {0};
114   gdouble dub;
115
116   g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
117
118   atk_value_get_current_value (value, &src);
119   g_value_init (&dest, G_TYPE_DOUBLE);
120
121   if (g_value_transform (&src, &dest))
122     {
123       dub = g_value_get_double (&dest);
124       return droute_return_v_double (iter, dub);
125     }
126   else
127     {
128       return FALSE;
129     }
130 }
131
132 static dbus_bool_t
133 impl_set_currentValue (DBusMessageIter * iter,
134                        void *user_data)
135 {
136   AtkValue *value = (AtkValue *) user_data;
137   GValue src = {0};
138   GValue dest = {0};
139   gdouble dub;
140   DBusMessageIter iter_variant;
141
142   g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
143
144   dbus_message_iter_recurse (iter, &iter_variant);
145   if (dbus_message_iter_get_arg_type (&iter_variant) != DBUS_TYPE_DOUBLE)
146   {
147     G_WARNING ("TODO: Support setting value from a non-double");
148     return FALSE;
149   }
150   dbus_message_iter_get_basic (&iter_variant, &dub);
151   g_value_init (&src, G_TYPE_DOUBLE);
152   g_value_set_double (&src, dub);
153
154   atk_value_get_current_value (value, &dest);
155
156   if (g_value_transform (&src, &dest))
157     {
158       atk_value_set_current_value (value, &dest);
159       return TRUE;
160     }
161   else
162     {
163       return FALSE;
164     }
165 }
166
167 static DRouteProperty properties[] = {
168   {impl_get_minimumValue, NULL, "minimumValue"},
169   {impl_get_maximumValue, NULL, "maximumValue"},
170   {impl_get_minimumIncrement, NULL, "minimumIncrement"},
171   {impl_get_currentValue, impl_set_currentValue, "currentValue"},
172   {NULL, NULL, NULL}
173 };
174
175 void
176 spi_initialize_value (DRoutePath *path)
177 {
178   droute_path_add_interface (path,
179                              SPI_DBUS_INTERFACE_VALUE,
180                              NULL,
181                              properties);
182 };