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 Lesser General Public
11
 * License as published by the Free Software Foundation; either
12
 * version 2.1 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
 * Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public
20
 * License along with this library; if not, write to the
21
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22
 * Boston, MA 02110-1301, USA.
23
 */
24

            
25
#include <math.h>
26

            
27
#define ATK_DISABLE_DEPRECATION_WARNINGS
28
#include "bridge.h"
29
#include <atk/atk.h>
30
#include <droute/droute.h>
31

            
32
#include "introspection.h"
33
#include "spi-dbus.h"
34

            
35
static dbus_bool_t
36
1
impl_get_MinimumValue (DBusMessageIter *iter, void *user_data)
37
{
38
1
  AtkValue *value = (AtkValue *) user_data;
39
1
  GValue src = { 0 };
40
1
  GValue dest = { 0 };
41
  gdouble dub;
42

            
43
1
  g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
44
1
  AtkValueIface *iface = ATK_VALUE_GET_IFACE (value);
45
1
  if (iface->get_range)
46
    {
47
1
      AtkRange *range = atk_value_get_range (value);
48
1
      dub = atk_range_get_lower_limit (range);
49
1
      atk_range_free (range);
50
1
      return droute_return_v_double (iter, dub);
51
    }
52

            
53
  g_value_init (&src, G_TYPE_DOUBLE);
54
  atk_value_get_minimum_value (value, &src);
55
  g_value_init (&dest, G_TYPE_DOUBLE);
56

            
57
  if (g_value_transform (&src, &dest))
58
    {
59
      dub = g_value_get_double (&dest);
60
      return droute_return_v_double (iter, dub);
61
    }
62
  else
63
    {
64
      return FALSE;
65
    }
66
}
67

            
68
static dbus_bool_t
69
1
impl_get_MaximumValue (DBusMessageIter *iter, void *user_data)
70
{
71
1
  AtkValue *value = (AtkValue *) user_data;
72
1
  GValue src = { 0 };
73
1
  GValue dest = { 0 };
74
1
  gdouble dub = 0;
75

            
76
1
  g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
77

            
78
1
  AtkValueIface *iface = ATK_VALUE_GET_IFACE (value);
79
1
  if (iface->get_range)
80
    {
81
1
      AtkRange *range = atk_value_get_range (value);
82
1
      dub = atk_range_get_upper_limit (range);
83
1
      atk_range_free (range);
84
1
      return droute_return_v_double (iter, dub);
85
    }
86

            
87
  g_value_init (&src, G_TYPE_DOUBLE);
88
  atk_value_get_maximum_value (value, &src);
89
  g_value_init (&dest, G_TYPE_DOUBLE);
90

            
91
  if (g_value_transform (&src, &dest))
92
    {
93
      dub = g_value_get_double (&dest);
94
    }
95
  return droute_return_v_double (iter, dub);
96
}
97

            
98
static dbus_bool_t
99
1
impl_get_MinimumIncrement (DBusMessageIter *iter, void *user_data)
100
{
101
1
  AtkValue *value = (AtkValue *) user_data;
102
1
  GValue src = { 0 };
103
1
  GValue dest = { 0 };
104
1
  gdouble dub = 0;
105

            
106
1
  g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
107

            
108
1
  AtkValueIface *iface = ATK_VALUE_GET_IFACE (value);
109
1
  if (iface->get_increment)
110
    {
111
1
      dub = atk_value_get_increment (value);
112
1
      return droute_return_v_double (iter, dub);
113
    }
114

            
115
  g_value_init (&src, G_TYPE_DOUBLE);
116
  atk_value_get_minimum_increment (value, &src);
117
  g_value_init (&dest, G_TYPE_DOUBLE);
118

            
119
  if (g_value_transform (&src, &dest))
120
    {
121
      dub = g_value_get_double (&dest);
122
    }
123
  return droute_return_v_double (iter, dub);
124
}
125

            
126
static dbus_bool_t
127
2
impl_get_CurrentValue (DBusMessageIter *iter, void *user_data)
128
{
129
2
  AtkValue *value = (AtkValue *) user_data;
130
2
  GValue src = { 0 };
131
2
  GValue dest = { 0 };
132
2
  gdouble dub = 0;
133

            
134
2
  g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
135

            
136
2
  AtkValueIface *iface = ATK_VALUE_GET_IFACE (value);
137
2
  if (iface->get_value_and_text)
138
    {
139
2
      gchar *text = NULL;
140
2
      atk_value_get_value_and_text (value, &dub, &text);
141
2
      return droute_return_v_double (iter, dub);
142
    }
143

            
144
  g_value_init (&src, G_TYPE_DOUBLE);
145
  atk_value_get_current_value (value, &src);
146
  g_value_init (&dest, G_TYPE_DOUBLE);
147

            
148
  if (g_value_transform (&src, &dest))
149
    {
150
      dub = g_value_get_double (&dest);
151
    }
152
  return droute_return_v_double (iter, dub);
153
}
154

            
155
static dbus_bool_t
156
1
impl_set_CurrentValue (DBusMessageIter *iter, void *user_data)
157
{
158
1
  AtkValue *value = (AtkValue *) user_data;
159
1
  GValue src = { 0 };
160
1
  GValue dest = { 0 };
161
  gdouble dub;
162
  DBusMessageIter iter_variant;
163

            
164
1
  g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
165

            
166
1
  dbus_message_iter_recurse (iter, &iter_variant);
167
1
  if (dbus_message_iter_get_arg_type (&iter_variant) != DBUS_TYPE_DOUBLE)
168
    {
169
      g_warning ("TODO: Support setting value from a non-double");
170
      return FALSE;
171
    }
172
1
  dbus_message_iter_get_basic (&iter_variant, &dub);
173

            
174
1
  AtkValueIface *iface = ATK_VALUE_GET_IFACE (value);
175
1
  if (iface->set_value)
176
    {
177
1
      atk_value_set_value (value, dub);
178
1
      return TRUE;
179
    }
180

            
181
  g_value_init (&src, G_TYPE_DOUBLE);
182
  g_value_set_double (&src, dub);
183

            
184
  atk_value_get_current_value (value, &dest);
185

            
186
  if (g_value_transform (&src, &dest))
187
    {
188
      atk_value_set_current_value (value, &dest);
189
      return TRUE;
190
    }
191
  else
192
    {
193
      return FALSE;
194
    }
195
}
196

            
197
/* keeping this method around for backwards-compatibility for now; see
198
 *  * BGO#652596 */
199
static DBusMessage *
200
impl_SetCurrentValue (DBusConnection *bus, DBusMessage *message, void *user_data)
201
{
202
  AtkValue *value = (AtkValue *) user_data;
203
  dbus_bool_t rv;
204
  DBusMessage *reply;
205
  gdouble dub = 0;
206
  GValue new_value = { 0 };
207

            
208
  g_return_val_if_fail (ATK_IS_VALUE (value),
209
                        droute_not_yet_handled_error (message));
210

            
211
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_DOUBLE, &dub, DBUS_TYPE_INVALID))
212
    {
213
      return droute_invalid_arguments_error (message);
214
    }
215

            
216
  g_value_init (&new_value, G_TYPE_DOUBLE);
217
  g_value_set_double (&new_value, dub);
218
  rv = atk_value_set_current_value (value, &new_value);
219

            
220
  reply = dbus_message_new_method_return (message);
221
  if (reply)
222
    {
223
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
224
                                DBUS_TYPE_INVALID);
225
    }
226
  return reply;
227
}
228

            
229
static dbus_bool_t
230
1
impl_get_Text (DBusMessageIter *iter, void *user_data)
231
{
232
1
  AtkValue *value = (AtkValue *) user_data;
233
  gdouble dub;
234
1
  gchar *text = NULL;
235
  dbus_bool_t ret;
236

            
237
1
  g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
238

            
239
1
  AtkValueIface *iface = ATK_VALUE_GET_IFACE (value);
240
1
  if (iface->get_value_and_text)
241
    {
242
1
      atk_value_get_value_and_text (value, &dub, &text);
243
1
      ret = droute_return_v_string (iter, text);
244
1
      g_free (text);
245
1
      return ret;
246
    }
247

            
248
  return droute_return_v_string (iter, "");
249
}
250

            
251
static DRouteMethod methods[] = {
252
  { impl_SetCurrentValue, "SetCurrentValue" },
253
  { NULL, NULL }
254
};
255

            
256
static DRouteProperty properties[] = {
257
  { impl_get_MinimumValue, NULL, "MinimumValue" },
258
  { impl_get_MaximumValue, NULL, "MaximumValue" },
259
  { impl_get_MinimumIncrement, NULL, "MinimumIncrement" },
260
  { impl_get_CurrentValue, impl_set_CurrentValue, "CurrentValue" },
261
  { impl_get_Text, NULL, "Text" },
262
  { NULL, NULL, NULL }
263
};
264

            
265
void
266
161
spi_initialize_value (DRoutePath *path)
267
{
268
161
  spi_atk_add_interface (path,
269
                         ATSPI_DBUS_INTERFACE_VALUE, spi_org_a11y_atspi_Value, methods, properties);
270
161
};