3 #pragma warning( disable : 4101 4786)
4 #pragma warning( disable : 4786)
9 #include <wx/variant.h>
18 //////////////////////////////////////////
19 // wxAutoOleInterface<Interface>
20 // Template class for smart interface handling
21 // - Automatically dereferences ole interfaces
22 // - Smart Copy Semantics
23 // - Can Create Interfaces
24 // - Can query for other interfaces
25 template <class I
> class wxAutoOleInterface
31 // takes ownership of an existing interface
32 // Assumed to already have a AddRef() applied
33 explicit wxAutoOleInterface(I
*pInterface
= NULL
) : m_interface(pInterface
) {}
35 // queries for an interface
36 wxAutoOleInterface(REFIID riid
, IUnknown
*pUnk
) : m_interface(NULL
)
38 QueryInterface(riid
, pUnk
);
40 // queries for an interface
41 wxAutoOleInterface(REFIID riid
, IDispatch
*pDispatch
) : m_interface(NULL
)
43 QueryInterface(riid
, pDispatch
);
46 // Creates an Interface
47 wxAutoOleInterface(REFCLSID clsid
, REFIID riid
) : m_interface(NULL
)
49 CreateInstance(clsid
, riid
);
53 wxAutoOleInterface(const wxAutoOleInterface
<I
>& ti
) : m_interface(NULL
)
58 // assignment operator
59 wxAutoOleInterface
<I
>& operator = (const wxAutoOleInterface
<I
>& ti
)
62 ti
.m_interface
->AddRef();
64 m_interface
= ti
.m_interface
;
68 // takes ownership of an existing interface
69 // Assumed to already have a AddRef() applied
70 wxAutoOleInterface
<I
>& operator = (I
*&ti
)
86 m_interface
->Release();
90 // queries for an interface
91 HRESULT
QueryInterface(REFIID riid
, IUnknown
*pUnk
)
94 wxASSERT(pUnk
!= NULL
);
95 return pUnk
->QueryInterface(riid
, (void **) &m_interface
);
98 // Create a Interface instance
99 HRESULT
CreateInstance(REFCLSID clsid
, REFIID riid
)
102 return CoCreateInstance(clsid
, NULL
, CLSCTX_ALL
, riid
, (void **) &m_interface
);
107 inline operator I
*() const {return m_interface
;}
108 inline I
* operator ->() {return m_interface
;}
109 inline I
** GetRef() {return &m_interface
;}
111 inline bool Ok() const {return m_interface
!= NULL
;}
115 wxString
OLEHResultToString(HRESULT hr
);
116 wxString
GetIIDName(REFIID riid
);
118 //#define __WXOLEDEBUG
122 #define WXOLE_TRACE(str) {OutputDebugString(str);OutputDebugString("\r\n");}
123 #define WXOLE_TRACEOUT(stuff)\
126 os << stuff << ends;\
127 WXOLE_TRACE(os.str().c_str());\
130 #define WXOLE_WARN(__hr,msg)\
134 wxString s = "*** ";\
136 s += " : "+ OLEHResultToString(__hr);\
137 WXOLE_TRACE(s.c_str());\
141 #define WXOLE_TRACE(str)
142 #define WXOLE_TRACEOUT(stuff)
143 #define WXOLE_WARN(_proc,msg) {_proc;}
146 // Auto Initialisation
150 static IMalloc
*GetIMalloc();
156 #define DECLARE_OLE_UNKNOWN(cls)\
162 TAutoInitInt() : l(0) {}\
164 TAutoInitInt refCount, lockCount;\
166 static void _GetInterface(cls *self, REFIID iid, void **_interface, const char *&desc);\
169 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void ** ppvObject);\
170 ULONG STDMETHODCALLTYPE AddRef();\
171 ULONG STDMETHODCALLTYPE Release();\
172 ULONG STDMETHODCALLTYPE AddLock();\
173 ULONG STDMETHODCALLTYPE ReleaseLock()
175 #define DEFINE_OLE_TABLE(cls)\
176 LONG cls::GetRefCount() {return refCount.l;}\
177 HRESULT STDMETHODCALLTYPE cls::QueryInterface(REFIID iid, void ** ppvObject)\
181 WXOLE_TRACE("*** NULL POINTER ***");\
184 const char *desc = NULL;\
185 cls::_GetInterface(this, iid, ppvObject, desc);\
188 WXOLE_TRACEOUT("<" << GetIIDName(iid).c_str() << "> Not Found");\
189 return E_NOINTERFACE;\
191 WXOLE_TRACEOUT("QI : <" << desc <<">");\
192 ((IUnknown * )(*ppvObject))->AddRef();\
195 ULONG STDMETHODCALLTYPE cls::AddRef()\
197 WXOLE_TRACEOUT(# cls << "::Add ref(" << refCount.l << ")");\
198 InterlockedIncrement(&refCount.l);\
201 ULONG STDMETHODCALLTYPE cls::Release()\
205 InterlockedDecrement(&refCount.l);\
206 WXOLE_TRACEOUT(# cls << "::Del ref(" << refCount.l << ")");\
207 if (refCount.l == 0)\
217 ULONG STDMETHODCALLTYPE cls::AddLock()\
219 WXOLE_TRACEOUT(# cls << "::Add Lock(" << lockCount.l << ")");\
220 InterlockedIncrement(&lockCount.l);\
223 ULONG STDMETHODCALLTYPE cls::ReleaseLock()\
225 if (lockCount.l > 0)\
227 InterlockedDecrement(&lockCount.l);\
228 WXOLE_TRACEOUT(# cls << "::Del Lock(" << lockCount.l << ")");\
236 #define DEFINE_OLE_BASE(cls)\
237 void cls::_GetInterface(cls *self, REFIID iid, void **_interface, const char *&desc)\
242 #define OLE_INTERFACE(_iid, _type)\
243 if (IsEqualIID(iid, _iid))\
245 WXOLE_TRACE("Found Interface <" # _type ">");\
246 *_interface = (IUnknown *) (_type *) self;\
251 #define OLE_IINTERFACE(_face) OLE_INTERFACE(IID_##_face, _face)
253 #define OLE_INTERFACE_CUSTOM(func)\
254 if (func(self, iid, _interface, desc))\
257 #define END_OLE_TABLE\
262 class wxActiveX
: public wxWindow
{
264 wxActiveX(wxWindow
* parent
, REFCLSID clsid
, wxWindowID id
= -1,
265 const wxPoint
& pos
= wxDefaultPosition
,
266 const wxSize
& size
= wxDefaultSize
,
268 const wxString
& name
= wxPanelNameStr
);
269 wxActiveX(wxWindow
* parent
, wxString progId
, wxWindowID id
= -1,
270 const wxPoint
& pos
= wxDefaultPosition
,
271 const wxSize
& size
= wxDefaultSize
,
273 const wxString
& name
= wxPanelNameStr
);
274 virtual ~wxActiveX();
276 void CreateActiveX(REFCLSID clsid
);
277 void CreateActiveX(LPOLESTR progId
);
280 void GetTypeInfo(ITypeInfo
*ti
, bool defEventSink
);
282 HRESULT
ConnectAdvise(REFIID riid
, IUnknown
*eventSink
);
284 void OnSize(wxSizeEvent
&);
285 void OnSetFocus(wxFocusEvent
&);
286 void OnKillFocus(wxFocusEvent
&);
288 DECLARE_EVENT_TABLE();
291 friend class FrameSite
;
292 friend class wxActiveXEvents
;
294 typedef wxAutoOleInterface
<IConnectionPoint
> wxOleConnectionPoint
;
295 typedef pair
<wxOleConnectionPoint
, DWORD
> wxOleConnection
;
296 typedef vector
<wxOleConnection
> wxOleConnectionArray
;
298 wxAutoOleInterface
<IOleClientSite
> m_clientSite
;
299 wxAutoOleInterface
<IUnknown
> m_ActiveX
;
300 wxAutoOleInterface
<IOleObject
> m_oleObject
;
301 wxAutoOleInterface
<IOleInPlaceObject
> m_oleInPlaceObject
;
302 wxAutoOleInterface
<IOleInPlaceActiveObject
>
304 m_oleInPlaceActiveObject
;
305 wxAutoOleInterface
<IOleDocumentView
> m_docView
;
306 HWND m_oleObjectHWND
;
307 bool m_bAmbientUserMode
;
308 DWORD m_docAdviseCookie
;
309 wxOleConnectionArray m_connections
;
311 HRESULT
AmbientPropertyChanged(DISPID dispid
);
314 class ParamX
// refer to ELEMDESC, IDLDESC in MSDN
321 inline bool IsIn() const {return (flags
& IDLFLAG_FIN
) != 0;}
322 inline bool IsOut() const {return (flags
& IDLFLAG_FOUT
) != 0;}
323 inline bool IsRetVal() const {return (flags
& IDLFLAG_FRETVAL
) != 0;}
326 typedef vector
<ParamX
> ParamXArray
;
328 class FuncX
// refer to FUNCDESC in MSDN
338 typedef vector
<FuncX
> FuncXArray
;
339 typedef map
<MEMBERID
, int> MemberIdList
;
343 MemberIdList m_eventsIdx
;
347 class wxActiveXEvent
: public wxNotifyEvent
350 friend class wxActiveXEvents
;
356 virtual wxEvent
*Clone() const { return new wxActiveXEvent(*this); }
358 int ParamCount() const;
359 wxVariant
operator[] (int idx
) const;
360 wxVariant
& operator[] (int idx
);
361 wxVariant
operator[] (wxString name
) const;
362 wxVariant
& operator[] (wxString name
);
365 const wxEventType
& RegisterActiveXEvent(wxChar
*eventName
);
367 typedef void (wxEvtHandler::*wxActiveXEventFunction
)(wxActiveXEvent
&);
369 #define EVT_ACTIVEX(id, eventName, fn) DECLARE_EVENT_TABLE_ENTRY(RegisterActiveXEvent(wxT(eventName)), id, -1, (wxObjectEventFunction) (wxEventFunction) (wxActiveXEventFunction) & fn, (wxObject *) NULL ),
372 bool MSWVariantToVariant(VARIANTARG
& va
, wxVariant
& vx
);
373 bool VariantToMSWVariant(wxVariant
& vx
, VARIANTARG
& va
);
375 #endif /* _IEHTMLWIN_H_ */