< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m

Print this page
rev 54094 : 8257853: Remove dependencies on JNF's JNI utility functions in AWT and 2D code
rev 54095 : 8259343: [macOS] Update JNI error handling in Cocoa code.
rev 54097 : 8259869: [macOS] Remove desktop module dependencies on JNF Reference APIs
rev 54098 : 8260616: Removing remaining JNF dependencies in the java.desktop module
8259729: Missed JNFInstanceOf -> IsInstanceOf conversion

*** 26,52 **** #import "PrinterView.h" #import "java_awt_print_Pageable.h" #import "java_awt_print_PageFormat.h" - #import <JavaNativeFoundation/JavaNativeFoundation.h> - #import "ThreadUtilities.h" #import "GeomUtilities.h" ! ! static JNF_CLASS_CACHE(sjc_CPrinterJob, "sun/lwawt/macosx/CPrinterJob"); ! static JNF_CLASS_CACHE(sjc_PageFormat, "java/awt/print/PageFormat"); @implementation PrinterView - (id)initWithFrame:(NSRect)aRect withEnv:(JNIEnv*)env withPrinterJob:(jobject)printerJob { self = [super initWithFrame:aRect]; if (self) { ! fPrinterJob = JNFNewGlobalRef(env, printerJob); fCurPageFormat = NULL; fCurPainter = NULL; fCurPeekGraphics = NULL; } return self; --- 26,51 ---- #import "PrinterView.h" #import "java_awt_print_Pageable.h" #import "java_awt_print_PageFormat.h" #import "ThreadUtilities.h" #import "GeomUtilities.h" + #import "JNIUtilities.h" ! static jclass sjc_CPrinterJob = NULL; ! #define GET_CPRINTERJOB_CLASS() (sjc_CPrinterJob, "sun/lwawt/macosx/CPrinterJob"); ! #define GET_CPRINTERJOB_CLASS_RETURN(ret) GET_CLASS_RETURN(sjc_CPrinterJob, "sun/lwawt/macosx/CPrinterJob", ret); @implementation PrinterView - (id)initWithFrame:(NSRect)aRect withEnv:(JNIEnv*)env withPrinterJob:(jobject)printerJob { self = [super initWithFrame:aRect]; if (self) { ! fPrinterJob = (*env)->NewGlobalRef(env, printerJob); fCurPageFormat = NULL; fCurPainter = NULL; fCurPeekGraphics = NULL; } return self;
*** 54,74 **** - (void)releaseReferences:(JNIEnv*)env { if (fCurPageFormat != NULL) { ! JNFDeleteGlobalRef(env, fCurPageFormat); fCurPageFormat = NULL; } if (fCurPainter != NULL) { ! JNFDeleteGlobalRef(env, fCurPainter); fCurPainter = NULL; } if (fCurPeekGraphics != NULL) { ! JNFDeleteGlobalRef(env, fCurPeekGraphics); fCurPeekGraphics = NULL; } } - (void)setFirstPage:(jint)firstPage lastPage:(jint)lastPage { --- 53,73 ---- - (void)releaseReferences:(JNIEnv*)env { if (fCurPageFormat != NULL) { ! (*env)->DeleteGlobalRef(env, fCurPageFormat); fCurPageFormat = NULL; } if (fCurPainter != NULL) { ! (*env)->DeleteGlobalRef(env, fCurPainter); fCurPainter = NULL; } if (fCurPeekGraphics != NULL) { ! (*env)->DeleteGlobalRef(env, fCurPeekGraphics); fCurPeekGraphics = NULL; } } - (void)setFirstPage:(jint)firstPage lastPage:(jint)lastPage {
*** 78,96 **** - (void)drawRect:(NSRect)aRect { AWT_ASSERT_NOT_APPKIT_THREAD; ! static JNF_MEMBER_CACHE(jm_printToPathGraphics, sjc_CPrinterJob, "printToPathGraphics", "(Lsun/print/PeekGraphics;Ljava/awt/print/PrinterJob;Ljava/awt/print/Printable;Ljava/awt/print/PageFormat;IJ)V"); // Create and draw into a new CPrinterGraphics with the current Context. assert(fCurPageFormat != NULL); assert(fCurPainter != NULL); assert(fCurPeekGraphics != NULL); - JNIEnv* env = [ThreadUtilities getJNIEnvUncached]; - if ([self cancelCheck:env]) { [self releaseReferences:env]; return; } --- 77,97 ---- - (void)drawRect:(NSRect)aRect { AWT_ASSERT_NOT_APPKIT_THREAD; ! JNIEnv* env = [ThreadUtilities getJNIEnvUncached]; ! ! GET_CPRINTERJOB_CLASS(); ! DECLARE_METHOD(jm_printToPathGraphics, sjc_CPrinterJob, "printToPathGraphics", ! "(Lsun/print/PeekGraphics;Ljava/awt/print/PrinterJob;Ljava/awt/print/Printable;Ljava/awt/print/PageFormat;IJ)V"); // Create and draw into a new CPrinterGraphics with the current Context. assert(fCurPageFormat != NULL); assert(fCurPainter != NULL); assert(fCurPeekGraphics != NULL); if ([self cancelCheck:env]) { [self releaseReferences:env]; return; }
*** 100,126 **** jlong context = ptr_to_jlong([printLoop context]); CGContextRef cgRef = (CGContextRef)[[printLoop context] graphicsPort]; CGContextSaveGState(cgRef); //04/28/2004: state needs to be saved here due to addition of lazy state management ! JNFCallVoidMethod(env, fPrinterJob, jm_printToPathGraphics, fCurPeekGraphics, fPrinterJob, fCurPainter, fCurPageFormat, jPageIndex, context); // AWT_THREADING Safe (AWTRunLoop) CGContextRestoreGState(cgRef); [self releaseReferences:env]; } - (NSString*)printJobTitle { AWT_ASSERT_NOT_APPKIT_THREAD; - static JNF_MEMBER_CACHE(jm_getJobName, sjc_CPrinterJob, "getJobName", "()Ljava/lang/String;"); - JNIEnv* env = [ThreadUtilities getJNIEnvUncached]; ! jobject o = JNFCallObjectMethod(env, fPrinterJob, jm_getJobName); // AWT_THREADING Safe (known object) ! id result = JNFJavaToNSString(env, o); (*env)->DeleteLocalRef(env, o); return result; } - (BOOL)knowsPageRange:(NSRangePointer)aRange --- 101,130 ---- jlong context = ptr_to_jlong([printLoop context]); CGContextRef cgRef = (CGContextRef)[[printLoop context] graphicsPort]; CGContextSaveGState(cgRef); //04/28/2004: state needs to be saved here due to addition of lazy state management ! (*env)->CallVoidMethod(env, fPrinterJob, jm_printToPathGraphics, fCurPeekGraphics, fPrinterJob, ! fCurPainter, fCurPageFormat, jPageIndex, context); ! CHECK_EXCEPTION(); CGContextRestoreGState(cgRef); [self releaseReferences:env]; } - (NSString*)printJobTitle { AWT_ASSERT_NOT_APPKIT_THREAD; JNIEnv* env = [ThreadUtilities getJNIEnvUncached]; + GET_CPRINTERJOB_CLASS_RETURN(nil); + DECLARE_METHOD_RETURN(jm_getJobName, sjc_CPrinterJob, "getJobName", "()Ljava/lang/String;", nil); ! jobject o = (*env)->CallObjectMethod(env, fPrinterJob, jm_getJobName); ! CHECK_EXCEPTION(); ! id result = JavaStringToNSString(env, o); (*env)->DeleteLocalRef(env, o); return result; } - (BOOL)knowsPageRange:(NSRangePointer)aRange
*** 149,178 **** - (NSRect)rectForPage:(NSInteger)pageNumber { AWT_ASSERT_NOT_APPKIT_THREAD; ! static JNF_MEMBER_CACHE(jm_getPageformatPrintablePeekgraphics, sjc_CPrinterJob, "getPageformatPrintablePeekgraphics", "(I)[Ljava/lang/Object;"); ! static JNF_MEMBER_CACHE(jm_printAndGetPageFormatArea, sjc_CPrinterJob, "printAndGetPageFormatArea", "(Ljava/awt/print/Printable;Ljava/awt/Graphics;Ljava/awt/print/PageFormat;I)Ljava/awt/geom/Rectangle2D;"); ! static JNF_MEMBER_CACHE(jm_getOrientation, sjc_PageFormat, "getOrientation", "()I"); ! // Assertions removed, and corresponding JNFDeleteGlobalRefs added, for radr://3962543 // Actual fix that will keep these assertions from being true is radr://3205462 , // which will hopefully be fixed by the blocking AppKit bug radr://3056694 //assert(fCurPageFormat == NULL); //assert(fCurPainter == NULL); //assert(fCurPeekGraphics == NULL); - JNIEnv* env = [ThreadUtilities getJNIEnvUncached]; if(fCurPageFormat != NULL) { ! JNFDeleteGlobalRef(env, fCurPageFormat); } if(fCurPainter != NULL) { ! JNFDeleteGlobalRef(env, fCurPainter); } if(fCurPeekGraphics != NULL) { ! JNFDeleteGlobalRef(env, fCurPeekGraphics); } //+++gdb Check the pageNumber for validity (PageAttrs) jint jPageNumber = pageNumber - 1; --- 153,186 ---- - (NSRect)rectForPage:(NSInteger)pageNumber { AWT_ASSERT_NOT_APPKIT_THREAD; ! JNIEnv* env = [ThreadUtilities getJNIEnvUncached]; ! GET_CPRINTERJOB_CLASS_RETURN(NSZeroRect); ! DECLARE_METHOD_RETURN(jm_getPageformatPrintablePeekgraphics, sjc_CPrinterJob, ! "getPageformatPrintablePeekgraphics", "(I)[Ljava/lang/Object;", NSZeroRect); ! DECLARE_METHOD_RETURN(jm_printAndGetPageFormatArea, sjc_CPrinterJob, "printAndGetPageFormatArea", ! "(Ljava/awt/print/Printable;Ljava/awt/Graphics;Ljava/awt/print/PageFormat;I)Ljava/awt/geom/Rectangle2D;", NSZeroRect); ! DECLARE_CLASS_RETURN(sjc_PageFormat, "java/awt/print/PageFormat", NSZeroRect); ! DECLARE_METHOD_RETURN(jm_getOrientation, sjc_PageFormat, "getOrientation", "()I", NSZeroRect); ! // Assertions removed, and corresponding DeleteGlobalRefs added, for radr://3962543 // Actual fix that will keep these assertions from being true is radr://3205462 , // which will hopefully be fixed by the blocking AppKit bug radr://3056694 //assert(fCurPageFormat == NULL); //assert(fCurPainter == NULL); //assert(fCurPeekGraphics == NULL); if(fCurPageFormat != NULL) { ! (*env)->DeleteGlobalRef(env, fCurPageFormat); } if(fCurPainter != NULL) { ! (*env)->DeleteGlobalRef(env, fCurPainter); } if(fCurPeekGraphics != NULL) { ! (*env)->DeleteGlobalRef(env, fCurPeekGraphics); } //+++gdb Check the pageNumber for validity (PageAttrs) jint jPageNumber = pageNumber - 1;
*** 182,214 **** if ([self cancelCheck:env]) { return NSZeroRect; } ! jobjectArray objectArray = JNFCallObjectMethod(env, fPrinterJob, jm_getPageformatPrintablePeekgraphics, jPageNumber); // AWT_THREADING Safe (AWTRunLoopMode) if (objectArray != NULL) { // Get references to the return objects -> PageFormat, Printable, PeekGraphics // Cheat - we know we either got NULL or a 3 element array jobject pageFormat = (*env)->GetObjectArrayElement(env, objectArray, 0); ! fCurPageFormat = JNFNewGlobalRef(env, pageFormat); (*env)->DeleteLocalRef(env, pageFormat); jobject painter = (*env)->GetObjectArrayElement(env, objectArray, 1); ! fCurPainter = JNFNewGlobalRef(env, painter); (*env)->DeleteLocalRef(env, painter); jobject peekGraphics = (*env)->GetObjectArrayElement(env, objectArray, 2); ! fCurPeekGraphics = JNFNewGlobalRef(env, peekGraphics); (*env)->DeleteLocalRef(env, peekGraphics); // Actually print and get the PageFormatArea ! jobject pageFormatArea = JNFCallObjectMethod(env, fPrinterJob, jm_printAndGetPageFormatArea, fCurPainter, fCurPeekGraphics, fCurPageFormat, jPageNumber); // AWT_THREADING Safe (AWTRunLoopMode) if (pageFormatArea != NULL) { NSPrintingOrientation currentOrientation = [[[NSPrintOperation currentOperation] printInfo] orientation]; // set page orientation ! switch (JNFCallIntMethod(env, fCurPageFormat, jm_getOrientation)) { case java_awt_print_PageFormat_PORTRAIT: default: if (currentOrientation != NSPortraitOrientation) { [[[NSPrintOperation currentOperation] printInfo] setOrientation:NSPortraitOrientation]; --- 190,226 ---- if ([self cancelCheck:env]) { return NSZeroRect; } ! jobjectArray objectArray = (*env)->CallObjectMethod(env, fPrinterJob, ! jm_getPageformatPrintablePeekgraphics, jPageNumber); ! CHECK_EXCEPTION(); if (objectArray != NULL) { // Get references to the return objects -> PageFormat, Printable, PeekGraphics // Cheat - we know we either got NULL or a 3 element array jobject pageFormat = (*env)->GetObjectArrayElement(env, objectArray, 0); ! fCurPageFormat = (*env)->NewGlobalRef(env, pageFormat); (*env)->DeleteLocalRef(env, pageFormat); jobject painter = (*env)->GetObjectArrayElement(env, objectArray, 1); ! fCurPainter = (*env)->NewGlobalRef(env, painter); (*env)->DeleteLocalRef(env, painter); jobject peekGraphics = (*env)->GetObjectArrayElement(env, objectArray, 2); ! fCurPeekGraphics = (*env)->NewGlobalRef(env, peekGraphics); (*env)->DeleteLocalRef(env, peekGraphics); // Actually print and get the PageFormatArea ! jobject pageFormatArea = (*env)->CallObjectMethod(env, fPrinterJob, jm_printAndGetPageFormatArea, fCurPainter, ! fCurPeekGraphics, fCurPageFormat, jPageNumber); ! CHECK_EXCEPTION(); if (pageFormatArea != NULL) { NSPrintingOrientation currentOrientation = [[[NSPrintOperation currentOperation] printInfo] orientation]; // set page orientation ! switch ((*env)->CallIntMethod(env, fCurPageFormat, jm_getOrientation)) { case java_awt_print_PageFormat_PORTRAIT: default: if (currentOrientation != NSPortraitOrientation) { [[[NSPrintOperation currentOperation] printInfo] setOrientation:NSPortraitOrientation];
*** 221,230 **** --- 233,243 ---- [[[NSPrintOperation currentOperation] printInfo] setOrientation:NSLandscapeOrientation]; } break; } + CHECK_EXCEPTION(); result = JavaToNSRect(env, pageFormatArea); (*env)->DeleteLocalRef(env, pageFormatArea); } else { [self releaseReferences:env]; result = NSZeroRect;
*** 241,269 **** - (BOOL)cancelCheck:(JNIEnv*)env { AWT_ASSERT_NOT_APPKIT_THREAD; ! static JNF_MEMBER_CACHE(jm_cancelCheck, sjc_CPrinterJob, "cancelCheck", "()Z"); ! return JNFCallBooleanMethod(env, fPrinterJob, jm_cancelCheck); // AWT_THREADING Safe (known object) } // This is called by -[PrintModel safePrintLoop] - (void)complete:(JNIEnv*)env { AWT_ASSERT_NOT_APPKIT_THREAD; ! static JNF_MEMBER_CACHE(jf_completePrintLoop, sjc_CPrinterJob, "completePrintLoop", "()V"); ! JNFCallVoidMethod(env, fPrinterJob, jf_completePrintLoop); // Clean up after ourselves // Can't put these into -dealloc since that happens (potentially) after the JNIEnv is stale [self releaseReferences:env]; if (fPrinterJob != NULL) { ! JNFDeleteGlobalRef(env, fPrinterJob); fPrinterJob = NULL; } } - (BOOL)isFlipped --- 254,286 ---- - (BOOL)cancelCheck:(JNIEnv*)env { AWT_ASSERT_NOT_APPKIT_THREAD; ! GET_CPRINTERJOB_CLASS_RETURN(NO); ! DECLARE_METHOD_RETURN(jm_cancelCheck, sjc_CPrinterJob, "cancelCheck", "()Z", NO); ! BOOL b = (*env)->CallBooleanMethod(env, fPrinterJob, jm_cancelCheck); // AWT_THREADING Safe (known object) ! CHECK_EXCEPTION(); ! return b; } // This is called by -[PrintModel safePrintLoop] - (void)complete:(JNIEnv*)env { AWT_ASSERT_NOT_APPKIT_THREAD; ! DECLARE_METHOD(jf_completePrintLoop, sjc_CPrinterJob, "completePrintLoop", "()V"); ! (*env)->CallVoidMethod(env, fPrinterJob, jf_completePrintLoop); ! CHECK_EXCEPTION(); // Clean up after ourselves // Can't put these into -dealloc since that happens (potentially) after the JNIEnv is stale [self releaseReferences:env]; if (fPrinterJob != NULL) { ! (*env)->DeleteGlobalRef(env, fPrinterJob); fPrinterJob = NULL; } } - (BOOL)isFlipped
< prev index next >