New wxActiveX code from Lindsay and added ability to load page from stream
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16220 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#include "IEHtmlWin.h"
|
||||
#include <wx/strconv.h>
|
||||
#include <wx/string.h>
|
||||
#include <wx/event.h>
|
||||
#include <wx/listctrl.h>
|
||||
#include <wx/mstream.h>
|
||||
#include <oleidl.h>
|
||||
#include <winerror.h>
|
||||
#include <exdispid.h>
|
||||
@@ -242,7 +244,8 @@ void wxIEHtmlWin::SetCharset(wxString charset)
|
||||
{
|
||||
wxAutoOleInterface<IHTMLDocument2> doc(IID_IHTMLDocument2, disp);
|
||||
if (doc.Ok())
|
||||
doc->put_charset((BSTR) (const wchar_t*)charset.wc_str(wxConvUTF8));
|
||||
doc->put_charset((BSTR) (const wchar_t *) charset.wc_str(wxConvUTF8));
|
||||
//doc->put_charset((BSTR) wxConvUTF8.cMB2WC(charset).data());
|
||||
};
|
||||
};
|
||||
|
||||
@@ -305,6 +308,32 @@ public:
|
||||
};
|
||||
};
|
||||
|
||||
class IwxStreamAdaptor : public IStreamAdaptorBase
|
||||
{
|
||||
private:
|
||||
wxInputStream *m_is;
|
||||
|
||||
public:
|
||||
|
||||
IwxStreamAdaptor(wxInputStream *is) : IStreamAdaptorBase(), m_is(is)
|
||||
{
|
||||
wxASSERT(m_is != NULL);
|
||||
}
|
||||
~IwxStreamAdaptor()
|
||||
{
|
||||
delete m_is;
|
||||
}
|
||||
|
||||
// ISequentialStream
|
||||
HRESULT STDMETHODCALLTYPE Read(void __RPC_FAR *pv, ULONG cb, ULONG __RPC_FAR *pcbRead)
|
||||
{
|
||||
m_is->Read((char *) pv, cb);
|
||||
if (pcbRead)
|
||||
*pcbRead = m_is->LastRead();
|
||||
|
||||
return S_OK;
|
||||
};
|
||||
};
|
||||
|
||||
void wxIEHtmlWin::LoadUrl(const wxString& url)
|
||||
{
|
||||
@@ -317,24 +346,38 @@ void wxIEHtmlWin::LoadUrl(const wxString& url)
|
||||
headers.vt = VT_EMPTY;
|
||||
|
||||
HRESULT hret = 0;
|
||||
hret = m_webBrowser->Navigate((BSTR) (const wchar_t*)url.wc_str(wxConvUTF8),
|
||||
hret = m_webBrowser->Navigate((BSTR) (const wchar_t *) url.wc_str(wxConvUTF8),
|
||||
&navFlag, &targetFrame, &postData, &headers);
|
||||
};
|
||||
|
||||
class wxOwnedMemInputStream : public wxMemoryInputStream
|
||||
{
|
||||
public:
|
||||
char *m_data;
|
||||
|
||||
wxOwnedMemInputStream(char *data, size_t len) :
|
||||
wxMemoryInputStream(data, len), m_data(data)
|
||||
{}
|
||||
~wxOwnedMemInputStream()
|
||||
{
|
||||
free(m_data);
|
||||
}
|
||||
};
|
||||
|
||||
bool wxIEHtmlWin::LoadString(wxString html)
|
||||
{
|
||||
string s = html.mb_str(wxConvUTF8);
|
||||
istringstream *is = new istringstream(s);
|
||||
return LoadStream(is);
|
||||
char *data = NULL;
|
||||
size_t len = html.length();
|
||||
#ifdef UNICODE
|
||||
len *= 2;
|
||||
#endif
|
||||
data = (char *) malloc(len);
|
||||
memcpy(data, html.c_str(), len);
|
||||
return LoadStream(new wxOwnedMemInputStream(data, len));
|
||||
};
|
||||
|
||||
bool wxIEHtmlWin::LoadStream(istream *is)
|
||||
bool wxIEHtmlWin::LoadStream(IStreamAdaptorBase *pstrm)
|
||||
{
|
||||
// wrap reference around stream
|
||||
IStreamAdaptor *pstrm = new IStreamAdaptor(is);
|
||||
pstrm->AddRef();
|
||||
|
||||
wxAutoOleInterface<IStream> strm(pstrm);
|
||||
|
||||
// Document Interface
|
||||
@@ -361,6 +404,25 @@ bool wxIEHtmlWin::LoadStream(istream *is)
|
||||
return false;
|
||||
};
|
||||
|
||||
bool wxIEHtmlWin::LoadStream(istream *is)
|
||||
{
|
||||
// wrap reference around stream
|
||||
IStreamAdaptor *pstrm = new IStreamAdaptor(is);
|
||||
pstrm->AddRef();
|
||||
|
||||
return LoadStream(pstrm);
|
||||
};
|
||||
|
||||
bool wxIEHtmlWin::LoadStream(wxInputStream *is)
|
||||
{
|
||||
// wrap reference around stream
|
||||
IwxStreamAdaptor *pstrm = new IwxStreamAdaptor(is);
|
||||
pstrm->AddRef();
|
||||
|
||||
return LoadStream(pstrm);
|
||||
};
|
||||
|
||||
|
||||
bool wxIEHtmlWin::GoBack()
|
||||
{
|
||||
HRESULT hret = 0;
|
||||
|
@@ -61,8 +61,11 @@ enum wxIEHtmlRefreshLevel
|
||||
wxIEHTML_REFRESH_COMPLETELY = 3
|
||||
};
|
||||
|
||||
class IStreamAdaptorBase;
|
||||
|
||||
class wxIEHtmlWin : public wxActiveX
|
||||
{
|
||||
|
||||
public:
|
||||
wxIEHtmlWin(wxWindow * parent, wxWindowID id = -1,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
@@ -74,6 +77,7 @@ public:
|
||||
void LoadUrl(const wxString&);
|
||||
bool LoadString(wxString html);
|
||||
bool LoadStream(istream *strm);
|
||||
bool LoadStream(wxInputStream *is);
|
||||
|
||||
void SetCharset(wxString charset);
|
||||
void SetEditMode(bool seton);
|
||||
@@ -92,6 +96,7 @@ public:
|
||||
|
||||
protected:
|
||||
void SetupBrowser();
|
||||
bool LoadStream(IStreamAdaptorBase *pstrm);
|
||||
|
||||
wxAutoOleInterface<IWebBrowser2> m_webBrowser;
|
||||
};
|
||||
|
@@ -57,6 +57,7 @@ extern PyObject *SWIG_newvarlink(void);
|
||||
|
||||
#include "wxPython.h"
|
||||
#include "IEHtmlWin.h"
|
||||
#include "pyistream.h"
|
||||
|
||||
|
||||
static PyObject* t_output_helper(PyObject* target, PyObject* o) {
|
||||
@@ -412,6 +413,55 @@ static PyObject *_wrap_wxIEHtmlWin_LoadString(PyObject *self, PyObject *args, Py
|
||||
return _resultobj;
|
||||
}
|
||||
|
||||
#define wxIEHtmlWin_LoadStream(_swigobj,_swigarg0) (_swigobj->LoadStream(_swigarg0))
|
||||
static PyObject *_wrap_wxIEHtmlWin_LoadStream(PyObject *self, PyObject *args, PyObject *kwargs) {
|
||||
PyObject * _resultobj;
|
||||
bool _result;
|
||||
wxIEHtmlWin * _arg0;
|
||||
wxInputStream * _arg1;
|
||||
PyObject * _argo0 = 0;
|
||||
wxPyInputStream * temp;
|
||||
bool created;
|
||||
PyObject * _obj1 = 0;
|
||||
char *_kwnames[] = { "self","is", NULL };
|
||||
|
||||
self = self;
|
||||
if(!PyArg_ParseTupleAndKeywords(args,kwargs,"OO:wxIEHtmlWin_LoadStream",_kwnames,&_argo0,&_obj1))
|
||||
return NULL;
|
||||
if (_argo0) {
|
||||
if (_argo0 == Py_None) { _arg0 = NULL; }
|
||||
else if (SWIG_GetPtrObj(_argo0,(void **) &_arg0,"_wxIEHtmlWin_p")) {
|
||||
PyErr_SetString(PyExc_TypeError,"Type error in argument 1 of wxIEHtmlWin_LoadStream. Expected _wxIEHtmlWin_p.");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
{
|
||||
if (SWIG_GetPtrObj(_obj1, (void **) &temp, "_wxPyInputStream_p") == 0) {
|
||||
_arg1 = temp->m_wxis;
|
||||
created = FALSE;
|
||||
} else {
|
||||
_arg1 = wxPyCBInputStream_create(_obj1, FALSE);
|
||||
if (_arg1 == NULL) {
|
||||
PyErr_SetString(PyExc_TypeError,"Expected _wxInputStream_p or Python file-like object.");
|
||||
return NULL;
|
||||
}
|
||||
created = TRUE;
|
||||
}
|
||||
}
|
||||
{
|
||||
PyThreadState* __tstate = wxPyBeginAllowThreads();
|
||||
_result = (bool )wxIEHtmlWin_LoadStream(_arg0,_arg1);
|
||||
|
||||
wxPyEndAllowThreads(__tstate);
|
||||
if (PyErr_Occurred()) return NULL;
|
||||
} _resultobj = Py_BuildValue("i",_result);
|
||||
{
|
||||
if (created)
|
||||
delete _arg1;
|
||||
}
|
||||
return _resultobj;
|
||||
}
|
||||
|
||||
#define wxIEHtmlWin_SetCharset(_swigobj,_swigarg0) (_swigobj->SetCharset(_swigarg0))
|
||||
static PyObject *_wrap_wxIEHtmlWin_SetCharset(PyObject *self, PyObject *args, PyObject *kwargs) {
|
||||
PyObject * _resultobj;
|
||||
@@ -771,6 +821,7 @@ static PyMethodDef iewincMethods[] = {
|
||||
{ "wxIEHtmlWin_GetEditMode", (PyCFunction) _wrap_wxIEHtmlWin_GetEditMode, METH_VARARGS | METH_KEYWORDS },
|
||||
{ "wxIEHtmlWin_SetEditMode", (PyCFunction) _wrap_wxIEHtmlWin_SetEditMode, METH_VARARGS | METH_KEYWORDS },
|
||||
{ "wxIEHtmlWin_SetCharset", (PyCFunction) _wrap_wxIEHtmlWin_SetCharset, METH_VARARGS | METH_KEYWORDS },
|
||||
{ "wxIEHtmlWin_LoadStream", (PyCFunction) _wrap_wxIEHtmlWin_LoadStream, METH_VARARGS | METH_KEYWORDS },
|
||||
{ "wxIEHtmlWin_LoadString", (PyCFunction) _wrap_wxIEHtmlWin_LoadString, METH_VARARGS | METH_KEYWORDS },
|
||||
{ "wxIEHtmlWin_LoadUrl", (PyCFunction) _wrap_wxIEHtmlWin_LoadUrl, METH_VARARGS | METH_KEYWORDS },
|
||||
{ "new_wxIEHtmlWin", (PyCFunction) _wrap_new_wxIEHtmlWin, METH_VARARGS | METH_KEYWORDS },
|
||||
|
@@ -16,6 +16,7 @@
|
||||
%{
|
||||
#include "wxPython.h"
|
||||
#include "IEHtmlWin.h"
|
||||
#include "pyistream.h"
|
||||
%}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -28,6 +29,7 @@
|
||||
%extern _defs.i
|
||||
%extern misc.i
|
||||
%extern events.i
|
||||
%extern streams.i
|
||||
|
||||
%pragma(python) code = "import wx"
|
||||
|
||||
@@ -101,7 +103,7 @@ public:
|
||||
|
||||
void LoadUrl(const wxString&);
|
||||
bool LoadString(wxString html);
|
||||
/* bool LoadStream(istream *strm); */
|
||||
bool LoadStream(wxInputStream *is);
|
||||
|
||||
%pragma(python) addtoclass = "Navigate = LoadUrl"
|
||||
|
||||
|
@@ -95,6 +95,9 @@ class wxIEHtmlWinPtr(wxWindowPtr):
|
||||
def LoadString(self, *_args, **_kwargs):
|
||||
val = apply(iewinc.wxIEHtmlWin_LoadString,(self,) + _args, _kwargs)
|
||||
return val
|
||||
def LoadStream(self, *_args, **_kwargs):
|
||||
val = apply(iewinc.wxIEHtmlWin_LoadStream,(self,) + _args, _kwargs)
|
||||
return val
|
||||
def SetCharset(self, *_args, **_kwargs):
|
||||
val = apply(iewinc.wxIEHtmlWin_SetCharset,(self,) + _args, _kwargs)
|
||||
return val
|
||||
|
@@ -207,7 +207,7 @@ wxActiveX::wxActiveX(wxWindow * parent, wxString progId, wxWindowID id,
|
||||
{
|
||||
m_bAmbientUserMode = true;
|
||||
m_docAdviseCookie = 0;
|
||||
CreateActiveX((LPOLESTR) (const wchar_t*)progId.wc_str(wxConvUTF8));
|
||||
CreateActiveX((LPOLESTR) (const wchar_t *) progId.wc_str(wxConvUTF8));
|
||||
}
|
||||
|
||||
wxActiveX::~wxActiveX()
|
||||
@@ -268,6 +268,16 @@ void wxActiveX::CreateActiveX(REFCLSID clsid)
|
||||
// Get IOleObject interface
|
||||
hret = m_oleObject.QueryInterface(IID_IOleObject, m_ActiveX);
|
||||
wxASSERT(SUCCEEDED(hret));
|
||||
|
||||
// document advise
|
||||
m_docAdviseCookie = 0;
|
||||
hret = m_oleObject->Advise(adviseSink, &m_docAdviseCookie);
|
||||
WXOLE_WARN(hret, "m_oleObject->Advise(adviseSink, &m_docAdviseCookie),\"Advise\")");
|
||||
m_oleObject->SetHostNames(L"wxActiveXContainer", NULL);
|
||||
OleSetContainedObject(m_oleObject, TRUE);
|
||||
OleRun(m_oleObject);
|
||||
|
||||
|
||||
// Get IOleInPlaceObject interface
|
||||
hret = m_oleInPlaceObject.QueryInterface(IID_IOleInPlaceObject, m_ActiveX);
|
||||
wxASSERT(SUCCEEDED(hret));
|
||||
@@ -292,13 +302,6 @@ void wxActiveX::CreateActiveX(REFCLSID clsid)
|
||||
WXOLE_WARN(hret, "CreateActiveX::pPersistStreamInit->InitNew()");
|
||||
};
|
||||
|
||||
// document advise
|
||||
m_docAdviseCookie = 0;
|
||||
hret = m_oleObject->Advise(adviseSink, &m_docAdviseCookie);
|
||||
WXOLE_WARN(hret, "m_oleObject->Advise(adviseSink, &m_docAdviseCookie),\"Advise\")");
|
||||
m_oleObject->SetHostNames(L"wxActiveXContainer", NULL);
|
||||
OleSetContainedObject(m_oleObject, TRUE);
|
||||
|
||||
if (! (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST))
|
||||
m_oleObject->SetClientSite(m_clientSite);
|
||||
|
||||
@@ -312,22 +315,26 @@ void wxActiveX::CreateActiveX(REFCLSID clsid)
|
||||
posRect.bottom = h;
|
||||
|
||||
m_oleObjectHWND = 0;
|
||||
|
||||
if (m_oleInPlaceObject.Ok())
|
||||
{
|
||||
hret = m_oleInPlaceObject->GetWindow(&m_oleObjectHWND);
|
||||
WXOLE_WARN(hret, "m_oleInPlaceObject->GetWindow(&m_oleObjectHWND)");
|
||||
if (SUCCEEDED(hret))
|
||||
::SetActiveWindow(m_oleObjectHWND);
|
||||
};
|
||||
|
||||
|
||||
if (! (dwMiscStatus & OLEMISC_INVISIBLEATRUNTIME))
|
||||
{
|
||||
if (w > 0 && h > 0)
|
||||
if (w > 0 && h > 0 && m_oleInPlaceObject.Ok())
|
||||
m_oleInPlaceObject->SetObjectRects(&posRect, &posRect);
|
||||
|
||||
hret = m_oleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, m_clientSite, 0, (HWND)GetHWND(), &posRect);
|
||||
hret = m_oleObject->DoVerb(OLEIVERB_SHOW, 0, m_clientSite, 0, (HWND)GetHWND(), &posRect);
|
||||
};
|
||||
|
||||
if (! m_oleObjectHWND)
|
||||
if (! m_oleObjectHWND && m_oleInPlaceObject.Ok())
|
||||
{
|
||||
hret = m_oleInPlaceObject->GetWindow(&m_oleObjectHWND);
|
||||
WXOLE_WARN(hret, "m_oleInPlaceObject->GetWindow(&m_oleObjectHWND)");
|
||||
@@ -385,13 +392,14 @@ public:
|
||||
|
||||
static ActiveXEventMapFlusher s_dummyActiveXEventMapFlusher;
|
||||
|
||||
const wxEventType& RegisterActiveXEvent(wxString eventName)
|
||||
const wxEventType& RegisterActiveXEvent(wxChar *eventName)
|
||||
{
|
||||
ActiveXEventMap::iterator it = sg_eventMap.find(eventName);
|
||||
wxString ev = eventName;
|
||||
ActiveXEventMap::iterator it = sg_eventMap.find(ev);
|
||||
if (it == sg_eventMap.end())
|
||||
{
|
||||
wxEventType *et = new wxEventType(wxNewEventType());
|
||||
sg_eventMap[eventName] = et;
|
||||
sg_eventMap[ev] = et;
|
||||
|
||||
return *et;
|
||||
};
|
||||
@@ -857,17 +865,21 @@ void wxActiveX::OnSize(wxSizeEvent& event)
|
||||
if (w <= 0 && h <= 0)
|
||||
return;
|
||||
|
||||
if (m_oleInPlaceObject)
|
||||
if (m_oleInPlaceObject.Ok())
|
||||
m_oleInPlaceObject->SetObjectRects(&posRect, &posRect);
|
||||
|
||||
// extents are in HIMETRIC units
|
||||
if (m_oleObject.Ok())
|
||||
{
|
||||
SIZEL sz = {w, h};
|
||||
PixelsToHimetric(sz);
|
||||
|
||||
SIZEL sz2;
|
||||
|
||||
m_oleObject->GetExtent(DVASPECT_CONTENT, &sz2);
|
||||
if (sz2.cx != sz.cx || sz.cy != sz2.cy)
|
||||
m_oleObject->SetExtent(DVASPECT_CONTENT, &sz);
|
||||
};
|
||||
}
|
||||
|
||||
void wxActiveX::OnSetFocus(wxFocusEvent& event)
|
||||
|
@@ -50,7 +50,7 @@ template <class I> class wxAutoOleInterface
|
||||
};
|
||||
|
||||
// copy constructor
|
||||
explicit wxAutoOleInterface(const wxAutoOleInterface<I>& ti) : m_interface(NULL)
|
||||
wxAutoOleInterface(const wxAutoOleInterface<I>& ti) : m_interface(NULL)
|
||||
{
|
||||
operator = (ti);
|
||||
}
|
||||
@@ -362,11 +362,11 @@ public:
|
||||
wxVariant& operator[] (wxString name);
|
||||
};
|
||||
|
||||
const wxEventType& RegisterActiveXEvent(wxString eventName);
|
||||
const wxEventType& RegisterActiveXEvent(wxChar *eventName);
|
||||
|
||||
typedef void (wxEvtHandler::*wxActiveXEventFunction)(wxActiveXEvent&);
|
||||
|
||||
#define EVT_ACTIVEX(id, eventName, fn) DECLARE_EVENT_TABLE_ENTRY(RegisterActiveXEvent(eventName), id, -1, (wxObjectEventFunction) (wxEventFunction) (wxActiveXEventFunction) & fn, (wxObject *) NULL ),
|
||||
#define EVT_ACTIVEX(id, eventName, fn) DECLARE_EVENT_TABLE_ENTRY(RegisterActiveXEvent(wxT(eventName)), id, -1, (wxObjectEventFunction) (wxEventFunction) (wxActiveXEventFunction) & fn, (wxObject *) NULL ),
|
||||
|
||||
//util
|
||||
bool MSWVariantToVariant(VARIANTARG& va, wxVariant& vx);
|
||||
|
Reference in New Issue
Block a user