]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: menu.h | |
3 | // Purpose: wxMenu, wxMenuBar classes | |
4 | // Author: Julian Smart | |
5 | // Modified by: Vadim Zeitlin (wxMenuItem is now in separate file) | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
a3622daa | 9 | // Licence: wxWindows license |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
bbcdf8bc JS |
12 | #ifndef _WX_MENU_H_ |
13 | #define _WX_MENU_H_ | |
2bda0e17 KB |
14 | |
15 | #ifdef __GNUG__ | |
c626a8b7 | 16 | #pragma interface "menu.h" |
2bda0e17 KB |
17 | #endif |
18 | ||
3f3cec48 | 19 | #if wxUSE_ACCEL |
974e8d94 | 20 | #include "wx/accel.h" |
717a57c2 VZ |
21 | #include "wx/dynarray.h" |
22 | ||
23 | WX_DEFINE_EXPORTED_ARRAY(wxAcceleratorEntry *, wxAcceleratorArray); | |
3f3cec48 | 24 | #endif // wxUSE_ACCEL |
2bda0e17 | 25 | |
c626a8b7 | 26 | class WXDLLEXPORT wxFrame; |
2bda0e17 | 27 | |
2bda0e17 KB |
28 | // ---------------------------------------------------------------------------- |
29 | // Menu | |
30 | // ---------------------------------------------------------------------------- | |
c626a8b7 | 31 | |
717a57c2 | 32 | class WXDLLEXPORT wxMenu : public wxMenuBase |
2bda0e17 | 33 | { |
2bda0e17 | 34 | public: |
b908d224 | 35 | // ctors & dtor |
717a57c2 VZ |
36 | wxMenu(const wxString& title, long style = 0) |
37 | : wxMenuBase(title, style) { Init(); } | |
33961d59 | 38 | |
717a57c2 | 39 | wxMenu(long style = 0) : wxMenuBase(style) { Init(); } |
b908d224 | 40 | |
c626a8b7 VZ |
41 | virtual ~wxMenu(); |
42 | ||
717a57c2 VZ |
43 | // implement base class virtuals |
44 | virtual bool DoAppend(wxMenuItem *item); | |
45 | virtual bool DoInsert(size_t pos, wxMenuItem *item); | |
46 | virtual wxMenuItem *DoRemove(wxMenuItem *item); | |
47 | ||
48 | virtual void Break(); | |
49 | ||
50 | virtual void SetTitle(const wxString& title); | |
c626a8b7 | 51 | |
cc160ba6 VZ |
52 | // deprecated functions |
53 | #if wxUSE_MENU_CALLBACK | |
717a57c2 VZ |
54 | wxMenu(const wxString& title, const wxFunction func) |
55 | : wxMenuBase(title) | |
56 | { | |
4a539480 VZ |
57 | Init(); |
58 | ||
717a57c2 VZ |
59 | Callback(func); |
60 | } | |
cc160ba6 VZ |
61 | #endif // wxUSE_MENU_CALLBACK |
62 | ||
63 | // MSW-specific | |
64 | bool ProcessCommand(wxCommandEvent& event); | |
c626a8b7 | 65 | |
717a57c2 VZ |
66 | // implementation only from now on |
67 | // ------------------------------- | |
c626a8b7 | 68 | |
717a57c2 | 69 | bool MSWCommand(WXUINT param, WXWORD id); |
c626a8b7 VZ |
70 | |
71 | // semi-private accessors | |
72 | // get the window which contains this menu | |
73 | wxWindow *GetWindow() const; | |
74 | // get the menu handle | |
717a57c2 | 75 | WXHMENU GetHMenu() const { return m_hMenu; } |
2bda0e17 | 76 | |
717a57c2 | 77 | // attach/detach menu to/from wxMenuBar |
c2dcfdef VZ |
78 | void Attach(wxMenuBar *menubar); |
79 | void Detach(); | |
80 | ||
d427503c | 81 | #if wxUSE_ACCEL |
717a57c2 VZ |
82 | // called by wxMenuBar to build its accel table from the accels of all menus |
83 | bool HasAccels() const { return !m_accels.IsEmpty(); } | |
974e8d94 | 84 | size_t GetAccelCount() const { return m_accels.GetCount(); } |
42e69d6b VZ |
85 | size_t CopyAccels(wxAcceleratorEntry *accels) const; |
86 | ||
717a57c2 VZ |
87 | // called by wxMenuItem when its accels changes |
88 | void UpdateAccel(wxMenuItem *item); | |
42e69d6b | 89 | |
717a57c2 VZ |
90 | // helper used by wxMenu itself (returns the index in m_accels) |
91 | int FindAccel(int id) const; | |
92 | #endif // wxUSE_ACCEL | |
42e69d6b | 93 | |
2bda0e17 | 94 | private: |
b908d224 | 95 | // common part of all ctors |
717a57c2 VZ |
96 | void Init(); |
97 | ||
98 | // common part of Append/Insert (behaves as Append is pos == (size_t)-1) | |
99 | bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1); | |
100 | ||
101 | // if TRUE, insert a breal before appending the next item | |
102 | bool m_doBreak; | |
103 | ||
104 | // the menu handle of this menu | |
105 | WXHMENU m_hMenu; | |
42e69d6b | 106 | |
d427503c | 107 | #if wxUSE_ACCEL |
974e8d94 VZ |
108 | // the accelerators for our menu items |
109 | wxAcceleratorArray m_accels; | |
d427503c | 110 | #endif // wxUSE_ACCEL |
717a57c2 VZ |
111 | |
112 | DECLARE_DYNAMIC_CLASS(wxMenu) | |
2bda0e17 KB |
113 | }; |
114 | ||
115 | // ---------------------------------------------------------------------------- | |
116 | // Menu Bar (a la Windows) | |
117 | // ---------------------------------------------------------------------------- | |
c626a8b7 | 118 | |
a8cfd0cb | 119 | class WXDLLEXPORT wxMenuBar : public wxMenuBarBase |
2bda0e17 | 120 | { |
c626a8b7 VZ |
121 | public: |
122 | // ctors & dtor | |
c2dcfdef | 123 | // default constructor |
c626a8b7 | 124 | wxMenuBar(); |
c2dcfdef | 125 | // unused under MSW |
c626a8b7 | 126 | wxMenuBar(long style); |
c2dcfdef | 127 | // menubar takes ownership of the menus arrays but copies the titles |
c626a8b7 VZ |
128 | wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); |
129 | virtual ~wxMenuBar(); | |
130 | ||
131 | // menubar construction | |
a8cfd0cb VZ |
132 | virtual bool Append( wxMenu *menu, const wxString &title ); |
133 | virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title); | |
134 | virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title); | |
135 | virtual wxMenu *Remove(size_t pos); | |
c626a8b7 | 136 | |
a8cfd0cb VZ |
137 | virtual int FindMenuItem(const wxString& menuString, |
138 | const wxString& itemString) const; | |
139 | virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const; | |
c626a8b7 | 140 | |
a8cfd0cb VZ |
141 | virtual void EnableTop( size_t pos, bool flag ); |
142 | virtual void SetLabelTop( size_t pos, const wxString& label ); | |
143 | virtual wxString GetLabelTop( size_t pos ) const; | |
c626a8b7 | 144 | |
a8cfd0cb | 145 | // compatibility: these functions are deprecated |
600ea9da | 146 | #if WXWIN_COMPATIBILITY |
c626a8b7 VZ |
147 | void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } |
148 | wxEvtHandler *GetEventHandler() { return m_eventHandler; } | |
149 | ||
c626a8b7 VZ |
150 | bool Enabled(int id) const { return IsEnabled(id); } |
151 | bool Checked(int id) const { return IsChecked(id); } | |
152 | #endif // WXWIN_COMPATIBILITY | |
2bda0e17 | 153 | |
a8cfd0cb VZ |
154 | // implementation from now on |
155 | WXHMENU Create(); | |
156 | int FindMenu(const wxString& title); | |
157 | void Detach(); | |
158 | ||
c2dcfdef VZ |
159 | // returns TRUE if we're attached to a frame |
160 | bool IsAttached() const { return m_menuBarFrame != NULL; } | |
161 | // get the frame we live in | |
162 | wxFrame *GetFrame() const { return m_menuBarFrame; } | |
163 | // attach to a frame | |
42e69d6b | 164 | void Attach(wxFrame *frame); |
c2dcfdef | 165 | |
d427503c | 166 | #if wxUSE_ACCEL |
717a57c2 | 167 | // get the accel table for all the menus |
42e69d6b | 168 | const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; } |
717a57c2 VZ |
169 | |
170 | // update the accel table (must be called after adding/deletign a menu) | |
171 | void RebuildAccelTable(); | |
d427503c VZ |
172 | #endif // wxUSE_ACCEL |
173 | ||
c2dcfdef VZ |
174 | // get the menu handle |
175 | WXHMENU GetHMenu() const { return m_hMenu; } | |
176 | ||
c2dcfdef VZ |
177 | // if the menubar is modified, the display is not updated automatically, |
178 | // call this function to update it (m_menuBarFrame should be !NULL) | |
179 | void Refresh(); | |
180 | ||
fbb90f7f PA |
181 | protected: |
182 | // common part of all ctors | |
183 | void Init(); | |
184 | ||
600ea9da | 185 | #if WXWIN_COMPATIBILITY |
c2dcfdef | 186 | wxEvtHandler *m_eventHandler; |
a8cfd0cb VZ |
187 | #endif // WXWIN_COMPATIBILITY |
188 | ||
189 | wxArrayString m_titles; | |
190 | ||
c2dcfdef VZ |
191 | wxFrame *m_menuBarFrame; |
192 | WXHMENU m_hMenu; | |
42e69d6b | 193 | |
d427503c | 194 | #if wxUSE_ACCEL |
42e69d6b VZ |
195 | // the accelerator table for all accelerators in all our menus |
196 | wxAcceleratorTable m_accelTable; | |
d427503c | 197 | #endif // wxUSE_ACCEL |
a8cfd0cb VZ |
198 | |
199 | private: | |
200 | DECLARE_DYNAMIC_CLASS(wxMenuBar) | |
2bda0e17 KB |
201 | }; |
202 | ||
bbcdf8bc | 203 | #endif // _WX_MENU_H_ |