X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f18eaf2687ab42c97ccf469a2617306cadc0c6ef..bf2c43c76e2819be443ab1d830ab68d9569d66b1:/src/generic/vscroll.cpp diff --git a/src/generic/vscroll.cpp b/src/generic/vscroll.cpp index a670b41955..3a66aa34b5 100644 --- a/src/generic/vscroll.cpp +++ b/src/generic/vscroll.cpp @@ -2,9 +2,8 @@ // Name: src/generic/vscroll.cpp // Purpose: wxVScrolledWindow implementation // Author: Vadim Zeitlin -// Modified by: Brad Anderson +// Modified by: Brad Anderson, David Warkentin // Created: 30.05.03 -// RCS-ID: $Id$ // Copyright: (c) 2003 Vadim Zeitlin // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -25,11 +24,14 @@ #endif #ifndef WX_PRECOMP + #include "wx/dc.h" #include "wx/sizer.h" #endif #include "wx/vscroll.h" +#include "wx/utils.h" // For wxMin/wxMax(). + // ============================================================================ // wxVarScrollHelperEvtHandler declaration // ============================================================================ @@ -52,7 +54,7 @@ public: private: wxVarScrollHelperBase *m_scrollHelper; - DECLARE_NO_COPY_CLASS(wxVarScrollHelperEvtHandler) + wxDECLARE_NO_COPY_CLASS(wxVarScrollHelperEvtHandler); }; // ============================================================================ @@ -96,10 +98,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 || @@ -126,8 +124,7 @@ bool wxVarScrollHelperEvtHandler::ProcessEvent(wxEvent& event) } #endif // wxUSE_MOUSEWHEEL - if ( processed ) - event.Skip(wasSkipped); + event.Skip(wasSkipped); return processed; } @@ -143,7 +140,7 @@ bool wxVarScrollHelperEvtHandler::ProcessEvent(wxEvent& event) wxVarScrollHelperBase::wxVarScrollHelperBase(wxWindow *win) { - wxASSERT_MSG( win, _T("associated window can't be NULL in wxVarScrollHelperBase") ); + wxASSERT_MSG( win, wxT("associated window can't be NULL in wxVarScrollHelperBase") ); #if wxUSE_MOUSEWHEEL m_sumWheelRotation = 0; @@ -154,8 +151,9 @@ wxVarScrollHelperBase::wxVarScrollHelperBase(wxWindow *win) m_unitFirst = 0; m_win = - m_targetWindow = (wxWindow *)NULL; + m_targetWindow = NULL; + m_physicalScrolling = true; m_handler = NULL; m_win = win; @@ -311,14 +309,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 ) { @@ -330,7 +331,7 @@ size_t wxVarScrollHelperBase::GetNewScrollPosition(wxScrollWinEvent& event) cons } // unknown scroll event? - wxFAIL_MSG( _T("unknown scroll event type?") ); + wxFAIL_MSG( wxT("unknown scroll event type?") ); return 0; } @@ -474,7 +475,7 @@ void wxVarScrollHelperBase::RefreshUnit(size_t unit) void wxVarScrollHelperBase::RefreshUnits(size_t from, size_t to) { - wxASSERT_MSG( from <= to, _T("RefreshUnits(): empty range") ); + wxASSERT_MSG( from <= to, wxT("RefreshUnits(): empty range") ); // clump the range to just the visible units -- it is useless to refresh // the other ones @@ -485,10 +486,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; @@ -538,7 +539,7 @@ bool wxVarScrollHelperBase::ScrollLayout() return m_targetWindow->wxWindow::Layout(); } -int wxVarScrollHelperBase::HitTest(wxCoord coord) const +int wxVarScrollHelperBase::VirtualHitTest(wxCoord coord) const { const size_t unitMax = GetVisibleEnd(); for ( size_t unit = GetVisibleBegin(); unit < unitMax; ++unit ) @@ -591,7 +592,7 @@ bool wxVarScrollHelperBase::DoScrollToUnit(size_t unit) // to avoid flicker. We can't do this if we have children because they // won't be scrolled if ( m_targetWindow->GetChildren().empty() && - GetVisibleBegin() >= unitLastOld || GetVisibleEnd() <= unitFirstOld ) + (GetVisibleBegin() >= unitLastOld || GetVisibleEnd() <= unitFirstOld) ) { // the simplest case: we don't have any old units left, just redraw // everything @@ -599,7 +600,12 @@ bool wxVarScrollHelperBase::DoScrollToUnit(size_t unit) } else // scroll the window { + // Avoid scrolling visible parts of the screen on Mac +#ifdef __WXMAC__ + if (m_physicalScrolling && m_targetWindow->IsShownOnScreen()) +#else if ( m_physicalScrolling ) +#endif { wxCoord dx = 0, dy = GetUnitsSize(GetVisibleBegin(), unitFirstOld); @@ -667,6 +673,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(); @@ -787,7 +826,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; @@ -810,7 +849,7 @@ void wxVarHVScrollHelper::RefreshRowsColumns(size_t fromRow, size_t toRow, size_t fromColumn, size_t toColumn) { wxASSERT_MSG( fromRow <= toRow || fromColumn <= toColumn, - _T("RefreshRowsColumns(): empty range") ); + wxT("RefreshRowsColumns(): empty range") ); // clump the range to just the visible units -- it is useless to refresh // the other ones @@ -854,7 +893,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; @@ -873,10 +912,10 @@ void wxVarHVScrollHelper::RefreshRowsColumns(size_t fromRow, size_t toRow, } } -wxPosition wxVarHVScrollHelper::HitTest(wxCoord x, wxCoord y) const +wxPosition wxVarHVScrollHelper::VirtualHitTest(wxCoord x, wxCoord y) const { - return wxPosition(wxVarVScrollHelper::HitTest(y), - wxVarHScrollHelper::HitTest(x)); + return wxPosition(wxVarVScrollHelper::VirtualHitTest(y), + wxVarHScrollHelper::VirtualHitTest(x)); } void wxVarHVScrollHelper::DoPrepareDC(wxDC& dc) @@ -922,3 +961,60 @@ IMPLEMENT_ABSTRACT_CLASS(wxVScrolledWindow, wxPanel) IMPLEMENT_ABSTRACT_CLASS(wxHScrolledWindow, wxPanel) IMPLEMENT_ABSTRACT_CLASS(wxHVScrolledWindow, wxPanel) + +#if WXWIN_COMPATIBILITY_2_8 + +// =========================================================================== +// wxVarVScrollLegacyAdaptor +// =========================================================================== + +size_t wxVarVScrollLegacyAdaptor::GetFirstVisibleLine() const +{ return GetVisibleRowsBegin(); } + +size_t wxVarVScrollLegacyAdaptor::GetLastVisibleLine() const +{ return GetVisibleRowsEnd() - 1; } + +size_t wxVarVScrollLegacyAdaptor::GetLineCount() const +{ return GetRowCount(); } + +void wxVarVScrollLegacyAdaptor::SetLineCount(size_t count) +{ SetRowCount(count); } + +void wxVarVScrollLegacyAdaptor::RefreshLine(size_t line) +{ RefreshRow(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); } + +wxCoord wxVarVScrollLegacyAdaptor::OnGetLineHeight(size_t WXUNUSED(n)) const +{ + wxFAIL_MSG( wxT("OnGetLineHeight() must be overridden if OnGetRowHeight() isn't!") ); + return -1; +} + +void wxVarVScrollLegacyAdaptor::OnGetLinesHint(size_t WXUNUSED(lineMin), + size_t WXUNUSED(lineMax)) const +{ +} + +wxCoord wxVarVScrollLegacyAdaptor::OnGetRowHeight(size_t n) const +{ + return OnGetLineHeight(n); +} + +void wxVarVScrollLegacyAdaptor::OnGetRowsHeightHint(size_t rowMin, + size_t rowMax) const +{ + OnGetLinesHint(rowMin, rowMax); +} + +#endif // WXWIN_COMPATIBILITY_2_8