#include <stdio.h>
#include <libspi/value.h>
+#define PARENT_TYPE SPI_TYPE_BASE
+
/* Static function declarations */
+static double
+get_double_from_gvalue (GValue *gvalue);
+static void
+gvalue_set_from_double (GValue *gvalue, double value);
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 double
impl__get_minimumValue (PortableServer_Servant _servant,
- CORBA_Environment * ev);
-static CORBA_float
+ CORBA_Environment * ev);
+static double
impl__get_maximumValue (PortableServer_Servant _servant,
- CORBA_Environment * ev);
-static CORBA_float
+ CORBA_Environment * ev);
+static double
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);
-
-
-
-static GObjectClass *parent_class;
+ const CORBA_double value,
+ CORBA_Environment * ev);
BONOBO_TYPE_FUNC_FULL (SpiValue,
Accessibility_Value,
- BONOBO_TYPE_OBJECT,
+ PARENT_TYPE,
spi_value);
+
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 = g_object_new (SPI_VALUE_TYPE, NULL);
- new_value->atko = obj;
- g_object_ref (obj);
+
+ 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 double
+get_double_from_gvalue (GValue *gvalue)
+{
+ double retval = 0;
+ if (G_TYPE_IS_FUNDAMENTAL (G_VALUE_TYPE (gvalue)))
+ {
+ switch (gvalue->g_type)
+ {
+ case G_TYPE_DOUBLE:
+ retval = g_value_get_double (gvalue);
+ break;
+ case G_TYPE_FLOAT:
+ retval = g_value_get_float (gvalue);
+ break;
+ case G_TYPE_ULONG:
+ retval = g_value_get_ulong (gvalue);
+ break;
+ case G_TYPE_LONG:
+ retval = g_value_get_long (gvalue);
+ break;
+ case G_TYPE_UINT:
+ retval = g_value_get_uint (gvalue);
+ break;
+ case G_TYPE_INT:
+ retval = g_value_get_int (gvalue);
+ break;
+ case G_TYPE_UCHAR:
+ retval = g_value_get_uchar (gvalue);
+ break;
+ case G_TYPE_CHAR:
+ retval = g_value_get_char (gvalue);
+ break;
+ case G_TYPE_BOOLEAN:
+ retval = g_value_get_boolean (gvalue);
+ break;
+ }
+ }
+ else
+ {
+ g_warning ("SpiValue requested from a non-fundamental type\n");
+ }
+ return retval;
+}
+static void
+gvalue_set_from_double (GValue *gvalue, double value)
+{
+ if (G_TYPE_IS_FUNDAMENTAL (G_VALUE_TYPE (gvalue)))
+ {
+ switch (gvalue->g_type)
+ {
+ case G_TYPE_DOUBLE:
+ g_value_set_double (gvalue, value);
+ break;
+ case G_TYPE_FLOAT:
+ g_value_set_float (gvalue, value);
+ break;
+ case G_TYPE_ULONG:
+ g_value_set_ulong (gvalue, value);
+ break;
+ case G_TYPE_LONG:
+ g_value_set_long (gvalue, value);
+ break;
+ case G_TYPE_UINT:
+ g_value_set_uint (gvalue, value);
+ break;
+ case G_TYPE_INT:
+ g_value_set_int (gvalue, value);
+ break;
+ case G_TYPE_UCHAR:
+ g_value_set_uchar (gvalue, value);
+ break;
+ case G_TYPE_CHAR:
+ g_value_set_char (gvalue, value);
+ break;
+ case G_TYPE_BOOLEAN:
+ g_value_set_boolean (gvalue, ((fabs (value) > 0.5) ? 1 : 0));
+ break;
+ }
+ }
+ else
+ {
+ g_warning ("SpiValue change requested for a non-fundamental type\n");
+ }
+}
-static CORBA_float
-impl__get_maximumValue (PortableServer_Servant _servant,
- CORBA_Environment * ev)
+static double
+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_return_val_if_fail (value != NULL, 0.0);
- 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);
+ atk_value_get_minimum_value (value, &gvalue);
+
+ return get_double_from_gvalue (&gvalue);
}
+static double
+impl__get_maximumValue (PortableServer_Servant servant,
+ CORBA_Environment *ev)
+{
+ GValue gvalue = {0, };
+ AtkValue *value = get_value_from_servant (servant);
+
+ g_return_val_if_fail (value != NULL, 0.0);
-static CORBA_float
-impl__get_currentValue (PortableServer_Servant _servant,
- CORBA_Environment * ev)
+ atk_value_get_maximum_value (value, &gvalue);
+
+ return get_double_from_gvalue (&gvalue);
+}
+
+
+static double
+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, 0.0);
- 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);
+ atk_value_get_current_value (value, &gvalue);
+
+ return get_double_from_gvalue (&gvalue);
}
static void
-impl__set_currentValue (PortableServer_Servant _servant,
- const CORBA_float value,
- CORBA_Environment * ev)
+impl__set_currentValue (PortableServer_Servant servant,
+ const CORBA_double 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);
+
+ atk_value_get_current_value (avalue, &gvalue);
+ gvalue_set_from_double (&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);
}