From 7d0cf3f9be68172d67ed1e82975ea5f080989a33 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 21 Sep 2011 15:08:10 +0000 Subject: [PATCH] Fix scrolling in small wxVListBox with tall items. Scrolling in a small wxVListBox with tall items (i.e. taller than the height of wxVListBox itself) behaved wrongly: wrong item was being scrolled into view and Page Up/Down didn't scroll as much as they should. Fix both of these problems by checking for these corner cases explicitly. Closes #13454. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69180 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/vlbox.cpp | 3 +++ src/generic/vscroll.cpp | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/generic/vlbox.cpp b/src/generic/vlbox.cpp index aa68ea1712..a4be49817c 100644 --- a/src/generic/vlbox.cpp +++ b/src/generic/vlbox.cpp @@ -249,7 +249,10 @@ bool wxVListBox::DoSetCurrent(int current) { // it is, indeed, only partly visible, so scroll it into view to // make it entirely visible + // BUT scrolling down when m_current is first visible makes it + // completely hidden, so that is even worse while ( (size_t)m_current + 1 == GetVisibleRowsEnd() && + (size_t)m_current != GetVisibleRowsBegin() && ScrollToRow(GetVisibleBegin() + 1) ) ; // but in any case refresh it as even if it was only partly visible diff --git a/src/generic/vscroll.cpp b/src/generic/vscroll.cpp index c1b5a4071a..0572b8e07b 100644 --- a/src/generic/vscroll.cpp +++ b/src/generic/vscroll.cpp @@ -31,6 +31,8 @@ #include "wx/vscroll.h" +#include "wx/utils.h" // For wxMin/wxMax(). + // ============================================================================ // wxVarScrollHelperEvtHandler declaration // ============================================================================ @@ -308,14 +310,17 @@ size_t wxVarScrollHelperBase::GetNewScrollPosition(wxScrollWinEvent& event) cons } else if ( evtType == wxEVT_SCROLLWIN_PAGEUP ) { - return FindFirstVisibleFromLast(m_unitFirst); + // Page up should do at least as much as line up. + return wxMin(FindFirstVisibleFromLast(m_unitFirst), + m_unitFirst ? m_unitFirst - 1 : 0); } else if ( evtType == wxEVT_SCROLLWIN_PAGEDOWN ) { + // And page down should do at least as much as line down. if ( GetVisibleEnd() ) - return GetVisibleEnd() - 1; + return wxMax(GetVisibleEnd() - 1, m_unitFirst + 1); else - return GetVisibleEnd(); + return wxMax(GetVisibleEnd(), m_unitFirst + 1); } else if ( evtType == wxEVT_SCROLLWIN_THUMBRELEASE ) { -- 2.45.2