]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: menuitem.h | |
e54c96f1 | 3 | // Purpose: interface of wxMenuItem |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxMenuItem | |
11 | @wxheader{menuitem.h} | |
7c913512 | 12 | |
23324ae1 FM |
13 | A menu item represents an item in a menu. Note that you usually don't have to |
14 | deal with it directly as wxMenu methods usually construct an | |
15 | object of this class for you. | |
7c913512 | 16 | |
23324ae1 FM |
17 | Also please note that the methods related to fonts and bitmaps are currently |
18 | only implemented for Windows and GTK+. | |
7c913512 | 19 | |
23324ae1 FM |
20 | @library{wxcore} |
21 | @category{menus} | |
7c913512 | 22 | |
e54c96f1 | 23 | @see wxMenuBar, wxMenu |
23324ae1 FM |
24 | */ |
25 | class wxMenuItem : public wxObject | |
26 | { | |
27 | public: | |
28 | /** | |
29 | Constructs a wxMenuItem object. | |
cdbcf4c2 | 30 | Menu items can be standard, or "stock menu items", or custom. For the |
23324ae1 FM |
31 | standard menu items (such as commands to open a file, exit the program and so |
32 | on, see @ref overview_stockitems "stock items" for the full list) it is enough | |
33 | to | |
4cc4bfaf FM |
34 | specify just the stock ID and leave @a text and @a helpString empty. In |
35 | fact, leaving at least @a text empty for the stock menu items is strongly | |
23324ae1 FM |
36 | recommended as they will have appearance and keyboard interface (including |
37 | standard accelerators) familiar to the user. | |
4cc4bfaf FM |
38 | For the custom (non-stock) menu items, @a text must be specified and while |
39 | @a helpString may be left empty, it's recommended to pass the item | |
23324ae1 FM |
40 | description (which is automatically shown by the library in the status bar when |
41 | the menu item is selected) in this parameter. | |
23324ae1 FM |
42 | Finally note that you can e.g. use a stock menu label without using its stock |
43 | help string: | |
3c4f71cc | 44 | |
23324ae1 | 45 | that is, stock properties are set independently one from the other. |
3c4f71cc | 46 | |
7c913512 | 47 | @param parentMenu |
4cc4bfaf | 48 | Menu that the menu item belongs to. |
7c913512 | 49 | @param id |
fa7134b0 VZ |
50 | Identifier for this menu item. May be wxID_SEPARATOR, in which case the |
51 | given kind is ignored and taken to be wxITEM_SEPARATOR instead. | |
7c913512 | 52 | @param text |
4cc4bfaf | 53 | Text for the menu item, as shown on the menu. An accelerator |
cdbcf4c2 | 54 | key can be specified using the ampersand " character. In order to embed an |
4cc4bfaf | 55 | ampersand character in the menu item text, the ampersand must be doubled. |
7c913512 | 56 | @param helpString |
4cc4bfaf | 57 | Optional help string that will be shown on the status bar. |
7c913512 | 58 | @param kind |
4cc4bfaf FM |
59 | May be wxITEM_SEPARATOR, wxITEM_NORMAL, |
60 | wxITEM_CHECK or wxITEM_RADIO | |
7c913512 | 61 | @param subMenu |
4cc4bfaf | 62 | If non-@NULL, indicates that the menu item is a submenu. |
23324ae1 | 63 | */ |
4cc4bfaf | 64 | wxMenuItem(wxMenu* parentMenu = NULL, int id = wxID_SEPARATOR, |
23324ae1 FM |
65 | const wxString& text = "", |
66 | const wxString& helpString = "", | |
67 | wxItemKind kind = wxITEM_NORMAL, | |
4cc4bfaf | 68 | wxMenu* subMenu = NULL); |
23324ae1 FM |
69 | |
70 | /** | |
71 | Destructor. | |
72 | */ | |
73 | ~wxMenuItem(); | |
74 | ||
75 | /** | |
76 | Checks or unchecks the menu item. | |
23324ae1 FM |
77 | Note that this only works when the item is already appended to a menu. |
78 | */ | |
4cc4bfaf | 79 | void Check(bool check = true); |
23324ae1 FM |
80 | |
81 | /** | |
82 | Enables or disables the menu item. | |
83 | */ | |
4cc4bfaf | 84 | void Enable(bool enable = true); |
23324ae1 FM |
85 | |
86 | /** | |
87 | Returns the background colour associated with the menu item (Windows only). | |
88 | */ | |
328f5751 | 89 | wxColour GetBackgroundColour() const; |
23324ae1 FM |
90 | |
91 | /** | |
92 | Returns the checked or unchecked bitmap (Windows only). | |
93 | */ | |
328f5751 | 94 | wxBitmap GetBitmap(bool checked = true) const; |
23324ae1 FM |
95 | |
96 | /** | |
97 | Returns the font associated with the menu item (Windows only). | |
98 | */ | |
328f5751 | 99 | wxFont GetFont() const; |
23324ae1 FM |
100 | |
101 | /** | |
102 | Returns the help string associated with the menu item. | |
103 | */ | |
328f5751 | 104 | wxString GetHelp() const; |
23324ae1 FM |
105 | |
106 | /** | |
107 | Returns the menu item identifier. | |
108 | */ | |
328f5751 | 109 | int GetId() const; |
23324ae1 FM |
110 | |
111 | /** | |
112 | Returns the text associated with the menu item including any accelerator | |
113 | characters that were passed to the constructor or SetItemLabel. | |
3c4f71cc | 114 | |
4cc4bfaf | 115 | @see GetItemLabelText(), GetLabelText() |
23324ae1 | 116 | */ |
328f5751 | 117 | wxString GetItemLabel() const; |
23324ae1 FM |
118 | |
119 | /** | |
120 | Returns the text associated with the menu item, without any accelerator | |
121 | characters. | |
3c4f71cc | 122 | |
4cc4bfaf | 123 | @see GetItemLabel(), GetLabelText() |
23324ae1 | 124 | */ |
328f5751 | 125 | wxString GetItemLabelText() const; |
23324ae1 FM |
126 | |
127 | /** | |
7c913512 | 128 | Returns the item kind, one of @c wxITEM_SEPARATOR, @c wxITEM_NORMAL, |
23324ae1 FM |
129 | @c wxITEM_CHECK or @c wxITEM_RADIO. |
130 | */ | |
328f5751 | 131 | wxItemKind GetKind() const; |
23324ae1 FM |
132 | |
133 | /** | |
134 | Returns the text associated with the menu item without any accelerator | |
135 | characters it might contain. | |
23324ae1 | 136 | This function is deprecated in favour of GetItemLabelText(). |
3c4f71cc | 137 | |
4cc4bfaf | 138 | @see GetText(), GetLabelFromText() |
23324ae1 | 139 | */ |
328f5751 | 140 | wxString GetLabel() const; |
23324ae1 FM |
141 | |
142 | /** | |
23324ae1 | 143 | This function is deprecated; please use GetLabelText() instead. |
3c4f71cc | 144 | |
4cc4bfaf | 145 | @see GetText(), GetLabel() |
23324ae1 FM |
146 | */ |
147 | static wxString GetLabelFromText(const wxString& text); | |
148 | ||
149 | /** | |
150 | Strips all accelerator characters and mnemonics from the given @e text. | |
3b3026ca RR |
151 | For example: |
152 | ||
153 | @code | |
154 | wxMenuItem::GetLabelfromText( "&Hello\tCtrl-h"); | |
155 | @endcode | |
3c4f71cc | 156 | |
23324ae1 | 157 | will return just @c "Hello". |
3c4f71cc | 158 | |
4cc4bfaf | 159 | @see GetItemLabelText(), GetItemLabel() |
23324ae1 FM |
160 | */ |
161 | static wxString GetLabelText(const wxString& text); | |
162 | ||
163 | /** | |
164 | Gets the width of the menu item checkmark bitmap (Windows only). | |
165 | */ | |
328f5751 | 166 | int GetMarginWidth() const; |
23324ae1 FM |
167 | |
168 | /** | |
169 | Returns the menu this menu item is in, or @NULL if this menu item is not | |
170 | attached. | |
171 | */ | |
328f5751 | 172 | wxMenu* GetMenu() const; |
23324ae1 FM |
173 | |
174 | /** | |
175 | Returns the text associated with the menu item. | |
1f1d2182 | 176 | @note this function is deprecated, please use |
7c913512 | 177 | GetItemLabel() or GetItemLabelText() |
23324ae1 FM |
178 | instead. |
179 | */ | |
328f5751 | 180 | wxString GetName() const; |
23324ae1 FM |
181 | |
182 | /** | |
183 | Returns the submenu associated with the menu item, or @NULL if there isn't one. | |
184 | */ | |
328f5751 | 185 | wxMenu* GetSubMenu() const; |
23324ae1 FM |
186 | |
187 | /** | |
188 | Returns the text associated with the menu item, such as it was passed to the | |
189 | wxMenuItem constructor, i.e. with any accelerator characters it may contain. | |
23324ae1 | 190 | This function is deprecated in favour of GetItemLabel(). |
3c4f71cc | 191 | |
4cc4bfaf | 192 | @see GetLabel(), GetLabelFromText() |
23324ae1 | 193 | */ |
328f5751 | 194 | wxString GetText() const; |
23324ae1 FM |
195 | |
196 | /** | |
197 | Returns the text colour associated with the menu item (Windows only). | |
198 | */ | |
328f5751 | 199 | wxColour GetTextColour() const; |
23324ae1 FM |
200 | |
201 | /** | |
202 | Returns @true if the item is checkable. | |
203 | */ | |
328f5751 | 204 | bool IsCheckable() const; |
23324ae1 FM |
205 | |
206 | /** | |
207 | Returns @true if the item is checked. | |
208 | */ | |
328f5751 | 209 | bool IsChecked() const; |
23324ae1 FM |
210 | |
211 | /** | |
212 | Returns @true if the item is enabled. | |
213 | */ | |
328f5751 | 214 | bool IsEnabled() const; |
23324ae1 FM |
215 | |
216 | /** | |
217 | Returns @true if the item is a separator. | |
218 | */ | |
328f5751 | 219 | bool IsSeparator() const; |
23324ae1 FM |
220 | |
221 | /** | |
222 | Returns @true if the item is a submenu. | |
223 | */ | |
328f5751 | 224 | bool IsSubMenu() const; |
23324ae1 FM |
225 | |
226 | /** | |
227 | Sets the background colour associated with the menu item (Windows only). | |
228 | */ | |
328f5751 | 229 | void SetBackgroundColour(const wxColour& colour) const; |
23324ae1 FM |
230 | |
231 | /** | |
232 | Sets the bitmap for the menu item (Windows and GTK+ only). It is | |
233 | equivalent to wxMenuItem::SetBitmaps(bmp, wxNullBitmap). | |
234 | */ | |
235 | void SetBitmap(const wxBitmap& bmp); | |
236 | ||
237 | /** | |
238 | Sets the checked/unchecked bitmaps for the menu item (Windows only). The first | |
239 | bitmap | |
240 | is also used as the single bitmap for uncheckable menu items. | |
241 | */ | |
242 | void SetBitmaps(const wxBitmap& checked, | |
243 | const wxBitmap& unchecked = wxNullBitmap); | |
244 | ||
245 | /** | |
246 | Sets the font associated with the menu item (Windows only). | |
247 | */ | |
248 | void SetFont(const wxFont& font); | |
249 | ||
250 | /** | |
251 | Sets the help string. | |
252 | */ | |
253 | void SetHelp(const wxString& helpString); | |
254 | ||
255 | /** | |
256 | Sets the label associated with the menu item. | |
257 | */ | |
258 | void SetItemLabel(const wxString& label); | |
259 | ||
260 | /** | |
261 | Sets the width of the menu item checkmark bitmap (Windows only). | |
262 | */ | |
328f5751 | 263 | void SetMarginWidth(int width) const; |
23324ae1 FM |
264 | |
265 | /** | |
266 | Sets the parent menu which will contain this menu item. | |
267 | */ | |
268 | void SetMenu(const wxMenu* menu); | |
269 | ||
270 | /** | |
271 | Sets the submenu of this menu item. | |
272 | */ | |
273 | void SetSubMenu(const wxMenu* menu); | |
274 | ||
275 | /** | |
276 | Sets the text associated with the menu item. | |
23324ae1 FM |
277 | This function is deprecated in favour of SetItemLabel(). |
278 | */ | |
279 | void SetText(const wxString& text); | |
280 | ||
281 | /** | |
282 | Sets the text colour associated with the menu item (Windows only). | |
283 | */ | |
284 | void SetTextColour(const wxColour& colour); | |
285 | }; | |
e54c96f1 | 286 |