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