Modified Value.idl interface to use unions, removes the assumption that
[platform/core/uifw/at-spi2-atk.git] / cspi / spi_value.c
1 #include <cspi/spi-private.h>
2
3 static void
4 svalue_set_from_float (Accessibility_SValue *sval, float newValue)
5 {
6   switch (sval->_d)
7     {
8       case Accessibility_SHORTVAL:
9         sval->_u.val_short = CLAMP (newValue, G_MINSHORT, G_MAXSHORT);
10         break;
11       case Accessibility_USHORTVAL:         
12         sval->_u.val_ushort = CLAMP (newValue, 0, G_MAXUSHORT);
13         break;
14       case Accessibility_LONGVAL:           
15         sval->_u.val_long = CLAMP (newValue, G_MINLONG, G_MAXLONG);
16         break;
17       case Accessibility_ULONGVAL:          
18         sval->_u.val_ulong = CLAMP (newValue, 0, G_MAXULONG);
19         break;
20       case Accessibility_FLOATVAL:          
21         sval->_u.val_float = newValue;
22         break;
23       case Accessibility_DOUBLEVAL:         
24         sval->_u.val_double = newValue;
25         break;
26     }
27 }
28
29
30 static float
31 svalue_to_float (Accessibility_SValue *sval)
32 {
33   float retval = 0.0;
34   switch (sval->_d)
35     {
36       case Accessibility_SHORTVAL:
37         retval = sval->_u.val_short;
38         break;
39       case Accessibility_USHORTVAL:         
40         retval = sval->_u.val_ushort;
41         break;
42       case Accessibility_LONGVAL:           
43         retval = sval->_u.val_long;
44         break;
45       case Accessibility_ULONGVAL:          
46         retval = sval->_u.val_ulong;
47         break;
48       case Accessibility_FLOATVAL:          
49         retval = sval->_u.val_float;
50         break;
51       case Accessibility_DOUBLEVAL:         
52         retval = sval->_u.val_double;
53         break;
54     }
55
56   return retval;
57 }
58
59
60 /**
61  * AccessibleValue_ref:
62  * @obj: a pointer to the #AccessibleValue implementor on which to operate.
63  *
64  * Increment the reference count for an #AccessibleValue object.
65  **/
66 void
67 AccessibleValue_ref (AccessibleValue *obj)
68 {
69   cspi_object_ref (obj);
70 }
71
72 /**
73  * AccessibleValue_unref:
74  * @obj: a pointer to the #AccessibleValue implementor on which to operate. 
75  *
76  * Decrement the reference count for an #AccessibleValue object.
77  **/
78 void
79 AccessibleValue_unref (AccessibleValue *obj)
80 {
81   cspi_object_unref (obj);
82 }
83
84 /**
85  * AccessibleValue_getMinimumValue:
86  * @obj: a pointer to the #AccessibleValue implementor on which to operate. 
87  *
88  * Get the minimum allowed value for an #AccessibleValue.
89  *
90  * Returns: the minimum allowed value for this object.
91  *
92  **/
93 float
94 AccessibleValue_getMinimumValue (AccessibleValue *obj)
95 {
96   Accessibility_SValue sval;
97
98   cspi_return_val_if_fail (obj != NULL, 0.0);
99
100   sval = 
101     Accessibility_Value__get_minimumValue (CSPI_OBJREF (obj), cspi_ev ());
102   
103   cspi_return_val_if_ev ("getMinimumValue", 0.0);
104
105   return svalue_to_float (&sval);
106 }
107
108 /**
109  * AccessibleValue_getCurrentValue:
110  * @obj: a pointer to the #AccessibleValue implementor on which to operate. 
111  *
112  * Get the current value for an #AccessibleValue.
113  *
114  * Returns: the current value for this object.
115  **/
116 float
117 AccessibleValue_getCurrentValue (AccessibleValue *obj)
118 {
119   Accessibility_SValue sval;
120
121   cspi_return_val_if_fail (obj != NULL, 0.0);
122
123   sval =
124     Accessibility_Value__get_currentValue (CSPI_OBJREF (obj), cspi_ev ());
125
126   cspi_return_val_if_ev ("getCurrentValue", 0.0);
127
128   return svalue_to_float (&sval);
129 }
130
131 /**
132  * AccessibleValue_getMaximumValue:
133  * @obj: a pointer to the #AccessibleValue implementor on which to operate. 
134  *
135  * Get the maximum allowed value for an #AccessibleValue.
136  *
137  * Returns: the maximum allowed value for this object.
138  **/
139 float
140 AccessibleValue_getMaximumValue (AccessibleValue *obj)
141 {
142   Accessibility_SValue sval;
143
144   cspi_return_val_if_fail (obj != NULL, 0.0);
145
146   sval =
147     Accessibility_Value__get_maximumValue (CSPI_OBJREF (obj), cspi_ev ());
148
149   cspi_return_val_if_ev ("getMaximumValue", 0.0);
150
151   return svalue_to_float (&sval);
152 }
153
154 /**
155  * AccessibleValue_setCurrentValue:
156  * @obj: a pointer to the #AccessibleValue implementor on which to operate.
157  * @newValue: a #float value which is the desired new value of the object.
158  *
159  * Set the current value of an #AccessibleValue.
160  *
161  * Returns: #TRUE if the value could be assigned the specified value,
162  *          #FALSE otherwise.
163  **/
164 SPIBoolean
165 AccessibleValue_setCurrentValue (AccessibleValue *obj,
166                                  float newValue)
167 {
168   Accessibility_SValue sval;    
169   cspi_return_val_if_fail (obj != NULL, FALSE);
170
171   /* erk, this is ugly */
172   sval = Accessibility_Value__get_currentValue (
173     CSPI_OBJREF (obj), cspi_ev ());
174
175   svalue_set_from_float (&sval, newValue);
176   
177   Accessibility_Value__set_currentValue (
178     CSPI_OBJREF (obj), &sval, cspi_ev ());
179
180   cspi_return_val_if_ev ("setCurrentValue", FALSE);
181
182   return TRUE;
183 }
184
185