Skip to content

Restore legacy menu message parity#21

Open
Rick-Xu-WTG wants to merge 6 commits into
masterfrom
squad/wm-menu-select-root-fix
Open

Restore legacy menu message parity#21
Rick-Xu-WTG wants to merge 6 commits into
masterfrom
squad/wm-menu-select-root-fix

Conversation

@Rick-Xu-WTG
Copy link
Copy Markdown

@Rick-Xu-WTG Rick-Xu-WTG commented Jun 1, 2026

Summary

  • Restore WM_MENUSELECT routing in the new WinForms tree so legacy MenuItem.Select behavior is preserved for both command and popup items.
  • Restore WM_INITMENUPOPUP routing so submenu Popup handlers fire and dynamic menu items can be populated.
  • Add LazyMenuPopulationRegressionTests proving the full end-to-end message path for both the Grid Colors (Select-based) and Universal Copy (Popup-based) lazy-loading patterns.
  • Keep the regression coverage in the new unit test tree under src/test/unit/System.Windows.Forms/System/Windows/Forms/Controls/Unsupported/ContextMenu/.

Rationale

  • The legacy CargoWise WinForms repo already routed these menu messages correctly; the new tree needed parity, not an app-level workaround.
  • App-layer workarounds (Select→Popup) in GridColourSchemeManager and UniversalCopyManager are not needed once this framework fix is in place.

Validation

  • dotnet build src\test\unit\System.Windows.Forms\System.Windows.Forms.Tests.csproj --no-restore
  • LazyMenuPopulationRegressionTests committed and covers: Grid Colors WM_MENUSELECT path, Universal Copy WM_INITMENUPOPUP path, idempotency (no duplicate items on repeat hover).
  • Local NuGet cache updated and verified: ProcessMenuSelect in Menu, WmMenuSelect in Control and Form.
  • Review notes saved on the desktop: C:\Users\Rick.Xu\OneDrive - WiseTech Global Pty Ltd\Desktop\wm-menu-select-root-fix-report.md.

Restore WM_MENUSELECT and WM_EXITMENULOOP dispatch in Control, keep Form and Menu parity aligned, add regression coverage in the new unit test tree, and document the validation findings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Rick-Xu-WTG Rick-Xu-WTG force-pushed the squad/wm-menu-select-root-fix branch from b855d59 to 3d70e95 Compare June 1, 2026 10:53
Rick-Xu-WTG and others added 5 commits June 1, 2026 18:57
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…py menus

Tests prove the end-to-end message path:
- WM_MENUSELECT -> Control.WmMenuSelect -> ContextMenu.ProcessMenuSelect
  -> MenuItem.PerformSelect -> Select event fires (Grid Colors pattern)
- WM_INITMENUPOPUP -> MenuItem.Popup fires (Universal Copy pattern)
- Idempotency: repeat hover on Grid Colors replaces items, no duplicates

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The previous ProcessMenuSelect used managed MenuItems[index] to find the
popup item, but hidden items (Visible = false) are skipped in the native
menu. This caused a native-to-managed index mismatch: Windows reports the
native index (which excludes hidden items), but the managed collection
includes hidden items at earlier indices, so the wrong MenuItem was found.

CargoWise's ZGrid context menu uses hidden items extensively
(DeactivateMenuItem, ActivateMenuItem, CustomiseMenuItem, CopyToNewRow,
etc.), which made every popup lookup return the wrong item.

The fix replaces the index-based lookup with GetMenuItemFromNativeIndex(),
which uses Win32 GetMenuItemID/GetSubMenu to navigate the actual native
menu structure. This matches the approach used by the .NET Framework
reference implementation (WinFormsLegacyControls) and is immune to
index mismatches from hidden items.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant