Version: 2.9.4
Public Member Functions | Static Public Member Functions
wxMenuBar Class Reference

#include </home/zeitlin/src/wx/github/interface/wx/menu.h>

Inheritance diagram for wxMenuBar:

Detailed Description

A menu bar is a series of menus accessible from the top of a frame.

注意:
To respond to a menu selection, provide a handler for EVT_MENU, in the frame that contains the menu bar.

If you have a toolbar which uses the same identifiers as your EVT_MENU entries, events from the toolbar will also be processed by your EVT_MENU event handlers.

Tip: under Windows, if you discover that menu shortcuts (for example, Alt-F to show the file menu) are not working, check any EVT_CHAR events you are handling in child windows. If you are not calling event.Skip() for events that you don't process in these event handlers, menu shortcuts may cease to work.

Library:  wxCore
Category:  Menus
参照:
wxMenu, Events and Event Handling

Public Member Functions

 wxMenuBar (long style=0)
 Construct an empty menu bar.
 wxMenuBar (size_t n, wxMenu *menus[], const wxString titles[], long style=0)
 Construct a menu bar from arrays of menus and titles.
virtual ~wxMenuBar ()
 Destructor, destroying the menu bar and removing it from the parent frame (if any).
virtual bool Append (wxMenu *menu, const wxString &title)
 Adds the item to the end of the menu bar.
void Check (int id, bool check)
 Checks or unchecks a menu item.
void Enable (int id, bool enable)
 Enables or disables (greys out) a menu item.
bool IsEnabledTop (size_t pos) const
 Returns true if the menu with the given index is enabled.
virtual void EnableTop (size_t pos, bool enable)
 Enables or disables a whole menu.
virtual wxMenuItemFindItem (int id, wxMenu **menu=NULL) const
 Finds the menu item object associated with the given menu item identifier.
int FindMenu (const wxString &title) const
 Returns the index of the menu with the given title or wxNOT_FOUND if no such menu exists in this menubar.
virtual int FindMenuItem (const wxString &menuString, const wxString &itemString) const
 Finds the menu item id for a menu name/menu item string pair.
wxString GetHelpString (int id) const
 Gets the help string associated with the menu item identifier.
wxString GetLabel (int id) const
 Gets the label associated with a menu item.
wxString GetLabelTop (size_t pos) const
 Returns the label of a top-level menu.
wxMenuGetMenu (size_t menuIndex) const
 Returns the menu at menuIndex (zero-based).
size_t GetMenuCount () const
 Returns the number of menus in this menubar.
virtual wxString GetMenuLabel (size_t pos) const
 Returns the label of a top-level menu.
virtual wxString GetMenuLabelText (size_t pos) const
 Returns the label of a top-level menu.
virtual bool Insert (size_t pos, wxMenu *menu, const wxString &title)
 Inserts the menu at the given position into the menu bar.
bool IsChecked (int id) const
 Determines whether an item is checked.
bool IsEnabled (int id) const
 Determines whether an item is enabled.
virtual void Refresh (bool eraseBackground=true, const wxRect *rect=NULL)
 Redraw the menu bar.
virtual wxMenuRemove (size_t pos)
 Removes the menu from the menu bar and returns the menu object - the caller is responsible for deleting it.
virtual wxMenuReplace (size_t pos, wxMenu *menu, const wxString &title)
 Replaces the menu at the given position with another one.
void SetHelpString (int id, const wxString &helpString)
 Sets the help string associated with a menu item.
void SetLabel (int id, const wxString &label)
 Sets the label of a menu item.
void SetLabelTop (size_t pos, const wxString &label)
 Sets the label of a top-level menu.
virtual void SetMenuLabel (size_t pos, const wxString &label)
 Sets the label of a top-level menu.
wxFrameGetFrame () const
bool IsAttached () const
virtual void Attach (wxFrame *frame)
virtual void Detach ()

Static Public Member Functions

static void MacSetCommonMenuBar (wxMenuBar *menubar)
 Enables you to set the global menubar on Mac, that is, the menubar displayed when the app is running without any frames open.
static wxMenuBarMacGetCommonMenuBar ()
 Enables you to get the global menubar on Mac, that is, the menubar displayed when the app is running without any frames open.

List of all members.


Constructor & Destructor Documentation

wxMenuBar::wxMenuBar ( long  style = 0)

Construct an empty menu bar.

Parameters:
styleIf wxMB_DOCKABLE the menu bar can be detached (wxGTK only).
wxMenuBar::wxMenuBar ( size_t  n,
wxMenu menus[],
const wxString  titles[],
long  style = 0 
)

Construct a menu bar from arrays of menus and titles.

Parameters:
nThe number of menus.
menusAn array of menus. Do not use this array again - it now belongs to the menu bar.
titlesAn array of title strings. Deallocate this array after creating the menu bar.
styleIf wxMB_DOCKABLE the menu bar can be detached (wxGTK only).

wxPerl Note: Not supported by wxPerl.

virtual wxMenuBar::~wxMenuBar ( ) [virtual]

Destructor, destroying the menu bar and removing it from the parent frame (if any).


Member Function Documentation

virtual bool wxMenuBar::Append ( wxMenu menu,
const wxString title 
) [virtual]

Adds the item to the end of the menu bar.

Parameters:
menuThe menu to add. Do not deallocate this menu after calling Append().
titleThe title of the menu, must be non-empty.
Returns:
true on success, false if an error occurred.
参照:
Insert()
virtual void wxMenuBar::Attach ( wxFrame frame) [virtual]
void wxMenuBar::Check ( int  id,
bool  check 
)

Checks or unchecks a menu item.

Parameters:
idThe menu item identifier.
checkIf true, checks the menu item, otherwise the item is unchecked.
注意:
Only use this when the menu bar has been associated with a frame; otherwise, use the wxMenu equivalent call.
virtual void wxMenuBar::Detach ( ) [virtual]
void wxMenuBar::Enable ( int  id,
bool  enable 
)

Enables or disables (greys out) a menu item.

Parameters:
idThe menu item identifier.
enabletrue to enable the item, false to disable it.
注意:
Only use this when the menu bar has been associated with a frame; otherwise, use the wxMenu equivalent call.
virtual void wxMenuBar::EnableTop ( size_t  pos,
bool  enable 
) [virtual]

Enables or disables a whole menu.

Parameters:
posThe position of the menu, starting from zero.
enabletrue to enable the menu, false to disable it.
注意:
Only use this when the menu bar has been associated with a frame.
virtual wxMenuItem* wxMenuBar::FindItem ( int  id,
wxMenu **  menu = NULL 
) const [virtual]

Finds the menu item object associated with the given menu item identifier.

Parameters:
idMenu item identifier.
menuIf not NULL, menu will get set to the associated menu.
Returns:
The found menu item object, or NULL if one was not found.

wxPerl Note: In wxPerl this method takes just the id parameter; in scalar context it returns the associated Wx::MenuItem, in list context it returns a 2-element list (item, submenu).

int wxMenuBar::FindMenu ( const wxString title) const

Returns the index of the menu with the given title or wxNOT_FOUND if no such menu exists in this menubar.

The title parameter may specify either the menu title (with accelerator characters, i.e. "&File") or just the menu label ("File") indifferently.

virtual int wxMenuBar::FindMenuItem ( const wxString menuString,
const wxString itemString 
) const [virtual]

Finds the menu item id for a menu name/menu item string pair.

Parameters:
menuStringMenu title to find.
itemStringItem to find.
Returns:
The menu item identifier, or wxNOT_FOUND if none was found.
注意:
Any special menu codes are stripped out of source and target strings before matching.
wxFrame* wxMenuBar::GetFrame ( ) const
wxString wxMenuBar::GetHelpString ( int  id) const

Gets the help string associated with the menu item identifier.

Parameters:
idThe menu item identifier.
Returns:
The help string, or the empty string if there was no help string or the menu item was not found.
参照:
SetHelpString()
wxString wxMenuBar::GetLabel ( int  id) const

Gets the label associated with a menu item.

Parameters:
idThe menu item identifier.
Returns:
The menu item label, or the empty string if the item was not found.
注意:
Use only after the menubar has been associated with a frame.
wxString wxMenuBar::GetLabelTop ( size_t  pos) const

Returns the label of a top-level menu.

Note that the returned string does not include the accelerator characters which could have been specified in the menu title string during its construction.

Parameters:
posPosition of the menu on the menu bar, starting from zero.
Returns:
The menu label, or the empty string if the menu was not found.
注意:
Use only after the menubar has been associated with a frame.
Deprecated:
This function is deprecated in favour of GetMenuLabel() and GetMenuLabelText().
参照:
SetLabelTop()
wxMenu* wxMenuBar::GetMenu ( size_t  menuIndex) const

Returns the menu at menuIndex (zero-based).

size_t wxMenuBar::GetMenuCount ( ) const

Returns the number of menus in this menubar.

virtual wxString wxMenuBar::GetMenuLabel ( size_t  pos) const [virtual]

Returns the label of a top-level menu.

Note that the returned string includes the accelerator characters that have been specified in the menu title string during its construction.

Parameters:
posPosition of the menu on the menu bar, starting from zero.
Returns:
The menu label, or the empty string if the menu was not found.
注意:
Use only after the menubar has been associated with a frame.
参照:
GetMenuLabelText(), SetMenuLabel()
virtual wxString wxMenuBar::GetMenuLabelText ( size_t  pos) const [virtual]

Returns the label of a top-level menu.

Note that the returned string does not include any accelerator characters that may have been specified in the menu title string during its construction.

Parameters:
posPosition of the menu on the menu bar, starting from zero.
Returns:
The menu label, or the empty string if the menu was not found.
注意:
Use only after the menubar has been associated with a frame.
参照:
GetMenuLabel(), SetMenuLabel()
virtual bool wxMenuBar::Insert ( size_t  pos,
wxMenu menu,
const wxString title 
) [virtual]

Inserts the menu at the given position into the menu bar.

Inserting menu at position 0 will insert it in the very beginning of it, inserting at position GetMenuCount() is the same as calling Append().

Parameters:
posThe position of the new menu in the menu bar
menuThe menu to add. wxMenuBar owns the menu and will free it.
titleThe title of the menu.
Returns:
true on success, false if an error occurred.
参照:
Append()
bool wxMenuBar::IsAttached ( ) const
bool wxMenuBar::IsChecked ( int  id) const

Determines whether an item is checked.

Parameters:
idThe menu item identifier.
Returns:
true if the item was found and is checked, false otherwise.
bool wxMenuBar::IsEnabled ( int  id) const

Determines whether an item is enabled.

Parameters:
idThe menu item identifier.
Returns:
true if the item was found and is enabled, false otherwise.
bool wxMenuBar::IsEnabledTop ( size_t  pos) const

Returns true if the menu with the given index is enabled.

Parameters:
posThe menu position (0-based)
Since:
2.9.4
static wxMenuBar* wxMenuBar::MacGetCommonMenuBar ( ) [static]

Enables you to get the global menubar on Mac, that is, the menubar displayed when the app is running without any frames open.

Returns:
The global menubar.
注意:
Only exists on Mac, other platforms do not have this method.
Availability:  only available for the wxOSX port.
static void wxMenuBar::MacSetCommonMenuBar ( wxMenuBar menubar) [static]

Enables you to set the global menubar on Mac, that is, the menubar displayed when the app is running without any frames open.

Parameters:
menubarThe menubar to set.
注意:
Only exists on Mac, other platforms do not have this method.
Availability:  only available for the wxOSX port.
virtual void wxMenuBar::Refresh ( bool  eraseBackground = true,
const wxRect rect = NULL 
) [virtual]

Redraw the menu bar.

Reimplemented from wxWindow.

virtual wxMenu* wxMenuBar::Remove ( size_t  pos) [virtual]

Removes the menu from the menu bar and returns the menu object - the caller is responsible for deleting it.

This function may be used together with Insert() to change the menubar dynamically.

参照:
Replace()
virtual wxMenu* wxMenuBar::Replace ( size_t  pos,
wxMenu menu,
const wxString title 
) [virtual]

Replaces the menu at the given position with another one.

Parameters:
posThe position of the new menu in the menu bar
menuThe menu to add.
titleThe title of the menu.
Returns:
The menu which was previously at position pos. The caller is responsible for deleting it.
参照:
Insert(), Remove()
void wxMenuBar::SetHelpString ( int  id,
const wxString helpString 
)

Sets the help string associated with a menu item.

Parameters:
idMenu item identifier.
helpStringHelp string to associate with the menu item.
参照:
GetHelpString()
void wxMenuBar::SetLabel ( int  id,
const wxString label 
)

Sets the label of a menu item.

Parameters:
idMenu item identifier.
labelMenu item label.
注意:
Use only after the menubar has been associated with a frame.
参照:
GetLabel()
void wxMenuBar::SetLabelTop ( size_t  pos,
const wxString label 
)

Sets the label of a top-level menu.

Parameters:
posThe position of a menu on the menu bar, starting from zero.
labelThe menu label.
注意:
Use only after the menubar has been associated with a frame.
Deprecated:
This function has been deprecated in favour of SetMenuLabel().
参照:
GetLabelTop()
virtual void wxMenuBar::SetMenuLabel ( size_t  pos,
const wxString label 
) [virtual]

Sets the label of a top-level menu.

Parameters:
posThe position of a menu on the menu bar, starting from zero.
labelThe menu label.
注意:
Use only after the menubar has been associated with a frame.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines