]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/menuitem.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxMenu, wxMenuItem
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
12 A menu item represents an item in a menu.
14 Note that you usually don't have to deal with it directly as wxMenu methods
15 usually construct an object of this class for you.
17 Also please note that the methods related to fonts and bitmaps are currently
18 only implemented for Windows and GTK+.
23 @see wxMenuBar, wxMenu
25 class wxMenuItem
: public wxObject
29 Constructs a wxMenuItem object.
31 Menu items can be standard, or "stock menu items", or custom.
32 For the standard menu items (such as commands to open a file, exit the
33 program and so on, see @ref page_stockitems for the full list) it is enough
34 to specify just the stock ID and leave @a text and @a helpString empty.
36 In fact, leaving at least @a text empty for the stock menu items is strongly
37 recommended as they will have appearance and keyboard interface (including
38 standard accelerators) familiar to the user.
40 For the custom (non-stock) menu items, @a text must be specified and while
41 @a helpString may be left empty, it's recommended to pass the item
42 description (which is automatically shown by the library in the status bar
43 when the menu item is selected) in this parameter.
45 Finally note that you can e.g. use a stock menu label without using its stock
49 // use all stock properties:
50 helpMenu->Append(wxID_ABOUT);
52 // use the stock label and the stock accelerator but not the stock help string:
53 helpMenu->Append(wxID_ABOUT, wxEmptyString, wxT("My custom help string"));
55 // use all stock properties except for the bitmap:
56 wxMenuItem *mymenu = new wxMenuItem(helpMenu, wxID_ABOUT);
57 mymenu->SetBitmap(wxArtProvider::GetBitmap(wxART_WARNING));
58 helpMenu->Append(mymenu);
61 that is, stock properties are set independently one from the other.
64 Menu that the menu item belongs to. Can be @NULL if the item is
65 going to be added to the menu later.
67 Identifier for this menu item. May be @c wxID_SEPARATOR, in which
68 case the given kind is ignored and taken to be @c wxITEM_SEPARATOR
71 Text for the menu item, as shown on the menu. An accelerator key can
72 be specified using the ampersand " character. In order to embed an
73 ampersand character in the menu item text, the ampersand must be doubled.
75 Optional help string that will be shown on the status bar.
77 May be @c wxITEM_SEPARATOR, @c wxITEM_NORMAL, @c wxITEM_CHECK or
80 If non-@NULL, indicates that the menu item is a submenu.
82 wxMenuItem(wxMenu
* parentMenu
= NULL
, int id
= wxID_SEPARATOR
,
83 const wxString
& text
= "",
84 const wxString
& helpString
= "",
85 wxItemKind kind
= wxITEM_NORMAL
,
86 wxMenu
* subMenu
= NULL
);
91 virtual ~wxMenuItem();
94 Checks or unchecks the menu item.
95 Note that this only works when the item is already appended to a menu.
97 virtual void Check(bool check
= true);
100 Enables or disables the menu item.
102 virtual void Enable(bool enable
= true);
105 Returns the background colour associated with the menu item (Windows only).
107 wxColour
GetBackgroundColour() const;
110 Returns the checked or unchecked bitmap (Windows only).
112 virtual const wxBitmap
& GetBitmap() const;
115 Returns the font associated with the menu item (Windows only).
117 wxFont
GetFont() const;
120 Returns the help string associated with the menu item.
122 const wxString
& GetHelp() const;
125 Returns the menu item identifier.
130 Returns the text associated with the menu item including any accelerator
131 characters that were passed to the constructor or SetItemLabel().
133 @see GetItemLabelText(), GetLabelText()
135 virtual wxString
GetItemLabel() const;
138 Returns the text associated with the menu item, without any accelerator
141 @see GetItemLabel(), GetLabelText()
143 virtual wxString
GetItemLabelText() const;
146 Returns the item kind, one of @c wxITEM_SEPARATOR, @c wxITEM_NORMAL,
147 @c wxITEM_CHECK or @c wxITEM_RADIO.
149 wxItemKind
GetKind() const;
152 Returns the text associated with the menu item without any accelerator
153 characters it might contain.
155 @deprecated This function is deprecated in favour of GetItemLabelText().
157 @see GetText(), GetLabelFromText()
159 wxString
GetLabel() const;
162 @deprecated This function is deprecated; please use GetLabelText() instead.
164 @see GetText(), GetLabel()
166 static wxString
GetLabelFromText(const wxString
& text
);
169 Strips all accelerator characters and mnemonics from the given @a text.
173 wxMenuItem::GetLabelfromText("&Hello\tCtrl-h");
176 will return just @c "Hello".
178 @see GetItemLabelText(), GetItemLabel()
180 static wxString
GetLabelText(const wxString
& text
);
183 Gets the width of the menu item checkmark bitmap (Windows only).
185 int GetMarginWidth() const;
188 Returns the menu this menu item is in, or @NULL if this menu item is not
191 wxMenu
* GetMenu() const;
194 Returns the text associated with the menu item.
196 @deprecated This function is deprecated. Please use
198 GetItemLabel() or GetItemLabelText() instead.
200 wxString
GetName() const;
203 Returns the submenu associated with the menu item, or @NULL if there isn't one.
205 wxMenu
* GetSubMenu() const;
208 Returns the text associated with the menu item, such as it was passed to the
209 wxMenuItem constructor, i.e. with any accelerator characters it may contain.
211 @deprecated This function is deprecated in favour of GetItemLabel().
213 @see GetLabel(), GetLabelFromText()
215 const wxString
& GetText() const;
218 Returns the text colour associated with the menu item (Windows only).
220 wxColour
GetTextColour() const;
223 Returns @true if the item is checkable.
225 bool IsCheckable() const;
228 Returns @true if the item is checked.
230 virtual bool IsChecked() const;
233 Returns @true if the item is enabled.
235 virtual bool IsEnabled() const;
238 Returns @true if the item is a separator.
240 bool IsSeparator() const;
243 Returns @true if the item is a submenu.
245 bool IsSubMenu() const;
248 Sets the background colour associated with the menu item (Windows only).
250 void SetBackgroundColour(const wxColour
& colour
) const;
253 Sets the bitmap for the menu item (Windows and GTK+ only).
254 It is equivalent to wxMenuItem::SetBitmaps(bmp, wxNullBitmap).
256 virtual void SetBitmap(const wxBitmap
& bmp
);
259 Sets the checked/unchecked bitmaps for the menu item (Windows only).
260 The first bitmap is also used as the single bitmap for uncheckable menu items.
262 void SetBitmaps(const wxBitmap
& checked
,
263 const wxBitmap
& unchecked
= wxNullBitmap
);
266 Sets the font associated with the menu item (Windows only).
268 void SetFont(const wxFont
& font
);
271 Sets the help string.
273 void SetHelp(const wxString
& helpString
);
276 Sets the label associated with the menu item.
278 virtual void SetItemLabel(const wxString
& label
);
281 Sets the width of the menu item checkmark bitmap (Windows only).
283 void SetMarginWidth(int width
) const;
286 Sets the parent menu which will contain this menu item.
288 void SetMenu(wxMenu
* menu
);
291 Sets the submenu of this menu item.
293 void SetSubMenu(wxMenu
* menu
);
296 Sets the text associated with the menu item.
298 @deprecated This function is deprecated in favour of SetItemLabel().
300 virtual void SetText(const wxString
& text
);
303 Sets the text colour associated with the menu item (Windows only).
305 void SetTextColour(const wxColour
& colour
);