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