Skip to content

Commit 689cee3

Browse files
committedJun 21, 2024
8334509: Cancelling PageDialog does not return the same PageFormat object
Reviewed-by: aivanov, prr
1 parent 8e1d2b0 commit 689cee3

File tree

2 files changed

+67
-7
lines changed

2 files changed

+67
-7
lines changed
 

‎src/java.desktop/windows/native/libawt/windows/awt_PrintJob.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer)
522522
AwtComponent *awtParent = (parent != NULL) ? (AwtComponent *)JNI_GET_PDATA(parent) : NULL;
523523
HWND hwndOwner = awtParent ? awtParent->GetHWnd() : NULL;
524524

525+
jboolean doIt = JNI_FALSE;
525526
PAGESETUPDLG setup;
526527
memset(&setup, 0, sizeof(setup));
527528

@@ -577,7 +578,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer)
577578
*/
578579
if ((setup.hDevMode == NULL) && (setup.hDevNames == NULL)) {
579580
CLEANUP_SHOW;
580-
return JNI_FALSE;
581+
return doIt;
581582
}
582583
} else {
583584
int measure = PSD_INTHOUSANDTHSOFINCHES;
@@ -605,7 +606,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer)
605606
pageFormatToSetup(env, self, page, &setup, AwtPrintControl::getPrintDC(env, self));
606607
if (env->ExceptionCheck()) {
607608
CLEANUP_SHOW;
608-
return JNI_FALSE;
609+
return doIt;
609610
}
610611

611612
setup.lpfnPageSetupHook = reinterpret_cast<LPPAGESETUPHOOK>(pageDlgHook);
@@ -619,7 +620,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer)
619620
jobject paper = getPaper(env, page);
620621
if (paper == NULL) {
621622
CLEANUP_SHOW;
622-
return JNI_FALSE;
623+
return doIt;
623624
}
624625
int units = setup.Flags & PSD_INTHOUSANDTHSOFINCHES ?
625626
MM_HIENGLISH :
@@ -661,7 +662,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer)
661662
setPaperValues(env, paper, &paperSize, &margins, units);
662663
if (env->ExceptionCheck()) {
663664
CLEANUP_SHOW;
664-
return JNI_FALSE;
665+
return doIt;
665666
}
666667
/*
667668
* Put the updated Paper instance and the orientation into
@@ -670,7 +671,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer)
670671
setPaper(env, page, paper);
671672
if (env->ExceptionCheck()) {
672673
CLEANUP_SHOW;
673-
return JNI_FALSE;
674+
return doIt;
674675
}
675676
setPageFormatOrientation(env, page, orientation);
676677
if (env->ExceptionCheck()) {
@@ -684,12 +685,13 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer)
684685
jboolean err = setPrintPaperSize(env, self, devmode->dmPaperSize);
685686
if (err) {
686687
CLEANUP_SHOW;
687-
return JNI_FALSE;
688+
return doIt;
688689
}
689690
}
690691
}
691692
::GlobalUnlock(setup.hDevMode);
692693
}
694+
doIt = JNI_TRUE;
693695
}
694696

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

709711
CLEANUP_SHOW;
710712

711-
return JNI_TRUE;
713+
return doIt;
712714

713715
CATCH_BAD_ALLOC_RET(0);
714716
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 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+
* @test
26+
* @bug 8334366
27+
* @key headful printer
28+
* @summary Verifies original pageobject is returned unmodified
29+
* on cancelling pagedialog
30+
* @requires (os.family == "windows")
31+
* @run main PageDialogCancelTest
32+
*/
33+
34+
import java.awt.Robot;
35+
import java.awt.event.KeyEvent;
36+
import java.awt.print.PageFormat;
37+
import java.awt.print.PrinterJob;
38+
39+
public class PageDialogCancelTest {
40+
41+
public static void main(String[] args) throws Exception {
42+
PrinterJob pj = PrinterJob.getPrinterJob();
43+
PageFormat oldFormat = new PageFormat();
44+
Robot robot = new Robot();
45+
Thread t1 = new Thread(() -> {
46+
robot.delay(2000);
47+
robot.keyPress(KeyEvent.VK_ESCAPE);
48+
robot.keyRelease(KeyEvent.VK_ESCAPE);
49+
robot.waitForIdle();
50+
});
51+
t1.start();
52+
PageFormat newFormat = pj.pageDialog(oldFormat);
53+
if (!newFormat.equals(oldFormat)) {
54+
throw new RuntimeException("Original PageFormat not returned on cancelling PageDialog");
55+
}
56+
}
57+
}
58+

0 commit comments

Comments
 (0)
Please sign in to comment.