changeset 4900:c28e318653c6

7124554: [macosx] JWindow does ignore setAlwaysOnTop property Summary: Re-apply the Floating level to AlwaysOnTop child windows after -addCHildWindow: calls Reviewed-by: leonidr, swingler
author anthony
date Fri, 27 Jan 2012 16:02:35 +0400
parents 03d38a9723ff
children 5780795f381e
files src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java src/macosx/classes/sun/lwawt/macosx/CWrapper.java src/macosx/native/sun/awt/CWrapper.m
diffstat 3 files changed, 62 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	Fri Jan 27 15:37:56 2012 +0400
+++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	Fri Jan 27 16:02:35 2012 +0400
@@ -496,6 +496,9 @@
         if (owner != null) {
             if (visible) {
                 CWrapper.NSWindow.addChildWindow(owner.getNSWindowPtr(), getNSWindowPtr(), CWrapper.NSWindow.NSWindowAbove);
+                if (target.isAlwaysOnTop()) {
+                    CWrapper.NSWindow.setLevel(getNSWindowPtr(), CWrapper.NSWindow.NSFloatingWindowLevel);
+                }
             }
         }
 
@@ -822,6 +825,9 @@
         final long nsWindowOwnerPtr = owner.getNSWindowPtr();
         CWrapper.NSWindow.removeChildWindow(nsWindowOwnerPtr, nsWindowSelfPtr);
         CWrapper.NSWindow.addChildWindow(nsWindowOwnerPtr, nsWindowSelfPtr, CWrapper.NSWindow.NSWindowAbove);
+        if (target.isAlwaysOnTop()) {
+            CWrapper.NSWindow.setLevel(getNSWindowPtr(), CWrapper.NSWindow.NSFloatingWindowLevel);
+        }
     }
 
     // ----------------------------------------------------------------------
--- a/src/macosx/classes/sun/lwawt/macosx/CWrapper.java	Fri Jan 27 15:37:56 2012 +0400
+++ b/src/macosx/classes/sun/lwawt/macosx/CWrapper.java	Fri Jan 27 16:02:35 2012 +0400
@@ -36,6 +36,16 @@
         public static final int NSWindowBelow = -1;
         public static final int NSWindowOut = 0;
 
+        // Window level constants
+        // The number of supported levels: (we'll use more in the future)
+        public static final int MAX_WINDOW_LEVELS = 2;
+        // The levels: (these are NOT real constants, these are keys. See native code.)
+        public static final int NSNormalWindowLevel = 0;
+        public static final int NSFloatingWindowLevel = 1;
+
+        // 'level' is one of the keys defined above
+        public static native void setLevel(long window, int level);
+
         public static native void makeKeyAndOrderFront(long window);
         public static native void makeMainWindow(long window);
         public static native boolean canBecomeMainWindow(long window);
--- a/src/macosx/native/sun/awt/CWrapper.m	Fri Jan 27 15:37:56 2012 +0400
+++ b/src/macosx/native/sun/awt/CWrapper.m	Fri Jan 27 16:02:35 2012 +0400
@@ -32,6 +32,7 @@
 #import "GeomUtilities.h"
 #import "ThreadUtilities.h"
 
+#import "sun_lwawt_macosx_CWrapper_NSWindow.h"
 
 /*
  * Class:     sun_lwawt_macosx_CWrapper$NSObject
@@ -105,10 +106,10 @@
     __block jboolean canBecomeMainWindow = JNI_FALSE;
 
 JNF_COCOA_ENTER(env);
-    
+
     NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
-	canBecomeMainWindow = [window canBecomeMainWindow];
+    canBecomeMainWindow = [window canBecomeMainWindow];
     }];
 
 JNF_COCOA_EXIT(env);
@@ -219,6 +220,42 @@
 JNF_COCOA_EXIT(env);
 }
 
+// Used for CWrapper.NSWindow.setLevel() (and level() which isn't implemented yet)
+static NSInteger LEVELS[sun_lwawt_macosx_CWrapper_NSWindow_MAX_WINDOW_LEVELS];
+static void initLevels()
+{
+    static dispatch_once_t pred;
+
+    dispatch_once(&pred, ^{
+        LEVELS[sun_lwawt_macosx_CWrapper_NSWindow_NSNormalWindowLevel] = NSNormalWindowLevel;
+        LEVELS[sun_lwawt_macosx_CWrapper_NSWindow_NSFloatingWindowLevel] = NSFloatingWindowLevel;
+    });
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    setLevel
+ * Signature: (JI)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_setLevel
+(JNIEnv *env, jclass cls, jlong windowPtr, jint level)
+{
+JNF_COCOA_ENTER(env);
+
+    if (level >= 0 && level < sun_lwawt_macosx_CWrapper_NSWindow_MAX_WINDOW_LEVELS) {
+        initLevels();
+
+        NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
+        [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+            [window setLevel: LEVELS[level]];
+        }];
+    } else {
+        [JNFException raise:env as:kIllegalArgumentException reason:"unknown level"];
+    }
+
+JNF_COCOA_EXIT(env);
+}
 
 /*
  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
@@ -310,7 +347,7 @@
 (JNIEnv *env, jclass cls, jlong windowPtr, jboolean opaque)
 {
 JNF_COCOA_ENTER(env);
-    
+
     AWTWindow *window = (AWTWindow *)jlong_to_ptr(windowPtr);
     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
         [window setOpaque:(BOOL)opaque];
@@ -329,13 +366,13 @@
 (JNIEnv *env, jclass cls, jlong windowPtr, jlong colorPtr)
 {
 JNF_COCOA_ENTER(env);
-    
+
     AWTWindow *window = (AWTWindow *)jlong_to_ptr(windowPtr);
     NSColor *color = (NSColor *)jlong_to_ptr(colorPtr);
     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
         [window setBackgroundColor:color];
     }];
-    
+
 JNF_COCOA_EXIT(env);
 }
 
@@ -688,15 +725,15 @@
 (JNIEnv *env, jclass cls)
 {
     __block jlong clearColorPtr = 0L;
-    
+
 JNF_COCOA_ENTER(env);
-    
+
     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
         clearColorPtr = ptr_to_jlong([NSColor clearColor]);
     }];
-    
+
 JNF_COCOA_EXIT(env);
-    
+
     return clearColorPtr;
 }