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 ////////////////////////////////////////
266 class ParamX
// refer to ELEMDESC, IDLDESC in MSDN
270 bool isPtr
, isSafeArray
;
274 inline bool IsIn() const {return (flags
& IDLFLAG_FIN
) != 0;}
275 inline bool IsOut() const {return (flags
& IDLFLAG_FOUT
) != 0;}
276 inline bool IsRetVal() const {return (flags
& IDLFLAG_FRETVAL
) != 0;}
279 typedef vector
<ParamX
> ParamXArray
;
281 class FuncX
// refer to FUNCDESC in MSDN
291 typedef vector
<FuncX
> FuncXArray
;
292 typedef map
<MEMBERID
, int> MemberIdList
;
294 wxActiveX(wxWindow
* parent
, REFCLSID clsid
, wxWindowID id
= -1,
295 const wxPoint
& pos
= wxDefaultPosition
,
296 const wxSize
& size
= wxDefaultSize
,
298 const wxString
& name
= wxPanelNameStr
);
299 wxActiveX(wxWindow
* parent
, wxString progId
, wxWindowID id
= -1,
300 const wxPoint
& pos
= wxDefaultPosition
,
301 const wxSize
& size
= wxDefaultSize
,
303 const wxString
& name
= wxPanelNameStr
);
304 virtual ~wxActiveX();
306 void CreateActiveX(REFCLSID clsid
);
307 void CreateActiveX(LPOLESTR progId
);
310 inline int GetEventCount() const {return m_events
.size();}
311 const FuncX
& GetEvent(int idx
) const;
313 HRESULT
ConnectAdvise(REFIID riid
, IUnknown
*eventSink
);
315 void OnSize(wxSizeEvent
&);
316 void OnPaint(wxPaintEvent
& event
);
317 void OnMouse(wxMouseEvent
& event
);
318 void OnSetFocus(wxFocusEvent
&);
319 void OnKillFocus(wxFocusEvent
&);
321 DECLARE_EVENT_TABLE();
324 friend class FrameSite
;
325 friend class wxActiveXEvents
;
327 typedef wxAutoOleInterface
<IConnectionPoint
> wxOleConnectionPoint
;
328 typedef pair
<wxOleConnectionPoint
, DWORD
> wxOleConnection
;
329 typedef vector
<wxOleConnection
> wxOleConnectionArray
;
331 wxAutoOleInterface
<IOleClientSite
> m_clientSite
;
332 wxAutoOleInterface
<IUnknown
> m_ActiveX
;
333 wxAutoOleInterface
<IOleObject
> m_oleObject
;
334 wxAutoOleInterface
<IOleInPlaceObject
> m_oleInPlaceObject
;
335 wxAutoOleInterface
<IOleInPlaceActiveObject
>
337 m_oleInPlaceActiveObject
;
338 wxAutoOleInterface
<IOleDocumentView
> m_docView
;
339 wxAutoOleInterface
<IViewObject
> m_viewObject
;
340 HWND m_oleObjectHWND
;
341 bool m_bAmbientUserMode
;
342 DWORD m_docAdviseCookie
;
343 wxOleConnectionArray m_connections
;
345 HRESULT
AmbientPropertyChanged(DISPID dispid
);
348 void GetTypeInfo(ITypeInfo
*ti
, bool defEventSink
);
353 MemberIdList m_eventsIdx
;
355 WXLRESULT
MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
359 class wxActiveXEvent
: public wxCommandEvent
362 friend class wxActiveXEvents
;
368 virtual wxEvent
*Clone() const { return new wxActiveXEvent(*this); }
370 wxString
EventName();
371 int ParamCount() const;
372 wxString
ParamType(int idx
);
373 wxString
ParamName(int idx
);
374 wxVariant
operator[] (int idx
) const;
375 wxVariant
& operator[] (int idx
);
376 wxVariant
operator[] (wxString name
) const;
377 wxVariant
& operator[] (wxString name
);
380 const wxEventType
& RegisterActiveXEvent(const wxChar
*eventName
);
381 const wxEventType
& RegisterActiveXEvent(DISPID event
);
383 typedef void (wxEvtHandler::*wxActiveXEventFunction
)(wxActiveXEvent
&);
385 #define EVT_ACTIVEX(id, eventName, fn) DECLARE_EVENT_TABLE_ENTRY(RegisterActiveXEvent(wxT(eventName)), id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxActiveXEventFunction, & fn ), (wxObject *) NULL ),
386 #define EVT_ACTIVEX_DISPID(id, eventDispId, fn) DECLARE_EVENT_TABLE_ENTRY(RegisterActiveXEvent(eventDispId), id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxActiveXEventFunction, & fn ), (wxObject *) NULL ),
389 bool MSWVariantToVariant(VARIANTARG
& va
, wxVariant
& vx
);
390 bool VariantToMSWVariant(wxVariant
& vx
, VARIANTARG
& va
);
392 #endif /* _IEHTMLWIN_H_ */