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
21
-behavoiur(wx_object).
23
-export([start/1, init/1, terminate/2, code_change/3,
24
handle_info/2, handle_call/3, handle_event/2]).
26
-include_lib("wx/include/wx.hrl").
37
wx_object:start_link(?MODULE, Config, []).
39
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41
wx:batch(fun() -> do_init(Config) end).
43
Parent = proplists:get_value(parent, Config),
44
Panel = wxScrolledWindow:new(Parent, []),
47
MainSizer = wxBoxSizer:new(?wxVERTICAL),
48
ListBoxSizer = wxStaticBoxSizer:new(?wxVERTICAL, Panel,
49
[{label, "wxListBox"}]),
50
Sizer = wxBoxSizer:new(?wxHORIZONTAL),
51
Sizer2 = wxBoxSizer:new(?wxHORIZONTAL),
53
Choices = ["one","two","three",
55
"seven","eight","nine",
56
"ten", "eleven", "twelve"],
61
ListBox = wxListBox:new(Panel, 1, [{size, {-1,100}},
62
{choices, ["Multiple selection"|Choices]},
63
{style, ?wxLB_MULTIPLE}]),
64
ListBox2 = wxListBox:new(Panel, 2, [{size, {-1,100}},
65
{choices, ["Single selection"|Choices]},
66
{style, ?wxLB_SINGLE}]),
71
Sizer3 = wxBoxSizer:new(?wxHORIZONTAL),
72
ChoiceSizer = wxStaticBoxSizer:new(?wxVERTICAL, Panel,
73
[{label, "wxChoice"}]),
74
Choice = wxChoice:new(Panel, 4, [{choices, Choices}]),
75
wxChoice:connect(Choice,command_choice_selected),
79
SpinSizer = wxStaticBoxSizer:new(?wxVERTICAL, Panel,
80
[{label, "wxSpinCtrl"}]),
81
SpinCtrl = wxSpinCtrl:new(Panel, []),
82
wxSpinCtrl:setRange(SpinCtrl, 0, 100),
83
wxChoice:connect(SpinCtrl,command_spinctrl_updated),
87
ComboSizer = wxStaticBoxSizer:new(?wxVERTICAL, Panel,
88
[{label, "wxComboBox"}]),
89
ComboBox = wxComboBox:new(Panel, 5, [{choices, Choices}]),
90
wxComboBox:setValue(ComboBox, "Default value"),
91
wxComboBox:connect(ComboBox, command_combobox_selected),
96
Options = [{border,4}, {flag, ?wxALL}],
97
wxSizer:add(Sizer, ListBox, Options),
98
wxSizer:add(Sizer, ListBox2, Options),
100
wxSizer:add(ChoiceSizer, Choice, Options),
101
wxSizer:add(SpinSizer, SpinCtrl, Options),
102
wxSizer:add(Sizer3, ChoiceSizer, []),
103
wxSizer:add(Sizer3, SpinSizer, [{border, 4}, {flag, ?wxLEFT}]),
105
wxSizer:add(ComboSizer, ComboBox, Options),
107
wxSizer:add(ListBoxSizer, Sizer, Options),
108
wxSizer:add(ListBoxSizer, Sizer2, Options),
109
wxSizer:add(MainSizer, ListBoxSizer, Options),
110
wxSizer:add(MainSizer, Sizer3, Options),
111
wxSizer:add(MainSizer, ComboSizer, Options),
113
wxScrolledWindow:setScrollRate(Panel, 5, 5),
114
wxPanel:setSizer(Panel, MainSizer),
115
{Panel, #state{parent=Panel, config=Config,
116
list_box = ListBox}}.
118
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119
%% Callbacks handled as normal gen_server callbacks
120
handle_info(Msg, State) ->
121
demo:format(State#state.config, "Got Info ~p\n",[Msg]),
124
handle_call(Msg, _From, State) ->
125
demo:format(State#state.config,"Got Call ~p\n",[Msg]),
126
{reply, {error,nyi}, State}.
128
%% Async Events are handled in handle_event as in handle_info
129
handle_event(#wx{obj = ComboBox,
130
event = #wxCommand{type = command_combobox_selected}},
132
Value = wxComboBox:getValue(ComboBox),
133
demo:format(State#state.config,"Selected wxComboBox ~p\n",[Value]),
135
handle_event(#wx{event = #wxCommand{type = command_choice_selected,
138
demo:format(State#state.config,"Selected wxChoice ~p\n",[Value]),
140
handle_event(#wx{event = #wxSpin{type = command_spinctrl_updated,
143
demo:format(State#state.config,"wxSpinCtrl changed to ~p\n",[Int]),
145
handle_event(Ev = #wx{}, State = #state{}) ->
146
demo:format(State#state.config,"Got Event ~p\n",[Ev]),
149
code_change(_, _, State) ->
150
{stop, ignore, State}.
152
terminate(_Reason, _State) ->
155
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%