]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/ole/activex.h
Fix wxPropertyGrid::GetPropertyRect when the last item is collapsed.
[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
bf354396
VZ
7// Copyright: (c) Ryan Norton
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// Definitions
13// ============================================================================
14
15#ifndef _WX_MSW_OLE_ACTIVEXCONTAINER_H_
16#define _WX_MSW_OLE_ACTIVEXCONTAINER_H_
17
a1f48575 18#if wxUSE_ACTIVEX
bf354396
VZ
19
20//---------------------------------------------------------------------------
a1f48575 21// wx includes
bf354396 22//---------------------------------------------------------------------------
bf354396 23
a1f48575
VZ
24#include "wx/msw/ole/oleutils.h" // wxBasicString &c
25#include "wx/msw/ole/uuid.h"
bf354396 26#include "wx/window.h"
557002cf 27#include "wx/variant.h"
bf354396 28
150ac0da
VZ
29class FrameSite;
30
bf354396
VZ
31//---------------------------------------------------------------------------
32// MSW COM includes
33//---------------------------------------------------------------------------
34#include <oleidl.h>
35#include <olectl.h>
0ed94e83
WS
36
37#if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__)
bf354396 38#include <exdisp.h>
0ed94e83
WS
39#endif
40
bf354396
VZ
41#include <docobj.h>
42
a1f48575
VZ
43#ifndef STDMETHOD
44 #define STDMETHOD(funcname) virtual HRESULT wxSTDCALL funcname
45#endif
46
bf354396
VZ
47//
48// These defines are from another ole header - but its not in the
49// latest sdk. Also the ifndef DISPID_READYSTATE is here because at
50// least on my machine with the latest sdk olectl.h defines these 3
51//
52#ifndef DISPID_READYSTATE
a1f48575
VZ
53 #define DISPID_READYSTATE (-525)
54 #define DISPID_READYSTATECHANGE (-609)
55 #define DISPID_AMBIENT_TRANSFERPRIORITY (-728)
bf354396
VZ
56#endif
57
a1f48575
VZ
58#define DISPID_AMBIENT_OFFLINEIFNOTCONNECTED (-5501)
59#define DISPID_AMBIENT_SILENT (-5502)
bf354396
VZ
60
61#ifndef DISPID_AMBIENT_CODEPAGE
a1f48575
VZ
62 #define DISPID_AMBIENT_CODEPAGE (-725)
63 #define DISPID_AMBIENT_CHARSET (-727)
bf354396
VZ
64#endif
65
66
67//---------------------------------------------------------------------------
68//
69// wxActiveXContainer
70//
71//---------------------------------------------------------------------------
72
c986b01f
VS
73template<typename I>
74class wxAutoOleInterface
75{
76public:
77 typedef I Interface;
78
79 explicit wxAutoOleInterface(I *pInterface = NULL) : m_interface(pInterface)
80 {}
81 wxAutoOleInterface(REFIID riid, IUnknown *pUnk) : m_interface(NULL)
82 { QueryInterface(riid, pUnk); }
83 wxAutoOleInterface(REFIID riid, IDispatch *pDispatch) : m_interface(NULL)
84 { QueryInterface(riid, pDispatch); }
85 wxAutoOleInterface(REFCLSID clsid, REFIID riid) : m_interface(NULL)
86 { CreateInstance(clsid, riid); }
87 wxAutoOleInterface(const wxAutoOleInterface& ti) : m_interface(NULL)
88 { operator=(ti); }
89
90 wxAutoOleInterface& operator=(const wxAutoOleInterface& ti)
91 {
92 if ( ti.m_interface )
93 ti.m_interface->AddRef();
94 Free();
95 m_interface = ti.m_interface;
96 return *this;
97 }
98
99 wxAutoOleInterface& operator=(I*& ti)
100 {
101 Free();
102 m_interface = ti;
103 return *this;
104 }
105
106 ~wxAutoOleInterface() { Free(); }
107
108 void Free()
109 {
110 if ( m_interface )
111 m_interface->Release();
112 m_interface = NULL;
113 }
114
115 HRESULT QueryInterface(REFIID riid, IUnknown *pUnk)
116 {
117 Free();
118 wxASSERT(pUnk != NULL);
119 return pUnk->QueryInterface(riid, (void **)&m_interface);
120 }
121
122 HRESULT CreateInstance(REFCLSID clsid, REFIID riid)
123 {
124 Free();
125 return CoCreateInstance
126 (
127 clsid,
128 NULL,
129 CLSCTX_ALL,
130 riid,
131 (void **)&m_interface
132 );
133 }
134
135 operator I*() const {return m_interface; }
136 I* operator->() {return m_interface; }
137 I** GetRef() {return &m_interface; }
138 bool Ok() const { return IsOk(); }
139 bool IsOk() const { return m_interface != NULL; }
140
141protected:
142 I *m_interface;
bf354396
VZ
143};
144
c986b01f
VS
145#if WXWIN_COMPATIBILITY_2_8
146// this macro is kept for compatibility with older wx versions
147#define WX_DECLARE_AUTOOLE(wxAutoOleInterfaceType, I) \
148 typedef wxAutoOleInterface<I> wxAutoOleInterfaceType;
149#endif // WXWIN_COMPATIBILITY_2_8
150
151typedef wxAutoOleInterface<IDispatch> wxAutoIDispatch;
152typedef wxAutoOleInterface<IOleClientSite> wxAutoIOleClientSite;
153typedef wxAutoOleInterface<IUnknown> wxAutoIUnknown;
154typedef wxAutoOleInterface<IOleObject> wxAutoIOleObject;
155typedef wxAutoOleInterface<IOleInPlaceObject> wxAutoIOleInPlaceObject;
156typedef wxAutoOleInterface<IOleInPlaceActiveObject> wxAutoIOleInPlaceActiveObject;
157typedef wxAutoOleInterface<IOleDocumentView> wxAutoIOleDocumentView;
158typedef wxAutoOleInterface<IViewObject> wxAutoIViewObject;
bf354396 159
213b5041 160class WXDLLIMPEXP_CORE wxActiveXContainer : public wxWindow
bf354396
VZ
161{
162public:
163 wxActiveXContainer(wxWindow * parent, REFIID iid, IUnknown* pUnk);
164 virtual ~wxActiveXContainer();
165
166 void OnSize(wxSizeEvent&);
167 void OnPaint(wxPaintEvent&);
168 void OnSetFocus(wxFocusEvent&);
169 void OnKillFocus(wxFocusEvent&);
8a4e043a 170 virtual bool MSWTranslateMessage(WXMSG* pMsg);
1f7d05f0 171 virtual bool QueryClientSiteInterface(REFIID iid, void **_interface, const char *&desc);
bf354396
VZ
172
173protected:
174 friend class FrameSite;
557002cf 175 friend class wxActiveXEvents;
bf354396 176
9b53796d 177 FrameSite *m_frameSite;
bf354396
VZ
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;
190
191 void CreateActiveX(REFIID, IUnknown*);
192};
193
2ddb8ccf
VZ
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.
197struct wxActiveXEventNativeMSW
198{
199 DISPID dispIdMember;
200 REFIID riid;
201 LCID lcid;
202 WORD wFlags;
203 DISPPARAMS *pDispParams;
204 VARIANT *pVarResult;
205 EXCEPINFO *pExcepInfo;
206 unsigned int *puArgErr;
207
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)
213 { }
214};
557002cf
VZ
215
216// Events
213b5041 217class WXDLLIMPEXP_CORE wxActiveXEvent : public wxCommandEvent
557002cf
VZ
218{
219private:
220 friend class wxActiveXEvents;
221 wxVariant m_params;
222 DISPID m_dispid;
223
224public:
225 virtual wxEvent *Clone() const
226 { return new wxActiveXEvent(*this); }
227
2ddb8ccf 228 size_t ParamCount() const;
557002cf 229
43f06cfd 230 wxString ParamType(size_t idx) const
557002cf 231 {
2ddb8ccf 232 wxASSERT(idx < ParamCount());
557002cf
VZ
233 return m_params[idx].GetType();
234 }
235
43f06cfd 236 wxString ParamName(size_t idx) const
557002cf 237 {
2ddb8ccf 238 wxASSERT(idx < ParamCount());
557002cf
VZ
239 return m_params[idx].GetName();
240 }
241
2ddb8ccf 242 wxVariant& operator[] (size_t idx);
557002cf
VZ
243
244 DISPID GetDispatchId() const
245 { return m_dispid; }
2ddb8ccf
VZ
246
247 wxActiveXEventNativeMSW *GetNativeParameters() const
248 { return (wxActiveXEventNativeMSW*)GetClientData(); }
557002cf
VZ
249};
250
3c778901 251// #define wxACTIVEX_ID 14001
9b11752c 252wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_ACTIVEX, wxActiveXEvent );
3c778901 253
557002cf 254typedef void (wxEvtHandler::*wxActiveXEventFunction)(wxActiveXEvent&);
3c778901 255
557002cf 256#define wxActiveXEventHandler(func) \
3c778901
VZ
257 wxEVENT_HANDLER_CAST( wxActiveXEventFunction, func )
258
a0e9a5df 259#define EVT_ACTIVEX(id, fn) wxDECLARE_EVENT_TABLE_ENTRY(wxEVT_ACTIVEX, id, -1, wxActiveXEventHandler( fn ), NULL ),
557002cf 260
a1f48575
VZ
261#endif // wxUSE_ACTIVEX
262
bf354396 263#endif // _WX_MSW_OLE_ACTIVEXCONTAINER_H_