X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/72e7876ba5ad16a1b03bb2449ea7886ec648854a..7f5f144a8143f02841ef9fa4662e25ef24038054:/src/mac/printmac.cpp?ds=inline diff --git a/src/mac/printmac.cpp b/src/mac/printmac.cpp index 4b84cc1a1e..274f8b1c9e 100644 --- a/src/mac/printmac.cpp +++ b/src/mac/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__ @@ -29,6 +29,8 @@ #include "wx/msgdlg.h" #endif +#include "wx/mac/private.h" + #include "wx/mac/printmac.h" #include "wx/dcprint.h" #include "wx/printdlg.h" @@ -41,11 +43,11 @@ IMPLEMENT_CLASS(wxMacPrintPreview, wxPrintPreviewBase) #endif /* - * Printer - */ - +* Printer +*/ + wxMacPrinter::wxMacPrinter(wxPrintDialogData *data): - wxPrinterBase(data) +wxPrinterBase(data) { } @@ -55,181 +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 - // Create a suitable device context - wxDC *dc = NULL; - if (prompt) - { - PrOpen() ; - m_printDialogData.ConvertToNative() ; // make sure we have a valid handle - if ( m_printDialogData.m_macPrintInfo ) - { - // todo incorporate the changes from a global page setup - if ( ::PrStlDialog( m_printDialogData.m_macPrintInfo ) ) // we should have the page setup dialog - { - PrClose() ; - wxPrintDialog dialog(parent, & m_printDialogData); - if (dialog.ShowModal() == wxID_OK) - { - dc = dialog.GetPrintDC(); - m_printDialogData = dialog.GetPrintData(); - } - } - else - { - PrClose() ; - } - } - } - 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; - long 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); - wxYield(); - - if (!win) - { - wxEndBusyCursor(); - wxMessageBox("Sorry, could not create an abort dialog.", "Print Error", wxOK, parent); - delete dc; - } - sm_abortWindow = win; - sm_abortWindow->Show(TRUE); - wxYield(); -*/ - - printout->OnBeginPrinting(); - - bool keepGoing = TRUE; - - int copyCount; - for (copyCount = 1; copyCount <= m_printDialogData.GetNoCopies(); copyCount ++) - { - if (!printout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage())) + 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) { - wxEndBusyCursor(); - wxMessageBox("Could not start printing.", "Print Error", wxOK, parent); - break; + 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()); } - if (sm_abortIt) - break; - - int pn; - for (pn = m_printDialogData.GetFromPage(); keepGoing && (pn <= m_printDialogData.GetToPage()) && printout->HasPage(pn); - pn++) + else + m_printDialogData.EnablePageNumbers(FALSE); + + // Create a suitable device context + wxDC *dc = NULL; + if (prompt) { - if (sm_abortIt) - { - keepGoing = FALSE; - break; - } - else - { - dc->StartPage(); - keepGoing = printout->OnPrintPage(pn); - dc->EndPage(); - } + wxPrintDialog dialog(parent, & m_printDialogData); + if (dialog.ShowModal() == wxID_OK) + { + dc = dialog.GetPrintDC(); + m_printDialogData = dialog.GetPrintData(); + } } - printout->OnEndDocument(); - } - - printout->OnEndPrinting(); - - if (sm_abortWindow) - { - sm_abortWindow->Show(FALSE); - delete sm_abortWindow; - sm_abortWindow = NULL; - } - - wxEndBusyCursor(); - - delete dc; - - return TRUE; + 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(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; } @@ -237,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) @@ -272,58 +263,46 @@ 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) { -/* - HDC dc = ::GetDC(NULL); - int screenWidth = ::GetDeviceCaps(dc, HORZSIZE); -// int screenHeight = ::GetDeviceCaps(dc, VERTSIZE); - int screenXRes = ::GetDeviceCaps(dc, HORZRES); -// int screenYRes = ::GetDeviceCaps(dc, VERTRES); - int logPPIScreenX = ::GetDeviceCaps(dc, LOGPIXELSX); - int logPPIScreenY = ::GetDeviceCaps(dc, LOGPIXELSY); - m_previewPrintout->SetPPIScreen(logPPIScreenX, logPPIScreenY); - - ::ReleaseDC(NULL, dc); - + 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("", "", "", FALSE, m_printDialogData.GetOrientation()); - - int printerWidth = 150; - int printerHeight = 250; - int printerXRes = 1500; - int printerYRes = 2500; - - if (printerDC.GetHDC()) + wxPrinterDC printerDC(m_printDialogData.GetPrintData()); + if (printerDC.Ok()) { - printerWidth = ::GetDeviceCaps((HDC) printerDC.GetHDC(), HORZSIZE); - printerHeight = ::GetDeviceCaps((HDC) printerDC.GetHDC(), VERTSIZE); - printerXRes = ::GetDeviceCaps((HDC) printerDC.GetHDC(), HORZRES); - printerYRes = ::GetDeviceCaps((HDC) printerDC.GetHDC(), VERTRES); - - int logPPIPrinterX = ::GetDeviceCaps((HDC) printerDC.GetHDC(), LOGPIXELSX); - int logPPIPrinterY = ::GetDeviceCaps((HDC) printerDC.GetHDC(), LOGPIXELSY); - - m_previewPrintout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY); - m_previewPrintout->SetPageSizeMM(printerWidth, printerHeight); - - if (logPPIPrinterX == 0 || logPPIPrinterY == 0 || printerWidth == 0 || printerHeight == 0) - 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; - - m_pageWidth = printerXRes; - m_pageHeight = printerYRes; - + { + 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)printerYRes); -*/ + // m_previewScale = (float)((float)screenWidth/(float)printerWidth); + // m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerXRes); + + m_previewScale = 1 ; }