~clint-fewbar/ubuntu/precise/erlang/merge-15b

« back to all changes in this revision

Viewing changes to lib/wx/test/wx_obj_test.erl

  • Committer: Package Import Robot
  • Author(s): Sergei Golovan
  • Date: 2011-12-15 19:20:10 UTC
  • mfrom: (1.1.18) (3.5.15 sid)
  • mto: (3.5.16 sid)
  • mto: This revision was merged to the branch mainline in revision 33.
  • Revision ID: package-import@ubuntu.com-20111215192010-jnxcfe3tbrpp0big
Tags: 1:15.b-dfsg-1
* New upstream release.
* Upload to experimental because this release breaks external drivers
  API along with ABI, so several applications are to be fixed.
* Removed SSL patch because the old SSL implementation is removed from
  the upstream distribution.
* Removed never used patch which added native code to erlang beam files.
* Removed the erlang-docbuilder binary package because the docbuilder
  application was dropped by upstream.
* Documented dropping ${erlang-docbuilder:Depends} substvar in
  erlang-depends(1) manpage.
* Made erlang-base and erlang-base-hipe provide virtual package
  erlang-abi-15.b (the number means the first erlang version, which
  provides current ABI).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%
 
2
%% %CopyrightBegin%
 
3
%%
 
4
%% Copyright Ericsson AB 2011. 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
-module(wx_obj_test).
 
19
-include_lib("wx/include/wx.hrl").
 
20
 
 
21
-export([start/1]).
 
22
 
 
23
%% wx_object callbacks
 
24
-export([init/1, handle_info/2, terminate/2, code_change/3, handle_call/3,
 
25
         handle_sync_event/3, handle_event/2, handle_cast/2]).
 
26
 
 
27
-record(state, {frame, panel, opts}).
 
28
 
 
29
start(Opts) ->
 
30
    wx_object:start_link(?MODULE, [{parent, self()}, Opts], []).
 
31
 
 
32
init(Opts) ->
 
33
    put(parent_pid, proplists:get_value(parent, Opts)),
 
34
    Frame = wxFrame:new(wx:null(), ?wxID_ANY, "Test wx_object", [{size, {500, 400}}]),
 
35
    Sz = wxBoxSizer:new(?wxHORIZONTAL),
 
36
    Panel = wxPanel:new(Frame),
 
37
    wxSizer:add(Sz, Panel, [{flag, ?wxEXPAND}, {proportion, 1}]),
 
38
    wxPanel:connect(Panel, size, [{skip, true}]),
 
39
    wxPanel:connect(Panel, paint, [callback, {userData, proplists:get_value(parent, Opts)}]),
 
40
    wxWindow:show(Frame),
 
41
    {Frame, #state{frame=Frame, panel=Panel, opts=Opts}}.
 
42
 
 
43
handle_sync_event(Event = #wx{obj=Panel}, WxEvent, #state{opts=Opts}) ->
 
44
    DC=wxPaintDC:new(Panel),  %% We must create & destroy paintDC, or call wxEvent:skip(WxEvent))
 
45
    wxPaintDC:destroy(DC),    %% in sync_event. Otherwise wx on windows keeps sending the events.
 
46
    Pid = proplists:get_value(parent, Opts),
 
47
    true = is_pid(Pid),
 
48
    Pid ! {sync_event, Event, WxEvent},
 
49
    ok.
 
50
 
 
51
handle_event(Event, State = #state{opts=Opts}) ->
 
52
    Pid = proplists:get_value(parent, Opts),
 
53
    Pid ! {event, Event},
 
54
    {noreply, State}.
 
55
 
 
56
handle_call(What, From, State) when is_function(What) ->
 
57
    Result = What(State),
 
58
    {reply, {call, Result, From}, State};
 
59
handle_call(What, From, State) ->
 
60
    {reply, {call, What, From}, State}.
 
61
 
 
62
handle_cast(What, State = #state{opts=Opts})  when is_function(What) ->
 
63
    Result = What(State),
 
64
    Pid = proplists:get_value(parent, Opts),
 
65
    Pid ! {cast, Result},
 
66
    {noreply, State};
 
67
 
 
68
handle_cast(What, State = #state{opts=Opts}) ->
 
69
    Pid = proplists:get_value(parent, Opts),
 
70
    Pid ! {cast, What},
 
71
    {noreply, State}.
 
72
 
 
73
handle_info(What, State = #state{opts=Opts}) ->
 
74
    Pid = proplists:get_value(parent, Opts),
 
75
    Pid ! {info, What},
 
76
    {noreply, State}.
 
77
 
 
78
terminate(What, #state{opts=Opts}) ->
 
79
    Pid = proplists:get_value(parent, Opts),
 
80
    Pid ! {terminate, What},
 
81
    ok.
 
82
 
 
83
code_change(Ver1, Ver2, State = #state{opts=Opts}) ->
 
84
    Pid = proplists:get_value(parent, Opts),
 
85
    Pid ! {code_change, Ver1, Ver2},
 
86
    State.