1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2011-2013. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%% %CopyrightEnd%
-module(observer_term_wx).
-behaviour(wx_object).
-export([start/2]).
-export([init/1, handle_event/2, handle_cast/2, terminate/2, code_change/3,
handle_call/3, handle_info/2]).
-include_lib("wx/include/wx.hrl").
-include("observer_defs.hrl").
-define(REFRESH, 601).
-record(state, {parent,
frame,
id
}).
start(Id, ParentFrame) ->
wx_object:start_link(?MODULE, [Id, ParentFrame, self()], []).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
init([{T,Key}=Id, ParentFrame, Parent]) ->
case ets:lookup(T,Key) of
[{Key,Term}] ->
init(Id, ParentFrame, Parent, Term);
[] ->
observer_lib:display_info_dialog(
"The term does no longer exist.\n"
"Please refresh the process window!"),
{stop, normal}
end.
init(Id, ParentFrame, Parent, Term) ->
Frame=wxFrame:new(ParentFrame, ?wxID_ANY, ["Expanded Term"],
[{style, ?wxDEFAULT_FRAME_STYLE}, {size, {850,600}}]),
MenuBar = wxMenuBar:new(),
Menus = [{"File", [#create_menu{id=?wxID_CLOSE, text="Close"}]}],
observer_lib:create_menus(Menus, MenuBar, new_window),
wxFrame:setMenuBar(Frame, MenuBar),
Panel = wxPanel:new(Frame),
Sizer = wxBoxSizer:new(?wxHORIZONTAL),
Window = observer_lib:html_window(Panel),
Html = crashdump_viewer_html:plain_page(io_lib:format("~p~n",[Term])),
wxHtmlWindow:setPage(Window, Html),
wxSizer:add(Sizer, Window, [{flag, ?wxEXPAND bor ?wxALL},
{proportion, 1},
{border, 5}]),
wxPanel:setSizer(Panel, Sizer),
wxFrame:show(Frame),
{Frame, #state{parent=Parent,
frame=Frame,
id=Id
}}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Callbacks%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
handle_event(#wx{event=#wxClose{type=close_window}}, State) ->
{stop, normal, State};
handle_event(#wx{id=?wxID_CLOSE, event=#wxCommand{type=command_menu_selected}}, State) ->
{stop, normal, State};
handle_event(#wx{event=#wxHtmlLink{linkInfo=#wxHtmlLinkInfo{href=Info}}}, State) ->
observer ! {open_link, Info},
{noreply, State};
handle_event(Event, _State) ->
error({unhandled_event, Event}).
handle_info(_Info, State) ->
%% io:format("~p: ~p, Handle info: ~p~n", [?MODULE, ?LINE, Info]),
{noreply, State}.
handle_call(Call, From, _State) ->
error({unhandled_call, Call, From}).
handle_cast(Cast, _State) ->
error({unhandled_cast, Cast}).
terminate(_Reason, #state{parent=Parent,id=Id,frame=Frame}) ->
Parent ! {expand_win_closed, Id},
case Frame of
undefined -> ok;
_ -> wxFrame:destroy(Frame)
end,
ok.
code_change(_, _, State) ->
{ok, State}.
|