packaging: exclude on non X11 configuration
[platform/core/uifw/at-spi2-core.git] / atspi / atspi-value.c
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 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 "atspi-private.h"
26
27 /**
28  * atspi_value_get_minimum_value:
29  * @obj: a pointer to the #AtspiValue implementor on which to operate. 
30  *
31  * Gets the minimum allowed value for an #AtspiValue.
32  *
33  * Returns: the minimum allowed value for this object.
34  *
35  **/
36 gdouble
37 atspi_value_get_minimum_value (AtspiValue *obj, GError **error)
38 {
39   double retval;
40
41   g_return_val_if_fail (obj != NULL, 0.0);
42   _atspi_dbus_get_property (obj, atspi_interface_value, "MinimumValue", error, "d", &retval);
43   
44   return retval;
45 }
46
47 /**
48  * atspi_value_get_current_value:
49  * @obj: a pointer to the #AtspiValue implementor on which to operate. 
50  *
51  * Gets the current value for an #AtspiValue.
52  *
53  * Returns: the current value for this object.
54  **/
55 gdouble
56 atspi_value_get_current_value (AtspiValue *obj, GError **error)
57 {
58   double retval;
59
60   g_return_val_if_fail (obj != NULL, 0.0);
61
62   _atspi_dbus_get_property (obj, atspi_interface_value, "CurrentValue", error, "d", &retval);
63
64   return retval;
65 }
66
67 /**
68  * atspi_value_get_maximum_value:
69  * @obj: a pointer to the #AtspiValue implementor on which to operate. 
70  *
71  * Gets the maximum allowed value for an #AtspiValue.
72  *
73  * Returns: the maximum allowed value for this object.
74  **/
75 gdouble
76 atspi_value_get_maximum_value (AtspiValue *obj, GError **error)
77 {
78   double retval;        
79
80   g_return_val_if_fail (obj != NULL, 0.0);
81
82   _atspi_dbus_get_property (obj, atspi_interface_value, "MaximumValue", error, "d", &retval);
83
84   return retval;
85 }
86
87 /**
88  * atspi_value_set_current_value:
89  * @obj: a pointer to the #AtspiValue implementor on which to operate.
90  * @new_value: a #gdouble value which is the desired new value of the object.
91  *
92  * Sets the current value of an #AtspiValue.
93  *
94  * Returns: #TRUE if the value could be assigned the specified value,
95  *          #FALSE otherwise.
96  **/
97 gboolean
98 atspi_value_set_current_value (AtspiValue *obj, gdouble new_value, GError **error)
99 {
100   double d_new_value = new_value;
101   DBusMessage *message, *reply;
102   DBusMessageIter iter, iter_variant;
103   static const char *str_curval = "CurrentValue";
104   AtspiAccessible *accessible = ATSPI_ACCESSIBLE (obj);
105
106   g_return_val_if_fail (accessible != NULL, FALSE);
107
108   if (!accessible->parent.app || !accessible->parent.app->bus_name)
109 {
110     g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_APPLICATION_GONE,
111                           _("The application no longer exists"));
112     return FALSE;
113   }
114
115     message = dbus_message_new_method_call (accessible->parent.app->bus_name,
116                                             accessible->parent.path,
117                                             DBUS_INTERFACE_PROPERTIES, "Set");
118     if (!message)
119       return FALSE;
120     dbus_message_append_args (message, DBUS_TYPE_STRING, &atspi_interface_value,
121                                DBUS_TYPE_STRING, &str_curval,
122                               DBUS_TYPE_INVALID);
123   dbus_message_iter_init_append (message, &iter);
124   dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "d", &iter_variant);
125   dbus_message_iter_append_basic (&iter_variant, DBUS_TYPE_DOUBLE, &d_new_value);
126   dbus_message_iter_close_container (&iter, &iter_variant);
127     reply = _atspi_dbus_send_with_reply_and_block (message, error);
128   dbus_message_unref (reply);
129
130   return TRUE;
131 }
132
133 /**
134  * atspi_value_get_minimum_increment:
135  * @obj: a pointer to the #AtspiValue implementor on which to operate. 
136  *
137  * Gets the minimum increment by which an #AtspiValue can be adjusted.
138  *
139  * Returns: the minimum increment by which the value may be changed, or
140  * zero if the minimum increment cannot be determined.
141  *
142  **/
143 gdouble
144 atspi_value_get_minimum_increment (AtspiValue *obj, GError **error)
145 {
146   double retval;
147
148   g_return_val_if_fail (obj != NULL, 0.0);
149
150   _atspi_dbus_get_property (obj, atspi_interface_value, "MinimumIncrement", error, "d", &retval);
151   
152   return retval;
153 }
154
155 static void
156 atspi_value_base_init (AtspiValue *klass)
157 {
158 }
159
160 GType
161 atspi_value_get_type (void)
162 {
163   static GType type = 0;
164
165   if (!type) {
166     static const GTypeInfo tinfo =
167     {
168       sizeof (AtspiValue),
169       (GBaseInitFunc) atspi_value_base_init,
170       (GBaseFinalizeFunc) NULL,
171     };
172
173     type = g_type_register_static (G_TYPE_INTERFACE, "AtspiValue", &tinfo, 0);
174
175   }
176   return type;
177 }