aboutsummaryrefslogtreecommitdiffstats
path: root/lib/wx/examples/simple
diff options
context:
space:
mode:
authorErlang/OTP <[email protected]>2009-11-20 14:54:40 +0000
committerErlang/OTP <[email protected]>2009-11-20 14:54:40 +0000
commit84adefa331c4159d432d22840663c38f155cd4c1 (patch)
treebff9a9c66adda4df2106dfd0e5c053ab182a12bd /lib/wx/examples/simple
downloadotp-84adefa331c4159d432d22840663c38f155cd4c1.tar.gz
otp-84adefa331c4159d432d22840663c38f155cd4c1.tar.bz2
otp-84adefa331c4159d432d22840663c38f155cd4c1.zip
The R13B03 release.OTP_R13B03
Diffstat (limited to 'lib/wx/examples/simple')
-rw-r--r--lib/wx/examples/simple/Makefile65
-rw-r--r--lib/wx/examples/simple/copy.xpm44
-rwxr-xr-xlib/wx/examples/simple/hello.erl69
-rw-r--r--lib/wx/examples/simple/hello2.erl81
-rwxr-xr-xlib/wx/examples/simple/menu.erl607
-rwxr-xr-xlib/wx/examples/simple/minimal.erl109
-rwxr-xr-xlib/wx/examples/simple/sample.xpm44
7 files changed, 1019 insertions, 0 deletions
diff --git a/lib/wx/examples/simple/Makefile b/lib/wx/examples/simple/Makefile
new file mode 100644
index 0000000000..41f0b46eb1
--- /dev/null
+++ b/lib/wx/examples/simple/Makefile
@@ -0,0 +1,65 @@
+#
+# %CopyrightBegin%
+#
+# Copyright Ericsson AB 2009. All Rights Reserved.
+#
+# The contents of this file are subject to the Erlang Public License,
+# Version 1.1, (the "License"); you may not use this file except in
+# compliance with the License. You should have received a copy of the
+# Erlang Public License along with this software. If not, it can be
+# retrieved online at http://www.erlang.org/.
+#
+# Software distributed under the License is distributed on an "AS IS"
+# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+# the License for the specific language governing rights and limitations
+# under the License.
+#
+# %CopyrightEnd%
+#
+
+include ../../vsn.mk
+include ../../config.mk
+
+TOPDIR = ../..
+SRC = .
+BIN = .
+ERLINC = $(TOPDIR)/include
+ERLC = erlc
+TESTMODS = hello hello2 minimal menu
+TESTTARGETS = $(TESTMODS:%=%.beam)
+TESTSRC = $(TESTMODS:%=%.erl)
+
+# Targets
+opt debug: $(TESTTARGETS)
+clean:
+ rm -f $(TESTTARGETS)
+ rm -f *~ core erl_crash.dump
+
+docs:
+
+run: opt
+ erl -smp -detached -pa $(TOPDIR)/ebin -s hello
+
+ifneq ($(INSIDE_ERLSRC),true)
+
+%.beam: %.erl
+ $(ERLC) -W -I$(ERLINC) -bbeam -o$(BIN) $<
+
+else
+EXRELSYSDIR = $(RELSYSDIR)/examples/simple
+include $(ERL_TOP)/make/otp_release_targets.mk
+
+docs:
+
+release_spec:
+ $(INSTALL_DIR) $(EXRELSYSDIR)
+ $(INSTALL_DATA) $(TESTSRC) $(EXRELSYSDIR)
+ $(INSTALL_DATA) copy.xpm sample.xpm $(TESTTARGETS) $(EXRELSYSDIR)
+
+release_tests_spec:
+
+release_docs_spec:
+
+endif
+
+
diff --git a/lib/wx/examples/simple/copy.xpm b/lib/wx/examples/simple/copy.xpm
new file mode 100644
index 0000000000..b14b414834
--- /dev/null
+++ b/lib/wx/examples/simple/copy.xpm
@@ -0,0 +1,44 @@
+/* XPM */
+static const char * copy_xpm[] = {
+/* columns rows colors chars-per-pixel */
+"16 15 23 1",
+"+ c #769CDA",
+": c #DCE6F6",
+"X c #3365B7",
+"* c #FFFFFF",
+"o c #9AB6E4",
+"< c #EAF0FA",
+"# c #B1C7EB",
+". c #6992D7",
+"3 c #F7F9FD",
+", c #F0F5FC",
+"$ c #A8C0E8",
+" c None",
+"- c #FDFEFF",
+"& c #C4D5F0",
+"1 c #E2EAF8",
+"O c #89A9DF",
+"= c #D2DFF4",
+"4 c #FAFCFE",
+"2 c #F5F8FD",
+"; c #DFE8F7",
+"% c #B8CCEC",
+"> c #E5EDF9",
+"@ c #648FD6",
+/* pixels */
+" .....XX ",
+" .oO+@X#X ",
+" .$oO+X##X ",
+" .%$o........ ",
+" .&%$.*=&#o.-. ",
+" .=&%.*;=&#.--. ",
+" .:=&.*>;=&.... ",
+" .>:=.*,>;=&#o. ",
+" .<1:.*2,>:=&#. ",
+" .2<1.*32,>:=&. ",
+" .32<.*432,>:=. ",
+" .32<.*-432,>:. ",
+" .....**-432,>. ",
+" .***-432,. ",
+" .......... "
+};
diff --git a/lib/wx/examples/simple/hello.erl b/lib/wx/examples/simple/hello.erl
new file mode 100755
index 0000000000..dc845ddfbb
--- /dev/null
+++ b/lib/wx/examples/simple/hello.erl
@@ -0,0 +1,69 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2009. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+%%%-------------------------------------------------------------------
+%%% File : hello.erl
+%%% Author : Matthew Harrison <harryhuk at users.sourceforge.net>
+%%% Description : _really_ minimal example of a wxerlang app
+%%%
+%%% Created : 18 Sep 2008 by Matthew Harrison <harryhuk at users.sourceforge.net>
+%%%-------------------------------------------------------------------
+-module(hello).
+
+-include_lib("wx/include/wx.hrl").
+
+-export([start/0]).
+-compile(export_all).
+
+start() ->
+ Wx = wx:new(),
+ Frame = wx:batch(fun() -> create_window(Wx) end),
+ wxWindow:show(Frame),
+ loop(Frame),
+ wx:destroy(),
+ ok.
+
+create_window(Wx) ->
+ Frame = wxFrame:new(Wx,
+ -1, % window id
+ "Hello World", % window title
+ [{size, {600,400}}]),
+
+
+ wxFrame:createStatusBar(Frame,[]),
+
+ %% if we don't handle this ourselves, wxwidgets will close the window
+ %% when the user clicks the frame's close button, but the event loop still runs
+ wxFrame:connect(Frame, close_window),
+
+ ok = wxFrame:setStatusText(Frame, "Hello World!",[]),
+ Frame.
+
+loop(Frame) ->
+ receive
+ #wx{event=#wxClose{}} ->
+ io:format("~p Closing window ~n",[self()]),
+ ok = wxFrame:setStatusText(Frame, "Closing...",[]),
+ wxWindow:destroy(Frame),
+ ok;
+ Msg ->
+ io:format("Got ~p ~n", [Msg]),
+ loop(Frame)
+ end.
+
+
diff --git a/lib/wx/examples/simple/hello2.erl b/lib/wx/examples/simple/hello2.erl
new file mode 100644
index 0000000000..af825f2e3c
--- /dev/null
+++ b/lib/wx/examples/simple/hello2.erl
@@ -0,0 +1,81 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2009. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+%%%-------------------------------------------------------------------
+%%% File : hello.erl
+%%% Author : Matthew Harrison <harryhuk at users.sourceforge.net>
+%%% Description : _really_ minimal example of a wxerlang app
+%%% implemented with wx_object behaviour
+%%%
+%%% Created : 18 Sep 2008 by Matthew Harrison <harryhuk at users.sourceforge.net>
+%%% Dan rewrote it to show wx_object behaviour
+%%%-------------------------------------------------------------------
+-module(hello2).
+-include_lib("wx/include/wx.hrl").
+
+-export([start/0]).
+-compile(export_all).
+
+-behavoiur(wx_object).
+
+-record(state, {win}).
+
+start() ->
+ wx_object:start_link(?MODULE, [], []).
+
+%% Init is called in the new process.
+init([]) ->
+ wx:new(),
+ Frame = wxFrame:new(wx:null(),
+ -1, % window id
+ "Hello World", % window title
+ [{size, {600,400}}]),
+
+ wxFrame:createStatusBar(Frame,[]),
+
+ %% if we don't handle this ourselves, wxwidgets will close the window
+ %% when the user clicks the frame's close button, but the event loop still runs
+ wxFrame:connect(Frame, close_window),
+
+ ok = wxFrame:setStatusText(Frame, "Hello World!",[]),
+ wxWindow:show(Frame),
+ {Frame, #state{win=Frame}}.
+
+
+%% Handled as in normal gen_server callbacks
+handle_info(Msg, State) ->
+ io:format("Got Info ~p~n",[Msg]),
+ {noreply,State}.
+
+handle_call(Msg, _From, State) ->
+ io:format("Got Call ~p~n",[Msg]),
+ {reply,ok,State}.
+
+%% Async Events are handled in handle_event as in handle_info
+handle_event(#wx{event=#wxClose{}}, State = #state{win=Frame}) ->
+ io:format("~p Closing window ~n",[self()]),
+ ok = wxFrame:setStatusText(Frame, "Closing...",[]),
+ wxWindow:destroy(Frame),
+ {stop, normal, State}.
+
+code_change(_, _, State) ->
+ {stop, not_yet_implemented, State}.
+
+terminate(_Reason, _State) ->
+ ok.
+
diff --git a/lib/wx/examples/simple/menu.erl b/lib/wx/examples/simple/menu.erl
new file mode 100755
index 0000000000..d573fcf13a
--- /dev/null
+++ b/lib/wx/examples/simple/menu.erl
@@ -0,0 +1,607 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2009. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+%%%-------------------------------------------------------------------
+%%% File : menus.erl
+%%% Author : Matthew Harrison <harryhuk at users.sourceforge.net>
+%%% Description : Test of menus
+%%%
+%%% Created : 18 Sep 2008 by Matthew Harrison <harryhuk at users.sourceforge.net>
+%%%-------------------------------------------------------------------
+-module(menu).
+
+-include_lib("wx/include/wx.hrl").
+
+-export([start/0]).
+-compile(export_all).
+
+%%%Lots of IDs to declare!
+-define(menuID_FILE_QUIT, ?wxID_EXIT).
+-define(menuID_FILE_CLEAR_LOG, 100).
+
+-define(menuID_MENUBAR_TOGGLE, 200).
+-define(menuID_MENUBAR_APPEND, 201).
+-define(menuID_MENUBAR_INSERT, 202).
+-define(menuID_MENUBAR_DELETE, 203).
+-define(menuID_MENUBAR_ENABLE, 204).
+-define(menuID_MENUBAR_GET_LABEL, 206).
+-define(menuID_MENUBAR_SET_LABEL, 207).
+-define(menuID_MENUBAR_FIND_MENU, 208).
+
+-define(menuID_MENU_APPEND, 300).
+-define(menuID_MENU_APPEND_SUB, 301).
+-define(menuID_MENU_INSERT, 302).
+-define(menuID_MENU_DELETE, 303).
+-define(menuID_MENU_ENABLE, 304).
+-define(menuID_MENU_CHECK, 305).
+-define(menuID_MENU_GET_LABEL, 306).
+-define(menuID_MENU_SET_LABEL, 307).
+-define(menuID_MENU_GET_INFO, 308).
+-define(menuID_MENU_FIND_ITEM, 309).
+
+-define(menuID_TEST_NORMAL, 400).
+-define(menuID_TEST_CHECK, 401).
+-define(menuID_TEST_RADIO_1, 402).
+-define(menuID_TEST_RADIO_2, 403).
+-define(menuID_TEST_RADIO_3, 404).
+
+-define(menuID_SUBMENU, 450).
+-define(menuID_SUBMENU_NORMAL, 451).
+-define(menuID_SUBMENU_CHECK, 452).
+-define(menuID_SUBMENU_RADIO_1, 453).
+-define(menuID_SUBMENU_RADIO_2, 454).
+-define(menuID_SUBMENU_RADIO_3, 455).
+
+-define(menuID_DUMMY_FIRST, 500).
+-define(menuID_DUMMY_SECOND, 501).
+-define(menuID_DUMMY_THIRD, 502).
+-define(menuID_DUMMY_FOURTH, 503).
+-define(menuID_DUMMY_LAST, 504).
+
+-define(menuID_HELP_ABOUT, ?wxID_ABOUT).
+
+-define(menuID_POPUP_TO_BE_DELETED, 2000).
+-define(menuID_POPUP_TO_BE_GREYED, 2001).
+-define(menuID_POPUP_TO_BE_CHECKED, 2002).
+-define(menuID_POPUP_TO_BE_SUBMENU, 2003).
+
+-define(wID_LOG_TEXT_CTRL, 3000).
+
+-record(state, {dummyMenuCount=0, fileMenu=undefined}).
+
+%%
+%%
+%%
+start() ->
+ Wx = wx:new(),
+ Frame = wx:batch(fun() -> create_frame(Wx) end),
+ wxWindow:show(Frame),
+
+ State = #state{},
+
+ loop(State),
+ ok.
+
+
+%%
+%%
+%%
+create_frame(Wx) ->
+ Frame = wxFrame:new(Wx, -1, "wxErlang menu sample", [{size, {600,400}}]),
+
+ Path = filename:dirname(code:which(?MODULE)),
+ wxFrame:setIcon(Frame, wxIcon:new(filename:join(Path,"sample.xpm"))),
+
+ wxFrame:createStatusBar(Frame,[]),
+ wxFrame:connect(Frame, close_window),
+
+ FileMenu = create_file_menu(),
+ MenuBarMenu = create_menubar_menu(),
+ MenuMenu = create_menu_menu(),
+ TestMenu = create_test_menu(),
+ HelpMenu = create_help_menu(),
+
+ MenuBar = wxMenuBar:new(?wxMB_DOCKABLE),
+
+
+ wxMenuBar:append(MenuBar, FileMenu, "&File"),
+ wxMenuBar:append(MenuBar, MenuBarMenu, "Menu&bar"),
+ wxMenuBar:append(MenuBar, MenuMenu, "&Menu"),
+ wxMenuBar:append(MenuBar, TestMenu, "&Test"),
+ wxMenuBar:append(MenuBar, HelpMenu, "&Help"),
+
+ wxFrame:setMenuBar(Frame, MenuBar),
+
+ LogTextCtrl = wxTextCtrl:new(Frame, ?wID_LOG_TEXT_CTRL,
+ [{value, ""},
+ %{pos, ?wxDefaultPosition},
+ %{size, ?wxDefaultSize},
+ {style, ?wxTE_MULTILINE}]),
+ wxTextCtrl:setEditable(LogTextCtrl, false),
+
+ ok = wxFrame:setStatusText(Frame, "Welcome to wxErlang menu sample",[]),
+
+ ok = wxFrame:connect(Frame, command_menu_selected),
+
+ String = "Brief explanations:~n"
+ "the commands from the \"Menu\" menu append/insert/delete items to/from the last menu.~n"
+ "The commands from \"Menubar\" menu work with the menubar itself.~n~n",
+ %% "Right click the band below to test popup menus.~n",
+ logMessage(Frame, String),
+ Frame.
+
+%%
+%%
+%%
+create_file_menu() ->
+ FileMenu = wxMenu:new(),
+
+ wxMenu:append(FileMenu, wxMenuItem:new([
+ {id, ?menuID_SUBMENU},
+ {subMenu, create_stock_menu()},
+ {text, "&Standard items demo"}
+ ])),
+ ClearLogBitmap = wxBitmap:new("copy.xpm"),
+ ClearLogItem = wxMenuItem:new([
+ {id, ?menuID_FILE_CLEAR_LOG},
+ {text, "Clear &log\tCtrl-L"} %% note mnemonic and accelerator
+ ]),
+ wxMenuItem:setBitmap(ClearLogItem, ClearLogBitmap),
+
+ wxMenu:append(FileMenu, ClearLogItem ),
+ wxMenu:appendSeparator(FileMenu),
+ wxMenu:append(FileMenu, wxMenuItem:new([
+ {id, ?menuID_FILE_QUIT} %,
+ %{text, "E&xit\tAlt-X"}
+ ])),
+ FileMenu.
+
+%%
+%%
+%%
+create_menubar_menu() ->
+ MenuBarMenu = wxMenu:new(),
+ wxMenu:append(MenuBarMenu, wxMenuItem:new([
+ {id, ?menuID_MENUBAR_APPEND},
+ {text, "&Append menu\tCtrl-A"},
+ {help, "Append a menu to the menubar"}
+ ])),
+ wxMenu:append(MenuBarMenu, wxMenuItem:new([
+ {id, ?menuID_MENUBAR_INSERT},
+ {text, "&Insert menu\tCtrl-I"},
+ {help, "Insert a menu into the menubar"}
+ ])),
+ wxMenu:append(MenuBarMenu, wxMenuItem:new([
+ {id, ?menuID_MENUBAR_DELETE},
+ {text, "&Delete menu\tCtrl-D"},
+ {help, "Insert a menu into the menubar"}
+ ])),
+ wxMenu:append(MenuBarMenu, wxMenuItem:new([
+ {id, ?menuID_MENUBAR_TOGGLE},
+ {text, "&Toggle menu\tCtrl-T"},
+ {help, "Toggle the first menu in the menubar"},
+ {kind, ?wxITEM_CHECK}
+ ])),
+ wxMenu:appendSeparator(MenuBarMenu), %% --------------------------
+ wxMenu:append(MenuBarMenu, wxMenuItem:new([
+ {id, ?menuID_MENUBAR_ENABLE},
+ {text, "&Enable menu\tCtrl-E"},
+ {help, "Enable or disable the last menu"},
+ {kind, ?wxITEM_CHECK}
+ ])),
+ wxMenu:appendSeparator(MenuBarMenu), %% --------------------------
+ wxMenu:append(MenuBarMenu, wxMenuItem:new([
+ {id, ?menuID_MENUBAR_GET_LABEL},
+ {text, "&Get menu label\tCtrl-G"},
+ {help, "Get the label of the last menu"}
+ ])),
+ wxMenu:append(MenuBarMenu, wxMenuItem:new([
+ {id, ?menuID_MENUBAR_SET_LABEL},
+ {text, "&Set menu label\tCtrl-S"},
+ {help, "Change the label of the last menu"}
+ ])),
+ wxMenu:appendSeparator(MenuBarMenu), %% --------------------------
+ wxMenu:append(MenuBarMenu, wxMenuItem:new([
+ {id, ?menuID_MENUBAR_FIND_MENU},
+ {text, "&Find menu from label\tCtrl-F"},
+ {help, "Find a menu by searching for its label"}
+ ])),
+ MenuBarMenu.
+
+
+%%
+%%
+%%
+create_submenu_menu() ->
+ SubMenuMenu = wxMenu:new(),
+ wxMenu:append(SubMenuMenu, wxMenuItem:new([
+ {id, ?menuID_SUBMENU_NORMAL},
+ {text, "&Normal submenu item"},
+ {help, "Disabled submenu item"}
+ ])),
+ %% note different way of adding check menu item
+ wxMenu:appendCheckItem(SubMenuMenu,
+ ?menuID_SUBMENU_CHECK,
+ "&Check submenu item",
+ [{help, "Check submenu item"}]),
+ wxMenu:appendRadioItem(SubMenuMenu,
+ ?menuID_SUBMENU_RADIO_1,
+ "Radio item &1",
+ [{help, "Radio item"}]),
+ wxMenu:appendRadioItem(SubMenuMenu,
+ ?menuID_SUBMENU_RADIO_2,
+ "Radio item &2",
+ [{help, "Radio item"}]),
+ wxMenu:appendRadioItem(SubMenuMenu,
+ ?menuID_SUBMENU_RADIO_3,
+ "Radio item &3",
+ [{help, "Radio item"}]),
+ SubMenuMenu.
+
+
+%%
+%%
+%%
+create_menu_menu() ->
+ MenuMenu = wxMenu:new(),
+ wxMenu:append(MenuMenu, wxMenuItem:new([
+ {id, ?menuID_MENU_APPEND},
+ {text, "&Append menu item\tAlt-A"},
+ {help, "Append a menu item to the last menu"}
+ ])),
+ wxMenu:append(MenuMenu, wxMenuItem:new([
+ {id, ?menuID_MENU_APPEND_SUB},
+ {text, "&Append sub menu\tAlt-S"},
+ {help, "Append a sub menu to the last menu"}
+ ])),
+ wxMenu:append(MenuMenu, wxMenuItem:new([
+ {id, ?menuID_MENU_INSERT},
+ {text, "&Insert menu item\tAlt-I"},
+ {help, "Insert a menu item in head of the last menu"}
+ ])),
+ wxMenu:append(MenuMenu, wxMenuItem:new([
+ {id, ?menuID_MENU_DELETE},
+ {text, "&Delete menu item\tAlt-D"},
+ {help, "Delete the last menu item from the last menu"}
+ ])),
+ wxMenu:appendSeparator(MenuMenu), %% --------------------------
+ wxMenu:append(MenuMenu, wxMenuItem:new([
+ {id, ?menuID_MENU_ENABLE},
+ {text, "&Enable menu item\tAlt-E"},
+ {help, "Enable or disable the last menu item"},
+ {kind, ?wxITEM_CHECK}
+ ])),
+ wxMenu:append(MenuMenu, wxMenuItem:new([
+ {id, ?menuID_MENU_CHECK},
+ {text, "&Check menu item\tAlt-C"},
+ {help, "Check or uncheck the last menu item"},
+ {kind, ?wxITEM_CHECK}
+ ])),
+ wxMenu:appendSeparator(MenuMenu), %% --------------------------
+ wxMenu:append(MenuMenu, wxMenuItem:new([
+ {id, ?menuID_MENU_GET_INFO},
+ {text, "Get menu item in&fo\tAlt-F"},
+ {help, "Show the state of the last menu item"}
+ ])),
+ wxMenu:append(MenuMenu, wxMenuItem:new([
+ {id, ?menuID_MENU_SET_LABEL},
+ {text, "&Set menu label\tCtrl-S"},
+ {help, "Change the label of the last menu"}
+ ])),
+ wxMenu:appendSeparator(MenuMenu), %% --------------------------
+ wxMenu:append(MenuMenu, wxMenuItem:new([
+ {id, ?menuID_MENU_FIND_ITEM},
+ {text, "Find menu item from label"},
+ {help, "Find a menu item by searching for its label"}
+ ])),
+ MenuMenu.
+
+
+%%
+%%
+%%
+create_test_menu() ->
+ TestMenu = wxMenu:new(),
+ wxMenu:append(TestMenu, wxMenuItem:new([
+ {id, ?menuID_TEST_NORMAL},
+ {text, "&Normal submenu item"},
+ {help, "Disabled submenu item"}
+ ])),
+ wxMenu:appendSeparator(TestMenu), %% --------------------------
+ %% note different way of adding check menu item
+ wxMenu:appendCheckItem(TestMenu, ?menuID_TEST_CHECK, "&Check item"),
+ wxMenu:appendSeparator(TestMenu), %% --------------------------
+ wxMenu:appendRadioItem(TestMenu, ?menuID_TEST_RADIO_1, "Radio item &1"),
+ wxMenu:appendRadioItem(TestMenu, ?menuID_TEST_RADIO_2, "Radio item &2"),
+ wxMenu:appendRadioItem(TestMenu, ?menuID_TEST_RADIO_3, "Radio item &3"),
+ TestMenu.
+
+%%
+%%
+%%
+create_help_menu() ->
+ HelpMenu = wxMenu:new(),
+ % unlike wxwidgets the stock menu items still need text to be given,
+ % although help text does appear
+ % Note the keybord accelerator
+ wxMenu:append(HelpMenu, wxMenuItem:new([
+ {id, ?menuID_HELP_ABOUT},
+ %{text, "&About\tF1"},
+ {help, "About menu sample"}
+ ])),
+ HelpMenu.
+
+%%
+%%
+%%
+create_stock_menu() ->
+ % unlike wxwidgets the stock menu items still need text to be given,
+ % although help text does appear
+ StockSubMenu = wxMenu:new(),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_ADD }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_APPLY }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_BOLD }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_CANCEL }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_CLEAR }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_CLOSE }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_COPY }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_CUT }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_DELETE }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_FIND }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_REPLACE }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_BACKWARD }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_DOWN }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_FORWARD }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_UP }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_HELP }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_HOME }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_INDENT }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_INDEX }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_ITALIC }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_JUSTIFY_CENTER }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_JUSTIFY_FILL }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_JUSTIFY_LEFT }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_JUSTIFY_RIGHT }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_NEW }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_NO }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_OK }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_OPEN }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_PASTE }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_PREFERENCES }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_PRINT }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_PREVIEW }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_PROPERTIES }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_EXIT }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_REDO }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_REFRESH }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_REMOVE }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_REVERT_TO_SAVED }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_SAVE }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_SAVEAS }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_STOP }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_UNDELETE }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_UNDERLINE }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_UNDO }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_UNINDENT }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_YES }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_ZOOM_100 }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_ZOOM_FIT }])),
+ wxMenu:append(StockSubMenu, wxMenuItem:new([{id, ?wxID_ZOOM_OUT }])),
+
+ StockSubMenu.
+
+create_dummy_menu() ->
+ DummyMenu = wxMenu:new(),
+ wxMenu:append(DummyMenu, ?menuID_DUMMY_FIRST, "&First item\tCtrl-F1"),
+ wxMenu:appendSeparator(DummyMenu), %% --------------------------
+ wxMenu:append(DummyMenu, ?menuID_DUMMY_SECOND, "&Second item\tCtrl-F2"),
+ DummyMenu.
+
+loop(State) ->
+ receive
+ #wx{event=#wxClose{}, obj=Frame} ->
+ io:format("~p Closing window ~n",[self()]),
+ wxWindow:destroy(Frame); %onClose(Frame);
+ #wx{id=?menuID_FILE_QUIT, obj=Frame, event=#wxCommand{type=command_menu_selected}} ->
+ io:format("~p Closing window ~n",[self()]),
+ wxWindow:destroy(Frame); %onClose(Frame);
+
+ #wx{obj=Frame, userData=UserData, event=#wxCommand{type=command_menu_selected}} = Wx->
+ logMessage(Frame, "got wx:~p ud:~p~n", [Wx, UserData]),
+ State1 = onMenuAction(Wx, State),
+ loop(State1);
+ Msg ->
+ io:format("Got ~p ~n", [Msg]),
+ loop(State)
+ after 5000 ->
+ loop(State)
+ end.
+
+
+onMenuAction(#wx{id=?menuID_FILE_CLEAR_LOG, obj=Frame}, #state{} = State) ->
+ wxTextCtrl:clear(findLogger(Frame)),
+ State;
+
+
+onMenuAction(#wx{id=?menuID_MENUBAR_APPEND, obj=Frame}, #state{} = State) ->
+ MenuBar = wxFrame:getMenuBar(Frame),
+ wxMenuBar:append(MenuBar, create_dummy_menu(), "DummyMenu"),
+ State;
+
+onMenuAction(#wx{id=?menuID_MENUBAR_INSERT, obj=Frame}, #state{} = State) ->
+ MenuBar = wxFrame:getMenuBar(Frame),
+ wxMenuBar:insert(MenuBar, 0, create_dummy_menu(), "DummyMenu"),
+ State;
+
+onMenuAction(#wx{id=?menuID_MENUBAR_DELETE, obj=Frame}, #state{} = State) ->
+ MenuBar = wxFrame:getMenuBar(Frame),
+ Count = wxMenuBar:getMenuCount(MenuBar),
+ if
+ (Count > 2) ->
+ wxMenuBar:remove(MenuBar, Count -1);
+ true ->
+ logMessage(Frame, "Cannot delete any more menus~n")
+ end,
+ State;
+
+onMenuAction(#wx{id=?menuID_MENUBAR_TOGGLE, obj=Frame}, #state{fileMenu=FileMenu} = State) ->
+ logMessage(Frame, "onMenubarToggle ~p ~n", [FileMenu]),
+ MenuBar = wxFrame:getMenuBar(Frame),
+ if
+ FileMenu =:= undefined ->
+ Menu = wxMenuBar:remove(MenuBar, 0),
+ State#state{fileMenu=Menu};
+ true ->
+ wxMenuBar:insert(MenuBar, 0, FileMenu, "&File"),
+ State#state{fileMenu=undefined}
+ end;
+
+onMenuAction( #wx{id=?menuID_MENUBAR_ENABLE=Id, obj=Frame}, #state{} = State) ->
+%% logMessage(Frame, "onMenubarEnable ~n"),
+ MenuBar = wxFrame:getMenuBar(Frame),
+ MenuItem = wxMenuBar:findItem(MenuBar, Id),
+ Enable = (not wxMenuItem:isCheckable(MenuItem)) orelse wxMenuItem:isChecked(MenuItem),
+
+ Count = wxMenuBar:getMenuCount(MenuBar),
+ wxMenuBar:enableTop(MenuBar, (Count - 1), Enable),
+ State;
+
+
+onMenuAction( #wx{id=?menuID_MENUBAR_GET_LABEL, obj=Frame}, #state{} = State) ->
+ logMessage(Frame, "onMenubarGetLabel ~n"),
+ MenuBar = wxFrame:getMenuBar(Frame),
+ Count = wxMenuBar:getMenuCount(MenuBar),
+ Label = wxMenuBar:getLabelTop(MenuBar, (Count - 1)),
+ logMessage(Frame, "The label of the last menu item is ~p", [Label]),
+ State;
+
+onMenuAction( #wx{id=?menuID_MENUBAR_SET_LABEL, obj=Frame}, #state{} = State) ->
+%% logMessage(Frame, "onMenubarGetLabel ~n"),
+ MenuBar = wxFrame:getMenuBar(Frame),
+ Count = wxMenuBar:getMenuCount(MenuBar),
+ Label = wxMenuBar:getLabelTop(MenuBar, (Count - 1)),
+ TextDialog = wxTextEntryDialog:new(Frame,
+ "Enter new label: ",
+ [{caption, "Change last menu text"}, {value, Label}]),
+ wxDialog:showModal(TextDialog),
+ NewLabel = wxTextEntryDialog:getValue(TextDialog),
+ wxMenuBar:setLabelTop(MenuBar, (Count - 1), NewLabel),
+ wxDialog:destroy(TextDialog),
+ State;
+
+onMenuAction( #wx{id=?menuID_MENUBAR_FIND_MENU, obj=Frame}, #state{} = State) ->
+%% logMessage(Frame, "onMenubarFindMenu ~n"),
+ MenuBar = wxFrame:getMenuBar(Frame),
+ _Count = wxMenuBar:getMenuCount(MenuBar),
+% Label = wxMenuBar:getLabelTop(MenuBar, (Count - 1)),
+ TextDialog = wxTextEntryDialog:new(Frame,
+ "Enter label to search for: ",
+ [{caption, "Find menu"}]),
+ wxDialog:showModal(TextDialog),
+ Label = wxTextEntryDialog:getValue(TextDialog),
+ Len = string:len(Label),
+ if
+ (Len > 0) ->
+ Index = wxMenuBar:findMenu(MenuBar, Label),
+ if
+ (Index =:= ?wxNOT_FOUND) ->
+ logMessage(Frame, "Warning: No menu with label ~p", [Label]);
+ true ->
+ logMessage(Frame, "Menu ~p has label ~p", [Index, Label])
+ end;
+ true -> true
+ end,
+
+ State;
+
+onMenuAction(#wx{id=?menuID_MENU_APPEND, obj=Frame}, #state{} = State) ->
+ MenuBar = wxFrame:getMenuBar(Frame),
+ Count = wxMenuBar:getMenuCount(MenuBar),
+ Menu = wxMenuBar:getMenu(MenuBar, Count - 1),
+ io:format("MenuBar ~p Menu ~p Count ~p ~n", [MenuBar, Menu, Count]),
+ wxMenu:appendSeparator(Menu),
+ wxMenu:append(Menu, wxMenuItem:new([
+ {id, ?menuID_DUMMY_THIRD},
+ {text, "&Third dummy item\tCtrl-F3"},
+ {kind, ?wxITEM_CHECK}
+ ])),
+
+ State;
+
+onMenuAction(#wx{id=?menuID_MENU_APPEND_SUB, obj=Frame}, #state{} = State) ->
+ MenuBar = wxFrame:getMenuBar(Frame),
+ Count = wxMenuBar:getMenuCount(MenuBar),
+ Menu = wxMenuBar:getMenu(MenuBar, Count - 2),
+ wxMenu:appendSeparator(Menu),
+ wxMenu:append(Menu, wxMenuItem:new([
+ {id, ?menuID_DUMMY_LAST},
+ {text, "&Dummy sub menu"},
+ {help, "Dummy sub menu help"},
+ {subMenu, create_dummy_menu()}
+ ])),
+
+ State;
+
+onMenuAction(#wx{id=Id, obj=Frame}, #state{}=State) when ((Id >= ?menuID_DUMMY_FIRST) and (Id =< ?menuID_DUMMY_LAST)) ->
+ logMessage(Frame, "Dummy item #~p ~n", [Id - ?menuID_DUMMY_FIRST + 1]),
+ State;
+
+onMenuAction( #wx{id=?menuID_HELP_ABOUT=Id, obj=Frame}, #state{} = State) ->
+ showDialog(Id, Frame),
+ State;
+
+onMenuAction( #wx{obj=Frame} = Wx, State) ->
+ logMessage(Frame, "unimplemented menu item event ~p ~n", [Wx]),
+ State.
+
+logMessage(Frame, Msg) ->
+ logMessage(Frame, Msg, []).
+
+logMessage(Frame, Msg, ArgList) ->
+ String = lists:flatten(io_lib:format(Msg, ArgList)),
+
+ wxTextCtrl:appendText(findLogger(Frame), String).
+
+findLogger(Frame) ->
+ LogWin = wxWindow:findWindowById(?wID_LOG_TEXT_CTRL, [{parent, Frame}]),
+ wx:typeCast(LogWin, wxTextCtrl).
+
+
+showDialog(?menuID_HELP_ABOUT, Frame) ->
+ String = lists:flatten(io_lib:format("Welcome to wxErlang 0.97.5.26!~n~n"
+ "This is the minimal wxErlang sample~n"
+ "running under ~p.",
+ [wx_misc:getOsDescription()])),
+ MessageDialog = wxMessageDialog:new(Frame,
+ String,
+ [{style, ?wxOK bor ?wxICON_INFORMATION},
+ {caption, "About wxErlang minimal sample"}]),
+
+ wxDialog:showModal(MessageDialog),
+ wxDialog:destroy(MessageDialog);
+
+showDialog(Id, Frame) ->
+ String = lists:flatten(io_lib:format("Unimplemented Dialog ~p", [Id])),
+ MessageDialog = wxMessageDialog:new(Frame,
+ String,
+ [{style, ?wxOK bor ?wxICON_INFORMATION},
+ {caption, "wxErlang minimal sample"}]),
+
+ wxDialog:showModal(MessageDialog),
+ wxDialog:destroy(MessageDialog).
+
diff --git a/lib/wx/examples/simple/minimal.erl b/lib/wx/examples/simple/minimal.erl
new file mode 100755
index 0000000000..dca4adc643
--- /dev/null
+++ b/lib/wx/examples/simple/minimal.erl
@@ -0,0 +1,109 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2009. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+%%%-------------------------------------------------------------------
+%%% File : minimal.erl
+%%% Author : Matthew Harrison <harryhuk at users.sourceforge.net>
+%%% Description : Minimal example of a wxerlang application
+%%%
+%%% Created : 18 Sep 2008 by Matthew Harrison <harryhuk at users.sourceforge.net>
+%%%-------------------------------------------------------------------
+-module(minimal).
+
+-include_lib("wx/include/wx.hrl").
+
+-export([start/0]).
+-compile(export_all).
+
+start() ->
+ Wx = wx:new(),
+ Frame = wx:batch(fun() -> create_window(Wx) end),
+ wxWindow:show(Frame),
+ loop(Frame),
+ wx:destroy(),
+ ok.
+
+create_window(Wx) ->
+ Frame = wxFrame:new(Wx, -1, "Minimal wxErlang App", [{size, {600,400}}]),
+
+ Path = filename:dirname(code:which(?MODULE)),
+ wxFrame:setIcon(Frame, wxIcon:new(filename:join(Path,"sample.xpm"))),
+
+ wxFrame:createStatusBar(Frame,[]),
+ wxFrame:connect(Frame, close_window),
+
+ MenuBar = wxMenuBar:new(),
+ FileM = wxMenu:new([]),
+ HelpM = wxMenu:new([]),
+
+ % unlike wxwidgets the stock menu items still need text to be given,
+ % although help text does appear
+ _QuitMenuItem = wxMenu:append(FileM, ?wxID_EXIT, "&Quit"),
+ % Note the keybord accelerator
+ _AboutMenuItem = wxMenu:append(HelpM, ?wxID_ABOUT, "&About...\tF1"),
+
+ wxMenu:appendSeparator(HelpM),
+ ContentsMenuItem = wxMenu:append(HelpM, ?wxID_HELP_CONTENTS, "&Contents"),
+ wxMenuItem:enable(ContentsMenuItem, [{enable, false}]),
+
+ ok = wxFrame:connect(Frame, command_menu_selected),
+
+ wxMenuBar:append(MenuBar, FileM, "&File"),
+ wxMenuBar:append(MenuBar, HelpM, "&Help"),
+ wxFrame:setMenuBar(Frame, MenuBar),
+
+ ok = wxFrame:setStatusText(Frame, "Welcome to wxErlang!",[]),
+ Frame.
+
+loop(Frame) ->
+ receive
+ #wx{event=#wxClose{}} ->
+ io:format("~p Closing window ~n",[self()]),
+ wxFrame:destroy(Frame),
+ ok;
+ #wx{id=?wxID_EXIT, event=#wxCommand{type=command_menu_selected}} ->
+ wxWindow:destroy(Frame),
+ ok;
+ #wx{id=?wxID_ABOUT, event=#wxCommand{type=command_menu_selected}} ->
+ io:format("Got about ~n", []),
+ dialog(?wxID_ABOUT, Frame),
+ loop(Frame);
+ Msg ->
+ io:format("Got ~p ~n", [Msg]),
+ loop(Frame)
+ after 1000 ->
+ io:fwrite("."),
+ loop(Frame)
+ end.
+
+dialog(?wxID_ABOUT, Frame) ->
+ Str = string:join(["Welcome to wxErlang.",
+ "This is the minimal wxErlang sample\n",
+ "running under ",
+ wx_misc:getOsDescription(),
+ "."],
+ ""),
+ MD = wxMessageDialog:new(Frame,
+ Str,
+ [{style, ?wxOK bor ?wxICON_INFORMATION},
+ {caption, "About wxErlang minimal sample"}]),
+
+ wxDialog:showModal(MD),
+ wxDialog:destroy(MD).
+
+
diff --git a/lib/wx/examples/simple/sample.xpm b/lib/wx/examples/simple/sample.xpm
new file mode 100755
index 0000000000..3263b15f8a
--- /dev/null
+++ b/lib/wx/examples/simple/sample.xpm
@@ -0,0 +1,44 @@
+/* XPM */
+static const char * sample_xpm[] = {
+/* columns rows colors chars-per-pixel */
+"32 32 6 1",
+" c black",
+". c navy",
+"X c red",
+"o c yellow",
+"O c gray100",
+"+ c None",
+/* pixels */
+"++++++++++++++++++++++++++++++++",
+"++++++++++++++++++++++++++++++++",
+"++++++++++++++++++++++++++++++++",
+"++++++++++++++++++++++++++++++++",
+"++++++++++++++++++++++++++++++++",
+"++++++++ ++++++++++",
+"++++++++ ............ ++++++++++",
+"++++++++ ............ ++++++++++",
+"++++++++ .OO......... ++++++++++",
+"++++++++ .OO......... ++++++++++",
+"++++++++ .OO......... ++++++++++",
+"++++++++ .OO...... ",
+"++++++++ .OO...... oooooooooooo ",
+" .OO...... oooooooooooo ",
+" XXXXXXX .OO...... oOOooooooooo ",
+" XXXXXXX .OO...... oOOooooooooo ",
+" XOOXXXX ......... oOOooooooooo ",
+" XOOXXXX ......... oOOooooooooo ",
+" XOOXXXX oOOooooooooo ",
+" XOOXXXXXXXXX ++++ oOOooooooooo ",
+" XOOXXXXXXXXX ++++ oOOooooooooo ",
+" XOOXXXXXXXXX ++++ oOOooooooooo ",
+" XOOXXXXXXXXX ++++ oooooooooooo ",
+" XOOXXXXXXXXX ++++ oooooooooooo ",
+" XXXXXXXXXXXX ++++ ",
+" XXXXXXXXXXXX ++++++++++++++++++",
+" ++++++++++++++++++",
+"++++++++++++++++++++++++++++++++",
+"++++++++++++++++++++++++++++++++",
+"++++++++++++++++++++++++++++++++",
+"++++++++++++++++++++++++++++++++",
+"++++++++++++++++++++++++++++++++"
+};