Skip to content

Commit

Permalink
Page dialog fix
Browse files Browse the repository at this point in the history
  • Loading branch information
prsadhuk committed Jun 19, 2024
1 parent 3a01b47 commit 921651b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer)
AwtComponent *awtParent = (parent != NULL) ? (AwtComponent *)JNI_GET_PDATA(parent) : NULL;
HWND hwndOwner = awtParent ? awtParent->GetHWnd() : NULL;

jboolean doIt = JNI_FALSE;
PAGESETUPDLG setup;
memset(&setup, 0, sizeof(setup));

Expand Down Expand Up @@ -690,6 +691,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer)
}
::GlobalUnlock(setup.hDevMode);
}
doIt = JNI_TRUE;
}

AwtDialog::CheckUninstallModalHook();
Expand All @@ -708,7 +710,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer)

CLEANUP_SHOW;

return JNI_TRUE;
return doIt;

CATCH_BAD_ALLOC_RET(0);
}
Expand Down
68 changes: 68 additions & 0 deletions test/jdk/java/awt/print/PrinterJob/PageDialogCancelTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2024, 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 8334366
* @key printer
* @summary Verifies oriignal pageobject is returned unmodified
* on cancelling pagedialog
* @requires (os.family == "windows")
* @run main PageDialogCancelTest
*/

import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.print.PageFormat;
import java.awt.print.PrinterJob;

public class PageDialogCancelTest {

public static void main(String[] args) throws Exception {
PrinterJob pj = PrinterJob.getPrinterJob();
PageFormat oldFormat = new PageFormat();
Robot robot = new Robot();
Thread t1 = new Thread(() -> {
robot.delay(2000);
for (int i = 0; i < 8; i++) {
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.waitForIdle();
robot.delay(500);
}
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.waitForIdle();
robot.delay(500);
});
t1.start();
PageFormat newFormat = pj.pageDialog(oldFormat);
boolean result = newFormat.equals(oldFormat);
if (result) {
System.out.println("Test Passed");
} else {
throw new RuntimeException("Original PageFormat not returned on cancelling PageDialog");
}
}
}

0 comments on commit 921651b

Please sign in to comment.