4632N/A/*
4632N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4632N/A *
4632N/A * This code is free software; you can redistribute it and/or modify it
4632N/A * under the terms of the GNU General Public License version 2 only, as
4632N/A * published by the Free Software Foundation. Oracle designates this
4632N/A * particular file as subject to the "Classpath" exception as provided
4632N/A * by Oracle in the LICENSE file that accompanied this code.
4632N/A *
4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4632N/A * version 2 for more details (a copy is included in the LICENSE file that
4632N/A * accompanied this code).
4632N/A *
4632N/A * You should have received a copy of the GNU General Public License version
4632N/A * 2 along with this work; if not, write to the Free Software Foundation,
4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4632N/A *
4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4632N/A * or visit www.oracle.com if you need additional information or have any
4632N/A * questions.
4632N/A */
4632N/A
4632N/A
4632N/A#import "java_awt_print_PageFormat.h"
4632N/A#import "java_awt_print_Pageable.h"
4632N/A#import "sun_lwawt_macosx_CPrinterJob.h"
4632N/A#import "sun_lwawt_macosx_CPrinterPageDialog.h"
4632N/A
4632N/A#import <Cocoa/Cocoa.h>
4632N/A#import <JavaNativeFoundation/JavaNativeFoundation.h>
4632N/A
4632N/A#import "PrinterView.h"
4632N/A#import "PrintModel.h"
4632N/A#import "ThreadUtilities.h"
4632N/A#import "GeomUtilities.h"
4632N/A
4632N/Astatic JNF_CLASS_CACHE(sjc_Paper, "java/awt/print/Paper");
4632N/Astatic JNF_CLASS_CACHE(sjc_PageFormat, "java/awt/print/PageFormat");
4632N/Astatic JNF_CLASS_CACHE(sjc_CPrinterJob, "sun/lwawt/macosx/CPrinterJob");
4632N/Astatic JNF_CLASS_CACHE(sjc_CPrinterDialog, "sun/lwawt/macosx/CPrinterDialog");
4632N/Astatic JNF_MEMBER_CACHE(sjm_getNSPrintInfo, sjc_CPrinterJob, "getNSPrintInfo", "()J");
4632N/Astatic JNF_MEMBER_CACHE(sjm_printerJob, sjc_CPrinterDialog, "fPrinterJob", "Lsun/lwawt/macosx/CPrinterJob;");
4632N/A
4632N/Astatic NSPrintInfo* createDefaultNSPrintInfo();
4632N/A
4632N/Astatic void makeBestFit(NSPrintInfo* src);
4632N/A
4632N/Astatic void nsPrintInfoToJavaPaper(JNIEnv* env, NSPrintInfo* src, jobject dst);
4632N/Astatic void javaPaperToNSPrintInfo(JNIEnv* env, jobject src, NSPrintInfo* dst);
4632N/A
4632N/Astatic void nsPrintInfoToJavaPageFormat(JNIEnv* env, NSPrintInfo* src, jobject dst);
4632N/Astatic void javaPageFormatToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobject srcPageFormat, NSPrintInfo* dst);
4632N/A
4632N/Astatic void nsPrintInfoToJavaPrinterJob(JNIEnv* env, NSPrintInfo* src, jobject dstPrinterJob, jobject dstPageable);
4632N/Astatic void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobject srcPageable, NSPrintInfo* dst);
4632N/A
4632N/A
4632N/Astatic NSPrintInfo* createDefaultNSPrintInfo(JNIEnv* env, jstring printer)
4632N/A{
4632N/A NSPrintInfo* defaultPrintInfo = [[NSPrintInfo sharedPrintInfo] copy];
4632N/A if (printer != NULL)
4632N/A {
4632N/A NSPrinter* nsPrinter = [NSPrinter printerWithName:JNFJavaToNSString(env, printer)];
4632N/A if (nsPrinter != nil)
4632N/A {
4632N/A [defaultPrintInfo setPrinter:nsPrinter];
4632N/A }
4632N/A }
4632N/A [defaultPrintInfo setUpPrintOperationDefaultValues];
4632N/A
4632N/A // cmc 05/18/04 radr://3160443 : setUpPrintOperationDefaultValues sets the
4632N/A // page margins to 72, 72, 90, 90 - need to use [NSPrintInfo imageablePageBounds]
4632N/A // to get values from the printer.
4632N/A // NOTE: currently [NSPrintInfo imageablePageBounds] does not update itself when
4632N/A // the user selects a different printer - see radr://3657453. However, rather than
4632N/A // directly querying the PPD here, we'll let AppKit printing do the work. The AppKit
4632N/A // printing bug above is set to be fixed for Tiger.
4632N/A NSRect imageableRect = [defaultPrintInfo imageablePageBounds];
4632N/A [defaultPrintInfo setLeftMargin: imageableRect.origin.x];
4632N/A [defaultPrintInfo setBottomMargin: imageableRect.origin.y]; //top and bottom are flipped because [NSPrintInfo imageablePageBounds] returns a flipped NSRect (bottom-left to top-right).
4632N/A [defaultPrintInfo setRightMargin: [defaultPrintInfo paperSize].width-imageableRect.origin.x-imageableRect.size.width];
4632N/A [defaultPrintInfo setTopMargin: [defaultPrintInfo paperSize].height-imageableRect.origin.y-imageableRect.size.height];
4632N/A
4632N/A return defaultPrintInfo;
4632N/A}
4632N/A
4632N/Astatic void makeBestFit(NSPrintInfo* src)
4632N/A{
4632N/A // This will look at the NSPrintInfo's margins. If they are out of bounds to the
4632N/A // imageable area of the page, it will set them to the largest possible size.
4632N/A
4632N/A NSRect imageable = [src imageablePageBounds];
4632N/A
4632N/A NSSize paperSize = [src paperSize];
4632N/A
4632N/A CGFloat fullLeftM = imageable.origin.x;
4632N/A CGFloat fullRightM = paperSize.width - (imageable.origin.x + imageable.size.width);
4632N/A
4632N/A // These are flipped because [NSPrintInfo imageablePageBounds] returns a flipped
4632N/A // NSRect (bottom-left to top-right).
4632N/A CGFloat fullTopM = paperSize.height - (imageable.origin.y + imageable.size.height);
4632N/A CGFloat fullBottomM = imageable.origin.y;
4632N/A
4632N/A if (fullLeftM > [src leftMargin])
4632N/A {
4632N/A [src setLeftMargin:fullLeftM];
4632N/A }
4632N/A
4632N/A if (fullRightM > [src rightMargin])
4632N/A {
4632N/A [src setRightMargin:fullRightM];
4632N/A }
4632N/A
4632N/A if (fullTopM > [src topMargin])
4632N/A {
4632N/A [src setTopMargin:fullTopM];
4632N/A }
4632N/A
4632N/A if (fullBottomM > [src bottomMargin])
4632N/A {
4632N/A [src setBottomMargin:fullBottomM];
4632N/A }
4632N/A}
4632N/A
4632N/A// In AppKit Printing, the rectangle is always oriented. In AppKit Printing, setting
4632N/A// the rectangle will always set the orientation.
4632N/A// In java printing, the rectangle is oriented if accessed from PageFormat. It is
4632N/A// not oriented when accessed from Paper.
4632N/A
4632N/Astatic void nsPrintInfoToJavaPaper(JNIEnv* env, NSPrintInfo* src, jobject dst)
4632N/A{
4632N/A static JNF_MEMBER_CACHE(jm_setSize, sjc_Paper, "setSize", "(DD)V");
4632N/A static JNF_MEMBER_CACHE(jm_setImageableArea, sjc_Paper, "setImageableArea", "(DDDD)V");
4632N/A
4632N/A jdouble jPaperW, jPaperH;
4632N/A
4632N/A // NSPrintInfo paperSize is oriented. java Paper is not oriented. Take
4632N/A // the -[NSPrintInfo orientation] into account when setting the Paper
4632N/A // rectangle.
4632N/A
4632N/A NSSize paperSize = [src paperSize];
4632N/A switch ([src orientation]) {
4632N/A case NSPortraitOrientation:
4632N/A jPaperW = paperSize.width;
4632N/A jPaperH = paperSize.height;
4632N/A break;
4632N/A
4632N/A case NSLandscapeOrientation:
4632N/A jPaperW = paperSize.height;
4632N/A jPaperH = paperSize.width;
4632N/A break;
4632N/A
4632N/A default:
4632N/A jPaperW = paperSize.width;
4632N/A jPaperH = paperSize.height;
4632N/A break;
4632N/A }
4632N/A
4632N/A JNFCallVoidMethod(env, dst, jm_setSize, jPaperW, jPaperH); // AWT_THREADING Safe (known object - always actual Paper)
4632N/A
4632N/A // Set the imageable area from the margins
4632N/A CGFloat leftM = [src leftMargin];
4632N/A CGFloat rightM = [src rightMargin];
4632N/A CGFloat topM = [src topMargin];
4632N/A CGFloat bottomM = [src bottomMargin];
4632N/A
4632N/A jdouble jImageX = leftM;
4632N/A jdouble jImageY = topM;
4632N/A jdouble jImageW = jPaperW - (leftM + rightM);
4632N/A jdouble jImageH = jPaperH - (topM + bottomM);
4632N/A
4632N/A JNFCallVoidMethod(env, dst, jm_setImageableArea, jImageX, jImageY, jImageW, jImageH); // AWT_THREADING Safe (known object - always actual Paper)
4632N/A}
4632N/A
4632N/Astatic void javaPaperToNSPrintInfo(JNIEnv* env, jobject src, NSPrintInfo* dst)
4632N/A{
4632N/A AWT_ASSERT_NOT_APPKIT_THREAD;
4632N/A
4632N/A static JNF_MEMBER_CACHE(jm_getWidth, sjc_Paper, "getWidth", "()D");
4632N/A static JNF_MEMBER_CACHE(jm_getHeight, sjc_Paper, "getHeight", "()D");
4632N/A static JNF_MEMBER_CACHE(jm_getImageableX, sjc_Paper, "getImageableX", "()D");
4632N/A static JNF_MEMBER_CACHE(jm_getImageableY, sjc_Paper, "getImageableY", "()D");
4632N/A static JNF_MEMBER_CACHE(jm_getImageableW, sjc_Paper, "getImageableWidth", "()D");
4632N/A static JNF_MEMBER_CACHE(jm_getImageableH, sjc_Paper, "getImageableHeight", "()D");
4632N/A
4632N/A // java Paper is always Portrait oriented. Set NSPrintInfo with this
4632N/A // rectangle, and it's orientation may change. If necessary, be sure to call
4632N/A // -[NSPrintInfo setOrientation] after this call, which will then
4632N/A // adjust the -[NSPrintInfo paperSize] as well.
4632N/A
4632N/A jdouble jPhysicalWidth = JNFCallDoubleMethod(env, src, jm_getWidth); // AWT_THREADING Safe (!appKit)
4632N/A jdouble jPhysicalHeight = JNFCallDoubleMethod(env, src, jm_getHeight); // AWT_THREADING Safe (!appKit)
4632N/A
4632N/A [dst setPaperSize:NSMakeSize(jPhysicalWidth, jPhysicalHeight)];
4632N/A
4632N/A // Set the margins from the imageable area
4632N/A jdouble jImageX = JNFCallDoubleMethod(env, src, jm_getImageableX); // AWT_THREADING Safe (!appKit)
4632N/A jdouble jImageY = JNFCallDoubleMethod(env, src, jm_getImageableY); // AWT_THREADING Safe (!appKit)
4632N/A jdouble jImageW = JNFCallDoubleMethod(env, src, jm_getImageableW); // AWT_THREADING Safe (!appKit)
4632N/A jdouble jImageH = JNFCallDoubleMethod(env, src, jm_getImageableH); // AWT_THREADING Safe (!appKit)
4632N/A
4632N/A [dst setLeftMargin:(CGFloat)jImageX];
4632N/A [dst setTopMargin:(CGFloat)jImageY];
4632N/A [dst setRightMargin:(CGFloat)(jPhysicalWidth - jImageW - jImageX)];
4632N/A [dst setBottomMargin:(CGFloat)(jPhysicalHeight - jImageH - jImageY)];
4632N/A}
4632N/A
4632N/Astatic void nsPrintInfoToJavaPageFormat(JNIEnv* env, NSPrintInfo* src, jobject dst)
4632N/A{
4632N/A AWT_ASSERT_NOT_APPKIT_THREAD;
4632N/A
4632N/A static JNF_MEMBER_CACHE(jm_setOrientation, sjc_PageFormat, "setOrientation", "(I)V");
4632N/A static JNF_MEMBER_CACHE(jm_setPaper, sjc_PageFormat, "setPaper", "(Ljava/awt/print/Paper;)V");
4632N/A static JNF_CTOR_CACHE(jm_Paper_ctor, sjc_Paper, "()V");
4632N/A
4632N/A jint jOrientation;
4632N/A NSPrintingOrientation nsOrientation = [src orientation];
4632N/A switch (nsOrientation) {
4632N/A case NSPortraitOrientation:
4632N/A jOrientation = java_awt_print_PageFormat_PORTRAIT;
4632N/A break;
4632N/A
4632N/A case NSLandscapeOrientation:
4632N/A jOrientation = java_awt_print_PageFormat_LANDSCAPE; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
4632N/A break;
4632N/A
4632N/A/*
4632N/A // AppKit printing doesn't support REVERSE_LANDSCAPE. Radar 2960295.
4632N/A case NSReverseLandscapeOrientation:
4632N/A jOrientation = java_awt_print_PageFormat.REVERSE_LANDSCAPE; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
4632N/A break;
4632N/A*/
4632N/A
4632N/A default:
4632N/A jOrientation = java_awt_print_PageFormat_PORTRAIT;
4632N/A break;
4632N/A }
4632N/A
4632N/A JNFCallVoidMethod(env, dst, jm_setOrientation, jOrientation); // AWT_THREADING Safe (!appKit)
4632N/A
4632N/A // Create a new Paper
4632N/A jobject paper = JNFNewObject(env, jm_Paper_ctor); // AWT_THREADING Safe (known object)
4632N/A
4632N/A nsPrintInfoToJavaPaper(env, src, paper);
4632N/A
4632N/A // Set the Paper in the PageFormat
4632N/A JNFCallVoidMethod(env, dst, jm_setPaper, paper); // AWT_THREADING Safe (!appKit)
4632N/A
4632N/A (*env)->DeleteLocalRef(env, paper);
4632N/A}
4632N/A
4632N/Astatic void javaPageFormatToNSPrintInfo(JNIEnv* env, jobject srcPrintJob, jobject srcPageFormat, NSPrintInfo* dstPrintInfo)
4632N/A{
4632N/A AWT_ASSERT_NOT_APPKIT_THREAD;
4632N/A
4632N/A static JNF_MEMBER_CACHE(jm_getOrientation, sjc_PageFormat, "getOrientation", "()I");
4632N/A static JNF_MEMBER_CACHE(jm_getPaper, sjc_PageFormat, "getPaper", "()Ljava/awt/print/Paper;");
4632N/A static JNF_MEMBER_CACHE(jm_getPrinterName, sjc_CPrinterJob, "getPrinterName", "()Ljava/lang/String;");
4632N/A
4632N/A // When setting page information (orientation, size) in NSPrintInfo, set the
4632N/A // rectangle first. This is because setting the orientation will change the
4632N/A // rectangle to match.
4632N/A
4632N/A // Set up the paper. This will force Portrait since java Paper is
4632N/A // not oriented. Then setting the NSPrintInfo orientation below
4632N/A // will flip NSPrintInfo's info as necessary.
4632N/A jobject paper = JNFCallObjectMethod(env, srcPageFormat, jm_getPaper); // AWT_THREADING Safe (!appKit)
4632N/A javaPaperToNSPrintInfo(env, paper, dstPrintInfo);
4632N/A (*env)->DeleteLocalRef(env, paper);
4632N/A
4632N/A switch (JNFCallIntMethod(env, srcPageFormat, jm_getOrientation)) { // AWT_THREADING Safe (!appKit)
4632N/A case java_awt_print_PageFormat_PORTRAIT:
4632N/A [dstPrintInfo setOrientation:NSPortraitOrientation];
4632N/A break;
4632N/A
4632N/A case java_awt_print_PageFormat_LANDSCAPE:
4632N/A [dstPrintInfo setOrientation:NSLandscapeOrientation]; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
4632N/A break;
4632N/A
4632N/A // AppKit printing doesn't support REVERSE_LANDSCAPE. Radar 2960295.
4632N/A case java_awt_print_PageFormat_REVERSE_LANDSCAPE:
4632N/A [dstPrintInfo setOrientation:NSLandscapeOrientation]; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
4632N/A break;
4632N/A
4632N/A default:
4632N/A [dstPrintInfo setOrientation:NSPortraitOrientation];
4632N/A break;
4632N/A }
4632N/A
4632N/A // <rdar://problem/4022422> NSPrinterInfo is not correctly set to the selected printer
4632N/A // from the Java side of CPrinterJob. Has always assumed the default printer was the one we wanted.
4632N/A if (srcPrintJob == NULL) return;
4632N/A jobject printerNameObj = JNFCallObjectMethod(env, srcPrintJob, jm_getPrinterName);
4632N/A if (printerNameObj == NULL) return;
4632N/A NSString *printerName = JNFJavaToNSString(env, printerNameObj);
4632N/A if (printerName == nil) return;
4632N/A NSPrinter *printer = [NSPrinter printerWithName:printerName];
4632N/A if (printer == nil) return;
4632N/A [dstPrintInfo setPrinter:printer];
4632N/A}
4632N/A
4632N/Astatic void nsPrintInfoToJavaPrinterJob(JNIEnv* env, NSPrintInfo* src, jobject dstPrinterJob, jobject dstPageable)
4632N/A{
4632N/A static JNF_MEMBER_CACHE(jm_setService, sjc_CPrinterJob, "setPrinterServiceFromNative", "(Ljava/lang/String;)V");
4632N/A static JNF_MEMBER_CACHE(jm_setCopies, sjc_CPrinterJob, "setCopies", "(I)V");
4632N/A static JNF_MEMBER_CACHE(jm_setCollated, sjc_CPrinterJob, "setCollated", "(Z)V");
4632N/A static JNF_MEMBER_CACHE(jm_setPageRange, sjc_CPrinterJob, "setPageRange", "(II)V");
4632N/A
4632N/A // get the selected printer's name, and set the appropriate PrintService on the Java side
4632N/A NSString *name = [[src printer] name];
4632N/A jstring printerName = JNFNSToJavaString(env, name);
4632N/A JNFCallVoidMethod(env, dstPrinterJob, jm_setService, printerName);
4632N/A
4632N/A
4632N/A NSMutableDictionary* printingDictionary = [src dictionary];
4632N/A
4632N/A NSNumber* nsCopies = [printingDictionary objectForKey:NSPrintCopies];
4632N/A if ([nsCopies respondsToSelector:@selector(integerValue)])
4632N/A {
4632N/A JNFCallVoidMethod(env, dstPrinterJob, jm_setCopies, [nsCopies integerValue]); // AWT_THREADING Safe (known object)
4632N/A }
4632N/A
4632N/A NSNumber* nsCollated = [printingDictionary objectForKey:NSPrintMustCollate];
4632N/A if ([nsCollated respondsToSelector:@selector(boolValue)])
4632N/A {
4632N/A JNFCallVoidMethod(env, dstPrinterJob, jm_setCollated, [nsCollated boolValue] ? JNI_TRUE : JNI_FALSE); // AWT_THREADING Safe (known object)
4632N/A }
4632N/A
4632N/A NSNumber* nsPrintAllPages = [printingDictionary objectForKey:NSPrintAllPages];
4632N/A if ([nsPrintAllPages respondsToSelector:@selector(boolValue)])
4632N/A {
4632N/A jint jFirstPage = 0, jLastPage = java_awt_print_Pageable_UNKNOWN_NUMBER_OF_PAGES;
4632N/A if (![nsPrintAllPages boolValue])
4632N/A {
4632N/A NSNumber* nsFirstPage = [printingDictionary objectForKey:NSPrintFirstPage];
4632N/A if ([nsFirstPage respondsToSelector:@selector(integerValue)])
4632N/A {
4632N/A jFirstPage = [nsFirstPage integerValue] - 1;
4632N/A }
4632N/A
4632N/A NSNumber* nsLastPage = [printingDictionary objectForKey:NSPrintLastPage];
4632N/A if ([nsLastPage respondsToSelector:@selector(integerValue)])
4632N/A {
4632N/A jLastPage = [nsLastPage integerValue] - 1;
4632N/A }
4632N/A }
4632N/A
4632N/A JNFCallVoidMethod(env, dstPrinterJob, jm_setPageRange, jFirstPage, jLastPage); // AWT_THREADING Safe (known object)
4632N/A }
4632N/A}
4632N/A
4632N/Astatic void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobject srcPageable, NSPrintInfo* dst)
4632N/A{
4632N/A AWT_ASSERT_NOT_APPKIT_THREAD;
4632N/A
4632N/A static JNF_CLASS_CACHE(jc_Pageable, "java/awt/print/Pageable");
4632N/A static JNF_MEMBER_CACHE(jm_getCopies, sjc_CPrinterJob, "getCopiesInt", "()I");
4632N/A static JNF_MEMBER_CACHE(jm_isCollated, sjc_CPrinterJob, "isCollated", "()Z");
4632N/A static JNF_MEMBER_CACHE(jm_getNumberOfPages, jc_Pageable, "getNumberOfPages", "()I");
4632N/A
4632N/A NSMutableDictionary* printingDictionary = [dst dictionary];
4632N/A
4632N/A jint copies = JNFCallIntMethod(env, srcPrinterJob, jm_getCopies); // AWT_THREADING Safe (known object)
4632N/A [printingDictionary setObject:[NSNumber numberWithInteger:copies] forKey:NSPrintCopies];
4632N/A
4632N/A jboolean collated = JNFCallBooleanMethod(env, srcPrinterJob, jm_isCollated); // AWT_THREADING Safe (known object)
4632N/A [printingDictionary setObject:[NSNumber numberWithBool:collated ? YES : NO] forKey:NSPrintMustCollate];
4632N/A
4632N/A jint jNumPages = JNFCallIntMethod(env, srcPageable, jm_getNumberOfPages); // AWT_THREADING Safe (!appKit)
4632N/A if (jNumPages != java_awt_print_Pageable_UNKNOWN_NUMBER_OF_PAGES)
4632N/A {
4632N/A [printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages];
4632N/A
4632N/A [printingDictionary setObject:[NSNumber numberWithInteger:1] forKey:NSPrintFirstPage];
4632N/A [printingDictionary setObject:[NSNumber numberWithInteger:jNumPages] forKey:NSPrintLastPage];
4632N/A }
4632N/A else
4632N/A {
4632N/A [printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintAllPages];
4632N/A }
4632N/A}
4632N/A
4632N/A/*
4632N/A * Class: sun_lwawt_macosx_EventDispatchAccess
4632N/A * Method: pumpEventsAndWait
4632N/A * Signature: ()V
4632N/A */
4632N/AJNIEXPORT void JNICALL Java_sun_lwawt_macosx_EventDispatchAccess_pumpEventsAndWait
4632N/A(JNIEnv *env, jobject eda)
4632N/A{
4632N/A static JNF_CLASS_CACHE(jc_Thread, "java/lang/Thread");
4632N/A static JNF_STATIC_MEMBER_CACHE(jm_currentThread, jc_Thread, "currentThread", "()Ljava/lang/Thread;");
4632N/A static JNF_CLASS_CACHE(jc_EventDispatchThread, "java/awt/EventDispatchThread");
4632N/A static JNF_MEMBER_CACHE(jm_macosxGetConditional, jc_EventDispatchThread, "_macosxGetConditional", "(Ljava/lang/Object;)Ljava/awt/Conditional;");
4632N/A static JNF_MEMBER_CACHE(jm_pumpEvents, jc_EventDispatchThread, "pumpEvents", "(Ljava/awt/Conditional;)V");
4632N/A
4632N/AJNF_COCOA_DURING(env);
4632N/A
4632N/A jobject thread = JNFCallStaticObjectMethod(env, jm_currentThread);
4632N/A jobject conditional = JNFCallObjectMethod(env, thread, jm_macosxGetConditional, eda);
4632N/A if (conditional != NULL) {
4632N/A JNFCallVoidMethod(env, thread, jm_pumpEvents, conditional);
4632N/A }
4632N/A
4632N/AJNF_COCOA_HANDLE(env);
4632N/A}
4632N/A
4632N/A/*
4632N/A * Class: sun_lwawt_macosx_CPrinterJob
4632N/A * Method: abortDoc
4632N/A * Signature: ()V
4632N/A */
4632N/AJNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob_abortDoc
4632N/A (JNIEnv *env, jobject jthis)
4632N/A{
4632N/AJNF_COCOA_ENTER(env);
4632N/A // This is only called during the printLoop from the printLoop thread
4632N/A NSPrintOperation* printLoop = [NSPrintOperation currentOperation];
4632N/A NSPrintInfo* printInfo = [printLoop printInfo];
4632N/A [printInfo setJobDisposition:NSPrintCancelJob];
4632N/AJNF_COCOA_EXIT(env);
4632N/A}
4632N/A
4632N/A/*
4632N/A * Class: sun_lwawt_macosx_CPrinterJob
4632N/A * Method: getDefaultPage
4632N/A * Signature: (Ljava/awt/print/PageFormat;)V
4632N/A */
4632N/AJNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob_getDefaultPage
4632N/A (JNIEnv *env, jobject jthis, jobject page)
4632N/A{
4632N/AJNF_COCOA_ENTER(env);
4632N/A NSPrintInfo* printInfo = createDefaultNSPrintInfo(env, NULL);
4632N/A
4632N/A nsPrintInfoToJavaPageFormat(env, printInfo, page);
4632N/A
4632N/A [printInfo release];
4632N/AJNF_COCOA_EXIT(env);
4632N/A}
4632N/A
4632N/A/*
4632N/A * Class: sun_lwawt_macosx_CPrinterJob
4632N/A * Method: validatePaper
4632N/A * Signature: (Ljava/awt/print/Paper;Ljava/awt/print/Paper;)V
4632N/A */
4632N/AJNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob_validatePaper
4632N/A (JNIEnv *env, jobject jthis, jobject origpaper, jobject newpaper)
4632N/A{
4632N/AJNF_COCOA_ENTER(env);
4632N/A
4632N/A NSPrintInfo* printInfo = createDefaultNSPrintInfo(env, NULL);
4632N/A javaPaperToNSPrintInfo(env, origpaper, printInfo);
4632N/A makeBestFit(printInfo);
4632N/A nsPrintInfoToJavaPaper(env, printInfo, newpaper);
4632N/A [printInfo release];
4632N/A
4632N/AJNF_COCOA_EXIT(env);
4632N/A}
4632N/A
4632N/A/*
4632N/A * Class: sun_lwawt_macosx_CPrinterJob
4632N/A * Method: createNSPrintInfo
4632N/A * Signature: ()J
4632N/A */
4632N/AJNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CPrinterJob_createNSPrintInfo
4632N/A (JNIEnv *env, jobject jthis)
4632N/A{
4632N/A jlong result = -1;
4632N/AJNF_COCOA_ENTER(env);
4632N/A // This is used to create the NSPrintInfo for this PrinterJob. Thread
4632N/A // safety is assured by the java side of this call.
4632N/A
4632N/A NSPrintInfo* printInfo = createDefaultNSPrintInfo(env, NULL);
4632N/A if (printInfo) CFRetain(printInfo); // GC
4632N/A [printInfo release];
4632N/A
4632N/A result = ptr_to_jlong(printInfo);
4632N/A
4632N/AJNF_COCOA_EXIT(env);
4632N/A return result;
4632N/A}
4632N/A
4632N/A/*
4632N/A * Class: sun_lwawt_macosx_CPrinterJob
4632N/A * Method: dispose
4632N/A * Signature: (J)V
4632N/A */
4632N/AJNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob_dispose
4632N/A (JNIEnv *env, jobject jthis, jlong nsPrintInfo)
4632N/A{
4632N/AJNF_COCOA_ENTER(env);
4632N/A if (nsPrintInfo != -1)
4632N/A {
4632N/A NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr(nsPrintInfo);
4632N/A if (printInfo) CFRelease(printInfo); // GC
4632N/A }
4632N/AJNF_COCOA_EXIT(env);
4632N/A}
4632N/A
4632N/A
4632N/A/*
4632N/A * Class: sun_lwawt_macosx_CPrinterJob
4632N/A * Method: printLoop
4632N/A * Signature: ()V
4632N/A */
4632N/AJNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CPrinterJob_printLoop
4632N/A (JNIEnv *env, jobject jthis, jboolean blocks, jint firstPage, jint lastPage)
4632N/A{
4632N/A AWT_ASSERT_NOT_APPKIT_THREAD;
4632N/A
4632N/A static JNF_MEMBER_CACHE(jm_getPageFormat, sjc_CPrinterJob, "getPageFormat", "(I)Ljava/awt/print/PageFormat;");
4632N/A static JNF_MEMBER_CACHE(jm_getPageFormatArea, sjc_CPrinterJob, "getPageFormatArea", "(Ljava/awt/print/PageFormat;)Ljava/awt/geom/Rectangle2D;");
4632N/A static JNF_MEMBER_CACHE(jm_getPrinterName, sjc_CPrinterJob, "getPrinterName", "()Ljava/lang/String;");
4632N/A static JNF_MEMBER_CACHE(jm_getPageable, sjc_CPrinterJob, "getPageable", "()Ljava/awt/print/Pageable;");
4632N/A
4632N/A jboolean retVal = JNI_FALSE;
4632N/A
4632N/AJNF_COCOA_ENTER(env);
4632N/A // Get the first page's PageFormat for setting things up (This introduces
4632N/A // and is a facet of the same problem in Radar 2818593/2708932).
4632N/A jobject page = JNFCallObjectMethod(env, jthis, jm_getPageFormat, 0); // AWT_THREADING Safe (!appKit)
4632N/A if (page != NULL) {
4632N/A jobject pageFormatArea = JNFCallObjectMethod(env, jthis, jm_getPageFormatArea, page); // AWT_THREADING Safe (!appKit)
4632N/A
4632N/A PrinterView* printerView = [[PrinterView alloc] initWithFrame:JavaToNSRect(env, pageFormatArea) withEnv:env withPrinterJob:jthis];
4632N/A [printerView setFirstPage:firstPage lastPage:lastPage];
4632N/A
4632N/A NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr(JNFCallLongMethod(env, jthis, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object)
4632N/A
4632N/A // <rdar://problem/4156975> passing jthis CPrinterJob as well, so we can extract the printer name from the current job
4632N/A javaPageFormatToNSPrintInfo(env, jthis, page, printInfo);
4632N/A
4632N/A // <rdar://problem/4093799> NSPrinterInfo is not correctly set to the selected printer
4632N/A // from the Java side of CPrinterJob. Had always assumed the default printer was the one we wanted.
4632N/A jobject printerNameObj = JNFCallObjectMethod(env, jthis, jm_getPrinterName);
4632N/A if (printerNameObj != NULL) {
4632N/A NSString *printerName = JNFJavaToNSString(env, printerNameObj);
4632N/A if (printerName != nil) {
4632N/A NSPrinter *printer = [NSPrinter printerWithName:printerName];
4632N/A if (printer != nil) [printInfo setPrinter:printer];
4632N/A }
4632N/A }
4632N/A
4632N/A // <rdar://problem/4367998> JTable.print attributes are ignored
4632N/A jobject pageable = JNFCallObjectMethod(env, jthis, jm_getPageable); // AWT_THREADING Safe (!appKit)
4632N/A javaPrinterJobToNSPrintInfo(env, jthis, pageable, printInfo);
4632N/A
4632N/A PrintModel* printModel = [[PrintModel alloc] initWithPrintInfo:printInfo];
4632N/A
4632N/A (void)[printModel runPrintLoopWithView:printerView waitUntilDone:blocks withEnv:env];
4632N/A
4632N/A // Only set this if we got far enough to call runPrintLoopWithView, or we will spin CPrinterJob.print() forever!
4632N/A retVal = JNI_TRUE;
4632N/A
4632N/A [printModel release];
4632N/A [printerView release];
4632N/A
4632N/A if (page != NULL)
4632N/A {
4632N/A (*env)->DeleteLocalRef(env, page);
4632N/A }
4632N/A
4632N/A if (pageFormatArea != NULL)
4632N/A {
4632N/A (*env)->DeleteLocalRef(env, pageFormatArea);
4632N/A }
4632N/A }
4632N/AJNF_COCOA_EXIT(env);
4632N/A return retVal;
4632N/A}
4632N/A
4632N/A/*
4632N/A * Class: sun_lwawt_macosx_CPrinterPageDialog
4632N/A * Method: showDialog
4632N/A * Signature: ()Z
4632N/A */
4632N/AJNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CPrinterPageDialog_showDialog
4632N/A (JNIEnv *env, jobject jthis)
4632N/A{
4632N/A
4632N/A static JNF_CLASS_CACHE(jc_CPrinterPageDialog, "sun/lwawt/macosx/CPrinterPageDialog");
4632N/A static JNF_MEMBER_CACHE(jm_page, jc_CPrinterPageDialog, "fPage", "Ljava/awt/print/PageFormat;");
4632N/A
4632N/A jboolean result = JNI_FALSE;
4632N/AJNF_COCOA_ENTER(env);
4632N/A jobject printerJob = JNFGetObjectField(env, jthis, sjm_printerJob);
4632N/A NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr(JNFCallLongMethod(env, printerJob, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object)
4632N/A
4632N/A jobject page = JNFGetObjectField(env, jthis, jm_page);
4632N/A
4632N/A // <rdar://problem/4156975> passing NULL, because only a CPrinterJob has a real printer associated with it
4632N/A javaPageFormatToNSPrintInfo(env, NULL, page, printInfo);
4632N/A
4632N/A PrintModel* printModel = [[PrintModel alloc] initWithPrintInfo:printInfo];
4632N/A result = [printModel runPageSetup];
4632N/A [printModel release];
4632N/A
4632N/A if (result)
4632N/A {
4632N/A nsPrintInfoToJavaPageFormat(env, printInfo, page);
4632N/A }
4632N/A
4632N/A if (printerJob != NULL)
4632N/A {
4632N/A (*env)->DeleteLocalRef(env, printerJob);
4632N/A }
4632N/A
4632N/A if (page != NULL)
4632N/A {
4632N/A (*env)->DeleteLocalRef(env, page);
4632N/A }
4632N/A
4632N/AJNF_COCOA_EXIT(env);
4632N/A return result;
4632N/A}
4632N/A
4632N/A/*
4632N/A * Class: sun_lwawt_macosx_CPrinterJobDialog
4632N/A * Method: showDialog
4632N/A * Signature: ()Z
4632N/A */
4632N/AJNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CPrinterJobDialog_showDialog
4632N/A (JNIEnv *env, jobject jthis)
4632N/A{
4632N/A static JNF_CLASS_CACHE(jc_CPrinterJobDialog, "sun/lwawt/macosx/CPrinterJobDialog");
4632N/A static JNF_MEMBER_CACHE(jm_pageable, jc_CPrinterJobDialog, "fPageable", "Ljava/awt/print/Pageable;");
4632N/A
4632N/A jboolean result = JNI_FALSE;
4632N/AJNF_COCOA_ENTER(env);
4632N/A jobject printerJob = JNFGetObjectField(env, jthis, sjm_printerJob);
4632N/A NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr(JNFCallLongMethod(env, printerJob, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object)
4632N/A
4632N/A jobject pageable = JNFGetObjectField(env, jthis, jm_pageable);
4632N/A
4632N/A javaPrinterJobToNSPrintInfo(env, printerJob, pageable, printInfo);
4632N/A
4632N/A PrintModel* printModel = [[PrintModel alloc] initWithPrintInfo:printInfo];
4632N/A result = [printModel runJobSetup];
4632N/A [printModel release];
4632N/A
4632N/A if (result)
4632N/A {
4632N/A nsPrintInfoToJavaPrinterJob(env, printInfo, printerJob, pageable);
4632N/A }
4632N/A
4632N/A if (printerJob != NULL)
4632N/A {
4632N/A (*env)->DeleteLocalRef(env, printerJob);
4632N/A }
4632N/A
4632N/A if (pageable != NULL)
4632N/A {
4632N/A (*env)->DeleteLocalRef(env, pageable);
4632N/A }
4632N/A
4632N/AJNF_COCOA_EXIT(env);
4632N/A return result;
4632N/A}