1 /*
2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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
562
563 for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
564 jint mask = isExtMods? cur->javaExtMask : cur->javaMask;
565 if ((mask & javaModifiers) != 0) {
566 nsFlags |= cur->nsMask;
567 }
568 }
569
570 // special case
571 jint mask = isExtMods? java_awt_event_InputEvent_ALT_GRAPH_DOWN_MASK :
572 java_awt_event_InputEvent_ALT_GRAPH_MASK;
573
574 if ((mask & javaModifiers) != 0) {
575 nsFlags |= NSAlternateKeyMask;
576 }
577
578 return nsFlags;
579 }
580
581
582 jint GetJavaMouseModifiers(NSInteger button, NSUInteger modifierFlags)
583 {
584 // Mousing needs the key modifiers
585 jint modifiers = NsKeyModifiersToJavaModifiers(modifierFlags, YES);
586
587
588 /*
589 * Ask Quartz about mouse buttons state
590 */
591
592 if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
593 kCGMouseButtonLeft)) {
594 modifiers |= java_awt_event_InputEvent_BUTTON1_DOWN_MASK;
595 }
596
597 if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
598 kCGMouseButtonRight)) {
599 modifiers |= java_awt_event_InputEvent_BUTTON3_DOWN_MASK;
600 }
601
602 if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
615 return modifiers;
616 }
617
618 jlong UTC(NSEvent *event) {
619 struct timeval tv;
620 if (gettimeofday(&tv, NULL) == 0) {
621 long long sec = (long long)tv.tv_sec;
622 return (sec*1000) + (tv.tv_usec/1000);
623 }
624 return 0;
625 }
626
627 JNIEXPORT void JNICALL
628 Java_java_awt_AWTEvent_nativeSetSource
629 (JNIEnv *env, jobject self, jobject newSource)
630 {
631 }
632
633 /*
634 * Class: sun_lwawt_macosx_NSEvent
635 * Method: nsToJavaMouseModifiers
636 * Signature: (II)I
637 */
638 JNIEXPORT jint JNICALL
639 Java_sun_lwawt_macosx_NSEvent_nsToJavaMouseModifiers
640 (JNIEnv *env, jclass cls, jint buttonNumber, jint modifierFlags)
641 {
642 jint jmodifiers = 0;
643
644 JNF_COCOA_ENTER(env);
645
646 jmodifiers = GetJavaMouseModifiers(buttonNumber, modifierFlags);
647
648 JNF_COCOA_EXIT(env);
649
650 return jmodifiers;
651 }
652
653 /*
654 * Class: sun_lwawt_macosx_NSEvent
655 * Method: nsToJavaKeyModifiers
656 * Signature: (I)I
657 */
658 JNIEXPORT jint JNICALL
659 Java_sun_lwawt_macosx_NSEvent_nsToJavaKeyModifiers
660 (JNIEnv *env, jclass cls, jint modifierFlags)
661 {
662 jint jmodifiers = 0;
663
664 JNF_COCOA_ENTER(env);
665
666 jmodifiers = NsKeyModifiersToJavaModifiers(modifierFlags, YES);
667
668 JNF_COCOA_EXIT(env);
669
670 return jmodifiers;
671 }
672
673 /*
674 * Class: sun_lwawt_macosx_NSEvent
675 * Method: nsToJavaKeyInfo
676 * Signature: ([I[I)Z
677 */
678 JNIEXPORT jboolean JNICALL
679 Java_sun_lwawt_macosx_NSEvent_nsToJavaKeyInfo
680 (JNIEnv *env, jclass cls, jintArray inData, jintArray outData)
681 {
682 BOOL postsTyped = NO;
683
684 JNF_COCOA_ENTER(env);
685
686 jboolean copy = JNI_FALSE;
|
1 /*
2 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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
562
563 for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
564 jint mask = isExtMods? cur->javaExtMask : cur->javaMask;
565 if ((mask & javaModifiers) != 0) {
566 nsFlags |= cur->nsMask;
567 }
568 }
569
570 // special case
571 jint mask = isExtMods? java_awt_event_InputEvent_ALT_GRAPH_DOWN_MASK :
572 java_awt_event_InputEvent_ALT_GRAPH_MASK;
573
574 if ((mask & javaModifiers) != 0) {
575 nsFlags |= NSAlternateKeyMask;
576 }
577
578 return nsFlags;
579 }
580
581
582 jint GetJavaMouseModifiers(NSUInteger modifierFlags)
583 {
584 // Mousing needs the key modifiers
585 jint modifiers = NsKeyModifiersToJavaModifiers(modifierFlags, YES);
586
587
588 /*
589 * Ask Quartz about mouse buttons state
590 */
591
592 if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
593 kCGMouseButtonLeft)) {
594 modifiers |= java_awt_event_InputEvent_BUTTON1_DOWN_MASK;
595 }
596
597 if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
598 kCGMouseButtonRight)) {
599 modifiers |= java_awt_event_InputEvent_BUTTON3_DOWN_MASK;
600 }
601
602 if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
615 return modifiers;
616 }
617
618 jlong UTC(NSEvent *event) {
619 struct timeval tv;
620 if (gettimeofday(&tv, NULL) == 0) {
621 long long sec = (long long)tv.tv_sec;
622 return (sec*1000) + (tv.tv_usec/1000);
623 }
624 return 0;
625 }
626
627 JNIEXPORT void JNICALL
628 Java_java_awt_AWTEvent_nativeSetSource
629 (JNIEnv *env, jobject self, jobject newSource)
630 {
631 }
632
633 /*
634 * Class: sun_lwawt_macosx_NSEvent
635 * Method: nsToJavaModifiers
636 * Signature: (II)I
637 */
638 JNIEXPORT jint JNICALL
639 Java_sun_lwawt_macosx_NSEvent_nsToJavaModifiers
640 (JNIEnv *env, jclass cls, jint modifierFlags)
641 {
642 jint jmodifiers = 0;
643
644 JNF_COCOA_ENTER(env);
645
646 jmodifiers = GetJavaMouseModifiers(modifierFlags);
647
648 JNF_COCOA_EXIT(env);
649
650 return jmodifiers;
651 }
652
653 /*
654 * Class: sun_lwawt_macosx_NSEvent
655 * Method: nsToJavaKeyInfo
656 * Signature: ([I[I)Z
657 */
658 JNIEXPORT jboolean JNICALL
659 Java_sun_lwawt_macosx_NSEvent_nsToJavaKeyInfo
660 (JNIEnv *env, jclass cls, jintArray inData, jintArray outData)
661 {
662 BOOL postsTyped = NO;
663
664 JNF_COCOA_ENTER(env);
665
666 jboolean copy = JNI_FALSE;
|