aboutsummaryrefslogtreecommitdiff
path: root/src/osx
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-10-21 18:42:58 +0800
committercrupest <crupest@outlook.com>2021-10-21 18:42:58 +0800
commit411027e66401d363abb6217b59b2b695b856c917 (patch)
tree9bf75a1a5ad4da9428909e3582f9b9a9a8db03aa /src/osx
parent72fc892792565ef39fcae6b7d2a19006dc3a3238 (diff)
downloadcru-411027e66401d363abb6217b59b2b695b856c917.tar.gz
cru-411027e66401d363abb6217b59b2b695b856c917.tar.bz2
cru-411027e66401d363abb6217b59b2b695b856c917.zip
...
Diffstat (limited to 'src/osx')
-rw-r--r--src/osx/gui/InputMethod.mm17
-rw-r--r--src/osx/gui/InputMethodPrivate.h3
-rw-r--r--src/osx/gui/Window.mm85
-rw-r--r--src/osx/gui/WindowPrivate.h11
4 files changed, 82 insertions, 34 deletions
diff --git a/src/osx/gui/InputMethod.mm b/src/osx/gui/InputMethod.mm
index e6105354..2331d8b7 100644
--- a/src/osx/gui/InputMethod.mm
+++ b/src/osx/gui/InputMethod.mm
@@ -32,6 +32,19 @@ void OsxInputMethodContextPrivate::PerformSel(SEL sel) {
[window_->p_->GetNSWindow() performSelector:sel];
}
+void OsxInputMethodContextPrivate::Activate() {
+ if (!window_->p_->GetNSWindow()) return;
+ auto input_context = [[window_->p_->GetNSWindow() contentView] inputContext];
+ Ensures(input_context);
+ [input_context activate];
+}
+
+void OsxInputMethodContextPrivate::Deactivate() {
+ if (!window_->p_->GetNSWindow()) return;
+ auto input_context = [[window_->p_->GetNSWindow() contentView] inputContext];
+ Ensures(input_context);
+ [input_context deactivate];
+}
}
OsxInputMethodContext::OsxInputMethodContext(OsxWindow* window)
@@ -41,9 +54,9 @@ OsxInputMethodContext::OsxInputMethodContext(OsxWindow* window)
OsxInputMethodContext::~OsxInputMethodContext() {}
-void OsxInputMethodContext::EnableIME() { [[NSTextInputContext currentInputContext] activate]; }
+void OsxInputMethodContext::EnableIME() { p_->Activate(); }
-void OsxInputMethodContext::DisableIME() { [[NSTextInputContext currentInputContext] deactivate]; }
+void OsxInputMethodContext::DisableIME() { p_->Deactivate(); }
bool OsxInputMethodContext::ShouldManuallyDrawCompositionText() { return true; }
diff --git a/src/osx/gui/InputMethodPrivate.h b/src/osx/gui/InputMethodPrivate.h
index a4b61432..4b5478e1 100644
--- a/src/osx/gui/InputMethodPrivate.h
+++ b/src/osx/gui/InputMethodPrivate.h
@@ -37,6 +37,9 @@ class OsxInputMethodContextPrivate {
void PerformSel(SEL sel);
+ void Activate();
+ void Deactivate();
+
private:
OsxWindow* window_;
diff --git a/src/osx/gui/Window.mm b/src/osx/gui/Window.mm
index cd1a70e6..da098d9b 100644
--- a/src/osx/gui/Window.mm
+++ b/src/osx/gui/Window.mm
@@ -269,22 +269,62 @@ IInputMethodContext* OsxWindow::GetInputMethodContext() { return p_->input_metho
backing:NSBackingStoreBuffered
defer:false];
_p = p;
+
+ [self setAcceptsMouseMovedEvents:YES];
+
+ return self;
+}
+@end
+
+@implementation CruView {
+ cru::platform::gui::osx::details::OsxWindowPrivate* _p;
+}
+
+- (instancetype)init:(cru::platform::gui::osx::details::OsxWindowPrivate*)p
+ frame:(cru::platform::Rect)frame {
+ [super initWithFrame:cru::platform::graphics::osx::quartz::Convert(frame)];
+ _p = p;
+
return self;
}
+- (void)drawRect:(NSRect)dirtyRect {
+ cru::log::TagDebug(u"CruView", u"Begin to draw layer in view.");
+ auto cg_context = [[NSGraphicsContext currentContext] CGContext];
+ auto layer = _p->GetDrawLayer();
+ Ensures(layer);
+ CGContextDrawLayerAtPoint(cg_context, CGPointMake(0, 0), layer);
+}
+
+- (BOOL)acceptsFirstResponder {
+ return YES;
+}
+
+- (BOOL)canBecomeKeyView {
+ return YES;
+}
+
- (void)mouseMoved:(NSEvent*)event {
+ cru::log::TagDebug(u"CruView", u"Recieved mouse move.");
_p->OnMouseMove(cru::platform::Point(event.locationInWindow.x, event.locationInWindow.y));
+ [super mouseMoved:event];
}
- (void)mouseEntered:(NSEvent*)event {
+ cru::log::TagDebug(u"CruView", u"Recieved mouse enter.");
_p->OnMouseEnterLeave(cru::platform::gui::MouseEnterLeaveType::Enter);
+ [super mouseEntered:event];
}
- (void)mouseExited:(NSEvent*)event {
+ cru::log::TagDebug(u"CruView", u"Recieved mouse exit.");
_p->OnMouseEnterLeave(cru::platform::gui::MouseEnterLeaveType::Leave);
+ [super mouseExited:event];
}
- (void)mouseDown:(NSEvent*)event {
+ cru::log::TagDebug(u"CruView", u"Recieved mouse down.");
+
cru::platform::gui::KeyModifier key_modifier;
if (event.modifierFlags & NSEventModifierFlagControl)
key_modifier |= cru::platform::gui::KeyModifiers::ctrl;
@@ -295,9 +335,12 @@ IInputMethodContext* OsxWindow::GetInputMethodContext() { return p_->input_metho
cru::platform::Point p(event.locationInWindow.x, event.locationInWindow.y);
_p->OnMouseDown(cru::platform::gui::mouse_buttons::left, p, key_modifier);
+ [super mouseDown:event];
}
- (void)mouseUp:(NSEvent*)event {
+ cru::log::TagDebug(u"CruView", u"Recieved mouse up.");
+
cru::platform::gui::KeyModifier key_modifier;
if (event.modifierFlags & NSEventModifierFlagControl)
key_modifier |= cru::platform::gui::KeyModifiers::ctrl;
@@ -308,9 +351,13 @@ IInputMethodContext* OsxWindow::GetInputMethodContext() { return p_->input_metho
cru::platform::Point p(event.locationInWindow.x, event.locationInWindow.y);
_p->OnMouseUp(cru::platform::gui::mouse_buttons::left, p, key_modifier);
+
+ [super mouseUp:event];
}
- (void)rightMouseDown:(NSEvent*)event {
+ cru::log::TagDebug(u"CruView", u"Recieved right mouse down.");
+
cru::platform::gui::KeyModifier key_modifier;
if (event.modifierFlags & NSEventModifierFlagControl)
key_modifier |= cru::platform::gui::KeyModifiers::ctrl;
@@ -321,9 +368,13 @@ IInputMethodContext* OsxWindow::GetInputMethodContext() { return p_->input_metho
cru::platform::Point p(event.locationInWindow.x, event.locationInWindow.y);
_p->OnMouseDown(cru::platform::gui::mouse_buttons::right, p, key_modifier);
+
+ [super rightMouseDown:event];
}
- (void)rightMouseUp:(NSEvent*)event {
+ cru::log::TagDebug(u"CruView", u"Recieved right mouse up.");
+
cru::platform::gui::KeyModifier key_modifier;
if (event.modifierFlags & NSEventModifierFlagControl)
key_modifier |= cru::platform::gui::KeyModifiers::ctrl;
@@ -334,9 +385,13 @@ IInputMethodContext* OsxWindow::GetInputMethodContext() { return p_->input_metho
cru::platform::Point p(event.locationInWindow.x, event.locationInWindow.y);
_p->OnMouseUp(cru::platform::gui::mouse_buttons::right, p, key_modifier);
+
+ [super rightMouseUp:event];
}
- (void)scrollWheel:(NSEvent*)event {
+ cru::log::TagDebug(u"CruView", u"Recieved mouse wheel.");
+
cru::platform::gui::KeyModifier key_modifier;
if (event.modifierFlags & NSEventModifierFlagControl)
key_modifier |= cru::platform::gui::KeyModifiers::ctrl;
@@ -347,9 +402,13 @@ IInputMethodContext* OsxWindow::GetInputMethodContext() { return p_->input_metho
cru::platform::Point p(event.locationInWindow.x, event.locationInWindow.y);
_p->OnMouseWheel(static_cast<float>(event.scrollingDeltaY), p, key_modifier);
+
+ [super scrollWheel:event];
}
- (void)keyDown:(NSEvent*)event {
+ cru::log::TagDebug(u"CruView", u"Recieved key down.");
+
cru::platform::gui::KeyModifier key_modifier;
if (event.modifierFlags & NSEventModifierFlagControl)
key_modifier |= cru::platform::gui::KeyModifiers::ctrl;
@@ -360,9 +419,13 @@ IInputMethodContext* OsxWindow::GetInputMethodContext() { return p_->input_metho
auto c = cru::platform::gui::osx::KeyCodeFromOsxToCru(event.keyCode);
_p->OnKeyDown(c, key_modifier);
+
+ [super keyDown:event];
}
- (void)keyUp:(NSEvent*)event {
+ cru::log::TagDebug(u"CruView", u"Recieved key up.");
+
cru::platform::gui::KeyModifier key_modifier;
if (event.modifierFlags & NSEventModifierFlagControl)
key_modifier |= cru::platform::gui::KeyModifiers::ctrl;
@@ -373,29 +436,9 @@ IInputMethodContext* OsxWindow::GetInputMethodContext() { return p_->input_metho
auto c = cru::platform::gui::osx::KeyCodeFromOsxToCru(event.keyCode);
_p->OnKeyUp(c, key_modifier);
-}
-@end
-
-@implementation CruView {
- cru::platform::gui::osx::details::OsxWindowPrivate* _p;
-}
-- (instancetype)init:(cru::platform::gui::osx::details::OsxWindowPrivate*)p
- frame:(cru::platform::Rect)frame {
- [super initWithFrame:cru::platform::graphics::osx::quartz::Convert(frame)];
- _p = p;
-
- return self;
+ [super keyUp:event];
}
-
-- (void)drawRect:(NSRect)dirtyRect {
- cru::log::TagDebug(u"CruView", u"Begin to draw layer in view.");
- auto cg_context = [[NSGraphicsContext currentContext] CGContext];
- auto layer = _p->GetDrawLayer();
- Ensures(layer);
- CGContextDrawLayerAtPoint(cg_context, CGPointMake(0, 0), layer);
-}
-
@end
@implementation CruWindowDelegate {
diff --git a/src/osx/gui/WindowPrivate.h b/src/osx/gui/WindowPrivate.h
index 279859ef..7b788ba6 100644
--- a/src/osx/gui/WindowPrivate.h
+++ b/src/osx/gui/WindowPrivate.h
@@ -15,17 +15,6 @@
- (instancetype)init:(cru::platform::gui::osx::details::OsxWindowPrivate*)p
contentRect:(NSRect)contentRect
style:(NSWindowStyleMask)style;
-
-- (void)mouseMoved:(NSEvent*)event;
-- (void)mouseEntered:(NSEvent*)event;
-- (void)mouseExited:(NSEvent*)event;
-- (void)mouseDown:(NSEvent*)event;
-- (void)mouseUp:(NSEvent*)event;
-- (void)rightMouseDown:(NSEvent*)event;
-- (void)rightMouseUp:(NSEvent*)event;
-- (void)scrollWheel:(NSEvent*)event;
-- (void)keyDown:(NSEvent*)event;
-- (void)keyUp:(NSEvent*)event;
@end
@interface CruView : NSView