]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/webview_ie.h
0f613d1200721b1f557a22459fd6d513c0e2e204
[wxWidgets.git] / include / wx / msw / webview_ie.h
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 WXDLLIMPEXP_WEBVIEW wxWebViewFactoryIE : public wxWebViewFactory
199 {
200 public:
201 virtual wxWebView* Create() { return new wxWebViewIE; }
202 virtual wxWebView* Create(wxWindow* parent,
203 wxWindowID id,
204 const wxString& url = wxWebViewDefaultURLStr,
205 const wxPoint& pos = wxDefaultPosition,
206 const wxSize& size = wxDefaultSize,
207 long style = 0,
208 const wxString& name = wxWebViewNameStr)
209 { return new wxWebViewIE(parent, id, url, pos, size, style, name); }
210 };
211
212 class VirtualProtocol : public wxIInternetProtocol
213 {
214 protected:
215 wxIInternetProtocolSink* m_protocolSink;
216 wxString m_html;
217 VOID * fileP;
218
219 wxFSFile* m_file;
220 wxSharedPtr<wxWebViewHandler> m_handler;
221
222 public:
223 VirtualProtocol(wxSharedPtr<wxWebViewHandler> handler);
224 ~VirtualProtocol() {}
225
226 //IUnknown
227 DECLARE_IUNKNOWN_METHODS;
228
229 //IInternetProtocolRoot
230 HRESULT STDMETHODCALLTYPE Abort(HRESULT WXUNUSED(hrReason),
231 DWORD WXUNUSED(dwOptions))
232 { return E_NOTIMPL; }
233 HRESULT STDMETHODCALLTYPE Continue(wxPROTOCOLDATA *WXUNUSED(pProtocolData))
234 { return S_OK; }
235 HRESULT STDMETHODCALLTYPE Resume() { return S_OK; }
236 HRESULT STDMETHODCALLTYPE Start(LPCWSTR szUrl,
237 wxIInternetProtocolSink *pOIProtSink,
238 wxIInternetBindInfo *pOIBindInfo,
239 DWORD grfPI,
240 HANDLE_PTR dwReserved);
241 HRESULT STDMETHODCALLTYPE Suspend() { return S_OK; }
242 HRESULT STDMETHODCALLTYPE Terminate(DWORD WXUNUSED(dwOptions)) { return S_OK; }
243
244 //IInternetProtocol
245 HRESULT STDMETHODCALLTYPE LockRequest(DWORD WXUNUSED(dwOptions))
246 { return S_OK; }
247 HRESULT STDMETHODCALLTYPE Read(void *pv, ULONG cb, ULONG *pcbRead);
248 HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER WXUNUSED(dlibMove),
249 DWORD WXUNUSED(dwOrigin),
250 ULARGE_INTEGER* WXUNUSED(plibNewPosition))
251 { return E_FAIL; }
252 HRESULT STDMETHODCALLTYPE UnlockRequest() { return S_OK; }
253 };
254
255 class ClassFactory : public IClassFactory
256 {
257 public:
258 ClassFactory(wxSharedPtr<wxWebViewHandler> handler) : m_handler(handler)
259 { AddRef(); }
260
261 wxString GetName() { return m_handler->GetName(); }
262
263 //IClassFactory
264 HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown* pUnkOuter,
265 REFIID riid, void** ppvObject);
266 HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock);
267
268 //IUnknown
269 DECLARE_IUNKNOWN_METHODS;
270
271 private:
272 wxSharedPtr<wxWebViewHandler> m_handler;
273 };
274
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:
288 DocHostUIHandler(wxWebView* browser) { m_browser = browser; }
289 ~DocHostUIHandler() {};
290
291 virtual HRESULT wxSTDCALL ShowContextMenu(DWORD dwID, POINT *ppt,
292 IUnknown *pcmdtReserved,
293 IDispatch *pdispReserved);
294
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
321 virtual HRESULT wxSTDCALL GetOptionKeyPath(LPOLESTR *pchKey,
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,
330 OLECHAR *pchURLIn,
331 OLECHAR **ppchURLOut);
332
333 virtual HRESULT wxSTDCALL FilterDataObject(IDataObject *pDO,
334 IDataObject **ppDORet);
335 //IUnknown
336 DECLARE_IUNKNOWN_METHODS;
337
338 private:
339 wxWebView* m_browser;
340 };
341
342 class wxFindPointers
343 {
344 public:
345 wxFindPointers(wxIMarkupPointer *ptrBegin, wxIMarkupPointer *ptrEnd)
346 {
347 begin = ptrBegin;
348 end = ptrEnd;
349 }
350 //The two markup pointers.
351 wxIMarkupPointer *begin, *end;
352 };
353
354 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
355
356 #endif // wxWebViewIE_H