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