Blame jni/src/jawvalue.c

Packit Service 31d16d
/*
Packit Service 31d16d
 * Java ATK Wrapper for GNOME
Packit Service 31d16d
 * Copyright (C) 2009 Sun Microsystems Inc.
Packit Service 31d16d
 *
Packit Service 31d16d
 * This library is free software; you can redistribute it and/or
Packit Service 31d16d
 * modify it under the terms of the GNU Lesser General Public
Packit Service 31d16d
 * License as published by the Free Software Foundation; either
Packit Service 31d16d
 * version 2.1 of the License, or (at your option) any later version.
Packit Service 31d16d
 *
Packit Service 31d16d
 * This library is distributed in the hope that it will be useful,
Packit Service 31d16d
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 31d16d
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 31d16d
 * Lesser General Public License for more details.
Packit Service 31d16d
 *
Packit Service 31d16d
 * You should have received a copy of the GNU Lesser General Public
Packit Service 31d16d
 * License along with this library; if not, write to the Free Software
Packit Service 31d16d
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit Service 31d16d
 */
Packit Service 31d16d
Packit Service 31d16d
#include <atk/atk.h>
Packit Service 31d16d
#include <glib.h>
Packit Service 31d16d
#include "jawimpl.h"
Packit Service 31d16d
#include "jawutil.h"
Packit Service 31d16d
Packit Service 31d16d
extern void	jaw_value_interface_init (AtkValueIface*);
Packit Service 31d16d
extern gpointer	jaw_value_data_init (jobject ac);
Packit Service 31d16d
extern void	jaw_value_data_finalize (gpointer);
Packit Service 31d16d
Packit Service 31d16d
static void jaw_value_get_current_value(AtkValue *obj, GValue *value);
Packit Service 31d16d
static void jaw_value_get_maximum_value(AtkValue *obj, GValue *value);
Packit Service 31d16d
static void jaw_value_get_minimum_value(AtkValue *obj, GValue *value);
Packit Service 31d16d
static gboolean jaw_value_set_current_value(AtkValue *obj, const GValue *value);
Packit Service 31d16d
static gdouble jaw_value_get_increment (AtkValue *obj);
Packit Service 31d16d
Packit Service 31d16d
typedef struct _ValueData {
Packit Service 31d16d
  jobject atk_value;
Packit Service 31d16d
} ValueData;
Packit Service 31d16d
Packit Service 31d16d
void
Packit Service 31d16d
jaw_value_interface_init (AtkValueIface *iface)
Packit Service 31d16d
{
Packit Service 31d16d
  iface->get_current_value = jaw_value_get_current_value;
Packit Service 31d16d
  iface->get_maximum_value = jaw_value_get_maximum_value;
Packit Service 31d16d
  iface->get_minimum_value = jaw_value_get_minimum_value;
Packit Service 31d16d
  iface->set_current_value = jaw_value_set_current_value;
Packit Service 31d16d
  iface->get_increment = jaw_value_get_increment;
Packit Service 31d16d
}
Packit Service 31d16d
Packit Service 31d16d
gpointer
Packit Service 31d16d
jaw_value_data_init (jobject ac)
Packit Service 31d16d
{
Packit Service 31d16d
  ValueData *data = g_new0(ValueData, 1);
Packit Service 31d16d
Packit Service 31d16d
  JNIEnv *jniEnv = jaw_util_get_jni_env();
Packit Service 31d16d
  jclass classValue = (*jniEnv)->FindClass(jniEnv,
Packit Service 31d16d
                                           "org/GNOME/Accessibility/AtkValue");
Packit Service 31d16d
  jmethodID jmid = (*jniEnv)->GetMethodID(jniEnv,
Packit Service 31d16d
                                          classValue,
Packit Service 31d16d
                                          "<init>",
Packit Service 31d16d
                                          "(Ljavax/accessibility/AccessibleContext;)V");
Packit Service 31d16d
  jobject jatk_value = (*jniEnv)->NewObject(jniEnv, classValue, jmid, ac);
Packit Service 31d16d
  data->atk_value = (*jniEnv)->NewGlobalRef(jniEnv, jatk_value);
Packit Service 31d16d
Packit Service 31d16d
  return data;
Packit Service 31d16d
}
Packit Service 31d16d
Packit Service 31d16d
void
Packit Service 31d16d
jaw_value_data_finalize (gpointer p)
Packit Service 31d16d
{
Packit Service 31d16d
  ValueData *data = (ValueData*)p;
Packit Service 31d16d
  JNIEnv *jniEnv = jaw_util_get_jni_env();
Packit Service 31d16d
Packit Service 31d16d
  if (data && data->atk_value)
Packit Service 31d16d
  {
Packit Service 31d16d
    (*jniEnv)->DeleteGlobalRef(jniEnv, data->atk_value);
Packit Service 31d16d
    data->atk_value = NULL;
Packit Service 31d16d
  }
Packit Service 31d16d
}
Packit Service 31d16d
Packit Service 31d16d
static void
Packit Service 31d16d
get_g_value_from_java_number (JNIEnv *jniEnv, jobject jnumber, GValue *value)
Packit Service 31d16d
{
Packit Service 31d16d
  jclass classByte = (*jniEnv)->FindClass(jniEnv, "java/lang/Byte");
Packit Service 31d16d
  jclass classDouble = (*jniEnv)->FindClass(jniEnv, "java/lang/Double");
Packit Service 31d16d
  jclass classFloat = (*jniEnv)->FindClass(jniEnv, "java/lang/Float");
Packit Service 31d16d
  jclass classInteger = (*jniEnv)->FindClass(jniEnv, "java/lang/Integer");
Packit Service 31d16d
  jclass classLong = (*jniEnv)->FindClass(jniEnv, "java/lang/Long");
Packit Service 31d16d
  jclass classShort = (*jniEnv)->FindClass(jniEnv, "java/lang/Short");
Packit Service 31d16d
Packit Service 31d16d
  jmethodID jmid;
Packit Service 31d16d
Packit Service 31d16d
  if ((*jniEnv)->IsInstanceOf(jniEnv, jnumber, classByte))
Packit Service 31d16d
  {
Packit Service 31d16d
    jmid = (*jniEnv)->GetMethodID(jniEnv, classByte, "byteValue", "()B");
Packit Service 31d16d
    g_value_init(value, G_TYPE_CHAR);
Packit Service 31d16d
    g_value_set_schar(value,
Packit Service 31d16d
                      (gchar)(*jniEnv)->CallByteMethod(jniEnv, jnumber, jmid));
Packit Service 31d16d
Packit Service 31d16d
    return;
Packit Service 31d16d
  }
Packit Service 31d16d
Packit Service 31d16d
  if ((*jniEnv)->IsInstanceOf(jniEnv, jnumber, classDouble))
Packit Service 31d16d
  {
Packit Service 31d16d
    jmid = (*jniEnv)->GetMethodID(jniEnv, classDouble, "doubleValue", "()D");
Packit Service 31d16d
    g_value_init(value, G_TYPE_DOUBLE);
Packit Service 31d16d
    g_value_set_double(value,
Packit Service 31d16d
                       (gdouble)(*jniEnv)->CallDoubleMethod(jniEnv, jnumber, jmid));
Packit Service 31d16d
Packit Service 31d16d
    return;
Packit Service 31d16d
  }
Packit Service 31d16d
Packit Service 31d16d
  if ((*jniEnv)->IsInstanceOf(jniEnv, jnumber, classFloat))
Packit Service 31d16d
  {
Packit Service 31d16d
    jmid = (*jniEnv)->GetMethodID(jniEnv, classFloat, "floatValue", "()F");
Packit Service 31d16d
    g_value_init(value, G_TYPE_FLOAT);
Packit Service 31d16d
    g_value_set_float(value,
Packit Service 31d16d
                      (gfloat)(*jniEnv)->CallFloatMethod(jniEnv, jnumber, jmid));
Packit Service 31d16d
Packit Service 31d16d
    return;
Packit Service 31d16d
  }
Packit Service 31d16d
Packit Service 31d16d
  if ((*jniEnv)->IsInstanceOf(jniEnv, jnumber, classInteger)
Packit Service 31d16d
    || (*jniEnv)->IsInstanceOf(jniEnv, jnumber, classShort))
Packit Service 31d16d
    {
Packit Service 31d16d
    jmid = (*jniEnv)->GetMethodID(jniEnv, classInteger, "intValue", "()I");
Packit Service 31d16d
    g_value_init(value, G_TYPE_INT);
Packit Service 31d16d
    g_value_set_int(value,
Packit Service 31d16d
                    (gint)(*jniEnv)->CallIntMethod(jniEnv, jnumber, jmid));
Packit Service 31d16d
Packit Service 31d16d
    return;
Packit Service 31d16d
  }
Packit Service 31d16d
Packit Service 31d16d
  if ((*jniEnv)->IsInstanceOf(jniEnv, jnumber, classLong)) {
Packit Service 31d16d
    jmid = (*jniEnv)->GetMethodID(jniEnv, classLong, "longValue", "()J");
Packit Service 31d16d
    g_value_init(value, G_TYPE_INT64);
Packit Service 31d16d
    g_value_set_int64(value,
Packit Service 31d16d
                      (gint64)(*jniEnv)->CallLongMethod(jniEnv, jnumber, jmid));
Packit Service 31d16d
Packit Service 31d16d
    return;
Packit Service 31d16d
  }
Packit Service 31d16d
}
Packit Service 31d16d
Packit Service 31d16d
static void
Packit Service 31d16d
jaw_value_get_current_value (AtkValue *obj, GValue *value)
Packit Service 31d16d
{
Packit Service 31d16d
  if (!value)
Packit Service 31d16d
  {
Packit Service 31d16d
    return;
Packit Service 31d16d
  }
Packit Service 31d16d
Packit Service 31d16d
  JawObject *jaw_obj = JAW_OBJECT(obj);
Packit Service 31d16d
  ValueData *data = jaw_object_get_interface_data(jaw_obj, INTERFACE_VALUE);
Packit Service 31d16d
  jobject atk_value = data->atk_value;
Packit Service 31d16d
Packit Service 31d16d
  JNIEnv *jniEnv = jaw_util_get_jni_env();
Packit Service 31d16d
  jclass classAtkValue = (*jniEnv)->FindClass(jniEnv,
Packit Service 31d16d
                                              "org/GNOME/Accessibility/AtkValue");
Packit Service 31d16d
  jmethodID jmid = (*jniEnv)->GetMethodID(jniEnv,
Packit Service 31d16d
                                          classAtkValue,
Packit Service 31d16d
                                          "get_current_value",
Packit Service 31d16d
                                          "()Ljava/lang/Number;");
Packit Service 31d16d
  jobject jnumber = (*jniEnv)->CallObjectMethod(jniEnv,
Packit Service 31d16d
                                                atk_value,
Packit Service 31d16d
                                                jmid);
Packit Service 31d16d
Packit Service 31d16d
  if (!jnumber)
Packit Service 31d16d
  {
Packit Service 31d16d
    return;
Packit Service 31d16d
  }
Packit Service 31d16d
Packit Service 31d16d
  get_g_value_from_java_number(jniEnv, jnumber, value);
Packit Service 31d16d
}
Packit Service 31d16d
Packit Service 31d16d
static void
Packit Service 31d16d
jaw_value_get_maximum_value (AtkValue *obj, GValue *value)
Packit Service 31d16d
{
Packit Service 31d16d
  if (!value)
Packit Service 31d16d
  {
Packit Service 31d16d
    return;
Packit Service 31d16d
  }
Packit Service 31d16d
Packit Service 31d16d
  JawObject *jaw_obj = JAW_OBJECT(obj);
Packit Service 31d16d
  ValueData *data = jaw_object_get_interface_data(jaw_obj, INTERFACE_VALUE);
Packit Service 31d16d
  jobject atk_value = data->atk_value;
Packit Service 31d16d
Packit Service 31d16d
  JNIEnv *jniEnv = jaw_util_get_jni_env();
Packit Service 31d16d
  jclass classAtkValue = (*jniEnv)->FindClass(jniEnv,
Packit Service 31d16d
                                              "org/GNOME/Accessibility/AtkValue");
Packit Service 31d16d
  jmethodID jmid = (*jniEnv)->GetMethodID(jniEnv,
Packit Service 31d16d
                                          classAtkValue,
Packit Service 31d16d
                                          "get_maximum_value",
Packit Service 31d16d
                                          "()Ljava/lang/Number;");
Packit Service 31d16d
  jobject jnumber = (*jniEnv)->CallObjectMethod(jniEnv, atk_value, jmid);
Packit Service 31d16d
Packit Service 31d16d
  if (!jnumber)
Packit Service 31d16d
  {
Packit Service 31d16d
    return;
Packit Service 31d16d
  }
Packit Service 31d16d
Packit Service 31d16d
  get_g_value_from_java_number(jniEnv, jnumber, value);
Packit Service 31d16d
}
Packit Service 31d16d
Packit Service 31d16d
static void
Packit Service 31d16d
jaw_value_get_minimum_value (AtkValue *obj, GValue *value)
Packit Service 31d16d
{
Packit Service 31d16d
  if (!value)
Packit Service 31d16d
  {
Packit Service 31d16d
    return;
Packit Service 31d16d
  }
Packit Service 31d16d
Packit Service 31d16d
  JawObject *jaw_obj = JAW_OBJECT(obj);
Packit Service 31d16d
  ValueData *data = jaw_object_get_interface_data(jaw_obj, INTERFACE_VALUE);
Packit Service 31d16d
  jobject atk_value = data->atk_value;
Packit Service 31d16d
Packit Service 31d16d
  JNIEnv *jniEnv = jaw_util_get_jni_env();
Packit Service 31d16d
  jclass classAtkValue = (*jniEnv)->FindClass(jniEnv,
Packit Service 31d16d
                                              "org/GNOME/Accessibility/AtkValue");
Packit Service 31d16d
  jmethodID jmid = (*jniEnv)->GetMethodID(jniEnv,
Packit Service 31d16d
                                          classAtkValue,
Packit Service 31d16d
                                          "get_minimum_value",
Packit Service 31d16d
                                          "()Ljava/lang/Number;");
Packit Service 31d16d
  jobject jnumber = (*jniEnv)->CallObjectMethod(jniEnv, atk_value, jmid);
Packit Service 31d16d
Packit Service 31d16d
  if (!jnumber)
Packit Service 31d16d
  {
Packit Service 31d16d
    return;
Packit Service 31d16d
  }
Packit Service 31d16d
Packit Service 31d16d
  get_g_value_from_java_number(jniEnv, jnumber, value);
Packit Service 31d16d
}
Packit Service 31d16d
Packit Service 31d16d
static gboolean
Packit Service 31d16d
jaw_value_set_current_value (AtkValue *obj, const GValue *value)
Packit Service 31d16d
{
Packit Service 31d16d
  if (!value)
Packit Service 31d16d
  {
Packit Service 31d16d
    return FALSE;
Packit Service 31d16d
  }
Packit Service 31d16d
Packit Service 31d16d
  if (!G_TYPE_IS_FUNDAMENTAL (G_VALUE_TYPE (value)))
Packit Service 31d16d
  {
Packit Service 31d16d
    return FALSE;
Packit Service 31d16d
  }
Packit Service 31d16d
Packit Service 31d16d
  JawObject *jaw_obj = JAW_OBJECT(obj);
Packit Service 31d16d
  ValueData *data = jaw_object_get_interface_data(jaw_obj, INTERFACE_VALUE);
Packit Service 31d16d
  jobject atk_value = data->atk_value;
Packit Service 31d16d
Packit Service 31d16d
  JNIEnv *jniEnv = jaw_util_get_jni_env();
Packit Service 31d16d
  jclass classAtkValue = (*jniEnv)->FindClass(jniEnv,
Packit Service 31d16d
                                              "org/GNOME/Accessibility/AtkValue");
Packit Service 31d16d
  jmethodID jmid = (*jniEnv)->GetMethodID(jniEnv,
Packit Service 31d16d
                                          classAtkValue,
Packit Service 31d16d
                                          "set_current_value",
Packit Service 31d16d
                                          "(Ljava/lang/Number;)Z");
Packit Service 31d16d
Packit Service 31d16d
  jboolean jbool;
Packit Service 31d16d
  jclass klass;
Packit Service 31d16d
  jmethodID jmidInit;
Packit Service 31d16d
  jobject o;
Packit Service 31d16d
  switch (value->g_type) {
Packit Service 31d16d
    case G_TYPE_CHAR:
Packit Service 31d16d
    {
Packit Service 31d16d
      gchar c = g_value_get_schar(value);
Packit Service 31d16d
      klass = (*jniEnv)->FindClass(jniEnv, "java/lang/Byte");
Packit Service 31d16d
      jmidInit = (*jniEnv)->GetMethodID(jniEnv, klass, "<init>", "(B)V");
Packit Service 31d16d
      o = (*jniEnv)->NewObject(jniEnv, klass, jmidInit, (jbyte)c);
Packit Service 31d16d
      jbool = (*jniEnv)->CallBooleanMethod(jniEnv, atk_value, jmid, o);
Packit Service 31d16d
      break;
Packit Service 31d16d
    }
Packit Service 31d16d
    case G_TYPE_DOUBLE:
Packit Service 31d16d
    {
Packit Service 31d16d
      gdouble d = g_value_get_double(value);
Packit Service 31d16d
      klass = (*jniEnv)->FindClass(jniEnv, "java/lang/Double");
Packit Service 31d16d
      jmidInit = (*jniEnv)->GetMethodID(jniEnv, klass, "<init>", "(D)V");
Packit Service 31d16d
      o = (*jniEnv)->NewObject(jniEnv, klass, jmidInit, (jdouble)d);
Packit Service 31d16d
      jbool = (*jniEnv)->CallBooleanMethod(jniEnv, atk_value, jmid, o);
Packit Service 31d16d
      break;
Packit Service 31d16d
    }
Packit Service 31d16d
    case G_TYPE_FLOAT:
Packit Service 31d16d
    {
Packit Service 31d16d
      gfloat f = g_value_get_float(value);
Packit Service 31d16d
      klass = (*jniEnv)->FindClass(jniEnv, "java/lang/Float");
Packit Service 31d16d
      jmidInit = (*jniEnv)->GetMethodID(jniEnv, klass, "<init>", "(F)V");
Packit Service 31d16d
      o = (*jniEnv)->NewObject(jniEnv, klass, jmidInit, (jfloat)f);
Packit Service 31d16d
      jbool = (*jniEnv)->CallBooleanMethod(jniEnv, atk_value, jmid, o);
Packit Service 31d16d
      break;
Packit Service 31d16d
    }
Packit Service 31d16d
    case G_TYPE_INT:
Packit Service 31d16d
    {
Packit Service 31d16d
      gint i = g_value_get_int(value);
Packit Service 31d16d
      klass = (*jniEnv)->FindClass(jniEnv, "java/lang/Integer");
Packit Service 31d16d
      jmidInit = (*jniEnv)->GetMethodID(jniEnv, klass, "<init>", "(I)V");
Packit Service 31d16d
      o = (*jniEnv)->NewObject(jniEnv, klass, jmidInit, (jint)i);
Packit Service 31d16d
      jbool = (*jniEnv)->CallBooleanMethod(jniEnv, atk_value, jmid, o);
Packit Service 31d16d
      break;
Packit Service 31d16d
    }
Packit Service 31d16d
    case G_TYPE_INT64:
Packit Service 31d16d
    {
Packit Service 31d16d
      gint64 i64 = g_value_get_int64(value);
Packit Service 31d16d
      klass = (*jniEnv)->FindClass(jniEnv, "java/lang/Long");
Packit Service 31d16d
      jmidInit = (*jniEnv)->GetMethodID(jniEnv, klass, "<init>", "(J)V");
Packit Service 31d16d
      o = (*jniEnv)->NewObject(jniEnv, klass, jmidInit, (jlong)i64);
Packit Service 31d16d
      jbool = (*jniEnv)->CallBooleanMethod(jniEnv, atk_value, jmid, o);
Packit Service 31d16d
      break;
Packit Service 31d16d
    }
Packit Service 31d16d
    default:
Packit Service 31d16d
      return FALSE;
Packit Service 31d16d
  }
Packit Service 31d16d
Packit Service 31d16d
  return (jbool == JNI_TRUE) ? TRUE : FALSE;
Packit Service 31d16d
}
Packit Service 31d16d
Packit Service 31d16d
static gdouble
Packit Service 31d16d
jaw_value_get_increment (AtkValue *obj)
Packit Service 31d16d
{
Packit Service 31d16d
 return atk_value_get_increment(obj);
Packit Service 31d16d
}
Packit Service 31d16d