Reactos

[SHELL32] Fix focus glitch when hovering separators with submenu open (#7932)

CORE-20124

Since `TB_HITTEST` returns negative numbers for ID for separator menu items [^1],
shell menu assumes mouse moved outside of the menu popup, highlighting the menu
item for currently open submenu.
To fix this behavior, we can detect separators in `CMenuFocusManager::ProcessMouseMove`
and negate the ID returned by `TB_HITTEST` to make it a positive number again,
so the shell menu wouldn't glitch.

[^1]: https://learn.microsoft.com/en-us/windows/win32/controls/tb-hittest

authored by

Mohammad Amin Mollazadeh and committed by
GitHub
cc167691 3e342246

+17
+17
dll/win32/shell32/shellmenu/CMenuFocusManager.cpp
··· 348 348 iHitTestResult = SendMessageW(child, TB_HITTEST, 0, (LPARAM) &pt); 349 349 isTracking = entry->mb->_IsTracking(); 350 350 351 + if (iHitTestResult < -1) 352 + { 353 + // TB_HITTEST would return negative numbers for separators 354 + iHitTestResult = -iHitTestResult; 355 + } 356 + else if (iHitTestResult == -1) 357 + { 358 + // TB_HITTEST would return -1 in two cases: 359 + // 1. the mouse is outside the toolbar; 360 + // 2. the mouse is over the first item, and that item is a separator. 361 + // Confirm the second scenario by checking first item's rect. 362 + RECT rc; 363 + SendMessageW(child, TB_GETITEMRECT, 1, (LPARAM)&rc); 364 + if (PtInRect(&rc, pt)) 365 + iHitTestResult = 1; 366 + } 367 + 351 368 if (SendMessage(child, WM_USER_ISTRACKEDITEM, iHitTestResult, 0) == S_FALSE) 352 369 { 353 370 // The current tracked item has changed, notify the toolbar