< prev index next >

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

Print this page




 295         default:
 296             [dstPrintInfo setOrientation:NS_PORTRAIT];
 297             break;
 298     }
 299 
 300     // <rdar://problem/4022422> NSPrinterInfo is not correctly set to the selected printer
 301     // from the Java side of CPrinterJob. Has always assumed the default printer was the one we wanted.
 302     if (srcPrintJob == NULL) return;
 303     jobject printerNameObj = JNFCallObjectMethod(env, srcPrintJob, jm_getPrinterName);
 304     if (printerNameObj == NULL) return;
 305     NSString *printerName = JNFJavaToNSString(env, printerNameObj);
 306     if (printerName == nil) return;
 307     NSPrinter *printer = [NSPrinter printerWithName:printerName];
 308     if (printer == nil) return;
 309     [dstPrintInfo setPrinter:printer];
 310 }
 311 
 312 static void nsPrintInfoToJavaPrinterJob(JNIEnv* env, NSPrintInfo* src, jobject dstPrinterJob, jobject dstPageable)
 313 {
 314     static JNF_MEMBER_CACHE(jm_setService, sjc_CPrinterJob, "setPrinterServiceFromNative", "(Ljava/lang/String;)V");
 315     static JNF_MEMBER_CACHE(jm_setCopies, sjc_CPrinterJob, "setCopies", "(I)V");
 316     static JNF_MEMBER_CACHE(jm_setCollated, sjc_CPrinterJob, "setCollated", "(Z)V");
 317     static JNF_MEMBER_CACHE(jm_setPageRange, sjc_CPrinterJob, "setPageRange", "(II)V");
 318 
 319     // get the selected printer's name, and set the appropriate PrintService on the Java side
 320     NSString *name = [[src printer] name];
 321     jstring printerName = JNFNSToJavaString(env, name);
 322     JNFCallVoidMethod(env, dstPrinterJob, jm_setService, printerName);
 323 
 324 
 325     NSMutableDictionary* printingDictionary = [src dictionary];
 326 
 327     NSNumber* nsCopies = [printingDictionary objectForKey:NSPrintCopies];
 328     if ([nsCopies respondsToSelector:@selector(integerValue)])
 329     {
 330         JNFCallVoidMethod(env, dstPrinterJob, jm_setCopies, [nsCopies integerValue]); // AWT_THREADING Safe (known object)
 331     }
 332 
 333     NSNumber* nsCollated = [printingDictionary objectForKey:NSPrintMustCollate];
 334     if ([nsCollated respondsToSelector:@selector(boolValue)])
 335     {
 336         JNFCallVoidMethod(env, dstPrinterJob, jm_setCollated, [nsCollated boolValue] ? JNI_TRUE : JNI_FALSE); // AWT_THREADING Safe (known object)
 337     }
 338 
 339     NSNumber* nsPrintAllPages = [printingDictionary objectForKey:NSPrintAllPages];
 340     if ([nsPrintAllPages respondsToSelector:@selector(boolValue)])
 341     {
 342         jint jFirstPage = 0, jLastPage = java_awt_print_Pageable_UNKNOWN_NUMBER_OF_PAGES;
 343         if (![nsPrintAllPages boolValue])
 344         {
 345             NSNumber* nsFirstPage = [printingDictionary objectForKey:NSPrintFirstPage];
 346             if ([nsFirstPage respondsToSelector:@selector(integerValue)])
 347             {
 348                 jFirstPage = [nsFirstPage integerValue] - 1;
 349             }
 350 
 351             NSNumber* nsLastPage = [printingDictionary objectForKey:NSPrintLastPage];
 352             if ([nsLastPage respondsToSelector:@selector(integerValue)])
 353             {
 354                 jLastPage = [nsLastPage integerValue] - 1;
 355             }



 356         }
 357 
 358         JNFCallVoidMethod(env, dstPrinterJob, jm_setPageRange, jFirstPage, jLastPage); // AWT_THREADING Safe (known object)
 359     }
 360 }
 361 
 362 static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobject srcPageable, NSPrintInfo* dst)
 363 {
 364     AWT_ASSERT_NOT_APPKIT_THREAD;
 365 
 366     static JNF_CLASS_CACHE(jc_Pageable, "java/awt/print/Pageable");
 367     static JNF_MEMBER_CACHE(jm_getCopies, sjc_CPrinterJob, "getCopiesInt", "()I");
 368     static JNF_MEMBER_CACHE(jm_isCollated, sjc_CPrinterJob, "isCollated", "()Z");
 369     static JNF_MEMBER_CACHE(jm_getFromPage, sjc_CPrinterJob, "getFromPageAttrib", "()I");
 370     static JNF_MEMBER_CACHE(jm_getToPage, sjc_CPrinterJob, "getToPageAttrib", "()I");
 371     static JNF_MEMBER_CACHE(jm_getSelectAttrib, sjc_CPrinterJob, "getSelectAttrib", "()I");
 372     static JNF_MEMBER_CACHE(jm_getNumberOfPages, jc_Pageable, "getNumberOfPages", "()I");
 373     static JNF_MEMBER_CACHE(jm_getPageFormat, sjc_CPrinterJob, "getPageFormatFromAttributes", "()Ljava/awt/print/PageFormat;");
 374 
 375     NSMutableDictionary* printingDictionary = [dst dictionary];
 376 
 377     jint copies = JNFCallIntMethod(env, srcPrinterJob, jm_getCopies); // AWT_THREADING Safe (known object)
 378     [printingDictionary setObject:[NSNumber numberWithInteger:copies] forKey:NSPrintCopies];




 295         default:
 296             [dstPrintInfo setOrientation:NS_PORTRAIT];
 297             break;
 298     }
 299 
 300     // <rdar://problem/4022422> NSPrinterInfo is not correctly set to the selected printer
 301     // from the Java side of CPrinterJob. Has always assumed the default printer was the one we wanted.
 302     if (srcPrintJob == NULL) return;
 303     jobject printerNameObj = JNFCallObjectMethod(env, srcPrintJob, jm_getPrinterName);
 304     if (printerNameObj == NULL) return;
 305     NSString *printerName = JNFJavaToNSString(env, printerNameObj);
 306     if (printerName == nil) return;
 307     NSPrinter *printer = [NSPrinter printerWithName:printerName];
 308     if (printer == nil) return;
 309     [dstPrintInfo setPrinter:printer];
 310 }
 311 
 312 static void nsPrintInfoToJavaPrinterJob(JNIEnv* env, NSPrintInfo* src, jobject dstPrinterJob, jobject dstPageable)
 313 {
 314     static JNF_MEMBER_CACHE(jm_setService, sjc_CPrinterJob, "setPrinterServiceFromNative", "(Ljava/lang/String;)V");
 315     static JNF_MEMBER_CACHE(jm_setCopiesAttribute, sjc_CPrinterJob, "setCopiesAttribute", "(I)V");
 316     static JNF_MEMBER_CACHE(jm_setCollated, sjc_CPrinterJob, "setCollated", "(Z)V");
 317     static JNF_MEMBER_CACHE(jm_setPageRangeAttribute, sjc_CPrinterJob, "setPageRangeAttribute", "(II)V");
 318 
 319     // get the selected printer's name, and set the appropriate PrintService on the Java side
 320     NSString *name = [[src printer] name];
 321     jstring printerName = JNFNSToJavaString(env, name);
 322     JNFCallVoidMethod(env, dstPrinterJob, jm_setService, printerName);
 323 
 324 
 325     NSMutableDictionary* printingDictionary = [src dictionary];
 326 
 327     NSNumber* nsCopies = [printingDictionary objectForKey:NSPrintCopies];
 328     if ([nsCopies respondsToSelector:@selector(integerValue)])
 329     {
 330         JNFCallVoidMethod(env, dstPrinterJob, jm_setCopiesAttribute, [nsCopies integerValue]); // AWT_THREADING Safe (known object)
 331     }
 332 
 333     NSNumber* nsCollated = [printingDictionary objectForKey:NSPrintMustCollate];
 334     if ([nsCollated respondsToSelector:@selector(boolValue)])
 335     {
 336         JNFCallVoidMethod(env, dstPrinterJob, jm_setCollated, [nsCollated boolValue] ? JNI_TRUE : JNI_FALSE); // AWT_THREADING Safe (known object)
 337     }
 338 
 339     NSNumber* nsPrintAllPages = [printingDictionary objectForKey:NSPrintAllPages];
 340     if ([nsPrintAllPages respondsToSelector:@selector(boolValue)])
 341     {
 342         jint jFirstPage = 0, jLastPage = java_awt_print_Pageable_UNKNOWN_NUMBER_OF_PAGES;
 343         if (![nsPrintAllPages boolValue])
 344         {
 345             NSNumber* nsFirstPage = [printingDictionary objectForKey:NSPrintFirstPage];
 346             if ([nsFirstPage respondsToSelector:@selector(integerValue)])
 347             {
 348                 jFirstPage = [nsFirstPage integerValue];
 349             }
 350 
 351             NSNumber* nsLastPage = [printingDictionary objectForKey:NSPrintLastPage];
 352             if ([nsLastPage respondsToSelector:@selector(integerValue)])
 353             {
 354                 jLastPage = [nsLastPage integerValue];
 355             }
 356             JNFCallVoidMethod(env, dstPrinterJob, jm_setPageRangeAttribute, 
 357                               jFirstPage, jLastPage); 
 358             // AWT_THREADING Safe (known object)
 359         }
 360 

 361     }
 362 }
 363 
 364 static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobject srcPageable, NSPrintInfo* dst)
 365 {
 366     AWT_ASSERT_NOT_APPKIT_THREAD;
 367 
 368     static JNF_CLASS_CACHE(jc_Pageable, "java/awt/print/Pageable");
 369     static JNF_MEMBER_CACHE(jm_getCopies, sjc_CPrinterJob, "getCopiesInt", "()I");
 370     static JNF_MEMBER_CACHE(jm_isCollated, sjc_CPrinterJob, "isCollated", "()Z");
 371     static JNF_MEMBER_CACHE(jm_getFromPage, sjc_CPrinterJob, "getFromPageAttrib", "()I");
 372     static JNF_MEMBER_CACHE(jm_getToPage, sjc_CPrinterJob, "getToPageAttrib", "()I");
 373     static JNF_MEMBER_CACHE(jm_getSelectAttrib, sjc_CPrinterJob, "getSelectAttrib", "()I");
 374     static JNF_MEMBER_CACHE(jm_getNumberOfPages, jc_Pageable, "getNumberOfPages", "()I");
 375     static JNF_MEMBER_CACHE(jm_getPageFormat, sjc_CPrinterJob, "getPageFormatFromAttributes", "()Ljava/awt/print/PageFormat;");
 376 
 377     NSMutableDictionary* printingDictionary = [dst dictionary];
 378 
 379     jint copies = JNFCallIntMethod(env, srcPrinterJob, jm_getCopies); // AWT_THREADING Safe (known object)
 380     [printingDictionary setObject:[NSNumber numberWithInteger:copies] forKey:NSPrintCopies];


< prev index next >