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
-include_lib("wx/include/wx.hrl").
23
-behavoiur(wx_object).
25
-export([start/1, init/1, terminate/2, code_change/3,
26
handle_info/2, handle_call/3, handle_event/2]).
36
wx_object:start_link(?MODULE, Config, []).
38
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40
wx:batch(fun() -> do_init(Config) end).
42
Parent = proplists:get_value(parent, Config),
43
Panel = wxPanel:new(Parent, []),
45
MainSizer = wxStaticBoxSizer:new(?wxVERTICAL, Panel,
46
[{label, "wxNotebook"}]),
48
Notebook = wxNotebook:new(Panel, 1, [{style, ?wxBK_DEFAULT%,
54
%?wxNB_MULTILINE % windows only
57
%% Make a wxImageList to be able to display icons in the tab field
58
IL = wxImageList:new(16,16),
59
wxImageList:add(IL, wxArtProvider:getBitmap("wxART_INFORMATION", [{size, {16,16}}])),
60
wxNotebook:assignImageList(Notebook, IL),
64
Win1 = wxPanel:new(Notebook, []),
65
wxPanel:setBackgroundColour(Win1, ?wxRED),
66
Win1Text = wxStaticText:new(Win1, ?wxID_ANY, "This is a red tab.",
68
wxStaticText:setForegroundColour(Win1Text, ?wxGREEN),
69
Sizer1 = wxBoxSizer:new(?wxHORIZONTAL),
70
wxSizer:add(Sizer1, Win1Text),
71
wxPanel:setSizer(Win1, Sizer1),
72
wxNotebook:addPage(Notebook, Win1, "Red", []),
74
Win2 = wxPanel:new(Notebook, []),
75
wxPanel:setBackgroundColour(Win2, ?wxBLUE),
76
Win2Text = wxStaticText:new(Win2, ?wxID_ANY, "This is a blue tab.",
78
wxStaticText:setForegroundColour(Win2Text, {255,255,0,255}),
79
Sizer2 = wxBoxSizer:new(?wxHORIZONTAL),
80
wxSizer:add(Sizer2, Win2Text),
81
wxPanel:setSizer(Win2, Sizer2),
82
wxNotebook:addPage(Notebook, Win2, "Blue", []),
84
Win3 = wxPanel:new(Notebook, []),
85
wxNotebook:addPage(Notebook, Win3, "No color", []),
87
Win4 = wxPanel:new(Notebook, []),
88
wxPanel:setBackgroundColour(Win4, ?wxBLACK),
89
Win4Text = wxStaticText:new(Win4, ?wxID_ANY, "This is a black tab.",
91
wxStaticText:setForegroundColour(Win4Text, ?wxWHITE),
92
Sizer4 = wxBoxSizer:new(?wxHORIZONTAL),
93
wxSizer:add(Sizer4, Win4Text),
94
wxPanel:setSizer(Win4, Sizer4),
95
wxNotebook:addPage(Notebook, Win4, "Black", []),
97
Win5 = wxPanel:new(Notebook, []),
98
wxNotebook:addPage(Notebook, Win5, "Tab with icon", []),
99
wxNotebook:setPageImage(Notebook, 4, 0),
105
wxSizer:add(MainSizer, Notebook, [{proportion, 1},
108
wxNotebook:connect(Notebook, command_notebook_page_changed,
109
[{skip, true}]), % {skip, true} has to be set on windows
110
wxPanel:setSizer(Panel, MainSizer),
111
{Panel, #state{parent=Panel, config=Config,
112
notebook = Notebook}}.
116
%% Callbacks handled as normal gen_server callbacks
117
handle_info(Msg, State) ->
118
demo:format(State#state.config, "Got Info ~p\n",[Msg]),
121
handle_call(Msg, _From, State) ->
122
demo:format(State#state.config,"Got Call ~p\n",[Msg]),
125
%% Async Events are handled in handle_event as in handle_info
126
handle_event(#wx{event = #wxNotebook{type = command_notebook_page_changed}},
127
State = #state{notebook = Notebook}) ->
128
Selection = wxNotebook:getSelection(Notebook),
129
Title = wxNotebook:getPageText(Notebook, Selection),
130
demo:format(State#state.config,"You have selected the tab ~p\n",[Title]),
132
handle_event(Ev = #wx{}, State = #state{}) ->
133
demo:format(State#state.config,"Got Event ~p\n",[Ev]),
136
code_change(_, _, State) ->
137
{stop, ignore, State}.
139
terminate(_Reason, _State) ->
142
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%