From 13f9789996672cb48d5e88b03db0273522ab8273 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sat, 9 Jul 2016 23:32:23 +0200 Subject: [PATCH] Fixed clearing wxWindowDC, wxMemoryDC for wxMSW. Current implementation suffers for two issues: 1. Because wxClientDC and wxWindowDC are not distinguished in wxMSWDCImpl::Clear and in both cases DC coordinates are obtained with GetClientRect() Win API what leads to this that for wxWindowDC the entire area is not cleared. 2. Translations like moving logical origin or scaling are not taken into account in wxMemoryDC coordinates calculations (only device origin is included) so for transformed DC calculated coordinates are invalid and finally the entire area is not cleared. To fix these issues we can use GetClipBox() Win API to obtain actual logical coordinates of the clipping box (with all translations and scaling already included) and this way we can avoid using separate methods of retrieving coordinates for wxClientDC, wxWindowDC and wxMemoryDC. --- src/msw/dc.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 7207c2311f..186db72bb0 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -709,30 +709,19 @@ int wxMSWDCImpl::GetDepth() const void wxMSWDCImpl::Clear() { - RECT rect; - if (m_window) - { - GetClientRect((HWND) m_window->GetHWND(), &rect); - } - else + if ( !m_window ) { // No, I think we should simply ignore this if printing on e.g. // a printer DC. // wxCHECK_RET( m_selectedBitmap.IsOk(), wxT("this DC can't be cleared") ); if (!m_selectedBitmap.IsOk()) return; - - rect.left = rect.top = 0; - rect.right = m_selectedBitmap.GetWidth(); - rect.bottom = m_selectedBitmap.GetHeight(); } - ::OffsetRect(&rect, -m_deviceOriginX, -m_deviceOriginY); - - (void) ::SetMapMode(GetHdc(), MM_TEXT); - DWORD colour = ::GetBkColor(GetHdc()); HBRUSH brush = ::CreateSolidBrush(colour); + RECT rect; + ::GetClipBox(GetHdc(), &rect); ::FillRect(GetHdc(), &rect, brush); ::DeleteObject(brush);