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).
26
%% wx_object callbacks
27
-export([init/1, terminate/2, code_change/3,
28
handle_info/2, handle_call/3, handle_event/2]).
30
-include_lib("wx/include/wx.hrl").
39
wx_object:start_link(?MODULE, Config, []).
41
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43
wx:batch(fun() -> do_init(Config) end).
46
Parent = proplists:get_value(parent, Config),
47
Panel = wxScrolledWindow:new(Parent, []),
48
wxScrolledWindow:setScrollRate(Panel, 5, 5),
51
MainSizer = wxBoxSizer:new(?wxVERTICAL),
52
TextSizer = wxStaticBoxSizer:new(?wxVERTICAL, Panel,
53
[{label, "wxStaticText"}]),
54
BitmapSizer = wxStaticBoxSizer:new(?wxVERTICAL, Panel,
55
[{label, "wxStaticBitmap"}]),
56
LineSizer = wxStaticBoxSizer:new(?wxVERTICAL, Panel,
57
[{label, "wxStaticLine"}]),
60
Texts = [wxStaticText:new(Panel, 1, "This is a regular text (left aligned)", []),
61
wxStaticText:new(Panel, 2, "This is a centered text",
62
[{style, ?wxALIGN_CENTER bor ?wxST_NO_AUTORESIZE}]),
63
wxStaticText:new(Panel, 3, "This is a right aligned text",
64
[{style, ?wxALIGN_RIGHT bor ?wxST_NO_AUTORESIZE}])],
67
Image = wxImage:new("image.jpg", []),
68
Bitmap = wxBitmap:new(wxImage:scale(Image,
69
round(wxImage:getWidth(Image)*1.5),
70
round(wxImage:getHeight(Image)*1.5),
71
[{quality, ?wxIMAGE_QUALITY_HIGH}])),
72
StaticBitmap = wxStaticBitmap:new(Panel, 1, Bitmap),
74
Line = wxStaticLine:new(Panel, [{style, ?wxLI_HORIZONTAL}]),
75
Line2 = wxStaticLine:new(Panel, [{style, ?wxLI_VERTICAL},
79
[wxSizer:add(TextSizer, Text, [{flag, ?wxEXPAND bor ?wxALL},
80
{border, 10}]) || Text <- Texts],
81
wxSizer:add(BitmapSizer, StaticBitmap, []),
82
wxSizer:add(LineSizer, Line, [{flag, ?wxTOP bor ?wxBOTTOM bor ?wxEXPAND},
84
wxSizer:add(LineSizer, Line2, [{flag, ?wxLEFT},
87
wxSizer:add(MainSizer, TextSizer, [{flag, ?wxEXPAND}]),
88
wxSizer:add(MainSizer, BitmapSizer, []),
89
wxSizer:add(MainSizer, LineSizer, [{flag, ?wxEXPAND}]),
91
wxPanel:setSizer(Panel, MainSizer),
92
{Panel, #state{parent=Panel, config=Config}}.
94
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95
%% Callbacks handled as normal gen_server callbacks
96
handle_info(Msg, State) ->
97
demo:format(State#state.config, "Got Info ~p\n", [Msg]),
100
handle_call(Msg, _From, State) ->
101
demo:format(State#state.config, "Got Call ~p\n", [Msg]),
102
{reply,{error, nyi}, State}.
104
%% Async Events are handled in handle_event as in handle_info
105
handle_event(Ev = #wx{}, State = #state{}) ->
106
demo:format(State#state.config, "Got Event ~p\n", [Ev]),
109
code_change(_, _, State) ->
110
{stop, ignore, State}.
112
terminate(_Reason, _State) ->
115
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%