Merge pull request #69 from Lenheart357/patch-1

Support enable & disable imm
This commit is contained in:
Haibo 2023-09-08 22:06:01 +08:00 committed by GitHub
commit a13d631edf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -264,6 +264,12 @@ public:
*/
void SetShouldClose(bool should);
/**
* \~chinese
* @brief
*/
virtual void SetImmEnabled(bool enable) = 0;
protected:
Window();

View File

@ -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<Resolution> 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_);