From: Vadim Zeitlin Date: Sat, 13 Oct 2012 22:52:35 +0000 (+0000) Subject: Freeze wxTreeCtrl in wxMSW by hiding it. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/6754c300cf9a378f4dcbe745be545139ffa0a989?ds=sidebyside Freeze wxTreeCtrl in wxMSW by hiding it. This is far from perfect but better than alternative as freezing this control by sending WM_SETREDRAW to it can result in completely broken behaviour as explained in http://support.microsoft.com/kb/130611. And not freezing it at all shows horrible flicker when adding even a relatively small number of items at once to the control because it recalculates and repositions its scrollbars after every parent node addition. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72665 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/msw/treectrl.h b/include/wx/msw/treectrl.h index 83e4afa6f2..2be605fa2f 100644 --- a/include/wx/msw/treectrl.h +++ b/include/wx/msw/treectrl.h @@ -212,6 +212,10 @@ public: virtual bool CanApplyThemeBorder() const { return false; } protected: + // Implement "update locking" in a custom way for this control. + virtual void DoFreeze(); + virtual void DoThaw(); + // SetImageList helper void SetAnyImageList(wxImageList *imageList, int which); diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index 9e99796c0a..0ac6f626c0 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -3923,4 +3923,32 @@ void wxTreeCtrl::DoSetItemState(const wxTreeItemId& item, int state) DoSetItem(&tvItem); } +// ---------------------------------------------------------------------------- +// Update locking. +// ---------------------------------------------------------------------------- + +// Using WM_SETREDRAW with the native control is a bad idea as it's broken in +// some Windows versions (see http://support.microsoft.com/kb/130611) and +// doesn't seem to do anything in other ones (e.g. under Windows 7 the tree +// control keeps updating its scrollbars while the items are added to it, +// resulting in horrible flicker when adding even a couple of dozen items). +// So we hide it instead of freezing -- this still flickers, but actually not +// as badly as it would if we didn't do it. + +void wxTreeCtrl::DoFreeze() +{ + // Notice that we don't call wxWindow::Hide() here as we want the window to + // remain shown from wxWidgets point of view and also because + // wxWindowMSW::Show() calls Do{Freeze,Thaw}() itself, so we'd get into + // infinite recursion this way. + if ( IsShown() ) + ::ShowWindow(GetHwnd(), SW_HIDE); +} + +void wxTreeCtrl::DoThaw() +{ + if ( IsShown() ) + ::ShowWindow(GetHwnd(), SW_SHOW); +} + #endif // wxUSE_TREECTRL