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