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