X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dd932cbe1c594a3adceaa521f0cf735b09810f4e..96ad3e4eb49763a433e5919fdd37cf44bbf2d657:/src/generic/vscroll.cpp diff --git a/src/generic/vscroll.cpp b/src/generic/vscroll.cpp index be1b108865..ec48cb9103 100644 --- a/src/generic/vscroll.cpp +++ b/src/generic/vscroll.cpp @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#pragma implementation "vscroll.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -28,6 +24,10 @@ #pragma hdrstop #endif +#ifndef WX_PRECOMP + #include "wx/sizer.h" +#endif + #include "wx/vscroll.h" // ---------------------------------------------------------------------------- @@ -160,8 +160,22 @@ size_t wxVScrolledWindow::FindFirstFromBottom(size_t lineLast, bool full) return lineFirst; } +void wxVScrolledWindow::RemoveScrollbar() +{ + m_lineFirst = 0; + m_nVisible = m_lineMax; + SetScrollbar(wxVERTICAL, 0, 0, 0); +} + 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; @@ -175,6 +189,25 @@ void wxVScrolledWindow::UpdateScrollbar() h += OnGetLineHeight(line); } + // if we still have remaining space below, maybe we can fit everything? + if ( h < hWindow ) + { + wxCoord hAll = h; + for ( size_t lineFirst = m_lineFirst; lineFirst > 0; lineFirst-- ) + { + hAll += OnGetLineHeight(m_lineFirst - 1); + if ( hAll > hWindow ) + break; + } + + if ( hAll < hWindow ) + { + // we don't need scrollbar at all + RemoveScrollbar(); + return; + } + } + m_nVisible = line - m_lineFirst; int pageSize = m_nVisible; @@ -202,9 +235,16 @@ void wxVScrolledWindow::SetLineCount(size_t count) // and our estimate for their total height m_heightTotal = EstimateTotalHeight(); - // recalculate the scrollbars parameters - m_lineFirst = 1; // make sure it is != 0 - ScrollToLine(0); + // 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 ) + { + // but if it didn't do it, we still need to update the scrollbar to + // reflect the changed number of lines ourselves + UpdateScrollbar(); + } } void wxVScrolledWindow::RefreshLine(size_t line) @@ -267,6 +307,27 @@ void wxVScrolledWindow::RefreshAll() Refresh(); } +bool wxVScrolledWindow::Layout() +{ + if ( GetSizer() ) + { + // adjust the sizer dimensions/position taking into account the + // virtual size and scrolled position of the window. + + int w = 0, h = 0; + GetVirtualSize(&w, &h); + + // x is always 0 so no variable needed + int y = -GetLinesHeight(0, GetFirstVisibleLine()); + + GetSizer()->SetDimension(0, y, w, h); + return true; + } + + // fall back to default for LayoutConstraints + return wxPanel::Layout(); +} + int wxVScrolledWindow::HitTest(wxCoord WXUNUSED(x), wxCoord y) const { const size_t lineMax = GetVisibleEnd(); @@ -455,4 +516,5 @@ void wxVScrolledWindow::OnMouseWheel(wxMouseEvent& event) ScrollPages( units_to_scroll ); } -#endif +#endif // wxUSE_MOUSEWHEEL +