Skip to content

Fix Windows menu item state and enabled properties ignored before addItem#45

Merged
lijy91 merged 1 commit into
mainfrom
fix/menu-item-state-windows
May 30, 2026
Merged

Fix Windows menu item state and enabled properties ignored before addItem#45
lijy91 merged 1 commit into
mainfrom
fix/menu-item-state-windows

Conversation

@lijy91
Copy link
Copy Markdown
Member

@lijy91 lijy91 commented May 30, 2026

Description

Fixes two issues where MenuItem.state and MenuItem.enabled properties are silently ignored on Windows when set before the item is added to a Menu via addItem() or insertItem().

Root Cause

MenuItem::Impl had no enabled_ field — SetEnabled() only called EnableMenuItem() if parent_menu_ was set (null before addItem), and IsEnabled() fell back to returning true when parent_menu_ was null. Additionally, Menu::AddItem() and Menu::InsertItem() hardcoded MF_UNCHECKED instead of reading the item's current state_.

Changes

  • MenuItem::Impl: Added bool enabled_ field (default true)
  • SetEnabled(): Always stores to enabled_ regardless of parent_menu_
  • IsEnabled(): Reads from enabled_ field directly (no longer falls back to true)
  • AddItem(): Reads item->GetState() for MF_CHECKED/MF_UNCHECKED and checks item->IsEnabled() for MF_GRAYED
  • InsertItem(): Same fixes as AddItem(), plus added submenu support (was entirely missing)
  • New example menu_state_example: Reproduces both issues with all tested item types

Resolves

@lijy91 lijy91 force-pushed the fix/menu-item-state-windows branch from 55d7b51 to 297beee Compare May 30, 2026 02:44
Add an enabled_ field to MenuItem::Impl and initialize it true; have SetEnabled update the stored flag and the native menu via EnableMenuItem. Change IsEnabled to return the stored enabled_ value instead of querying GetMenuState. When adding/inserting items, set MF_CHECKED/MF_UNCHECKED based on the item state for checkboxes and radio items, apply MF_GRAYED for disabled items, and fix InsertMenuW to pass the correct menu_id (handling submenus) for insertion. These changes ensure item enabled/checked state is tracked consistently and reflected in native menu flags.
@lijy91 lijy91 force-pushed the fix/menu-item-state-windows branch from 297beee to 1990c5b Compare May 30, 2026 02:47
@lijy91 lijy91 merged commit cc5cf84 into main May 30, 2026
9 checks passed
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