1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/msw/webviewie.h
3 // Purpose: wxMSW IE wxWebView backend
4 // Author: Marianne Gagnon
6 // Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
15 #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
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"
25 struct IHTMLDocument2
;
28 class WXDLLIMPEXP_WEBVIEW wxWebViewIE
: public wxWebView
34 wxWebViewIE(wxWindow
* parent
,
36 const wxString
& url
= wxWebViewDefaultURLStr
,
37 const wxPoint
& pos
= wxDefaultPosition
,
38 const wxSize
& size
= wxDefaultSize
,
40 const wxString
& name
= wxWebViewNameStr
)
42 Create(parent
, id
, url
, pos
, size
, style
, name
);
45 bool Create(wxWindow
* parent
,
47 const wxString
& url
= wxWebViewDefaultURLStr
,
48 const wxPoint
& pos
= wxDefaultPosition
,
49 const wxSize
& size
= wxDefaultSize
,
51 const wxString
& name
= wxWebViewNameStr
);
53 virtual void LoadURL(const wxString
& url
);
54 virtual void LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
);
55 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetBackwardHistory();
56 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetForwardHistory();
58 virtual bool CanGoForward() const;
59 virtual bool CanGoBack() const;
60 virtual void GoBack();
61 virtual void GoForward();
62 virtual void ClearHistory();
63 virtual void EnableHistory(bool enable
= true);
65 virtual void Reload(wxWebViewReloadFlags flags
= wxWEB_VIEW_RELOAD_DEFAULT
);
67 virtual wxString
GetPageSource() const;
68 virtual wxString
GetPageText() const;
70 virtual bool IsBusy() const;
71 virtual wxString
GetCurrentURL() const;
72 virtual wxString
GetCurrentTitle() const;
74 virtual void SetZoomType(wxWebViewZoomType
);
75 virtual wxWebViewZoomType
GetZoomType() const;
76 virtual bool CanSetZoomType(wxWebViewZoomType
) const;
80 virtual void SetPage(const wxString
& html
, const wxString
& baseUrl
);
82 virtual wxWebViewZoom
GetZoom() const;
83 virtual void SetZoom(wxWebViewZoom zoom
);
86 virtual bool CanCut() const;
87 virtual bool CanCopy() const;
88 virtual bool CanPaste() const;
93 //Undo / redo functionality
94 virtual bool CanUndo() const;
95 virtual bool CanRedo() const;
100 virtual void SetEditable(bool enable
= true);
101 virtual bool IsEditable() const;
104 virtual void SelectAll();
105 virtual bool HasSelection() const;
106 virtual void DeleteSelection();
107 virtual wxString
GetSelectedText() const;
108 virtual wxString
GetSelectedSource() const;
109 virtual void ClearSelection();
111 virtual void RunScript(const wxString
& javascript
);
113 //Virtual Filesystem Support
114 virtual void RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
);
116 // ---- IE-specific methods
118 // FIXME: I seem to be able to access remote webpages even in offline mode...
119 bool IsOfflineMode();
120 void SetOfflineMode(bool offline
);
122 wxWebViewZoom
GetIETextZoom() const;
123 void SetIETextZoom(wxWebViewZoom level
);
125 wxWebViewZoom
GetIEOpticalZoom() const;
126 void SetIEOpticalZoom(wxWebViewZoom level
);
128 void onActiveXEvent(wxActiveXEvent
& evt
);
129 void onEraseBg(wxEraseEvent
&) {}
131 DECLARE_EVENT_TABLE();
134 wxActiveXContainer
* m_container
;
135 wxAutomationObject m_ie
;
136 IWebBrowser2
* m_webBrowser
;
139 //We store the current zoom type;
140 wxWebViewZoomType m_zoomType
;
142 /** The "Busy" property of IWebBrowser2 does not always return busy when
143 * we'd want it to; this variable may be set to true in cases where the
144 * Busy property is false but should be true.
147 //We manage our own history, the history list contains the history items
148 //which are added as documentcomplete events arrive, unless we are loading
149 //an item from the history. The position is stored as an int, and reflects
150 //where we are in the history list.
151 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > m_historyList
;
152 int m_historyPosition
;
153 bool m_historyLoadingFromList
;
154 bool m_historyEnabled
;
156 //Generic helper functions for IHtmlDocument commands
157 bool CanExecCommand(wxString command
) const;
158 void ExecCommand(wxString command
);
159 IHTMLDocument2
* GetDocument() const;
161 wxDECLARE_DYNAMIC_CLASS(wxWebViewIE
);
164 class VirtualProtocol
: public IInternetProtocol
168 IInternetProtocolSink
* m_protocolSink
;
173 wxSharedPtr
<wxWebViewHandler
> m_handler
;
176 VirtualProtocol(wxSharedPtr
<wxWebViewHandler
> handler
);
180 ULONG STDMETHODCALLTYPE
AddRef();
181 HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID riid
, void **ppvObject
);
182 ULONG STDMETHODCALLTYPE
Release();
184 //IInternetProtocolRoot
185 HRESULT STDMETHODCALLTYPE
Abort(HRESULT
WXUNUSED(hrReason
),
186 DWORD
WXUNUSED(dwOptions
))
187 { return E_NOTIMPL
; }
188 HRESULT STDMETHODCALLTYPE
Continue(PROTOCOLDATA
*WXUNUSED(pProtocolData
))
190 HRESULT STDMETHODCALLTYPE
Resume() { return S_OK
; }
191 HRESULT STDMETHODCALLTYPE
Start(LPCWSTR szUrl
,
192 IInternetProtocolSink
*pOIProtSink
,
193 IInternetBindInfo
*pOIBindInfo
,
195 HANDLE_PTR dwReserved
);
196 HRESULT STDMETHODCALLTYPE
Suspend() { return S_OK
; }
197 HRESULT STDMETHODCALLTYPE
Terminate(DWORD
WXUNUSED(dwOptions
)) { return S_OK
; }
200 HRESULT STDMETHODCALLTYPE
LockRequest(DWORD
WXUNUSED(dwOptions
))
202 HRESULT STDMETHODCALLTYPE
Read(void *pv
, ULONG cb
, ULONG
*pcbRead
);
203 HRESULT STDMETHODCALLTYPE
Seek(LARGE_INTEGER
WXUNUSED(dlibMove
),
204 DWORD
WXUNUSED(dwOrigin
),
205 ULARGE_INTEGER
* WXUNUSED(plibNewPosition
))
207 HRESULT STDMETHODCALLTYPE
UnlockRequest() { return S_OK
; }
210 class ClassFactory
: public IClassFactory
215 ClassFactory(wxSharedPtr
<wxWebViewHandler
> handler
) : m_handler(handler
) {}
217 ULONG STDMETHODCALLTYPE
AddRef();
218 HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID riid
, void **ppvObject
);
219 ULONG STDMETHODCALLTYPE
Release();
222 HRESULT STDMETHODCALLTYPE
CreateInstance(IUnknown
* pUnkOuter
,
223 REFIID riid
, void** ppvObject
);
224 HRESULT STDMETHODCALLTYPE
LockServer(BOOL fLock
);
226 wxSharedPtr
<wxWebViewHandler
> m_handler
;
229 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
231 #endif // wxWebViewIE_H