1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 2009-2016. 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
20-module(ex_htmlWindow).
21
22-behaviour(wx_object).
23
24%% Client API
25-export([start/1]).
26
27%% wx_object callbacks
28-export([init/1, terminate/2,  code_change/3,
29	 handle_info/2, handle_call/3, handle_cast/2, handle_event/2]).
30
31-include("../../include/wx.hrl").
32
33-record(state,
34	{
35	  parent,
36	  config
37	}).
38
39start(Config) ->
40    wx_object:start_link(?MODULE, Config, []).
41
42%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43init(Config) ->
44    wx:batch(fun() -> do_init(Config) end).
45
46do_init(Config) ->
47    Parent = proplists:get_value(parent, Config),
48    Panel = wxPanel:new(Parent, []),
49
50    %% Setup sizers
51    MainSizer = wxBoxSizer:new(?wxVERTICAL),
52    Sizer = wxStaticBoxSizer:new(?wxVERTICAL, Panel,
53				 [{label, "wxHtmlWindow"}]),
54
55    %% Create the wxHtmlWindow
56    HtmlWin = wxHtmlWindow:new(Panel, []),
57    %% Load a file and display it
58    wxHtmlWindow:loadFile(HtmlWin, "ex_htmlWindow.html"),
59
60    %% Add to sizers
61    wxSizer:add(Sizer, HtmlWin, [{flag, ?wxEXPAND}, {proportion, 1}]),
62    wxSizer:add(MainSizer, Sizer, [{flag, ?wxEXPAND}, {proportion, 1}]),
63
64    wxHtmlWindow:connect(HtmlWin, command_html_link_clicked, [{skip,true}]),
65
66    wxPanel:setSizer(Panel, MainSizer),
67    {Panel, #state{parent=Panel, config=Config}}.
68
69%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70%% Async Events are handled in handle_event as in handle_info
71handle_event(#wx{event = #wxHtmlLink{linkInfo = #wxHtmlLinkInfo{href=Link}}},
72	     State = #state{}) ->
73    demo:format(State#state.config, "You clicked link ~p.\n", [Link]),
74    {noreply, State}.
75
76%% Callbacks handled as normal gen_server callbacks
77handle_info(Msg, State) ->
78    demo:format(State#state.config, "Got Info ~p\n", [Msg]),
79    {noreply, State}.
80
81handle_call(shutdown, _From, State=#state{parent=Panel}) ->
82    wxPanel:destroy(Panel),
83    {stop, normal, ok, State};
84
85handle_call(Msg, _From, State) ->
86    demo:format(State#state.config, "Got Call ~p\n", [Msg]),
87    {reply,{error, nyi}, State}.
88
89handle_cast(Msg, State) ->
90    io:format("Got cast ~p~n",[Msg]),
91    {noreply,State}.
92
93code_change(_, _, State) ->
94    {stop, ignore, State}.
95
96terminate(_Reason, _State) ->
97    ok.
98
99%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100%% Local functions
101%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102
103