diff options
author | crupest <crupest@outlook.com> | 2020-04-21 17:08:43 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-04-21 17:08:43 +0800 |
commit | 2898b68fc4f7ff40844ddf5a1d0b59f76b06290f (patch) | |
tree | 167ba0bff2d995a6f68337bb83cc9e3648dc720a /src/win/native/input_method.cpp | |
parent | 857adcb7ee2d45b2e29d4250fa4246bb8861a8f9 (diff) | |
download | cru-2898b68fc4f7ff40844ddf5a1d0b59f76b06290f.tar.gz cru-2898b68fc4f7ff40844ddf5a1d0b59f76b06290f.tar.bz2 cru-2898b68fc4f7ff40844ddf5a1d0b59f76b06290f.zip |
...
Diffstat (limited to 'src/win/native/input_method.cpp')
-rw-r--r-- | src/win/native/input_method.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
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<std::nullptr_t>* WinInputMethodContext::CompositionEvent() { return &composition_event_; } +IEvent<std::string_view>* 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<wchar_t>(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; } |