Added wxAutoOleInterface<T> 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
This commit is contained in:
Václav Slavík
2010-01-02 13:07:17 +00:00
parent 371ae8b57c
commit c986b01f89
2 changed files with 92 additions and 76 deletions

View File

@@ -71,76 +71,92 @@ class FrameSite;
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#define WX_DECLARE_AUTOOLE(wxAutoOleInterface, I) \ template<typename I>
class wxAutoOleInterface \ class wxAutoOleInterface
{ \ {
protected: \ public:
I *m_interface; \ typedef I Interface;
\
public: \ explicit wxAutoOleInterface(I *pInterface = NULL) : m_interface(pInterface)
explicit wxAutoOleInterface(I *pInterface = NULL) : m_interface(pInterface) {} \ {}
wxAutoOleInterface(REFIID riid, IUnknown *pUnk) : m_interface(NULL) \ wxAutoOleInterface(REFIID riid, IUnknown *pUnk) : m_interface(NULL)
{ QueryInterface(riid, pUnk); } \ { QueryInterface(riid, pUnk); }
wxAutoOleInterface(REFIID riid, IDispatch *pDispatch) : m_interface(NULL) \ wxAutoOleInterface(REFIID riid, IDispatch *pDispatch) : m_interface(NULL)
{ QueryInterface(riid, pDispatch); } \ { QueryInterface(riid, pDispatch); }
wxAutoOleInterface(REFCLSID clsid, REFIID riid) : m_interface(NULL)\ wxAutoOleInterface(REFCLSID clsid, REFIID riid) : m_interface(NULL)
{ CreateInstance(clsid, riid); }\ { CreateInstance(clsid, riid); }
wxAutoOleInterface(const wxAutoOleInterface& ti) : m_interface(NULL)\ wxAutoOleInterface(const wxAutoOleInterface& ti) : m_interface(NULL)
{ operator = (ti); }\ { operator=(ti); }
\
wxAutoOleInterface& operator = (const wxAutoOleInterface& ti)\ wxAutoOleInterface& operator=(const wxAutoOleInterface& ti)
{\ {
if (ti.m_interface)\ if ( ti.m_interface )
ti.m_interface->AddRef();\ ti.m_interface->AddRef();
Free();\ Free();
m_interface = ti.m_interface;\ m_interface = ti.m_interface;
return *this;\ return *this;
}\ }
\
wxAutoOleInterface& operator = (I *&ti)\ wxAutoOleInterface& operator=(I*& ti)
{\ {
Free();\ Free();
m_interface = ti;\ m_interface = ti;
return *this;\ return *this;
}\ }
\
~wxAutoOleInterface() { Free(); }\ ~wxAutoOleInterface() { Free(); }
\
inline void Free()\ void Free()
{\ {
if (m_interface)\ if ( m_interface )
m_interface->Release();\ m_interface->Release();
m_interface = NULL;\ m_interface = NULL;
}\ }
\
HRESULT QueryInterface(REFIID riid, IUnknown *pUnk)\ HRESULT QueryInterface(REFIID riid, IUnknown *pUnk)
{\ {
Free();\ Free();
wxASSERT(pUnk != NULL);\ wxASSERT(pUnk != NULL);
return pUnk->QueryInterface(riid, (void **) &m_interface);\ return pUnk->QueryInterface(riid, (void **)&m_interface);
}\ }
\
HRESULT CreateInstance(REFCLSID clsid, REFIID riid)\ HRESULT CreateInstance(REFCLSID clsid, REFIID riid)
{\ {
Free();\ Free();
return CoCreateInstance(clsid, NULL, CLSCTX_ALL, riid, (void **) &m_interface);\ return CoCreateInstance
}\ (
\ clsid,
inline operator I *() const {return m_interface;}\ NULL,
inline I* operator ->() {return m_interface;}\ CLSCTX_ALL,
inline I** GetRef() {return &m_interface;}\ riid,
inline bool Ok() const { return IsOk(); }\ (void **)&m_interface
inline bool IsOk() const {return m_interface != NULL;}\ );
}
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) #if WXWIN_COMPATIBILITY_2_8
WX_DECLARE_AUTOOLE(wxAutoIOleClientSite, IOleClientSite) // this macro is kept for compatibility with older wx versions
WX_DECLARE_AUTOOLE(wxAutoIUnknown, IUnknown) #define WX_DECLARE_AUTOOLE(wxAutoOleInterfaceType, I) \
WX_DECLARE_AUTOOLE(wxAutoIOleObject, IOleObject) typedef wxAutoOleInterface<I> wxAutoOleInterfaceType;
WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceObject, IOleInPlaceObject) #endif // WXWIN_COMPATIBILITY_2_8
WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceActiveObject, IOleInPlaceActiveObject)
WX_DECLARE_AUTOOLE(wxAutoIOleDocumentView, IOleDocumentView) typedef wxAutoOleInterface<IDispatch> wxAutoIDispatch;
WX_DECLARE_AUTOOLE(wxAutoIViewObject, IViewObject) typedef wxAutoOleInterface<IOleClientSite> wxAutoIOleClientSite;
typedef wxAutoOleInterface<IUnknown> wxAutoIUnknown;
typedef wxAutoOleInterface<IOleObject> wxAutoIOleObject;
typedef wxAutoOleInterface<IOleInPlaceObject> wxAutoIOleInPlaceObject;
typedef wxAutoOleInterface<IOleInPlaceActiveObject> wxAutoIOleInPlaceActiveObject;
typedef wxAutoOleInterface<IOleDocumentView> wxAutoIOleDocumentView;
typedef wxAutoOleInterface<IViewObject> wxAutoIViewObject;
class WXDLLIMPEXP_CORE wxActiveXContainer : public wxWindow class WXDLLIMPEXP_CORE wxActiveXContainer : public wxWindow
{ {

View File

@@ -36,14 +36,14 @@
#include "wx/msw/private.h" // for wxCopyRectToRECT #include "wx/msw/private.h" // for wxCopyRectToRECT
// autointerfaces that we only use here // autointerfaces that we only use here
WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceSite, IOleInPlaceSite) typedef wxAutoOleInterface<IOleInPlaceSite> wxAutoIOleInPlaceSite;
WX_DECLARE_AUTOOLE(wxAutoIOleDocument, IOleDocument) typedef wxAutoOleInterface<IOleDocument> wxAutoIOleDocument;
WX_DECLARE_AUTOOLE(wxAutoIPersistStreamInit, IPersistStreamInit) typedef wxAutoOleInterface<IPersistStreamInit> wxAutoIPersistStreamInit;
WX_DECLARE_AUTOOLE(wxAutoIAdviseSink, IAdviseSink) typedef wxAutoOleInterface<IAdviseSink> wxAutoIAdviseSink;
WX_DECLARE_AUTOOLE(wxAutoIProvideClassInfo, IProvideClassInfo) typedef wxAutoOleInterface<IProvideClassInfo> wxAutoIProvideClassInfo;
WX_DECLARE_AUTOOLE(wxAutoITypeInfo, ITypeInfo) typedef wxAutoOleInterface<ITypeInfo> wxAutoITypeInfo;
WX_DECLARE_AUTOOLE(wxAutoIConnectionPoint, IConnectionPoint) typedef wxAutoOleInterface<IConnectionPoint> wxAutoIConnectionPoint;
WX_DECLARE_AUTOOLE(wxAutoIConnectionPointContainer, IConnectionPointContainer) typedef wxAutoOleInterface<IConnectionPointContainer> wxAutoIConnectionPointContainer;
wxDEFINE_EVENT( wxEVT_ACTIVEX, wxActiveXEvent ); wxDEFINE_EVENT( wxEVT_ACTIVEX, wxActiveXEvent );