1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenuItem class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_MENUITEM_H_BASE_
13 #define _WX_MENUITEM_H_BASE_
19 // ----------------------------------------------------------------------------
21 // ----------------------------------------------------------------------------
23 #include "wx/object.h" // base class
25 // ----------------------------------------------------------------------------
26 // forward declarations
27 // ----------------------------------------------------------------------------
29 class WXDLLEXPORT wxAcceleratorEntry
;
30 class WXDLLEXPORT wxMenuItem
;
31 class WXDLLEXPORT wxMenu
;
33 // ----------------------------------------------------------------------------
34 // wxMenuItem is an item in the menu which may be either a normal item, a sub
35 // menu or a separator
36 // ----------------------------------------------------------------------------
38 class WXDLLEXPORT wxMenuItemBase
: public wxObject
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
);
49 // destruction: wxMenuItem will delete its submenu
50 virtual ~wxMenuItemBase();
53 wxMenu
*GetMenu() const { return m_parentMenu
; }
54 void SetMenu(wxMenu
* menu
) { m_parentMenu
= menu
; }
57 void SetId(int itemid
) { m_id
= itemid
; }
58 int GetId() const { return m_id
; }
59 bool IsSeparator() const { return m_id
== wxID_SEPARATOR
; }
61 // the item's text (or name)
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
67 virtual void SetText(const wxString
& str
) { m_text
= str
; }
68 wxString
GetLabel() const { return GetLabelFromText(m_text
); }
69 const wxString
& GetText() const { return m_text
; }
71 // get the label from text (implemented in platform-specific code)
72 static wxString
GetLabelFromText(const wxString
& text
);
74 // what kind of menu item we are
75 wxItemKind
GetKind() const { return m_kind
; }
76 void SetKind(wxItemKind kind
) { m_kind
= kind
; }
78 virtual void SetCheckable(bool checkable
) { m_kind
= checkable
? wxITEM_CHECK
: wxITEM_NORMAL
; }
79 bool IsCheckable() const
80 { return m_kind
== wxITEM_CHECK
|| m_kind
== wxITEM_RADIO
; }
82 bool IsSubMenu() const { return m_subMenu
!= NULL
; }
83 void SetSubMenu(wxMenu
*menu
) { m_subMenu
= menu
; }
84 wxMenu
*GetSubMenu() const { return m_subMenu
; }
87 virtual void Enable(bool enable
= true) { m_isEnabled
= enable
; }
88 virtual bool IsEnabled() const { return m_isEnabled
; }
90 virtual void Check(bool check
= true) { m_isChecked
= check
; }
91 virtual bool IsChecked() const { return m_isChecked
; }
92 void Toggle() { Check(!m_isChecked
); }
94 // help string (displayed in the status bar by default)
95 void SetHelp(const wxString
& str
) { m_help
= str
; }
96 const wxString
& GetHelp() const { return m_help
; }
99 // extract the accelerator from the given menu string, return NULL if none
101 static wxAcceleratorEntry
*GetAccelFromString(const wxString
& label
);
103 // get our accelerator or NULL (caller must delete the pointer)
104 virtual wxAcceleratorEntry
*GetAccel() const;
106 // set the accel for this item - this may also be done indirectly with
108 virtual void SetAccel(wxAcceleratorEntry
*accel
);
109 #endif // wxUSE_ACCEL
111 // compatibility only, use new functions in the new code
112 void SetName(const wxString
& str
) { SetText(str
); }
113 const wxString
& GetName() const { return GetText(); }
115 static wxMenuItem
*New(wxMenu
*parentMenu
,
117 const wxString
& text
,
118 const wxString
& help
,
120 wxMenu
*subMenu
= (wxMenu
*)NULL
)
122 return New(parentMenu
, itemid
, text
, help
,
123 isCheckable
? wxITEM_CHECK
: wxITEM_NORMAL
, subMenu
);
127 int m_id
; // numeric id of the item >= 0 or wxID_ANY or wxID_SEPARATOR
128 wxMenu
*m_parentMenu
, // the menu we belong to
129 *m_subMenu
; // our sub menu or NULL
130 wxString m_text
, // label of the item
131 m_help
; // the help string for the item
132 wxItemKind m_kind
; // seperator/normal/check/radio item?
133 bool m_isChecked
; // is checked?
134 bool m_isEnabled
; // is enabled?
136 // this ctor is for the derived classes only, we're never created directly
137 wxMenuItemBase(wxMenu
*parentMenu
= (wxMenu
*)NULL
,
138 int itemid
= wxID_SEPARATOR
,
139 const wxString
& text
= wxEmptyString
,
140 const wxString
& help
= wxEmptyString
,
141 wxItemKind kind
= wxITEM_NORMAL
,
142 wxMenu
*subMenu
= (wxMenu
*)NULL
);
145 // and, if we have one ctor, compiler won't generate a default copy one, so
146 // declare them ourselves - but don't implement as they shouldn't be used
147 wxMenuItemBase(const wxMenuItemBase
& item
);
148 wxMenuItemBase
& operator=(const wxMenuItemBase
& item
);
151 // ----------------------------------------------------------------------------
152 // include the real class declaration
153 // ----------------------------------------------------------------------------
155 #ifdef wxUSE_BASE_CLASSES_ONLY
156 #define wxMenuItem wxMenuItemBase
157 #else // !wxUSE_BASE_CLASSES_ONLY
158 #if defined(__WXUNIVERSAL__)
159 #include "wx/univ/menuitem.h"
160 #elif defined(__WXPALMOS__)
161 #include "wx/palmos/menuitem.h"
162 #elif defined(__WXMSW__)
163 #include "wx/msw/menuitem.h"
164 #elif defined(__WXMOTIF__)
165 #include "wx/motif/menuitem.h"
166 #elif defined(__WXGTK__)
167 #include "wx/gtk/menuitem.h"
168 #elif defined(__WXMAC__)
169 #include "wx/mac/menuitem.h"
170 #elif defined(__WXCOCOA__)
171 #include "wx/cocoa/menuitem.h"
172 #elif defined(__WXPM__)
173 #include "wx/os2/menuitem.h"
175 #endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY
177 #endif // wxUSE_MENUS
180 // _WX_MENUITEM_H_BASE_