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 const wxString& GetBackend() const { return m_backend; }
43
44 void LoadURL( const wxString& url );
45 void SetPage( const wxString& htmlContent );
46
47 bool AddMessageHandler( const wxString& name, MESSAGE_HANDLER handler );
49
50 void SetHandleExternalLinks( bool aHandle ) { m_handleExternalLinks = aHandle; }
52
53 void RunScriptAsync( const wxString& aScript, void* aClientData = nullptr ) const
54 {
55 m_browser->RunScriptAsync( aScript, aClientData );
56 }
57
58 bool HasLoadError() const { return m_loadError; }
59
60 void BindLoadedEvent();
61
62protected:
63 void OnNavigationRequest( wxWebViewEvent& evt );
64 void OnWebViewLoaded( wxWebViewEvent& evt );
65 void OnNewWindow( wxWebViewEvent& evt );
66 void OnScriptMessage( wxWebViewEvent& evt );
67 void OnScriptResult( wxWebViewEvent& evt );
68 void OnError( wxWebViewEvent& evt );
69
70private:
71
76 wxWebView* m_browser;
77 wxString m_backend;
78 std::map<wxString, MESSAGE_HANDLER> m_msgHandlers;
81};
82
83#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
wxString m_backend
bool m_loadedEventBound
void OnScriptMessage(wxWebViewEvent &evt)
void OnNewWindow(wxWebViewEvent &evt)
std::map< wxString, MESSAGE_HANDLER > m_msgHandlers
void SetPage(const wxString &htmlContent)
const wxString & GetBackend() const
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