From ff629f3853722f25776caeb643956a3ab904dcf5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 16 Oct 2022 21:26:33 +0100 Subject: [PATCH] Fix drawing wxListCtrl since enabling double buffering by default We need to avoid using WS_EX_COMPOSITED for any of the parents of this native control and not just for the control itself. --- include/wx/msw/listctrl.h | 5 +++++ src/msw/listctrl.cpp | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/wx/msw/listctrl.h b/include/wx/msw/listctrl.h index 4a3362bf84..8bec412b92 100644 --- a/include/wx/msw/listctrl.h +++ b/include/wx/msw/listctrl.h @@ -399,6 +399,8 @@ protected: virtual void MSWUpdateFontOnDPIChange(const wxSize& newDPI) override; + virtual void MSWAfterReparent() override; + void OnDPIChanged(wxDPIChangedEvent& event); wxSize MSWGetBestViewRect(int x, int y) const; @@ -441,6 +443,9 @@ private: // UpdateStyle()), only should be called if InReportView() void MSWSetExListStyles(); + // ensure that none of our parents uses WS_EX_COMPOSITED + void MSWResetParentComposited(); + // initialize the (already created) m_textCtrl with the associated HWND void InitEditControl(WXHWND hWnd); diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 1fbf0a11a2..dc150b25e8 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -41,6 +41,7 @@ #include "wx/msw/private.h" #include "wx/msw/private/customdraw.h" #include "wx/msw/private/keyboard.h" +#include "wx/msw/private/winstyle.h" // Currently gcc doesn't define NMLVFINDITEM, and DMC only defines // it by its old name NM_FINDTIEM. @@ -300,6 +301,8 @@ bool wxListCtrl::Create(wxWindow *parent, if ( !MSWCreateControl(WC_LISTVIEW, wxEmptyString, pos, size) ) return false; + MSWResetParentComposited(); + EnableSystemThemeByDefault(); // explicitly say that we want to use Unicode because otherwise we get ANSI @@ -371,6 +374,26 @@ void wxListCtrl::MSWSetExListStyles() ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE, 0, exStyle); } +void wxListCtrl::MSWResetParentComposited() +{ + // LISTVIEW doesn't redraw correctly when WS_EX_COMPOSITED is used by + // either the control itself (which never happens now, see our overridden + // SetDoubleBuffered()) or even by any of its parents, so we must reset + // this style for them. + for ( wxWindow* parent = GetParent(); parent; parent = parent->GetParent() ) + { + wxMSWWinExStyleUpdater(GetHwndOf(parent)).TurnOff(WS_EX_COMPOSITED); + + if ( parent->IsTopLevel() ) + break; + } +} + +void wxListCtrl::MSWAfterReparent() +{ + MSWResetParentComposited(); +} + WXDWORD wxListCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const { WXDWORD wstyle = wxListCtrlBase::MSWGetStyle(style, exstyle);