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.
This commit is contained in:
Vadim Zeitlin 2022-10-16 21:26:33 +01:00
parent cd637663c8
commit ff629f3853
2 changed files with 28 additions and 0 deletions

View file

@ -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);

View file

@ -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);