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