4
%% Copyright Ericsson AB 2009. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
19
%%%-------------------------------------------------------------------
21
%%% Author : Matthew Harrison <harryhuk at users.sourceforge.net>
22
%%% Description : Test of menus
24
%%% Created : 18 Sep 2008 by Matthew Harrison <harryhuk at users.sourceforge.net>
25
%%%-------------------------------------------------------------------
28
-include_lib("wx/include/wx.hrl").
33
%%%Lots of IDs to declare!
34
-define(menuID_FILE_QUIT, ?wxID_EXIT).
35
-define(menuID_FILE_CLEAR_LOG, 100).
37
-define(menuID_MENUBAR_TOGGLE, 200).
38
-define(menuID_MENUBAR_APPEND, 201).
39
-define(menuID_MENUBAR_INSERT, 202).
40
-define(menuID_MENUBAR_DELETE, 203).
41
-define(menuID_MENUBAR_ENABLE, 204).
42
-define(menuID_MENUBAR_GET_LABEL, 206).
43
-define(menuID_MENUBAR_SET_LABEL, 207).
44
-define(menuID_MENUBAR_FIND_MENU, 208).
46
-define(menuID_MENU_APPEND, 300).
47
-define(menuID_MENU_APPEND_SUB, 301).
48
-define(menuID_MENU_INSERT, 302).
49
-define(menuID_MENU_DELETE, 303).
50
-define(menuID_MENU_ENABLE, 304).
51
-define(menuID_MENU_CHECK, 305).
52
-define(menuID_MENU_GET_LABEL, 306).
53
-define(menuID_MENU_SET_LABEL, 307).
54
-define(menuID_MENU_GET_INFO, 308).
55
-define(menuID_MENU_FIND_ITEM, 309).
57
-define(menuID_TEST_NORMAL, 400).
58
-define(menuID_TEST_CHECK, 401).
59
-define(menuID_TEST_RADIO_1, 402).
60
-define(menuID_TEST_RADIO_2, 403).
61
-define(menuID_TEST_RADIO_3, 404).
63
-define(menuID_SUBMENU, 450).
64
-define(menuID_SUBMENU_NORMAL, 451).
65
-define(menuID_SUBMENU_CHECK, 452).
66
-define(menuID_SUBMENU_RADIO_1, 453).
67
-define(menuID_SUBMENU_RADIO_2, 454).
68
-define(menuID_SUBMENU_RADIO_3, 455).
70
-define(menuID_DUMMY_FIRST, 500).
71
-define(menuID_DUMMY_SECOND, 501).
72
-define(menuID_DUMMY_THIRD, 502).
73
-define(menuID_DUMMY_FOURTH, 503).
74
-define(menuID_DUMMY_LAST, 504).
76
-define(menuID_HELP_ABOUT, ?wxID_ABOUT).
78
-define(menuID_POPUP_TO_BE_DELETED, 2000).
79
-define(menuID_POPUP_TO_BE_GREYED, 2001).
80
-define(menuID_POPUP_TO_BE_CHECKED, 2002).
81
-define(menuID_POPUP_TO_BE_SUBMENU, 2003).
83
-define(wID_LOG_TEXT_CTRL, 3000).
85
-record(state, {dummyMenuCount=0, fileMenu=undefined}).
92
Frame = wx:batch(fun() -> create_frame(Wx) end),
105
Frame = wxFrame:new(Wx, -1, "wxErlang menu sample", [{size, {600,400}}]),
107
Path = filename:dirname(code:which(?MODULE)),
108
wxFrame:setIcon(Frame, wxIcon:new(filename:join(Path,"sample.xpm"))),
110
wxFrame:createStatusBar(Frame,[]),
111
wxFrame:connect(Frame, close_window),
113
FileMenu = create_file_menu(),
114
MenuBarMenu = create_menubar_menu(),
115
MenuMenu = create_menu_menu(),
116
TestMenu = create_test_menu(),
117
HelpMenu = create_help_menu(),
119
MenuBar = wxMenuBar:new(?wxMB_DOCKABLE),
122
wxMenuBar:append(MenuBar, FileMenu, "&File"),
123
wxMenuBar:append(MenuBar, MenuBarMenu, "Menu&bar"),
124
wxMenuBar:append(MenuBar, MenuMenu, "&Menu"),
125
wxMenuBar:append(MenuBar, TestMenu, "&Test"),
126
wxMenuBar:append(MenuBar, HelpMenu, "&Help"),
128
wxFrame:setMenuBar(Frame, MenuBar),
130
LogTextCtrl = wxTextCtrl:new(Frame, ?wID_LOG_TEXT_CTRL,
132
%{pos, ?wxDefaultPosition},
133
%{size, ?wxDefaultSize},
134
{style, ?wxTE_MULTILINE}]),
135
wxTextCtrl:setEditable(LogTextCtrl, false),
137
ok = wxFrame:setStatusText(Frame, "Welcome to wxErlang menu sample",[]),
139
ok = wxFrame:connect(Frame, command_menu_selected),
141
String = "Brief explanations:~n"
142
"the commands from the \"Menu\" menu append/insert/delete items to/from the last menu.~n"
143
"The commands from \"Menubar\" menu work with the menubar itself.~n~n",
144
%% "Right click the band below to test popup menus.~n",
145
logMessage(Frame, String),
151
create_file_menu() ->
152
FileMenu = wxMenu:new(),
154
wxMenu:append(FileMenu, wxMenuItem:new([
155
{id, ?menuID_SUBMENU},
156
{subMenu, create_stock_menu()},
157
{text, "&Standard items demo"}
159
ClearLogBitmap = wxBitmap:new("copy.xpm"),
160
ClearLogItem = wxMenuItem:new([
161
{id, ?menuID_FILE_CLEAR_LOG},
162
{text, "Clear &log\tCtrl-L"} %% note mnemonic and accelerator
164
wxMenuItem:setBitmap(ClearLogItem, ClearLogBitmap),
166
wxMenu:append(FileMenu, ClearLogItem ),
167
wxMenu:appendSeparator(FileMenu),
168
wxMenu:append(FileMenu, wxMenuItem:new([
169
{id, ?menuID_FILE_QUIT} %,
170
%{text, "E&xit\tAlt-X"}
177
create_menubar_menu() ->
178
MenuBarMenu = wxMenu:new(),
179
wxMenu:append(MenuBarMenu, wxMenuItem:new([
180
{id, ?menuID_MENUBAR_APPEND},
181
{text, "&Append menu\tCtrl-A"},
182
{help, "Append a menu to the menubar"}
184
wxMenu:append(MenuBarMenu, wxMenuItem:new([
185
{id, ?menuID_MENUBAR_INSERT},
186
{text, "&Insert menu\tCtrl-I"},
187
{help, "Insert a menu into the menubar"}
189
wxMenu:append(MenuBarMenu, wxMenuItem:new([
190
{id, ?menuID_MENUBAR_DELETE},
191
{text, "&Delete menu\tCtrl-D"},
192
{help, "Insert a menu into the menubar"}
194
wxMenu:append(MenuBarMenu, wxMenuItem:new([
195
{id, ?menuID_MENUBAR_TOGGLE},
196
{text, "&Toggle menu\tCtrl-T"},
197
{help, "Toggle the first menu in the menubar"},
198
{kind, ?wxITEM_CHECK}
200
wxMenu:appendSeparator(MenuBarMenu), %% --------------------------
201
wxMenu:append(MenuBarMenu, wxMenuItem:new([
202
{id, ?menuID_MENUBAR_ENABLE},
203
{text, "&Enable menu\tCtrl-E"},
204
{help, "Enable or disable the last menu"},
205
{kind, ?wxITEM_CHECK}
207
wxMenu:appendSeparator(MenuBarMenu), %% --------------------------
208
wxMenu:append(MenuBarMenu, wxMenuItem:new([
209
{id, ?menuID_MENUBAR_GET_LABEL},
210
{text, "&Get menu label\tCtrl-G"},
211
{help, "Get the label of the last menu"}
213
wxMenu:append(MenuBarMenu, wxMenuItem:new([
214
{id, ?menuID_MENUBAR_SET_LABEL},
215
{text, "&Set menu label\tCtrl-S"},
216
{help, "Change the label of the last menu"}
218
wxMenu:appendSeparator(MenuBarMenu), %% --------------------------
219
wxMenu:append(MenuBarMenu, wxMenuItem:new([
220
{id, ?menuID_MENUBAR_FIND_MENU},
221
{text, "&Find menu from label\tCtrl-F"},
222
{help, "Find a menu by searching for its label"}
230
create_submenu_menu() ->
231
SubMenuMenu = wxMenu:new(),
232
wxMenu:append(SubMenuMenu, wxMenuItem:new([
233
{id, ?menuID_SUBMENU_NORMAL},
234
{text, "&Normal submenu item"},
235
{help, "Disabled submenu item"}
237
%% note different way of adding check menu item
238
wxMenu:appendCheckItem(SubMenuMenu,
239
?menuID_SUBMENU_CHECK,
240
"&Check submenu item",
241
[{help, "Check submenu item"}]),
242
wxMenu:appendRadioItem(SubMenuMenu,
243
?menuID_SUBMENU_RADIO_1,
245
[{help, "Radio item"}]),
246
wxMenu:appendRadioItem(SubMenuMenu,
247
?menuID_SUBMENU_RADIO_2,
249
[{help, "Radio item"}]),
250
wxMenu:appendRadioItem(SubMenuMenu,
251
?menuID_SUBMENU_RADIO_3,
253
[{help, "Radio item"}]),
260
create_menu_menu() ->
261
MenuMenu = wxMenu:new(),
262
wxMenu:append(MenuMenu, wxMenuItem:new([
263
{id, ?menuID_MENU_APPEND},
264
{text, "&Append menu item\tAlt-A"},
265
{help, "Append a menu item to the last menu"}
267
wxMenu:append(MenuMenu, wxMenuItem:new([
268
{id, ?menuID_MENU_APPEND_SUB},
269
{text, "&Append sub menu\tAlt-S"},
270
{help, "Append a sub menu to the last menu"}
272
wxMenu:append(MenuMenu, wxMenuItem:new([
273
{id, ?menuID_MENU_INSERT},
274
{text, "&Insert menu item\tAlt-I"},
275
{help, "Insert a menu item in head of the last menu"}
277
wxMenu:append(MenuMenu, wxMenuItem:new([
278
{id, ?menuID_MENU_DELETE},
279
{text, "&Delete menu item\tAlt-D"},
280
{help, "Delete the last menu item from the last menu"}
282
wxMenu:appendSeparator(MenuMenu), %% --------------------------
283
wxMenu:append(MenuMenu, wxMenuItem:new([
284
{id, ?menuID_MENU_ENABLE},
285
{text, "&Enable menu item\tAlt-E"},
286
{help, "Enable or disable the last menu item"},
287
{kind, ?wxITEM_CHECK}
289
wxMenu:append(MenuMenu, wxMenuItem:new([
290
{id, ?menuID_MENU_CHECK},
291
{text, "&Check menu item\tAlt-C"},
292
{help, "Check or uncheck the last menu item"},
293
{kind, ?wxITEM_CHECK}
295
wxMenu:appendSeparator(MenuMenu), %% --------------------------
296
wxMenu:append(MenuMenu, wxMenuItem:new([
297
{id, ?menuID_MENU_GET_INFO},
298
{text, "Get menu item in&fo\tAlt-F"},
299
{help, "Show the state of the last menu item"}
301
wxMenu:append(MenuMenu, wxMenuItem:new([
302
{id, ?menuID_MENU_SET_LABEL},
303
{text, "&Set menu label\tCtrl-S"},
304
{help, "Change the label of the last menu"}
306
wxMenu:appendSeparator(MenuMenu), %% --------------------------
307
wxMenu:append(MenuMenu, wxMenuItem:new([
308
{id, ?menuID_MENU_FIND_ITEM},
309
{text, "Find menu item from label"},
310
{help, "Find a menu item by searching for its label"}
318
create_test_menu() ->
319
TestMenu = wxMenu:new(),
320
wxMenu:append(TestMenu, wxMenuItem:new([
321
{id, ?menuID_TEST_NORMAL},
322
{text, "&Normal submenu item"},
323
{help, "Disabled submenu item"}
325
wxMenu:appendSeparator(TestMenu), %% --------------------------
326
%% note different way of adding check menu item
327
wxMenu:appendCheckItem(TestMenu, ?menuID_TEST_CHECK, "&Check item"),
328
wxMenu:appendSeparator(TestMenu), %% --------------------------
329
wxMenu:appendRadioItem(TestMenu, ?menuID_TEST_RADIO_1, "Radio item &1"),
330
wxMenu:appendRadioItem(TestMenu, ?menuID_TEST_RADIO_2, "Radio item &2"),
331
wxMenu:appendRadioItem(TestMenu, ?menuID_TEST_RADIO_3, "Radio item &3"),
337
create_help_menu() ->
338
HelpMenu = wxMenu:new(),
339
% unlike wxwidgets the stock menu items still need text to be given,
340
% although help text does appear
341
% Note the keybord accelerator
342
wxMenu:append(HelpMenu, wxMenuItem:new([
343
{id, ?menuID_HELP_ABOUT},
344
%{text, "&About\tF1"},
345
{help, "About menu sample"}
352
create_stock_menu() ->
353
% unlike wxwidgets the stock menu items still need text to be given,
354
% although help text does appear
355
StockSubMenu = wxMenu:new(),
356
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_ADD }])),
357
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_APPLY }])),
358
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_BOLD }])),
359
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_CANCEL }])),
360
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_CLEAR }])),
361
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_CLOSE }])),
362
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_COPY }])),
363
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_CUT }])),
364
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_DELETE }])),
365
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_FIND }])),
366
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_REPLACE }])),
367
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_BACKWARD }])),
368
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_DOWN }])),
369
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_FORWARD }])),
370
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_UP }])),
371
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_HELP }])),
372
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_HOME }])),
373
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_INDENT }])),
374
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_INDEX }])),
375
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_ITALIC }])),
376
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_JUSTIFY_CENTER }])),
377
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_JUSTIFY_FILL }])),
378
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_JUSTIFY_LEFT }])),
379
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_JUSTIFY_RIGHT }])),
380
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_NEW }])),
381
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_NO }])),
382
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_OK }])),
383
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_OPEN }])),
384
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_PASTE }])),
385
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_PREFERENCES }])),
386
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_PRINT }])),
387
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_PREVIEW }])),
388
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_PROPERTIES }])),
389
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_EXIT }])),
390
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_REDO }])),
391
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_REFRESH }])),
392
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_REMOVE }])),
393
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_REVERT_TO_SAVED }])),
394
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_SAVE }])),
395
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_SAVEAS }])),
396
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_STOP }])),
397
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_UNDELETE }])),
398
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_UNDERLINE }])),
399
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_UNDO }])),
400
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_UNINDENT }])),
401
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_YES }])),
402
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_ZOOM_100 }])),
403
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_ZOOM_FIT }])),
404
wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_ZOOM_OUT }])),
408
create_dummy_menu() ->
409
DummyMenu = wxMenu:new(),
410
wxMenu:append(DummyMenu, ?menuID_DUMMY_FIRST, "&First item\tCtrl-F1"),
411
wxMenu:appendSeparator(DummyMenu), %% --------------------------
412
wxMenu:append(DummyMenu, ?menuID_DUMMY_SECOND, "&Second item\tCtrl-F2"),
417
#wx{event=#wxClose{}, obj=Frame} ->
418
io:format("~p Closing window ~n",[self()]),
419
wxWindow:destroy(Frame); %onClose(Frame);
420
#wx{id=?menuID_FILE_QUIT, obj=Frame, event=#wxCommand{type=command_menu_selected}} ->
421
io:format("~p Closing window ~n",[self()]),
422
wxWindow:destroy(Frame); %onClose(Frame);
424
#wx{obj=Frame, userData=UserData, event=#wxCommand{type=command_menu_selected}} = Wx->
425
logMessage(Frame, "got wx:~p ud:~p~n", [Wx, UserData]),
426
State1 = onMenuAction(Wx, State),
429
io:format("Got ~p ~n", [Msg]),
436
onMenuAction(#wx{id=?menuID_FILE_CLEAR_LOG, obj=Frame}, #state{} = State) ->
437
wxTextCtrl:clear(findLogger(Frame)),
441
onMenuAction(#wx{id=?menuID_MENUBAR_APPEND, obj=Frame}, #state{} = State) ->
442
MenuBar = wxFrame:getMenuBar(Frame),
443
wxMenuBar:append(MenuBar, create_dummy_menu(), "DummyMenu"),
446
onMenuAction(#wx{id=?menuID_MENUBAR_INSERT, obj=Frame}, #state{} = State) ->
447
MenuBar = wxFrame:getMenuBar(Frame),
448
wxMenuBar:insert(MenuBar, 0, create_dummy_menu(), "DummyMenu"),
451
onMenuAction(#wx{id=?menuID_MENUBAR_DELETE, obj=Frame}, #state{} = State) ->
452
MenuBar = wxFrame:getMenuBar(Frame),
453
Count = wxMenuBar:getMenuCount(MenuBar),
456
wxMenuBar:remove(MenuBar, Count -1);
458
logMessage(Frame, "Cannot delete any more menus~n")
462
onMenuAction(#wx{id=?menuID_MENUBAR_TOGGLE, obj=Frame}, #state{fileMenu=FileMenu} = State) ->
463
logMessage(Frame, "onMenubarToggle ~p ~n", [FileMenu]),
464
MenuBar = wxFrame:getMenuBar(Frame),
466
FileMenu =:= undefined ->
467
Menu = wxMenuBar:remove(MenuBar, 0),
468
State#state{fileMenu=Menu};
470
wxMenuBar:insert(MenuBar, 0, FileMenu, "&File"),
471
State#state{fileMenu=undefined}
474
onMenuAction( #wx{id=?menuID_MENUBAR_ENABLE=Id, obj=Frame}, #state{} = State) ->
475
%% logMessage(Frame, "onMenubarEnable ~n"),
476
MenuBar = wxFrame:getMenuBar(Frame),
477
MenuItem = wxMenuBar:findItem(MenuBar, Id),
478
Enable = (not wxMenuItem:isCheckable(MenuItem)) orelse wxMenuItem:isChecked(MenuItem),
480
Count = wxMenuBar:getMenuCount(MenuBar),
481
wxMenuBar:enableTop(MenuBar, (Count - 1), Enable),
485
onMenuAction( #wx{id=?menuID_MENUBAR_GET_LABEL, obj=Frame}, #state{} = State) ->
486
logMessage(Frame, "onMenubarGetLabel ~n"),
487
MenuBar = wxFrame:getMenuBar(Frame),
488
Count = wxMenuBar:getMenuCount(MenuBar),
489
Label = wxMenuBar:getLabelTop(MenuBar, (Count - 1)),
490
logMessage(Frame, "The label of the last menu item is ~p", [Label]),
493
onMenuAction( #wx{id=?menuID_MENUBAR_SET_LABEL, obj=Frame}, #state{} = State) ->
494
%% logMessage(Frame, "onMenubarGetLabel ~n"),
495
MenuBar = wxFrame:getMenuBar(Frame),
496
Count = wxMenuBar:getMenuCount(MenuBar),
497
Label = wxMenuBar:getLabelTop(MenuBar, (Count - 1)),
498
TextDialog = wxTextEntryDialog:new(Frame,
500
[{caption, "Change last menu text"}, {value, Label}]),
501
wxDialog:showModal(TextDialog),
502
NewLabel = wxTextEntryDialog:getValue(TextDialog),
503
wxMenuBar:setLabelTop(MenuBar, (Count - 1), NewLabel),
504
wxDialog:destroy(TextDialog),
507
onMenuAction( #wx{id=?menuID_MENUBAR_FIND_MENU, obj=Frame}, #state{} = State) ->
508
%% logMessage(Frame, "onMenubarFindMenu ~n"),
509
MenuBar = wxFrame:getMenuBar(Frame),
510
_Count = wxMenuBar:getMenuCount(MenuBar),
511
% Label = wxMenuBar:getLabelTop(MenuBar, (Count - 1)),
512
TextDialog = wxTextEntryDialog:new(Frame,
513
"Enter label to search for: ",
514
[{caption, "Find menu"}]),
515
wxDialog:showModal(TextDialog),
516
Label = wxTextEntryDialog:getValue(TextDialog),
517
Len = string:len(Label),
520
Index = wxMenuBar:findMenu(MenuBar, Label),
522
(Index =:= ?wxNOT_FOUND) ->
523
logMessage(Frame, "Warning: No menu with label ~p", [Label]);
525
logMessage(Frame, "Menu ~p has label ~p", [Index, Label])
532
onMenuAction(#wx{id=?menuID_MENU_APPEND, obj=Frame}, #state{} = State) ->
533
MenuBar = wxFrame:getMenuBar(Frame),
534
Count = wxMenuBar:getMenuCount(MenuBar),
535
Menu = wxMenuBar:getMenu(MenuBar, Count - 1),
536
io:format("MenuBar ~p Menu ~p Count ~p ~n", [MenuBar, Menu, Count]),
537
wxMenu:appendSeparator(Menu),
538
wxMenu:append(Menu, wxMenuItem:new([
539
{id, ?menuID_DUMMY_THIRD},
540
{text, "&Third dummy item\tCtrl-F3"},
541
{kind, ?wxITEM_CHECK}
546
onMenuAction(#wx{id=?menuID_MENU_APPEND_SUB, obj=Frame}, #state{} = State) ->
547
MenuBar = wxFrame:getMenuBar(Frame),
548
Count = wxMenuBar:getMenuCount(MenuBar),
549
Menu = wxMenuBar:getMenu(MenuBar, Count - 2),
550
wxMenu:appendSeparator(Menu),
551
wxMenu:append(Menu, wxMenuItem:new([
552
{id, ?menuID_DUMMY_LAST},
553
{text, "&Dummy sub menu"},
554
{help, "Dummy sub menu help"},
555
{subMenu, create_dummy_menu()}
560
onMenuAction(#wx{id=Id, obj=Frame}, #state{}=State) when ((Id >= ?menuID_DUMMY_FIRST) and (Id =< ?menuID_DUMMY_LAST)) ->
561
logMessage(Frame, "Dummy item #~p ~n", [Id - ?menuID_DUMMY_FIRST + 1]),
564
onMenuAction( #wx{id=?menuID_HELP_ABOUT=Id, obj=Frame}, #state{} = State) ->
565
showDialog(Id, Frame),
568
onMenuAction( #wx{obj=Frame} = Wx, State) ->
569
logMessage(Frame, "unimplemented menu item event ~p ~n", [Wx]),
572
logMessage(Frame, Msg) ->
573
logMessage(Frame, Msg, []).
575
logMessage(Frame, Msg, ArgList) ->
576
String = lists:flatten(io_lib:format(Msg, ArgList)),
578
wxTextCtrl:appendText(findLogger(Frame), String).
581
LogWin = wxWindow:findWindowById(?wID_LOG_TEXT_CTRL, [{parent, Frame}]),
582
wx:typeCast(LogWin, wxTextCtrl).
585
showDialog(?menuID_HELP_ABOUT, Frame) ->
586
String = lists:flatten(io_lib:format("Welcome to wxErlang 0.97.5.26!~n~n"
587
"This is the minimal wxErlang sample~n"
589
[wx_misc:getOsDescription()])),
590
MessageDialog = wxMessageDialog:new(Frame,
592
[{style, ?wxOK bor ?wxICON_INFORMATION},
593
{caption, "About wxErlang minimal sample"}]),
595
wxDialog:showModal(MessageDialog),
596
wxDialog:destroy(MessageDialog);
598
showDialog(Id, Frame) ->
599
String = lists:flatten(io_lib:format("Unimplemented Dialog ~p", [Id])),
600
MessageDialog = wxMessageDialog:new(Frame,
602
[{style, ?wxOK bor ?wxICON_INFORMATION},
603
{caption, "wxErlang minimal sample"}]),
605
wxDialog:showModal(MessageDialog),
606
wxDialog:destroy(MessageDialog).