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

« back to all changes in this revision

Viewing changes to lib/wx/examples/demo/ex_static.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_static).
 
20
 
 
21
-behavoiur(wx_object).
 
22
 
 
23
%% Client API
 
24
-export([start/1]).
 
25
 
 
26
%% wx_object callbacks
 
27
-export([init/1, terminate/2,  code_change/3,
 
28
         handle_info/2, handle_call/3, handle_event/2]).
 
29
 
 
30
-include_lib("wx/include/wx.hrl").
 
31
 
 
32
-record(state, 
 
33
        {
 
34
          parent,
 
35
          config
 
36
        }).
 
37
 
 
38
start(Config) ->
 
39
    wx_object:start_link(?MODULE, Config, []).
 
40
 
 
41
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
42
init(Config) ->
 
43
    wx:batch(fun() -> do_init(Config) end).
 
44
 
 
45
do_init(Config) ->
 
46
    Parent = proplists:get_value(parent, Config),  
 
47
    Panel = wxScrolledWindow:new(Parent, []),
 
48
    wxScrolledWindow:setScrollRate(Panel, 5, 5),
 
49
 
 
50
    %% Setup sizers
 
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"}]),
 
58
 
 
59
    %% Create items
 
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}])],
 
65
 
 
66
 
 
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),
 
73
 
 
74
    Line = wxStaticLine:new(Panel, [{style, ?wxLI_HORIZONTAL}]),
 
75
    Line2 = wxStaticLine:new(Panel, [{style, ?wxLI_VERTICAL},
 
76
                                     {size, {-1, 100}}]),
 
77
 
 
78
    %% Add to sizers
 
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},
 
83
                                  {border, 10}]),
 
84
    wxSizer:add(LineSizer, Line2, [{flag, ?wxLEFT},
 
85
                                   {border, 50}]),
 
86
 
 
87
    wxSizer:add(MainSizer, TextSizer, [{flag, ?wxEXPAND}]),
 
88
    wxSizer:add(MainSizer, BitmapSizer, []),
 
89
    wxSizer:add(MainSizer, LineSizer, [{flag, ?wxEXPAND}]),
 
90
 
 
91
    wxPanel:setSizer(Panel, MainSizer),
 
92
    {Panel, #state{parent=Panel, config=Config}}.
 
93
 
 
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]),
 
98
    {noreply, State}.
 
99
 
 
100
handle_call(Msg, _From, State) ->
 
101
    demo:format(State#state.config, "Got Call ~p\n", [Msg]),
 
102
    {reply,{error, nyi}, State}.
 
103
 
 
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]),
 
107
    {noreply, State}.
 
108
 
 
109
code_change(_, _, State) ->
 
110
    {stop, ignore, State}.
 
111
 
 
112
terminate(_Reason, _State) ->
 
113
    ok.
 
114
 
 
115
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
116
%% Local functions
 
117
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
118