jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTEvent.m
author serb
Sat, 26 Sep 2015 22:38:36 +0300
changeset 32872 abca6234313d
parent 26751 70bac69b37c9
child 35657 5ee7a31d7923
permissions -rw-r--r--
8079965: Stop ignoring warnings for libawt_lwawt Reviewed-by: prr, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     1
/*
23268
2cdb715ff32d 8029868: Fix KSS issues in sun.lwawt.macosx
pchelko
parents: 20105
diff changeset
     2
 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
#import "java_awt_event_InputEvent.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
#import "java_awt_event_KeyEvent.h"
32872
abca6234313d 8079965: Stop ignoring warnings for libawt_lwawt
serb
parents: 26751
diff changeset
    28
#import "LWCToolkit.h"
abca6234313d 8079965: Stop ignoring warnings for libawt_lwawt
serb
parents: 26751
diff changeset
    29
abca6234313d 8079965: Stop ignoring warnings for libawt_lwawt
serb
parents: 26751
diff changeset
    30
#import "jni_util.h"
abca6234313d 8079965: Stop ignoring warnings for libawt_lwawt
serb
parents: 26751
diff changeset
    31
abca6234313d 8079965: Stop ignoring warnings for libawt_lwawt
serb
parents: 26751
diff changeset
    32
#import <JavaNativeFoundation/JavaNativeFoundation.h>
abca6234313d 8079965: Stop ignoring warnings for libawt_lwawt
serb
parents: 26751
diff changeset
    33
#import <sys/time.h>
abca6234313d 8079965: Stop ignoring warnings for libawt_lwawt
serb
parents: 26751
diff changeset
    34
#import <Carbon/Carbon.h>
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
 * Table to map typed characters to their Java virtual key equivalent and back.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
 * We use the incoming unichar (ignoring all modifiers) and try to figure out
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
 * which virtual key code is appropriate. A lot of them just have direct
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
 * mappings (the function keys, arrow keys, etc.) so they aren't a problem.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
 * We had to do something a little funky to catch the keys on the numeric
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
 * key pad (i.e. using event mask to distinguish between period on regular
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
 * keyboard and decimal on keypad). We also have to do something incredibly
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
 * hokey with regards to the shifted punctuation characters. For examples,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
 * consider '&' which is usually Shift-7.  For the Java key typed events,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
 * that's no problem, we just say pass the unichar. But for the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    47
 * KeyPressed/Released events, we need to identify the virtual key code
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    48
 * (which roughly correspond to hardware keys) which means we are supposed
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
 * to say the virtual 7 key was pressed.  But how are we supposed to know
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
 * when we get a punctuation char what was the real hardware key was that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
 * was pressed?  Although '&' often comes from Shift-7 the keyboard can be
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    52
 * remapped!  I don't think there really is a good answer, and hopefully
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    53
 * all good applets are only interested in logical key typed events not
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    54
 * press/release.  Meanwhile, we are hard-coding the shifted punctuation
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    55
 * to trigger the virtual keys that are the expected ones under a standard
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
 * keymapping. Looking at Windows & Mac, they don't actually do this, the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    57
 * Mac seems to just put the ascii code in for the shifted punctuation
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
 * (which means they actually end up with bogus key codes on the Java side),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    59
 * Windows I can't even figure out what it's doing.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    60
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    61
#define KL_STANDARD java_awt_event_KeyEvent_KEY_LOCATION_STANDARD
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    62
#define KL_NUMPAD   java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    63
#define KL_UNKNOWN  java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
static struct _key
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
    unsigned short keyCode;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
    BOOL postsTyped;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
    jint javaKeyLocation;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    69
    jint javaKeyCode;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    70
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
const keyTable[] =
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    73
    {0x00, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_A},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
    {0x01, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_S},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
    {0x02, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_D},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
    {0x03, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_F},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
    {0x04, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_H},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
    {0x05, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_G},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
    {0x06, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_Z},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
    {0x07, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_X},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
    {0x08, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_C},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
    {0x09, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_V},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
    {0x0A, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_BACK_QUOTE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
    {0x0B, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_B},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
    {0x0C, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_Q},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
    {0x0D, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_W},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
    {0x0E, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_E},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
    {0x0F, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_R},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
    {0x10, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_Y},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
    {0x11, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_T},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
    {0x12, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_1},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
    {0x13, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_2},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
    {0x14, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_3},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
    {0x15, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_4},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
    {0x16, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_6},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
    {0x17, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_5},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
    {0x18, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_EQUALS},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
    {0x19, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_9},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    99
    {0x1A, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_7},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
    {0x1B, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_MINUS},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
    {0x1C, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_8},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
    {0x1D, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_0},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
    {0x1E, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_CLOSE_BRACKET},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   104
    {0x1F, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_O},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   105
    {0x20, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_U},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   106
    {0x21, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_OPEN_BRACKET},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   107
    {0x22, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_I},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   108
    {0x23, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_P},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   109
    {0x24, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_ENTER},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
    {0x25, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_L},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
    {0x26, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_J},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
    {0x27, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_QUOTE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   113
    {0x28, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_K},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
    {0x29, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_SEMICOLON},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
    {0x2A, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_BACK_SLASH},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
    {0x2B, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_COMMA},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
    {0x2C, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_SLASH},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
    {0x2D, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_N},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
    {0x2E, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_M},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   120
    {0x2F, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_PERIOD},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
    {0x30, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_TAB},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
    {0x31, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_SPACE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
    {0x32, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_BACK_QUOTE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
    {0x33, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_BACK_SPACE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
    {0x34, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_ENTER},
12407
221ba2aa8d51 7124411: [macosx] There's no KEY_TYPED for VK_ESCAPE
leonidr
parents: 12047
diff changeset
   126
    {0x35, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_ESCAPE},
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
    {0x36, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   128
    {0x37, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_META},      // ****
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
    {0x38, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_SHIFT},     // ****
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
    {0x39, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_CAPS_LOCK},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   131
    {0x3A, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_ALT},       // ****
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   132
    {0x3B, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_CONTROL},   // ****
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   133
    {0x3C, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   134
    {0x3D, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   135
    {0x3E, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   136
    {0x3F, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED}, // the 'fn' key on PowerBooks
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   137
    {0x40, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
    {0x41, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_DECIMAL},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   139
    {0x42, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
    {0x43, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_MULTIPLY},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   141
    {0x44, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   142
    {0x45, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_ADD},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   143
    {0x46, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   144
    {0x47, NO,  KL_NUMPAD,   java_awt_event_KeyEvent_VK_CLEAR},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   145
    {0x48, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   146
    {0x49, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   147
    {0x4A, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   148
    {0x4B, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_DIVIDE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   149
    {0x4C, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_ENTER},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   150
    {0x4D, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   151
    {0x4E, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_SUBTRACT},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
    {0x4F, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   153
    {0x50, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   154
    {0x51, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_EQUALS},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   155
    {0x52, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD0},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   156
    {0x53, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD1},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   157
    {0x54, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD2},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
    {0x55, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD3},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
    {0x56, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD4},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
    {0x57, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD5},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   161
    {0x58, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD6},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   162
    {0x59, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD7},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   163
    {0x5A, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   164
    {0x5B, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD8},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   165
    {0x5C, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD9},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   166
    {0x5D, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_BACK_SLASH}, // This is a combo yen/backslash on JIS keyboards.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   167
    {0x5E, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_UNDERSCORE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   168
    {0x5F, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_COMMA},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   169
    {0x60, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F5},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   170
    {0x61, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F6},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   171
    {0x62, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F7},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   172
    {0x63, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F3},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
    {0x64, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F8},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
    {0x65, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F9},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   175
    {0x66, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_ALPHANUMERIC},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   176
    {0x67, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F11},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   177
    {0x68, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_KATAKANA},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   178
    {0x69, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F13},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
    {0x6A, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F16},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   180
    {0x6B, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F14},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   181
    {0x6C, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
    {0x6D, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F10},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
    {0x6E, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
    {0x6F, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F12},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
    {0x70, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
    {0x71, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F15},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
    {0x72, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_HELP},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   188
    {0x73, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_HOME},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   189
    {0x74, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_PAGE_UP},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
    {0x75, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_DELETE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   191
    {0x76, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F4},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
    {0x77, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_END},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
    {0x78, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F2},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   194
    {0x79, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_PAGE_DOWN},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   195
    {0x7A, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F1},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
    {0x7B, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_LEFT},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
    {0x7C, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_RIGHT},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
    {0x7D, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_DOWN},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
    {0x7E, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_UP},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
    {0x7F, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
};
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
 * This table was stolen from the Windows implementation for mapping
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
 * Unicode values to VK codes for dead keys.  On Windows, some layouts
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
 * return ASCII punctuation for dead accents, while some return spacing
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
 * accent chars, so both should be listed.  However, in all of the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
 * keyboard layouts I tried only the Unicode values are used.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
struct CharToVKEntry {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
    UniChar c;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   212
    jint javaKey;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
};
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   214
static const struct CharToVKEntry charToDeadVKTable[] = {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
    {0x0060, java_awt_event_KeyEvent_VK_DEAD_GRAVE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   216
    {0x00B4, java_awt_event_KeyEvent_VK_DEAD_ACUTE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
    {0x0384, java_awt_event_KeyEvent_VK_DEAD_ACUTE}, // Unicode "GREEK TONOS" -- Greek keyboard, semicolon key
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
    {0x005E, java_awt_event_KeyEvent_VK_DEAD_CIRCUMFLEX},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
    {0x007E, java_awt_event_KeyEvent_VK_DEAD_TILDE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
    {0x02DC, java_awt_event_KeyEvent_VK_DEAD_TILDE}, // Unicode "SMALL TILDE"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
    {0x00AF, java_awt_event_KeyEvent_VK_DEAD_MACRON},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
    {0x02D8, java_awt_event_KeyEvent_VK_DEAD_BREVE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   223
    {0x02D9, java_awt_event_KeyEvent_VK_DEAD_ABOVEDOT},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
    {0x00A8, java_awt_event_KeyEvent_VK_DEAD_DIAERESIS},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
    {0x02DA, java_awt_event_KeyEvent_VK_DEAD_ABOVERING},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   226
    {0x02DD, java_awt_event_KeyEvent_VK_DEAD_DOUBLEACUTE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   227
    {0x02C7, java_awt_event_KeyEvent_VK_DEAD_CARON},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   228
    {0x00B8, java_awt_event_KeyEvent_VK_DEAD_CEDILLA},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   229
    {0x02DB, java_awt_event_KeyEvent_VK_DEAD_OGONEK},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   230
    {0x037A, java_awt_event_KeyEvent_VK_DEAD_IOTA},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   231
    {0x309B, java_awt_event_KeyEvent_VK_DEAD_VOICED_SOUND},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   232
    {0x309C, java_awt_event_KeyEvent_VK_DEAD_SEMIVOICED_SOUND},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   233
    {0,0}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
};
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   235
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
// TODO: some constants below are part of CGS (private interfaces)...
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
// for now we will look at the raw key code to determine left/right status
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   238
// but not sure this is foolproof...
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   239
static struct _nsKeyToJavaModifier
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   240
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   241
    NSUInteger nsMask;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
    //NSUInteger cgsLeftMask;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
    //NSUInteger cgsRightMask;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
    unsigned short leftKeyCode;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
    unsigned short rightKeyCode;
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   246
    jint javaExtMask;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   247
    jint javaMask;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   248
    jint javaKey;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   249
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   250
const nsKeyToJavaModifierTable[] =
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   251
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   252
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   253
        NSAlphaShiftKeyMask,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   254
        0,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   255
        0,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   256
        0, // no Java equivalent
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   257
        0, // no Java equivalent
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   258
        java_awt_event_KeyEvent_VK_CAPS_LOCK
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   259
    },
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   260
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   261
        NSShiftKeyMask,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   262
        //kCGSFlagsMaskAppleShiftKey,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   263
        //kCGSFlagsMaskAppleRightShiftKey,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   264
        56,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   265
        60,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   266
        java_awt_event_InputEvent_SHIFT_DOWN_MASK,
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   267
        java_awt_event_InputEvent_SHIFT_MASK,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   268
        java_awt_event_KeyEvent_VK_SHIFT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   269
    },
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   271
        NSControlKeyMask,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   272
        //kCGSFlagsMaskAppleControlKey,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   273
        //kCGSFlagsMaskAppleRightControlKey,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
        59,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   275
        62,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   276
        java_awt_event_InputEvent_CTRL_DOWN_MASK,
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   277
        java_awt_event_InputEvent_CTRL_MASK,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   278
        java_awt_event_KeyEvent_VK_CONTROL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   279
    },
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   280
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   281
        NSAlternateKeyMask,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   282
        //kCGSFlagsMaskAppleLeftAlternateKey,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   283
        //kCGSFlagsMaskAppleRightAlternateKey,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   284
        58,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   285
        61,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   286
        java_awt_event_InputEvent_ALT_DOWN_MASK,
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   287
        java_awt_event_InputEvent_ALT_MASK,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   288
        java_awt_event_KeyEvent_VK_ALT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   289
    },
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   290
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   291
        NSCommandKeyMask,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   292
        //kCGSFlagsMaskAppleLeftCommandKey,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   293
        //kCGSFlagsMaskAppleRightCommandKey,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   294
        55,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   295
        54,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   296
        java_awt_event_InputEvent_META_DOWN_MASK,
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   297
        java_awt_event_InputEvent_META_MASK,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   298
        java_awt_event_KeyEvent_VK_META
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   299
    },
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   300
    // NSNumericPadKeyMask
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   301
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   302
        NSHelpKeyMask,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   303
        0,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   304
        0,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   305
        0, // no Java equivalent
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   306
        0, // no Java equivalent
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   307
        java_awt_event_KeyEvent_VK_HELP
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   308
    },
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   309
    // NSFunctionKeyMask
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   310
    {0, 0, 0, 0, 0, 0}
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   311
};
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   312
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   313
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   314
 * Almost all unicode characters just go from NS to Java with no translation.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   315
 *  For the few exceptions, we handle it here with this small table.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   316
 */
12410
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   317
#define ALL_NS_KEY_MODIFIERS_MASK \
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   318
    (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask)
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   319
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   320
static struct _char {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   321
    NSUInteger modifier;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   322
    unichar nsChar;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   323
    unichar javaChar;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   324
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   325
const charTable[] = {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   326
    // map enter on keypad to same as return key
12410
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   327
    {0,                         NSEnterCharacter,          NSNewlineCharacter},
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   328
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   329
    // [3134616] return newline instead of carriage return
12410
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   330
    {0,                         NSCarriageReturnCharacter, NSNewlineCharacter},
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   331
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   332
    // "delete" means backspace in Java
12410
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   333
    {ALL_NS_KEY_MODIFIERS_MASK, NSDeleteCharacter,         NSBackspaceCharacter},
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   334
    {ALL_NS_KEY_MODIFIERS_MASK, NSDeleteFunctionKey,       NSDeleteCharacter},
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   335
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   336
    // back-tab is only differentiated from tab by Shift flag
12410
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   337
    {NSShiftKeyMask,            NSBackTabCharacter,        NSTabCharacter},
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   338
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   339
    {0, 0, 0}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   340
};
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   341
17144
0c7842966236 8008366: [macosx] ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13990
diff changeset
   342
unichar NsCharToJavaChar(unichar nsChar, NSUInteger modifiers)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   343
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   344
    const struct _char *cur;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   345
    // Mask off just the keyboard modifiers from the event modifier mask.
12410
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   346
    NSUInteger testableFlags = (modifiers & ALL_NS_KEY_MODIFIERS_MASK);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   347
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   348
    // walk through table & find the match
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   349
    for (cur = charTable; cur->nsChar != 0 ; cur++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   350
        // <rdar://Problem/3476426> Need to determine if we are looking at
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   351
        // a plain keypress or a modified keypress.  Don't adjust the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   352
        // character of a keypress with a modifier.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   353
        if (cur->nsChar == nsChar) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   354
            if (cur->modifier == 0 && testableFlags == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   355
                // If the modifier field is 0, that means to transform
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   356
                // this character if no additional keyboard modifiers are set.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   357
                // This lets ctrl-C be reported as ctrl-C and not transformed
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   358
                // into Newline.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   359
                return cur->javaChar;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   360
            } else if (cur->modifier != 0 &&
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   361
                       (testableFlags & cur->modifier) == testableFlags)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   362
            {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   363
                // Likewise, if the modifier field is nonzero, that means
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   364
                // transform this character if only these modifiers are
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   365
                // set in the testable flags.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   366
                return cur->javaChar;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   367
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   368
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   369
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   370
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   371
    if (nsChar >= NSUpArrowFunctionKey && nsChar <= NSModeSwitchFunctionKey) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   372
        return java_awt_event_KeyEvent_CHAR_UNDEFINED;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   373
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   374
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   375
    // otherwise return character unchanged
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   376
    return nsChar;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   377
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   378
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   379
static unichar NsGetDeadKeyChar(unsigned short keyCode)
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   380
{
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   381
    TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource();
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   382
    CFDataRef uchr = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
18599
213883c7fab6 8012925: [parfait] Missing return value in jdk/src/macosx/native/sun/awt/AWTEvent.m
tbell
parents: 17144
diff changeset
   383
    if (uchr == nil) { return 0; }
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   384
    const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout*)CFDataGetBytePtr(uchr);
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   385
    // Carbon modifiers should be used instead of NSEvent modifiers
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   386
    UInt32 modifierKeyState = (GetCurrentEventKeyModifiers() >> 8) & 0xFF;
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   387
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   388
    if (keyboardLayout) {
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   389
        UInt32 deadKeyState = 0;
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   390
        UniCharCount maxStringLength = 255;
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   391
        UniCharCount actualStringLength = 0;
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   392
        UniChar unicodeString[maxStringLength];
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   393
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   394
        // get the deadKeyState
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   395
        OSStatus status = UCKeyTranslate(keyboardLayout,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   396
                                         keyCode, kUCKeyActionDown, modifierKeyState,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   397
                                         LMGetKbdType(), kUCKeyTranslateNoDeadKeysBit,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   398
                                         &deadKeyState,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   399
                                         maxStringLength,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   400
                                         &actualStringLength, unicodeString);
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   401
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   402
        if (status == noErr && deadKeyState != 0) {
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   403
            // Press SPACE to get the dead key char
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   404
            status = UCKeyTranslate(keyboardLayout,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   405
                                    kVK_Space, kUCKeyActionDown, 0,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   406
                                    LMGetKbdType(), 0,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   407
                                    &deadKeyState,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   408
                                    maxStringLength,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   409
                                    &actualStringLength, unicodeString);
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   410
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   411
            if (status == noErr && actualStringLength > 0) {
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   412
                return unicodeString[0];
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   413
            }
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   414
        }
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   415
    }
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   416
    return 0;
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   417
}
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   418
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   419
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   420
 * This is the function that uses the table above to take incoming
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   421
 * NSEvent keyCodes and translate to the Java virtual key code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   422
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   423
static void
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   424
NsCharToJavaVirtualKeyCode(unichar ch, BOOL isDeadChar,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   425
                           NSUInteger flags, unsigned short key,
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   426
                           jint *keyCode, jint *keyLocation, BOOL *postsTyped, unichar *deadChar)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   427
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   428
    static size_t size = sizeof(keyTable) / sizeof(struct _key);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   429
    NSInteger offset;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   430
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   431
    if (isDeadChar) {
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   432
        unichar testDeadChar = NsGetDeadKeyChar(key);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   433
        const struct CharToVKEntry *map;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   434
        for (map = charToDeadVKTable; map->c != 0; ++map) {
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   435
            if (testDeadChar == map->c) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   436
                *keyCode = map->javaKey;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   437
                *postsTyped = NO;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   438
                // TODO: use UNKNOWN here?
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   439
                *keyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   440
                *deadChar = testDeadChar;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   441
                return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   442
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   443
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   444
        // If we got here, we keep looking for a normal key.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   445
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   446
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   447
    if ([[NSCharacterSet letterCharacterSet] characterIsMember:ch]) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   448
        // key is an alphabetic character
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   449
        unichar lower;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   450
        lower = tolower(ch);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   451
        offset = lower - 'a';
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   452
        if (offset >= 0 && offset <= 25) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   453
            // some chars in letter set are NOT actually A-Z characters?!
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   454
            // skip them...
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   455
            *postsTyped = YES;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   456
            // do quick conversion
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   457
            *keyCode = java_awt_event_KeyEvent_VK_A + offset;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   458
            *keyLocation = java_awt_event_KeyEvent_KEY_LOCATION_STANDARD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   459
            return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   460
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   461
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   462
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   463
    if ([[NSCharacterSet decimalDigitCharacterSet] characterIsMember:ch]) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   464
        // key is a digit
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   465
        offset = ch - '0';
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   466
        // make sure in range for decimal digits
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   467
        if (offset >= 0 && offset <= 9)    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   468
            jboolean numpad = (flags & NSNumericPadKeyMask) != 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   469
            *postsTyped = YES;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   470
            if (numpad) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   471
                *keyCode = offset + java_awt_event_KeyEvent_VK_NUMPAD0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   472
                *keyLocation = java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   473
            } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   474
                *keyCode = offset + java_awt_event_KeyEvent_VK_0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   475
                *keyLocation = java_awt_event_KeyEvent_KEY_LOCATION_STANDARD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   476
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   477
            return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   478
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   479
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   480
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   481
    if (key < size) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   482
        *postsTyped = keyTable[key].postsTyped;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   483
        *keyCode = keyTable[key].javaKeyCode;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   484
        *keyLocation = keyTable[key].javaKeyLocation;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   485
    } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   486
        // Should we report this? This means we've got a keyboard
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   487
        // we don't know about...
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   488
        *postsTyped = NO;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   489
        *keyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   490
        *keyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   491
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   492
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   493
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   494
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   495
 * This returns the java key data for the key NSEvent modifiers
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   496
 * (after NSFlagChanged).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   497
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   498
static void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   499
NsKeyModifiersToJavaKeyInfo(NSUInteger nsFlags, unsigned short eventKeyCode,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   500
                            jint *javaKeyCode,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   501
                            jint *javaKeyLocation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   502
                            jint *javaKeyType)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   503
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   504
    static NSUInteger sPreviousNSFlags = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   505
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   506
    const struct _nsKeyToJavaModifier* cur;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   507
    NSUInteger oldNSFlags = sPreviousNSFlags;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   508
    NSUInteger changedNSFlags = oldNSFlags ^ nsFlags;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   509
    sPreviousNSFlags = nsFlags;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   510
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   511
    *javaKeyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   512
    *javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   513
    *javaKeyType = java_awt_event_KeyEvent_KEY_PRESSED;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   514
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   515
    for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   516
        if (changedNSFlags & cur->nsMask) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   517
            *javaKeyCode = cur->javaKey;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   518
            *javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_STANDARD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   519
            // TODO: uses SPI...
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   520
            //if (changedNSFlags & cur->cgsLeftMask) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   521
            //    *javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_LEFT;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   522
            //} else if (changedNSFlags & cur->cgsRightMask) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   523
            //    *javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_RIGHT;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   524
            //}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   525
            if (eventKeyCode == cur->leftKeyCode) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   526
                *javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_LEFT;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   527
            } else if (eventKeyCode == cur->rightKeyCode) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   528
                *javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_RIGHT;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   529
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   530
            *javaKeyType = (cur->nsMask & nsFlags) ?
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   531
                java_awt_event_KeyEvent_KEY_PRESSED :
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   532
                java_awt_event_KeyEvent_KEY_RELEASED;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   533
            break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   534
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   535
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   536
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   537
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   538
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   539
 * This returns the java modifiers for a key NSEvent.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   540
 */
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   541
jint NsKeyModifiersToJavaModifiers(NSUInteger nsFlags, BOOL isExtMods)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   542
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   543
    jint javaModifiers = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   544
    const struct _nsKeyToJavaModifier* cur;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   545
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   546
    for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   547
        if ((cur->nsMask & nsFlags) != 0) {
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   548
            javaModifiers |= isExtMods? cur->javaExtMask : cur->javaMask;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   549
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   550
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   551
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   552
    return javaModifiers;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   553
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   554
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   555
/*
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   556
 * This returns the NSEvent flags for java key modifiers.
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   557
 */
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   558
NSUInteger JavaModifiersToNsKeyModifiers(jint javaModifiers, BOOL isExtMods)
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   559
{
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   560
    NSUInteger nsFlags = 0;
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   561
    const struct _nsKeyToJavaModifier* cur;
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   562
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   563
    for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
13990
3e72145fd93a 7199180: [macosx] Dead keys handling for input methods
alexsch
parents: 13781
diff changeset
   564
        jint mask = isExtMods? cur->javaExtMask : cur->javaMask;
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   565
        if ((mask & javaModifiers) != 0) {
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   566
            nsFlags |= cur->nsMask;
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   567
        }
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   568
    }
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   569
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   570
    // special case
13990
3e72145fd93a 7199180: [macosx] Dead keys handling for input methods
alexsch
parents: 13781
diff changeset
   571
    jint mask = isExtMods? java_awt_event_InputEvent_ALT_GRAPH_DOWN_MASK :
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   572
                           java_awt_event_InputEvent_ALT_GRAPH_MASK;
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   573
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   574
    if ((mask & javaModifiers) != 0) {
13990
3e72145fd93a 7199180: [macosx] Dead keys handling for input methods
alexsch
parents: 13781
diff changeset
   575
        nsFlags |= NSAlternateKeyMask;
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   576
    }
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   577
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   578
    return nsFlags;
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   579
}
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   580
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   581
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   582
jint GetJavaMouseModifiers(NSInteger button, NSUInteger modifierFlags)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   583
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   584
    // Mousing needs the key modifiers
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   585
    jint modifiers = NsKeyModifiersToJavaModifiers(modifierFlags, YES);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   586
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   587
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   588
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   589
     * Ask Quartz about mouse buttons state
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   590
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   591
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   592
    if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   593
                                 kCGMouseButtonLeft)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   594
        modifiers |= java_awt_event_InputEvent_BUTTON1_DOWN_MASK;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   595
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   596
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   597
    if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   598
                                 kCGMouseButtonRight)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   599
        modifiers |= java_awt_event_InputEvent_BUTTON3_DOWN_MASK;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   600
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   601
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   602
    if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   603
                                 kCGMouseButtonCenter)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   604
        modifiers |= java_awt_event_InputEvent_BUTTON2_DOWN_MASK;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   605
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   606
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   607
    NSInteger extraButton = 3;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   608
    for (; extraButton < gNumberOfButtons; extraButton++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   609
        if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   610
                                 extraButton)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   611
            modifiers |= gButtonDownMasks[extraButton];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   612
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   613
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   614
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   615
    return modifiers;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   616
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   617
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   618
jlong UTC(NSEvent *event) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   619
    struct timeval tv;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   620
    if (gettimeofday(&tv, NULL) == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   621
        long long sec = (long long)tv.tv_sec;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   622
        return (sec*1000) + (tv.tv_usec/1000);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   623
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   624
    return 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   625
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   626
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   627
JNIEXPORT void JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   628
Java_java_awt_AWTEvent_nativeSetSource
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   629
    (JNIEnv *env, jobject self, jobject newSource)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   630
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   631
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   632
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   633
/*
23268
2cdb715ff32d 8029868: Fix KSS issues in sun.lwawt.macosx
pchelko
parents: 20105
diff changeset
   634
 * Class:     sun_lwawt_macosx_NSEvent
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   635
 * Method:    nsToJavaMouseModifiers
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   636
 * Signature: (II)I
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   637
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   638
JNIEXPORT jint JNICALL
23268
2cdb715ff32d 8029868: Fix KSS issues in sun.lwawt.macosx
pchelko
parents: 20105
diff changeset
   639
Java_sun_lwawt_macosx_NSEvent_nsToJavaMouseModifiers
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   640
(JNIEnv *env, jclass cls, jint buttonNumber, jint modifierFlags)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   641
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   642
    jint jmodifiers = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   643
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   644
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   645
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   646
    jmodifiers = GetJavaMouseModifiers(buttonNumber, modifierFlags);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   647
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   648
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   649
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   650
    return jmodifiers;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   651
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   652
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   653
/*
23268
2cdb715ff32d 8029868: Fix KSS issues in sun.lwawt.macosx
pchelko
parents: 20105
diff changeset
   654
 * Class:     sun_lwawt_macosx_NSEvent
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   655
 * Method:    nsToJavaKeyModifiers
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   656
 * Signature: (I)I
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   657
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   658
JNIEXPORT jint JNICALL
23268
2cdb715ff32d 8029868: Fix KSS issues in sun.lwawt.macosx
pchelko
parents: 20105
diff changeset
   659
Java_sun_lwawt_macosx_NSEvent_nsToJavaKeyModifiers
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   660
(JNIEnv *env, jclass cls, jint modifierFlags)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   661
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   662
    jint jmodifiers = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   663
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   664
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   665
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   666
    jmodifiers = NsKeyModifiersToJavaModifiers(modifierFlags, YES);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   667
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   668
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   669
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   670
    return jmodifiers;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   671
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   672
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   673
/*
23268
2cdb715ff32d 8029868: Fix KSS issues in sun.lwawt.macosx
pchelko
parents: 20105
diff changeset
   674
 * Class:     sun_lwawt_macosx_NSEvent
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   675
 * Method:    nsToJavaKeyInfo
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   676
 * Signature: ([I[I)Z
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   677
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   678
JNIEXPORT jboolean JNICALL
23268
2cdb715ff32d 8029868: Fix KSS issues in sun.lwawt.macosx
pchelko
parents: 20105
diff changeset
   679
Java_sun_lwawt_macosx_NSEvent_nsToJavaKeyInfo
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   680
(JNIEnv *env, jclass cls, jintArray inData, jintArray outData)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   681
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   682
    BOOL postsTyped = NO;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   683
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   684
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   685
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   686
    jboolean copy = JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   687
    jint *data = (*env)->GetIntArrayElements(env, inData, &copy);
23625
bb223c2c6fc0 8034037: [parfait] JNI exception pending in macosx/native/sun/awt/AWTEvent.m, AWTView.m
serb
parents: 23268
diff changeset
   688
    CHECK_NULL_RETURN(data, postsTyped);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   689
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   690
    // in  = [testChar, testDeadChar, modifierFlags, keyCode]
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   691
    jchar testChar = (jchar)data[0];
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   692
    BOOL isDeadChar = (data[1] != 0);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   693
    jint modifierFlags = data[2];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   694
    jshort keyCode = (jshort)data[3];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   695
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   696
    jint jkeyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   697
    jint jkeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   698
    jchar testDeadChar = 0;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   699
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   700
    NsCharToJavaVirtualKeyCode((unichar)testChar, isDeadChar,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   701
                               (NSUInteger)modifierFlags, (unsigned short)keyCode,
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   702
                               &jkeyCode, &jkeyLocation, &postsTyped, &testDeadChar);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   703
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   704
    // out = [jkeyCode, jkeyLocation];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   705
    (*env)->SetIntArrayRegion(env, outData, 0, 1, &jkeyCode);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   706
    (*env)->SetIntArrayRegion(env, outData, 1, 1, &jkeyLocation);
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   707
    (*env)->SetIntArrayRegion(env, outData, 2, 1, (jint *)&testDeadChar);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   708
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   709
    (*env)->ReleaseIntArrayElements(env, inData, data, 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   710
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   711
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   712
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   713
    return postsTyped;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   714
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   715
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   716
/*
23268
2cdb715ff32d 8029868: Fix KSS issues in sun.lwawt.macosx
pchelko
parents: 20105
diff changeset
   717
 * Class:     sun_lwawt_macosx_NSEvent
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   718
 * Method:    nsKeyModifiersToJavaKeyInfo
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   719
 * Signature: ([I[I)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   720
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   721
JNIEXPORT void JNICALL
23268
2cdb715ff32d 8029868: Fix KSS issues in sun.lwawt.macosx
pchelko
parents: 20105
diff changeset
   722
Java_sun_lwawt_macosx_NSEvent_nsKeyModifiersToJavaKeyInfo
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   723
(JNIEnv *env, jclass cls, jintArray inData, jintArray outData)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   724
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   725
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   726
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   727
    jboolean copy = JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   728
    jint *data = (*env)->GetIntArrayElements(env, inData, &copy);
23625
bb223c2c6fc0 8034037: [parfait] JNI exception pending in macosx/native/sun/awt/AWTEvent.m, AWTView.m
serb
parents: 23268
diff changeset
   729
    CHECK_NULL(data);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   730
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   731
    // in  = [modifierFlags, keyCode]
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   732
    jint modifierFlags = data[0];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   733
    jshort keyCode = (jshort)data[1];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   734
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   735
    jint jkeyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   736
    jint jkeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   737
    jint jkeyType = java_awt_event_KeyEvent_KEY_PRESSED;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   738
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   739
    NsKeyModifiersToJavaKeyInfo(modifierFlags,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   740
                                keyCode,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   741
                                &jkeyCode,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   742
                                &jkeyLocation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   743
                                &jkeyType);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   744
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   745
    // out = [jkeyCode, jkeyLocation, jkeyType];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   746
    (*env)->SetIntArrayRegion(env, outData, 0, 1, &jkeyCode);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   747
    (*env)->SetIntArrayRegion(env, outData, 1, 1, &jkeyLocation);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   748
    (*env)->SetIntArrayRegion(env, outData, 2, 1, &jkeyType);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   749
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   750
    (*env)->ReleaseIntArrayElements(env, inData, data, 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   751
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   752
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   753
}
12410
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   754
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   755
/*
23268
2cdb715ff32d 8029868: Fix KSS issues in sun.lwawt.macosx
pchelko
parents: 20105
diff changeset
   756
 * Class:     sun_lwawt_macosx_NSEvent
12410
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   757
 * Method:    nsToJavaChar
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   758
 * Signature: (CI)C
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   759
 */
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   760
JNIEXPORT jint JNICALL
23268
2cdb715ff32d 8029868: Fix KSS issues in sun.lwawt.macosx
pchelko
parents: 20105
diff changeset
   761
Java_sun_lwawt_macosx_NSEvent_nsToJavaChar
20105
f698ce625852 8022401: [macosx] javax/swing/text/JTextComponent/5074573/bug5074573.java fails
alexsch
parents: 18599
diff changeset
   762
(JNIEnv *env, jclass cls, jchar nsChar, jint modifierFlags)
12410
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   763
{
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   764
    jchar javaChar = 0;
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   765
12410
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   766
JNF_COCOA_ENTER(env);
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   767
12410
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   768
    javaChar = NsCharToJavaChar(nsChar, modifierFlags);
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   769
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   770
JNF_COCOA_EXIT(env);
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   771
12410
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   772
    return javaChar;
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   773
}