aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/native/NewtMacWindow.m
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-10-16 07:30:09 +0200
committerSven Gothel <[email protected]>2011-10-16 07:30:09 +0200
commitcac4e2e3f2d6c69a207077fd5e0ebec803afb6b0 (patch)
treef9e47f3ba7ac704f8c14bfe83f64122b883af49c /src/newt/native/NewtMacWindow.m
parentaf332515f76a4017e7a52ebec920e794a5398db4 (diff)
NEWT/OSX: Proper impl. of NEWT's focus management (fixes NEWT/AWT focus behavior/tests)
- Old code was just requesting the focus and made the window upfront and notifying a gained focus to WindowImpl. (hack) - Using proper requestFocus impl. issuing focusAction() and utilizing native focus gained/lost messages. This distinguish between 'makeKey' and 'orderFront'. Also requesting and accepting (view) first responder role, which is a precursor to proper gained/lost focus handling on OSX. - NEWTCanvasAWT: Adding 'steal AWT focus': +++ void requestFocus() { super.requestFocus(); // AWT < steal AWT focus > NEWTChild.requestFocus() } +++ Helps make the focus traversal between NEWT/AWT more reliable. Happend on OSX that AWT (NewtCanvasAWT instance) didn't release the focus after NEWT child gained the same. We are not able to use the 'focusAction()' here (disabled in this code path) due to AWT-EDT blocking and recursive focus changes. The latter is also intendend to request the AWT focus first .. - AWT/NEWT focus test 01 passes on OSX
Diffstat (limited to 'src/newt/native/NewtMacWindow.m')
-rw-r--r--src/newt/native/NewtMacWindow.m43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m
index d4e2c2b6d..bb7fddb60 100644
--- a/src/newt/native/NewtMacWindow.m
+++ b/src/newt/native/NewtMacWindow.m
@@ -213,6 +213,11 @@ static jmethodID windowDestroyNotifyID = NULL;
[super viewDidUnhide];
}
+- (BOOL)acceptsFirstResponder
+{
+ return YES;
+}
+
@end
@implementation NewtMacWindow
@@ -742,8 +747,33 @@ static jint mods2JavaMods(NSUInteger mods)
[pool release];
}
+- (BOOL) becomeFirstResponder
+{
+ DBG_PRINT( "*************** becomeFirstResponder\n");
+ return [super becomeFirstResponder];
+}
+
+- (BOOL) resignFirstResponder
+{
+ DBG_PRINT( "*************** resignFirstResponder\n");
+ return [super resignFirstResponder];
+}
+
+- (void) becomeKeyWindow
+{
+ DBG_PRINT( "*************** becomeKeyWindow\n");
+ [super becomeKeyWindow];
+}
+
- (void) windowDidBecomeKey: (NSNotification *) notification
{
+ DBG_PRINT( "*************** windowDidBecomeKey\n");
+ [self sendFocusGained];
+}
+
+- (void) sendFocusGained
+{
+ DBG_PRINT( "sendFocusGained\n");
NSView* nsview = [self contentView];
if( ! [nsview isMemberOfClass:[NewtView class]] ) {
return;
@@ -769,8 +799,21 @@ static jint mods2JavaMods(NSUInteger mods)
}
}
+- (void) resignKeyWindow
+{
+ DBG_PRINT( "*************** becomeKeyWindow\n");
+ [super becomeKeyWindow];
+}
+
- (void) windowDidResignKey: (NSNotification *) notification
{
+ DBG_PRINT( "*************** windowDidResignKey\n");
+ [self sendFocusLost];
+}
+
+- (void) sendFocusLost
+{
+ DBG_PRINT( "sendFocusLost\n");
NSView* nsview = [self contentView];
if( ! [nsview isMemberOfClass:[NewtView class]] ) {
return;