+ dc->SetDeviceLocalOrigin( (wxCoord) rPage.left, (wxCoord) rPage.top );
+#endif
+ }
+ // since this is a non-critical error, we set the flag back
+ m_err = noErr ;
+ }
+#if wxMAC_USE_CORE_GRAPHICS
+ dc->SetGraphicsContext( wxGraphicsContext::CreateFromNative( pageContext ) );
+#endif
+}
+
+void wxMacCarbonPrinterDC::EndPage( wxPrinterDC* dc )
+{
+ if ( m_err )
+ return ;
+
+ wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) dc->GetPrintData().GetNativeData() ;
+
+ m_err = PMSessionEndPage(native->m_macPrintSession);
+ if ( m_err != noErr )
+ {
+ PMSessionEndDocument(native->m_macPrintSession);
+ }
+#if wxMAC_USE_CORE_GRAPHICS
+ // the cg context we got when starting the page isn't valid anymore, so replace it
+ dc->SetGraphicsContext( wxGraphicsContext::Create() );
+#endif
+}
+
+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 ;
+};
+
+//
+//
+//
+
+wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
+{
+ 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;
+ }
+#if wxMAC_USE_CORE_GRAPHICS
+ // we need at least a measuring context because people start measuring before a page
+ // gets printed at all
+ SetGraphicsContext( wxGraphicsContext::Create() );
+#endif
+ }
+}
+
+wxSize wxPrinterDC::GetPPI() const
+{
+ return m_nativePrinterDC->GetPPI() ;
+}
+
+wxPrinterDC::~wxPrinterDC(void)
+{
+ delete m_nativePrinterDC ;
+}
+
+bool wxPrinterDC::StartDoc( const wxString& message )
+{
+ wxASSERT_MSG( Ok() , wxT("Called wxPrinterDC::StartDoc from an invalid object") ) ;
+
+ if ( !m_ok )
+ return false ;
+
+ if ( m_nativePrinterDC->StartDoc(this, 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 ;
+}
+
+void wxPrinterDC::EndDoc(void)
+{
+ if ( !m_ok )
+ return ;
+
+ m_nativePrinterDC->EndDoc( this ) ;
+ 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();
+ }
+}
+
+wxRect wxPrinterDC::GetPaperRect()
+{
+ wxCoord w, h;
+ GetSize(&w, &h);
+ wxRect pageRect(0, 0, w, h);
+ wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) m_printData.GetNativeData() ;
+ OSStatus err = noErr ;
+ PMRect rPaper;
+ err = PMGetAdjustedPaperRect(native->m_macPageFormat, &rPaper);
+ if ( err != noErr )
+ return pageRect;
+ return wxRect(wxCoord(rPaper.left), wxCoord(rPaper.top),
+ wxCoord(rPaper.right - rPaper.left), wxCoord(rPaper.bottom - rPaper.top));
+}
+
+void wxPrinterDC::StartPage(void)
+{
+ if ( !m_ok )
+ return ;
+
+ m_logicalFunction = wxCOPY;
+ // m_textAlignment = wxALIGN_TOP_LEFT;
+ m_backgroundMode = wxTRANSPARENT;
+
+ m_textForegroundColour = *wxBLACK;
+ m_textBackgroundColour = *wxWHITE;
+ m_pen = *wxBLACK_PEN;
+ m_font = *wxNORMAL_FONT;
+ m_brush = *wxTRANSPARENT_BRUSH;
+ m_backgroundBrush = *wxWHITE_BRUSH;
+#if !wxMAC_USE_CORE_GRAPHICS
+ m_macFontInstalled = false ;
+ m_macBrushInstalled = false ;
+ m_macPenInstalled = false ;