1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenuItem class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_MENUITEM_H_BASE_
13 #define _WX_MENUITEM_H_BASE_
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
21 #include "wx/object.h" // base class
23 // ----------------------------------------------------------------------------
24 // forward declarations
25 // ----------------------------------------------------------------------------
27 class WXDLLEXPORT wxAcceleratorEntry
;
28 class WXDLLEXPORT wxMenuItem
;
29 class WXDLLEXPORT wxMenu
;
31 // ----------------------------------------------------------------------------
32 // wxMenuItem is an item in the menu which may be either a normal item, a sub
33 // menu or a separator
34 // ----------------------------------------------------------------------------
36 class WXDLLEXPORT wxMenuItemBase
: public wxObject
40 static wxMenuItem
*New(wxMenu
*parentMenu
= (wxMenu
*)NULL
,
41 int id
= wxID_SEPARATOR
,
42 const wxString
& text
= wxEmptyString
,
43 const wxString
& help
= wxEmptyString
,
44 bool isCheckable
= FALSE
,
45 wxMenu
*subMenu
= (wxMenu
*)NULL
);
47 // destruction: wxMenuItem will delete its submenu
48 virtual ~wxMenuItemBase();
51 wxMenu
*GetMenu() const { return m_parentMenu
; }
54 void SetId(int id
) { m_id
= id
; }
55 int GetId() const { return m_id
; }
56 bool IsSeparator() const { return m_id
== wxID_SEPARATOR
; }
58 // the item's text (or name)
60 // NB: the item's text includes the accelerators and mnemonics info (if
61 // any), i.e. it may contain '&' or '_' or "\t..." and thus is
62 // different from the item's label which only contains the text shown
64 virtual void SetText(const wxString
& str
) { m_text
= str
; }
65 wxString
GetLabel() const { return GetLabelFromText(m_text
); }
66 const wxString
& GetText() const { return m_text
; }
68 // get the label from text (implemented in platform-specific code)
69 static wxString
GetLabelFromText(const wxString
& text
);
71 // what kind of menu item we are
72 virtual void SetCheckable(bool checkable
) { m_isCheckable
= checkable
; }
73 bool IsCheckable() const { return m_isCheckable
; }
75 bool IsSubMenu() const { return m_subMenu
!= NULL
; }
76 void SetSubMenu(wxMenu
*menu
) { m_subMenu
= menu
; }
77 wxMenu
*GetSubMenu() const { return m_subMenu
; }
80 virtual void Enable(bool enable
= TRUE
) { m_isEnabled
= enable
; }
81 virtual bool IsEnabled() const { return m_isEnabled
; }
83 virtual void Check(bool check
= TRUE
) { m_isChecked
= check
; }
84 virtual bool IsChecked() const { return m_isChecked
; }
85 void Toggle() { Check(!m_isChecked
); }
87 // help string (displayed in the status bar by default)
88 void SetHelp(const wxString
& str
) { m_help
= str
; }
89 const wxString
& GetHelp() const { return m_help
; }
92 // extract the accelerator from the given menu string, return NULL if none
94 static wxAcceleratorEntry
*GetAccelFromString(const wxString
& label
);
96 // get our accelerator or NULL (caller must delete the pointer)
97 virtual wxAcceleratorEntry
*GetAccel() const;
99 // set the accel for this item - this may also be done indirectly with
101 virtual void SetAccel(wxAcceleratorEntry
*accel
);
102 #endif // wxUSE_ACCEL
104 // compatibility only, use new functions in the new code
105 void SetName(const wxString
& str
) { SetText(str
); }
106 const wxString
& GetName() const { return GetText(); }
109 int m_id
; // numeric id of the item >= 0 or -1
110 wxMenu
*m_parentMenu
, // the menu we belong to
111 *m_subMenu
; // our sub menu or NULL
112 wxString m_text
, // label of the item
113 m_help
; // the help string for the item
114 bool m_isCheckable
; // can be checked?
115 bool m_isChecked
; // is checked?
116 bool m_isEnabled
; // is enabled?
118 // some compilers need a default constructor here, do not remove
122 // and, if we have one ctor, compiler won't generate a default copy one, so
123 // declare them ourselves - but don't implement as they shouldn't be used
124 wxMenuItemBase(const wxMenuItemBase
& item
);
125 wxMenuItemBase
& operator=(const wxMenuItemBase
& item
);
128 // ----------------------------------------------------------------------------
129 // include the real class declaration
130 // ----------------------------------------------------------------------------
132 #ifdef wxUSE_BASE_CLASSES_ONLY
133 #define wxMenuItem wxMenuItemBase
134 #else // !wxUSE_BASE_CLASSES_ONLY
135 #if defined(__WXUNIVERSAL__)
136 #include "wx/univ/menuitem.h"
137 #elif defined(__WXMSW__)
138 #include "wx/msw/menuitem.h"
139 #elif defined(__WXMOTIF__)
140 #include "wx/motif/menuitem.h"
141 #elif defined(__WXGTK__)
142 #include "wx/gtk/menuitem.h"
143 #elif defined(__WXQT__)
144 #include "wx/qt/menuitem.h"
145 #elif defined(__WXMAC__)
146 #include "wx/mac/menuitem.h"
147 #elif defined(__WXPM__)
148 #include "wx/os2/menuitem.h"
149 #elif defined(__WXSTUBS__)
150 #include "wx/stubs/menuitem.h"
152 #endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY
154 #endif // wxUSE_MENUS
157 // _WX_MENUITEM_H_BASE_