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_static).
21
22-behaviour(wx_object).
23
24%% Client API
25-export([start/1]).
26
27%% wx_object callbacks
28-export([init/1, terminate/2,  code_change/3,
29	 handle_info/2, handle_call/3, handle_cast/2, handle_event/2]).
30
31-include_lib("wx/include/wx.hrl").
32
33-record(state,
34	{
35	  parent,
36	  config
37	}).
38
39start(Config) ->
40    wx_object:start_link(?MODULE, Config, []).
41
42%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43init(Config) ->
44    wx:batch(fun() -> do_init(Config) end).
45
46do_init(Config) ->
47    Parent = proplists:get_value(parent, Config),
48    Panel = wxScrolledWindow:new(Parent, []),
49    wxScrolledWindow:setScrollRate(Panel, 5, 5),
50
51    %% Setup sizers
52    MainSizer = wxBoxSizer:new(?wxVERTICAL),
53    TextSizer = wxStaticBoxSizer:new(?wxVERTICAL, Panel,
54				 [{label, "wxStaticText"}]),
55    BitmapSizer = wxStaticBoxSizer:new(?wxVERTICAL, Panel,
56				       [{label, "wxStaticBitmap"}]),
57    LineSizer = wxStaticBoxSizer:new(?wxVERTICAL, Panel,
58				     [{label, "wxStaticLine"}]),
59
60    %% Create static texts
61    Texts = [wxStaticText:new(Panel, 1, "This is a regular text (left aligned)", []),
62	     wxStaticText:new(Panel, 2, "This is a centered text",
63			      [{style, ?wxALIGN_CENTER bor ?wxST_NO_AUTORESIZE}]),
64	     wxStaticText:new(Panel, 3, "This is a right aligned text",
65			      [{style, ?wxALIGN_RIGHT bor ?wxST_NO_AUTORESIZE}])],
66
67
68    Image = wxImage:new("image.jpg", []),
69    Bitmap = wxBitmap:new(wxImage:scale(Image,
70					round(wxImage:getWidth(Image)*1.5),
71					round(wxImage:getHeight(Image)*1.5),
72					[{quality, ?wxIMAGE_QUALITY_HIGH}])),
73    StaticBitmap = wxStaticBitmap:new(Panel, 1, Bitmap),
74
75    Line = wxStaticLine:new(Panel, [{style, ?wxLI_HORIZONTAL}]),
76    Line2 = wxStaticLine:new(Panel, [{style, ?wxLI_VERTICAL},
77				     {size, {-1, 100}}]),
78
79    %% Add to sizers
80    [wxSizer:add(TextSizer, Text, [{flag, ?wxEXPAND bor ?wxALL},
81				   {border, 10}]) || Text <- Texts],
82    wxSizer:add(BitmapSizer, StaticBitmap, []),
83    wxSizer:add(LineSizer, Line, [{flag, ?wxTOP bor ?wxBOTTOM bor ?wxEXPAND},
84				  {border, 10}]),
85    wxSizer:add(LineSizer, Line2, [{flag, ?wxLEFT},
86				   {border, 50}]),
87
88    wxSizer:add(MainSizer, TextSizer, [{flag, ?wxEXPAND}]),
89    wxSizer:add(MainSizer, BitmapSizer, []),
90    wxSizer:add(MainSizer, LineSizer, [{flag, ?wxEXPAND}]),
91
92    wxPanel:setSizer(Panel, MainSizer),
93    {Panel, #state{parent=Panel, config=Config}}.
94
95%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96%% Async Events are handled in handle_event as in handle_info
97handle_event(#wx{}, State = #state{}) ->
98    {noreply, State}.
99
100%% Callbacks handled as normal gen_server callbacks
101handle_info(Msg, State) ->
102    demo:format(State#state.config, "Got Info ~p\n", [Msg]),
103    {noreply, State}.
104
105handle_call(shutdown, _From, State=#state{parent=Panel}) ->
106    wxPanel:destroy(Panel),
107    {stop, normal, ok, State};
108
109handle_call(Msg, _From, State) ->
110    demo:format(State#state.config, "Got Call ~p\n", [Msg]),
111    {reply,{error, nyi}, State}.
112
113handle_cast(Msg, State) ->
114    io:format("Got cast ~p~n",[Msg]),
115    {noreply,State}.
116
117code_change(_, _, State) ->
118    {stop, ignore, State}.
119
120terminate(_Reason, _State) ->
121    ok.
122
123%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124%% Local functions
125%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126
127