KiCad PCB EDA Suite
Loading...
Searching...
No Matches
webview_panel.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef WEBVIEW_PANEL_H
21#define WEBVIEW_PANEL_H
22
23#include <wx/panel.h>
24#include <wx/webview.h>
25#include <functional>
26#include <map>
27
28class TOOL_MANAGER;
29class TOOL_BASE;
30
31class WEBVIEW_PANEL : public wxPanel
32{
33public:
34 using MESSAGE_HANDLER = std::function<void( const wxString& )>;
35
36 explicit WEBVIEW_PANEL( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
37 const wxSize& size = wxDefaultSize, const int style = 0,
38 TOOL_MANAGER* aToolManager = nullptr, TOOL_BASE* aTool = nullptr );
39 ~WEBVIEW_PANEL() override;
40
41 wxWebView* GetWebView() const { return m_browser; }
42
43 void LoadURL( const wxString& url );
44 void SetPage( const wxString& htmlContent );
45
46 bool AddMessageHandler( const wxString& name, MESSAGE_HANDLER handler );
48
49 void SetHandleExternalLinks( bool aHandle ) { m_handleExternalLinks = aHandle; }
51
52 void RunScriptAsync( const wxString& aScript, void* aClientData = nullptr ) const
53 {
54 m_browser->RunScriptAsync( aScript, aClientData );
55 }
56
57 bool HasLoadError() const { return m_loadError; }
58
59 void BindLoadedEvent();
60
61protected:
62 void OnNavigationRequest( wxWebViewEvent& evt );
63 void OnWebViewLoaded( wxWebViewEvent& evt );
64 void OnNewWindow( wxWebViewEvent& evt );
65 void OnScriptMessage( wxWebViewEvent& evt );
66 void OnScriptResult( wxWebViewEvent& evt );
67 void OnError( wxWebViewEvent& evt );
68
69private:
70
75 wxWebView* m_browser;
76 std::map<wxString, MESSAGE_HANDLER> m_msgHandlers;
79};
80
81#endif // WEBVIEW_PANEL_H
const char * name
Base abstract interface for all kinds of tools.
Definition tool_base.h:66
Master controller class:
WEBVIEW_PANEL(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, const int style=0, TOOL_MANAGER *aToolManager=nullptr, TOOL_BASE *aTool=nullptr)
TOOL_MANAGER * m_toolManager
bool m_loadedEventBound
void OnScriptMessage(wxWebViewEvent &evt)
void OnNewWindow(wxWebViewEvent &evt)
std::map< wxString, MESSAGE_HANDLER > m_msgHandlers
void SetPage(const wxString &htmlContent)
void OnWebViewLoaded(wxWebViewEvent &evt)
bool HasLoadError() const
void OnNavigationRequest(wxWebViewEvent &evt)
TOOL_BASE * m_tool
void SetHandleExternalLinks(bool aHandle)
void ClearMessageHandlers()
bool AddMessageHandler(const wxString &name, MESSAGE_HANDLER handler)
void RunScriptAsync(const wxString &aScript, void *aClientData=nullptr) const
bool m_handleExternalLinks
std::function< void(const wxString &)> MESSAGE_HANDLER
bool GetHandleExternalLinks() const
void OnScriptResult(wxWebViewEvent &evt)
wxWebView * GetWebView() const
void OnError(wxWebViewEvent &evt)
~WEBVIEW_PANEL() override
void LoadURL(const wxString &url)
wxWebView * m_browser