]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: include/wx/msw/webview_ie.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/msw/webview_missing.h" | |
26 | #include "wx/sharedptr.h" | |
27 | #include "wx/vector.h" | |
28 | ||
29 | struct IHTMLDocument2; | |
30 | struct IHTMLElement; | |
31 | struct IMarkupPointer; | |
32 | class wxFSFile; | |
33 | class ClassFactory; | |
34 | class wxIEContainer; | |
35 | class DocHostUIHandler; | |
36 | class wxFindPointers; | |
37 | class wxIInternetProtocol; | |
38 | ||
39 | class WXDLLIMPEXP_WEBVIEW wxWebViewIE : public wxWebView | |
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 | ||
56 | ~wxWebViewIE(); | |
57 | ||
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 | ||
66 | virtual void LoadURL(const wxString& url); | |
67 | virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item); | |
68 | virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory(); | |
69 | virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory(); | |
70 | ||
71 | virtual bool CanGoForward() const; | |
72 | virtual bool CanGoBack() const; | |
73 | virtual void GoBack(); | |
74 | virtual void GoForward(); | |
75 | virtual void ClearHistory(); | |
76 | virtual void EnableHistory(bool enable = true); | |
77 | virtual void Stop(); | |
78 | virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT); | |
79 | ||
80 | virtual wxString GetPageSource() const; | |
81 | virtual wxString GetPageText() const; | |
82 | ||
83 | virtual bool IsBusy() const; | |
84 | virtual wxString GetCurrentURL() const; | |
85 | virtual wxString GetCurrentTitle() const; | |
86 | ||
87 | virtual void SetZoomType(wxWebViewZoomType); | |
88 | virtual wxWebViewZoomType GetZoomType() const; | |
89 | virtual bool CanSetZoomType(wxWebViewZoomType) const; | |
90 | ||
91 | virtual void Print(); | |
92 | ||
93 | virtual wxWebViewZoom GetZoom() const; | |
94 | virtual void SetZoom(wxWebViewZoom zoom); | |
95 | ||
96 | //Clipboard functions | |
97 | virtual bool CanCut() const; | |
98 | virtual bool CanCopy() const; | |
99 | virtual bool CanPaste() const; | |
100 | virtual void Cut(); | |
101 | virtual void Copy(); | |
102 | virtual void Paste(); | |
103 | ||
104 | //Undo / redo functionality | |
105 | virtual bool CanUndo() const; | |
106 | virtual bool CanRedo() const; | |
107 | virtual void Undo(); | |
108 | virtual void Redo(); | |
109 | ||
110 | //Find function | |
111 | virtual long Find(const wxString& text, int flags = wxWEB_VIEW_FIND_DEFAULT); | |
112 | ||
113 | //Editing functions | |
114 | virtual void SetEditable(bool enable = true); | |
115 | virtual bool IsEditable() const; | |
116 | ||
117 | //Selection | |
118 | virtual void SelectAll(); | |
119 | virtual bool HasSelection() const; | |
120 | virtual void DeleteSelection(); | |
121 | virtual wxString GetSelectedText() const; | |
122 | virtual wxString GetSelectedSource() const; | |
123 | virtual void ClearSelection(); | |
124 | ||
125 | virtual void RunScript(const wxString& javascript); | |
126 | ||
127 | //Virtual Filesystem Support | |
128 | virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler); | |
129 | ||
130 | virtual void* GetNativeBackend() const { return m_webBrowser; } | |
131 | ||
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 | ||
138 | wxWebViewZoom GetIETextZoom() const; | |
139 | void SetIETextZoom(wxWebViewZoom level); | |
140 | ||
141 | wxWebViewZoom GetIEOpticalZoom() const; | |
142 | void SetIEOpticalZoom(wxWebViewZoom level); | |
143 | ||
144 | void onActiveXEvent(wxActiveXEvent& evt); | |
145 | void onEraseBg(wxEraseEvent&) {} | |
146 | ||
147 | DECLARE_EVENT_TABLE(); | |
148 | ||
149 | protected: | |
150 | virtual void DoSetPage(const wxString& html, const wxString& baseUrl); | |
151 | ||
152 | private: | |
153 | wxIEContainer* m_container; | |
154 | wxAutomationObject m_ie; | |
155 | IWebBrowser2* m_webBrowser; | |
156 | DWORD m_dwCookie; | |
157 | wxCOMPtr<DocHostUIHandler> m_uiHandler; | |
158 | ||
159 | //We store the current zoom type; | |
160 | wxWebViewZoomType m_zoomType; | |
161 | ||
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; | |
167 | //We manage our own history, the history list contains the history items | |
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. | |
171 | wxVector<wxSharedPtr<wxWebViewHistoryItem> > m_historyList; | |
172 | wxVector<ClassFactory*> m_factories; | |
173 | int m_historyPosition; | |
174 | bool m_historyLoadingFromList; | |
175 | bool m_historyEnabled; | |
176 | ||
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 | |
184 | bool CanExecCommand(wxString command) const; | |
185 | void ExecCommand(wxString command); | |
186 | wxCOMPtr<IHTMLDocument2> GetDocument() const; | |
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(); | |
192 | //Toggles control features see INTERNETFEATURELIST for values. | |
193 | bool EnableControlFeature(long flag, bool enable = true); | |
194 | ||
195 | wxDECLARE_DYNAMIC_CLASS(wxWebViewIE); | |
196 | }; | |
197 | ||
198 | class VirtualProtocol : public wxIInternetProtocol | |
199 | { | |
200 | protected: | |
201 | wxIInternetProtocolSink* m_protocolSink; | |
202 | wxString m_html; | |
203 | VOID * fileP; | |
204 | ||
205 | wxFSFile* m_file; | |
206 | wxSharedPtr<wxWebViewHandler> m_handler; | |
207 | ||
208 | public: | |
209 | VirtualProtocol(wxSharedPtr<wxWebViewHandler> handler); | |
210 | ~VirtualProtocol() {} | |
211 | ||
212 | //IUnknown | |
213 | DECLARE_IUNKNOWN_METHODS; | |
214 | ||
215 | //IInternetProtocolRoot | |
216 | HRESULT STDMETHODCALLTYPE Abort(HRESULT WXUNUSED(hrReason), | |
217 | DWORD WXUNUSED(dwOptions)) | |
218 | { return E_NOTIMPL; } | |
219 | HRESULT STDMETHODCALLTYPE Continue(wxPROTOCOLDATA *WXUNUSED(pProtocolData)) | |
220 | { return S_OK; } | |
221 | HRESULT STDMETHODCALLTYPE Resume() { return S_OK; } | |
222 | HRESULT STDMETHODCALLTYPE Start(LPCWSTR szUrl, | |
223 | wxIInternetProtocolSink *pOIProtSink, | |
224 | wxIInternetBindInfo *pOIBindInfo, | |
225 | DWORD grfPI, | |
226 | HANDLE_PTR dwReserved); | |
227 | HRESULT STDMETHODCALLTYPE Suspend() { return S_OK; } | |
228 | HRESULT STDMETHODCALLTYPE Terminate(DWORD WXUNUSED(dwOptions)) { return S_OK; } | |
229 | ||
230 | //IInternetProtocol | |
231 | HRESULT STDMETHODCALLTYPE LockRequest(DWORD WXUNUSED(dwOptions)) | |
232 | { return S_OK; } | |
233 | HRESULT STDMETHODCALLTYPE Read(void *pv, ULONG cb, ULONG *pcbRead); | |
234 | HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER WXUNUSED(dlibMove), | |
235 | DWORD WXUNUSED(dwOrigin), | |
236 | ULARGE_INTEGER* WXUNUSED(plibNewPosition)) | |
237 | { return E_FAIL; } | |
238 | HRESULT STDMETHODCALLTYPE UnlockRequest() { return S_OK; } | |
239 | }; | |
240 | ||
241 | class ClassFactory : public IClassFactory | |
242 | { | |
243 | public: | |
244 | ClassFactory(wxSharedPtr<wxWebViewHandler> handler) : m_handler(handler) | |
245 | { AddRef(); } | |
246 | ||
247 | wxString GetName() { return m_handler->GetName(); } | |
248 | ||
249 | //IClassFactory | |
250 | HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown* pUnkOuter, | |
251 | REFIID riid, void** ppvObject); | |
252 | HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock); | |
253 | ||
254 | //IUnknown | |
255 | DECLARE_IUNKNOWN_METHODS; | |
256 | ||
257 | private: | |
258 | wxSharedPtr<wxWebViewHandler> m_handler; | |
259 | }; | |
260 | ||
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); | |
279 | ||
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 | ||
306 | virtual HRESULT wxSTDCALL GetOptionKeyPath(LPOLESTR *pchKey, | |
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, | |
315 | OLECHAR *pchURLIn, | |
316 | OLECHAR **ppchURLOut); | |
317 | ||
318 | virtual HRESULT wxSTDCALL FilterDataObject(IDataObject *pDO, | |
319 | IDataObject **ppDORet); | |
320 | //IUnknown | |
321 | DECLARE_IUNKNOWN_METHODS; | |
322 | }; | |
323 | ||
324 | class wxFindPointers | |
325 | { | |
326 | public: | |
327 | wxFindPointers(wxIMarkupPointer *ptrBegin, wxIMarkupPointer *ptrEnd) | |
328 | { | |
329 | begin = ptrBegin; | |
330 | end = ptrEnd; | |
331 | } | |
332 | //The two markup pointers. | |
333 | wxIMarkupPointer *begin, *end; | |
334 | }; | |
335 | ||
336 | #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__) | |
337 | ||
338 | #endif // wxWebViewIE_H |