From 9319b2649c8f2ce555a5aaae42ebfff103e588d5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 2 Feb 2014 01:15:39 +0000 Subject: [PATCH] Fix handling of menu items checked before being attached in wxMSW. Calling wxMenuItem::Check() before appending the item to a menu didn't have any effect, fix this by checking the item state when actually attaching it. Closes #15748. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@75767 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/msw/menu.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index 484b7f7fda..d8ae058900 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -626,6 +626,7 @@ wxMSW: - Fix handling of wxSET, wxCLEAR and wxINVERT in wxDC (Artur Wieczorek). - Fix bug with multiple default buttons in a dialog (Artur Wieczorek). - Improve tooltips wrapping after updating their text (Artur Wieczorek). +- Fix checking menu items before appending them to the menu. wxOSX: diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index 3d3ea7e7b0..1845d92dae 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -526,6 +526,15 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) checkInitially = true; } + // Also handle the case of check menu items that had been checked before + // being attached to the menu: we don't need to actually call Check() on + // them, so we don't use checkInitially in this case, but we do need to + // make them checked at Windows level too. Notice that we shouldn't ask + // Windows for the checked state here, as wxMenuItem::IsChecked() does, as + // the item is not attached yet, so explicitly call the base class version. + if ( pItem->IsCheck() && pItem->wxMenuItemBase::IsChecked() ) + flags |= MF_CHECKED; + // adjust position to account for the title of a popup menu, if any if ( !GetMenuBar() && !m_title.empty() ) pos += 2; // for the title itself and its separator @@ -611,6 +620,12 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) mii.wID = id; } + if ( flags & MF_CHECKED ) + { + mii.fMask |= MIIM_STATE; + mii.fState = MFS_CHECKED; + } + mii.dwItemData = reinterpret_cast(pItem); ok = ::InsertMenuItem(GetHmenu(), pos, TRUE /* by pos */, &mii);