]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/webview_ie.h
d5304e2a7ef3356bfeb56b9b9f2768b56f0f8ccb
[wxWidgets.git] / include / wx / msw / webview_ie.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/msw/webviewie.h
3 // Purpose: wxMSW IE wxWebView backend
4 // Author: Marianne Gagnon
5 // Id: $Id$
6 // Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef wxWebViewIE_H
11 #define wxWebViewIE_H
12
13 #include "wx/setup.h"
14
15 #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
16
17 #include "wx/control.h"
18 #include "wx/webview.h"
19 #include "wx/msw/ole/automtn.h"
20 #include "wx/msw/ole/activex.h"
21 #include "wx/msw/wrapwin.h"
22 #include "wx/msw/missing.h"
23 #include "wx/sharedptr.h"
24 #include "wx/vector.h"
25
26 /* Classes and definitions from urlmon.h vary in their
27 * completeness between compilers and versions of compilers.
28 * We implement our own versions here which should work
29 * for all compilers. The definitions are taken from the
30 * mingw-w64 headers which are public domain.
31 */
32
33 #ifndef REFRESH_NORMAL
34 #define REFRESH_NORMAL 0
35 #endif
36
37 #ifndef REFRESH_COMPLETELY
38 #define REFRESH_COMPLETELY 3
39 #endif
40
41 typedef enum __wxMIDL_IBindStatusCallback_0006
42 {
43 wxBSCF_FIRSTDATANOTIFICATION = 0x1,
44 wxBSCF_INTERMEDIATEDATANOTIFICATION = 0x2,
45 wxBSCF_LASTDATANOTIFICATION = 0x4,
46 wxBSCF_DATAFULLYAVAILABLE = 0x8,
47 wxBSCF_AVAILABLEDATASIZEUNKNOWN = 0x10
48 } wxBSCF;
49
50 EXTERN_C const IID CLSID_FileProtocol;
51
52 typedef struct _tagwxBINDINFO
53 {
54 ULONG cbSize;
55 LPWSTR szExtraInfo;
56 STGMEDIUM stgmedData;
57 DWORD grfBindInfoF;
58 DWORD dwBindVerb;
59 LPWSTR szCustomVerb;
60 DWORD cbstgmedData;
61 DWORD dwOptions;
62 DWORD dwOptionsFlags;
63 DWORD dwCodePage;
64 SECURITY_ATTRIBUTES securityAttributes;
65 IID iid;
66 IUnknown *pUnk;
67 DWORD dwReserved;
68 } wxBINDINFO;
69
70 typedef struct _tagwxPROTOCOLDATA
71 {
72 DWORD grfFlags;
73 DWORD dwState;
74 LPVOID pData;
75 ULONG cbData;
76 } wxPROTOCOLDATA;
77
78 class wxIInternetBindInfo : public IUnknown
79 {
80 public:
81 virtual HRESULT wxSTDCALL GetBindInfo(DWORD *grfBINDF,wxBINDINFO *pbindinfo) = 0;
82 virtual HRESULT wxSTDCALL GetBindString(ULONG ulStringType,LPOLESTR *ppwzStr,
83 ULONG cEl,ULONG *pcElFetched) = 0;
84 };
85
86 class wxIInternetProtocolSink : public IUnknown
87 {
88 public:
89 virtual HRESULT wxSTDCALL Switch(wxPROTOCOLDATA *pProtocolData) = 0;
90 virtual HRESULT wxSTDCALL ReportProgress(ULONG ulStatusCode,
91 LPCWSTR szStatusText) = 0;
92 virtual HRESULT wxSTDCALL ReportData(DWORD grfBSCF,ULONG ulProgress,
93 ULONG ulProgressMax) = 0;
94 virtual HRESULT wxSTDCALL ReportResult(HRESULT hrResult,DWORD dwError,
95 LPCWSTR szResult) = 0;
96 };
97
98 class wxIInternetProtocolRoot : public IUnknown
99 {
100 public:
101 virtual HRESULT wxSTDCALL Start(LPCWSTR szUrl,wxIInternetProtocolSink *pOIProtSink,
102 wxIInternetBindInfo *pOIBindInfo,DWORD grfPI,
103 HANDLE_PTR dwReserved) = 0;
104 virtual HRESULT wxSTDCALL Continue(wxPROTOCOLDATA *pProtocolData) = 0;
105 virtual HRESULT wxSTDCALL Abort(HRESULT hrReason,DWORD dwOptions) = 0;
106 virtual HRESULT wxSTDCALL Terminate(DWORD dwOptions) = 0;
107 virtual HRESULT wxSTDCALL Suspend(void) = 0;
108 virtual HRESULT wxSTDCALL Resume(void) = 0;
109 };
110
111
112 class wxIInternetProtocol : public wxIInternetProtocolRoot
113 {
114 public:
115 virtual HRESULT wxSTDCALL Read(void *pv,ULONG cb,ULONG *pcbRead) = 0;
116 virtual HRESULT wxSTDCALL Seek(LARGE_INTEGER dlibMove,DWORD dwOrigin,
117 ULARGE_INTEGER *plibNewPosition) = 0;
118 virtual HRESULT wxSTDCALL LockRequest(DWORD dwOptions) = 0;
119 virtual HRESULT wxSTDCALL UnlockRequest(void) = 0;
120 };
121
122
123 class wxIInternetSession : public IUnknown
124 {
125 public:
126 virtual HRESULT wxSTDCALL RegisterNameSpace(IClassFactory *pCF,REFCLSID rclsid,
127 LPCWSTR pwzProtocol,
128 ULONG cPatterns,
129 const LPCWSTR *ppwzPatterns,
130 DWORD dwReserved) = 0;
131 virtual HRESULT wxSTDCALL UnregisterNameSpace(IClassFactory *pCF,
132 LPCWSTR pszProtocol) = 0;
133 virtual HRESULT wxSTDCALL RegisterMimeFilter(IClassFactory *pCF,
134 REFCLSID rclsid,
135 LPCWSTR pwzType) = 0;
136 virtual HRESULT wxSTDCALL UnregisterMimeFilter(IClassFactory *pCF,
137 LPCWSTR pwzType) = 0;
138 virtual HRESULT wxSTDCALL CreateBinding(LPBC pBC,LPCWSTR szUrl,
139 IUnknown *pUnkOuter,IUnknown **ppUnk,
140 wxIInternetProtocol **ppOInetProt,
141 DWORD dwOption) = 0;
142 virtual HRESULT wxSTDCALL SetSessionOption(DWORD dwOption,LPVOID pBuffer,
143 DWORD dwBufferLength,
144 DWORD dwReserved) = 0;
145 virtual HRESULT wxSTDCALL GetSessionOption(DWORD dwOption,LPVOID pBuffer,
146 DWORD *pdwBufferLength,
147 DWORD dwReserved) = 0;
148 };
149
150 /* END OF URLMON.H implementation */
151
152 struct IHTMLDocument2;
153 class wxFSFile;
154 class ClassFactory;
155
156 class WXDLLIMPEXP_WEBVIEW wxWebViewIE : public wxWebView
157 {
158 public:
159
160 wxWebViewIE() {}
161
162 wxWebViewIE(wxWindow* parent,
163 wxWindowID id,
164 const wxString& url = wxWebViewDefaultURLStr,
165 const wxPoint& pos = wxDefaultPosition,
166 const wxSize& size = wxDefaultSize,
167 long style = 0,
168 const wxString& name = wxWebViewNameStr)
169 {
170 Create(parent, id, url, pos, size, style, name);
171 }
172
173 ~wxWebViewIE();
174
175 bool Create(wxWindow* parent,
176 wxWindowID id,
177 const wxString& url = wxWebViewDefaultURLStr,
178 const wxPoint& pos = wxDefaultPosition,
179 const wxSize& size = wxDefaultSize,
180 long style = 0,
181 const wxString& name = wxWebViewNameStr);
182
183 virtual void LoadURL(const wxString& url);
184 virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item);
185 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory();
186 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory();
187
188 virtual bool CanGoForward() const;
189 virtual bool CanGoBack() const;
190 virtual void GoBack();
191 virtual void GoForward();
192 virtual void ClearHistory();
193 virtual void EnableHistory(bool enable = true);
194 virtual void Stop();
195 virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT);
196
197 virtual wxString GetPageSource() const;
198 virtual wxString GetPageText() const;
199
200 virtual bool IsBusy() const;
201 virtual wxString GetCurrentURL() const;
202 virtual wxString GetCurrentTitle() const;
203
204 virtual void SetZoomType(wxWebViewZoomType);
205 virtual wxWebViewZoomType GetZoomType() const;
206 virtual bool CanSetZoomType(wxWebViewZoomType) const;
207
208 virtual void Print();
209
210 virtual void SetPage(const wxString& html, const wxString& baseUrl);
211
212 virtual wxWebViewZoom GetZoom() const;
213 virtual void SetZoom(wxWebViewZoom zoom);
214
215 //Clipboard functions
216 virtual bool CanCut() const;
217 virtual bool CanCopy() const;
218 virtual bool CanPaste() const;
219 virtual void Cut();
220 virtual void Copy();
221 virtual void Paste();
222
223 //Undo / redo functionality
224 virtual bool CanUndo() const;
225 virtual bool CanRedo() const;
226 virtual void Undo();
227 virtual void Redo();
228
229 //Editing functions
230 virtual void SetEditable(bool enable = true);
231 virtual bool IsEditable() const;
232
233 //Selection
234 virtual void SelectAll();
235 virtual bool HasSelection() const;
236 virtual void DeleteSelection();
237 virtual wxString GetSelectedText() const;
238 virtual wxString GetSelectedSource() const;
239 virtual void ClearSelection();
240
241 virtual void RunScript(const wxString& javascript);
242
243 //Virtual Filesystem Support
244 virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler);
245
246 // ---- IE-specific methods
247
248 // FIXME: I seem to be able to access remote webpages even in offline mode...
249 bool IsOfflineMode();
250 void SetOfflineMode(bool offline);
251
252 wxWebViewZoom GetIETextZoom() const;
253 void SetIETextZoom(wxWebViewZoom level);
254
255 wxWebViewZoom GetIEOpticalZoom() const;
256 void SetIEOpticalZoom(wxWebViewZoom level);
257
258 void onActiveXEvent(wxActiveXEvent& evt);
259 void onEraseBg(wxEraseEvent&) {}
260
261 DECLARE_EVENT_TABLE();
262
263 private:
264 wxActiveXContainer* m_container;
265 wxAutomationObject m_ie;
266 IWebBrowser2* m_webBrowser;
267 DWORD m_dwCookie;
268
269 //We store the current zoom type;
270 wxWebViewZoomType m_zoomType;
271
272 /** The "Busy" property of IWebBrowser2 does not always return busy when
273 * we'd want it to; this variable may be set to true in cases where the
274 * Busy property is false but should be true.
275 */
276 bool m_isBusy;
277 //We manage our own history, the history list contains the history items
278 //which are added as documentcomplete events arrive, unless we are loading
279 //an item from the history. The position is stored as an int, and reflects
280 //where we are in the history list.
281 wxVector<wxSharedPtr<wxWebViewHistoryItem> > m_historyList;
282 wxVector<ClassFactory*> m_factories;
283 int m_historyPosition;
284 bool m_historyLoadingFromList;
285 bool m_historyEnabled;
286
287 //Generic helper functions for IHtmlDocument commands
288 bool CanExecCommand(wxString command) const;
289 void ExecCommand(wxString command);
290 IHTMLDocument2* GetDocument() const;
291
292 wxDECLARE_DYNAMIC_CLASS(wxWebViewIE);
293 };
294
295 class VirtualProtocol : public wxIInternetProtocol
296 {
297 protected:
298 ULONG m_refCount;
299 wxIInternetProtocolSink* m_protocolSink;
300 wxString m_html;
301 VOID * fileP;
302
303 wxFSFile* m_file;
304 wxSharedPtr<wxWebViewHandler> m_handler;
305
306 public:
307 VirtualProtocol(wxSharedPtr<wxWebViewHandler> handler);
308 ~VirtualProtocol();
309
310 //IUnknown
311 ULONG STDMETHODCALLTYPE AddRef();
312 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject);
313 ULONG STDMETHODCALLTYPE Release();
314
315 //IInternetProtocolRoot
316 HRESULT STDMETHODCALLTYPE Abort(HRESULT WXUNUSED(hrReason),
317 DWORD WXUNUSED(dwOptions))
318 { return E_NOTIMPL; }
319 HRESULT STDMETHODCALLTYPE Continue(wxPROTOCOLDATA *WXUNUSED(pProtocolData))
320 { return S_OK; }
321 HRESULT STDMETHODCALLTYPE Resume() { return S_OK; }
322 HRESULT STDMETHODCALLTYPE Start(LPCWSTR szUrl,
323 wxIInternetProtocolSink *pOIProtSink,
324 wxIInternetBindInfo *pOIBindInfo,
325 DWORD grfPI,
326 HANDLE_PTR dwReserved);
327 HRESULT STDMETHODCALLTYPE Suspend() { return S_OK; }
328 HRESULT STDMETHODCALLTYPE Terminate(DWORD WXUNUSED(dwOptions)) { return S_OK; }
329
330 //IInternetProtocol
331 HRESULT STDMETHODCALLTYPE LockRequest(DWORD WXUNUSED(dwOptions))
332 { return S_OK; }
333 HRESULT STDMETHODCALLTYPE Read(void *pv, ULONG cb, ULONG *pcbRead);
334 HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER WXUNUSED(dlibMove),
335 DWORD WXUNUSED(dwOrigin),
336 ULARGE_INTEGER* WXUNUSED(plibNewPosition))
337 { return E_FAIL; }
338 HRESULT STDMETHODCALLTYPE UnlockRequest() { return S_OK; }
339 };
340
341 class ClassFactory : public IClassFactory
342 {
343 public:
344 ClassFactory(wxSharedPtr<wxWebViewHandler> handler) : m_refCount(0), m_handler(handler) {}
345 //IUnknown
346 ULONG STDMETHODCALLTYPE AddRef();
347 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject);
348 ULONG STDMETHODCALLTYPE Release();
349
350 //IClassFactory
351 HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown* pUnkOuter,
352 REFIID riid, void** ppvObject);
353 HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock);
354 private:
355 ULONG m_refCount;
356 wxSharedPtr<wxWebViewHandler> m_handler;
357 };
358
359 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
360
361 #endif // wxWebViewIE_H