]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/printmac.cpp
Fixed DDE memory leaks.
[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
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
46IMPLEMENT_DYNAMIC_CLASS(wxMacPrinter, wxPrinterBase)
47IMPLEMENT_CLASS(wxMacPrintPreview, wxPrintPreviewBase)
2f1ae414 48#endif
72e7876b 49
746d7582
SC
50#if TARGET_CARBON
51
52wxNativePrintData* wxNativePrintData::Create()
53{
54 return new wxMacCarbonPrintData() ;
55}
56
57wxMacCarbonPrintData::wxMacCarbonPrintData()
58{
59 m_macPageFormat = kPMNoPageFormat;
60 m_macPrintSettings = kPMNoPrintSettings;
61 m_macPrintSession = kPMNoReference ;
62 ValidateOrCreate() ;
63}
64
65wxMacCarbonPrintData::~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
86void 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
138void 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
164void 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
212void 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
222void 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
243void 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
259void 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 ) ;
b386cd7a
JS
264
265 int toPage = data->GetToPage();
266 if (toPage < 1)
267 toPage = data->GetFromPage();
268 PMSetLastPage( m_macPrintSettings , toPage , false ) ;
746d7582
SC
269}
270
271void wxMacCarbonPrintData::CopyFrom( wxNativePrintData* d )
272{
273 wxMacCarbonPrintData *data = (wxMacCarbonPrintData*) d ;
274 if ( data->m_macPrintSession != kPMNoReference )
275 PMRetain( data->m_macPrintSession ) ;
276 if ( m_macPrintSession != kPMNoReference )
277 {
278 PMRelease( m_macPrintSession ) ;
279 m_macPrintSession = kPMNoReference ;
280 }
281 if ( data->m_macPrintSession != kPMNoReference )
282 m_macPrintSession = data->m_macPrintSession ;
283
284 if ( data->m_macPrintSettings != kPMNoPrintSettings )
285 PMRetain( data->m_macPrintSettings ) ;
286 if ( m_macPrintSettings != kPMNoPrintSettings )
287 {
288 PMRelease( m_macPrintSettings ) ;
289 m_macPrintSettings = kPMNoPrintSettings ;
290 }
291 if ( data->m_macPrintSettings != kPMNoPrintSettings )
292 m_macPrintSettings = data->m_macPrintSettings ;
293
294 if ( data->m_macPageFormat != kPMNoPageFormat )
295 PMRetain( data->m_macPageFormat ) ;
296 if ( m_macPageFormat != kPMNoPageFormat )
297 {
298 PMRelease( m_macPageFormat ) ;
299 m_macPageFormat = kPMNoPageFormat ;
300 }
301 if ( data->m_macPageFormat != kPMNoPageFormat )
302 m_macPageFormat = data->m_macPageFormat ;
303}
304
305int wxMacCarbonPrintData::ShowPrintDialog()
306{
307 int result = wxID_CANCEL ;
308 OSErr err = noErr ;
309 wxString message ;
310
311 Boolean accepted;
312
313 {
314 // Display the Print dialog.
315 if (err == noErr)
316 {
317 err = PMSessionPrintDialog( m_macPrintSession,
318 m_macPrintSettings,
319 m_macPageFormat,
320 &accepted);
321 if ((err == noErr) && !accepted)
322 {
323 err = kPMCancel; // user clicked Cancel button
324 }
325 }
326 if ( err == noErr )
327 {
328 result = wxID_OK ;
329 }
330 }
331 if ((err != noErr) && (err != kPMCancel))
332 {
333 message.Printf( wxT("Print Error %d"), err ) ;
334 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
335 dialog.ShowModal();
336 }
337
338 return result ;
339}
340
341int wxMacCarbonPrintData::ShowPageSetupDialog()
342{
343 int result = wxID_CANCEL ;
344 OSErr err = noErr ;
345 wxString message ;
346
347 Boolean accepted;
348 {
349 // Display the Page Setup dialog.
350 if (err == noErr)
351 {
352 err = PMSessionPageSetupDialog( m_macPrintSession,
353 m_macPageFormat,
354 &accepted);
355 if ((err == noErr) && !accepted)
356 {
357 err = kPMCancel; // user clicked Cancel button
358 }
359 }
360
361 // If the user did not cancel, flatten and save the PageFormat object
362 // with our document.
363 if (err == noErr) {
364 result = wxID_OK ;
365 }
366 }
367 if ((err != noErr) && (err != kPMCancel))
368 {
369 message.Printf( wxT("Print Error %d"), err ) ;
370 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
371 dialog.ShowModal();
372 }
373
374 return result ;
375}
376
377#else
378
379wxNativePrintData* wxNativePrintData::Create()
380{
381 return new wxMacClassicPrintData() ;
382}
383
384wxMacClassicPrintData::wxMacClassicPrintData()
385{
386 m_macPrintSettings = NULL ;
387 ValidateOrCreate() ;
388}
389
390wxMacClassicPrintData::~wxMacClassicPrintData()
391{
392 wxASSERT( m_macPrintSettings );
393 DisposeHandle( (Handle) m_macPrintSettings ) ;
394}
395
396void wxMacClassicPrintData::ValidateOrCreate()
397{
398 if ( m_macPrintSettings == NULL )
399 {
400 m_macPrintSettings = (THPrint) NewHandleClear( sizeof( TPrint ) );
401 (**m_macPrintSettings).iPrVersion = 0; // something invalid
402
403 (**m_macPrintSettings).prInfo.iHRes = 72;
404 (**m_macPrintSettings).prInfo.iVRes = 72;
405 Rect r1 = { 0, 0, 8*72 - 2 * 18, 11*72 - 2 * 36 };
406 (**m_macPrintSettings).prInfo.rPage = r1;// must have its top left & (0,0)
407
408 Rect r2 = { -18, -36, 8*72 - 18, 11*72 - 36 };
409 (**m_macPrintSettings).rPaper = r2;
410 (**m_macPrintSettings).prStl.iPageV = 11 * 120 ; // 11 inches in 120th of an inch
411 (**m_macPrintSettings).prStl.iPageH = 8 * 120 ; // 8 inches in 120th of an inch
412 }
413 else
414 {
415 }
416}
417
418void wxMacClassicPrintData::TransferFrom( wxPrintData* data )
419{
420 ValidateOrCreate() ;
421 (**m_macPrintSettings).prJob.iCopies = data->GetNoCopies() ;
422 // on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0
423 // if all printing data is consolidated in on structure we will be able to set additional infos about pages
424}
425
426void wxMacClassicPrintData::TransferTo( wxPrintData* data )
427{
428 data->SetNoCopies( (**m_macPrintSettings).prJob.iCopies );
429 data->SetPaperSize( wxSize(
430 ((double) (**m_macPrintSettings).rPaper.right - (**m_macPrintSettings).rPaper.left ) * pt2mm ,
431 ((double) (**m_macPrintSettings).rPaper.bottom - (**m_macPrintSettings).rPaper.top ) * pt2mm ) ) ;
432}
433
434void wxMacClassicPrintData::TransferFrom( wxPageSetupData *data )
435{
436}
437
438void wxMacClassicPrintData::TransferTo( wxPageSetupData* data )
439{
440 data->SetMinMarginTopLeft( wxPoint(
441 ((double) (**m_macPrintSettings).prInfo.rPage.left -(**m_macPrintSettings).rPaper.left ) * pt2mm ,
442 ((double) (**m_macPrintSettings).prInfo.rPage.top -(**m_macPrintSettings).rPaper.top ) * pt2mm ) ) ;
443 data->SetMinMarginBottomRight( wxPoint(
444 ((double) (**m_macPrintSettings).rPaper.right - (**m_macPrintSettings).prInfo.rPage.right ) * pt2mm ,
445 ((double)(**m_macPrintSettings).rPaper.bottom - (**m_macPrintSettings).prInfo.rPage.bottom ) * pt2mm ) ) ;
446}
447
448void wxMacClassicPrintData::TransferFrom( wxPrintDialogData* data )
449{
b386cd7a
JS
450 int toPage = data->GetToPage();
451 if (toPage < 1)
452 toPage = data->GetFromPage();
746d7582 453 (**m_macPrintSettings).prJob.iFstPage = data->GetFromPage() ;
b386cd7a 454 (**m_macPrintSettings).prJob.iLstPage = toPage;
746d7582
SC
455}
456
457void wxMacClassicPrintData::TransferTo( wxPrintDialogData* data )
458{
459 data->SetFromPage( (**m_macPrintSettings).prJob.iFstPage ) ;
460 data->SetToPage( (**m_macPrintSettings).prJob.iLstPage ) ;
461}
462
463void wxMacClassicPrintData::CopyFrom( wxNativePrintData* data )
464{
465 DisposeHandle( (Handle) m_macPrintSettings ) ;
466 m_macPrintSettings = ((wxMacClassicPrintData*)data)->m_macPrintSettings;
467 HandToHand( (Handle*) &m_macPrintSettings );
468}
469
470int wxMacClassicPrintData::ShowPrintDialog()
471{
472 int result = wxID_CANCEL ;
473 OSErr err = noErr ;
474 wxString message ;
475
476 err = ::UMAPrOpen() ;
477 if ( err == noErr )
478 {
479 if ( ::PrJobDialog( m_macPrintSettings ) )
480 {
481 result = wxID_OK ;
482 }
483
484 }
485 else
486 {
487 message.Printf( wxT("Print Error %d"), err ) ;
488 wxMessageDialog dialog( NULL , message , wxT(""), wxICON_HAND | wxOK) ;
489 dialog.ShowModal();
490 }
491 ::UMAPrClose() ;
492
493 return result ;
494}
495
496int wxMacClassicPrintData::ShowPageSetupDialog()
497{
498 int result = wxID_CANCEL ;
499 OSErr err = noErr ;
500 wxString message ;
501
502 err = ::UMAPrOpen() ;
503 if ( err == noErr )
504 {
505 if ( ::PrStlDialog( m_macPrintSettings ) )
506 {
507 result = wxID_OK ;
508 }
509
510 }
511 else
512 {
513 message.Printf( wxT("Print Error %d"), err ) ;
514 wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ;
515 dialog.ShowModal();
516 }
517 ::UMAPrClose() ;
518 return result ;
519}
520
521#endif
522
72e7876b 523/*
e40298d5
JS
524* Printer
525*/
526
72e7876b 527wxMacPrinter::wxMacPrinter(wxPrintDialogData *data):
e40298d5 528wxPrinterBase(data)
72e7876b
SC
529{
530}
531
532wxMacPrinter::~wxMacPrinter(void)
533{
534}
535
536bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
537{
e40298d5
JS
538 sm_abortIt = FALSE;
539 sm_abortWindow = NULL;
72e7876b 540
e40298d5
JS
541 if (!printout)
542 return FALSE;
543
544 printout->SetIsPreview(FALSE);
d2b354f9
JS
545 if (m_printDialogData.GetMinPage() < 1)
546 m_printDialogData.SetMinPage(1);
547 if (m_printDialogData.GetMaxPage() < 1)
548 m_printDialogData.SetMaxPage(9999);
549
e40298d5
JS
550 // Create a suitable device context
551 wxDC *dc = NULL;
552 if (prompt)
553 {
2f1ae414
SC
554 wxPrintDialog dialog(parent, & m_printDialogData);
555 if (dialog.ShowModal() == wxID_OK)
e40298d5
JS
556 {
557 dc = dialog.GetPrintDC();
ffcd5195 558 m_printDialogData = dialog.GetPrintDialogData();
e40298d5
JS
559 }
560 }
561 else
72e7876b 562 {
e40298d5 563 dc = new wxPrinterDC( m_printDialogData.GetPrintData() ) ;
72e7876b 564 }
e40298d5
JS
565
566
567 // May have pressed cancel.
568 if (!dc || !dc->Ok())
72e7876b 569 {
e40298d5
JS
570 if (dc) delete dc;
571 return FALSE;
72e7876b 572 }
e40298d5
JS
573
574 // on the mac we have always pixels as addressing mode with 72 dpi
575
576 printout->SetPPIScreen(72, 72);
577 printout->SetPPIPrinter(72, 72);
578
579 // Set printout parameters
580 printout->SetDC(dc);
581
582 int w, h;
583 wxCoord ww, hh;
584 dc->GetSize(&w, &h);
585 printout->SetPageSizePixels((int)w, (int)h);
586 dc->GetSizeMM(&ww, &hh);
587 printout->SetPageSizeMM((int)ww, (int)hh);
588
589 // Create an abort window
590 wxBeginBusyCursor();
591
d2b354f9
JS
592 printout->OnPreparePrinting();
593
594 // Get some parameters from the printout, if defined
595 int fromPage, toPage;
596 int minPage, maxPage;
597 printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage);
598
599 if (maxPage == 0)
600 {
601 wxEndBusyCursor();
602 return FALSE;
603 }
604
605 // Only set min and max, because from and to have been
606 // set by the user
607 m_printDialogData.SetMinPage(minPage);
608 m_printDialogData.SetMaxPage(maxPage);
609
e40298d5
JS
610 wxWindow *win = CreateAbortWindow(parent, printout);
611 wxSafeYield(win,true);
612
613 if (!win)
614 {
615 wxEndBusyCursor();
427ff662 616 wxMessageBox(wxT("Sorry, could not create an abort dialog."), wxT("Print Error"), wxOK, parent);
e40298d5
JS
617 delete dc;
618 return FALSE;
619 }
620 sm_abortWindow = win;
621 sm_abortWindow->Show(TRUE);
622 wxSafeYield(win,true);
623
624 printout->OnBeginPrinting();
625
626 bool keepGoing = TRUE;
627
628 int copyCount;
629 for (copyCount = 1; copyCount <= m_printDialogData.GetNoCopies(); copyCount ++)
630 {
631 if (!printout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage()))
632 {
633 wxEndBusyCursor();
427ff662 634 wxMessageBox(wxT("Could not start printing."), wxT("Print Error"), wxOK, parent);
e40298d5
JS
635 break;
636 }
637 if (sm_abortIt)
638 break;
639
640 int pn;
641 for (pn = m_printDialogData.GetFromPage(); keepGoing && (pn <= m_printDialogData.GetToPage()) && printout->HasPage(pn);
642 pn++)
643 {
644 if (sm_abortIt)
645 {
646 keepGoing = FALSE;
647 break;
648 }
649 else
650 {
746d7582 651// #if !TARGET_CARBON
e40298d5
JS
652 GrafPtr thePort ;
653 GetPort( &thePort ) ;
654 wxSafeYield(win,true);
655 SetPort( thePort ) ;
746d7582 656// #endif
e40298d5
JS
657 dc->StartPage();
658 keepGoing = printout->OnPrintPage(pn);
659 dc->EndPage();
660 }
661 }
662 printout->OnEndDocument();
663 }
664
665 printout->OnEndPrinting();
666
667 if (sm_abortWindow)
668 {
669 sm_abortWindow->Show(FALSE);
670 delete sm_abortWindow;
671 sm_abortWindow = NULL;
672 }
673
674 wxEndBusyCursor();
675
676 delete dc;
677
678 return TRUE;
72e7876b
SC
679}
680
681wxDC* wxMacPrinter::PrintDialog(wxWindow *parent)
682{
683 wxDC* dc = (wxDC*) NULL;
e40298d5 684
72e7876b
SC
685 wxPrintDialog dialog(parent, & m_printDialogData);
686 int ret = dialog.ShowModal();
e40298d5 687
72e7876b
SC
688 if (ret == wxID_OK)
689 {
690 dc = dialog.GetPrintDC();
691 m_printDialogData = dialog.GetPrintDialogData();
692 }
e40298d5 693
72e7876b
SC
694 return dc;
695}
696
697bool wxMacPrinter::Setup(wxWindow *parent)
698{
699 wxPrintDialog dialog(parent, & m_printDialogData);
700 dialog.GetPrintDialogData().SetSetupDialog(TRUE);
e40298d5 701
72e7876b 702 int ret = dialog.ShowModal();
e40298d5 703
72e7876b
SC
704 if (ret == wxID_OK)
705 {
706 m_printDialogData = dialog.GetPrintDialogData();
707 }
e40298d5 708
72e7876b
SC
709 return (ret == wxID_OK);
710}
711
712/*
e40298d5
JS
713* Print preview
714*/
72e7876b
SC
715
716wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout,
e40298d5
JS
717 wxPrintout *printoutForPrinting,
718 wxPrintDialogData *data)
719 : wxPrintPreviewBase(printout, printoutForPrinting, data)
72e7876b
SC
720{
721 DetermineScaling();
722}
723
724wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data):
e40298d5 725wxPrintPreviewBase(printout, printoutForPrinting, data)
72e7876b 726{
e40298d5 727 DetermineScaling();
72e7876b
SC
728}
729
730wxMacPrintPreview::~wxMacPrintPreview(void)
731{
732}
733
734bool wxMacPrintPreview::Print(bool interactive)
735{
e40298d5
JS
736 if (!m_printPrintout)
737 return FALSE;
738 wxMacPrinter printer(&m_printDialogData);
739 return printer.Print(m_previewFrame, m_printPrintout, interactive);
72e7876b
SC
740}
741
742void wxMacPrintPreview::DetermineScaling(void)
743{
e40298d5
JS
744 int screenWidth , screenHeight ;
745 wxDisplaySize( &screenWidth , &screenHeight ) ;
746
747 m_previewPrintout->SetPPIScreen( 72 , 72 ) ;
748 m_previewPrintout->SetPPIPrinter( 72 , 72 ) ;
749 m_previewPrintout->SetPageSizeMM( (int) (8.0 * 25.6), (int) (11.0 * 25.6) );
750 m_previewPrintout->SetPageSizePixels( 8 * 72 , 11 * 72 ) ;
2f1ae414
SC
751 m_pageWidth = 8 * 72 ;
752 m_pageHeight = 11 * 72 ;
753 m_previewScale = 1 ;
e40298d5 754
72e7876b 755 // Get a device context for the currently selected printer
2f1ae414
SC
756 wxPrinterDC printerDC(m_printDialogData.GetPrintData());
757 if (printerDC.Ok())
72e7876b 758 {
e40298d5
JS
759 int x , y ;
760 wxCoord ww, hh;
761 printerDC.GetSizeMM(&ww, &hh);
762 printerDC.GetSize( &x , &y ) ;
763 m_previewPrintout->SetPageSizeMM((int)ww, (int)hh);
764 m_previewPrintout->SetPageSizePixels( x , y) ;
765 m_pageWidth = x ;
766 m_pageHeight = y ;
767 m_isOk = true ;
768 }
769 else
770 {
771 m_isOk = false ;
772 }
72e7876b 773 // At 100%, the page should look about page-size on the screen.
2f1ae414
SC
774 // m_previewScale = (float)((float)screenWidth/(float)printerWidth);
775 // m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerXRes);
776
777 m_previewScale = 1 ;
72e7876b 778}