]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/webview_ie.h
68dd4d712164c017bb38fa483f4d21a21b0a063f
[wxWidgets.git] / include / wx / msw / webview_ie.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/msw/webviewie.h
3 // Purpose: wxMSW IE wxWebView backend
4 // Author: Marianne Gagnon
5 // Id: $Id$
6 // Copyright: (c) 2010 Marianne Gagnon, 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_IE
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/sharedptr.h"
22 #include "wx/vector.h"
23
24 struct IHTMLDocument2;
25
26 class wxFSFile;
27 class wxFileSystem;
28
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
32 {
33 public:
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);
38 private:
39 wxString m_protocol;
40 wxFileSystem* m_fileSystem;
41 };
42
43 class WXDLLIMPEXP_WEB wxWebViewIE : public wxWebView
44 {
45 public:
46
47 wxWebViewIE() {}
48
49 wxWebViewIE(wxWindow* parent,
50 wxWindowID id,
51 const wxString& url = wxWebViewDefaultURLStr,
52 const wxPoint& pos = wxDefaultPosition,
53 const wxSize& size = wxDefaultSize,
54 long style = 0,
55 const wxString& name = wxWebViewNameStr)
56 {
57 Create(parent, id, url, pos, size, style, name);
58 }
59
60 bool Create(wxWindow* parent,
61 wxWindowID id,
62 const wxString& url = wxWebViewDefaultURLStr,
63 const wxPoint& pos = wxDefaultPosition,
64 const wxSize& size = wxDefaultSize,
65 long style = 0,
66 const wxString& name = wxWebViewNameStr);
67
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();
72
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);
79 virtual void Stop();
80 virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT);
81
82 virtual wxString GetPageSource();
83 virtual wxString GetPageText();
84
85 virtual bool IsBusy();
86 virtual wxString GetCurrentURL();
87 virtual wxString GetCurrentTitle();
88
89 virtual void SetZoomType(wxWebViewZoomType);
90 virtual wxWebViewZoomType GetZoomType() const;
91 virtual bool CanSetZoomType(wxWebViewZoomType) const;
92
93 virtual void Print();
94
95 virtual void SetPage(const wxString& html, const wxString& baseUrl);
96
97 virtual wxWebViewZoom GetZoom();
98 virtual void SetZoom(wxWebViewZoom zoom);
99
100 //Clipboard functions
101 virtual bool CanCut();
102 virtual bool CanCopy();
103 virtual bool CanPaste();
104 virtual void Cut();
105 virtual void Copy();
106 virtual void Paste();
107
108 //Undo / redo functionality
109 virtual bool CanUndo();
110 virtual bool CanRedo();
111 virtual void Undo();
112 virtual void Redo();
113
114 //Editing functions
115 virtual void SetEditable(bool enable = true);
116 virtual bool IsEditable();
117
118 //Selection
119 virtual void SelectAll();
120 virtual bool HasSelection();
121 virtual void DeleteSelection();
122 virtual wxString GetSelectedText();
123 virtual wxString GetSelectedSource();
124 virtual void ClearSelection();
125
126 virtual void RunScript(const wxString& javascript);
127
128 //Virtual Filesystem Support
129 virtual void RegisterProtocol(wxWebProtocolHandler* hanlder);
130
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
137 wxWebViewZoom GetIETextZoom();
138 void SetIETextZoom(wxWebViewZoom level);
139
140 wxWebViewZoom GetIEOpticalZoom();
141 void SetIEOpticalZoom(wxWebViewZoom level);
142
143 void onActiveXEvent(wxActiveXEvent& evt);
144 void onEraseBg(wxEraseEvent&) {}
145
146 DECLARE_EVENT_TABLE();
147
148 private:
149 wxActiveXContainer* m_container;
150 wxAutomationObject m_ie;
151 IWebBrowser2* m_webBrowser;
152 DWORD m_dwCookie;
153
154 //We store the current zoom type;
155 wxWebViewZoomType m_zoomType;
156
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.
160 */
161 bool m_isBusy;
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;
170
171 //Generic helper functions for IHtmlDocument commands
172 bool CanExecCommand(wxString command);
173 void ExecCommand(wxString command);
174 IHTMLDocument2* GetDocument();
175
176 };
177
178 class VirtualProtocol : public IInternetProtocol, public IInternetProtocolInfo
179 {
180 protected:
181 ULONG m_refCount;
182 IInternetProtocolSink* m_protocolSink;
183 wxString m_html;
184 VOID * fileP;
185
186 wxFSFile* m_file;
187 wxWebProtocolHandler* m_handler;
188
189 public:
190 VirtualProtocol(wxWebProtocolHandler *handler);
191 ~VirtualProtocol();
192
193 //IUnknown
194 ULONG STDMETHODCALLTYPE AddRef();
195 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject);
196 ULONG STDMETHODCALLTYPE Release();
197
198 //IInternetProtocolRoot
199 HRESULT STDMETHODCALLTYPE Abort(HRESULT WXUNUSED(hrReason),
200 DWORD WXUNUSED(dwOptions))
201 { return E_NOTIMPL; }
202 HRESULT STDMETHODCALLTYPE Continue(PROTOCOLDATA *WXUNUSED(pProtocolData))
203 { return S_OK; }
204 HRESULT STDMETHODCALLTYPE Resume() { return S_OK; }
205 HRESULT STDMETHODCALLTYPE Start(LPCWSTR szUrl,
206 IInternetProtocolSink *pOIProtSink,
207 IInternetBindInfo *pOIBindInfo,
208 DWORD grfPI,
209 HANDLE_PTR dwReserved);
210 HRESULT STDMETHODCALLTYPE Suspend() { return S_OK; }
211 HRESULT STDMETHODCALLTYPE Terminate(DWORD WXUNUSED(dwOptions)) { return S_OK; }
212
213 //IInternetProtocol
214 HRESULT STDMETHODCALLTYPE LockRequest(DWORD WXUNUSED(dwOptions))
215 { return S_OK; }
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))
220 { return E_FAIL; }
221 HRESULT STDMETHODCALLTYPE UnlockRequest() { return S_OK; }
222
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,
235 DWORD dwReserved);
236 HRESULT STDMETHODCALLTYPE QueryInfo(LPCWSTR pwzUrl,
237 QUERYOPTION OueryOption,
238 DWORD dwQueryFlags, LPVOID pBuffer,
239 DWORD cbBuffer, DWORD *pcbBuf,
240 DWORD dwReserved);
241 };
242
243 class ClassFactory : public IClassFactory
244 {
245 private:
246 ULONG m_refCount;
247 public:
248 ClassFactory(wxWebProtocolHandler* handler) : m_handler(handler) {}
249 //IUnknown
250 ULONG STDMETHODCALLTYPE AddRef();
251 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject);
252 ULONG STDMETHODCALLTYPE Release();
253
254 //IClassFactory
255 HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown* pUnkOuter,
256 REFIID riid, void** ppvObject);
257 HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock);
258 private:
259 wxWebProtocolHandler* m_handler;
260 };
261
262 #endif // wxUSE_WEBVIEW_IE
263
264 #endif // wxWebViewIE_H