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 ); }
bool wxScrollBar::PerformAction(const wxControlAction& action, long numArg, const wxString& strArg) { int thumbOld = m_thumbPos; bool notify = false; // send an event about the change? wxEventType scrollType; // test for thumb move first as these events happen in quick succession if ( action == wxACTION_SCROLL_THUMB_MOVE ) { DoSetThumb(numArg); // VS: we have to force redraw here, otherwise the thumb will lack // behind mouse cursor UpdateThumb(); scrollType = wxEVT_SCROLLWIN_THUMBTRACK; } else if ( action == wxACTION_SCROLL_LINE_UP ) { scrollType = wxEVT_SCROLLWIN_LINEUP; ScrollLines(-1); } else if ( action == wxACTION_SCROLL_LINE_DOWN ) { scrollType = wxEVT_SCROLLWIN_LINEDOWN; ScrollLines(1); } else if ( action == wxACTION_SCROLL_PAGE_UP ) { scrollType = wxEVT_SCROLLWIN_PAGEUP; ScrollPages(-1); } else if ( action == wxACTION_SCROLL_PAGE_DOWN ) { scrollType = wxEVT_SCROLLWIN_PAGEDOWN; ScrollPages(1); } else if ( action == wxACTION_SCROLL_START ) { scrollType = wxEVT_SCROLLWIN_THUMBRELEASE; // anything better? ScrollToStart(); } else if ( action == wxACTION_SCROLL_END ) { scrollType = wxEVT_SCROLLWIN_THUMBRELEASE; // anything better? ScrollToEnd(); } else if ( action == wxACTION_SCROLL_THUMB_DRAG ) { // we won't use it but this line suppresses the compiler // warning about "variable may be used without having been // initialized" scrollType = wxEVT_NULL; } else if ( action == wxACTION_SCROLL_THUMB_RELEASE ) { // always notify about this notify = true; scrollType = wxEVT_SCROLLWIN_THUMBRELEASE; } else return wxControl::PerformAction(action, numArg, strArg); // has scrollbar position changed? bool changed = m_thumbPos != thumbOld; if ( notify || changed ) { if ( IsStandalone() ) { // we should generate EVT_SCROLL events for the standalone // scrollbars and not the EVT_SCROLLWIN ones // // NB: we assume that scrollbar events are sequentially numbered // but this should be ok as other code relies on this as well scrollType += wxEVT_SCROLL_TOP - wxEVT_SCROLLWIN_TOP; wxScrollEvent event(scrollType, this->GetId(), m_thumbPos, IsVertical() ? wxVERTICAL : wxHORIZONTAL); event.SetEventObject(this); GetEventHandler()->ProcessEvent(event); } else // part of the window { wxScrollWinEvent event(scrollType, m_thumbPos, IsVertical() ? wxVERTICAL : wxHORIZONTAL); event.SetEventObject(this); GetParent()->GetEventHandler()->ProcessEvent(event); } } return true; }