]>
Commit | Line | Data |
---|---|---|
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 | |
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" | |
27 | #include "wx/msgdlg.h" | |
28 | #include <math.h> | |
29 | #include "wx/mac/uma.h" | |
30 | #ifndef __DARWIN__ | |
31 | #include "Printing.h" | |
32 | #endif | |
33 | ||
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 | ||
41 | #if !USE_SHARED_LIBRARY | |
42 | IMPLEMENT_CLASS(wxPrinterDC, wxDC) | |
43 | #endif | |
44 | ||
45 | GrafPtr macPrintFormerPort = NULL ; | |
46 | ||
47 | wxPrinterDC::wxPrinterDC(const wxPrintData& printdata) | |
48 | { | |
49 | OSStatus err = noErr ; | |
50 | wxString message ; | |
51 | ||
52 | m_printData = printdata ; | |
53 | m_printData.ConvertToNative() ; | |
54 | ||
55 | #if TARGET_CARBON && PM_USE_SESSION_APIS | |
56 | m_macPrintSessionPort = printdata.m_macPrintSession ; | |
57 | PMRetain( m_macPrintSessionPort ) ; | |
58 | ||
59 | if ( err != noErr || m_macPrintSessionPort == kPMNoData ) | |
60 | #else | |
61 | err = UMAPrOpen(NULL) ; | |
62 | if ( err != noErr ) | |
63 | #endif | |
64 | { | |
65 | message.Printf( wxT("Print Error %ld"), err ) ; | |
66 | wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ; | |
67 | dialog.ShowModal(); | |
68 | #if TARGET_CARBON && PM_USE_SESSION_APIS | |
69 | PMRelease( m_macPrintSessionPort ) ; | |
70 | #else | |
71 | UMAPrClose(NULL) ; | |
72 | #endif | |
73 | m_ok = FALSE; | |
74 | return; | |
75 | } | |
76 | ||
77 | #if !TARGET_CARBON | |
78 | if ( ::PrValidate( (THPrint) m_printData.m_macPrintSettings ) ) | |
79 | { | |
80 | // the driver has changed in the mean time, should we pop up a page setup dialog ? | |
81 | if ( !::PrStlDialog( (THPrint) m_printData.m_macPrintSettings ) ) | |
82 | { | |
83 | UMAPrClose(NULL) ; | |
84 | m_ok = FALSE; | |
85 | return; | |
86 | } | |
87 | } | |
88 | err = PrError() ; | |
89 | if ( err != noErr ) | |
90 | { | |
91 | message.Printf( wxT("Print Error %ld"), err ) ; | |
92 | wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ; | |
93 | dialog.ShowModal(); | |
94 | UMAPrClose(NULL) ; | |
95 | m_ok = FALSE; | |
96 | return; | |
97 | } | |
98 | ::GetPort( &macPrintFormerPort ) ; | |
99 | /* | |
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 ; | |
113 | */ | |
114 | #else | |
115 | /* | |
116 | #if PM_USE_SESSION_APIS | |
117 | err = PMSessionBeginDocument((PMPrintSession)m_macPrintSessionPort, | |
118 | (PMPrintSettings)m_printData.m_macPrintSettings, | |
119 | (PMPageFormat)m_printData.m_macPageFormat); | |
120 | if ( err != noErr ) | |
121 | #else | |
122 | m_macPrintSessionPort = kPMNoReference ; | |
123 | err = PMBeginDocument( | |
124 | m_printData.m_macPrintSettings, | |
125 | m_printData.m_macPageFormat, | |
126 | &m_macPrintSessionPort); | |
127 | if ( err != noErr || m_macPrintSessionPort == kPMNoReference ) | |
128 | #endif | |
129 | { | |
130 | message.Printf( "Print Error %ld", err ) ; | |
131 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
132 | dialog.ShowModal(); | |
133 | #if TARGET_CARBON && PM_USE_SESSION_APIS | |
134 | PMRelease(&m_macPrintSessionPort) ; | |
135 | #else | |
136 | UMAPrClose(NULL) ; | |
137 | #endif | |
138 | m_ok = FALSE; | |
139 | return; | |
140 | } | |
141 | // sets current port | |
142 | ::GetPort( (GrafPtr *)&m_macPort ) ; | |
143 | */ | |
144 | #endif | |
145 | m_ok = TRUE ; | |
146 | m_minY = m_minX = 0 ; | |
147 | #if TARGET_CARBON | |
148 | PMRect rPage; | |
149 | ||
150 | err = PMGetAdjustedPageRect((PMPageFormat)m_printData.m_macPageFormat, &rPage); | |
151 | if ( err != noErr ) | |
152 | { | |
153 | message.Printf( wxT("Print Error %ld"), err ) ; | |
154 | wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ; | |
155 | dialog.ShowModal(); | |
156 | #if TARGET_CARBON && PM_USE_SESSION_APIS | |
157 | PMRelease(&m_macPrintSessionPort) ; | |
158 | #else | |
159 | UMAPrClose(NULL) ; | |
160 | #endif | |
161 | m_ok = FALSE; | |
162 | return; | |
163 | } | |
164 | m_maxX = wxCoord(rPage.right - rPage.left) ; | |
165 | m_maxY = wxCoord(rPage.bottom - rPage.top); | |
166 | #else | |
167 | m_maxX = (**(THPrint)m_printData.m_macPrintSettings).rPage.right - (**(THPrint)m_printData.m_macPrintSettings).rPage.left ; | |
168 | m_maxY = (**(THPrint)m_printData.m_macPrintSettings).rPage.bottom - (**(THPrint)m_printData.m_macPrintSettings).rPage.top ; | |
169 | #endif | |
170 | } | |
171 | ||
172 | wxPrinterDC::~wxPrinterDC(void) | |
173 | { | |
174 | OSStatus err ; | |
175 | wxString message ; | |
176 | #if !TARGET_CARBON | |
177 | if ( m_ok ) | |
178 | { | |
179 | /* | |
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 | } | |
197 | */ | |
198 | ::UMAPrClose(NULL) ; | |
199 | // ::SetPort( macPrintFormerPort ) ; | |
200 | ::SetPort( LMGetWMgrPort() ) ; | |
201 | } | |
202 | #else | |
203 | if ( m_ok ) | |
204 | { | |
205 | /* | |
206 | #if PM_USE_SESSION_APIS | |
207 | err = PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort); | |
208 | #else | |
209 | err = PMEndDocument(m_macPrintSessionPort); | |
210 | #endif | |
211 | if ( err != noErr ) | |
212 | { | |
213 | message.Printf( "Print Error %ld", err ) ; | |
214 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
215 | dialog.ShowModal(); | |
216 | } | |
217 | */ | |
218 | #if TARGET_CARBON && PM_USE_SESSION_APIS | |
219 | PMRelease(&m_macPrintSessionPort) ; | |
220 | #else | |
221 | UMAPrClose(NULL) ; | |
222 | #endif | |
223 | } | |
224 | #endif | |
225 | } | |
226 | ||
227 | bool wxPrinterDC::StartDoc( const wxString& WXUNUSED(message) ) | |
228 | { | |
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( wxT("Print Error %d"), err ) ; | |
238 | wxMessageDialog dialog( NULL , message , wxEmptyString, 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( wxT("Print Error %d"), err ) ; | |
262 | wxMessageDialog dialog( NULL , message , wxEmptyString, 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 rPage; | |
279 | ||
280 | err = PMGetAdjustedPageRect((PMPageFormat)m_printData.m_macPageFormat, &rPage); | |
281 | if ( err != noErr ) | |
282 | { | |
283 | message.Printf( wxT("Print Error %d"), err ) ; | |
284 | wxMessageDialog dialog( NULL , message , wxEmptyString, 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 = rPage.right - rPage.left ; | |
295 | m_maxY = rPage.bottom - rPage.top ; | |
296 | #else | |
297 | m_maxX = (**(THPrint)m_printData.m_macPrintSettings).rPage.right - (**(THPrint)m_printData.m_macPrintSettings).rPage.left ; | |
298 | m_maxY = (**(THPrint)m_printData.m_macPrintSettings).rPage.bottom - (**(THPrint)m_printData.m_macPrintSettings).rPage.top ; | |
299 | #endif | |
300 | return m_ok ; | |
301 | } | |
302 | ||
303 | void wxPrinterDC::EndDoc(void) | |
304 | { | |
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( wxT("Print Error %d"), err ) ; | |
325 | wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ; | |
326 | dialog.ShowModal(); | |
327 | } | |
328 | } | |
329 | #endif | |
330 | } | |
331 | ||
332 | void wxPrinterDC::StartPage(void) | |
333 | { | |
334 | if ( !m_ok ) | |
335 | return ; | |
336 | ||
337 | m_logicalFunction = wxCOPY; | |
338 | // m_textAlignment = wxALIGN_TOP_LEFT; | |
339 | m_backgroundMode = wxTRANSPARENT; | |
340 | ||
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; | |
347 | ||
348 | m_macFontInstalled = false ; | |
349 | m_macBrushInstalled = false ; | |
350 | m_macPenInstalled = false ; | |
351 | ||
352 | ||
353 | OSStatus err ; | |
354 | wxString message ; | |
355 | ||
356 | #if !TARGET_CARBON | |
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( wxT("Print Error %ld"), err ) ; | |
367 | wxMessageDialog dialog( NULL , message , wxEmptyString , 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 | } | |
375 | #else | |
376 | #if PM_USE_SESSION_APIS | |
377 | err = PMSessionBeginPage((PMPrintSession)m_macPrintSessionPort, | |
378 | (PMPageFormat)m_printData.m_macPageFormat, | |
379 | nil); | |
380 | #else | |
381 | err = PMBeginPage(m_macPrintSessionPort, nil); | |
382 | #endif | |
383 | if ( err != noErr ) | |
384 | { | |
385 | message.Printf( wxT("Print Error %ld"), err ) ; | |
386 | wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ; | |
387 | dialog.ShowModal(); | |
388 | #if PM_USE_SESSION_APIS | |
389 | PMSessionEndPage((PMPrintSession)m_macPrintSessionPort); | |
390 | PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort); | |
391 | UMAPrClose(&m_macPrintSessionPort) ; | |
392 | #else | |
393 | PMEndPage(m_macPrintSessionPort); | |
394 | PMEndDocument(m_macPrintSessionPort); | |
395 | UMAPrClose(NULL) ; | |
396 | #endif | |
397 | ::SetPort( macPrintFormerPort ) ; | |
398 | m_ok = FALSE ; | |
399 | } | |
400 | PMRect rPage; | |
401 | ||
402 | err = PMGetAdjustedPageRect((PMPageFormat)m_printData.m_macPageFormat, &rPage); | |
403 | if ( !err ) | |
404 | { | |
405 | m_macLocalOrigin.x = rPage.left ; | |
406 | m_macLocalOrigin.y = rPage.top ; | |
407 | } | |
408 | #endif | |
409 | } | |
410 | ||
411 | void wxPrinterDC::EndPage(void) | |
412 | { | |
413 | if ( !m_ok ) | |
414 | return ; | |
415 | ||
416 | OSStatus err ; | |
417 | wxString message ; | |
418 | ||
419 | #if !TARGET_CARBON | |
420 | PrClosePage( (TPPrPort) m_macPort ) ; | |
421 | err = PrError() ; | |
422 | if ( err != noErr ) | |
423 | { | |
424 | message.Printf( wxT("Print Error %ld") , err ) ; | |
425 | wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ; | |
426 | dialog.ShowModal(); | |
427 | ::PrCloseDoc( (TPPrPort) m_macPrintSessionPort ) ; | |
428 | ::UMAPrClose(NULL) ; | |
429 | ::SetPort( macPrintFormerPort ) ; | |
430 | m_ok = FALSE ; | |
431 | } | |
432 | #else | |
433 | #if PM_USE_SESSION_APIS | |
434 | err = PMSessionEndPage((PMPrintSession)m_macPrintSessionPort); | |
435 | #else | |
436 | err = PMEndPage(m_macPrintSessionPort); | |
437 | #endif | |
438 | if ( err != noErr ) | |
439 | { | |
440 | message.Printf( wxT("Print Error %ld"), err ) ; | |
441 | wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ; | |
442 | dialog.ShowModal(); | |
443 | #if PM_USE_SESSION_APIS | |
444 | PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort); | |
445 | UMAPrClose(&m_macPrintSessionPort) ; | |
446 | #else | |
447 | PMEndDocument(m_macPrintSessionPort); | |
448 | UMAPrClose(NULL) ; | |
449 | #endif | |
450 | ::SetPort( macPrintFormerPort ) ; | |
451 | m_ok = FALSE ; | |
452 | } | |
453 | #endif | |
454 | ||
455 | } |