* Boston, MA 02111-1307, USA.
*/
-/*
- * component.c : bonobo wrapper for accessible component implementation
- *
- */
+/* value.c : implements the Value interface */
#include <config.h>
-#include <bonobo/Bonobo.h>
-
#include <stdio.h>
+#include <libspi/value.h>
-/*
- * This pulls the CORBA definitions for the "Accessibility::Accessible" server
- */
-#include <libspi/Accessibility.h>
-
-/*
- * This pulls the definition of the SpiValue bonobo object
- */
-#include "value.h"
+#define PARENT_TYPE SPI_TYPE_BASE
-/*
- * Static function declarations
- */
+/* Static function declarations */
+static Accessibility_SValue
+gvalue_to_svalue (GValue *gvalue);
static void
spi_value_class_init (SpiValueClass *klass);
static void
spi_value_init (SpiValue *value);
-static void
-spi_value_finalize (GObject *obj);
-static CORBA_float
+static Accessibility_SValue
impl__get_minimumValue (PortableServer_Servant _servant,
- CORBA_Environment * ev);
-static CORBA_float
+ CORBA_Environment * ev);
+static Accessibility_SValue
impl__get_maximumValue (PortableServer_Servant _servant,
- CORBA_Environment * ev);
-static CORBA_float
+ CORBA_Environment * ev);
+static Accessibility_SValue
impl__get_currentValue (PortableServer_Servant _servant,
- CORBA_Environment * ev);
+ CORBA_Environment * ev);
static void
-impl__set_currentValue (PortableServer_Servant _servant,
- const CORBA_float value,
- CORBA_Environment * ev);
-
-
+impl__set_currentValue (PortableServer_Servant _servant,
+ const Accessibility_SValue * value,
+ CORBA_Environment * ev);
-static GObjectClass *parent_class;
+BONOBO_TYPE_FUNC_FULL (SpiValue,
+ Accessibility_Value,
+ PARENT_TYPE,
+ spi_value);
-GType
-spi_value_get_type (void)
-{
- static GType type = 0;
-
- if (!type) {
- static const GTypeInfo tinfo = {
- sizeof (SpiValueClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) spi_value_class_init,
- (GClassFinalizeFunc) NULL,
- NULL, /* class data */
- sizeof (SpiValue),
- 0, /* n preallocs */
- (GInstanceInitFunc) spi_value_init,
- NULL /* value table */
- };
-
- /*
- * Bonobo_type_unique auto-generates a load of
- * CORBA structures for us. All derived types must
- * use bonobo_type_unique.
- */
- type = bonobo_type_unique (
- BONOBO_OBJECT_TYPE,
- POA_Accessibility_Value__init,
- NULL,
- G_STRUCT_OFFSET (SpiValueClass, epv),
- &tinfo,
- "SpiAccessibleValue");
- }
-
- return type;
-}
static void
spi_value_class_init (SpiValueClass *klass)
{
- GObjectClass * object_class = (GObjectClass *) klass;
POA_Accessibility_Value__epv *epv = &klass->epv;
- parent_class = g_type_class_peek_parent (klass);
-
- object_class->finalize = spi_value_finalize;
-
/* Initialize epv table */
epv->_set_currentValue = impl__set_currentValue;
}
+
static void
spi_value_init (SpiValue *value)
{
}
-static void
-spi_value_finalize (GObject *obj)
-{
- SpiValue *value = SPI_VALUE (obj);
- g_object_unref (value->atko);
- value->atko = NULL;
- parent_class->finalize (obj);
-}
SpiValue *
spi_value_interface_new (AtkObject *obj)
{
- SpiValue *new_value =
- SPI_VALUE(g_object_new (SPI_VALUE_TYPE, NULL));
- new_value->atko = obj;
- g_object_ref (obj);
+ SpiValue *new_value = g_object_new (SPI_VALUE_TYPE, NULL);
+
+ spi_base_construct (SPI_BASE (new_value), obj);
+
return new_value;
}
-
-static CORBA_float
-impl__get_minimumValue (PortableServer_Servant _servant,
- CORBA_Environment * ev)
+static AtkValue *
+get_value_from_servant (PortableServer_Servant servant)
{
- SpiValue *value = SPI_VALUE (bonobo_object_from_servant (_servant));
- GValue gvalue = {0, };
+ SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
- g_value_init (&gvalue, G_TYPE_FLOAT);
- atk_value_get_minimum_value (ATK_VALUE(value->atko), &gvalue);
- return (CORBA_float) g_value_get_float (&gvalue);
+ if (!object)
+ {
+ return NULL;
+ }
+
+ return ATK_VALUE (object->atko);
}
+static Accessibility_SValue
+gvalue_to_svalue (GValue *gvalue)
+{
+ Accessibility_SValue sval;
+ if (G_VALUE_HOLDS_DOUBLE (gvalue))
+ {
+ sval._d = Accessibility_DOUBLEVAL;
+ sval._u.val_double = g_value_get_double (gvalue);
+ }
+ else if (G_VALUE_HOLDS_FLOAT (gvalue))
+ {
+ sval._d = Accessibility_FLOATVAL;
+ sval._u.val_float = g_value_get_float (gvalue);
+ }
+ else if (G_VALUE_HOLDS_ULONG (gvalue))
+ {
+ sval._d = Accessibility_ULONGVAL;
+ sval._u.val_ulong = g_value_get_ulong (gvalue);
+ }
+ else if (G_VALUE_HOLDS_LONG (gvalue))
+ {
+ sval._d = Accessibility_LONGVAL;
+ sval._u.val_long = g_value_get_long (gvalue);
+ }
+ else if (G_VALUE_HOLDS_UINT (gvalue))
+ {
+ sval._d = Accessibility_USHORTVAL;
+ sval._u.val_ushort = CLAMP (g_value_get_uint (gvalue), 0, G_MAXUSHORT);
+ }
+ else if (G_VALUE_HOLDS_INT (gvalue))
+ {
+ sval._d = Accessibility_SHORTVAL;
+ sval._u.val_short = CLAMP (g_value_get_int (gvalue), G_MINSHORT, G_MAXSHORT);
+ }
+ else
+ {
+ sval._d = Accessibility_SHORTVAL;
+ sval._u.val_short = 0;
+ }
+ return sval;
+}
+static void
+gvalue_set_from_svalue (GValue *gvalue, Accessibility_SValue *sval)
+{
+ switch (sval->_d)
+ {
+ case Accessibility_DOUBLEVAL:
+ g_value_init (gvalue, G_TYPE_DOUBLE);
+ g_value_set_double (gvalue, sval->_u.val_double);
+ break;
+ case Accessibility_FLOATVAL:
+ g_value_init (gvalue, G_TYPE_FLOAT);
+ g_value_set_float (gvalue, sval->_u.val_float);
+ break;
+ case Accessibility_ULONGVAL:
+ g_value_init (gvalue, G_TYPE_ULONG);
+ g_value_set_ulong (gvalue, sval->_u.val_ulong);
+ break;
+ case Accessibility_LONGVAL:
+ g_value_init (gvalue, G_TYPE_LONG);
+ g_value_set_long (gvalue, sval->_u.val_long);
+ break;
+ case Accessibility_USHORTVAL:
+ g_value_init (gvalue, G_TYPE_UINT);
+ g_value_set_uint (gvalue, sval->_u.val_ushort);
+ break;
+ case Accessibility_SHORTVAL:
+ g_value_init (gvalue, G_TYPE_INT);
+ g_value_set_int (gvalue, sval->_u.val_short);
+ break;
+ default:
+ g_value_init (gvalue, G_TYPE_INT);
+ g_value_set_int (gvalue, 0);
+ }
+}
-static CORBA_float
-impl__get_maximumValue (PortableServer_Servant _servant,
- CORBA_Environment * ev)
+static Accessibility_SValue
+impl__get_minimumValue (PortableServer_Servant servant,
+ CORBA_Environment *ev)
{
- SpiValue *value = SPI_VALUE (bonobo_object_from_servant (_servant));
- GValue gvalue = {0, };
+ GValue gvalue = {0, };
+ AtkValue *value = get_value_from_servant (servant);
- g_value_init (&gvalue, G_TYPE_FLOAT);
- atk_value_get_maximum_value (ATK_VALUE(value->atko), &gvalue);
- return (CORBA_float) g_value_get_float (&gvalue);
+ g_return_val_if_fail (value != NULL, gvalue_to_svalue (&gvalue));
+
+ g_value_init (&gvalue, G_TYPE_DOUBLE);
+ atk_value_get_minimum_value (value, &gvalue);
+
+ return gvalue_to_svalue (&gvalue);
}
+static Accessibility_SValue
+impl__get_maximumValue (PortableServer_Servant servant,
+ CORBA_Environment *ev)
+{
+ GValue gvalue = {0, };
+ AtkValue *value = get_value_from_servant (servant);
-static CORBA_float
-impl__get_currentValue (PortableServer_Servant _servant,
- CORBA_Environment * ev)
+ g_return_val_if_fail (value != NULL, gvalue_to_svalue (&gvalue));
+
+ g_value_init (&gvalue, G_TYPE_DOUBLE);
+ atk_value_get_maximum_value (value, &gvalue);
+
+ return gvalue_to_svalue (&gvalue);
+}
+
+
+static Accessibility_SValue
+impl__get_currentValue (PortableServer_Servant servant,
+ CORBA_Environment *ev)
{
- SpiValue *value = SPI_VALUE (bonobo_object_from_servant (_servant));
- GValue gvalue = {0, };
+ GValue gvalue = {0, };
+ AtkValue *value = get_value_from_servant (servant);
+
+ g_return_val_if_fail (value != NULL, gvalue_to_svalue (&gvalue));
- g_value_init (&gvalue, G_TYPE_FLOAT);
- atk_value_get_current_value (ATK_VALUE(value->atko), &gvalue);
- return (CORBA_float) g_value_get_float (&gvalue);
+ g_value_init (&gvalue, G_TYPE_DOUBLE);
+ atk_value_get_current_value (value, &gvalue);
+
+ return gvalue_to_svalue (&gvalue);
}
static void
-impl__set_currentValue (PortableServer_Servant _servant,
- const CORBA_float value,
- CORBA_Environment * ev)
+impl__set_currentValue (PortableServer_Servant servant,
+ const Accessibility_SValue *value,
+ CORBA_Environment *ev)
{
- SpiValue *val = SPI_VALUE (bonobo_object_from_servant (_servant));
- GValue gvalue = {0, };
+ GValue gvalue = {0, };
+ AtkValue *avalue = get_value_from_servant (servant);
+
+ g_return_if_fail (avalue != NULL);
+
+ gvalue_set_from_svalue (&gvalue, value);
- g_value_init (&gvalue, G_TYPE_FLOAT);
- g_value_set_float (&gvalue, (gfloat) value);
- atk_value_set_current_value (ATK_VALUE(val->atko), &gvalue);
+ atk_value_set_current_value (avalue, &gvalue);
}