diff --git a/src/macosx/native/sun/awt/CPrinterJob.m b/src/macosx/native/sun/awt/CPrinterJob.m index 3935240ff7836c35dbcd6d057a0f880a8ea66192..2b92c2250fbd6bae12ecaf82ffc607491c0e82f2 100644 --- a/src/macosx/native/sun/awt/CPrinterJob.m +++ b/src/macosx/native/sun/awt/CPrinterJob.m @@ -359,7 +359,11 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj static JNF_CLASS_CACHE(jc_Pageable, "java/awt/print/Pageable"); static JNF_MEMBER_CACHE(jm_getCopies, sjc_CPrinterJob, "getCopiesInt", "()I"); static JNF_MEMBER_CACHE(jm_isCollated, sjc_CPrinterJob, "isCollated", "()Z"); + static JNF_MEMBER_CACHE(jm_getFromPage, sjc_CPrinterJob, "getFromPageAttrib", "()I"); + static JNF_MEMBER_CACHE(jm_getToPage, sjc_CPrinterJob, "getToPageAttrib", "()I"); + static JNF_MEMBER_CACHE(jm_getSelectAttrib, sjc_CPrinterJob, "getSelectAttrib", "()I"); static JNF_MEMBER_CACHE(jm_getNumberOfPages, jc_Pageable, "getNumberOfPages", "()I"); + static JNF_MEMBER_CACHE(jm_getPageFormat, sjc_CPrinterJob, "getPageFormatFromAttributes", "()Ljava/awt/print/PageFormat;"); NSMutableDictionary* printingDictionary = [dst dictionary]; @@ -368,19 +372,35 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj jboolean collated = JNFCallBooleanMethod(env, srcPrinterJob, jm_isCollated); // AWT_THREADING Safe (known object) [printingDictionary setObject:[NSNumber numberWithBool:collated ? YES : NO] forKey:NSPrintMustCollate]; - jint jNumPages = JNFCallIntMethod(env, srcPageable, jm_getNumberOfPages); // AWT_THREADING Safe (!appKit) if (jNumPages != java_awt_print_Pageable_UNKNOWN_NUMBER_OF_PAGES) { - [printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages]; + jint selectID = JNFCallIntMethod(env, srcPrinterJob, jm_getSelectAttrib); + if (selectID ==0) { + [printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintAllPages]; + } else if (selectID == 2) { + // In Mac 10.7, Print ALL is deselected if PrintSelection is YES whether + // NSPrintAllPages is YES or NO + [printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages]; + [printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintSelectionOnly]; + } else { + [printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages]; + } - [printingDictionary setObject:[NSNumber numberWithInteger:1] forKey:NSPrintFirstPage]; - [printingDictionary setObject:[NSNumber numberWithInteger:jNumPages] forKey:NSPrintLastPage]; + jint fromPage = JNFCallIntMethod(env, srcPrinterJob, jm_getFromPage); + jint toPage = JNFCallIntMethod(env, srcPrinterJob, jm_getToPage); + // setting fromPage and toPage will not be shown in the dialog if printing All pages + [printingDictionary setObject:[NSNumber numberWithInteger:fromPage] forKey:NSPrintFirstPage]; + [printingDictionary setObject:[NSNumber numberWithInteger:toPage] forKey:NSPrintLastPage]; } else { [printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintAllPages]; } + jobject page = JNFCallObjectMethod(env, srcPrinterJob, jm_getPageFormat); + if (page != NULL) { + javaPageFormatToNSPrintInfo(env, NULL, page, dst); + } } /* diff --git a/src/share/classes/sun/print/RasterPrinterJob.java b/src/share/classes/sun/print/RasterPrinterJob.java index 437b54e71d8a5d80ab0de0ccdae5eca5f3f83563..05a73b1658d2c8d5d1a7b3a6ca46fa3aab3011e6 100644 --- a/src/share/classes/sun/print/RasterPrinterJob.java +++ b/src/share/classes/sun/print/RasterPrinterJob.java @@ -117,6 +117,16 @@ public abstract class RasterPrinterJob extends PrinterJob { /* Stream destination type. */ protected static final int STREAM = 2; + /** + * Pageable MAX pages + */ + private static final int MAX_UNKNOWN_PAGES = 9999; + + private static final int PD_ALLPAGES = 0x00000000; + private static final int PD_SELECTION = 0x00000001; + private static final int PD_PAGENUMS = 0x00000002; + private static final int PD_NOSELECTION = 0x00000004; + /** * Maximum amount of memory in bytes to use for the * buffered image "band". 4Mb is a compromise between @@ -800,6 +810,14 @@ public abstract class RasterPrinterJob extends PrinterJob { } } + protected PageFormat getPageFormatFromAttributes() { + if (attributes == null) { + return null; + } + return attributeToPageFormat(getPrintService(), this.attributes); + } + + /** * Presents the user a dialog for changing properties of the * print job interactively. @@ -1762,6 +1780,78 @@ public abstract class RasterPrinterJob extends PrinterJob { return mCollate; } + private final int getSelectAttrib() { + if (attributes != null) { + SunPageSelection pages = + (SunPageSelection)attributes.get(SunPageSelection.class); + if (pages == SunPageSelection.RANGE) { + return PD_PAGENUMS; + } else if (pages == SunPageSelection.SELECTION) { + return PD_SELECTION; + } else if (pages == SunPageSelection.ALL) { + return PD_ALLPAGES; + } + } + return PD_NOSELECTION; + } + + //returns 1-based index for "From" page + private final int getFromPageAttrib() { + if (attributes != null) { + PageRanges pageRangesAttr = + (PageRanges)attributes.get(PageRanges.class); + if (pageRangesAttr != null) { + int[][] range = pageRangesAttr.getMembers(); + return range[0][0]; + } + } + return getMinPageAttrib(); + } + + //returns 1-based index for "To" page + private final int getToPageAttrib() { + if (attributes != null) { + PageRanges pageRangesAttr = + (PageRanges)attributes.get(PageRanges.class); + if (pageRangesAttr != null) { + int[][] range = pageRangesAttr.getMembers(); + return range[range.length-1][1]; + } + } + return getMaxPageAttrib(); + } + + private final int getMinPageAttrib() { + if (attributes != null) { + SunMinMaxPage s = + (SunMinMaxPage)attributes.get(SunMinMaxPage.class); + if (s != null) { + return s.getMin(); + } + } + return 1; + } + + private final int getMaxPageAttrib() { + if (attributes != null) { + SunMinMaxPage s = + (SunMinMaxPage)attributes.get(SunMinMaxPage.class); + if (s != null) { + return s.getMax(); + } + } + + Pageable pageable = getPageable(); + if (pageable != null) { + int numPages = pageable.getNumberOfPages(); + if (numPages <= Pageable.UNKNOWN_NUMBER_OF_PAGES) { + numPages = MAX_UNKNOWN_PAGES; + } + return ((numPages == 0) ? 1 : numPages); + } + + return Integer.MAX_VALUE; + } /** * Called by the print() method at the start of * a print job. diff --git a/src/windows/classes/sun/awt/windows/WPrinterJob.java b/src/windows/classes/sun/awt/windows/WPrinterJob.java index 6f22231a53cdd03303f12d32c8f9227855e1c96f..d56b7d32428a492d8f39a6f58df5c828f5c8d19d 100644 --- a/src/windows/classes/sun/awt/windows/WPrinterJob.java +++ b/src/windows/classes/sun/awt/windows/WPrinterJob.java @@ -183,10 +183,6 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { /** * Values must match those defined in wingdi.h & commdlg.h */ - private static final int PD_ALLPAGES = 0x00000000; - private static final int PD_SELECTION = 0x00000001; - private static final int PD_PAGENUMS = 0x00000002; - private static final int PD_NOSELECTION = 0x00000004; private static final int PD_COLLATE = 0x00000010; private static final int PD_PRINTTOFILE = 0x00000020; private static final int DM_ORIENTATION = 0x00000001; @@ -1639,63 +1635,7 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { } } - //returns 1-based index for "From" page - private final int getFromPageAttrib() { - if (attributes != null) { - PageRanges pageRangesAttr = - (PageRanges)attributes.get(PageRanges.class); - if (pageRangesAttr != null) { - int[][] range = pageRangesAttr.getMembers(); - return range[0][0]; - } - } - return getMinPageAttrib(); - } - - //returns 1-based index for "To" page - private final int getToPageAttrib() { - if (attributes != null) { - PageRanges pageRangesAttr = - (PageRanges)attributes.get(PageRanges.class); - if (pageRangesAttr != null) { - int[][] range = pageRangesAttr.getMembers(); - return range[range.length-1][1]; - } - } - return getMaxPageAttrib(); - } - - private final int getMinPageAttrib() { - if (attributes != null) { - SunMinMaxPage s = - (SunMinMaxPage)attributes.get(SunMinMaxPage.class); - if (s != null) { - return s.getMin(); - } - } - return 1; - } - - private final int getMaxPageAttrib() { - if (attributes != null) { - SunMinMaxPage s = - (SunMinMaxPage)attributes.get(SunMinMaxPage.class); - if (s != null) { - return s.getMax(); - } - } - - Pageable pageable = getPageable(); - if (pageable != null) { - int numPages = pageable.getNumberOfPages(); - if (numPages <= Pageable.UNKNOWN_NUMBER_OF_PAGES) { - numPages = MAX_UNKNOWN_PAGES; - } - return ((numPages == 0) ? 1 : numPages); - } - return Integer.MAX_VALUE; - } private final boolean getDestAttrib() { return (mDestination != null); @@ -1847,20 +1787,7 @@ public class WPrinterJob extends RasterPrinterJob implements DisposerTarget { return mAttMediaTray; } - private final int getSelectAttrib() { - if (attributes != null) { - SunPageSelection pages = - (SunPageSelection)attributes.get(SunPageSelection.class); - if (pages == SunPageSelection.RANGE) { - return PD_PAGENUMS; - } else if (pages == SunPageSelection.SELECTION) { - return PD_SELECTION; - } else if (pages == SunPageSelection.ALL) { - return PD_ALLPAGES; - } - } - return PD_NOSELECTION; - } + private final boolean getPrintToFileEnabled() { SecurityManager security = System.getSecurityManager(); diff --git a/test/java/awt/PrintJob/SaveDialogTitleTest.java b/test/java/awt/PrintJob/SaveDialogTitleTest.java index b369f0771d748c17e613640003f5c13b3a8da739..4e502290f94bce99a1e99fbb6cad40dd3da8f8ac 100644 --- a/test/java/awt/PrintJob/SaveDialogTitleTest.java +++ b/test/java/awt/PrintJob/SaveDialogTitleTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 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 @@ -23,8 +23,8 @@ /* * @test - * @bug 4851363 - * @summary Tests the save to file dialog has a title + * @bug 4851363 8025988 8025990 + * @summary Tests the save to file dialog has a title. * @run main/manual=yesno/othervm SaveDialogTitleTest */ @@ -37,12 +37,21 @@ public class SaveDialogTitleTest { System.out.print("Once the dialog appears, press OK and the "); System.out.print("Save to File dialog should appear and it "); System.out.println("must have a window title else the test fails."); + System.out.println("To test 8025988: Range should be selected with pages 3 to 8."); + System.out.println("To test 8025990: Paper should be Legal and in Landscape."); Toolkit tk = Toolkit.getDefaultToolkit(); JobAttributes jobAttributes = new JobAttributes(); jobAttributes.setDestination(JobAttributes.DestinationType.FILE); + jobAttributes.setDefaultSelection(JobAttributes.DefaultSelectionType.RANGE); + jobAttributes.setPageRanges(new int[][]{new int[]{3,8}}); + PageAttributes page = new PageAttributes(); + page.setMedia(PageAttributes.MediaType.LEGAL); + page.setOrientationRequested(PageAttributes. + OrientationRequestedType.LANDSCAPE); + PrintJob printJob = tk.getPrintJob(new Frame(), "Save Title Test", - jobAttributes, null); + jobAttributes, page); if (printJob != null) { // in case user cancels. printJob.end(); }