]>
Commit | Line | Data |
---|---|---|
72e7876b SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dcprint.cpp | |
3 | // Purpose: wxPrinterDC class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "dcprint.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #endif | |
25 | ||
26 | #include "wx/dcprint.h" | |
03e11df5 GD |
27 | #include "wx/msgdlg.h" |
28 | #include <math.h> | |
2f1ae414 | 29 | #include "wx/mac/uma.h" |
72e7876b | 30 | |
2f1ae414 | 31 | #if !USE_SHARED_LIBRARY |
72e7876b | 32 | IMPLEMENT_CLASS(wxPrinterDC, wxDC) |
2f1ae414 | 33 | #endif |
72e7876b SC |
34 | |
35 | GrafPtr macPrintFormerPort = NULL ; | |
36 | ||
37 | wxPrinterDC::wxPrinterDC(const wxPrintData& printdata) | |
38 | { | |
5b781a67 | 39 | OSStatus err ; |
72e7876b SC |
40 | wxString message ; |
41 | ||
42 | m_printData = printdata ; | |
43 | m_printData.ConvertToNative() ; | |
a689a4d0 | 44 | |
f520d381 GD |
45 | #if TARGET_CARBON && PM_USE_SESSION_APIS |
46 | err = UMAPrOpen(&m_macPrintSession) ; | |
47 | if ( err != noErr || m_macPrintSession == kPMNoData ) | |
87df17a1 GD |
48 | #else |
49 | err = UMAPrOpen() ; | |
f520d381 | 50 | if ( err != noErr ) |
a689a4d0 | 51 | #endif |
72e7876b SC |
52 | { |
53 | message.Printf( "Print Error %d", err ) ; | |
54 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
f520d381 GD |
55 | dialog.ShowModal(); |
56 | #if TARGET_CARBON && PM_USE_SESSION_APIS | |
57 | UMAPrClose(&m_macPrintSession) ; | |
87df17a1 GD |
58 | #else |
59 | UMAPrClose() ; | |
a689a4d0 | 60 | #endif |
f520d381 GD |
61 | m_ok = FALSE; |
62 | return; | |
72e7876b SC |
63 | } |
64 | ||
5b781a67 | 65 | #if !TARGET_CARBON |
72e7876b SC |
66 | if ( ::PrValidate( m_printData.m_macPrintInfo ) ) |
67 | { | |
2f1ae414 | 68 | ::PrStlDialog( m_printData.m_macPrintInfo ) ; |
72e7876b SC |
69 | // the driver has changed in the mean time, should we pop up a page setup dialog ? |
70 | } | |
71 | err = PrError() ; | |
f520d381 | 72 | if ( err != noErr ) |
72e7876b SC |
73 | { |
74 | message.Printf( "Print Error %d", err ) ; | |
75 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
f520d381 | 76 | dialog.ShowModal(); |
2f1ae414 | 77 | UMAPrClose() ; |
f520d381 GD |
78 | m_ok = FALSE; |
79 | return; | |
72e7876b SC |
80 | } |
81 | ::GetPort( &macPrintFormerPort ) ; | |
82 | m_macPrintPort = ::PrOpenDoc( m_printData.m_macPrintInfo , NULL , NULL ) ; | |
2f1ae414 SC |
83 | err = PrError() ; |
84 | if ( err ) | |
85 | { | |
86 | message.Printf( "Print Error %d", err ) ; | |
87 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
f520d381 | 88 | dialog.ShowModal(); |
2f1ae414 | 89 | UMAPrClose() ; |
f520d381 GD |
90 | m_ok = FALSE; |
91 | return; | |
2f1ae414 | 92 | } |
72e7876b SC |
93 | // sets current port |
94 | m_macPort = (GrafPtr ) m_macPrintPort ; | |
5b781a67 | 95 | #else |
a689a4d0 | 96 | #if PM_USE_SESSION_APIS |
f520d381 GD |
97 | err = PMSessionBeginDocument(m_macPrintSession, |
98 | m_printData.m_macPrintSettings, | |
99 | m_printData.m_macPageFormat); | |
100 | if ( err != noErr ) | |
a689a4d0 | 101 | #else |
f520d381 | 102 | m_macPrintPort = kPMNoReference ; |
5b781a67 | 103 | err = PMBeginDocument( |
f520d381 GD |
104 | m_printData.m_macPrintSettings, |
105 | m_printData.m_macPageFormat, | |
106 | &m_macPrintPort); | |
5b781a67 | 107 | if ( err != noErr || m_macPrintPort == kPMNoReference ) |
f520d381 | 108 | #endif |
5b781a67 SC |
109 | { |
110 | message.Printf( "Print Error %d", err ) ; | |
111 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
f520d381 GD |
112 | dialog.ShowModal(); |
113 | #if TARGET_CARBON && PM_USE_SESSION_APIS | |
114 | UMAPrClose(&m_macPrintSession) ; | |
87df17a1 GD |
115 | #else |
116 | UMAPrClose() ; | |
117 | #endif | |
f520d381 GD |
118 | m_ok = FALSE; |
119 | return; | |
5b781a67 SC |
120 | } |
121 | // sets current port | |
122 | ::GetPort( &m_macPort ) ; | |
123 | #endif | |
72e7876b SC |
124 | m_ok = TRUE ; |
125 | m_minY = m_minX = 0 ; | |
5b781a67 | 126 | #if TARGET_CARBON |
f520d381 GD |
127 | PMRect rPaper; |
128 | ||
129 | err = PMGetAdjustedPaperRect(m_printData.m_macPageFormat, &rPaper); | |
130 | if ( err != noErr ) | |
131 | { | |
132 | message.Printf( "Print Error %d", err ) ; | |
133 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
134 | dialog.ShowModal(); | |
135 | #if TARGET_CARBON && PM_USE_SESSION_APIS | |
136 | UMAPrClose(&m_macPrintSession) ; | |
137 | #else | |
138 | UMAPrClose() ; | |
139 | #endif | |
140 | m_ok = FALSE; | |
141 | return; | |
142 | } | |
143 | m_maxX = rPaper.right - rPaper.left ; | |
144 | m_maxY = rPaper.bottom - rPaper.top ; | |
5b781a67 | 145 | #else |
72e7876b SC |
146 | m_maxX = (**m_printData.m_macPrintInfo).rPaper.right - (**m_printData.m_macPrintInfo).rPaper.left ; |
147 | m_maxY = (**m_printData.m_macPrintInfo).rPaper.bottom - (**m_printData.m_macPrintInfo).rPaper.top ; | |
2f1ae414 | 148 | #endif |
72e7876b SC |
149 | } |
150 | ||
151 | wxPrinterDC::~wxPrinterDC(void) | |
152 | { | |
5b781a67 SC |
153 | OSStatus err ; |
154 | wxString message ; | |
2f1ae414 | 155 | #if !TARGET_CARBON |
72e7876b SC |
156 | if ( m_ok ) |
157 | { | |
72e7876b SC |
158 | ::PrCloseDoc( m_macPrintPort ) ; |
159 | err = PrError() ; | |
160 | ||
f520d381 | 161 | if ( err == noErr ) |
72e7876b SC |
162 | { |
163 | if ( (**m_printData.m_macPrintInfo).prJob.bJDocLoop == bSpoolLoop ) | |
164 | { | |
165 | TPrStatus status ; | |
166 | ::PrPicFile( m_printData.m_macPrintInfo , NULL , NULL , NULL , &status ) ; | |
167 | } | |
168 | } | |
169 | else | |
170 | { | |
171 | message.Printf( "Print Error %d", err ) ; | |
172 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
f520d381 | 173 | dialog.ShowModal(); |
72e7876b | 174 | } |
2f1ae414 SC |
175 | ::UMAPrClose() ; |
176 | // ::SetPort( macPrintFormerPort ) ; | |
177 | ::SetPort( LMGetWMgrPort() ) ; | |
72e7876b | 178 | } |
2f1ae414 | 179 | #else |
5b781a67 SC |
180 | if ( m_ok ) |
181 | { | |
a689a4d0 | 182 | #if PM_USE_SESSION_APIS |
f520d381 | 183 | err = PMSessionEndDocument(m_macPrintSession); |
a689a4d0 GD |
184 | #else |
185 | err = PMEndDocument(m_macPrintPort); | |
186 | #endif | |
f520d381 | 187 | if ( err != noErr ) |
5b781a67 SC |
188 | { |
189 | message.Printf( "Print Error %d", err ) ; | |
190 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
f520d381 | 191 | dialog.ShowModal(); |
5b781a67 | 192 | } |
f520d381 GD |
193 | #if TARGET_CARBON && PM_USE_SESSION_APIS |
194 | UMAPrClose(&m_macPrintSession) ; | |
a689a4d0 | 195 | #else |
87df17a1 | 196 | UMAPrClose() ; |
a689a4d0 | 197 | #endif |
5b781a67 | 198 | } |
2f1ae414 | 199 | #endif |
72e7876b SC |
200 | } |
201 | ||
202 | bool wxPrinterDC::StartDoc( const wxString& WXUNUSED(message) ) | |
203 | { | |
204 | return m_ok ; | |
205 | } | |
206 | ||
207 | void wxPrinterDC::EndDoc(void) | |
208 | { | |
209 | } | |
210 | ||
211 | void wxPrinterDC::StartPage(void) | |
212 | { | |
213 | if ( !m_ok ) | |
214 | return ; | |
2f1ae414 SC |
215 | |
216 | m_logicalFunction = wxCOPY; | |
217 | // m_textAlignment = wxALIGN_TOP_LEFT; | |
218 | m_backgroundMode = wxTRANSPARENT; | |
219 | ||
220 | m_textForegroundColour = *wxBLACK; | |
221 | m_textBackgroundColour = *wxWHITE; | |
222 | m_pen = *wxBLACK_PEN; | |
223 | m_font = *wxNORMAL_FONT; | |
224 | m_brush = *wxTRANSPARENT_BRUSH; | |
225 | m_backgroundBrush = *wxWHITE_BRUSH; | |
226 | ||
227 | m_macFontInstalled = false ; | |
228 | m_macBrushInstalled = false ; | |
229 | m_macPenInstalled = false ; | |
230 | ||
72e7876b | 231 | |
5b781a67 | 232 | OSStatus err ; |
72e7876b SC |
233 | wxString message ; |
234 | ||
5b781a67 | 235 | #if !TARGET_CARBON |
2f1ae414 | 236 | PrOpenPage( m_macPrintPort , NULL ) ; |
5b781a67 SC |
237 | m_macLocalOrigin.h = (**m_printData.m_macPrintInfo).rPaper.left ; |
238 | m_macLocalOrigin.v = (**m_printData.m_macPrintInfo).rPaper.top ; | |
239 | ||
72e7876b SC |
240 | Rect clip = { -32000 , -32000 , 32000 , 32000 } ; |
241 | ::ClipRect( &clip ) ; | |
242 | err = PrError() ; | |
f520d381 | 243 | if ( err != noErr ) |
72e7876b SC |
244 | { |
245 | message.Printf( "Print Error %d", err ) ; | |
246 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
f520d381 GD |
247 | dialog.ShowModal(); |
248 | ::PrClosePage( m_macPrintPort ) ; | |
249 | ::PrCloseDoc( m_macPrintPort ) ; | |
2f1ae414 | 250 | ::UMAPrClose() ; |
72e7876b SC |
251 | ::SetPort( macPrintFormerPort ) ; |
252 | m_ok = FALSE ; | |
253 | } | |
2f1ae414 | 254 | #else |
a689a4d0 | 255 | #if PM_USE_SESSION_APIS |
f520d381 | 256 | err = PMSessionBeginPage(m_macPrintSession, |
a689a4d0 GD |
257 | m_printData.m_macPageFormat, |
258 | nil); | |
259 | #else | |
260 | err = PMBeginPage(m_macPrintPort, nil); | |
261 | #endif | |
f520d381 | 262 | if ( err != noErr ) |
5b781a67 SC |
263 | { |
264 | message.Printf( "Print Error %d", err ) ; | |
265 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
f520d381 | 266 | dialog.ShowModal(); |
a689a4d0 | 267 | #if PM_USE_SESSION_APIS |
f520d381 GD |
268 | PMSessionEndPage(m_macPrintSession); |
269 | PMSessionEndDocument(m_macPrintSession); | |
270 | UMAPrClose(&m_macPrintSession) ; | |
a689a4d0 | 271 | #else |
5b781a67 SC |
272 | PMEndPage(m_macPrintPort); |
273 | PMEndDocument(m_macPrintPort); | |
87df17a1 | 274 | UMAPrClose() ; |
a689a4d0 | 275 | #endif |
5b781a67 SC |
276 | ::SetPort( macPrintFormerPort ) ; |
277 | m_ok = FALSE ; | |
278 | } | |
2f1ae414 | 279 | #endif |
72e7876b SC |
280 | } |
281 | ||
282 | void wxPrinterDC::EndPage(void) | |
283 | { | |
284 | if ( !m_ok ) | |
285 | return ; | |
286 | ||
5b781a67 | 287 | OSStatus err ; |
72e7876b SC |
288 | wxString message ; |
289 | ||
5b781a67 | 290 | #if !TARGET_CARBON |
72e7876b SC |
291 | PrClosePage( (TPrPort*) m_macPort ) ; |
292 | err = PrError() ; | |
f520d381 | 293 | if ( err != noErr ) |
72e7876b SC |
294 | { |
295 | message.Printf( "Print Error %d", err ) ; | |
296 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
f520d381 | 297 | dialog.ShowModal(); |
72e7876b | 298 | ::PrCloseDoc( m_macPrintPort ) ; |
2f1ae414 | 299 | ::UMAPrClose() ; |
72e7876b SC |
300 | ::SetPort( macPrintFormerPort ) ; |
301 | m_ok = FALSE ; | |
302 | } | |
2f1ae414 | 303 | #else |
a689a4d0 | 304 | #if PM_USE_SESSION_APIS |
f520d381 | 305 | err = PMSessionEndPage(m_macPrintSession); |
a689a4d0 | 306 | #else |
5b781a67 | 307 | err = PMEndPage(m_macPrintPort); |
a689a4d0 | 308 | #endif |
f520d381 | 309 | if ( err != noErr ) |
5b781a67 SC |
310 | { |
311 | message.Printf( "Print Error %d", err ) ; | |
312 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
f520d381 | 313 | dialog.ShowModal(); |
a689a4d0 | 314 | #if PM_USE_SESSION_APIS |
f520d381 GD |
315 | PMSessionEndDocument(m_macPrintSession); |
316 | UMAPrClose(&m_macPrintSession) ; | |
a689a4d0 | 317 | #else |
5b781a67 | 318 | PMEndDocument(m_macPrintPort); |
87df17a1 | 319 | UMAPrClose() ; |
a689a4d0 | 320 | #endif |
5b781a67 SC |
321 | ::SetPort( macPrintFormerPort ) ; |
322 | m_ok = FALSE ; | |
323 | } | |
2f1ae414 SC |
324 | #endif |
325 | ||
72e7876b | 326 | } |