summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2013-08-05 20:37:37 +0000
committermichi_cc <michi_cc@openttd.org>2013-08-05 20:37:37 +0000
commit643a294e68e1281e85c783ce53d0051ee2f31ea9 (patch)
treeb154ba65b5d7ad36ccbbc175503c76222b6e5d4e
parente4d48f3a3b67026825f54e2c8df18550f7220acf (diff)
downloadopenttd-643a294e68e1281e85c783ce53d0051ee2f31ea9.tar.xz
(svn r25687) -Codechange: [OSX] Pass text input directly down to the text handling.
-rw-r--r--src/video/cocoa/cocoa_v.mm17
-rw-r--r--src/video/cocoa/event.mm21
2 files changed, 28 insertions, 10 deletions
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm
index 11ba8ab84..99f2c3fed 100644
--- a/src/video/cocoa/cocoa_v.mm
+++ b/src/video/cocoa/cocoa_v.mm
@@ -788,6 +788,23 @@ void cocoaReleaseAutoreleasePool()
if (_cocoa_subdriver != NULL) UndrawMouseCursor();
_cursor.in_window = false;
}
+
+
+/** Insert the given text at the caret. */
+- (void)insertText:(id)aString
+{
+ NSString *s = [ aString isKindOfClass:[ NSAttributedString class ] ] ? [ aString string ] : (NSString *)aString;
+
+ HandleTextInput(NULL, true);
+ HandleTextInput([ s UTF8String ]);
+}
+
+/** Invoke the selector if we implement it. */
+- (void)doCommandBySelector:(SEL)aSelector
+{
+ if ([ self respondsToSelector:aSelector ]) [ self performSelector:aSelector ];
+}
+
@end
diff --git a/src/video/cocoa/event.mm b/src/video/cocoa/event.mm
index 40bf57eb6..81b9db1d2 100644
--- a/src/video/cocoa/event.mm
+++ b/src/video/cocoa/event.mm
@@ -35,6 +35,7 @@
#include "../../network/network.h"
#include "../../core/random_func.hpp"
#include "../../texteff.hpp"
+#include "../../window_func.h"
#import <sys/time.h> /* gettimeofday */
@@ -399,7 +400,6 @@ static bool QZ_PollEvent()
NSString *chars;
NSPoint pt;
- NSText *fieldEditor;
switch ([ event type ]) {
case NSMouseMoved:
case NSOtherMouseDragged:
@@ -516,17 +516,18 @@ static bool QZ_PollEvent()
break;
}
- fieldEditor = [[ event window ] fieldEditor:YES forObject:nil ];
- [ fieldEditor setString:@"" ];
- [ fieldEditor interpretKeyEvents: [ NSArray arrayWithObject:event ] ];
-
- chars = [ event characters ];
- if ([ chars length ] == 0) {
+ if (EditBoxInGlobalFocus()) {
+ [ _cocoa_subdriver->cocoaview interpretKeyEvents:[ NSArray arrayWithObject:event ] ];
QZ_KeyEvent([ event keyCode ], 0, YES);
} else {
- QZ_KeyEvent([ event keyCode ], [ chars characterAtIndex:0 ], YES);
- for (uint i = 1; i < [ chars length ]; i++) {
- QZ_KeyEvent(0, [ chars characterAtIndex:i ], YES);
+ chars = [ event characters ];
+ if ([ chars length ] == 0) {
+ QZ_KeyEvent([ event keyCode ], 0, YES);
+ } else {
+ QZ_KeyEvent([ event keyCode ], [ chars characterAtIndex:0 ], YES);
+ for (uint i = 1; i < [ chars length ]; i++) {
+ QZ_KeyEvent(0, [ chars characterAtIndex:i ], YES);
+ }
}
}
break;