1216a21ce257abe45a528a8db41613b405318897
[platform/upstream/atk.git] / atk / atkvalue.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <string.h>
19 #include "atkvalue.h"
20
21 /**
22  * SECTION:atkvalue
23  * @Short_description: The ATK interface implemented by valuators and
24  *  components which display or select a value from a bounded range of
25  *  values.
26  * @Title:AtkValue
27  *
28  * #AtkValue should be implemented for components which either display
29  * a value from a bounded range, or which allow the user to specify a
30  * value from a bounded range, or both.  For instance, most sliders
31  * and range controls, as well as dials, should have #AtkObject
32  * representations which implement #AtkValue on the component's
33  * behalf.  #AtKValues may be read-only, in which case attempts to
34  * alter the value return FALSE to indicate failure.
35  */
36
37 GType
38 atk_value_get_type (void)
39 {
40   static GType type = 0;
41
42   if (!type) {
43     GTypeInfo tinfo =
44     {
45       sizeof (AtkValueIface),
46       (GBaseInitFunc) NULL,
47       (GBaseFinalizeFunc) NULL,
48
49     };
50
51     type = g_type_register_static (G_TYPE_INTERFACE, "AtkValue", &tinfo, 0);
52   }
53
54   return type;
55 }
56
57 /**
58  * atk_value_get_current_value:
59  * @obj: a GObject instance that implements AtkValueIface
60  * @value: a #GValue representing the current accessible value
61  *
62  * Gets the value of this object.
63  **/
64 void
65 atk_value_get_current_value (AtkValue *obj,
66                              GValue   *value)
67 {
68   AtkValueIface *iface;
69
70   g_return_if_fail (value != NULL);
71   g_return_if_fail (ATK_IS_VALUE (obj));
72
73   iface = ATK_VALUE_GET_IFACE (obj);
74
75   if (iface->get_current_value)
76     {
77       if (G_IS_VALUE (value))
78         g_value_unset (value);
79       else
80         memset (value, 0, sizeof (*value));
81
82       (iface->get_current_value) (obj, value);
83     }
84 }
85
86 /**
87  * atk_value_get_maximum_value:
88  * @obj: a GObject instance that implements AtkValueIface
89  * @value: a #GValue representing the maximum accessible value
90  *
91  * Gets the maximum value of this object.
92  **/
93 void
94 atk_value_get_maximum_value  (AtkValue *obj,
95                               GValue   *value)
96 {
97   AtkValueIface *iface;
98
99   g_return_if_fail (value != NULL);
100   g_return_if_fail (ATK_IS_VALUE (obj));
101
102   iface = ATK_VALUE_GET_IFACE (obj);
103
104   if (iface->get_maximum_value)
105     {
106       if (G_IS_VALUE (value))
107         g_value_unset (value);
108       else
109         memset (value, 0, sizeof (*value));
110
111       (iface->get_maximum_value) (obj, value);
112     }
113 }
114
115 /**
116  * atk_value_get_minimum_value:
117  * @obj: a GObject instance that implements AtkValueIface
118  * @value: a #GValue representing the minimum accessible value
119  *
120  * Gets the minimum value of this object.
121  **/
122 void
123 atk_value_get_minimum_value (AtkValue *obj,
124                              GValue   *value)
125 {
126   AtkValueIface *iface;
127
128   g_return_if_fail (value != NULL);
129   g_return_if_fail (ATK_IS_VALUE (obj));
130
131   iface = ATK_VALUE_GET_IFACE (obj);
132
133   if (iface->get_minimum_value)
134     {
135       if (G_IS_VALUE (value))
136         g_value_unset (value);
137       else
138         memset (value, 0, sizeof (*value));
139
140       (iface->get_minimum_value) (obj, value);
141     }
142 }
143
144 /**
145  * atk_value_get_minimum_increment:
146  * @obj: a GObject instance that implements AtkValueIface
147  * @value: a #GValue representing the minimum increment by which the accessible value may be changed
148  *
149  * Gets the minimum increment by which the value of this object may be changed.  If zero,
150  * the minimum increment is undefined, which may mean that it is limited only by the 
151  * floating point precision of the platform.
152  *
153  * Since: 1.12
154  **/
155 void
156 atk_value_get_minimum_increment (AtkValue *obj,
157                              GValue   *value)
158 {
159   AtkValueIface *iface;
160
161   g_return_if_fail (value != NULL);
162   g_return_if_fail (ATK_IS_VALUE (obj));
163
164   iface = ATK_VALUE_GET_IFACE (obj);
165
166   if (iface->get_minimum_increment)
167     {
168       if (G_IS_VALUE (value))
169         g_value_unset (value);
170       else
171         memset (value, 0, sizeof (*value));
172
173       (iface->get_minimum_increment) (obj, value);
174     }
175 }
176
177 /**
178  * atk_value_set_current_value:
179  * @obj: a GObject instance that implements AtkValueIface
180  * @value: a #GValue which is the desired new accessible value.
181  *
182  * Sets the value of this object.
183  *
184  * Returns: %TRUE if new value is successfully set, %FALSE otherwise.
185  **/
186 gboolean
187 atk_value_set_current_value (AtkValue       *obj, 
188                              const GValue   *value)
189 {
190   AtkValueIface *iface;
191
192   g_return_val_if_fail (ATK_IS_VALUE (obj), FALSE);
193   g_return_val_if_fail (G_IS_VALUE (value), FALSE);
194
195   iface = ATK_VALUE_GET_IFACE (obj);
196
197   if (iface->set_current_value)
198     return (iface->set_current_value) (obj, value);
199   else
200     return FALSE;
201 }