X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/57bd4c6031d438f11af0ec540136f49a928b923c..5cd8b5b8ba2511da91e8003f3948d4648aa18e0a:/src/msw/printwin.cpp diff --git a/src/msw/printwin.cpp b/src/msw/printwin.cpp index 6856dd9462..98dae5fc75 100644 --- a/src/msw/printwin.cpp +++ b/src/msw/printwin.cpp @@ -42,8 +42,9 @@ #endif #include "wx/msw/printwin.h" -#include "wx/printdlg.h" +#include "wx/msw/printdlg.h" #include "wx/msw/private.h" +#include "wx/msw/dcprint.h" #include @@ -75,7 +76,7 @@ LONG APIENTRY _EXPORT wxAbortProc(HDC hPr, int Code); wxWindowsPrinter::wxWindowsPrinter(wxPrintDialogData *data) : wxPrinterBase(data) { - m_lpAbortProc = (WXFARPROC) MakeProcInstance((FARPROC) wxAbortProc, wxGetInstance()); + m_lpAbortProc = (WXFARPROC)wxAbortProc; } wxWindowsPrinter::~wxWindowsPrinter() @@ -106,10 +107,10 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt m_printDialogData.SetMaxPage(9999); // Create a suitable device context - wxDC *dc wxDUMMY_INITIALIZE(NULL); + wxPrinterDC *dc wxDUMMY_INITIALIZE(NULL); if (prompt) { - dc = PrintDialog(parent); + dc = wxDynamicCast(PrintDialog(parent), wxPrinterDC); if (!dc) return false; } @@ -119,19 +120,21 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt } // May have pressed cancel. - if (!dc || !dc->Ok()) + if (!dc || !dc->IsOk()) { if (dc) delete dc; return false; } + wxPrinterDCImpl *impl = (wxPrinterDCImpl*) dc->GetImpl(); + HDC hdc = ::GetDC(NULL); int logPPIScreenX = ::GetDeviceCaps(hdc, LOGPIXELSX); int logPPIScreenY = ::GetDeviceCaps(hdc, LOGPIXELSY); ::ReleaseDC(NULL, hdc); - int logPPIPrinterX = ::GetDeviceCaps((HDC) dc->GetHDC(), LOGPIXELSX); - int logPPIPrinterY = ::GetDeviceCaps((HDC) dc->GetHDC(), LOGPIXELSY); + int logPPIPrinterX = ::GetDeviceCaps((HDC) impl->GetHDC(), LOGPIXELSX); + int logPPIPrinterY = ::GetDeviceCaps((HDC) impl->GetHDC(), LOGPIXELSY); if (logPPIPrinterX == 0 || logPPIPrinterY == 0) { delete dc; @@ -148,6 +151,7 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt int w, h; dc->GetSize(&w, &h); printout->SetPageSizePixels((int)w, (int)h); + printout->SetPaperRectPixels(dc->GetPaperRect()); dc->GetSizeMM(&w, &h); printout->SetPageSizeMM((int)w, (int)h); @@ -178,12 +182,12 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt #if defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__GNUWIN32__) || defined(__SALFORDC__) || !defined(__WIN32__) #ifdef STRICT - ::SetAbortProc((HDC) dc->GetHDC(), (ABORTPROC) m_lpAbortProc); + ::SetAbortProc((HDC) impl->GetHDC(), (ABORTPROC) m_lpAbortProc); #else - ::SetAbortProc((HDC) dc->GetHDC(), (FARPROC) m_lpAbortProc); + ::SetAbortProc((HDC) impl->GetHDC(), (FARPROC) m_lpAbortProc); #endif #else - ::SetAbortProc((HDC) dc->GetHDC(), (int (_stdcall *) + ::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 @@ -276,11 +280,11 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt return sm_lastError == wxPRINTER_NO_ERROR; } -wxDC* wxWindowsPrinter::PrintDialog(wxWindow *parent) +wxDC *wxWindowsPrinter::PrintDialog(wxWindow *parent) { - wxDC* dc = (wxDC*) NULL; + wxDC *dc = (wxPrinterDC*) NULL; - wxPrintDialog dialog(parent, & m_printDialogData); + wxWindowsPrintDialog dialog(parent, & m_printDialogData); int ret = dialog.ShowModal(); if (ret == wxID_OK) @@ -353,58 +357,66 @@ bool wxWindowsPrintPreview::Print(bool interactive) void wxWindowsPrintPreview::DetermineScaling() { ScreenHDC dc; - int screenWidth = ::GetDeviceCaps(dc, HORZSIZE); - int screenXRes = ::GetDeviceCaps(dc, HORZRES); int logPPIScreenX = ::GetDeviceCaps(dc, LOGPIXELSX); int logPPIScreenY = ::GetDeviceCaps(dc, LOGPIXELSY); m_previewPrintout->SetPPIScreen(logPPIScreenX, logPPIScreenY); - // Get a device context for the currently selected printer wxPrinterDC printerDC(m_printDialogData.GetPrintData()); - int printerWidth = 150; - int printerXRes = 1500; - int printerYRes = 2500; + int printerWidthMM; + int printerHeightMM; + int printerXRes; + int printerYRes; + int logPPIPrinterX; + int logPPIPrinterY; - if ( printerDC.Ok() ) - { - HDC dc = GetHdcOf(printerDC); + wxRect paperRect; - printerWidth = ::GetDeviceCaps(dc, HORZSIZE); - int printerHeight = ::GetDeviceCaps(dc, VERTSIZE); + if ( printerDC.IsOk() ) + { + wxPrinterDCImpl *impl = (wxPrinterDCImpl*) printerDC.GetImpl(); + HDC dc = GetHdcOf(*impl); + printerWidthMM = ::GetDeviceCaps(dc, HORZSIZE); + printerHeightMM = ::GetDeviceCaps(dc, VERTSIZE); printerXRes = ::GetDeviceCaps(dc, HORZRES); printerYRes = ::GetDeviceCaps(dc, VERTRES); + logPPIPrinterX = ::GetDeviceCaps(dc, LOGPIXELSX); + logPPIPrinterY = ::GetDeviceCaps(dc, LOGPIXELSY); - int logPPIPrinterX = ::GetDeviceCaps(dc, LOGPIXELSX); - int logPPIPrinterY = ::GetDeviceCaps(dc, LOGPIXELSY); - - m_previewPrintout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY); - m_previewPrintout->SetPageSizeMM(printerWidth, printerHeight); + paperRect = printerDC.GetPaperRect(); if ( logPPIPrinterX == 0 || logPPIPrinterY == 0 || - printerWidth == 0 || - printerHeight == 0 ) + printerWidthMM == 0 || + printerHeightMM == 0 ) { m_isOk = false; } } else { + // use some defaults + printerWidthMM = 150; + printerHeightMM = 250; + printerXRes = 1500; + printerYRes = 2500; + logPPIPrinterX = 600; + logPPIPrinterY = 600; + + paperRect = wxRect(0, 0, printerXRes, printerYRes); m_isOk = false; } - m_pageWidth = printerXRes; m_pageHeight = printerYRes; + m_previewPrintout->SetPageSizePixels(printerXRes, printerYRes); + m_previewPrintout->SetPageSizeMM(printerWidthMM, printerHeightMM); + m_previewPrintout->SetPaperRectPixels(paperRect); + m_previewPrintout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY); // At 100%, the page should look about page-size on the screen. - // - // TODO: the scale could be different in vertical and horizontal directions - float screenDPI = (float)screenXRes / screenWidth; - float printerDPI = (float)printerXRes / printerWidth; - - m_previewScale = screenDPI / printerDPI; + m_previewScaleX = float(logPPIScreenX) / logPPIPrinterX; + m_previewScaleY = float(logPPIScreenY) / logPPIPrinterY; } /****************************************************************************