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