1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% Purpose: wxMenuItem documentation
4 %% Author: wxWidgets Team
8 %% Copyright: (c) wxWidgets Team
9 %% License: wxWindows license
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 \section{\class{wxMenuItem
}}\label{wxmenuitem
}
14 A menu item represents an item in a menu. Note that you usually don't have to
15 deal with it directly as
\helpref{wxMenu
}{wxmenu
} methods usually construct an
16 object of this class for you.
18 Also please note that the methods related to fonts and bitmaps are currently
19 only implemented for Windows and GTK+.
21 \wxheading{Derived from
}
23 % add wxOwnerDrawn once it is documented
24 \helpref{wxObject
}{wxobject
}
26 \wxheading{Include files
}
32 \helpref{wxCore
}{librarieslist
}
36 \helpref{wxMenuBar
}{wxmenubar
},
\helpref{wxMenu
}{wxmenu
}
38 \latexignore{\rtfignore{\wxheading{Members
}}}
41 \membersection{wxMenuItem::wxMenuItem
}\label{wxmenuitemctor
}
43 \func{}{wxMenuItem
}{\param{wxMenu*
}{ parentMenu = NULL
},
\param{int
}{ id = wxID
\_SEPARATOR},
44 \param{const wxString\&
}{text = ""
},
\param{const wxString\&
}{helpString = ""
},
45 \param{wxItemKind
}{kind = wxITEM
\_NORMAL},
\param{wxMenu*
}{ subMenu = NULL
}}
47 Constructs a wxMenuItem object.
49 Menu items can be standard, or ``stock menu items'', or custom. For the
50 standard menu items (such as commands to open a file, exit the program and so
51 on, see
\helpref{stock items
}{stockitems
} for the full list) it is enough to
52 specify just the stock ID and leave
\arg{text
} and
\arg{helpString
} empty. In
53 fact, leaving at least
\arg{text
} empty for the stock menu items is strongly
54 recommended as they will have appearance and keyboard interface (including
55 standard accelerators) familiar to the user.
57 For the custom (non-stock) menu items,
\arg{text
} must be specified and while
58 \arg{helpString
} may be left empty, it's recommended to pass the item
59 description (which is automatically shown by the library in the status bar when
60 the menu item is selected) in this parameter.
62 Finally note that you can e.g. use a stock menu label without using its stock
66 // use all stock properties:
67 helpMenu->Append(wxID_ABOUT);
69 // use the stock label and the stock accelerator but not the stock help string:
70 helpMenu->Append(wxID_ABOUT, wxEmptyString, wxT("My custom help string"));
72 // use all stock properties except for the bitmap:
73 wxMenuItem *mymenu = new wxMenuItem(helpMenu, wxID_ABOUT);
74 mymenu->SetBitmap(wxArtProvider::GetBitmap(wxART_WARNING));
75 helpMenu->Append(mymenu);
78 that is, stock properties are set independently one from the other.
80 \wxheading{Parameters
}
82 \docparam{parentMenu
}{Menu that the menu item belongs to.
}
84 \docparam{id
}{Identifier for this menu item, or wxID
\_SEPARATOR to indicate a separator.
}
86 \docparam{text
}{Text for the menu item, as shown on the menu. An accelerator
87 key can be specified using the ampersand '\&' character. In order to embed an
88 ampersand character in the menu item text, the ampersand must be doubled.
}
90 \docparam{helpString
}{Optional help string that will be shown on the status bar.
}
92 \docparam{kind
}{May be
{\tt wxITEM
\_SEPARATOR},
{\tt wxITEM
\_NORMAL},
93 {\tt wxITEM
\_CHECK} or
{\tt wxITEM
\_RADIO}}
95 \docparam{subMenu
}{If non-NULL, indicates that the menu item is a submenu.
}
98 \membersection{wxMenuItem::
\destruct{wxMenuItem
}}\label{wxmenuitemdtor
}
100 \func{}{\destruct{wxMenuItem
}}{\void}
105 \membersection{wxMenuItem::Check
}\label{wxmenuitemcheck
}
107 \func{void
}{Check
}{\param{bool
}{ check = true
}}
109 Checks or unchecks the menu item.
111 Note that this only works when the item is already appended to a menu.
114 \membersection{wxMenuItem::Enable
}\label{wxmenuitemenable
}
116 \func{void
}{Enable
}{\param{bool
}{ enable = true
}}
118 Enables or disables the menu item.
121 \membersection{wxMenuItem::GetBackgroundColour
}\label{wxmenuitemgetbackgroundcolour
}
123 \constfunc{wxColour\&
}{GetBackgroundColour
}{\void}
125 Returns the background colour associated with the menu item (Windows only).
128 \membersection{wxMenuItem::GetBitmap
}\label{wxmenuitemgetbitmap
}
130 \constfunc{wxBitmap\&
}{GetBitmap
}{\param{bool
}{ checked = true
}}
132 Returns the checked or unchecked bitmap (Windows only).
135 \membersection{wxMenuItem::GetFont
}\label{wxmenuitemgetfont
}
137 \constfunc{wxFont\&
}{GetFont
}{\void}
139 Returns the font associated with the menu item (Windows only).
142 \membersection{wxMenuItem::GetHelp
}\label{wxmenuitemgethelp
}
144 \constfunc{wxString
}{GetHelp
}{\void}
146 Returns the help string associated with the menu item.
149 \membersection{wxMenuItem::GetId
}\label{wxmenuitemgetid
}
151 \constfunc{int
}{GetId
}{\void}
153 Returns the menu item identifier.
156 \membersection{wxMenuItem::GetItemLabel
}\label{wxmenuitemgetitemlabel
}
158 \constfunc{wxString
}{GetItemLabel
}{\void}
160 Returns the text associated with the menu item including any accelerator
161 characters that were passed to the constructor or SetItemLabel.
165 \helpref{GetItemLabelText
}{wxmenuitemgetitemlabeltext
},
166 \helpref{GetLabelText
}{wxmenuitemgetlabeltext
}
169 \membersection{wxMenuItem::GetItemLabelText
}\label{wxmenuitemgetitemlabeltext
}
171 \constfunc{wxString
}{GetItemLabelText
}{\void}
173 Returns the text associated with the menu item, without any accelerator
178 \helpref{GetItemLabel
}{wxmenuitemgetitemlabel
},
179 \helpref{GetLabelText
}{wxmenuitemgetlabeltext
}
182 \membersection{wxMenuItem::GetKind
}\label{wxmenuitemgetkind
}
184 \constfunc{wxItemKind
}{GetKind
}{\void}
186 Returns the item kind, one of
{\tt wxITEM
\_SEPARATOR},
{\tt wxITEM
\_NORMAL},
187 {\tt wxITEM
\_CHECK} or
{\tt wxITEM
\_RADIO}.
190 \membersection{wxMenuItem::GetLabel
}\label{wxmenuitemgetlabel
}
192 \constfunc{wxString
}{GetLabel
}{\void}
194 Returns the text associated with the menu item without any accelerator
195 characters it might contain.
197 This function is deprecated in favour of
\helpref{GetItemLabelText
}{wxmenuitemgetitemlabeltext
}.
201 \helpref{GetText
}{wxmenuitemgettext
},
202 \helpref{GetLabelFromText
}{wxmenuitemgetlabelfromtext
}
204 \membersection{wxMenuItem::GetLabelText
}\label{wxmenuitemgetlabeltext
}
206 \func{static wxString
}{GetLabelText
}{\param{const wxString\&
}{text
}}
208 Strips all accelerator characters and mnemonics from the given
{\it text
}.
212 wxMenuItem::GetLabelFromText("&Hello
\tCtrl-H");
215 will return just
{\tt "Hello"
}.
219 \helpref{GetItemLabelText
}{wxmenuitemgetitemlabeltext
},
220 \helpref{GetItemLabel
}{wxmenuitemgetitemlabel
}
223 \membersection{wxMenuItem::GetLabelFromText
}\label{wxmenuitemgetlabelfromtext
}
225 \func{static wxString
}{GetLabelFromText
}{\param{const wxString\&
}{text
}}
227 Strips all accelerator characters and mnemonics from the given
{\it text
}.
231 wxMenuItem::GetLabelFromText("&Hello
\tCtrl-H");
234 will return just
{\tt "Hello"
}.
236 This function is deprecated; please use
\helpref{wxMenuItem::GetLabelText
}{wxmenuitemgetlabeltext
} instead.
240 \helpref{GetText
}{wxmenuitemgettext
},
241 \helpref{GetLabel
}{wxmenuitemgetlabel
}
244 \membersection{wxMenuItem::GetMarginWidth
}\label{wxmenuitemgetmarginwidth
}
246 \constfunc{int
}{GetMarginWidth
}{\void}
248 Gets the width of the menu item checkmark bitmap (Windows only).
251 \membersection{wxMenuItem::GetMenu
}\label{wxmenuitemgetmenu
}
253 \constfunc{wxMenu*
}{GetMenu
}{\void}
255 Returns the menu this menu item is in, or NULL if this menu item is not attached.
258 \membersection{wxMenuItem::GetName
}\label{wxmenuitemgetname
}
260 \constfunc{wxString
}{GetName
}{\void}
262 Returns the text associated with the menu item.
264 {\bf NB:
} this function is deprecated, please use
265 \helpref{GetItemLabel
}{wxmenuitemgetitemlabel
} or
\helpref{GetItemLabelText
}{wxmenuitemgetitemlabeltext
}
269 \membersection{wxMenuItem::GetText
}\label{wxmenuitemgettext
}
271 \constfunc{wxString
}{GetText
}{\void}
273 Returns the text associated with the menu item, such as it was passed to the
274 wxMenuItem constructor, i.e. with any accelerator characters it may contain.
276 This function is deprecated in favour of
\helpref{GetItemLabel
}{wxmenuitemgetitemlabel
}.
280 \helpref{GetLabel
}{wxmenuitemgetlabel
},
281 \helpref{GetLabelFromText
}{wxmenuitemgetlabelfromtext
}
284 \membersection{wxMenuItem::GetSubMenu
}\label{wxmenuitemgetsubmenu
}
286 \constfunc{wxMenu*
}{GetSubMenu
}{\void}
288 Returns the submenu associated with the menu item, or NULL if there isn't one.
291 \membersection{wxMenuItem::GetTextColour
}\label{wxmenuitemgettextcolour
}
293 \constfunc{wxColour\&
}{GetTextColour
}{\void}
295 Returns the text colour associated with the menu item (Windows only).
298 \membersection{wxMenuItem::IsCheckable
}\label{wxmenuitemischeckable
}
300 \constfunc{bool
}{IsCheckable
}{\void}
302 Returns true if the item is checkable.
305 \membersection{wxMenuItem::IsChecked
}\label{wxmenuitemischecked
}
307 \constfunc{bool
}{IsChecked
}{\void}
309 Returns true if the item is checked.
312 \membersection{wxMenuItem::IsEnabled
}\label{wxmenuitemisenabled
}
314 \constfunc{bool
}{IsEnabled
}{\void}
316 Returns true if the item is enabled.
319 \membersection{wxMenuItem::IsSeparator
}\label{wxmenuitemisseparator
}
321 \constfunc{bool
}{IsSeparator
}{\void}
323 Returns true if the item is a separator.
326 \membersection{wxMenuItem::IsSubMenu
}\label{wxmenuitemissubmenu
}
328 \constfunc{bool
}{IsSubMenu
}{\void}
330 Returns true if the item is a submenu.
333 \membersection{wxMenuItem::SetBackgroundColour
}\label{wxmenuitemsetbackgroundcolour
}
335 \constfunc{void
}{SetBackgroundColour
}{\param{const wxColour\&
}{colour
}}
337 Sets the background colour associated with the menu item (Windows only).
340 \membersection{wxMenuItem::SetBitmap
}\label{wxmenuitemsetbitmap
}
342 \func{void
}{SetBitmap
}{\param{const wxBitmap\&
}{bmp
}}
344 Sets the bitmap for the menu item (Windows and GTK+ only). It is
345 equivalent to
\helpref{SetBitmaps
}{wxmenuitemsetbitmaps
}(bmp, wxNullBitmap).
348 \membersection{wxMenuItem::SetBitmaps
}\label{wxmenuitemsetbitmaps
}
350 \func{void
}{SetBitmaps
}{\param{const wxBitmap\&
}{checked
},
351 \param{const wxBitmap\&
}{unchecked = wxNullBitmap
}}
353 Sets the checked/unchecked bitmaps for the menu item (Windows only). The first bitmap
354 is also used as the single bitmap for uncheckable menu items.
357 \membersection{wxMenuItem::SetFont
}\label{wxmenuitemsetfont
}
359 \func{void
}{SetFont
}{\param{const wxFont\&
}{font
}}
361 Sets the font associated with the menu item (Windows only).
364 \membersection{wxMenuItem::SetHelp
}\label{wxmenuitemsethelp
}
366 \func{void
}{SetHelp
}{\param{const wxString\&
}{helpString
}}
368 Sets the help string.
371 \membersection{wxMenuItem::SetItemLabel
}\label{wxmenuitemsetitemlabel
}
373 \func{void
}{SetItemLabel
}{\param{const wxString\&
}{label
}}
375 Sets the label associated with the menu item.
378 \membersection{wxMenuItem::SetMarginWidth
}\label{wxmenuitemsetmarginwidth
}
380 \constfunc{void
}{SetMarginWidth
}{\param{int
}{ width
}}
382 Sets the width of the menu item checkmark bitmap (Windows only).
385 \membersection{wxMenuItem::SetMenu
}\label{wxmenuitemsetmenu
}
387 \func{void
}{SetMenu
}{\param{const wxMenu*
}{menu
}}
389 Sets the parent menu which will contain this menu item.
392 \membersection{wxMenuItem::SetSubMenu
}\label{wxmenuitemsetsubmenu
}
394 \func{void
}{SetSubMenu
}{\param{const wxMenu*
}{menu
}}
396 Sets the submenu of this menu item.
399 \membersection{wxMenuItem::SetText
}\label{wxmenuitemsettext
}
401 \func{void
}{SetText
}{\param{const wxString\&
}{text
}}
403 Sets the text associated with the menu item.
405 This function is deprecated in favour of
\helpref{SetItemLabel
}{wxmenuitemsetitemlabel
}.
408 \membersection{wxMenuItem::SetTextColour
}\label{wxmenuitemsettextcolour
}
410 \func{void
}{SetTextColour
}{\param{const wxColour\&
}{colour
}}
412 Sets the text colour associated with the menu item (Windows only).