From e0f7dca2b80f505a105e050136fb674166b05f58 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 28 Apr 2022 23:42:11 +0100 Subject: [PATCH] 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. --- src/msw/listctrl.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 8e2dc51f8d..6ee2948e00 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -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);