aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/win/native/input_method.cpp27
-rw-r--r--src/win/native/window.cpp21
2 files changed, 23 insertions, 25 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;
}
diff --git a/src/win/native/window.cpp b/src/win/native/window.cpp
index 30c77659..bda8e764 100644
--- a/src/win/native/window.cpp
+++ b/src/win/native/window.cpp
@@ -304,10 +304,6 @@ bool WinNativeWindow::HandleNativeWindowMessage(HWND hwnd, UINT msg,
return true;
}
return false;
- case WM_CHAR:
- OnCharInternal(static_cast<wchar_t>(w_param));
- *result = 0;
- return true;
case WM_SIZE:
OnResizeInternal(LOWORD(l_param), HIWORD(l_param));
*result = 0;
@@ -428,23 +424,6 @@ void WinNativeWindow::OnKeyUpInternal(int virtual_code) {
{VirtualKeyToKeyCode(virtual_code), RetrieveKeyMofifier()});
}
-void WinNativeWindow::OnCharInternal(wchar_t c) {
- if (platform::win::IsSurrogatePairLeading(c)) {
- last_wm_char_event_wparam_ = c;
- return;
- } else if (platform::win::IsSurrogatePairTrailing(c)) {
- 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[1] = {c};
- auto str = platform::win::ToUtf8String({s, 1});
- char_event_.Raise(str);
- log::Debug("WinNativeWindow: char event, charactor is {}", str);
- }
-}
-
void WinNativeWindow::OnActivatedInternal() {}
void WinNativeWindow::OnDeactivatedInternal() {}