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_
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 #include "wx/object.h" // base class
21 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
25 // id for a separator line in the menu (invalid for normal item)
26 #define wxID_SEPARATOR (-1)
28 #ifndef ID_SEPARATOR // for compatibility only, don't use in new code
29 #define ID_SEPARATOR wxID_SEPARATOR
32 // ----------------------------------------------------------------------------
33 // forward declarations
34 // ----------------------------------------------------------------------------
36 class WXDLLEXPORT wxAcceleratorEntry
;
37 class WXDLLEXPORT wxMenuItem
;
38 class WXDLLEXPORT wxMenu
;
40 // ----------------------------------------------------------------------------
41 // wxMenuItem is an item in the menu which may be either a normal item, a sub
42 // menu or a separator
43 // ----------------------------------------------------------------------------
45 class WXDLLEXPORT wxMenuItemBase
: public wxObject
51 static wxMenuItem
*New(wxMenu
*parentMenu
= (wxMenu
*)NULL
,
52 int id
= wxID_SEPARATOR
,
53 const wxString
& text
= wxEmptyString
,
54 const wxString
& help
= wxEmptyString
,
55 bool isCheckable
= FALSE
,
56 wxMenu
*subMenu
= (wxMenu
*)NULL
);
58 // destruction: wxMenuItem will delete its submenu
59 virtual ~wxMenuItemBase();
62 wxMenu
*GetMenu() const { return m_parentMenu
; }
65 void SetId(int id
) { m_id
= id
; }
66 int GetId() const { return m_id
; }
67 bool IsSeparator() const { return m_id
== wxID_SEPARATOR
; }
69 // the item's text (or name)
71 // NB: the item's text includes the accelerators and mnemonics info (if
72 // any), i.e. it may contain '&' or '_' or "\t..." and thus is
73 // different from the item's label which only contains the text shown
75 virtual void SetText(const wxString
& str
) { m_text
= str
; }
76 virtual wxString
GetLabel() const { return m_text
; }
77 const wxString
& GetText() const { return m_text
; }
79 // what kind of menu item we are
80 virtual void SetCheckable(bool checkable
) { m_isCheckable
= checkable
; }
81 bool IsCheckable() const { return m_isCheckable
; }
83 bool IsSubMenu() const { return m_subMenu
!= NULL
; }
84 void SetSubMenu(wxMenu
*menu
) { m_subMenu
= menu
; }
85 wxMenu
*GetSubMenu() const { return m_subMenu
; }
88 virtual void Enable(bool enable
= TRUE
) { m_isEnabled
= enable
; }
89 virtual bool IsEnabled() const { return m_isEnabled
; }
91 virtual void Check(bool check
= TRUE
) { m_isChecked
= check
; }
92 virtual bool IsChecked() const { return m_isChecked
; }
93 void Toggle() { Check(!m_isChecked
); }
95 // help string (displayed in the status bar by default)
96 void SetHelp(const wxString
& str
) { m_help
= str
; }
97 const wxString
& GetHelp() const { return m_help
; }
100 // get our accelerator or NULL (caller must delete the pointer)
101 virtual wxAcceleratorEntry
*GetAccel() const { return NULL
; }
103 // set the accel for this item - this may also be done indirectly with
105 virtual void SetAccel(wxAcceleratorEntry
*accel
);
106 #endif // wxUSE_ACCEL
108 // compatibility only, use new functions in the new code
109 void SetName(const wxString
& str
) { SetText(str
); }
110 const wxString
& GetName() const { return GetText(); }
113 int m_id
; // numeric id of the item >= 0 or -1
114 wxMenu
*m_parentMenu
, // the menu we belong to
115 *m_subMenu
; // our sub menu or NULL
116 wxString m_text
, // label of the item
117 m_help
; // the help string for the item
118 bool m_isCheckable
; // can be checked?
119 bool m_isChecked
; // is checked?
120 bool m_isEnabled
; // is enabled?
123 // ----------------------------------------------------------------------------
124 // include the real class declaration
125 // ----------------------------------------------------------------------------
127 #ifdef wxUSE_BASE_CLASSES_ONLY
128 #define wxMenuItem wxMenuItemBase
129 #else // !wxUSE_BASE_CLASSES_ONLY
130 #if defined(__WXMSW__)
131 #include "wx/msw/menuitem.h"
132 #elif defined(__WXMOTIF__)
133 #include "wx/motif/menuitem.h"
134 #elif defined(__WXGTK__)
135 #include "wx/gtk/menuitem.h"
136 #elif defined(__WXQT__)
137 #include "wx/qt/menuitem.h"
138 #elif defined(__WXMAC__)
139 #include "wx/mac/menuitem.h"
140 #elif defined(__WXPM__)
141 #include "wx/os2/menuitem.h"
142 #elif defined(__WXSTUBS__)
143 #include "wx/stubs/menuitem.h"
145 #endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY
148 // _WX_MENUITEM_H_BASE_