[java-atk-wrapper] JNI: Init windows iface via impl & util



commit e7faa8e5ccd187bb7d913602a6ba46745b988508
Author: Magdalen Berns <m berns thismagpie com>
Date:   Wed Jun 10 20:04:05 2015 +0100

    JNI: Init windows iface via impl & util
    
    Bug: https://bugzilla.gnome.org/show_bug.cgi?id=745343

 jni/src/AtkWrapper.c |    1 +
 jni/src/jawimpl.c    |   24 +++++++
 jni/src/jawutil.c    |   10 +++
 jni/src/jawwindow.c  |  176 ++++++++++----------------------------------------
 4 files changed, 69 insertions(+), 142 deletions(-)
---
diff --git a/jni/src/AtkWrapper.c b/jni/src/AtkWrapper.c
index 7cfb8cc..16db5ae 100644
--- a/jni/src/AtkWrapper.c
+++ b/jni/src/AtkWrapper.c
@@ -29,6 +29,7 @@
 #include <X11/Xlib.h>
 #include "jawutil.h"
 #include "jawimpl.h"
+#include "jawwindow.h"
 #include "jawtoplevel.h"
 
 #ifdef __cplusplus
diff --git a/jni/src/jawimpl.c b/jni/src/jawimpl.c
index 7b56f53..27e3286 100644
--- a/jni/src/jawimpl.c
+++ b/jni/src/jawimpl.c
@@ -80,6 +80,10 @@ extern void jaw_table_interface_init (AtkTableIface*);
 extern gpointer jaw_table_data_init (jobject);
 extern void jaw_table_data_finalize (gpointer);
 
+extern void jaw_window_interface_init (AtkWindowIface*);
+extern gpointer jaw_window_data_init (jobject);
+extern void jaw_window_data_finalize (gpointer);
+
 typedef struct _JawInterfaceInfo {
   void (*finalize) (gpointer);
   gpointer data;
@@ -233,6 +237,16 @@ aggregate_interface(JNIEnv *jniEnv, JawObject *jaw_obj, guint tflag)
                         (gpointer)INTERFACE_TABLE,
                         (gpointer)info);
   }
+
+  if (tflag & INTERFACE_WINDOW)
+  {
+    JawInterfaceInfo *info = g_new(JawInterfaceInfo, 1);
+    info->data = jaw_window_data_init(ac);
+    info->finalize = jaw_window_data_finalize;
+    g_hash_table_insert(jaw_impl->ifaceTable,
+                        (gpointer)INTERFACE_WINDOW,
+                        (gpointer)info);
+  }
 }
 
 JawImpl*
@@ -383,6 +397,13 @@ jaw_impl_get_type (guint tflag)
     NULL
   };
 
+  static const GInterfaceInfo atk_window_info =
+  {
+    (GInterfaceInitFunc) jaw_window_interface_init,
+    (GInterfaceFinalizeFunc) NULL,
+    NULL
+  };
+
   if (typeTable == NULL) {
     typeTable = g_hash_table_new( NULL, NULL );
   }
@@ -434,6 +455,9 @@ jaw_impl_get_type (guint tflag)
     if (tflag & INTERFACE_TABLE)
       g_type_add_interface_static (type, ATK_TYPE_TABLE, &atk_table_info);
 
+    if (tflag & INTERFACE_WINDOW)
+      g_type_add_interface_static (type, ATK_TYPE_WINDOW, &atk_window_info);
+
     g_hash_table_insert(typeTable, GINT_TO_POINTER(tflag), GTYPE_TO_POINTER(type));
   }
 
diff --git a/jni/src/jawutil.c b/jni/src/jawutil.c
index 33941f1..eea77b7 100644
--- a/jni/src/jawutil.c
+++ b/jni/src/jawutil.c
@@ -424,6 +424,16 @@ jaw_util_get_tflag_from_jobj(JNIEnv *jniEnv, jobject jObj)
     tflag |= INTERFACE_VALUE;
   }
 
+  jmid = (*jniEnv)->GetMethodID(jniEnv,
+                                classAccessibleContext,
+                                "getAccessibleContext",
+                                "()Ljavax/accessibility/AccessibleContext;");
+  iface = (*jniEnv)->CallObjectMethod(jniEnv, ac, jmid);
+  if (iface != NULL)
+  {
+    tflag |= INTERFACE_WINDOW;
+  }
+
   return tflag;
 }
 
diff --git a/jni/src/jawwindow.c b/jni/src/jawwindow.c
index f80ce1c..2073d83 100644
--- a/jni/src/jawwindow.c
+++ b/jni/src/jawwindow.c
@@ -25,124 +25,37 @@
 #include "jawutil.h"
 #include "jawtoplevel.h"
 
-static void jaw_window_class_init(JawWindowClass *klass);
+static void jaw_window_interface_init (AtkWindowIface *iface);
 static void jaw_window_init(JawWindow *object);
-static void jaw_window_dispose(GObject *gobject);
-static void jaw_window_finalize(GObject *gobject);
 
-static gpointer parent_class = NULL;
+extern void jaw_window_interface_init (AtkWindowIface*);
+extern gpointer jaw_window_data_init (jobject ac);
+extern void jaw_window_data_finalize (gpointer p);
 
-enum {
-  ACTIVATE,
-  CREATE,
-  DEACTIVATE,
-  DESTROY,
-  MAXIMIZE,
-  MINIMIZE,
-  MOVE,
-  RESIZE,
-  RESTORE,
-  TOTAL_SIGNAL
-};
+typedef struct _WindowData {
+  jobject atk_window;
+  gchar* description;
+  jstring jstrDescription;
+} WindowData;
 
-static guint     jaw_window_signals[TOTAL_SIGNAL] = { 0, };
-
-G_DEFINE_TYPE(JawWindow, jaw_window, JAW_TYPE_OBJECT)
-
-static void
-jaw_window_class_init (JawWindowClass *klass)
+void
+jaw_window_interface_init (AtkWindowIface *iface)
 {
-
-  GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-  gobject_class->dispose = jaw_window_dispose;
-  gobject_class->finalize = jaw_window_finalize;
-  parent_class = g_type_class_peek_parent (klass);
-
-  klass->get_interface_data = NULL;
-
-  jaw_window_signals [ACTIVATE] = g_signal_new ("activate",
-                                                G_TYPE_FROM_CLASS (klass),
-                                                G_SIGNAL_RUN_LAST,
-                                                0, /* default signal handler */
-                                                NULL,
-                                                NULL,
-                                                g_cclosure_marshal_VOID__VOID,
-                                                G_TYPE_NONE,
-                                                0);
-  jaw_window_signals [CREATE] = g_signal_new ("create",
-                                              G_TYPE_FROM_CLASS (klass),
-                                              G_SIGNAL_RUN_LAST,
-                                              0, /* default signal handler */
-                                              NULL, NULL,
-                                              g_cclosure_marshal_VOID__VOID,
-                                              G_TYPE_NONE,
-                                              0);
-  jaw_window_signals [DEACTIVATE] = g_signal_new ("deactivate",
-                                                  G_TYPE_FROM_CLASS (klass),
-                                                  G_SIGNAL_RUN_LAST,
-                                                  0, /* default signal handler */
-                                                  NULL, NULL,
-                                                  g_cclosure_marshal_VOID__VOID,
-                                                  G_TYPE_NONE, 0);
-  jaw_window_signals [DESTROY] = g_signal_new ("destroy",
-                                                G_TYPE_FROM_CLASS (klass),
-                                                G_SIGNAL_RUN_LAST,
-                                                0, /* default signal handler */
-                                                NULL,
-                                                NULL,
-                                                g_cclosure_marshal_VOID__VOID,
-                                                G_TYPE_NONE,
-                                                0);
-  jaw_window_signals [MAXIMIZE] = g_signal_new ("maximize",
-                                                G_TYPE_FROM_CLASS (klass),
-                                                G_SIGNAL_RUN_LAST,
-                                                0, /* default signal handler */
-                                                NULL, NULL,
-                                                g_cclosure_marshal_VOID__VOID,
-                                                G_TYPE_NONE, 0);
-  jaw_window_signals [MINIMIZE] = g_signal_new ("minimize",
-                                                G_TYPE_FROM_CLASS (klass),
-                                                G_SIGNAL_RUN_LAST,
-                                                0, /* default signal handler */
-                                                NULL, NULL,
-                                                g_cclosure_marshal_VOID__VOID,
-                                                G_TYPE_NONE, 0);
-  jaw_window_signals [MOVE] = g_signal_new ("move",
-                                            G_TYPE_FROM_CLASS (klass),
-                                            G_SIGNAL_RUN_LAST,
-                                            0, /* default signal handler */
-                                            NULL, NULL,
-                                            g_cclosure_marshal_VOID__VOID,
-                                            G_TYPE_NONE, 0);
-  jaw_window_signals [RESIZE] = g_signal_new ("resize",
-                                              G_TYPE_FROM_CLASS (klass),
-                                              G_SIGNAL_RUN_LAST,
-                                              0, /* default signal handler */
-                                              NULL,
-                                              NULL,
-                                              g_cclosure_marshal_VOID__VOID,
-                                              G_TYPE_NONE,
-                                              0);
-  jaw_window_signals [RESTORE] = g_signal_new ("restore",
-                                                G_TYPE_FROM_CLASS (klass),
-                                                G_SIGNAL_RUN_LAST,
-                                                0, /* default signal handler */
-                                                NULL,
-                                                NULL,
-                                                g_cclosure_marshal_VOID__VOID,
-                                                G_TYPE_NONE,
-                                                0);
+  // Signals
 }
 
 gpointer
-jaw_window_get_interface_data (JawWindow *jaw_win, guint iface)
+jaw_window_data_init (jobject ac)
 {
+  WindowData *data = g_new0(WindowData, 1);
 
-  JawWindowClass *klass = JAW_WINDOW_GET_CLASS(jaw_win);
-  if (klass->get_interface_data)
-    return klass->get_interface_data(jaw_win, iface);
+  JNIEnv *jniEnv = jaw_util_get_jni_env();
+  jclass classWindow = (*jniEnv)->FindClass(jniEnv, "org/GNOME/Accessibility/AtkWindow");
+  jmethodID jmid = (*jniEnv)->GetMethodID(jniEnv, classWindow, "<init>", 
"(Ljavax/accessibility/AccessibleContext;)V");
+  jobject jatk_window = (*jniEnv)->NewObject(jniEnv, classWindow, jmid, ac);
+  data->atk_window = (*jniEnv)->NewGlobalRef(jniEnv, jatk_window);
 
-  return NULL;
+  return data;
 }
 
 static void
@@ -151,45 +64,24 @@ jaw_window_init (JawWindow *window)
   window->state_set = atk_state_set_new();
 }
 
-static void
-jaw_window_dispose (GObject *gobject)
+void
+jaw_window_data_finalize (gpointer p)
 {
-  /* Chain up to parent's dispose method */
-  G_OBJECT_CLASS(parent_class)->dispose(gobject);
-}
-
-static void
-jaw_window_finalize (GObject *gobject)
-{
-  /* Customized finalize code */
-  JawObject *jaw_obj = JAW_OBJECT(gobject);
-  AtkObject *atk_obj = ATK_OBJECT(gobject);
+  WindowData *data = (WindowData*)p;
   JNIEnv *jniEnv = jaw_util_get_jni_env();
 
-  if (atk_obj->name != NULL)
-  {
-    (*jniEnv)->ReleaseStringUTFChars(jniEnv, jaw_obj->jstrName, atk_obj->name);
-    (*jniEnv)->DeleteGlobalRef(jniEnv, jaw_obj->jstrName);
-    jaw_obj->jstrName = NULL;
-    atk_obj->name = NULL;
-  }
-
-  if (atk_obj->description != NULL)
-  {
-    (*jniEnv)->ReleaseStringUTFChars(jniEnv,
-                                     jaw_obj->jstrDescription,
-                                     atk_obj->description);
-
-    (*jniEnv)->DeleteGlobalRef(jniEnv, jaw_obj->jstrDescription);
-    jaw_obj->jstrDescription = NULL;
-    atk_obj->description = NULL;
-  }
-
-  if (G_OBJECT(jaw_obj->state_set) != NULL)
+  if (data && data->atk_window)
   {
-    g_object_unref(G_OBJECT(jaw_obj->state_set));
-    /* Chain up to parent's finalize method */
-    G_OBJECT_CLASS(parent_class)->finalize(gobject);
+    if (data->description != NULL)
+    {
+      (*jniEnv)->ReleaseStringUTFChars(jniEnv, data->jstrDescription, data->description);
+      (*jniEnv)->DeleteGlobalRef(jniEnv, data->jstrDescription);
+      data->jstrDescription = NULL;
+      data->description = NULL;
+    }
+
+    (*jniEnv)->DeleteGlobalRef(jniEnv, data->atk_window);
+    data->atk_window = NULL;
   }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]