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/sharedptr.h"
|
||||||
#include "wx/vector.h"
|
#include "wx/vector.h"
|
||||||
|
|
||||||
|
class IHTMLDocument2;
|
||||||
|
|
||||||
class WXDLLIMPEXP_WEB wxWebViewIE : public wxWebView
|
class WXDLLIMPEXP_WEB wxWebViewIE : public wxWebView
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -141,6 +143,7 @@ private:
|
|||||||
//Generic helper functions for IHtmlDocument commands
|
//Generic helper functions for IHtmlDocument commands
|
||||||
bool CanExecCommand(wxString command);
|
bool CanExecCommand(wxString command);
|
||||||
void ExecCommand(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
|
// FIXME: calling wxYield is not elegant nor very reliable probably
|
||||||
wxYield();
|
wxYield();
|
||||||
|
|
||||||
wxVariant documentVariant = m_ie.GetProperty("Document");
|
|
||||||
void* documentPtr = documentVariant.GetVoidPtr();
|
|
||||||
|
|
||||||
wxASSERT (documentPtr != NULL);
|
|
||||||
|
|
||||||
// TODO: consider the "baseUrl" parameter if possible
|
// TODO: consider the "baseUrl" parameter if possible
|
||||||
// TODO: consider encoding
|
// TODO: consider encoding
|
||||||
BSTR bstr = SysAllocString(html.wc_str());
|
BSTR bstr = SysAllocString(html.wc_str());
|
||||||
@@ -157,8 +152,7 @@ void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
|
|||||||
param->bstrVal = bstr;
|
param->bstrVal = bstr;
|
||||||
|
|
||||||
hr = SafeArrayUnaccessData(psaStrings);
|
hr = SafeArrayUnaccessData(psaStrings);
|
||||||
|
IHTMLDocument2* document = GetDocument();
|
||||||
IHTMLDocument2* document = (IHTMLDocument2*)documentPtr;
|
|
||||||
document->write(psaStrings);
|
document->write(psaStrings);
|
||||||
|
|
||||||
// SafeArrayDestroy calls SysFreeString for each BSTR
|
// SafeArrayDestroy calls SysFreeString for each BSTR
|
||||||
@@ -173,16 +167,7 @@ void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
|
|||||||
|
|
||||||
wxString wxWebViewIE::GetPageSource()
|
wxString wxWebViewIE::GetPageSource()
|
||||||
{
|
{
|
||||||
wxVariant documentVariant = m_ie.GetProperty("Document");
|
IHTMLDocument2* document = GetDocument();
|
||||||
void* documentPtr = documentVariant.GetVoidPtr();
|
|
||||||
|
|
||||||
if (documentPtr == NULL)
|
|
||||||
{
|
|
||||||
return wxEmptyString;
|
|
||||||
}
|
|
||||||
|
|
||||||
IHTMLDocument2* document = (IHTMLDocument2*)documentPtr;
|
|
||||||
|
|
||||||
IHTMLElement *bodyTag = NULL;
|
IHTMLElement *bodyTag = NULL;
|
||||||
IHTMLElement *htmlTag = NULL;
|
IHTMLElement *htmlTag = NULL;
|
||||||
document->get_body(&bodyTag);
|
document->get_body(&bodyTag);
|
||||||
@@ -504,11 +489,7 @@ wxString wxWebViewIE::GetCurrentURL()
|
|||||||
|
|
||||||
wxString wxWebViewIE::GetCurrentTitle()
|
wxString wxWebViewIE::GetCurrentTitle()
|
||||||
{
|
{
|
||||||
wxVariant documentVariant = m_ie.GetProperty("Document");
|
IHTMLDocument2* document = GetDocument();
|
||||||
void* documentPtr = documentVariant.GetVoidPtr();
|
|
||||||
IHTMLDocument2* document = (IHTMLDocument2*)documentPtr;
|
|
||||||
|
|
||||||
wxASSERT(documentPtr && document);
|
|
||||||
|
|
||||||
BSTR title;
|
BSTR title;
|
||||||
document->get_nameProp(&title);
|
document->get_nameProp(&title);
|
||||||
@@ -565,11 +546,7 @@ void wxWebViewIE::Redo()
|
|||||||
|
|
||||||
bool wxWebViewIE::CanExecCommand(wxString command)
|
bool wxWebViewIE::CanExecCommand(wxString command)
|
||||||
{
|
{
|
||||||
wxVariant documentVariant = m_ie.GetProperty("Document");
|
IHTMLDocument2* document = GetDocument();
|
||||||
void* documentPtr = documentVariant.GetVoidPtr();
|
|
||||||
IHTMLDocument2* document = (IHTMLDocument2*)documentPtr;
|
|
||||||
|
|
||||||
wxASSERT(documentPtr && document);
|
|
||||||
|
|
||||||
VARIANT_BOOL enabled;
|
VARIANT_BOOL enabled;
|
||||||
document->queryCommandEnabled(SysAllocString(command.wc_str()), &enabled);
|
document->queryCommandEnabled(SysAllocString(command.wc_str()), &enabled);
|
||||||
@@ -579,15 +556,20 @@ bool wxWebViewIE::CanExecCommand(wxString command)
|
|||||||
|
|
||||||
void wxWebViewIE::ExecCommand(wxString command)
|
void wxWebViewIE::ExecCommand(wxString command)
|
||||||
{
|
{
|
||||||
wxVariant documentVariant = m_ie.GetProperty("Document");
|
IHTMLDocument2* document = GetDocument();
|
||||||
void* documentPtr = documentVariant.GetVoidPtr();
|
|
||||||
IHTMLDocument2* document = (IHTMLDocument2*)documentPtr;
|
|
||||||
|
|
||||||
wxASSERT(documentPtr && document);
|
|
||||||
|
|
||||||
document->execCommand(SysAllocString(command.wc_str()), VARIANT_FALSE, VARIANT(), NULL);
|
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)
|
void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt)
|
||||||
{
|
{
|
||||||
if (m_webBrowser == NULL) return;
|
if (m_webBrowser == NULL) return;
|
||||||
|
Reference in New Issue
Block a user