]>
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 | ||
974e8d94 VZ |
21 | // ---------------------------------------------------------------------------- |
22 | // forward declarations | |
23 | // ---------------------------------------------------------------------------- | |
24 | ||
717a57c2 | 25 | class WXDLLEXPORT wxAcceleratorEntry; |
974e8d94 VZ |
26 | class WXDLLEXPORT wxMenuItem; |
27 | class WXDLLEXPORT wxMenu; | |
28 | ||
29 | // ---------------------------------------------------------------------------- | |
30 | // wxMenuItem is an item in the menu which may be either a normal item, a sub | |
31 | // menu or a separator | |
32 | // ---------------------------------------------------------------------------- | |
33 | ||
34 | class WXDLLEXPORT wxMenuItemBase : public wxObject | |
35 | { | |
36 | public: | |
20e05ffb | 37 | |
974e8d94 VZ |
38 | // creation |
39 | static wxMenuItem *New(wxMenu *parentMenu = (wxMenu *)NULL, | |
40 | int id = wxID_SEPARATOR, | |
41 | const wxString& text = wxEmptyString, | |
42 | const wxString& help = wxEmptyString, | |
43 | bool isCheckable = FALSE, | |
44 | wxMenu *subMenu = (wxMenu *)NULL); | |
45 | ||
717a57c2 VZ |
46 | // destruction: wxMenuItem will delete its submenu |
47 | virtual ~wxMenuItemBase(); | |
48 | ||
3dfac970 VZ |
49 | // the menu we're in |
50 | wxMenu *GetMenu() const { return m_parentMenu; } | |
51 | ||
974e8d94 VZ |
52 | // get/set id |
53 | void SetId(int id) { m_id = id; } | |
54 | int GetId() const { return m_id; } | |
55 | bool IsSeparator() const { return m_id == wxID_SEPARATOR; } | |
56 | ||
717a57c2 VZ |
57 | // the item's text (or name) |
58 | // | |
59 | // NB: the item's text includes the accelerators and mnemonics info (if | |
60 | // any), i.e. it may contain '&' or '_' or "\t..." and thus is | |
61 | // different from the item's label which only contains the text shown | |
62 | // in the menu | |
974e8d94 | 63 | virtual void SetText(const wxString& str) { m_text = str; } |
717a57c2 | 64 | virtual wxString GetLabel() const { return m_text; } |
974e8d94 VZ |
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; } | |
717a57c2 | 78 | |
974e8d94 VZ |
79 | virtual void Check(bool check = TRUE) { m_isChecked = check; } |
80 | virtual bool IsChecked() const { return m_isChecked; } | |
717a57c2 | 81 | void Toggle() { Check(!m_isChecked); } |
974e8d94 VZ |
82 | |
83 | // help string (displayed in the status bar by default) | |
84 | void SetHelp(const wxString& str) { m_help = str; } | |
85 | const wxString& GetHelp() const { return m_help; } | |
86 | ||
717a57c2 VZ |
87 | #if wxUSE_ACCEL |
88 | // get our accelerator or NULL (caller must delete the pointer) | |
89 | virtual wxAcceleratorEntry *GetAccel() const { return NULL; } | |
90 | ||
91 | // set the accel for this item - this may also be done indirectly with | |
92 | // SetText() | |
93 | virtual void SetAccel(wxAcceleratorEntry *accel); | |
94 | #endif // wxUSE_ACCEL | |
95 | ||
974e8d94 VZ |
96 | // compatibility only, use new functions in the new code |
97 | void SetName(const wxString& str) { SetText(str); } | |
98 | const wxString& GetName() const { return GetText(); } | |
99 | ||
100 | protected: | |
101 | int m_id; // numeric id of the item >= 0 or -1 | |
102 | wxMenu *m_parentMenu, // the menu we belong to | |
103 | *m_subMenu; // our sub menu or NULL | |
104 | wxString m_text, // label of the item | |
105 | m_help; // the help string for the item | |
106 | bool m_isCheckable; // can be checked? | |
107 | bool m_isChecked; // is checked? | |
108 | bool m_isEnabled; // is enabled? | |
c0d6c58b KB |
109 | |
110 | // some compilers need a default constructor here, do not use | |
111 | wxMenuItemBase() | |
112 | { } | |
974e8d94 VZ |
113 | }; |
114 | ||
115 | // ---------------------------------------------------------------------------- | |
116 | // include the real class declaration | |
117 | // ---------------------------------------------------------------------------- | |
118 | ||
119 | #ifdef wxUSE_BASE_CLASSES_ONLY | |
120 | #define wxMenuItem wxMenuItemBase | |
121 | #else // !wxUSE_BASE_CLASSES_ONLY | |
50414e24 | 122 | #if defined(__WXMSW__) |
974e8d94 | 123 | #include "wx/msw/menuitem.h" |
50414e24 | 124 | #elif defined(__WXMOTIF__) |
974e8d94 | 125 | #include "wx/motif/menuitem.h" |
50414e24 | 126 | #elif defined(__WXGTK__) |
974e8d94 | 127 | #include "wx/gtk/menuitem.h" |
50414e24 | 128 | #elif defined(__WXQT__) |
974e8d94 | 129 | #include "wx/qt/menuitem.h" |
50414e24 | 130 | #elif defined(__WXMAC__) |
974e8d94 | 131 | #include "wx/mac/menuitem.h" |
1777b9bb | 132 | #elif defined(__WXPM__) |
974e8d94 | 133 | #include "wx/os2/menuitem.h" |
50414e24 | 134 | #elif defined(__WXSTUBS__) |
974e8d94 | 135 | #include "wx/stubs/menuitem.h" |
c801d85f | 136 | #endif |
974e8d94 | 137 | #endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY |
c801d85f | 138 | |
c801d85f | 139 | #endif |
50414e24 | 140 | // _WX_MENUITEM_H_BASE_ |