📄 menu.tex
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Name: menu.tex%% Purpose: wxMenu documentation%% Author: wxWidgets Team%% Modified by:%% Created: %% RCS-ID: $Id: menu.tex,v 1.66 2006/10/25 00:00:22 VZ Exp $%% Copyright: (c) wxWidgets Team%% License: wxWindows license%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\section{\class{wxMenu}}\label{wxmenu}A menu is a popup (or pull down) list of items, one of which may beselected before the menu goes away (clicking elsewhere dismisses themenu). 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 toidentify the selection, or to change the menu item in some way. A menu itemwith a special identifier $-1$ is a separator item and doesn't have anassociated command but just makes a separator line appear in the menu.{\bf NB:} Please note that {\it wxID\_ABOUT} and {\it wxID\_EXIT} arepredefined by wxWidgets and have a special meaning since entriesusing these IDs will be taken out of the normal menus under MacOS Xand will be inserted into the system menu (following the appropriateMacOS X interface guideline). On PalmOS {\it wxID\_EXIT} is disabled accordingto Palm OS Companion guidelines.Menu items may be either normal items, check items or radio items. Normal itemsdon't have any special properties while the check items have a boolean flagassociated 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 itsvalue may be retrieved using either \helpref{IsChecked}{wxmenuischecked} methodof wxMenu or wxMenuBar itself or by using \helpref{wxEvent::IsChecked}{wxcommandeventischecked} when you get the menunotification for the item in question.The radio items are similar to the check items except that all the other itemsin the same radio group are unchecked when a radio item is checked. The radiogroup is formed by a contiguous range of radio items, i.e. it starts at thefirst item of this kind and ends with the first item of a different kind (orthe end of the menu). Notice that because the radio groups are defined in termsof the item positions inserting or removing the items in the menu containingthe radio items risks to not work correctly. Finally note that radio itemsare not supported under Motif.\wxheading{Allocation strategy}All menus except the popup ones must be created on the heap. All menusattached to a menubar or to another menu will be deleted by their parent whenit is deleted. As the frame menubar is deleted by the frame itself, it meansthat normally all menus used are deleted automatically.\wxheading{Derived from}\helpref{wxEvtHandler}{wxevthandler}\\\helpref{wxObject}{wxobject}\wxheading{Include files}<wx/menu.h>\wxheading{Event handling}If the menu is part of a menubar, then \helpref{wxMenuBar}{wxmenubar} event processing is used.With a popup menu, there is a variety of ways to handle a menu selection event(wxEVT\_COMMAND\_MENU\_SELECTED).\begin{enumerate}\itemsep=0pt\item Derive a new class from wxMenu and define event table entries using the EVT\_MENU macro.\item Set a new event handler for wxMenu, using an object whose class has EVT\_MENU entries.\item Provide EVT\_MENU handlers in the window which pops up the menu, or in an ancestor ofthis window.\item Define a callback of type wxFunction, which you pass to the wxMenu constructor.The callback takes a reference to the menu, and a reference to a\helpref{wxCommandEvent}{wxcommandevent}. This method is deprecated and shouldnot be used in the new code, it is provided for backwards compatibility only.\end{enumerate}\wxheading{See also}\helpref{wxMenuBar}{wxmenubar}, \helpref{wxWindow::PopupMenu}{wxwindowpopupmenu},\rtfsp\helpref{Event handling overview}{eventhandlingoverview},\rtfsp\helpref{wxFileHistory (most recently used files menu)}{wxfilehistory}\latexignore{\rtfignore{\wxheading{Members}}}\membersection{wxMenu::wxMenu}\label{wxmenuctor}\func{}{wxMenu}{\param{const wxString\& }{title = ""}, \param{long}{ style = 0}}Constructs a wxMenu object.\wxheading{Parameters}\docparam{title}{A title for the popup menu: the empty string denotes no title.}\docparam{style}{If set to {\tt wxMENU\_TEAROFF}, the menu will be detachable (wxGTK only).}\func{}{wxMenu}{\param{long}{ style}}Constructs a wxMenu object.\wxheading{Parameters}\docparam{style}{If set to {\tt wxMENU\_TEAROFF}, the menu will be detachable (wxGTK only).}\membersection{wxMenu::\destruct{wxMenu}}\label{wxmenudtor}\func{}{\destruct{wxMenu}}{\void}Destructor, destroying the menu.Note: under Motif, a popup menu must have a valid parent (the windowit was last popped up on) when being destroyed. Therefore, make sureyou delete or re-use the popup menu {\it before} destroying theparent window. Re-use in this context means popping up the menu ona different window from last time, which causes an implicit destructionand recreation of internal data structures.\membersection{wxMenu::Append}\label{wxmenuappend}\func{wxMenuItem*}{Append}{\param{int}{ id}, \param{const wxString\& }{ item = ""}, \param{const wxString\& }{helpString = ""},\rtfsp\param{wxItemKind}{ kind = wxITEM\_NORMAL}}Adds a string item to the end of the menu.\func{wxMenuItem*}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{wxMenu *}{subMenu},\rtfsp\param{const wxString\& }{helpString = ""}}Adds a pull-right submenu to the end of the menu. Append the submenu to the parentmenu {\it after} you have added your menu items, or accelerators may not beregistered properly.\func{wxMenuItem*}{Append}{\param{wxMenuItem*}{ menuItem}}Adds a menu item object. This is the most generic variant of Append() methodbecause it may be used for both items (including separators) and submenus andbecause you can also specify various extra properties of a menu item this way,such as bitmaps and fonts.\wxheading{Parameters}\docparam{id}{The menu command identifier.}\docparam{item}{The string to appear on the menu item.}\docparam{menu}{Pull-right submenu.}\docparam{kind}{May be {\tt wxITEM\_SEPARATOR}, {\tt wxITEM\_NORMAL}, {\tt wxITEM\_CHECK} or {\tt wxITEM\_RADIO}}\docparam{helpString}{An optional help string associated with the item.By default, the handler for the wxEVT\_MENU\_HIGHLIGHT event displaysthis string in the status line.}\docparam{menuItem}{A menuitem object. It will be owned by the wxMenu object after this functionis called, so do not delete it yourself.}\wxheading{Remarks}This command can be used after the menu has been shown, as well as on initialcreation of a menu or menubar.The {\it item} string for the normal menu items (not submenus or separators)may include the accelerator which can be used to activate the menu itemfrom keyboard. The accelerator string follows the item label and is separatedfrom it by a {\tt TAB} character ({\tt '$\backslash$t'}). Its general syntax isany combination of {\tt "CTRL"}, {\tt "ALT"} and {\tt "SHIFT"} strings (casedoesn't matter) separated by either {\tt '-'} or {\tt '+'} characters andfollowed by the accelerator itself. The accelerator may be any alphanumericcharacter, any function key (from {\tt F1} to {\tt F12}) or one of the specialcharacters listed in the table below (again, case doesn't matter):\begin{twocollist}\itemsep=0pt\twocolitem{{\tt DEL} or {\tt DELETE}}{Delete key}\twocolitem{{\tt INS} or {\tt INSERT}}{Insert key}\twocolitem{{\tt ENTER} or {\tt RETURN}}{Enter key}\twocolitem{{\tt PGUP}}{PageUp key}\twocolitem{{\tt PGDN}}{PageDown key}\twocolitem{{\tt LEFT}}{Left cursor arrow key}\twocolitem{{\tt RIGHT}}{Right cursor arrow key}\twocolitem{{\tt UP}}{Up cursor arrow key}\twocolitem{{\tt DOWN}}{Down cursor arrow key}\twocolitem{{\tt HOME}}{Home key}\twocolitem{{\tt END}}{End key}\twocolitem{{\tt SPACE}}{Space}\twocolitem{{\tt TAB}}{Tab key}\twocolitem{{\tt ESC} or {\tt ESCAPE}}{Escape key (Windows only)}\end{twocollist}\wxheading{See also}\helpref{wxMenu::AppendSeparator}{wxmenuappendseparator},\rtfsp\helpref{wxMenu::AppendCheckItem}{wxmenuappendcheckitem},\rtfsp\helpref{wxMenu::AppendRadioItem}{wxmenuappendradioitem},\rtfsp\helpref{wxMenu::AppendSubMenu}{wxmenuappendsubmenu},\rtfsp\helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp\helpref{wxMenu::SetLabel}{wxmenusetlabel}, \helpref{wxMenu::GetHelpString}{wxmenugethelpstring},\rtfsp\helpref{wxMenu::SetHelpString}{wxmenusethelpstring}, \helpref{wxMenuItem}{wxmenuitem}\pythonnote{In place of a single overloaded method name, wxPythonimplements the following methods:\indented{2cm}{\begin{twocollist}\twocolitem{{\bf Append(id, string, helpStr="", checkable=false)}}{}\twocolitem{{\bf AppendMenu(id, string, aMenu, helpStr="")}}{}\twocolitem{{\bf AppendItem(aMenuItem)}}{}\end{twocollist}}}\membersection{wxMenu::AppendCheckItem}\label{wxmenuappendcheckitem}\func{wxMenuItem*}{AppendCheckItem}{\param{int}{ id},\rtfsp\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}Adds a checkable item to the end of the menu.\wxheading{See also}\helpref{wxMenu::Append}{wxmenuappend},\rtfsp\helpref{wxMenu::InsertCheckItem}{wxmenuinsertcheckitem}\membersection{wxMenu::AppendRadioItem}\label{wxmenuappendradioitem}\func{wxMenuItem*}{AppendRadioItem}{\param{int}{ id},\rtfsp\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}Adds a radio item to the end of the menu. All consequent radio items form agroup and when an item in the group is checked, all the others areautomatically unchecked.\wxheading{See also}\helpref{wxMenu::Append}{wxmenuappend},\rtfsp\helpref{wxMenu::InsertRadioItem}{wxmenuinsertradioitem}\membersection{wxMenu::AppendSeparator}\label{wxmenuappendseparator}\func{wxMenuItem*}{AppendSeparator}{\void}Adds a separator to the end of the menu.\wxheading{See also}\helpref{wxMenu::Append}{wxmenuappend},\rtfsp\helpref{wxMenu::InsertSeparator}{wxmenuinsertseparator}\membersection{wxMenu::AppendSubMenu}\label{wxmenuappendsubmenu}\func{wxMenuItem *}{AppendSubMenu}{\param{wxMenu *}{submenu}, \param{const wxString\& }{text}, \param{const wxString\& }{help = wxEmptyString}}Adds the given \arg{submenu} to this menu. \arg{text} is the text shown in themenu for it and \arg{help} is the help string shown in the status bar when thesubmenu item is selected.\membersection{wxMenu::Break}\label{wxmenubreak}\func{void}{Break}{\void}Inserts a break in a menu, causing the next appended item to appear in a new column.\membersection{wxMenu::Check}\label{wxmenucheck}\func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}}Checks or unchecks the menu item.\wxheading{Parameters}\docparam{id}{The menu item identifier.}\docparam{check}{If true, the item will be checked, otherwise it will be unchecked.}\wxheading{See also}\helpref{wxMenu::IsChecked}{wxmenuischecked}\membersection{wxMenu::Delete}\label{wxmenudelete}\func{void}{Delete}{\param{int }{id}}\func{void}{Delete}{\param{wxMenuItem *}{item}}Deletes the menu item from the menu. If the item is a submenu, it will{\bf not} be deleted. Use \helpref{Destroy}{wxmenudestroy} if you want todelete a submenu.\wxheading{Parameters}\docparam{id}{Id of the menu item to be deleted.}\docparam{item}{Menu item to be deleted.}\wxheading{See also}\helpref{wxMenu::FindItem}{wxmenufinditem},\rtfsp\helpref{wxMenu::Destroy}{wxmenudestroy},\rtfsp\helpref{wxMenu::Remove}{wxmenuremove}\membersection{wxMenu::Destroy}\label{wxmenudestroy}\func{void}{Destroy}{\param{int }{id}}\func{void}{Destroy}{\param{wxMenuItem *}{item}}Deletes the menu item from the menu. If the item is a submenu, it willbe deleted. Use \helpref{Remove}{wxmenuremove} if you want to keep the submenu(for example, to reuse it later).\wxheading{Parameters}\docparam{id}{Id of the menu item to be deleted.}\docparam{item}{Menu item to be deleted.}\wxheading{See also}\helpref{wxMenu::FindItem}{wxmenufinditem},\rtfsp\helpref{wxMenu::Deletes}{wxmenudelete},\rtfsp\helpref{wxMenu::Remove}{wxmenuremove}\membersection{wxMenu::Enable}\label{wxmenuenable}\func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}}Enables or disables (greys out) a menu item.\wxheading{Parameters}\docparam{id}{The menu item identifier.}\docparam{enable}{true to enable the menu item, false to disable it.}\wxheading{See also}\helpref{wxMenu::IsEnabled}{wxmenuisenabled}\membersection{wxMenu::FindItem}\label{wxmenufinditem}\constfunc{int}{FindItem}{\param{const wxString\& }{itemString}}Finds the menu item id for a menu item string.\constfunc{wxMenuItem *}{FindItem}{\param{int}{ id}, \param{wxMenu **}{menu = NULL}}Finds the menu item object associated with the given menu item identifier and,optionally, the (sub)menu it belongs to.\perlnote{In wxPerl this method takes just the {\tt id} parameter;in scalar context it returns the associated {\tt Wx::MenuItem}, in listcontext it returns a 2-element list {\tt ( item, submenu )}}\wxheading{Parameters}\docparam{itemString}{Menu item string to find.}\docparam{id}{Menu item identifier.}\docparam{menu}{If the pointer is not NULL, it will be filled with the item'sparent menu (if the item was found)}\wxheading{Return value}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -