diff options
Diffstat (limited to 'src/newt')
-rwxr-xr-x | src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java | 17 | ||||
-rw-r--r-- | src/newt/native/MacWindow.m | 14 | ||||
-rw-r--r-- | src/newt/native/NewtMacWindow.m | 30 |
3 files changed, 60 insertions, 1 deletions
diff --git a/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java b/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java index 598313fcd..39f7a5bba 100755 --- a/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java +++ b/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java @@ -182,6 +182,7 @@ public class MacWindow extends Window { if (created) { sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); } } else { if (nativeWindow != 0) { @@ -198,6 +199,13 @@ public class MacWindow extends Window { setTitle0(nativeWindow, title); } } + + public void requestFocus() { + super.requestFocus(); + if (nativeWindow != 0) { + makeKey(nativeWindow); + } + } public void setSize(int width, int height) { this.width = width; @@ -248,6 +256,14 @@ public class MacWindow extends Window { } } + private void focusChanged(boolean focusGained) { + if (focusGained) { + sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); + } else { + sendWindowEvent(WindowEvent.EVENT_WINDOW_LOST_FOCUS); + } + } + private char convertKeyChar(char keyChar) { if (keyChar == '\r') { // Turn these into \n @@ -343,6 +359,7 @@ public class MacWindow extends Window { int backingStoreType, boolean deferCreation); private native void makeKeyAndOrderFront(long window); + private native void makeKey(long window); private native void orderOut(long window); private native void close0(long window); private native void setTitle0(long window, String title); diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m index 701187b2a..20190ae58 100644 --- a/src/newt/native/MacWindow.m +++ b/src/newt/native/MacWindow.m @@ -173,6 +173,20 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_makeKeyAndOrder /* * Class: com_sun_javafx_newt_macosx_MacWindow + * Method: makeKey + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_makeKey + (JNIEnv *env, jobject unused, jlong window) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSWindow* win = (NSWindow*) ((intptr_t) window); + [win makeKeyWindow]; + [pool release]; +} + +/* + * Class: com_sun_javafx_newt_macosx_MacWindow * Method: orderOut * Signature: (J)V */ diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m index 75d0a8e62..d225381d4 100644 --- a/src/newt/native/NewtMacWindow.m +++ b/src/newt/native/NewtMacWindow.m @@ -40,6 +40,7 @@ static jmethodID sendMouseEventID = NULL; static jmethodID sendKeyEventID = NULL; static jmethodID sizeChangedID = NULL; static jmethodID positionChangedID = NULL; +static jmethodID focusChangedID = NULL; static jmethodID windowDestroyNotifyID = NULL; static jmethodID windowDestroyedID = NULL; @@ -54,9 +55,10 @@ static JNIEnv* env = NULL; sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V"); sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V"); positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V"); + focusChangedID = (*env)->GetMethodID(env, clazz, "focusChanged", "(Z)V"); windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "()V"); windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V"); - if (sendMouseEventID && sendKeyEventID && sizeChangedID && positionChangedID && windowDestroyedID && windowDestroyNotifyID) { + if (sendMouseEventID && sendKeyEventID && sizeChangedID && positionChangedID && focusChangedID && windowDestroyedID && windowDestroyNotifyID) { return YES; } return NO; @@ -315,4 +317,30 @@ static jint mods2JavaMods(NSUInteger mods) // Will be called by Window.java (*env)->CallVoidMethod(env, javaWindowObject, windowDestroyedID); } +- (void) windowDidBecomeKey: (NSNotification *) notification +{ + if (env == NULL) { + return; + } + + if (javaWindowObject == NULL) { + return; + } + + (*env)->CallVoidMethod(env, javaWindowObject, focusChangedID, JNI_TRUE); +} + +- (void) windowDidResignKey: (NSNotification *) notification +{ + if (env == NULL) { + return; + } + + if (javaWindowObject == NULL) { + return; + } + + (*env)->CallVoidMethod(env, javaWindowObject, focusChangedID, JNI_FALSE); +} + @end |