]>
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$ | |
6aa89a22 | 8 | // Copyright: (c) Julian Smart |
e40298d5 | 9 | // Licence: wxWindows licence |
72e7876b SC |
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" |
66a09d47 SC |
30 | #ifndef __DARWIN__ |
31 | #include "Printing.h" | |
32 | #endif | |
72e7876b | 33 | |
a3d3d3bf GD |
34 | #if defined(TARGET_CARBON) && !defined(__DARWIN__) |
35 | # if PM_USE_SESSION_APIS | |
36 | # include <PMCore.h> | |
37 | # endif | |
38 | # include <PMApplication.h> | |
39 | #endif | |
40 | ||
2f1ae414 | 41 | #if !USE_SHARED_LIBRARY |
72e7876b | 42 | IMPLEMENT_CLASS(wxPrinterDC, wxDC) |
2f1ae414 | 43 | #endif |
72e7876b SC |
44 | |
45 | GrafPtr macPrintFormerPort = NULL ; | |
46 | ||
47 | wxPrinterDC::wxPrinterDC(const wxPrintData& printdata) | |
48 | { | |
75411508 | 49 | OSStatus err = noErr ; |
e40298d5 JS |
50 | wxString message ; |
51 | ||
52 | m_printData = printdata ; | |
53 | m_printData.ConvertToNative() ; | |
a689a4d0 | 54 | |
f520d381 | 55 | #if TARGET_CARBON && PM_USE_SESSION_APIS |
75411508 SC |
56 | m_macPrintSessionPort = printdata.m_macPrintSession ; |
57 | PMRetain( m_macPrintSessionPort ) ; | |
58 | ||
e40298d5 | 59 | if ( err != noErr || m_macPrintSessionPort == kPMNoData ) |
87df17a1 | 60 | #else |
e40298d5 JS |
61 | err = UMAPrOpen(NULL) ; |
62 | if ( err != noErr ) | |
a689a4d0 | 63 | #endif |
e40298d5 JS |
64 | { |
65 | message.Printf( "Print Error %ld", err ) ; | |
66 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
67 | dialog.ShowModal(); | |
f520d381 | 68 | #if TARGET_CARBON && PM_USE_SESSION_APIS |
75411508 | 69 | PMRelease( m_macPrintSessionPort ) ; |
87df17a1 | 70 | #else |
e40298d5 | 71 | UMAPrClose(NULL) ; |
a689a4d0 | 72 | #endif |
e40298d5 JS |
73 | m_ok = FALSE; |
74 | return; | |
75 | } | |
76 | ||
5b781a67 | 77 | #if !TARGET_CARBON |
e40298d5 JS |
78 | if ( ::PrValidate( (THPrint) m_printData.m_macPrintSettings ) ) |
79 | { | |
e40298d5 | 80 | // the driver has changed in the mean time, should we pop up a page setup dialog ? |
75411508 SC |
81 | if ( !::PrStlDialog( (THPrint) m_printData.m_macPrintSettings ) ) |
82 | { | |
83 | UMAPrClose(NULL) ; | |
84 | m_ok = FALSE; | |
85 | return; | |
86 | } | |
e40298d5 JS |
87 | } |
88 | err = PrError() ; | |
89 | if ( err != noErr ) | |
90 | { | |
91 | message.Printf( "Print Error %ld", err ) ; | |
92 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
93 | dialog.ShowModal(); | |
94 | UMAPrClose(NULL) ; | |
95 | m_ok = FALSE; | |
96 | return; | |
97 | } | |
98 | ::GetPort( &macPrintFormerPort ) ; | |
75411508 | 99 | /* |
e40298d5 JS |
100 | m_macPrintSessionPort = ::PrOpenDoc( (THPrint) m_printData.m_macPrintSettings , NULL , NULL ) ; |
101 | err = PrError() ; | |
102 | if ( err ) | |
103 | { | |
104 | message.Printf( "Print Error %ld", err ) ; | |
105 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
106 | dialog.ShowModal(); | |
107 | UMAPrClose(NULL) ; | |
108 | m_ok = FALSE; | |
109 | return; | |
110 | } | |
111 | // sets current port | |
112 | m_macPort = (GrafPtr ) m_macPrintSessionPort ; | |
75411508 | 113 | */ |
5b781a67 | 114 | #else |
75411508 | 115 | /* |
a689a4d0 | 116 | #if PM_USE_SESSION_APIS |
1d78308f | 117 | err = PMSessionBeginDocument((PMPrintSession)m_macPrintSessionPort, |
962cbf2e | 118 | (PMPrintSettings)m_printData.m_macPrintSettings, |
e40298d5 | 119 | (PMPageFormat)m_printData.m_macPageFormat); |
f520d381 | 120 | if ( err != noErr ) |
a689a4d0 | 121 | #else |
e40298d5 | 122 | m_macPrintSessionPort = kPMNoReference ; |
5b781a67 | 123 | err = PMBeginDocument( |
e40298d5 JS |
124 | m_printData.m_macPrintSettings, |
125 | m_printData.m_macPageFormat, | |
126 | &m_macPrintSessionPort); | |
1d78308f | 127 | if ( err != noErr || m_macPrintSessionPort == kPMNoReference ) |
f520d381 | 128 | #endif |
5b781a67 | 129 | { |
e40298d5 JS |
130 | message.Printf( "Print Error %ld", err ) ; |
131 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
132 | dialog.ShowModal(); | |
f520d381 | 133 | #if TARGET_CARBON && PM_USE_SESSION_APIS |
75411508 | 134 | PMRelease(&m_macPrintSessionPort) ; |
87df17a1 | 135 | #else |
e40298d5 | 136 | UMAPrClose(NULL) ; |
87df17a1 | 137 | #endif |
e40298d5 JS |
138 | m_ok = FALSE; |
139 | return; | |
5b781a67 | 140 | } |
e40298d5 JS |
141 | // sets current port |
142 | ::GetPort( (GrafPtr *)&m_macPort ) ; | |
75411508 | 143 | */ |
5b781a67 | 144 | #endif |
e40298d5 JS |
145 | m_ok = TRUE ; |
146 | m_minY = m_minX = 0 ; | |
5b781a67 | 147 | #if TARGET_CARBON |
e40298d5 JS |
148 | PMRect rPaper; |
149 | ||
150 | err = PMGetAdjustedPaperRect((PMPageFormat)m_printData.m_macPageFormat, &rPaper); | |
f520d381 GD |
151 | if ( err != noErr ) |
152 | { | |
e40298d5 JS |
153 | message.Printf( "Print Error %ld", err ) ; |
154 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
155 | dialog.ShowModal(); | |
f520d381 | 156 | #if TARGET_CARBON && PM_USE_SESSION_APIS |
75411508 | 157 | PMRelease(&m_macPrintSessionPort) ; |
f520d381 | 158 | #else |
e40298d5 | 159 | UMAPrClose(NULL) ; |
f520d381 | 160 | #endif |
e40298d5 JS |
161 | m_ok = FALSE; |
162 | return; | |
f520d381 | 163 | } |
e40298d5 JS |
164 | m_maxX = wxCoord(rPaper.right - rPaper.left) ; |
165 | m_maxY = wxCoord(rPaper.bottom - rPaper.top); | |
5b781a67 | 166 | #else |
e40298d5 JS |
167 | m_maxX = (**(THPrint)m_printData.m_macPrintSettings).rPaper.right - (**(THPrint)m_printData.m_macPrintSettings).rPaper.left ; |
168 | m_maxY = (**(THPrint)m_printData.m_macPrintSettings).rPaper.bottom - (**(THPrint)m_printData.m_macPrintSettings).rPaper.top ; | |
2f1ae414 | 169 | #endif |
72e7876b SC |
170 | } |
171 | ||
172 | wxPrinterDC::~wxPrinterDC(void) | |
173 | { | |
e40298d5 JS |
174 | OSStatus err ; |
175 | wxString message ; | |
2f1ae414 | 176 | #if !TARGET_CARBON |
e40298d5 JS |
177 | if ( m_ok ) |
178 | { | |
75411508 | 179 | /* |
e40298d5 JS |
180 | ::PrCloseDoc( (TPPrPort) m_macPrintSessionPort ) ; |
181 | err = PrError() ; | |
182 | ||
183 | if ( err == noErr ) | |
184 | { | |
185 | if ( (**(THPrint)m_printData.m_macPrintSettings).prJob.bJDocLoop == bSpoolLoop ) | |
186 | { | |
187 | TPrStatus status ; | |
188 | ::PrPicFile( (THPrint) m_printData.m_macPrintSettings , NULL , NULL , NULL , &status ) ; | |
189 | } | |
190 | } | |
191 | else | |
192 | { | |
193 | message.Printf( "Print Error %ld", err ) ; | |
194 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
195 | dialog.ShowModal(); | |
196 | } | |
75411508 | 197 | */ |
e40298d5 JS |
198 | ::UMAPrClose(NULL) ; |
199 | // ::SetPort( macPrintFormerPort ) ; | |
200 | ::SetPort( LMGetWMgrPort() ) ; | |
201 | } | |
2f1ae414 | 202 | #else |
e40298d5 JS |
203 | if ( m_ok ) |
204 | { | |
75411508 | 205 | /* |
a689a4d0 | 206 | #if PM_USE_SESSION_APIS |
e40298d5 | 207 | err = PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort); |
a689a4d0 | 208 | #else |
e40298d5 | 209 | err = PMEndDocument(m_macPrintSessionPort); |
a689a4d0 | 210 | #endif |
e40298d5 JS |
211 | if ( err != noErr ) |
212 | { | |
213 | message.Printf( "Print Error %ld", err ) ; | |
214 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
215 | dialog.ShowModal(); | |
216 | } | |
75411508 | 217 | */ |
f520d381 | 218 | #if TARGET_CARBON && PM_USE_SESSION_APIS |
75411508 | 219 | PMRelease(&m_macPrintSessionPort) ; |
a689a4d0 | 220 | #else |
e40298d5 | 221 | UMAPrClose(NULL) ; |
a689a4d0 | 222 | #endif |
e40298d5 | 223 | } |
2f1ae414 | 224 | #endif |
72e7876b SC |
225 | } |
226 | ||
227 | bool wxPrinterDC::StartDoc( const wxString& WXUNUSED(message) ) | |
228 | { | |
75411508 SC |
229 | OSStatus err = noErr ; |
230 | wxString message ; | |
231 | ||
232 | #if !TARGET_CARBON | |
233 | m_macPrintSessionPort = ::PrOpenDoc( (THPrint) m_printData.m_macPrintSettings , NULL , NULL ) ; | |
234 | err = PrError() ; | |
235 | if ( err ) | |
236 | { | |
237 | message.Printf( "Print Error %d", err ) ; | |
238 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
239 | dialog.ShowModal(); | |
240 | UMAPrClose(NULL) ; | |
241 | m_ok = FALSE; | |
242 | return false ; | |
243 | } | |
244 | // sets current port | |
245 | m_macPort = (GrafPtr ) m_macPrintSessionPort ; | |
246 | #else | |
247 | #if PM_USE_SESSION_APIS | |
248 | err = PMSessionBeginDocument((PMPrintSession)m_macPrintSessionPort, | |
249 | (PMPrintSettings)m_printData.m_macPrintSettings, | |
250 | (PMPageFormat)m_printData.m_macPageFormat); | |
251 | if ( err != noErr ) | |
252 | #else | |
253 | m_macPrintSessionPort = kPMNoReference ; | |
254 | err = PMBeginDocument( | |
255 | m_printData.m_macPrintSettings, | |
256 | m_printData.m_macPageFormat, | |
257 | &m_macPrintSessionPort); | |
258 | if ( err != noErr || m_macPrintSessionPort == kPMNoReference ) | |
259 | #endif | |
260 | { | |
261 | message.Printf( "Print Error %d", err ) ; | |
262 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
263 | dialog.ShowModal(); | |
264 | #if TARGET_CARBON && PM_USE_SESSION_APIS | |
265 | PMRelease(&m_macPrintSessionPort) ; | |
266 | #else | |
267 | UMAPrClose(NULL) ; | |
268 | #endif | |
269 | m_ok = FALSE; | |
270 | return m_ok; | |
271 | } | |
272 | // sets current port | |
273 | ::GetPort( (GrafPtr *)&m_macPort ) ; | |
274 | #endif | |
275 | m_ok = TRUE ; | |
276 | m_minY = m_minX = 0 ; | |
277 | #if TARGET_CARBON | |
278 | PMRect rPaper; | |
279 | ||
280 | err = PMGetAdjustedPaperRect((PMPageFormat)m_printData.m_macPageFormat, &rPaper); | |
281 | if ( err != noErr ) | |
282 | { | |
283 | message.Printf( "Print Error %d", err ) ; | |
284 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
285 | dialog.ShowModal(); | |
286 | #if TARGET_CARBON && PM_USE_SESSION_APIS | |
287 | PMRelease(&m_macPrintSessionPort) ; | |
288 | #else | |
289 | UMAPrClose(NULL) ; | |
290 | #endif | |
291 | m_ok = FALSE; | |
292 | return m_ok; | |
293 | } | |
294 | m_maxX = rPaper.right - rPaper.left ; | |
295 | m_maxY = rPaper.bottom - rPaper.top ; | |
296 | #else | |
297 | m_maxX = (**(THPrint)m_printData.m_macPrintSettings).rPaper.right - (**(THPrint)m_printData.m_macPrintSettings).rPaper.left ; | |
298 | m_maxY = (**(THPrint)m_printData.m_macPrintSettings).rPaper.bottom - (**(THPrint)m_printData.m_macPrintSettings).rPaper.top ; | |
299 | #endif | |
e40298d5 | 300 | return m_ok ; |
72e7876b SC |
301 | } |
302 | ||
303 | void wxPrinterDC::EndDoc(void) | |
304 | { | |
75411508 SC |
305 | OSStatus err ; |
306 | wxString message ; | |
307 | #if !TARGET_CARBON | |
308 | if ( m_ok ) | |
309 | { | |
310 | ::UMAPrClose(NULL) ; | |
311 | // ::SetPort( macPrintFormerPort ) ; | |
312 | ::SetPort( LMGetWMgrPort() ) ; | |
313 | } | |
314 | #else | |
315 | if ( m_ok ) | |
316 | { | |
317 | #if PM_USE_SESSION_APIS | |
318 | err = PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort); | |
319 | #else | |
320 | err = PMEndDocument(m_macPrintSessionPort); | |
321 | #endif | |
322 | if ( err != noErr ) | |
323 | { | |
324 | message.Printf( "Print Error %d", err ) ; | |
325 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
326 | dialog.ShowModal(); | |
327 | } | |
328 | } | |
329 | #endif | |
72e7876b SC |
330 | } |
331 | ||
332 | void wxPrinterDC::StartPage(void) | |
333 | { | |
e40298d5 JS |
334 | if ( !m_ok ) |
335 | return ; | |
2f1ae414 | 336 | |
e40298d5 | 337 | m_logicalFunction = wxCOPY; |
2f1ae414 | 338 | // m_textAlignment = wxALIGN_TOP_LEFT; |
e40298d5 | 339 | m_backgroundMode = wxTRANSPARENT; |
2f1ae414 | 340 | |
e40298d5 JS |
341 | m_textForegroundColour = *wxBLACK; |
342 | m_textBackgroundColour = *wxWHITE; | |
343 | m_pen = *wxBLACK_PEN; | |
344 | m_font = *wxNORMAL_FONT; | |
345 | m_brush = *wxTRANSPARENT_BRUSH; | |
346 | m_backgroundBrush = *wxWHITE_BRUSH; | |
2f1ae414 | 347 | |
e40298d5 JS |
348 | m_macFontInstalled = false ; |
349 | m_macBrushInstalled = false ; | |
350 | m_macPenInstalled = false ; | |
2f1ae414 | 351 | |
e40298d5 JS |
352 | |
353 | OSStatus err ; | |
354 | wxString message ; | |
72e7876b | 355 | |
5b781a67 | 356 | #if !TARGET_CARBON |
e40298d5 JS |
357 | PrOpenPage( (TPPrPort) m_macPrintSessionPort , NULL ) ; |
358 | m_macLocalOrigin.x = (**(THPrint)m_printData.m_macPrintSettings).rPaper.left ; | |
359 | m_macLocalOrigin.y = (**(THPrint)m_printData.m_macPrintSettings).rPaper.top ; | |
360 | ||
361 | Rect clip = { -32000 , -32000 , 32000 , 32000 } ; | |
362 | ::ClipRect( &clip ) ; | |
363 | err = PrError() ; | |
364 | if ( err != noErr ) | |
365 | { | |
366 | message.Printf( "Print Error %ld", err ) ; | |
367 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
368 | dialog.ShowModal(); | |
369 | ::PrClosePage( (TPPrPort) m_macPrintSessionPort ) ; | |
370 | ::PrCloseDoc( (TPPrPort) m_macPrintSessionPort ) ; | |
371 | ::UMAPrClose(NULL) ; | |
372 | ::SetPort( macPrintFormerPort ) ; | |
373 | m_ok = FALSE ; | |
374 | } | |
2f1ae414 | 375 | #else |
a689a4d0 | 376 | #if PM_USE_SESSION_APIS |
e40298d5 JS |
377 | err = PMSessionBeginPage((PMPrintSession)m_macPrintSessionPort, |
378 | (PMPageFormat)m_printData.m_macPageFormat, | |
379 | nil); | |
a689a4d0 | 380 | #else |
e40298d5 | 381 | err = PMBeginPage(m_macPrintSessionPort, nil); |
a689a4d0 | 382 | #endif |
e40298d5 JS |
383 | if ( err != noErr ) |
384 | { | |
385 | message.Printf( "Print Error %ld", err ) ; | |
386 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
387 | dialog.ShowModal(); | |
a689a4d0 | 388 | #if PM_USE_SESSION_APIS |
e40298d5 JS |
389 | PMSessionEndPage((PMPrintSession)m_macPrintSessionPort); |
390 | PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort); | |
391 | UMAPrClose(&m_macPrintSessionPort) ; | |
a689a4d0 | 392 | #else |
e40298d5 JS |
393 | PMEndPage(m_macPrintSessionPort); |
394 | PMEndDocument(m_macPrintSessionPort); | |
395 | UMAPrClose(NULL) ; | |
a689a4d0 | 396 | #endif |
e40298d5 JS |
397 | ::SetPort( macPrintFormerPort ) ; |
398 | m_ok = FALSE ; | |
399 | } | |
75411508 SC |
400 | PMRect rPaper; |
401 | ||
402 | err = PMGetAdjustedPaperRect((PMPageFormat)m_printData.m_macPageFormat, &rPaper); | |
403 | if ( !err ) | |
404 | { | |
405 | m_macLocalOrigin.x = rPaper.left ; | |
406 | m_macLocalOrigin.y = rPaper.top ; | |
407 | } | |
2f1ae414 | 408 | #endif |
72e7876b SC |
409 | } |
410 | ||
411 | void wxPrinterDC::EndPage(void) | |
412 | { | |
e40298d5 JS |
413 | if ( !m_ok ) |
414 | return ; | |
72e7876b | 415 | |
e40298d5 JS |
416 | OSStatus err ; |
417 | wxString message ; | |
72e7876b | 418 | |
5b781a67 | 419 | #if !TARGET_CARBON |
75411508 | 420 | PrClosePage( (TPPrPort) m_macPort ) ; |
e40298d5 JS |
421 | err = PrError() ; |
422 | if ( err != noErr ) | |
423 | { | |
424 | message.Printf( "Print Error %ld", err ) ; | |
425 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
426 | dialog.ShowModal(); | |
427 | ::PrCloseDoc( (TPPrPort) m_macPrintSessionPort ) ; | |
428 | ::UMAPrClose(NULL) ; | |
429 | ::SetPort( macPrintFormerPort ) ; | |
430 | m_ok = FALSE ; | |
431 | } | |
2f1ae414 | 432 | #else |
a689a4d0 | 433 | #if PM_USE_SESSION_APIS |
e40298d5 | 434 | err = PMSessionEndPage((PMPrintSession)m_macPrintSessionPort); |
a689a4d0 | 435 | #else |
e40298d5 | 436 | err = PMEndPage(m_macPrintSessionPort); |
a689a4d0 | 437 | #endif |
e40298d5 JS |
438 | if ( err != noErr ) |
439 | { | |
440 | message.Printf( "Print Error %ld", err ) ; | |
441 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
442 | dialog.ShowModal(); | |
a689a4d0 | 443 | #if PM_USE_SESSION_APIS |
e40298d5 JS |
444 | PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort); |
445 | UMAPrClose(&m_macPrintSessionPort) ; | |
a689a4d0 | 446 | #else |
e40298d5 JS |
447 | PMEndDocument(m_macPrintSessionPort); |
448 | UMAPrClose(NULL) ; | |
a689a4d0 | 449 | #endif |
e40298d5 JS |
450 | ::SetPort( macPrintFormerPort ) ; |
451 | m_ok = FALSE ; | |
452 | } | |
2f1ae414 SC |
453 | #endif |
454 | ||
72e7876b | 455 | } |