]> git.saurik.com Git - wxWidgets.git/blame - include/wx/menuitem.h
reSWIGged
[wxWidgets.git] / include / wx / menuitem.h
CommitLineData
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 27class WXDLLEXPORT wxAcceleratorEntry;
974e8d94
VZ
28class WXDLLEXPORT wxMenuItem;
29class 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
36class WXDLLEXPORT wxMenuItemBase : public wxObject
37{
38public:
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; }
1e93ca17 52 void SetMenu(wxMenu* menu) { m_parentMenu = menu; }
3dfac970 53
974e8d94 54 // get/set id
d9e2e4c2 55 void SetId(int itemid) { m_id = itemid; }
974e8d94
VZ
56 int GetId() const { return m_id; }
57 bool IsSeparator() const { return m_id == wxID_SEPARATOR; }
58
717a57c2
VZ
59 // the item's text (or name)
60 //
61 // NB: the item's text includes the accelerators and mnemonics info (if
62 // any), i.e. it may contain '&' or '_' or "\t..." and thus is
63 // different from the item's label which only contains the text shown
64 // in the menu
974e8d94 65 virtual void SetText(const wxString& str) { m_text = str; }
3b59cdbf 66 wxString GetLabel() const { return GetLabelFromText(m_text); }
974e8d94
VZ
67 const wxString& GetText() const { return m_text; }
68
3b59cdbf
VZ
69 // get the label from text (implemented in platform-specific code)
70 static wxString GetLabelFromText(const wxString& text);
71
974e8d94 72 // what kind of menu item we are
d65c269b 73 wxItemKind GetKind() const { return m_kind; }
d36d8dd7 74 void SetKind(wxItemKind kind) { m_kind = kind; }
d65c269b 75
bb28b477 76 virtual void SetCheckable(bool checkable) { m_kind = checkable ? wxITEM_CHECK : wxITEM_NORMAL; }
0472ece7 77 bool IsCheckable() const
546bfbea 78 { return m_kind == wxITEM_CHECK || m_kind == wxITEM_RADIO; }
974e8d94
VZ
79
80 bool IsSubMenu() const { return m_subMenu != NULL; }
81 void SetSubMenu(wxMenu *menu) { m_subMenu = menu; }
82 wxMenu *GetSubMenu() const { return m_subMenu; }
83
84 // state
85 virtual void Enable(bool enable = TRUE) { m_isEnabled = enable; }
86 virtual bool IsEnabled() const { return m_isEnabled; }
717a57c2 87
974e8d94
VZ
88 virtual void Check(bool check = TRUE) { m_isChecked = check; }
89 virtual bool IsChecked() const { return m_isChecked; }
717a57c2 90 void Toggle() { Check(!m_isChecked); }
974e8d94
VZ
91
92 // help string (displayed in the status bar by default)
93 void SetHelp(const wxString& str) { m_help = str; }
94 const wxString& GetHelp() const { return m_help; }
95
717a57c2 96#if wxUSE_ACCEL
1e6feb95
VZ
97 // extract the accelerator from the given menu string, return NULL if none
98 // found
99 static wxAcceleratorEntry *GetAccelFromString(const wxString& label);
100
717a57c2 101 // get our accelerator or NULL (caller must delete the pointer)
1e6feb95 102 virtual wxAcceleratorEntry *GetAccel() const;
717a57c2
VZ
103
104 // set the accel for this item - this may also be done indirectly with
105 // SetText()
106 virtual void SetAccel(wxAcceleratorEntry *accel);
107#endif // wxUSE_ACCEL
108
974e8d94
VZ
109 // compatibility only, use new functions in the new code
110 void SetName(const wxString& str) { SetText(str); }
111 const wxString& GetName() const { return GetText(); }
112
d65c269b 113 static wxMenuItem *New(wxMenu *parentMenu,
d9e2e4c2 114 int itemid,
d65c269b
VZ
115 const wxString& text,
116 const wxString& help,
117 bool isCheckable,
118 wxMenu *subMenu = (wxMenu *)NULL)
119 {
d9e2e4c2 120 return New(parentMenu, itemid, text, help,
546bfbea 121 isCheckable ? wxITEM_CHECK : wxITEM_NORMAL, subMenu);
d65c269b
VZ
122 }
123
974e8d94
VZ
124protected:
125 int m_id; // numeric id of the item >= 0 or -1
126 wxMenu *m_parentMenu, // the menu we belong to
127 *m_subMenu; // our sub menu or NULL
128 wxString m_text, // label of the item
129 m_help; // the help string for the item
d65c269b 130 wxItemKind m_kind; // seperator/normal/check/radio item?
974e8d94
VZ
131 bool m_isChecked; // is checked?
132 bool m_isEnabled; // is enabled?
c0d6c58b 133
d65c269b
VZ
134 // this ctor is for the derived classes only, we're never created directly
135 wxMenuItemBase(wxMenu *parentMenu = (wxMenu *)NULL,
d9e2e4c2 136 int itemid = wxID_SEPARATOR,
d65c269b
VZ
137 const wxString& text = wxEmptyString,
138 const wxString& help = wxEmptyString,
546bfbea 139 wxItemKind kind = wxITEM_NORMAL,
d65c269b 140 wxMenu *subMenu = (wxMenu *)NULL);
7af206c1
VZ
141
142private:
143 // and, if we have one ctor, compiler won't generate a default copy one, so
144 // declare them ourselves - but don't implement as they shouldn't be used
145 wxMenuItemBase(const wxMenuItemBase& item);
146 wxMenuItemBase& operator=(const wxMenuItemBase& item);
974e8d94
VZ
147};
148
149// ----------------------------------------------------------------------------
150// include the real class declaration
151// ----------------------------------------------------------------------------
152
153#ifdef wxUSE_BASE_CLASSES_ONLY
154 #define wxMenuItem wxMenuItemBase
155#else // !wxUSE_BASE_CLASSES_ONLY
1e6feb95
VZ
156#if defined(__WXUNIVERSAL__)
157 #include "wx/univ/menuitem.h"
158#elif defined(__WXMSW__)
974e8d94 159 #include "wx/msw/menuitem.h"
50414e24 160#elif defined(__WXMOTIF__)
974e8d94 161 #include "wx/motif/menuitem.h"
50414e24 162#elif defined(__WXGTK__)
974e8d94 163 #include "wx/gtk/menuitem.h"
50414e24 164#elif defined(__WXMAC__)
974e8d94 165 #include "wx/mac/menuitem.h"
e64df9bc
DE
166#elif defined(__WXCOCOA__)
167 #include "wx/cocoa/menuitem.h"
1777b9bb 168#elif defined(__WXPM__)
974e8d94 169 #include "wx/os2/menuitem.h"
c801d85f 170#endif
974e8d94 171#endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY
c801d85f 172
1e6feb95
VZ
173#endif // wxUSE_MENUS
174
c801d85f 175#endif
50414e24 176 // _WX_MENUITEM_H_BASE_