Allow overriding wxMenu::MSWCommand() in wxMSW

This can be useful to implement custom handling of WM_COMMAND for the
popup menus, so make this function virtual and document it to indicate
that it is now part of the public API.

Closes https://github.com/wxWidgets/wxWidgets/pull/2170
This commit is contained in:
Gary Allen
2021-01-17 15:07:28 +02:00
committed by Vadim Zeitlin
parent a571ec6fbb
commit f4172b0b46
2 changed files with 30 additions and 2 deletions

View File

@@ -55,11 +55,12 @@ public:
// Don't use this object after calling this method. // Don't use this object after calling this method.
WXHMENU MSWDetachHMENU() { WXHMENU m = m_hMenu; m_hMenu = NULL; return m; } WXHMENU MSWDetachHMENU() { WXHMENU m = m_hMenu; m_hMenu = NULL; return m; }
// Process WM_COMMAND.
virtual bool MSWCommand(WXUINT param, WXWORD id);
// implementation only from now on // implementation only from now on
// ------------------------------- // -------------------------------
bool MSWCommand(WXUINT param, WXWORD id);
// get the native menu handle // get the native menu handle
WXHMENU GetHMenu() const { return m_hMenu; } WXHMENU GetHMenu() const { return m_hMenu; }

View File

@@ -931,6 +931,33 @@ public:
*/ */
bool IsEnabled(int id) const; bool IsEnabled(int id) const;
/**
Allows handling native MSW menu command messages.
This is a low-level function which allows handling MSW @c WM_COMMAND
messages generated when menu items are selected. It is particularly
useful for the popup menus, as specific handling can then be defined in
a wxMenu-derived class directly, instead of in the wxWindow-derived
owner class.
The base class version of this function generates @c wxEVT_MENU command
events.
@param param
The MSW command parameter.
@param id
The id of the command.
@return
@true if the command was handled, @false otherwise.
@onlyfor{wxMSW}
@since 3.1.5
*/
virtual bool MSWCommand(WXUINT param, WXWORD id);
/** /**
Inserts the given @a item at position 0, i.e.\ before all the other Inserts the given @a item at position 0, i.e.\ before all the other
existing items. existing items.