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