diff --git a/include/wx/event.h b/include/wx/event.h index 8b26fe820e..de8e772d35 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -1801,6 +1801,10 @@ public: // should occur for each delta. int GetWheelDelta() const { return m_wheelDelta; } + // On Mac, has the user selected "Natural" scrolling in their System + // Preferences? Currently false on all other OS's. + bool IsWheelInverted() const { return m_wheelInverted; } + // Gets the axis the wheel operation concerns; wxMOUSE_WHEEL_VERTICAL // (most common case) or wxMOUSE_WHEEL_HORIZONTAL (for horizontal scrolling // using e.g. a trackpad). @@ -1834,6 +1838,7 @@ public: wxMouseWheelAxis m_wheelAxis; int m_wheelRotation; int m_wheelDelta; + bool m_wheelInverted; int m_linesPerAction; int m_columnsPerAction; float m_magnification; diff --git a/interface/wx/event.h b/interface/wx/event.h index f0134f5d36..dfd7e1b626 100644 --- a/interface/wx/event.h +++ b/interface/wx/event.h @@ -2795,6 +2795,22 @@ public: */ int GetWheelDelta() const; + /** + On Mac, has the user selected "Natural" scrolling in their System + Preferences? Currently false on all other OS's. + + "Natural" scrolling means that content scrolling happens in the + opposite direction, and if you are indeed scrolling content then + you don't need to use this function because macOS has already + inverted the scroll direction. + But there can be special situations where you want the mouse wheel + action to work always in the same direction and in that case you + will need this function. + + @since 3.1.3 + */ + bool IsWheelInverted() const; + /** Get wheel rotation, positive or negative indicates direction of rotation. diff --git a/samples/scroll/scroll.cpp b/samples/scroll/scroll.cpp index fcea79627f..f368805286 100644 --- a/samples/scroll/scroll.cpp +++ b/samples/scroll/scroll.cpp @@ -708,9 +708,10 @@ void MyCanvas::OnMouseWheel( wxMouseEvent &event ) int x,y; CalcUnscrolledPosition( pt.x, pt.y, &x, &y ); wxLogMessage( "Mouse wheel event at: %d %d, scrolled: %d %d\n" - "Rotation: %d, delta = %d", + "Rotation: %d, delta: %d, inverted: %d", pt.x, pt.y, x, y, - event.GetWheelRotation(), event.GetWheelDelta() ); + event.GetWheelRotation(), event.GetWheelDelta(), + event.IsWheelInverted() ); event.Skip(); } diff --git a/src/common/event.cpp b/src/common/event.cpp index 7c34d5239f..52b7d90819 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -577,6 +577,7 @@ wxMouseEvent::wxMouseEvent(wxEventType commandType) m_wheelAxis = wxMOUSE_WHEEL_VERTICAL; m_wheelRotation = 0; m_wheelDelta = 0; + m_wheelInverted = false; m_linesPerAction = 0; m_columnsPerAction = 0; m_magnification = 0.0f; @@ -601,6 +602,7 @@ void wxMouseEvent::Assign(const wxMouseEvent& event) m_wheelRotation = event.m_wheelRotation; m_wheelDelta = event.m_wheelDelta; + m_wheelInverted = event.m_wheelInverted; m_linesPerAction = event.m_linesPerAction; m_columnsPerAction = event.m_columnsPerAction; m_wheelAxis = event.m_wheelAxis; diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 4b356e720b..fa157a9442 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -719,9 +719,10 @@ void wxWidgetCocoaImpl::SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEve } wxevent.m_wheelDelta = 10; + wxevent.m_wheelInverted = [nsEvent isDirectionInvertedFromDevice]; wxevent.m_linesPerAction = 1; wxevent.m_columnsPerAction = 1; - + if ( fabs(deltaX) > fabs(deltaY) ) { // wx conventions for horizontal are inverted from vertical (originating from native msw behavior)