3 #pragma warning( disable : 4101 4786)
4 #pragma warning( disable : 4786)
15 //////////////////////////////////////////
16 // wxAutoOleInterface<Interface>
17 // Template class for smart interface handling
18 // - Automatically dereferences ole interfaces
19 // - Smart Copy Semantics
20 // - Can Create Interfaces
21 // - Can query for other interfaces
22 template <class I
> class wxAutoOleInterface
28 // takes ownership of an existing interface
29 // Assumed to already have a AddRef() applied
30 explicit wxAutoOleInterface(I
*pInterface
= NULL
) : m_interface(pInterface
) {}
32 // queries for an interface
33 wxAutoOleInterface(REFIID riid
, IUnknown
*pUnk
) : m_interface(NULL
)
35 QueryInterface(riid
, pUnk
);
37 // queries for an interface
38 wxAutoOleInterface(REFIID riid
, IDispatch
*pDispatch
) : m_interface(NULL
)
40 QueryInterface(riid
, pDispatch
);
43 // Creates an Interface
44 wxAutoOleInterface(REFCLSID clsid
, REFIID riid
) : m_interface(NULL
)
46 CreateInstance(clsid
, riid
);
50 explicit wxAutoOleInterface(const wxAutoOleInterface
<I
>& ti
) : m_interface(NULL
)
55 // assignment operator
56 wxAutoOleInterface
<I
>& operator = (const wxAutoOleInterface
<I
>& ti
)
59 ti
.m_interface
->AddRef();
61 m_interface
= ti
.m_interface
;
65 // takes ownership of an existing interface
66 // Assumed to already have a AddRef() applied
67 wxAutoOleInterface
<I
>& operator = (I
*&ti
)
83 m_interface
->Release();
87 // queries for an interface
88 HRESULT
QueryInterface(REFIID riid
, IUnknown
*pUnk
)
91 wxASSERT(pUnk
!= NULL
);
92 return pUnk
->QueryInterface(riid
, (void **) &m_interface
);
95 // Create a Interface instance
96 HRESULT
CreateInstance(REFCLSID clsid
, REFIID riid
)
99 return CoCreateInstance(clsid
, NULL
, CLSCTX_ALL
, riid
, (void **) &m_interface
);
104 inline operator I
*() const {return m_interface
;}
105 inline I
* operator ->() {return m_interface
;}
106 inline I
** GetRef() {return &m_interface
;}
108 inline bool Ok() const {return m_interface
!= NULL
;}
112 wxString
OLEHResultToString(HRESULT hr
);
113 wxString
GetIIDName(REFIID riid
);
115 //#define __WXOLEDEBUG
119 #define WXOLE_TRACE(str) {OutputDebugString(str);OutputDebugString("\r\n");}
120 #define WXOLE_TRACEOUT(stuff)\
123 os << stuff << ends;\
124 WXOLE_TRACE(os.str().c_str());\
127 #define WXOLE_WARN(__hr,msg)\
131 wxString s = "*** ";\
133 s += " : "+ OLEHResultToString(__hr);\
134 WXOLE_TRACE(s.c_str());\
138 #define WXOLE_TRACE(str)
139 #define WXOLE_TRACEOUT(stuff)
140 #define WXOLE_WARN(_proc,msg) {_proc;}
143 // Auto Initialisation
147 static IMalloc
*GetIMalloc();
153 #define DECLARE_OLE_UNKNOWN(cls)\
159 TAutoInitInt() : l(0) {}\
161 TAutoInitInt refCount, lockCount;\
163 static void _GetInterface(cls *self, REFIID iid, void **_interface, const char *&desc);\
166 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void ** ppvObject);\
167 ULONG STDMETHODCALLTYPE AddRef();\
168 ULONG STDMETHODCALLTYPE Release();\
169 ULONG STDMETHODCALLTYPE AddLock();\
170 ULONG STDMETHODCALLTYPE ReleaseLock()
172 #define DEFINE_OLE_TABLE(cls)\
173 LONG cls::GetRefCount() {return refCount.l;}\
174 HRESULT STDMETHODCALLTYPE cls::QueryInterface(REFIID iid, void ** ppvObject)\
178 WXOLE_TRACE("*** NULL POINTER ***");\
181 const char *desc = NULL;\
182 cls::_GetInterface(this, iid, ppvObject, desc);\
185 WXOLE_TRACEOUT("<" << GetIIDName(iid).c_str() << "> Not Found");\
186 return E_NOINTERFACE;\
188 WXOLE_TRACEOUT("QI : <" << desc <<">");\
189 ((IUnknown * )(*ppvObject))->AddRef();\
192 ULONG STDMETHODCALLTYPE cls::AddRef()\
194 WXOLE_TRACEOUT(# cls << "::Add ref(" << refCount.l << ")");\
195 InterlockedIncrement(&refCount.l);\
198 ULONG STDMETHODCALLTYPE cls::Release()\
202 InterlockedDecrement(&refCount.l);\
203 WXOLE_TRACEOUT(# cls << "::Del ref(" << refCount.l << ")");\
204 if (refCount.l == 0)\
214 ULONG STDMETHODCALLTYPE cls::AddLock()\
216 WXOLE_TRACEOUT(# cls << "::Add Lock(" << lockCount.l << ")");\
217 InterlockedIncrement(&lockCount.l);\
220 ULONG STDMETHODCALLTYPE cls::ReleaseLock()\
222 if (lockCount.l > 0)\
224 InterlockedDecrement(&lockCount.l);\
225 WXOLE_TRACEOUT(# cls << "::Del Lock(" << lockCount.l << ")");\
233 #define DEFINE_OLE_BASE(cls)\
234 void cls::_GetInterface(cls *self, REFIID iid, void **_interface, const char *&desc)\
239 #define OLE_INTERFACE(_iid, _type)\
240 if (IsEqualIID(iid, _iid))\
242 WXOLE_TRACE("Found Interface <" # _type ">");\
243 *_interface = (IUnknown *) (_type *) self;\
248 #define OLE_IINTERFACE(_face) OLE_INTERFACE(IID_##_face, _face)
250 #define OLE_INTERFACE_CUSTOM(func)\
251 if (func(self, iid, _interface, desc))\
254 #define END_OLE_TABLE\
259 class wxActiveX
: public wxWindow
{
261 wxActiveX(wxWindow
* parent
, REFCLSID clsid
, wxWindowID id
= -1,
262 const wxPoint
& pos
= wxDefaultPosition
,
263 const wxSize
& size
= wxDefaultSize
,
265 const wxString
& name
= wxPanelNameStr
);
266 wxActiveX(wxWindow
* parent
, wxString progId
, wxWindowID id
= -1,
267 const wxPoint
& pos
= wxDefaultPosition
,
268 const wxSize
& size
= wxDefaultSize
,
270 const wxString
& name
= wxPanelNameStr
);
272 virtual ~wxActiveX();
274 void CreateActiveX(REFCLSID clsid
);
275 void CreateActiveX(LPOLESTR progId
);
277 HRESULT
ConnectAdvise(REFIID riid
, IUnknown
*eventSink
);
279 void OnSize(wxSizeEvent
&);
280 void OnSetFocus(wxFocusEvent
&);
281 void OnKillFocus(wxFocusEvent
&);
283 DECLARE_EVENT_TABLE();
286 friend class FrameSite
;
288 typedef wxAutoOleInterface
<IConnectionPoint
> wxOleConnectionPoint
;
289 typedef pair
<wxOleConnectionPoint
, DWORD
> wxOleConnection
;
290 typedef vector
<wxOleConnection
> wxOleConnectionArray
;
292 wxAutoOleInterface
<IOleClientSite
> m_clientSite
;
293 wxAutoOleInterface
<IUnknown
> m_ActiveX
;
294 wxAutoOleInterface
<IOleObject
> m_oleObject
;
295 wxAutoOleInterface
<IOleInPlaceObject
> m_oleInPlaceObject
;
296 wxAutoOleInterface
<IOleInPlaceActiveObject
>
298 m_oleInPlaceActiveObject
;
299 wxAutoOleInterface
<IOleDocumentView
> m_docView
;
300 HWND m_oleObjectHWND
;
301 bool m_bAmbientUserMode
;
302 DWORD m_docAdviseCookie
;
303 wxOleConnectionArray m_connections
;
305 HRESULT
AmbientPropertyChanged(DISPID dispid
);
309 #endif /* _IEHTMLWIN_H_ */