X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0f07e3dc2480b6a9e963162fe9bf53495b3f1f71..f868f88665d2d72e542b0c1cd16c8d9dd4e246ae:/src/msw/printwin.cpp diff --git a/src/msw/printwin.cpp b/src/msw/printwin.cpp index bc72876edd..6856dd9462 100644 --- a/src/msw/printwin.cpp +++ b/src/msw/printwin.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: printwin.cpp +// Name: src/msw/printwin.cpp // Purpose: wxWindowsPrinter framework // Author: Julian Smart // Modified by: @@ -17,10 +17,6 @@ // headers // --------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "printwin.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -28,13 +24,12 @@ #pragma hdrstop #endif -#include "wx/defs.h" - // Don't use the Windows printer if we're in wxUniv mode and using // the PostScript architecture #if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXUNIVERSAL__) || !wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW) #ifndef WX_PRECOMP + #include "wx/msw/wrapcdlg.h" #include "wx/window.h" #include "wx/msw/private.h" #include "wx/utils.h" @@ -42,20 +37,16 @@ #include "wx/app.h" #include "wx/msgdlg.h" #include "wx/intl.h" + #include "wx/log.h" + #include "wx/dcprint.h" #endif #include "wx/msw/printwin.h" -#include "wx/dcprint.h" #include "wx/printdlg.h" -#include "wx/log.h" #include "wx/msw/private.h" #include -#include "wx/msw/private.h" - -#include - #ifndef __WIN32__ #include #endif @@ -115,7 +106,7 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt m_printDialogData.SetMaxPage(9999); // Create a suitable device context - wxDC *dc = NULL; + wxDC *dc wxDUMMY_INITIALIZE(NULL); if (prompt) { dc = PrintDialog(parent); @@ -134,18 +125,13 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt return false; } - int logPPIScreenX = 0; - int logPPIScreenY = 0; - int logPPIPrinterX = 0; - int logPPIPrinterY = 0; - HDC hdc = ::GetDC(NULL); - logPPIScreenX = ::GetDeviceCaps(hdc, LOGPIXELSX); - logPPIScreenY = ::GetDeviceCaps(hdc, LOGPIXELSY); + int logPPIScreenX = ::GetDeviceCaps(hdc, LOGPIXELSX); + int logPPIScreenY = ::GetDeviceCaps(hdc, LOGPIXELSY); ::ReleaseDC(NULL, hdc); - logPPIPrinterX = ::GetDeviceCaps((HDC) dc->GetHDC(), LOGPIXELSX); - logPPIPrinterY = ::GetDeviceCaps((HDC) dc->GetHDC(), LOGPIXELSY); + int logPPIPrinterX = ::GetDeviceCaps((HDC) dc->GetHDC(), LOGPIXELSX); + int logPPIPrinterY = ::GetDeviceCaps((HDC) dc->GetHDC(), LOGPIXELSY); if (logPPIPrinterX == 0 || logPPIPrinterY == 0) { delete dc; @@ -190,7 +176,7 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt wxWindow *win = CreateAbortWindow(parent, printout); wxYield(); -#if defined(__BORLANDC__) || defined(__GNUWIN32__) || defined(__SALFORDC__) || !defined(__WIN32__) +#if defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__GNUWIN32__) || defined(__SALFORDC__) || !defined(__WIN32__) #ifdef STRICT ::SetAbortProc((HDC) dc->GetHDC(), (ABORTPROC) m_lpAbortProc); #else @@ -215,6 +201,7 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt sm_lastError = wxPRINTER_ERROR; delete dc; + return false; } sm_abortWindow = win; sm_abortWindow->Show(); @@ -286,7 +273,7 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt delete dc; - return (sm_lastError == wxPRINTER_NO_ERROR); + return sm_lastError == wxPRINTER_NO_ERROR; } wxDC* wxWindowsPrinter::PrintDialog(wxWindow *parent) @@ -311,8 +298,10 @@ wxDC* wxWindowsPrinter::PrintDialog(wxWindow *parent) return dc; } -bool wxWindowsPrinter::Setup(wxWindow *parent) +bool wxWindowsPrinter::Setup(wxWindow *WXUNUSED(parent)) { +#if 0 + // We no longer expose that dialog wxPrintDialog dialog(parent, & m_printDialogData); dialog.GetPrintDialogData().SetSetupDialog(true); @@ -324,6 +313,9 @@ bool wxWindowsPrinter::Setup(wxWindow *parent) } return (ret == wxID_OK); +#else + return false; +#endif } /* @@ -360,28 +352,27 @@ bool wxWindowsPrintPreview::Print(bool interactive) void wxWindowsPrintPreview::DetermineScaling() { - HDC dc = ::GetDC(NULL); + ScreenHDC dc; int screenWidth = ::GetDeviceCaps(dc, HORZSIZE); - int screenYRes = ::GetDeviceCaps(dc, VERTRES); + int screenXRes = ::GetDeviceCaps(dc, HORZRES); int logPPIScreenX = ::GetDeviceCaps(dc, LOGPIXELSX); int logPPIScreenY = ::GetDeviceCaps(dc, LOGPIXELSY); m_previewPrintout->SetPPIScreen(logPPIScreenX, logPPIScreenY); - ::ReleaseDC(NULL, dc); // Get a device context for the currently selected printer wxPrinterDC printerDC(m_printDialogData.GetPrintData()); int printerWidth = 150; - int printerHeight = 250; int printerXRes = 1500; int printerYRes = 2500; - dc = GetHdcOf(printerDC); - if ( dc ) + if ( printerDC.Ok() ) { + HDC dc = GetHdcOf(printerDC); + printerWidth = ::GetDeviceCaps(dc, HORZSIZE); - printerHeight = ::GetDeviceCaps(dc, VERTSIZE); + int printerHeight = ::GetDeviceCaps(dc, VERTSIZE); printerXRes = ::GetDeviceCaps(dc, HORZRES); printerYRes = ::GetDeviceCaps(dc, VERTRES); @@ -391,18 +382,29 @@ void wxWindowsPrintPreview::DetermineScaling() m_previewPrintout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY); m_previewPrintout->SetPageSizeMM(printerWidth, printerHeight); - if (logPPIPrinterX == 0 || logPPIPrinterY == 0 || printerWidth == 0 || printerHeight == 0) + if ( logPPIPrinterX == 0 || + logPPIPrinterY == 0 || + printerWidth == 0 || + printerHeight == 0 ) + { m_isOk = false; + } } else + { m_isOk = false; + } m_pageWidth = printerXRes; m_pageHeight = printerYRes; // 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)screenYRes/(float)printerYRes); + // + // 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; } /**************************************************************************** @@ -422,15 +424,15 @@ LONG APIENTRY _EXPORT wxAbortProc(HDC WXUNUSED(hPr), int WXUNUSED(Code)) /* Process messages intended for the abort dialog box */ - while (!wxPrinterBase::sm_abortIt && PeekMessage(&msg, 0, 0, 0, TRUE)) + while (!wxPrinterBase::sm_abortIt && ::PeekMessage(&msg, 0, 0, 0, TRUE)) if (!IsDialogMessage((HWND) wxPrinterBase::sm_abortWindow->GetHWND(), &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } - /* bAbort is TRUE (return is FALSE) if the user has aborted */ + /* bAbort is TRUE (return is FALSE) if the user has aborted */ - return (!wxPrinterBase::sm_abortIt); + return !wxPrinterBase::sm_abortIt; } #endif