1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/msw/webviewie.h
3 // Purpose: wxMSW IE wxWebView backend
4 // Author: Marianne Gagnon
6 // Copyright: (c) 2010 Marianne Gagnon, Steven Lamerton
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
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/sharedptr.h"
22 #include "wx/vector.h"
24 struct IHTMLDocument2
;
29 //Loads from uris such as file:///C:/example/example.html or archives such as
30 //file:///C:/example/example.zip?protocol=zip;path=example.html
31 class WXDLLIMPEXP_WEB wxWebFileProtocolHandler
: public wxWebProtocolHandler
34 wxWebFileProtocolHandler();
35 virtual wxString
GetProtocol() { return m_protocol
; }
36 virtual wxFSFile
* GetFile(const wxString
&uri
);
37 virtual wxString
CombineURIs(const wxString
&baseuri
, const wxString
&newuri
);
40 wxFileSystem
* m_fileSystem
;
43 class WXDLLIMPEXP_WEB wxWebViewIE
: public wxWebView
49 wxWebViewIE(wxWindow
* parent
,
51 const wxString
& url
= wxWebViewDefaultURLStr
,
52 const wxPoint
& pos
= wxDefaultPosition
,
53 const wxSize
& size
= wxDefaultSize
,
55 const wxString
& name
= wxWebViewNameStr
)
57 Create(parent
, id
, url
, pos
, size
, style
, name
);
60 bool Create(wxWindow
* parent
,
62 const wxString
& url
= wxWebViewDefaultURLStr
,
63 const wxPoint
& pos
= wxDefaultPosition
,
64 const wxSize
& size
= wxDefaultSize
,
66 const wxString
& name
= wxWebViewNameStr
);
68 virtual void LoadUrl(const wxString
& url
);
69 virtual void LoadHistoryItem(wxSharedPtr
<wxWebHistoryItem
> item
);
70 virtual wxVector
<wxSharedPtr
<wxWebHistoryItem
> > GetBackwardHistory();
71 virtual wxVector
<wxSharedPtr
<wxWebHistoryItem
> > GetForwardHistory();
73 virtual bool CanGoForward();
74 virtual bool CanGoBack();
75 virtual void GoBack();
76 virtual void GoForward();
77 virtual void ClearHistory();
78 virtual void EnableHistory(bool enable
= true);
80 virtual void Reload(wxWebViewReloadFlags flags
= wxWEB_VIEW_RELOAD_DEFAULT
);
82 virtual wxString
GetPageSource();
83 virtual wxString
GetPageText();
85 virtual bool IsBusy();
86 virtual wxString
GetCurrentURL();
87 virtual wxString
GetCurrentTitle();
89 virtual void SetZoomType(wxWebViewZoomType
);
90 virtual wxWebViewZoomType
GetZoomType() const;
91 virtual bool CanSetZoomType(wxWebViewZoomType
) const;
95 virtual void SetPage(const wxString
& html
, const wxString
& baseUrl
);
97 virtual wxWebViewZoom
GetZoom();
98 virtual void SetZoom(wxWebViewZoom zoom
);
100 //Clipboard functions
101 virtual bool CanCut();
102 virtual bool CanCopy();
103 virtual bool CanPaste();
106 virtual void Paste();
108 //Undo / redo functionality
109 virtual bool CanUndo();
110 virtual bool CanRedo();
115 virtual void SetEditable(bool enable
= true);
116 virtual bool IsEditable();
119 virtual void SelectAll();
120 virtual bool HasSelection();
121 virtual void DeleteSelection();
122 virtual wxString
GetSelectedText();
123 virtual wxString
GetSelectedSource();
124 virtual void ClearSelection();
126 virtual void RunScript(const wxString
& javascript
);
128 //Virtual Filesystem Support
129 virtual void RegisterProtocol(wxWebProtocolHandler
* hanlder
);
131 // ---- IE-specific methods
133 // FIXME: I seem to be able to access remote webpages even in offline mode...
134 bool IsOfflineMode();
135 void SetOfflineMode(bool offline
);
137 wxWebViewZoom
GetIETextZoom();
138 void SetIETextZoom(wxWebViewZoom level
);
140 wxWebViewZoom
GetIEOpticalZoom();
141 void SetIEOpticalZoom(wxWebViewZoom level
);
143 void onActiveXEvent(wxActiveXEvent
& evt
);
144 void onEraseBg(wxEraseEvent
&) {}
146 DECLARE_EVENT_TABLE();
149 wxActiveXContainer
* m_container
;
150 wxAutomationObject m_ie
;
151 IWebBrowser2
* m_webBrowser
;
154 //We store the current zoom type;
155 wxWebViewZoomType m_zoomType
;
157 /** The "Busy" property of IWebBrowser2 does not always return busy when
158 * we'd want it to; this variable may be set to true in cases where the
159 * Busy property is false but should be true.
162 //We manage our own history, the history list contains the history items
163 //which are added as documentcomplete events arrive, unless we are loading
164 //an item from the history. The position is stored as an int, and reflects
165 //where we are in the history list.
166 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > m_historyList
;
167 int m_historyPosition
;
168 bool m_historyLoadingFromList
;
169 bool m_historyEnabled
;
171 //Generic helper functions for IHtmlDocument commands
172 bool CanExecCommand(wxString command
);
173 void ExecCommand(wxString command
);
174 IHTMLDocument2
* GetDocument();
178 class VirtualProtocol
: public IInternetProtocol
, public IInternetProtocolInfo
182 IInternetProtocolSink
* m_protocolSink
;
187 wxWebProtocolHandler
* m_handler
;
190 VirtualProtocol(wxWebProtocolHandler
*handler
);
194 ULONG STDMETHODCALLTYPE
AddRef();
195 HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID riid
, void **ppvObject
);
196 ULONG STDMETHODCALLTYPE
Release();
198 //IInternetProtocolRoot
199 HRESULT STDMETHODCALLTYPE
Abort(HRESULT
WXUNUSED(hrReason
),
200 DWORD
WXUNUSED(dwOptions
))
201 { return E_NOTIMPL
; }
202 HRESULT STDMETHODCALLTYPE
Continue(PROTOCOLDATA
*WXUNUSED(pProtocolData
))
204 HRESULT STDMETHODCALLTYPE
Resume() { return S_OK
; }
205 HRESULT STDMETHODCALLTYPE
Start(LPCWSTR szUrl
,
206 IInternetProtocolSink
*pOIProtSink
,
207 IInternetBindInfo
*pOIBindInfo
,
209 HANDLE_PTR dwReserved
);
210 HRESULT STDMETHODCALLTYPE
Suspend() { return S_OK
; }
211 HRESULT STDMETHODCALLTYPE
Terminate(DWORD
WXUNUSED(dwOptions
)) { return S_OK
; }
214 HRESULT STDMETHODCALLTYPE
LockRequest(DWORD
WXUNUSED(dwOptions
))
216 HRESULT STDMETHODCALLTYPE
Read(void *pv
, ULONG cb
, ULONG
*pcbRead
);
217 HRESULT STDMETHODCALLTYPE
Seek(LARGE_INTEGER
WXUNUSED(dlibMove
),
218 DWORD
WXUNUSED(dwOrigin
),
219 ULARGE_INTEGER
* WXUNUSED(plibNewPosition
))
221 HRESULT STDMETHODCALLTYPE
UnlockRequest() { return S_OK
; }
223 //IInternetProtocolInfo
224 HRESULT STDMETHODCALLTYPE
CombineUrl(LPCWSTR pwzBaseUrl
,
225 LPCWSTR pwzRelativeUrl
,
226 DWORD dwCombineFlags
,
227 LPWSTR pwzResult
, DWORD cchResult
,
228 DWORD
*pcchResult
, DWORD dwReserved
);
229 HRESULT STDMETHODCALLTYPE
CompareUrl(LPCWSTR pwzUrl1
, LPCWSTR pwzUrl2
,
230 DWORD dwCompareFlags
)
231 { return INET_E_DEFAULT_ACTION
; }
232 HRESULT STDMETHODCALLTYPE
ParseUrl(LPCWSTR pwzUrl
, PARSEACTION ParseAction
,
233 DWORD dwParseFlags
, LPWSTR pwzResult
,
234 DWORD cchResult
, DWORD
*pcchResult
,
236 HRESULT STDMETHODCALLTYPE
QueryInfo(LPCWSTR pwzUrl
,
237 QUERYOPTION OueryOption
,
238 DWORD dwQueryFlags
, LPVOID pBuffer
,
239 DWORD cbBuffer
, DWORD
*pcbBuf
,
243 class ClassFactory
: public IClassFactory
248 ClassFactory(wxWebProtocolHandler
* handler
) : m_handler(handler
) {}
250 ULONG STDMETHODCALLTYPE
AddRef();
251 HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID riid
, void **ppvObject
);
252 ULONG STDMETHODCALLTYPE
Release();
255 HRESULT STDMETHODCALLTYPE
CreateInstance(IUnknown
* pUnkOuter
,
256 REFIID riid
, void** ppvObject
);
257 HRESULT STDMETHODCALLTYPE
LockServer(BOOL fLock
);
259 wxWebProtocolHandler
* m_handler
;
262 #endif // wxUSE_WEBVIEW_IE
264 #endif // wxWebViewIE_H