From 4e0eb391d6c64f956ea5c87c0385ab48a24b2175 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 1 May 2012 09:21:14 +0200 Subject: Fix Bug 560 and NEWT window closing behavior in general for all platforms. - NEWT/WindowImpl: - 'void windowDestroyNotify()' -> 'boolean windowDestroyNotify(boolean force)', allowing to signal a forced close, as well as replying whether the window has been closed. (called by native code) - destroy(): set states before releasing the window lock - NEWT/X11: Pass windowDeleteAtom for reconfigure window, in case of reparenting child to top-level - NEWT/OSX: - Add 'BOOL windowShouldClose()' impl., ie. having a chance to reject the close attempt - Common impl. for 'windowShouldClose' and 'windowWillClose' -> 'windowClosingImpl' utilizing new 'windowDestroyNotify' code (see above). Fixes bug 560. - NEWT/JOGLNewtApplet1Run: Refine out-of browser window behavior for window-close button - default: move NEWT window back to browser parent - closeable: close NEWT window - jogl-test-applets: Add NApplet-Closeable test (Applet out-of browser window is closable) --- src/newt/native/NewtMacWindow.m | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'src/newt/native/NewtMacWindow.m') diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m index 187aec7fb..f914467af 100644 --- a/src/newt/native/NewtMacWindow.m +++ b/src/newt/native/NewtMacWindow.m @@ -337,7 +337,7 @@ static jmethodID windowRepaintID = NULL; insetsChangedID = (*env)->GetMethodID(env, clazz, "insetsChanged", "(ZIIII)V"); positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(ZII)V"); focusChangedID = (*env)->GetMethodID(env, clazz, "focusChanged", "(ZZ)V"); - windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "()V"); + windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "(Z)Z"); windowRepaintID = (*env)->GetMethodID(env, clazz, "windowRepaint", "(ZIIII)V"); requestFocusID = (*env)->GetMethodID(env, clazz, "requestFocus", "(Z)V"); if (enqueueMouseEventID && sendMouseEventID && enqueueKeyEventID && sendKeyEventID && sizeChangedID && visibleChangedID && insetsChangedID && @@ -372,6 +372,7 @@ static jmethodID windowRepaintID = NULL; mouseVisible = YES; mouseInside = NO; cursorIsHidden = NO; + realized = YES; return res; } @@ -393,6 +394,16 @@ static jmethodID windowRepaintID = NULL; [super dealloc]; } +- (void) setUnrealized +{ + realized = NO; +} + +- (BOOL) isRealized +{ + return realized; +} + - (void) updateInsets: (JNIEnv*) env { NSView* nsview = [self contentView]; @@ -942,8 +953,19 @@ static jint mods2JavaMods(NSUInteger mods) } } +- (BOOL)windowShouldClose: (id) sender +{ + return [self windowClosingImpl: NO]; +} + - (void)windowWillClose: (NSNotification*) notification { + [self windowClosingImpl: YES]; +} + +- (BOOL) windowClosingImpl: (BOOL) force +{ + jboolean closed = JNI_FALSE; NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; [self cursorHide: NO]; @@ -969,17 +991,22 @@ static jint mods2JavaMods(NSUInteger mods) return; } - [view setDestroyNotifySent: true]; - (*env)->CallVoidMethod(env, javaWindowObject, windowDestroyNotifyID); + [view setDestroyNotifySent: true]; // earmark assumption of being closed + closed = (*env)->CallBooleanMethod(env, javaWindowObject, windowDestroyNotifyID, force ? JNI_TRUE : JNI_FALSE); + if(!force && !closed) { + // not closed on java side, not force -> clear flag + [view setDestroyNotifySent: false]; + } if (shallBeDetached) { (*jvmHandle)->DetachCurrentThread(jvmHandle); } - DBG_PRINT( "*************** windowWillClose.X: %p\n", (void *)(intptr_t)javaWindowObject); + DBG_PRINT( "*************** windowWillClose.X: %p, closed %d\n", (void *)(intptr_t)javaWindowObject, (int)closed); } else { DBG_PRINT( "*************** windowWillClose (skip)\n"); } [pool release]; + return JNI_TRUE == closed ? YES : NO ; } @end -- cgit v1.2.3