]>
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 | |
aaf996e5 | 44 | #if defined(__WXMOTIF__) || defined(__WXPM__) || defined(__WXX11__) || defined(__WXMGL__) |
51a9eb73 VZ |
45 | #define USE_CONTEXT_MENU 0 |
46 | #else | |
47 | #define USE_CONTEXT_MENU 1 | |
62ad15a5 VZ |
48 | #endif |
49 | ||
1242c2d9 WS |
50 | // this sample is usefull when new port is developed |
51 | // and usually new port has majority of flags turned off | |
52 | #if wxUSE_LOG && wxUSE_TEXTCTRL | |
53 | #define USE_LOG_WINDOW 1 | |
54 | #else | |
55 | #define USE_LOG_WINDOW 0 | |
56 | #endif | |
57 | ||
67160991 | 58 | #if wxUSE_OWNER_DRAWN || defined(__WXGTK__) |
fcaf9e70 | 59 | #include "copy.xpm" |
c1a48eaf | 60 | #endif |
fcaf9e70 | 61 | |
717a57c2 VZ |
62 | // ---------------------------------------------------------------------------- |
63 | // classes | |
64 | // ---------------------------------------------------------------------------- | |
65 | ||
66 | // Define a new application | |
67 | class MyApp: public wxApp | |
68 | { | |
69 | public: | |
70 | bool OnInit(); | |
71 | }; | |
72 | ||
73 | // Define a new frame | |
74 | class MyFrame: public wxFrame | |
75 | { | |
76 | public: | |
77 | MyFrame(); | |
78 | ||
3ca6a5f0 BP |
79 | virtual ~MyFrame(); |
80 | ||
81 | void LogMenuEvent(const wxCommandEvent& event); | |
717a57c2 | 82 | |
e421922f | 83 | protected: |
717a57c2 | 84 | void OnQuit(wxCommandEvent& event); |
1242c2d9 | 85 | #if USE_LOG_WINDOW |
e421922f | 86 | void OnClearLog(wxCommandEvent& event); |
cfbf301d VZ |
87 | void OnClearLogUpdateUI(wxUpdateUIEvent& event); |
88 | #endif // USE_LOG_WINDOW | |
e421922f | 89 | |
717a57c2 VZ |
90 | void OnAbout(wxCommandEvent& event); |
91 | ||
92 | void OnDummy(wxCommandEvent& event); | |
93 | ||
94 | void OnAppendMenuItem(wxCommandEvent& event); | |
95 | void OnAppendSubMenu(wxCommandEvent& event); | |
96 | void OnDeleteMenuItem(wxCommandEvent& event); | |
97 | void OnInsertMenuItem(wxCommandEvent& event); | |
98 | void OnCheckMenuItem(wxCommandEvent& event); | |
99 | void OnEnableMenuItem(wxCommandEvent& event); | |
100 | void OnGetLabelMenuItem(wxCommandEvent& event); | |
1242c2d9 | 101 | #if wxUSE_TEXTDLG |
717a57c2 | 102 | void OnSetLabelMenuItem(wxCommandEvent& event); |
1242c2d9 | 103 | #endif |
a80c322c | 104 | void OnGetMenuItemInfo(wxCommandEvent& event); |
1242c2d9 | 105 | #if wxUSE_TEXTDLG |
f6d90fb9 | 106 | void OnFindMenuItem(wxCommandEvent& event); |
1242c2d9 | 107 | #endif |
717a57c2 VZ |
108 | |
109 | void OnAppendMenu(wxCommandEvent& event); | |
f03ec224 | 110 | void OnInsertMenu(wxCommandEvent& event); |
717a57c2 VZ |
111 | void OnDeleteMenu(wxCommandEvent& event); |
112 | void OnToggleMenu(wxCommandEvent& event); | |
113 | void OnEnableMenu(wxCommandEvent& event); | |
114 | void OnGetLabelMenu(wxCommandEvent& event); | |
115 | void OnSetLabelMenu(wxCommandEvent& event); | |
1242c2d9 | 116 | #if wxUSE_TEXTDLG |
f6d90fb9 | 117 | void OnFindMenu(wxCommandEvent& event); |
1242c2d9 | 118 | #endif |
717a57c2 | 119 | |
d65c269b VZ |
120 | void OnTestNormal(wxCommandEvent& event); |
121 | void OnTestCheck(wxCommandEvent& event); | |
122 | void OnTestRadio(wxCommandEvent& event); | |
123 | ||
c377f1be JS |
124 | void OnUpdateSubMenuNormal(wxUpdateUIEvent& event); |
125 | void OnUpdateSubMenuCheck(wxUpdateUIEvent& event); | |
126 | void OnUpdateSubMenuRadio(wxUpdateUIEvent& event); | |
127 | ||
62ad15a5 | 128 | #if USE_CONTEXT_MENU |
ac103441 | 129 | void OnContextMenu(wxContextMenuEvent& event); |
ccef86c7 VZ |
130 | #else |
131 | void OnRightUp(wxMouseEvent& event) | |
132 | { ShowContextMenu(event.GetPosition()); } | |
133 | #endif | |
134 | ||
135 | void OnMenuOpen(wxMenuEvent& event) | |
1242c2d9 WS |
136 | { |
137 | #if USE_LOG_WINDOW | |
138 | LogMenuOpenOrClose(event, _T("opened")); event.Skip(); | |
139 | #endif | |
140 | } | |
ccef86c7 | 141 | void OnMenuClose(wxMenuEvent& event) |
1242c2d9 WS |
142 | { |
143 | #if USE_LOG_WINDOW | |
144 | LogMenuOpenOrClose(event, _T("closed")); event.Skip(); | |
145 | #endif | |
146 | } | |
717a57c2 VZ |
147 | |
148 | void OnUpdateCheckMenuItemUI(wxUpdateUIEvent& event); | |
149 | ||
e421922f VZ |
150 | void OnSize(wxSizeEvent& event); |
151 | ||
717a57c2 | 152 | private: |
ccef86c7 VZ |
153 | void LogMenuOpenOrClose(const wxMenuEvent& event, const wxChar *what); |
154 | void ShowContextMenu(const wxPoint& pos); | |
155 | ||
f03ec224 | 156 | wxMenu *CreateDummyMenu(wxString *title); |
717a57c2 VZ |
157 | |
158 | wxMenuItem *GetLastMenuItem() const; | |
159 | ||
e421922f VZ |
160 | // the menu previously detached from the menubar (may be NULL) |
161 | wxMenu *m_menu; | |
717a57c2 | 162 | |
e421922f | 163 | // the count of dummy menus already created |
f03ec224 VZ |
164 | size_t m_countDummy; |
165 | ||
1242c2d9 | 166 | #if USE_LOG_WINDOW |
e421922f VZ |
167 | // the control used for logging |
168 | wxTextCtrl *m_textctrl; | |
1242c2d9 | 169 | #endif |
e421922f VZ |
170 | |
171 | // the previous log target | |
172 | wxLog *m_logOld; | |
173 | ||
717a57c2 VZ |
174 | DECLARE_EVENT_TABLE() |
175 | }; | |
176 | ||
3ca6a5f0 BP |
177 | // A small helper class which intercepts all menu events and logs them |
178 | class MyEvtHandler : public wxEvtHandler | |
179 | { | |
180 | public: | |
181 | MyEvtHandler(MyFrame *frame) { m_frame = frame; } | |
182 | ||
183 | void OnMenuEvent(wxCommandEvent& event) | |
184 | { | |
185 | m_frame->LogMenuEvent(event); | |
186 | ||
187 | event.Skip(); | |
188 | } | |
189 | ||
190 | private: | |
191 | MyFrame *m_frame; | |
192 | ||
193 | DECLARE_EVENT_TABLE() | |
194 | }; | |
195 | ||
717a57c2 VZ |
196 | // ---------------------------------------------------------------------------- |
197 | // constants | |
198 | // ---------------------------------------------------------------------------- | |
199 | ||
200 | enum | |
201 | { | |
1242c2d9 WS |
202 | Menu_File_Quit = wxID_EXIT, |
203 | #if USE_LOG_WINDOW | |
cfbf301d | 204 | Menu_File_ClearLog = 100, |
1242c2d9 | 205 | #endif |
717a57c2 VZ |
206 | |
207 | Menu_MenuBar_Toggle = 200, | |
208 | Menu_MenuBar_Append, | |
f03ec224 | 209 | Menu_MenuBar_Insert, |
717a57c2 VZ |
210 | Menu_MenuBar_Delete, |
211 | Menu_MenuBar_Enable, | |
212 | Menu_MenuBar_GetLabel, | |
1242c2d9 | 213 | #if wxUSE_TEXTDLG |
717a57c2 | 214 | Menu_MenuBar_SetLabel, |
f6d90fb9 | 215 | Menu_MenuBar_FindMenu, |
1242c2d9 | 216 | #endif |
717a57c2 VZ |
217 | |
218 | Menu_Menu_Append = 300, | |
219 | Menu_Menu_AppendSub, | |
220 | Menu_Menu_Insert, | |
221 | Menu_Menu_Delete, | |
222 | Menu_Menu_Enable, | |
223 | Menu_Menu_Check, | |
224 | Menu_Menu_GetLabel, | |
1242c2d9 | 225 | #if wxUSE_TEXTDLG |
717a57c2 | 226 | Menu_Menu_SetLabel, |
1242c2d9 | 227 | #endif |
a80c322c | 228 | Menu_Menu_GetInfo, |
1242c2d9 | 229 | #if wxUSE_TEXTDLG |
f6d90fb9 | 230 | Menu_Menu_FindItem, |
1242c2d9 | 231 | #endif |
717a57c2 | 232 | |
d65c269b VZ |
233 | Menu_Test_Normal = 400, |
234 | Menu_Test_Check, | |
235 | Menu_Test_Radio1, | |
236 | Menu_Test_Radio2, | |
237 | Menu_Test_Radio3, | |
238 | ||
c377f1be JS |
239 | Menu_SubMenu = 450, |
240 | Menu_SubMenu_Normal, | |
241 | Menu_SubMenu_Check, | |
242 | Menu_SubMenu_Radio1, | |
243 | Menu_SubMenu_Radio2, | |
244 | Menu_SubMenu_Radio3, | |
245 | ||
d65c269b | 246 | Menu_Dummy_First = 500, |
717a57c2 VZ |
247 | Menu_Dummy_Second, |
248 | Menu_Dummy_Third, | |
249 | Menu_Dummy_Fourth, | |
250 | Menu_Dummy_Last, | |
251 | ||
1242c2d9 | 252 | Menu_Help_About = wxID_ABOUT, |
717a57c2 VZ |
253 | |
254 | Menu_Popup_ToBeDeleted = 2000, | |
255 | Menu_Popup_ToBeGreyed, | |
256 | Menu_Popup_ToBeChecked, | |
257 | Menu_Popup_Submenu, | |
258 | ||
259 | Menu_Max | |
260 | }; | |
261 | ||
262 | // ---------------------------------------------------------------------------- | |
263 | // event tables | |
264 | // ---------------------------------------------------------------------------- | |
265 | ||
266 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
e421922f | 267 | EVT_MENU(Menu_File_Quit, MyFrame::OnQuit) |
1242c2d9 | 268 | #if USE_LOG_WINDOW |
e421922f | 269 | EVT_MENU(Menu_File_ClearLog, MyFrame::OnClearLog) |
cfbf301d | 270 | EVT_UPDATE_UI(Menu_File_ClearLog, MyFrame::OnClearLogUpdateUI) |
1242c2d9 | 271 | #endif |
717a57c2 VZ |
272 | |
273 | EVT_MENU(Menu_Help_About, MyFrame::OnAbout) | |
274 | ||
275 | EVT_MENU(Menu_MenuBar_Toggle, MyFrame::OnToggleMenu) | |
276 | EVT_MENU(Menu_MenuBar_Append, MyFrame::OnAppendMenu) | |
f03ec224 | 277 | EVT_MENU(Menu_MenuBar_Insert, MyFrame::OnInsertMenu) |
717a57c2 VZ |
278 | EVT_MENU(Menu_MenuBar_Delete, MyFrame::OnDeleteMenu) |
279 | EVT_MENU(Menu_MenuBar_Enable, MyFrame::OnEnableMenu) | |
280 | EVT_MENU(Menu_MenuBar_GetLabel, MyFrame::OnGetLabelMenu) | |
1242c2d9 | 281 | #if wxUSE_TEXTDLG |
717a57c2 | 282 | EVT_MENU(Menu_MenuBar_SetLabel, MyFrame::OnSetLabelMenu) |
f6d90fb9 | 283 | EVT_MENU(Menu_MenuBar_FindMenu, MyFrame::OnFindMenu) |
1242c2d9 | 284 | #endif |
717a57c2 VZ |
285 | |
286 | EVT_MENU(Menu_Menu_Append, MyFrame::OnAppendMenuItem) | |
287 | EVT_MENU(Menu_Menu_AppendSub, MyFrame::OnAppendSubMenu) | |
288 | EVT_MENU(Menu_Menu_Insert, MyFrame::OnInsertMenuItem) | |
289 | EVT_MENU(Menu_Menu_Delete, MyFrame::OnDeleteMenuItem) | |
290 | EVT_MENU(Menu_Menu_Enable, MyFrame::OnEnableMenuItem) | |
a80c322c | 291 | EVT_MENU(Menu_Menu_Check, MyFrame::OnCheckMenuItem) |
717a57c2 | 292 | EVT_MENU(Menu_Menu_GetLabel, MyFrame::OnGetLabelMenuItem) |
1242c2d9 | 293 | #if wxUSE_TEXTDLG |
717a57c2 | 294 | EVT_MENU(Menu_Menu_SetLabel, MyFrame::OnSetLabelMenuItem) |
1242c2d9 | 295 | #endif |
a80c322c | 296 | EVT_MENU(Menu_Menu_GetInfo, MyFrame::OnGetMenuItemInfo) |
1242c2d9 | 297 | #if wxUSE_TEXTDLG |
f6d90fb9 | 298 | EVT_MENU(Menu_Menu_FindItem, MyFrame::OnFindMenuItem) |
1242c2d9 | 299 | #endif |
717a57c2 | 300 | |
d65c269b VZ |
301 | EVT_MENU(Menu_Test_Normal, MyFrame::OnTestNormal) |
302 | EVT_MENU(Menu_Test_Check, MyFrame::OnTestCheck) | |
303 | EVT_MENU(Menu_Test_Radio1, MyFrame::OnTestRadio) | |
304 | EVT_MENU(Menu_Test_Radio2, MyFrame::OnTestRadio) | |
305 | EVT_MENU(Menu_Test_Radio3, MyFrame::OnTestRadio) | |
306 | ||
c377f1be JS |
307 | EVT_UPDATE_UI(Menu_SubMenu_Normal, MyFrame::OnUpdateSubMenuNormal) |
308 | EVT_UPDATE_UI(Menu_SubMenu_Check, MyFrame::OnUpdateSubMenuCheck) | |
309 | EVT_UPDATE_UI(Menu_SubMenu_Radio1, MyFrame::OnUpdateSubMenuRadio) | |
310 | EVT_UPDATE_UI(Menu_SubMenu_Radio2, MyFrame::OnUpdateSubMenuRadio) | |
311 | EVT_UPDATE_UI(Menu_SubMenu_Radio3, MyFrame::OnUpdateSubMenuRadio) | |
312 | ||
717a57c2 VZ |
313 | EVT_MENU_RANGE(Menu_Dummy_First, Menu_Dummy_Last, MyFrame::OnDummy) |
314 | ||
315 | EVT_UPDATE_UI(Menu_Menu_Check, MyFrame::OnUpdateCheckMenuItemUI) | |
316 | ||
62ad15a5 | 317 | #if USE_CONTEXT_MENU |
ccef86c7 VZ |
318 | EVT_CONTEXT_MENU(MyFrame::OnContextMenu) |
319 | #else | |
e421922f | 320 | EVT_RIGHT_UP(MyFrame::OnRightUp) |
ccef86c7 VZ |
321 | #endif |
322 | ||
323 | EVT_MENU_OPEN(MyFrame::OnMenuOpen) | |
324 | EVT_MENU_CLOSE(MyFrame::OnMenuClose) | |
e421922f VZ |
325 | |
326 | EVT_SIZE(MyFrame::OnSize) | |
717a57c2 VZ |
327 | END_EVENT_TABLE() |
328 | ||
3ca6a5f0 | 329 | BEGIN_EVENT_TABLE(MyEvtHandler, wxEvtHandler) |
1242c2d9 | 330 | EVT_MENU(wxID_ANY, MyEvtHandler::OnMenuEvent) |
3ca6a5f0 BP |
331 | END_EVENT_TABLE() |
332 | ||
717a57c2 VZ |
333 | // ============================================================================ |
334 | // implementation | |
335 | // ============================================================================ | |
336 | ||
337 | // ---------------------------------------------------------------------------- | |
338 | // MyApp | |
339 | // ---------------------------------------------------------------------------- | |
340 | ||
341 | IMPLEMENT_APP(MyApp) | |
342 | ||
343 | // The `main program' equivalent, creating the windows and returning the | |
344 | // main frame | |
345 | bool MyApp::OnInit() | |
346 | { | |
347 | // Create the main frame window | |
348 | MyFrame* frame = new MyFrame; | |
349 | ||
6ee9b7b5 | 350 | frame->Show(true); |
717a57c2 | 351 | |
6d5b2a57 | 352 | #if wxUSE_STATUSBAR |
be5a51fb | 353 | frame->SetStatusText(_T("Welcome to wxWidgets menu sample")); |
6d5b2a57 | 354 | #endif // wxUSE_STATUSBAR |
717a57c2 VZ |
355 | |
356 | SetTopWindow(frame); | |
357 | ||
6ee9b7b5 | 358 | return true; |
717a57c2 VZ |
359 | } |
360 | ||
361 | // ---------------------------------------------------------------------------- | |
362 | // MyFrame | |
363 | // ---------------------------------------------------------------------------- | |
364 | ||
365 | // Define my frame constructor | |
366 | MyFrame::MyFrame() | |
be5a51fb | 367 | : wxFrame((wxFrame *)NULL, wxID_ANY, _T("wxWidgets menu sample")) |
717a57c2 | 368 | { |
1242c2d9 | 369 | #if USE_LOG_WINDOW |
268766dd | 370 | m_textctrl = NULL; |
1242c2d9 | 371 | #endif |
717a57c2 | 372 | m_menu = NULL; |
f03ec224 | 373 | m_countDummy = 0; |
e421922f | 374 | m_logOld = NULL; |
717a57c2 | 375 | |
6d5b2a57 | 376 | #if wxUSE_STATUSBAR |
e421922f | 377 | CreateStatusBar(); |
6d5b2a57 | 378 | #endif // wxUSE_STATUSBAR |
717a57c2 VZ |
379 | |
380 | // create the menubar | |
381 | wxMenu *fileMenu = new wxMenu; | |
6d5b2a57 | 382 | |
ab73fe8d | 383 | wxMenu *stockSubMenu = new wxMenu; |
ee0a94cf RR |
384 | stockSubMenu->Append(wxID_ADD); |
385 | stockSubMenu->Append(wxID_APPLY); | |
386 | stockSubMenu->Append(wxID_BOLD); | |
387 | stockSubMenu->Append(wxID_CANCEL); | |
388 | stockSubMenu->Append(wxID_CLEAR); | |
389 | stockSubMenu->Append(wxID_CLOSE); | |
390 | stockSubMenu->Append(wxID_COPY); | |
391 | stockSubMenu->Append(wxID_CUT); | |
392 | stockSubMenu->Append(wxID_DELETE); | |
393 | stockSubMenu->Append(wxID_FIND); | |
394 | stockSubMenu->Append(wxID_REPLACE); | |
395 | stockSubMenu->Append(wxID_BACKWARD); | |
396 | stockSubMenu->Append(wxID_DOWN); | |
397 | stockSubMenu->Append(wxID_FORWARD); | |
398 | stockSubMenu->Append(wxID_UP); | |
399 | stockSubMenu->Append(wxID_HELP); | |
400 | stockSubMenu->Append(wxID_HOME); | |
401 | stockSubMenu->Append(wxID_INDENT); | |
402 | stockSubMenu->Append(wxID_INDEX); | |
403 | stockSubMenu->Append(wxID_ITALIC); | |
404 | stockSubMenu->Append(wxID_JUSTIFY_CENTER); | |
405 | stockSubMenu->Append(wxID_JUSTIFY_FILL); | |
406 | stockSubMenu->Append(wxID_JUSTIFY_LEFT); | |
407 | stockSubMenu->Append(wxID_JUSTIFY_RIGHT); | |
408 | stockSubMenu->Append(wxID_NEW); | |
409 | stockSubMenu->Append(wxID_NO); | |
410 | stockSubMenu->Append(wxID_OK); | |
411 | stockSubMenu->Append(wxID_OPEN); | |
412 | stockSubMenu->Append(wxID_PASTE); | |
413 | stockSubMenu->Append(wxID_PREFERENCES); | |
414 | stockSubMenu->Append(wxID_PRINT); | |
415 | stockSubMenu->Append(wxID_PREVIEW); | |
416 | stockSubMenu->Append(wxID_PROPERTIES); | |
417 | stockSubMenu->Append(wxID_EXIT); | |
418 | stockSubMenu->Append(wxID_REDO); | |
419 | stockSubMenu->Append(wxID_REFRESH); | |
420 | stockSubMenu->Append(wxID_REMOVE); | |
421 | stockSubMenu->Append(wxID_REVERT_TO_SAVED); | |
422 | stockSubMenu->Append(wxID_SAVE); | |
423 | stockSubMenu->Append(wxID_SAVEAS); | |
424 | stockSubMenu->Append(wxID_STOP); | |
425 | stockSubMenu->Append(wxID_UNDELETE); | |
426 | stockSubMenu->Append(wxID_UNDERLINE); | |
427 | stockSubMenu->Append(wxID_UNDO); | |
428 | stockSubMenu->Append(wxID_UNINDENT); | |
429 | stockSubMenu->Append(wxID_YES); | |
430 | stockSubMenu->Append(wxID_ZOOM_100); | |
431 | stockSubMenu->Append(wxID_ZOOM_FIT); | |
432 | stockSubMenu->Append(wxID_ZOOM_IN); | |
433 | stockSubMenu->Append(wxID_ZOOM_OUT); | |
ab73fe8d VZ |
434 | fileMenu->AppendSubMenu(stockSubMenu, _T("&Standard items demo")); |
435 | ||
1242c2d9 | 436 | #if USE_LOG_WINDOW |
e421922f | 437 | wxMenuItem *item = new wxMenuItem(fileMenu, Menu_File_ClearLog, |
42ed7532 | 438 | _T("Clear &log\tCtrl-L")); |
67160991 | 439 | #if wxUSE_OWNER_DRAWN || defined(__WXGTK__) |
e421922f | 440 | item->SetBitmap(copy_xpm); |
1242c2d9 | 441 | #endif |
e421922f VZ |
442 | fileMenu->Append(item); |
443 | fileMenu->AppendSeparator(); | |
ab73fe8d VZ |
444 | #endif // USE_LOG_WINDOW |
445 | ||
42ed7532 | 446 | fileMenu->Append(Menu_File_Quit, _T("E&xit\tAlt-X"), _T("Quit menu sample")); |
717a57c2 VZ |
447 | |
448 | wxMenu *menubarMenu = new wxMenu; | |
42ed7532 MB |
449 | menubarMenu->Append(Menu_MenuBar_Append, _T("&Append menu\tCtrl-A"), |
450 | _T("Append a menu to the menubar")); | |
451 | menubarMenu->Append(Menu_MenuBar_Insert, _T("&Insert menu\tCtrl-I"), | |
452 | _T("Insert a menu into the menubar")); | |
453 | menubarMenu->Append(Menu_MenuBar_Delete, _T("&Delete menu\tCtrl-D"), | |
454 | _T("Delete the last menu from the menubar")); | |
455 | menubarMenu->Append(Menu_MenuBar_Toggle, _T("&Toggle menu\tCtrl-T"), | |
6ee9b7b5 | 456 | _T("Toggle the first menu in the menubar"), true); |
717a57c2 | 457 | menubarMenu->AppendSeparator(); |
42ed7532 | 458 | menubarMenu->Append(Menu_MenuBar_Enable, _T("&Enable menu\tCtrl-E"), |
6ee9b7b5 | 459 | _T("Enable or disable the last menu"), true); |
717a57c2 | 460 | menubarMenu->AppendSeparator(); |
42ed7532 MB |
461 | menubarMenu->Append(Menu_MenuBar_GetLabel, _T("&Get menu label\tCtrl-G"), |
462 | _T("Get the label of the last menu")); | |
1242c2d9 | 463 | #if wxUSE_TEXTDLG |
42ed7532 MB |
464 | menubarMenu->Append(Menu_MenuBar_SetLabel, _T("&Set menu label\tCtrl-S"), |
465 | _T("Change the label of the last menu")); | |
f6d90fb9 | 466 | menubarMenu->AppendSeparator(); |
42ed7532 MB |
467 | menubarMenu->Append(Menu_MenuBar_FindMenu, _T("&Find menu from label\tCtrl-F"), |
468 | _T("Find a menu by searching for its label")); | |
1242c2d9 | 469 | #endif |
717a57c2 | 470 | |
c377f1be JS |
471 | wxMenu* subMenu = new wxMenu; |
472 | subMenu->Append(Menu_SubMenu_Normal, _T("&Normal submenu item"), _T("Disabled submenu item")); | |
8e1b6d43 | 473 | subMenu->AppendCheckItem(Menu_SubMenu_Check, _T("&Check submenu item"), _T("Check submenu item")); |
9f486b32 VZ |
474 | subMenu->AppendRadioItem(Menu_SubMenu_Radio1, _T("Radio item &1"), _T("Radio item")); |
475 | subMenu->AppendRadioItem(Menu_SubMenu_Radio2, _T("Radio item &2"), _T("Radio item")); | |
476 | subMenu->AppendRadioItem(Menu_SubMenu_Radio3, _T("Radio item &3"), _T("Radio item")); | |
c377f1be JS |
477 | |
478 | menubarMenu->Append(Menu_SubMenu, _T("Submenu"), subMenu); | |
479 | ||
717a57c2 | 480 | wxMenu *menuMenu = new wxMenu; |
42ed7532 MB |
481 | menuMenu->Append(Menu_Menu_Append, _T("&Append menu item\tAlt-A"), |
482 | _T("Append a menu item to the last menu")); | |
483 | menuMenu->Append(Menu_Menu_AppendSub, _T("&Append sub menu\tAlt-S"), | |
484 | _T("Append a sub menu to the last menu")); | |
485 | menuMenu->Append(Menu_Menu_Insert, _T("&Insert menu item\tAlt-I"), | |
486 | _T("Insert a menu item in head of the last menu")); | |
487 | menuMenu->Append(Menu_Menu_Delete, _T("&Delete menu item\tAlt-D"), | |
488 | _T("Delete the last menu item from the last menu")); | |
717a57c2 | 489 | menuMenu->AppendSeparator(); |
42ed7532 | 490 | menuMenu->Append(Menu_Menu_Enable, _T("&Enable menu item\tAlt-E"), |
6ee9b7b5 | 491 | _T("Enable or disable the last menu item"), true); |
42ed7532 | 492 | menuMenu->Append(Menu_Menu_Check, _T("&Check menu item\tAlt-C"), |
6ee9b7b5 | 493 | _T("Check or uncheck the last menu item"), true); |
717a57c2 | 494 | menuMenu->AppendSeparator(); |
42ed7532 MB |
495 | menuMenu->Append(Menu_Menu_GetInfo, _T("Get menu item in&fo\tAlt-F"), |
496 | _T("Show the state of the last menu item")); | |
532d575b | 497 | #if wxUSE_TEXTDLG |
98f29783 RR |
498 | menuMenu->Append(Menu_Menu_SetLabel, _T("Set menu item label\tAlt-L"), |
499 | _T("Set the label of a menu item")); | |
532d575b | 500 | #endif |
1242c2d9 | 501 | #if wxUSE_TEXTDLG |
a80c322c | 502 | menuMenu->AppendSeparator(); |
42ed7532 MB |
503 | menuMenu->Append(Menu_Menu_FindItem, _T("Find menu item from label"), |
504 | _T("Find a menu item by searching for its label")); | |
1242c2d9 | 505 | #endif |
717a57c2 | 506 | |
d65c269b | 507 | wxMenu *testMenu = new wxMenu; |
42ed7532 | 508 | testMenu->Append(Menu_Test_Normal, _T("&Normal item")); |
d65c269b | 509 | testMenu->AppendSeparator(); |
42ed7532 | 510 | testMenu->AppendCheckItem(Menu_Test_Check, _T("&Check item")); |
d65c269b | 511 | testMenu->AppendSeparator(); |
42ed7532 MB |
512 | testMenu->AppendRadioItem(Menu_Test_Radio1, _T("Radio item &1")); |
513 | testMenu->AppendRadioItem(Menu_Test_Radio2, _T("Radio item &2")); | |
514 | testMenu->AppendRadioItem(Menu_Test_Radio3, _T("Radio item &3")); | |
d65c269b | 515 | |
717a57c2 | 516 | wxMenu *helpMenu = new wxMenu; |
42ed7532 | 517 | helpMenu->Append(Menu_Help_About, _T("&About\tF1"), _T("About menu sample")); |
717a57c2 VZ |
518 | |
519 | wxMenuBar* menuBar = new wxMenuBar( wxMB_DOCKABLE ); | |
520 | ||
42ed7532 MB |
521 | menuBar->Append(fileMenu, _T("&File")); |
522 | menuBar->Append(menubarMenu, _T("Menu&bar")); | |
523 | menuBar->Append(menuMenu, _T("&Menu")); | |
524 | menuBar->Append(testMenu, _T("&Test")); | |
525 | menuBar->Append(helpMenu, _T("&Help")); | |
717a57c2 VZ |
526 | |
527 | // these items should be initially checked | |
6ee9b7b5 JS |
528 | menuBar->Check(Menu_MenuBar_Toggle, true); |
529 | menuBar->Check(Menu_MenuBar_Enable, true); | |
530 | menuBar->Check(Menu_Menu_Enable, true); | |
531 | menuBar->Check(Menu_Menu_Check, false); | |
717a57c2 VZ |
532 | |
533 | // associate the menu bar with the frame | |
534 | SetMenuBar(menuBar); | |
3ca6a5f0 BP |
535 | |
536 | // intercept all menu events and log them in this custom event handler | |
537 | PushEventHandler(new MyEvtHandler(this)); | |
e421922f | 538 | |
1242c2d9 | 539 | #if USE_LOG_WINDOW |
e421922f | 540 | // create the log text window |
532d575b | 541 | m_textctrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, |
e421922f VZ |
542 | wxDefaultPosition, wxDefaultSize, |
543 | wxTE_MULTILINE); | |
6ee9b7b5 | 544 | m_textctrl->SetEditable(false); |
5c7766de VZ |
545 | |
546 | wxLog::SetTimestamp(NULL); | |
e421922f VZ |
547 | m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_textctrl)); |
548 | ||
5c7766de | 549 | wxLogMessage(_T("Brief explanations: the commands or the \"Menu\" menu ") |
e421922f | 550 | _T("append/insert/delete items to/from the last menu.\n") |
5c7766de VZ |
551 | _T("The commands from \"Menubar\" menu work with the ") |
552 | _T("menubar itself.\n\n") | |
e421922f | 553 | _T("Right click the band below to test popup menus.\n")); |
1242c2d9 | 554 | #endif |
92f07cf8 JS |
555 | #ifdef __POCKETPC__ |
556 | EnableContextMenu(); | |
557 | #endif | |
3ca6a5f0 BP |
558 | } |
559 | ||
560 | MyFrame::~MyFrame() | |
561 | { | |
562 | delete m_menu; | |
563 | ||
564 | // delete the event handler installed in ctor | |
6ee9b7b5 | 565 | PopEventHandler(true); |
e421922f | 566 | |
1242c2d9 | 567 | #if USE_LOG_WINDOW |
e421922f VZ |
568 | // restore old logger |
569 | delete wxLog::SetActiveTarget(m_logOld); | |
1242c2d9 | 570 | #endif |
717a57c2 VZ |
571 | } |
572 | ||
f03ec224 | 573 | wxMenu *MyFrame::CreateDummyMenu(wxString *title) |
717a57c2 VZ |
574 | { |
575 | wxMenu *menu = new wxMenu; | |
42ed7532 | 576 | menu->Append(Menu_Dummy_First, _T("&First item\tCtrl-F1")); |
717a57c2 | 577 | menu->AppendSeparator(); |
2153bf89 | 578 | menu->AppendCheckItem(Menu_Dummy_Second, _T("&Second item\tCtrl-F2")); |
717a57c2 | 579 | |
f03ec224 VZ |
580 | if ( title ) |
581 | { | |
6ee9b7b5 | 582 | title->Printf(_T("Dummy menu &%u"), (unsigned)++m_countDummy); |
f03ec224 VZ |
583 | } |
584 | ||
717a57c2 VZ |
585 | return menu; |
586 | } | |
587 | ||
588 | wxMenuItem *MyFrame::GetLastMenuItem() const | |
589 | { | |
590 | wxMenuBar *menubar = GetMenuBar(); | |
591 | wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1); | |
592 | ||
65c0217e | 593 | wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetLast(); |
717a57c2 VZ |
594 | if ( !node ) |
595 | { | |
6ee9b7b5 | 596 | wxLogWarning(_T("No last item in the last menu!")); |
717a57c2 VZ |
597 | |
598 | return NULL; | |
599 | } | |
600 | else | |
601 | { | |
602 | return node->GetData(); | |
603 | } | |
604 | } | |
605 | ||
3ca6a5f0 BP |
606 | void MyFrame::LogMenuEvent(const wxCommandEvent& event) |
607 | { | |
608 | int id = event.GetId(); | |
e421922f | 609 | |
6ee9b7b5 | 610 | wxString msg = wxString::Format(_T("Menu command %d"), id); |
030f50ef VZ |
611 | |
612 | // catch all checkable menubar items and also the check item from the popup | |
613 | // menu | |
614 | wxMenuItem *item = GetMenuBar()->FindItem(id); | |
615 | if ( (item && item->IsCheckable()) || id == Menu_Popup_ToBeChecked ) | |
3ca6a5f0 | 616 | { |
6ee9b7b5 JS |
617 | msg += wxString::Format(_T(" (the item is currently %schecked)"), |
618 | event.IsChecked() ? _T("") : _T("not ")); | |
3ca6a5f0 BP |
619 | } |
620 | ||
e421922f | 621 | wxLogMessage(msg); |
3ca6a5f0 BP |
622 | } |
623 | ||
624 | // ---------------------------------------------------------------------------- | |
625 | // menu callbacks | |
626 | // ---------------------------------------------------------------------------- | |
627 | ||
717a57c2 VZ |
628 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
629 | { | |
6ee9b7b5 | 630 | Close(true); |
717a57c2 VZ |
631 | } |
632 | ||
1242c2d9 | 633 | #if USE_LOG_WINDOW |
cfbf301d | 634 | |
e421922f VZ |
635 | void MyFrame::OnClearLog(wxCommandEvent& WXUNUSED(event)) |
636 | { | |
637 | m_textctrl->Clear(); | |
638 | } | |
cfbf301d VZ |
639 | |
640 | void MyFrame::OnClearLogUpdateUI(wxUpdateUIEvent& event) | |
641 | { | |
642 | // if we only enable this item when the log window is empty, we never see | |
643 | // it in the disable state as a message is logged whenever the menu is | |
644 | // opened, so we disable it if there is not "much" text in the window | |
645 | event.Enable( m_textctrl->GetNumberOfLines() > 5 ); | |
646 | } | |
647 | ||
648 | #endif // USE_LOG_WINDOW | |
e421922f | 649 | |
717a57c2 VZ |
650 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
651 | { | |
232ba4c3 | 652 | (void)wxMessageBox(_T("wxWidgets menu sample\n(c) 1999-2001 Vadim Zeitlin"), |
be5a51fb | 653 | _T("About wxWidgets menu sample"), |
717a57c2 VZ |
654 | wxICON_INFORMATION); |
655 | } | |
656 | ||
657 | void MyFrame::OnDeleteMenu(wxCommandEvent& WXUNUSED(event)) | |
658 | { | |
659 | wxMenuBar *mbar = GetMenuBar(); | |
660 | ||
661 | size_t count = mbar->GetMenuCount(); | |
662 | if ( count == 2 ) | |
663 | { | |
664 | // don't let delete the first 2 menus | |
6ee9b7b5 | 665 | wxLogError(_T("Can't delete any more menus")); |
717a57c2 VZ |
666 | } |
667 | else | |
668 | { | |
669 | delete mbar->Remove(count - 1); | |
670 | } | |
671 | } | |
672 | ||
f03ec224 | 673 | void MyFrame::OnInsertMenu(wxCommandEvent& WXUNUSED(event)) |
717a57c2 | 674 | { |
717a57c2 | 675 | wxString title; |
f03ec224 VZ |
676 | wxMenu *menu = CreateDummyMenu(&title); |
677 | GetMenuBar()->Insert(0, menu, title); | |
678 | } | |
717a57c2 | 679 | |
f03ec224 VZ |
680 | void MyFrame::OnAppendMenu(wxCommandEvent& WXUNUSED(event)) |
681 | { | |
682 | wxString title; | |
683 | wxMenu *menu = CreateDummyMenu(&title); | |
684 | GetMenuBar()->Append(menu, title); | |
717a57c2 VZ |
685 | } |
686 | ||
687 | void MyFrame::OnToggleMenu(wxCommandEvent& WXUNUSED(event)) | |
688 | { | |
689 | wxMenuBar *mbar = GetMenuBar(); | |
690 | if ( !m_menu ) | |
691 | { | |
692 | // hide the menu | |
693 | m_menu = mbar->Remove(0); | |
694 | } | |
695 | else | |
696 | { | |
697 | // restore it | |
42ed7532 | 698 | mbar->Insert(0, m_menu, _T("&File")); |
717a57c2 VZ |
699 | m_menu = NULL; |
700 | } | |
701 | } | |
702 | ||
e421922f | 703 | void MyFrame::OnEnableMenu(wxCommandEvent& event) |
717a57c2 VZ |
704 | { |
705 | wxMenuBar *mbar = GetMenuBar(); | |
706 | size_t count = mbar->GetMenuCount(); | |
707 | ||
e421922f | 708 | mbar->EnableTop(count - 1, event.IsChecked()); |
717a57c2 VZ |
709 | } |
710 | ||
711 | void MyFrame::OnGetLabelMenu(wxCommandEvent& WXUNUSED(event)) | |
712 | { | |
713 | wxMenuBar *mbar = GetMenuBar(); | |
714 | size_t count = mbar->GetMenuCount(); | |
715 | ||
5c7766de VZ |
716 | wxCHECK_RET( count, _T("no last menu?") ); |
717 | ||
6ee9b7b5 | 718 | wxLogMessage(_T("The label of the last menu item is '%s'"), |
1987af7e | 719 | mbar->GetLabelTop(count - 1).c_str()); |
717a57c2 VZ |
720 | } |
721 | ||
1242c2d9 | 722 | #if wxUSE_TEXTDLG |
717a57c2 VZ |
723 | void MyFrame::OnSetLabelMenu(wxCommandEvent& WXUNUSED(event)) |
724 | { | |
725 | wxMenuBar *mbar = GetMenuBar(); | |
726 | size_t count = mbar->GetMenuCount(); | |
727 | ||
5c7766de VZ |
728 | wxCHECK_RET( count, _T("no last menu?") ); |
729 | ||
730 | wxString label = wxGetTextFromUser | |
731 | ( | |
732 | _T("Enter new label: "), | |
733 | _T("Change last menu text"), | |
734 | mbar->GetLabelTop(count - 1), | |
735 | this | |
736 | ); | |
737 | ||
738 | if ( !label.empty() ) | |
739 | { | |
740 | mbar->SetLabelTop(count - 1, label); | |
741 | } | |
717a57c2 VZ |
742 | } |
743 | ||
f6d90fb9 GD |
744 | void MyFrame::OnFindMenu(wxCommandEvent& WXUNUSED(event)) |
745 | { | |
746 | wxMenuBar *mbar = GetMenuBar(); | |
747 | size_t count = mbar->GetMenuCount(); | |
748 | ||
749 | wxCHECK_RET( count, _T("no last menu?") ); | |
750 | ||
751 | wxString label = wxGetTextFromUser | |
752 | ( | |
753 | _T("Enter label to search for: "), | |
754 | _T("Find menu"), | |
532d575b | 755 | wxEmptyString, |
f6d90fb9 GD |
756 | this |
757 | ); | |
758 | ||
759 | if ( !label.empty() ) | |
760 | { | |
761 | int index = mbar->FindMenu(label); | |
762 | ||
763 | if (index == wxNOT_FOUND) | |
764 | { | |
6ee9b7b5 | 765 | wxLogWarning(_T("No menu with label '%s'"), label.c_str()); |
f6d90fb9 GD |
766 | } |
767 | else | |
768 | { | |
6ee9b7b5 | 769 | wxLogMessage(_T("Menu %d has label '%s'"), index, label.c_str()); |
f6d90fb9 GD |
770 | } |
771 | } | |
772 | } | |
1242c2d9 | 773 | #endif |
f6d90fb9 | 774 | |
717a57c2 VZ |
775 | void MyFrame::OnDummy(wxCommandEvent& event) |
776 | { | |
6ee9b7b5 | 777 | wxLogMessage(_T("Dummy item #%d"), event.GetId() - Menu_Dummy_First + 1); |
717a57c2 VZ |
778 | } |
779 | ||
780 | void MyFrame::OnAppendMenuItem(wxCommandEvent& WXUNUSED(event)) | |
781 | { | |
782 | wxMenuBar *menubar = GetMenuBar(); | |
783 | wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1); | |
784 | ||
785 | menu->AppendSeparator(); | |
42ed7532 | 786 | menu->Append(Menu_Dummy_Third, _T("&Third dummy item\tCtrl-F3"), |
6ee9b7b5 | 787 | _T("Checkable item"), true); |
717a57c2 VZ |
788 | } |
789 | ||
790 | void MyFrame::OnAppendSubMenu(wxCommandEvent& WXUNUSED(event)) | |
791 | { | |
792 | wxMenuBar *menubar = GetMenuBar(); | |
f6bcfd97 | 793 | |
0c2d3577 | 794 | wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 2); |
f6bcfd97 | 795 | |
42ed7532 MB |
796 | menu->Append(Menu_Dummy_Last, _T("&Dummy sub menu"), |
797 | CreateDummyMenu(NULL), _T("Dummy sub menu help")); | |
717a57c2 VZ |
798 | } |
799 | ||
800 | void MyFrame::OnDeleteMenuItem(wxCommandEvent& WXUNUSED(event)) | |
801 | { | |
802 | wxMenuBar *menubar = GetMenuBar(); | |
803 | wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1); | |
804 | ||
805 | size_t count = menu->GetMenuItemCount(); | |
806 | if ( !count ) | |
807 | { | |
6ee9b7b5 | 808 | wxLogWarning(_T("No items to delete!")); |
717a57c2 VZ |
809 | } |
810 | else | |
811 | { | |
812 | menu->Destroy(menu->GetMenuItems().Item(count - 1)->GetData()); | |
813 | } | |
814 | } | |
815 | ||
816 | void MyFrame::OnInsertMenuItem(wxCommandEvent& WXUNUSED(event)) | |
817 | { | |
818 | wxMenuBar *menubar = GetMenuBar(); | |
819 | wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1); | |
820 | ||
821 | menu->Insert(0, wxMenuItem::New(menu, Menu_Dummy_Fourth, | |
42ed7532 | 822 | _T("Fourth dummy item\tCtrl-F4"))); |
532d575b | 823 | menu->Insert(1, wxMenuItem::New(menu, wxID_SEPARATOR)); |
717a57c2 VZ |
824 | } |
825 | ||
826 | void MyFrame::OnEnableMenuItem(wxCommandEvent& WXUNUSED(event)) | |
827 | { | |
828 | wxMenuItem *item = GetLastMenuItem(); | |
829 | ||
830 | if ( item ) | |
831 | { | |
832 | item->Enable(!item->IsEnabled()); | |
833 | } | |
834 | } | |
835 | ||
836 | void MyFrame::OnCheckMenuItem(wxCommandEvent& WXUNUSED(event)) | |
837 | { | |
838 | wxMenuItem *item = GetLastMenuItem(); | |
839 | ||
840 | item->Toggle(); | |
841 | } | |
842 | ||
843 | void MyFrame::OnUpdateCheckMenuItemUI(wxUpdateUIEvent& event) | |
844 | { | |
32db328c VZ |
845 | wxLogNull nolog; |
846 | ||
717a57c2 VZ |
847 | wxMenuItem *item = GetLastMenuItem(); |
848 | ||
849 | event.Enable(item && item->IsCheckable()); | |
850 | } | |
851 | ||
852 | void MyFrame::OnGetLabelMenuItem(wxCommandEvent& WXUNUSED(event)) | |
853 | { | |
854 | wxMenuItem *item = GetLastMenuItem(); | |
855 | ||
856 | if ( item ) | |
857 | { | |
6ee9b7b5 | 858 | wxLogMessage(_T("The label of the last menu item is '%s'"), |
1987af7e | 859 | item->GetLabel().c_str()); |
717a57c2 VZ |
860 | } |
861 | } | |
862 | ||
1242c2d9 | 863 | #if wxUSE_TEXTDLG |
717a57c2 VZ |
864 | void MyFrame::OnSetLabelMenuItem(wxCommandEvent& WXUNUSED(event)) |
865 | { | |
866 | wxMenuItem *item = GetLastMenuItem(); | |
867 | ||
868 | if ( item ) | |
869 | { | |
5c7766de VZ |
870 | wxString label = wxGetTextFromUser |
871 | ( | |
872 | _T("Enter new label: "), | |
873 | _T("Change last menu item text"), | |
874 | item->GetLabel(), | |
875 | this | |
876 | ); | |
98f29783 | 877 | label.Replace( _T("\\t"), _T("\t") ); |
5c7766de VZ |
878 | |
879 | if ( !label.empty() ) | |
880 | { | |
881 | item->SetText(label); | |
882 | } | |
717a57c2 VZ |
883 | } |
884 | } | |
1242c2d9 | 885 | #endif |
717a57c2 | 886 | |
a80c322c VZ |
887 | void MyFrame::OnGetMenuItemInfo(wxCommandEvent& WXUNUSED(event)) |
888 | { | |
889 | wxMenuItem *item = GetLastMenuItem(); | |
890 | ||
891 | if ( item ) | |
892 | { | |
893 | wxString msg; | |
42ed7532 MB |
894 | msg << _T("The item is ") << (item->IsEnabled() ? _T("enabled") |
895 | : _T("disabled")) | |
6ee9b7b5 | 896 | << _T('\n'); |
f6bcfd97 | 897 | |
a80c322c VZ |
898 | if ( item->IsCheckable() ) |
899 | { | |
42ed7532 MB |
900 | msg << _T("It is checkable and ") << (item->IsChecked() ? _T("") : _T("un")) |
901 | << _T("checked\n"); | |
a80c322c VZ |
902 | } |
903 | ||
904 | #if wxUSE_ACCEL | |
905 | wxAcceleratorEntry *accel = item->GetAccel(); | |
906 | if ( accel ) | |
907 | { | |
42ed7532 | 908 | msg << _T("Its accelerator is "); |
a80c322c VZ |
909 | |
910 | int flags = accel->GetFlags(); | |
911 | if ( flags & wxACCEL_ALT ) | |
6ee9b7b5 | 912 | msg << _T("Alt-"); |
a80c322c | 913 | if ( flags & wxACCEL_CTRL ) |
6ee9b7b5 | 914 | msg << _T("Ctrl-"); |
a80c322c | 915 | if ( flags & wxACCEL_SHIFT ) |
6ee9b7b5 | 916 | msg << _T("Shift-"); |
a80c322c VZ |
917 | |
918 | int code = accel->GetKeyCode(); | |
919 | switch ( code ) | |
920 | { | |
921 | case WXK_F1: | |
922 | case WXK_F2: | |
923 | case WXK_F3: | |
924 | case WXK_F4: | |
925 | case WXK_F5: | |
926 | case WXK_F6: | |
927 | case WXK_F7: | |
928 | case WXK_F8: | |
929 | case WXK_F9: | |
930 | case WXK_F10: | |
931 | case WXK_F11: | |
932 | case WXK_F12: | |
6ee9b7b5 | 933 | msg << _T('F') << code - WXK_F1 + 1; |
a80c322c VZ |
934 | break; |
935 | ||
936 | // if there are any other keys wxGetAccelFromString() may return, | |
937 | // we should process them here | |
938 | ||
939 | default: | |
940 | if ( wxIsalnum(code) ) | |
941 | { | |
942 | msg << (wxChar)code; | |
943 | ||
944 | break; | |
945 | } | |
946 | ||
6ee9b7b5 | 947 | wxFAIL_MSG( _T("unknown keyboard accel") ); |
a80c322c VZ |
948 | } |
949 | ||
950 | delete accel; | |
951 | } | |
952 | else | |
953 | { | |
42ed7532 | 954 | msg << _T("It doesn't have an accelerator"); |
a80c322c VZ |
955 | } |
956 | #endif // wxUSE_ACCEL | |
957 | ||
958 | wxLogMessage(msg); | |
959 | } | |
960 | } | |
961 | ||
1242c2d9 | 962 | #if wxUSE_TEXTDLG |
f6d90fb9 GD |
963 | void MyFrame::OnFindMenuItem(wxCommandEvent& WXUNUSED(event)) |
964 | { | |
965 | wxMenuBar *mbar = GetMenuBar(); | |
966 | size_t count = mbar->GetMenuCount(); | |
967 | ||
968 | wxCHECK_RET( count, _T("no last menu?") ); | |
969 | ||
970 | wxString label = wxGetTextFromUser | |
971 | ( | |
972 | _T("Enter label to search for: "), | |
973 | _T("Find menu item"), | |
532d575b | 974 | wxEmptyString, |
f6d90fb9 GD |
975 | this |
976 | ); | |
977 | ||
978 | if ( !label.empty() ) | |
979 | { | |
6ee9b7b5 | 980 | size_t menuindex; |
f6d90fb9 | 981 | int index = wxNOT_FOUND; |
62ad15a5 | 982 | |
f6d90fb9 GD |
983 | for (menuindex = 0; (menuindex < count) && (index == wxNOT_FOUND); ++menuindex) |
984 | { | |
985 | index = mbar->FindMenuItem(mbar->GetMenu(menuindex)->GetTitle(), label); | |
986 | } | |
987 | if (index == wxNOT_FOUND) | |
988 | { | |
6ee9b7b5 | 989 | wxLogWarning(_T("No menu item with label '%s'"), label.c_str()); |
f6d90fb9 GD |
990 | } |
991 | else | |
992 | { | |
6ee9b7b5 | 993 | wxLogMessage(_T("Menu item %d in menu %lu has label '%s'"), |
2e491df9 | 994 | index, (unsigned long)menuindex, label.c_str()); |
f6d90fb9 GD |
995 | } |
996 | } | |
997 | } | |
1242c2d9 | 998 | #endif |
f6d90fb9 | 999 | |
ccef86c7 | 1000 | void MyFrame::ShowContextMenu(const wxPoint& pos) |
717a57c2 | 1001 | { |
42b16af4 | 1002 | wxMenu menu; |
717a57c2 | 1003 | |
42ed7532 MB |
1004 | menu.Append(Menu_Help_About, _T("&About")); |
1005 | menu.Append(Menu_Popup_Submenu, _T("&Submenu"), CreateDummyMenu(NULL)); | |
1006 | menu.Append(Menu_Popup_ToBeDeleted, _T("To be &deleted")); | |
2153bf89 | 1007 | menu.AppendCheckItem(Menu_Popup_ToBeChecked, _T("To be &checked")); |
4760fa91 VZ |
1008 | menu.Append(Menu_Popup_ToBeGreyed, _T("To be &greyed"), |
1009 | _T("This menu item should be initially greyed out")); | |
717a57c2 | 1010 | menu.AppendSeparator(); |
42ed7532 | 1011 | menu.Append(Menu_File_Quit, _T("E&xit")); |
717a57c2 | 1012 | |
f6bcfd97 | 1013 | menu.Delete(Menu_Popup_ToBeDeleted); |
6ee9b7b5 JS |
1014 | menu.Check(Menu_Popup_ToBeChecked, true); |
1015 | menu.Enable(Menu_Popup_ToBeGreyed, false); | |
717a57c2 | 1016 | |
ccef86c7 | 1017 | PopupMenu(&menu, pos.x, pos.y); |
f6bcfd97 BP |
1018 | |
1019 | // test for destroying items in popup menus | |
e421922f | 1020 | #if 0 // doesn't work in wxGTK! |
f6bcfd97 BP |
1021 | menu.Destroy(Menu_Popup_Submenu); |
1022 | ||
1023 | PopupMenu( &menu, event.GetX(), event.GetY() ); | |
1024 | #endif // 0 | |
717a57c2 | 1025 | } |
e421922f | 1026 | |
256b8649 | 1027 | void MyFrame::OnTestNormal(wxCommandEvent& WXUNUSED(event)) |
d65c269b VZ |
1028 | { |
1029 | wxLogMessage(_T("Normal item selected")); | |
1030 | } | |
1031 | ||
1032 | void MyFrame::OnTestCheck(wxCommandEvent& event) | |
1033 | { | |
1034 | wxLogMessage(_T("Check item %schecked"), | |
1035 | event.IsChecked() ? _T("") : _T("un")); | |
1036 | } | |
1037 | ||
1038 | void MyFrame::OnTestRadio(wxCommandEvent& event) | |
1039 | { | |
1040 | wxLogMessage(_T("Radio item %d selected"), | |
1041 | event.GetId() - Menu_Test_Radio1 + 1); | |
1042 | } | |
1043 | ||
1242c2d9 | 1044 | #if USE_LOG_WINDOW |
ccef86c7 VZ |
1045 | void MyFrame::LogMenuOpenOrClose(const wxMenuEvent& event, const wxChar *what) |
1046 | { | |
6ee9b7b5 JS |
1047 | wxString msg; |
1048 | msg << _T("A ") | |
1049 | << ( event.IsPopup() ? _T("popup ") : _T("") ) | |
1050 | << _T("menu has been ") | |
1051 | << what | |
1052 | << _T("."); | |
62ad15a5 | 1053 | |
6ee9b7b5 | 1054 | wxLogStatus(this, msg.c_str()); |
ccef86c7 | 1055 | } |
1242c2d9 | 1056 | #endif |
ccef86c7 | 1057 | |
c377f1be JS |
1058 | void MyFrame::OnUpdateSubMenuNormal(wxUpdateUIEvent& event) |
1059 | { | |
6ee9b7b5 | 1060 | event.Enable(false); |
c377f1be JS |
1061 | } |
1062 | ||
1063 | void MyFrame::OnUpdateSubMenuCheck(wxUpdateUIEvent& event) | |
1064 | { | |
6ee9b7b5 | 1065 | event.Enable(true); |
c377f1be JS |
1066 | } |
1067 | ||
1068 | void MyFrame::OnUpdateSubMenuRadio(wxUpdateUIEvent& event) | |
1069 | { | |
1070 | int which = (event.GetId() - Menu_SubMenu_Radio1 + 1); | |
1071 | if (which == 2) | |
6ee9b7b5 | 1072 | event.Check(true); |
c377f1be | 1073 | else |
6ee9b7b5 | 1074 | event.Check(false); |
c377f1be JS |
1075 | } |
1076 | ||
ac103441 RR |
1077 | #if USE_CONTEXT_MENU |
1078 | void MyFrame::OnContextMenu(wxContextMenuEvent& event) | |
1079 | { | |
1080 | wxPoint point = event.GetPosition(); | |
1081 | // If from keyboard | |
1082 | if (point.x == -1 && point.y == -1) { | |
1083 | wxSize size = GetSize(); | |
1084 | point.x = size.x / 2; | |
1085 | point.y = size.y / 2; | |
1086 | } else { | |
1087 | point = ScreenToClient(point); | |
1088 | } | |
1089 | ShowContextMenu(point); | |
1090 | } | |
1091 | #endif | |
1092 | ||
256b8649 | 1093 | void MyFrame::OnSize(wxSizeEvent& WXUNUSED(event)) |
e421922f | 1094 | { |
1242c2d9 | 1095 | #if USE_LOG_WINDOW |
268766dd VZ |
1096 | if ( !m_textctrl ) |
1097 | return; | |
1098 | ||
e421922f VZ |
1099 | // leave a band below for popup menu testing |
1100 | wxSize size = GetClientSize(); | |
1101 | m_textctrl->SetSize(0, 0, size.x, (3*size.y)/4); | |
1242c2d9 | 1102 | #endif |
e421922f VZ |
1103 | |
1104 | // this is really ugly but we have to do it as we can't just call | |
1105 | // event.Skip() because wxFrameBase would make the text control fill the | |
1106 | // entire frame then | |
1107 | #ifdef __WXUNIVERSAL__ | |
1108 | PositionMenuBar(); | |
1109 | #endif // __WXUNIVERSAL__ | |
1110 | } | |
1111 |