From 90106003d3c6f934a974b4f550df2679f04532ad Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 1 Oct 2019 01:13:42 +0200 Subject: [PATCH] Clear DC using white background by default in wxMSW Since 848f5e78a60bde49900159a77b218bb15c80382d the background wasn't cleared at all if the background brush hadn't been explicitly set prior to calling wxDC::Clear(). This was incompatible with the old behaviour and even managed to break our own print preview code, so it clearly wasn't a good idea to change Clear() like this. Instead, continue to clear the DC using white background by default, while still not doing anything if a transparent background brush had been explicitly set. This fixes print preview background under MSW. See #10273, #18371. --- src/msw/dc.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 9652af4ccf..5260a7085e 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -729,8 +729,23 @@ void wxMSWDCImpl::Clear() return; } + HBRUSH hbr; if ( !m_backgroundBrush.IsOk() ) + { + // By default, use the stock white brush for compatibility with the + // previous wx versions. + hbr = WHITE_BRUSH; + } + else if ( !m_backgroundBrush.IsTransparent() ) + { + hbr = GetHbrushOf(m_backgroundBrush); + } + else // Using transparent background brush. + { + // Clearing with transparent brush doesn't do anything, just as drawing + // with transparent pen doesn't. return; + } RECT rect; ::GetClipBox(GetHdc(), &rect); @@ -738,7 +753,7 @@ void wxMSWDCImpl::Clear() // to compensate rounding errors if DC is the subject // of complex transformation (is e.g. rotated). ::InflateRect(&rect, 1, 1); - ::FillRect(GetHdc(), &rect, GetHbrushOf(m_backgroundBrush)); + ::FillRect(GetHdc(), &rect, hbr); RealizeScaleAndOrigin(); }