-GrafPtr macPrintFormerPort = NULL ;
-
-wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
-{
- OSErr err ;
- wxString message ;
-
- m_printData = printdata ;
- m_printData.ConvertToNative() ;
-
- ::PrOpen() ;
- err = PrError() ;
- if ( err )
- {
- message.Printf( "Print Error %d", err ) ;
- wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
- PrClose() ;
- }
-
- if ( ::PrValidate( m_printData.m_macPrintInfo ) )
- {
- // the driver has changed in the mean time, should we pop up a page setup dialog ?
- }
- err = PrError() ;
- if ( err )
- {
- message.Printf( "Print Error %d", err ) ;
- wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
- PrClose() ;
- }
- ::GetPort( &macPrintFormerPort ) ;
- m_macPrintPort = ::PrOpenDoc( m_printData.m_macPrintInfo , NULL , NULL ) ;
- // sets current port
- m_macPort = (GrafPtr ) m_macPrintPort ;
- m_ok = TRUE ;
- m_minY = m_minX = 0 ;
- m_maxX = (**m_printData.m_macPrintInfo).rPaper.right - (**m_printData.m_macPrintInfo).rPaper.left ;
- m_maxY = (**m_printData.m_macPrintInfo).rPaper.bottom - (**m_printData.m_macPrintInfo).rPaper.top ;
-}
-
-wxPrinterDC::~wxPrinterDC(void)
-{
- if ( m_ok )
- {
- OSErr err ;
- wxString message ;
-
- ::PrCloseDoc( m_macPrintPort ) ;
- err = PrError() ;
-
- if ( !err )
- {
- if ( (**m_printData.m_macPrintInfo).prJob.bJDocLoop == bSpoolLoop )
- {
- TPrStatus status ;
- ::PrPicFile( m_printData.m_macPrintInfo , NULL , NULL , NULL , &status ) ;
- }
- }
- else
- {
- message.Printf( "Print Error %d", err ) ;
- wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
- PrClose() ;
- }
- ::PrClose() ;
- ::SetPort( macPrintFormerPort ) ;
- }
-}
-
-bool wxPrinterDC::StartDoc( const wxString& WXUNUSED(message) )
-{
- return m_ok ;
-}
-
-void wxPrinterDC::EndDoc(void)
-{
-}
-
-void wxPrinterDC::StartPage(void)
-{
- if ( !m_ok )
- return ;
-
- OSErr err ;
- wxString message ;
-
- PrOpenPage( m_macPrintPort , NULL ) ;
- SetOrigin( - (**m_printData.m_macPrintInfo).rPaper.left , - (**m_printData.m_macPrintInfo).rPaper.top ) ;
- Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
- ::ClipRect( &clip ) ;
- err = PrError() ;
- if ( err )
- {
- message.Printf( "Print Error %d", err ) ;
- wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
- ::PrClosePage( m_macPrintPort) ;
- ::PrCloseDoc( m_macPrintPort ) ;
- ::PrClose() ;
- ::SetPort( macPrintFormerPort ) ;
- m_ok = FALSE ;
- }
-}
-
-void wxPrinterDC::EndPage(void)
-{
- if ( !m_ok )
- return ;
-
- OSErr err ;
- wxString message ;
-
- PrClosePage( (TPrPort*) m_macPort ) ;
- err = PrError() ;
- if ( err )
- {
- message.Printf( "Print Error %d", err ) ;
- wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
- ::PrCloseDoc( m_macPrintPort ) ;
- ::PrClose() ;
- ::SetPort( macPrintFormerPort ) ;
- m_ok = FALSE ;
- }
+void wxMacCarbonPrinterDC::EndPage( wxPrinterDC* dc )
+{
+ if ( m_err )
+ return ;
+
+ wxPrinterDCImpl *impl = (wxPrinterDCImpl*) dc->GetImpl();
+ wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) impl->GetPrintData().GetNativeData() ;
+
+ m_err = PMSessionEndPageNoDialog(native->m_macPrintSession);
+ if ( m_err != noErr )
+ {
+ PMSessionEndDocumentNoDialog(native->m_macPrintSession);
+ }
+ // the cg context we got when starting the page isn't valid anymore, so replace it
+ impl->SetGraphicsContext( wxGraphicsContext::Create() );
+}
+
+void wxMacCarbonPrinterDC::GetSize( int *w , int *h) const
+{
+ if ( w )
+ *w = m_maxX ;
+ if ( h )
+ *h = m_maxY ;
+}
+
+wxSize wxMacCarbonPrinterDC::GetPPI() const
+{
+ return m_ppi ;
+};
+
+//
+//
+//
+
+wxPrinterDCImpl::wxPrinterDCImpl( wxPrinterDC *owner, const wxPrintData& printdata )
+ : wxGCDCImpl( owner )
+{
+ m_ok = false ;
+ m_printData = printdata ;
+ m_printData.ConvertToNative() ;
+ m_nativePrinterDC = wxNativePrinterDC::Create( &m_printData ) ;
+ if ( m_nativePrinterDC )
+ {
+ m_ok = m_nativePrinterDC->Ok() ;
+ if ( !m_ok )
+ {
+ wxString message ;
+ message.Printf( wxT("Print Error %u"), m_nativePrinterDC->GetStatus() ) ;
+ wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
+ dialog.ShowModal();
+ }
+ else
+ {
+ wxSize sz = GetPPI();
+ m_mm_to_pix_x = mm2inches * sz.x;
+ m_mm_to_pix_y = mm2inches * sz.y;
+ }
+ // we need at least a measuring context because people start measuring before a page
+ // gets printed at all
+ SetGraphicsContext( wxGraphicsContext::Create() );
+ }
+}
+
+wxSize wxPrinterDCImpl::GetPPI() const
+{
+ return m_nativePrinterDC->GetPPI() ;
+}
+
+wxPrinterDCImpl::~wxPrinterDCImpl()
+{
+ delete m_nativePrinterDC ;
+}
+
+bool wxPrinterDCImpl::StartDoc( const wxString& message )
+{
+ wxASSERT_MSG( IsOk() , wxT("Called wxPrinterDC::StartDoc from an invalid object") ) ;
+
+ if ( !m_ok )
+ return false ;
+
+ if ( m_nativePrinterDC->StartDoc( (wxPrinterDC*) GetOwner(), message ) )
+ {
+ // in case we have to do additional things when successful
+ }
+ m_ok = m_nativePrinterDC->Ok() ;
+ if ( !m_ok )
+ {
+ wxString message ;
+ message.Printf( wxT("Print Error %u"), m_nativePrinterDC->GetStatus() ) ;
+ wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
+ dialog.ShowModal();
+ }
+
+ return m_ok ;