1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2011-2018. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19-module(cdv_info_wx). 20 21-behaviour(wx_object). 22 23-export([start_link/2]). 24%% wx_object callbacks 25-export([init/1, handle_info/2, terminate/2, code_change/3, handle_call/3, 26 handle_event/2, handle_cast/2]). 27 28-include_lib("wx/include/wx.hrl"). 29-include("observer_defs.hrl"). 30 31%% Records 32-record(state, 33 {panel, 34 sizer, 35 fpanel, 36 callback, 37 trunc_warn=[] 38 }). 39 40start_link(ParentWin, Info) -> 41 wx_object:start_link(?MODULE, [ParentWin, Info], []). 42 43%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 44 45init([ParentWin, Callback]) when is_atom(Callback) -> 46 {InfoFields,Info,TW} = Callback:get_info(), 47 {Panel,Sizer,FPanel} = create_box(ParentWin,InfoFields,Info), 48 {Panel,#state{panel=Panel, 49 sizer=Sizer, 50 fpanel=FPanel, 51 callback=Callback, 52 trunc_warn=TW}}; 53 54init([ParentWin, {InfoFields,Info,TW}]) -> 55 {Panel,Sizer,FPanel} = create_box(ParentWin,InfoFields,Info), 56 {Panel, #state{panel=Panel, 57 sizer=Sizer, 58 fpanel=FPanel, 59 trunc_warn=TW}}. 60 61%%%%%%%%%%%%%%%%%%%%%%% Callbacks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 62 63handle_info(active, State) -> 64 cdv_wx:set_status(State#state.trunc_warn), 65 {noreply, State}; 66 67handle_info(Info, State) -> 68 io:format("~p:~p: Unhandled info: ~tp~n", [?MODULE, ?LINE, Info]), 69 {noreply, State}. 70 71terminate(_Reason, _State) -> 72 ok. 73 74code_change(_, _, State) -> 75 {ok, State}. 76 77handle_call(new_dump, _From, #state{callback=Callback,panel=Panel, 78 sizer=Sizer,fpanel=FPanel} = State) -> 79 {InfoFields,Info,TW} = Callback:get_info(), 80 NewFPanel = 81 wx:batch( 82 fun() -> 83 wxWindow:destroy(FPanel), 84 FP = create_field_panel(Panel,Sizer,InfoFields,Info), 85 wxSizer:layout(Sizer), 86 FP 87 end), 88 {reply, ok, State#state{fpanel=NewFPanel,trunc_warn=TW}}; 89 90handle_call(Msg, _From, State) -> 91 io:format("~p~p: Unhandled Call ~tp~n",[?MODULE, ?LINE, Msg]), 92 {reply, ok, State}. 93 94handle_cast(Msg, State) -> 95 io:format("~p~p: Unhandled cast ~tp~n",[?MODULE, ?LINE, Msg]), 96 {noreply, State}. 97 98handle_event(#wx{obj=MoreEntry,event=#wxMouse{type=left_down},userData={more,More}}, State) -> 99 observer_lib:add_scroll_entries(MoreEntry,More), 100 {noreply, State}; 101 102handle_event(#wx{event=#wxMouse{type=left_down},userData=Target}, State) -> 103 cdv_virtual_list_wx:start_detail_win(Target), 104 {noreply, State}; 105 106handle_event(#wx{obj=Obj,event=#wxMouse{type=enter_window}},State) -> 107 wxTextCtrl:setForegroundColour(Obj,{0,0,100,255}), 108 {noreply, State}; 109 110handle_event(#wx{obj=Obj,event=#wxMouse{type=leave_window}},State) -> 111 wxTextCtrl:setForegroundColour(Obj,?wxBLUE), 112 {noreply, State}; 113 114handle_event(Event, State) -> 115 io:format("~p:~p: Unhandled event ~tp\n", [?MODULE,?LINE,Event]), 116 {noreply, State}. 117 118%%%----------------------------------------------------------------- 119%%% Internal 120create_box(ParentWin,InfoFields,Info) -> 121 Panel = wxPanel:new(ParentWin), 122 Sizer = wxBoxSizer:new(?wxVERTICAL), 123 FPanel = create_field_panel(Panel,Sizer,InfoFields,Info), 124 wxPanel:setSizer(Panel, Sizer), 125 {Panel,Sizer,FPanel}. 126 127create_field_panel(Panel,Sizer,InfoFields,Info0) -> 128 Info = observer_lib:fill_info(InfoFields, Info0), 129 {FPanel, _FSizer, _Fields} = observer_lib:display_info(Panel,Info), 130 BorderFlags = ?wxLEFT bor ?wxRIGHT, 131 wxSizer:add(Sizer, FPanel, [{flag, ?wxEXPAND bor BorderFlags bor ?wxTOP}, 132 {proportion, 0}, {border, 5}]), 133 FPanel. 134