summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/newt/native/NewtMacWindow.h7
-rw-r--r--src/newt/native/NewtMacWindow.m52
2 files changed, 15 insertions, 44 deletions
diff --git a/src/newt/native/NewtMacWindow.h b/src/newt/native/NewtMacWindow.h
index e649fdb13..88fb67a68 100644
--- a/src/newt/native/NewtMacWindow.h
+++ b/src/newt/native/NewtMacWindow.h
@@ -36,7 +36,7 @@
#include "NewtCommon.h"
-// #define VERBOSE_ON 1
+#define VERBOSE_ON 1
#ifdef VERBOSE_ON
#define DBG_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr)
@@ -128,10 +128,9 @@
- (BOOL) becomeFirstResponder;
- (BOOL) resignFirstResponder;
- (void) becomeKeyWindow;
-- (void) windowDidBecomeKey: (NSNotification *) notification;
-- (void) sendFocusGained;
- (void) resignKeyWindow;
+- (void) windowDidBecomeKey: (NSNotification *) notification;
- (void) windowDidResignKey: (NSNotification *) notification;
-- (void) sendFocusLost;
+- (void) focusChanged: (BOOL) gained;
@end
diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m
index dc11fd61b..0b6386b2d 100644
--- a/src/newt/native/NewtMacWindow.m
+++ b/src/newt/native/NewtMacWindow.m
@@ -826,55 +826,27 @@ static jint mods2JavaMods(NSUInteger mods)
[super becomeKeyWindow];
}
-- (void) windowDidBecomeKey: (NSNotification *) notification
+- (void) resignKeyWindow
{
- DBG_PRINT( "*************** windowDidBecomeKey\n");
- [self sendFocusGained];
+ DBG_PRINT( "*************** resignKeyWindow\n");
+ [super resignKeyWindow];
}
-- (void) sendFocusGained
-{
- DBG_PRINT( "sendFocusGained\n");
- NSView* nsview = [self contentView];
- if( ! [nsview isMemberOfClass:[NewtView class]] ) {
- return;
- }
- NewtView* view = (NewtView *) nsview;
- jobject javaWindowObject = [view getJavaWindowObject];
- if (javaWindowObject == NULL) {
- NSLog(@"windowDidBecomeKey: null javaWindowObject");
- return;
- }
- int shallBeDetached = 0;
- JavaVM *jvmHandle = [view getJVMHandle];
- JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], &shallBeDetached);
- if(NULL==env) {
- NSLog(@"windowDidBecomeKey: null JNIEnv");
- return;
- }
-
- (*env)->CallVoidMethod(env, javaWindowObject, focusChangedID, JNI_FALSE, JNI_TRUE);
-
- if (shallBeDetached) {
- (*jvmHandle)->DetachCurrentThread(jvmHandle);
- }
-}
-
-- (void) resignKeyWindow
+- (void) windowDidBecomeKey: (NSNotification *) notification
{
- DBG_PRINT( "*************** becomeKeyWindow\n");
- [super becomeKeyWindow];
+ DBG_PRINT( "*************** windowDidBecomeKey\n");
+ [self focusChanged: YES];
}
- (void) windowDidResignKey: (NSNotification *) notification
{
DBG_PRINT( "*************** windowDidResignKey\n");
- [self sendFocusLost];
+ [self focusChanged: NO];
}
-- (void) sendFocusLost
+- (void) focusChanged: (BOOL) gained
{
- DBG_PRINT( "sendFocusLost\n");
+ DBG_PRINT( "focusChanged: gained %d\n", gained);
NSView* nsview = [self contentView];
if( ! [nsview isMemberOfClass:[NewtView class]] ) {
return;
@@ -882,18 +854,18 @@ static jint mods2JavaMods(NSUInteger mods)
NewtView* view = (NewtView *) nsview;
jobject javaWindowObject = [view getJavaWindowObject];
if (javaWindowObject == NULL) {
- NSLog(@"windowDidResignKey: null javaWindowObject");
+ NSLog(@"focusChanged: null javaWindowObject");
return;
}
int shallBeDetached = 0;
JavaVM *jvmHandle = [view getJVMHandle];
JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], &shallBeDetached);
if(NULL==env) {
- NSLog(@"windowDidResignKey: null JNIEnv");
+ NSLog(@"focusChanged: null JNIEnv");
return;
}
- (*env)->CallVoidMethod(env, javaWindowObject, focusChangedID, JNI_FALSE, JNI_FALSE);
+ (*env)->CallVoidMethod(env, javaWindowObject, focusChangedID, JNI_FALSE, (gained == YES) ? JNI_TRUE : JNI_FALSE);
if (shallBeDetached) {
(*jvmHandle)->DetachCurrentThread(jvmHandle);