X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/04ee05f92add0ab92ce08ecb827e3be41336aa06..a9d859df6f433c962a9ed777d2c26da6ce714441:/src/common/dcbase.cpp diff --git a/src/common/dcbase.cpp b/src/common/dcbase.cpp index 3c466c6b20..a60da2e657 100644 --- a/src/common/dcbase.cpp +++ b/src/common/dcbase.cpp @@ -53,9 +53,9 @@ #endif #ifdef __WXMAC__ - #include "wx/mac/dcclient.h" - #include "wx/mac/dcmemory.h" - #include "wx/mac/dcscreen.h" + #include "wx/osx/dcclient.h" + #include "wx/osx/dcmemory.h" + #include "wx/osx/dcscreen.h" #endif #ifdef __WXPM__ @@ -131,34 +131,25 @@ IMPLEMENT_DYNAMIC_CLASS(wxDCFactoryCleanupModule, wxModule) // wxNativeDCFactory //----------------------------------------------------------------------------- -wxDCImpl* wxNativeDCFactory::CreateWindowDC( wxWindowDC *owner ) -{ - return new wxWindowDCImpl( owner ); -} - wxDCImpl* wxNativeDCFactory::CreateWindowDC( wxWindowDC *owner, wxWindow *window ) { - return new wxWindowDCImpl( owner, window ); -} - -wxDCImpl* wxNativeDCFactory::CreateClientDC( wxClientDC *owner ) -{ - return new wxClientDCImpl( owner ); + wxDCImpl * const impl = new wxWindowDCImpl( owner, window ); + impl->InheritAttributes(window); + return impl; } wxDCImpl* wxNativeDCFactory::CreateClientDC( wxClientDC *owner, wxWindow *window ) { - return new wxClientDCImpl( owner, window ); -} - -wxDCImpl* wxNativeDCFactory::CreatePaintDC( wxPaintDC *owner ) -{ - return new wxPaintDCImpl( owner ); + wxDCImpl * const impl = new wxClientDCImpl( owner, window ); + impl->InheritAttributes(window); + return impl; } wxDCImpl* wxNativeDCFactory::CreatePaintDC( wxPaintDC *owner, wxWindow *window ) { - return new wxPaintDCImpl( owner, window ); + wxDCImpl * const impl = new wxPaintDCImpl( owner, window ); + impl->InheritAttributes(window); + return impl; } wxDCImpl* wxNativeDCFactory::CreateMemoryDC( wxMemoryDC *owner ) @@ -166,9 +157,19 @@ wxDCImpl* wxNativeDCFactory::CreateMemoryDC( wxMemoryDC *owner ) return new wxMemoryDCImpl( owner ); } -wxDCImpl* wxNativeDCFactory::CreateMemoryDC( wxMemoryDC *owner, wxBitmap &bitmap ) +wxDCImpl* wxNativeDCFactory::CreateMemoryDC(wxMemoryDC *owner, wxBitmap& bitmap) { - return new wxMemoryDCImpl( owner, bitmap ); + // the bitmap may be modified when it's selected into a memory DC so make + // sure changing this bitmap doesn't affect any other shallow copies of it + // (see wxMemoryDC::SelectObject()) + // + // notice that we don't provide any ctor equivalent to SelectObjectAsSource + // method because this should be rarely needed and easy to work around by + // using the default ctor and calling SelectObjectAsSource itself + if ( bitmap.IsOk() ) + bitmap.UnShare(); + + return new wxMemoryDCImpl(owner, bitmap); } wxDCImpl* wxNativeDCFactory::CreateMemoryDC( wxMemoryDC *owner, wxDC *dc ) @@ -299,12 +300,12 @@ wxPrinterDC::wxPrinterDC(const wxPrintData& data) { } -wxRect wxPrinterDC::GetPaperRect() +wxRect wxPrinterDC::GetPaperRect() const { return GetImpl()->GetPaperRect(); } -int wxPrinterDC::GetResolution() +int wxPrinterDC::GetResolution() const { return GetImpl()->GetResolution(); } @@ -368,12 +369,12 @@ wxDCImpl::~wxDCImpl() wxCoord wxDCImpl::DeviceToLogicalX(wxCoord x) const { - return wxRound((double)(x - m_deviceOriginX - m_deviceLocalOriginX) / m_scaleX) * m_signX + m_logicalOriginX; + return wxRound( (double)((x - m_deviceOriginX - m_deviceLocalOriginX) * m_signX) / m_scaleX ) + m_logicalOriginX ; } wxCoord wxDCImpl::DeviceToLogicalY(wxCoord y) const { - return wxRound((double)(y - m_deviceOriginY - m_deviceLocalOriginY) / m_scaleY) * m_signY + m_logicalOriginY; + return wxRound( (double)((y - m_deviceOriginY - m_deviceLocalOriginY) * m_signY) / m_scaleY ) + m_logicalOriginY ; } wxCoord wxDCImpl::DeviceToLogicalXRel(wxCoord x) const @@ -388,12 +389,12 @@ wxCoord wxDCImpl::DeviceToLogicalYRel(wxCoord y) const wxCoord wxDCImpl::LogicalToDeviceX(wxCoord x) const { - return wxRound((double)(x - m_logicalOriginX) * m_scaleX) * m_signX + m_deviceOriginX * m_signY + m_deviceLocalOriginX; + return wxRound( (double)((x - m_logicalOriginX) * m_signX) * m_scaleX) + m_deviceOriginX + m_deviceLocalOriginX; } wxCoord wxDCImpl::LogicalToDeviceY(wxCoord y) const { - return wxRound((double)(y - m_logicalOriginY) * m_scaleY) * m_signY + m_deviceOriginY * m_signY + m_deviceLocalOriginY; + return wxRound( (double)((y - m_logicalOriginY) * m_signY) * m_scaleY) + m_deviceOriginY + m_deviceLocalOriginY; } wxCoord wxDCImpl::LogicalToDeviceXRel(wxCoord x) const @@ -758,38 +759,21 @@ wxDCImpl::DoDrawPolyPolygon(int n, #if wxUSE_SPLINES -void wxDCImpl::DoDrawSpline(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord x3, wxCoord y3) +void wxDCImpl::DrawSpline(wxCoord x1, wxCoord y1, + wxCoord x2, wxCoord y2, + wxCoord x3, wxCoord y3) { - wxPointList point_list; - - wxPoint *point1 = new wxPoint; - point1->x = x1; point1->y = y1; - point_list.Append( point1 ); - - wxPoint *point2 = new wxPoint; - point2->x = x2; point2->y = y2; - point_list.Append( point2 ); - - wxPoint *point3 = new wxPoint; - point3->x = x3; point3->y = y3; - point_list.Append( point3 ); - - DoDrawSpline(&point_list); - - for( wxPointList::compatibility_iterator node = point_list.GetFirst(); node; node = node->GetNext() ) - { - wxPoint *p = node->GetData(); - delete p; - } + wxPoint points[] = { wxPoint(x1, y1), wxPoint(x2, y2), wxPoint(x3, y3) }; + DrawSpline(WXSIZEOF(points), points); } -void wxDCImpl::DoDrawSpline(int n, wxPoint points[]) +void wxDCImpl::DrawSpline(int n, wxPoint points[]) { wxPointList list; - for (int i =0; i < n; i++) - list.Append( &points[i] ); + for ( int i = 0; i < n; i++ ) + list.Append(&points[i]); - DoDrawSpline(&list); + DrawSpline(&list); } // ----------------------------------- spline code ---------------------------------------- @@ -1124,6 +1108,16 @@ void wxDCImpl::DoGradientFillConcentric(const wxRect& rect, m_pen.SetColour(oldPenColour); } +void wxDCImpl::InheritAttributes(wxWindow *win) +{ + wxCHECK_RET( win, "window can't be NULL" ); + + SetFont(win->GetFont()); + SetTextForeground(win->GetForegroundColour()); + SetTextBackground(win->GetBackgroundColour()); + SetBackground(wxBrush(win->GetBackgroundColour())); +} + //----------------------------------------------------------------------------- // wxDC //----------------------------------------------------------------------------- @@ -1204,7 +1198,7 @@ void wxDC::DrawLabel(const wxString& text, wxString curLine; for ( wxString::const_iterator pc = text.begin(); ; ++pc ) { - if ( *pc == _T('\n') || pc == text.end() ) + if ( pc == text.end() || *pc == '\n' ) { int xRealStart = x; // init it here to avoid compielr warnings @@ -1654,3 +1648,15 @@ void wxDCImpl::CalculateEllipticPoints( wxPointList* points, } // CalculateEllipticPoints #endif // __WXWINCE__ + +float wxDCImpl::GetFontPointSizeAdjustment(float dpi) +{ + // wxMSW has long-standing bug where wxFont point size is interpreted as + // "pixel size corresponding to given point size *on screen*". In other + // words, on a typical 600dpi printer and a typical 96dpi screen, fonts + // are ~6 times smaller when printing. Unfortunately, this bug is so severe + // that *all* printing code has to account for it and consequently, other + // ports need to emulate this bug too: + const wxSize screenPPI = wxGetDisplayPPI(); + return float(screenPPI.y) / dpi; +}