]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/ole/activex.h
Use /bin/echo for creation of Mac OS X PkgInfo files.
[wxWidgets.git] / include / wx / msw / ole / activex.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/ole/activex.h
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
19 #if wxUSE_ACTIVEX
20
21 //---------------------------------------------------------------------------
22 // wx includes
23 //---------------------------------------------------------------------------
24
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"
29
30 class FrameSite;
31
32 //---------------------------------------------------------------------------
33 // MSW COM includes
34 //---------------------------------------------------------------------------
35 #include <oleidl.h>
36 #include <olectl.h>
37
38 #if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__)
39 #include <exdisp.h>
40 #endif
41
42 #include <docobj.h>
43
44 #ifndef STDMETHOD
45 #define STDMETHOD(funcname) virtual HRESULT wxSTDCALL funcname
46 #endif
47
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
54 #define DISPID_READYSTATE (-525)
55 #define DISPID_READYSTATECHANGE (-609)
56 #define DISPID_AMBIENT_TRANSFERPRIORITY (-728)
57 #endif
58
59 #define DISPID_AMBIENT_OFFLINEIFNOTCONNECTED (-5501)
60 #define DISPID_AMBIENT_SILENT (-5502)
61
62 #ifndef DISPID_AMBIENT_CODEPAGE
63 #define DISPID_AMBIENT_CODEPAGE (-725)
64 #define DISPID_AMBIENT_CHARSET (-727)
65 #endif
66
67
68 //---------------------------------------------------------------------------
69 //
70 // wxActiveXContainer
71 //
72 //---------------------------------------------------------------------------
73
74 template<typename I>
75 class wxAutoOleInterface
76 {
77 public:
78 typedef I Interface;
79
80 explicit wxAutoOleInterface(I *pInterface = NULL) : m_interface(pInterface)
81 {}
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 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
127 (
128 clsid,
129 NULL,
130 CLSCTX_ALL,
131 riid,
132 (void **)&m_interface
133 );
134 }
135
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; }
141
142 protected:
143 I *m_interface;
144 };
145
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
151
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;
160
161 class WXDLLIMPEXP_CORE wxActiveXContainer : public wxWindow
162 {
163 public:
164 wxActiveXContainer(wxWindow * parent, REFIID iid, IUnknown* pUnk);
165 virtual ~wxActiveXContainer();
166
167 void OnSize(wxSizeEvent&);
168 void OnPaint(wxPaintEvent&);
169 void OnSetFocus(wxFocusEvent&);
170 void OnKillFocus(wxFocusEvent&);
171 virtual bool MSWTranslateMessage(WXMSG* pMsg);
172 virtual bool QueryClientSiteInterface(REFIID iid, void **_interface, const char *&desc);
173
174 protected:
175 friend class FrameSite;
176 friend class wxActiveXEvents;
177
178 FrameSite *m_frameSite;
179 wxAutoIDispatch m_Dispatch;
180 wxAutoIOleClientSite m_clientSite;
181 wxAutoIUnknown m_ActiveX;
182 wxAutoIOleObject m_oleObject;
183 wxAutoIOleInPlaceObject m_oleInPlaceObject;
184 wxAutoIOleInPlaceActiveObject m_oleInPlaceActiveObject;
185 wxAutoIOleDocumentView m_docView;
186 wxAutoIViewObject m_viewObject;
187 HWND m_oleObjectHWND;
188 bool m_bAmbientUserMode;
189 DWORD m_docAdviseCookie;
190 wxWindow* m_realparent;
191
192 void CreateActiveX(REFIID, IUnknown*);
193 };
194
195 ///\brief Store native event parameters.
196 ///\detail Store OLE 'Invoke' parameters for event handlers that need to access them.
197 /// These are the exact values for the event as they are passed to the wxActiveXContainer.
198 struct wxActiveXEventNativeMSW
199 {
200 DISPID dispIdMember;
201 REFIID riid;
202 LCID lcid;
203 WORD wFlags;
204 DISPPARAMS *pDispParams;
205 VARIANT *pVarResult;
206 EXCEPINFO *pExcepInfo;
207 unsigned int *puArgErr;
208
209 wxActiveXEventNativeMSW
210 (DISPID a_dispIdMember, REFIID a_riid, LCID a_lcid, WORD a_wFlags, DISPPARAMS *a_pDispParams,
211 VARIANT *a_pVarResult, EXCEPINFO *a_pExcepInfo, unsigned int *a_puArgErr)
212 :dispIdMember(a_dispIdMember), riid(a_riid), lcid(a_lcid), wFlags(a_wFlags), pDispParams(a_pDispParams),
213 pVarResult(a_pVarResult), pExcepInfo(a_pExcepInfo), puArgErr(a_puArgErr)
214 { }
215 };
216
217 // Events
218 class WXDLLIMPEXP_CORE wxActiveXEvent : public wxCommandEvent
219 {
220 private:
221 friend class wxActiveXEvents;
222 wxVariant m_params;
223 DISPID m_dispid;
224
225 public:
226 virtual wxEvent *Clone() const
227 { return new wxActiveXEvent(*this); }
228
229 size_t ParamCount() const;
230
231 wxString ParamType(size_t idx) const
232 {
233 wxASSERT(idx < ParamCount());
234 return m_params[idx].GetType();
235 }
236
237 wxString ParamName(size_t idx) const
238 {
239 wxASSERT(idx < ParamCount());
240 return m_params[idx].GetName();
241 }
242
243 wxVariant& operator[] (size_t idx);
244
245 DISPID GetDispatchId() const
246 { return m_dispid; }
247
248 wxActiveXEventNativeMSW *GetNativeParameters() const
249 { return (wxActiveXEventNativeMSW*)GetClientData(); }
250 };
251
252 // #define wxACTIVEX_ID 14001
253 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_ACTIVEX, wxActiveXEvent );
254
255 typedef void (wxEvtHandler::*wxActiveXEventFunction)(wxActiveXEvent&);
256
257 #define wxActiveXEventHandler(func) \
258 wxEVENT_HANDLER_CAST( wxActiveXEventFunction, func )
259
260 #define EVT_ACTIVEX(id, fn) wxDECLARE_EVENT_TABLE_ENTRY(wxEVT_ACTIVEX, id, -1, wxActiveXEventHandler( fn ), NULL ),
261
262 #endif // wxUSE_ACTIVEX
263
264 #endif // _WX_MSW_OLE_ACTIVEXCONTAINER_H_