]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/ole/activex.h
honour user scale and source offset in wxDC::Blit() (#2605)
[wxWidgets.git] / include / wx / msw / ole / activex.h
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) \
73 class 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 IsOk(); }\
131 inline bool IsOk() const {return m_interface != NULL;}\
132 };
133
134 WX_DECLARE_AUTOOLE(wxAutoIDispatch, IDispatch)
135 WX_DECLARE_AUTOOLE(wxAutoIOleClientSite, IOleClientSite)
136 WX_DECLARE_AUTOOLE(wxAutoIUnknown, IUnknown)
137 WX_DECLARE_AUTOOLE(wxAutoIOleObject, IOleObject)
138 WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceObject, IOleInPlaceObject)
139 WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceActiveObject, IOleInPlaceActiveObject)
140 WX_DECLARE_AUTOOLE(wxAutoIOleDocumentView, IOleDocumentView)
141 WX_DECLARE_AUTOOLE(wxAutoIViewObject, IViewObject)
142
143 class wxActiveXContainer : public wxWindow
144 {
145 public:
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
154 protected:
155 friend class FrameSite;
156 friend class wxActiveXEvents;
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
174
175 // Events
176 class wxActiveXEvent : public wxCommandEvent
177 {
178 private:
179 friend class wxActiveXEvents;
180 wxVariant m_params;
181 DISPID m_dispid;
182
183 public:
184 virtual wxEvent *Clone() const
185 { return new wxActiveXEvent(*this); }
186
187 size_t ParamCount() const
188 { return m_params.GetCount(); }
189
190 wxString ParamType(size_t idx) const
191 {
192 wxASSERT(idx < m_params.GetCount());
193 return m_params[idx].GetType();
194 }
195
196 wxString ParamName(size_t idx) const
197 {
198 wxASSERT(idx < m_params.GetCount());
199 return m_params[idx].GetName();
200 }
201
202 wxVariant& operator[] (size_t idx)
203 {
204 wxASSERT(idx < ParamCount());
205 return m_params[idx];
206 }
207
208 DISPID GetDispatchId() const
209 { return m_dispid; }
210 };
211
212 #define wxACTIVEX_ID 14001
213 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_ACTIVEX, wxACTIVEX_ID)
214 typedef 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
219 #endif // wxUSE_ACTIVEX
220
221 #endif // _WX_MSW_OLE_ACTIVEXCONTAINER_H_