Fix int field of wxCommandEvents generated by menu items in wxMSW.
Set the int field of wxCommandEvent generated by clicking on the menu items correctly for not checkable items: it is supposed to be -1 and not 0 (which is the value for checkable but currently unchecked items). This was already the case for wxGTK and wxOSX and implied by the comments in the code. Make wxMSW behave like this too and clearly document this behaviour. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69101 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -2608,6 +2608,10 @@ public:
|
|||||||
Returns the integer identifier corresponding to a listbox, choice or
|
Returns the integer identifier corresponding to a listbox, choice or
|
||||||
radiobox selection (only if the event was a selection, not a deselection),
|
radiobox selection (only if the event was a selection, not a deselection),
|
||||||
or a boolean value representing the value of a checkbox.
|
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;
|
int GetInt() const;
|
||||||
|
|
||||||
|
@@ -271,6 +271,10 @@ bool wxFrameBase::ProcessCommand(wxMenuItem *item)
|
|||||||
// use the new value
|
// use the new value
|
||||||
commandEvent.SetInt(item->IsChecked());
|
commandEvent.SetInt(item->IsChecked());
|
||||||
}
|
}
|
||||||
|
else // Uncheckable item.
|
||||||
|
{
|
||||||
|
commandEvent.SetInt(-1);
|
||||||
|
}
|
||||||
|
|
||||||
return HandleWindowEvent(commandEvent);
|
return HandleWindowEvent(commandEvent);
|
||||||
}
|
}
|
||||||
|
@@ -949,18 +949,25 @@ bool wxMenu::MSWCommand(WXUINT WXUNUSED(param), WXWORD id_)
|
|||||||
// ignore commands from the menu title
|
// ignore commands from the menu title
|
||||||
if ( id != idMenuTitle )
|
if ( id != idMenuTitle )
|
||||||
{
|
{
|
||||||
|
// Default value for uncheckable items.
|
||||||
|
int checked = -1;
|
||||||
|
|
||||||
// update the check item when it's clicked
|
// update the check item when it's clicked
|
||||||
wxMenuItem * const item = FindItem(id);
|
wxMenuItem * const item = FindItem(id);
|
||||||
if ( item && item->IsCheckable() )
|
if ( item && item->IsCheckable() )
|
||||||
|
{
|
||||||
item->Toggle();
|
item->Toggle();
|
||||||
|
|
||||||
// get the status of the menu item: note that it has been just changed
|
// 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
|
// 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
|
// Also notice that we must pass unsigned id_ and not sign-extended id
|
||||||
// to ::GetMenuState() as this is what it expects.
|
// to ::GetMenuState() as this is what it expects.
|
||||||
UINT menuState = ::GetMenuState(GetHmenu(), id_, MF_BYCOMMAND);
|
UINT menuState = ::GetMenuState(GetHmenu(), id_, MF_BYCOMMAND);
|
||||||
SendEvent(id, menuState & MF_CHECKED ? 1 : 0);
|
checked = (menuState & MF_CHECKED) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SendEvent(id, checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user