X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ac55e0a1a8c344626a94bc055e018630ed77b004..6b4f099df5e71af0449049ce0a19e7863915ee44:/src/generic/vscroll.cpp diff --git a/src/generic/vscroll.cpp b/src/generic/vscroll.cpp index a7d388a9bf..ec48cb9103 100644 --- a/src/generic/vscroll.cpp +++ b/src/generic/vscroll.cpp @@ -169,6 +169,13 @@ void wxVScrolledWindow::RemoveScrollbar() void wxVScrolledWindow::UpdateScrollbar() { + // if there is nothing to scroll, remove the scrollbar + if ( !m_lineMax ) + { + RemoveScrollbar(); + return; + } + // see how many lines can we fit on screen const wxCoord hWindow = GetClientSize().y; @@ -228,15 +235,15 @@ void wxVScrolledWindow::SetLineCount(size_t count) // and our estimate for their total height m_heightTotal = EstimateTotalHeight(); - // recalculate the scrollbars parameters - if ( count ) - { - m_lineFirst = 1; // make sure it is != 0 - ScrollToLine(0); - } - else // no items + // ScrollToLine() will update the scrollbar itself if it changes the line + // we pass to it because it's out of [new] range + size_t oldScrollPos = m_lineFirst; + ScrollToLine(m_lineFirst); + if ( oldScrollPos == m_lineFirst ) { - RemoveScrollbar(); + // but if it didn't do it, we still need to update the scrollbar to + // reflect the changed number of lines ourselves + UpdateScrollbar(); } }