X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bb56b0a828cad8b9a57dc8270a2aca42afb1903e..6376cdc3a547095337c388a464f8e28b08d1e138:/src/gtk1/dcclient.cpp diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index c260841eda..d67e3cc0c0 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -2331,6 +2331,25 @@ int wxWindowDC::GetDepth() const IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxClientDC) +// Limit the paint region to the window size. Sometimes +// the paint region is too big, and this risks X11 errors +static void wxLimitRegionToSize(wxRegion& region, const wxSize& sz) +{ + wxRect originalRect = region.GetBox(); + wxRect rect(originalRect); + if (rect.width + rect.x > sz.x) + rect.width = sz.x - rect.x; + if (rect.height + rect.y > sz.y) + rect.height = sz.y - rect.y; + if (rect != originalRect) + { + region = wxRegion(rect); + wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"), + originalRect.x, originalRect.y, originalRect.width, originalRect.height, + rect.x, rect.y, rect.width, rect.height); + } +} + wxPaintDC::wxPaintDC( wxWindow *win ) : wxClientDC( win ) { @@ -2338,21 +2357,23 @@ wxPaintDC::wxPaintDC( wxWindow *win ) if (!win->m_clipPaintRegion) return; + wxSize sz = win->GetSize(); m_paintClippingRegion = win->GetUpdateRegion(); + wxLimitRegionToSize(m_paintClippingRegion, sz); + GdkRegion *region = m_paintClippingRegion.GetRegion(); if ( region ) { - m_paintClippingRegion = win->GetUpdateRegion(); - GdkRegion *region = m_paintClippingRegion.GetRegion(); - if ( region ) - { - m_currentClippingRegion.Union( m_paintClippingRegion ); + m_currentClippingRegion.Union( m_paintClippingRegion ); + wxLimitRegionToSize(m_currentClippingRegion, sz); - gdk_gc_set_clip_region( m_penGC, region ); - gdk_gc_set_clip_region( m_brushGC, region ); - gdk_gc_set_clip_region( m_textGC, region ); - gdk_gc_set_clip_region( m_bgGC, region ); - } + if (sz.x <= 0 || sz.y <= 0) + return ; + + gdk_gc_set_clip_region( m_penGC, region ); + gdk_gc_set_clip_region( m_brushGC, region ); + gdk_gc_set_clip_region( m_textGC, region ); + gdk_gc_set_clip_region( m_bgGC, region ); } #endif // USE_PAINT_REGION }