X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b7c75283f2144469e8fa6a24ca285b42fab69a6b..728f972bcef8d6b01f5f67cb77060d23098d8877:/wxPython/contrib/activex/activex.i diff --git a/wxPython/contrib/activex/activex.i b/wxPython/contrib/activex/activex.i index d4288437d8..c3830258e0 100644 --- a/wxPython/contrib/activex/activex.i +++ b/wxPython/contrib/activex/activex.i @@ -11,7 +11,7 @@ ///////////////////////////////////////////////////////////////////////////// -%module activex +%module(package="wx") activex %{ #include "wx/wxPython/wxPython.h" @@ -24,7 +24,8 @@ //--------------------------------------------------------------------------- %import core.i -%pythoncode { wx = core } +%pythoncode { wx = _core } +%pythoncode { __docfilter__ = wx.__DocFilter(globals()) } MAKE_CONST_WXSTRING_NOSWIG(PanelNameStr); @@ -55,16 +56,17 @@ typedef unsigned short VARTYPE; %{ // Some conversion helpers static wxVariant _PyObj2Variant(PyObject* value); -static PyObject* _Variant2PyObj(wxVariant& value, bool useNone=False); +static bool _PyObj2Variant(PyObject* value, wxVariant& wv); +static PyObject* _Variant2PyObj(wxVariant& value, bool useNone=false); static wxString _VARTYPEname(VARTYPE vt); // Check if an exception has been raised (blocking threads) inline bool wxPyErr_Occurred() { bool rval; - wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); rval = PyErr_Occurred() != NULL; - wxPyEndBlockThreads(); + wxPyEndBlockThreads(blocked); return rval; } @@ -78,7 +80,7 @@ DocStr(CLSID, specify the class of the ActiveX object that is to be created. A CLSID can be constructed from either a ProgID string, (such as 'WordPad.Document.1') or a classID string, (such as -'{CA8A9783-280D-11CF-A24D-444553540000}')."); +'{CA8A9783-280D-11CF-A24D-444553540000}').", ""); class CLSID { public: @@ -238,6 +240,9 @@ class wxActiveXWindow : public wxActiveX { private: CLSID m_CLSID; + + DECLARE_ABSTRACT_CLASS(wxActiveXWindow); + public: wxActiveXWindow( wxWindow* parent, const CLSID& clsId, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, @@ -292,7 +297,7 @@ public: NameMap::const_iterator it = m_methodNames.find(name); if (it == m_methodNames.end()) { wxString msg; - msg << "method <" << name << "> not found"; + msg << _T("method <") << name << _T("> not found"); wxPyErr_SetString(PyExc_KeyError, msg.mb_str()); static wxFuncX BadVal; return BadVal; @@ -304,7 +309,7 @@ public: NameMap::const_iterator it = m_propNames.find(name); if (it == m_propNames.end()) { wxString msg; - msg << "property <" << name << "> not found"; + msg << _T("property <") << name << _T("> not found"); wxPyErr_SetString(PyExc_KeyError, msg.mb_str()); static wxPropX BadVal; return BadVal; @@ -324,11 +329,11 @@ public: void SetAXProp(const wxString& name, PyObject* value) { const wxPropX& prop = GetAXPropDesc(name); - wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); if (! PyErr_Occurred() ) { if (! prop.CanSet()) { wxString msg; - msg << "property <" << name << "> is readonly"; + msg << _T("property <") << name << _T("> is readonly"); PyErr_SetString(PyExc_TypeError, msg.mb_str()); goto done; } else { @@ -338,9 +343,9 @@ public: VARIANT v = {prop.arg.vt}; if (!VariantToMSWVariant(wxV, v) || PyErr_Occurred()) { wxString msg; - msg << "Unable to convert value to expected type: (" - << _VARTYPEname(prop.arg.vt) << ") for property <" - << name << ">"; + msg << _T("Unable to convert value to expected type: (") + << _VARTYPEname(prop.arg.vt) << _T(") for property <") + << name << _T(">"); PyErr_SetString(PyExc_TypeError, msg.mb_str()); goto done; } @@ -351,7 +356,7 @@ public: } } done: - wxPyEndBlockThreads(); + wxPyEndBlockThreads(blocked); } @@ -360,11 +365,11 @@ public: { PyObject* rval = NULL; const wxPropX& prop = GetAXPropDesc(name); - wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); if (! PyErr_Occurred() ) { if (! prop.CanGet()) { wxString msg; - msg << "property <" << name << "> is writeonly"; + msg << _T("property <") << name << _T("> is writeonly"); PyErr_SetString(PyExc_TypeError, msg.mb_str()); goto done; } else { @@ -374,9 +379,9 @@ public: wxVariant wv; if (!MSWVariantToVariant(v, wv) || PyErr_Occurred()) { wxString msg; - msg << "Unable to convert value to expected type: (" - << _VARTYPEname(prop.arg.vt) << ") for property <" - << name << ">"; + msg << _T("Unable to convert value to expected type: (") + << _VARTYPEname(prop.arg.vt) << _T(") for property <") + << name << _T(">"); PyErr_SetString(PyExc_TypeError, msg.mb_str()); goto done; } @@ -385,7 +390,7 @@ public: } } done: - wxPyEndBlockThreads(); + wxPyEndBlockThreads(blocked); return rval; } @@ -406,7 +411,7 @@ public: PyObject* rval = NULL; const wxFuncX& func = GetAXMethodDesc(name); - wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); if (! PyErr_Occurred() ) { nargs = func.params.size(); if (nargs > 0) @@ -437,9 +442,9 @@ public: goto done; if (!VariantToMSWVariant(wxV, vargs[nargs - i - 1]) || PyErr_Occurred()) { wxString msg; - msg << "Unable to convert value to expected type: (" + msg << _T("Unable to convert value to expected type: (") << _VARTYPEname(vargs[nargs - i - 1].vt) - << ") for parameter " << i; + << _T(") for parameter ") << i; PyErr_SetString(PyExc_TypeError, msg.mb_str()); goto done; } @@ -458,7 +463,7 @@ public: // conversion errors for now wxVariant wv; MSWVariantToVariant(rv, wv); - rval = _Variant2PyObj(wv, True); + rval = _Variant2PyObj(wv, true); VariantClear(&rv); if (func.hasOut) { @@ -475,7 +480,7 @@ public: const wxParamX &px = func.params[i]; if (px.IsOut()) { MSWVariantToVariant(va, wv); - PyObject* obj = _Variant2PyObj(wv, True); + PyObject* obj = _Variant2PyObj(wv, true); PyList_Append(lst, obj); } } @@ -486,7 +491,7 @@ public: PyErr_Clear(); } done: - wxPyEndBlockThreads(); + wxPyEndBlockThreads(blocked); if (vargs) { for (int i = 0; i < nargs; i++) VariantClear(&vargs[i]); @@ -495,6 +500,8 @@ public: return rval; } }; + +IMPLEMENT_ABSTRACT_CLASS( wxActiveXWindow, wxWindow ); %} @@ -510,9 +517,11 @@ get/set properties or call methods by name. The Python implementation automatically handles converting parameters and return values to/from the types expected by the ActiveX code as specified by the TypeInfo. -"); +", ""); +MustHaveApp(wxActiveXWindow); + class wxActiveXWindow : public wxWindow { public: @@ -525,28 +534,28 @@ public: long style = 0, const wxString& name = wxPyPanelNameStr), "Creates an ActiveX control from the clsID given and makes it act -as much like a regular wx.Window as possible."); +as much like a regular wx.Window as possible.", ""); DocDeclStr( const CLSID& , GetCLSID() const, - "Return the CLSID used to construct this ActiveX window"); + "Return the CLSID used to construct this ActiveX window", ""); DocDeclStr( int , GetAXEventCount() const, - "Number of events defined for this control"); + "Number of events defined for this control", ""); DocDeclStr( const wxFuncX& , GetAXEventDesc(int idx) const, - "Returns event description by index"); + "Returns event description by index", ""); DocDeclStr( int , GetAXPropCount() const, - "Number of properties defined for this control"); + "Number of properties defined for this control", ""); %nokwargs GetAXPropDesc; - DocStr(GetPropDesc, "Returns property description by index or by name"); + DocStr(GetPropDesc, "Returns property description by index or by name", ""); const wxPropX& GetAXPropDesc(int idx) const; const wxPropX& GetAXPropDesc(const wxString& name) const; @@ -554,10 +563,10 @@ as much like a regular wx.Window as possible."); DocDeclStr( int , GetAXMethodCount() const, - "Number of methods defined for this control"); + "Number of methods defined for this control", ""); %nokwargs GetAXMethodDesc; - DocStr(GetMethodDesc, "Returns method description by index or name"); + DocStr(GetMethodDesc, "Returns method description by index or name", ""); const wxFuncX& GetAXMethodDesc(int idx) const; const wxFuncX& GetAXMethodDesc(const wxString& name) const; @@ -565,35 +574,35 @@ as much like a regular wx.Window as possible."); DocDeclStr( const wxFuncXArray& , GetAXEvents(), "Returns a sequence of FuncX objects describing the events -available for this ActiveX object."); +available for this ActiveX object.", ""); DocDeclStr( const wxFuncXArray& , GetAXMethods(), "Returns a sequence of FuncX objects describing the methods -available for this ActiveX object."); +available for this ActiveX object.", ""); DocDeclStr( const wxPropXArray& , GetAXProperties(), "Returns a sequence of PropX objects describing the properties -available for this ActiveX object."); +available for this ActiveX object.", ""); DocDeclStr( void , SetAXProp(const wxString& name, PyObject* value), - "Set a property of the ActiveX object by name."); + "Set a property of the ActiveX object by name.", ""); DocDeclStr( PyObject* , GetAXProp(const wxString& name), - "Get the value of an ActiveX property by name."); + "Get the value of an ActiveX property by name.", ""); %nokwargs _CallAXMethod; DocDeclStr( PyObject* , _CallAXMethod(const wxString& name, PyObject* args), "The implementation for CallMethod. Calls an ActiveX method, by -name passing the parameters given in args."); +name passing the parameters given in args.", ""); %pythoncode { def CallAXMethod(self, name, *args): """ @@ -609,7 +618,7 @@ name passing the parameters given in args."); DocDeclStr( wxEventType , RegisterActiveXEvent(const wxString& eventName), - "Creates a standard wx event ID for the given eventName."); + "Creates a standard wx event ID for the given eventName.", ""); @@ -618,7 +627,7 @@ DocStr(wxActiveXEvent, ActiveX events. Any event parameters from the ActiveX cntrol are turned into attributes of the Python proxy for this event object. Additionally, there is a property called eventName that will -return (suprizingly ) the name of the ActiveX event."); +return (surprisingly ) the name of the ActiveX event.", ""); class wxActiveXEvent : public wxCommandEvent { @@ -627,25 +636,41 @@ public: wxString EventName(); %extend { - DocStr(_preInit, -"This is called by the EventThunker before calling the handler. -We'll convert and load the ActiveX event parameters into -attributes of the Python event object."); - void _preInit(PyObject* pyself) { - wxPyBeginBlockThreads(); + + // This is called by the EventThunker before calling the + // handler. We'll convert and load the ActiveX event parameters into + // attributes of the Python event object. + void _preCallInit(PyObject* pyself) { + wxPyBlock_t blocked = wxPyBeginBlockThreads(); PyObject* pList = PyList_New(0); PyObject_SetAttrString(pyself, "paramList", pList); Py_DECREF(pList); for (int i=0; iParamCount(); i+=1) { - PyObject* name = PyString_FromString((char*)self->ParamName(i).mb_str()); - PyObject* val = _Variant2PyObj((*self)[i], True); + PyObject* name = PyString_FromString((char*)(const char*)self->ParamName(i).mb_str()); + PyObject* val = _Variant2PyObj((*self)[i], true); PyObject_SetAttr(pyself, name, val); PyList_Append(pList, name); Py_DECREF(val); Py_DECREF(name); } - wxPyEndBlockThreads(); + wxPyEndBlockThreads(blocked); } + + // This one is called by the EventThunker after calling the + // handler. It reloads any "out" parameters from the python attributes + // back into the wxVariant they came from. + void _postCallCleanup(PyObject* pyself) { + wxPyBlock_t blocked = wxPyBeginBlockThreads(); + for (int i=0; iParamCount(); i+=1) { + PyObject* val = PyObject_GetAttrString( + pyself, (char*)(const char*)self->ParamName(i).mb_str()); + _PyObj2Variant(val, (*self)[i]); + Py_DECREF(val); + } + wxPyEndBlockThreads(blocked); + } + + } }; @@ -661,9 +686,11 @@ wxVariant _PyObj2Variant(PyObject* value) if (value == Py_None) return rval; +#if PYTHON_API_VERSION >= 1012 // Python 2.3+ else if (PyBool_Check(value)) rval = (value == Py_True) ? true : false; - +#endif + else if (PyInt_Check(value)) rval = PyInt_AS_LONG(value); @@ -676,6 +703,7 @@ wxVariant _PyObj2Variant(PyObject* value) // TODO: PyList of strings --> wxArrayString // wxDateTime // list of objects + // etc. else { PyErr_SetString(PyExc_TypeError, "Unsupported object type in _PyObj2Variant"); @@ -685,6 +713,26 @@ wxVariant _PyObj2Variant(PyObject* value) return rval; } +// This one uses the type of the variant to try and force the conversion +bool _PyObj2Variant(PyObject* value, wxVariant& wv) +{ + wxString type = wv.GetType(); + + if ( type == _T("long") || type == _T("bool") || type == _T("char") ) + wv = PyInt_AsLong(value); + + else if ( type == _T("string") ) + wv = Py2wxString(value); + + else if ( type == _T("double") ) + wv = PyFloat_AsDouble(value); + + else { + // it's some other type that we dont' handle yet. Log it? + return false; + } + return true; +} // Caller should already have the GIL! PyObject* _Variant2PyObj(wxVariant& value, bool useNone) @@ -703,8 +751,10 @@ PyObject* _Variant2PyObj(wxVariant& value, bool useNone) else if (value.IsType(_T("double"))) rval = PyFloat_FromDouble(value); - else if (value.IsType(_T("bool"))) - rval = PyBool_FromLong((bool)value); + else if (value.IsType(_T("bool"))) { + rval = (bool)value ? Py_True : Py_False; + Py_INCREF(rval); + } else if (value.IsType(_T("string"))) rval = wx2PyString(value); @@ -792,7 +842,7 @@ wxString _VARTYPEname(VARTYPE vt) %{ -// A class derived from out wxActiveXWindow for the IE WebBrowser +// A class derived from our wxActiveXWindow for the IE WebBrowser // control that will serve as a base class for a Python // implementation. This is done so we can "eat our own dog food" // and use a class at least mostly generated by genaxmodule, but @@ -816,6 +866,8 @@ class wxIEHtmlWindowBase : public wxActiveXWindow { private: wxAutoOleInterface m_webBrowser; + DECLARE_ABSTRACT_CLASS(wxIEHtmlWindowBase); + public: wxIEHtmlWindowBase ( wxWindow* parent, const CLSID& clsId, wxWindowID id = -1, @@ -829,7 +881,18 @@ public: // Get IWebBrowser2 Interface hret = m_webBrowser.QueryInterface(IID_IWebBrowser2, m_ActiveX); - wxASSERT(SUCCEEDED(hret)); + wxASSERT(SUCCEEDED(hret)); + + // web browser setup + m_webBrowser->put_MenuBar(VARIANT_FALSE); + m_webBrowser->put_AddressBar(VARIANT_FALSE); + m_webBrowser->put_StatusBar(VARIANT_FALSE); + m_webBrowser->put_ToolBar(VARIANT_FALSE); + + m_webBrowser->put_RegisterAsBrowser(VARIANT_TRUE); + m_webBrowser->put_RegisterAsDropTarget(VARIANT_TRUE); + + m_webBrowser->Navigate( L"about:blank", NULL, NULL, NULL, NULL ); } @@ -868,7 +931,11 @@ public: // need to prepend this as poxy MSHTML will not recognise a HTML comment // as starting a html document and treats it as plain text // Does nayone know how to force it to html mode ? - pstrm->prepend = ""; +#if wxUSE_UNICODE + // TODO: What to do in this case??? +#else + pstrm->prepend = _T(""); +#endif // strip leading whitespace as it can confuse MSHTML wxAutoOleInterface strm(pstrm); @@ -983,6 +1050,9 @@ public: // return ! m_bAmbientUserMode; // }; }; + +IMPLEMENT_ABSTRACT_CLASS( wxIEHtmlWindowBase, wxActiveXWindow ); + %} @@ -995,8 +1065,11 @@ public: %feature("noautodoc") wxIEHtmlWindowBase::GetText; +MustHaveApp(wxIEHtmlWindowBase); + class wxIEHtmlWindowBase : public wxActiveXWindow { public: + %pythonAppend wxIEHtmlWindowBase "self._setOORInfo(self)" wxIEHtmlWindowBase ( wxWindow* parent, const CLSID& clsId, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,