From ee61633d81cc9e34c3bd8b5fbfb6a5a25a1f3ea5 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 2 Apr 2020 23:00:34 +0800 Subject: ... --- include/cru/platform/native/base.hpp | 1 + include/cru/platform/native/input_method.hpp | 30 ++++++++++++++++++++ include/cru/win/native/input_method.hpp | 42 ++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 include/cru/platform/native/input_method.hpp create mode 100644 include/cru/win/native/input_method.hpp (limited to 'include') diff --git a/include/cru/platform/native/base.hpp b/include/cru/platform/native/base.hpp index 5ebd98d6..883a9450 100644 --- a/include/cru/platform/native/base.hpp +++ b/include/cru/platform/native/base.hpp @@ -10,6 +10,7 @@ struct ICursorManager; struct IUiApplication; struct INativeWindow; struct INativeWindowResolver; +struct IInputMethodManager; struct Dpi { float x; diff --git a/include/cru/platform/native/input_method.hpp b/include/cru/platform/native/input_method.hpp new file mode 100644 index 00000000..ecc47fd8 --- /dev/null +++ b/include/cru/platform/native/input_method.hpp @@ -0,0 +1,30 @@ +#pragma once +#include "../resource.hpp" +#include "base.hpp" +#include "cru/common/event.hpp" + +#include + +namespace cru::platform::native { +// It is a reference, so there is a ref count, remember to destroy it to release +// the ref after use. +struct IInputMethodContextRef : INativeResource { + // Reset composition string. Use this method to prepare typing. + virtual void Reset() = 0; + // Get the composition string. + virtual std::string GetCompositionString() = 0; + // Set the candidate window lefttop. Use this method to prepare typing. + virtual void SetCandidateWindowPosition(const Point& point); + // Triggered every time composition text changes, evet args is the new + // composition text. + virtual IEvent* CompositionTextChangeEvent() = 0; + // User comfirmed compostition. Use this method to get the final input text. + virtual IEvent* CharEvent() = 0; +}; + +struct IInputMethodManager : INativeResource { + // Get a reference of context of a window. + virtual std::unique_ptr GetContext( + INativeWindow* window) = 0; +}; +} // namespace cru::platform::native diff --git a/include/cru/win/native/input_method.hpp b/include/cru/win/native/input_method.hpp new file mode 100644 index 00000000..3ea16709 --- /dev/null +++ b/include/cru/win/native/input_method.hpp @@ -0,0 +1,42 @@ +#pragma once +#include "resource.hpp" + +#include "cru/platform/native/input_method.hpp" + +#include + +namespace cru::platform::native::win { +class WinNativeWindow; + +class WinInputMethodContextRef : public WinNativeResource, + public IInputMethodContextRef { + public: + WinInputMethodContextRef(WinNativeWindow* window); + + CRU_DELETE_COPY(WinInputMethodContextRef) + CRU_DELETE_MOVE(WinInputMethodContextRef) + + ~WinInputMethodContextRef() override; + + ::HIMC GetHandle() const { return handle_; } + + void Reset() override; + + std::string GetCompositionString() override; + + void SetCandidateWindowPosition(const Point& point) override; + + IEvent* CompositionTextChangeEvent() override; + + IEvent* CharEvent() override; + + private: + WinNativeWindow* window_; + + ::HWND window_handle_; + ::HIMC handle_; + + Event composition_text_change_event_; + Event char_event_; +}; +} // namespace cru::platform::native::win -- cgit v1.2.3