|
| 1 | +/* |
| 2 | + * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +/* |
| 25 | + * DeiconifyClipTest.java |
| 26 | + * |
| 27 | + * summary: |
| 28 | + * |
| 29 | + * What happens is that we call AwtWindow::UpdateInsets when |
| 30 | + * processing WM_NCCALCSIZE delivered on programmatic deiconification. |
| 31 | + * At this point IsIconic returns false (so UpdateInsets proceeds), |
| 32 | + * but the rect sizes still seems to be those weird of the iconic |
| 33 | + * state. Based on them we compute insets with top = left = 0 (and |
| 34 | + * bottom and right that are completely bogus) and pass them to |
| 35 | + * PaintUpdateRgn which results in incorrect clip origin. Immediately |
| 36 | + * after that we do UpdateInsets again during WM_SIZE processing and |
| 37 | + * get real values. |
| 38 | + */ |
| 39 | + |
| 40 | +import javax.swing.BoxLayout; |
| 41 | +import javax.swing.JFrame; |
| 42 | +import javax.swing.SwingUtilities; |
| 43 | +import java.awt.Color; |
| 44 | +import java.awt.Dimension; |
| 45 | +import java.awt.Frame; |
| 46 | +import java.awt.Graphics; |
| 47 | +import java.awt.Insets; |
| 48 | + |
| 49 | +/* |
| 50 | + * @test |
| 51 | + * @bug 4792958 |
| 52 | + * @summary Incorrect clip region after programmatic restore |
| 53 | + * @library /java/awt/regtesthelpers |
| 54 | + * @build PassFailJFrame |
| 55 | + * @run main/manual DeiconifyClipTest |
| 56 | +*/ |
| 57 | + |
| 58 | +public class DeiconifyClipTest { |
| 59 | + private static final String INSTRUCTIONS = """ |
| 60 | + This test creates a frame that is automatically iconified/deiconified |
| 61 | + in a cycle. |
| 62 | +
|
| 63 | + The test FAILS if after deiconfication the frame has a greyed-out area |
| 64 | + in the lower-right corner. |
| 65 | + If the frame contents is drawn completely - the test PASSES. |
| 66 | +
|
| 67 | + Press PASS or FAIL button accordingly. |
| 68 | + """; |
| 69 | + |
| 70 | + static TestFrame testFrame; |
| 71 | + static volatile boolean shouldContinue = true; |
| 72 | + |
| 73 | + public static void main(String[] args) throws Exception { |
| 74 | + PassFailJFrame passFailJFrame = PassFailJFrame.builder() |
| 75 | + .title("DeiconifyClipTest Instructions") |
| 76 | + .instructions(INSTRUCTIONS) |
| 77 | + .columns(45) |
| 78 | + .testUI(DeiconifyClipTest::createAndShowUI) |
| 79 | + .build(); |
| 80 | + try { |
| 81 | + runThread(); |
| 82 | + } finally { |
| 83 | + passFailJFrame.awaitAndCheck(); |
| 84 | + shouldContinue = false; |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + private static void runThread() { |
| 89 | + new Thread(() -> { |
| 90 | + for (int i = 0; i < 1000 && shouldContinue; ++i) { |
| 91 | + try { |
| 92 | + Thread.sleep(3000); |
| 93 | + SwingUtilities.invokeAndWait(() -> { |
| 94 | + if ((testFrame.getExtendedState() & Frame.ICONIFIED) |
| 95 | + != 0) { |
| 96 | + testFrame.setExtendedState(Frame.NORMAL); |
| 97 | + } else { |
| 98 | + testFrame.setState(Frame.ICONIFIED); |
| 99 | + } |
| 100 | + }); |
| 101 | + } catch (Exception ignored) { |
| 102 | + } |
| 103 | + } |
| 104 | + }).start(); |
| 105 | + } |
| 106 | + |
| 107 | + static Frame createAndShowUI() { |
| 108 | + testFrame = new TestFrame(); |
| 109 | + testFrame.getContentPane().setLayout(new BoxLayout(testFrame.getContentPane(), |
| 110 | + BoxLayout.Y_AXIS)); |
| 111 | + testFrame.getContentPane().setBackground(Color.yellow); |
| 112 | + testFrame.setSize(300, 300); |
| 113 | + return testFrame; |
| 114 | + } |
| 115 | + |
| 116 | + static class TestFrame extends JFrame { |
| 117 | + public TestFrame() { |
| 118 | + super("DeiconifyClipTest"); |
| 119 | + } |
| 120 | + |
| 121 | + // make it more visible if the clip is wrong. |
| 122 | + public void paint(Graphics g) { |
| 123 | + Insets b = getInsets(); |
| 124 | + Dimension d = getSize(); |
| 125 | + |
| 126 | + int x = b.left; |
| 127 | + int y = b.top; |
| 128 | + int w = d.width - x - b.right; |
| 129 | + int h = d.height - y - b.bottom; |
| 130 | + |
| 131 | + g.setColor(Color.white); |
| 132 | + g.fillRect(0, 0, d.width, d.height); |
| 133 | + |
| 134 | + g.setColor(Color.green); |
| 135 | + g.drawRect(x, y, w-1, h-1); |
| 136 | + g.drawLine(x, y, x+w, y+h); |
| 137 | + g.drawLine(x, y+h, x+w, y); |
| 138 | + } |
| 139 | + } |
| 140 | +} |
0 commit comments