]>
Commit | Line | Data |
---|---|---|
717a57c2 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: samples/menu.cpp | |
3 | // Purpose: wxMenu/wxMenuBar sample | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 01.11.99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1999 Vadim Zeitlin | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // For compilers that support precompilation, includes "wx/wx.h". | |
92a19c2e | 21 | #include "wx/wxprec.h" |
717a57c2 VZ |
22 | |
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #ifndef WX_PRECOMP | |
f91bf72f GD |
28 | #include "wx/app.h" |
29 | #include "wx/frame.h" | |
30 | #include "wx/menu.h" | |
31 | #include "wx/msgdlg.h" | |
32 | #include "wx/log.h" | |
33 | #include "wx/textctrl.h" | |
5c7766de | 34 | #include "wx/textdlg.h" |
717a57c2 VZ |
35 | #endif |
36 | ||
6d5b2a57 VZ |
37 | #if !wxUSE_MENUS |
38 | // nice try... | |
39 | #error "menu sample requires wxUSE_MENUS=1" | |
40 | #endif // wxUSE_MENUS | |
41 | ||
62ad15a5 VZ |
42 | // not all ports have support for EVT_CONTEXT_MENU yet, don't define |
43 | // USE_CONTEXT_MENU for those which don't | |
ba8eb933 | 44 | #if defined(__WXMOTIF__) || defined(__WXPM__) |
51a9eb73 VZ |
45 | #define USE_CONTEXT_MENU 0 |
46 | #else | |
47 | #define USE_CONTEXT_MENU 1 | |
62ad15a5 VZ |
48 | #endif |
49 | ||
fcaf9e70 RR |
50 | #include "copy.xpm" |
51 | ||
717a57c2 VZ |
52 | // ---------------------------------------------------------------------------- |
53 | // classes | |
54 | // ---------------------------------------------------------------------------- | |
55 | ||
56 | // Define a new application | |
57 | class MyApp: public wxApp | |
58 | { | |
59 | public: | |
60 | bool OnInit(); | |
61 | }; | |
62 | ||
63 | // Define a new frame | |
64 | class MyFrame: public wxFrame | |
65 | { | |
66 | public: | |
67 | MyFrame(); | |
68 | ||
3ca6a5f0 BP |
69 | virtual ~MyFrame(); |
70 | ||
71 | void LogMenuEvent(const wxCommandEvent& event); | |
717a57c2 | 72 | |
e421922f | 73 | protected: |
717a57c2 | 74 | void OnQuit(wxCommandEvent& event); |
e421922f VZ |
75 | void OnClearLog(wxCommandEvent& event); |
76 | ||
717a57c2 VZ |
77 | void OnAbout(wxCommandEvent& event); |
78 | ||
79 | void OnDummy(wxCommandEvent& event); | |
80 | ||
81 | void OnAppendMenuItem(wxCommandEvent& event); | |
82 | void OnAppendSubMenu(wxCommandEvent& event); | |
83 | void OnDeleteMenuItem(wxCommandEvent& event); | |
84 | void OnInsertMenuItem(wxCommandEvent& event); | |
85 | void OnCheckMenuItem(wxCommandEvent& event); | |
86 | void OnEnableMenuItem(wxCommandEvent& event); | |
87 | void OnGetLabelMenuItem(wxCommandEvent& event); | |
88 | void OnSetLabelMenuItem(wxCommandEvent& event); | |
a80c322c | 89 | void OnGetMenuItemInfo(wxCommandEvent& event); |
f6d90fb9 | 90 | void OnFindMenuItem(wxCommandEvent& event); |
717a57c2 VZ |
91 | |
92 | void OnAppendMenu(wxCommandEvent& event); | |
f03ec224 | 93 | void OnInsertMenu(wxCommandEvent& event); |
717a57c2 VZ |
94 | void OnDeleteMenu(wxCommandEvent& event); |
95 | void OnToggleMenu(wxCommandEvent& event); | |
96 | void OnEnableMenu(wxCommandEvent& event); | |
97 | void OnGetLabelMenu(wxCommandEvent& event); | |
98 | void OnSetLabelMenu(wxCommandEvent& event); | |
f6d90fb9 | 99 | void OnFindMenu(wxCommandEvent& event); |
717a57c2 | 100 | |
d65c269b VZ |
101 | void OnTestNormal(wxCommandEvent& event); |
102 | void OnTestCheck(wxCommandEvent& event); | |
103 | void OnTestRadio(wxCommandEvent& event); | |
104 | ||
c377f1be JS |
105 | void OnUpdateSubMenuNormal(wxUpdateUIEvent& event); |
106 | void OnUpdateSubMenuCheck(wxUpdateUIEvent& event); | |
107 | void OnUpdateSubMenuRadio(wxUpdateUIEvent& event); | |
108 | ||
62ad15a5 | 109 | #if USE_CONTEXT_MENU |
ccef86c7 VZ |
110 | void OnContextMenu(wxContextMenuEvent& event) |
111 | { ShowContextMenu(ScreenToClient(event.GetPosition())); } | |
112 | #else | |
113 | void OnRightUp(wxMouseEvent& event) | |
114 | { ShowContextMenu(event.GetPosition()); } | |
115 | #endif | |
116 | ||
117 | void OnMenuOpen(wxMenuEvent& event) | |
deadb443 | 118 | { LogMenuOpenOrClose(event, _T("opened")); event.Skip(); } |
ccef86c7 | 119 | void OnMenuClose(wxMenuEvent& event) |
deadb443 | 120 | { LogMenuOpenOrClose(event, _T("closed")); event.Skip(); } |
717a57c2 VZ |
121 | |
122 | void OnUpdateCheckMenuItemUI(wxUpdateUIEvent& event); | |
123 | ||
e421922f VZ |
124 | void OnSize(wxSizeEvent& event); |
125 | ||
717a57c2 | 126 | private: |
ccef86c7 VZ |
127 | void LogMenuOpenOrClose(const wxMenuEvent& event, const wxChar *what); |
128 | void ShowContextMenu(const wxPoint& pos); | |
129 | ||
f03ec224 | 130 | wxMenu *CreateDummyMenu(wxString *title); |
717a57c2 VZ |
131 | |
132 | wxMenuItem *GetLastMenuItem() const; | |
133 | ||
e421922f VZ |
134 | // the menu previously detached from the menubar (may be NULL) |
135 | wxMenu *m_menu; | |
717a57c2 | 136 | |
e421922f | 137 | // the count of dummy menus already created |
f03ec224 VZ |
138 | size_t m_countDummy; |
139 | ||
e421922f VZ |
140 | // the control used for logging |
141 | wxTextCtrl *m_textctrl; | |
142 | ||
143 | // the previous log target | |
144 | wxLog *m_logOld; | |
145 | ||
717a57c2 VZ |
146 | DECLARE_EVENT_TABLE() |
147 | }; | |
148 | ||
3ca6a5f0 BP |
149 | // A small helper class which intercepts all menu events and logs them |
150 | class MyEvtHandler : public wxEvtHandler | |
151 | { | |
152 | public: | |
153 | MyEvtHandler(MyFrame *frame) { m_frame = frame; } | |
154 | ||
155 | void OnMenuEvent(wxCommandEvent& event) | |
156 | { | |
157 | m_frame->LogMenuEvent(event); | |
158 | ||
159 | event.Skip(); | |
160 | } | |
161 | ||
162 | private: | |
163 | MyFrame *m_frame; | |
164 | ||
165 | DECLARE_EVENT_TABLE() | |
166 | }; | |
167 | ||
717a57c2 VZ |
168 | // ---------------------------------------------------------------------------- |
169 | // constants | |
170 | // ---------------------------------------------------------------------------- | |
171 | ||
172 | enum | |
173 | { | |
174 | Menu_File_Quit = 100, | |
e421922f | 175 | Menu_File_ClearLog, |
717a57c2 VZ |
176 | |
177 | Menu_MenuBar_Toggle = 200, | |
178 | Menu_MenuBar_Append, | |
f03ec224 | 179 | Menu_MenuBar_Insert, |
717a57c2 VZ |
180 | Menu_MenuBar_Delete, |
181 | Menu_MenuBar_Enable, | |
182 | Menu_MenuBar_GetLabel, | |
183 | Menu_MenuBar_SetLabel, | |
f6d90fb9 | 184 | Menu_MenuBar_FindMenu, |
717a57c2 VZ |
185 | |
186 | Menu_Menu_Append = 300, | |
187 | Menu_Menu_AppendSub, | |
188 | Menu_Menu_Insert, | |
189 | Menu_Menu_Delete, | |
190 | Menu_Menu_Enable, | |
191 | Menu_Menu_Check, | |
192 | Menu_Menu_GetLabel, | |
193 | Menu_Menu_SetLabel, | |
a80c322c | 194 | Menu_Menu_GetInfo, |
f6d90fb9 | 195 | Menu_Menu_FindItem, |
717a57c2 | 196 | |
d65c269b VZ |
197 | Menu_Test_Normal = 400, |
198 | Menu_Test_Check, | |
199 | Menu_Test_Radio1, | |
200 | Menu_Test_Radio2, | |
201 | Menu_Test_Radio3, | |
202 | ||
c377f1be JS |
203 | Menu_SubMenu = 450, |
204 | Menu_SubMenu_Normal, | |
205 | Menu_SubMenu_Check, | |
206 | Menu_SubMenu_Radio1, | |
207 | Menu_SubMenu_Radio2, | |
208 | Menu_SubMenu_Radio3, | |
209 | ||
d65c269b | 210 | Menu_Dummy_First = 500, |
717a57c2 VZ |
211 | Menu_Dummy_Second, |
212 | Menu_Dummy_Third, | |
213 | Menu_Dummy_Fourth, | |
214 | Menu_Dummy_Last, | |
215 | ||
216 | Menu_Help_About = 1000, | |
217 | ||
218 | Menu_Popup_ToBeDeleted = 2000, | |
219 | Menu_Popup_ToBeGreyed, | |
220 | Menu_Popup_ToBeChecked, | |
221 | Menu_Popup_Submenu, | |
222 | ||
223 | Menu_Max | |
224 | }; | |
225 | ||
226 | // ---------------------------------------------------------------------------- | |
227 | // event tables | |
228 | // ---------------------------------------------------------------------------- | |
229 | ||
230 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
e421922f VZ |
231 | EVT_MENU(Menu_File_Quit, MyFrame::OnQuit) |
232 | EVT_MENU(Menu_File_ClearLog, MyFrame::OnClearLog) | |
717a57c2 VZ |
233 | |
234 | EVT_MENU(Menu_Help_About, MyFrame::OnAbout) | |
235 | ||
236 | EVT_MENU(Menu_MenuBar_Toggle, MyFrame::OnToggleMenu) | |
237 | EVT_MENU(Menu_MenuBar_Append, MyFrame::OnAppendMenu) | |
f03ec224 | 238 | EVT_MENU(Menu_MenuBar_Insert, MyFrame::OnInsertMenu) |
717a57c2 VZ |
239 | EVT_MENU(Menu_MenuBar_Delete, MyFrame::OnDeleteMenu) |
240 | EVT_MENU(Menu_MenuBar_Enable, MyFrame::OnEnableMenu) | |
241 | EVT_MENU(Menu_MenuBar_GetLabel, MyFrame::OnGetLabelMenu) | |
242 | EVT_MENU(Menu_MenuBar_SetLabel, MyFrame::OnSetLabelMenu) | |
f6d90fb9 | 243 | EVT_MENU(Menu_MenuBar_FindMenu, MyFrame::OnFindMenu) |
717a57c2 VZ |
244 | |
245 | EVT_MENU(Menu_Menu_Append, MyFrame::OnAppendMenuItem) | |
246 | EVT_MENU(Menu_Menu_AppendSub, MyFrame::OnAppendSubMenu) | |
247 | EVT_MENU(Menu_Menu_Insert, MyFrame::OnInsertMenuItem) | |
248 | EVT_MENU(Menu_Menu_Delete, MyFrame::OnDeleteMenuItem) | |
249 | EVT_MENU(Menu_Menu_Enable, MyFrame::OnEnableMenuItem) | |
a80c322c | 250 | EVT_MENU(Menu_Menu_Check, MyFrame::OnCheckMenuItem) |
717a57c2 VZ |
251 | EVT_MENU(Menu_Menu_GetLabel, MyFrame::OnGetLabelMenuItem) |
252 | EVT_MENU(Menu_Menu_SetLabel, MyFrame::OnSetLabelMenuItem) | |
a80c322c | 253 | EVT_MENU(Menu_Menu_GetInfo, MyFrame::OnGetMenuItemInfo) |
f6d90fb9 | 254 | EVT_MENU(Menu_Menu_FindItem, MyFrame::OnFindMenuItem) |
717a57c2 | 255 | |
d65c269b VZ |
256 | EVT_MENU(Menu_Test_Normal, MyFrame::OnTestNormal) |
257 | EVT_MENU(Menu_Test_Check, MyFrame::OnTestCheck) | |
258 | EVT_MENU(Menu_Test_Radio1, MyFrame::OnTestRadio) | |
259 | EVT_MENU(Menu_Test_Radio2, MyFrame::OnTestRadio) | |
260 | EVT_MENU(Menu_Test_Radio3, MyFrame::OnTestRadio) | |
261 | ||
c377f1be JS |
262 | EVT_UPDATE_UI(Menu_SubMenu_Normal, MyFrame::OnUpdateSubMenuNormal) |
263 | EVT_UPDATE_UI(Menu_SubMenu_Check, MyFrame::OnUpdateSubMenuCheck) | |
264 | EVT_UPDATE_UI(Menu_SubMenu_Radio1, MyFrame::OnUpdateSubMenuRadio) | |
265 | EVT_UPDATE_UI(Menu_SubMenu_Radio2, MyFrame::OnUpdateSubMenuRadio) | |
266 | EVT_UPDATE_UI(Menu_SubMenu_Radio3, MyFrame::OnUpdateSubMenuRadio) | |
267 | ||
717a57c2 VZ |
268 | EVT_MENU_RANGE(Menu_Dummy_First, Menu_Dummy_Last, MyFrame::OnDummy) |
269 | ||
270 | EVT_UPDATE_UI(Menu_Menu_Check, MyFrame::OnUpdateCheckMenuItemUI) | |
271 | ||
62ad15a5 | 272 | #if USE_CONTEXT_MENU |
ccef86c7 VZ |
273 | EVT_CONTEXT_MENU(MyFrame::OnContextMenu) |
274 | #else | |
e421922f | 275 | EVT_RIGHT_UP(MyFrame::OnRightUp) |
ccef86c7 VZ |
276 | #endif |
277 | ||
278 | EVT_MENU_OPEN(MyFrame::OnMenuOpen) | |
279 | EVT_MENU_CLOSE(MyFrame::OnMenuClose) | |
e421922f VZ |
280 | |
281 | EVT_SIZE(MyFrame::OnSize) | |
717a57c2 VZ |
282 | END_EVENT_TABLE() |
283 | ||
3ca6a5f0 BP |
284 | BEGIN_EVENT_TABLE(MyEvtHandler, wxEvtHandler) |
285 | EVT_MENU(-1, MyEvtHandler::OnMenuEvent) | |
286 | END_EVENT_TABLE() | |
287 | ||
717a57c2 VZ |
288 | // ============================================================================ |
289 | // implementation | |
290 | // ============================================================================ | |
291 | ||
292 | // ---------------------------------------------------------------------------- | |
293 | // MyApp | |
294 | // ---------------------------------------------------------------------------- | |
295 | ||
296 | IMPLEMENT_APP(MyApp) | |
297 | ||
298 | // The `main program' equivalent, creating the windows and returning the | |
299 | // main frame | |
300 | bool MyApp::OnInit() | |
301 | { | |
302 | // Create the main frame window | |
303 | MyFrame* frame = new MyFrame; | |
304 | ||
6ee9b7b5 | 305 | frame->Show(true); |
717a57c2 | 306 | |
6d5b2a57 | 307 | #if wxUSE_STATUSBAR |
42ed7532 | 308 | frame->SetStatusText(_T("Welcome to wxWindows menu sample")); |
6d5b2a57 | 309 | #endif // wxUSE_STATUSBAR |
717a57c2 VZ |
310 | |
311 | SetTopWindow(frame); | |
312 | ||
6ee9b7b5 | 313 | return true; |
717a57c2 VZ |
314 | } |
315 | ||
316 | // ---------------------------------------------------------------------------- | |
317 | // MyFrame | |
318 | // ---------------------------------------------------------------------------- | |
319 | ||
320 | // Define my frame constructor | |
321 | MyFrame::MyFrame() | |
42ed7532 | 322 | : wxFrame((wxFrame *)NULL, -1, _T("wxWindows menu sample"), |
5c7766de | 323 | wxDefaultPosition, wxSize(400, 250)) |
717a57c2 | 324 | { |
268766dd | 325 | m_textctrl = NULL; |
717a57c2 | 326 | m_menu = NULL; |
f03ec224 | 327 | m_countDummy = 0; |
e421922f | 328 | m_logOld = NULL; |
717a57c2 | 329 | |
6d5b2a57 | 330 | #if wxUSE_STATUSBAR |
e421922f | 331 | CreateStatusBar(); |
6d5b2a57 | 332 | #endif // wxUSE_STATUSBAR |
717a57c2 VZ |
333 | |
334 | // create the menubar | |
335 | wxMenu *fileMenu = new wxMenu; | |
6d5b2a57 | 336 | |
e421922f | 337 | wxMenuItem *item = new wxMenuItem(fileMenu, Menu_File_ClearLog, |
42ed7532 | 338 | _T("Clear &log\tCtrl-L")); |
e421922f VZ |
339 | item->SetBitmap(copy_xpm); |
340 | fileMenu->Append(item); | |
341 | fileMenu->AppendSeparator(); | |
42ed7532 | 342 | fileMenu->Append(Menu_File_Quit, _T("E&xit\tAlt-X"), _T("Quit menu sample")); |
717a57c2 VZ |
343 | |
344 | wxMenu *menubarMenu = new wxMenu; | |
42ed7532 MB |
345 | menubarMenu->Append(Menu_MenuBar_Append, _T("&Append menu\tCtrl-A"), |
346 | _T("Append a menu to the menubar")); | |
347 | menubarMenu->Append(Menu_MenuBar_Insert, _T("&Insert menu\tCtrl-I"), | |
348 | _T("Insert a menu into the menubar")); | |
349 | menubarMenu->Append(Menu_MenuBar_Delete, _T("&Delete menu\tCtrl-D"), | |
350 | _T("Delete the last menu from the menubar")); | |
351 | menubarMenu->Append(Menu_MenuBar_Toggle, _T("&Toggle menu\tCtrl-T"), | |
6ee9b7b5 | 352 | _T("Toggle the first menu in the menubar"), true); |
717a57c2 | 353 | menubarMenu->AppendSeparator(); |
42ed7532 | 354 | menubarMenu->Append(Menu_MenuBar_Enable, _T("&Enable menu\tCtrl-E"), |
6ee9b7b5 | 355 | _T("Enable or disable the last menu"), true); |
717a57c2 | 356 | menubarMenu->AppendSeparator(); |
42ed7532 MB |
357 | menubarMenu->Append(Menu_MenuBar_GetLabel, _T("&Get menu label\tCtrl-G"), |
358 | _T("Get the label of the last menu")); | |
359 | menubarMenu->Append(Menu_MenuBar_SetLabel, _T("&Set menu label\tCtrl-S"), | |
360 | _T("Change the label of the last menu")); | |
f6d90fb9 | 361 | menubarMenu->AppendSeparator(); |
42ed7532 MB |
362 | menubarMenu->Append(Menu_MenuBar_FindMenu, _T("&Find menu from label\tCtrl-F"), |
363 | _T("Find a menu by searching for its label")); | |
717a57c2 | 364 | |
c377f1be JS |
365 | wxMenu* subMenu = new wxMenu; |
366 | subMenu->Append(Menu_SubMenu_Normal, _T("&Normal submenu item"), _T("Disabled submenu item")); | |
367 | subMenu->AppendCheckItem(Menu_SubMenu_Check, _T("&Unchecked submenu item"), _T("Unchecked submenu item")); | |
368 | subMenu->AppendRadioItem(Menu_SubMenu_Radio1, _T("&Radio item 1"), _T("Radio item")); | |
369 | subMenu->AppendRadioItem(Menu_SubMenu_Radio2, _T("&Radio item 2"), _T("Radio item")); | |
370 | subMenu->AppendRadioItem(Menu_SubMenu_Radio3, _T("&Radio item 3"), _T("Radio item")); | |
371 | ||
372 | menubarMenu->Append(Menu_SubMenu, _T("Submenu"), subMenu); | |
373 | ||
717a57c2 | 374 | wxMenu *menuMenu = new wxMenu; |
42ed7532 MB |
375 | menuMenu->Append(Menu_Menu_Append, _T("&Append menu item\tAlt-A"), |
376 | _T("Append a menu item to the last menu")); | |
377 | menuMenu->Append(Menu_Menu_AppendSub, _T("&Append sub menu\tAlt-S"), | |
378 | _T("Append a sub menu to the last menu")); | |
379 | menuMenu->Append(Menu_Menu_Insert, _T("&Insert menu item\tAlt-I"), | |
380 | _T("Insert a menu item in head of the last menu")); | |
381 | menuMenu->Append(Menu_Menu_Delete, _T("&Delete menu item\tAlt-D"), | |
382 | _T("Delete the last menu item from the last menu")); | |
717a57c2 | 383 | menuMenu->AppendSeparator(); |
42ed7532 | 384 | menuMenu->Append(Menu_Menu_Enable, _T("&Enable menu item\tAlt-E"), |
6ee9b7b5 | 385 | _T("Enable or disable the last menu item"), true); |
42ed7532 | 386 | menuMenu->Append(Menu_Menu_Check, _T("&Check menu item\tAlt-C"), |
6ee9b7b5 | 387 | _T("Check or uncheck the last menu item"), true); |
717a57c2 | 388 | menuMenu->AppendSeparator(); |
42ed7532 MB |
389 | menuMenu->Append(Menu_Menu_GetInfo, _T("Get menu item in&fo\tAlt-F"), |
390 | _T("Show the state of the last menu item")); | |
a80c322c | 391 | menuMenu->AppendSeparator(); |
42ed7532 MB |
392 | menuMenu->Append(Menu_Menu_FindItem, _T("Find menu item from label"), |
393 | _T("Find a menu item by searching for its label")); | |
717a57c2 | 394 | |
d65c269b | 395 | wxMenu *testMenu = new wxMenu; |
42ed7532 | 396 | testMenu->Append(Menu_Test_Normal, _T("&Normal item")); |
d65c269b | 397 | testMenu->AppendSeparator(); |
42ed7532 | 398 | testMenu->AppendCheckItem(Menu_Test_Check, _T("&Check item")); |
d65c269b | 399 | testMenu->AppendSeparator(); |
42ed7532 MB |
400 | testMenu->AppendRadioItem(Menu_Test_Radio1, _T("Radio item &1")); |
401 | testMenu->AppendRadioItem(Menu_Test_Radio2, _T("Radio item &2")); | |
402 | testMenu->AppendRadioItem(Menu_Test_Radio3, _T("Radio item &3")); | |
d65c269b | 403 | |
717a57c2 | 404 | wxMenu *helpMenu = new wxMenu; |
42ed7532 | 405 | helpMenu->Append(Menu_Help_About, _T("&About\tF1"), _T("About menu sample")); |
717a57c2 VZ |
406 | |
407 | wxMenuBar* menuBar = new wxMenuBar( wxMB_DOCKABLE ); | |
408 | ||
42ed7532 MB |
409 | menuBar->Append(fileMenu, _T("&File")); |
410 | menuBar->Append(menubarMenu, _T("Menu&bar")); | |
411 | menuBar->Append(menuMenu, _T("&Menu")); | |
412 | menuBar->Append(testMenu, _T("&Test")); | |
413 | menuBar->Append(helpMenu, _T("&Help")); | |
717a57c2 VZ |
414 | |
415 | // these items should be initially checked | |
6ee9b7b5 JS |
416 | menuBar->Check(Menu_MenuBar_Toggle, true); |
417 | menuBar->Check(Menu_MenuBar_Enable, true); | |
418 | menuBar->Check(Menu_Menu_Enable, true); | |
419 | menuBar->Check(Menu_Menu_Check, false); | |
717a57c2 VZ |
420 | |
421 | // associate the menu bar with the frame | |
422 | SetMenuBar(menuBar); | |
3ca6a5f0 BP |
423 | |
424 | // intercept all menu events and log them in this custom event handler | |
425 | PushEventHandler(new MyEvtHandler(this)); | |
e421922f VZ |
426 | |
427 | // create the log text window | |
428 | m_textctrl = new wxTextCtrl(this, -1, _T(""), | |
429 | wxDefaultPosition, wxDefaultSize, | |
430 | wxTE_MULTILINE); | |
6ee9b7b5 | 431 | m_textctrl->SetEditable(false); |
5c7766de VZ |
432 | |
433 | wxLog::SetTimestamp(NULL); | |
e421922f VZ |
434 | m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_textctrl)); |
435 | ||
5c7766de | 436 | wxLogMessage(_T("Brief explanations: the commands or the \"Menu\" menu ") |
e421922f | 437 | _T("append/insert/delete items to/from the last menu.\n") |
5c7766de VZ |
438 | _T("The commands from \"Menubar\" menu work with the ") |
439 | _T("menubar itself.\n\n") | |
e421922f | 440 | _T("Right click the band below to test popup menus.\n")); |
3ca6a5f0 BP |
441 | } |
442 | ||
443 | MyFrame::~MyFrame() | |
444 | { | |
445 | delete m_menu; | |
446 | ||
447 | // delete the event handler installed in ctor | |
6ee9b7b5 | 448 | PopEventHandler(true); |
e421922f VZ |
449 | |
450 | // restore old logger | |
451 | delete wxLog::SetActiveTarget(m_logOld); | |
717a57c2 VZ |
452 | } |
453 | ||
f03ec224 | 454 | wxMenu *MyFrame::CreateDummyMenu(wxString *title) |
717a57c2 VZ |
455 | { |
456 | wxMenu *menu = new wxMenu; | |
42ed7532 | 457 | menu->Append(Menu_Dummy_First, _T("&First item\tCtrl-F1")); |
717a57c2 | 458 | menu->AppendSeparator(); |
6ee9b7b5 | 459 | menu->Append(Menu_Dummy_Second, _T("&Second item\tCtrl-F2"), _T(""), true); |
717a57c2 | 460 | |
f03ec224 VZ |
461 | if ( title ) |
462 | { | |
6ee9b7b5 | 463 | title->Printf(_T("Dummy menu &%u"), (unsigned)++m_countDummy); |
f03ec224 VZ |
464 | } |
465 | ||
717a57c2 VZ |
466 | return menu; |
467 | } | |
468 | ||
469 | wxMenuItem *MyFrame::GetLastMenuItem() const | |
470 | { | |
471 | wxMenuBar *menubar = GetMenuBar(); | |
472 | wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1); | |
473 | ||
65c0217e | 474 | wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetLast(); |
717a57c2 VZ |
475 | if ( !node ) |
476 | { | |
6ee9b7b5 | 477 | wxLogWarning(_T("No last item in the last menu!")); |
717a57c2 VZ |
478 | |
479 | return NULL; | |
480 | } | |
481 | else | |
482 | { | |
483 | return node->GetData(); | |
484 | } | |
485 | } | |
486 | ||
3ca6a5f0 BP |
487 | void MyFrame::LogMenuEvent(const wxCommandEvent& event) |
488 | { | |
489 | int id = event.GetId(); | |
e421922f | 490 | if ( !GetMenuBar()->FindItem(id) ) |
d3d69314 | 491 | return; |
e421922f | 492 | |
6ee9b7b5 | 493 | wxString msg = wxString::Format(_T("Menu command %d"), id); |
3ca6a5f0 BP |
494 | if ( GetMenuBar()->FindItem(id)->IsCheckable() ) |
495 | { | |
6ee9b7b5 JS |
496 | msg += wxString::Format(_T(" (the item is currently %schecked)"), |
497 | event.IsChecked() ? _T("") : _T("not ")); | |
3ca6a5f0 BP |
498 | } |
499 | ||
e421922f | 500 | wxLogMessage(msg); |
3ca6a5f0 BP |
501 | } |
502 | ||
503 | // ---------------------------------------------------------------------------- | |
504 | // menu callbacks | |
505 | // ---------------------------------------------------------------------------- | |
506 | ||
717a57c2 VZ |
507 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
508 | { | |
6ee9b7b5 | 509 | Close(true); |
717a57c2 VZ |
510 | } |
511 | ||
e421922f VZ |
512 | void MyFrame::OnClearLog(wxCommandEvent& WXUNUSED(event)) |
513 | { | |
514 | m_textctrl->Clear(); | |
515 | } | |
516 | ||
717a57c2 VZ |
517 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
518 | { | |
42ed7532 MB |
519 |