]>
Commit | Line | Data |
---|---|---|
974e8d94 VZ |
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> | |
371a5b4e | 9 | // Licence: wxWindows licence |
974e8d94 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
50414e24 JS |
12 | #ifndef _WX_MENUITEM_H_BASE_ |
13 | #define _WX_MENUITEM_H_BASE_ | |
14 | ||
1e6feb95 VZ |
15 | #if wxUSE_MENUS |
16 | ||
974e8d94 VZ |
17 | // ---------------------------------------------------------------------------- |
18 | // headers | |
19 | // ---------------------------------------------------------------------------- | |
20 | ||
21 | #include "wx/object.h" // base class | |
22 | ||
974e8d94 VZ |
23 | // ---------------------------------------------------------------------------- |
24 | // forward declarations | |
25 | // ---------------------------------------------------------------------------- | |
26 | ||
717a57c2 | 27 | class WXDLLEXPORT wxAcceleratorEntry; |
974e8d94 VZ |
28 | class WXDLLEXPORT wxMenuItem; |
29 | class WXDLLEXPORT wxMenu; | |
30 | ||
31 | // ---------------------------------------------------------------------------- | |
32 | // wxMenuItem is an item in the menu which may be either a normal item, a sub | |
33 | // menu or a separator | |
34 | // ---------------------------------------------------------------------------- | |
35 | ||
36 | class WXDLLEXPORT wxMenuItemBase : public wxObject | |
37 | { | |
38 | public: | |
39 | // creation | |
40 | static wxMenuItem *New(wxMenu *parentMenu = (wxMenu *)NULL, | |
d9e2e4c2 | 41 | int itemid = wxID_SEPARATOR, |
974e8d94 VZ |
42 | const wxString& text = wxEmptyString, |
43 | const wxString& help = wxEmptyString, | |
546bfbea | 44 | wxItemKind kind = wxITEM_NORMAL, |
974e8d94 VZ |
45 | wxMenu *subMenu = (wxMenu *)NULL); |
46 | ||
717a57c2 VZ |
47 | // destruction: wxMenuItem will delete its submenu |
48 | virtual ~wxMenuItemBase(); | |
49 | ||
3dfac970 VZ |
50 | // the menu we're in |
51 | wxMenu *GetMenu() const { return m_parentMenu; } | |
52 | ||
974e8d94 | 53 | // get/set id |
d9e2e4c2 | 54 | void SetId(int itemid) { m_id = itemid; } |
974e8d94 VZ |
55 | int GetId() const { return m_id; } |
56 | bool IsSeparator() const { return m_id == wxID_SEPARATOR; } | |
57 | ||
717a57c2 VZ |
58 | // the item's text (or name) |
59 | // | |
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 | |
63 | // in the menu | |
974e8d94 | 64 | virtual void SetText(const wxString& str) { m_text = str; } |
3b59cdbf | 65 | wxString GetLabel() const { return GetLabelFromText(m_text); } |
974e8d94 VZ |
66 | const wxString& GetText() const { return m_text; } |
67 | ||
3b59cdbf VZ |
68 | // get the label from text (implemented in platform-specific code) |
69 | static wxString GetLabelFromText(const wxString& text); | |
70 | ||
974e8d94 | 71 | // what kind of menu item we are |
d65c269b VZ |
72 | wxItemKind GetKind() const { return m_kind; } |
73 | ||
bb28b477 | 74 | virtual void SetCheckable(bool checkable) { m_kind = checkable ? wxITEM_CHECK : wxITEM_NORMAL; } |
0472ece7 | 75 | bool IsCheckable() const |
546bfbea | 76 | { return m_kind == wxITEM_CHECK || m_kind == wxITEM_RADIO; } |
974e8d94 VZ |
77 | |
78 | bool IsSubMenu() const { return m_subMenu != NULL; } | |
79 | void SetSubMenu(wxMenu *menu) { m_subMenu = menu; } | |
80 | wxMenu *GetSubMenu() const { return m_subMenu; } | |
81 | ||
82 | // state | |
83 | virtual void Enable(bool enable = TRUE) { m_isEnabled = enable; } | |
84 | virtual bool IsEnabled() const { return m_isEnabled; } | |
717a57c2 | 85 | |
974e8d94 VZ |
86 | virtual void Check(bool check = TRUE) { m_isChecked = check; } |
87 | virtual bool IsChecked() const { return m_isChecked; } | |
717a57c2 | 88 | void Toggle() { Check(!m_isChecked); } |
974e8d94 VZ |
89 | |
90 | // help string (displayed in the status bar by default) | |
91 | void SetHelp(const wxString& str) { m_help = str; } | |
92 | const wxString& GetHelp() const { return m_help; } | |
93 | ||
717a57c2 | 94 | #if wxUSE_ACCEL |
1e6feb95 VZ |
95 | // extract the accelerator from the given menu string, return NULL if none |
96 | // found | |
97 | static wxAcceleratorEntry *GetAccelFromString(const wxString& label); | |
98 | ||
717a57c2 | 99 | // get our accelerator or NULL (caller must delete the pointer) |
1e6feb95 | 100 | virtual wxAcceleratorEntry *GetAccel() const; |
717a57c2 VZ |
101 | |
102 | // set the accel for this item - this may also be done indirectly with | |
103 | // SetText() | |
104 | virtual void SetAccel(wxAcceleratorEntry *accel); | |
105 | #endif // wxUSE_ACCEL | |
106 | ||
974e8d94 VZ |
107 | // compatibility only, use new functions in the new code |
108 | void SetName(const wxString& str) { SetText(str); } | |
109 | const wxString& GetName() const { return GetText(); } | |
110 | ||
d65c269b | 111 | static wxMenuItem *New(wxMenu *parentMenu, |
d9e2e4c2 | 112 | int itemid, |
d65c269b VZ |
113 | const wxString& text, |
114 | const wxString& help, | |
115 | bool isCheckable, | |
116 | wxMenu *subMenu = (wxMenu *)NULL) | |
117 | { | |
d9e2e4c2 | 118 | return New(parentMenu, itemid, text, help, |
546bfbea | 119 | isCheckable ? wxITEM_CHECK : wxITEM_NORMAL, subMenu); |
d65c269b VZ |
120 | } |
121 | ||
974e8d94 VZ |
122 | protected: |
123 | int m_id; // numeric id of the item >= 0 or -1 | |
124 | wxMenu *m_parentMenu, // the menu we belong to | |
125 | *m_subMenu; // our sub menu or NULL | |
126 | wxString m_text, // label of the item | |
127 | m_help; // the help string for the item | |
d65c269b | 128 | wxItemKind m_kind; // seperator/normal/check/radio item? |
974e8d94 VZ |
129 | bool m_isChecked; // is checked? |
130 | bool m_isEnabled; // is enabled? | |
c0d6c58b | 131 | |
d65c269b VZ |
132 | // this ctor is for the derived classes only, we're never created directly |
133 | wxMenuItemBase(wxMenu *parentMenu = (wxMenu *)NULL, | |
d9e2e4c2 | 134 | int itemid = wxID_SEPARATOR, |
d65c269b VZ |
135 | const wxString& text = wxEmptyString, |
136 | const wxString& help = wxEmptyString, | |
546bfbea | 137 | wxItemKind kind = wxITEM_NORMAL, |
d65c269b | 138 | wxMenu *subMenu = (wxMenu *)NULL); |
7af206c1 VZ |
139 | |
140 | private: | |
141 | // and, if we have one ctor, compiler won't generate a default copy one, so | |
142 | // declare them ourselves - but don't implement as they shouldn't be used | |
143 | wxMenuItemBase(const wxMenuItemBase& item); | |
144 | wxMenuItemBase& operator=(const wxMenuItemBase& item); | |
974e8d94 VZ |
145 | }; |
146 | ||
147 | // ---------------------------------------------------------------------------- | |
148 | // include the real class declaration | |
149 | // ---------------------------------------------------------------------------- | |
150 | ||
151 | #ifdef wxUSE_BASE_CLASSES_ONLY | |
152 | #define wxMenuItem wxMenuItemBase | |
153 | #else // !wxUSE_BASE_CLASSES_ONLY | |
1e6feb95 VZ |
154 | #if defined(__WXUNIVERSAL__) |
155 | #include "wx/univ/menuitem.h" | |
156 | #elif defined(__WXMSW__) | |
974e8d94 | 157 | #include "wx/msw/menuitem.h" |
50414e24 | 158 | #elif defined(__WXMOTIF__) |
974e8d94 | 159 | #include "wx/motif/menuitem.h" |
50414e24 | 160 | #elif defined(__WXGTK__) |
974e8d94 | 161 | #include "wx/gtk/menuitem.h" |
50414e24 | 162 | #elif defined(__WXMAC__) |
974e8d94 | 163 | #include "wx/mac/menuitem.h" |
1777b9bb | 164 | #elif defined(__WXPM__) |
974e8d94 | 165 | #include "wx/os2/menuitem.h" |
c801d85f | 166 | #endif |
974e8d94 | 167 | #endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY |
c801d85f | 168 | |
1e6feb95 VZ |
169 | #endif // wxUSE_MENUS |
170 | ||
c801d85f | 171 | #endif |
50414e24 | 172 | // _WX_MENUITEM_H_BASE_ |