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