aboutsummaryrefslogtreecommitdiff
path: root/src/win/native/input_method.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-04-05 00:04:05 +0800
committercrupest <crupest@outlook.com>2020-04-05 00:04:05 +0800
commit37bb421e963662e8203acbe3a03bdbd5d1f5858e (patch)
tree400af7a9d378be209158eda8ca8adeced60b0cc8 /src/win/native/input_method.cpp
parentee61633d81cc9e34c3bd8b5fbfb6a5a25a1f3ea5 (diff)
downloadcru-37bb421e963662e8203acbe3a03bdbd5d1f5858e.tar.gz
cru-37bb421e963662e8203acbe3a03bdbd5d1f5858e.tar.bz2
cru-37bb421e963662e8203acbe3a03bdbd5d1f5858e.zip
...
Diffstat (limited to 'src/win/native/input_method.cpp')
-rw-r--r--src/win/native/input_method.cpp43
1 files changed, 40 insertions, 3 deletions
diff --git a/src/win/native/input_method.cpp b/src/win/native/input_method.cpp
index 4edfdc5f..837d0ed7 100644
--- a/src/win/native/input_method.cpp
+++ b/src/win/native/input_method.cpp
@@ -17,6 +17,11 @@ WinInputMethodContextRef::WinInputMethodContextRef(WinNativeWindow* window)
handle_ = ::ImmGetContext(window_handle_);
// TODO: Events
+
+ event_revoker_guards_.push_back(
+ EventRevokerGuard(window->NativeMessageEvent()->AddHandler(
+ std::bind(&WinInputMethodContextRef::OnWindowNativeMessage, this,
+ std::placeholders::_1))));
}
WinInputMethodContextRef::~WinInputMethodContextRef() {
@@ -34,7 +39,7 @@ void WinInputMethodContextRef::Reset() {
}
}
-std::string WinInputMethodContextRef::GetCompositionString() {
+std::string WinInputMethodContextRef::GetCompositionText() {
const auto length =
::ImmGetCompositionStringW(handle_, GCS_RESULTREADSTR, NULL, 0) +
sizeof(wchar_t);
@@ -65,11 +70,43 @@ void WinInputMethodContextRef::SetCandidateWindowPosition(const Point& point) {
"position.");
}
+IEvent<std::nullptr_t>* WinInputMethodContextRef::CompositionStartEvent() {
+ return &composition_start_event_;
+}
+
+IEvent<std::nullptr_t>* WinInputMethodContextRef::CompositionEndEvent() {
+ return &composition_end_event_;
+};
+
IEvent<std::string>* WinInputMethodContextRef::CompositionTextChangeEvent() {
return &composition_text_change_event_;
}
-IEvent<std::string>* WinInputMethodContextRef::CharEvent() {
- return &char_event_;
+void WinInputMethodContextRef::OnWindowNativeMessage(
+ WindowNativeMessageEventArgs& args) {
+ const auto message = args.GetWindowMessage();
+ switch (message.msg) {
+ case WM_IME_COMPOSITION: {
+ composition_text_change_event_.Raise(this->GetCompositionText());
+ args.HandleWithResult(0);
+ break;
+ }
+ case WM_IME_STARTCOMPOSITION: {
+ composition_start_event_.Raise(nullptr);
+ args.HandleWithResult(0);
+ break;
+ }
+ case WM_IME_ENDCOMPOSITION: {
+ composition_end_event_.Raise(nullptr);
+ args.HandleWithResult(0);
+ break;
+ }
+ case WM_IME_SETCONTEXT: {
+ const auto new_l_param =
+ message.l_param & (~static_cast<LPARAM>(ISC_SHOWUICOMPOSITIONWINDOW));
+ args.HandleWithResult(::DefWindowProcW(message.hwnd, message.msg,
+ message.w_param, new_l_param));
+ }
+ }
}
} // namespace cru::platform::native::win