~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to lib/wx/examples/demo/ex_notebook.erl

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-08-05 20:54:29 UTC
  • mfrom: (6.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090805205429-pm4pnwew8axraosl
Tags: 1:13.b.1-dfsg-5
* Fixed parentheses in Emacs mode (closes: #536891).
* Removed unnecessary conflicts with erlang-manpages package.
* Added workaround for #475459: disabled threads on sparc architecture.
  This breaks wxErlang, so it's only a temporary solution.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%
 
2
%% %CopyrightBegin%
 
3
%% 
 
4
%% Copyright Ericsson AB 2009. All Rights Reserved.
 
5
%% 
 
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/.
 
11
%% 
 
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
 
15
%% under the License.
 
16
%% 
 
17
%% %CopyrightEnd%
 
18
 
 
19
-module(ex_notebook).
 
20
 
 
21
-include_lib("wx/include/wx.hrl").
 
22
 
 
23
-behavoiur(wx_object).
 
24
 
 
25
-export([start/1, init/1, terminate/2,  code_change/3,
 
26
         handle_info/2, handle_call/3, handle_event/2]).
 
27
 
 
28
-record(state, 
 
29
        {
 
30
          parent,
 
31
          config,
 
32
          notebook
 
33
         }).
 
34
 
 
35
start(Config) ->
 
36
    wx_object:start_link(?MODULE, Config, []).
 
37
 
 
38
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
39
init(Config) ->
 
40
        wx:batch(fun() -> do_init(Config) end).
 
41
do_init(Config) ->
 
42
    Parent = proplists:get_value(parent, Config),  
 
43
    Panel = wxPanel:new(Parent, []),
 
44
    %% Setup sizers
 
45
    MainSizer = wxStaticBoxSizer:new(?wxVERTICAL, Panel, 
 
46
                                     [{label, "wxNotebook"}]),
 
47
 
 
48
    Notebook = wxNotebook:new(Panel, 1, [{style, ?wxBK_DEFAULT%,
 
49
                                                %?wxBK_ALIGN_MASK,
 
50
                                                %?wxBK_TOP,
 
51
                                                %?wxBK_BOTTOM,
 
52
                                                %?wxBK_LEFT,
 
53
                                                %?wxBK_RIGHT,
 
54
                                                %?wxNB_MULTILINE % windows only
 
55
                                         }]),
 
56
 
 
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),
 
61
    
 
62
 
 
63
 
 
64
    Win1 = wxPanel:new(Notebook, []),
 
65
    wxPanel:setBackgroundColour(Win1, ?wxRED),
 
66
    Win1Text = wxStaticText:new(Win1, ?wxID_ANY, "This is a red tab.",
 
67
                                [{pos, {50, 100}}]),
 
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", []),
 
73
 
 
74
    Win2 = wxPanel:new(Notebook, []),
 
75
    wxPanel:setBackgroundColour(Win2, ?wxBLUE),
 
76
    Win2Text = wxStaticText:new(Win2, ?wxID_ANY, "This is a blue tab.",
 
77
                                [{pos, {50, 100}}]),
 
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", []),
 
83
 
 
84
    Win3 = wxPanel:new(Notebook, []),
 
85
    wxNotebook:addPage(Notebook, Win3, "No color", []),
 
86
 
 
87
    Win4 = wxPanel:new(Notebook, []),
 
88
    wxPanel:setBackgroundColour(Win4, ?wxBLACK),
 
89
    Win4Text = wxStaticText:new(Win4, ?wxID_ANY, "This is a black tab.",
 
90
                                [{pos, {50, 100}}]),
 
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", []),
 
96
 
 
97
    Win5 = wxPanel:new(Notebook, []),
 
98
    wxNotebook:addPage(Notebook, Win5, "Tab with icon", []),
 
99
    wxNotebook:setPageImage(Notebook, 4, 0),
 
100
    
 
101
 
 
102
 
 
103
 
 
104
    %% Add to sizers
 
105
    wxSizer:add(MainSizer, Notebook, [{proportion, 1},
 
106
                                  {flag, ?wxEXPAND}]),
 
107
 
 
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}}.
 
113
 
 
114
 
 
115
%%%%%%%%%%%%
 
116
%% Callbacks handled as normal gen_server callbacks
 
117
handle_info(Msg, State) ->
 
118
    demo:format(State#state.config, "Got Info ~p\n",[Msg]),
 
119
    {noreply,State}.
 
120
 
 
121
handle_call(Msg, _From, State) ->
 
122
    demo:format(State#state.config,"Got Call ~p\n",[Msg]),
 
123
    {reply,ok,State}.
 
124
 
 
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]),
 
131
    {noreply,State};
 
132
handle_event(Ev = #wx{}, State = #state{}) ->
 
133
    demo:format(State#state.config,"Got Event ~p\n",[Ev]),
 
134
    {noreply,State}.
 
135
 
 
136
code_change(_, _, State) ->
 
137
    {stop, ignore, State}.
 
138
 
 
139
terminate(_Reason, _State) ->
 
140
    ok.
 
141
 
 
142
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
143
%%%% Local functions
 
144
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
145
 
 
146
            
 
147