提交 be5a175a 编写于 作者: A alexsch

7197619: Using modifiers for the dead key detection on Windows

Reviewed-by: bagiras, leonidr
上级 fd6a4551
...@@ -3144,7 +3144,8 @@ void AwtComponent::JavaKeyToWindowsKey(UINT javaKey, ...@@ -3144,7 +3144,8 @@ void AwtComponent::JavaKeyToWindowsKey(UINT javaKey,
return; return;
} }
UINT AwtComponent::WindowsKeyToJavaKey(UINT windowsKey, UINT modifiers) UINT AwtComponent::WindowsKeyToJavaKey(UINT windowsKey, UINT modifiers, UINT character, BOOL isDeadKey)
{ {
// Handle the few cases where we need to take the modifier into // Handle the few cases where we need to take the modifier into
// consideration for the Java VK code or where we have to take the keyboard // consideration for the Java VK code or where we have to take the keyboard
...@@ -3171,6 +3172,15 @@ UINT AwtComponent::WindowsKeyToJavaKey(UINT windowsKey, UINT modifiers) ...@@ -3171,6 +3172,15 @@ UINT AwtComponent::WindowsKeyToJavaKey(UINT windowsKey, UINT modifiers)
break; break;
}; };
// check dead key
if (isDeadKey) {
for (int i = 0; charToDeadVKTable[i].c != 0; i++) {
if (charToDeadVKTable[i].c == character) {
return charToDeadVKTable[i].javaKey;
}
}
}
// for the general case, use a bi-directional table // for the general case, use a bi-directional table
for (int i = 0; keyMapTable[i].windowsKey != 0; i++) { for (int i = 0; keyMapTable[i].windowsKey != 0; i++) {
if (keyMapTable[i].windowsKey == windowsKey) { if (keyMapTable[i].windowsKey == windowsKey) {
...@@ -3384,14 +3394,18 @@ AwtComponent::UpdateDynPrimaryKeymap(UINT wkey, UINT jkeyLegacy, jint keyLocatio ...@@ -3384,14 +3394,18 @@ AwtComponent::UpdateDynPrimaryKeymap(UINT wkey, UINT jkeyLegacy, jint keyLocatio
} }
} }
UINT AwtComponent::WindowsKeyToJavaChar(UINT wkey, UINT modifiers, TransOps ops) UINT AwtComponent::WindowsKeyToJavaChar(UINT wkey, UINT modifiers, TransOps ops, BOOL &isDeadKey)
{ {
static Hashtable transTable("VKEY translations"); static Hashtable transTable("VKEY translations");
static Hashtable deadKeyFlagTable("Dead Key Flags");
isDeadKey = FALSE;
// Try to translate using last saved translation // Try to translate using last saved translation
if (ops == LOAD) { if (ops == LOAD) {
void* deadKeyFlag = deadKeyFlagTable.remove(reinterpret_cast<void*>(static_cast<INT_PTR>(wkey)));
void* value = transTable.remove(reinterpret_cast<void*>(static_cast<INT_PTR>(wkey))); void* value = transTable.remove(reinterpret_cast<void*>(static_cast<INT_PTR>(wkey)));
if (value != NULL) { if (value != NULL) {
isDeadKey = static_cast<BOOL>(reinterpret_cast<INT_PTR>(deadKeyFlag));
return static_cast<UINT>(reinterpret_cast<INT_PTR>(value)); return static_cast<UINT>(reinterpret_cast<INT_PTR>(value));
} }
} }
...@@ -3484,12 +3498,13 @@ UINT AwtComponent::WindowsKeyToJavaChar(UINT wkey, UINT modifiers, TransOps ops) ...@@ -3484,12 +3498,13 @@ UINT AwtComponent::WindowsKeyToJavaChar(UINT wkey, UINT modifiers, TransOps ops)
// instead of creating our own conversion tables, I'll let Win32 // instead of creating our own conversion tables, I'll let Win32
// convert the character for me. // convert the character for me.
WORD mbChar; WORD wChar[2];
UINT scancode = ::MapVirtualKey(wkey, 0); UINT scancode = ::MapVirtualKey(wkey, 0);
int converted = ::ToAsciiEx(wkey, scancode, keyboardState, int converted = ::ToUnicodeEx(wkey, scancode, keyboardState,
&mbChar, 0, GetKeyboardLayout()); wChar, 2, 0, GetKeyboardLayout());
UINT translation; UINT translation;
BOOL deadKeyFlag = (converted == 2);
// Dead Key // Dead Key
if (converted < 0) { if (converted < 0) {
...@@ -3508,16 +3523,16 @@ UINT AwtComponent::WindowsKeyToJavaChar(UINT wkey, UINT modifiers, TransOps ops) ...@@ -3508,16 +3523,16 @@ UINT AwtComponent::WindowsKeyToJavaChar(UINT wkey, UINT modifiers, TransOps ops)
} else } else
// the caller expects a Unicode character. // the caller expects a Unicode character.
if (converted > 0) { if (converted > 0) {
WCHAR unicodeChar[2]; translation = wChar[0];
VERIFY(::MultiByteToWideChar(GetCodePage(), MB_PRECOMPOSED,
(LPCSTR)&mbChar, 1, unicodeChar, 1));
translation = unicodeChar[0];
} }
if (ops == SAVE) { if (ops == SAVE) {
transTable.put(reinterpret_cast<void*>(static_cast<INT_PTR>(wkey)), transTable.put(reinterpret_cast<void*>(static_cast<INT_PTR>(wkey)),
reinterpret_cast<void*>(static_cast<INT_PTR>(translation))); reinterpret_cast<void*>(static_cast<INT_PTR>(translation)));
deadKeyFlagTable.put(reinterpret_cast<void*>(static_cast<INT_PTR>(wkey)),
reinterpret_cast<void*>(static_cast<INT_PTR>(deadKeyFlag)));
} }
isDeadKey = deadKeyFlag;
return translation; return translation;
} }
...@@ -3537,8 +3552,9 @@ MsgRouting AwtComponent::WmKeyDown(UINT wkey, UINT repCnt, ...@@ -3537,8 +3552,9 @@ MsgRouting AwtComponent::WmKeyDown(UINT wkey, UINT repCnt,
UINT modifiers = GetJavaModifiers(); UINT modifiers = GetJavaModifiers();
jint keyLocation = GetKeyLocation(wkey, flags); jint keyLocation = GetKeyLocation(wkey, flags);
UINT jkey = WindowsKeyToJavaKey(wkey, modifiers); BOOL isDeadKey = FALSE;
UINT character = WindowsKeyToJavaChar(wkey, modifiers, SAVE); UINT character = WindowsKeyToJavaChar(wkey, modifiers, SAVE, isDeadKey);
UINT jkey = WindowsKeyToJavaKey(wkey, modifiers, character, isDeadKey);
UpdateDynPrimaryKeymap(wkey, jkey, keyLocation, modifiers); UpdateDynPrimaryKeymap(wkey, jkey, keyLocation, modifiers);
...@@ -3579,8 +3595,9 @@ MsgRouting AwtComponent::WmKeyUp(UINT wkey, UINT repCnt, ...@@ -3579,8 +3595,9 @@ MsgRouting AwtComponent::WmKeyUp(UINT wkey, UINT repCnt,
UINT modifiers = GetJavaModifiers(); UINT modifiers = GetJavaModifiers();
jint keyLocation = GetKeyLocation(wkey, flags); jint keyLocation = GetKeyLocation(wkey, flags);
UINT jkey = WindowsKeyToJavaKey(wkey, modifiers); BOOL isDeadKey = FALSE;
UINT character = WindowsKeyToJavaChar(wkey, modifiers, LOAD); UINT character = WindowsKeyToJavaChar(wkey, modifiers, LOAD, isDeadKey);
UINT jkey = WindowsKeyToJavaKey(wkey, modifiers, character, isDeadKey);
UpdateDynPrimaryKeymap(wkey, jkey, keyLocation, modifiers); UpdateDynPrimaryKeymap(wkey, jkey, keyLocation, modifiers);
SendKeyEventToFocusOwner(java_awt_event_KeyEvent_KEY_RELEASED, SendKeyEventToFocusOwner(java_awt_event_KeyEvent_KEY_RELEASED,
...@@ -5628,7 +5645,8 @@ void AwtComponent::_NativeHandleEvent(void *param) ...@@ -5628,7 +5645,8 @@ void AwtComponent::_NativeHandleEvent(void *param)
} }
} }
modifiedChar = p->WindowsKeyToJavaChar(winKey, modifiers, AwtComponent::NONE); BOOL isDeadKey = FALSE;
modifiedChar = p->WindowsKeyToJavaChar(winKey, modifiers, AwtComponent::NONE, isDeadKey);
bCharChanged = (keyChar != modifiedChar); bCharChanged = (keyChar != modifiedChar);
} }
break; break;
......
...@@ -441,7 +441,7 @@ public: ...@@ -441,7 +441,7 @@ public:
static jint GetJavaModifiers(); static jint GetJavaModifiers();
static jint GetButton(int mouseButton); static jint GetButton(int mouseButton);
static UINT GetButtonMK(int mouseButton); static UINT GetButtonMK(int mouseButton);
static UINT WindowsKeyToJavaKey(UINT windowsKey, UINT modifiers); static UINT WindowsKeyToJavaKey(UINT windowsKey, UINT modifiers, UINT character, BOOL isDeadKey);
static void JavaKeyToWindowsKey(UINT javaKey, UINT *windowsKey, UINT *modifiers, UINT originalWindowsKey); static void JavaKeyToWindowsKey(UINT javaKey, UINT *windowsKey, UINT *modifiers, UINT originalWindowsKey);
static void UpdateDynPrimaryKeymap(UINT wkey, UINT jkeyLegacy, jint keyLocation, UINT modifiers); static void UpdateDynPrimaryKeymap(UINT wkey, UINT jkeyLegacy, jint keyLocation, UINT modifiers);
...@@ -453,7 +453,7 @@ public: ...@@ -453,7 +453,7 @@ public:
enum TransOps {NONE, LOAD, SAVE}; enum TransOps {NONE, LOAD, SAVE};
UINT WindowsKeyToJavaChar(UINT wkey, UINT modifiers, TransOps ops); UINT WindowsKeyToJavaChar(UINT wkey, UINT modifiers, TransOps ops, BOOL &isDeadKey);
/* routines used for input method support */ /* routines used for input method support */
void SetInputMethod(jobject im, BOOL useNativeCompWindow); void SetInputMethod(jobject im, BOOL useNativeCompWindow);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册