]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/msw/webview_ie.h
synchronize GTK2 minimum version in docs
[wxWidgets.git] / include / wx / msw / webview_ie.h
... / ...
CommitLineData
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/ole/oleutils.h"
22#include "wx/msw/private/comptr.h"
23#include "wx/msw/wrapwin.h"
24#include "wx/msw/missing.h"
25#include "wx/sharedptr.h"
26#include "wx/vector.h"
27
28/* Classes and definitions from urlmon.h vary in their
29 * completeness between compilers and versions of compilers.
30 * We implement our own versions here which should work
31 * for all compilers. The definitions are taken from the
32 * mingw-w64 headers which are public domain.
33 */
34
35#ifndef REFRESH_NORMAL
36#define REFRESH_NORMAL 0
37#endif
38
39#ifndef REFRESH_COMPLETELY
40#define REFRESH_COMPLETELY 3
41#endif
42
43typedef enum __wxMIDL_IBindStatusCallback_0006
44{
45 wxBSCF_FIRSTDATANOTIFICATION = 0x1,
46 wxBSCF_INTERMEDIATEDATANOTIFICATION = 0x2,
47 wxBSCF_LASTDATANOTIFICATION = 0x4,
48 wxBSCF_DATAFULLYAVAILABLE = 0x8,
49 wxBSCF_AVAILABLEDATASIZEUNKNOWN = 0x10
50} wxBSCF;
51
52EXTERN_C const IID CLSID_FileProtocol;
53
54typedef struct _tagwxBINDINFO
55{
56 ULONG cbSize;
57 LPWSTR szExtraInfo;
58 STGMEDIUM stgmedData;
59 DWORD grfBindInfoF;
60 DWORD dwBindVerb;
61 LPWSTR szCustomVerb;
62 DWORD cbstgmedData;
63 DWORD dwOptions;
64 DWORD dwOptionsFlags;
65 DWORD dwCodePage;
66 SECURITY_ATTRIBUTES securityAttributes;
67 IID iid;
68 IUnknown *pUnk;
69 DWORD dwReserved;
70} wxBINDINFO;
71
72typedef struct _tagwxPROTOCOLDATA
73{
74 DWORD grfFlags;
75 DWORD dwState;
76 LPVOID pData;
77 ULONG cbData;
78} wxPROTOCOLDATA;
79
80class wxIInternetBindInfo : public IUnknown
81{
82public:
83 virtual HRESULT wxSTDCALL GetBindInfo(DWORD *grfBINDF,wxBINDINFO *pbindinfo) = 0;
84 virtual HRESULT wxSTDCALL GetBindString(ULONG ulStringType,LPOLESTR *ppwzStr,
85 ULONG cEl,ULONG *pcElFetched) = 0;
86};
87
88class wxIInternetProtocolSink : public IUnknown
89{
90public:
91 virtual HRESULT wxSTDCALL Switch(wxPROTOCOLDATA *pProtocolData) = 0;
92 virtual HRESULT wxSTDCALL ReportProgress(ULONG ulStatusCode,
93 LPCWSTR szStatusText) = 0;
94 virtual HRESULT wxSTDCALL ReportData(DWORD grfBSCF,ULONG ulProgress,
95 ULONG ulProgressMax) = 0;
96 virtual HRESULT wxSTDCALL ReportResult(HRESULT hrResult,DWORD dwError,
97 LPCWSTR szResult) = 0;
98};
99
100class wxIInternetProtocolRoot : public IUnknown
101{
102public:
103 virtual HRESULT wxSTDCALL Start(LPCWSTR szUrl,wxIInternetProtocolSink *pOIProtSink,
104 wxIInternetBindInfo *pOIBindInfo,DWORD grfPI,
105 HANDLE_PTR dwReserved) = 0;
106 virtual HRESULT wxSTDCALL Continue(wxPROTOCOLDATA *pProtocolData) = 0;
107 virtual HRESULT wxSTDCALL Abort(HRESULT hrReason,DWORD dwOptions) = 0;
108 virtual HRESULT wxSTDCALL Terminate(DWORD dwOptions) = 0;
109 virtual HRESULT wxSTDCALL Suspend(void) = 0;
110 virtual HRESULT wxSTDCALL Resume(void) = 0;
111};
112
113
114class wxIInternetProtocol : public wxIInternetProtocolRoot
115{
116public:
117 virtual HRESULT wxSTDCALL Read(void *pv,ULONG cb,ULONG *pcbRead) = 0;
118 virtual HRESULT wxSTDCALL Seek(LARGE_INTEGER dlibMove,DWORD dwOrigin,
119 ULARGE_INTEGER *plibNewPosition) = 0;
120 virtual HRESULT wxSTDCALL LockRequest(DWORD dwOptions) = 0;
121 virtual HRESULT wxSTDCALL UnlockRequest(void) = 0;
122};
123
124
125class wxIInternetSession : public IUnknown
126{
127 public:
128 virtual HRESULT wxSTDCALL RegisterNameSpace(IClassFactory *pCF,REFCLSID rclsid,
129 LPCWSTR pwzProtocol,
130 ULONG cPatterns,
131 const LPCWSTR *ppwzPatterns,
132 DWORD dwReserved) = 0;
133 virtual HRESULT wxSTDCALL UnregisterNameSpace(IClassFactory *pCF,
134 LPCWSTR pszProtocol) = 0;
135 virtual HRESULT wxSTDCALL RegisterMimeFilter(IClassFactory *pCF,
136 REFCLSID rclsid,
137 LPCWSTR pwzType) = 0;
138 virtual HRESULT wxSTDCALL UnregisterMimeFilter(IClassFactory *pCF,
139 LPCWSTR pwzType) = 0;
140 virtual HRESULT wxSTDCALL CreateBinding(LPBC pBC,LPCWSTR szUrl,
141 IUnknown *pUnkOuter,IUnknown **ppUnk,
142 wxIInternetProtocol **ppOInetProt,
143 DWORD dwOption) = 0;
144 virtual HRESULT wxSTDCALL SetSessionOption(DWORD dwOption,LPVOID pBuffer,
145 DWORD dwBufferLength,
146 DWORD dwReserved) = 0;
147 virtual HRESULT wxSTDCALL GetSessionOption(DWORD dwOption,LPVOID pBuffer,
148 DWORD *pdwBufferLength,
149 DWORD dwReserved) = 0;
150};
151
152/* END OF URLMON.H implementation */
153
154/* Same goes for the mshtmhst.h, these are also taken
155 * from mingw-w64 headers.
156 */
157
158typedef enum _tagwxDOCHOSTUIFLAG
159{
160 DOCHOSTUIFLAG_DIALOG = 0x1,
161 DOCHOSTUIFLAG_DISABLE_HELP_MENU = 0x2,
162 DOCHOSTUIFLAG_NO3DBORDER = 0x4,
163 DOCHOSTUIFLAG_SCROLL_NO = 0x8,
164 DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE = 0x10,
165 DOCHOSTUIFLAG_OPENNEWWIN = 0x20,
166 DOCHOSTUIFLAG_DISABLE_OFFSCREEN = 0x40,
167 DOCHOSTUIFLAG_FLAT_SCROLLBAR = 0x80,
168 DOCHOSTUIFLAG_DIV_BLOCKDEFAULT = 0x100,
169 DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY = 0x200,
170 DOCHOSTUIFLAG_OVERRIDEBEHAVIORFACTORY = 0x400,
171 DOCHOSTUIFLAG_CODEPAGELINKEDFONTS = 0x800,
172 DOCHOSTUIFLAG_URL_ENCODING_DISABLE_UTF8 = 0x1000,
173 DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 = 0x2000,
174 DOCHOSTUIFLAG_ENABLE_FORMS_AUTOCOMPLETE = 0x4000,
175 DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION = 0x10000,
176 DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION = 0x20000,
177 DOCHOSTUIFLAG_THEME = 0x40000,
178 DOCHOSTUIFLAG_NOTHEME = 0x80000,
179 DOCHOSTUIFLAG_NOPICS = 0x100000,
180 DOCHOSTUIFLAG_NO3DOUTERBORDER = 0x200000,
181 DOCHOSTUIFLAG_DISABLE_EDIT_NS_FIXUP = 0x400000,
182 DOCHOSTUIFLAG_LOCAL_MACHINE_ACCESS_CHECK = 0x800000,
183 DOCHOSTUIFLAG_DISABLE_UNTRUSTEDPROTOCOL = 0x1000000
184} DOCHOSTUIFLAG;
185
186typedef struct _tagwxDOCHOSTUIINFO
187{
188 ULONG cbSize;
189 DWORD dwFlags;
190 DWORD dwDoubleClick;
191 OLECHAR *pchHostCss;
192 OLECHAR *pchHostNS;
193} DOCHOSTUIINFO;
194
195class wxIDocHostUIHandler : public IUnknown
196{
197public:
198 virtual HRESULT wxSTDCALL ShowContextMenu(DWORD dwID, POINT *ppt,
199 IUnknown *pcmdtReserved,
200 IDispatch *pdispReserved) = 0;
201
202 virtual HRESULT wxSTDCALL GetHostInfo(DOCHOSTUIINFO *pInfo) = 0;
203
204 virtual HRESULT wxSTDCALL ShowUI(DWORD dwID,
205 IOleInPlaceActiveObject *pActiveObject,
206 IOleCommandTarget *pCommandTarget,
207 IOleInPlaceFrame *pFrame,
208 IOleInPlaceUIWindow *pDoc) = 0;
209
210 virtual HRESULT wxSTDCALL HideUI(void) = 0;
211
212 virtual HRESULT wxSTDCALL UpdateUI(void) = 0;
213
214 virtual HRESULT wxSTDCALL EnableModeless(BOOL fEnable) = 0;
215
216 virtual HRESULT wxSTDCALL OnDocWindowActivate(BOOL fActivate) = 0;
217
218 virtual HRESULT wxSTDCALL OnFrameWindowActivate(BOOL fActivate) = 0;
219
220 virtual HRESULT wxSTDCALL ResizeBorder(LPCRECT prcBorder,
221 IOleInPlaceUIWindow *pUIWindow,
222 BOOL fRameWindow) = 0;
223
224 virtual HRESULT wxSTDCALL TranslateAccelerator(LPMSG lpMsg,
225 const GUID *pguidCmdGroup,
226 DWORD nCmdID) = 0;
227
228 virtual HRESULT wxSTDCALL GetOptionKeyPath(LPOLESTR *pchKey,
229 DWORD dw) = 0;
230
231 virtual HRESULT wxSTDCALL GetDropTarget(IDropTarget *pDropTarget,
232 IDropTarget **ppDropTarget) = 0;
233
234 virtual HRESULT wxSTDCALL GetExternal(IDispatch **ppDispatch) = 0;
235
236 virtual HRESULT wxSTDCALL TranslateUrl(DWORD dwTranslate,
237 OLECHAR *pchURLIn,
238 OLECHAR **ppchURLOut) = 0;
239
240 virtual HRESULT wxSTDCALL FilterDataObject(IDataObject *pDO,
241 IDataObject **ppDORet) = 0;
242};
243
244/* END OF MSHTMHST.H implementation */
245
246struct IHTMLDocument2;
247class wxFSFile;
248class ClassFactory;
249class wxIEContainer;
250class DocHostUIHandler;
251
252class WXDLLIMPEXP_WEBVIEW wxWebViewIE : public wxWebView
253{
254public:
255
256 wxWebViewIE() {}
257
258 wxWebViewIE(wxWindow* parent,
259 wxWindowID id,
260 const wxString& url = wxWebViewDefaultURLStr,
261 const wxPoint& pos = wxDefaultPosition,
262 const wxSize& size = wxDefaultSize,
263 long style = 0,
264 const wxString& name = wxWebViewNameStr)
265 {
266 Create(parent, id, url, pos, size, style, name);
267 }
268
269 ~wxWebViewIE();
270
271 bool Create(wxWindow* parent,
272 wxWindowID id,
273 const wxString& url = wxWebViewDefaultURLStr,
274 const wxPoint& pos = wxDefaultPosition,
275 const wxSize& size = wxDefaultSize,
276 long style = 0,
277 const wxString& name = wxWebViewNameStr);
278
279 virtual void LoadURL(const wxString& url);
280 virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item);
281 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory();
282 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory();
283
284 virtual bool CanGoForward() const;
285 virtual bool CanGoBack() const;
286 virtual void GoBack();
287 virtual void GoForward();
288 virtual void ClearHistory();
289 virtual void EnableHistory(bool enable = true);
290 virtual void Stop();
291 virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT);
292
293 virtual wxString GetPageSource() const;
294 virtual wxString GetPageText() const;
295
296 virtual bool IsBusy() const;
297 virtual wxString GetCurrentURL() const;
298 virtual wxString GetCurrentTitle() const;
299
300 virtual void SetZoomType(wxWebViewZoomType);
301 virtual wxWebViewZoomType GetZoomType() const;
302 virtual bool CanSetZoomType(wxWebViewZoomType) const;
303
304 virtual void Print();
305
306 virtual void SetPage(const wxString& html, const wxString& baseUrl);
307
308 virtual wxWebViewZoom GetZoom() const;
309 virtual void SetZoom(wxWebViewZoom zoom);
310
311 //Clipboard functions
312 virtual bool CanCut() const;
313 virtual bool CanCopy() const;
314 virtual bool CanPaste() const;
315 virtual void Cut();
316 virtual void Copy();
317 virtual void Paste();
318
319 //Undo / redo functionality
320 virtual bool CanUndo() const;
321 virtual bool CanRedo() const;
322 virtual void Undo();
323 virtual void Redo();
324
325 //Editing functions
326 virtual void SetEditable(bool enable = true);
327 virtual bool IsEditable() const;
328
329 //Selection
330 virtual void SelectAll();
331 virtual bool HasSelection() const;
332 virtual void DeleteSelection();
333 virtual wxString GetSelectedText() const;
334 virtual wxString GetSelectedSource() const;
335 virtual void ClearSelection();
336
337 virtual void RunScript(const wxString& javascript);
338
339 //Virtual Filesystem Support
340 virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler);
341
342 // ---- IE-specific methods
343
344 // FIXME: I seem to be able to access remote webpages even in offline mode...
345 bool IsOfflineMode();
346 void SetOfflineMode(bool offline);
347
348 wxWebViewZoom GetIETextZoom() const;
349 void SetIETextZoom(wxWebViewZoom level);
350
351 wxWebViewZoom GetIEOpticalZoom() const;
352 void SetIEOpticalZoom(wxWebViewZoom level);
353
354 void onActiveXEvent(wxActiveXEvent& evt);
355 void onEraseBg(wxEraseEvent&) {}
356
357 DECLARE_EVENT_TABLE();
358
359private:
360 wxIEContainer* m_container;
361 wxAutomationObject m_ie;
362 IWebBrowser2* m_webBrowser;
363 DWORD m_dwCookie;
364 wxCOMPtr<DocHostUIHandler> m_uiHandler;
365
366 //We store the current zoom type;
367 wxWebViewZoomType m_zoomType;
368
369 /** The "Busy" property of IWebBrowser2 does not always return busy when
370 * we'd want it to; this variable may be set to true in cases where the
371 * Busy property is false but should be true.
372 */
373 bool m_isBusy;
374 //We manage our own history, the history list contains the history items
375 //which are added as documentcomplete events arrive, unless we are loading
376 //an item from the history. The position is stored as an int, and reflects
377 //where we are in the history list.
378 wxVector<wxSharedPtr<wxWebViewHistoryItem> > m_historyList;
379 wxVector<ClassFactory*> m_factories;
380 int m_historyPosition;
381 bool m_historyLoadingFromList;
382 bool m_historyEnabled;
383
384 //Generic helper functions for IHtmlDocument commands
385 bool CanExecCommand(wxString command) const;
386 void ExecCommand(wxString command);
387 wxCOMPtr<IHTMLDocument2> GetDocument() const;
388 //Toggles control features see INTERNETFEATURELIST for values.
389 bool EnableControlFeature(long flag, bool enable = true);
390
391 wxDECLARE_DYNAMIC_CLASS(wxWebViewIE);
392};
393
394class VirtualProtocol : public wxIInternetProtocol
395{
396protected:
397 wxIInternetProtocolSink* m_protocolSink;
398 wxString m_html;
399 VOID * fileP;
400
401 wxFSFile* m_file;
402 wxSharedPtr<wxWebViewHandler> m_handler;
403
404public:
405 VirtualProtocol(wxSharedPtr<wxWebViewHandler> handler);
406 ~VirtualProtocol() {}
407
408 //IUnknown
409 DECLARE_IUNKNOWN_METHODS;
410
411 //IInternetProtocolRoot
412 HRESULT STDMETHODCALLTYPE Abort(HRESULT WXUNUSED(hrReason),
413 DWORD WXUNUSED(dwOptions))
414 { return E_NOTIMPL; }
415 HRESULT STDMETHODCALLTYPE Continue(wxPROTOCOLDATA *WXUNUSED(pProtocolData))
416 { return S_OK; }
417 HRESULT STDMETHODCALLTYPE Resume() { return S_OK; }
418 HRESULT STDMETHODCALLTYPE Start(LPCWSTR szUrl,
419 wxIInternetProtocolSink *pOIProtSink,
420 wxIInternetBindInfo *pOIBindInfo,
421 DWORD grfPI,
422 HANDLE_PTR dwReserved);
423 HRESULT STDMETHODCALLTYPE Suspend() { return S_OK; }
424 HRESULT STDMETHODCALLTYPE Terminate(DWORD WXUNUSED(dwOptions)) { return S_OK; }
425
426 //IInternetProtocol
427 HRESULT STDMETHODCALLTYPE LockRequest(DWORD WXUNUSED(dwOptions))
428 { return S_OK; }
429 HRESULT STDMETHODCALLTYPE Read(void *pv, ULONG cb, ULONG *pcbRead);
430 HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER WXUNUSED(dlibMove),
431 DWORD WXUNUSED(dwOrigin),
432 ULARGE_INTEGER* WXUNUSED(plibNewPosition))
433 { return E_FAIL; }
434 HRESULT STDMETHODCALLTYPE UnlockRequest() { return S_OK; }
435};
436
437class ClassFactory : public IClassFactory
438{
439public:
440 ClassFactory(wxSharedPtr<wxWebViewHandler> handler) : m_handler(handler) {}
441
442 //IClassFactory
443 HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown* pUnkOuter,
444 REFIID riid, void** ppvObject);
445 HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock);
446
447 //IUnknown
448 DECLARE_IUNKNOWN_METHODS;
449
450private:
451 wxSharedPtr<wxWebViewHandler> m_handler;
452};
453
454class wxIEContainer : public wxActiveXContainer
455{
456public:
457 wxIEContainer(wxWindow *parent, REFIID iid, IUnknown *pUnk, DocHostUIHandler* uiHandler = NULL);
458 virtual ~wxIEContainer();
459 virtual bool QueryClientSiteInterface(REFIID iid, void **_interface, const char *&desc);
460private:
461 DocHostUIHandler* m_uiHandler;
462};
463
464class DocHostUIHandler : public wxIDocHostUIHandler
465{
466public:
467 DocHostUIHandler() {};
468 ~DocHostUIHandler() {};
469 virtual HRESULT wxSTDCALL ShowContextMenu(DWORD dwID, POINT *ppt,
470 IUnknown *pcmdtReserved,
471 IDispatch *pdispReserved);
472
473 virtual HRESULT wxSTDCALL GetHostInfo(DOCHOSTUIINFO *pInfo);
474
475 virtual HRESULT wxSTDCALL ShowUI(DWORD dwID,
476 IOleInPlaceActiveObject *pActiveObject,
477 IOleCommandTarget *pCommandTarget,
478 IOleInPlaceFrame *pFrame,
479 IOleInPlaceUIWindow *pDoc);
480
481 virtual HRESULT wxSTDCALL HideUI(void);
482
483 virtual HRESULT wxSTDCALL UpdateUI(void);
484
485 virtual HRESULT wxSTDCALL EnableModeless(BOOL fEnable);
486
487 virtual HRESULT wxSTDCALL OnDocWindowActivate(BOOL fActivate);
488
489 virtual HRESULT wxSTDCALL OnFrameWindowActivate(BOOL fActivate);
490
491 virtual HRESULT wxSTDCALL ResizeBorder(LPCRECT prcBorder,
492 IOleInPlaceUIWindow *pUIWindow,
493 BOOL fRameWindow);
494
495 virtual HRESULT wxSTDCALL TranslateAccelerator(LPMSG lpMsg,
496 const GUID *pguidCmdGroup,
497 DWORD nCmdID);
498
499 virtual HRESULT wxSTDCALL GetOptionKeyPath(LPOLESTR *pchKey,
500 DWORD dw);
501
502 virtual HRESULT wxSTDCALL GetDropTarget(IDropTarget *pDropTarget,
503 IDropTarget **ppDropTarget);
504
505 virtual HRESULT wxSTDCALL GetExternal(IDispatch **ppDispatch);
506
507 virtual HRESULT wxSTDCALL TranslateUrl(DWORD dwTranslate,
508 OLECHAR *pchURLIn,
509 OLECHAR **ppchURLOut);
510
511 virtual HRESULT wxSTDCALL FilterDataObject(IDataObject *pDO,
512 IDataObject **ppDORet);
513 //IUnknown
514 DECLARE_IUNKNOWN_METHODS;
515};
516
517#endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
518
519#endif // wxWebViewIE_H