]>
Commit | Line | Data |
---|---|---|
72e7876b SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: printwin.cpp | |
3 | // Purpose: wxMacPrinter framework | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6aa89a22 JS |
8 | // Copyright: (c) Julian Smart |
9 | // Licence: wxWindows licence | |
72e7876b SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "printwin.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 | #include "wx/defs.h" | |
24 | ||
25 | #ifndef WX_PRECOMP | |
26 | #include "wx/utils.h" | |
27 | #include "wx/dc.h" | |
28 | #include "wx/app.h" | |
29 | #include "wx/msgdlg.h" | |
30 | #endif | |
31 | ||
746d7582 | 32 | #include "wx/mac/uma.h" |
76a5e5d2 | 33 | |
72e7876b | 34 | #include "wx/mac/printmac.h" |
746d7582 SC |
35 | #include "wx/mac/private/print.h" |
36 | ||
37 | #define mm2pt 2.83464566929 | |
38 | #define pt2mm 0.352777777778 | |
39 | ||
72e7876b SC |
40 | #include "wx/dcprint.h" |
41 | #include "wx/printdlg.h" | |
42 | ||
43 | #include <stdlib.h> | |
44 | ||
2f1ae414 | 45 | #if !USE_SHARED_LIBRARY |
72e7876b SC |
46 | IMPLEMENT_DYNAMIC_CLASS(wxMacPrinter, wxPrinterBase) |
47 | IMPLEMENT_CLASS(wxMacPrintPreview, wxPrintPreviewBase) | |
2f1ae414 | 48 | #endif |
72e7876b | 49 | |
746d7582 SC |
50 | #if TARGET_CARBON |
51 | ||
52 | wxNativePrintData* wxNativePrintData::Create() | |
53 | { | |
54 | return new wxMacCarbonPrintData() ; | |
55 | } | |
56 | ||
57 | wxMacCarbonPrintData::wxMacCarbonPrintData() | |
58 | { | |
59 | m_macPageFormat = kPMNoPageFormat; | |
60 | m_macPrintSettings = kPMNoPrintSettings; | |
61 | m_macPrintSession = kPMNoReference ; | |
62 | ValidateOrCreate() ; | |
63 | } | |
64 | ||
65 | wxMacCarbonPrintData::~wxMacCarbonPrintData() | |
66 | { | |
67 | if (m_macPageFormat != kPMNoPageFormat) | |
68 | { | |
69 | (void)PMRelease(m_macPageFormat); | |
70 | m_macPageFormat = kPMNoPageFormat; | |
71 | } | |
72 | ||
73 | if (m_macPrintSettings != kPMNoPrintSettings) | |
74 | { | |
75 | (void)PMRelease(m_macPrintSettings); | |
76 | m_macPrintSettings = kPMNoPrintSettings; | |
77 | } | |
78 | ||
79 | if ( m_macPrintSession != kPMNoReference ) | |
80 | { | |
81 | (void)PMRelease(m_macPrintSession); | |
82 | m_macPrintSession = kPMNoReference; | |
83 | } | |
84 | } | |
85 | ||
86 | void wxMacCarbonPrintData::ValidateOrCreate() | |
87 | { | |
88 | OSStatus err = noErr ; | |
89 | if ( m_macPrintSession == kPMNoReference ) | |
90 | { | |
91 | err = PMCreateSession( (PMPrintSession *) &m_macPrintSession ) ; | |
92 | } | |
93 | // Set up a valid PageFormat object. | |
94 | if ( m_macPageFormat == kPMNoPageFormat) | |
95 | { | |
96 | err = PMCreatePageFormat((PMPageFormat *) &m_macPageFormat); | |
97 | ||
98 | // Note that PMPageFormat is not session-specific, but calling | |
99 | // PMSessionDefaultPageFormat assigns values specific to the printer | |
100 | // associated with the current printing session. | |
101 | if ((err == noErr) && | |
102 | ( m_macPageFormat != kPMNoPageFormat)) | |
103 | { | |
104 | err = PMSessionDefaultPageFormat((PMPrintSession) m_macPrintSession, | |
105 | (PMPageFormat) m_macPageFormat); | |
106 | } | |
107 | } | |
108 | else | |
109 | { | |
110 | err = PMSessionValidatePageFormat((PMPrintSession) m_macPrintSession, | |
111 | (PMPageFormat) m_macPageFormat, | |
112 | kPMDontWantBoolean); | |
113 | } | |
114 | ||
115 | // Set up a valid PrintSettings object. | |
116 | if ( m_macPrintSettings == kPMNoPrintSettings) | |
117 | { | |
118 | err = PMCreatePrintSettings((PMPrintSettings *) &m_macPrintSettings); | |
119 | ||
120 | // Note that PMPrintSettings is not session-specific, but calling | |
121 | // PMSessionDefaultPrintSettings assigns values specific to the printer | |
122 | // associated with the current printing session. | |
123 | if ((err == noErr) && | |
124 | ( m_macPrintSettings != kPMNoPrintSettings)) | |
125 | { | |
126 | err = PMSessionDefaultPrintSettings((PMPrintSession) m_macPrintSession, | |
127 | (PMPrintSettings) m_macPrintSettings); | |
128 | } | |
129 | } | |
130 | else | |
131 | { | |
132 | err = PMSessionValidatePrintSettings((PMPrintSession) m_macPrintSession, | |
133 | (PMPrintSettings) m_macPrintSettings, | |
134 | kPMDontWantBoolean); | |
135 | } | |
136 | } | |
137 | ||
138 | void wxMacCarbonPrintData::TransferFrom( wxPrintData* data ) | |
139 | { | |
140 | ValidateOrCreate() ; | |
141 | PMSetCopies( (PMPrintSettings) m_macPrintSettings , data->GetNoCopies() , false ) ; | |
142 | PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data->GetOrientation() == wxLANDSCAPE ) ? | |
143 | kPMLandscape : kPMPortrait , false ) ; | |
144 | // collate cannot be set | |
145 | #if 0 // not yet tested | |
146 | if ( m_printerName.Length() > 0 ) | |
147 | PMSessionSetCurrentPrinter( (PMPrintSession) m_macPrintSession , wxMacCFStringHolder( m_printerName ) ) ; | |
148 | #endif | |
149 | PMColorMode color ; | |
150 | PMGetColorMode( (PMPrintSettings) m_macPrintSettings, &color ) ; | |
151 | if ( data->GetColour() ) | |
152 | { | |
153 | if ( color == kPMBlackAndWhite ) | |
154 | PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMColor ) ; | |
155 | } | |
156 | else | |
157 | PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMBlackAndWhite ) ; | |
158 | ||
159 | // PMDuplexMode not yet accessible via API | |
160 | // PMQualityMode not yet accessible via API | |
161 | // todo paperSize | |
162 | } | |
163 | ||
164 | void wxMacCarbonPrintData::TransferTo( wxPrintData* data ) | |
165 | { | |
166 | OSStatus err = noErr ; | |
167 | ||
168 | UInt32 copies ; | |
169 | err = PMGetCopies( m_macPrintSettings , &copies ) ; | |
170 | if ( err == noErr ) | |
171 | data->SetNoCopies( copies ) ; | |
172 | ||
173 | PMOrientation orientation ; | |
174 | err = PMGetOrientation( m_macPageFormat , &orientation ) ; | |
175 | if ( err == noErr ) | |
176 | { | |
177 | if ( orientation == kPMPortrait || orientation == kPMReversePortrait ) | |
178 | data->SetOrientation( wxPORTRAIT ); | |
179 | else | |
180 | data->SetOrientation( wxLANDSCAPE ); | |
181 | } | |
182 | ||
183 | // collate cannot be set | |
184 | #if 0 | |
185 | { | |
186 | wxMacCFStringHolder name ; | |
187 | PMPrinter printer ; | |
188 | PMSessionGetCurrentPrinter( m_macPrintSession , | |
189 | &printer ) ; | |
190 | m_printerName = name.AsString() ; | |
191 | } | |
192 | #endif | |
193 | ||
194 | PMColorMode color ; | |
195 | err = PMGetColorMode( m_macPrintSettings, &color ) ; | |
196 | if ( err == noErr ) | |
197 | data->SetColour( !(color == kPMBlackAndWhite) ) ; | |
198 | ||
199 | // PMDuplexMode not yet accessible via API | |
200 | // PMQualityMode not yet accessible via API | |
201 | // todo paperSize | |
202 | PMRect rPaper; | |
203 | err = PMGetUnadjustedPaperRect( m_macPageFormat, &rPaper); | |
204 | if ( err == noErr ) | |
205 | { | |
206 | data->SetPaperSize( wxSize ( | |
207 | (int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 ) , | |
208 | (int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 ) ) ); | |
209 | } | |
210 | } | |
211 | ||
212 | void wxMacCarbonPrintData::TransferFrom( wxPageSetupData *data ) | |
213 | { | |
214 | // should we setup the page rect here ? | |
215 | // since MacOS sometimes has two same paper rects with different | |
216 | // page rects we could make it roundtrip safe perhaps | |
217 | #if TARGET_CARBON | |
218 | #else | |
219 | #endif | |
220 | } | |
221 | ||
222 | void wxMacCarbonPrintData::TransferTo( wxPageSetupData* data ) | |
223 | { | |
224 | PMRect rPaper; | |
225 | OSStatus err = PMGetUnadjustedPaperRect(m_macPageFormat, &rPaper); | |
226 | if ( err == noErr ) | |
227 | { | |
228 | PMRect rPage ; | |
229 | err = PMGetUnadjustedPageRect(m_macPageFormat , &rPage ) ; | |
230 | if ( err == noErr ) | |
231 | { | |
232 | data->SetMinMarginTopLeft( wxPoint ( | |
233 | (int)(((double) rPage.left - rPaper.left ) * pt2mm) , | |
234 | (int)(((double) rPage.top - rPaper.top ) * pt2mm) ) ) ; | |
235 | ||
236 | data->SetMinMarginBottomRight( wxPoint ( | |
5be55d56 VZ |
237 | (wxCoord)(((double) rPaper.right - rPage.right ) * pt2mm), |
238 | (wxCoord)(((double) rPaper.bottom - rPage.bottom ) * pt2mm)) ) ; | |
746d7582 SC |
239 | } |
240 | } | |
241 | } | |
242 | ||
243 | void wxMacCarbonPrintData::TransferTo( wxPrintDialogData* data ) | |
244 | { | |
245 | UInt32 minPage , maxPage ; | |
246 | PMGetPageRange( m_macPrintSettings , &minPage , &maxPage ) ; | |
247 | data->SetMinPage( minPage ) ; | |
248 | data->SetMaxPage( maxPage ) ; | |
249 | UInt32 copies ; | |
250 | PMGetCopies( m_macPrintSettings , &copies ) ; | |
251 | data->SetNoCopies( copies ) ; | |
252 | UInt32 from , to ; | |
253 | PMGetFirstPage( m_macPrintSettings , &from ) ; | |
254 | PMGetLastPage( m_macPrintSettings , &to ) ; | |
255 | data->SetFromPage( from ) ; | |
256 | data->SetToPage( to ) ; | |
257 | } | |
258 | ||
259 | void wxMacCarbonPrintData::TransferFrom( wxPrintDialogData* data ) | |
260 | { | |
261 | PMSetPageRange( m_macPrintSettings , data->GetMinPage() , data->GetMaxPage() ) ; | |
262 | PMSetCopies( m_macPrintSettings , data->GetNoCopies() , false ) ; | |
263 | PMSetFirstPage( m_macPrintSettings , data->GetFromPage() , false ) ; | |
264 | PMSetLastPage( m_macPrintSettings , data->GetToPage() , false ) ; | |
265 | } | |
266 | ||
267 | void wxMacCarbonPrintData::CopyFrom( wxNativePrintData* d ) | |
268 | { | |
269 | wxMacCarbonPrintData *data = (wxMacCarbonPrintData*) d ; | |
270 | if ( data->m_macPrintSession != kPMNoReference ) | |
271 | PMRetain( data->m_macPrintSession ) ; | |
272 | if ( m_macPrintSession != kPMNoReference ) | |
273 | { | |
274 | PMRelease( m_macPrintSession ) ; | |
275 | m_macPrintSession = kPMNoReference ; | |
276 | } | |
277 | if ( data->m_macPrintSession != kPMNoReference ) | |
278 | m_macPrintSession = data->m_macPrintSession ; | |
279 | ||
280 | if ( data->m_macPrintSettings != kPMNoPrintSettings ) | |
281 | PMRetain( data->m_macPrintSettings ) ; | |
282 | if ( m_macPrintSettings != kPMNoPrintSettings ) | |
283 | { | |
284 | PMRelease( m_macPrintSettings ) ; | |
285 | m_macPrintSettings = kPMNoPrintSettings ; | |
286 | } | |
287 | if ( data->m_macPrintSettings != kPMNoPrintSettings ) | |
288 | m_macPrintSettings = data->m_macPrintSettings ; | |
289 | ||
290 | if ( data->m_macPageFormat != kPMNoPageFormat ) | |
291 | PMRetain( data->m_macPageFormat ) ; | |
292 | if ( m_macPageFormat != kPMNoPageFormat ) | |
293 | { | |
294 | PMRelease( m_macPageFormat ) ; | |
295 | m_macPageFormat = kPMNoPageFormat ; | |
296 | } | |
297 | if ( data->m_macPageFormat != kPMNoPageFormat ) | |
298 | m_macPageFormat = data->m_macPageFormat ; | |
299 | } | |
300 | ||
301 | int wxMacCarbonPrintData::ShowPrintDialog() | |
302 | { | |
303 | int result = wxID_CANCEL ; | |
304 | OSErr err = noErr ; | |
305 | wxString message ; | |
306 | ||
307 | Boolean accepted; | |
308 | ||
309 | { | |
310 | // Display the Print dialog. | |
311 | if (err == noErr) | |
312 | { | |
313 | err = PMSessionPrintDialog( m_macPrintSession, | |
314 | m_macPrintSettings, | |
315 | m_macPageFormat, | |
316 | &accepted); | |
317 | if ((err == noErr) && !accepted) | |
318 | { | |
319 | err = kPMCancel; // user clicked Cancel button | |
320 | } | |
321 | } | |
322 | if ( err == noErr ) | |
323 | { | |
324 | result = wxID_OK ; | |
325 | } | |
326 | } | |
327 | if ((err != noErr) && (err != kPMCancel)) | |
328 | { | |
329 | message.Printf( wxT("Print Error %d"), err ) ; | |
330 | wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ; | |
331 | dialog.ShowModal(); | |
332 | } | |
333 | ||
334 | return result ; | |
335 | } | |
336 | ||
337 | int wxMacCarbonPrintData::ShowPageSetupDialog() | |
338 | { | |
339 | int result = wxID_CANCEL ; | |
340 | OSErr err = noErr ; | |
341 | wxString message ; | |
342 | ||
343 | Boolean accepted; | |
344 | { | |
345 | // Display the Page Setup dialog. | |
346 | if (err == noErr) | |
347 | { | |
348 | err = PMSessionPageSetupDialog( m_macPrintSession, | |
349 | m_macPageFormat, | |
350 | &accepted); | |
351 | if ((err == noErr) && !accepted) | |
352 | { | |
353 | err = kPMCancel; // user clicked Cancel button | |
354 | } | |
355 | } | |
356 | ||
357 | // If the user did not cancel, flatten and save the PageFormat object | |
358 | // with our document. | |
359 | if (err == noErr) { | |
360 | result = wxID_OK ; | |
361 | } | |
362 | } | |
363 | if ((err != noErr) && (err != kPMCancel)) | |
364 | { | |
365 | message.Printf( wxT("Print Error %d"), err ) ; | |
366 | wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ; | |
367 | dialog.ShowModal(); | |
368 | } | |
369 | ||
370 | return result ; | |
371 | } | |
372 | ||
373 | #else | |
374 | ||
375 | wxNativePrintData* wxNativePrintData::Create() | |
376 | { | |
377 | return new wxMacClassicPrintData() ; | |
378 | } | |
379 | ||
380 | wxMacClassicPrintData::wxMacClassicPrintData() | |
381 | { | |
382 | m_macPrintSettings = NULL ; | |
383 | ValidateOrCreate() ; | |
384 | } | |
385 | ||
386 | wxMacClassicPrintData::~wxMacClassicPrintData() | |
387 | { | |
388 | wxASSERT( m_macPrintSettings ); | |
389 | DisposeHandle( (Handle) m_macPrintSettings ) ; | |
390 | } | |
391 | ||
392 | void wxMacClassicPrintData::ValidateOrCreate() | |
393 | { | |
394 | if ( m_macPrintSettings == NULL ) | |
395 | { | |
396 | m_macPrintSettings = (THPrint) NewHandleClear( sizeof( TPrint ) ); | |
397 | (**m_macPrintSettings).iPrVersion = 0; // something invalid | |
398 | ||
399 | (**m_macPrintSettings).prInfo.iHRes = 72; | |
400 | (**m_macPrintSettings).prInfo.iVRes = 72; | |
401 | Rect r1 = { 0, 0, 8*72 - 2 * 18, 11*72 - 2 * 36 }; | |
402 | (**m_macPrintSettings).prInfo.rPage = r1;// must have its top left & (0,0) | |
403 | ||
404 | Rect r2 = { -18, -36, 8*72 - 18, 11*72 - 36 }; | |
405 | (**m_macPrintSettings).rPaper = r2; | |
406 | (**m_macPrintSettings).prStl.iPageV = 11 * 120 ; // 11 inches in 120th of an inch | |
407 | (**m_macPrintSettings).prStl.iPageH = 8 * 120 ; // 8 inches in 120th of an inch | |
408 | } | |
409 | else | |
410 | { | |
411 | } | |
412 | } | |
413 | ||
414 | void wxMacClassicPrintData::TransferFrom( wxPrintData* data ) | |
415 | { | |
416 | ValidateOrCreate() ; | |
417 | (**m_macPrintSettings).prJob.iCopies = data->GetNoCopies() ; | |
418 | // on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0 | |
419 | // if all printing data is consolidated in on structure we will be able to set additional infos about pages | |
420 | } | |
421 | ||
422 | void wxMacClassicPrintData::TransferTo( wxPrintData* data ) | |
423 | { | |
424 | data->SetNoCopies( (**m_macPrintSettings).prJob.iCopies ); | |
425 | data->SetPaperSize( wxSize( | |
426 | ((double) (**m_macPrintSettings).rPaper.right - (**m_macPrintSettings).rPaper.left ) * pt2mm , | |
427 | ((double) (**m_macPrintSettings).rPaper.bottom - (**m_macPrintSettings).rPaper.top ) * pt2mm ) ) ; | |
428 | } | |
429 | ||
430 | void wxMacClassicPrintData::TransferFrom( wxPageSetupData *data ) | |
431 | { | |
432 | } | |
433 | ||
434 | void wxMacClassicPrintData::TransferTo( wxPageSetupData* data ) | |
435 | { | |
436 | data->SetMinMarginTopLeft( wxPoint( | |
437 | ((double) (**m_macPrintSettings).prInfo.rPage.left -(**m_macPrintSettings).rPaper.left ) * pt2mm , | |
438 | ((double) (**m_macPrintSettings).prInfo.rPage.top -(**m_macPrintSettings).rPaper.top ) * pt2mm ) ) ; | |
439 | data->SetMinMarginBottomRight( wxPoint( | |
440 | ((double) (**m_macPrintSettings).rPaper.right - (**m_macPrintSettings).prInfo.rPage.right ) * pt2mm , | |
441 | ((double)(**m_macPrintSettings).rPaper.bottom - (**m_macPrintSettings).prInfo.rPage.bottom ) * pt2mm ) ) ; | |
442 | } | |
443 | ||
444 | void wxMacClassicPrintData::TransferFrom( wxPrintDialogData* data ) | |
445 | { | |
446 | (**m_macPrintSettings).prJob.iFstPage = data->GetFromPage() ; | |
447 | (**m_macPrintSettings).prJob.iLstPage = data->GetToPage() ; | |
448 | } | |
449 | ||
450 | void wxMacClassicPrintData::TransferTo( wxPrintDialogData* data ) | |
451 | { | |
452 | data->SetFromPage( (**m_macPrintSettings).prJob.iFstPage ) ; | |
453 | data->SetToPage( (**m_macPrintSettings).prJob.iLstPage ) ; | |
454 | } | |
455 | ||
456 | void wxMacClassicPrintData::CopyFrom( wxNativePrintData* data ) | |
457 | { | |
458 | DisposeHandle( (Handle) m_macPrintSettings ) ; | |
459 | m_macPrintSettings = ((wxMacClassicPrintData*)data)->m_macPrintSettings; | |
460 | HandToHand( (Handle*) &m_macPrintSettings ); | |
461 | } | |
462 | ||
463 | int wxMacClassicPrintData::ShowPrintDialog() | |
464 | { | |
465 | int result = wxID_CANCEL ; | |
466 | OSErr err = noErr ; | |
467 | wxString message ; | |
468 | ||
469 | err = ::UMAPrOpen() ; | |
470 | if ( err == noErr ) | |
471 | { | |
472 | if ( ::PrJobDialog( m_macPrintSettings ) ) | |
473 | { | |
474 | result = wxID_OK ; | |
475 | } | |
476 | ||
477 | } | |
478 | else | |
479 | { | |
480 | message.Printf( wxT("Print Error %d"), err ) ; | |
481 | wxMessageDialog dialog( NULL , message , wxT(""), wxICON_HAND | wxOK) ; | |
482 | dialog.ShowModal(); | |
483 | } | |
484 | ::UMAPrClose() ; | |
485 | ||
486 | return result ; | |
487 | } | |
488 | ||
489 | int wxMacClassicPrintData::ShowPageSetupDialog() | |
490 | { | |
491 | int result = wxID_CANCEL ; | |
492 | OSErr err = noErr ; | |
493 | wxString message ; | |
494 | ||
495 | err = ::UMAPrOpen() ; | |
496 | if ( err == noErr ) | |
497 | { | |
498 | if ( ::PrStlDialog( m_macPrintSettings ) ) | |
499 | { | |
500 | result = wxID_OK ; | |
501 | } | |
502 | ||
503 | } | |
504 | else | |
505 | { | |
506 | message.Printf( wxT("Print Error %d"), err ) ; | |
507 | wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ; | |
508 | dialog.ShowModal(); | |
509 | } | |
510 | ::UMAPrClose() ; | |
511 | return result ; | |
512 | } | |
513 | ||
514 | #endif | |
515 | ||
72e7876b | 516 | /* |
e40298d5 JS |
517 | * Printer |
518 | */ | |
519 | ||
72e7876b | 520 | wxMacPrinter::wxMacPrinter(wxPrintDialogData *data): |
e40298d5 | 521 | wxPrinterBase(data) |
72e7876b SC |
522 | { |
523 | } | |
524 | ||
525 | wxMacPrinter::~wxMacPrinter(void) | |
526 | { | |
527 | } | |
528 | ||
529 | bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt) | |
530 | { | |
e40298d5 JS |
531 | sm_abortIt = FALSE; |
532 | sm_abortWindow = NULL; | |
72e7876b | 533 | |
e40298d5 JS |
534 | if (!printout) |
535 | return FALSE; | |
536 | ||
537 | printout->SetIsPreview(FALSE); | |
d2b354f9 JS |
538 | if (m_printDialogData.GetMinPage() < 1) |
539 | m_printDialogData.SetMinPage(1); | |
540 | if (m_printDialogData.GetMaxPage() < 1) | |
541 | m_printDialogData.SetMaxPage(9999); | |
542 | ||
e40298d5 JS |
543 | // Create a suitable device context |
544 | wxDC *dc = NULL; | |
545 | if (prompt) | |
546 | { | |
2f1ae414 SC |
547 | wxPrintDialog dialog(parent, & m_printDialogData); |
548 | if (dialog.ShowModal() == wxID_OK) | |
e40298d5 JS |
549 | { |
550 | dc = dialog.GetPrintDC(); | |
551 | m_printDialogData = dialog.GetPrintData(); | |
552 | } | |
553 | } | |
554 | else | |
72e7876b | 555 | { |
e40298d5 | 556 | dc = new wxPrinterDC( m_printDialogData.GetPrintData() ) ; |
72e7876b | 557 | } |
e40298d5 JS |
558 | |
559 | ||
560 | // May have pressed cancel. | |
561 | if (!dc || !dc->Ok()) | |
72e7876b | 562 | { |
e40298d5 JS |
563 | if (dc) delete dc; |
564 | return FALSE; | |
72e7876b | 565 | } |
e40298d5 JS |
566 | |
567 | // on the mac we have always pixels as addressing mode with 72 dpi | |
568 | ||
569 | printout->SetPPIScreen(72, 72); | |
570 | printout->SetPPIPrinter(72, 72); | |
571 | ||
572 | // Set printout parameters | |
573 | printout->SetDC(dc); | |
574 | ||
575 | int w, h; | |
576 | wxCoord ww, hh; | |
577 | dc->GetSize(&w, &h); | |
578 | printout->SetPageSizePixels((int)w, (int)h); | |
579 | dc->GetSizeMM(&ww, &hh); | |
580 | printout->SetPageSizeMM((int)ww, (int)hh); | |
581 | ||
582 | // Create an abort window | |
583 | wxBeginBusyCursor(); | |
584 | ||
d2b354f9 JS |
585 | printout->OnPreparePrinting(); |
586 | ||
587 | // Get some parameters from the printout, if defined | |
588 | int fromPage, toPage; | |
589 | int minPage, maxPage; | |
590 | printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); | |
591 | ||
592 | if (maxPage == 0) | |
593 | { | |
594 | wxEndBusyCursor(); | |
595 | return FALSE; | |
596 | } | |
597 | ||
598 | // Only set min and max, because from and to have been | |
599 | // set by the user | |
600 | m_printDialogData.SetMinPage(minPage); | |
601 | m_printDialogData.SetMaxPage(maxPage); | |
602 | ||
e40298d5 JS |
603 | wxWindow *win = CreateAbortWindow(parent, printout); |
604 | wxSafeYield(win,true); | |
605 | ||
606 | if (!win) | |
607 | { | |
608 | wxEndBusyCursor(); | |
427ff662 | 609 | wxMessageBox(wxT("Sorry, could not create an abort dialog."), wxT("Print Error"), wxOK, parent); |
e40298d5 JS |
610 | delete dc; |
611 | return FALSE; | |
612 | } | |
613 | sm_abortWindow = win; | |
614 | sm_abortWindow->Show(TRUE); | |
615 | wxSafeYield(win,true); | |
616 | ||
617 | printout->OnBeginPrinting(); | |
618 | ||
619 | bool keepGoing = TRUE; | |
620 | ||
621 | int copyCount; | |
622 | for (copyCount = 1; copyCount <= m_printDialogData.GetNoCopies(); copyCount ++) | |
623 | { | |
624 | if (!printout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage())) | |
625 | { | |
626 | wxEndBusyCursor(); | |
427ff662 | 627 | wxMessageBox(wxT("Could not start printing."), wxT("Print Error"), wxOK, parent); |
e40298d5 JS |
628 | break; |
629 | } | |
630 | if (sm_abortIt) | |
631 | break; | |
632 | ||
633 | int pn; | |
634 | for (pn = m_printDialogData.GetFromPage(); keepGoing && (pn <= m_printDialogData.GetToPage()) && printout->HasPage(pn); | |
635 | pn++) | |
636 | { | |
637 | if (sm_abortIt) | |
638 | { | |
639 | keepGoing = FALSE; | |
640 | break; | |
641 | } | |
642 | else | |
643 | { | |
746d7582 | 644 | // #if !TARGET_CARBON |
e40298d5 JS |
645 | GrafPtr thePort ; |
646 | GetPort( &thePort ) ; | |
647 | wxSafeYield(win,true); | |
648 | SetPort( thePort ) ; | |
746d7582 | 649 | // #endif |
e40298d5 JS |
650 | dc->StartPage(); |
651 | keepGoing = printout->OnPrintPage(pn); | |
652 | dc->EndPage(); | |
653 | } | |
654 | } | |
655 | printout->OnEndDocument(); | |
656 | } | |
657 | ||
658 | printout->OnEndPrinting(); | |
659 | ||
660 | if (sm_abortWindow) | |
661 | { | |
662 | sm_abortWindow->Show(FALSE); | |
663 | delete sm_abortWindow; | |
664 | sm_abortWindow = NULL; | |
665 | } | |
666 | ||
667 | wxEndBusyCursor(); | |
668 | ||
669 | delete dc; | |
670 | ||
671 | return TRUE; | |
72e7876b SC |
672 | } |
673 | ||
674 | wxDC* wxMacPrinter::PrintDialog(wxWindow *parent) | |
675 | { | |
676 | wxDC* dc = (wxDC*) NULL; | |
e40298d5 | 677 | |
72e7876b SC |
678 | wxPrintDialog dialog(parent, & m_printDialogData); |
679 | int ret = dialog.ShowModal(); | |
e40298d5 | 680 | |
72e7876b SC |
681 | if (ret == wxID_OK) |
682 | { | |
683 | dc = dialog.GetPrintDC(); | |
684 | m_printDialogData = dialog.GetPrintDialogData(); | |
685 | } | |
e40298d5 | 686 | |
72e7876b SC |
687 | return dc; |
688 | } | |
689 | ||
690 | bool wxMacPrinter::Setup(wxWindow *parent) | |
691 | { | |
692 | wxPrintDialog dialog(parent, & m_printDialogData); | |
693 | dialog.GetPrintDialogData().SetSetupDialog(TRUE); | |
e40298d5 | 694 | |
72e7876b | 695 | int ret = dialog.ShowModal(); |
e40298d5 | 696 | |
72e7876b SC |
697 | if (ret == wxID_OK) |
698 | { | |
699 | m_printDialogData = dialog.GetPrintDialogData(); | |
700 | } | |
e40298d5 | 701 | |
72e7876b SC |
702 | return (ret == wxID_OK); |
703 | } | |
704 | ||
705 | /* | |
e40298d5 JS |
706 | * Print preview |
707 | */ | |
72e7876b SC |
708 | |
709 | wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout, | |
e40298d5 JS |
710 | wxPrintout *printoutForPrinting, |
711 | wxPrintDialogData *data) | |
712 | : wxPrintPreviewBase(printout, printoutForPrinting, data) | |
72e7876b SC |
713 | { |
714 | DetermineScaling(); | |
715 | } | |
716 | ||
717 | wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data): | |
e40298d5 | 718 | wxPrintPreviewBase(printout, printoutForPrinting, data) |
72e7876b | 719 | { |
e40298d5 | 720 | DetermineScaling(); |
72e7876b SC |
721 | } |
722 | ||
723 | wxMacPrintPreview::~wxMacPrintPreview(void) | |
724 | { | |
725 | } | |
726 | ||
727 | bool wxMacPrintPreview::Print(bool interactive) | |
728 | { | |
e40298d5 JS |
729 | if (!m_printPrintout) |
730 | return FALSE; | |
731 | wxMacPrinter printer(&m_printDialogData); | |
732 | return printer.Print(m_previewFrame, m_printPrintout, interactive); | |
72e7876b SC |
733 | } |
734 | ||
735 | void wxMacPrintPreview::DetermineScaling(void) | |
736 | { | |
e40298d5 JS |
737 | int screenWidth , screenHeight ; |
738 | wxDisplaySize( &screenWidth , &screenHeight ) ; | |
739 | ||
740 | m_previewPrintout->SetPPIScreen( 72 , 72 ) ; | |
741 | m_previewPrintout->SetPPIPrinter( 72 , 72 ) ; | |
742 | m_previewPrintout->SetPageSizeMM( (int) (8.0 * 25.6), (int) (11.0 * 25.6) ); | |
743 | m_previewPrintout->SetPageSizePixels( 8 * 72 , 11 * 72 ) ; | |
2f1ae414 SC |
744 | m_pageWidth = 8 * 72 ; |
745 | m_pageHeight = 11 * 72 ; | |
746 | m_previewScale = 1 ; | |
e40298d5 | 747 | |
72e7876b | 748 | // Get a device context for the currently selected printer |
2f1ae414 SC |
749 | wxPrinterDC printerDC(m_printDialogData.GetPrintData()); |
750 | if (printerDC.Ok()) | |
72e7876b | 751 | { |
e40298d5 JS |
752 | int x , y ; |
753 | wxCoord ww, hh; | |
754 | printerDC.GetSizeMM(&ww, &hh); | |
755 | printerDC.GetSize( &x , &y ) ; | |
756 | m_previewPrintout->SetPageSizeMM((int)ww, (int)hh); | |
757 | m_previewPrintout->SetPageSizePixels( x , y) ; | |
758 | m_pageWidth = x ; | |
759 | m_pageHeight = y ; | |
760 | m_isOk = true ; | |
761 | } | |
762 | else | |
763 | { | |
764 | m_isOk = false ; | |
765 | } | |
72e7876b | 766 | // At 100%, the page should look about page-size on the screen. |
2f1ae414 SC |
767 | // m_previewScale = (float)((float)screenWidth/(float)printerWidth); |
768 | // m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerXRes); | |
769 | ||
770 | m_previewScale = 1 ; | |
72e7876b | 771 | } |