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