--- old/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java 2012-07-04 18:48:13.000000000 +0400 +++ new/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java 2012-07-04 18:48:13.000000000 +0400 @@ -209,6 +209,7 @@ private boolean undecorated; // initialized in getInitialStyleBits() private Rectangle normalBounds = null; // not-null only for undecorated maximized windows private CPlatformResponder responder; + private volatile boolean zoomed = false; // from native perspective public CPlatformWindow(final PeerType peerType) { super(0, true); @@ -467,8 +468,13 @@ nativeSetNSWindowBounds(getNSWindowPtr(), x, y, w, h); } + private boolean isZoomed() { + return zoomed || this.normalBounds != null; + } + private void zoom() { if (!undecorated) { + zoomed = !zoomed; CWrapper.NSWindow.zoom(getNSWindowPtr()); } else { // OS X handles -zoom incorrectly for undecorated windows @@ -499,9 +505,9 @@ public void setVisible(boolean visible) { final long nsWindowPtr = getNSWindowPtr(); - // 1. Process parent-child relationship when hiding + // Process parent-child relationship when hiding if (!visible) { - // 1a. Unparent my children + // Unparent my children for (Window w : target.getOwnedWindows()) { WindowPeer p = (WindowPeer)w.getPeer(); if (p instanceof LWWindowPeer) { @@ -512,30 +518,17 @@ } } - // 1b. Unparent myself + // Unparent myself if (owner != null && owner.isVisible()) { CWrapper.NSWindow.removeChildWindow(owner.getNSWindowPtr(), nsWindowPtr); } } - // 2. Configure stuff + // Configure stuff updateIconImages(); updateFocusabilityForAutoRequestFocus(false); - // 3. Manage the extended state when hiding - if (!visible) { - // Cancel out the current native state of the window - switch (peer.getState()) { - case Frame.ICONIFIED: - CWrapper.NSWindow.deminiaturize(nsWindowPtr); - break; - case Frame.MAXIMIZED_BOTH: - zoom(); - break; - } - } - - // 4. Actually show or hide the window + // Actually show or hide the window LWWindowPeer blocker = peer.getBlocker(); if (blocker == null || !visible) { // If it ain't blocked, or is being hidden, go regular way @@ -564,16 +557,23 @@ } this.visible = visible; - // 5. Manage the extended state when showing + // Manage the extended state when showing if (visible) { - // Re-apply the extended state as expected in shared code + // Apply the extended state as expected in shared code if (target instanceof Frame) { switch (((Frame)target).getExtendedState()) { case Frame.ICONIFIED: CWrapper.NSWindow.miniaturize(nsWindowPtr); break; case Frame.MAXIMIZED_BOTH: - zoom(); + if (!isZoomed()) { + zoom(); + } + break; + default: // NORMAL + if (isZoomed()) { + zoom(); + } break; } } @@ -581,12 +581,12 @@ nativeSynthesizeMouseEnteredExitedEvents(nsWindowPtr); - // 6. Configure stuff #2 + // Configure stuff #2 updateFocusabilityForAutoRequestFocus(true); - // 7. Manage parent-child relationship when showing + // Manage parent-child relationship when showing if (visible) { - // 7a. Add myself as a child + // Add myself as a child if (owner != null && owner.isVisible()) { CWrapper.NSWindow.addChildWindow(owner.getNSWindowPtr(), nsWindowPtr, CWrapper.NSWindow.NSWindowAbove); if (target.isAlwaysOnTop()) { @@ -594,7 +594,7 @@ } } - // 7b. Add my own children to myself + // Add my own children to myself for (Window w : target.getOwnedWindows()) { WindowPeer p = (WindowPeer)w.getPeer(); if (p instanceof LWWindowPeer) { @@ -609,7 +609,7 @@ } } - // 8. Deal with the blocker of the window being shown + // Deal with the blocker of the window being shown if (blocker != null && visible) { // Make sure the blocker is above its siblings ((CPlatformWindow)blocker.getPlatformWindow()).orderAboveSiblings(); --- /dev/null 2012-06-04 20:32:32.718000000 +0400 +++ new/test/java/awt/Frame/HideMaximized/HideMaximized.java 2012-07-04 18:48:14.000000000 +0400 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + @test + @bug 7177173 + @summary The maximized state shouldn't be reset upon hiding a frame + @author anthony.petrov@oracle.com: area=awt.toplevel + @run main HideMaximized +*/ + +import java.awt.*; + +public class HideMaximized { + public static void main(String[] args) { + if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) { + // Nothing to test + return; + } + + Frame frame = new Frame("test"); + frame.setExtendedState(Frame.MAXIMIZED_BOTH); + frame.setVisible(true); + + try { Thread.sleep(1000); } catch (Exception ex) {} + + if (frame.getExtendedState() != Frame.MAXIMIZED_BOTH) { + throw new RuntimeException("The maximized state has not been applied"); + } + + // This will hide the frame, and also clean things up for safe exiting + frame.dispose(); + + try { Thread.sleep(1000); } catch (Exception ex) {} + + if (frame.getExtendedState() != Frame.MAXIMIZED_BOTH) { + throw new RuntimeException("The maximized state has been reset"); + } + } +}