~statik/ubuntu/maverick/erlang/erlang-merge-testing

« back to all changes in this revision

Viewing changes to lib/wx/examples/simple/menu.erl

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-05-01 10:14:38 UTC
  • mfrom: (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090501101438-6qlr6rsdxgyzrg2z
Tags: 1:13.b-dfsg-2
* Cleaned up patches: removed unneeded patch which helped to support
  different SCTP library versions, made sure that changes for m68k
  architecture applied only when building on this architecture.
* Removed duplicated information from binary packages descriptions.
* Don't require libsctp-dev build-dependency on solaris-i386 architecture
  which allows to build Erlang on Nexenta (thanks to Tim Spriggs for
  the suggestion).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%
 
2
%% %CopyrightBegin%
 
3
%% 
 
4
%% Copyright Ericsson AB 2009. All Rights Reserved.
 
5
%% 
 
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/.
 
11
%% 
 
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
 
15
%% under the License.
 
16
%% 
 
17
%% %CopyrightEnd%
 
18
%%
 
19
%%%-------------------------------------------------------------------
 
20
%%% File    : menus.erl
 
21
%%% Author  : Matthew Harrison <harryhuk at users.sourceforge.net>
 
22
%%% Description : Test of menus
 
23
%%%
 
24
%%% Created :  18 Sep 2008 by  Matthew Harrison <harryhuk at users.sourceforge.net>
 
25
%%%-------------------------------------------------------------------
 
26
-module(menu).
 
27
 
 
28
-include_lib("wx/include/wx.hrl").
 
29
 
 
30
-export([start/0]).
 
31
-compile(export_all).
 
32
 
 
33
%%%Lots of IDs to declare!
 
34
-define(menuID_FILE_QUIT,           ?wxID_EXIT).
 
35
-define(menuID_FILE_CLEAR_LOG,      100).
 
36
 
 
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).
 
45
 
 
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).
 
56
 
 
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).
 
62
 
 
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).
 
69
 
 
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).
 
75
 
 
76
-define(menuID_HELP_ABOUT,          ?wxID_ABOUT).
 
77
 
 
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).
 
82
 
 
83
-define(wID_LOG_TEXT_CTRL, 3000).
 
84
 
 
85
-record(state, {dummyMenuCount=0, fileMenu=undefined}).
 
86
 
 
87
%%    
 
88
%%    
 
89
%%    
 
90
start() ->
 
91
    Wx = wx:new(),
 
92
    Frame = wx:batch(fun() -> create_frame(Wx) end),
 
93
    wxWindow:show(Frame),
 
94
    
 
95
    State = #state{},
 
96
    
 
97
    loop(State),
 
98
    ok.
 
99
 
 
100
 
 
101
%%    
 
102
%%    
 
103
%%    
 
104
create_frame(Wx) ->
 
105
    Frame = wxFrame:new(Wx, -1, "wxErlang menu sample", [{size, {600,400}}]),
 
106
 
 
107
    Path = filename:dirname(code:which(?MODULE)),    
 
108
    wxFrame:setIcon(Frame,  wxIcon:new(filename:join(Path,"sample.xpm"))),
 
109
 
 
110
    wxFrame:createStatusBar(Frame,[]),
 
111
    wxFrame:connect(Frame, close_window),
 
112
 
 
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(),
 
118
            
 
119
    MenuBar    = wxMenuBar:new(?wxMB_DOCKABLE),
 
120
 
 
121
 
 
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"),
 
127
    
 
128
    wxFrame:setMenuBar(Frame, MenuBar),
 
129
    
 
130
    LogTextCtrl = wxTextCtrl:new(Frame, ?wID_LOG_TEXT_CTRL, 
 
131
                                 [{value, ""},
 
132
                                                %{pos, ?wxDefaultPosition}, 
 
133
                                                %{size, ?wxDefaultSize}, 
 
134
                                  {style, ?wxTE_MULTILINE}]),
 
135
    wxTextCtrl:setEditable(LogTextCtrl, false),
 
136
 
 
137
    ok = wxFrame:setStatusText(Frame, "Welcome to wxErlang menu sample",[]),
 
138
    
 
139
    ok = wxFrame:connect(Frame, command_menu_selected), 
 
140
    
 
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),
 
146
    Frame.
 
147
 
 
148
%%    
 
149
%%    
 
150
%%    
 
151
create_file_menu() ->
 
152
    FileMenu  = wxMenu:new(),
 
153
    
 
154
    wxMenu:append(FileMenu, wxMenuItem:new([
 
155
            {id,        ?menuID_SUBMENU},
 
156
            {subMenu,   create_stock_menu()},
 
157
            {text,      "&Standard items demo"}
 
158
            ])),
 
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
 
163
            ]),
 
164
    wxMenuItem:setBitmap(ClearLogItem, ClearLogBitmap),
 
165
            
 
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"}
 
171
            ])),
 
172
    FileMenu.
 
173
 
 
174
%%    
 
175
%%    
 
176
%%    
 
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"}
 
183
            ])),
 
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"}
 
188
            ])),
 
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"}
 
193
            ])),
 
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}
 
199
            ])),   
 
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}
 
206
            ])),
 
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"}
 
212
            ])),
 
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"}
 
217
            ])),
 
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"}
 
223
            ])),
 
224
    MenuBarMenu.
 
225
 
 
226
 
 
227
%%    
 
228
%%    
 
229
%%    
 
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"}
 
236
            ])),
 
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,
 
244
            "Radio item &1",
 
245
            [{help,  "Radio item"}]),
 
246
    wxMenu:appendRadioItem(SubMenuMenu, 
 
247
            ?menuID_SUBMENU_RADIO_2,
 
248
            "Radio item &2",
 
249
            [{help,  "Radio item"}]),
 
250
    wxMenu:appendRadioItem(SubMenuMenu, 
 
251
            ?menuID_SUBMENU_RADIO_3,
 
252
            "Radio item &3",
 
253
            [{help,  "Radio item"}]),
 
254
    SubMenuMenu.
 
255
 
 
256
 
 
257
%%    
 
258
%%    
 
259
%%    
 
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"}
 
266
            ])),
 
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"}
 
271
            ])),
 
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"}
 
276
            ])),
 
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"}
 
281
            ])),
 
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}
 
288
            ])),
 
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}
 
294
            ])),   
 
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"}
 
300
            ])),
 
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"}
 
305
            ])),
 
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"}
 
311
            ])),
 
312
    MenuMenu.
 
313
 
 
314
 
 
315
%%    
 
316
%%    
 
317
%%    
 
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"}
 
324
            ])),
 
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"),
 
332
    TestMenu.
 
333
 
 
334
%%    
 
335
%%    
 
336
%%    
 
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"}
 
346
            ])),
 
347
    HelpMenu.
 
348
 
 
349
%%    
 
350
%%    
 
351
%%    
 
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         }])),
 
405
 
 
406
    StockSubMenu.
 
407
 
 
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"),
 
413
    DummyMenu.
 
414
 
 
415
loop(State) ->
 
416
    receive 
 
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); 
 
423
            
 
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),
 
427
            loop(State1);
 
428
        Msg ->
 
429
            io:format("Got ~p ~n", [Msg]),
 
430
            loop(State)
 
431
    after 5000 ->
 
432
            loop(State)
 
433
    end.
 
434
    
 
435
 
 
436
onMenuAction(#wx{id=?menuID_FILE_CLEAR_LOG, obj=Frame}, #state{} = State) ->
 
437
    wxTextCtrl:clear(findLogger(Frame)), 
 
438
    State;
 
439
    
 
440
    
 
441
onMenuAction(#wx{id=?menuID_MENUBAR_APPEND, obj=Frame},  #state{} = State) ->
 
442
    MenuBar = wxFrame:getMenuBar(Frame),
 
443
    wxMenuBar:append(MenuBar, create_dummy_menu(), "DummyMenu"),
 
444
    State;
 
445
 
 
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"),
 
449
    State;
 
450
 
 
451
onMenuAction(#wx{id=?menuID_MENUBAR_DELETE, obj=Frame},  #state{} = State) ->
 
452
    MenuBar = wxFrame:getMenuBar(Frame),
 
453
    Count = wxMenuBar:getMenuCount(MenuBar),
 
454
    if
 
455
        (Count > 2) ->
 
456
            wxMenuBar:remove(MenuBar, Count -1);
 
457
        true ->
 
458
            logMessage(Frame, "Cannot delete any more menus~n")
 
459
    end,
 
460
    State;
 
461
 
 
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),
 
465
    if 
 
466
        FileMenu =:= undefined ->    
 
467
            Menu = wxMenuBar:remove(MenuBar, 0), 
 
468
            State#state{fileMenu=Menu};
 
469
        true ->
 
470
            wxMenuBar:insert(MenuBar, 0, FileMenu, "&File"),
 
471
            State#state{fileMenu=undefined}
 
472
    end;
 
473
        
 
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),
 
479
    
 
480
    Count = wxMenuBar:getMenuCount(MenuBar),
 
481
    wxMenuBar:enableTop(MenuBar, (Count - 1), Enable), 
 
482
    State;
 
483
 
 
484
 
 
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]),
 
491
    State;
 
492
    
 
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, 
 
499
            "Enter new label: ", 
 
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),
 
505
    State;
 
506
    
 
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),
 
518
    if
 
519
        (Len > 0) ->
 
520
            Index = wxMenuBar:findMenu(MenuBar, Label),
 
521
            if 
 
522
                (Index =:= ?wxNOT_FOUND) ->
 
523
                    logMessage(Frame, "Warning: No menu with label ~p", [Label]);
 
524
                true ->
 
525
                    logMessage(Frame, "Menu ~p has label ~p", [Index, Label])
 
526
            end;
 
527
        true -> true
 
528
    end,
 
529
            
 
530
    State;
 
531
   
 
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}
 
542
            ])),   
 
543
 
 
544
    State;
 
545
 
 
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()}
 
556
            ])),   
 
557
 
 
558
    State;
 
559
 
 
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]),
 
562
    State;
 
563
 
 
564
onMenuAction( #wx{id=?menuID_HELP_ABOUT=Id, obj=Frame},  #state{} = State) ->
 
565
    showDialog(Id,  Frame),
 
566
    State;
 
567
 
 
568
onMenuAction( #wx{obj=Frame} = Wx,  State) ->
 
569
    logMessage(Frame, "unimplemented menu item event ~p ~n", [Wx]),
 
570
    State.
 
571
    
 
572
logMessage(Frame, Msg) ->
 
573
    logMessage(Frame, Msg, []).
 
574
    
 
575
logMessage(Frame, Msg, ArgList) ->
 
576
    String  = lists:flatten(io_lib:format(Msg, ArgList)),
 
577
    
 
578
    wxTextCtrl:appendText(findLogger(Frame), String).
 
579
    
 
580
findLogger(Frame) ->
 
581
    LogWin = wxWindow:findWindowById(?wID_LOG_TEXT_CTRL, [{parent, Frame}]),
 
582
    wx:typeCast(LogWin, wxTextCtrl).
 
583
    
 
584
   
 
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"
 
588
                       "running under ~p.",
 
589
                       [wx_misc:getOsDescription()])),
 
590
    MessageDialog = wxMessageDialog:new(Frame,
 
591
                             String,
 
592
                             [{style, ?wxOK bor ?wxICON_INFORMATION}, 
 
593
                              {caption, "About wxErlang minimal sample"}]),
 
594
 
 
595
    wxDialog:showModal(MessageDialog),
 
596
    wxDialog:destroy(MessageDialog);
 
597
    
 
598
showDialog(Id,  Frame) ->
 
599
    String = lists:flatten(io_lib:format("Unimplemented Dialog ~p", [Id])),
 
600
    MessageDialog = wxMessageDialog:new(Frame,
 
601
                             String,
 
602
                             [{style, ?wxOK bor ?wxICON_INFORMATION}, 
 
603
                              {caption, "wxErlang minimal sample"}]),
 
604
 
 
605
    wxDialog:showModal(MessageDialog),
 
606
    wxDialog:destroy(MessageDialog).
 
607