]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/ole/activex.h
Don't redefine symbols already defined in latest MinGW headers.
[wxWidgets.git] / include / wx / msw / ole / activex.h
CommitLineData
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
30class 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
c986b01f
VS
74template<typename I>
75class wxAutoOleInterface
76{
77public:
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
142protected:
143 I *m_interface;
bf354396
VZ
144};
145
c986b01f
VS
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
152typedef wxAutoOleInterface<IDispatch> wxAutoIDispatch;
153typedef wxAutoOleInterface<IOleClientSite> wxAutoIOleClientSite;
154typedef wxAutoOleInterface<IUnknown> wxAutoIUnknown;
155typedef wxAutoOleInterface<IOleObject> wxAutoIOleObject;
156typedef wxAutoOleInterface<IOleInPlaceObject> wxAutoIOleInPlaceObject;
157typedef wxAutoOleInterface<IOleInPlaceActiveObject> wxAutoIOleInPlaceActiveObject;
158typedef wxAutoOleInterface<IOleDocumentView> wxAutoIOleDocumentView;
159typedef wxAutoOleInterface<IViewObject> wxAutoIViewObject;
bf354396 160
213b5041 161class WXDLLIMPEXP_CORE wxActiveXContainer : public wxWindow
bf354396
VZ
162{
163public:
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
172protected:
173 friend class FrameSite;
557002cf 174 friend class wxActiveXEvents;
bf354396 175
9b53796d 176 FrameSite *m_frameSite;
bf354396
VZ
177 wxAutoIDispatch m_Dispatch;
178 wxAutoIOleClientSite m_clientSite;
179 wxAutoIUnknown m_ActiveX;
180 wxAutoIOleObject m_oleObject;
181 wxAutoIOleInPlaceObject m_oleInPlaceObject;
182 wxAutoIOleInPlaceActiveObject m_oleInPlaceActiveObject;
183 wxAutoIOleDocumentView m_docView;
184 wxAutoIViewObject m_viewObject;
185 HWND m_oleObjectHWND;
186 bool m_bAmbientUserMode;
187 DWORD m_docAdviseCookie;
188 wxWindow* m_realparent;
189
190 void CreateActiveX(REFIID, IUnknown*);
191};
192
2ddb8ccf
VZ
193///\brief Store native event parameters.
194///\detail Store OLE 'Invoke' parameters for event handlers that need to access them.
195/// These are the exact values for the event as they are passed to the wxActiveXContainer.
196struct wxActiveXEventNativeMSW
197{
198 DISPID dispIdMember;
199 REFIID riid;
200 LCID lcid;
201 WORD wFlags;
202 DISPPARAMS *pDispParams;
203 VARIANT *pVarResult;
204 EXCEPINFO *pExcepInfo;
205 unsigned int *puArgErr;
206
207 wxActiveXEventNativeMSW
208 (DISPID a_dispIdMember, REFIID a_riid, LCID a_lcid, WORD a_wFlags, DISPPARAMS *a_pDispParams,
209 VARIANT *a_pVarResult, EXCEPINFO *a_pExcepInfo, unsigned int *a_puArgErr)
210 :dispIdMember(a_dispIdMember), riid(a_riid), lcid(a_lcid), wFlags(a_wFlags), pDispParams(a_pDispParams),
211 pVarResult(a_pVarResult), pExcepInfo(a_pExcepInfo), puArgErr(a_puArgErr)
212 { }
213};
557002cf
VZ
214
215// Events
213b5041 216class WXDLLIMPEXP_CORE wxActiveXEvent : public wxCommandEvent
557002cf
VZ
217{
218private:
219 friend class wxActiveXEvents;
220 wxVariant m_params;
221 DISPID m_dispid;
222
223public:
224 virtual wxEvent *Clone() const
225 { return new wxActiveXEvent(*this); }
226
2ddb8ccf 227 size_t ParamCount() const;
557002cf 228
43f06cfd 229 wxString ParamType(size_t idx) const
557002cf 230 {
2ddb8ccf 231 wxASSERT(idx < ParamCount());
557002cf
VZ
232 return m_params[idx].GetType();
233 }
234
43f06cfd 235 wxString ParamName(size_t idx) const
557002cf 236 {
2ddb8ccf 237 wxASSERT(idx < ParamCount());
557002cf
VZ
238 return m_params[idx].GetName();
239 }
240
2ddb8ccf 241 wxVariant& operator[] (size_t idx);
557002cf
VZ
242
243 DISPID GetDispatchId() const
244 { return m_dispid; }
2ddb8ccf
VZ
245
246 wxActiveXEventNativeMSW *GetNativeParameters() const
247 { return (wxActiveXEventNativeMSW*)GetClientData(); }
557002cf
VZ
248};
249
3c778901 250// #define wxACTIVEX_ID 14001
9b11752c 251wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_ACTIVEX, wxActiveXEvent );
3c778901 252
557002cf 253typedef void (wxEvtHandler::*wxActiveXEventFunction)(wxActiveXEvent&);
3c778901 254
557002cf 255#define wxActiveXEventHandler(func) \
3c778901
VZ
256 wxEVENT_HANDLER_CAST( wxActiveXEventFunction, func )
257
a0e9a5df 258#define EVT_ACTIVEX(id, fn) wxDECLARE_EVENT_TABLE_ENTRY(wxEVT_ACTIVEX, id, -1, wxActiveXEventHandler( fn ), NULL ),
557002cf 259
a1f48575
VZ
260#endif // wxUSE_ACTIVEX
261
bf354396 262#endif // _WX_MSW_OLE_ACTIVEXCONTAINER_H_