]> git.saurik.com Git - wxWidgets.git/blob - include/wx/menuitem.h
Somehow, setting a tint color makes gauge work :/.
[wxWidgets.git] / include / wx / menuitem.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/menuitem.h
3 // Purpose: wxMenuItem class
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 25.10.99
7 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_MENUITEM_H_BASE_
12 #define _WX_MENUITEM_H_BASE_
13
14 #include "wx/defs.h"
15
16 #if wxUSE_MENUS
17
18 // ----------------------------------------------------------------------------
19 // headers
20 // ----------------------------------------------------------------------------
21
22 #include "wx/object.h" // base class
23
24 // ----------------------------------------------------------------------------
25 // forward declarations
26 // ----------------------------------------------------------------------------
27
28 class WXDLLIMPEXP_FWD_CORE wxAcceleratorEntry;
29 class WXDLLIMPEXP_FWD_CORE wxMenuItem;
30 class WXDLLIMPEXP_FWD_CORE wxMenu;
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
37 class WXDLLIMPEXP_CORE wxMenuItemBase : public wxObject
38 {
39 public:
40 // creation
41 static wxMenuItem *New(wxMenu *parentMenu = NULL,
42 int itemid = wxID_SEPARATOR,
43 const wxString& text = wxEmptyString,
44 const wxString& help = wxEmptyString,
45 wxItemKind kind = wxITEM_NORMAL,
46 wxMenu *subMenu = NULL);
47
48 // destruction: wxMenuItem will delete its submenu
49 virtual ~wxMenuItemBase();
50
51 // the menu we're in
52 wxMenu *GetMenu() const { return m_parentMenu; }
53 void SetMenu(wxMenu* menu) { m_parentMenu = menu; }
54
55 // get/set id
56 void SetId(int itemid) { m_id = itemid; }
57 int GetId() const { return m_id; }
58
59 // the item's text (or name)
60 //
61 // NB: the item's label includes the accelerators and mnemonics info (if
62 // any), i.e. it may contain '&' or '_' or "\t..." and thus is
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);
66
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);
78
79 // what kind of menu item we are
80 wxItemKind GetKind() const { return m_kind; }
81 void SetKind(wxItemKind kind) { m_kind = kind; }
82 bool IsSeparator() const { return m_kind == wxITEM_SEPARATOR; }
83
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().
91 bool IsCheckable() const
92 { return m_kind == wxITEM_CHECK || m_kind == wxITEM_RADIO; }
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
99 virtual void Enable(bool enable = true) { m_isEnabled = enable; }
100 virtual bool IsEnabled() const { return m_isEnabled; }
101
102 virtual void Check(bool check = true) { m_isChecked = check; }
103 virtual bool IsChecked() const { return m_isChecked; }
104 void Toggle() { Check(!m_isChecked); }
105
106 // help string (displayed in the status bar by default)
107 void SetHelp(const wxString& str);
108 const wxString& GetHelp() const { return m_help; }
109
110 #if wxUSE_ACCEL
111 // extract the accelerator from the given menu string, return NULL if none
112 // found
113 static wxAcceleratorEntry *GetAccelFromString(const wxString& label);
114
115 // get our accelerator or NULL (caller must delete the pointer)
116 virtual wxAcceleratorEntry *GetAccel() const;
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
123 #if WXWIN_COMPATIBILITY_2_8
124 // compatibility only, use new functions in the new code
125 wxDEPRECATED( void SetName(const wxString& str) );
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
135 static wxDEPRECATED( wxString GetLabelFromText(const wxString& text) );
136
137 // Now use SetItemLabel
138 wxDEPRECATED( virtual void SetText(const wxString& str) );
139 #endif // WXWIN_COMPATIBILITY_2_8
140
141 static wxMenuItem *New(wxMenu *parentMenu,
142 int itemid,
143 const wxString& text,
144 const wxString& help,
145 bool isCheckable,
146 wxMenu *subMenu = NULL)
147 {
148 return New(parentMenu, itemid, text, help,
149 isCheckable ? wxITEM_CHECK : wxITEM_NORMAL, subMenu);
150 }
151
152 protected:
153 wxWindowIDRef m_id; // numeric id of the item >= 0 or wxID_ANY or wxID_SEPARATOR
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
158 wxItemKind m_kind; // separator/normal/check/radio item?
159 bool m_isChecked; // is checked?
160 bool m_isEnabled; // is enabled?
161
162 // this ctor is for the derived classes only, we're never created directly
163 wxMenuItemBase(wxMenu *parentMenu = NULL,
164 int itemid = wxID_SEPARATOR,
165 const wxString& text = wxEmptyString,
166 const wxString& help = wxEmptyString,
167 wxItemKind kind = wxITEM_NORMAL,
168 wxMenu *subMenu = NULL);
169
170 private:
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);
175 };
176
177 #if WXWIN_COMPATIBILITY_2_8
178 inline void wxMenuItemBase::SetName(const wxString &str)
179 { SetItemLabel(str); }
180 inline wxString wxMenuItemBase::GetName() const
181 { return GetItemLabel(); }
182 inline wxString wxMenuItemBase::GetLabel() const
183 { return GetLabelText(m_text); }
184 inline const wxString& wxMenuItemBase::GetText() const { return m_text; }
185 inline void wxMenuItemBase::SetText(const wxString& text) { SetItemLabel(text); }
186 #endif // WXWIN_COMPATIBILITY_2_8
187
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
195 #if defined(__WXUNIVERSAL__)
196 #include "wx/univ/menuitem.h"
197 #elif defined(__WXMSW__)
198 #include "wx/msw/menuitem.h"
199 #elif defined(__WXMOTIF__)
200 #include "wx/motif/menuitem.h"
201 #elif defined(__WXGTK20__)
202 #include "wx/gtk/menuitem.h"
203 #elif defined(__WXGTK__)
204 #include "wx/gtk1/menuitem.h"
205 #elif defined(__WXMAC__)
206 #include "wx/osx/menuitem.h"
207 #elif defined(__WXCOCOA__)
208 #include "wx/cocoa/menuitem.h"
209 #elif defined(__WXPM__)
210 #include "wx/os2/menuitem.h"
211 #endif
212 #endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY
213
214 #endif // wxUSE_MENUS
215
216 #endif
217 // _WX_MENUITEM_H_BASE_