2001-11-20 Michael Meeks <michael@ximian.com>
[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 void
35 spi_value_finalize (GObject *obj);
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
52 static GObjectClass *parent_class;
53
54
55 BONOBO_TYPE_FUNC_FULL (SpiValue,
56                        Accessibility_Value,
57                        BONOBO_TYPE_OBJECT,
58                        spi_value);
59
60 static void
61 spi_value_class_init (SpiValueClass *klass)
62 {
63   GObjectClass * object_class = (GObjectClass *) klass;
64   POA_Accessibility_Value__epv *epv = &klass->epv;
65   parent_class = g_type_class_peek_parent (klass);
66
67   object_class->finalize = spi_value_finalize;
68
69
70   /* Initialize epv table */
71
72   epv->_get_minimumValue = impl__get_minimumValue;
73   epv->_get_maximumValue = impl__get_maximumValue;
74   epv->_get_currentValue = impl__get_currentValue;
75   epv->_set_currentValue = impl__set_currentValue;
76 }
77
78 static void
79 spi_value_init (SpiValue *value)
80 {
81 }
82
83 static void
84 spi_value_finalize (GObject *obj)
85 {
86   SpiValue *value = SPI_VALUE (obj);
87   g_object_unref (value->atko);
88   value->atko = NULL;
89   parent_class->finalize (obj);
90 }
91
92 SpiValue *
93 spi_value_interface_new (AtkObject *obj)
94 {
95   SpiValue *new_value = 
96     SPI_VALUE(g_object_new (SPI_VALUE_TYPE, NULL));
97   new_value->atko = obj;
98   g_object_ref (obj);
99   return new_value;
100 }
101
102
103
104 static CORBA_float
105 impl__get_minimumValue (PortableServer_Servant _servant,
106                        CORBA_Environment * ev)
107 {
108   SpiValue *value = SPI_VALUE (bonobo_object_from_servant (_servant));
109   GValue gvalue = {0, };
110
111   g_value_init (&gvalue, G_TYPE_FLOAT);
112   atk_value_get_minimum_value (ATK_VALUE(value->atko), &gvalue);
113   return (CORBA_float) g_value_get_float (&gvalue);
114 }
115
116
117
118 static        CORBA_float
119 impl__get_maximumValue (PortableServer_Servant _servant,
120                         CORBA_Environment * ev)
121 {
122   SpiValue *value = SPI_VALUE (bonobo_object_from_servant (_servant));
123   GValue gvalue = {0, };
124
125   g_value_init (&gvalue, G_TYPE_FLOAT);
126   atk_value_get_maximum_value (ATK_VALUE(value->atko), &gvalue);
127   return (CORBA_float) g_value_get_float (&gvalue);
128 }
129
130
131
132 static CORBA_float
133 impl__get_currentValue (PortableServer_Servant _servant,
134                         CORBA_Environment * ev)
135 {
136   SpiValue *value = SPI_VALUE (bonobo_object_from_servant (_servant));
137   GValue gvalue = {0, };
138
139   g_value_init (&gvalue, G_TYPE_FLOAT);
140   atk_value_get_current_value (ATK_VALUE(value->atko), &gvalue);
141   return (CORBA_float) g_value_get_float (&gvalue);
142 }
143
144
145 static void 
146 impl__set_currentValue (PortableServer_Servant _servant,
147                         const CORBA_float value,
148                         CORBA_Environment * ev)
149 {
150   SpiValue *val = SPI_VALUE (bonobo_object_from_servant (_servant));
151   GValue gvalue = {0, };
152
153   g_value_init (&gvalue, G_TYPE_FLOAT);
154   g_value_set_float (&gvalue, (gfloat) value);
155   atk_value_set_current_value (ATK_VALUE(val->atko), &gvalue);
156 }
157
158