CPrinterJob.m revision 4632
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
#import "java_awt_print_PageFormat.h"
#import "java_awt_print_Pageable.h"
#import "sun_lwawt_macosx_CPrinterJob.h"
#import "sun_lwawt_macosx_CPrinterPageDialog.h"
#import <Cocoa/Cocoa.h>
#import "PrinterView.h"
#import "PrintModel.h"
#import "ThreadUtilities.h"
#import "GeomUtilities.h"
static JNF_MEMBER_CACHE(sjm_printerJob, sjc_CPrinterDialog, "fPrinterJob", "Lsun/lwawt/macosx/CPrinterJob;");
static NSPrintInfo* createDefaultNSPrintInfo();
static void javaPageFormatToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobject srcPageFormat, NSPrintInfo* dst);
static void nsPrintInfoToJavaPrinterJob(JNIEnv* env, NSPrintInfo* src, jobject dstPrinterJob, jobject dstPageable);
static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobject srcPageable, NSPrintInfo* dst);
{
{
{
}
}
// cmc 05/18/04 radr://3160443 : setUpPrintOperationDefaultValues sets the
// page margins to 72, 72, 90, 90 - need to use [NSPrintInfo imageablePageBounds]
// to get values from the printer.
// NOTE: currently [NSPrintInfo imageablePageBounds] does not update itself when
// the user selects a different printer - see radr://3657453. However, rather than
// directly querying the PPD here, we'll let AppKit printing do the work. The AppKit
// printing bug above is set to be fixed for Tiger.
[defaultPrintInfo setBottomMargin: imageableRect.origin.y]; //top and bottom are flipped because [NSPrintInfo imageablePageBounds] returns a flipped NSRect (bottom-left to top-right).
[defaultPrintInfo setRightMargin: [defaultPrintInfo paperSize].width-imageableRect.origin.x-imageableRect.size.width];
[defaultPrintInfo setTopMargin: [defaultPrintInfo paperSize].height-imageableRect.origin.y-imageableRect.size.height];
return defaultPrintInfo;
}
{
// This will look at the NSPrintInfo's margins. If they are out of bounds to the
// imageable area of the page, it will set them to the largest possible size.
// These are flipped because [NSPrintInfo imageablePageBounds] returns a flipped
// NSRect (bottom-left to top-right).
{
}
{
}
{
}
{
}
}
// In AppKit Printing, the rectangle is always oriented. In AppKit Printing, setting
// the rectangle will always set the orientation.
// In java printing, the rectangle is oriented if accessed from PageFormat. It is
// not oriented when accessed from Paper.
{
// NSPrintInfo paperSize is oriented. java Paper is not oriented. Take
// the -[NSPrintInfo orientation] into account when setting the Paper
// rectangle.
switch ([src orientation]) {
case NSPortraitOrientation:
break;
case NSLandscapeOrientation:
break;
default:
break;
}
JNFCallVoidMethod(env, dst, jm_setSize, jPaperW, jPaperH); // AWT_THREADING Safe (known object - always actual Paper)
// Set the imageable area from the margins
JNFCallVoidMethod(env, dst, jm_setImageableArea, jImageX, jImageY, jImageW, jImageH); // AWT_THREADING Safe (known object - always actual Paper)
}
{
// java Paper is always Portrait oriented. Set NSPrintInfo with this
// rectangle, and it's orientation may change. If necessary, be sure to call
// -[NSPrintInfo setOrientation] after this call, which will then
// adjust the -[NSPrintInfo paperSize] as well.
jdouble jPhysicalWidth = JNFCallDoubleMethod(env, src, jm_getWidth); // AWT_THREADING Safe (!appKit)
jdouble jPhysicalHeight = JNFCallDoubleMethod(env, src, jm_getHeight); // AWT_THREADING Safe (!appKit)
// Set the margins from the imageable area
}
{
switch (nsOrientation) {
case NSPortraitOrientation:
break;
case NSLandscapeOrientation:
jOrientation = java_awt_print_PageFormat_LANDSCAPE; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
break;
/*
// AppKit printing doesn't support REVERSE_LANDSCAPE. Radar 2960295.
case NSReverseLandscapeOrientation:
jOrientation = java_awt_print_PageFormat.REVERSE_LANDSCAPE; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
break;
*/
default:
break;
}
// Create a new Paper
// Set the Paper in the PageFormat
}
static void javaPageFormatToNSPrintInfo(JNIEnv* env, jobject srcPrintJob, jobject srcPageFormat, NSPrintInfo* dstPrintInfo)
{
static JNF_MEMBER_CACHE(jm_getPrinterName, sjc_CPrinterJob, "getPrinterName", "()Ljava/lang/String;");
// When setting page information (orientation, size) in NSPrintInfo, set the
// rectangle first. This is because setting the orientation will change the
// rectangle to match.
// Set up the paper. This will force Portrait since java Paper is
// not oriented. Then setting the NSPrintInfo orientation below
// will flip NSPrintInfo's info as necessary.
jobject paper = JNFCallObjectMethod(env, srcPageFormat, jm_getPaper); // AWT_THREADING Safe (!appKit)
break;
[dstPrintInfo setOrientation:NSLandscapeOrientation]; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
break;
// AppKit printing doesn't support REVERSE_LANDSCAPE. Radar 2960295.
[dstPrintInfo setOrientation:NSLandscapeOrientation]; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
break;
default:
break;
}
// <rdar://problem/4022422> NSPrinterInfo is not correctly set to the selected printer
// from the Java side of CPrinterJob. Has always assumed the default printer was the one we wanted.
if (srcPrintJob == NULL) return;
if (printerNameObj == NULL) return;
if (printerName == nil) return;
}
static void nsPrintInfoToJavaPrinterJob(JNIEnv* env, NSPrintInfo* src, jobject dstPrinterJob, jobject dstPageable)
{
static JNF_MEMBER_CACHE(jm_setService, sjc_CPrinterJob, "setPrinterServiceFromNative", "(Ljava/lang/String;)V");
// get the selected printer's name, and set the appropriate PrintService on the Java side
{
JNFCallVoidMethod(env, dstPrinterJob, jm_setCopies, [nsCopies integerValue]); // AWT_THREADING Safe (known object)
}
{
JNFCallVoidMethod(env, dstPrinterJob, jm_setCollated, [nsCollated boolValue] ? JNI_TRUE : JNI_FALSE); // AWT_THREADING Safe (known object)
}
{
if (![nsPrintAllPages boolValue])
{
{
}
{
}
}
JNFCallVoidMethod(env, dstPrinterJob, jm_setPageRange, jFirstPage, jLastPage); // AWT_THREADING Safe (known object)
}
}
static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobject srcPageable, NSPrintInfo* dst)
{
jint copies = JNFCallIntMethod(env, srcPrinterJob, jm_getCopies); // AWT_THREADING Safe (known object)
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)
{
}
else
{
}
}
/*
* Class: sun_lwawt_macosx_EventDispatchAccess
* Method: pumpEventsAndWait
* Signature: ()V
*/
{
static JNF_STATIC_MEMBER_CACHE(jm_currentThread, jc_Thread, "currentThread", "()Ljava/lang/Thread;");
static JNF_MEMBER_CACHE(jm_macosxGetConditional, jc_EventDispatchThread, "_macosxGetConditional", "(Ljava/lang/Object;)Ljava/awt/Conditional;");
static JNF_MEMBER_CACHE(jm_pumpEvents, jc_EventDispatchThread, "pumpEvents", "(Ljava/awt/Conditional;)V");
if (conditional != NULL) {
}
}
/*
* Class: sun_lwawt_macosx_CPrinterJob
* Method: abortDoc
* Signature: ()V
*/
{
// This is only called during the printLoop from the printLoop thread
}
/*
* Class: sun_lwawt_macosx_CPrinterJob
* Method: getDefaultPage
* Signature: (Ljava/awt/print/PageFormat;)V
*/
{
}
/*
* Class: sun_lwawt_macosx_CPrinterJob
* Method: validatePaper
*/
{
}
/*
* Class: sun_lwawt_macosx_CPrinterJob
* Method: createNSPrintInfo
* Signature: ()J
*/
{
// This is used to create the NSPrintInfo for this PrinterJob. Thread
// safety is assured by the java side of this call.
return result;
}
/*
* Class: sun_lwawt_macosx_CPrinterJob
* Method: dispose
* Signature: (J)V
*/
{
if (nsPrintInfo != -1)
{
}
}
/*
* Class: sun_lwawt_macosx_CPrinterJob
* Method: printLoop
* Signature: ()V
*/
{
static JNF_MEMBER_CACHE(jm_getPageFormat, sjc_CPrinterJob, "getPageFormat", "(I)Ljava/awt/print/PageFormat;");
static JNF_MEMBER_CACHE(jm_getPageFormatArea, sjc_CPrinterJob, "getPageFormatArea", "(Ljava/awt/print/PageFormat;)Ljava/awt/geom/Rectangle2D;");
static JNF_MEMBER_CACHE(jm_getPrinterName, sjc_CPrinterJob, "getPrinterName", "()Ljava/lang/String;");
static JNF_MEMBER_CACHE(jm_getPageable, sjc_CPrinterJob, "getPageable", "()Ljava/awt/print/Pageable;");
// Get the first page's PageFormat for setting things up (This introduces
// and is a facet of the same problem in Radar 2818593/2708932).
jobject page = JNFCallObjectMethod(env, jthis, jm_getPageFormat, 0); // AWT_THREADING Safe (!appKit)
jobject pageFormatArea = JNFCallObjectMethod(env, jthis, jm_getPageFormatArea, page); // AWT_THREADING Safe (!appKit)
PrinterView* printerView = [[PrinterView alloc] initWithFrame:JavaToNSRect(env, pageFormatArea) withEnv:env withPrinterJob:jthis];
NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr(JNFCallLongMethod(env, jthis, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object)
// <rdar://problem/4156975> passing jthis CPrinterJob as well, so we can extract the printer name from the current job
// <rdar://problem/4093799> NSPrinterInfo is not correctly set to the selected printer
// from the Java side of CPrinterJob. Had always assumed the default printer was the one we wanted.
if (printerNameObj != NULL) {
if (printerName != nil) {
}
}
// <rdar://problem/4367998> JTable.print attributes are ignored
// Only set this if we got far enough to call runPrintLoopWithView, or we will spin CPrinterJob.print() forever!
{
}
if (pageFormatArea != NULL)
{
}
}
return retVal;
}
/*
* Class: sun_lwawt_macosx_CPrinterPageDialog
* Method: showDialog
* Signature: ()Z
*/
{
NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr(JNFCallLongMethod(env, printerJob, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object)
// <rdar://problem/4156975> passing NULL, because only a CPrinterJob has a real printer associated with it
if (result)
{
}
if (printerJob != NULL)
{
}
{
}
return result;
}
/*
* Class: sun_lwawt_macosx_CPrinterJobDialog
* Method: showDialog
* Signature: ()Z
*/
{
static JNF_MEMBER_CACHE(jm_pageable, jc_CPrinterJobDialog, "fPageable", "Ljava/awt/print/Pageable;");
NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr(JNFCallLongMethod(env, printerJob, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object)
if (result)
{
}
if (printerJob != NULL)
{
}
{
}
return result;
}