diff --git a/panda/src/wdxdisplay/wdxGraphicsWindow.cxx b/panda/src/wdxdisplay/wdxGraphicsWindow.cxx index b1050c48f5..8f33faa9d0 100644 --- a/panda/src/wdxdisplay/wdxGraphicsWindow.cxx +++ b/panda/src/wdxdisplay/wdxGraphicsWindow.cxx @@ -271,6 +271,7 @@ set_window_handle(HWND hwnd) { // Determine the initial open status of the IME. _ime_open = false; + _ime_active = false; HIMC hIMC = ImmGetContext(hwnd); if (hIMC != 0) { _ime_open = (ImmGetOpenStatus(hIMC) != 0); @@ -350,6 +351,9 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { HIMC hIMC = ImmGetContext(hwnd); nassertr(hIMC != 0, 0); _ime_open = (ImmGetOpenStatus(hIMC) != 0); + if (!_ime_open) { + _ime_active = false; // Sanity enforcement. + } ImmReleaseContext(hwnd, hIMC); } break; @@ -359,12 +363,14 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { // explicit DX support for overlay windows now, so we'll be able // to see the IME window. _dxgsg->support_overlay_window(true); + _ime_active = true; break; case WM_IME_ENDCOMPOSITION: // Turn off the support for overlay windows, since we're done // with the IME window for now and it just slows things down. _dxgsg->support_overlay_window(false); + _ime_active = false; break; case WM_IME_COMPOSITION: @@ -960,7 +966,7 @@ void wdxGraphicsWindow::reactivate_window(void) { // Description: //////////////////////////////////////////////////////////////////// wdxGraphicsWindow::wdxGraphicsWindow(GraphicsPipe* pipe) : GraphicsWindow(pipe) { - _ime_open = false; + _ime_active = false; _pParentWindowGroup=NULL; _pParentWindowGroup=new wdxGraphicsWindowGroup(this); } @@ -2657,15 +2663,25 @@ TypeHandle wdxGraphicsWindow::get_type(void) const { //////////////////////////////////////////////////////////////////// ButtonHandle wdxGraphicsWindow:: lookup_key(WPARAM wparam) const { + // First, check for a few buttons that we filter out when the IME + // window is open. + if (!_ime_active) { + switch(wparam) { + case VK_BACK: return KeyboardButton::backspace(); + case VK_DELETE: return KeyboardButton::del(); + case VK_ESCAPE: return KeyboardButton::escape(); + case VK_SPACE: return KeyboardButton::space(); + case VK_UP: return KeyboardButton::up(); + case VK_DOWN: return KeyboardButton::down(); + case VK_LEFT: return KeyboardButton::left(); + case VK_RIGHT: return KeyboardButton::right(); + } + } + + // Now check for the rest of the buttons, including the ones that + // we allow through even when the IME window is open. switch(wparam) { - case VK_BACK: return KeyboardButton::backspace(); case VK_TAB: return KeyboardButton::tab(); - case VK_ESCAPE: return KeyboardButton::escape(); - case VK_SPACE: return KeyboardButton::space(); - case VK_UP: return KeyboardButton::up(); - case VK_DOWN: return KeyboardButton::down(); - case VK_LEFT: return KeyboardButton::left(); - case VK_RIGHT: return KeyboardButton::right(); case VK_PRIOR: return KeyboardButton::page_up(); case VK_NEXT: return KeyboardButton::page_down(); case VK_HOME: return KeyboardButton::home(); @@ -2683,7 +2699,6 @@ lookup_key(WPARAM wparam) const { case VK_F11: return KeyboardButton::f11(); case VK_F12: return KeyboardButton::f12(); case VK_INSERT: return KeyboardButton::insert(); - case VK_DELETE: return KeyboardButton::del(); case VK_CAPITAL: return KeyboardButton::caps_lock(); case VK_NUMLOCK: return KeyboardButton::num_lock(); case VK_SCROLL: return KeyboardButton::scroll_lock(); diff --git a/panda/src/wdxdisplay/wdxGraphicsWindow.h b/panda/src/wdxdisplay/wdxGraphicsWindow.h index 35d00b801c..99b3d2ca48 100644 --- a/panda/src/wdxdisplay/wdxGraphicsWindow.h +++ b/panda/src/wdxdisplay/wdxGraphicsWindow.h @@ -127,6 +127,7 @@ private: bool _mouse_passive_motion_enabled; bool _mouse_entry_enabled; bool _ime_open; + bool _ime_active; bool _ime_composition_w; bool _exiting_window; bool _window_inactive; diff --git a/panda/src/wgldisplay/wglGraphicsWindow.cxx b/panda/src/wgldisplay/wglGraphicsWindow.cxx index d4d4fe5f78..4aa0406a24 100644 --- a/panda/src/wgldisplay/wglGraphicsWindow.cxx +++ b/panda/src/wgldisplay/wglGraphicsWindow.cxx @@ -513,6 +513,7 @@ void wglGraphicsWindow::config() { // Determine the initial open status of the IME. _ime_open = false; + _ime_active = false; HIMC hIMC = ImmGetContext(_mwindow); if (hIMC != 0) { _ime_open = (ImmGetOpenStatus(hIMC) != 0); @@ -1663,10 +1664,21 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { HIMC hIMC = ImmGetContext(hwnd); nassertr(hIMC != 0, 0); _ime_open = (ImmGetOpenStatus(hIMC) != 0); + if (!_ime_open) { + _ime_active = false; // Sanity enforcement. + } ImmReleaseContext(hwnd, hIMC); } break; + case WM_IME_STARTCOMPOSITION: + _ime_active = true; + break; + + case WM_IME_ENDCOMPOSITION: + _ime_active = false; + break; + case WM_IME_COMPOSITION: if (lparam & GCS_RESULTSTR) { if (!_input_devices.empty()) { @@ -1912,15 +1924,25 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { //////////////////////////////////////////////////////////////////// ButtonHandle wglGraphicsWindow:: lookup_key(WPARAM wparam) const { + // First, check for a few buttons that we filter out when the IME + // window is open. + if (!_ime_active) { + switch(wparam) { + case VK_BACK: return KeyboardButton::backspace(); + case VK_DELETE: return KeyboardButton::del(); + case VK_ESCAPE: return KeyboardButton::escape(); + case VK_SPACE: return KeyboardButton::space(); + case VK_UP: return KeyboardButton::up(); + case VK_DOWN: return KeyboardButton::down(); + case VK_LEFT: return KeyboardButton::left(); + case VK_RIGHT: return KeyboardButton::right(); + } + } + + // Now check for the rest of the buttons, including the ones that + // we allow through even when the IME window is open. switch(wparam) { - case VK_BACK: return KeyboardButton::backspace(); case VK_TAB: return KeyboardButton::tab(); - case VK_ESCAPE: return KeyboardButton::escape(); - case VK_SPACE: return KeyboardButton::space(); - case VK_UP: return KeyboardButton::up(); - case VK_DOWN: return KeyboardButton::down(); - case VK_LEFT: return KeyboardButton::left(); - case VK_RIGHT: return KeyboardButton::right(); case VK_PRIOR: return KeyboardButton::page_up(); case VK_NEXT: return KeyboardButton::page_down(); case VK_HOME: return KeyboardButton::home(); @@ -1938,7 +1960,6 @@ lookup_key(WPARAM wparam) const { case VK_F11: return KeyboardButton::f11(); case VK_F12: return KeyboardButton::f12(); case VK_INSERT: return KeyboardButton::insert(); - case VK_DELETE: return KeyboardButton::del(); case VK_CAPITAL: return KeyboardButton::caps_lock(); case VK_NUMLOCK: return KeyboardButton::num_lock(); case VK_SCROLL: return KeyboardButton::scroll_lock(); diff --git a/panda/src/wgldisplay/wglGraphicsWindow.h b/panda/src/wgldisplay/wglGraphicsWindow.h index 8ec63b9392..98d91e270c 100644 --- a/panda/src/wgldisplay/wglGraphicsWindow.h +++ b/panda/src/wgldisplay/wglGraphicsWindow.h @@ -131,6 +131,7 @@ private: bool _mouse_passive_motion_enabled; bool _mouse_entry_enabled; bool _ime_open; + bool _ime_active; bool _ime_composition_w; // vars for frames/sec meter