1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/core/printmac.cpp
3 // Purpose: wxMacPrinter framework
4 // Author: Julian Smart, Stefan Csomor
8 // Copyright: (c) Julian Smart, Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
15 #if wxUSE_PRINTING_ARCHITECTURE
25 #include "wx/msgdlg.h"
26 #include "wx/dcprint.h"
30 #include "wx/osx/private.h"
32 #include "wx/osx/printmac.h"
33 #include "wx/osx/private/print.h"
35 #include "wx/printdlg.h"
37 #include "wx/osx/printdlg.h"
42 // move to print_osx.cpp
45 static int ResolutionSorter(const void *e1
, const void *e2
)
47 const PMResolution
*res1
= (const PMResolution
*)e1
;
48 const PMResolution
*res2
= (const PMResolution
*)e2
;
49 const double area1
= res1
->hRes
* res1
->vRes
;
50 const double area2
= res2
->hRes
* res2
->vRes
;
54 else if (area1
> area2
)
60 static PMResolution
*GetSupportedResolutions(PMPrinter printer
, UInt32
*count
)
62 PMResolution res
, *resolutions
= NULL
;
63 OSStatus status
= PMPrinterGetPrinterResolutionCount(printer
, count
);
64 if (status
== kPMNotImplemented
)
66 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
67 resolutions
= (PMResolution
*)malloc(sizeof(PMResolution
) * 4);
69 if (PMPrinterGetPrinterResolution(printer
, kPMMinRange
, &res
) == noErr
)
70 resolutions
[(*count
)++] = res
;
71 if (PMPrinterGetPrinterResolution(printer
, kPMMinSquareResolution
, &res
) == noErr
)
72 resolutions
[(*count
)++] = res
;
73 if (PMPrinterGetPrinterResolution(printer
, kPMMaxSquareResolution
, &res
) == noErr
)
74 resolutions
[(*count
)++] = res
;
75 if (PMPrinterGetPrinterResolution(printer
, kPMMaxRange
, &res
) == noErr
)
76 resolutions
[(*count
)++] = res
;
79 if (PMPrinterGetPrinterResolution(printer
, kPMDefaultResolution
, &res
) == noErr
)
80 resolutions
[(*count
)++] = res
;
84 else if (status
== noErr
)
86 resolutions
= (PMResolution
*)malloc(sizeof(PMResolution
) * (*count
));
88 for (UInt32 i
= 0; i
< *count
; i
++)
90 if (PMPrinterGetIndexedPrinterResolution(printer
, i
+ 1, &res
) == noErr
)
91 resolutions
[realCount
++] = res
;
93 qsort(resolutions
, realCount
, sizeof(PMResolution
), ResolutionSorter
);
97 if ((*count
== 0) && (resolutions
))
107 IMPLEMENT_DYNAMIC_CLASS(wxOSXPrintData
, wxPrintNativeDataBase
)
109 bool wxOSXPrintData::IsOk() const
111 return (m_macPageFormat
!= kPMNoPageFormat
) && (m_macPrintSettings
!= kPMNoPrintSettings
) && (m_macPrintSession
!= kPMNoReference
);
114 wxOSXPrintData::wxOSXPrintData()
116 m_macPageFormat
= kPMNoPageFormat
;
117 m_macPrintSettings
= kPMNoPrintSettings
;
118 m_macPrintSession
= kPMNoReference
;
119 m_macPaper
= kPMNoData
;
122 wxOSXPrintData::~wxOSXPrintData()
126 void wxOSXPrintData::UpdateFromPMState()
130 void wxOSXPrintData::UpdateToPMState()
134 void wxOSXPrintData::TransferPrinterNameFrom( const wxPrintData
&data
)
136 CFArrayRef printerList
;
137 CFIndex index
, count
;
140 if (PMServerCreatePrinterList(kPMServerLocal
, &printerList
) == noErr
)
142 PMPrinter printer
= NULL
;
143 count
= CFArrayGetCount(printerList
);
144 for (index
= 0; index
< count
; index
++)
146 printer
= (PMPrinter
)CFArrayGetValueAtIndex(printerList
, index
);
147 if ((data
.GetPrinterName().empty()) && (PMPrinterIsDefault(printer
)))
151 name
= PMPrinterGetName(printer
);
153 if (data
.GetPrinterName() == wxCFStringRef(name
).AsString())
158 PMSessionSetCurrentPMPrinter(m_macPrintSession
, printer
);
159 CFRelease(printerList
);
163 void wxOSXPrintData::TransferPaperInfoFrom( const wxPrintData
&data
)
166 PMSessionGetCurrentPrinter(m_macPrintSession
, &printer
);
168 wxSize papersize
= wxDefaultSize
;
169 const wxPaperSize paperId
= data
.GetPaperId();
170 if ( paperId
!= wxPAPER_NONE
&& wxThePrintPaperDatabase
)
172 papersize
= wxThePrintPaperDatabase
->GetSize(paperId
);
173 if ( papersize
!= wxDefaultSize
)
181 papersize
= data
.GetPaperSize();
184 if ( papersize
!= wxDefaultSize
)
186 papersize
.x
= (wxInt32
) (papersize
.x
* mm2pt
);
187 papersize
.y
= (wxInt32
) (papersize
.y
* mm2pt
);
189 double height
, width
;
190 PMPaperGetHeight(m_macPaper
, &height
);
191 PMPaperGetWidth(m_macPaper
, &width
);
193 if ( fabs( width
- papersize
.x
) >= 5 ||
194 fabs( height
- papersize
.y
) >= 5 )
196 // we have to change the current paper
197 CFArrayRef paperlist
= 0 ;
198 if ( PMPrinterGetPaperList( printer
, &paperlist
) == noErr
)
200 PMPaper bestPaper
= kPMNoData
;
201 CFIndex top
= CFArrayGetCount(paperlist
);
202 for ( CFIndex i
= 0 ; i
< top
; ++ i
)
204 PMPaper paper
= (PMPaper
) CFArrayGetValueAtIndex( paperlist
, i
);
205 PMPaperGetHeight(paper
, &height
);
206 PMPaperGetWidth(paper
, &width
);
207 if ( fabs( width
- papersize
.x
) < 5 &&
208 fabs( height
- papersize
.y
) < 5 )
210 // TODO test for duplicate hits and use additional
211 // criteria for best match
215 PMPaper paper
= kPMNoData
;
216 if ( bestPaper
== kPMNoData
)
218 const PMPaperMargins margins
= { 0.0, 0.0, 0.0, 0.0 };
219 wxString id
, name(wxT("Custom paper"));
220 id
.Printf(wxT("wxPaperCustom%dx%d"), papersize
.x
, papersize
.y
);
222 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
223 if ( PMPaperCreateCustom
!= NULL
)
225 PMPaperCreateCustom(printer
, wxCFStringRef( id
, wxFont::GetDefaultEncoding() ), wxCFStringRef( name
, wxFont::GetDefaultEncoding() ),
226 papersize
.x
, papersize
.y
, &margins
, &paper
);
229 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
230 if ( paper
== kPMNoData
)
232 PMPaperCreate(printer
, wxCFStringRef( id
, wxFont::GetDefaultEncoding() ), wxCFStringRef( name
, wxFont::GetDefaultEncoding() ),
233 papersize
.x
, papersize
.y
, &margins
, &paper
);
237 if ( bestPaper
!= kPMNoData
)
239 PMPageFormat pageFormat
;
240 PMCreatePageFormatWithPMPaper(&pageFormat
, bestPaper
);
241 PMCopyPageFormat( pageFormat
, m_macPageFormat
);
242 PMRelease(pageFormat
);
243 PMGetPageFormatPaper(m_macPageFormat
, &m_macPaper
);
250 PMSetCopies( m_macPrintSettings
, data
.GetNoCopies() , false ) ;
251 PMSetCollate(m_macPrintSettings
, data
.GetCollate());
252 if ( data
.IsOrientationReversed() )
253 PMSetOrientation( m_macPageFormat
, ( data
.GetOrientation() == wxLANDSCAPE
) ?
254 kPMReverseLandscape
: kPMReversePortrait
, false ) ;
256 PMSetOrientation( m_macPageFormat
, ( data
.GetOrientation() == wxLANDSCAPE
) ?
257 kPMLandscape
: kPMPortrait
, false ) ;
259 PMDuplexMode mode
= 0 ;
260 switch( data
.GetDuplex() )
262 case wxDUPLEX_HORIZONTAL
:
263 mode
= kPMDuplexNoTumble
;
265 case wxDUPLEX_VERTICAL
:
266 mode
= kPMDuplexTumble
;
268 case wxDUPLEX_SIMPLEX
:
270 mode
= kPMDuplexNone
;
273 PMSetDuplex( m_macPrintSettings
, mode
) ;
276 if ( data
.IsOrientationReversed() )
277 PMSetOrientation( m_macPageFormat
, ( data
.GetOrientation() == wxLANDSCAPE
) ?
278 kPMReverseLandscape
: kPMReversePortrait
, false ) ;
280 PMSetOrientation( m_macPageFormat
, ( data
.GetOrientation() == wxLANDSCAPE
) ?
281 kPMLandscape
: kPMPortrait
, false ) ;
284 void wxOSXPrintData::TransferResolutionFrom( const wxPrintData
&data
)
287 PMSessionGetCurrentPrinter(m_macPrintSession
, &printer
);
290 PMResolution
*resolutions
= GetSupportedResolutions(printer
, &resCount
);
293 wxPrintQuality quality
= data
.GetQuality();
295 quality
= wxPRINT_QUALITY_HIGH
;
297 PMResolution res
= resolutions
[((quality
- wxPRINT_QUALITY_DRAFT
) * (resCount
- 1)) / 3];
298 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
299 if ( PMPrinterSetOutputResolution
!= NULL
)
300 PMPrinterSetOutputResolution(printer
, m_macPrintSettings
, &res
);
304 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
305 PMSetResolution( m_macPageFormat
, &res
);
313 bool wxOSXPrintData::TransferFrom( const wxPrintData
&data
)
315 TransferPrinterNameFrom(data
);
316 TransferPaperInfoFrom(data
);
317 TransferResolutionFrom(data
);
319 // after setting the new resolution the format has to be updated, otherwise the page rect remains
320 // at the 'old' scaling
322 PMSessionValidatePageFormat(m_macPrintSession
,
323 m_macPageFormat
, kPMDontWantBoolean
);
324 PMSessionValidatePrintSettings(m_macPrintSession
,
325 m_macPrintSettings
, kPMDontWantBoolean
);
334 void wxOSXPrintData::TransferPrinterNameTo( wxPrintData
&data
)
338 PMSessionGetCurrentPrinter( m_macPrintSession
, &printer
);
339 if (PMPrinterIsDefault(printer
))
340 data
.SetPrinterName(wxEmptyString
);
343 name
= PMPrinterGetName(printer
);
345 data
.SetPrinterName(wxCFStringRef(name
).AsString());
349 void wxOSXPrintData::TransferPaperInfoTo( wxPrintData
&data
)
352 PMSessionGetCurrentPrinter( m_macPrintSession
, &printer
);
353 OSStatus err
= noErr
;
355 err
= PMGetCopies( m_macPrintSettings
, &copies
) ;
357 data
.SetNoCopies( copies
) ;
359 PMOrientation orientation
;
360 err
= PMGetOrientation( m_macPageFormat
, &orientation
) ;
363 if ( orientation
== kPMPortrait
|| orientation
== kPMReversePortrait
)
365 data
.SetOrientation( wxPORTRAIT
);
366 data
.SetOrientationReversed( orientation
== kPMReversePortrait
);
370 data
.SetOrientation( wxLANDSCAPE
);
371 data
.SetOrientationReversed( orientation
== kPMReverseLandscape
);
376 if (PMGetCollate(m_macPrintSettings
, &collate
) == noErr
)
377 data
.SetCollate(collate
);
380 PMDuplexMode mode
= 0 ;
381 PMGetDuplex( m_macPrintSettings
, &mode
) ;
384 case kPMDuplexNoTumble
:
385 data
.SetDuplex(wxDUPLEX_HORIZONTAL
);
387 case kPMDuplexTumble
:
388 data
.SetDuplex(wxDUPLEX_VERTICAL
);
392 data
.SetDuplex(wxDUPLEX_SIMPLEX
);
396 double height
, width
;
397 PMPaperGetHeight(m_macPaper
, &height
);
398 PMPaperGetWidth(m_macPaper
, &width
);
400 wxSize
sz((int)(width
* pt2mm
+ 0.5 ) ,
401 (int)(height
* pt2mm
+ 0.5 ));
402 data
.SetPaperSize(sz
);
403 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
404 if (id
!= wxPAPER_NONE
)
410 void wxOSXPrintData::TransferResolutionTo( wxPrintData
&data
)
413 PMSessionGetCurrentPrinter( m_macPrintSession
, &printer
);
415 /* assume high quality, will change below if we are able to */
416 data
.SetQuality(wxPRINT_QUALITY_HIGH
);
418 PMResolution
*resolutions
;
420 resolutions
= GetSupportedResolutions(printer
, &resCount
);
425 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
426 if ( PMPrinterGetOutputResolution
!= NULL
)
428 if ( PMPrinterGetOutputResolution(printer
, m_macPrintSettings
, &res
) == noErr
)
432 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
433 if (PMPrinterGetPrinterResolution(printer
, kPMCurrentValue
, &res
) == noErr
)
439 for (i
= 0; i
< resCount
; i
++)
441 if ((resolutions
[i
].hRes
== res
.hRes
) && (resolutions
[i
].vRes
= res
.vRes
))
445 data
.SetQuality((((i
+ 1) * 3) / resCount
) + wxPRINT_QUALITY_DRAFT
);
451 bool wxOSXPrintData::TransferTo( wxPrintData
&data
)
457 TransferPrinterNameTo(data
);
458 TransferPaperInfoTo(data
);
459 TransferResolutionTo(data
);
463 void wxOSXPrintData::TransferFrom( wxPageSetupData
*WXUNUSED(data
) )
465 // should we setup the page rect here ?
466 // since MacOS sometimes has two same paper rects with different
467 // page rects we could make it roundtrip safe perhaps
470 void wxOSXPrintData::TransferTo( wxPageSetupData
* data
)
476 OSStatus err
= PMGetUnadjustedPaperRect(m_macPageFormat
, &rPaper
);
479 wxSize
sz((int)(( rPaper
.right
- rPaper
.left
) * pt2mm
+ 0.5 ) ,
480 (int)(( rPaper
.bottom
- rPaper
.top
) * pt2mm
+ 0.5 ));
481 data
->SetPaperSize(sz
);
484 err
= PMGetUnadjustedPageRect(m_macPageFormat
, &rPage
) ;
487 data
->SetMinMarginTopLeft( wxPoint (
488 (int)(((double) rPage
.left
- rPaper
.left
) * pt2mm
) ,
489 (int)(((double) rPage
.top
- rPaper
.top
) * pt2mm
) ) ) ;
491 data
->SetMinMarginBottomRight( wxPoint (
492 (wxCoord
)(((double) rPaper
.right
- rPage
.right
) * pt2mm
),
493 (wxCoord
)(((double) rPaper
.bottom
- rPage
.bottom
) * pt2mm
)) ) ;
495 if ( data
->GetMarginTopLeft().x
< data
->GetMinMarginTopLeft().x
)
496 data
->SetMarginTopLeft( wxPoint( data
->GetMinMarginTopLeft().x
,
497 data
->GetMarginTopLeft().y
) ) ;
499 if ( data
->GetMarginBottomRight().x
< data
->GetMinMarginBottomRight().x
)
500 data
->SetMarginBottomRight( wxPoint( data
->GetMinMarginBottomRight().x
,
501 data
->GetMarginBottomRight().y
) );
503 if ( data
->GetMarginTopLeft().y
< data
->GetMinMarginTopLeft().y
)
504 data
->SetMarginTopLeft( wxPoint( data
->GetMarginTopLeft().x
, data
->GetMinMarginTopLeft().y
) );
506 if ( data
->GetMarginBottomRight().y
< data
->GetMinMarginBottomRight().y
)
507 data
->SetMarginBottomRight( wxPoint( data
->GetMarginBottomRight().x
,
508 data
->GetMinMarginBottomRight().y
) );
513 void wxOSXPrintData::TransferTo( wxPrintDialogData
* data
)
518 UInt32 minPage
, maxPage
;
519 PMGetPageRange( m_macPrintSettings
, &minPage
, &maxPage
) ;
520 data
->SetMinPage( minPage
) ;
521 data
->SetMaxPage( maxPage
) ;
523 PMGetCopies( m_macPrintSettings
, &copies
) ;
524 data
->SetNoCopies( copies
) ;
526 PMGetFirstPage( m_macPrintSettings
, &from
) ;
527 PMGetLastPage( m_macPrintSettings
, &to
) ;
528 if ( to
>= 0x7FFFFFFF ) // due to an OS Bug we don't get back kPMPrintAllPages
530 data
->SetAllPages( true ) ;
531 // This means all pages, more or less
532 data
->SetFromPage(1);
533 data
->SetToPage(9999);
537 data
->SetFromPage( from
) ;
538 data
->SetToPage( to
) ;
539 data
->SetAllPages( false );
543 void wxOSXPrintData::TransferFrom( wxPrintDialogData
* data
)
545 // Respect the value of m_printAllPages
546 if ( data
->GetAllPages() )
547 PMSetPageRange( m_macPrintSettings
, data
->GetMinPage() , (UInt32
) kPMPrintAllPages
) ;
549 PMSetPageRange( m_macPrintSettings
, data
->GetMinPage() , data
->GetMaxPage() ) ;
550 PMSetCopies( m_macPrintSettings
, data
->GetNoCopies() , false ) ;
551 PMSetFirstPage( m_macPrintSettings
, data
->GetFromPage() , false ) ;
553 if (data
->GetAllPages() || data
->GetFromPage() == 0)
554 PMSetLastPage( m_macPrintSettings
, (UInt32
) kPMPrintAllPages
, true ) ;
556 PMSetLastPage( m_macPrintSettings
, (UInt32
) data
->GetToPage() , false ) ;
562 wxPrintNativeDataBase
* wxOSXCreatePrintData()
565 return new wxOSXCocoaPrintData();
566 #elif wxOSX_USE_CARBON
567 return new wxOSXCarbonPrintData();
577 IMPLEMENT_DYNAMIC_CLASS(wxMacPrinter
, wxPrinterBase
)
579 wxMacPrinter::wxMacPrinter(wxPrintDialogData
*data
):
584 wxMacPrinter::~wxMacPrinter(void)
588 bool wxMacPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
591 sm_abortWindow
= NULL
;
595 sm_lastError
= wxPRINTER_ERROR
;
599 if (m_printDialogData
.GetMinPage() < 1)
600 m_printDialogData
.SetMinPage(1);
601 if (m_printDialogData
.GetMaxPage() < 1)
602 m_printDialogData
.SetMaxPage(9999);
604 // Create a suitable device context
605 wxPrinterDC
*dc
= NULL
;
608 wxMacPrintDialog
dialog(parent
, & m_printDialogData
);
609 if (dialog
.ShowModal() == wxID_OK
)
611 dc
= wxDynamicCast(dialog
.GetPrintDC(), wxPrinterDC
);
613 m_printDialogData
= dialog
.GetPrintDialogData();
618 dc
= new wxPrinterDC( m_printDialogData
.GetPrintData() ) ;
621 // May have pressed cancel.
622 if (!dc
|| !dc
->IsOk())
628 // on the mac we have always pixels as addressing mode with 72 dpi
629 printout
->SetPPIScreen(72, 72);
633 wxOSXPrintData
* nativeData
= (wxOSXPrintData
*)
634 (m_printDialogData
.GetPrintData().GetNativeData());
636 if (PMSessionGetCurrentPrinter(nativeData
->GetPrintSession(), &printer
) == noErr
)
638 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
639 if ( PMPrinterGetOutputResolution
!= NULL
)
641 if (PMPrinterGetOutputResolution( printer
, nativeData
->GetPrintSettings(), &res
) == -9589 /* kPMKeyNotFound */ )
643 res
.hRes
= res
.vRes
= 300;
649 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
650 PMPrinterGetPrinterResolution(printer
, kPMCurrentValue
, &res
);
654 printout
->SetPPIPrinter(int(res
.hRes
), int(res
.vRes
));
656 // Set printout parameters
661 printout
->SetPageSizePixels((int)w
, (int)h
);
662 printout
->SetPaperRectPixels(dc
->GetPaperRect());
664 dc
->GetSizeMM(&mw
, &mh
);
665 printout
->SetPageSizeMM((int)mw
, (int)mh
);
667 // Create an abort window
670 printout
->OnPreparePrinting();
672 // Get some parameters from the printout, if defined
673 int fromPage
, toPage
;
674 int minPage
, maxPage
;
675 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
679 sm_lastError
= wxPRINTER_ERROR
;
683 // Only set min and max, because from and to will be
685 m_printDialogData
.SetMinPage(minPage
);
686 m_printDialogData
.SetMaxPage(maxPage
);
688 printout
->OnBeginPrinting();
690 bool keepGoing
= true;
692 if (!printout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
695 wxMessageBox(wxT("Could not start printing."), wxT("Print Error"), wxOK
, parent
);
699 for (pn
= m_printDialogData
.GetFromPage();
700 keepGoing
&& (pn
<= m_printDialogData
.GetToPage()) && printout
->HasPage(pn
);
710 keepGoing
= printout
->OnPrintPage(pn
);
714 printout
->OnEndDocument();
716 printout
->OnEndPrinting();
720 sm_abortWindow
->Show(false);
721 wxDELETE(sm_abortWindow
);
731 wxDC
* wxMacPrinter::PrintDialog(wxWindow
*parent
)
735 wxPrintDialog
dialog(parent
, & m_printDialogData
);
736 int ret
= dialog
.ShowModal();
740 dc
= dialog
.GetPrintDC();
741 m_printDialogData
= dialog
.GetPrintDialogData();
747 bool wxMacPrinter::Setup(wxWindow
*WXUNUSED(parent
))
750 wxPrintDialog
dialog(parent
, & m_printDialogData
);
751 dialog
.GetPrintDialogData().SetSetupDialog(true);
753 int ret
= dialog
.ShowModal();
756 m_printDialogData
= dialog
.GetPrintDialogData();
758 return (ret
== wxID_OK
);
768 IMPLEMENT_CLASS(wxMacPrintPreview
, wxPrintPreviewBase
)
770 wxMacPrintPreview::wxMacPrintPreview(wxPrintout
*printout
,
771 wxPrintout
*printoutForPrinting
,
772 wxPrintDialogData
*data
)
773 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
778 wxMacPrintPreview::wxMacPrintPreview(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
, wxPrintData
*data
):
779 wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
784 wxMacPrintPreview::~wxMacPrintPreview(void)
788 bool wxMacPrintPreview::Print(bool interactive
)
790 if (!m_printPrintout
)
793 wxMacPrinter
printer(&m_printDialogData
);
794 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
797 void wxMacPrintPreview::DetermineScaling(void)
799 int screenWidth
, screenHeight
;
800 wxDisplaySize( &screenWidth
, &screenHeight
) ;
802 wxSize
ppiScreen( 72 , 72 ) ;
803 wxSize
ppiPrinter( 72 , 72 ) ;
805 // Note that with Leopard, screen dpi=72 is no longer a given
806 m_previewPrintout
->SetPPIScreen( ppiScreen
.x
, ppiScreen
.y
) ;
812 // Get a device context for the currently selected printer
813 wxPrinterDC
printerDC(m_printDialogData
.GetPrintData());
814 if (printerDC
.IsOk())
816 printerDC
.GetSizeMM(&ww
, &hh
);
817 printerDC
.GetSize( &w
, &h
) ;
818 ppiPrinter
= printerDC
.GetPPI() ;
819 paperRect
= printerDC
.GetPaperRect();
827 ww
= (wxCoord
) (w
* 25.4 / ppiPrinter
.x
) ;
828 hh
= (wxCoord
) (h
* 25.4 / ppiPrinter
.y
) ;
829 paperRect
= wxRect(0, 0, w
, h
);
835 m_previewPrintout
->SetPageSizePixels(w
, h
) ;
836 m_previewPrintout
->SetPageSizeMM(ww
, hh
);
837 m_previewPrintout
->SetPaperRectPixels(paperRect
);
838 m_previewPrintout
->SetPPIPrinter( ppiPrinter
.x
, ppiPrinter
.y
) ;
840 m_previewScaleX
= float(ppiScreen
.x
) / ppiPrinter
.x
;
841 m_previewScaleY
= float(ppiScreen
.y
) / ppiPrinter
.y
;
845 // end of print_osx.cpp
850 IMPLEMENT_DYNAMIC_CLASS(wxOSXCarbonPrintData
, wxOSXPrintData
)
852 wxOSXCarbonPrintData::wxOSXCarbonPrintData()
854 if ( PMCreateSession( &m_macPrintSession
) == noErr
)
856 if ( PMCreatePageFormat(&m_macPageFormat
) == noErr
)
858 PMSessionDefaultPageFormat(m_macPrintSession
,
860 PMGetPageFormatPaper(m_macPageFormat
, &m_macPaper
);
863 if ( PMCreatePrintSettings(&m_macPrintSettings
) == noErr
)
865 PMSessionDefaultPrintSettings(m_macPrintSession
,
871 wxOSXCarbonPrintData::~wxOSXCarbonPrintData()
873 (void)PMRelease(m_macPageFormat
);
874 (void)PMRelease(m_macPrintSettings
);
875 (void)PMRelease(m_macPrintSession
);