1 /*
2 * Copyright (c) 2011, 2017, 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
302 0,
303 61,
304 java_awt_event_InputEvent_ALT_DOWN_MASK | java_awt_event_InputEvent_ALT_GRAPH_DOWN_MASK,
305 java_awt_event_InputEvent_ALT_MASK | java_awt_event_InputEvent_ALT_GRAPH_MASK,
306 java_awt_event_KeyEvent_VK_ALT | java_awt_event_KeyEvent_VK_ALT_GRAPH
307 },
308 // NSNumericPadKeyMask
309 {
310 NSHelpKeyMask,
311 0,
312 0,
313 0, // no Java equivalent
314 0, // no Java equivalent
315 java_awt_event_KeyEvent_VK_HELP
316 },
317 // NSFunctionKeyMask
318 {0, 0, 0, 0, 0, 0}
319 };
320
321 static BOOL leftAltKeyPressed;
322 static BOOL altGRPressed = NO;
323
324 /*
325 * Almost all unicode characters just go from NS to Java with no translation.
326 * For the few exceptions, we handle it here with this small table.
327 */
328 #define ALL_NS_KEY_MODIFIERS_MASK \
329 (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask)
330
331 static struct _char {
332 NSUInteger modifier;
333 unichar nsChar;
334 unichar javaChar;
335 }
336 const charTable[] = {
337 // map enter on keypad to same as return key
338 {0, NSEnterCharacter, NSNewlineCharacter},
339
340 // [3134616] return newline instead of carriage return
341 {0, NSCarriageReturnCharacter, NSNewlineCharacter},
342
550 continue;
551 }
552 *javaKeyType = (cur->nsMask & nsFlags) ?
553 java_awt_event_KeyEvent_KEY_PRESSED :
554 java_awt_event_KeyEvent_KEY_RELEASED;
555 break;
556 }
557 }
558 }
559
560 /*
561 * This returns the java modifiers for a key NSEvent.
562 */
563 jint NsKeyModifiersToJavaModifiers(NSUInteger nsFlags, BOOL isExtMods)
564 {
565 jint javaModifiers = 0;
566 const struct _nsKeyToJavaModifier* cur;
567
568 for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
569 if ((cur->nsMask & nsFlags) != 0) {
570
571 if (cur->nsMask == NSAlternateKeyMask) {
572 if (leftAltKeyPressed == YES) {
573 javaModifiers |= isExtMods? cur->javaExtMask : cur->javaMask;
574 if (altGRPressed == NO)
575 break;
576 } else {
577 leftAltKeyPressed = YES;
578 altGRPressed = YES;
579 continue;
580 }
581 }
582 javaModifiers |= isExtMods ? cur->javaExtMask : cur->javaMask;
583 }
584 }
585
586 return javaModifiers;
587 }
588
589 /*
590 * This returns the NSEvent flags for java key modifiers.
591 */
592 NSUInteger JavaModifiersToNsKeyModifiers(jint javaModifiers, BOOL isExtMods)
593 {
594 NSUInteger nsFlags = 0;
595 const struct _nsKeyToJavaModifier* cur;
596
597 for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
598 jint mask = isExtMods? cur->javaExtMask : cur->javaMask;
599 if ((mask & javaModifiers) != 0) {
600 nsFlags |= cur->nsMask;
601 }
602 }
|
1 /*
2 * Copyright (c) 2011, 2019, 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
302 0,
303 61,
304 java_awt_event_InputEvent_ALT_DOWN_MASK | java_awt_event_InputEvent_ALT_GRAPH_DOWN_MASK,
305 java_awt_event_InputEvent_ALT_MASK | java_awt_event_InputEvent_ALT_GRAPH_MASK,
306 java_awt_event_KeyEvent_VK_ALT | java_awt_event_KeyEvent_VK_ALT_GRAPH
307 },
308 // NSNumericPadKeyMask
309 {
310 NSHelpKeyMask,
311 0,
312 0,
313 0, // no Java equivalent
314 0, // no Java equivalent
315 java_awt_event_KeyEvent_VK_HELP
316 },
317 // NSFunctionKeyMask
318 {0, 0, 0, 0, 0, 0}
319 };
320
321 static BOOL leftAltKeyPressed;
322
323 /*
324 * Almost all unicode characters just go from NS to Java with no translation.
325 * For the few exceptions, we handle it here with this small table.
326 */
327 #define ALL_NS_KEY_MODIFIERS_MASK \
328 (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask)
329
330 static struct _char {
331 NSUInteger modifier;
332 unichar nsChar;
333 unichar javaChar;
334 }
335 const charTable[] = {
336 // map enter on keypad to same as return key
337 {0, NSEnterCharacter, NSNewlineCharacter},
338
339 // [3134616] return newline instead of carriage return
340 {0, NSCarriageReturnCharacter, NSNewlineCharacter},
341
549 continue;
550 }
551 *javaKeyType = (cur->nsMask & nsFlags) ?
552 java_awt_event_KeyEvent_KEY_PRESSED :
553 java_awt_event_KeyEvent_KEY_RELEASED;
554 break;
555 }
556 }
557 }
558
559 /*
560 * This returns the java modifiers for a key NSEvent.
561 */
562 jint NsKeyModifiersToJavaModifiers(NSUInteger nsFlags, BOOL isExtMods)
563 {
564 jint javaModifiers = 0;
565 const struct _nsKeyToJavaModifier* cur;
566
567 for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
568 if ((cur->nsMask & nsFlags) != 0) {
569 //This code will consider the mask value for left alt as well as
570 //right alt, but that should be ok, since right alt contains left alt
571 //mask value.
572 javaModifiers |= isExtMods ? cur->javaExtMask : cur->javaMask;
573 if (cur->nsMask == NSAlternateKeyMask && leftAltKeyPressed) {
574 break; //since right alt key struct is defined last, break out of the loop }
575 }
576 }
577 }
578
579 return javaModifiers;
580 }
581
582 /*
583 * This returns the NSEvent flags for java key modifiers.
584 */
585 NSUInteger JavaModifiersToNsKeyModifiers(jint javaModifiers, BOOL isExtMods)
586 {
587 NSUInteger nsFlags = 0;
588 const struct _nsKeyToJavaModifier* cur;
589
590 for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
591 jint mask = isExtMods? cur->javaExtMask : cur->javaMask;
592 if ((mask & javaModifiers) != 0) {
593 nsFlags |= cur->nsMask;
594 }
595 }
|