summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2018-11-23 14:07:48 +0200
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2018-11-23 14:07:48 +0200
commit4554c682e6c9749116c79313d6f08cd6e8b7e6e6 (patch)
treeca6f01129c89cd85eb6dd9b065a90a976c30ba44 /platform
parent8ba0d513fa0068a241a25fbb6db09315fa3309cc (diff)
Changes IME input to use notification instead of callback, exposes IME methods to gdscript/gdnative.
Diffstat (limited to 'platform')
-rw-r--r--platform/osx/os_osx.h7
-rw-r--r--platform/osx/os_osx.mm39
2 files changed, 29 insertions, 17 deletions
diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h
index 546c88e74a..ae2eb6288c 100644
--- a/platform/osx/os_osx.h
+++ b/platform/osx/os_osx.h
@@ -124,8 +124,8 @@ public:
Point2 im_position;
bool im_active;
- ImeCallback im_callback;
- void *im_target;
+ String im_text;
+ Point2 im_selection;
power_osx *power_manager;
@@ -245,7 +245,8 @@ public:
virtual void set_ime_active(const bool p_active);
virtual void set_ime_position(const Point2 &p_pos);
- virtual void set_ime_intermediate_text_callback(ImeCallback p_callback, void *p_inp);
+ virtual Point2 get_ime_selection() const;
+ virtual String get_ime_text() const;
virtual String get_unique_id() const;
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index e7b3e35381..f8dec3ec7a 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -427,11 +427,13 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
} else {
[markedText initWithString:aString];
}
- if (OS_OSX::singleton->im_callback) {
+ if (OS_OSX::singleton->im_active) {
imeMode = true;
- String ret;
- ret.parse_utf8([[markedText mutableString] UTF8String]);
- OS_OSX::singleton->im_callback(OS_OSX::singleton->im_target, ret, Point2(selectedRange.location, selectedRange.length));
+ OS_OSX::singleton->im_text.parse_utf8([[markedText mutableString] UTF8String]);
+ OS_OSX::singleton->im_selection = Point2(selectedRange.location, selectedRange.length);
+
+ if (OS_OSX::singleton->get_main_loop())
+ OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_OS_IME_UPDATE);
}
}
@@ -443,8 +445,13 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
- (void)unmarkText {
imeMode = false;
[[markedText mutableString] setString:@""];
- if (OS_OSX::singleton->im_callback)
- OS_OSX::singleton->im_callback(OS_OSX::singleton->im_target, "", Point2());
+ if (OS_OSX::singleton->im_active) {
+ OS_OSX::singleton->im_text = String();
+ OS_OSX::singleton->im_selection = Point2();
+
+ if (OS_OSX::singleton->get_main_loop())
+ OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_OS_IME_UPDATE);
+ }
}
- (NSArray *)validAttributesForMarkedText {
@@ -1136,12 +1143,14 @@ inline void sendPanEvent(double dx, double dy, int modifierFlags) {
@end
-void OS_OSX::set_ime_intermediate_text_callback(ImeCallback p_callback, void *p_inp) {
- im_callback = p_callback;
- im_target = p_inp;
- if (!im_callback) {
- [window_view cancelComposition];
- }
+Point2 OS_OSX::get_ime_selection() const {
+
+ return im_selection;
+}
+
+String OS_OSX::get_ime_text() const {
+
+ return im_text;
}
String OS_OSX::get_unique_id() const {
@@ -1169,10 +1178,14 @@ String OS_OSX::get_unique_id() const {
}
void OS_OSX::set_ime_active(const bool p_active) {
+
im_active = p_active;
+ if (!im_active)
+ [window_view cancelComposition];
}
void OS_OSX::set_ime_position(const Point2 &p_pos) {
+
im_position = p_pos;
}
@@ -2637,8 +2650,6 @@ OS_OSX::OS_OSX() {
singleton = this;
im_active = false;
im_position = Point2();
- im_callback = NULL;
- im_target = NULL;
layered_window = false;
autoreleasePool = [[NSAutoreleasePool alloc] init];