diff options
Diffstat (limited to 'src/win/native')
-rw-r--r-- | src/win/native/input_method.cpp | 32 | ||||
-rw-r--r-- | src/win/native/ui_application.cpp | 6 | ||||
-rw-r--r-- | src/win/native/window.cpp | 22 |
3 files changed, 54 insertions, 6 deletions
diff --git a/src/win/native/input_method.cpp b/src/win/native/input_method.cpp index 73831bd5..091abedd 100644 --- a/src/win/native/input_method.cpp +++ b/src/win/native/input_method.cpp @@ -84,8 +84,8 @@ CompositionClauses GetCompositionClauses(HIMC imm_context, int target_start, int clause_size = ::ImmGetCompositionString(imm_context, GCS_COMPCLAUSE, NULL, 0); int clause_length = clause_size / sizeof(std::uint32_t); - result.reserve(clause_length - 1); if (clause_length) { + result.reserve(clause_length - 1); std::vector<std::uint32_t> clause_data(clause_length); ::ImmGetCompositionString(imm_context, GCS_COMPCLAUSE, clause_data.data(), clause_size); @@ -107,12 +107,21 @@ CompositionClauses GetCompositionClauses(HIMC imm_context, int target_start, std::wstring GetString(HIMC imm_context) { LONG string_size = ::ImmGetCompositionString(imm_context, GCS_COMPSTR, NULL, 0); - std::wstring result((string_size / sizeof(wchar_t)) + 1, 0); + std::wstring result((string_size / sizeof(wchar_t)), 0); ::ImmGetCompositionString(imm_context, GCS_COMPSTR, result.data(), string_size); return result; } +std::wstring GetResultString(HIMC imm_context) { + LONG string_size = + ::ImmGetCompositionString(imm_context, GCS_RESULTSTR, NULL, 0); + std::wstring result((string_size / sizeof(wchar_t)), 0); + ::ImmGetCompositionString(imm_context, GCS_RESULTSTR, result.data(), + string_size); + return result; +} + CompositionText GetCompositionInfo(HIMC imm_context) { // We only care about GCS_COMPATTR, GCS_COMPCLAUSE and GCS_CURSORPOS, and // convert them into underlines and selection range respectively. @@ -244,6 +253,16 @@ void WinInputMethodContext::OnWindowNativeMessage( switch (message.msg) { case WM_IME_COMPOSITION: { composition_event_.Raise(nullptr); + auto composition_text = GetCompositionText(); + log::Debug( + "WinInputMethodContext: WM_IME_COMPOSITION composition text:\n{}", + composition_text); + if (message.l_param & GCS_RESULTSTR) { + auto result_string = GetResultString(); + log::Debug( + "WinInputMethodContext: WM_IME_COMPOSITION result string: {}", + result_string); + } break; } case WM_IME_STARTCOMPOSITION: { @@ -257,6 +276,15 @@ void WinInputMethodContext::OnWindowNativeMessage( } } +std::string WinInputMethodContext::GetResultString() { + auto optional_himc = TryGetHIMC(); + if (!optional_himc.has_value()) return ""; + auto himc = *std::move(optional_himc); + + auto w_result = win::GetResultString(himc.Get()); + return platform::win::ToUtf8String(w_result); +} + std::optional<AutoHIMC> WinInputMethodContext::TryGetHIMC() { const auto native_window = Resolve(native_window_resolver_.get()); if (native_window == nullptr) return std::nullopt; diff --git a/src/win/native/ui_application.cpp b/src/win/native/ui_application.cpp index 7fba6805..9aa3ebcd 100644 --- a/src/win/native/ui_application.cpp +++ b/src/win/native/ui_application.cpp @@ -13,6 +13,12 @@ #include "timer.hpp" #include "window_manager.hpp" +namespace cru::platform::native { +std::unique_ptr<IUiApplication> CreateUiApplication() { + return std::make_unique<win::WinUiApplication>(); +} +} // namespace cru::platform::native + namespace cru::platform::native::win { WinUiApplication* WinUiApplication::instance = nullptr; diff --git a/src/win/native/window.cpp b/src/win/native/window.cpp index 7ad63769..30c77659 100644 --- a/src/win/native/window.cpp +++ b/src/win/native/window.cpp @@ -290,6 +290,20 @@ bool WinNativeWindow::HandleNativeWindowMessage(HWND hwnd, UINT msg, OnKeyUpInternal(static_cast<int>(w_param)); *result = 0; return true; + case WM_SYSKEYDOWN: + if (l_param & (1 << 29)) { + OnKeyDownInternal(static_cast<int>(w_param)); + *result = 0; + return true; + } + return false; + case WM_SYSKEYUP: + if (l_param & (1 << 29)) { + OnKeyUpInternal(static_cast<int>(w_param)); + *result = 0; + return true; + } + return false; case WM_CHAR: OnCharInternal(static_cast<wchar_t>(w_param)); *result = 0; @@ -419,13 +433,13 @@ void WinNativeWindow::OnCharInternal(wchar_t c) { last_wm_char_event_wparam_ = c; return; } else if (platform::win::IsSurrogatePairTrailing(c)) { - wchar_t s[3] = {last_wm_char_event_wparam_, c, 0}; - auto str = platform::win::ToUtf8String(s); + wchar_t s[2] = {last_wm_char_event_wparam_, c}; + auto str = platform::win::ToUtf8String({s, 2}); char_event_.Raise(str); log::Debug("WinNativeWindow: char event, charactor is {}", str); } else { - wchar_t s[2] = {c, 0}; - auto str = platform::win::ToUtf8String(s); + wchar_t s[1] = {c}; + auto str = platform::win::ToUtf8String({s, 1}); char_event_.Raise(str); log::Debug("WinNativeWindow: char event, charactor is {}", str); } |