From 0b49ccf8d66e2568e2b0de85c25b406aad39f3b1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 3 Jun 2003 11:15:38 +0000 Subject: [PATCH] pressing PageDown and then PageUp should return to the same item git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20885 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/vscroll.h | 4 ++-- src/generic/vscroll.cpp | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/wx/vscroll.h b/include/wx/vscroll.h index 73d3815d13..8ba386cc2f 100644 --- a/include/wx/vscroll.h +++ b/include/wx/vscroll.h @@ -146,8 +146,8 @@ protected: void OnScroll(wxScrollWinEvent& event); // find the index of the line we need to show at the top of the window such - // that the last line shown is the given one - size_t FindFirstFromBottom(size_t lineLast); + // that the last (fully or partially) visible line is the given one + size_t FindFirstFromBottom(size_t lineLast, bool fullyVisible = false); // get the total height of the lines between lineMin (inclusive) and // lineMax (exclusive) diff --git a/src/generic/vscroll.cpp b/src/generic/vscroll.cpp index 5d2ccf0cb6..4a9cc64d7c 100644 --- a/src/generic/vscroll.cpp +++ b/src/generic/vscroll.cpp @@ -74,7 +74,7 @@ wxCoord wxVScrolledWindow::GetLinesHeight(size_t lineMin, size_t lineMax) const return height; } -size_t wxVScrolledWindow::FindFirstFromBottom(size_t lineLast) +size_t wxVScrolledWindow::FindFirstFromBottom(size_t lineLast, bool full) { const wxCoord hWindow = GetClientSize().y; @@ -88,7 +88,13 @@ size_t wxVScrolledWindow::FindFirstFromBottom(size_t lineLast) if ( h > hWindow ) { - lineFirst++; + // for this line to be fully visible we need to go one line + // down, but if it is enough for it to be only partly visible then + // this line will do as well + if ( full ) + { + lineFirst++; + } break; } @@ -230,7 +236,7 @@ bool wxVScrolledWindow::ScrollToLine(size_t line) // determine the real first line to scroll to: we shouldn't scroll beyond // the end - size_t lineFirstLast = FindFirstFromBottom(m_lineMax - 1); + size_t lineFirstLast = FindFirstFromBottom(m_lineMax - 1, true); if ( line > lineFirstLast ) line = lineFirstLast; -- 2.45.2