From d86a71f79afe0e4dac768f61d6bff690567aca5b Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 24 May 2020 01:40:02 +0800 Subject: ... --- include/cru/platform/native/InputMethod.hpp | 77 ++++++++++++++++++++++++++ include/cru/platform/native/UiApplication.hpp | 58 +++++++++++++++++++ include/cru/platform/native/base.hpp | 8 +-- include/cru/platform/native/cursor.hpp | 4 +- include/cru/platform/native/input_method.hpp | 77 -------------------------- include/cru/platform/native/keyboard.hpp | 2 +- include/cru/platform/native/ui_application.hpp | 58 ------------------- include/cru/platform/native/window.hpp | 6 +- 8 files changed, 145 insertions(+), 145 deletions(-) create mode 100644 include/cru/platform/native/InputMethod.hpp create mode 100644 include/cru/platform/native/UiApplication.hpp delete mode 100644 include/cru/platform/native/input_method.hpp delete mode 100644 include/cru/platform/native/ui_application.hpp (limited to 'include/cru/platform/native') diff --git a/include/cru/platform/native/InputMethod.hpp b/include/cru/platform/native/InputMethod.hpp new file mode 100644 index 00000000..1ede15b2 --- /dev/null +++ b/include/cru/platform/native/InputMethod.hpp @@ -0,0 +1,77 @@ +#pragma once +#include "../Resource.hpp" +#include "Base.hpp" + +#include "cru/common/Event.hpp" + +#include +#include +#include + +namespace cru::platform::native { +struct CompositionClause { + int start; + int end; + bool target; +}; + +using CompositionClauses = std::vector; + +struct CompositionText { + std::string text; + CompositionClauses clauses; + TextRange selection; +}; + +inline std::ostream& operator<<(std::ostream& stream, + const CompositionText& composition_text) { + stream << "text: " << composition_text.text << "\n" + << "clauses:\n"; + for (int i = 0; i < static_cast(composition_text.clauses.size()); i++) { + const auto& clause = composition_text.clauses[i]; + stream << "\t" << i << ". start:" << clause.start << " end:" << clause.end; + if (clause.target) { + stream << " target"; + } + stream << "\n"; + } + stream << "selection: position:" << composition_text.selection.position + << " count:" << composition_text.selection.count; + return stream; +} + +struct IInputMethodContext : virtual INativeResource { + // Return true if you should draw composition text manually. Return false if + // system will take care of that for you. + virtual bool ShouldManuallyDrawCompositionText() = 0; + + virtual void EnableIME() = 0; + + virtual void DisableIME() = 0; + + virtual void CompleteComposition() = 0; + + virtual void CancelComposition() = 0; + + virtual CompositionText GetCompositionText() = 0; + + // Set the candidate window lefttop. Use this method to prepare typing. + virtual void SetCandidateWindowPosition(const Point& point) = 0; + + // Triggered when user starts composition. + virtual IEvent* CompositionStartEvent() = 0; + + // Triggered when user stops composition. + virtual IEvent* CompositionEndEvent() = 0; + + // Triggered every time composition text changes. + virtual IEvent* CompositionEvent() = 0; + + virtual IEvent* TextEvent() = 0; +}; + +struct IInputMethodManager : virtual INativeResource { + virtual std::unique_ptr GetContext( + INativeWindow* window) = 0; +}; +} // namespace cru::platform::native diff --git a/include/cru/platform/native/UiApplication.hpp b/include/cru/platform/native/UiApplication.hpp new file mode 100644 index 00000000..1aa4df57 --- /dev/null +++ b/include/cru/platform/native/UiApplication.hpp @@ -0,0 +1,58 @@ +#pragma once +#include "../Resource.hpp" +#include "Base.hpp" + +#include +#include +#include +#include + +namespace cru::platform::native { +// The entry point of a ui application. +struct IUiApplication : public virtual INativeResource { + public: + static IUiApplication* GetInstance() { return instance; } + + private: + static IUiApplication* instance; + + protected: + IUiApplication(); + + public: + ~IUiApplication() override; + + // Block current thread and run the message loop. Return the exit code when + // message loop gets a quit message (possibly posted by method RequestQuit). + virtual int Run() = 0; + + // Post a quit message with given quit code. + virtual void RequestQuit(int quit_code) = 0; + + virtual void AddOnQuitHandler(std::function handler) = 0; + + virtual void InvokeLater(std::function action) = 0; + // Timer id should always be positive and never the same. So it's ok to use + // negative value to represent no timer. + virtual long long SetTimeout(std::chrono::milliseconds milliseconds, + std::function action) = 0; + virtual long long SetInterval(std::chrono::milliseconds milliseconds, + std::function action) = 0; + // Implementation should guarantee calls on timer id already canceled have no + // effects and do not crash. Also canceling negative id should always result + // in no-op. + virtual void CancelTimer(long long id) = 0; + + virtual std::vector GetAllWindow() = 0; + virtual std::shared_ptr CreateWindow( + INativeWindow* parent) = 0; + + virtual cru::platform::graph::IGraphFactory* GetGraphFactory() = 0; + + virtual ICursorManager* GetCursorManager() = 0; + virtual IInputMethodManager* GetInputMethodManager() = 0; +}; + +// Bootstrap from this. +std::unique_ptr CreateUiApplication(); +} // namespace cru::platform::native diff --git a/include/cru/platform/native/base.hpp b/include/cru/platform/native/base.hpp index e0ecbda7..bba7b960 100644 --- a/include/cru/platform/native/base.hpp +++ b/include/cru/platform/native/base.hpp @@ -1,8 +1,8 @@ #pragma once -#include "cru/common/base.hpp" -#include "cru/common/bitmask.hpp" -#include "cru/platform/graph/base.hpp" -#include "keyboard.hpp" +#include "cru/common/Base.hpp" +#include "cru/common/Bitmask.hpp" +#include "cru/platform/graph/Base.hpp" +#include "Keyboard.hpp" namespace cru::platform::native { struct ICursor; diff --git a/include/cru/platform/native/cursor.hpp b/include/cru/platform/native/cursor.hpp index eae51ffe..6c8f8068 100644 --- a/include/cru/platform/native/cursor.hpp +++ b/include/cru/platform/native/cursor.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../resource.hpp" -#include "base.hpp" +#include "../Resource.hpp" +#include "Base.hpp" #include diff --git a/include/cru/platform/native/input_method.hpp b/include/cru/platform/native/input_method.hpp deleted file mode 100644 index bcf030b4..00000000 --- a/include/cru/platform/native/input_method.hpp +++ /dev/null @@ -1,77 +0,0 @@ -#pragma once -#include "../resource.hpp" -#include "base.hpp" - -#include "cru/common/event.hpp" - -#include -#include -#include - -namespace cru::platform::native { -struct CompositionClause { - int start; - int end; - bool target; -}; - -using CompositionClauses = std::vector; - -struct CompositionText { - std::string text; - CompositionClauses clauses; - TextRange selection; -}; - -inline std::ostream& operator<<(std::ostream& stream, - const CompositionText& composition_text) { - stream << "text: " << composition_text.text << "\n" - << "clauses:\n"; - for (int i = 0; i < static_cast(composition_text.clauses.size()); i++) { - const auto& clause = composition_text.clauses[i]; - stream << "\t" << i << ". start:" << clause.start << " end:" << clause.end; - if (clause.target) { - stream << " target"; - } - stream << "\n"; - } - stream << "selection: position:" << composition_text.selection.position - << " count:" << composition_text.selection.count; - return stream; -} - -struct IInputMethodContext : virtual INativeResource { - // Return true if you should draw composition text manually. Return false if - // system will take care of that for you. - virtual bool ShouldManuallyDrawCompositionText() = 0; - - virtual void EnableIME() = 0; - - virtual void DisableIME() = 0; - - virtual void CompleteComposition() = 0; - - virtual void CancelComposition() = 0; - - virtual CompositionText GetCompositionText() = 0; - - // Set the candidate window lefttop. Use this method to prepare typing. - virtual void SetCandidateWindowPosition(const Point& point) = 0; - - // Triggered when user starts composition. - virtual IEvent* CompositionStartEvent() = 0; - - // Triggered when user stops composition. - virtual IEvent* CompositionEndEvent() = 0; - - // Triggered every time composition text changes. - virtual IEvent* CompositionEvent() = 0; - - virtual IEvent* TextEvent() = 0; -}; - -struct IInputMethodManager : virtual INativeResource { - virtual std::unique_ptr GetContext( - INativeWindow* window) = 0; -}; -} // namespace cru::platform::native diff --git a/include/cru/platform/native/keyboard.hpp b/include/cru/platform/native/keyboard.hpp index 8b5e6162..26a1409d 100644 --- a/include/cru/platform/native/keyboard.hpp +++ b/include/cru/platform/native/keyboard.hpp @@ -1,5 +1,5 @@ #pragma once -#include "cru/common/bitmask.hpp" +#include "cru/common/Bitmask.hpp" namespace cru::platform::native { // Because of the complexity of keyboard layout, I only add code in US keyboard diff --git a/include/cru/platform/native/ui_application.hpp b/include/cru/platform/native/ui_application.hpp deleted file mode 100644 index afcc7117..00000000 --- a/include/cru/platform/native/ui_application.hpp +++ /dev/null @@ -1,58 +0,0 @@ -#pragma once -#include "../resource.hpp" -#include "base.hpp" - -#include -#include -#include -#include - -namespace cru::platform::native { -// The entry point of a ui application. -struct IUiApplication : public virtual INativeResource { - public: - static IUiApplication* GetInstance() { return instance; } - - private: - static IUiApplication* instance; - - protected: - IUiApplication(); - - public: - ~IUiApplication() override; - - // Block current thread and run the message loop. Return the exit code when - // message loop gets a quit message (possibly posted by method RequestQuit). - virtual int Run() = 0; - - // Post a quit message with given quit code. - virtual void RequestQuit(int quit_code) = 0; - - virtual void AddOnQuitHandler(std::function handler) = 0; - - virtual void InvokeLater(std::function action) = 0; - // Timer id should always be positive and never the same. So it's ok to use - // negative value to represent no timer. - virtual long long SetTimeout(std::chrono::milliseconds milliseconds, - std::function action) = 0; - virtual long long SetInterval(std::chrono::milliseconds milliseconds, - std::function action) = 0; - // Implementation should guarantee calls on timer id already canceled have no - // effects and do not crash. Also canceling negative id should always result - // in no-op. - virtual void CancelTimer(long long id) = 0; - - virtual std::vector GetAllWindow() = 0; - virtual std::shared_ptr CreateWindow( - INativeWindow* parent) = 0; - - virtual cru::platform::graph::IGraphFactory* GetGraphFactory() = 0; - - virtual ICursorManager* GetCursorManager() = 0; - virtual IInputMethodManager* GetInputMethodManager() = 0; -}; - -// Bootstrap from this. -std::unique_ptr CreateUiApplication(); -} // namespace cru::platform::native diff --git a/include/cru/platform/native/window.hpp b/include/cru/platform/native/window.hpp index 57363a3b..1fcac1fc 100644 --- a/include/cru/platform/native/window.hpp +++ b/include/cru/platform/native/window.hpp @@ -1,7 +1,7 @@ #pragma once -#include "../resource.hpp" -#include "base.hpp" -#include "cru/common/event.hpp" +#include "../Resource.hpp" +#include "Base.hpp" +#include "cru/common/Event.hpp" #include -- cgit v1.2.3