diff options
author | crupest <crupest@outlook.com> | 2022-05-15 14:08:06 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-05-15 14:08:06 +0800 |
commit | 8ad2966933957ac5d6ff8dcd5e732736fd5e4dc6 (patch) | |
tree | 77e41cc14264060517c0f7ed95837012afb8342e /src/platform/gui/osx/InputMethod.mm | |
parent | 9e0c9d3499bc50c3534b4dc500d8b5d0b5f22752 (diff) | |
download | cru-8ad2966933957ac5d6ff8dcd5e732736fd5e4dc6.tar.gz cru-8ad2966933957ac5d6ff8dcd5e732736fd5e4dc6.tar.bz2 cru-8ad2966933957ac5d6ff8dcd5e732736fd5e4dc6.zip |
...
Diffstat (limited to 'src/platform/gui/osx/InputMethod.mm')
-rw-r--r-- | src/platform/gui/osx/InputMethod.mm | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/platform/gui/osx/InputMethod.mm b/src/platform/gui/osx/InputMethod.mm new file mode 100644 index 00000000..50ff80de --- /dev/null +++ b/src/platform/gui/osx/InputMethod.mm @@ -0,0 +1,84 @@ +#include "cru/platform/gui/osx/InputMethod.h" + +#import <AppKit/AppKit.h> +#include "InputMethodPrivate.h" +#include "WindowPrivate.h" +#include "cru/common/log/Logger.h" +#include "cru/platform/osx/Convert.h" +#include "cru/platform/gui/osx/Window.h" + +namespace cru::platform::gui::osx { +namespace details { +OsxInputMethodContextPrivate::OsxInputMethodContextPrivate( + OsxInputMethodContext* input_method_context, OsxWindow* window) { + input_method_context_ = input_method_context; + window_ = window; +} + +OsxInputMethodContextPrivate::~OsxInputMethodContextPrivate() {} + +void OsxInputMethodContextPrivate::RaiseCompositionStartEvent() { + composition_start_event_.Raise(nullptr); +} +void OsxInputMethodContextPrivate::RaiseCompositionEndEvent() { + composition_end_event_.Raise(nullptr); +} +void OsxInputMethodContextPrivate::RaiseCompositionEvent() { composition_event_.Raise(nullptr); } + +void OsxInputMethodContextPrivate::RaiseTextEvent(StringView text) { text_event_.Raise(text); } + +void OsxInputMethodContextPrivate::PerformSel(SEL sel) { + // [window_->p_->GetNSWindow() performSelector:sel]; +} + +void OsxInputMethodContextPrivate::Activate() { is_enabled_ = true; } + +void OsxInputMethodContextPrivate::Deactivate() { + input_method_context_->CompleteComposition(); + is_enabled_ = false; +} +} + +OsxInputMethodContext::OsxInputMethodContext(OsxWindow* window) + : OsxGuiResource(window->GetUiApplication()) { + p_ = std::make_unique<details::OsxInputMethodContextPrivate>(this, window); +} + +OsxInputMethodContext::~OsxInputMethodContext() {} + +void OsxInputMethodContext::EnableIME() { p_->Activate(); } + +void OsxInputMethodContext::DisableIME() { p_->Deactivate(); } + +bool OsxInputMethodContext::ShouldManuallyDrawCompositionText() { return true; } + +void OsxInputMethodContext::CompleteComposition() { + // TODO: Implement this. +} + +void OsxInputMethodContext::CancelComposition() { + [[NSTextInputContext currentInputContext] discardMarkedText]; +} + +CompositionText OsxInputMethodContext::GetCompositionText() { return p_->composition_text_; } + +void OsxInputMethodContext::SetCandidateWindowPosition(const Point& point) { + p_->SetCandidateWindowPosition(point); +} + +IEvent<std::nullptr_t>* OsxInputMethodContext::CompositionStartEvent() { + return &p_->composition_start_event_; +} + +IEvent<std::nullptr_t>* OsxInputMethodContext::CompositionEndEvent() { + return &p_->composition_end_event_; +} + +IEvent<std::nullptr_t>* OsxInputMethodContext::CompositionEvent() { + return &p_->composition_event_; +} + +IEvent<StringView>* OsxInputMethodContext::TextEvent() { return &p_->text_event_; } + +bool OsxInputMethodContext::IsEnabled() { return p_->is_enabled_; } +} |