X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9a83f860948059b0273b5cc6d9e43fadad3ebfca..bcfe86f0b5aae2ea3cd6c5e9a202d19bdbb21b25:/src/generic/vscroll.cpp diff --git a/src/generic/vscroll.cpp b/src/generic/vscroll.cpp index a98c29da79..589451775c 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 // ============================================================================ @@ -97,10 +99,6 @@ bool wxVarScrollHelperEvtHandler::ProcessEvent(wxEvent& event) if ( wasSkipped ) event.Skip(false); - // reset the skipped flag to false as it might have been set to true in - // ProcessEvent() above - event.Skip(false); - if ( evType == wxEVT_SCROLLWIN_TOP || evType == wxEVT_SCROLLWIN_BOTTOM || evType == wxEVT_SCROLLWIN_LINEUP || @@ -127,8 +125,7 @@ bool wxVarScrollHelperEvtHandler::ProcessEvent(wxEvent& event) } #endif // wxUSE_MOUSEWHEEL - if ( processed ) - event.Skip(wasSkipped); + event.Skip(wasSkipped); return processed; } @@ -313,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 ) { @@ -487,10 +487,10 @@ void wxVarScrollHelperBase::RefreshUnits(size_t from, size_t to) to = GetVisibleEnd(); // calculate the rect occupied by these units on screen - int orient_size, nonorient_size, orient_pos; - orient_size = nonorient_size = orient_pos = 0; + int orient_size = 0, + orient_pos = 0; - nonorient_size = GetNonOrientationTargetSize(); + int nonorient_size = GetNonOrientationTargetSize(); for ( size_t nBefore = GetVisibleBegin(); nBefore < from; @@ -674,6 +674,39 @@ bool wxVarScrollHelperBase::DoScrollPages(int pages) void wxVarScrollHelperBase::HandleOnSize(wxSizeEvent& event) { + if ( m_unitMax ) + { + // sometimes change in varscrollable window's size can result in + // unused empty space after the last item. Fix it by decrementing + // first visible item position according to the available space. + + // determine free space + const wxCoord sWindow = GetOrientationTargetSize(); + wxCoord s = 0; + size_t unit; + for ( unit = m_unitFirst; unit < m_unitMax; ++unit ) + { + if ( s > sWindow ) + break; + + s += OnGetUnitSize(unit); + } + wxCoord freeSpace = sWindow - s; + + // decrement first visible item index as long as there is free space + size_t idealUnitFirst; + for ( idealUnitFirst = m_unitFirst; + idealUnitFirst > 0; + idealUnitFirst-- ) + { + wxCoord us = OnGetUnitSize(idealUnitFirst-1); + if ( freeSpace < us ) + break; + freeSpace -= us; + } + m_unitFirst = idealUnitFirst; + } + UpdateScrollbar(); event.Skip(); @@ -794,7 +827,7 @@ void wxVarHVScrollHelper::RefreshRowColumn(size_t row, size_t column) h_rect.x += OnGetColumnWidth(n); } - // refresh but specialize the behavior if we have a single target window + // refresh but specialize the behaviour if we have a single target window if ( wxVarVScrollHelper::GetTargetWindow() == wxVarHScrollHelper::GetTargetWindow() ) { v_rect.x = h_rect.x; @@ -861,7 +894,7 @@ void wxVarHVScrollHelper::RefreshRowsColumns(size_t fromRow, size_t toRow, h_rect.width += OnGetColumnWidth(nBetween); } - // refresh but specialize the behavior if we have a single target window + // refresh but specialize the behaviour if we have a single target window if ( wxVarVScrollHelper::GetTargetWindow() == wxVarHScrollHelper::GetTargetWindow() ) { v_rect.x = h_rect.x; @@ -936,7 +969,7 @@ IMPLEMENT_ABSTRACT_CLASS(wxHVScrolledWindow, wxPanel) // wxVarVScrollLegacyAdaptor // =========================================================================== -size_t wxVarVScrollLegacyAdaptor::GetFirstVisibleLine() const +size_t wxVarVScrollLegacyAdaptor::GetFirstVisibleLine() const { return GetVisibleRowsBegin(); } size_t wxVarVScrollLegacyAdaptor::GetLastVisibleLine() const @@ -953,13 +986,13 @@ void wxVarVScrollLegacyAdaptor::RefreshLine(size_t line) void wxVarVScrollLegacyAdaptor::RefreshLines(size_t from, size_t to) { RefreshRows(from, to); } - + bool wxVarVScrollLegacyAdaptor::ScrollToLine(size_t line) { return ScrollToRow(line); } bool wxVarVScrollLegacyAdaptor::ScrollLines(int lines) { return ScrollRows(lines); } - + bool wxVarVScrollLegacyAdaptor::ScrollPages(int pages) { return ScrollRowPages(pages); }