2009-03-12 Mark Doffman <mark.doffman@codethink.co.uk>
[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       dbus_message_iter_append_basic (iter, DBUS_TYPE_DOUBLE, &dub);
50       return TRUE;
51     }
52   else
53     {
54       return FALSE;
55     }
56 }
57
58 static dbus_bool_t
59 impl_get_maximumValue (DBusMessageIter * iter,
60                        void *user_data)
61 {
62   AtkValue *value = (AtkValue *) user_data;
63   GValue src = {0};
64   GValue dest = {0};
65   gdouble dub;
66
67   g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
68
69   atk_value_get_maximum_value (value, &src);
70   g_value_init (&dest, G_TYPE_DOUBLE);
71
72   if (g_value_transform (&src, &dest))
73     {
74       dub = g_value_get_double (&dest);
75       dbus_message_iter_append_basic (iter, DBUS_TYPE_DOUBLE, &dub);
76       return TRUE;
77     }
78   else
79     {
80       return FALSE;
81     }
82 }
83
84 static dbus_bool_t
85 impl_get_minimumIncrement (DBusMessageIter * iter,
86                            void *user_data)
87 {
88   AtkValue *value = (AtkValue *) user_data;
89   GValue src = {0};
90   GValue dest = {0};
91   gdouble dub;
92
93   g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
94
95   atk_value_get_minimum_increment (value, &src);
96   g_value_init (&dest, G_TYPE_DOUBLE);
97
98   if (g_value_transform (&src, &dest))
99     {
100       dub = g_value_get_double (&dest);
101       dbus_message_iter_append_basic (iter, DBUS_TYPE_DOUBLE, &dub);
102       return TRUE;
103     }
104   else
105     {
106       return FALSE;
107     }
108 }
109
110 static dbus_bool_t
111 impl_get_currentValue (DBusMessageIter * iter,
112                        void *user_data)
113 {
114   AtkValue *value = (AtkValue *) user_data;
115   GValue src = {0};
116   GValue dest = {0};
117   gdouble dub;
118
119   g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
120
121   atk_value_get_current_value (value, &src);
122   g_value_init (&dest, G_TYPE_DOUBLE);
123
124   if (g_value_transform (&src, &dest))
125     {
126       dub = g_value_get_double (&dest);
127       dbus_message_iter_append_basic (iter, DBUS_TYPE_DOUBLE, &dub);
128       return TRUE;
129     }
130   else
131     {
132       return FALSE;
133     }
134 }
135
136 static dbus_bool_t
137 impl_set_currentValue (DBusMessageIter * iter,
138                        void *user_data)
139 {
140   AtkValue *value = (AtkValue *) user_data;
141   GValue src = {0};
142   GValue dest = {0};
143   gdouble dub;
144
145   g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
146
147   dbus_message_iter_get_basic (iter, &dub);
148   g_value_init (&src, G_TYPE_DOUBLE);
149   g_value_set_double (&src, dub);
150
151   atk_value_get_current_value (value, &dest);
152
153   if (g_value_transform (&src, &dest))
154     {
155       atk_value_set_current_value (value, &dest);
156       return TRUE;
157     }
158   else
159     {
160       return FALSE;
161     }
162 }
163
164 static DRouteProperty properties[] = {
165   {impl_get_minimumValue, NULL, "minimumValue"},
166   {impl_get_maximumValue, NULL, "maximumValue"},
167   {impl_get_minimumIncrement, NULL, "minimumIncrement"},
168   {impl_get_currentValue, impl_set_currentValue, "currentValue"},
169   {NULL, NULL, NULL}
170 };
171
172 void
173 spi_initialize_value (DRoutePath *path)
174 {
175   droute_path_add_interface (path,
176                              SPI_DBUS_INTERFACE_VALUE,
177                              NULL,
178                              properties);
179 };