changeset 4904:0b7acd016f8c

7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows Summary: Emulate -zoom request for undecorated windows Reviewed-by: swingler
author anthony
date Wed, 21 Mar 2012 20:17:07 +0400
parents 28cf821cd6a1
children fdd008c3ef5a
files src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java
diffstat 1 files changed, 33 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	Wed Mar 21 20:10:14 2012 +0400
+++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	Wed Mar 21 20:17:07 2012 +0400
@@ -205,6 +205,8 @@
     private CPlatformView contentView;
     private CPlatformWindow owner;
     private boolean visible = false; // visibility status from native perspective
+    private boolean undecorated; // initialized in getInitialStyleBits()
+    private Rectangle normalBounds = null; // not-null only for undecorated maximized windows
 
     public CPlatformWindow(final PeerType peerType) {
         super(0, true);
@@ -283,8 +285,8 @@
 
         // Either java.awt.Frame or java.awt.Dialog can be undecorated, however java.awt.Window always is undecorated.
         {
-            final boolean undecorated = isFrame ? ((Frame)target).isUndecorated() : (isDialog ? ((Dialog)target).isUndecorated() : true);
-            if (undecorated) styleBits = SET(styleBits, DECORATED, false);
+            this.undecorated = isFrame ? ((Frame)target).isUndecorated() : (isDialog ? ((Dialog)target).isUndecorated() : true);
+            if (this.undecorated) styleBits = SET(styleBits, DECORATED, false);
         }
 
         // Either java.awt.Frame or java.awt.Dialog can be resizable, however java.awt.Window is never resizable
@@ -474,6 +476,30 @@
         return this.visible;
     }
 
+    private void zoom() {
+        if (!undecorated) {
+            CWrapper.NSWindow.zoom(getNSWindowPtr());
+        } else {
+            // OS X handles -zoom incorrectly for undecorated windows
+            final boolean isZoomed = this.normalBounds == null;
+            deliverZoom(isZoomed);
+
+            Rectangle toBounds;
+            if (isZoomed) {
+                this.normalBounds = peer.getBounds();
+                long screen = CWrapper.NSWindow.screen(getNSWindowPtr());
+                toBounds = CWrapper.NSScreen.visibleFrame(screen).getBounds();
+                // Flip the y coordinate
+                Rectangle frame = CWrapper.NSScreen.frame(screen).getBounds();
+                toBounds.y = frame.height - toBounds.y - toBounds.height;
+            } else {
+                toBounds = normalBounds;
+                this.normalBounds = null;
+            }
+            setBounds(toBounds.x, toBounds.y, toBounds.width, toBounds.height);
+        }
+    }
+
     @Override // PlatformWindow
     public void setVisible(boolean visible) {
         final long nsWindowPtr = getNSWindowPtr();
@@ -509,7 +535,7 @@
                     CWrapper.NSWindow.deminiaturize(nsWindowPtr);
                     break;
                 case Frame.MAXIMIZED_BOTH:
-                    CWrapper.NSWindow.zoom(nsWindowPtr);
+                    zoom();
                     break;
             }
         }
@@ -545,7 +571,7 @@
                         CWrapper.NSWindow.miniaturize(nsWindowPtr);
                         break;
                     case Frame.MAXIMIZED_BOTH:
-                        CWrapper.NSWindow.zoom(nsWindowPtr);
+                        zoom();
                         break;
                 }
             }
@@ -724,7 +750,7 @@
                 if (prevWindowState == Frame.MAXIMIZED_BOTH) {
                     // let's return into the normal states first
                     // the zoom call toggles between the normal and the max states
-                    CWrapper.NSWindow.zoom(nsWindowPtr);
+                    zoom();
                 }
                 CWrapper.NSWindow.miniaturize(nsWindowPtr);
                 break;
@@ -733,14 +759,14 @@
                     // let's return into the normal states first
                     CWrapper.NSWindow.deminiaturize(nsWindowPtr);
                 }
-                CWrapper.NSWindow.zoom(nsWindowPtr);
+                zoom();
                 break;
             case Frame.NORMAL:
                 if (prevWindowState == Frame.ICONIFIED) {
                     CWrapper.NSWindow.deminiaturize(nsWindowPtr);
                 } else if (prevWindowState == Frame.MAXIMIZED_BOTH) {
                     // the zoom call toggles between the normal and the max states
-                    CWrapper.NSWindow.zoom(nsWindowPtr);
+                    zoom();
                 }
                 break;
             default: