]>
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> | |
9 | // Licence: wxWindows license | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
50414e24 JS |
12 | #ifndef _WX_MENUITEM_H_BASE_ |
13 | #define _WX_MENUITEM_H_BASE_ | |
14 | ||
974e8d94 VZ |
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 | ||
717a57c2 | 36 | class WXDLLEXPORT wxAcceleratorEntry; |
974e8d94 VZ |
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: | |
20e05ffb | 48 | |
974e8d94 VZ |
49 | // creation |
50 | static wxMenuItem *New(wxMenu *parentMenu = (wxMenu *)NULL, | |
51 | int id = wxID_SEPARATOR, | |
52 | const wxString& text = wxEmptyString, | |
53 | const wxString& help = wxEmptyString, | |
54 | bool isCheckable = FALSE, | |
55 | wxMenu *subMenu = (wxMenu *)NULL); | |
56 | ||
717a57c2 VZ |
57 | // destruction: wxMenuItem will delete its submenu |
58 | virtual ~wxMenuItemBase(); | |
59 | ||
3dfac970 VZ |
60 | // the menu we're in |
61 | wxMenu *GetMenu() const { return m_parentMenu; } | |
62 | ||
974e8d94 VZ |
63 | // get/set id |
64 | void SetId(int id) { m_id = id; } | |
65 | int GetId() const { return m_id; } | |
66 | bool IsSeparator() const { return m_id == wxID_SEPARATOR; } | |
67 | ||
717a57c2 VZ |
68 | // the item's text (or name) |
69 | // | |
70 | // NB: the item's text includes the accelerators and mnemonics info (if | |
71 | // any), i.e. it may contain '&' or '_' or "\t..." and thus is | |
72 | // different from the item's label which only contains the text shown | |
73 | // in the menu | |
974e8d94 | 74 | virtual void SetText(const wxString& str) { m_text = str; } |
717a57c2 | 75 | virtual wxString GetLabel() const { return m_text; } |
974e8d94 VZ |
76 | const wxString& GetText() const { return m_text; } |
77 | ||
78 | // what kind of menu item we are | |
79 | virtual void SetCheckable(bool checkable) { m_isCheckable = checkable; } | |
80 | bool IsCheckable() const { return m_isCheckable; } | |
81 | ||
82 | bool IsSubMenu() const { return m_subMenu != NULL; } | |
83 | void SetSubMenu(wxMenu *menu) { m_subMenu = menu; } | |
84 | wxMenu *GetSubMenu() const { return m_subMenu; } | |
85 | ||
86 | // state | |
87 | virtual void Enable(bool enable = TRUE) { m_isEnabled = enable; } | |
88 | virtual bool IsEnabled() const { return m_isEnabled; } | |
717a57c2 | 89 | |
974e8d94 VZ |
90 | virtual void Check(bool check = TRUE) { m_isChecked = check; } |
91 | virtual bool IsChecked() const { return m_isChecked; } | |
717a57c2 | 92 | void Toggle() { Check(!m_isChecked); } |
974e8d94 VZ |
93 | |
94 | // help string (displayed in the status bar by default) | |
95 | void SetHelp(const wxString& str) { m_help = str; } | |
96 | const wxString& GetHelp() const { return m_help; } | |
97 | ||
717a57c2 VZ |
98 | #if wxUSE_ACCEL |
99 | // get our accelerator or NULL (caller must delete the pointer) | |
100 | virtual wxAcceleratorEntry *GetAccel() const { return NULL; } | |
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 | ||
111 | protected: | |
112 | int m_id; // numeric id of the item >= 0 or -1 | |
113 | wxMenu *m_parentMenu, // the menu we belong to | |
114 | *m_subMenu; // our sub menu or NULL | |
115 | wxString m_text, // label of the item | |
116 | m_help; // the help string for the item | |
117 | bool m_isCheckable; // can be checked? | |
118 | bool m_isChecked; // is checked? | |
119 | bool m_isEnabled; // is enabled? | |
c0d6c58b KB |
120 | |
121 | // some compilers need a default constructor here, do not use | |
122 | wxMenuItemBase() | |
123 | { } | |
974e8d94 VZ |
124 | }; |
125 | ||
126 | // ---------------------------------------------------------------------------- | |
127 | // include the real class declaration | |
128 | // ---------------------------------------------------------------------------- | |
129 | ||
130 | #ifdef wxUSE_BASE_CLASSES_ONLY | |
131 | #define wxMenuItem wxMenuItemBase | |
132 | #else // !wxUSE_BASE_CLASSES_ONLY | |
50414e24 | 133 | #if defined(__WXMSW__) |
974e8d94 | 134 | #include "wx/msw/menuitem.h" |
50414e24 | 135 | #elif defined(__WXMOTIF__) |
974e8d94 | 136 | #include "wx/motif/menuitem.h" |
50414e24 | 137 | #elif defined(__WXGTK__) |
974e8d94 | 138 | #include "wx/gtk/menuitem.h" |
50414e24 | 139 | #elif defined(__WXQT__) |
974e8d94 | 140 | #include "wx/qt/menuitem.h" |
50414e24 | 141 | #elif defined(__WXMAC__) |
974e8d94 | 142 | #include "wx/mac/menuitem.h" |
1777b9bb | 143 | #elif defined(__WXPM__) |
974e8d94 | 144 | #include "wx/os2/menuitem.h" |
50414e24 | 145 | #elif defined(__WXSTUBS__) |
974e8d94 | 146 | #include "wx/stubs/menuitem.h" |
c801d85f | 147 | #endif |
974e8d94 | 148 | #endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY |
c801d85f | 149 | |
c801d85f | 150 | #endif |
50414e24 | 151 | // _WX_MENUITEM_H_BASE_ |