menu.tex
来自「Wxpython Implemented on Windows CE, Sou」· TEX 代码 · 共 1,140 行 · 第 1/3 页
TEX
1,140 行
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Name: menu.tex
%% Purpose: wxMenu documentation
%% Author: wxWidgets Team
%% Modified by:
%% Created:
%% RCS-ID: $Id: menu.tex,v 1.64 2006/07/06 00:17:50 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 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 $-1$ is a separator item and doesn't have an
associated command but just makes a separator line appear in the menu.
{\bf NB:} Please note that {\it wxID\_ABOUT} and {\it 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 X
and will be inserted into the system menu (following the appropriate
MacOS X interface guideline). On PalmOS {\it wxID\_EXIT} is disabled according
to Palm OS Companion guidelines.
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 \helpref{IsChecked}{wxmenuischecked} method
of wxMenu or wxMenuBar itself or by using
\helpref{wxEvent::IsChecked}{wxcommandeventischecked} 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. Finally note that radio items
are not supported under Motif.
\wxheading{Allocation strategy}
All menus except the popup ones must be created on the heap. All menus
attached to a menubar or to another menu will be deleted by their parent when
it is deleted. As the frame menubar is deleted by the frame itself, it means
that 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 of
this 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 should
not 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 window
it was last popped up on) when being destroyed. Therefore, make sure
you delete or re-use the popup menu {\it before} destroying the
parent window. Re-use in this context means popping up the menu on
a different window from last time, which causes an implicit destruction
and 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 parent
menu {\it after} you have added your menu items, or accelerators may not be
registered properly.
\func{wxMenuItem*}{Append}{\param{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.
\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 displays
this string in the status line.}
\docparam{menuItem}{A menuitem object. It will be owned by the wxMenu object after this function
is called, so do not delete it yourself.}
\wxheading{Remarks}
This command can be used after the menu has been shown, as well as on initial
creation 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 item
from keyboard. The accelerator string follows the item label and is separated
from it by a {\tt TAB} character ({\tt '$\backslash$t'}). Its general syntax is
any combination of {\tt "CTRL"}, {\tt "ALT"} and {\tt "SHIFT"} strings (case
doesn't matter) separated by either {\tt '-'} or {\tt '+'} characters and
followed by the accelerator itself. The accelerator may be any alphanumeric
character, any function key (from {\tt F1} to {\tt F12}) or one of the special
characters 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, wxPython
implements 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 a
group and when an item in the group is checked, all the others are
automatically 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 the
menu for it and \arg{help} is the help string shown in the status bar when the
submenu 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 to
delete 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 will
be 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 list
context 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's
parent menu (if the item was found)}
\wxheading{Return value}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?