WI01087563 - Fix ToopStrip issue#39
Open
jaywang-cn wants to merge 2 commits into
Open
Conversation
While it lacks the fix commits: dotnet@9341877 dotnet@e0bbecd Cherry-pick the commits instead of sync the fork to avoid unknown issues.
…nto JWA/WI01087563
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root Cause
In the affected .NET 10 WinForms implementation,
ToolStrip.WndProccontains the following behavior forWM_SETFOCUS:This registers the ToolStrip as the active ToolStrip and enters modal menu tracking.
When
Application.DoEvents()retrieves a posted CodeBox key message, WinForms calls the thread-level message filters before control preprocessing and dispatch.ToolStripManager.ModalMenuFilter.PreFilterMessagecontains this logic:Because the real focus is now on the CodeBox,
activeToolStrip.ContainsFocusis false. The filter changes the message HWND to the ToolStrip HWND.ModalMenuFilterimplementsIMessageModifyAndFilter. Therefore, even thoughPreFilterMessagereturnsfalse,Application.ThreadContext.ProcessFilterscopies the modified HWND back into the native message.Why .NET 8 Is Not Affected
The WiseTech
net8.0_legacybranch and upstreamrelease/8.0only callSnapFocuswhen a ToolStrip receivesWM_SETFOCUS:The problematic behavior was introduced by upstream commit:
6e112b86c1That commit is part of the current .NET 10 baseline but is not part of the .NET 8 legacy baseline.
Consequently, under .NET 8, the basher can focus the internal ToolStrip without registering it as the active modal-menu ToolStrip. Subsequent CodeBox keys continue to target the CodeBox.
Fix
The correct fix is to backport the following upstream WinForms commits in order.
1. Restrict and clear ordinary ToolStrip menu tracking
934187737This change:
ModalMenuFilterfor an ordinary ToolStrip only when focus transfers from another ToolStrip or one of its child controls.WM_KILLFOCUSand removes the active ToolStrip when focus moves outside the ToolStrip context.This commit directly addresses the
WarehouseEntryFormfailure.2. Preserve tracking for real ToolStripDropDown scenarios
e0bbecdc9The first fix correctly handles ordinary ToolStrips but can be too restrictive for
ToolStripDropDowncontrols used by dropdowns and designer SmartTag panels.This follow-up change:
ToolStripDropDowncontrols participating in modal menu tracking when they receive focus.Both commits should be applied together and in this order.