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