From ef1c9b2f892d211d70d240b22d61f37ffd7e4a07 Mon Sep 17 00:00:00 2001 From: Lenheart357 <106205154+Lenheart357@users.noreply.github.com> Date: Fri, 8 Sep 2023 20:52:41 +0800 Subject: [PATCH] feat(window): support enable & disable imm --- src/kiwano/platform/Window.h | 6 ++++++ src/kiwano/platform/win32/WindowImpl.cpp | 23 ++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/kiwano/platform/Window.h b/src/kiwano/platform/Window.h index 58841950..a712f20f 100644 --- a/src/kiwano/platform/Window.h +++ b/src/kiwano/platform/Window.h @@ -264,6 +264,12 @@ public: */ void SetShouldClose(bool should); + /** + * \~chinese + * @brief 启用或禁用输入法(默认禁用) + */ + virtual void SetImmEnabled(bool enable) = 0; + protected: Window(); diff --git a/src/kiwano/platform/win32/WindowImpl.cpp b/src/kiwano/platform/win32/WindowImpl.cpp index 2dff045a..9d09131b 100644 --- a/src/kiwano/platform/win32/WindowImpl.cpp +++ b/src/kiwano/platform/win32/WindowImpl.cpp @@ -66,6 +66,8 @@ public: void PumpEvents() override; + void SetImmEnabled(bool enable) override; + DWORD GetStyle() const; void SetActive(bool active); @@ -81,6 +83,7 @@ private: bool is_moving_or_resizing_; bool is_minimized_; CursorType mouse_cursor_; + HIMC imc_; String device_name_; Vector resolutions_; @@ -170,6 +173,7 @@ WindowWin32Impl::WindowWin32Impl() , is_minimized_(false) , mouse_cursor_(CursorType::Arrow) , key_map_{} + , imc_(nullptr) { // Keys key_map_[VK_UP] = KeyCode::Up; @@ -280,7 +284,7 @@ void WindowWin32Impl::Init(const WindowConfig& config) } // disable imm - ::ImmAssociateContext(handle_, nullptr); + SetImmEnabled(false); // use Application instance in message loop ::SetWindowLongPtrA(handle_, GWLP_USERDATA, LONG_PTR(this)); @@ -323,6 +327,23 @@ void WindowWin32Impl::PumpEvents() } } +void WindowWin32Impl::SetImmEnabled(bool enable) +{ + const bool enabled = imc_ != nullptr; + if (enable != enabled) + { + if (enable) + { + imc_ = ::ImmAssociateContext(handle_, nullptr); + } + else + { + ::ImmAssociateContext(handle_, imc_); + imc_ = nullptr; + } + } +} + void WindowWin32Impl::SetTitle(const String& title) { KGE_ASSERT(handle_);