Factor logic that returns an IHTMLDocument2 into a separate function to reduce repetition.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68156 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
#include "wx/sharedptr.h"
|
||||
#include "wx/vector.h"
|
||||
|
||||
class IHTMLDocument2;
|
||||
|
||||
class WXDLLIMPEXP_WEB wxWebViewIE : public wxWebView
|
||||
{
|
||||
public:
|
||||
@@ -141,6 +143,7 @@ private:
|
||||
//Generic helper functions for IHtmlDocument commands
|
||||
bool CanExecCommand(wxString command);
|
||||
void ExecCommand(wxString command);
|
||||
IHTMLDocument2* GetDocument();
|
||||
|
||||
};
|
||||
|
||||
|
@@ -138,11 +138,6 @@ void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
|
||||
// FIXME: calling wxYield is not elegant nor very reliable probably
|
||||
wxYield();
|
||||
|
||||
wxVariant documentVariant = m_ie.GetProperty("Document");
|
||||
void* documentPtr = documentVariant.GetVoidPtr();
|
||||
|
||||
wxASSERT (documentPtr != NULL);
|
||||
|
||||
// TODO: consider the "baseUrl" parameter if possible
|
||||
// TODO: consider encoding
|
||||
BSTR bstr = SysAllocString(html.wc_str());
|
||||
@@ -157,8 +152,7 @@ void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
|
||||
param->bstrVal = bstr;
|
||||
|
||||
hr = SafeArrayUnaccessData(psaStrings);
|
||||
|
||||
IHTMLDocument2* document = (IHTMLDocument2*)documentPtr;
|
||||
IHTMLDocument2* document = GetDocument();
|
||||
document->write(psaStrings);
|
||||
|
||||
// SafeArrayDestroy calls SysFreeString for each BSTR
|
||||
@@ -173,16 +167,7 @@ void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
|
||||
|
||||
wxString wxWebViewIE::GetPageSource()
|
||||
{
|
||||
wxVariant documentVariant = m_ie.GetProperty("Document");
|
||||
void* documentPtr = documentVariant.GetVoidPtr();
|
||||
|
||||
if (documentPtr == NULL)
|
||||
{
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
IHTMLDocument2* document = (IHTMLDocument2*)documentPtr;
|
||||
|
||||
IHTMLDocument2* document = GetDocument();
|
||||
IHTMLElement *bodyTag = NULL;
|
||||
IHTMLElement *htmlTag = NULL;
|
||||
document->get_body(&bodyTag);
|
||||
@@ -504,11 +489,7 @@ wxString wxWebViewIE::GetCurrentURL()
|
||||
|
||||
wxString wxWebViewIE::GetCurrentTitle()
|
||||
{
|
||||
wxVariant documentVariant = m_ie.GetProperty("Document");
|
||||
void* documentPtr = documentVariant.GetVoidPtr();
|
||||
IHTMLDocument2* document = (IHTMLDocument2*)documentPtr;
|
||||
|
||||
wxASSERT(documentPtr && document);
|
||||
IHTMLDocument2* document = GetDocument();
|
||||
|
||||
BSTR title;
|
||||
document->get_nameProp(&title);
|
||||
@@ -565,11 +546,7 @@ void wxWebViewIE::Redo()
|
||||
|
||||
bool wxWebViewIE::CanExecCommand(wxString command)
|
||||
{
|
||||
wxVariant documentVariant = m_ie.GetProperty("Document");
|
||||
void* documentPtr = documentVariant.GetVoidPtr();
|
||||
IHTMLDocument2* document = (IHTMLDocument2*)documentPtr;
|
||||
|
||||
wxASSERT(documentPtr && document);
|
||||
IHTMLDocument2* document = GetDocument();
|
||||
|
||||
VARIANT_BOOL enabled;
|
||||
document->queryCommandEnabled(SysAllocString(command.wc_str()), &enabled);
|
||||
@@ -579,15 +556,20 @@ bool wxWebViewIE::CanExecCommand(wxString command)
|
||||
|
||||
void wxWebViewIE::ExecCommand(wxString command)
|
||||
{
|
||||
wxVariant documentVariant = m_ie.GetProperty("Document");
|
||||
void* documentPtr = documentVariant.GetVoidPtr();
|
||||
IHTMLDocument2* document = (IHTMLDocument2*)documentPtr;
|
||||
|
||||
wxASSERT(documentPtr && document);
|
||||
|
||||
IHTMLDocument2* document = GetDocument();
|
||||
document->execCommand(SysAllocString(command.wc_str()), VARIANT_FALSE, VARIANT(), NULL);
|
||||
}
|
||||
|
||||
IHTMLDocument2* wxWebViewIE::GetDocument()
|
||||
{
|
||||
wxVariant variant = m_ie.GetProperty("Document");
|
||||
IHTMLDocument2* document = (IHTMLDocument2*)variant.GetVoidPtr();
|
||||
|
||||
wxASSERT(document);
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt)
|
||||
{
|
||||
if (m_webBrowser == NULL) return;
|
||||
|
Reference in New Issue
Block a user