]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/ole/activex.h
argh, really, really fix Darwin build
[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
VZ
29
30//---------------------------------------------------------------------------
31// MSW COM includes
32//---------------------------------------------------------------------------
33#include <oleidl.h>
34#include <olectl.h>
0ed94e83
WS
35
36#if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__)
bf354396 37#include <exdisp.h>
0ed94e83
WS
38#endif
39
bf354396
VZ
40#include <docobj.h>
41
a1f48575
VZ
42#ifndef STDMETHOD
43 #define STDMETHOD(funcname) virtual HRESULT wxSTDCALL funcname
44#endif
45
bf354396
VZ
46//
47// These defines are from another ole header - but its not in the
48// latest sdk. Also the ifndef DISPID_READYSTATE is here because at
49// least on my machine with the latest sdk olectl.h defines these 3
50//
51#ifndef DISPID_READYSTATE
a1f48575
VZ
52 #define DISPID_READYSTATE (-525)
53 #define DISPID_READYSTATECHANGE (-609)
54 #define DISPID_AMBIENT_TRANSFERPRIORITY (-728)
bf354396
VZ
55#endif
56
a1f48575
VZ
57#define DISPID_AMBIENT_OFFLINEIFNOTCONNECTED (-5501)
58#define DISPID_AMBIENT_SILENT (-5502)
bf354396
VZ
59
60#ifndef DISPID_AMBIENT_CODEPAGE
a1f48575
VZ
61 #define DISPID_AMBIENT_CODEPAGE (-725)
62 #define DISPID_AMBIENT_CHARSET (-727)
bf354396
VZ
63#endif
64
65
66//---------------------------------------------------------------------------
67//
68// wxActiveXContainer
69//
70//---------------------------------------------------------------------------
71
72#define WX_DECLARE_AUTOOLE(wxAutoOleInterface, I) \
73class wxAutoOleInterface \
74{ \
75 protected: \
76 I *m_interface; \
77\
78 public: \
79 explicit wxAutoOleInterface(I *pInterface = NULL) : m_interface(pInterface) {} \
80 wxAutoOleInterface(REFIID riid, IUnknown *pUnk) : m_interface(NULL) \
81 { QueryInterface(riid, pUnk); } \
82 wxAutoOleInterface(REFIID riid, IDispatch *pDispatch) : m_interface(NULL) \
83 { QueryInterface(riid, pDispatch); } \
84 wxAutoOleInterface(REFCLSID clsid, REFIID riid) : m_interface(NULL)\
85 { CreateInstance(clsid, riid); }\
86 wxAutoOleInterface(const wxAutoOleInterface& ti) : m_interface(NULL)\
87 { operator = (ti); }\
88\
89 wxAutoOleInterface& operator = (const wxAutoOleInterface& ti)\
90 {\
91 if (ti.m_interface)\
92 ti.m_interface->AddRef();\
93 Free();\
94 m_interface = ti.m_interface;\
95 return *this;\
96 }\
97\
98 wxAutoOleInterface& operator = (I *&ti)\
99 {\
100 Free();\
101 m_interface = ti;\
102 return *this;\
103 }\
104\
105 ~wxAutoOleInterface() { Free(); }\
106\
107 inline void Free()\
108 {\
109 if (m_interface)\
110 m_interface->Release();\
111 m_interface = NULL;\
112 }\
113\
114 HRESULT QueryInterface(REFIID riid, IUnknown *pUnk)\
115 {\
116 Free();\
117 wxASSERT(pUnk != NULL);\
118 return pUnk->QueryInterface(riid, (void **) &m_interface);\
119 }\
120\
121 HRESULT CreateInstance(REFCLSID clsid, REFIID riid)\
122 {\
123 Free();\
124 return CoCreateInstance(clsid, NULL, CLSCTX_ALL, riid, (void **) &m_interface);\
125 }\
126\
127 inline operator I *() const {return m_interface;}\
128 inline I* operator ->() {return m_interface;}\
129 inline I** GetRef() {return &m_interface;}\
bba0e4dc 130 inline bool Ok() const { return IsOk(); }\
b7cacb43 131 inline bool IsOk() const {return m_interface != NULL;}\
bf354396
VZ
132};
133
134WX_DECLARE_AUTOOLE(wxAutoIDispatch, IDispatch)
135WX_DECLARE_AUTOOLE(wxAutoIOleClientSite, IOleClientSite)
136WX_DECLARE_AUTOOLE(wxAutoIUnknown, IUnknown)
137WX_DECLARE_AUTOOLE(wxAutoIOleObject, IOleObject)
138WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceObject, IOleInPlaceObject)
139WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceActiveObject, IOleInPlaceActiveObject)
140WX_DECLARE_AUTOOLE(wxAutoIOleDocumentView, IOleDocumentView)
141WX_DECLARE_AUTOOLE(wxAutoIViewObject, IViewObject)
bf354396
VZ
142
143class wxActiveXContainer : public wxWindow
144{
145public:
146 wxActiveXContainer(wxWindow * parent, REFIID iid, IUnknown* pUnk);
147 virtual ~wxActiveXContainer();
148
149 void OnSize(wxSizeEvent&);
150 void OnPaint(wxPaintEvent&);
151 void OnSetFocus(wxFocusEvent&);
152 void OnKillFocus(wxFocusEvent&);
153
154protected:
155 friend class FrameSite;
557002cf 156 friend class wxActiveXEvents;
bf354396
VZ
157
158 wxAutoIDispatch m_Dispatch;
159 wxAutoIOleClientSite m_clientSite;
160 wxAutoIUnknown m_ActiveX;
161 wxAutoIOleObject m_oleObject;
162 wxAutoIOleInPlaceObject m_oleInPlaceObject;
163 wxAutoIOleInPlaceActiveObject m_oleInPlaceActiveObject;
164 wxAutoIOleDocumentView m_docView;
165 wxAutoIViewObject m_viewObject;
166 HWND m_oleObjectHWND;
167 bool m_bAmbientUserMode;
168 DWORD m_docAdviseCookie;
169 wxWindow* m_realparent;
170
171 void CreateActiveX(REFIID, IUnknown*);
172};
173
557002cf
VZ
174
175// Events
176class wxActiveXEvent : public wxCommandEvent
177{
178private:
179 friend class wxActiveXEvents;
180 wxVariant m_params;
181 DISPID m_dispid;
182
183public:
184 virtual wxEvent *Clone() const
185 { return new wxActiveXEvent(*this); }
186
43f06cfd 187 size_t ParamCount() const
557002cf
VZ
188 { return m_params.GetCount(); }
189
43f06cfd 190 wxString ParamType(size_t idx) const
557002cf 191 {
43f06cfd 192 wxASSERT(idx < m_params.GetCount());
557002cf
VZ
193 return m_params[idx].GetType();
194 }
195
43f06cfd 196 wxString ParamName(size_t idx) const
557002cf 197 {
43f06cfd 198 wxASSERT(idx < m_params.GetCount());
557002cf
VZ
199 return m_params[idx].GetName();
200 }
201
43f06cfd 202 wxVariant& operator[] (size_t idx)
557002cf 203 {
43f06cfd 204 wxASSERT(idx < ParamCount());
557002cf
VZ
205 return m_params[idx];
206 }
207
208 DISPID GetDispatchId() const
209 { return m_dispid; }
210};
211
212#define wxACTIVEX_ID 14001
213DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_ACTIVEX, wxACTIVEX_ID)
214typedef void (wxEvtHandler::*wxActiveXEventFunction)(wxActiveXEvent&);
215#define EVT_ACTIVEX(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_ACTIVEX, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxActiveXEventFunction) & fn, (wxObject *) NULL ),
216#define wxActiveXEventHandler(func) \
217 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxActiveXEventFunction, &func)
218
a1f48575
VZ
219#endif // wxUSE_ACTIVEX
220
bf354396 221#endif // _WX_MSW_OLE_ACTIVEXCONTAINER_H_