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{wxMenuBar
}{wxmenubar
},
\helpref{wxMenu
}{wxmenu
}
34 \latexignore{\rtfignore{\wxheading{Members
}}}
37 \membersection{wxMenuItem::wxMenuItem
}\label{wxmenuitemctor
}
39 \func{}{wxMenuItem
}{\param{wxMenu*
}{ parentMenu = NULL
},
\param{int
}{ id = wxID
\_SEPARATOR},
40 \param{const wxString\&
}{text = ""
},
\param{const wxString\&
}{helpString = ""
},
41 \param{wxItemKind
}{kind = wxITEM
\_NORMAL},
\param{wxMenu*
}{ subMenu = NULL
}}
43 Constructs a wxMenuItem object.
45 Menu items can be standard, or ``stock menu items'', or custom. For the
46 standard menu items (such as commands to open a file, exit the program and so
47 on, see
\helpref{stock items
}{stockitems
} for the full list) it is enough to
48 specify just the stock ID and leave
\arg{text
} and
\arg{helpString
} empty. In
49 fact, leaving at least
\arg{text
} empty for the stock menu items is strongly
50 recommended as they will have appearance and keyboard interface (including
51 standard accelerators) familiar to the user.
53 For 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
55 description (which is automatically shown by the library in the status bar when
56 the menu item is selected) in this parameter.
58 Finally note that you can e.g. use a stock menu label without using its stock
62 // use all stock properties:
63 helpMenu->Append(wxID_ABOUT);
65 // use the stock label and the stock accelerator but not the stock help string:
66 helpMenu->Append(wxID_ABOUT, wxEmptyString, wxT("My custom help string"));
68 // use all stock properties except for the bitmap:
69 wxMenuItem *mymenu = new wxMenuItem(helpMenu, wxID_ABOUT);
70 mymenu->SetBitmap(wxArtProvider::GetBitmap(wxART_WARNING));
71 helpMenu->Append(mymenu);
74 that is, stock properties are set independently one from the other.
76 \wxheading{Parameters
}
78 \docparam{parentMenu
}{Menu that the menu item belongs to.
}
80 \docparam{id
}{Identifier for this menu item, or wxID
\_SEPARATOR to indicate a separator.
}
82 \docparam{text
}{Text for the menu item, as shown on the menu. An accelerator
83 key can be specified using the ampersand '\&' character. In order to embed an
84 ampersand character in the menu item text, the ampersand must be doubled.
}
86 \docparam{helpString
}{Optional help string that will be shown on the status bar.
}
88 \docparam{kind
}{May be
{\tt wxITEM
\_SEPARATOR},
{\tt wxITEM
\_NORMAL},
89 {\tt wxITEM
\_CHECK} or
{\tt wxITEM
\_RADIO}}
91 \docparam{subMenu
}{If non-NULL, indicates that the menu item is a submenu.
}
94 \membersection{wxMenuItem::
\destruct{wxMenuItem
}}\label{wxmenuitemdtor
}
96 \func{}{\destruct{wxMenuItem
}}{\void}
101 \membersection{wxMenuItem::Check
}\label{wxmenuitemcheck
}
103 \func{void
}{Check
}{\param{bool
}{ check = true
}}
105 Checks or unchecks the menu item.
107 Note that this only works when the item is already appended to a menu.
110 \membersection{wxMenuItem::Enable
}\label{wxmenuitemenable
}
112 \func{void
}{Enable
}{\param{bool
}{ enable = true
}}
114 Enables or disables the menu item.
117 \membersection{wxMenuItem::GetBackgroundColour
}\label{wxmenuitemgetbackgroundcolour
}
119 \constfunc{wxColour\&
}{GetBackgroundColour
}{\void}
121 Returns the background colour associated with the menu item (Windows only).
124 \membersection{wxMenuItem::GetBitmap
}\label{wxmenuitemgetbitmap
}
126 \constfunc{wxBitmap\&
}{GetBitmap
}{\param{bool
}{ checked = true
}}
128 Returns the checked or unchecked bitmap (Windows only).
131 \membersection{wxMenuItem::GetFont
}\label{wxmenuitemgetfont
}
133 \constfunc{wxFont\&
}{GetFont
}{\void}
135 Returns the font associated with the menu item (Windows only).
138 \membersection{wxMenuItem::GetHelp
}\label{wxmenuitemgethelp
}
140 \constfunc{wxString
}{GetHelp
}{\void}
142 Returns the help string associated with the menu item.
145 \membersection{wxMenuItem::GetId
}\label{wxmenuitemgetid
}
147 \constfunc{int
}{GetId
}{\void}
149 Returns the menu item identifier.
152 \membersection{wxMenuItem::GetKind
}\label{wxmenuitemgetkind
}
154 \constfunc{wxItemKind
}{GetKind
}{\void}
156 Returns the item kind, one of
{\tt wxITEM
\_SEPARATOR},
{\tt wxITEM
\_NORMAL},
157 {\tt wxITEM
\_CHECK} or
{\tt wxITEM
\_RADIO}.
160 \membersection{wxMenuItem::GetLabel
}\label{wxmenuitemgetlabel
}
162 \constfunc{wxString
}{GetLabel
}{\void}
164 Returns the text associated with the menu item without any accelerator
165 characters it might contain.
169 \helpref{GetText
}{wxmenuitemgettext
},
170 \helpref{GetLabelFromText
}{wxmenuitemgetlabelfromtext
}
173 \membersection{wxMenuItem::GetLabelFromText
}\label{wxmenuitemgetlabelfromtext
}
175 \func{static wxString
}{GetLabelFromText
}{\param{const wxString\&
}{text
}}
177 Strips all accelerator characters and mnemonics from the given
{\it text
}.
181 wxMenuItem::GetLabelFromText("&Hello
\tCtrl-H");
184 will return just
{\tt "Hello"
}.
188 \helpref{GetText
}{wxmenuitemgettext
},
189 \helpref{GetLabel
}{wxmenuitemgetlabel
}
192 \membersection{wxMenuItem::GetMarginWidth
}\label{wxmenuitemgetmarginwidth
}
194 \constfunc{int
}{GetMarginWidth
}{\void}
196 Gets the width of the menu item checkmark bitmap (Windows only).
199 \membersection{wxMenuItem::GetMenu
}\label{wxmenuitemgetmenu
}
201 \constfunc{wxMenu*
}{GetMenu
}{\void}
203 Returns the menu this menu item is in, or NULL if this menu item is not attached.
206 \membersection{wxMenuItem::GetName
}\label{wxmenuitemgetname
}
208 \constfunc{wxString
}{GetName
}{\void}
210 Returns the text associated with the menu item.
212 {\bf NB:
} this function is deprecated, please use
213 \helpref{GetText
}{wxmenuitemgettext
} or
\helpref{GetLabel
}{wxmenuitemgetlabel
}
217 \membersection{wxMenuItem::GetText
}\label{wxmenuitemgettext
}
219 \constfunc{wxString
}{GetText
}{\void}
221 Returns the text associated with the menu item, such as it was passed to the
222 wxMenuItem constructor, i.e. with any accelerator characters it may contain.
226 \helpref{GetLabel
}{wxmenuitemgetlabel
},
227 \helpref{GetLabelFromText
}{wxmenuitemgetlabelfromtext
}
230 \membersection{wxMenuItem::GetSubMenu
}\label{wxmenuitemgetsubmenu
}
232 \constfunc{wxMenu*
}{GetSubMenu
}{\void}
234 Returns the submenu associated with the menu item, or NULL if there isn't one.
237 \membersection{wxMenuItem::GetTextColour
}\label{wxmenuitemgettextcolour
}
239 \constfunc{wxColour\&
}{GetTextColour
}{\void}
241 Returns the text colour associated with the menu item (Windows only).
244 \membersection{wxMenuItem::IsCheckable
}\label{wxmenuitemischeckable
}
246 \constfunc{bool
}{IsCheckable
}{\void}
248 Returns true if the item is checkable.
251 \membersection{wxMenuItem::IsChecked
}\label{wxmenuitemischecked
}
253 \constfunc{bool
}{IsChecked
}{\void}
255 Returns true if the item is checked.
258 \membersection{wxMenuItem::IsEnabled
}\label{wxmenuitemisenabled
}
260 \constfunc{bool
}{IsEnabled
}{\void}
262 Returns true if the item is enabled.
265 \membersection{wxMenuItem::IsSeparator
}\label{wxmenuitemisseparator
}
267 \constfunc{bool
}{IsSeparator
}{\void}
269 Returns true if the item is a separator.
272 \membersection{wxMenuItem::IsSubMenu
}\label{wxmenuitemissubmenu
}
274 \constfunc{bool
}{IsSubMenu
}{\void}
276 Returns true if the item is a submenu.
279 \membersection{wxMenuItem::SetBackgroundColour
}\label{wxmenuitemsetbackgroundcolour
}
281 \constfunc{void
}{SetBackgroundColour
}{\param{const wxColour\&
}{colour
}}
283 Sets the background colour associated with the menu item (Windows only).
286 \membersection{wxMenuItem::SetBitmap
}\label{wxmenuitemsetbitmap
}
288 \func{void
}{SetBitmap
}{\param{const wxBitmap\&
}{bmp
}}
290 Sets the bitmap for the menu item (Windows and GTK+ only). It is
291 equivalent to
\helpref{SetBitmaps
}{wxmenuitemsetbitmaps
}(bmp, wxNullBitmap).
294 \membersection{wxMenuItem::SetBitmaps
}\label{wxmenuitemsetbitmaps
}
296 \func{void
}{SetBitmaps
}{\param{const wxBitmap\&
}{checked
},
297 \param{const wxBitmap\&
}{unchecked = wxNullBitmap
}}
299 Sets the checked/unchecked bitmaps for the menu item (Windows only). The first bitmap
300 is also used as the single bitmap for uncheckable menu items.
303 \membersection{wxMenuItem::SetFont
}\label{wxmenuitemsetfont
}
305 \func{void
}{SetFont
}{\param{const wxFont\&
}{font
}}
307 Sets the font associated with the menu item (Windows only).
310 \membersection{wxMenuItem::SetHelp
}\label{wxmenuitemsethelp
}
312 \func{void
}{SetHelp
}{\param{const wxString\&
}{helpString
}}
314 Sets the help string.
317 \membersection{wxMenuItem::SetMarginWidth
}\label{wxmenuitemsetmarginwidth
}
319 \constfunc{void
}{SetMarginWidth
}{\param{int
}{ width
}}
321 Sets the width of the menu item checkmark bitmap (Windows only).
324 \membersection{wxMenuItem::SetMenu
}\label{wxmenuitemsetmenu
}
326 \func{void
}{SetMenu
}{\param{const wxMenu*
}{menu
}}
328 Sets the parent menu which will contain this menu item.
331 \membersection{wxMenuItem::SetSubMenu
}\label{wxmenuitemsetsubmenu
}
333 \func{void
}{SetSubMenu
}{\param{const wxMenu*
}{menu
}}
335 Sets the submenu of this menu item.
338 \membersection{wxMenuItem::SetText
}\label{wxmenuitemsettext
}
340 \func{void
}{SetText
}{\param{const wxString\&
}{text
}}
342 Sets the text associated with the menu item.
345 \membersection{wxMenuItem::SetTextColour
}\label{wxmenuitemsettextcolour
}
347 \func{void
}{SetTextColour
}{\param{const wxColour\&
}{colour
}}
349 Sets the text colour associated with the menu item (Windows only).