Improve wxListCtrl::MSWGetBestViewRect() fit

It looks like ListView_ApproximateViewRect() doesn't actually take the
borders into account and doesn't even take margins into account
correctly.

With this change, vertical wxListbook in the notebook sample doesn't
show any horizontal scrollbar and has symmetric margins around its
contents (whether it shows a vertical scrollbar or not) under both
Windows 7 and 10.
This commit is contained in:
Vadim Zeitlin
2022-04-28 23:31:32 +01:00
parent ebf5e8813e
commit 25e46d0a4d

View File

@@ -1611,10 +1611,16 @@ wxSize wxListCtrl::MSWGetBestViewRect(int x, int y) const
if ( mswStyle & WS_VSCROLL )
size.x += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X, m_parent);
// OTOH we have to subtract the size of our borders because the base class
// public method already adds them, but ListView_ApproximateViewRect()
// already takes the borders into account, so this would be superfluous.
return size - GetWindowBorderSize();
// This is a dirty hack, but while the size returned by the control does
// fit its contents, it results in asymmetric horizontal margins around it,
// with 3px on one side and just 1px on the other one. Adding these 2px
// makes it looks nicely symmetrical, at least under Windows 7 and 10.
// Vertical margins are even more asymmetric, but they're too big and not
// too small and it might be a bad idea to allocate size smaller than what
// the control thinks it needs, so leave them be.
size.IncBy(2, 0);
return size;
}
// ----------------------------------------------------------------------------