]> git.saurik.com Git - wxWidgets.git/blame - include/wx/menuitem.h
merged in the commit from the 2.2 branch
[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>
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 25class WXDLLEXPORT wxAcceleratorEntry;
974e8d94
VZ
26class WXDLLEXPORT wxMenuItem;
27class 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
34class WXDLLEXPORT wxMenuItemBase : public wxObject
35{
36public:
37 // creation
38 static wxMenuItem *New(wxMenu *parentMenu = (wxMenu *)NULL,
39 int id = wxID_SEPARATOR,
40 const wxString& text = wxEmptyString,
41 const wxString& help = wxEmptyString,
42 bool isCheckable = FALSE,
43 wxMenu *subMenu = (wxMenu *)NULL);
44
717a57c2
VZ
45 // destruction: wxMenuItem will delete its submenu
46 virtual ~wxMenuItemBase();
47
3dfac970
VZ
48 // the menu we're in
49 wxMenu *GetMenu() const { return m_parentMenu; }
50
974e8d94
VZ
51 // get/set id
52 void SetId(int id) { m_id = id; }
53 int GetId() const { return m_id; }
54 bool IsSeparator() const { return m_id == wxID_SEPARATOR; }
55
717a57c2
VZ
56 // the item's text (or name)
57 //
58 // NB: the item's text includes the accelerators and mnemonics info (if
59 // any), i.e. it may contain '&' or '_' or "\t..." and thus is
60 // different from the item's label which only contains the text shown
61 // in the menu
974e8d94 62 virtual void SetText(const wxString& str) { m_text = str; }
3b59cdbf 63 wxString GetLabel() const { return GetLabelFromText(m_text); }
974e8d94
VZ
64 const wxString& GetText() const { return m_text; }
65
3b59cdbf
VZ
66 // get the label from text (implemented in platform-specific code)
67 static wxString GetLabelFromText(const wxString& text);
68
974e8d94
VZ
69 // what kind of menu item we are
70 virtual void SetCheckable(bool checkable) { m_isCheckable = checkable; }
71 bool IsCheckable() const { return m_isCheckable; }
72
73 bool IsSubMenu() const { return m_subMenu != NULL; }
74 void SetSubMenu(wxMenu *menu) { m_subMenu = menu; }
75 wxMenu *GetSubMenu() const { return m_subMenu; }
76
77 // state
78 virtual void Enable(bool enable = TRUE) { m_isEnabled = enable; }
79 virtual bool IsEnabled() const { return m_isEnabled; }
717a57c2 80
974e8d94
VZ
81 virtual void Check(bool check = TRUE) { m_isChecked = check; }
82 virtual bool IsChecked() const { return m_isChecked; }
717a57c2 83 void Toggle() { Check(!m_isChecked); }
974e8d94
VZ
84
85 // help string (displayed in the status bar by default)
86 void SetHelp(const wxString& str) { m_help = str; }
87 const wxString& GetHelp() const { return m_help; }
88
717a57c2
VZ
89#if wxUSE_ACCEL
90 // get our accelerator or NULL (caller must delete the pointer)
91 virtual wxAcceleratorEntry *GetAccel() const { return NULL; }
92
93 // set the accel for this item - this may also be done indirectly with
94 // SetText()
95 virtual void SetAccel(wxAcceleratorEntry *accel);
96#endif // wxUSE_ACCEL
97
974e8d94
VZ
98 // compatibility only, use new functions in the new code
99 void SetName(const wxString& str) { SetText(str); }
100 const wxString& GetName() const { return GetText(); }
101
102protected:
103 int m_id; // numeric id of the item >= 0 or -1
104 wxMenu *m_parentMenu, // the menu we belong to
105 *m_subMenu; // our sub menu or NULL
106 wxString m_text, // label of the item
107 m_help; // the help string for the item
108 bool m_isCheckable; // can be checked?
109 bool m_isChecked; // is checked?
110 bool m_isEnabled; // is enabled?
c0d6c58b 111
3b59cdbf
VZ
112 // some compilers need a default constructor here, do not remove
113 wxMenuItemBase() { }
7af206c1
VZ
114
115private:
116 // and, if we have one ctor, compiler won't generate a default copy one, so
117 // declare them ourselves - but don't implement as they shouldn't be used
118 wxMenuItemBase(const wxMenuItemBase& item);
119 wxMenuItemBase& operator=(const wxMenuItemBase& item);
974e8d94
VZ
120};
121
122// ----------------------------------------------------------------------------
123// include the real class declaration
124// ----------------------------------------------------------------------------
125
126#ifdef wxUSE_BASE_CLASSES_ONLY
127 #define wxMenuItem wxMenuItemBase
128#else // !wxUSE_BASE_CLASSES_ONLY
50414e24 129#if defined(__WXMSW__)
974e8d94 130 #include "wx/msw/menuitem.h"
50414e24 131#elif defined(__WXMOTIF__)
974e8d94 132 #include "wx/motif/menuitem.h"
50414e24 133#elif defined(__WXGTK__)
974e8d94 134 #include "wx/gtk/menuitem.h"
50414e24 135#elif defined(__WXQT__)
974e8d94 136 #include "wx/qt/menuitem.h"
50414e24 137#elif defined(__WXMAC__)
974e8d94 138 #include "wx/mac/menuitem.h"
1777b9bb 139#elif defined(__WXPM__)
974e8d94 140 #include "wx/os2/menuitem.h"
50414e24 141#elif defined(__WXSTUBS__)
974e8d94 142 #include "wx/stubs/menuitem.h"
c801d85f 143#endif
974e8d94 144#endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY
c801d85f 145
c801d85f 146#endif
50414e24 147 // _WX_MENUITEM_H_BASE_