]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/menuitem.tex
another patch bring the docs more up to date (patch 1717776)
[wxWidgets.git] / docs / latex / wx / menuitem.tex
CommitLineData
66760199
WS
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%% Name: menuitem.tex
3%% Purpose: wxMenuItem documentation
4%% Author: wxWidgets Team
5%% Modified by:
6%% Created:
7%% RCS-ID: $Id$
8%% Copyright: (c) wxWidgets Team
9%% License: wxWindows license
10%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
a660d684
KB
12\section{\class{wxMenuItem}}\label{wxmenuitem}
13
d65c269b
VZ
14A menu item represents an item in a menu. Note that you usually don't have to
15deal with it directly as \helpref{wxMenu}{wxmenu} methods usually construct an
16object of this class for you.
17
18Also please note that the methods related to fonts and bitmaps are currently
c436b310 19only implemented for Windows and GTK+.
a660d684
KB
20
21\wxheading{Derived from}
22
8dbb7967 23% add wxOwnerDrawn once it is documented
a660d684
KB
24\helpref{wxObject}{wxobject}
25
954b8ae6
JS
26\wxheading{Include files}
27
28<wx/menuitem.h>
29
a660d684
KB
30\wxheading{See also}
31
2432b92d 32\helpref{wxMenuBar}{wxmenubar}, \helpref{wxMenu}{wxmenu}
a660d684
KB
33
34\latexignore{\rtfignore{\wxheading{Members}}}
35
1892d641 36
dcbd177f 37\membersection{wxMenuItem::wxMenuItem}\label{wxmenuitemctor}
a660d684 38
0ed48c11 39\func{}{wxMenuItem}{\param{wxMenu*}{ parentMenu = NULL}, \param{int}{ id = wxID\_SEPARATOR},
a660d684 40 \param{const wxString\& }{text = ""}, \param{const wxString\& }{helpString = ""},
3980000c 41 \param{wxItemKind }{kind = wxITEM\_NORMAL}, \param{wxMenu*}{ subMenu = NULL}}
a660d684
KB
42
43Constructs a wxMenuItem object.
44
345319d6
VZ
45Menu items can be standard, or ``stock menu items'', or custom. For the
46standard menu items (such as commands to open a file, exit the program and so
47on, see \helpref{stock items}{stockitems} for the full list) it is enough to
48specify just the stock ID and leave \arg{text} and \arg{helpString} empty. In
49fact, leaving at least \arg{text} empty for the stock menu items is strongly
50recommended as they will have appearance and keyboard interface (including
51standard accelerators) familiar to the user.
52
53For the custom (non-stock) menu items, \arg{text} must be specified and while
54\arg{helpString} may be left empty, it's recommended to pass the item
55description (which is automatically shown by the library in the status bar when
56the menu item is selected) in this parameter.
57
58Finally note that you can e.g. use a stock menu label without using its stock
59help string:
60
61\begin{verbatim}
62// use all stock properties:
63helpMenu->Append(wxID_ABOUT);
64
65// use the stock label and the stock accelerator but not the stock help string:
66helpMenu->Append(wxID_ABOUT, wxEmptyString, wxT("My custom help string"));
67
68// use all stock properties except for the bitmap:
69wxMenuItem *mymenu = new wxMenuItem(helpMenu, wxID_ABOUT);
70mymenu->SetBitmap(wxArtProvider::GetBitmap(wxART_WARNING));
71helpMenu->Append(mymenu);
72\end{verbatim}
73
74that is, stock properties are set independently one from the other.
ee0a94cf 75
a660d684
KB
76\wxheading{Parameters}
77
78\docparam{parentMenu}{Menu that the menu item belongs to.}
79
0ed48c11 80\docparam{id}{Identifier for this menu item, or wxID\_SEPARATOR to indicate a separator.}
a660d684 81
2b5f62a0
VZ
82\docparam{text}{Text for the menu item, as shown on the menu. An accelerator
83key can be specified using the ampersand '\&' character. In order to embed an
84ampersand character in the menu item text, the ampersand must be doubled.}
a660d684
KB
85
86\docparam{helpString}{Optional help string that will be shown on the status bar.}
87
8def689d
VZ
88\docparam{kind}{May be {\tt wxITEM\_SEPARATOR}, {\tt wxITEM\_NORMAL},
89{\tt wxITEM\_CHECK} or {\tt wxITEM\_RADIO}}
a660d684
KB
90
91\docparam{subMenu}{If non-NULL, indicates that the menu item is a submenu.}
92
1892d641 93
dcbd177f 94\membersection{wxMenuItem::\destruct{wxMenuItem}}\label{wxmenuitemdtor}
a660d684
KB
95
96\func{}{\destruct{wxMenuItem}}{\void}
97
98Destructor.
99
1892d641 100
a660d684
KB
101\membersection{wxMenuItem::Check}\label{wxmenuitemcheck}
102
3980000c 103\func{void}{Check}{\param{bool}{ check = true}}
a660d684
KB
104
105Checks or unchecks the menu item.
106
1892d641
VZ
107Note that this only works when the item is already appended to a menu.
108
109
a660d684
KB
110\membersection{wxMenuItem::Enable}\label{wxmenuitemenable}
111
3980000c 112\func{void}{Enable}{\param{bool}{ enable = true}}
a660d684
KB
113
114Enables or disables the menu item.
115
1892d641 116
a660d684
KB
117\membersection{wxMenuItem::GetBackgroundColour}\label{wxmenuitemgetbackgroundcolour}
118
119\constfunc{wxColour\&}{GetBackgroundColour}{\void}
120
121Returns the background colour associated with the menu item (Windows only).
122
1892d641 123
a660d684
KB
124\membersection{wxMenuItem::GetBitmap}\label{wxmenuitemgetbitmap}
125
cc81d32f 126\constfunc{wxBitmap\&}{GetBitmap}{\param{bool}{ checked = true}}
a660d684
KB
127
128Returns the checked or unchecked bitmap (Windows only).
129
1892d641 130
a660d684
KB
131\membersection{wxMenuItem::GetFont}\label{wxmenuitemgetfont}
132
133\constfunc{wxFont\&}{GetFont}{\void}
134
135Returns the font associated with the menu item (Windows only).
136
1892d641 137
a660d684
KB
138\membersection{wxMenuItem::GetHelp}\label{wxmenuitemgethelp}
139
140\constfunc{wxString}{GetHelp}{\void}
141
142Returns the help string associated with the menu item.
143
1892d641 144
a660d684
KB
145\membersection{wxMenuItem::GetId}\label{wxmenuitemgetid}
146
147\constfunc{int}{GetId}{\void}
148
149Returns the menu item identifier.
150
1892d641 151
d65c269b
VZ
152\membersection{wxMenuItem::GetKind}\label{wxmenuitemgetkind}
153
154\constfunc{wxItemKind}{GetKind}{\void}
155
8def689d
VZ
156Returns the item kind, one of {\tt wxITEM\_SEPARATOR}, {\tt wxITEM\_NORMAL},
157{\tt wxITEM\_CHECK} or {\tt wxITEM\_RADIO}.
d65c269b 158
1892d641 159
64a89766
VZ
160\membersection{wxMenuItem::GetLabel}\label{wxmenuitemgetlabel}
161
162\constfunc{wxString}{GetLabel}{\void}
163
164Returns the text associated with the menu item without any accelerator
2edb0bde 165characters it might contain.
64a89766
VZ
166
167\wxheading{See also}
168
fa482912 169\helpref{GetText}{wxmenuitemgettext},
3b59cdbf
VZ
170\helpref{GetLabelFromText}{wxmenuitemgetlabelfromtext}
171
1892d641 172
3b59cdbf
VZ
173\membersection{wxMenuItem::GetLabelFromText}\label{wxmenuitemgetlabelfromtext}
174
175\func{static wxString}{GetLabelFromText}{\param{const wxString\& }{text}}
176
2edb0bde 177Strips all accelerator characters and mnemonics from the given {\it text}.
3b59cdbf
VZ
178For example,
179
180\begin{verbatim}
181wxMenuItem::GetLabelFromText("&Hello\tCtrl-H");
182\end{verbatim}
183
184will return just {\tt "Hello"}.
185
186\wxheading{See also}
187
fa482912 188\helpref{GetText}{wxmenuitemgettext},
3b59cdbf 189\helpref{GetLabel}{wxmenuitemgetlabel}
64a89766 190
1892d641 191
a660d684
KB
192\membersection{wxMenuItem::GetMarginWidth}\label{wxmenuitemgetmarginwidth}
193
194\constfunc{int}{GetMarginWidth}{\void}
195
196Gets the width of the menu item checkmark bitmap (Windows only).
197
1892d641 198
66760199
WS
199\membersection{wxMenuItem::GetMenu}\label{wxmenuitemgetmenu}
200
201\constfunc{wxMenu*}{GetMenu}{\void}
202
203Returns the menu this menu item is in, or NULL if this menu item is not attached.
204
205
a660d684
KB
206\membersection{wxMenuItem::GetName}\label{wxmenuitemgetname}
207
208\constfunc{wxString}{GetName}{\void}
209
210Returns the text associated with the menu item.
211
64a89766
VZ
212{\bf NB:} this function is deprecated, please use
213\helpref{GetText}{wxmenuitemgettext} or \helpref{GetLabel}{wxmenuitemgetlabel}
214instead.
215
1892d641 216
64a89766
VZ
217\membersection{wxMenuItem::GetText}\label{wxmenuitemgettext}
218
219\constfunc{wxString}{GetText}{\void}
220
221Returns the text associated with the menu item, such as it was passed to the
222wxMenuItem constructor, i.e. with any accelerator characters it may contain.
223
224\wxheading{See also}
225
fa482912 226\helpref{GetLabel}{wxmenuitemgetlabel},
3b59cdbf 227\helpref{GetLabelFromText}{wxmenuitemgetlabelfromtext}
64a89766 228
1892d641 229
a660d684
KB
230\membersection{wxMenuItem::GetSubMenu}\label{wxmenuitemgetsubmenu}
231
232\constfunc{wxMenu*}{GetSubMenu}{\void}
233
234Returns the submenu associated with the menu item, or NULL if there isn't one.
235
1892d641 236
a660d684
KB
237\membersection{wxMenuItem::GetTextColour}\label{wxmenuitemgettextcolour}
238
239\constfunc{wxColour\&}{GetTextColour}{\void}
240
241Returns the text colour associated with the menu item (Windows only).
242
1892d641 243
a660d684
KB
244\membersection{wxMenuItem::IsCheckable}\label{wxmenuitemischeckable}
245
246\constfunc{bool}{IsCheckable}{\void}
247
cc81d32f 248Returns true if the item is checkable.
a660d684 249
1892d641 250
a660d684
KB
251\membersection{wxMenuItem::IsChecked}\label{wxmenuitemischecked}
252
253\constfunc{bool}{IsChecked}{\void}
254
cc81d32f 255Returns true if the item is checked.
a660d684 256
1892d641 257
a660d684
KB
258\membersection{wxMenuItem::IsEnabled}\label{wxmenuitemisenabled}
259
260\constfunc{bool}{IsEnabled}{\void}
261
cc81d32f 262Returns true if the item is enabled.
a660d684 263
1892d641 264
a660d684
KB
265\membersection{wxMenuItem::IsSeparator}\label{wxmenuitemisseparator}
266
267\constfunc{bool}{IsSeparator}{\void}
268
cc81d32f 269Returns true if the item is a separator.
a660d684 270
1892d641 271
c87957c2
WS
272\membersection{wxMenuItem::IsSubMenu}\label{wxmenuitemissubmenu}
273
274\constfunc{bool}{IsSubMenu}{\void}
275
276Returns true if the item is a submenu.
277
278
a660d684
KB
279\membersection{wxMenuItem::SetBackgroundColour}\label{wxmenuitemsetbackgroundcolour}
280
e14dccff 281\constfunc{void}{SetBackgroundColour}{\param{const wxColour\& }{colour}}
a660d684
KB
282
283Sets the background colour associated with the menu item (Windows only).
284
1892d641 285
0996d32a
VS
286\membersection{wxMenuItem::SetBitmap}\label{wxmenuitemsetbitmap}
287
66760199 288\func{void}{SetBitmap}{\param{const wxBitmap\& }{bmp}}
0996d32a
VS
289
290Sets the bitmap for the menu item (Windows and GTK+ only). It is
291equivalent to \helpref{SetBitmaps}{wxmenuitemsetbitmaps}(bmp, wxNullBitmap).
292
1892d641 293
a660d684
KB
294\membersection{wxMenuItem::SetBitmaps}\label{wxmenuitemsetbitmaps}
295
66760199 296\func{void}{SetBitmaps}{\param{const wxBitmap\& }{checked},
e14dccff 297 \param{const wxBitmap\& }{unchecked = wxNullBitmap}}
a660d684
KB
298
299Sets the checked/unchecked bitmaps for the menu item (Windows only). The first bitmap
300is also used as the single bitmap for uncheckable menu items.
301
1892d641 302
a660d684
KB
303\membersection{wxMenuItem::SetFont}\label{wxmenuitemsetfont}
304
66760199 305\func{void}{SetFont}{\param{const wxFont\& }{font}}
a660d684
KB
306
307Sets the font associated with the menu item (Windows only).
308
1892d641 309
a660d684
KB
310\membersection{wxMenuItem::SetHelp}\label{wxmenuitemsethelp}
311
66760199 312\func{void}{SetHelp}{\param{const wxString\& }{helpString}}
a660d684
KB
313
314Sets the help string.
315
1892d641 316
a660d684
KB
317\membersection{wxMenuItem::SetMarginWidth}\label{wxmenuitemsetmarginwidth}
318
319\constfunc{void}{SetMarginWidth}{\param{int}{ width}}
320
321Sets the width of the menu item checkmark bitmap (Windows only).
322
1892d641 323
66760199
WS
324\membersection{wxMenuItem::SetMenu}\label{wxmenuitemsetmenu}
325
326\func{void}{SetMenu}{\param{const wxMenu*}{menu}}
327
328Sets the parent menu which will contain this menu item.
329
330
331\membersection{wxMenuItem::SetSubMenu}\label{wxmenuitemsetsubmenu}
332
333\func{void}{SetSubMenu}{\param{const wxMenu*}{menu}}
334
335Sets the submenu of this menu item.
336
337
4e6978c3 338\membersection{wxMenuItem::SetText}\label{wxmenuitemsettext}
a660d684 339
66760199 340\func{void}{SetText}{\param{const wxString\& }{text}}
a660d684
KB
341
342Sets the text associated with the menu item.
343
1892d641 344
a660d684
KB
345\membersection{wxMenuItem::SetTextColour}\label{wxmenuitemsettextcolour}
346
66760199 347\func{void}{SetTextColour}{\param{const wxColour\& }{colour}}
a660d684
KB
348
349Sets the text colour associated with the menu item (Windows only).
350