Version: 3.3.0
wxMenu Class Reference

#include <wx/menu.h>

+ Inheritance diagram for wxMenu:

Detailed Description

A menu is a popup (or pull down) list of items, one of which may be selected before the menu goes away (clicking elsewhere dismisses the menu).

Menus may be used to construct either menu bars or popup menus.

A menu item has an integer ID associated with it which can be used to identify the selection, or to change the menu item in some way. A menu item with a special identifier wxID_SEPARATOR is a separator item and doesn't have an associated command but just makes a separator line appear in the menu.

Note
Please note that wxID_ABOUT and wxID_EXIT are predefined by wxWidgets and have a special meaning since entries using these IDs will be taken out of the normal menus under macOS and will be inserted into the system menu (following the appropriate macOS interface guideline).

Menu items may be either normal items, check items or radio items. Normal items don't have any special properties while the check items have a boolean flag associated to them and they show a checkmark in the menu when the flag is set. wxWidgets automatically toggles the flag value when the item is clicked and its value may be retrieved using either wxMenu::IsChecked method of wxMenu or wxMenuBar itself or by using wxEvent::IsChecked when you get the menu notification for the item in question.

The radio items are similar to the check items except that all the other items in the same radio group are unchecked when a radio item is checked. The radio group is formed by a contiguous range of radio items, i.e. it starts at the first item of this kind and ends with the first item of a different kind (or the end of the menu). Notice that because the radio groups are defined in terms of the item positions inserting or removing the items in the menu containing the radio items risks to not work correctly.

Allocation strategy

All menus must be created on the heap because all menus attached to a menubar or to another menu will be deleted by their parent when it is deleted. The only exception to this rule are the popup menus (i.e. menus used with wxWindow::PopupMenu()) as wxWidgets does not destroy them to allow reusing the same menu more than once. But the exception applies only to the menus themselves and not to any submenus of popup menus which are still destroyed by wxWidgets as usual and so must be heap-allocated.

As the frame menubar is deleted by the frame itself, it means that normally all menus used are deleted automatically.

Event handling

Event handlers for the commands generated by the menu items can be connected directly to the menu object itself using wxEvtHandler::Bind(). If this menu is a submenu of another one, the events from its items can also be processed in the parent menu and so on, recursively.

If the menu is part of a menu bar, then events can also be handled in wxMenuBar object.

Finally, menu events can also be handled in the associated window, which is either the wxFrame associated with the menu bar this menu belongs to or the window for which wxWindow::PopupMenu() was called for the popup menus.

See Dynamic Event Handling for how to bind event handlers to the various objects.

Library:  wxCore
Category:  Menus
See also
wxMenuBar, wxWindow::PopupMenu, Events and Event Handling, wxFileHistory (most recently used files menu)

Public Member Functions

 wxMenu ()
 Constructs a wxMenu object. More...
 
 wxMenu (long style)
 Constructs a wxMenu object. More...
 
 wxMenu (const wxString &title, long style=0)
 Constructs a wxMenu object with a title. More...
 
virtual ~wxMenu ()
 Destructor, destroying the menu. More...
 
wxMenuItemAppend (int id, const wxString &item=wxEmptyString, const wxString &helpString=wxEmptyString, wxItemKind kind=wxITEM_NORMAL)
 Adds a menu item. More...
 
wxMenuItemAppend (int id, const wxString &item, wxMenu *subMenu, const wxString &helpString=wxEmptyString)
 Adds a submenu. More...
 
wxMenuItemAppend (wxMenuItem *menuItem)
 Adds a menu item object. More...
 
wxMenuItemAppendCheckItem (int id, const wxString &item, const wxString &help=wxEmptyString)
 Adds a checkable item to the end of the menu. More...
 
wxMenuItemAppendRadioItem (int id, const wxString &item, const wxString &help=wxEmptyString)
 Adds a radio item to the end of the menu. More...
 
wxMenuItemAppendSeparator ()
 Adds a separator to the end of the menu. More...
 
wxMenuItemAppendSubMenu (wxMenu *submenu, const wxString &text, const wxString &help=wxEmptyString)
 Adds the given submenu to this menu. More...
 
virtual void Break ()
 Inserts a break in a menu, causing the next appended item to appear in a new column. More...
 
void Check (int id, bool check)
 Checks or unchecks the menu item. More...
 
bool Delete (int id)
 Deletes the menu item from the menu. More...
 
bool Delete (wxMenuItem *item)
 Deletes the menu item from the menu. More...
 
bool Destroy (int id)
 Deletes the menu item from the menu. More...
 
bool Destroy (wxMenuItem *item)
 Deletes the menu item from the menu. More...
 
void Enable (int id, bool enable)
 Enables or disables (greys out) a menu item. More...
 
wxMenuItemFindChildItem (int id, size_t *pos=nullptr) const
 Finds the menu item object associated with the given menu item identifier and, optionally, the position of the item in the menu. More...
 
virtual int FindItem (const wxString &itemString) const
 Finds the menu id for a menu item string. More...
 
wxMenuItemFindItem (int id, wxMenu **menu=nullptr) const
 Finds the menu item object associated with the given menu item identifier and, optionally, the (sub)menu it belongs to. More...
 
wxMenuItemFindItemByPosition (size_t position) const
 Returns the wxMenuItem given a position in the menu. More...
 
virtual wxString GetHelpString (int id) const
 Returns the help string associated with a menu item. More...
 
wxString GetLabel (int id) const
 Returns a menu item label. More...
 
wxString GetLabelText (int id) const
 Returns a menu item label, without any of the original mnemonics and accelerators. More...
 
size_t GetMenuItemCount () const
 Returns the number of items in the menu. More...
 
const wxStringGetTitle () const
 Returns the title of the menu. More...
 
wxMenuItemInsert (size_t pos, wxMenuItem *menuItem)
 Inserts the given item before the position pos. More...
 
wxMenuItemInsert (size_t pos, int id, const wxString &item=wxEmptyString, const wxString &helpString=wxEmptyString, wxItemKind kind=wxITEM_NORMAL)
 Inserts the given item before the position pos. More...
 
wxMenuItemInsert (size_t pos, int id, const wxString &text, wxMenu *submenu, const wxString &help=wxEmptyString)
 Inserts the given submenu before the position pos. More...
 
wxMenuItemInsertCheckItem (size_t pos, int id, const wxString &item, const wxString &helpString=wxEmptyString)
 Inserts a checkable item at the given position. More...
 
wxMenuItemInsertRadioItem (size_t pos, int id, const wxString &item, const wxString &helpString=wxEmptyString)
 Inserts a radio item at the given position. More...
 
wxMenuItemInsertSeparator (size_t pos)
 Inserts a separator at the given position. More...
 
bool IsChecked (int id) const
 Determines whether a menu item is checked. More...
 
bool IsEnabled (int id) const
 Determines whether a menu item is enabled. More...
 
virtual bool MSWCommand (WXUINT param, WXWORD id)
 Allows handling native MSW menu command messages. More...
 
wxMenuItemPrepend (wxMenuItem *item)
 Inserts the given item at position 0, i.e. before all the other existing items. More...
 
wxMenuItemPrepend (int id, const wxString &item=wxEmptyString, const wxString &helpString=wxEmptyString, wxItemKind kind=wxITEM_NORMAL)
 Inserts the given item at position 0, i.e. before all the other existing items. More...
 
wxMenuItemPrepend (int id, const wxString &text, wxMenu *submenu, const wxString &help=wxEmptyString)
 Inserts the given submenu at position 0. More...
 
wxMenuItemPrependCheckItem (int id, const wxString &item, const wxString &helpString=wxEmptyString)
 Inserts a checkable item at position 0. More...
 
wxMenuItemPrependRadioItem (int id, const wxString &item, const wxString &helpString=wxEmptyString)
 Inserts a radio item at position 0. More...
 
wxMenuItemPrependSeparator ()
 Inserts a separator at position 0. More...
 
wxMenuItemRemove (int id)
 Removes the menu item from the menu but doesn't delete the associated C++ object. More...
 
wxMenuItemRemove (wxMenuItem *item)
 Removes the menu item from the menu but doesn't delete the associated C++ object. More...
 
virtual void SetHelpString (int id, const wxString &helpString)
 Sets an item's help string. More...
 
void SetLabel (int id, const wxString &label)
 Sets the label of a menu item. More...
 
virtual void SetTitle (const wxString &title)
 Sets the title of the menu. More...
 
void UpdateUI (wxEvtHandler *source=nullptr)
 Update the state of all menu items, recursively, by generating wxEVT_UPDATE_UI events for them. More...
 
void SetInvokingWindow (wxWindow *win)
 
wxWindowGetInvokingWindow () const
 
wxWindowGetWindow () const
 
long GetStyle () const
 
void SetParent (wxMenu *parent)
 
wxMenuGetParent () const
 
virtual void Attach (wxMenuBar *menubar)
 
virtual void Detach ()
 
bool IsAttached () const
 
wxMenuItemList & GetMenuItems ()
 Returns the list of items in the menu. More...
 
const wxMenuItemList & GetMenuItems () const
 Returns the list of items in the menu. More...
 
- Public Member Functions inherited from wxEvtHandler
 wxEvtHandler ()
 Constructor. More...
 
virtual ~wxEvtHandler ()
 Destructor. More...
 
virtual void QueueEvent (wxEvent *event)
 Queue event for a later processing. More...
 
virtual void AddPendingEvent (const wxEvent &event)
 Post an event to be processed later. More...
 
template<typename T , typename T1 , ... >
void CallAfter (void(T::*method)(T1,...), T1 x1,...)
 Asynchronously call the given method. More...
 
template<typename T >
void CallAfter (const T &functor)
 Asynchronously call the given functor. More...
 
virtual bool ProcessEvent (wxEvent &event)
 Processes an event, searching event tables and calling zero or more suitable event handler function(s). More...
 
bool ProcessEventLocally (wxEvent &event)
 Try to process the event in this handler and all those chained to it. More...
 
bool SafelyProcessEvent (wxEvent &event)
 Processes an event by calling ProcessEvent() and handles any exceptions that occur in the process. More...
 
void ProcessPendingEvents ()
 Processes the pending events previously queued using QueueEvent() or AddPendingEvent(); you must call this function only if you are sure there are pending events for this handler, otherwise a wxCHECK will fail. More...
 
void DeletePendingEvents ()
 Deletes all events queued on this event handler using QueueEvent() or AddPendingEvent(). More...
 
void Connect (int id, int lastId, wxEventType eventType, wxObjectEventFunction function, wxObject *userData=nullptr, wxEvtHandler *eventSink=nullptr)
 Connects the given function dynamically with the event handler, id and event type. More...
 
void Connect (int id, wxEventType eventType, wxObjectEventFunction function, wxObject *userData=nullptr, wxEvtHandler *eventSink=nullptr)
 See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. More...
 
void Connect (wxEventType eventType, wxObjectEventFunction function, wxObject *userData=nullptr, wxEvtHandler *eventSink=nullptr)
 See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. More...
 
bool Disconnect (wxEventType eventType, wxObjectEventFunction function, wxObject *userData=nullptr, wxEvtHandler *eventSink=nullptr)
 Disconnects the given function dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed. More...
 
bool Disconnect (int id=wxID_ANY, wxEventType eventType=wxEVT_NULL, wxObjectEventFunction function=nullptr, wxObject *userData=nullptr, wxEvtHandler *eventSink=nullptr)
 See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. More...
 
bool Disconnect (int id, int lastId, wxEventType eventType, wxObjectEventFunction function=nullptr, wxObject *userData=nullptr, wxEvtHandler *eventSink=nullptr)
 See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. More...
 
template<typename EventTag , typename Functor >
void Bind (const EventTag &eventType, Functor functor, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=nullptr)
 Binds the given function, functor or method dynamically with the event. More...
 
template<typename EventTag , typename Class , typename EventArg , typename EventHandler >
void Bind (const EventTag &eventType, void(Class::*method)(EventArg &), EventHandler *handler, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=nullptr)
 See the Bind<>(const EventTag&, Functor, int, int, wxObject*) overload for more info. More...
 
template<typename EventTag , typename Functor >
bool Unbind (const EventTag &eventType, Functor functor, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=nullptr)
 Unbinds the given function, functor or method dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed. More...
 
template<typename EventTag , typename Class , typename EventArg , typename EventHandler >
bool Unbind (const EventTag &eventType, void(Class::*method)(EventArg &), EventHandler *handler, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=nullptr)
 See the Unbind<>(const EventTag&, Functor, int, int, wxObject*) overload for more info. More...
 
void * GetClientData () const
 Returns user-supplied client data. More...
 
wxClientDataGetClientObject () const
 Returns a pointer to the user-supplied client data object. More...
 
void SetClientData (void *data)
 Sets user-supplied client data. More...
 
void SetClientObject (wxClientData *data)
 Set the client data object. More...
 
bool GetEvtHandlerEnabled () const
 Returns true if the event handler is enabled, false otherwise. More...
 
wxEvtHandlerGetNextHandler () const
 Returns the pointer to the next handler in the chain. More...
 
wxEvtHandlerGetPreviousHandler () const
 Returns the pointer to the previous handler in the chain. More...
 
void SetEvtHandlerEnabled (bool enabled)
 Enables or disables the event handler. More...
 
virtual void SetNextHandler (wxEvtHandler *handler)
 Sets the pointer to the next handler. More...
 
virtual void SetPreviousHandler (wxEvtHandler *handler)
 Sets the pointer to the previous handler. More...
 
void Unlink ()
 Unlinks this event handler from the chain it's part of (if any); then links the "previous" event handler to the "next" one (so that the chain won't be interrupted). More...
 
bool IsUnlinked () const
 Returns true if the next and the previous handler pointers of this event handler instance are nullptr. More...
 
- Public Member Functions inherited from wxObject
 wxObject ()
 Default ctor; initializes to nullptr the internal reference data. More...
 
 wxObject (const wxObject &other)
 Copy ctor. More...
 
virtual ~wxObject ()
 Destructor. More...
 
virtual wxClassInfoGetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
 
wxObjectRefDataGetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
 
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class. More...
 
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj. More...
 
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone. More...
 
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer. More...
 
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
 
void UnShare ()
 This is the same of AllocExclusive() but this method is public. More...
 
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. More...
 
void * operator new (size_t size, const wxString &filename=nullptr, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from wxEvtHandler
static void AddFilter (wxEventFilter *filter)
 Add an event filter whose FilterEvent() method will be called for each and every event processed by wxWidgets. More...
 
static void RemoveFilter (wxEventFilter *filter)
 Remove a filter previously installed with AddFilter(). More...
 
- Protected Member Functions inherited from wxEvtHandler
virtual bool TryBefore (wxEvent &event)
 Method called by ProcessEvent() before examining this object event tables. More...
 
virtual bool TryAfter (wxEvent &event)
 Method called by ProcessEvent() as last resort. More...
 
- Protected Member Functions inherited from wxObject
void AllocExclusive ()
 Ensure that this object's data is not shared with any other object. More...
 
virtual wxObjectRefDataCreateRefData () const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
 
virtual wxObjectRefDataCloneRefData (const wxObjectRefData *data) const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
 
- Protected Attributes inherited from wxObject
wxObjectRefDatam_refData
 Pointer to an object which is the object's reference-counted data. More...
 

Constructor & Destructor Documentation

◆ wxMenu() [1/3]

wxMenu::wxMenu ( )

Constructs a wxMenu object.

◆ wxMenu() [2/3]

wxMenu::wxMenu ( long  style)

Constructs a wxMenu object.

Parameters
styleIf set to wxMENU_TEAROFF, the menu will be detachable (wxGTK and wxQT only).

◆ wxMenu() [3/3]

wxMenu::wxMenu ( const wxString title,
long  style = 0 
)

Constructs a wxMenu object with a title.

Parameters
titleTitle at the top of the menu (not always supported).
styleIf set to wxMENU_TEAROFF, the menu will be detachable (wxGTK and wxQT only).

◆ ~wxMenu()

virtual wxMenu::~wxMenu ( )
virtual

Destructor, destroying the menu.

Member Function Documentation

◆ Append() [1/3]

wxMenuItem* wxMenu::Append ( int  id,
const wxString item,
wxMenu subMenu,
const wxString helpString = wxEmptyString 
)

Adds a submenu.

Deprecated:
This function is deprecated, use AppendSubMenu() instead.
Parameters
idThe menu command identifier.
itemThe string to appear on the menu item.
subMenuPull-right submenu.
helpStringAn optional help string associated with the item. By default, the handler for the wxEVT_MENU_HIGHLIGHT event displays this string in the status line.
See also
AppendSeparator(), AppendCheckItem(), AppendRadioItem(), AppendSubMenu(), Insert(), SetLabel(), GetHelpString(), SetHelpString(), wxMenuItem

◆ Append() [2/3]

wxMenuItem* wxMenu::Append ( int  id,
const wxString item = wxEmptyString,
const wxString helpString = wxEmptyString,
wxItemKind  kind = wxITEM_NORMAL 
)

Adds a menu item.

Parameters
idThe menu command identifier. See Window IDs for more information about IDs (same considerations apply to both window and menu item IDs).
itemThe string to appear on the menu item. See wxMenuItem::SetItemLabel() for more details.
helpStringAn optional help string associated with the item. By default, the handler for the wxEVT_MENU_HIGHLIGHT event displays this string in the status line.
kindMay be wxITEM_SEPARATOR, wxITEM_NORMAL, wxITEM_CHECK or wxITEM_RADIO.

Example:

m_pFileMenu->Append(ID_NEW_FILE, "&New file\tCTRL+N", "Creates a new XYZ document");

or even better for stock menu items (see wxMenuItem::wxMenuItem):

m_pFileMenu->Append(wxID_NEW, "", "Creates a new XYZ document");
@ wxID_NEW
Definition: defs.h:602
Remarks
This command can be used after the menu has been shown, as well as on initial creation of a menu or menubar.
See also
AppendSeparator(), AppendCheckItem(), AppendRadioItem(), AppendSubMenu(), Insert(), SetLabel(), GetHelpString(), SetHelpString(), wxMenuItem

◆ Append() [3/3]

wxMenuItem* wxMenu::Append ( wxMenuItem menuItem)

Adds a menu item object.

This is the most generic variant of Append() method because it may be used for both items (including separators) and submenus and because you can also specify various extra properties of a menu item this way, such as bitmaps and fonts.

Parameters
menuItemA menuitem object. It will be owned by the wxMenu object after this function is called, so do not delete it yourself.
Remarks
See the remarks for the other Append() overloads.
See also
AppendSeparator(), AppendCheckItem(), AppendRadioItem(), AppendSubMenu(), Insert(), SetLabel(), GetHelpString(), SetHelpString(), wxMenuItem

◆ AppendCheckItem()

wxMenuItem* wxMenu::AppendCheckItem ( int  id,
const wxString item,
const wxString help = wxEmptyString 
)

Adds a checkable item to the end of the menu.

See also
Append(), InsertCheckItem()

◆ AppendRadioItem()

wxMenuItem* wxMenu::AppendRadioItem ( int  id,
const wxString item,
const wxString help = wxEmptyString 
)

Adds a radio item to the end of the menu.

All consequent radio items form a group and when an item in the group is checked, all the others are automatically unchecked.

See also
Append(), InsertRadioItem()

◆ AppendSeparator()

wxMenuItem* wxMenu::AppendSeparator ( )

Adds a separator to the end of the menu.

See also
Append(), InsertSeparator()

◆ AppendSubMenu()

wxMenuItem* wxMenu::AppendSubMenu ( wxMenu submenu,
const wxString text,
const wxString help = wxEmptyString 
)

Adds the given submenu to this menu.

text is the text shown in the menu for it and help is the help string shown in the status bar when the submenu item is selected.

See also
Insert(), Prepend()

◆ Attach()

virtual void wxMenu::Attach ( wxMenuBar menubar)
virtual

◆ Break()

virtual void wxMenu::Break ( )
virtual

Inserts a break in a menu, causing the next appended item to appear in a new column.

This function only actually inserts a break in wxMSW and does nothing under the other platforms.

◆ Check()

void wxMenu::Check ( int  id,
bool  check 
)

Checks or unchecks the menu item.

Parameters
idThe menu item identifier.
checkIf true, the item will be checked, otherwise it will be unchecked.
See also
IsChecked()

◆ Delete() [1/2]

bool wxMenu::Delete ( int  id)

Deletes the menu item from the menu.

If the item is a submenu, it will not be deleted. Use Destroy() if you want to delete a submenu.

Parameters
idId of the menu item to be deleted.
See also
FindItem(), Destroy(), Remove()

◆ Delete() [2/2]

bool wxMenu::Delete ( wxMenuItem item)

Deletes the menu item from the menu.

If the item is a submenu, it will not be deleted. Use Destroy() if you want to delete a submenu.

Parameters
itemMenu item to be deleted.
See also
FindItem(), Destroy(), Remove()

◆ Destroy() [1/2]

bool wxMenu::Destroy ( int  id)

Deletes the menu item from the menu.

If the item is a submenu, it will be deleted. Use Remove() if you want to keep the submenu (for example, to reuse it later).

Parameters
idId of the menu item to be deleted.
See also
FindItem(), Delete(), Remove()

◆ Destroy() [2/2]

bool wxMenu::Destroy ( wxMenuItem item)

Deletes the menu item from the menu.

If the item is a submenu, it will be deleted. Use Remove() if you want to keep the submenu (for example, to reuse it later).

Parameters
itemMenu item to be deleted.
See also
FindItem(), Delete(), Remove()

◆ Detach()

virtual void wxMenu::Detach ( )
virtual

◆ Enable()

void wxMenu::Enable ( int  id,
bool  enable 
)

Enables or disables (greys out) a menu item.

Parameters
idThe menu item identifier.
enabletrue to enable the menu item, false to disable it.
See also
IsEnabled()

◆ FindChildItem()

wxMenuItem* wxMenu::FindChildItem ( int  id,
size_t *  pos = nullptr 
) const

Finds the menu item object associated with the given menu item identifier and, optionally, the position of the item in the menu.

Unlike FindItem(), this function doesn't recurse but only looks at the direct children of this menu.

Parameters
idThe identifier of the menu item to find.
posIf the pointer is not nullptr, it is filled with the item's position if it was found or (size_t)wxNOT_FOUND otherwise.
Returns
Menu item object or nullptr if not found.

◆ FindItem() [1/2]

virtual int wxMenu::FindItem ( const wxString itemString) const
virtual

Finds the menu id for a menu item string.

Parameters
itemStringMenu item string to find.
Returns
Menu item identifier, or wxNOT_FOUND if none is found.
Remarks
Any special menu codes are stripped out of source and target strings before matching.

◆ FindItem() [2/2]

wxMenuItem* wxMenu::FindItem ( int  id,
wxMenu **  menu = nullptr 
) const

Finds the menu item object associated with the given menu item identifier and, optionally, the (sub)menu it belongs to.

Parameters
idMenu item identifier.
menuIf the pointer is not nullptr, it will be filled with the item's parent menu (if the item was found)
Returns
Menu item object or nullptr if none is found.

◆ FindItemByPosition()

wxMenuItem* wxMenu::FindItemByPosition ( size_t  position) const

Returns the wxMenuItem given a position in the menu.

◆ GetHelpString()

virtual wxString wxMenu::GetHelpString ( int  id) const
virtual

Returns the help string associated with a menu item.

Parameters
idThe menu item identifier.
Returns
The help string, or the empty string if there is no help string or the item was not found.
See also
SetHelpString(), Append()

◆ GetInvokingWindow()

wxWindow* wxMenu::GetInvokingWindow ( ) const

◆ GetLabel()

wxString wxMenu::GetLabel ( int  id) const

Returns a menu item label.

Parameters
idThe menu item identifier.
Returns
The item label, or the empty string if the item was not found.
See also
GetLabelText(), SetLabel()

◆ GetLabelText()

wxString wxMenu::GetLabelText ( int  id) const

Returns a menu item label, without any of the original mnemonics and accelerators.

Parameters
idThe menu item identifier.
Returns
The item label, or the empty string if the item was not found.
See also
GetLabel(), SetLabel()

◆ GetMenuItemCount()

size_t wxMenu::GetMenuItemCount ( ) const

Returns the number of items in the menu.

◆ GetMenuItems() [1/2]

wxMenuItemList& wxMenu::GetMenuItems ( )

Returns the list of items in the menu.

wxMenuItemList is a pseudo-template list class containing wxMenuItem pointers, see wxList.

◆ GetMenuItems() [2/2]

const wxMenuItemList& wxMenu::GetMenuItems ( ) const

Returns the list of items in the menu.

wxMenuItemList is a pseudo-template list class containing wxMenuItem pointers, see wxList.

◆ GetParent()

wxMenu* wxMenu::GetParent ( ) const

◆ GetStyle()

long wxMenu::GetStyle ( ) const

◆ GetTitle()

const wxString& wxMenu::GetTitle ( ) const

Returns the title of the menu.

See also
SetTitle()

◆ GetWindow()

wxWindow* wxMenu::GetWindow ( ) const

◆ Insert() [1/3]

wxMenuItem* wxMenu::Insert ( size_t  pos,
int  id,
const wxString item = wxEmptyString,
const wxString helpString = wxEmptyString,
wxItemKind  kind = wxITEM_NORMAL 
)

Inserts the given item before the position pos.

Inserting the item at position GetMenuItemCount() is the same as appending it.

See also
Append(), Prepend()

◆ Insert() [2/3]

wxMenuItem* wxMenu::Insert ( size_t  pos,
int  id,
const wxString text,
wxMenu submenu,
const wxString help = wxEmptyString 
)

Inserts the given submenu before the position pos.

text is the text shown in the menu for it and help is the help string shown in the status bar when the submenu item is selected.

See also
AppendSubMenu(), Prepend()

◆ Insert() [3/3]

wxMenuItem* wxMenu::Insert ( size_t  pos,
wxMenuItem menuItem 
)

Inserts the given item before the position pos.

Inserting the item at position GetMenuItemCount() is the same as appending it.

See also
Append(), Prepend()

◆ InsertCheckItem()

wxMenuItem* wxMenu::InsertCheckItem ( size_t  pos,
int  id,
const wxString item,
const wxString helpString = wxEmptyString 
)

Inserts a checkable item at the given position.

See also
Insert(), AppendCheckItem()

◆ InsertRadioItem()

wxMenuItem* wxMenu::InsertRadioItem ( size_t  pos,
int  id,
const wxString item,
const wxString helpString = wxEmptyString 
)

Inserts a radio item at the given position.

See also
Insert(), AppendRadioItem()

◆ InsertSeparator()

wxMenuItem* wxMenu::InsertSeparator ( size_t  pos)

Inserts a separator at the given position.

See also
Insert(), AppendSeparator()

◆ IsAttached()

bool wxMenu::IsAttached ( ) const

◆ IsChecked()

bool wxMenu::IsChecked ( int  id) const

Determines whether a menu item is checked.

Parameters
idThe menu item identifier.
Returns
true if the menu item is checked, false otherwise.
See also
Check()

◆ IsEnabled()

bool wxMenu::IsEnabled ( int  id) const

Determines whether a menu item is enabled.

Parameters
idThe menu item identifier.
Returns
true if the menu item is enabled, false otherwise.
See also
Enable()

◆ MSWCommand()

virtual bool wxMenu::MSWCommand ( WXUINT  param,
WXWORD  id 
)
virtual

Allows handling native MSW menu command messages.

This is a low-level function which allows handling MSW 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 wxEVT_MENU command events.

Parameters
paramThe MSW command parameter.
idThe id of the command.
Returns
true if the command was handled, false otherwise.
Availability:  only available for the wxMSW port.
Since
3.1.5

◆ Prepend() [1/3]

wxMenuItem* wxMenu::Prepend ( int  id,
const wxString item = wxEmptyString,
const wxString helpString = wxEmptyString,
wxItemKind  kind = wxITEM_NORMAL 
)

Inserts the given item at position 0, i.e. before all the other existing items.

See also
Append(), Insert()

◆ Prepend() [2/3]

wxMenuItem* wxMenu::Prepend ( int  id,
const wxString text,
wxMenu submenu,
const wxString help = wxEmptyString 
)

Inserts the given submenu at position 0.

See also
AppendSubMenu(), Insert()

◆ Prepend() [3/3]

wxMenuItem* wxMenu::Prepend ( wxMenuItem item)

Inserts the given item at position 0, i.e. before all the other existing items.

See also
Append(), Insert()

◆ PrependCheckItem()

wxMenuItem* wxMenu::PrependCheckItem ( int  id,
const wxString item,
const wxString helpString = wxEmptyString 
)

Inserts a checkable item at position 0.

See also
Prepend(), AppendCheckItem()

◆ PrependRadioItem()

wxMenuItem* wxMenu::PrependRadioItem ( int  id,
const wxString item,
const wxString helpString = wxEmptyString 
)

Inserts a radio item at position 0.

See also
Prepend(), AppendRadioItem()

◆ PrependSeparator()

wxMenuItem* wxMenu::PrependSeparator ( )

Inserts a separator at position 0.

See also
Prepend(), AppendSeparator()

◆ Remove() [1/2]

wxMenuItem* wxMenu::Remove ( int  id)

Removes the menu item from the menu but doesn't delete the associated C++ object.

This allows you to reuse the same item later by adding it back to the menu (especially useful with submenus).

Parameters
idThe identifier of the menu item to remove.
Returns
A pointer to the item which was detached from the menu.

◆ Remove() [2/2]

wxMenuItem* wxMenu::Remove ( wxMenuItem item)

Removes the menu item from the menu but doesn't delete the associated C++ object.

This allows you to reuse the same item later by adding it back to the menu (especially useful with submenus).

Parameters
itemThe menu item to remove.
Returns
A pointer to the item which was detached from the menu.

◆ SetHelpString()

virtual void wxMenu::SetHelpString ( int  id,
const wxString helpString 
)
virtual

Sets an item's help string.

Parameters
idThe menu item identifier.
helpStringThe help string to set.
See also
GetHelpString()

◆ SetInvokingWindow()

void wxMenu::SetInvokingWindow ( wxWindow win)

◆ SetLabel()

void wxMenu::SetLabel ( int  id,
const wxString label 
)

Sets the label of a menu item.

Parameters
idThe menu item identifier.
labelThe menu item label to set.
See also
Append(), GetLabel()

◆ SetParent()

void wxMenu::SetParent ( wxMenu parent)

◆ SetTitle()

virtual void wxMenu::SetTitle ( const wxString title)
virtual

Sets the title of the menu.

Parameters
titleThe title to set.
Remarks
Notice that you can only call this method directly for the popup menus, to change the title of a menu that is part of a menu bar you need to use wxMenuBar::SetLabelTop().
See also
GetTitle()

◆ UpdateUI()

void wxMenu::UpdateUI ( wxEvtHandler source = nullptr)

Update the state of all menu items, recursively, by generating wxEVT_UPDATE_UI events for them.

This is an internal wxWidgets function and shouldn't normally be called from outside of the library. If it is called, source argument should not be used, it is deprecated and exists only for backwards compatibility.