X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/72625f830b9469204f9ee13cf712df562cf28a4c..4241baae4472ef2736b8ac8c6a975b0ba398909b:/src/mac/carbon/printmac.cpp diff --git a/src/mac/carbon/printmac.cpp b/src/mac/carbon/printmac.cpp index 60d15137cf..274f8b1c9e 100644 --- a/src/mac/carbon/printmac.cpp +++ b/src/mac/carbon/printmac.cpp @@ -5,8 +5,8 @@ // Modified by: // Created: 04/01/98 // RCS-ID: $Id$ -// Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Copyright: (c) Julian Smart +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -43,11 +43,11 @@ IMPLEMENT_CLASS(wxMacPrintPreview, wxPrintPreviewBase) #endif /* - * Printer - */ - +* Printer +*/ + wxMacPrinter::wxMacPrinter(wxPrintDialogData *data): - wxPrinterBase(data) +wxPrinterBase(data) { } @@ -57,170 +57,170 @@ wxMacPrinter::~wxMacPrinter(void) bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt) { - sm_abortIt = FALSE; - sm_abortWindow = NULL; - - if (!printout) - return FALSE; + sm_abortIt = FALSE; + sm_abortWindow = NULL; - printout->SetIsPreview(FALSE); - 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) - return FALSE; - - m_printDialogData.SetMinPage(minPage); - m_printDialogData.SetMaxPage(maxPage); - if (fromPage != 0) - m_printDialogData.SetFromPage(fromPage); - if (toPage != 0) - m_printDialogData.SetToPage(toPage); - - if (minPage != 0) - { - m_printDialogData.EnablePageNumbers(TRUE); - if (m_printDialogData.GetFromPage() < m_printDialogData.GetMinPage()) - m_printDialogData.SetFromPage(m_printDialogData.GetMinPage()); - else if (m_printDialogData.GetFromPage() > m_printDialogData.GetMaxPage()) - m_printDialogData.SetFromPage(m_printDialogData.GetMaxPage()); - if (m_printDialogData.GetToPage() > m_printDialogData.GetMaxPage()) - m_printDialogData.SetToPage(m_printDialogData.GetMaxPage()); - else if (m_printDialogData.GetToPage() < m_printDialogData.GetMinPage()) - m_printDialogData.SetToPage(m_printDialogData.GetMinPage()); - } - else - m_printDialogData.EnablePageNumbers(FALSE); - - // Create a suitable device context - wxDC *dc = NULL; - if (prompt) - { + if (!printout) + return FALSE; + + printout->SetIsPreview(FALSE); + 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) + return FALSE; + + m_printDialogData.SetMinPage(minPage); + m_printDialogData.SetMaxPage(maxPage); + if (fromPage != 0) + m_printDialogData.SetFromPage(fromPage); + if (toPage != 0) + m_printDialogData.SetToPage(toPage); + + if (minPage != 0) + { + m_printDialogData.EnablePageNumbers(TRUE); + if (m_printDialogData.GetFromPage() < m_printDialogData.GetMinPage()) + m_printDialogData.SetFromPage(m_printDialogData.GetMinPage()); + else if (m_printDialogData.GetFromPage() > m_printDialogData.GetMaxPage()) + m_printDialogData.SetFromPage(m_printDialogData.GetMaxPage()); + if (m_printDialogData.GetToPage() > m_printDialogData.GetMaxPage()) + m_printDialogData.SetToPage(m_printDialogData.GetMaxPage()); + else if (m_printDialogData.GetToPage() < m_printDialogData.GetMinPage()) + m_printDialogData.SetToPage(m_printDialogData.GetMinPage()); + } + else + m_printDialogData.EnablePageNumbers(FALSE); + + // 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.GetPrintData(); - } - } - 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(); - - wxWindow *win = CreateAbortWindow(parent, printout); - wxSafeYield(win,true); - - if (!win) - { - wxEndBusyCursor(); - wxMessageBox("Sorry, could not create an abort dialog.", "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())) + { + dc = dialog.GetPrintDC(); + m_printDialogData = dialog.GetPrintData(); + } + } + else { - wxEndBusyCursor(); - wxMessageBox("Could not start printing.", "Print Error", wxOK, parent); - break; + dc = new wxPrinterDC( m_printDialogData.GetPrintData() ) ; } - if (sm_abortIt) - break; - - int pn; - for (pn = m_printDialogData.GetFromPage(); keepGoing && (pn <= m_printDialogData.GetToPage()) && printout->HasPage(pn); - pn++) + + + // May have pressed cancel. + if (!dc || !dc->Ok()) { - if (sm_abortIt) - { - keepGoing = FALSE; - break; - } - else - { - GrafPtr thePort ; - GetPort( &thePort ) ; - wxSafeYield(win,true); - SetPort( thePort ) ; - - dc->StartPage(); - keepGoing = printout->OnPrintPage(pn); - dc->EndPage(); - } + if (dc) delete dc; + return FALSE; } - printout->OnEndDocument(); - } - - printout->OnEndPrinting(); - - if (sm_abortWindow) - { - sm_abortWindow->Show(FALSE); - delete sm_abortWindow; - sm_abortWindow = NULL; - } - - wxEndBusyCursor(); - - delete dc; - - return TRUE; + + // 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(); + + 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 + { + 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; } wxDC* wxMacPrinter::PrintDialog(wxWindow *parent) { wxDC* dc = (wxDC*) NULL; - + wxPrintDialog dialog(parent, & m_printDialogData); int ret = dialog.ShowModal(); - + if (ret == wxID_OK) { dc = dialog.GetPrintDC(); m_printDialogData = dialog.GetPrintDialogData(); } - + return dc; } @@ -228,33 +228,33 @@ bool wxMacPrinter::Setup(wxWindow *parent) { wxPrintDialog dialog(parent, & m_printDialogData); dialog.GetPrintDialogData().SetSetupDialog(TRUE); - + int ret = dialog.ShowModal(); - + if (ret == wxID_OK) { m_printDialogData = dialog.GetPrintDialogData(); } - + return (ret == wxID_OK); } /* - * Print preview - */ +* Print preview +*/ wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout, - wxPrintout *printoutForPrinting, - wxPrintDialogData *data) - : wxPrintPreviewBase(printout, printoutForPrinting, data) + wxPrintout *printoutForPrinting, + wxPrintDialogData *data) + : wxPrintPreviewBase(printout, printoutForPrinting, data) { DetermineScaling(); } wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data): - wxPrintPreviewBase(printout, printoutForPrinting, data) +wxPrintPreviewBase(printout, printoutForPrinting, data) { - DetermineScaling(); + DetermineScaling(); } wxMacPrintPreview::~wxMacPrintPreview(void) @@ -263,43 +263,43 @@ wxMacPrintPreview::~wxMacPrintPreview(void) bool wxMacPrintPreview::Print(bool interactive) { - if (!m_printPrintout) - return FALSE; - wxMacPrinter printer(&m_printDialogData); - return printer.Print(m_previewFrame, m_printPrintout, interactive); + if (!m_printPrintout) + return FALSE; + wxMacPrinter printer(&m_printDialogData); + return printer.Print(m_previewFrame, m_printPrintout, interactive); } void wxMacPrintPreview::DetermineScaling(void) { - int screenWidth , screenHeight ; - wxDisplaySize( &screenWidth , &screenHeight ) ; - - m_previewPrintout->SetPPIScreen( 72 , 72 ) ; - m_previewPrintout->SetPPIPrinter( 72 , 72 ) ; - m_previewPrintout->SetPageSizeMM( (int) (8.0 * 25.6), (int) (11.0 * 25.6) ); - m_previewPrintout->SetPageSizePixels( 8 * 72 , 11 * 72 ) ; + int screenWidth , screenHeight ; + wxDisplaySize( &screenWidth , &screenHeight ) ; + + m_previewPrintout->SetPPIScreen( 72 , 72 ) ; + m_previewPrintout->SetPPIPrinter( 72 , 72 ) ; + m_previewPrintout->SetPageSizeMM( (int) (8.0 * 25.6), (int) (11.0 * 25.6) ); + m_previewPrintout->SetPageSizePixels( 8 * 72 , 11 * 72 ) ; m_pageWidth = 8 * 72 ; m_pageHeight = 11 * 72 ; m_previewScale = 1 ; - + // Get a device context for the currently selected printer wxPrinterDC printerDC(m_printDialogData.GetPrintData()); if (printerDC.Ok()) { - int x , y ; - wxCoord ww, hh; - printerDC.GetSizeMM(&ww, &hh); - printerDC.GetSize( &x , &y ) ; - m_previewPrintout->SetPageSizeMM((int)ww, (int)hh); - m_previewPrintout->SetPageSizePixels( x , y) ; - m_pageWidth = x ; - m_pageHeight = y ; - m_isOk = true ; - } - else - { - m_isOk = false ; - } + int x , y ; + wxCoord ww, hh; + printerDC.GetSizeMM(&ww, &hh); + printerDC.GetSize( &x , &y ) ; + m_previewPrintout->SetPageSizeMM((int)ww, (int)hh); + m_previewPrintout->SetPageSizePixels( x , y) ; + m_pageWidth = x ; + m_pageHeight = y ; + m_isOk = true ; + } + else + { + m_isOk = false ; + } // At 100%, the page should look about page-size on the screen. // m_previewScale = (float)((float)screenWidth/(float)printerWidth); // m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerXRes);