1. added wxMenuBarBase
[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 wxMenuItem;
37 class WXDLLEXPORT wxMenu;
38
39 // ----------------------------------------------------------------------------
40 // wxMenuItem is an item in the menu which may be either a normal item, a sub
41 // menu or a separator
42 // ----------------------------------------------------------------------------
43
44 class WXDLLEXPORT wxMenuItemBase : public wxObject
45 {
46 public:
47 // creation
48 static wxMenuItem *New(wxMenu *parentMenu = (wxMenu *)NULL,
49 int id = wxID_SEPARATOR,
50 const wxString& text = wxEmptyString,
51 const wxString& help = wxEmptyString,
52 bool isCheckable = FALSE,
53 wxMenu *subMenu = (wxMenu *)NULL);
54
55 // the menu we're in
56 wxMenu *GetMenu() const { return m_parentMenu; }
57
58 // get/set id
59 void SetId(int id) { m_id = id; }
60 int GetId() const { return m_id; }
61 bool IsSeparator() const { return m_id == wxID_SEPARATOR; }
62
63 // the item's text (or name, or label...)
64 virtual void SetText(const wxString& str) { m_text = str; }
65 const wxString& GetText() const { return m_text; }
66
67 // what kind of menu item we are
68 virtual void SetCheckable(bool checkable) { m_isCheckable = checkable; }
69 bool IsCheckable() const { return m_isCheckable; }
70
71 bool IsSubMenu() const { return m_subMenu != NULL; }
72 void SetSubMenu(wxMenu *menu) { m_subMenu = menu; }
73 wxMenu *GetSubMenu() const { return m_subMenu; }
74
75 // state
76 virtual void Enable(bool enable = TRUE) { m_isEnabled = enable; }
77 virtual bool IsEnabled() const { return m_isEnabled; }
78 virtual void Check(bool check = TRUE) { m_isChecked = check; }
79 virtual bool IsChecked() const { return m_isChecked; }
80
81 // help string (displayed in the status bar by default)
82 void SetHelp(const wxString& str) { m_help = str; }
83 const wxString& GetHelp() const { return m_help; }
84
85 // compatibility only, use new functions in the new code
86 void SetName(const wxString& str) { SetText(str); }
87 const wxString& GetName() const { return GetText(); }
88
89 protected:
90 int m_id; // numeric id of the item >= 0 or -1
91 wxMenu *m_parentMenu, // the menu we belong to
92 *m_subMenu; // our sub menu or NULL
93 wxString m_text, // label of the item
94 m_help; // the help string for the item
95 bool m_isCheckable; // can be checked?
96 bool m_isChecked; // is checked?
97 bool m_isEnabled; // is enabled?
98 };
99
100 // ----------------------------------------------------------------------------
101 // include the real class declaration
102 // ----------------------------------------------------------------------------
103
104 #ifdef wxUSE_BASE_CLASSES_ONLY
105 #define wxMenuItem wxMenuItemBase
106 #else // !wxUSE_BASE_CLASSES_ONLY
107 #if defined(__WXMSW__)
108 #include "wx/msw/menuitem.h"
109 #elif defined(__WXMOTIF__)
110 #include "wx/motif/menuitem.h"
111 #elif defined(__WXGTK__)
112 #include "wx/gtk/menuitem.h"
113 #elif defined(__WXQT__)
114 #include "wx/qt/menuitem.h"
115 #elif defined(__WXMAC__)
116 #include "wx/mac/menuitem.h"
117 #elif defined(__WXPM__)
118 #include "wx/os2/menuitem.h"
119 #elif defined(__WXSTUBS__)
120 #include "wx/stubs/menuitem.h"
121 #endif
122 #endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY
123
124 #endif
125 // _WX_MENUITEM_H_BASE_