X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/888dde65f43d5f57e8fb2028b27191cca1741403..12bb29f5432174ecbd65549bda832d70d34a98ae:/src/msw/printwin.cpp diff --git a/src/msw/printwin.cpp b/src/msw/printwin.cpp index 98dae5fc75..62abb589f6 100644 --- a/src/msw/printwin.cpp +++ b/src/msw/printwin.cpp @@ -39,24 +39,26 @@ #include "wx/intl.h" #include "wx/log.h" #include "wx/dcprint.h" + #include "wx/dcmemory.h" + #include "wx/image.h" #endif +#include "wx/msw/dib.h" +#include "wx/msw/dcmemory.h" #include "wx/msw/printwin.h" #include "wx/msw/printdlg.h" #include "wx/msw/private.h" #include "wx/msw/dcprint.h" - -#include - -#ifndef __WIN32__ - #include +#if wxUSE_ENH_METAFILE + #include "wx/msw/enhmeta.h" #endif +#include // --------------------------------------------------------------------------- // private functions // --------------------------------------------------------------------------- -LONG APIENTRY _EXPORT wxAbortProc(HDC hPr, int Code); +BOOL CALLBACK wxAbortProc(HDC hdc, int error); // --------------------------------------------------------------------------- // wxWin macros @@ -76,16 +78,6 @@ LONG APIENTRY _EXPORT wxAbortProc(HDC hPr, int Code); wxWindowsPrinter::wxWindowsPrinter(wxPrintDialogData *data) : wxPrinterBase(data) { - m_lpAbortProc = (WXFARPROC)wxAbortProc; -} - -wxWindowsPrinter::~wxWindowsPrinter() -{ - // avoids warning about statement with no effect (FreeProcInstance - // doesn't do anything under Win32) -#if !defined(__WIN32__) && !defined(__NT__) - FreeProcInstance((FARPROC) m_lpAbortProc); -#endif } bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt) @@ -99,8 +91,6 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt return false; } - printout->SetIsPreview(false); - if (m_printDialogData.GetMinPage() < 1) m_printDialogData.SetMinPage(1); if (m_printDialogData.GetMaxPage() < 1) @@ -177,27 +167,10 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt m_printDialogData.SetMinPage(minPage); m_printDialogData.SetMaxPage(maxPage); - wxWindow *win = CreateAbortWindow(parent, printout); + wxPrintAbortDialog *win = CreateAbortWindow(parent, printout); wxYield(); -#if defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__GNUWIN32__) || defined(__SALFORDC__) || !defined(__WIN32__) -#ifdef STRICT - ::SetAbortProc((HDC) impl->GetHDC(), (ABORTPROC) m_lpAbortProc); -#else - ::SetAbortProc((HDC) impl->GetHDC(), (FARPROC) m_lpAbortProc); -#endif -#else - ::SetAbortProc((HDC) impl->GetHDC(), (int (_stdcall *) - // cast it to right type only if required - // FIXME it's really cdecl and we're casting it to stdcall - either there is - // something I don't understand or it will crash at first usage -#ifdef STRICT - (HDC, int) -#else - () -#endif - )m_lpAbortProc); -#endif + ::SetAbortProc(GetHdcOf(*impl), wxAbortProc); if (!win) { @@ -223,10 +196,15 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt maxPageNum = m_printDialogData.GetToPage(); } - int copyCount; - for ( copyCount = 1; - copyCount <= m_printDialogData.GetNoCopies(); - copyCount++ ) + // The dc we get from the PrintDialog will do multiple copies without help + // if the device supports it. Loop only if we have created a dc from our + // own m_printDialogData or the device does not support multiple copies. + // m_printDialogData.GetPrintData().GetNoCopies() is set from device + // devMode in printdlg.cpp/wxWindowsPrintDialog::ConvertFromNative() + const int maxCopyCount = !prompt || + !m_printDialogData.GetPrintData().GetNoCopies() + ? m_printDialogData.GetNoCopies() : 1; + for ( int copyCount = 1; copyCount <= maxCopyCount; copyCount++ ) { if ( !printout->OnBeginDocument(minPageNum, maxPageNum) ) { @@ -246,6 +224,10 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt pn <= maxPageNum && printout->HasPage(pn); pn++ ) { + win->SetProgress(pn - minPageNum + 1, + maxPageNum - minPageNum + 1, + copyCount, maxCopyCount); + if ( sm_abortIt ) { sm_lastError = wxPRINTER_CANCELLED; @@ -271,8 +253,7 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt if (sm_abortWindow) { sm_abortWindow->Show(false); - delete sm_abortWindow; - sm_abortWindow = NULL; + wxDELETE(sm_abortWindow); } delete dc; @@ -282,7 +263,7 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt wxDC *wxWindowsPrinter::PrintDialog(wxWindow *parent) { - wxDC *dc = (wxPrinterDC*) NULL; + wxDC *dc = NULL; wxWindowsPrintDialog dialog(parent, & m_printDialogData); int ret = dialog.ShowModal(); @@ -419,15 +400,55 @@ void wxWindowsPrintPreview::DetermineScaling() m_previewScaleY = float(logPPIScreenY) / logPPIPrinterY; } -/**************************************************************************** +#if wxUSE_ENH_METAFILE +bool wxWindowsPrintPreview::RenderPageIntoBitmap(wxBitmap& bmp, int pageNum) +{ + // The preview, as implemented in wxPrintPreviewBase (and as used prior to + // wx3) is inexact: it uses screen DC, which has much lower resolution and + // has other properties different from printer DC, so the preview is not + // quite right. + // + // To make matters worse, if the application depends heavily on + // GetTextExtent() or does text layout itself, the output in preview and on + // paper can be very different. In particular, wxHtmlEasyPrinting is + // affected and the preview can be easily off by several pages. + // + // To fix this, we render the preview into high-resolution enhanced + // metafile with properties identical to the printer DC. This guarantees + // metrics correctness while still being fast. + + + // print the preview into a metafile: + wxPrinterDC printerDC(m_printDialogData.GetPrintData()); + wxEnhMetaFileDC metaDC(printerDC, + wxEmptyString, + printerDC.GetSize().x, printerDC.GetSize().y); - FUNCTION: wxAbortProc() + if ( !RenderPageIntoDC(metaDC, pageNum) ) + return false; - PURPOSE: Processes messages for the Abort Dialog box + wxEnhMetaFile *metafile = metaDC.Close(); + if ( !metafile ) + return false; -****************************************************************************/ + // now render the metafile: + wxMemoryDC bmpDC; + bmpDC.SelectObject(bmp); + bmpDC.Clear(); + + wxRect outRect(0, 0, bmp.GetWidth(), bmp.GetHeight()); + metafile->Play(&bmpDC, &outRect); + + + delete metafile; + + // TODO: we should keep the metafile and reuse it when changing zoom level + + return true; +} +#endif // wxUSE_ENH_METAFILE -LONG APIENTRY _EXPORT wxAbortProc(HDC WXUNUSED(hPr), int WXUNUSED(Code)) +BOOL CALLBACK wxAbortProc(HDC WXUNUSED(hdc), int WXUNUSED(error)) { MSG msg;