4
%% Copyright Ericsson AB 2011. 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
19
-include_lib("wx/include/wx.hrl").
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]).
27
-record(state, {frame, panel, opts}).
30
wx_object:start_link(?MODULE, [{parent, self()}, 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)}]),
41
{Frame, #state{frame=Frame, panel=Panel, opts=Opts}}.
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),
48
Pid ! {sync_event, Event, WxEvent},
51
handle_event(Event, State = #state{opts=Opts}) ->
52
Pid = proplists:get_value(parent, Opts),
56
handle_call(What, From, State) when is_function(What) ->
58
{reply, {call, Result, From}, State};
59
handle_call(What, From, State) ->
60
{reply, {call, What, From}, State}.
62
handle_cast(What, State = #state{opts=Opts}) when is_function(What) ->
64
Pid = proplists:get_value(parent, Opts),
68
handle_cast(What, State = #state{opts=Opts}) ->
69
Pid = proplists:get_value(parent, Opts),
73
handle_info(What, State = #state{opts=Opts}) ->
74
Pid = proplists:get_value(parent, Opts),
78
terminate(What, #state{opts=Opts}) ->
79
Pid = proplists:get_value(parent, Opts),
80
Pid ! {terminate, What},
83
code_change(Ver1, Ver2, State = #state{opts=Opts}) ->
84
Pid = proplists:get_value(parent, Opts),
85
Pid ! {code_change, Ver1, Ver2},