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