Create wxWebViewEdge implementation in constructor

This helps with various potential error when using two step creation
This commit is contained in:
Tobias Taschner
2021-03-16 22:09:55 +01:00
parent 7f7191066b
commit 3d568c7105
2 changed files with 22 additions and 6 deletions

View File

@@ -23,7 +23,7 @@ class WXDLLIMPEXP_WEBVIEW wxWebViewEdge : public wxWebView
{ {
public: public:
wxWebViewEdge() {} wxWebViewEdge();
wxWebViewEdge(wxWindow* parent, wxWebViewEdge(wxWindow* parent,
wxWindowID id, wxWindowID id,
@@ -31,10 +31,7 @@ public:
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, long style = 0,
const wxString& name = wxWebViewNameStr) const wxString& name = wxWebViewNameStr);
{
Create(parent, id, url, pos, size, style, name);
}
~wxWebViewEdge(); ~wxWebViewEdge();

View File

@@ -476,6 +476,24 @@ ICoreWebView2Settings* wxWebViewEdgeImpl::GetSettings()
return settings; return settings;
} }
wxWebViewEdge::wxWebViewEdge():
m_impl(new wxWebViewEdgeImpl(this))
{
}
wxWebViewEdge::wxWebViewEdge(wxWindow* parent,
wxWindowID id,
const wxString& url,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name):
m_impl(new wxWebViewEdgeImpl(this))
{
Create(parent, id, url, pos, size, style, name);
}
wxWebViewEdge::~wxWebViewEdge() wxWebViewEdge::~wxWebViewEdge()
{ {
wxWindow* topLevelParent = wxGetTopLevelParent(this); wxWindow* topLevelParent = wxGetTopLevelParent(this);
@@ -501,7 +519,6 @@ bool wxWebViewEdge::Create(wxWindow* parent,
return false; return false;
} }
m_impl = new wxWebViewEdgeImpl(this);
if (!m_impl->Create()) if (!m_impl->Create())
return false; return false;
Bind(wxEVT_SIZE, &wxWebViewEdge::OnSize, this); Bind(wxEVT_SIZE, &wxWebViewEdge::OnSize, this);
@@ -774,6 +791,8 @@ void wxWebViewEdge::MSWSetBrowserExecutableDir(const wxString & path)
bool wxWebViewEdge::RunScriptSync(const wxString& javascript, wxString* output) const bool wxWebViewEdge::RunScriptSync(const wxString& javascript, wxString* output) const
{ {
bool scriptExecuted = false; bool scriptExecuted = false;
if (!m_impl->m_webView)
return false;
// Start script execution // Start script execution
HRESULT executionResult = m_impl->m_webView->ExecuteScript(javascript.wc_str(), Callback<ICoreWebView2ExecuteScriptCompletedHandler>( HRESULT executionResult = m_impl->m_webView->ExecuteScript(javascript.wc_str(), Callback<ICoreWebView2ExecuteScriptCompletedHandler>(