]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/printmac.cpp
LocalToGlobal/GlobalToLocal Conversions with Carbon API, cleanup, hittesting correcte...
[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 , wxFont::GetDefaultEncoding() ) ) ;
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
265 int toPage = data->GetToPage();
266 if (toPage < 1)
267 toPage = data->GetFromPage();
268 PMSetLastPage( m_macPrintSettings , toPage , false ) ;
269 }
270
271 void 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
305 int 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
341 int 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
379 wxNativePrintData* wxNativePrintData::Create()
380 {
381 return new wxMacClassicPrintData() ;
382 }
383
384 wxMacClassicPrintData::wxMacClassicPrintData()
385 {
386 m_macPrintSettings = NULL ;
387 ValidateOrCreate() ;
388 }
389
390 wxMacClassicPrintData::~wxMacClassicPrintData()
391 {
392 wxASSERT( m_macPrintSettings );
393 DisposeHandle( (Handle) m_macPrintSettings ) ;
394 }
395
396 void 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
418 void 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
426 void 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
434 void wxMacClassicPrintData::TransferFrom( wxPageSetupData *data )
435 {
436 }
437
438 void 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
448 void wxMacClassicPrintData::TransferFrom( wxPrintDialogData* data )
449 {
450 int toPage = data->GetToPage();
451 if (toPage < 1)
452 toPage = data->GetFromPage();
453 (**m_macPrintSettings).prJob.iFstPage = data->GetFromPage() ;
454 (**m_macPrintSettings).prJob.iLstPage = toPage;
455 }
456
457 void wxMacClassicPrintData::TransferTo( wxPrintDialogData* data )
458 {
459 data->SetFromPage( (**m_macPrintSettings).prJob.iFstPage ) ;
460 data->SetToPage( (**m_macPrintSettings).prJob.iLstPage ) ;
461 }
462
463 void wxMacClassicPrintData::CopyFrom( wxNativePrintData* data )
464 {
465 DisposeHandle( (Handle) m_macPrintSettings ) ;
466 m_macPrintSettings = ((wxMacClassicPrintData*)data)->m_macPrintSettings;
467 HandToHand( (Handle*) &m_macPrintSettings );
468 }
469
470 int 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
496 int 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
523 /*
524 * Printer
525 */
526
527 wxMacPrinter::wxMacPrinter(wxPrintDialogData *data):
528 wxPrinterBase(data)
529 {
530 }
531
532 wxMacPrinter::~wxMacPrinter(void)
533 {
534 }
535
536 bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
537 {
538 sm_abortIt = FALSE;
539 sm_abortWindow = NULL;
540
541 if (!printout)
542 return FALSE;
543
544 printout->SetIsPreview(FALSE);
545 if (m_printDialogData.GetMinPage() < 1)
546 m_printDialogData.SetMinPage(1);
547 if (m_printDialogData.GetMaxPage() < 1)
548 m_printDialogData.SetMaxPage(9999);
549
550 // Create a suitable device context
551 wxDC *dc = NULL;
552 if (prompt)
553 {
554 wxPrintDialog dialog(parent, & m_printDialogData);
555 if (dialog.ShowModal() == wxID_OK)
556 {
557 dc = dialog.GetPrintDC();
558 m_printDialogData = dialog.GetPrintDialogData();
559 }
560 }
561 else
562 {
563 dc = new wxPrinterDC( m_printDialogData.GetPrintData() ) ;
564 }
565
566
567 // May have pressed cancel.
568 if (!dc || !dc->Ok())
569 {
570 if (dc) delete dc;
571 return FALSE;
572 }
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
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
610 wxWindow *win = CreateAbortWindow(parent, printout);
611 wxSafeYield(win,true);
612
613 if (!win)
614 {
615 wxEndBusyCursor();
616 wxMessageBox(wxT("Sorry, could not create an abort dialog."), wxT("Print Error"), wxOK, parent);
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();
634 wxMessageBox(wxT("Could not start printing."), wxT("Print Error"), wxOK, parent);
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 {
651 #if TARGET_CARBON
652 if ( UMAGetSystemVersion() >= 0x1000 )
653 #endif
654 {
655 GrafPtr thePort ;
656 GetPort( &thePort ) ;
657 wxSafeYield(win,true);
658 SetPort( thePort ) ;
659 }
660 dc->StartPage();
661 keepGoing = printout->OnPrintPage(pn);
662 dc->EndPage();
663 }
664 }
665 printout->OnEndDocument();
666 }
667
668 printout->OnEndPrinting();
669
670 if (sm_abortWindow)
671 {
672 sm_abortWindow->Show(FALSE);
673 delete sm_abortWindow;
674 sm_abortWindow = NULL;
675 }
676
677 wxEndBusyCursor();
678
679 delete dc;
680
681 return TRUE;
682 }
683
684 wxDC* wxMacPrinter::PrintDialog(wxWindow *parent)
685 {
686 wxDC* dc = (wxDC*) NULL;
687
688 wxPrintDialog dialog(parent, & m_printDialogData);
689 int ret = dialog.ShowModal();
690
691 if (ret == wxID_OK)
692 {
693 dc = dialog.GetPrintDC();
694 m_printDialogData = dialog.GetPrintDialogData();
695 }
696
697 return dc;
698 }
699
700 bool wxMacPrinter::Setup(wxWindow *parent)
701 {
702 wxPrintDialog dialog(parent, & m_printDialogData);
703 dialog.GetPrintDialogData().SetSetupDialog(TRUE);
704
705 int ret = dialog.ShowModal();
706
707 if (ret == wxID_OK)
708 {
709 m_printDialogData = dialog.GetPrintDialogData();
710 }
711
712 return (ret == wxID_OK);
713 }
714
715 /*
716 * Print preview
717 */
718
719 wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout,
720 wxPrintout *printoutForPrinting,
721 wxPrintDialogData *data)
722 : wxPrintPreviewBase(printout, printoutForPrinting, data)
723 {
724 DetermineScaling();
725 }
726
727 wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data):
728 wxPrintPreviewBase(printout, printoutForPrinting, data)
729 {
730 DetermineScaling();
731 }
732
733 wxMacPrintPreview::~wxMacPrintPreview(void)
734 {
735 }
736
737 bool wxMacPrintPreview::Print(bool interactive)
738 {
739 if (!m_printPrintout)
740 return FALSE;
741 wxMacPrinter printer(&m_printDialogData);
742 return printer.Print(m_previewFrame, m_printPrintout, interactive);
743 }
744
745 void wxMacPrintPreview::DetermineScaling(void)
746 {
747 int screenWidth , screenHeight ;
748 wxDisplaySize( &screenWidth , &screenHeight ) ;
749
750 m_previewPrintout->SetPPIScreen( 72 , 72 ) ;
751 m_previewPrintout->SetPPIPrinter( 72 , 72 ) ;
752 m_previewPrintout->SetPageSizeMM( (int) (8.0 * 25.6), (int) (11.0 * 25.6) );
753 m_previewPrintout->SetPageSizePixels( 8 * 72 , 11 * 72 ) ;
754 m_pageWidth = 8 * 72 ;
755 m_pageHeight = 11 * 72 ;
756 m_previewScale = 1 ;
757
758 // Get a device context for the currently selected printer
759 wxPrinterDC printerDC(m_printDialogData.GetPrintData());
760 if (printerDC.Ok())
761 {
762 int x , y ;
763 wxCoord ww, hh;
764 printerDC.GetSizeMM(&ww, &hh);
765 printerDC.GetSize( &x , &y ) ;
766 m_previewPrintout->SetPageSizeMM((int)ww, (int)hh);
767 m_previewPrintout->SetPageSizePixels( x , y) ;
768 m_pageWidth = x ;
769 m_pageHeight = y ;
770 m_isOk = true ;
771 }
772 else
773 {
774 m_isOk = false ;
775 }
776 // At 100%, the page should look about page-size on the screen.
777 // m_previewScale = (float)((float)screenWidth/(float)printerWidth);
778 // m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerXRes);
779
780 m_previewScale = 1 ;
781 }