8025988: [macosx] Attribute settings don't work for JobAttributes range
authorjgodinez
Fri, 18 Oct 2013 15:30:10 -0700
changeset 21230 895c9e490351
parent 21229 dfcbcf500680
child 21231 f4e5b541f29d
8025988: [macosx] Attribute settings don't work for JobAttributes range 8025990: [macosx] Attribute settings don't work for JobAttributes setOrientationRequested, setMedia Reviewed-by: prr, jchen
jdk/src/macosx/native/sun/awt/CPrinterJob.m
jdk/src/share/classes/sun/print/RasterPrinterJob.java
jdk/src/windows/classes/sun/awt/windows/WPrinterJob.java
jdk/test/java/awt/PrintJob/SaveDialogTitleTest.java
--- a/jdk/src/macosx/native/sun/awt/CPrinterJob.m	Wed Oct 16 14:00:05 2013 -0700
+++ b/jdk/src/macosx/native/sun/awt/CPrinterJob.m	Fri Oct 18 15:30:10 2013 -0700
@@ -359,7 +359,11 @@
     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 @@
 
     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);
+    }
 }
 
 /*
--- a/jdk/src/share/classes/sun/print/RasterPrinterJob.java	Wed Oct 16 14:00:05 2013 -0700
+++ b/jdk/src/share/classes/sun/print/RasterPrinterJob.java	Fri Oct 18 15:30:10 2013 -0700
@@ -118,6 +118,16 @@
     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
      * limiting the number of bands on hi-res printers and
@@ -800,6 +810,14 @@
         }
    }
 
+   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 @@
             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.
--- a/jdk/src/windows/classes/sun/awt/windows/WPrinterJob.java	Wed Oct 16 14:00:05 2013 -0700
+++ b/jdk/src/windows/classes/sun/awt/windows/WPrinterJob.java	Fri Oct 18 15:30:10 2013 -0700
@@ -183,10 +183,6 @@
     /**
      * 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 @@
         }
     }
 
-    //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 @@
         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();
--- a/jdk/test/java/awt/PrintJob/SaveDialogTitleTest.java	Wed Oct 16 14:00:05 2013 -0700
+++ b/jdk/test/java/awt/PrintJob/SaveDialogTitleTest.java	Fri Oct 18 15:30:10 2013 -0700
@@ -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 @@
         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();
         }