< prev index next >

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

Print this page




 345 
 346     NSNumber* nsPrintAllPages = [printingDictionary objectForKey:NSPrintAllPages];
 347     if ([nsPrintAllPages respondsToSelector:@selector(boolValue)])
 348     {
 349         jint jFirstPage = 0, jLastPage = java_awt_print_Pageable_UNKNOWN_NUMBER_OF_PAGES;
 350         jboolean isRangeSet = false;
 351         if (![nsPrintAllPages boolValue])
 352         {
 353             NSNumber* nsFirstPage = [printingDictionary objectForKey:NSPrintFirstPage];
 354             if ([nsFirstPage respondsToSelector:@selector(integerValue)])
 355             {
 356                 jFirstPage = [nsFirstPage integerValue] - 1;
 357             }
 358 
 359             NSNumber* nsLastPage = [printingDictionary objectForKey:NSPrintLastPage];
 360             if ([nsLastPage respondsToSelector:@selector(integerValue)])
 361             {
 362                 jLastPage = [nsLastPage integerValue] - 1;
 363             }
 364             isRangeSet = true;
 365         } 
 366         JNFCallVoidMethod(env, dstPrinterJob, jm_setPageRangeAttribute, 
 367                           jFirstPage, jLastPage, isRangeSet); 
 368             // AWT_THREADING Safe (known object)
 369 
 370     }
 371 }
 372 
 373 static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobject srcPageable, NSPrintInfo* dst)
 374 {
 375     AWT_ASSERT_NOT_APPKIT_THREAD;
 376 
 377     static JNF_CLASS_CACHE(jc_Pageable, "java/awt/print/Pageable");
 378     static JNF_MEMBER_CACHE(jm_getCopies, sjc_CPrinterJob, "getCopiesInt", "()I");
 379     static JNF_MEMBER_CACHE(jm_isCollated, sjc_CPrinterJob, "isCollated", "()Z");
 380     static JNF_MEMBER_CACHE(jm_getFromPage, sjc_CPrinterJob, "getFromPageAttrib", "()I");
 381     static JNF_MEMBER_CACHE(jm_getToPage, sjc_CPrinterJob, "getToPageAttrib", "()I");
 382     static JNF_MEMBER_CACHE(jm_getMinPage, sjc_CPrinterJob, "getMinPageAttrib", "()I");
 383     static JNF_MEMBER_CACHE(jm_getMaxPage, sjc_CPrinterJob, "getMaxPageAttrib", "()I");
 384     static JNF_MEMBER_CACHE(jm_getSelectAttrib, sjc_CPrinterJob, "getSelectAttrib", "()I");
 385     static JNF_MEMBER_CACHE(jm_getNumberOfPages, jc_Pageable, "getNumberOfPages", "()I");
 386     static JNF_MEMBER_CACHE(jm_getPageFormat, sjc_CPrinterJob, "getPageFormatFromAttributes", "()Ljava/awt/print/PageFormat;");
 387 


 402         // NSPrintAllPages is YES or NO
 403         [printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages];
 404         [printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintSelectionOnly];
 405     } else {
 406         jint minPage = JNFCallIntMethod(env, srcPrinterJob, jm_getMinPage);
 407         jint maxPage = JNFCallIntMethod(env, srcPrinterJob, jm_getMaxPage);
 408 
 409         // for PD_SELECTION or PD_NOSELECTION, check from/to page
 410         // to determine which radio button to select
 411         if (fromPage > minPage || toPage < maxPage) {
 412             [printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages];
 413         } else {
 414             [printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintAllPages];
 415         }
 416     }
 417 
 418     // setting fromPage and toPage will not be shown in the dialog if printing All pages
 419     [printingDictionary setObject:[NSNumber numberWithInteger:fromPage] forKey:NSPrintFirstPage];
 420     [printingDictionary setObject:[NSNumber numberWithInteger:toPage] forKey:NSPrintLastPage];
 421 
 422     jobject page = JNFCallObjectMethod(env, srcPrinterJob, jm_getPageFormat); 
 423     if (page != NULL) {
 424         javaPageFormatToNSPrintInfo(env, NULL, page, dst);
 425     }
 426 }
 427 
 428 /*
 429  * Class:     sun_lwawt_macosx_CPrinterJob
 430  * Method:    abortDoc
 431  * Signature: ()V
 432  */
 433 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob_abortDoc
 434   (JNIEnv *env, jobject jthis)
 435 {
 436 JNF_COCOA_ENTER(env);
 437     // This is only called during the printLoop from the printLoop thread
 438     NSPrintOperation* printLoop = [NSPrintOperation currentOperation];
 439     NSPrintInfo* printInfo = [printLoop printInfo];
 440     [printInfo setJobDisposition:NSPrintCancelJob];
 441 JNF_COCOA_EXIT(env);
 442 }




 345 
 346     NSNumber* nsPrintAllPages = [printingDictionary objectForKey:NSPrintAllPages];
 347     if ([nsPrintAllPages respondsToSelector:@selector(boolValue)])
 348     {
 349         jint jFirstPage = 0, jLastPage = java_awt_print_Pageable_UNKNOWN_NUMBER_OF_PAGES;
 350         jboolean isRangeSet = false;
 351         if (![nsPrintAllPages boolValue])
 352         {
 353             NSNumber* nsFirstPage = [printingDictionary objectForKey:NSPrintFirstPage];
 354             if ([nsFirstPage respondsToSelector:@selector(integerValue)])
 355             {
 356                 jFirstPage = [nsFirstPage integerValue] - 1;
 357             }
 358 
 359             NSNumber* nsLastPage = [printingDictionary objectForKey:NSPrintLastPage];
 360             if ([nsLastPage respondsToSelector:@selector(integerValue)])
 361             {
 362                 jLastPage = [nsLastPage integerValue] - 1;
 363             }
 364             isRangeSet = true;
 365         }
 366         JNFCallVoidMethod(env, dstPrinterJob, jm_setPageRangeAttribute,
 367                           jFirstPage, jLastPage, isRangeSet);
 368             // AWT_THREADING Safe (known object)
 369 
 370     }
 371 }
 372 
 373 static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobject srcPageable, NSPrintInfo* dst)
 374 {
 375     AWT_ASSERT_NOT_APPKIT_THREAD;
 376 
 377     static JNF_CLASS_CACHE(jc_Pageable, "java/awt/print/Pageable");
 378     static JNF_MEMBER_CACHE(jm_getCopies, sjc_CPrinterJob, "getCopiesInt", "()I");
 379     static JNF_MEMBER_CACHE(jm_isCollated, sjc_CPrinterJob, "isCollated", "()Z");
 380     static JNF_MEMBER_CACHE(jm_getFromPage, sjc_CPrinterJob, "getFromPageAttrib", "()I");
 381     static JNF_MEMBER_CACHE(jm_getToPage, sjc_CPrinterJob, "getToPageAttrib", "()I");
 382     static JNF_MEMBER_CACHE(jm_getMinPage, sjc_CPrinterJob, "getMinPageAttrib", "()I");
 383     static JNF_MEMBER_CACHE(jm_getMaxPage, sjc_CPrinterJob, "getMaxPageAttrib", "()I");
 384     static JNF_MEMBER_CACHE(jm_getSelectAttrib, sjc_CPrinterJob, "getSelectAttrib", "()I");
 385     static JNF_MEMBER_CACHE(jm_getNumberOfPages, jc_Pageable, "getNumberOfPages", "()I");
 386     static JNF_MEMBER_CACHE(jm_getPageFormat, sjc_CPrinterJob, "getPageFormatFromAttributes", "()Ljava/awt/print/PageFormat;");
 387 


 402         // NSPrintAllPages is YES or NO
 403         [printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages];
 404         [printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintSelectionOnly];
 405     } else {
 406         jint minPage = JNFCallIntMethod(env, srcPrinterJob, jm_getMinPage);
 407         jint maxPage = JNFCallIntMethod(env, srcPrinterJob, jm_getMaxPage);
 408 
 409         // for PD_SELECTION or PD_NOSELECTION, check from/to page
 410         // to determine which radio button to select
 411         if (fromPage > minPage || toPage < maxPage) {
 412             [printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages];
 413         } else {
 414             [printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintAllPages];
 415         }
 416     }
 417 
 418     // setting fromPage and toPage will not be shown in the dialog if printing All pages
 419     [printingDictionary setObject:[NSNumber numberWithInteger:fromPage] forKey:NSPrintFirstPage];
 420     [printingDictionary setObject:[NSNumber numberWithInteger:toPage] forKey:NSPrintLastPage];
 421 
 422     jobject page = JNFCallObjectMethod(env, srcPrinterJob, jm_getPageFormat);
 423     if (page != NULL) {
 424         javaPageFormatToNSPrintInfo(env, NULL, page, dst);
 425     }
 426 }
 427 
 428 /*
 429  * Class:     sun_lwawt_macosx_CPrinterJob
 430  * Method:    abortDoc
 431  * Signature: ()V
 432  */
 433 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob_abortDoc
 434   (JNIEnv *env, jobject jthis)
 435 {
 436 JNF_COCOA_ENTER(env);
 437     // This is only called during the printLoop from the printLoop thread
 438     NSPrintOperation* printLoop = [NSPrintOperation currentOperation];
 439     NSPrintInfo* printInfo = [printLoop printInfo];
 440     [printInfo setJobDisposition:NSPrintCancelJob];
 441 JNF_COCOA_EXIT(env);
 442 }


< prev index next >