macOS expose scroll invertion in event

applied patch from #18358, thanks for the patch Andy
This commit is contained in:
Stefan Csomor
2019-03-12 12:22:41 +01:00
parent 593257ea05
commit f163578c94
5 changed files with 28 additions and 3 deletions

View File

@@ -1801,6 +1801,10 @@ public:
// should occur for each delta. // should occur for each delta.
int GetWheelDelta() const { return m_wheelDelta; } 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 // Gets the axis the wheel operation concerns; wxMOUSE_WHEEL_VERTICAL
// (most common case) or wxMOUSE_WHEEL_HORIZONTAL (for horizontal scrolling // (most common case) or wxMOUSE_WHEEL_HORIZONTAL (for horizontal scrolling
// using e.g. a trackpad). // using e.g. a trackpad).
@@ -1834,6 +1838,7 @@ public:
wxMouseWheelAxis m_wheelAxis; wxMouseWheelAxis m_wheelAxis;
int m_wheelRotation; int m_wheelRotation;
int m_wheelDelta; int m_wheelDelta;
bool m_wheelInverted;
int m_linesPerAction; int m_linesPerAction;
int m_columnsPerAction; int m_columnsPerAction;
float m_magnification; float m_magnification;

View File

@@ -2795,6 +2795,22 @@ public:
*/ */
int GetWheelDelta() const; 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. Get wheel rotation, positive or negative indicates direction of rotation.

View File

@@ -708,9 +708,10 @@ void MyCanvas::OnMouseWheel( wxMouseEvent &event )
int x,y; int x,y;
CalcUnscrolledPosition( pt.x, pt.y, &x, &y ); CalcUnscrolledPosition( pt.x, pt.y, &x, &y );
wxLogMessage( "Mouse wheel event at: %d %d, scrolled: %d %d\n" 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, pt.x, pt.y, x, y,
event.GetWheelRotation(), event.GetWheelDelta() ); event.GetWheelRotation(), event.GetWheelDelta(),
event.IsWheelInverted() );
event.Skip(); event.Skip();
} }

View File

@@ -577,6 +577,7 @@ wxMouseEvent::wxMouseEvent(wxEventType commandType)
m_wheelAxis = wxMOUSE_WHEEL_VERTICAL; m_wheelAxis = wxMOUSE_WHEEL_VERTICAL;
m_wheelRotation = 0; m_wheelRotation = 0;
m_wheelDelta = 0; m_wheelDelta = 0;
m_wheelInverted = false;
m_linesPerAction = 0; m_linesPerAction = 0;
m_columnsPerAction = 0; m_columnsPerAction = 0;
m_magnification = 0.0f; m_magnification = 0.0f;
@@ -601,6 +602,7 @@ void wxMouseEvent::Assign(const wxMouseEvent& event)
m_wheelRotation = event.m_wheelRotation; m_wheelRotation = event.m_wheelRotation;
m_wheelDelta = event.m_wheelDelta; m_wheelDelta = event.m_wheelDelta;
m_wheelInverted = event.m_wheelInverted;
m_linesPerAction = event.m_linesPerAction; m_linesPerAction = event.m_linesPerAction;
m_columnsPerAction = event.m_columnsPerAction; m_columnsPerAction = event.m_columnsPerAction;
m_wheelAxis = event.m_wheelAxis; m_wheelAxis = event.m_wheelAxis;

View File

@@ -719,6 +719,7 @@ void wxWidgetCocoaImpl::SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEve
} }
wxevent.m_wheelDelta = 10; wxevent.m_wheelDelta = 10;
wxevent.m_wheelInverted = [nsEvent isDirectionInvertedFromDevice];
wxevent.m_linesPerAction = 1; wxevent.m_linesPerAction = 1;
wxevent.m_columnsPerAction = 1; wxevent.m_columnsPerAction = 1;