From b488f468a33f3d243ea074fd03e1039f02db5bc3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 10 Sep 2014 16:51:26 +0000 Subject: [PATCH] Make skipping event in wxEVT_PAINT handler work correctly in wxMSW. This should result in the default handler still being called and painting the window, but the latter didn't happen because we called ::EndPaint(), and so validated the window and reset its update region, before passing WM_PAINT to DefWindowProc() in this case. Closes #16381. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77655 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/window.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/msw/window.cpp b/src/msw/window.cpp index d986da7b35..3d4dae58fd 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -4926,11 +4926,15 @@ bool wxWindowMSW::HandlePaint() bool processed = HandleWindowEvent(event); - if ( processed && !wxDidCreatePaintDC ) + if ( wxDidCreatePaintDC && !processed ) { - // do call MSWDefWindowProc() to validate the update region to avoid - // the problems mentioned above - processed = false; + // Event handler did paint something as wxPaintDC object was created + // but then it must have skipped the event to indicate that default + // handling should still take place, so call MSWDefWindowProc() right + // now. It's important to do it before EndPaint() call below as that + // would validate the window and MSWDefWindowProc(WM_PAINT) wouldn't do + // anything if called after it. + OnPaint(event); } // note that we must generate NC event after the normal one as otherwise @@ -4946,7 +4950,14 @@ bool wxWindowMSW::HandlePaint() wxPaintDCImpl::EndPaint((wxWindow *)this); - return processed; + // It doesn't matter whether the event was actually processed or not here, + // what matters is whether we already painted, and hence validated, the + // window or not. If we did, either the event was processed or we called + // OnPaint() above, so we should return true. If we did not, even the event + // was processed, we must still call MSWDefWindowProc() to ensure that the + // window is validated, i.e. to avoid the problem described in the comment + // before wxDidCreatePaintDC definition above. + return wxDidCreatePaintDC; } // Can be called from an application's OnPaint handler