Improve best height of horizontally laid out wxListCtrl in wxMSW

It seems that ListView_ApproximateViewRect() always reserves space for
the horizontal scrollbar vertically, even when it isn't needed,
resulting in a lot of blank space remaining in horizontal wxListbook
(e.g. using "top" orientation) in the notebook sample.

So instead of adding extra space when the scrollbar is shown, remove it
when it is not shown.
This commit is contained in:
Vadim Zeitlin
2022-04-28 23:42:11 +01:00
parent 25e46d0a4d
commit e0f7dca2b8

View File

@@ -1601,13 +1601,16 @@ wxSize wxListCtrl::MSWGetBestViewRect(int x, int y) const
wxSize size(LOWORD(rc), HIWORD(rc));
// We have to add space for the scrollbars ourselves, they're not taken
// into account by ListView_ApproximateViewRect(), at least not with
// commctrl32.dll v6.
// We have to account for the scrollbars ourselves, as the control itself
// seems to always reserve space for the horizontal scrollbar, even when it
// is not needed, but does not reserve space for the vertical scrollbar,
// even when it is used. This doesn't make any sense, but using this logic
// results in correct result, i.e. just enough space, in all cases.
const DWORD mswStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE);
if ( mswStyle & WS_HSCROLL )
size.y += wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y, m_parent);
if ( !(mswStyle & WS_HSCROLL) )
size.y -= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y, m_parent);
if ( mswStyle & WS_VSCROLL )
size.x += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X, m_parent);