10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #import "java_awt_event_InputEvent.h"
27 #import "java_awt_event_KeyEvent.h"
28 #import "LWCToolkit.h"
29
30 #import "jni_util.h"
31
32 #import <JavaNativeFoundation/JavaNativeFoundation.h>
33 #import <sys/time.h>
34 #import <Carbon/Carbon.h>
35
36 /*
37 * Table to map typed characters to their Java virtual key equivalent and back.
38 * We use the incoming unichar (ignoring all modifiers) and try to figure out
39 * which virtual key code is appropriate. A lot of them just have direct
40 * mappings (the function keys, arrow keys, etc.) so they aren't a problem.
41 * We had to do something a little funky to catch the keys on the numeric
42 * key pad (i.e. using event mask to distinguish between period on regular
43 * keyboard and decimal on keypad). We also have to do something incredibly
44 * hokey with regards to the shifted punctuation characters. For examples,
45 * consider '&' which is usually Shift-7. For the Java key typed events,
46 * that's no problem, we just say pass the unichar. But for the
47 * KeyPressed/Released events, we need to identify the virtual key code
48 * (which roughly correspond to hardware keys) which means we are supposed
49 * to say the virtual 7 key was pressed. But how are we supposed to know
50 * when we get a punctuation char what was the real hardware key was that
51 * was pressed? Although '&' often comes from Shift-7 the keyboard can be
52 * remapped! I don't think there really is a good answer, and hopefully
658 return 0;
659 }
660
661 JNIEXPORT void JNICALL
662 Java_java_awt_AWTEvent_nativeSetSource
663 (JNIEnv *env, jobject self, jobject newSource)
664 {
665 }
666
667 /*
668 * Class: sun_lwawt_macosx_NSEvent
669 * Method: nsToJavaModifiers
670 * Signature: (II)I
671 */
672 JNIEXPORT jint JNICALL
673 Java_sun_lwawt_macosx_NSEvent_nsToJavaModifiers
674 (JNIEnv *env, jclass cls, jint modifierFlags)
675 {
676 jint jmodifiers = 0;
677
678 JNF_COCOA_ENTER(env);
679
680 jmodifiers = GetJavaMouseModifiers(modifierFlags);
681
682 JNF_COCOA_EXIT(env);
683
684 return jmodifiers;
685 }
686
687 /*
688 * Class: sun_lwawt_macosx_NSEvent
689 * Method: nsToJavaKeyInfo
690 * Signature: ([I[I)Z
691 */
692 JNIEXPORT jboolean JNICALL
693 Java_sun_lwawt_macosx_NSEvent_nsToJavaKeyInfo
694 (JNIEnv *env, jclass cls, jintArray inData, jintArray outData)
695 {
696 BOOL postsTyped = NO;
697
698 JNF_COCOA_ENTER(env);
699
700 jboolean copy = JNI_FALSE;
701 jint *data = (*env)->GetIntArrayElements(env, inData, ©);
702 CHECK_NULL_RETURN(data, postsTyped);
703
704 // in = [testChar, testDeadChar, modifierFlags, keyCode]
705 jchar testChar = (jchar)data[0];
706 BOOL isDeadChar = (data[1] != 0);
707 jint modifierFlags = data[2];
708 jshort keyCode = (jshort)data[3];
709
710 jint jkeyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
711 jint jkeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
712 jint testDeadChar = 0;
713
714 NsCharToJavaVirtualKeyCode((unichar)testChar, isDeadChar,
715 (NSUInteger)modifierFlags, (unsigned short)keyCode,
716 &jkeyCode, &jkeyLocation, &postsTyped,
717 (unichar *) &testDeadChar);
718
719 // out = [jkeyCode, jkeyLocation, deadChar];
720 (*env)->SetIntArrayRegion(env, outData, 0, 1, &jkeyCode);
721 (*env)->SetIntArrayRegion(env, outData, 1, 1, &jkeyLocation);
722 (*env)->SetIntArrayRegion(env, outData, 2, 1, &testDeadChar);
723
724 (*env)->ReleaseIntArrayElements(env, inData, data, 0);
725
726 JNF_COCOA_EXIT(env);
727
728 return postsTyped;
729 }
730
731 /*
732 * Class: sun_lwawt_macosx_NSEvent
733 * Method: nsKeyModifiersToJavaKeyInfo
734 * Signature: ([I[I)V
735 */
736 JNIEXPORT void JNICALL
737 Java_sun_lwawt_macosx_NSEvent_nsKeyModifiersToJavaKeyInfo
738 (JNIEnv *env, jclass cls, jintArray inData, jintArray outData)
739 {
740 JNF_COCOA_ENTER(env);
741
742 jboolean copy = JNI_FALSE;
743 jint *data = (*env)->GetIntArrayElements(env, inData, ©);
744 CHECK_NULL(data);
745
746 // in = [modifierFlags, keyCode]
747 jint modifierFlags = data[0];
748 jshort keyCode = (jshort)data[1];
749
750 jint jkeyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
751 jint jkeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
752 jint jkeyType = java_awt_event_KeyEvent_KEY_PRESSED;
753
754 NsKeyModifiersToJavaKeyInfo(modifierFlags,
755 keyCode,
756 &jkeyCode,
757 &jkeyLocation,
758 &jkeyType);
759
760 // out = [jkeyCode, jkeyLocation, jkeyType];
761 (*env)->SetIntArrayRegion(env, outData, 0, 1, &jkeyCode);
762 (*env)->SetIntArrayRegion(env, outData, 1, 1, &jkeyLocation);
763 (*env)->SetIntArrayRegion(env, outData, 2, 1, &jkeyType);
764
765 (*env)->ReleaseIntArrayElements(env, inData, data, 0);
766
767 JNF_COCOA_EXIT(env);
768 }
769
770 /*
771 * Class: sun_lwawt_macosx_NSEvent
772 * Method: nsToJavaChar
773 * Signature: (CI)C
774 */
775 JNIEXPORT jint JNICALL
776 Java_sun_lwawt_macosx_NSEvent_nsToJavaChar
777 (JNIEnv *env, jclass cls, jchar nsChar, jint modifierFlags, jboolean spaceKeyTyped)
778 {
779 jchar javaChar = 0;
780
781 JNF_COCOA_ENTER(env);
782
783 javaChar = NsCharToJavaChar(nsChar, modifierFlags, spaceKeyTyped);
784
785 JNF_COCOA_EXIT(env);
786
787 return javaChar;
788 }
|
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #import "java_awt_event_InputEvent.h"
27 #import "java_awt_event_KeyEvent.h"
28 #import "LWCToolkit.h"
29
30 #import "JNIUtilities.h"
31
32 #import <sys/time.h>
33 #import <Carbon/Carbon.h>
34
35 /*
36 * Table to map typed characters to their Java virtual key equivalent and back.
37 * We use the incoming unichar (ignoring all modifiers) and try to figure out
38 * which virtual key code is appropriate. A lot of them just have direct
39 * mappings (the function keys, arrow keys, etc.) so they aren't a problem.
40 * We had to do something a little funky to catch the keys on the numeric
41 * key pad (i.e. using event mask to distinguish between period on regular
42 * keyboard and decimal on keypad). We also have to do something incredibly
43 * hokey with regards to the shifted punctuation characters. For examples,
44 * consider '&' which is usually Shift-7. For the Java key typed events,
45 * that's no problem, we just say pass the unichar. But for the
46 * KeyPressed/Released events, we need to identify the virtual key code
47 * (which roughly correspond to hardware keys) which means we are supposed
48 * to say the virtual 7 key was pressed. But how are we supposed to know
49 * when we get a punctuation char what was the real hardware key was that
50 * was pressed? Although '&' often comes from Shift-7 the keyboard can be
51 * remapped! I don't think there really is a good answer, and hopefully
657 return 0;
658 }
659
660 JNIEXPORT void JNICALL
661 Java_java_awt_AWTEvent_nativeSetSource
662 (JNIEnv *env, jobject self, jobject newSource)
663 {
664 }
665
666 /*
667 * Class: sun_lwawt_macosx_NSEvent
668 * Method: nsToJavaModifiers
669 * Signature: (II)I
670 */
671 JNIEXPORT jint JNICALL
672 Java_sun_lwawt_macosx_NSEvent_nsToJavaModifiers
673 (JNIEnv *env, jclass cls, jint modifierFlags)
674 {
675 jint jmodifiers = 0;
676
677 JNI_COCOA_ENTER(env);
678
679 jmodifiers = GetJavaMouseModifiers(modifierFlags);
680
681 JNI_COCOA_EXIT(env);
682
683 return jmodifiers;
684 }
685
686 /*
687 * Class: sun_lwawt_macosx_NSEvent
688 * Method: nsToJavaKeyInfo
689 * Signature: ([I[I)Z
690 */
691 JNIEXPORT jboolean JNICALL
692 Java_sun_lwawt_macosx_NSEvent_nsToJavaKeyInfo
693 (JNIEnv *env, jclass cls, jintArray inData, jintArray outData)
694 {
695 BOOL postsTyped = NO;
696
697 JNI_COCOA_ENTER(env);
698
699 jboolean copy = JNI_FALSE;
700 jint *data = (*env)->GetIntArrayElements(env, inData, ©);
701 CHECK_NULL_RETURN(data, postsTyped);
702
703 // in = [testChar, testDeadChar, modifierFlags, keyCode]
704 jchar testChar = (jchar)data[0];
705 BOOL isDeadChar = (data[1] != 0);
706 jint modifierFlags = data[2];
707 jshort keyCode = (jshort)data[3];
708
709 jint jkeyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
710 jint jkeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
711 jint testDeadChar = 0;
712
713 NsCharToJavaVirtualKeyCode((unichar)testChar, isDeadChar,
714 (NSUInteger)modifierFlags, (unsigned short)keyCode,
715 &jkeyCode, &jkeyLocation, &postsTyped,
716 (unichar *) &testDeadChar);
717
718 // out = [jkeyCode, jkeyLocation, deadChar];
719 (*env)->SetIntArrayRegion(env, outData, 0, 1, &jkeyCode);
720 (*env)->SetIntArrayRegion(env, outData, 1, 1, &jkeyLocation);
721 (*env)->SetIntArrayRegion(env, outData, 2, 1, &testDeadChar);
722
723 (*env)->ReleaseIntArrayElements(env, inData, data, 0);
724
725 JNI_COCOA_EXIT(env);
726
727 return postsTyped;
728 }
729
730 /*
731 * Class: sun_lwawt_macosx_NSEvent
732 * Method: nsKeyModifiersToJavaKeyInfo
733 * Signature: ([I[I)V
734 */
735 JNIEXPORT void JNICALL
736 Java_sun_lwawt_macosx_NSEvent_nsKeyModifiersToJavaKeyInfo
737 (JNIEnv *env, jclass cls, jintArray inData, jintArray outData)
738 {
739 JNI_COCOA_ENTER(env);
740
741 jboolean copy = JNI_FALSE;
742 jint *data = (*env)->GetIntArrayElements(env, inData, ©);
743 CHECK_NULL(data);
744
745 // in = [modifierFlags, keyCode]
746 jint modifierFlags = data[0];
747 jshort keyCode = (jshort)data[1];
748
749 jint jkeyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
750 jint jkeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
751 jint jkeyType = java_awt_event_KeyEvent_KEY_PRESSED;
752
753 NsKeyModifiersToJavaKeyInfo(modifierFlags,
754 keyCode,
755 &jkeyCode,
756 &jkeyLocation,
757 &jkeyType);
758
759 // out = [jkeyCode, jkeyLocation, jkeyType];
760 (*env)->SetIntArrayRegion(env, outData, 0, 1, &jkeyCode);
761 (*env)->SetIntArrayRegion(env, outData, 1, 1, &jkeyLocation);
762 (*env)->SetIntArrayRegion(env, outData, 2, 1, &jkeyType);
763
764 (*env)->ReleaseIntArrayElements(env, inData, data, 0);
765
766 JNI_COCOA_EXIT(env);
767 }
768
769 /*
770 * Class: sun_lwawt_macosx_NSEvent
771 * Method: nsToJavaChar
772 * Signature: (CI)C
773 */
774 JNIEXPORT jint JNICALL
775 Java_sun_lwawt_macosx_NSEvent_nsToJavaChar
776 (JNIEnv *env, jclass cls, jchar nsChar, jint modifierFlags, jboolean spaceKeyTyped)
777 {
778 jchar javaChar = 0;
779
780 JNI_COCOA_ENTER(env);
781
782 javaChar = NsCharToJavaChar(nsChar, modifierFlags, spaceKeyTyped);
783
784 JNI_COCOA_EXIT(env);
785
786 return javaChar;
787 }
|