tdf#119745: Use scroll distance from Windows to calculate scroll lines.

Calculate lines scrolled using scroll distance from Windows message instead of fixed value. Use Windows macros for mouse wheel distance and modifier keys (from Microsoft WM_MOUSEWHEEL dev page).

Change-Id: I30ddf1641103a15549f38983c60c35e0d514bb38
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174713
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Marc Mondesir 2024-10-08 16:06:51 -07:00 committed by Mike Kaganski
parent 1b648b3705
commit 274781b308

View file

@ -3363,7 +3363,7 @@ static bool ImplHandleWheelMsg( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lPar
WinSalFrame* pFrame = GetWindowPtr( hWnd );
if ( pFrame )
{
WORD nWinModCode = LOWORD( wParam );
WORD nWinModCode = GET_KEYSTATE_WPARAM( wParam ); // Key modifiers
POINT aWinPt;
aWinPt.x = static_cast<short>(LOWORD( lParam ));
aWinPt.y = static_cast<short>(HIWORD( lParam ));
@ -3374,32 +3374,63 @@ static bool ImplHandleWheelMsg( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lPar
aWheelEvt.mnX = aWinPt.x;
aWheelEvt.mnY = aWinPt.y;
aWheelEvt.mnCode = 0;
aWheelEvt.mnDelta = static_cast<short>(HIWORD( wParam ));
aWheelEvt.mnNotchDelta = aWheelEvt.mnDelta/WHEEL_DELTA;
aWheelEvt.mnDelta = GET_WHEEL_DELTA_WPARAM( wParam ); // Distance scrolled passed in message param
aWheelEvt.mnNotchDelta = aWheelEvt.mnDelta/WHEEL_DELTA; // Number of mouse notches/detents scrolled
if( aWheelEvt.mnNotchDelta == 0 )
{
// Keep mnNotchDelta nonzero unless distance scrolled was exactly zero.
// Many places use its sign to indicate direction scrolled.
if( aWheelEvt.mnDelta > 0 )
aWheelEvt.mnNotchDelta = 1;
else if( aWheelEvt.mnDelta < 0 )
aWheelEvt.mnNotchDelta = -1;
}
if( nMsg == WM_MOUSEWHEEL )
if( nMsg == WM_MOUSEWHEEL ) // Vertical scroll
{
if ( aSalShlData.mnWheelScrollLines == WHEEL_PAGESCROLL )
aWheelEvt.mnScrollLines = SAL_WHEELMOUSE_EVENT_PAGESCROLL;
else
aWheelEvt.mnScrollLines = aSalShlData.mnWheelScrollLines;
if ( aSalShlData.mnWheelScrollLines == WHEEL_PAGESCROLL ) // Mouse wheel set to "One screen at a time"
{
// Note: mnDelta may hit a multiple of WHEEL_DELTA via touchpad scrolling. That's the tradeoff to keep
// smooth touchpad scrolling with mouse wheel set to screen.
if ( (aWheelEvt.mnDelta % WHEEL_DELTA) == 0 ) // Mouse wheel sends WHEEL_DELTA (or multiple of it)
aWheelEvt.mnScrollLines = SAL_WHEELMOUSE_EVENT_PAGESCROLL; // "Magic" page scroll value
else // Touchpad can send smaller values. Use default 3 lines to scroll at a time.
aWheelEvt.mnScrollLines = aWheelEvt.mnDelta / double(WHEEL_DELTA) * 3.0; // Calculate actual lines using distance
}
else // Mouse wheel set to "Multiple lines at a time"
{
// Windows legacy touchpad support sends touchpad scroll gesture as multiple mouse wheel messages.
// Calculate number of mouse notches scrolled using distance from Windows.
aWheelEvt.mnScrollLines = aWheelEvt.mnDelta / double(WHEEL_DELTA);
// Multiply by user setting for number of lines to scroll at a time.
aWheelEvt.mnScrollLines *= aSalShlData.mnWheelScrollLines;
}
aWheelEvt.mbHorz = false;
}
else
else // Horizontal scroll
{
aWheelEvt.mnScrollLines = aSalShlData.mnWheelScrollChars;
// Windows legacy touchpad support sends touchpad scroll gesture as multiple mouse wheel messages.
// Calculate number of mouse notches scrolled using distance from Windows.
aWheelEvt.mnScrollLines = aWheelEvt.mnDelta / double(WHEEL_DELTA);
// Multiply by user setting for number of characters to scroll at a time.
aWheelEvt.mnScrollLines *= aSalShlData.mnWheelScrollChars;
aWheelEvt.mbHorz = true;
// fdo#36380 - seems horiz scrolling has swapped direction
aWheelEvt.mnDelta *= -1;
aWheelEvt.mnNotchDelta *= -1;
aWheelEvt.mnScrollLines *= -1.0;
}
// Do not change magic value for page scrolling
if (aWheelEvt.mnScrollLines != SAL_WHEELMOUSE_EVENT_PAGESCROLL)
{
// Scrolling code multiplies (scroll lines * number of notches), so pull # notches out to prevent double multiply.
if (aWheelEvt.mnNotchDelta != 0) // No divide by zero!
aWheelEvt.mnScrollLines /= aWheelEvt.mnNotchDelta;
else
aWheelEvt.mnScrollLines = abs(aWheelEvt.mnScrollLines); // Just ensure (+) value
}
if ( nWinModCode & MK_SHIFT )