1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/ole/activex.h
3 // Purpose: wxActiveXContainer class
4 // Author: Ryan Norton <wxprojects@comcast.net>
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 #ifndef _WX_MSW_OLE_ACTIVEXCONTAINER_H_
17 #define _WX_MSW_OLE_ACTIVEXCONTAINER_H_
21 //---------------------------------------------------------------------------
23 //---------------------------------------------------------------------------
25 #include "wx/msw/ole/oleutils.h" // wxBasicString &c
26 #include "wx/msw/ole/uuid.h"
27 #include "wx/window.h"
28 #include "wx/variant.h"
30 //---------------------------------------------------------------------------
32 //---------------------------------------------------------------------------
36 #if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__)
43 #define STDMETHOD(funcname) virtual HRESULT wxSTDCALL funcname
47 // These defines are from another ole header - but its not in the
48 // latest sdk. Also the ifndef DISPID_READYSTATE is here because at
49 // least on my machine with the latest sdk olectl.h defines these 3
51 #ifndef DISPID_READYSTATE
52 #define DISPID_READYSTATE (-525)
53 #define DISPID_READYSTATECHANGE (-609)
54 #define DISPID_AMBIENT_TRANSFERPRIORITY (-728)
57 #define DISPID_AMBIENT_OFFLINEIFNOTCONNECTED (-5501)
58 #define DISPID_AMBIENT_SILENT (-5502)
60 #ifndef DISPID_AMBIENT_CODEPAGE
61 #define DISPID_AMBIENT_CODEPAGE (-725)
62 #define DISPID_AMBIENT_CHARSET (-727)
66 //---------------------------------------------------------------------------
70 //---------------------------------------------------------------------------
72 #define WX_DECLARE_AUTOOLE(wxAutoOleInterface, I) \
73 class wxAutoOleInterface \
79 explicit wxAutoOleInterface(I *pInterface = NULL) : m_interface(pInterface) {} \
80 wxAutoOleInterface(REFIID riid, IUnknown *pUnk) : m_interface(NULL) \
81 { QueryInterface(riid, pUnk); } \
82 wxAutoOleInterface(REFIID riid, IDispatch *pDispatch) : m_interface(NULL) \
83 { QueryInterface(riid, pDispatch); } \
84 wxAutoOleInterface(REFCLSID clsid, REFIID riid) : m_interface(NULL)\
85 { CreateInstance(clsid, riid); }\
86 wxAutoOleInterface(const wxAutoOleInterface& ti) : m_interface(NULL)\
89 wxAutoOleInterface& operator = (const wxAutoOleInterface& ti)\
92 ti.m_interface->AddRef();\
94 m_interface = ti.m_interface;\
98 wxAutoOleInterface& operator = (I *&ti)\
105 ~wxAutoOleInterface() { Free(); }\
110 m_interface->Release();\
114 HRESULT QueryInterface(REFIID riid, IUnknown *pUnk)\
117 wxASSERT(pUnk != NULL);\
118 return pUnk->QueryInterface(riid, (void **) &m_interface);\
121 HRESULT CreateInstance(REFCLSID clsid, REFIID riid)\
124 return CoCreateInstance(clsid, NULL, CLSCTX_ALL, riid, (void **) &m_interface);\
127 inline operator I *() const {return m_interface;}\
128 inline I* operator ->() {return m_interface;}\
129 inline I** GetRef() {return &m_interface;}\
130 inline bool Ok() const { return IsOk(); }\
131 inline bool IsOk() const {return m_interface != NULL;}\
134 WX_DECLARE_AUTOOLE(wxAutoIDispatch
, IDispatch
)
135 WX_DECLARE_AUTOOLE(wxAutoIOleClientSite
, IOleClientSite
)
136 WX_DECLARE_AUTOOLE(wxAutoIUnknown
, IUnknown
)
137 WX_DECLARE_AUTOOLE(wxAutoIOleObject
, IOleObject
)
138 WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceObject
, IOleInPlaceObject
)
139 WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceActiveObject
, IOleInPlaceActiveObject
)
140 WX_DECLARE_AUTOOLE(wxAutoIOleDocumentView
, IOleDocumentView
)
141 WX_DECLARE_AUTOOLE(wxAutoIViewObject
, IViewObject
)
143 class wxActiveXContainer
: public wxWindow
146 wxActiveXContainer(wxWindow
* parent
, REFIID iid
, IUnknown
* pUnk
);
147 virtual ~wxActiveXContainer();
149 void OnSize(wxSizeEvent
&);
150 void OnPaint(wxPaintEvent
&);
151 void OnSetFocus(wxFocusEvent
&);
152 void OnKillFocus(wxFocusEvent
&);
155 friend class FrameSite
;
156 friend class wxActiveXEvents
;
158 wxAutoIDispatch m_Dispatch
;
159 wxAutoIOleClientSite m_clientSite
;
160 wxAutoIUnknown m_ActiveX
;
161 wxAutoIOleObject m_oleObject
;
162 wxAutoIOleInPlaceObject m_oleInPlaceObject
;
163 wxAutoIOleInPlaceActiveObject m_oleInPlaceActiveObject
;
164 wxAutoIOleDocumentView m_docView
;
165 wxAutoIViewObject m_viewObject
;
166 HWND m_oleObjectHWND
;
167 bool m_bAmbientUserMode
;
168 DWORD m_docAdviseCookie
;
169 wxWindow
* m_realparent
;
171 void CreateActiveX(REFIID
, IUnknown
*);
176 class wxActiveXEvent
: public wxCommandEvent
179 friend class wxActiveXEvents
;
184 virtual wxEvent
*Clone() const
185 { return new wxActiveXEvent(*this); }
187 size_t ParamCount() const
188 { return m_params
.GetCount(); }
190 wxString
ParamType(size_t idx
) const
192 wxASSERT(idx
< m_params
.GetCount());
193 return m_params
[idx
].GetType();
196 wxString
ParamName(size_t idx
) const
198 wxASSERT(idx
< m_params
.GetCount());
199 return m_params
[idx
].GetName();
202 wxVariant
& operator[] (size_t idx
)
204 wxASSERT(idx
< ParamCount());
205 return m_params
[idx
];
208 DISPID
GetDispatchId() const
212 #define wxACTIVEX_ID 14001
213 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA
, wxEVT_ACTIVEX
, wxACTIVEX_ID
)
214 typedef void (wxEvtHandler::*wxActiveXEventFunction
)(wxActiveXEvent
&);
215 #define EVT_ACTIVEX(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_ACTIVEX, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxActiveXEventFunction) & fn, (wxObject *) NULL ),
216 #define wxActiveXEventHandler(func) \
217 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxActiveXEventFunction, &func)
219 #endif // wxUSE_ACTIVEX
221 #endif // _WX_MSW_OLE_ACTIVEXCONTAINER_H_