Removed po directory from Makefile.am for now.
[platform/core/uifw/at-spi2-atk.git] / libspi / 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 Sun Microsystems Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /* value.c : implements the Value interface */
24 #include <config.h>
25 #include <stdio.h>
26 #include <libspi/value.h>
27
28 #define PARENT_TYPE SPI_TYPE_BASE
29
30 /* Static function declarations */
31
32 static void
33 spi_value_class_init (SpiValueClass *klass);
34 static void
35 spi_value_init (SpiValue *value);
36 static CORBA_float
37 impl__get_minimumValue (PortableServer_Servant _servant,
38                         CORBA_Environment * ev);
39 static        CORBA_float
40 impl__get_maximumValue (PortableServer_Servant _servant,
41                         CORBA_Environment * ev);
42 static CORBA_float
43 impl__get_currentValue (PortableServer_Servant _servant,
44                         CORBA_Environment * ev);
45 static void 
46 impl__set_currentValue (PortableServer_Servant _servant,
47                         const CORBA_float value,
48                         CORBA_Environment * ev);
49
50
51 BONOBO_TYPE_FUNC_FULL (SpiValue,
52                        Accessibility_Value,
53                        PARENT_TYPE,
54                        spi_value);
55
56
57 static void
58 spi_value_class_init (SpiValueClass *klass)
59 {
60   POA_Accessibility_Value__epv *epv = &klass->epv;
61
62   /* Initialize epv table */
63
64   epv->_get_minimumValue = impl__get_minimumValue;
65   epv->_get_maximumValue = impl__get_maximumValue;
66   epv->_get_currentValue = impl__get_currentValue;
67   epv->_set_currentValue = impl__set_currentValue;
68 }
69
70
71 static void
72 spi_value_init (SpiValue *value)
73 {
74 }
75
76
77 SpiValue *
78 spi_value_interface_new (AtkObject *obj)
79 {
80   SpiValue *new_value = g_object_new (SPI_VALUE_TYPE, NULL);
81
82   spi_base_construct (SPI_BASE (new_value), obj);
83
84   return new_value;
85 }
86
87
88 static AtkValue *
89 get_value_from_servant (PortableServer_Servant servant)
90 {
91   SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
92
93   if (!object)
94     {
95       return NULL;
96     }
97
98   return ATK_VALUE (object->atko);
99 }
100
101
102 static CORBA_float
103 impl__get_minimumValue (PortableServer_Servant servant,
104                         CORBA_Environment     *ev)
105 {
106   GValue    gvalue = {0, };
107   AtkValue *value = get_value_from_servant (servant);
108
109   g_return_val_if_fail (value != NULL, 0.0);
110
111   /*
112    * FIXME: ahem, there's no guarantee that
113    * atk_value_get_minimum_value returns a float.
114    * What we really need is a generic value API here
115    */
116
117   g_value_init (&gvalue, G_TYPE_FLOAT);
118   atk_value_get_minimum_value (value, &gvalue);
119
120   return (CORBA_float) g_value_get_float (&gvalue);
121 }
122
123
124 static CORBA_float
125 impl__get_maximumValue (PortableServer_Servant servant,
126                         CORBA_Environment     *ev)
127 {
128   GValue   gvalue = {0, };
129   AtkValue *value = get_value_from_servant (servant);
130
131   g_return_val_if_fail (value != NULL, 0.0);
132
133   g_value_init (&gvalue, G_TYPE_FLOAT);
134   atk_value_get_maximum_value (value, &gvalue);
135
136   return (CORBA_float) g_value_get_float (&gvalue);
137 }
138
139
140 static CORBA_float
141 impl__get_currentValue (PortableServer_Servant servant,
142                         CORBA_Environment     *ev)
143 {
144   GValue   gvalue = {0, };
145   AtkValue *value = get_value_from_servant (servant);
146
147   g_return_val_if_fail (value != NULL, 0.0);
148
149   g_value_init (&gvalue, G_TYPE_FLOAT);
150   atk_value_get_current_value (value, &gvalue);
151
152   return (CORBA_float) g_value_get_float (&gvalue);
153 }
154
155
156 static void 
157 impl__set_currentValue (PortableServer_Servant servant,
158                         const CORBA_float      value,
159                         CORBA_Environment     *ev)
160 {
161   GValue    gvalue = {0, };
162   AtkValue *avalue = get_value_from_servant (servant);
163
164   g_return_if_fail (avalue != NULL);
165
166   g_value_init (&gvalue, G_TYPE_FLOAT);
167   g_value_set_float (&gvalue, (gfloat) value);
168
169   atk_value_set_current_value (avalue, &gvalue);
170 }
171
172