Fix Windows menu item state and enabled properties ignored before addItem#45
Merged
Conversation
55d7b51 to
297beee
Compare
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.
297beee to
1990c5b
Compare
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.
Description
Fixes two issues where
MenuItem.stateandMenuItem.enabledproperties are silently ignored on Windows when set before the item is added to aMenuviaaddItem()orinsertItem().Root Cause
MenuItem::Implhad noenabled_field —SetEnabled()only calledEnableMenuItem()ifparent_menu_was set (null beforeaddItem), andIsEnabled()fell back to returningtruewhenparent_menu_was null. Additionally,Menu::AddItem()andMenu::InsertItem()hardcodedMF_UNCHECKEDinstead of reading the item's currentstate_.Changes
MenuItem::Impl: Addedbool enabled_field (defaulttrue)SetEnabled(): Always stores toenabled_regardless ofparent_menu_IsEnabled(): Reads fromenabled_field directly (no longer falls back totrue)AddItem(): Readsitem->GetState()forMF_CHECKED/MF_UNCHECKEDand checksitem->IsEnabled()forMF_GRAYEDInsertItem(): Same fixes asAddItem(), plus added submenu support (was entirely missing)menu_state_example: Reproduces both issues with all tested item typesResolves