]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/classic/printmac.cpp
!__WX_DC_BLIT_FIXED__ case
[wxWidgets.git] / src / mac / classic / printmac.cpp
... / ...
CommitLineData
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
39IMPLEMENT_DYNAMIC_CLASS(wxMacPrinter, wxPrinterBase)
40IMPLEMENT_CLASS(wxMacPrintPreview, wxPrintPreviewBase)
41
42#if TARGET_CARBON
43
44wxNativePrintData* wxNativePrintData::Create()
45{
46 return new wxMacCarbonPrintData() ;
47}
48
49wxMacCarbonPrintData::wxMacCarbonPrintData()
50{
51 m_macPageFormat = kPMNoPageFormat;
52 m_macPrintSettings = kPMNoPrintSettings;
53 m_macPrintSession = kPMNoReference ;
54 ValidateOrCreate() ;
55}
56
57wxMacCarbonPrintData::~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
78void 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
130void 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
156void 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
204void 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
214void 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
235void 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
251void 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
263void 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
297int 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
333int 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
371wxNativePrintData* wxNativePrintData::Create()
372{
373 return new wxMacClassicPrintData() ;
374}
375
376wxMacClassicPrintData::wxMacClassicPrintData()
377{
378 m_macPrintSettings = NULL ;
379 ValidateOrCreate() ;
380}
381
382wxMacClassicPrintData::~wxMacClassicPrintData()
383{
384 wxASSERT( m_macPrintSettings );
385 DisposeHandle( (Handle) m_macPrintSettings ) ;
386}
387
388void 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
410void 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
418void 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
426void wxMacClassicPrintData::TransferFrom( wxPageSetupData *data )
427{
428}
429
430void 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
440void 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
449void wxMacClassicPrintData::TransferTo( wxPrintDialogData* data )
450{
451 data->SetFromPage( (**m_macPrintSettings).prJob.iFstPage ) ;
452 data->SetToPage( (**m_macPrintSettings).prJob.iLstPage ) ;
453}
454
455void wxMacClassicPrintData::CopyFrom( wxNativePrintData* data )
456{
457 DisposeHandle( (Handle) m_macPrintSettings ) ;
458 m_macPrintSettings = ((wxMacClassicPrintData*)data)->m_macPrintSettings;
459 HandToHand( (Handle*) &m_macPrintSettings );
460}
461
462int 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
488int 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
519wxMacPrinter::wxMacPrinter(wxPrintDialogData *data):
520wxPrinterBase(data)
521{
522}
523
524wxMacPrinter::~wxMacPrinter(void)
525{
526}
527
528bool 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 wxDC *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
559 // May have pressed cancel.
560 if (!dc || !dc->Ok())
561 {
562 if (dc) delete dc;
563 return false;
564 }
565
566 // on the mac we have always pixels as addressing mode with 72 dpi
567
568 printout->SetPPIScreen(72, 72);
569 printout->SetPPIPrinter(72, 72);
570
571 // Set printout parameters
572 printout->SetDC(dc);
573
574 int w, h;
575 wxCoord ww, hh;
576 dc->GetSize(&w, &h);
577 printout->SetPageSizePixels((int)w, (int)h);
578 dc->GetSizeMM(&ww, &hh);
579 printout->SetPageSizeMM((int)ww, (int)hh);
580
581 // Create an abort window
582 wxBeginBusyCursor();
583
584 printout->OnPreparePrinting();
585
586 // Get some parameters from the printout, if defined
587 int fromPage, toPage;
588 int minPage, maxPage;
589 printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage);
590
591 if (maxPage == 0)
592 {
593 wxEndBusyCursor();
594 return false;
595 }
596
597 // Only set min and max, because from and to have been
598 // set by the user
599 m_printDialogData.SetMinPage(minPage);
600 m_printDialogData.SetMaxPage(maxPage);
601
602 wxWindow *win = CreateAbortWindow(parent, printout);
603 wxSafeYield(win,true);
604
605 if (!win)
606 {
607 wxEndBusyCursor();
608 wxMessageBox(wxT("Sorry, could not create an abort dialog."), wxT("Print Error"), wxOK, parent);
609 delete dc;
610 return false;
611 }
612 sm_abortWindow = win;
613 sm_abortWindow->Show(true);
614 wxSafeYield(win,true);
615
616 printout->OnBeginPrinting();
617
618 bool keepGoing = true;
619
620 int copyCount;
621 for (copyCount = 1; copyCount <= m_printDialogData.GetNoCopies(); copyCount ++)
622 {
623 if (!printout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage()))
624 {
625 wxEndBusyCursor();
626 wxMessageBox(wxT("Could not start printing."), wxT("Print Error"), wxOK, parent);
627 break;
628 }
629 if (sm_abortIt)
630 break;
631
632 int pn;
633 for (pn = m_printDialogData.GetFromPage(); keepGoing && (pn <= m_printDialogData.GetToPage()) && printout->HasPage(pn);
634 pn++)
635 {
636 if (sm_abortIt)
637 {
638 keepGoing = false;
639 break;
640 }
641 else
642 {
643#if TARGET_CARBON
644 if ( UMAGetSystemVersion() >= 0x1000 )
645#endif
646 {
647 GrafPtr thePort ;
648 GetPort( &thePort ) ;
649 wxSafeYield(win,true);
650 SetPort( thePort ) ;
651 }
652 dc->StartPage();
653 keepGoing = printout->OnPrintPage(pn);
654 dc->EndPage();
655 }
656 }
657 printout->OnEndDocument();
658 }
659
660 printout->OnEndPrinting();
661
662 if (sm_abortWindow)
663 {
664 sm_abortWindow->Show(false);
665 delete sm_abortWindow;
666 sm_abortWindow = NULL;
667 }
668
669 wxEndBusyCursor();
670
671 delete dc;
672
673 return true;
674}
675
676wxDC* wxMacPrinter::PrintDialog(wxWindow *parent)
677{
678 wxDC* dc = (wxDC*) NULL;
679
680 wxPrintDialog dialog(parent, & m_printDialogData);
681 int ret = dialog.ShowModal();
682
683 if (ret == wxID_OK)
684 {
685 dc = dialog.GetPrintDC();
686 m_printDialogData = dialog.GetPrintDialogData();
687 }
688
689 return dc;
690}
691
692bool wxMacPrinter::Setup(wxWindow *parent)
693{
694#if 0
695 wxPrintDialog dialog(parent, & m_printDialogData);
696 dialog.GetPrintDialogData().SetSetupDialog(true);
697
698 int ret = dialog.ShowModal();
699
700 if (ret == wxID_OK)
701 {
702 m_printDialogData = dialog.GetPrintDialogData();
703 }
704
705 return (ret == wxID_OK);
706#endif
707 return wxID_CANCEL;
708}
709
710/*
711* Print preview
712*/
713
714wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout,
715 wxPrintout *printoutForPrinting,
716 wxPrintDialogData *data)
717 : wxPrintPreviewBase(printout, printoutForPrinting, data)
718{
719 DetermineScaling();
720}
721
722wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data):
723wxPrintPreviewBase(printout, printoutForPrinting, data)
724{
725 DetermineScaling();
726}
727
728wxMacPrintPreview::~wxMacPrintPreview(void)
729{
730}
731
732bool wxMacPrintPreview::Print(bool interactive)
733{
734 if (!m_printPrintout)
735 return false;
736 wxMacPrinter printer(&m_printDialogData);
737 return printer.Print(m_previewFrame, m_printPrintout, interactive);
738}
739
740void wxMacPrintPreview::DetermineScaling(void)
741{
742 int screenWidth , screenHeight ;
743 wxDisplaySize( &screenWidth , &screenHeight ) ;
744
745 m_previewPrintout->SetPPIScreen( 72 , 72 ) ;
746 m_previewPrintout->SetPPIPrinter( 72 , 72 ) ;
747 m_previewPrintout->SetPageSizeMM( (int) (8.0 * 25.6), (int) (11.0 * 25.6) );
748 m_previewPrintout->SetPageSizePixels( 8 * 72 , 11 * 72 ) ;
749 m_pageWidth = 8 * 72 ;
750 m_pageHeight = 11 * 72 ;
751 m_previewScale = 1 ;
752
753 // Get a device context for the currently selected printer
754 wxPrinterDC printerDC(m_printDialogData.GetPrintData());
755 if (printerDC.Ok())
756 {
757 int x , y ;
758 wxCoord ww, hh;
759 printerDC.GetSizeMM(&ww, &hh);
760 printerDC.GetSize( &x , &y ) ;
761 m_previewPrintout->SetPageSizeMM((int)ww, (int)hh);
762 m_previewPrintout->SetPageSizePixels( x , y) ;
763 m_pageWidth = x ;
764 m_pageHeight = y ;
765 m_isOk = true ;
766 }
767 else
768 {
769 m_isOk = false ;
770 }
771 // At 100%, the page should look about page-size on the screen.
772 // m_previewScale = (float)((float)screenWidth/(float)printerWidth);
773 // m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerXRes);
774
775 m_previewScale = 1 ;
776}