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