changeset 7291:3aa343ef3313

RT-37492 refactor Glass KeyEvent.getKeyCodeForChar moving impl to Application for ease of overriding in Java Reviewed-by: kcr, anthony
author ddhill
date Wed, 11 Jun 2014 17:01:44 -0400
parents 1bb43e54af7a
children 8ff6f815767f
files modules/graphics/src/main/java/com/sun/glass/events/KeyEvent.java modules/graphics/src/main/java/com/sun/glass/ui/Application.java modules/graphics/src/main/java/com/sun/glass/ui/gtk/GtkApplication.java modules/graphics/src/main/java/com/sun/glass/ui/ios/IosApplication.java modules/graphics/src/main/java/com/sun/glass/ui/lens/LensApplication.java modules/graphics/src/main/java/com/sun/glass/ui/mac/MacApplication.java modules/graphics/src/main/java/com/sun/glass/ui/monocle/MonocleApplication.java modules/graphics/src/main/java/com/sun/glass/ui/swt/SWTApplication.java modules/graphics/src/main/java/com/sun/glass/ui/win/WinApplication.java modules/graphics/src/main/native-glass/gtk/glass_key.cpp modules/graphics/src/main/native-glass/ios/GlassKey.m modules/graphics/src/main/native-glass/lens/LensApplication.c modules/graphics/src/main/native-glass/mac/GlassKey.m modules/graphics/src/main/native-glass/win/KeyTable.cpp
diffstat 14 files changed, 62 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/glass/events/KeyEvent.java	Wed Jun 11 22:52:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/events/KeyEvent.java	Wed Jun 11 17:01:44 2014 -0400
@@ -24,13 +24,9 @@
  */
 package com.sun.glass.events;
 
+import com.sun.glass.ui.Application;
+
 public class KeyEvent {
-    /***************************************************************************
-     *                                                                         *
-     * Native methods                                                          *
-     *                                                                         *
-     **************************************************************************/
-    native private static int _getKeyCodeForChar(char c);
 
     /***************************************************************************
      *                                                                         *
@@ -249,7 +245,7 @@
      * @return integer code for the given char
      */
     public static int getKeyCodeForChar(char c) {
-        return _getKeyCodeForChar(c);
+        return Application.getKeyCodeForChar(c);
     }
 
     /**
--- a/modules/graphics/src/main/java/com/sun/glass/ui/Application.java	Wed Jun 11 22:52:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/Application.java	Wed Jun 11 17:01:44 2014 -0400
@@ -729,4 +729,17 @@
         checkEventThread();
         return _supportsSystemMenu();
     }
+
+    protected abstract int _getKeyCodeForChar(char c);
+    /**
+     * Returns a VK_ code of a key capable of producing the given unicode
+     * character with respect to the currently active keyboard layout or
+     * VK_UNDEFINED if the character isn't present in the current layout.
+     *
+     * @param c the character
+     * @return integer code for the given char
+     */
+    public static int getKeyCodeForChar(char c) {
+        return application._getKeyCodeForChar(c);
+    }
 }
--- a/modules/graphics/src/main/java/com/sun/glass/ui/gtk/GtkApplication.java	Wed Jun 11 22:52:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/gtk/GtkApplication.java	Wed Jun 11 17:01:44 2014 -0400
@@ -324,4 +324,7 @@
         return false;
     }
 
+    @Override
+    protected native int _getKeyCodeForChar(char c);
+
 }
--- a/modules/graphics/src/main/java/com/sun/glass/ui/ios/IosApplication.java	Wed Jun 11 22:52:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/ios/IosApplication.java	Wed Jun 11 17:01:44 2014 -0400
@@ -279,4 +279,7 @@
     public boolean hasMultiTouch() {
         return true;
     }   
+
+    @Override
+    protected native int _getKeyCodeForChar(char c);
 }
--- a/modules/graphics/src/main/java/com/sun/glass/ui/lens/LensApplication.java	Wed Jun 11 22:52:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/lens/LensApplication.java	Wed Jun 11 17:01:44 2014 -0400
@@ -1798,4 +1798,7 @@
         return deviceFlags[DEVICE_POINTER] > 0;
     }
 
+    @Override
+    protected native int _getKeyCodeForChar(char c);
+
 }
--- a/modules/graphics/src/main/java/com/sun/glass/ui/mac/MacApplication.java	Wed Jun 11 22:52:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/mac/MacApplication.java	Wed Jun 11 17:01:44 2014 -0400
@@ -332,4 +332,7 @@
         }
         return baseDirectory + File.separator + name + File.separator;
     }
+
+    @Override
+    protected native int _getKeyCodeForChar(char c);
 }
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/MonocleApplication.java	Wed Jun 11 22:52:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/MonocleApplication.java	Wed Jun 11 17:01:44 2014 -0400
@@ -372,4 +372,9 @@
         _leaveNestedEventLoop(null);
     }
 
+    @Override
+    protected int _getKeyCodeForChar(char c) {
+        throw new UnsupportedOperationException("Missing function _getKeyCodeForChar ");
+    }
+
 }
--- a/modules/graphics/src/main/java/com/sun/glass/ui/swt/SWTApplication.java	Wed Jun 11 22:52:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/swt/SWTApplication.java	Wed Jun 11 17:01:44 2014 -0400
@@ -978,4 +978,9 @@
 //        return new SWTPixels(width, height, buffer);
         return null;
     }
+
+    @Override
+    protected int _getKeyCodeForChar(char c) {
+        return KeyEvent.VK_UNDEFINED;
+    }
 }
--- a/modules/graphics/src/main/java/com/sun/glass/ui/win/WinApplication.java	Wed Jun 11 22:52:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/win/WinApplication.java	Wed Jun 11 17:01:44 2014 -0400
@@ -283,4 +283,7 @@
         }
         return baseDirectory + File.separator + name + File.separator;
     }
+
+    @Override
+    protected native int _getKeyCodeForChar(char c);
 }
--- a/modules/graphics/src/main/native-glass/gtk/glass_key.cpp	Wed Jun 11 22:52:13 2014 +0300
+++ b/modules/graphics/src/main/native-glass/gtk/glass_key.cpp	Wed Jun 11 17:01:44 2014 -0400
@@ -25,6 +25,7 @@
 #include "glass_key.h"
 #include "glass_gtkcompat.h"
 #include <com_sun_glass_events_KeyEvent.h>
+#include <com_sun_glass_ui_gtk_GtkApplication.h>
 
 #include <glib.h>
 #include <gdk/gdk.h>
@@ -289,12 +290,12 @@
 extern "C" {
 
 /*
- * Class:     com_sun_glass_events_KeyEvent
+ * Class:     com_sun_glass_ui_gtk_GtkApplication
  * Method:    _getKeyCodeForChar
  * Signature: (C)I
  */
-JNIEXPORT jint JNICALL Java_com_sun_glass_events_KeyEvent__1getKeyCodeForChar
-  (JNIEnv *env, jclass clazz, jchar character)
+JNIEXPORT jint JNICALL Java_com_sun_glass_ui_gtk_GtkApplication__1getKeyCodeForChar
+  (JNIEnv *env, jobject jApplication, jchar character)
 {
     gunichar *ucs_char = g_utf16_to_ucs4(&character, 1, NULL, NULL, NULL);
     if (ucs_char == NULL) {
--- a/modules/graphics/src/main/native-glass/ios/GlassKey.m	Wed Jun 11 22:52:13 2014 +0300
+++ b/modules/graphics/src/main/native-glass/ios/GlassKey.m	Wed Jun 11 17:01:44 2014 -0400
@@ -26,19 +26,20 @@
 #import <UIKit/UIKit.h>
 
 #include "com_sun_glass_events_KeyEvent.h"
+#include "com_sun_glass_ui_ios_IosApplication.h"
 
 #include "GlassMacros.h"
 
 
 /*
- * Class:     com_sun_glass_events_KeyEvent
+ * Class:     com_sun_glass_ui_ios_IosApplication
  * Method:    _getKeyCodeForChar
  * Signature: (C)I
  */
-JNIEXPORT jint JNICALL Java_com_sun_glass_events_KeyEvent__1getKeyCodeForChar
-(JNIEnv * env, jclass cls, jchar c)
+JNIEXPORT jint JNICALL Java_com_sun_glass_ui_ios_IosApplication__1getKeyCodeForChar
+(JNIEnv * env, jobject jApplication, jchar c)
 {
-    GLASS_LOG("Java_com_sun_glass_events_KeyEvent__1getKeyCodeForChar");
+    GLASS_LOG("Java_com_sun_glass_ui_ios_IosApplication__1getKeyCodeForChar");
     
     return com_sun_glass_events_KeyEvent_VK_UNDEFINED;
 }
--- a/modules/graphics/src/main/native-glass/lens/LensApplication.c	Wed Jun 11 22:52:13 2014 +0300
+++ b/modules/graphics/src/main/native-glass/lens/LensApplication.c	Wed Jun 11 17:01:44 2014 -0400
@@ -789,12 +789,12 @@
 
 
 /*
- * Class:     com_sun_glass_events_KeyEvent
+ * Class:     com_sun_glass_ui_lens_LensApplication
  * Method:    _getKeyCodeForChar
  * Signature: (C)I
  */
-JNIEXPORT jint JNICALL Java_com_sun_glass_events_KeyEvent__1getKeyCodeForChar
-(JNIEnv *env, jclass keyeventClass, jchar c) {
+JNIEXPORT jint JNICALL Java_com_sun_glass_ui_lens_LensApplication__1getKeyCodeForChar
+(JNIEnv *env, jobject jApplication, jchar c) {
     GLASS_LOG_FINE("Java key code requested for c='%c' (0x%04x)",
                    (char) c, (int) c);
     return glass_inputEvents_getJavaKeyCodeFromJChar(c);
--- a/modules/graphics/src/main/native-glass/mac/GlassKey.m	Wed Jun 11 22:52:13 2014 +0300
+++ b/modules/graphics/src/main/native-glass/mac/GlassKey.m	Wed Jun 11 17:01:44 2014 -0400
@@ -25,6 +25,7 @@
 
 #import "common.h"
 #import "com_sun_glass_events_KeyEvent.h"
+#import "com_sun_glass_ui_mac_MacApplication.h"
 
 #import "GlassApplication.h"
 #import "GlassMacros.h"
@@ -369,14 +370,14 @@
 }
 
 /*
- * Class:     com_sun_glass_events_KeyEvent
+ * Class:     com_sun_glass_ui_mac_MacApplication
  * Method:    _getKeyCodeForChar
  * Signature: (C)I
  */
-JNIEXPORT jint JNICALL Java_com_sun_glass_events_KeyEvent__1getKeyCodeForChar
-(JNIEnv * env, jclass cls, jchar c)
+JNIEXPORT jint JNICALL Java_com_sun_glass_ui_mac_MacApplication__1getKeyCodeForChar
+(JNIEnv * env, jobject jApplication, jchar c)
 {
-    LOG("Java_com_sun_glass_events_KeyEvent__1getKeyCodeForChar");
+    LOG("Java_com_sun_glass_ui_mac_MacApplication__1getKeyCodeForChar");
 
     return [GlassApplication getKeyCodeForChar:c];
 }
--- a/modules/graphics/src/main/native-glass/win/KeyTable.cpp	Wed Jun 11 22:52:13 2014 +0300
+++ b/modules/graphics/src/main/native-glass/win/KeyTable.cpp	Wed Jun 11 17:01:44 2014 -0400
@@ -29,6 +29,7 @@
 #include "GlassApplication.h"
 
 #include "com_sun_glass_events_KeyEvent.h"
+#include "com_sun_glass_ui_win_WinApplication.h"
 
 
 struct KeyMapEntry
@@ -229,12 +230,12 @@
 }
 
 /*
- * Class:     com_sun_glass_events_KeyEvent
+ * Class:     Java_com_sun_glass_ui_win_WinApplication
  * Method:    _getKeyCodeForChar
  * Signature: (C)I
  */
-JNIEXPORT jint JNICALL Java_com_sun_glass_events_KeyEvent__1getKeyCodeForChar
-  (JNIEnv * env, jclass cls, jchar c)
+JNIEXPORT jint JNICALL Java_com_sun_glass_ui_win_WinApplication__1getKeyCodeForChar
+  (JNIEnv * env, jobject jApplication, jchar c)
 {
     BYTE vkey = 0xFF & ::VkKeyScanEx((TCHAR)c,
             ::GetKeyboardLayout(GlassApplication::GetMainThreadId()));