From 2898b68fc4f7ff40844ddf5a1d0b59f76b06290f Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 21 Apr 2020 17:08:43 +0800 Subject: ... --- src/win/native/input_method.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src/win/native/input_method.cpp') diff --git a/src/win/native/input_method.cpp b/src/win/native/input_method.cpp index 091abedd..dba2b1eb 100644 --- a/src/win/native/input_method.cpp +++ b/src/win/native/input_method.cpp @@ -247,10 +247,31 @@ IEvent* WinInputMethodContext::CompositionEvent() { return &composition_event_; } +IEvent* WinInputMethodContext::TextEvent() { + return &text_event_; +} + void WinInputMethodContext::OnWindowNativeMessage( WindowNativeMessageEventArgs& args) { - const auto message = args.GetWindowMessage(); + const auto& message = args.GetWindowMessage(); switch (message.msg) { + case WM_CHAR: { + const auto c = static_cast(message.w_param); + if (platform::win::IsSurrogatePair(c)) { + // I don't think this will happen because normal key strike without ime + // should only trigger ascci character. If it is a charater from + // supplementary planes, it should be handled with ime messages. + log::Warn( + "WinInputMethodContext: A WM_CHAR message for character from " + "supplementary planes is ignored."); + } else { + wchar_t s[1] = {c}; + auto str = platform::win::ToUtf8String({s, 1}); + text_event_.Raise(str); + } + args.HandleWithResult(0); + break; + } case WM_IME_COMPOSITION: { composition_event_.Raise(nullptr); auto composition_text = GetCompositionText(); @@ -259,9 +280,7 @@ void WinInputMethodContext::OnWindowNativeMessage( composition_text); if (message.l_param & GCS_RESULTSTR) { auto result_string = GetResultString(); - log::Debug( - "WinInputMethodContext: WM_IME_COMPOSITION result string: {}", - result_string); + text_event_.Raise(result_string); } break; } -- cgit v1.2.3