author | lana |
Thu, 26 Dec 2013 12:04:16 -0800 | |
changeset 23010 | 6dadb192ad81 |
parent 12047 | 320a714614e9 |
child 23651 | e41298d0da2f |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
12047
diff
changeset
|
2 |
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
12047 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
||
27 |
#import "PrintModel.h" |
|
28 |
||
29 |
#import <JavaNativeFoundation/JavaNativeFoundation.h> |
|
30 |
||
31 |
#import "PrinterView.h" |
|
32 |
#import "ThreadUtilities.h" |
|
33 |
||
34 |
@implementation PrintModel |
|
35 |
||
36 |
- (id)initWithPrintInfo:(NSPrintInfo*)printInfo { |
|
37 |
self = [super init]; |
|
38 |
if (self) { |
|
39 |
fPrintInfo = [printInfo retain]; |
|
40 |
} |
|
41 |
||
42 |
return self; |
|
43 |
} |
|
44 |
||
45 |
- (void)dealloc { |
|
46 |
[fPrintInfo release]; |
|
47 |
fPrintInfo = nil; |
|
48 |
||
49 |
[super dealloc]; |
|
50 |
} |
|
51 |
//- (void)finalize { [super finalize]; } |
|
52 |
||
53 |
- (BOOL)runPageSetup { |
|
54 |
__block BOOL fResult = NO; |
|
55 |
||
56 |
[JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ |
|
57 |
NSPageLayout* pageLayout = [NSPageLayout pageLayout]; |
|
58 |
fResult = ([pageLayout runModalWithPrintInfo:fPrintInfo] == NSOKButton); |
|
59 |
}]; |
|
60 |
||
61 |
return fResult; |
|
62 |
} |
|
63 |
||
64 |
- (BOOL)runJobSetup { |
|
65 |
__block BOOL fResult = NO; |
|
66 |
||
67 |
[JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ |
|
68 |
NSPrintPanel* printPanel = [NSPrintPanel printPanel]; |
|
69 |
fResult = ([printPanel runModalWithPrintInfo:fPrintInfo] == NSOKButton); |
|
70 |
}]; |
|
71 |
||
72 |
return fResult; |
|
73 |
} |
|
74 |
||
75 |
- (BOOL)runPrintLoopWithView:(NSView*)printerView waitUntilDone:(BOOL)wait withEnv:(JNIEnv *)env |
|
76 |
{ |
|
77 |
AWT_ASSERT_NOT_APPKIT_THREAD; |
|
78 |
||
79 |
BOOL fResult = NO; |
|
80 |
||
81 |
// <rdar://problem/4310184> Because people like to put up modal dialogs during print operations, |
|
82 |
// we have to run the print operation on a non-AppKit thread or else we get a deadlock and errors |
|
83 |
// the AppKit team believes it's OK for us to call runOperation from non-AppKit threads, |
|
84 |
// as long as we don't show any panels, and we don't touch the NSPrintInfo or the NSView from other threads. |
|
85 |
if (wait) { |
|
86 |
fResult = [self safePrintLoop:printerView withEnv:env]; |
|
87 |
} else { |
|
88 |
// Retain these so they don't go away while we're in Java |
|
89 |
CFRetain(self); // GC |
|
90 |
if (printerView) CFRetain(printerView); // GC |
|
91 |
||
92 |
static JNF_CLASS_CACHE(jc_CPrinterJob, "sun/lwawt/macosx/CPrinterJob"); |
|
93 |
static JNF_STATIC_MEMBER_CACHE(jm_detachPrintLoop, jc_CPrinterJob, "detachPrintLoop", "(JJ)V"); |
|
94 |
JNFCallStaticVoidMethod(env, jm_detachPrintLoop, ptr_to_jlong(self), ptr_to_jlong(printerView)); // AWT_THREADING Safe (known object) |
|
95 |
} |
|
96 |
||
97 |
return fResult; |
|
98 |
} |
|
99 |
||
100 |
- (BOOL) safePrintLoop:(id)arg withEnv:(JNIEnv *)env |
|
101 |
{ |
|
102 |
AWT_ASSERT_NOT_APPKIT_THREAD; |
|
103 |
||
104 |
PrinterView* printerView = (PrinterView*)arg; |
|
105 |
BOOL fResult; |
|
106 |
@try { |
|
107 |
NSPrintOperation* printLoop = [NSPrintOperation printOperationWithView:printerView printInfo:fPrintInfo]; |
|
108 |
[printLoop setShowPanels:NO]; //+++gdb Problem: This will avoid progress bars... |
|
109 |
//[printLoop setCanSpawnSeparateThread:YES]; //+++gdb Need to check this... |
|
110 |
||
111 |
fResult = [printLoop runOperation]; |
|
112 |
} @finally { |
|
113 |
// Tell CPrinterJob that things are done. |
|
114 |
[printerView complete:env]; |
|
115 |
} |
|
116 |
return fResult; |
|
117 |
} |
|
118 |
||
119 |
@end |
|
120 |
||
121 |
/* |
|
122 |
* Class: sun_lwawt_macosx_CPrinterJob |
|
123 |
* Method: _safePrintLoop |
|
124 |
* Signature: (JJ)V |
|
125 |
*/ |
|
126 |
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob__1safePrintLoop |
|
127 |
(JNIEnv *env, jclass clz, jlong target, jlong view) |
|
128 |
{ |
|
129 |
JNF_COCOA_ENTER(env); |
|
130 |
||
131 |
PrintModel *model = (PrintModel *)jlong_to_ptr(target); |
|
132 |
PrinterView *arg = (PrinterView *)jlong_to_ptr(view); |
|
133 |
||
134 |
[model safePrintLoop:arg withEnv:env]; |
|
135 |
||
136 |
// These are to match the retains in runPrintLoopWithView: |
|
137 |
if (model) CFRelease(model); // GC |
|
138 |
if (arg) CFRelease(arg); // GC |
|
139 |
||
140 |
JNF_COCOA_EXIT(env); |
|
141 |
} |
|
142 |