Removed the extra boolean parameter added to know when to unref the
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / adaptors / 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 "common/spi-dbus.h"
31 #include "introspection.h"
32
33 static dbus_bool_t
34 impl_get_MinimumValue (DBusMessageIter * iter, 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, void *user_data)
59 {
60   AtkValue *value = (AtkValue *) user_data;
61   GValue src = { 0 };
62   GValue dest = { 0 };
63   gdouble dub;
64
65   g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
66
67   atk_value_get_maximum_value (value, &src);
68   g_value_init (&dest, G_TYPE_DOUBLE);
69
70   if (g_value_transform (&src, &dest))
71     {
72       dub = g_value_get_double (&dest);
73       return droute_return_v_double (iter, dub);
74     }
75   else
76     {
77       return FALSE;
78     }
79 }
80
81 static dbus_bool_t
82 impl_get_MinimumIncrement (DBusMessageIter * iter, void *user_data)
83 {
84   AtkValue *value = (AtkValue *) user_data;
85   GValue src = { 0 };
86   GValue dest = { 0 };
87   gdouble dub;
88
89   g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
90
91   atk_value_get_minimum_increment (value, &src);
92   g_value_init (&dest, G_TYPE_DOUBLE);
93
94   if (g_value_transform (&src, &dest))
95     {
96       dub = g_value_get_double (&dest);
97       return droute_return_v_double (iter, dub);
98     }
99   else
100     {
101       return FALSE;
102     }
103 }
104
105 static dbus_bool_t
106 impl_get_CurrentValue (DBusMessageIter * iter, void *user_data)
107 {
108   AtkValue *value = (AtkValue *) user_data;
109   GValue src = { 0 };
110   GValue dest = { 0 };
111   gdouble dub;
112
113   g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
114
115   atk_value_get_current_value (value, &src);
116   g_value_init (&dest, G_TYPE_DOUBLE);
117
118   if (g_value_transform (&src, &dest))
119     {
120       dub = g_value_get_double (&dest);
121       return droute_return_v_double (iter, dub);
122     }
123   else
124     {
125       return FALSE;
126     }
127 }
128
129 static dbus_bool_t
130 impl_set_currentValue (DBusMessageIter * iter, void *user_data)
131 {
132   AtkValue *value = (AtkValue *) user_data;
133   GValue src = { 0 };
134   GValue dest = { 0 };
135   gdouble dub;
136   DBusMessageIter iter_variant;
137
138   g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
139
140   dbus_message_iter_recurse (iter, &iter_variant);
141   if (dbus_message_iter_get_arg_type (&iter_variant) != DBUS_TYPE_DOUBLE)
142     {
143       g_warning ("TODO: Support setting value from a non-double");
144       return FALSE;
145     }
146   dbus_message_iter_get_basic (&iter_variant, &dub);
147   g_value_init (&src, G_TYPE_DOUBLE);
148   g_value_set_double (&src, dub);
149
150   atk_value_get_current_value (value, &dest);
151
152   if (g_value_transform (&src, &dest))
153     {
154       atk_value_set_current_value (value, &dest);
155       return TRUE;
156     }
157   else
158     {
159       return FALSE;
160     }
161 }
162
163 static DRouteProperty properties[] = {
164   {impl_get_MinimumValue, NULL, "MinimumValue"},
165   {impl_get_MaximumValue, NULL, "MaximumValue"},
166   {impl_get_MinimumIncrement, NULL, "MinimumIncrement"},
167   {impl_get_CurrentValue, impl_set_currentValue, "CurrentValue"},
168   {NULL, NULL, NULL}
169 };
170
171 void
172 spi_initialize_value (DRoutePath * path)
173 {
174   droute_path_add_interface (path,
175                              SPI_DBUS_INTERFACE_VALUE, spi_org_a11y_atspi_Value, NULL, properties);
176 };