1
/*
2
 * AT-SPI - Assistive Technology Service Provider Interface
3
 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4
 *
5
 * Copyright 2001, 2002 Sun Microsystems Inc.,
6
 * Copyright 2001, 2002 Ximian, Inc.
7
 * Copyright 2010, 2011 Novell, 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 "atspi-private.h"
26

            
27
/**
28
 * AtspiValue:
29
 *
30
 * An interface supporting a one-dimensional scalar
31
 * to be modified, or which reflects its value.
32
 *
33
 * An interface supporting a one-dimensional scalar
34
 * to be modified, or which reflects its value. If
35
 * STATE_EDITABLE is not present, the value is
36
 * treated as "read only".
37
 */
38

            
39
/**
40
 * atspi_value_get_minimum_value:
41
 * @obj: a pointer to the #AtspiValue implementor on which to operate.
42
 *
43
 * Gets the minimum allowed value for an #AtspiValue.
44
 *
45
 * Returns: the minimum allowed value for this object.
46
 *
47
 **/
48
gdouble
49
1
atspi_value_get_minimum_value (AtspiValue *obj, GError **error)
50
{
51
  double retval;
52

            
53
1
  g_return_val_if_fail (obj != NULL, 0.0);
54
1
  _atspi_dbus_get_property (obj, atspi_interface_value, "MinimumValue", error, "d", &retval);
55

            
56
1
  return retval;
57
}
58

            
59
/**
60
 * atspi_value_get_current_value:
61
 * @obj: a pointer to the #AtspiValue implementor on which to operate.
62
 *
63
 * Gets the current value for an #AtspiValue.
64
 *
65
 * Returns: the current value for this object.
66
 **/
67
gdouble
68
2
atspi_value_get_current_value (AtspiValue *obj, GError **error)
69
{
70
  double retval;
71

            
72
2
  g_return_val_if_fail (obj != NULL, 0.0);
73

            
74
2
  _atspi_dbus_get_property (obj, atspi_interface_value, "CurrentValue", error, "d", &retval);
75

            
76
2
  return retval;
77
}
78

            
79
/**
80
 * atspi_value_get_maximum_value:
81
 * @obj: a pointer to the #AtspiValue implementor on which to operate.
82
 *
83
 * Gets the maximum allowed value for an #AtspiValue.
84
 *
85
 * Returns: the maximum allowed value for this object.
86
 **/
87
gdouble
88
1
atspi_value_get_maximum_value (AtspiValue *obj, GError **error)
89
{
90
  double retval;
91

            
92
1
  g_return_val_if_fail (obj != NULL, 0.0);
93

            
94
1
  _atspi_dbus_get_property (obj, atspi_interface_value, "MaximumValue", error, "d", &retval);
95

            
96
1
  return retval;
97
}
98

            
99
/**
100
 * atspi_value_set_current_value:
101
 * @obj: a pointer to the #AtspiValue implementor on which to operate.
102
 * @new_value: a #gdouble value which is the desired new value of the object.
103
 *
104
 * Sets the current value of an #AtspiValue.
105
 *
106
 * Returns: #TRUE if the value could be assigned the specified value,
107
 *          #FALSE otherwise.
108
 **/
109
gboolean
110
1
atspi_value_set_current_value (AtspiValue *obj, gdouble new_value, GError **error)
111
{
112
1
  double d_new_value = new_value;
113
  DBusMessage *message, *reply;
114
  DBusMessageIter iter, iter_variant;
115
  static const char *str_curval = "CurrentValue";
116
1
  AtspiAccessible *accessible = ATSPI_ACCESSIBLE (obj);
117

            
118
1
  g_return_val_if_fail (accessible != NULL, FALSE);
119

            
120
1
  if (!accessible->parent.app || !accessible->parent.app->bus_name)
121
    {
122
      g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_APPLICATION_GONE,
123
                           _ ("The application no longer exists"));
124
      return FALSE;
125
    }
126

            
127
1
  message = dbus_message_new_method_call (accessible->parent.app->bus_name,
128
1
                                          accessible->parent.path,
129
                                          DBUS_INTERFACE_PROPERTIES, "Set");
130
1
  if (!message)
131
    return FALSE;
132
1
  dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_value,
133
                            DBUS_TYPE_STRING, &str_curval,
134
                            DBUS_TYPE_INVALID);
135
1
  dbus_message_iter_init_append (message, &iter);
136
1
  dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "d", &iter_variant);
137
1
  dbus_message_iter_append_basic (&iter_variant, DBUS_TYPE_DOUBLE, &d_new_value);
138
1
  dbus_message_iter_close_container (&iter, &iter_variant);
139
1
  reply = _atspi_dbus_send_with_reply_and_block (message, error);
140
1
  dbus_message_unref (reply);
141

            
142
1
  return TRUE;
143
}
144

            
145
/**
146
 * atspi_value_get_minimum_increment:
147
 * @obj: a pointer to the #AtspiValue implementor on which to operate.
148
 *
149
 * Gets the minimum increment by which an #AtspiValue can be adjusted.
150
 *
151
 * Returns: the minimum increment by which the value may be changed, or
152
 * zero if the minimum increment cannot be determined.
153
 *
154
 **/
155
gdouble
156
1
atspi_value_get_minimum_increment (AtspiValue *obj, GError **error)
157
{
158
  double retval;
159

            
160
1
  g_return_val_if_fail (obj != NULL, 0.0);
161

            
162
1
  _atspi_dbus_get_property (obj, atspi_interface_value, "MinimumIncrement", error, "d", &retval);
163

            
164
1
  return retval;
165
}
166

            
167
/**
168
 * atspi_value_get_text:
169
 * @obj: a pointer to the #AtspiValue implementor on which to operate.
170
 *
171
 * Gets the human readable text alternative associated with the value.
172
 * @text is a newly created string, that must be freed by the
173
 * caller. Can be NULL if no descriptor is available.
174
 *
175
 * Since: 2.46
176
 **/
177
gchar *
178
1
atspi_value_get_text (AtspiValue *obj, GError **error)
179
{
180
1
  gchar *retval = NULL;
181

            
182
1
  g_return_val_if_fail (obj != NULL, NULL);
183

            
184
1
  _atspi_dbus_get_property (obj, atspi_interface_value, "Text", error, "s", &retval);
185

            
186
1
  return retval;
187
}
188

            
189
static void
190
4
atspi_value_base_init (AtspiValue *klass)
191
{
192
4
}
193

            
194
GType
195
9
atspi_value_get_type (void)
196
{
197
  static GType type = 0;
198

            
199
9
  if (!type)
200
    {
201
      static const GTypeInfo tinfo = {
202
        sizeof (AtspiValue),
203
        (GBaseInitFunc) atspi_value_base_init,
204
        (GBaseFinalizeFunc) NULL,
205
      };
206

            
207
2
      type = g_type_register_static (G_TYPE_INTERFACE, "AtspiValue", &tinfo, 0);
208
    }
209
9
  return type;
210
}