]>
Commit | Line | Data |
---|---|---|
61b98a2d | 1 | ///////////////////////////////////////////////////////////////////////////// |
e52aec97 | 2 | // Name: include/wx/msw/webview_ie.h |
61b98a2d SL |
3 | // Purpose: wxMSW IE wxWebView backend |
4 | // Author: Marianne Gagnon | |
153530af | 5 | // Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton |
61b98a2d SL |
6 | // Licence: wxWindows licence |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | #ifndef wxWebViewIE_H | |
10 | #define wxWebViewIE_H | |
11 | ||
12 | #include "wx/setup.h" | |
13 | ||
9d2f31db | 14 | #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__) |
61b98a2d SL |
15 | |
16 | #include "wx/control.h" | |
17 | #include "wx/webview.h" | |
18 | #include "wx/msw/ole/automtn.h" | |
19 | #include "wx/msw/ole/activex.h" | |
9f194b9d | 20 | #include "wx/msw/ole/oleutils.h" |
f40f8e17 | 21 | #include "wx/msw/private/comptr.h" |
97aa7b99 | 22 | #include "wx/msw/wrapwin.h" |
e924e848 | 23 | #include "wx/msw/missing.h" |
e52aec97 | 24 | #include "wx/msw/webview_missing.h" |
74af0b13 | 25 | #include "wx/sharedptr.h" |
5cbda74b | 26 | #include "wx/vector.h" |
61b98a2d | 27 | |
22ca10fa | 28 | struct IHTMLDocument2; |
66ac0400 SL |
29 | struct IHTMLElement; |
30 | struct IMarkupPointer; | |
7d3f6b4d | 31 | class wxFSFile; |
39498710 | 32 | class ClassFactory; |
accc94d5 SL |
33 | class wxIEContainer; |
34 | class DocHostUIHandler; | |
66ac0400 | 35 | class wxFindPointers; |
e52aec97 | 36 | class wxIInternetProtocol; |
29365629 | 37 | |
467d261e | 38 | class WXDLLIMPEXP_WEBVIEW wxWebViewIE : public wxWebView |
61b98a2d SL |
39 | { |
40 | public: | |
41 | ||
42 | wxWebViewIE() {} | |
43 | ||
44 | wxWebViewIE(wxWindow* parent, | |
45 | wxWindowID id, | |
46 | const wxString& url = wxWebViewDefaultURLStr, | |
47 | const wxPoint& pos = wxDefaultPosition, | |
48 | const wxSize& size = wxDefaultSize, | |
49 | long style = 0, | |
50 | const wxString& name = wxWebViewNameStr) | |
51 | { | |
52 | Create(parent, id, url, pos, size, style, name); | |
53 | } | |
54 | ||
39498710 SL |
55 | ~wxWebViewIE(); |
56 | ||
61b98a2d SL |
57 | bool Create(wxWindow* parent, |
58 | wxWindowID id, | |
59 | const wxString& url = wxWebViewDefaultURLStr, | |
60 | const wxPoint& pos = wxDefaultPosition, | |
61 | const wxSize& size = wxDefaultSize, | |
62 | long style = 0, | |
63 | const wxString& name = wxWebViewNameStr); | |
64 | ||
4d0dddc7 | 65 | virtual void LoadURL(const wxString& url); |
c13d6ac1 SL |
66 | virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item); |
67 | virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory(); | |
68 | virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory(); | |
61b98a2d | 69 | |
e669ddde SL |
70 | virtual bool CanGoForward() const; |
71 | virtual bool CanGoBack() const; | |
61b98a2d SL |
72 | virtual void GoBack(); |
73 | virtual void GoForward(); | |
74af0b13 SL |
74 | virtual void ClearHistory(); |
75 | virtual void EnableHistory(bool enable = true); | |
61b98a2d | 76 | virtual void Stop(); |
236cff73 | 77 | virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT); |
61b98a2d | 78 | |
e669ddde SL |
79 | virtual wxString GetPageSource() const; |
80 | virtual wxString GetPageText() const; | |
61b98a2d | 81 | |
e669ddde SL |
82 | virtual bool IsBusy() const; |
83 | virtual wxString GetCurrentURL() const; | |
84 | virtual wxString GetCurrentTitle() const; | |
61b98a2d SL |
85 | |
86 | virtual void SetZoomType(wxWebViewZoomType); | |
87 | virtual wxWebViewZoomType GetZoomType() const; | |
88 | virtual bool CanSetZoomType(wxWebViewZoomType) const; | |
89 | ||
90 | virtual void Print(); | |
91 | ||
e669ddde | 92 | virtual wxWebViewZoom GetZoom() const; |
61b98a2d SL |
93 | virtual void SetZoom(wxWebViewZoom zoom); |
94 | ||
4681a3ea | 95 | //Clipboard functions |
e669ddde SL |
96 | virtual bool CanCut() const; |
97 | virtual bool CanCopy() const; | |
98 | virtual bool CanPaste() const; | |
4681a3ea SL |
99 | virtual void Cut(); |
100 | virtual void Copy(); | |
101 | virtual void Paste(); | |
102 | ||
97e49559 | 103 | //Undo / redo functionality |
e669ddde SL |
104 | virtual bool CanUndo() const; |
105 | virtual bool CanRedo() const; | |
97e49559 SL |
106 | virtual void Undo(); |
107 | virtual void Redo(); | |
108 | ||
66ac0400 | 109 | //Find function |
236cff73 | 110 | virtual long Find(const wxString& text, int flags = wxWEBVIEW_FIND_DEFAULT); |
66ac0400 | 111 | |
c7cbe308 SL |
112 | //Editing functions |
113 | virtual void SetEditable(bool enable = true); | |
e669ddde | 114 | virtual bool IsEditable() const; |
c7cbe308 | 115 | |
63a65070 SL |
116 | //Selection |
117 | virtual void SelectAll(); | |
e669ddde | 118 | virtual bool HasSelection() const; |
63a65070 | 119 | virtual void DeleteSelection(); |
e669ddde SL |
120 | virtual wxString GetSelectedText() const; |
121 | virtual wxString GetSelectedSource() const; | |
41933aa5 | 122 | virtual void ClearSelection(); |
63a65070 | 123 | |
c9ccc09c | 124 | virtual void RunScript(const wxString& javascript); |
63a65070 | 125 | |
29365629 | 126 | //Virtual Filesystem Support |
7d8d6163 | 127 | virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler); |
29365629 | 128 | |
b6a49c2b VZ |
129 | virtual void* GetNativeBackend() const { return m_webBrowser; } |
130 | ||
61b98a2d SL |
131 | // ---- IE-specific methods |
132 | ||
133 | // FIXME: I seem to be able to access remote webpages even in offline mode... | |
134 | bool IsOfflineMode(); | |
135 | void SetOfflineMode(bool offline); | |
136 | ||
e669ddde | 137 | wxWebViewZoom GetIETextZoom() const; |
c5f417cb | 138 | void SetIETextZoom(wxWebViewZoom level); |
61b98a2d | 139 | |
e669ddde | 140 | wxWebViewZoom GetIEOpticalZoom() const; |
c5f417cb | 141 | void SetIEOpticalZoom(wxWebViewZoom level); |
61b98a2d SL |
142 | |
143 | void onActiveXEvent(wxActiveXEvent& evt); | |
22ca10fa | 144 | void onEraseBg(wxEraseEvent&) {} |
61b98a2d SL |
145 | |
146 | DECLARE_EVENT_TABLE(); | |
147 | ||
a977376a VZ |
148 | protected: |
149 | virtual void DoSetPage(const wxString& html, const wxString& baseUrl); | |
150 | ||
61b98a2d | 151 | private: |
accc94d5 | 152 | wxIEContainer* m_container; |
61b98a2d SL |
153 | wxAutomationObject m_ie; |
154 | IWebBrowser2* m_webBrowser; | |
155 | DWORD m_dwCookie; | |
f40f8e17 | 156 | wxCOMPtr<DocHostUIHandler> m_uiHandler; |
61b98a2d | 157 | |
c5f417cb SL |
158 | //We store the current zoom type; |
159 | wxWebViewZoomType m_zoomType; | |
160 | ||
61b98a2d SL |
161 | /** The "Busy" property of IWebBrowser2 does not always return busy when |
162 | * we'd want it to; this variable may be set to true in cases where the | |
163 | * Busy property is false but should be true. | |
164 | */ | |
165 | bool m_isBusy; | |
60eabdbe | 166 | //We manage our own history, the history list contains the history items |
3e7968c2 SL |
167 | //which are added as documentcomplete events arrive, unless we are loading |
168 | //an item from the history. The position is stored as an int, and reflects | |
169 | //where we are in the history list. | |
c13d6ac1 | 170 | wxVector<wxSharedPtr<wxWebViewHistoryItem> > m_historyList; |
39498710 | 171 | wxVector<ClassFactory*> m_factories; |
74af0b13 SL |
172 | int m_historyPosition; |
173 | bool m_historyLoadingFromList; | |
174 | bool m_historyEnabled; | |
175 | ||
66ac0400 SL |
176 | //We store find flag, results and position. |
177 | wxVector<wxFindPointers> m_findPointers; | |
178 | int m_findFlags; | |
179 | wxString m_findText; | |
180 | int m_findPosition; | |
181 | ||
182 | //Generic helper functions | |
e669ddde | 183 | bool CanExecCommand(wxString command) const; |
4681a3ea | 184 | void ExecCommand(wxString command); |
f40f8e17 | 185 | wxCOMPtr<IHTMLDocument2> GetDocument() const; |
938506b1 | 186 | bool IsElementVisible(wxCOMPtr<IHTMLElement> elm); |
66ac0400 SL |
187 | //Find helper functions. |
188 | void FindInternal(const wxString& text, int flags, int internal_flag); | |
189 | long FindNext(int direction = 1); | |
190 | void FindClear(); | |
9447a0d6 SL |
191 | //Toggles control features see INTERNETFEATURELIST for values. |
192 | bool EnableControlFeature(long flag, bool enable = true); | |
4681a3ea | 193 | |
cddf4541 | 194 | wxDECLARE_DYNAMIC_CLASS(wxWebViewIE); |
61b98a2d SL |
195 | }; |
196 | ||
4c687fff SL |
197 | class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryIE : public wxWebViewFactory |
198 | { | |
199 | public: | |
200 | virtual wxWebView* Create() { return new wxWebViewIE; } | |
201 | virtual wxWebView* Create(wxWindow* parent, | |
202 | wxWindowID id, | |
203 | const wxString& url = wxWebViewDefaultURLStr, | |
204 | const wxPoint& pos = wxDefaultPosition, | |
205 | const wxSize& size = wxDefaultSize, | |
206 | long style = 0, | |
207 | const wxString& name = wxWebViewNameStr) | |
208 | { return new wxWebViewIE(parent, id, url, pos, size, style, name); } | |
209 | }; | |
210 | ||
f559d1a2 | 211 | class VirtualProtocol : public wxIInternetProtocol |
7d3f6b4d SL |
212 | { |
213 | protected: | |
f559d1a2 | 214 | wxIInternetProtocolSink* m_protocolSink; |
7d3f6b4d SL |
215 | wxString m_html; |
216 | VOID * fileP; | |
217 | ||
218 | wxFSFile* m_file; | |
7d8d6163 | 219 | wxSharedPtr<wxWebViewHandler> m_handler; |
7d3f6b4d SL |
220 | |
221 | public: | |
7d8d6163 | 222 | VirtualProtocol(wxSharedPtr<wxWebViewHandler> handler); |
9fe7a9ad | 223 | virtual ~VirtualProtocol() {} |
7d3f6b4d SL |
224 | |
225 | //IUnknown | |
9f194b9d | 226 | DECLARE_IUNKNOWN_METHODS; |
7d3f6b4d SL |
227 | |
228 | //IInternetProtocolRoot | |
60eabdbe | 229 | HRESULT STDMETHODCALLTYPE Abort(HRESULT WXUNUSED(hrReason), |
0995b9dc | 230 | DWORD WXUNUSED(dwOptions)) |
7d3f6b4d | 231 | { return E_NOTIMPL; } |
f559d1a2 | 232 | HRESULT STDMETHODCALLTYPE Continue(wxPROTOCOLDATA *WXUNUSED(pProtocolData)) |
7d3f6b4d SL |
233 | { return S_OK; } |
234 | HRESULT STDMETHODCALLTYPE Resume() { return S_OK; } | |
60eabdbe | 235 | HRESULT STDMETHODCALLTYPE Start(LPCWSTR szUrl, |
f559d1a2 VZ |
236 | wxIInternetProtocolSink *pOIProtSink, |
237 | wxIInternetBindInfo *pOIBindInfo, | |
60eabdbe | 238 | DWORD grfPI, |
7d3f6b4d SL |
239 | HANDLE_PTR dwReserved); |
240 | HRESULT STDMETHODCALLTYPE Suspend() { return S_OK; } | |
0995b9dc | 241 | HRESULT STDMETHODCALLTYPE Terminate(DWORD WXUNUSED(dwOptions)) { return S_OK; } |
7d3f6b4d SL |
242 | |
243 | //IInternetProtocol | |
60eabdbe | 244 | HRESULT STDMETHODCALLTYPE LockRequest(DWORD WXUNUSED(dwOptions)) |
0995b9dc | 245 | { return S_OK; } |
7d3f6b4d | 246 | HRESULT STDMETHODCALLTYPE Read(void *pv, ULONG cb, ULONG *pcbRead); |
60eabdbe VZ |
247 | HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER WXUNUSED(dlibMove), |
248 | DWORD WXUNUSED(dwOrigin), | |
249 | ULARGE_INTEGER* WXUNUSED(plibNewPosition)) | |
7d3f6b4d SL |
250 | { return E_FAIL; } |
251 | HRESULT STDMETHODCALLTYPE UnlockRequest() { return S_OK; } | |
252 | }; | |
253 | ||
254 | class ClassFactory : public IClassFactory | |
255 | { | |
7d3f6b4d | 256 | public: |
8626e0b7 | 257 | ClassFactory(wxSharedPtr<wxWebViewHandler> handler) : m_handler(handler) |
9fe7a9ad VZ |
258 | { AddRef(); } |
259 | virtual ~ClassFactory() {} | |
8626e0b7 SL |
260 | |
261 | wxString GetName() { return m_handler->GetName(); } | |
7d3f6b4d SL |
262 | |
263 | //IClassFactory | |
60eabdbe | 264 | HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown* pUnkOuter, |
7d3f6b4d SL |
265 | REFIID riid, void** ppvObject); |
266 | HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock); | |
9f194b9d SL |
267 | |
268 | //IUnknown | |
269 | DECLARE_IUNKNOWN_METHODS; | |
270 | ||
29365629 | 271 | private: |
7d8d6163 | 272 | wxSharedPtr<wxWebViewHandler> m_handler; |
7d3f6b4d SL |
273 | }; |
274 | ||
accc94d5 SL |
275 | class wxIEContainer : public wxActiveXContainer |
276 | { | |
277 | public: | |
278 | wxIEContainer(wxWindow *parent, REFIID iid, IUnknown *pUnk, DocHostUIHandler* uiHandler = NULL); | |
279 | virtual ~wxIEContainer(); | |
280 | virtual bool QueryClientSiteInterface(REFIID iid, void **_interface, const char *&desc); | |
281 | private: | |
282 | DocHostUIHandler* m_uiHandler; | |
283 | }; | |
284 | ||
285 | class DocHostUIHandler : public wxIDocHostUIHandler | |
286 | { | |
287 | public: | |
c420d57b | 288 | DocHostUIHandler(wxWebView* browser) { m_browser = browser; } |
9fe7a9ad | 289 | virtual ~DocHostUIHandler() {} |
c420d57b | 290 | |
accc94d5 SL |
291 | virtual HRESULT wxSTDCALL ShowContextMenu(DWORD dwID, POINT *ppt, |
292 | IUnknown *pcmdtReserved, | |
293 | IDispatch *pdispReserved); | |
34326da7 | 294 | |
accc94d5 SL |
295 | virtual HRESULT wxSTDCALL GetHostInfo(DOCHOSTUIINFO *pInfo); |
296 | ||
297 | virtual HRESULT wxSTDCALL ShowUI(DWORD dwID, | |
298 | IOleInPlaceActiveObject *pActiveObject, | |
299 | IOleCommandTarget *pCommandTarget, | |
300 | IOleInPlaceFrame *pFrame, | |
301 | IOleInPlaceUIWindow *pDoc); | |
302 | ||
303 | virtual HRESULT wxSTDCALL HideUI(void); | |
304 | ||
305 | virtual HRESULT wxSTDCALL UpdateUI(void); | |
306 | ||
307 | virtual HRESULT wxSTDCALL EnableModeless(BOOL fEnable); | |
308 | ||
309 | virtual HRESULT wxSTDCALL OnDocWindowActivate(BOOL fActivate); | |
310 | ||
311 | virtual HRESULT wxSTDCALL OnFrameWindowActivate(BOOL fActivate); | |
312 | ||
313 | virtual HRESULT wxSTDCALL ResizeBorder(LPCRECT prcBorder, | |
314 | IOleInPlaceUIWindow *pUIWindow, | |
315 | BOOL fRameWindow); | |
316 | ||
317 | virtual HRESULT wxSTDCALL TranslateAccelerator(LPMSG lpMsg, | |
318 | const GUID *pguidCmdGroup, | |
319 | DWORD nCmdID); | |
320 | ||
34326da7 | 321 | virtual HRESULT wxSTDCALL GetOptionKeyPath(LPOLESTR *pchKey, |
accc94d5 SL |
322 | DWORD dw); |
323 | ||
324 | virtual HRESULT wxSTDCALL GetDropTarget(IDropTarget *pDropTarget, | |
325 | IDropTarget **ppDropTarget); | |
326 | ||
327 | virtual HRESULT wxSTDCALL GetExternal(IDispatch **ppDispatch); | |
328 | ||
329 | virtual HRESULT wxSTDCALL TranslateUrl(DWORD dwTranslate, | |
96457e67 SL |
330 | OLECHAR *pchURLIn, |
331 | OLECHAR **ppchURLOut); | |
accc94d5 SL |
332 | |
333 | virtual HRESULT wxSTDCALL FilterDataObject(IDataObject *pDO, | |
334 | IDataObject **ppDORet); | |
335 | //IUnknown | |
336 | DECLARE_IUNKNOWN_METHODS; | |
c420d57b SL |
337 | |
338 | private: | |
339 | wxWebView* m_browser; | |
accc94d5 SL |
340 | }; |
341 | ||
66ac0400 SL |
342 | class wxFindPointers |
343 | { | |
344 | public: | |
e52aec97 | 345 | wxFindPointers(wxIMarkupPointer *ptrBegin, wxIMarkupPointer *ptrEnd) |
66ac0400 SL |
346 | { |
347 | begin = ptrBegin; | |
348 | end = ptrEnd; | |
349 | } | |
350 | //The two markup pointers. | |
e52aec97 | 351 | wxIMarkupPointer *begin, *end; |
66ac0400 SL |
352 | }; |
353 | ||
9d2f31db | 354 | #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__) |
61b98a2d SL |
355 | |
356 | #endif // wxWebViewIE_H |