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