]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/msw/ole/activex.h
use wxSTRINGIZE instead of redefining a special STRINGIZE in this file
[wxWidgets.git] / include / wx / msw / ole / activex.h
... / ...
CommitLineData
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//---------------------------------------------------------------------------
31// MSW COM includes
32//---------------------------------------------------------------------------
33#include <oleidl.h>
34#include <olectl.h>
35
36#if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__)
37#include <exdisp.h>
38#endif
39
40#include <docobj.h>
41
42#ifndef STDMETHOD
43 #define STDMETHOD(funcname) virtual HRESULT wxSTDCALL funcname
44#endif
45
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
52 #define DISPID_READYSTATE (-525)
53 #define DISPID_READYSTATECHANGE (-609)
54 #define DISPID_AMBIENT_TRANSFERPRIORITY (-728)
55#endif
56
57#define DISPID_AMBIENT_OFFLINEIFNOTCONNECTED (-5501)
58#define DISPID_AMBIENT_SILENT (-5502)
59
60#ifndef DISPID_AMBIENT_CODEPAGE
61 #define DISPID_AMBIENT_CODEPAGE (-725)
62 #define DISPID_AMBIENT_CHARSET (-727)
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;}\
130 inline bool Ok() const {return m_interface != NULL;}\
131};
132
133WX_DECLARE_AUTOOLE(wxAutoIDispatch, IDispatch)
134WX_DECLARE_AUTOOLE(wxAutoIOleClientSite, IOleClientSite)
135WX_DECLARE_AUTOOLE(wxAutoIUnknown, IUnknown)
136WX_DECLARE_AUTOOLE(wxAutoIOleObject, IOleObject)
137WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceObject, IOleInPlaceObject)
138WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceActiveObject, IOleInPlaceActiveObject)
139WX_DECLARE_AUTOOLE(wxAutoIOleDocumentView, IOleDocumentView)
140WX_DECLARE_AUTOOLE(wxAutoIViewObject, IViewObject)
141
142class wxActiveXContainer : public wxWindow
143{
144public:
145 wxActiveXContainer(wxWindow * parent, REFIID iid, IUnknown* pUnk);
146 virtual ~wxActiveXContainer();
147
148 void OnSize(wxSizeEvent&);
149 void OnPaint(wxPaintEvent&);
150 void OnSetFocus(wxFocusEvent&);
151 void OnKillFocus(wxFocusEvent&);
152
153protected:
154 friend class FrameSite;
155 friend class wxActiveXEvents;
156
157 wxAutoIDispatch m_Dispatch;
158 wxAutoIOleClientSite m_clientSite;
159 wxAutoIUnknown m_ActiveX;
160 wxAutoIOleObject m_oleObject;
161 wxAutoIOleInPlaceObject m_oleInPlaceObject;
162 wxAutoIOleInPlaceActiveObject m_oleInPlaceActiveObject;
163 wxAutoIOleDocumentView m_docView;
164 wxAutoIViewObject m_viewObject;
165 HWND m_oleObjectHWND;
166 bool m_bAmbientUserMode;
167 DWORD m_docAdviseCookie;
168 wxWindow* m_realparent;
169
170 void CreateActiveX(REFIID, IUnknown*);
171};
172
173
174// Events
175class wxActiveXEvent : public wxCommandEvent
176{
177private:
178 friend class wxActiveXEvents;
179 wxVariant m_params;
180 DISPID m_dispid;
181
182public:
183 virtual wxEvent *Clone() const
184 { return new wxActiveXEvent(*this); }
185
186 size_t ParamCount() const
187 { return m_params.GetCount(); }
188
189 wxString ParamType(size_t idx) const
190 {
191 wxASSERT(idx < m_params.GetCount());
192 return m_params[idx].GetType();
193 }
194
195 wxString ParamName(size_t idx) const
196 {
197 wxASSERT(idx < m_params.GetCount());
198 return m_params[idx].GetName();
199 }
200
201 wxVariant& operator[] (size_t idx)
202 {
203 wxASSERT(idx < ParamCount());
204 return m_params[idx];
205 }
206
207 DISPID GetDispatchId() const
208 { return m_dispid; }
209};
210
211#define wxACTIVEX_ID 14001
212DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_ACTIVEX, wxACTIVEX_ID)
213typedef void (wxEvtHandler::*wxActiveXEventFunction)(wxActiveXEvent&);
214#define EVT_ACTIVEX(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_ACTIVEX, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxActiveXEventFunction) & fn, (wxObject *) NULL ),
215#define wxActiveXEventHandler(func) \
216 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxActiveXEventFunction, &func)
217
218#endif // wxUSE_ACTIVEX
219
220#endif // _WX_MSW_OLE_ACTIVEXCONTAINER_H_