Correctly use QueryInterface in GetDocument to ensure that we only return an IHTMLDocument2 pointer if one is available. Check GetDocument being NULL when used. This fixes the displaying of non-html documents such as pdfs.

Fixes #14060

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71030 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Steve Lamerton
2012-03-27 19:33:59 +00:00
parent 0ffc170455
commit e81ef29720

View File

@@ -122,6 +122,10 @@ void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
hr = SafeArrayUnaccessData(psaStrings);
IHTMLDocument2* document = GetDocument();
if(!document)
return;
document->write(psaStrings);
document->close();
document->Release();
@@ -140,6 +144,10 @@ void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
hr = SafeArrayUnaccessData(psaStrings);
document = GetDocument();
if(!document)
return;
document->write(psaStrings);
document->Release();
@@ -172,6 +180,9 @@ void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
wxString wxWebViewIE::GetPageSource() const
{
IHTMLDocument2* document = GetDocument();
if(document)
{
IHTMLElement *bodyTag = NULL;
IHTMLElement *htmlTag = NULL;
wxString source;
@@ -191,6 +202,11 @@ wxString wxWebViewIE::GetPageSource() const
document->Release();
return source;
}
else
{
return "";
}
}
wxWebViewZoom wxWebViewIE::GetZoom() const
@@ -521,11 +537,18 @@ wxString wxWebViewIE::GetCurrentURL() const
wxString wxWebViewIE::GetCurrentTitle() const
{
IHTMLDocument2* document = GetDocument();
BSTR title;
if(document)
{
BSTR title;
document->get_nameProp(&title);
document->Release();
return wxString(title);
}
else
{
return "";
}
}
bool wxWebViewIE::CanCut() const
@@ -579,17 +602,24 @@ void wxWebViewIE::Redo()
void wxWebViewIE::SetEditable(bool enable)
{
IHTMLDocument2* document = GetDocument();
if(document)
{
if( enable )
document->put_designMode(SysAllocString(L"On"));
else
document->put_designMode(SysAllocString(L"Off"));
document->Release();
}
}
bool wxWebViewIE::IsEditable() const
{
IHTMLDocument2* document = GetDocument();
if(document)
{
BSTR mode;
document->get_designMode(&mode);
document->Release();
@@ -597,6 +627,11 @@ bool wxWebViewIE::IsEditable() const
return true;
else
return false;
}
else
{
return false;
}
}
void wxWebViewIE::SelectAll()
@@ -607,6 +642,9 @@ void wxWebViewIE::SelectAll()
bool wxWebViewIE::HasSelection() const
{
IHTMLDocument2* document = GetDocument();
if(document)
{
IHTMLSelectionObject* selection;
wxString sel;
HRESULT hr = document->get_selection(&selection);
@@ -619,6 +657,11 @@ bool wxWebViewIE::HasSelection() const
}
document->Release();
return sel != "None";
}
else
{
return false;
}
}
void wxWebViewIE::DeleteSelection()
@@ -629,6 +672,9 @@ void wxWebViewIE::DeleteSelection()
wxString wxWebViewIE::GetSelectedText() const
{
IHTMLDocument2* document = GetDocument();
if(document)
{
IHTMLSelectionObject* selection;
wxString selected;
HRESULT hr = document->get_selection(&selection);
@@ -653,11 +699,19 @@ wxString wxWebViewIE::GetSelectedText() const
}
document->Release();
return selected;
}
else
{
return "";
}
}
wxString wxWebViewIE::GetSelectedSource() const
{
IHTMLDocument2* document = GetDocument();
if(document)
{
IHTMLSelectionObject* selection;
wxString selected;
HRESULT hr = document->get_selection(&selection);
@@ -682,11 +736,19 @@ wxString wxWebViewIE::GetSelectedSource() const
}
document->Release();
return selected;
}
else
{
return "";
}
}
void wxWebViewIE::ClearSelection()
{
IHTMLDocument2* document = GetDocument();
if(document)
{
IHTMLSelectionObject* selection;
wxString selected;
HRESULT hr = document->get_selection(&selection);
@@ -696,11 +758,15 @@ void wxWebViewIE::ClearSelection()
selection->Release();
}
document->Release();
}
}
wxString wxWebViewIE::GetPageText() const
{
IHTMLDocument2* document = GetDocument();
if(document)
{
wxString text;
IHTMLElement* body;
HRESULT hr = document->get_body(&body);
@@ -713,11 +779,19 @@ wxString wxWebViewIE::GetPageText() const
}
document->Release();
return text;
}
else
{
return "";
}
}
void wxWebViewIE::RunScript(const wxString& javascript)
{
IHTMLDocument2* document = GetDocument();
if(document)
{
IHTMLWindow2* window;
wxString language = "javascript";
HRESULT hr = document->get_parentWindow(&window);
@@ -731,6 +805,7 @@ void wxWebViewIE::RunScript(const wxString& javascript)
&level);
}
document->Release();
}
}
void wxWebViewIE::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
@@ -767,29 +842,49 @@ void wxWebViewIE::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
bool wxWebViewIE::CanExecCommand(wxString command) const
{
IHTMLDocument2* document = GetDocument();
if(document)
{
VARIANT_BOOL enabled;
document->queryCommandEnabled(SysAllocString(command.wc_str()), &enabled);
document->Release();
return (enabled == VARIANT_TRUE);
}
else
{
return false;
}
}
void wxWebViewIE::ExecCommand(wxString command)
{
IHTMLDocument2* document = GetDocument();
if(document)
{
document->execCommand(SysAllocString(command.wc_str()), VARIANT_FALSE, VARIANT(), NULL);
document->Release();
}
}
IHTMLDocument2* wxWebViewIE::GetDocument() const
{
wxVariant variant = m_ie.GetProperty("Document");
IHTMLDocument2* document = (IHTMLDocument2*)variant.GetVoidPtr();
wxASSERT(document);
IDispatch* dispatch;
HRESULT result = m_webBrowser->get_Document(&dispatch);
if(SUCCEEDED(result))
{
IHTMLDocument2* document;
dispatch->QueryInterface(IID_IHTMLDocument2, (void**)&document);
//document is set to null automatically if the interface isn't supported
return document;
}
else
{
return NULL;
}
}
bool wxWebViewIE::EnableControlFeature(long flag, bool enable)