+wxMacPrinter::wxMacPrinter(wxPrintDialogData *data):
+wxPrinterBase(data)
+{
+}
+
+wxMacPrinter::~wxMacPrinter(void)
+{
+}
+
+bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
+{
+ sm_abortIt = FALSE;
+ sm_abortWindow = NULL;
+
+ if (!printout)
+ return FALSE;
+
+ printout->SetIsPreview(FALSE);
+ if (m_printDialogData.GetMinPage() < 1)
+ m_printDialogData.SetMinPage(1);
+ if (m_printDialogData.GetMaxPage() < 1)
+ m_printDialogData.SetMaxPage(9999);
+
+ // Create a suitable device context
+ wxDC *dc = NULL;
+ if (prompt)
+ {
+ wxPrintDialog dialog(parent, & m_printDialogData);
+ if (dialog.ShowModal() == wxID_OK)
+ {
+ dc = dialog.GetPrintDC();
+ m_printDialogData = dialog.GetPrintDialogData();
+ }
+ }
+ else
+ {
+ dc = new wxPrinterDC( m_printDialogData.GetPrintData() ) ;
+ }
+
+
+ // May have pressed cancel.
+ if (!dc || !dc->Ok())
+ {
+ if (dc) delete dc;
+ return FALSE;
+ }
+
+ // on the mac we have always pixels as addressing mode with 72 dpi
+
+ printout->SetPPIScreen(72, 72);
+ printout->SetPPIPrinter(72, 72);
+
+ // Set printout parameters
+ printout->SetDC(dc);
+
+ int w, h;
+ wxCoord ww, hh;
+ dc->GetSize(&w, &h);
+ printout->SetPageSizePixels((int)w, (int)h);
+ dc->GetSizeMM(&ww, &hh);
+ printout->SetPageSizeMM((int)ww, (int)hh);
+
+ // Create an abort window
+ wxBeginBusyCursor();
+
+ printout->OnPreparePrinting();
+
+ // Get some parameters from the printout, if defined
+ int fromPage, toPage;
+ int minPage, maxPage;
+ printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage);
+
+ if (maxPage == 0)
+ {
+ wxEndBusyCursor();
+ return FALSE;
+ }
+
+ // Only set min and max, because from and to have been
+ // set by the user
+ m_printDialogData.SetMinPage(minPage);
+ m_printDialogData.SetMaxPage(maxPage);
+
+ wxWindow *win = CreateAbortWindow(parent, printout);
+ wxSafeYield(win,true);
+
+ if (!win)
+ {
+ wxEndBusyCursor();
+ wxMessageBox(wxT("Sorry, could not create an abort dialog."), wxT("Print Error"), wxOK, parent);
+ delete dc;
+ return FALSE;
+ }
+ sm_abortWindow = win;
+ sm_abortWindow->Show(TRUE);
+ wxSafeYield(win,true);
+
+ printout->OnBeginPrinting();
+
+ bool keepGoing = TRUE;
+
+ int copyCount;
+ for (copyCount = 1; copyCount <= m_printDialogData.GetNoCopies(); copyCount ++)
+ {
+ if (!printout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage()))
+ {
+ wxEndBusyCursor();
+ wxMessageBox(wxT("Could not start printing."), wxT("Print Error"), wxOK, parent);
+ break;
+ }
+ if (sm_abortIt)
+ break;
+
+ int pn;
+ for (pn = m_printDialogData.GetFromPage(); keepGoing && (pn <= m_printDialogData.GetToPage()) && printout->HasPage(pn);
+ pn++)
+ {
+ if (sm_abortIt)
+ {
+ keepGoing = FALSE;
+ break;
+ }
+ else
+ {
+#if TARGET_CARBON
+ if ( UMAGetSystemVersion() >= 0x1000 )
+#endif
+ {
+ GrafPtr thePort ;
+ GetPort( &thePort ) ;
+ wxSafeYield(win,true);
+ SetPort( thePort ) ;
+ }
+ dc->StartPage();
+ keepGoing = printout->OnPrintPage(pn);
+ dc->EndPage();
+ }
+ }
+ printout->OnEndDocument();
+ }
+
+ printout->OnEndPrinting();
+
+ if (sm_abortWindow)
+ {
+ sm_abortWindow->Show(FALSE);
+ delete sm_abortWindow;
+ sm_abortWindow = NULL;
+ }
+
+ wxEndBusyCursor();
+
+ delete dc;
+
+ return TRUE;