jdk/src/macosx/native/sun/awt/AWTEvent.m
author leonidr
Mon, 22 Apr 2013 19:24:41 +0400
changeset 17144 0c7842966236
parent 13990 3e72145fd93a
child 18599 213883c7fab6
permissions -rw-r--r--
8008366: [macosx] ActionListener called twice for JMenuItem using ScreenMenuBar Reviewed-by: anthony, serb
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
/*
17144
0c7842966236 8008366: [macosx] ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13990
diff changeset
     2
 * Copyright (c) 2011, 2013, 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 <JavaNativeFoundation/JavaNativeFoundation.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
#import <sys/time.h>
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
    29
#include <Carbon/Carbon.h>
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
#import "LWCToolkit.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
#import "ThreadUtilities.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    34
#import "java_awt_event_InputEvent.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
#import "java_awt_event_KeyEvent.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
#import "java_awt_event_MouseEvent.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
 * 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
    40
 * 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
    41
 * 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
    42
 * 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
    43
 * 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
    44
 * 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
    45
 * 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
    46
 * hokey with regards to the shifted punctuation characters. For examples,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    47
 * 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
    48
 * 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
    49
 * KeyPressed/Released events, we need to identify the virtual key code
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
 * (which roughly correspond to hardware keys) which means we are supposed
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
 * 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
    52
 * 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
    53
 * 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
    54
 * 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
    55
 * 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
    56
 * press/release.  Meanwhile, we are hard-coding the shifted punctuation
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    57
 * 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
    58
 * 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
    59
 * 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
    60
 * (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
    61
 * Windows I can't even figure out what it's doing.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    62
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    63
#define KL_STANDARD java_awt_event_KeyEvent_KEY_LOCATION_STANDARD
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
#define KL_NUMPAD   java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
#define KL_UNKNOWN  java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
static struct _key
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
    unsigned short keyCode;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    69
    BOOL postsTyped;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    70
    jint javaKeyLocation;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
    jint javaKeyCode;
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
const keyTable[] =
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
    {0x00, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_A},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
    {0x01, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_S},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
    {0x02, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_D},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
    {0x03, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_F},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
    {0x04, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_H},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
    {0x05, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_G},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
    {0x06, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_Z},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
    {0x07, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_X},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
    {0x08, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_C},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
    {0x09, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_V},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
    {0x0A, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_BACK_QUOTE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
    {0x0B, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_B},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
    {0x0C, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_Q},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
    {0x0D, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_W},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
    {0x0E, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_E},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
    {0x0F, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_R},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
    {0x10, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_Y},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
    {0x11, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_T},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
    {0x12, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_1},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
    {0x13, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_2},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
    {0x14, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_3},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
    {0x15, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_4},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
    {0x16, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_6},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
    {0x17, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_5},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    99
    {0x18, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_EQUALS},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
    {0x19, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_9},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
    {0x1A, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_7},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
    {0x1B, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_MINUS},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
    {0x1C, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_8},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   104
    {0x1D, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_0},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   105
    {0x1E, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_CLOSE_BRACKET},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   106
    {0x1F, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_O},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   107
    {0x20, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_U},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   108
    {0x21, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_OPEN_BRACKET},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   109
    {0x22, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_I},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
    {0x23, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_P},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
    {0x24, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_ENTER},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
    {0x25, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_L},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   113
    {0x26, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_J},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
    {0x27, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_QUOTE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
    {0x28, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_K},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
    {0x29, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_SEMICOLON},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
    {0x2A, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_BACK_SLASH},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
    {0x2B, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_COMMA},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
    {0x2C, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_SLASH},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   120
    {0x2D, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_N},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
    {0x2E, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_M},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
    {0x2F, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_PERIOD},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
    {0x30, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_TAB},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
    {0x31, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_SPACE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
    {0x32, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_BACK_QUOTE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
    {0x33, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_BACK_SPACE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
    {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
   128
    {0x35, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_ESCAPE},
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
    {0x36, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
    {0x37, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_META},      // ****
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   131
    {0x38, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_SHIFT},     // ****
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   132
    {0x39, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_CAPS_LOCK},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   133
    {0x3A, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_ALT},       // ****
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   134
    {0x3B, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_CONTROL},   // ****
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   135
    {0x3C, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   136
    {0x3D, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   137
    {0x3E, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
    {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
   139
    {0x40, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
    {0x41, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_DECIMAL},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   141
    {0x42, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   142
    {0x43, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_MULTIPLY},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   143
    {0x44, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   144
    {0x45, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_ADD},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   145
    {0x46, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   146
    {0x47, NO,  KL_NUMPAD,   java_awt_event_KeyEvent_VK_CLEAR},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   147
    {0x48, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   148
    {0x49, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   149
    {0x4A, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   150
    {0x4B, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_DIVIDE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   151
    {0x4C, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_ENTER},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
    {0x4D, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   153
    {0x4E, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_SUBTRACT},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   154
    {0x4F, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   155
    {0x50, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   156
    {0x51, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_EQUALS},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   157
    {0x52, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD0},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
    {0x53, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD1},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
    {0x54, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD2},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
    {0x55, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD3},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   161
    {0x56, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD4},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   162
    {0x57, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD5},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   163
    {0x58, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD6},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   164
    {0x59, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD7},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   165
    {0x5A, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   166
    {0x5B, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD8},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   167
    {0x5C, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_NUMPAD9},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   168
    {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
   169
    {0x5E, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_UNDERSCORE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   170
    {0x5F, YES, KL_NUMPAD,   java_awt_event_KeyEvent_VK_COMMA},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   171
    {0x60, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F5},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   172
    {0x61, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F6},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
    {0x62, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F7},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
    {0x63, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F3},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   175
    {0x64, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F8},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   176
    {0x65, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F9},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   177
    {0x66, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_ALPHANUMERIC},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   178
    {0x67, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F11},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
    {0x68, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_KATAKANA},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   180
    {0x69, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F13},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   181
    {0x6A, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F16},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
    {0x6B, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F14},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
    {0x6C, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
    {0x6D, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F10},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
    {0x6E, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
    {0x6F, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F12},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
    {0x70, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   188
    {0x71, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F15},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   189
    {0x72, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_HELP},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
    {0x73, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_HOME},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   191
    {0x74, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_PAGE_UP},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
    {0x75, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_DELETE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
    {0x76, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F4},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   194
    {0x77, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_END},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   195
    {0x78, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F2},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
    {0x79, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_PAGE_DOWN},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
    {0x7A, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_F1},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
    {0x7B, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_LEFT},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
    {0x7C, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_RIGHT},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
    {0x7D, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_DOWN},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
    {0x7E, NO,  KL_STANDARD, java_awt_event_KeyEvent_VK_UP},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
    {0x7F, NO,  KL_UNKNOWN,  java_awt_event_KeyEvent_VK_UNDEFINED},
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
 * This table was stolen from the Windows implementation for mapping
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
 * 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
   208
 * return ASCII punctuation for dead accents, while some return spacing
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
 * 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
   210
 * keyboard layouts I tried only the Unicode values are used.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   212
struct CharToVKEntry {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
    UniChar c;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   214
    jint javaKey;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
};
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   216
static const struct CharToVKEntry charToDeadVKTable[] = {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
    {0x0060, java_awt_event_KeyEvent_VK_DEAD_GRAVE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
    {0x00B4, java_awt_event_KeyEvent_VK_DEAD_ACUTE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
    {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
   220
    {0x005E, java_awt_event_KeyEvent_VK_DEAD_CIRCUMFLEX},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
    {0x007E, java_awt_event_KeyEvent_VK_DEAD_TILDE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
    {0x02DC, java_awt_event_KeyEvent_VK_DEAD_TILDE}, // Unicode "SMALL TILDE"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   223
    {0x00AF, java_awt_event_KeyEvent_VK_DEAD_MACRON},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
    {0x02D8, java_awt_event_KeyEvent_VK_DEAD_BREVE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
    {0x02D9, java_awt_event_KeyEvent_VK_DEAD_ABOVEDOT},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   226
    {0x00A8, java_awt_event_KeyEvent_VK_DEAD_DIAERESIS},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   227
    {0x02DA, java_awt_event_KeyEvent_VK_DEAD_ABOVERING},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   228
    {0x02DD, java_awt_event_KeyEvent_VK_DEAD_DOUBLEACUTE},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   229
    {0x02C7, java_awt_event_KeyEvent_VK_DEAD_CARON},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   230
    {0x00B8, java_awt_event_KeyEvent_VK_DEAD_CEDILLA},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   231
    {0x02DB, java_awt_event_KeyEvent_VK_DEAD_OGONEK},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   232
    {0x037A, java_awt_event_KeyEvent_VK_DEAD_IOTA},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   233
    {0x309B, java_awt_event_KeyEvent_VK_DEAD_VOICED_SOUND},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
    {0x309C, java_awt_event_KeyEvent_VK_DEAD_SEMIVOICED_SOUND},
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   235
    {0,0}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
};
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   238
// TODO: some constants below are part of CGS (private interfaces)...
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   239
// 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
   240
// but not sure this is foolproof...
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   241
static struct _nsKeyToJavaModifier
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
    NSUInteger nsMask;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
    //NSUInteger cgsLeftMask;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
    //NSUInteger cgsRightMask;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   246
    unsigned short leftKeyCode;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   247
    unsigned short rightKeyCode;
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   248
    jint javaExtMask;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   249
    jint javaMask;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   250
    jint javaKey;
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
const nsKeyToJavaModifierTable[] =
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   253
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   254
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   255
        NSAlphaShiftKeyMask,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   256
        0,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   257
        0,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   258
        0, // no Java equivalent
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   259
        0, // no Java equivalent
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   260
        java_awt_event_KeyEvent_VK_CAPS_LOCK
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   261
    },
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   262
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   263
        NSShiftKeyMask,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   264
        //kCGSFlagsMaskAppleShiftKey,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   265
        //kCGSFlagsMaskAppleRightShiftKey,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   266
        56,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   267
        60,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   268
        java_awt_event_InputEvent_SHIFT_DOWN_MASK,
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   269
        java_awt_event_InputEvent_SHIFT_MASK,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
        java_awt_event_KeyEvent_VK_SHIFT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   271
    },
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   272
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   273
        NSControlKeyMask,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
        //kCGSFlagsMaskAppleControlKey,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   275
        //kCGSFlagsMaskAppleRightControlKey,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   276
        59,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   277
        62,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   278
        java_awt_event_InputEvent_CTRL_DOWN_MASK,
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   279
        java_awt_event_InputEvent_CTRL_MASK,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   280
        java_awt_event_KeyEvent_VK_CONTROL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   281
    },
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   282
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   283
        NSAlternateKeyMask,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   284
        //kCGSFlagsMaskAppleLeftAlternateKey,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   285
        //kCGSFlagsMaskAppleRightAlternateKey,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   286
        58,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   287
        61,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   288
        java_awt_event_InputEvent_ALT_DOWN_MASK,
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   289
        java_awt_event_InputEvent_ALT_MASK,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   290
        java_awt_event_KeyEvent_VK_ALT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   291
    },
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   292
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   293
        NSCommandKeyMask,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   294
        //kCGSFlagsMaskAppleLeftCommandKey,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   295
        //kCGSFlagsMaskAppleRightCommandKey,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   296
        55,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   297
        54,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   298
        java_awt_event_InputEvent_META_DOWN_MASK,
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   299
        java_awt_event_InputEvent_META_MASK,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   300
        java_awt_event_KeyEvent_VK_META
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
    // NSNumericPadKeyMask
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   303
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   304
        NSHelpKeyMask,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   305
        0,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   306
        0,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   307
        0, // no Java equivalent
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   308
        0, // no Java equivalent
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   309
        java_awt_event_KeyEvent_VK_HELP
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   310
    },
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   311
    // NSFunctionKeyMask
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   312
    {0, 0, 0, 0, 0, 0}
12047
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   315
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   316
 * 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
   317
 *  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
   318
 */
12410
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   319
#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
   320
    (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask)
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   321
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   322
static struct _char {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   323
    NSUInteger modifier;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   324
    unichar nsChar;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   325
    unichar javaChar;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   326
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   327
const charTable[] = {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   328
    // 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
   329
    {0,                         NSEnterCharacter,          NSNewlineCharacter},
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   330
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   331
    // [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
   332
    {0,                         NSCarriageReturnCharacter, NSNewlineCharacter},
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   333
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   334
    // "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
   335
    {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
   336
    {ALL_NS_KEY_MODIFIERS_MASK, NSDeleteFunctionKey,       NSDeleteCharacter},
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   337
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   338
    // 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
   339
    {NSShiftKeyMask,            NSBackTabCharacter,        NSTabCharacter},
12047
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
    {0, 0, 0}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   342
};
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   343
17144
0c7842966236 8008366: [macosx] ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13990
diff changeset
   344
unichar NsCharToJavaChar(unichar nsChar, NSUInteger modifiers)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   345
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   346
    const struct _char *cur;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   347
    // 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
   348
    NSUInteger testableFlags = (modifiers & ALL_NS_KEY_MODIFIERS_MASK);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   349
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   350
    // walk through table & find the match
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   351
    for (cur = charTable; cur->nsChar != 0 ; cur++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   352
        // <rdar://Problem/3476426> Need to determine if we are looking at
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   353
        // a plain keypress or a modified keypress.  Don't adjust the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   354
        // character of a keypress with a modifier.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   355
        if (cur->nsChar == nsChar) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   356
            if (cur->modifier == 0 && testableFlags == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   357
                // If the modifier field is 0, that means to transform
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   358
                // this character if no additional keyboard modifiers are set.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   359
                // 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
   360
                // into Newline.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   361
                return cur->javaChar;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   362
            } else if (cur->modifier != 0 &&
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   363
                       (testableFlags & cur->modifier) == testableFlags)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   364
            {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   365
                // Likewise, if the modifier field is nonzero, that means
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   366
                // transform this character if only these modifiers are
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   367
                // set in the testable flags.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   368
                return cur->javaChar;
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
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   372
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   373
    if (nsChar >= NSUpArrowFunctionKey && nsChar <= NSModeSwitchFunctionKey) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   374
        return java_awt_event_KeyEvent_CHAR_UNDEFINED;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   375
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   376
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   377
    // otherwise return character unchanged
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   378
    return nsChar;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   379
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   380
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   381
static unichar NsGetDeadKeyChar(unsigned short keyCode)
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   382
{
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   383
    TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource();
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   384
    CFDataRef uchr = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
13990
3e72145fd93a 7199180: [macosx] Dead keys handling for input methods
alexsch
parents: 13781
diff changeset
   385
    if (uchr == nil) { return; }
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   386
    const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout*)CFDataGetBytePtr(uchr);
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   387
    // Carbon modifiers should be used instead of NSEvent modifiers
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   388
    UInt32 modifierKeyState = (GetCurrentEventKeyModifiers() >> 8) & 0xFF;
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   389
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   390
    if (keyboardLayout) {
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   391
        UInt32 deadKeyState = 0;
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   392
        UniCharCount maxStringLength = 255;
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   393
        UniCharCount actualStringLength = 0;
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   394
        UniChar unicodeString[maxStringLength];
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   395
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   396
        // get the deadKeyState
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   397
        OSStatus status = UCKeyTranslate(keyboardLayout,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   398
                                         keyCode, kUCKeyActionDown, modifierKeyState,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   399
                                         LMGetKbdType(), kUCKeyTranslateNoDeadKeysBit,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   400
                                         &deadKeyState,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   401
                                         maxStringLength,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   402
                                         &actualStringLength, unicodeString);
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   403
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   404
        if (status == noErr && deadKeyState != 0) {
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   405
            // Press SPACE to get the dead key char
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   406
            status = UCKeyTranslate(keyboardLayout,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   407
                                    kVK_Space, kUCKeyActionDown, 0,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   408
                                    LMGetKbdType(), 0,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   409
                                    &deadKeyState,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   410
                                    maxStringLength,
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   411
                                    &actualStringLength, unicodeString);
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   412
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   413
            if (status == noErr && actualStringLength > 0) {
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   414
                return unicodeString[0];
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
        }
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
    return 0;
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   419
}
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   420
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   421
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   422
 * 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
   423
 * NSEvent keyCodes and translate to the Java virtual key code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   424
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   425
static void
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   426
NsCharToJavaVirtualKeyCode(unichar ch, BOOL isDeadChar,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   427
                           NSUInteger flags, unsigned short key,
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   428
                           jint *keyCode, jint *keyLocation, BOOL *postsTyped, unichar *deadChar)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   429
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   430
    static size_t size = sizeof(keyTable) / sizeof(struct _key);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   431
    NSInteger offset;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   432
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   433
    if (isDeadChar) {
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   434
        unichar testDeadChar = NsGetDeadKeyChar(key);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   435
        const struct CharToVKEntry *map;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   436
        for (map = charToDeadVKTable; map->c != 0; ++map) {
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   437
            if (testDeadChar == map->c) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   438
                *keyCode = map->javaKey;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   439
                *postsTyped = NO;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   440
                // TODO: use UNKNOWN here?
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   441
                *keyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   442
                *deadChar = testDeadChar;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   443
                return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   444
            }
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
        // If we got here, we keep looking for a normal key.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   447
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   448
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   449
    if ([[NSCharacterSet letterCharacterSet] characterIsMember:ch]) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   450
        // key is an alphabetic character
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   451
        unichar lower;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   452
        lower = tolower(ch);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   453
        offset = lower - 'a';
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   454
        if (offset >= 0 && offset <= 25) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   455
            // some chars in letter set are NOT actually A-Z characters?!
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   456
            // skip them...
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   457
            *postsTyped = YES;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   458
            // do quick conversion
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   459
            *keyCode = java_awt_event_KeyEvent_VK_A + offset;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   460
            *keyLocation = java_awt_event_KeyEvent_KEY_LOCATION_STANDARD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   461
            return;
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
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   464
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   465
    if ([[NSCharacterSet decimalDigitCharacterSet] characterIsMember:ch]) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   466
        // key is a digit
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   467
        offset = ch - '0';
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   468
        // make sure in range for decimal digits
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   469
        if (offset >= 0 && offset <= 9)    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   470
            jboolean numpad = (flags & NSNumericPadKeyMask) != 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   471
            *postsTyped = YES;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   472
            if (numpad) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   473
                *keyCode = offset + java_awt_event_KeyEvent_VK_NUMPAD0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   474
                *keyLocation = java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   475
            } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   476
                *keyCode = offset + java_awt_event_KeyEvent_VK_0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   477
                *keyLocation = java_awt_event_KeyEvent_KEY_LOCATION_STANDARD;
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
            return;
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
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   482
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   483
    if (key < size) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   484
        *postsTyped = keyTable[key].postsTyped;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   485
        *keyCode = keyTable[key].javaKeyCode;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   486
        *keyLocation = keyTable[key].javaKeyLocation;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   487
    } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   488
        // Should we report this? This means we've got a keyboard
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   489
        // we don't know about...
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   490
        *postsTyped = NO;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   491
        *keyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   492
        *keyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   496
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   497
 * This returns the java key data for the key NSEvent modifiers
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   498
 * (after NSFlagChanged).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   499
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   500
static void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   501
NsKeyModifiersToJavaKeyInfo(NSUInteger nsFlags, unsigned short eventKeyCode,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   502
                            jint *javaKeyCode,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   503
                            jint *javaKeyLocation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   504
                            jint *javaKeyType)
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
    static NSUInteger sPreviousNSFlags = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   507
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   508
    const struct _nsKeyToJavaModifier* cur;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   509
    NSUInteger oldNSFlags = sPreviousNSFlags;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   510
    NSUInteger changedNSFlags = oldNSFlags ^ nsFlags;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   511
    sPreviousNSFlags = nsFlags;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   512
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   513
    *javaKeyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   514
    *javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   515
    *javaKeyType = java_awt_event_KeyEvent_KEY_PRESSED;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   516
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   517
    for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   518
        if (changedNSFlags & cur->nsMask) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   519
            *javaKeyCode = cur->javaKey;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   520
            *javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_STANDARD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   521
            // TODO: uses SPI...
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   522
            //if (changedNSFlags & cur->cgsLeftMask) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   523
            //    *javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_LEFT;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   524
            //} else if (changedNSFlags & cur->cgsRightMask) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   525
            //    *javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_RIGHT;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   526
            //}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   527
            if (eventKeyCode == cur->leftKeyCode) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   528
                *javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_LEFT;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   529
            } else if (eventKeyCode == cur->rightKeyCode) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   530
                *javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_RIGHT;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   531
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   532
            *javaKeyType = (cur->nsMask & nsFlags) ?
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   533
                java_awt_event_KeyEvent_KEY_PRESSED :
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   534
                java_awt_event_KeyEvent_KEY_RELEASED;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   535
            break;
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   540
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   541
 * This returns the java modifiers for a key NSEvent.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   542
 */
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   543
jint NsKeyModifiersToJavaModifiers(NSUInteger nsFlags, BOOL isExtMods)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   544
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   545
    jint javaModifiers = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   546
    const struct _nsKeyToJavaModifier* cur;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   547
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   548
    for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   549
        if ((cur->nsMask & nsFlags) != 0) {
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   550
            javaModifiers |= isExtMods? cur->javaExtMask : cur->javaMask;
12047
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
    }
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
    return javaModifiers;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   555
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   556
13781
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
 * This returns the NSEvent flags for java key modifiers.
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 JavaModifiersToNsKeyModifiers(jint javaModifiers, BOOL isExtMods)
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   561
{
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   562
    NSUInteger nsFlags = 0;
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   563
    const struct _nsKeyToJavaModifier* cur;
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   564
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   565
    for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
13990
3e72145fd93a 7199180: [macosx] Dead keys handling for input methods
alexsch
parents: 13781
diff changeset
   566
        jint mask = isExtMods? cur->javaExtMask : cur->javaMask;
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   567
        if ((mask & javaModifiers) != 0) {
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   568
            nsFlags |= cur->nsMask;
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
    }
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   571
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   572
    // special case
13990
3e72145fd93a 7199180: [macosx] Dead keys handling for input methods
alexsch
parents: 13781
diff changeset
   573
    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
   574
                           java_awt_event_InputEvent_ALT_GRAPH_MASK;
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   575
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   576
    if ((mask & javaModifiers) != 0) {
13990
3e72145fd93a 7199180: [macosx] Dead keys handling for input methods
alexsch
parents: 13781
diff changeset
   577
        nsFlags |= NSAlternateKeyMask;
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   578
    }
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
    return nsFlags;
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   581
}
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   582
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   583
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   584
jint GetJavaMouseModifiers(NSInteger button, NSUInteger modifierFlags)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   585
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   586
    // Mousing needs the key modifiers
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   587
    jint modifiers = NsKeyModifiersToJavaModifiers(modifierFlags, YES);
12047
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
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
     * Ask Quartz about mouse buttons state
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   592
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   593
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   594
    if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   595
                                 kCGMouseButtonLeft)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   596
        modifiers |= java_awt_event_InputEvent_BUTTON1_DOWN_MASK;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   597
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   598
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   599
    if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   600
                                 kCGMouseButtonRight)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   601
        modifiers |= java_awt_event_InputEvent_BUTTON3_DOWN_MASK;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   602
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   603
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   604
    if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   605
                                 kCGMouseButtonCenter)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   606
        modifiers |= java_awt_event_InputEvent_BUTTON2_DOWN_MASK;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   607
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   608
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   609
    NSInteger extraButton = 3;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   610
    for (; extraButton < gNumberOfButtons; extraButton++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   611
        if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   612
                                 extraButton)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   613
            modifiers |= gButtonDownMasks[extraButton];
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
    }
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
    return modifiers;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   618
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   619
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   620
jlong UTC(NSEvent *event) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   621
    struct timeval tv;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   622
    if (gettimeofday(&tv, NULL) == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   623
        long long sec = (long long)tv.tv_sec;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   624
        return (sec*1000) + (tv.tv_usec/1000);
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
    return 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   627
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   628
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   629
JNIEXPORT void JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   630
Java_java_awt_AWTEvent_nativeSetSource
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   631
    (JNIEnv *env, jobject self, jobject newSource)
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
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   634
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   635
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   636
 * Class:     sun_lwawt_macosx_event_NSEvent
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   637
 * Method:    nsToJavaMouseModifiers
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   638
 * Signature: (II)I
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   639
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   640
JNIEXPORT jint JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   641
Java_sun_lwawt_macosx_event_NSEvent_nsToJavaMouseModifiers
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   642
(JNIEnv *env, jclass cls, jint buttonNumber, jint modifierFlags)
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
    jint jmodifiers = 0;
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
JNF_COCOA_ENTER(env);
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
    jmodifiers = GetJavaMouseModifiers(buttonNumber, modifierFlags);
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
JNF_COCOA_EXIT(env);
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
    return jmodifiers;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   653
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   654
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   655
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   656
 * Class:     sun_lwawt_macosx_event_NSEvent
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   657
 * Method:    nsToJavaKeyModifiers
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   658
 * Signature: (I)I
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   659
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   660
JNIEXPORT jint JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   661
Java_sun_lwawt_macosx_event_NSEvent_nsToJavaKeyModifiers
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   662
(JNIEnv *env, jclass cls, jint modifierFlags)
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
    jint jmodifiers = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   665
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   666
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   667
13781
bf3d53b1fba7 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents: 13778
diff changeset
   668
    jmodifiers = NsKeyModifiersToJavaModifiers(modifierFlags, YES);
12047
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
JNF_COCOA_EXIT(env);
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
    return jmodifiers;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   673
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   674
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   675
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   676
 * Class:     sun_lwawt_macosx_event_NSEvent
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   677
 * Method:    nsToJavaKeyInfo
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   678
 * Signature: ([I[I)Z
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   679
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   680
JNIEXPORT jboolean JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   681
Java_sun_lwawt_macosx_event_NSEvent_nsToJavaKeyInfo
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   682
(JNIEnv *env, jclass cls, jintArray inData, jintArray outData)
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
    BOOL postsTyped = NO;
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
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   687
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   688
    jboolean copy = JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   689
    jint *data = (*env)->GetIntArrayElements(env, inData, &copy);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   690
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   691
    // in  = [testChar, testDeadChar, modifierFlags, keyCode]
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   692
    jchar testChar = (jchar)data[0];
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   693
    BOOL isDeadChar = (data[1] != 0);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   694
    jint modifierFlags = data[2];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   695
    jshort keyCode = (jshort)data[3];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   696
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   697
    jint jkeyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   698
    jint jkeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   699
    jchar testDeadChar = 0;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   700
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   701
    NsCharToJavaVirtualKeyCode((unichar)testChar, isDeadChar,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   702
                               (NSUInteger)modifierFlags, (unsigned short)keyCode,
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   703
                               &jkeyCode, &jkeyLocation, &postsTyped, &testDeadChar);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   704
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   705
    // out = [jkeyCode, jkeyLocation];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   706
    (*env)->SetIntArrayRegion(env, outData, 0, 1, &jkeyCode);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   707
    (*env)->SetIntArrayRegion(env, outData, 1, 1, &jkeyLocation);
13778
0ba9254a04ad 7196547: [macosx] Implement dead key detection for KeyEvent
alexsch
parents: 12410
diff changeset
   708
    (*env)->SetIntArrayRegion(env, outData, 2, 1, (jint *)&testDeadChar);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   709
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   710
    (*env)->ReleaseIntArrayElements(env, inData, data, 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   711
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   712
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   713
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   714
    return postsTyped;
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   717
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   718
 * Class:     sun_lwawt_macosx_event_NSEvent
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   719
 * Method:    nsKeyModifiersToJavaKeyInfo
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   720
 * Signature: ([I[I)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   721
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   722
JNIEXPORT void JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   723
Java_sun_lwawt_macosx_event_NSEvent_nsKeyModifiersToJavaKeyInfo
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   724
(JNIEnv *env, jclass cls, jintArray inData, jintArray outData)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   725
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   726
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   727
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   728
    jboolean copy = JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   729
    jint *data = (*env)->GetIntArrayElements(env, inData, &copy);
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
/*
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   756
 * Class:     sun_lwawt_macosx_event_NSEvent
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
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   761
Java_sun_lwawt_macosx_event_NSEvent_nsToJavaChar
6e5f5781a5af 7124272: [macosx] VK_DELETE does produce an extraneous character in a TextArea or TextField
leonidr
parents: 12407
diff changeset
   762
(JNIEnv *env, jclass cls, char nsChar, jint modifierFlags)
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
}