]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/ole/activex.h
Added wxRichTextCtrl
[wxWidgets.git] / include / wx / msw / ole / activex.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/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 //---------------------------------------------------------------------------
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"
45
46 //---------------------------------------------------------------------------
47 // MSW COM includes
48 //---------------------------------------------------------------------------
49 #include <oleidl.h>
50 #include <olectl.h>
51 #include <exdisp.h>
52 #include <docobj.h>
53
54 //
55 // These defines are from another ole header - but its not in the
56 // latest sdk. Also the ifndef DISPID_READYSTATE is here because at
57 // least on my machine with the latest sdk olectl.h defines these 3
58 //
59 #ifndef DISPID_READYSTATE
60 #define DISPID_READYSTATE -525
61 #define DISPID_READYSTATECHANGE -609
62 #define DISPID_AMBIENT_TRANSFERPRIORITY -728
63 #endif
64
65 #define DISPID_AMBIENT_OFFLINEIFNOTCONNECTED -5501
66 #define DISPID_AMBIENT_SILENT -5502
67
68 #ifndef DISPID_AMBIENT_CODEPAGE
69 # define DISPID_AMBIENT_CODEPAGE -725
70 # define DISPID_AMBIENT_CHARSET -727
71 #endif
72
73
74 //---------------------------------------------------------------------------
75 //
76 // wxActiveXContainer
77 //
78 //---------------------------------------------------------------------------
79
80 #define WX_DECLARE_AUTOOLE(wxAutoOleInterface, I) \
81 class wxAutoOleInterface \
82 { \
83 protected: \
84 I *m_interface; \
85 \
86 public: \
87 explicit wxAutoOleInterface(I *pInterface = NULL) : m_interface(pInterface) {} \
88 wxAutoOleInterface(REFIID riid, IUnknown *pUnk) : m_interface(NULL) \
89 { QueryInterface(riid, pUnk); } \
90 wxAutoOleInterface(REFIID riid, IDispatch *pDispatch) : m_interface(NULL) \
91 { QueryInterface(riid, pDispatch); } \
92 wxAutoOleInterface(REFCLSID clsid, REFIID riid) : m_interface(NULL)\
93 { CreateInstance(clsid, riid); }\
94 wxAutoOleInterface(const wxAutoOleInterface& ti) : m_interface(NULL)\
95 { operator = (ti); }\
96 \
97 wxAutoOleInterface& operator = (const wxAutoOleInterface& ti)\
98 {\
99 if (ti.m_interface)\
100 ti.m_interface->AddRef();\
101 Free();\
102 m_interface = ti.m_interface;\
103 return *this;\
104 }\
105 \
106 wxAutoOleInterface& operator = (I *&ti)\
107 {\
108 Free();\
109 m_interface = ti;\
110 return *this;\
111 }\
112 \
113 ~wxAutoOleInterface() { Free(); }\
114 \
115 inline void Free()\
116 {\
117 if (m_interface)\
118 m_interface->Release();\
119 m_interface = NULL;\
120 }\
121 \
122 HRESULT QueryInterface(REFIID riid, IUnknown *pUnk)\
123 {\
124 Free();\
125 wxASSERT(pUnk != NULL);\
126 return pUnk->QueryInterface(riid, (void **) &m_interface);\
127 }\
128 \
129 HRESULT CreateInstance(REFCLSID clsid, REFIID riid)\
130 {\
131 Free();\
132 return CoCreateInstance(clsid, NULL, CLSCTX_ALL, riid, (void **) &m_interface);\
133 }\
134 \
135 inline operator I *() const {return m_interface;}\
136 inline I* operator ->() {return m_interface;}\
137 inline I** GetRef() {return &m_interface;}\
138 inline bool Ok() const {return m_interface != NULL;}\
139 };
140
141 WX_DECLARE_AUTOOLE(wxAutoIDispatch, IDispatch)
142 WX_DECLARE_AUTOOLE(wxAutoIOleClientSite, IOleClientSite)
143 WX_DECLARE_AUTOOLE(wxAutoIUnknown, IUnknown)
144 WX_DECLARE_AUTOOLE(wxAutoIOleObject, IOleObject)
145 WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceObject, IOleInPlaceObject)
146 WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceActiveObject, IOleInPlaceActiveObject)
147 WX_DECLARE_AUTOOLE(wxAutoIOleDocumentView, IOleDocumentView)
148 WX_DECLARE_AUTOOLE(wxAutoIViewObject, IViewObject)
149 WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceSite, IOleInPlaceSite)
150 WX_DECLARE_AUTOOLE(wxAutoIOleDocument, IOleDocument)
151 WX_DECLARE_AUTOOLE(wxAutoIPersistStreamInit, IPersistStreamInit)
152 WX_DECLARE_AUTOOLE(wxAutoIAdviseSink, IAdviseSink)
153
154 class wxActiveXContainer : public wxWindow
155 {
156 public:
157 wxActiveXContainer(wxWindow * parent, REFIID iid, IUnknown* pUnk);
158 virtual ~wxActiveXContainer();
159
160 void OnSize(wxSizeEvent&);
161 void OnPaint(wxPaintEvent&);
162 void OnSetFocus(wxFocusEvent&);
163 void OnKillFocus(wxFocusEvent&);
164
165 protected:
166 friend class FrameSite;
167
168 wxAutoIDispatch m_Dispatch;
169 wxAutoIOleClientSite m_clientSite;
170 wxAutoIUnknown m_ActiveX;
171 wxAutoIOleObject m_oleObject;
172 wxAutoIOleInPlaceObject m_oleInPlaceObject;
173 wxAutoIOleInPlaceActiveObject m_oleInPlaceActiveObject;
174 wxAutoIOleDocumentView m_docView;
175 wxAutoIViewObject m_viewObject;
176 HWND m_oleObjectHWND;
177 bool m_bAmbientUserMode;
178 DWORD m_docAdviseCookie;
179 wxWindow* m_realparent;
180
181 void CreateActiveX(REFIID, IUnknown*);
182 };
183
184 #endif // _WX_MSW_OLE_ACTIVEXCONTAINER_H_
185