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