X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f415cab9ef1433413a1a68a982ee9b17c5a8deda..747d7d7c159a57015d7aa9d844f834b78f613272:/src/common/prntbase.cpp diff --git a/src/common/prntbase.cpp b/src/common/prntbase.cpp index 3b7a963959..6e98cfadac 100644 --- a/src/common/prntbase.cpp +++ b/src/common/prntbase.cpp @@ -27,12 +27,14 @@ #include "wx/utils.h" #include "wx/dc.h" #include "wx/app.h" + #include "wx/math.h" #include "wx/msgdlg.h" #include "wx/layout.h" #include "wx/choice.h" #include "wx/button.h" #include "wx/settings.h" #include "wx/dcmemory.h" + #include "wx/dcclient.h" #include "wx/stattext.h" #include "wx/intl.h" #include "wx/textdlg.h" @@ -50,9 +52,14 @@ #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) #include "wx/msw/printdlg.h" +#include "wx/msw/dcprint.h" #elif defined(__WXMAC__) #include "wx/mac/printdlg.h" #include "wx/mac/private/print.h" +#include "wx/mac/dcprint.h" +#elif defined(__WXPM__) +#include "wx/os2/dcprint.h" +#include "wx/generic/prntdlgg.h" #else #include "wx/generic/prntdlgg.h" #include "wx/dcps.h" @@ -203,14 +210,12 @@ wxDialog *wxNativePrintFactory::CreatePrintSetupDialog( wxWindow *parent, #endif } -wxDC* wxNativePrintFactory::CreatePrinterDC( const wxPrintData& data ) +wxDCImpl* wxNativePrintFactory::CreatePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data ) { -#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) - return new wxPrinterDC(data); -#elif defined(__WXMAC__) - return new wxPrinterDC(data); +#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXUNIVERSAL__) + return new wxPostScriptDCImpl( owner, data ); #else - return new wxPostScriptDC(data); + return new wxPrinterDCImpl( owner, data ); #endif } @@ -617,10 +622,10 @@ void wxPrintout::FitThisSizeToPageMargins(const wxSize& imageSize, const wxPageS GetPageSizeMM(&mw, &mh); float mmToDeviceX = float(pw) / mw; float mmToDeviceY = float(ph) / mh; - wxRect pageMarginsRect(paperRect.x + wxCoord(mmToDeviceX * topLeft.x), - paperRect.y + wxCoord(mmToDeviceY * topLeft.y), - paperRect.width - wxCoord(mmToDeviceX * (topLeft.x + bottomRight.x)), - paperRect.height - wxCoord(mmToDeviceY * (topLeft.y + bottomRight.y))); + wxRect pageMarginsRect(paperRect.x + wxRound(mmToDeviceX * topLeft.x), + paperRect.y + wxRound(mmToDeviceY * topLeft.y), + paperRect.width - wxRound(mmToDeviceX * (topLeft.x + bottomRight.x)), + paperRect.height - wxRound(mmToDeviceY * (topLeft.y + bottomRight.y))); wxCoord w, h; m_printoutDC->GetSize(&w, &h); float scaleX = (float(pageMarginsRect.width) * w) / (float(pw) * imageSize.x); @@ -708,10 +713,10 @@ wxRect wxPrintout::GetLogicalPaperRect() const // This DC doesn't match the printed page, so we have to scale. float scaleX = float(w) / pw; float scaleY = float(h) / ph; - return wxRect(m_printoutDC->DeviceToLogicalX(wxCoord(paperRect.x * scaleX)), - m_printoutDC->DeviceToLogicalY(wxCoord(paperRect.y * scaleY)), - m_printoutDC->DeviceToLogicalXRel(wxCoord(paperRect.width * scaleX)), - m_printoutDC->DeviceToLogicalYRel(wxCoord(paperRect.height * scaleY))); + return wxRect(m_printoutDC->DeviceToLogicalX(wxRound(paperRect.x * scaleX)), + m_printoutDC->DeviceToLogicalY(wxRound(paperRect.y * scaleY)), + m_printoutDC->DeviceToLogicalXRel(wxRound(paperRect.width * scaleX)), + m_printoutDC->DeviceToLogicalYRel(wxRound(paperRect.height * scaleY))); } wxRect wxPrintout::GetLogicalPageRect() const @@ -731,51 +736,66 @@ wxRect wxPrintout::GetLogicalPageMarginsRect(const wxPageSetupDialogData& pageSe // Return the rectangle in logical units that corresponds to the region // within the page margins as specified by the given wxPageSetupDialogData // object. - wxRect paperRect = GetPaperRectPixels(); + + // We get the paper size in device units and the margins in mm, + // so we need to calculate the conversion with this trick wxCoord pw, ph; GetPageSizePixels(&pw, &ph); - wxPoint topLeft = pageSetupData.GetMarginTopLeft(); - wxPoint bottomRight = pageSetupData.GetMarginBottomRight(); wxCoord mw, mh; GetPageSizeMM(&mw, &mh); float mmToDeviceX = float(pw) / mw; float mmToDeviceY = float(ph) / mh; - wxRect pageMarginsRect(paperRect.x + wxCoord(mmToDeviceX * topLeft.x), - paperRect.y + wxCoord(mmToDeviceY * topLeft.y), - paperRect.width - wxCoord(mmToDeviceX * (topLeft.x + bottomRight.x)), - paperRect.height - wxCoord(mmToDeviceY * (topLeft.y + bottomRight.y))); + + // paper size in device units + wxRect paperRect = GetPaperRectPixels(); + + // margins in mm + wxPoint topLeft = pageSetupData.GetMarginTopLeft(); + wxPoint bottomRight = pageSetupData.GetMarginBottomRight(); + + // calculate margins in device units + wxRect pageMarginsRect( + paperRect.x + wxRound(mmToDeviceX * topLeft.x), + paperRect.y + wxRound(mmToDeviceY * topLeft.y), + paperRect.width - wxRound(mmToDeviceX * (topLeft.x + bottomRight.x)), + paperRect.height - wxRound(mmToDeviceY * (topLeft.y + bottomRight.y))); + wxCoord w, h; m_printoutDC->GetSize(&w, &h); - if (w == pw && h == ph) { + if (w == pw && h == ph) + { // this DC matches the printed page, so no scaling - return wxRect(m_printoutDC->DeviceToLogicalX(pageMarginsRect.x), + return wxRect( + m_printoutDC->DeviceToLogicalX(pageMarginsRect.x), m_printoutDC->DeviceToLogicalY(pageMarginsRect.y), m_printoutDC->DeviceToLogicalXRel(pageMarginsRect.width), m_printoutDC->DeviceToLogicalYRel(pageMarginsRect.height)); } + // This DC doesn't match the printed page, so we have to scale. float scaleX = float(w) / pw; float scaleY = float(h) / ph; - return wxRect(m_printoutDC->DeviceToLogicalX(wxCoord(pageMarginsRect.x * scaleX)), - m_printoutDC->DeviceToLogicalY(wxCoord(pageMarginsRect.y * scaleY)), - m_printoutDC->DeviceToLogicalXRel(wxCoord(pageMarginsRect.width * scaleX)), - m_printoutDC->DeviceToLogicalYRel(wxCoord(pageMarginsRect.height * scaleY))); + return wxRect(m_printoutDC->DeviceToLogicalX(wxRound(pageMarginsRect.x * scaleX)), + m_printoutDC->DeviceToLogicalY(wxRound(pageMarginsRect.y * scaleY)), + m_printoutDC->DeviceToLogicalXRel(wxRound(pageMarginsRect.width * scaleX)), + m_printoutDC->DeviceToLogicalYRel(wxRound(pageMarginsRect.height * scaleY))); } void wxPrintout::SetLogicalOrigin(wxCoord x, wxCoord y) { // Set the device origin by specifying a point in logical coordinates. - m_printoutDC->SetDeviceOrigin(m_printoutDC->LogicalToDeviceX(x), - m_printoutDC->LogicalToDeviceY(y)); + m_printoutDC->SetDeviceOrigin( + m_printoutDC->LogicalToDeviceX(x), + m_printoutDC->LogicalToDeviceY(y) ); } void wxPrintout::OffsetLogicalOrigin(wxCoord xoff, wxCoord yoff) { // Offset the device origin by a specified distance in device coordinates. - wxCoord x = m_printoutDC->LogicalToDeviceX(0); - wxCoord y = m_printoutDC->LogicalToDeviceY(0); - m_printoutDC->SetDeviceOrigin(x + m_printoutDC->LogicalToDeviceXRel(xoff), - y + m_printoutDC->LogicalToDeviceYRel(yoff)); + wxPoint dev_org = m_printoutDC->GetDeviceOrigin(); + m_printoutDC->SetDeviceOrigin( + dev_org.x + m_printoutDC->LogicalToDeviceXRel(xoff), + dev_org.y + m_printoutDC->LogicalToDeviceYRel(yoff) ); } @@ -807,6 +827,8 @@ wxScrolledWindow(parent, wxID_ANY, pos, size, style | wxFULL_REPAINT_ON_RESIZE, // The app workspace colour is always white, but we should have // a contrast with the page. wxSystemColour colourIndex = wxSYS_COLOUR_3DDKSHADOW; +#elif defined(__WXGTK__) + wxSystemColour colourIndex = wxSYS_COLOUR_BTNFACE; #else wxSystemColour colourIndex = wxSYS_COLOUR_APPWORKSPACE; #endif @@ -844,6 +866,8 @@ void wxPreviewCanvas::OnSysColourChanged(wxSysColourChangedEvent& event) // The app workspace colour is always white, but we should have // a contrast with the page. wxSystemColour colourIndex = wxSYS_COLOUR_3DDKSHADOW; +#elif defined(__WXGTK__) + wxSystemColour colourIndex = wxSYS_COLOUR_BTNFACE; #else wxSystemColour colourIndex = wxSYS_COLOUR_APPWORKSPACE; #endif @@ -857,20 +881,14 @@ void wxPreviewCanvas::OnSysColourChanged(wxSysColourChangedEvent& event) void wxPreviewCanvas::OnChar(wxKeyEvent &event) { wxPreviewControlBar* controlBar = ((wxPreviewFrame*) GetParent())->GetControlBar(); - if (event.GetKeyCode() == WXK_ESCAPE) + switch (event.GetKeyCode()) { - ((wxPreviewFrame*) GetParent())->Close(true); - return; - } - else if (event.GetKeyCode() == WXK_TAB) - { - controlBar->OnGoto(); - return; - } - else if (event.GetKeyCode() == WXK_RETURN) - { - controlBar->OnPrint(); - return; + case WXK_TAB: + controlBar->OnGoto(); + return; + case WXK_RETURN: + controlBar->OnPrint(); + return; } if (!event.ControlDown()) @@ -1203,9 +1221,22 @@ int wxPreviewControlBar::GetZoomControl() IMPLEMENT_CLASS(wxPreviewFrame, wxFrame) BEGIN_EVENT_TABLE(wxPreviewFrame, wxFrame) + EVT_CHAR_HOOK(wxPreviewFrame::OnChar) EVT_CLOSE(wxPreviewFrame::OnCloseWindow) END_EVENT_TABLE() +void wxPreviewFrame::OnChar(wxKeyEvent &event) +{ + if ( event.GetKeyCode() == WXK_ESCAPE ) + { + Close(true); + } + else + { + event.Skip(); + } +} + wxPreviewFrame::wxPreviewFrame(wxPrintPreviewBase *preview, wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name): wxFrame(parent, wxID_ANY, title, pos, size, style, name)