Skip to content

Commit 19b1e35

Browse files
author
duke
committed
Backport 689cee3d0950e15e88a1f6738bfded00655dca9c
1 parent d29794f commit 19b1e35

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer)
534534
AwtComponent *awtParent = (parent != NULL) ? (AwtComponent *)JNI_GET_PDATA(parent) : NULL;
535535
HWND hwndOwner = awtParent ? awtParent->GetHWnd() : NULL;
536536

537+
jboolean doIt = JNI_FALSE;
537538
PAGESETUPDLG setup;
538539
memset(&setup, 0, sizeof(setup));
539540

@@ -589,7 +590,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer)
589590
*/
590591
if ((setup.hDevMode == NULL) && (setup.hDevNames == NULL)) {
591592
CLEANUP_SHOW;
592-
return JNI_FALSE;
593+
return doIt;
593594
}
594595
} else {
595596
int measure = PSD_INTHOUSANDTHSOFINCHES;
@@ -617,7 +618,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer)
617618
pageFormatToSetup(env, self, page, &setup, AwtPrintControl::getPrintDC(env, self));
618619
if (env->ExceptionCheck()) {
619620
CLEANUP_SHOW;
620-
return JNI_FALSE;
621+
return doIt;
621622
}
622623

623624
setup.lpfnPageSetupHook = reinterpret_cast<LPPAGESETUPHOOK>(pageDlgHook);
@@ -631,7 +632,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer)
631632
jobject paper = getPaper(env, page);
632633
if (paper == NULL) {
633634
CLEANUP_SHOW;
634-
return JNI_FALSE;
635+
return doIt;
635636
}
636637
int units = setup.Flags & PSD_INTHOUSANDTHSOFINCHES ?
637638
MM_HIENGLISH :
@@ -673,7 +674,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer)
673674
setPaperValues(env, paper, &paperSize, &margins, units);
674675
if (env->ExceptionCheck()) {
675676
CLEANUP_SHOW;
676-
return JNI_FALSE;
677+
return doIt;
677678
}
678679
/*
679680
* Put the updated Paper instance and the orientation into
@@ -682,7 +683,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer)
682683
setPaper(env, page, paper);
683684
if (env->ExceptionCheck()) {
684685
CLEANUP_SHOW;
685-
return JNI_FALSE;
686+
return doIt;
686687
}
687688
setPageFormatOrientation(env, page, orientation);
688689
if (env->ExceptionCheck()) {
@@ -696,12 +697,13 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer)
696697
jboolean err = setPrintPaperSize(env, self, devmode->dmPaperSize);
697698
if (err) {
698699
CLEANUP_SHOW;
699-
return JNI_FALSE;
700+
return doIt;
700701
}
701702
}
702703
}
703704
::GlobalUnlock(setup.hDevMode);
704705
}
706+
doIt = JNI_TRUE;
705707
}
706708

707709
AwtDialog::CheckUninstallModalHook();
@@ -720,7 +722,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer)
720722

721723
CLEANUP_SHOW;
722724

723-
return JNI_TRUE;
725+
return doIt;
724726

725727
CATCH_BAD_ALLOC_RET(0);
726728
}
Lines changed: 58 additions & 0 deletions
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)