Disable scrollbars for frozen wxTreeCtrl in MSW
Replace the hack with resizing the control to the minimal possible size while it's frozen with just disabling its scrollbars in the frozen state. This should also fix the original problem (of scrollbar jumping around wildly as the items are added), but without different problems due to the control being resized unexpectedly. Unfortunately we don't have a reproducer for the original problem, which the commits6754c300cf
("Freeze wxTreeCtrl in wxMSW by hiding it") and4e1e8dc51b
("Change wxMSW wxTreeCtrl::DoFreeze() to not hide the tree any more" -- but resize it instead) tried to fix, so it's difficult to be sure that it really doesn't exist any more, but it does seem like it ought to be as the comment added back then spoke of the problem with scrollbar updating and this really shouldn't happen if scrollbars are completely disabled. See https://github.com/wxWidgets/wxWidgets/pull/375
This commit is contained in:
parent
aa4d51d579
commit
badf6bc300
@ -207,10 +207,6 @@ protected:
|
||||
virtual void DoFreeze() wxOVERRIDE;
|
||||
virtual void DoThaw() wxOVERRIDE;
|
||||
|
||||
virtual void DoSetSize(int x, int y,
|
||||
int width, int height,
|
||||
int sizeFlags = wxSIZE_AUTO) wxOVERRIDE;
|
||||
|
||||
virtual bool MSWShouldSetDefaultFont() const wxOVERRIDE { return false; }
|
||||
|
||||
// SetImageList helper
|
||||
@ -336,9 +332,6 @@ private:
|
||||
// whether we need to deselect other items on mouse up
|
||||
bool m_mouseUpDeselect;
|
||||
|
||||
// The size to restore the control to when it is thawed, see DoThaw().
|
||||
wxSize m_thawnSize;
|
||||
|
||||
friend class wxTreeItemIndirectData;
|
||||
friend class wxTreeSortHelper;
|
||||
|
||||
|
@ -3898,47 +3898,23 @@ void wxTreeCtrl::DoSetItemState(const wxTreeItemId& item, int state)
|
||||
// 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 resize it to the smallest possible size instead of freezing -- this
|
||||
// still flickers, but actually not as badly as it would if we didn't do it.
|
||||
|
||||
void wxTreeCtrl::DoFreeze()
|
||||
{
|
||||
if ( IsShown() )
|
||||
{
|
||||
RECT rc;
|
||||
::GetWindowRect(GetHwnd(), &rc);
|
||||
m_thawnSize = wxRectFromRECT(rc).GetSize();
|
||||
wxTreeCtrlBase::DoFreeze();
|
||||
|
||||
::SetWindowPos(GetHwnd(), 0, 0, 0, 1, 1,
|
||||
SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE);
|
||||
}
|
||||
// In addition to disabling redrawing, we also need to disable scrollbar
|
||||
// updates that would still happen otherwise.
|
||||
const LONG_PTR styleOld = ::GetWindowLongPtr(GetHwnd(), GWL_STYLE);
|
||||
::SetWindowLongPtr(GetHwnd(), GWL_STYLE, styleOld | TVS_NOSCROLL);
|
||||
}
|
||||
|
||||
void wxTreeCtrl::DoThaw()
|
||||
{
|
||||
if ( IsShown() )
|
||||
{
|
||||
if ( m_thawnSize != wxDefaultSize )
|
||||
{
|
||||
::SetWindowPos(GetHwnd(), 0, 0, 0, m_thawnSize.x, m_thawnSize.y,
|
||||
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Undo temporary TVS_NOSCROLL addition.
|
||||
const LONG_PTR styleOld = ::GetWindowLongPtr(GetHwnd(), GWL_STYLE);
|
||||
::SetWindowLongPtr(GetHwnd(), GWL_STYLE, styleOld & ~TVS_NOSCROLL);
|
||||
|
||||
// We also need to override DoSetSize() to ensure that m_thawnSize is reset if
|
||||
// the window is resized while being frozen -- in this case, we need to avoid
|
||||
// resizing it back to its original, pre-freeze, size when it's thawed.
|
||||
void wxTreeCtrl::DoSetSize(int x, int y, int width, int height, int sizeFlags)
|
||||
{
|
||||
m_thawnSize = wxDefaultSize;
|
||||
|
||||
wxTreeCtrlBase::DoSetSize(x, y, width, height, sizeFlags);
|
||||
wxTreeCtrlBase::DoThaw();
|
||||
}
|
||||
|
||||
#endif // wxUSE_TREECTRL
|
||||
|
Loading…
Reference in New Issue
Block a user