c099b2ca5cb4968d5eda5e11e3308bfc16cda54e
[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 /* Static function declarations */
29
30 static void
31 spi_value_class_init (SpiValueClass *klass);
32 static void
33 spi_value_init (SpiValue *value);
34 static CORBA_float
35 impl__get_minimumValue (PortableServer_Servant _servant,
36                         CORBA_Environment * ev);
37 static        CORBA_float
38 impl__get_maximumValue (PortableServer_Servant _servant,
39                         CORBA_Environment * ev);
40 static CORBA_float
41 impl__get_currentValue (PortableServer_Servant _servant,
42                         CORBA_Environment * ev);
43 static void 
44 impl__set_currentValue (PortableServer_Servant _servant,
45                         const CORBA_float value,
46                         CORBA_Environment * ev);
47
48
49 BONOBO_TYPE_FUNC_FULL (SpiValue,
50                        Accessibility_Value,
51                        BONOBO_TYPE_OBJECT,
52                        spi_value);
53
54
55 static void
56 spi_value_class_init (SpiValueClass *klass)
57 {
58   POA_Accessibility_Value__epv *epv = &klass->epv;
59
60   /* Initialize epv table */
61
62   epv->_get_minimumValue = impl__get_minimumValue;
63   epv->_get_maximumValue = impl__get_maximumValue;
64   epv->_get_currentValue = impl__get_currentValue;
65   epv->_set_currentValue = impl__set_currentValue;
66 }
67
68
69 static void
70 spi_value_init (SpiValue *value)
71 {
72 }
73
74
75 SpiValue *
76 spi_value_interface_new (AtkObject *obj)
77 {
78   SpiValue *new_value = g_object_new (SPI_VALUE_TYPE, NULL);
79
80   spi_base_construct (SPI_BASE (new_value), obj);
81
82   return new_value;
83 }
84
85
86 static AtkValue *
87 get_value_from_servant (PortableServer_Servant servant)
88 {
89   SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
90
91   if (!object)
92     {
93       return NULL;
94     }
95
96   return ATK_VALUE (object->atko);
97 }
98
99
100 static CORBA_float
101 impl__get_minimumValue (PortableServer_Servant servant,
102                         CORBA_Environment     *ev)
103 {
104   GValue    gvalue = {0, };
105   AtkValue *value = get_value_from_servant (servant);
106
107   g_return_val_if_fail (value != NULL, 0.0);
108
109   g_value_init (&gvalue, G_TYPE_FLOAT);
110   atk_value_get_minimum_value (value, &gvalue);
111
112   return (CORBA_float) g_value_get_float (&gvalue);
113 }
114
115
116 static CORBA_float
117 impl__get_maximumValue (PortableServer_Servant servant,
118                         CORBA_Environment     *ev)
119 {
120   GValue   gvalue = {0, };
121   AtkValue *value = get_value_from_servant (servant);
122
123   g_return_val_if_fail (value != NULL, 0.0);
124
125   g_value_init (&gvalue, G_TYPE_FLOAT);
126   atk_value_get_maximum_value (value, &gvalue);
127
128   return (CORBA_float) g_value_get_float (&gvalue);
129 }
130
131
132 static CORBA_float
133 impl__get_currentValue (PortableServer_Servant servant,
134                         CORBA_Environment     *ev)
135 {
136   GValue   gvalue = {0, };
137   AtkValue *value = get_value_from_servant (servant);
138
139   g_return_val_if_fail (value != NULL, 0.0);
140
141   g_value_init (&gvalue, G_TYPE_FLOAT);
142   atk_value_get_current_value (value, &gvalue);
143
144   return (CORBA_float) g_value_get_float (&gvalue);
145 }
146
147
148 static void 
149 impl__set_currentValue (PortableServer_Servant servant,
150                         const CORBA_float      value,
151                         CORBA_Environment     *ev)
152 {
153   GValue    gvalue = {0, };
154   AtkValue *avalue = get_value_from_servant (servant);
155
156   g_return_if_fail (avalue != NULL);
157
158   g_value_init (&gvalue, G_TYPE_FLOAT);
159   g_value_set_float (&gvalue, (gfloat) value);
160
161   atk_value_set_current_value (avalue, &gvalue);
162 }
163
164