1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 2009-2016. All Rights Reserved.
5%%
6%% Licensed under the Apache License, Version 2.0 (the "License");
7%% you may not use this file except in compliance with the License.
8%% You may obtain a copy of the License at
9%%
10%%     http://www.apache.org/licenses/LICENSE-2.0
11%%
12%% Unless required by applicable law or agreed to in writing, software
13%% distributed under the License is distributed on an "AS IS" BASIS,
14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15%% See the License for the specific language governing permissions and
16%% limitations under the License.
17%%
18%% %CopyrightEnd%
19
20-module(ex_textCtrl).
21
22-behaviour(wx_object).
23
24-export([start/1, init/1, terminate/2,  code_change/3,
25	 handle_info/2, handle_call/3, handle_cast/2, handle_event/2]).
26
27-include_lib("wx/include/wx.hrl").
28
29-record(state,
30	{
31	  parent,
32	  config
33	 }).
34
35start(Config) ->
36    wx_object:start_link(?MODULE, Config, []).
37
38%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39init(Config) ->
40        wx:batch(fun() -> do_init(Config) end).
41
42do_init(Config) ->
43    Parent = proplists:get_value(parent, Config),
44    Panel = wxPanel:new(Parent, []),
45
46    %% Setup sizers
47    MainSizer = wxBoxSizer:new(?wxVERTICAL),
48    Sizer = wxStaticBoxSizer:new(?wxVERTICAL, Panel,
49				 [{label, "wxTextCtrl single line"}]),
50    Sizer2 = wxStaticBoxSizer:new(?wxVERTICAL, Panel,
51				  [{label, "wxTextCtrl single line password"}]),
52    Sizer3 = wxStaticBoxSizer:new(?wxVERTICAL, Panel,
53				  [{label, "wxTextCtrl multiline"}]),
54
55    TextCtrl  = wxTextCtrl:new(Panel, 1, [{value, "This is a single line wxTextCtrl"},
56					 {style, ?wxDEFAULT}]),
57    TextCtrl2 = wxTextCtrl:new(Panel, 2, [{value, "password"},
58					  {style, ?wxDEFAULT bor ?wxTE_PASSWORD}]),
59    TextCtrl3 = wxTextCtrl:new(Panel, 3, [{value, "This is a\nmultiline\nwxTextCtrl"},
60					  {style, ?wxDEFAULT bor ?wxTE_MULTILINE}]),
61
62    %% Add to sizers
63    wxSizer:add(Sizer, TextCtrl,  [{flag, ?wxEXPAND}]),
64    wxSizer:add(Sizer2, TextCtrl2, []),
65    wxSizer:add(Sizer3, TextCtrl3, [{flag, ?wxEXPAND}, {proportion, 1}]),
66
67    wxSizer:add(MainSizer, Sizer,  [{flag, ?wxEXPAND}]),
68    wxSizer:addSpacer(MainSizer, 10),
69    wxSizer:add(MainSizer, Sizer2, [{flag, ?wxEXPAND}]),
70    wxSizer:addSpacer(MainSizer, 10),
71    wxSizer:add(MainSizer, Sizer3, [{flag, ?wxEXPAND}, {proportion, 1}]),
72
73    wxPanel:setSizer(Panel, MainSizer),
74    {Panel, #state{parent=Panel, config=Config}}.
75
76
77%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78%% Async Events are handled in handle_event as in handle_info
79handle_event(Ev = #wx{}, State = #state{}) ->
80    demo:format(State#state.config,"Got Event ~p\n",[Ev]),
81    {noreply, State}.
82
83%% Callbacks handled as normal gen_server callbacks
84handle_info(Msg, State) ->
85    demo:format(State#state.config, "Got Info ~p\n",[Msg]),
86    {noreply, State}.
87
88handle_call(shutdown, _From, State=#state{parent=Panel}) ->
89    wxPanel:destroy(Panel),
90    {stop, normal, ok, State};
91
92handle_call(Msg, _From, State) ->
93    demo:format(State#state.config,"Got Call ~p\n",[Msg]),
94    {reply, {error,nyi}, State}.
95
96handle_cast(Msg, State) ->
97    io:format("Got cast ~p~n",[Msg]),
98    {noreply,State}.
99
100code_change(_, _, State) ->
101    {stop, ignore, State}.
102
103terminate(_Reason, _State) ->
104    ok.
105
106%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107%% Local functions
108%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109
110