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"
32 //---------------------------------------------------------------------------
34 //---------------------------------------------------------------------------
38 #if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__)
45 #define STDMETHOD(funcname) virtual HRESULT wxSTDCALL funcname
49 // These defines are from another ole header - but its not in the
50 // latest sdk. Also the ifndef DISPID_READYSTATE is here because at
51 // least on my machine with the latest sdk olectl.h defines these 3
53 #ifndef DISPID_READYSTATE
54 #define DISPID_READYSTATE (-525)
55 #define DISPID_READYSTATECHANGE (-609)
56 #define DISPID_AMBIENT_TRANSFERPRIORITY (-728)
59 #define DISPID_AMBIENT_OFFLINEIFNOTCONNECTED (-5501)
60 #define DISPID_AMBIENT_SILENT (-5502)
62 #ifndef DISPID_AMBIENT_CODEPAGE
63 #define DISPID_AMBIENT_CODEPAGE (-725)
64 #define DISPID_AMBIENT_CHARSET (-727)
68 //---------------------------------------------------------------------------
72 //---------------------------------------------------------------------------
75 class wxAutoOleInterface
80 explicit wxAutoOleInterface(I
*pInterface
= NULL
) : m_interface(pInterface
)
82 wxAutoOleInterface(REFIID riid
, IUnknown
*pUnk
) : m_interface(NULL
)
83 { QueryInterface(riid
, pUnk
); }
84 wxAutoOleInterface(REFIID riid
, IDispatch
*pDispatch
) : m_interface(NULL
)
85 { QueryInterface(riid
, pDispatch
); }
86 wxAutoOleInterface(REFCLSID clsid
, REFIID riid
) : m_interface(NULL
)
87 { CreateInstance(clsid
, riid
); }
88 wxAutoOleInterface(const wxAutoOleInterface
& ti
) : m_interface(NULL
)
91 wxAutoOleInterface
& operator=(const wxAutoOleInterface
& ti
)
94 ti
.m_interface
->AddRef();
96 m_interface
= ti
.m_interface
;
100 wxAutoOleInterface
& operator=(I
*& ti
)
107 ~wxAutoOleInterface() { Free(); }
112 m_interface
->Release();
116 HRESULT
QueryInterface(REFIID riid
, IUnknown
*pUnk
)
119 wxASSERT(pUnk
!= NULL
);
120 return pUnk
->QueryInterface(riid
, (void **)&m_interface
);
123 HRESULT
CreateInstance(REFCLSID clsid
, REFIID riid
)
126 return CoCreateInstance
132 (void **)&m_interface
136 operator I
*() const {return m_interface
; }
137 I
* operator->() {return m_interface
; }
138 I
** GetRef() {return &m_interface
; }
139 bool Ok() const { return IsOk(); }
140 bool IsOk() const { return m_interface
!= NULL
; }
146 #if WXWIN_COMPATIBILITY_2_8
147 // this macro is kept for compatibility with older wx versions
148 #define WX_DECLARE_AUTOOLE(wxAutoOleInterfaceType, I) \
149 typedef wxAutoOleInterface<I> wxAutoOleInterfaceType;
150 #endif // WXWIN_COMPATIBILITY_2_8
152 typedef wxAutoOleInterface
<IDispatch
> wxAutoIDispatch
;
153 typedef wxAutoOleInterface
<IOleClientSite
> wxAutoIOleClientSite
;
154 typedef wxAutoOleInterface
<IUnknown
> wxAutoIUnknown
;
155 typedef wxAutoOleInterface
<IOleObject
> wxAutoIOleObject
;
156 typedef wxAutoOleInterface
<IOleInPlaceObject
> wxAutoIOleInPlaceObject
;
157 typedef wxAutoOleInterface
<IOleInPlaceActiveObject
> wxAutoIOleInPlaceActiveObject
;
158 typedef wxAutoOleInterface
<IOleDocumentView
> wxAutoIOleDocumentView
;
159 typedef wxAutoOleInterface
<IViewObject
> wxAutoIViewObject
;
161 class WXDLLIMPEXP_CORE wxActiveXContainer
: public wxWindow
164 wxActiveXContainer(wxWindow
* parent
, REFIID iid
, IUnknown
* pUnk
);
165 virtual ~wxActiveXContainer();
167 void OnSize(wxSizeEvent
&);
168 void OnPaint(wxPaintEvent
&);
169 void OnSetFocus(wxFocusEvent
&);
170 void OnKillFocus(wxFocusEvent
&);
171 virtual bool MSWTranslateMessage(WXMSG
* pMsg
);
174 friend class FrameSite
;
175 friend class wxActiveXEvents
;
177 FrameSite
*m_frameSite
;
178 wxAutoIDispatch m_Dispatch
;
179 wxAutoIOleClientSite m_clientSite
;
180 wxAutoIUnknown m_ActiveX
;
181 wxAutoIOleObject m_oleObject
;
182 wxAutoIOleInPlaceObject m_oleInPlaceObject
;
183 wxAutoIOleInPlaceActiveObject m_oleInPlaceActiveObject
;
184 wxAutoIOleDocumentView m_docView
;
185 wxAutoIViewObject m_viewObject
;
186 HWND m_oleObjectHWND
;
187 bool m_bAmbientUserMode
;
188 DWORD m_docAdviseCookie
;
189 wxWindow
* m_realparent
;
191 void CreateActiveX(REFIID
, IUnknown
*);
194 ///\brief Store native event parameters.
195 ///\detail Store OLE 'Invoke' parameters for event handlers that need to access them.
196 /// These are the exact values for the event as they are passed to the wxActiveXContainer.
197 struct wxActiveXEventNativeMSW
203 DISPPARAMS
*pDispParams
;
205 EXCEPINFO
*pExcepInfo
;
206 unsigned int *puArgErr
;
208 wxActiveXEventNativeMSW
209 (DISPID a_dispIdMember
, REFIID a_riid
, LCID a_lcid
, WORD a_wFlags
, DISPPARAMS
*a_pDispParams
,
210 VARIANT
*a_pVarResult
, EXCEPINFO
*a_pExcepInfo
, unsigned int *a_puArgErr
)
211 :dispIdMember(a_dispIdMember
), riid(a_riid
), lcid(a_lcid
), wFlags(a_wFlags
), pDispParams(a_pDispParams
),
212 pVarResult(a_pVarResult
), pExcepInfo(a_pExcepInfo
), puArgErr(a_puArgErr
)
217 class WXDLLIMPEXP_CORE wxActiveXEvent
: public wxCommandEvent
220 friend class wxActiveXEvents
;
225 virtual wxEvent
*Clone() const
226 { return new wxActiveXEvent(*this); }
228 size_t ParamCount() const;
230 wxString
ParamType(size_t idx
) const
232 wxASSERT(idx
< ParamCount());
233 return m_params
[idx
].GetType();
236 wxString
ParamName(size_t idx
) const
238 wxASSERT(idx
< ParamCount());
239 return m_params
[idx
].GetName();
242 wxVariant
& operator[] (size_t idx
);
244 DISPID
GetDispatchId() const
247 wxActiveXEventNativeMSW
*GetNativeParameters() const
248 { return (wxActiveXEventNativeMSW
*)GetClientData(); }
251 // #define wxACTIVEX_ID 14001
252 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_ACTIVEX
, wxActiveXEvent
);
254 typedef void (wxEvtHandler::*wxActiveXEventFunction
)(wxActiveXEvent
&);
256 #define wxActiveXEventHandler(func) \
257 wxEVENT_HANDLER_CAST( wxActiveXEventFunction, func )
259 #define EVT_ACTIVEX(id, fn) wxDECLARE_EVENT_TABLE_ENTRY(wxEVT_ACTIVEX, id, -1, wxActiveXEventHandler( fn ), NULL ),
261 #endif // wxUSE_ACTIVEX
263 #endif // _WX_MSW_OLE_ACTIVEXCONTAINER_H_