]>
Commit | Line | Data |
---|---|---|
bf354396 | 1 | /////////////////////////////////////////////////////////////////////////////// |
43f06cfd | 2 | // Name: wx/msw/ole/activex.h |
bf354396 VZ |
3 | // Purpose: wxActiveXContainer class |
4 | // Author: Ryan Norton <wxprojects@comcast.net> | |
5 | // Modified by: | |
6 | // Created: 8/18/05 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Ryan Norton | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // Definitions | |
14 | // ============================================================================ | |
15 | ||
16 | #ifndef _WX_MSW_OLE_ACTIVEXCONTAINER_H_ | |
17 | #define _WX_MSW_OLE_ACTIVEXCONTAINER_H_ | |
18 | ||
a1f48575 | 19 | #if wxUSE_ACTIVEX |
bf354396 VZ |
20 | |
21 | //--------------------------------------------------------------------------- | |
a1f48575 | 22 | // wx includes |
bf354396 | 23 | //--------------------------------------------------------------------------- |
bf354396 | 24 | |
a1f48575 VZ |
25 | #include "wx/msw/ole/oleutils.h" // wxBasicString &c |
26 | #include "wx/msw/ole/uuid.h" | |
bf354396 | 27 | #include "wx/window.h" |
557002cf | 28 | #include "wx/variant.h" |
bf354396 | 29 | |
150ac0da VZ |
30 | class FrameSite; |
31 | ||
bf354396 VZ |
32 | //--------------------------------------------------------------------------- |
33 | // MSW COM includes | |
34 | //--------------------------------------------------------------------------- | |
35 | #include <oleidl.h> | |
36 | #include <olectl.h> | |
0ed94e83 WS |
37 | |
38 | #if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__) | |
bf354396 | 39 | #include <exdisp.h> |
0ed94e83 WS |
40 | #endif |
41 | ||
bf354396 VZ |
42 | #include <docobj.h> |
43 | ||
a1f48575 VZ |
44 | #ifndef STDMETHOD |
45 | #define STDMETHOD(funcname) virtual HRESULT wxSTDCALL funcname | |
46 | #endif | |
47 | ||
bf354396 VZ |
48 | // |
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 | |
52 | // | |
53 | #ifndef DISPID_READYSTATE | |
a1f48575 VZ |
54 | #define DISPID_READYSTATE (-525) |
55 | #define DISPID_READYSTATECHANGE (-609) | |
56 | #define DISPID_AMBIENT_TRANSFERPRIORITY (-728) | |
bf354396 VZ |
57 | #endif |
58 | ||
a1f48575 VZ |
59 | #define DISPID_AMBIENT_OFFLINEIFNOTCONNECTED (-5501) |
60 | #define DISPID_AMBIENT_SILENT (-5502) | |
bf354396 VZ |
61 | |
62 | #ifndef DISPID_AMBIENT_CODEPAGE | |
a1f48575 VZ |
63 | #define DISPID_AMBIENT_CODEPAGE (-725) |
64 | #define DISPID_AMBIENT_CHARSET (-727) | |
bf354396 VZ |
65 | #endif |
66 | ||
67 | ||
68 | //--------------------------------------------------------------------------- | |
69 | // | |
70 | // wxActiveXContainer | |
71 | // | |
72 | //--------------------------------------------------------------------------- | |
73 | ||
74 | #define WX_DECLARE_AUTOOLE(wxAutoOleInterface, I) \ | |
75 | class wxAutoOleInterface \ | |
76 | { \ | |
77 | protected: \ | |
78 | I *m_interface; \ | |
79 | \ | |
80 | public: \ | |
81 | 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)\ | |
89 | { operator = (ti); }\ | |
90 | \ | |
91 | wxAutoOleInterface& operator = (const wxAutoOleInterface& ti)\ | |
92 | {\ | |
93 | if (ti.m_interface)\ | |
94 | ti.m_interface->AddRef();\ | |
95 | Free();\ | |
96 | m_interface = ti.m_interface;\ | |
97 | return *this;\ | |
98 | }\ | |
99 | \ | |
100 | wxAutoOleInterface& operator = (I *&ti)\ | |
101 | {\ | |
102 | Free();\ | |
103 | m_interface = ti;\ | |
104 | return *this;\ | |
105 | }\ | |
106 | \ | |
107 | ~wxAutoOleInterface() { Free(); }\ | |
108 | \ | |
109 | inline void Free()\ | |
110 | {\ | |
111 | if (m_interface)\ | |
112 | m_interface->Release();\ | |
113 | m_interface = NULL;\ | |
114 | }\ | |
115 | \ | |
116 | HRESULT QueryInterface(REFIID riid, IUnknown *pUnk)\ | |
117 | {\ | |
118 | Free();\ | |
119 | wxASSERT(pUnk != NULL);\ | |
120 | return pUnk->QueryInterface(riid, (void **) &m_interface);\ | |
121 | }\ | |
122 | \ | |
123 | HRESULT CreateInstance(REFCLSID clsid, REFIID riid)\ | |
124 | {\ | |
125 | Free();\ | |
126 | return CoCreateInstance(clsid, NULL, CLSCTX_ALL, riid, (void **) &m_interface);\ | |
127 | }\ | |
128 | \ | |
129 | inline operator I *() const {return m_interface;}\ | |
130 | inline I* operator ->() {return m_interface;}\ | |
131 | inline I** GetRef() {return &m_interface;}\ | |
bba0e4dc | 132 | inline bool Ok() const { return IsOk(); }\ |
b7cacb43 | 133 | inline bool IsOk() const {return m_interface != NULL;}\ |
bf354396 VZ |
134 | }; |
135 | ||
136 | WX_DECLARE_AUTOOLE(wxAutoIDispatch, IDispatch) | |
137 | WX_DECLARE_AUTOOLE(wxAutoIOleClientSite, IOleClientSite) | |
138 | WX_DECLARE_AUTOOLE(wxAutoIUnknown, IUnknown) | |
139 | WX_DECLARE_AUTOOLE(wxAutoIOleObject, IOleObject) | |
140 | WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceObject, IOleInPlaceObject) | |
141 | WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceActiveObject, IOleInPlaceActiveObject) | |
142 | WX_DECLARE_AUTOOLE(wxAutoIOleDocumentView, IOleDocumentView) | |
143 | WX_DECLARE_AUTOOLE(wxAutoIViewObject, IViewObject) | |
bf354396 | 144 | |
213b5041 | 145 | class WXDLLIMPEXP_CORE wxActiveXContainer : public wxWindow |
bf354396 VZ |
146 | { |
147 | public: | |
148 | wxActiveXContainer(wxWindow * parent, REFIID iid, IUnknown* pUnk); | |
149 | virtual ~wxActiveXContainer(); | |
150 | ||
151 | void OnSize(wxSizeEvent&); | |
152 | void OnPaint(wxPaintEvent&); | |
153 | void OnSetFocus(wxFocusEvent&); | |
154 | void OnKillFocus(wxFocusEvent&); | |
155 | ||
156 | protected: | |
157 | friend class FrameSite; | |
557002cf | 158 | friend class wxActiveXEvents; |
bf354396 | 159 | |
9b53796d | 160 | FrameSite *m_frameSite; |
bf354396 VZ |
161 | wxAutoIDispatch m_Dispatch; |
162 | wxAutoIOleClientSite m_clientSite; | |
163 | wxAutoIUnknown m_ActiveX; | |
164 | wxAutoIOleObject m_oleObject; | |
165 | wxAutoIOleInPlaceObject m_oleInPlaceObject; | |
166 | wxAutoIOleInPlaceActiveObject m_oleInPlaceActiveObject; | |
167 | wxAutoIOleDocumentView m_docView; | |
168 | wxAutoIViewObject m_viewObject; | |
169 | HWND m_oleObjectHWND; | |
170 | bool m_bAmbientUserMode; | |
171 | DWORD m_docAdviseCookie; | |
172 | wxWindow* m_realparent; | |
173 | ||
174 | void CreateActiveX(REFIID, IUnknown*); | |
175 | }; | |
176 | ||
2ddb8ccf VZ |
177 | ///\brief Store native event parameters. |
178 | ///\detail Store OLE 'Invoke' parameters for event handlers that need to access them. | |
179 | /// These are the exact values for the event as they are passed to the wxActiveXContainer. | |
180 | struct wxActiveXEventNativeMSW | |
181 | { | |
182 | DISPID dispIdMember; | |
183 | REFIID riid; | |
184 | LCID lcid; | |
185 | WORD wFlags; | |
186 | DISPPARAMS *pDispParams; | |
187 | VARIANT *pVarResult; | |
188 | EXCEPINFO *pExcepInfo; | |
189 | unsigned int *puArgErr; | |
190 | ||
191 | wxActiveXEventNativeMSW | |
192 | (DISPID a_dispIdMember, REFIID a_riid, LCID a_lcid, WORD a_wFlags, DISPPARAMS *a_pDispParams, | |
193 | VARIANT *a_pVarResult, EXCEPINFO *a_pExcepInfo, unsigned int *a_puArgErr) | |
194 | :dispIdMember(a_dispIdMember), riid(a_riid), lcid(a_lcid), wFlags(a_wFlags), pDispParams(a_pDispParams), | |
195 | pVarResult(a_pVarResult), pExcepInfo(a_pExcepInfo), puArgErr(a_puArgErr) | |
196 | { } | |
197 | }; | |
557002cf VZ |
198 | |
199 | // Events | |
213b5041 | 200 | class WXDLLIMPEXP_CORE wxActiveXEvent : public wxCommandEvent |
557002cf VZ |
201 | { |
202 | private: | |
203 | friend class wxActiveXEvents; | |
204 | wxVariant m_params; | |
205 | DISPID m_dispid; | |
206 | ||
207 | public: | |
208 | virtual wxEvent *Clone() const | |
209 | { return new wxActiveXEvent(*this); } | |
210 | ||
2ddb8ccf | 211 | size_t ParamCount() const; |
557002cf | 212 | |
43f06cfd | 213 | wxString ParamType(size_t idx) const |
557002cf | 214 | { |
2ddb8ccf | 215 | wxASSERT(idx < ParamCount()); |
557002cf VZ |
216 | return m_params[idx].GetType(); |
217 | } | |
218 | ||
43f06cfd | 219 | wxString ParamName(size_t idx) const |
557002cf | 220 | { |
2ddb8ccf | 221 | wxASSERT(idx < ParamCount()); |
557002cf VZ |
222 | return m_params[idx].GetName(); |
223 | } | |
224 | ||
2ddb8ccf | 225 | wxVariant& operator[] (size_t idx); |
557002cf VZ |
226 | |
227 | DISPID GetDispatchId() const | |
228 | { return m_dispid; } | |
2ddb8ccf VZ |
229 | |
230 | wxActiveXEventNativeMSW *GetNativeParameters() const | |
231 | { return (wxActiveXEventNativeMSW*)GetClientData(); } | |
557002cf VZ |
232 | }; |
233 | ||
3c778901 | 234 | // #define wxACTIVEX_ID 14001 |
9b11752c | 235 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_ACTIVEX, wxActiveXEvent ); |
3c778901 | 236 | |
557002cf | 237 | typedef void (wxEvtHandler::*wxActiveXEventFunction)(wxActiveXEvent&); |
3c778901 | 238 | |
557002cf | 239 | #define wxActiveXEventHandler(func) \ |
3c778901 VZ |
240 | wxEVENT_HANDLER_CAST( wxActiveXEventFunction, func ) |
241 | ||
d3b9f782 | 242 | #define EVT_ACTIVEX(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_ACTIVEX, id, -1, wxActiveXEventHandler( fn ), NULL ), |
557002cf | 243 | |
a1f48575 VZ |
244 | #endif // wxUSE_ACTIVEX |
245 | ||
bf354396 | 246 | #endif // _WX_MSW_OLE_ACTIVEXCONTAINER_H_ |