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