diff --git a/interface/wx/event.h b/interface/wx/event.h index 06939b2889..f8cd19f9ec 100644 --- a/interface/wx/event.h +++ b/interface/wx/event.h @@ -2608,6 +2608,10 @@ public: Returns the integer identifier corresponding to a listbox, choice or radiobox selection (only if the event was a selection, not a deselection), or a boolean value representing the value of a checkbox. + + For a menu item, this method returns -1 if the item is not checkable or + a boolean value (true or false) for checkable items indicating the new + state of the item. */ int GetInt() const; diff --git a/src/common/framecmn.cpp b/src/common/framecmn.cpp index 11d35444bc..17633160c4 100644 --- a/src/common/framecmn.cpp +++ b/src/common/framecmn.cpp @@ -271,6 +271,10 @@ bool wxFrameBase::ProcessCommand(wxMenuItem *item) // use the new value commandEvent.SetInt(item->IsChecked()); } + else // Uncheckable item. + { + commandEvent.SetInt(-1); + } return HandleWindowEvent(commandEvent); } diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index 8e11eeb1d3..3b1871f09d 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -949,18 +949,25 @@ bool wxMenu::MSWCommand(WXUINT WXUNUSED(param), WXWORD id_) // ignore commands from the menu title if ( id != idMenuTitle ) { + // Default value for uncheckable items. + int checked = -1; + // update the check item when it's clicked wxMenuItem * const item = FindItem(id); if ( item && item->IsCheckable() ) + { item->Toggle(); - // get the status of the menu item: note that it has been just changed - // by Toggle() above so here we already get the new state of the item - // - // Also notice that we must pass unsigned id_ and not sign-extended id - // to ::GetMenuState() as this is what it expects. - UINT menuState = ::GetMenuState(GetHmenu(), id_, MF_BYCOMMAND); - SendEvent(id, menuState & MF_CHECKED ? 1 : 0); + // Get the status of the menu item: note that it has been just changed + // by Toggle() above so here we already get the new state of the item. + // + // Also notice that we must pass unsigned id_ and not sign-extended id + // to ::GetMenuState() as this is what it expects. + UINT menuState = ::GetMenuState(GetHmenu(), id_, MF_BYCOMMAND); + checked = (menuState & MF_CHECKED) != 0; + } + + SendEvent(id, checked); } return true;