From d86a71f79afe0e4dac768f61d6bff690567aca5b Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 24 May 2020 01:40:02 +0800 Subject: ... --- include/cru/win/native/InputMethod.hpp | 98 ++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 include/cru/win/native/InputMethod.hpp (limited to 'include/cru/win/native/InputMethod.hpp') diff --git a/include/cru/win/native/InputMethod.hpp b/include/cru/win/native/InputMethod.hpp new file mode 100644 index 00000000..0e9634aa --- /dev/null +++ b/include/cru/win/native/InputMethod.hpp @@ -0,0 +1,98 @@ +// Some useful information can be found from chromium code: +// https://chromium.googlesource.com/chromium/chromium/+/refs/heads/master/ui/base/win/ime_input.h +// https://chromium.googlesource.com/chromium/chromium/+/refs/heads/master/ui/base/win/ime_input.cc + +#pragma once +#include "Resource.hpp" + +#include "cru/platform/native/InputMethod.hpp" +#include "WindowNativeMessageEventArgs.hpp" + +#include + +namespace cru::platform::native::win { +class AutoHIMC : public Object { + public: + explicit AutoHIMC(HWND hwnd); + + CRU_DELETE_COPY(AutoHIMC) + + AutoHIMC(AutoHIMC&& other); + AutoHIMC& operator=(AutoHIMC&& other); + + ~AutoHIMC() override; + + HWND GetHwnd() const { return hwnd_; } + + HIMC Get() const { return handle_; } + + private: + HWND hwnd_; + HIMC handle_; +}; + +class WinInputMethodContext : public WinNativeResource, + public virtual IInputMethodContext { + public: + WinInputMethodContext(gsl::not_null window); + + CRU_DELETE_COPY(WinInputMethodContext) + CRU_DELETE_MOVE(WinInputMethodContext) + + ~WinInputMethodContext() override; + + bool ShouldManuallyDrawCompositionText() override { return true; } + + void EnableIME() override; + + void DisableIME() override; + + void CompleteComposition() override; + + void CancelComposition() override; + + CompositionText GetCompositionText() override; + + void SetCandidateWindowPosition(const Point& point) override; + + IEvent* CompositionStartEvent() override; + + IEvent* CompositionEndEvent() override; + + IEvent* CompositionEvent() override; + + IEvent* TextEvent() override; + + private: + void OnWindowNativeMessage(WindowNativeMessageEventArgs& args); + + std::string GetResultString(); + + std::optional TryGetHIMC(); + + private: + std::shared_ptr native_window_resolver_; + + std::vector event_revoker_guards_; + + Event composition_start_event_; + Event composition_end_event_; + Event composition_event_; + Event text_event_; +}; + +class WinInputMethodManager : public WinNativeResource, + public virtual IInputMethodManager { + public: + WinInputMethodManager(WinUiApplication* application); + + CRU_DELETE_COPY(WinInputMethodManager) + CRU_DELETE_MOVE(WinInputMethodManager) + + ~WinInputMethodManager() override; + + public: + std::unique_ptr GetContext( + INativeWindow* window) override; +}; +} // namespace cru::platform::native::win -- cgit v1.2.3