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