diff --git a/docs/changes.txt b/docs/changes.txt index 1b8ee90d70..dc1d948b26 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -74,7 +74,6 @@ All: - Add support for loading dynamic lexer in wxStyledTextCtrl (New Pagodi). - Handle strings with embedded NULs in wxDataStream (Nitch). - Don't crash in wxTextFile::GetLastLine() if the file is empty (crohr). -- Many fixes and improvements in Direct2D, Cairo, and GDI+ graphics renderers. All (GUI): @@ -92,6 +91,8 @@ All (GUI): - Implement auto complete in generic wxSearchCtrl (Eric Jensen). - Fix preserving selection when changing selection mode in wxGrid (jonkraber). - Fix wxTextEntry::SetHint() with wxTE_PASSWORD in generic implementation. +- Many fixes and improvements in Direct2D, Cairo, and GDI+ graphics renderers. +- Fix and unify clipping region support for MSW and GTK+. wxGTK: diff --git a/src/gtk/dc.cpp b/src/gtk/dc.cpp index e87585b6d5..bef12a5081 100644 --- a/src/gtk/dc.cpp +++ b/src/gtk/dc.cpp @@ -398,11 +398,43 @@ wxGTKDCImpl::~wxGTKDCImpl() void wxGTKDCImpl::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) { - m_clipping = TRUE; - m_clipX1 = x; - m_clipY1 = y; - m_clipX2 = x + width; - m_clipY2 = y + height; + wxASSERT_MSG( width >= 0 && height >= 0, + "Clipping box size values cannot be negative" ); + + wxRect newRegion(x, y, width, height); + + wxRect clipRegion; + if ( m_clipping ) + { + // New clipping box is an intersection + // of required clipping box and the current one. + wxRect curRegion(m_clipX1, m_clipY1, m_clipX2 - m_clipX1, m_clipY2 - m_clipY1); + clipRegion = curRegion.Intersect(newRegion); + } + else + { + // Effective clipping box is an intersection + // of required clipping box and DC surface. + int dcWidth, dcHeight; + DoGetSize(&dcWidth, &dcHeight); + wxRect dcRect(DeviceToLogicalX(0), DeviceToLogicalY(0), + DeviceToLogicalXRel(dcWidth), DeviceToLogicalYRel(dcHeight)); + clipRegion = dcRect.Intersect(newRegion); + + m_clipping = true; + } + + if ( clipRegion.IsEmpty() ) + { + m_clipX1 = m_clipY1 = m_clipX2 = m_clipY2 = 0; + } + else + { + m_clipX1 = clipRegion.GetLeftTop().x; + m_clipY1 = clipRegion.GetLeftTop().y; + m_clipX2 = clipRegion.GetBottomRight().x + 1; + m_clipY2 = clipRegion.GetBottomRight().y + 1; + } } // --------------------------------------------------------------------------- diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index f0cd8151ce..05ccdea82b 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -1918,7 +1918,8 @@ void wxWindowDCImpl::DoSetDeviceClippingRegion( const wxRegion ®ion ) wxCoord xx, yy, ww, hh; m_currentClippingRegion.GetBox( xx, yy, ww, hh ); - wxGTKDCImpl::DoSetClippingRegion( xx, yy, ww, hh ); + wxGTKDCImpl::DoSetClippingRegion(DeviceToLogicalX(xx), DeviceToLogicalY(yy), + DeviceToLogicalXRel(ww), DeviceToLogicalYRel(hh)); GdkRegion* gdkRegion = m_currentClippingRegion.GetRegion(); gdk_gc_set_clip_region(m_penGC, gdkRegion);