]> git.saurik.com Git - wxWidgets.git/blame - include/wx/menuitem.h
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / include / wx / menuitem.h
CommitLineData
974e8d94
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/menuitem.h
3// Purpose: wxMenuItem class
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 25.10.99
974e8d94 7// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 8// Licence: wxWindows licence
974e8d94
VZ
9///////////////////////////////////////////////////////////////////////////////
10
50414e24
JS
11#ifndef _WX_MENUITEM_H_BASE_
12#define _WX_MENUITEM_H_BASE_
13
2ecf902b
WS
14#include "wx/defs.h"
15
1e6feb95
VZ
16#if wxUSE_MENUS
17
974e8d94
VZ
18// ----------------------------------------------------------------------------
19// headers
20// ----------------------------------------------------------------------------
21
22#include "wx/object.h" // base class
23
974e8d94
VZ
24// ----------------------------------------------------------------------------
25// forward declarations
26// ----------------------------------------------------------------------------
27
b5dbe15d
VS
28class WXDLLIMPEXP_FWD_CORE wxAcceleratorEntry;
29class WXDLLIMPEXP_FWD_CORE wxMenuItem;
30class WXDLLIMPEXP_FWD_CORE wxMenu;
974e8d94
VZ
31
32// ----------------------------------------------------------------------------
33// wxMenuItem is an item in the menu which may be either a normal item, a sub
34// menu or a separator
35// ----------------------------------------------------------------------------
36
53a2db12 37class WXDLLIMPEXP_CORE wxMenuItemBase : public wxObject
974e8d94
VZ
38{
39public:
40 // creation
d3b9f782 41 static wxMenuItem *New(wxMenu *parentMenu = NULL,
d9e2e4c2 42 int itemid = wxID_SEPARATOR,
974e8d94
VZ
43 const wxString& text = wxEmptyString,
44 const wxString& help = wxEmptyString,
546bfbea 45 wxItemKind kind = wxITEM_NORMAL,
d3b9f782 46 wxMenu *subMenu = NULL);
974e8d94 47
717a57c2
VZ
48 // destruction: wxMenuItem will delete its submenu
49 virtual ~wxMenuItemBase();
50
3dfac970
VZ
51 // the menu we're in
52 wxMenu *GetMenu() const { return m_parentMenu; }
1e93ca17 53 void SetMenu(wxMenu* menu) { m_parentMenu = menu; }
3dfac970 54
974e8d94 55 // get/set id
d9e2e4c2 56 void SetId(int itemid) { m_id = itemid; }
974e8d94 57 int GetId() const { return m_id; }
974e8d94 58
717a57c2
VZ
59 // the item's text (or name)
60 //
52af3158 61 // NB: the item's label includes the accelerators and mnemonics info (if
717a57c2 62 // any), i.e. it may contain '&' or '_' or "\t..." and thus is
52af3158
JS
63 // different from the item's text which only contains the text shown
64 // in the menu. This used to be called SetText.
65 virtual void SetItemLabel(const wxString& str);
974e8d94 66
52af3158
JS
67 // return the item label including any mnemonics and accelerators.
68 // This used to be called GetText.
69 virtual wxString GetItemLabel() const { return m_text; }
70
71 // return just the text of the item label, without any mnemonics
72 // This used to be called GetLabel.
73 virtual wxString GetItemLabelText() const { return GetLabelText(m_text); }
74
75 // return just the text part of the given label (implemented in platform-specific code)
76 // This used to be called GetLabelFromText.
77 static wxString GetLabelText(const wxString& label);
3b59cdbf 78
974e8d94 79 // what kind of menu item we are
d65c269b 80 wxItemKind GetKind() const { return m_kind; }
d36d8dd7 81 void SetKind(wxItemKind kind) { m_kind = kind; }
fa7134b0 82 bool IsSeparator() const { return m_kind == wxITEM_SEPARATOR; }
d65c269b 83
e3f4ca2e
VZ
84 bool IsCheck() const { return m_kind == wxITEM_CHECK; }
85 bool IsRadio() const { return m_kind == wxITEM_RADIO; }
86
87 virtual void SetCheckable(bool checkable)
88 { m_kind = checkable ? wxITEM_CHECK : wxITEM_NORMAL; }
89
90 // Notice that this doesn't quite match SetCheckable().
0472ece7 91 bool IsCheckable() const
546bfbea 92 { return m_kind == wxITEM_CHECK || m_kind == wxITEM_RADIO; }
974e8d94
VZ
93
94 bool IsSubMenu() const { return m_subMenu != NULL; }
95 void SetSubMenu(wxMenu *menu) { m_subMenu = menu; }
96 wxMenu *GetSubMenu() const { return m_subMenu; }
97
98 // state
4e32eea1 99 virtual void Enable(bool enable = true) { m_isEnabled = enable; }
974e8d94 100 virtual bool IsEnabled() const { return m_isEnabled; }
717a57c2 101
4e32eea1 102 virtual void Check(bool check = true) { m_isChecked = check; }
974e8d94 103 virtual bool IsChecked() const { return m_isChecked; }
717a57c2 104 void Toggle() { Check(!m_isChecked); }
974e8d94
VZ
105
106 // help string (displayed in the status bar by default)
345319d6 107 void SetHelp(const wxString& str);
974e8d94
VZ
108 const wxString& GetHelp() const { return m_help; }
109
717a57c2 110#if wxUSE_ACCEL
1e6feb95
VZ
111 // extract the accelerator from the given menu string, return NULL if none
112 // found
113 static wxAcceleratorEntry *GetAccelFromString(const wxString& label);
114
717a57c2 115 // get our accelerator or NULL (caller must delete the pointer)
1e6feb95 116 virtual wxAcceleratorEntry *GetAccel() const;
717a57c2
VZ
117
118 // set the accel for this item - this may also be done indirectly with
119 // SetText()
120 virtual void SetAccel(wxAcceleratorEntry *accel);
121#endif // wxUSE_ACCEL
122
b4a980f4 123#if WXWIN_COMPATIBILITY_2_8
974e8d94 124 // compatibility only, use new functions in the new code
b4a980f4 125 wxDEPRECATED( void SetName(const wxString& str) );
52af3158
JS
126 wxDEPRECATED( wxString GetName() const );
127
128 // Now use GetItemLabelText
129 wxDEPRECATED( wxString GetLabel() const ) ;
130
131 // Now use GetItemLabel
132 wxDEPRECATED( const wxString& GetText() const );
133
134 // Now use GetLabelText to strip the accelerators
d65e9d57 135 static wxDEPRECATED( wxString GetLabelFromText(const wxString& text) );
52af3158
JS
136
137 // Now use SetItemLabel
138 wxDEPRECATED( virtual void SetText(const wxString& str) );
b4a980f4 139#endif // WXWIN_COMPATIBILITY_2_8
974e8d94 140
d65c269b 141 static wxMenuItem *New(wxMenu *parentMenu,
d9e2e4c2 142 int itemid,
d65c269b
VZ
143 const wxString& text,
144 const wxString& help,
145 bool isCheckable,
d3b9f782 146 wxMenu *subMenu = NULL)
d65c269b 147 {
d9e2e4c2 148 return New(parentMenu, itemid, text, help,
546bfbea 149 isCheckable ? wxITEM_CHECK : wxITEM_NORMAL, subMenu);
d65c269b
VZ
150 }
151
974e8d94 152protected:
cf2810aa 153 wxWindowIDRef m_id; // numeric id of the item >= 0 or wxID_ANY or wxID_SEPARATOR
974e8d94
VZ
154 wxMenu *m_parentMenu, // the menu we belong to
155 *m_subMenu; // our sub menu or NULL
156 wxString m_text, // label of the item
157 m_help; // the help string for the item
3103e8a9 158 wxItemKind m_kind; // separator/normal/check/radio item?
974e8d94
VZ
159 bool m_isChecked; // is checked?
160 bool m_isEnabled; // is enabled?
c0d6c58b 161
d65c269b 162 // this ctor is for the derived classes only, we're never created directly
d3b9f782 163 wxMenuItemBase(wxMenu *parentMenu = NULL,
d9e2e4c2 164 int itemid = wxID_SEPARATOR,
d65c269b
VZ
165 const wxString& text = wxEmptyString,
166 const wxString& help = wxEmptyString,
546bfbea 167 wxItemKind kind = wxITEM_NORMAL,
d3b9f782 168 wxMenu *subMenu = NULL);
7af206c1
VZ
169
170private:
171 // and, if we have one ctor, compiler won't generate a default copy one, so
172 // declare them ourselves - but don't implement as they shouldn't be used
173 wxMenuItemBase(const wxMenuItemBase& item);
174 wxMenuItemBase& operator=(const wxMenuItemBase& item);
974e8d94
VZ
175};
176
b4a980f4 177#if WXWIN_COMPATIBILITY_2_8
21324807 178inline void wxMenuItemBase::SetName(const wxString &str)
52af3158
JS
179 { SetItemLabel(str); }
180inline wxString wxMenuItemBase::GetName() const
181 { return GetItemLabel(); }
182inline wxString wxMenuItemBase::GetLabel() const
808260ec 183 { return GetLabelText(m_text); }
52af3158
JS
184inline const wxString& wxMenuItemBase::GetText() const { return m_text; }
185inline void wxMenuItemBase::SetText(const wxString& text) { SetItemLabel(text); }
b4a980f4
VZ
186#endif // WXWIN_COMPATIBILITY_2_8
187
974e8d94
VZ
188// ----------------------------------------------------------------------------
189// include the real class declaration
190// ----------------------------------------------------------------------------
191
192#ifdef wxUSE_BASE_CLASSES_ONLY
193 #define wxMenuItem wxMenuItemBase
194#else // !wxUSE_BASE_CLASSES_ONLY
1e6feb95
VZ
195#if defined(__WXUNIVERSAL__)
196 #include "wx/univ/menuitem.h"
197#elif defined(__WXMSW__)
974e8d94 198 #include "wx/msw/menuitem.h"
50414e24 199#elif defined(__WXMOTIF__)
974e8d94 200 #include "wx/motif/menuitem.h"
1be7a35c 201#elif defined(__WXGTK20__)
974e8d94 202 #include "wx/gtk/menuitem.h"
1be7a35c
MR
203#elif defined(__WXGTK__)
204 #include "wx/gtk1/menuitem.h"
50414e24 205#elif defined(__WXMAC__)
ef0e9220 206 #include "wx/osx/menuitem.h"
e64df9bc
DE
207#elif defined(__WXCOCOA__)
208 #include "wx/cocoa/menuitem.h"
1777b9bb 209#elif defined(__WXPM__)
974e8d94 210 #include "wx/os2/menuitem.h"
c801d85f 211#endif
974e8d94 212#endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY
c801d85f 213
1e6feb95
VZ
214#endif // wxUSE_MENUS
215
c801d85f 216#endif
50414e24 217 // _WX_MENUITEM_H_BASE_