]>
Commit | Line | Data |
---|---|---|
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 | ||
717a57c2 | 29 | class WXDLLEXPORT wxAcceleratorEntry; |
974e8d94 VZ |
30 | class WXDLLEXPORT wxMenuItem; |
31 | class WXDLLEXPORT wxMenu; | |
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 | ||
38 | class WXDLLEXPORT wxMenuItemBase : public wxObject | |
39 | { | |
40 | public: | |
41 | // creation | |
42 | static wxMenuItem *New(wxMenu *parentMenu = (wxMenu *)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, |
974e8d94 VZ |
47 | wxMenu *subMenu = (wxMenu *)NULL); |
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 VZ |
58 | int GetId() const { return m_id; } |
59 | bool IsSeparator() const { return m_id == wxID_SEPARATOR; } | |
60 | ||
717a57c2 VZ |
61 | // the item's text (or name) |
62 | // | |
63 | // NB: the item's text includes the accelerators and mnemonics info (if | |
64 | // any), i.e. it may contain '&' or '_' or "\t..." and thus is | |
65 | // different from the item's label which only contains the text shown | |
66 | // in the menu | |
345319d6 | 67 | virtual void SetText(const wxString& str); |
3b59cdbf | 68 | wxString GetLabel() const { return GetLabelFromText(m_text); } |
974e8d94 VZ |
69 | const wxString& GetText() const { return m_text; } |
70 | ||
3b59cdbf VZ |
71 | // get the label from text (implemented in platform-specific code) |
72 | static wxString GetLabelFromText(const wxString& text); | |
73 | ||
974e8d94 | 74 | // what kind of menu item we are |
d65c269b | 75 | wxItemKind GetKind() const { return m_kind; } |
d36d8dd7 | 76 | void SetKind(wxItemKind kind) { m_kind = kind; } |
d65c269b | 77 | |
bb28b477 | 78 | virtual void SetCheckable(bool checkable) { m_kind = checkable ? wxITEM_CHECK : wxITEM_NORMAL; } |
0472ece7 | 79 | bool IsCheckable() const |
546bfbea | 80 | { return m_kind == wxITEM_CHECK || m_kind == wxITEM_RADIO; } |
974e8d94 VZ |
81 | |
82 | bool IsSubMenu() const { return m_subMenu != NULL; } | |
83 | void SetSubMenu(wxMenu *menu) { m_subMenu = menu; } | |
84 | wxMenu *GetSubMenu() const { return m_subMenu; } | |
85 | ||
86 | // state | |
4e32eea1 | 87 | virtual void Enable(bool enable = true) { m_isEnabled = enable; } |
974e8d94 | 88 | virtual bool IsEnabled() const { return m_isEnabled; } |
717a57c2 | 89 | |
4e32eea1 | 90 | virtual void Check(bool check = true) { m_isChecked = check; } |
974e8d94 | 91 | virtual bool IsChecked() const { return m_isChecked; } |
717a57c2 | 92 | void Toggle() { Check(!m_isChecked); } |
974e8d94 VZ |
93 | |
94 | // help string (displayed in the status bar by default) | |
345319d6 | 95 | void SetHelp(const wxString& str); |
974e8d94 VZ |
96 | const wxString& GetHelp() const { return m_help; } |
97 | ||
717a57c2 | 98 | #if wxUSE_ACCEL |
1e6feb95 VZ |
99 | // extract the accelerator from the given menu string, return NULL if none |
100 | // found | |
101 | static wxAcceleratorEntry *GetAccelFromString(const wxString& label); | |
102 | ||
717a57c2 | 103 | // get our accelerator or NULL (caller must delete the pointer) |
1e6feb95 | 104 | virtual wxAcceleratorEntry *GetAccel() const; |
717a57c2 VZ |
105 | |
106 | // set the accel for this item - this may also be done indirectly with | |
107 | // SetText() | |
108 | virtual void SetAccel(wxAcceleratorEntry *accel); | |
109 | #endif // wxUSE_ACCEL | |
110 | ||
b4a980f4 | 111 | #if WXWIN_COMPATIBILITY_2_8 |
974e8d94 | 112 | // compatibility only, use new functions in the new code |
b4a980f4 VZ |
113 | wxDEPRECATED( void SetName(const wxString& str) ); |
114 | wxDEPRECATED( const wxString& GetName() const ); | |
115 | #endif // WXWIN_COMPATIBILITY_2_8 | |
974e8d94 | 116 | |
d65c269b | 117 | static wxMenuItem *New(wxMenu *parentMenu, |
d9e2e4c2 | 118 | int itemid, |
d65c269b VZ |
119 | const wxString& text, |
120 | const wxString& help, | |
121 | bool isCheckable, | |
122 | wxMenu *subMenu = (wxMenu *)NULL) | |
123 | { | |
d9e2e4c2 | 124 | return New(parentMenu, itemid, text, help, |
546bfbea | 125 | isCheckable ? wxITEM_CHECK : wxITEM_NORMAL, subMenu); |
d65c269b VZ |
126 | } |
127 | ||
974e8d94 | 128 | protected: |
4e32eea1 | 129 | int m_id; // numeric id of the item >= 0 or wxID_ANY or wxID_SEPARATOR |
974e8d94 VZ |
130 | wxMenu *m_parentMenu, // the menu we belong to |
131 | *m_subMenu; // our sub menu or NULL | |
132 | wxString m_text, // label of the item | |
133 | m_help; // the help string for the item | |
3103e8a9 | 134 | wxItemKind m_kind; // separator/normal/check/radio item? |
974e8d94 VZ |
135 | bool m_isChecked; // is checked? |
136 | bool m_isEnabled; // is enabled? | |
c0d6c58b | 137 | |
d65c269b VZ |
138 | // this ctor is for the derived classes only, we're never created directly |
139 | wxMenuItemBase(wxMenu *parentMenu = (wxMenu *)NULL, | |
d9e2e4c2 | 140 | int itemid = wxID_SEPARATOR, |
d65c269b VZ |
141 | const wxString& text = wxEmptyString, |
142 | const wxString& help = wxEmptyString, | |
546bfbea | 143 | wxItemKind kind = wxITEM_NORMAL, |
d65c269b | 144 | wxMenu *subMenu = (wxMenu *)NULL); |
7af206c1 VZ |
145 | |
146 | private: | |
147 | // and, if we have one ctor, compiler won't generate a default copy one, so | |
148 | // declare them ourselves - but don't implement as they shouldn't be used | |
149 | wxMenuItemBase(const wxMenuItemBase& item); | |
150 | wxMenuItemBase& operator=(const wxMenuItemBase& item); | |
974e8d94 VZ |
151 | }; |
152 | ||
b4a980f4 | 153 | #if WXWIN_COMPATIBILITY_2_8 |
21324807 | 154 | inline void wxMenuItemBase::SetName(const wxString &str) |
b4a980f4 | 155 | { SetText(str); } |
21324807 | 156 | inline const wxString& wxMenuItemBase::GetName() const |
b4a980f4 VZ |
157 | { return GetText(); } |
158 | #endif // WXWIN_COMPATIBILITY_2_8 | |
159 | ||
974e8d94 VZ |
160 | // ---------------------------------------------------------------------------- |
161 | // include the real class declaration | |
162 | // ---------------------------------------------------------------------------- | |
163 | ||
164 | #ifdef wxUSE_BASE_CLASSES_ONLY | |
165 | #define wxMenuItem wxMenuItemBase | |
166 | #else // !wxUSE_BASE_CLASSES_ONLY | |
1e6feb95 VZ |
167 | #if defined(__WXUNIVERSAL__) |
168 | #include "wx/univ/menuitem.h" | |
4055ed82 | 169 | #elif defined(__WXPALMOS__) |
ffecfa5a | 170 | #include "wx/palmos/menuitem.h" |
1e6feb95 | 171 | #elif defined(__WXMSW__) |
974e8d94 | 172 | #include "wx/msw/menuitem.h" |
50414e24 | 173 | #elif defined(__WXMOTIF__) |
974e8d94 | 174 | #include "wx/motif/menuitem.h" |
1be7a35c | 175 | #elif defined(__WXGTK20__) |
974e8d94 | 176 | #include "wx/gtk/menuitem.h" |
1be7a35c MR |
177 | #elif defined(__WXGTK__) |
178 | #include "wx/gtk1/menuitem.h" | |
50414e24 | 179 | #elif defined(__WXMAC__) |
974e8d94 | 180 | #include "wx/mac/menuitem.h" |
e64df9bc DE |
181 | #elif defined(__WXCOCOA__) |
182 | #include "wx/cocoa/menuitem.h" | |
1777b9bb | 183 | #elif defined(__WXPM__) |
974e8d94 | 184 | #include "wx/os2/menuitem.h" |
c801d85f | 185 | #endif |
974e8d94 | 186 | #endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY |
c801d85f | 187 | |
1e6feb95 VZ |
188 | #endif // wxUSE_MENUS |
189 | ||
c801d85f | 190 | #endif |
50414e24 | 191 | // _WX_MENUITEM_H_BASE_ |