X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0c8392cac2d36d0d211432e71d3b24d3d93c22db..902725eefee5a402d21d13b2630583ab28ae3931:/src/generic/vscroll.cpp diff --git a/src/generic/vscroll.cpp b/src/generic/vscroll.cpp index abe374f694..be1b108865 100644 --- a/src/generic/vscroll.cpp +++ b/src/generic/vscroll.cpp @@ -17,7 +17,7 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(__APPLE__) +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "vscroll.h" #endif @@ -37,6 +37,9 @@ BEGIN_EVENT_TABLE(wxVScrolledWindow, wxPanel) EVT_SIZE(wxVScrolledWindow::OnSize) EVT_SCROLLWIN(wxVScrolledWindow::OnScroll) +#if wxUSE_MOUSEWHEEL + EVT_MOUSEWHEEL(wxVScrolledWindow::OnMouseWheel) +#endif END_EVENT_TABLE() @@ -60,6 +63,10 @@ void wxVScrolledWindow::Init() m_nVisible = 1; m_heightTotal = 0; + +#if wxUSE_MOUSEWHEEL + m_sumWheelRotation = 0; +#endif } // ---------------------------------------------------------------------------- @@ -92,7 +99,7 @@ wxCoord wxVScrolledWindow::EstimateTotalHeight() const // use the height of the lines we looked as the average heightTotal = (wxCoord) - (((float)m_heightTotal / (3*NUM_LINES_TO_SAMPLE)) * m_lineMax); + (((float)heightTotal / (3*NUM_LINES_TO_SAMPLE)) * m_lineMax); } return heightTotal; @@ -213,7 +220,7 @@ void wxVScrolledWindow::RefreshLine(size_t line) wxRect rect; rect.width = GetClientSize().x; rect.height = OnGetLineHeight(line); - for ( size_t n = GetFirstVisibleLine(); n < line; n++ ) + for ( size_t n = GetVisibleBegin(); n < line; n++ ) { rect.y += OnGetLineHeight(n); } @@ -228,21 +235,23 @@ void wxVScrolledWindow::RefreshLines(size_t from, size_t to) // clump the range to just the visible lines -- it is useless to refresh // the other ones - if ( from < GetFirstVisibleLine() ) - from = GetFirstVisibleLine(); + if ( from < GetVisibleBegin() ) + from = GetVisibleBegin(); - if ( to > GetLastVisibleLine() ) - to = GetLastVisibleLine(); + if ( to >= GetVisibleEnd() ) + to = GetVisibleEnd(); + else + to++; // calculate the rect occupied by these lines on screen wxRect rect; rect.width = GetClientSize().x; - for ( size_t nBefore = GetFirstVisibleLine(); nBefore < from; nBefore++ ) + for ( size_t nBefore = GetVisibleBegin(); nBefore < from; nBefore++ ) { rect.y += OnGetLineHeight(nBefore); } - for ( size_t nBetween = from; nBetween <= to; nBetween++ ) + for ( size_t nBetween = from; nBetween < to; nBetween++ ) { rect.height += OnGetLineHeight(nBetween); } @@ -260,8 +269,8 @@ void wxVScrolledWindow::RefreshAll() int wxVScrolledWindow::HitTest(wxCoord WXUNUSED(x), wxCoord y) const { - const size_t lineMax = GetLastVisibleLine(); - for ( size_t line = GetFirstVisibleLine(); line <= lineMax; line++ ) + const size_t lineMax = GetVisibleEnd(); + for ( size_t line = GetVisibleBegin(); line < lineMax; line++ ) { y -= OnGetLineHeight(line); if ( y < 0 ) @@ -298,8 +307,8 @@ bool wxVScrolledWindow::ScrollToLine(size_t line) // remember the currently shown lines for the refresh code below - size_t lineFirstOld = GetFirstVisibleLine(), - lineLastOld = GetLastVisibleLine(); + size_t lineFirstOld = GetVisibleBegin(), + lineLastOld = GetVisibleEnd(); m_lineFirst = line; @@ -310,8 +319,8 @@ bool wxVScrolledWindow::ScrollToLine(size_t line) // finally refresh the display -- but only redraw as few lines as possible // to avoid flicker - if ( GetFirstVisibleLine() > lineLastOld || - GetLastVisibleLine() < lineFirstOld ) + if ( GetVisibleBegin() >= lineLastOld || + GetVisibleEnd() <= lineFirstOld ) { // the simplest case: we don't have any old lines left, just redraw // everything @@ -319,7 +328,7 @@ bool wxVScrolledWindow::ScrollToLine(size_t line) } else // overlap between the lines we showed before and should show now { - ScrollWindow(0, GetLinesHeight(GetFirstVisibleLine(), lineFirstOld)); + ScrollWindow(0, GetLinesHeight(GetVisibleBegin(), lineFirstOld)); } return true; @@ -343,12 +352,14 @@ bool wxVScrolledWindow::ScrollPages(int pages) int line; if ( pages > 0 ) { - line = GetLastVisibleLine(); + line = GetVisibleEnd(); + if ( line ) + line--; pages--; } else // pages < 0 { - line = FindFirstFromBottom(GetFirstVisibleLine()); + line = FindFirstFromBottom(GetVisibleBegin()); pages++; } @@ -374,6 +385,7 @@ void wxVScrolledWindow::OnScroll(wxScrollWinEvent& event) size_t lineFirstNew; const wxEventType evtType = event.GetEventType(); + if ( evtType == wxEVT_SCROLLWIN_TOP ) { lineFirstNew = 0; @@ -396,23 +408,23 @@ void wxVScrolledWindow::OnScroll(wxScrollWinEvent& event) } else if ( evtType == wxEVT_SCROLLWIN_PAGEDOWN ) { - lineFirstNew = GetLastVisibleLine(); + lineFirstNew = GetVisibleEnd(); + if ( lineFirstNew ) + lineFirstNew--; } - else // unknown scroll event? + else if ( evtType == wxEVT_SCROLLWIN_THUMBRELEASE ) { - if ( evtType == wxEVT_SCROLLWIN_THUMBRELEASE ) - { - lineFirstNew = event.GetPosition(); - } - else - { - wxASSERT_MSG( evtType == wxEVT_SCROLLWIN_THUMBTRACK, - _T("unknown scroll event type?") ); + lineFirstNew = event.GetPosition(); + } + else if ( evtType == wxEVT_SCROLLWIN_THUMBTRACK ) + { + lineFirstNew = event.GetPosition(); + } - // don't do anything, otherwise dragging the thumb around would - // be too slow - return; - } + else // unknown scroll event? + { + wxFAIL_MSG( _T("unknown scroll event type?") ); + return; } ScrollToLine(lineFirstNew); @@ -422,3 +434,25 @@ void wxVScrolledWindow::OnScroll(wxScrollWinEvent& event) #endif // __WXMAC__ } +#if wxUSE_MOUSEWHEEL + +void wxVScrolledWindow::OnMouseWheel(wxMouseEvent& event) +{ + m_sumWheelRotation += event.GetWheelRotation(); + int delta = event.GetWheelDelta(); + + // how much to scroll this time + int units_to_scroll = -(m_sumWheelRotation/delta); + if ( !units_to_scroll ) + return; + + m_sumWheelRotation += units_to_scroll*delta; + + if ( !event.IsPageScroll() ) + ScrollLines( units_to_scroll*event.GetLinesPerAction() ); + else + // scroll pages instead of lines + ScrollPages( units_to_scroll ); +} + +#endif