Add wxPrintout::SetUp() to reuse the same code in all ports
MSW, GTK, OSX and Postscript implementations all did almost exactly the same thing to initialize wxPrintout, so extract this common code into a new wxPrintout method and just call it instead. There should be no changes in behaviour.
This commit is contained in:
@@ -281,6 +281,10 @@ public:
|
||||
|
||||
virtual wxString GetTitle() const { return m_printoutTitle; }
|
||||
|
||||
// Port-specific code should call this function to initialize this object
|
||||
// with everything it needs, instead of using individual accessors below.
|
||||
bool SetUp(wxDC& dc);
|
||||
|
||||
wxDC *GetDC() const { return m_printoutDC; }
|
||||
void SetDC(wxDC *dc) { m_printoutDC = dc; }
|
||||
|
||||
|
@@ -638,6 +638,33 @@ void wxPrintout::GetPageInfo(int *minPage, int *maxPage, int *fromPage, int *toP
|
||||
*toPage = 1;
|
||||
}
|
||||
|
||||
bool wxPrintout::SetUp(wxDC& dc)
|
||||
{
|
||||
SetPPIScreen(wxGetDisplayPPI());
|
||||
|
||||
// We need to know printer PPI. In most ports, this can be retrieved from
|
||||
// the printer DC, but in others it is computed (probably for legacy
|
||||
// reasons) outside of wxDC code, so don't override it if it had been
|
||||
// already set.
|
||||
if ( !m_PPIPrinterX || !m_PPIPrinterY )
|
||||
{
|
||||
SetPPIPrinter(dc.GetPPI());
|
||||
if ( !m_PPIPrinterX || !m_PPIPrinterY )
|
||||
{
|
||||
// But if we couldn't get it in any way, we can't continue.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
SetDC(&dc);
|
||||
|
||||
dc.GetSize(&m_pageWidthPixels, &m_pageHeightPixels);
|
||||
m_paperRectPixels = wxRect(0, 0, m_pageWidthPixels, m_pageHeightPixels);
|
||||
dc.GetSizeMM(&m_pageWidthMM, &m_pageHeightMM);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxPrintout::FitThisSizeToPaper(const wxSize& imageSize)
|
||||
{
|
||||
// Set the DC scale and origin so that the given image size fits within the
|
||||
|
@@ -105,24 +105,8 @@ bool wxPostScriptPrinter::Print(wxWindow *parent, wxPrintout *printout, bool pro
|
||||
return false;
|
||||
}
|
||||
|
||||
wxSize ScreenPixels = wxGetDisplaySize();
|
||||
wxSize ScreenMM = wxGetDisplaySizeMM();
|
||||
|
||||
printout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()),
|
||||
(int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) );
|
||||
printout->SetPPIPrinter( dc->GetResolution(),
|
||||
dc->GetResolution() );
|
||||
|
||||
// Set printout parameters
|
||||
printout->SetDC(dc);
|
||||
|
||||
int w, h;
|
||||
dc->GetSize(&w, &h);
|
||||
printout->SetPageSizePixels((int)w, (int)h);
|
||||
printout->SetPaperRectPixels(wxRect(0, 0, w, h));
|
||||
int mw, mh;
|
||||
dc->GetSizeMM(&mw, &mh);
|
||||
printout->SetPageSizeMM((int)mw, (int)mh);
|
||||
printout->SetUp(*dc);
|
||||
|
||||
// Create an abort window
|
||||
wxBeginBusyCursor();
|
||||
|
@@ -1024,19 +1024,8 @@ void wxGtkPrinter::BeginPrint(wxPrintout *printout, GtkPrintOperation *operation
|
||||
return;
|
||||
}
|
||||
|
||||
printout->SetPPIScreen(wxGetDisplayPPI());
|
||||
printout->SetPPIPrinter( printDC->GetResolution(),
|
||||
printDC->GetResolution() );
|
||||
printout->SetUp(*m_dc);
|
||||
|
||||
printout->SetDC(m_dc);
|
||||
|
||||
int w, h;
|
||||
m_dc->GetSize(&w, &h);
|
||||
printout->SetPageSizePixels((int)w, (int)h);
|
||||
printout->SetPaperRectPixels(wxRect(0, 0, w, h));
|
||||
int mw, mh;
|
||||
m_dc->GetSizeMM(&mw, &mh);
|
||||
printout->SetPageSizeMM((int)mw, (int)mh);
|
||||
printout->OnPreparePrinting();
|
||||
|
||||
// Get some parameters from the printout, if defined.
|
||||
|
@@ -115,36 +115,14 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt
|
||||
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) impl->GetHDC(), LOGPIXELSX);
|
||||
int logPPIPrinterY = ::GetDeviceCaps((HDC) impl->GetHDC(), LOGPIXELSY);
|
||||
if (logPPIPrinterX == 0 || logPPIPrinterY == 0)
|
||||
// Set printout parameters
|
||||
if (!printout->SetUp(*dc))
|
||||
{
|
||||
delete dc;
|
||||
sm_lastError = wxPRINTER_ERROR;
|
||||
return false;
|
||||
}
|
||||
|
||||
printout->SetPPIScreen(logPPIScreenX, logPPIScreenY);
|
||||
printout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY);
|
||||
|
||||
// Set printout parameters
|
||||
printout->SetDC(dc);
|
||||
|
||||
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);
|
||||
|
||||
// Create an abort window
|
||||
wxBusyCursor busyCursor;
|
||||
|
||||
@@ -169,7 +147,7 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt
|
||||
wxPrintAbortDialog *win = CreateAbortWindow(parent, printout);
|
||||
wxYield();
|
||||
|
||||
::SetAbortProc(GetHdcOf(*impl), wxAbortProc);
|
||||
::SetAbortProc(GetHdcOf(*dc), wxAbortProc);
|
||||
|
||||
if (!win)
|
||||
{
|
||||
|
@@ -585,8 +585,6 @@ bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
|
||||
return false;
|
||||
}
|
||||
|
||||
printout->SetPPIScreen(wxGetDisplayPPI());
|
||||
|
||||
PMResolution res;
|
||||
PMPrinter printer;
|
||||
wxOSXPrintData* nativeData = (wxOSXPrintData*)
|
||||
@@ -607,15 +605,7 @@ bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
|
||||
printout->SetPPIPrinter(int(res.hRes), int(res.vRes));
|
||||
|
||||
// Set printout parameters
|
||||
printout->SetDC(dc);
|
||||
|
||||
int w, h;
|
||||
dc->GetSize(&w, &h);
|
||||
printout->SetPageSizePixels((int)w, (int)h);
|
||||
printout->SetPaperRectPixels(dc->GetPaperRect());
|
||||
wxCoord mw, mh;
|
||||
dc->GetSizeMM(&mw, &mh);
|
||||
printout->SetPageSizeMM((int)mw, (int)mh);
|
||||
printout->SetUp(*dc);
|
||||
|
||||
// Create an abort window
|
||||
wxBeginBusyCursor();
|
||||
|
Reference in New Issue
Block a user