From c986b01f893e1f457ce94ade0b28d9d7ed890aad Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Sat, 2 Jan 2010 13:07:17 +0000 Subject: [PATCH] Added wxAutoOleInterface template. This replaces WX_DECLARE_AUTOOLE with easier-to-debug version. The macro is still preserved for backward compatibility. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63038 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/ole/activex.h | 152 +++++++++++++++++++---------------- src/msw/ole/activex.cpp | 16 ++-- 2 files changed, 92 insertions(+), 76 deletions(-) diff --git a/include/wx/msw/ole/activex.h b/include/wx/msw/ole/activex.h index 54940e2fac..a1573c5b02 100644 --- a/include/wx/msw/ole/activex.h +++ b/include/wx/msw/ole/activex.h @@ -71,76 +71,92 @@ class FrameSite; // //--------------------------------------------------------------------------- -#define WX_DECLARE_AUTOOLE(wxAutoOleInterface, I) \ -class wxAutoOleInterface \ -{ \ - protected: \ - I *m_interface; \ -\ - public: \ - explicit wxAutoOleInterface(I *pInterface = NULL) : m_interface(pInterface) {} \ - wxAutoOleInterface(REFIID riid, IUnknown *pUnk) : m_interface(NULL) \ - { QueryInterface(riid, pUnk); } \ - wxAutoOleInterface(REFIID riid, IDispatch *pDispatch) : m_interface(NULL) \ - { QueryInterface(riid, pDispatch); } \ - wxAutoOleInterface(REFCLSID clsid, REFIID riid) : m_interface(NULL)\ - { CreateInstance(clsid, riid); }\ - wxAutoOleInterface(const wxAutoOleInterface& ti) : m_interface(NULL)\ - { operator = (ti); }\ -\ - wxAutoOleInterface& operator = (const wxAutoOleInterface& ti)\ - {\ - if (ti.m_interface)\ - ti.m_interface->AddRef();\ - Free();\ - m_interface = ti.m_interface;\ - return *this;\ - }\ -\ - wxAutoOleInterface& operator = (I *&ti)\ - {\ - Free();\ - m_interface = ti;\ - return *this;\ - }\ -\ - ~wxAutoOleInterface() { Free(); }\ -\ - inline void Free()\ - {\ - if (m_interface)\ - m_interface->Release();\ - m_interface = NULL;\ - }\ -\ - HRESULT QueryInterface(REFIID riid, IUnknown *pUnk)\ - {\ - Free();\ - wxASSERT(pUnk != NULL);\ - return pUnk->QueryInterface(riid, (void **) &m_interface);\ - }\ -\ - HRESULT CreateInstance(REFCLSID clsid, REFIID riid)\ - {\ - Free();\ - return CoCreateInstance(clsid, NULL, CLSCTX_ALL, riid, (void **) &m_interface);\ - }\ -\ - inline operator I *() const {return m_interface;}\ - inline I* operator ->() {return m_interface;}\ - inline I** GetRef() {return &m_interface;}\ - inline bool Ok() const { return IsOk(); }\ - inline bool IsOk() const {return m_interface != NULL;}\ +template +class wxAutoOleInterface +{ +public: + typedef I Interface; + + explicit wxAutoOleInterface(I *pInterface = NULL) : m_interface(pInterface) + {} + wxAutoOleInterface(REFIID riid, IUnknown *pUnk) : m_interface(NULL) + { QueryInterface(riid, pUnk); } + wxAutoOleInterface(REFIID riid, IDispatch *pDispatch) : m_interface(NULL) + { QueryInterface(riid, pDispatch); } + wxAutoOleInterface(REFCLSID clsid, REFIID riid) : m_interface(NULL) + { CreateInstance(clsid, riid); } + wxAutoOleInterface(const wxAutoOleInterface& ti) : m_interface(NULL) + { operator=(ti); } + + wxAutoOleInterface& operator=(const wxAutoOleInterface& ti) + { + if ( ti.m_interface ) + ti.m_interface->AddRef(); + Free(); + m_interface = ti.m_interface; + return *this; + } + + wxAutoOleInterface& operator=(I*& ti) + { + Free(); + m_interface = ti; + return *this; + } + + ~wxAutoOleInterface() { Free(); } + + void Free() + { + if ( m_interface ) + m_interface->Release(); + m_interface = NULL; + } + + HRESULT QueryInterface(REFIID riid, IUnknown *pUnk) + { + Free(); + wxASSERT(pUnk != NULL); + return pUnk->QueryInterface(riid, (void **)&m_interface); + } + + HRESULT CreateInstance(REFCLSID clsid, REFIID riid) + { + Free(); + return CoCreateInstance + ( + clsid, + NULL, + CLSCTX_ALL, + riid, + (void **)&m_interface + ); + } + + operator I*() const {return m_interface; } + I* operator->() {return m_interface; } + I** GetRef() {return &m_interface; } + bool Ok() const { return IsOk(); } + bool IsOk() const { return m_interface != NULL; } + +protected: + I *m_interface; }; -WX_DECLARE_AUTOOLE(wxAutoIDispatch, IDispatch) -WX_DECLARE_AUTOOLE(wxAutoIOleClientSite, IOleClientSite) -WX_DECLARE_AUTOOLE(wxAutoIUnknown, IUnknown) -WX_DECLARE_AUTOOLE(wxAutoIOleObject, IOleObject) -WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceObject, IOleInPlaceObject) -WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceActiveObject, IOleInPlaceActiveObject) -WX_DECLARE_AUTOOLE(wxAutoIOleDocumentView, IOleDocumentView) -WX_DECLARE_AUTOOLE(wxAutoIViewObject, IViewObject) +#if WXWIN_COMPATIBILITY_2_8 +// this macro is kept for compatibility with older wx versions +#define WX_DECLARE_AUTOOLE(wxAutoOleInterfaceType, I) \ + typedef wxAutoOleInterface wxAutoOleInterfaceType; +#endif // WXWIN_COMPATIBILITY_2_8 + +typedef wxAutoOleInterface wxAutoIDispatch; +typedef wxAutoOleInterface wxAutoIOleClientSite; +typedef wxAutoOleInterface wxAutoIUnknown; +typedef wxAutoOleInterface wxAutoIOleObject; +typedef wxAutoOleInterface wxAutoIOleInPlaceObject; +typedef wxAutoOleInterface wxAutoIOleInPlaceActiveObject; +typedef wxAutoOleInterface wxAutoIOleDocumentView; +typedef wxAutoOleInterface wxAutoIViewObject; class WXDLLIMPEXP_CORE wxActiveXContainer : public wxWindow { diff --git a/src/msw/ole/activex.cpp b/src/msw/ole/activex.cpp index caf9d7595d..92a5a1186b 100644 --- a/src/msw/ole/activex.cpp +++ b/src/msw/ole/activex.cpp @@ -36,14 +36,14 @@ #include "wx/msw/private.h" // for wxCopyRectToRECT // autointerfaces that we only use here -WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceSite, IOleInPlaceSite) -WX_DECLARE_AUTOOLE(wxAutoIOleDocument, IOleDocument) -WX_DECLARE_AUTOOLE(wxAutoIPersistStreamInit, IPersistStreamInit) -WX_DECLARE_AUTOOLE(wxAutoIAdviseSink, IAdviseSink) -WX_DECLARE_AUTOOLE(wxAutoIProvideClassInfo, IProvideClassInfo) -WX_DECLARE_AUTOOLE(wxAutoITypeInfo, ITypeInfo) -WX_DECLARE_AUTOOLE(wxAutoIConnectionPoint, IConnectionPoint) -WX_DECLARE_AUTOOLE(wxAutoIConnectionPointContainer, IConnectionPointContainer) +typedef wxAutoOleInterface wxAutoIOleInPlaceSite; +typedef wxAutoOleInterface wxAutoIOleDocument; +typedef wxAutoOleInterface wxAutoIPersistStreamInit; +typedef wxAutoOleInterface wxAutoIAdviseSink; +typedef wxAutoOleInterface wxAutoIProvideClassInfo; +typedef wxAutoOleInterface wxAutoITypeInfo; +typedef wxAutoOleInterface wxAutoIConnectionPoint; +typedef wxAutoOleInterface wxAutoIConnectionPointContainer; wxDEFINE_EVENT( wxEVT_ACTIVEX, wxActiveXEvent ); -- 2.45.2