[java-atk-wrapper] JNI: Create JAW_TYPE_WINDOW



commit b1b75e80a7685c71eb73b5b134bf1980860f9668
Author: Magdalen Berns <m berns thismagpie com>
Date:   Thu Jun 18 21:57:50 2015 +0100

    JNI: Create JAW_TYPE_WINDOW
    
    Bug: https://bugzilla.gnome.org/show_bug.cgi?id=751183

 jni/src/AtkWrapper.c |   17 ++++++-----
 jni/src/Makefile.am  |    3 +-
 jni/src/jawutil.c    |   18 +++++--------
 jni/src/jawwindow.c  |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++
 jni/src/jawwindow.h  |   68 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 157 insertions(+), 20 deletions(-)
---
diff --git a/jni/src/AtkWrapper.c b/jni/src/AtkWrapper.c
index 971ac56..2831f2c 100644
--- a/jni/src/AtkWrapper.c
+++ b/jni/src/AtkWrapper.c
@@ -30,6 +30,7 @@
 #include "jawutil.h"
 #include "jawimpl.h"
 #include "jawtoplevel.h"
+#include "jawwindow.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -318,7 +319,7 @@ window_open_handler (gpointer p)
                           atk_obj,
                           NULL);
 
-    g_signal_emit(atk_obj, g_signal_lookup("create", JAW_TYPE_OBJECT), 0);
+    g_signal_emit(atk_obj, g_signal_lookup("create", JAW_TYPE_WINDOW), 0);
   }
 
   free_callback_para(para);
@@ -396,7 +397,7 @@ window_close_handler (gpointer p)
                           atk_obj,
                           NULL);
 
-    g_signal_emit(atk_obj, g_signal_lookup("destroy", JAW_TYPE_OBJECT), 0);
+    g_signal_emit(atk_obj, g_signal_lookup("destroy", JAW_TYPE_WINDOW), 0);
   }
 
   free_callback_para(para);
@@ -448,7 +449,7 @@ window_minimize_handler (gpointer p)
   }
 
   AtkObject* atk_obj = ATK_OBJECT(jaw_impl);
-  g_signal_emit(atk_obj, g_signal_lookup("minimize", JAW_TYPE_OBJECT), 0);
+  g_signal_emit(atk_obj, g_signal_lookup("minimize", JAW_TYPE_WINDOW), 0);
 
   free_callback_para(para);
 
@@ -498,7 +499,7 @@ window_maximize_handler (gpointer p)
   }
 
   AtkObject* atk_obj = ATK_OBJECT(jaw_impl);
-  g_signal_emit(atk_obj, g_signal_lookup("maximize", JAW_TYPE_OBJECT), 0);
+  g_signal_emit(atk_obj, g_signal_lookup("maximize", JAW_TYPE_WINDOW), 0);
 
   free_callback_para(para);
 
@@ -547,7 +548,7 @@ window_restore_handler (gpointer p)
   }
 
   AtkObject* atk_obj = ATK_OBJECT(jaw_impl);
-  g_signal_emit(atk_obj, g_signal_lookup("restore", JAW_TYPE_OBJECT), 0);
+  g_signal_emit(atk_obj, g_signal_lookup("restore", JAW_TYPE_WINDOW), 0);
 
   free_callback_para(para);
 
@@ -596,7 +597,7 @@ window_activate_handler (gpointer p)
   }
 
   AtkObject* atk_obj = ATK_OBJECT(jaw_impl);
-  g_signal_emit(atk_obj, g_signal_lookup("activate", JAW_TYPE_OBJECT), 0);
+  g_signal_emit(atk_obj, g_signal_lookup("activate", JAW_TYPE_WINDOW), 0);
 
   free_callback_para(para);
 
@@ -644,7 +645,7 @@ window_deactivate_handler (gpointer p)
   }
 
   AtkObject* atk_obj = ATK_OBJECT(jaw_impl);
-  g_signal_emit(atk_obj, g_signal_lookup("deactivate", JAW_TYPE_OBJECT), 0);
+  g_signal_emit(atk_obj, g_signal_lookup("deactivate", JAW_TYPE_WINDOW), 0);
 
   free_callback_para(para);
 
@@ -695,7 +696,7 @@ window_state_change_handler (gpointer p)
   }
 
   AtkObject* atk_obj = ATK_OBJECT(jaw_impl);
-  g_signal_emit(atk_obj, g_signal_lookup("state-change", JAW_TYPE_OBJECT), 0);
+  g_signal_emit(atk_obj, g_signal_lookup("state-change", JAW_TYPE_WINDOW), 0);
 
   free_callback_para(para);
 
diff --git a/jni/src/Makefile.am b/jni/src/Makefile.am
index b4f0902..f4b3279 100644
--- a/jni/src/Makefile.am
+++ b/jni/src/Makefile.am
@@ -22,7 +22,8 @@ noinst_HEADERS = jawimpl.h \
                  jawobject.h \
                  jawhyperlink.h \
                  jawtoplevel.h \
-                 jawutil.h
+                 jawutil.h \
+                 jawwindow.h
 
 libatk_wrapper_la_CFLAGS = $(JAW_CFLAGS) \
                            $(JNI_INCLUDES)
diff --git a/jni/src/jawutil.c b/jni/src/jawutil.c
index d148267..8d6fdff 100644
--- a/jni/src/jawutil.c
+++ b/jni/src/jawutil.c
@@ -27,6 +27,7 @@
 #include "jawutil.h"
 #include "jawtoplevel.h"
 #include "jawobject.h"
+#include "jawwindow.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -120,19 +121,14 @@ jaw_util_add_global_event_listener(GSignalEmissionHook listener,
 {
   guint rc = 0;
   gchar **split_string;
+  guint length;
 
-  g_type_class_unref( g_type_class_ref(JAW_TYPE_OBJECT));
-  split_string = g_strsplit (event_type, ":", 3);
+  split_string = g_strsplit (event_type, ":", 0);
+  length = g_strv_length (split_string);
 
-  if (split_string) {
-    if (!strcmp ("window", split_string[0])) {
-      rc = add_listener (listener, "JawObject", split_string[1], event_type);
-    } else {
-      rc = add_listener (listener, split_string[1], split_string[2], event_type);
-    }
-
-    g_strfreev (split_string);
-  }
+  if ((length == 3) || (length == 4))
+    rc = add_listener (listener, split_string[1], split_string[2], event_type);
+  g_strfreev (split_string);
 
   return rc;
 }
diff --git a/jni/src/jawwindow.c b/jni/src/jawwindow.c
index f2b24ca..70a6f34 100644
--- a/jni/src/jawwindow.c
+++ b/jni/src/jawwindow.c
@@ -24,11 +24,24 @@
 #include "jawimpl.h"
 #include "jawutil.h"
 #include "jawtoplevel.h"
+#include "jawwindow.h"
 
 extern void jaw_window_interface_init (AtkWindowIface*);
 extern gpointer jaw_window_data_init (jobject ac);
 extern void jaw_window_data_finalize (gpointer p);
 
+static void jaw_window_class_init(JawWindowClass *klass);
+static void jaw_window_class_dispose(GObject *gobject);
+static void jaw_window_class_finalize(GObject *gobject);
+
+G_DEFINE_TYPE_WITH_CODE (JawWindow,
+                         jaw_window,
+                         JAW_TYPE_WINDOW,
+                         G_IMPLEMENT_INTERFACE (ATK_TYPE_WINDOW,
+                                                jaw_window_interface_init));
+
+static gpointer parent_class = NULL;
+
 typedef struct _WindowData {
   jobject atk_window;
 } WindowData;
@@ -39,6 +52,64 @@ jaw_window_interface_init (AtkWindowIface *iface)
   // Signals
 }
 
+static void
+jaw_window_initialize (AtkObject *atk_obj, gpointer data)
+{
+  JawObject *jaw_obj = JAW_OBJECT(atk_obj);
+  WindowData *windata = jaw_object_get_interface_data(jaw_obj, INTERFACE_WINDOW);
+  jobject atk_widget = windata->atk_window;
+  atk_obj->role = jaw_util_get_atk_role_from_jobj (atk_widget);
+}
+
+static void jaw_window_class_init(JawWindowClass *klass)
+{
+  AtkUtilClass *atk_class;
+  gpointer data;
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  gobject_class->finalize = jaw_window_class_finalize;
+  gobject_class->dispose = jaw_window_class_dispose;
+
+  parent_class = g_type_class_peek_parent (klass);
+  JawObjectClass *jaw_class = JAW_OBJECT_CLASS (klass);
+  klass->get_interface_data = NULL;
+}
+
+gpointer
+jaw_window_get_interface_data (JawWindow *jaw_win, guint iface)
+{
+  JawWindowClass *klass = JAW_WINDOW_GET_CLASS(jaw_win);
+  if (klass->get_interface_data)
+    return klass->get_interface_data(jaw_win, iface);
+
+  return NULL;
+}
+
+static void
+jaw_window_init (JawWindow *window)
+{
+  window->state_set = atk_state_set_new();
+}
+
+static void
+jaw_window_class_dispose (GObject *gobject)
+{
+  G_OBJECT_CLASS(parent_class)->dispose(gobject);
+}
+
+static void
+jaw_window_class_finalize (GObject *gobject)
+{
+  JawWindow *jaw_obj = JAW_WINDOW(gobject);
+  AtkObject *atk_obj = ATK_OBJECT(gobject);
+  JNIEnv *jniEnv = jaw_util_get_jni_env();
+
+  if (G_OBJECT(jaw_obj->state_set) != NULL)
+  {
+    g_object_unref(G_OBJECT(jaw_obj->state_set));
+    G_OBJECT_CLASS(parent_class)->finalize(gobject);
+  }
+}
+
 gpointer
 jaw_window_data_init (jobject ac)
 {
diff --git a/jni/src/jawwindow.h b/jni/src/jawwindow.h
new file mode 100644
index 0000000..6317741
--- /dev/null
+++ b/jni/src/jawwindow.h
@@ -0,0 +1,68 @@
+/**
+ * Java ATK Wrapper for GNOME
+ *
+ * Copyright (C) 2015 Magdalen Berns <m berns thismagpie com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+ 
+#ifndef __JAW_WINDOW_H__
+#define __JAW_WINDOW_H__
+
+#include <atk/atk.h>
+#include <glib.h>
+#include "jawtoplevel.h"
+
+G_BEGIN_DECLS
+
+#define JAW_TYPE_WINDOW            (jaw_window_get_type ())
+#define JAW_WINDOW(obj)       (G_TYPE_CHECK_INSTANCE_CAST ((obj), JAW_TYPE_WINDOW, JawWindow))
+#define JAW_WINDOW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), JAW_TYPE_WINDOW, JawWindowClass))
+#define JAW_IS_WINDOW(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), JAW_TYPE_WINDOW))
+#define JAW_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), JAW_TYPE_WINDOW))
+#define JAW_WINDOW_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), JAW_TYPE_WINDOW, JawWindowClass))
+#define JAW_WINDOW_GET_IFACE(obj)  (G_TYPE_INSTANCE_GET_INTERFACE ((obj), JAW_TYPE_WINDOW, JawWindowIface))
+
+typedef struct _JawWindow        JawWindow;
+typedef struct _JawWindowClass   JawWindowClass;
+typedef struct _JawWindowPrivate JawWindowPrivate;
+typedef struct _JawWindowIface   JawWindowIface;
+
+struct _JawWindow
+{
+  JawToplevel parent;
+  AtkStateSet *state_set;
+  JawWindowPrivate *priv;
+};
+
+struct _JawWindowClass
+{
+  JawToplevelClass parent_class;
+  gpointer (*get_interface_data) (JawWindow*, guint);
+};
+
+struct _JawWindowIface
+{
+  GTypeInterface iface_parent;
+};
+
+GType jaw_window_get_type (void);
+
+gpointer
+jaw_window_get_interface_data (JawWindow *jaw_win, guint iface);
+
+G_END_DECLS
+
+#endif /* __JAW_WINDOW_H__ */


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