Implement basic support for virtual file systems for the ie backend. Registering...
[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 class WXDLLIMPEXP_WEB wxWebViewIE : public wxWebView
30 {
31 public:
32
33 wxWebViewIE() {}
34
35 wxWebViewIE(wxWindow* parent,
36 wxWindowID id,
37 const wxString& url = wxWebViewDefaultURLStr,
38 const wxPoint& pos = wxDefaultPosition,
39 const wxSize& size = wxDefaultSize,
40 long style = 0,
41 const wxString& name = wxWebViewNameStr)
42 {
43 Create(parent, id, url, pos, size, style, name);
44 }
45
46 bool Create(wxWindow* parent,
47 wxWindowID id,
48 const wxString& url = wxWebViewDefaultURLStr,
49 const wxPoint& pos = wxDefaultPosition,
50 const wxSize& size = wxDefaultSize,
51 long style = 0,
52 const wxString& name = wxWebViewNameStr);
53
54 virtual void LoadUrl(const wxString& url);
55 virtual void LoadHistoryItem(wxSharedPtr<wxWebHistoryItem> item);
56 virtual wxVector<wxSharedPtr<wxWebHistoryItem> > GetBackwardHistory();
57 virtual wxVector<wxSharedPtr<wxWebHistoryItem> > GetForwardHistory();
58
59 virtual bool CanGoForward();
60 virtual bool CanGoBack();
61 virtual void GoBack();
62 virtual void GoForward();
63 virtual void ClearHistory();
64 virtual void EnableHistory(bool enable = true);
65 virtual void Stop();
66 virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT);
67
68 virtual wxString GetPageSource();
69 virtual wxString GetPageText();
70
71 virtual bool IsBusy();
72 virtual wxString GetCurrentURL();
73 virtual wxString GetCurrentTitle();
74
75 virtual void SetZoomType(wxWebViewZoomType);
76 virtual wxWebViewZoomType GetZoomType() const;
77 virtual bool CanSetZoomType(wxWebViewZoomType) const;
78
79 virtual void Print();
80
81 virtual void SetPage(const wxString& html, const wxString& baseUrl);
82
83 virtual wxWebViewZoom GetZoom();
84 virtual void SetZoom(wxWebViewZoom zoom);
85
86 //Clipboard functions
87 virtual bool CanCut();
88 virtual bool CanCopy();
89 virtual bool CanPaste();
90 virtual void Cut();
91 virtual void Copy();
92 virtual void Paste();
93
94 //Undo / redo functionality
95 virtual bool CanUndo();
96 virtual bool CanRedo();
97 virtual void Undo();
98 virtual void Redo();
99
100 //Editing functions
101 virtual void SetEditable(bool enable = true);
102 virtual bool IsEditable();
103
104 //Selection
105 virtual void SelectAll();
106 virtual bool HasSelection();
107 virtual void DeleteSelection();
108 virtual wxString GetSelectedText();
109 virtual wxString GetSelectedSource();
110 virtual void ClearSelection();
111
112 virtual void RunScript(const wxString& javascript);
113
114 // ---- IE-specific methods
115
116 // FIXME: I seem to be able to access remote webpages even in offline mode...
117 bool IsOfflineMode();
118 void SetOfflineMode(bool offline);
119
120 wxWebViewZoom GetIETextZoom();
121 void SetIETextZoom(wxWebViewZoom level);
122
123 wxWebViewZoom GetIEOpticalZoom();
124 void SetIEOpticalZoom(wxWebViewZoom level);
125
126 void onActiveXEvent(wxActiveXEvent& evt);
127 void onEraseBg(wxEraseEvent&) {}
128
129 DECLARE_EVENT_TABLE();
130
131 private:
132 wxActiveXContainer* m_container;
133 wxAutomationObject m_ie;
134 IWebBrowser2* m_webBrowser;
135 DWORD m_dwCookie;
136 bool m_canNavigateBack;
137 bool m_canNavigateForward;
138
139 //We store the current zoom type;
140 wxWebViewZoomType m_zoomType;
141
142 /** The "Busy" property of IWebBrowser2 does not always return busy when
143 * we'd want it to; this variable may be set to true in cases where the
144 * Busy property is false but should be true.
145 */
146 bool m_isBusy;
147 //We manage our own history, the history list contains the history items
148 //which are added as documentcomplete events arrive, unless we are loading
149 //an item from the history. The position is stored as an int, and reflects
150 //where we are in the history list.
151 wxVector<wxSharedPtr<wxWebHistoryItem> > m_historyList;
152 int m_historyPosition;
153 bool m_historyLoadingFromList;
154 bool m_historyEnabled;
155
156 //Generic helper functions for IHtmlDocument commands
157 bool CanExecCommand(wxString command);
158 void ExecCommand(wxString command);
159 IHTMLDocument2* GetDocument();
160
161 };
162
163 class VirtualProtocol : public IInternetProtocol
164 {
165 protected:
166 ULONG m_refCount;
167 IInternetProtocolSink* m_protocolSink;
168 wxString m_html;
169 VOID * fileP;
170
171 wxFSFile* m_file;
172 wxFileSystem* m_fileSys;
173
174 public:
175 VirtualProtocol();
176 ~VirtualProtocol();
177
178 //IUnknown
179 ULONG STDMETHODCALLTYPE AddRef();
180 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject);
181 ULONG STDMETHODCALLTYPE Release();
182
183 //IInternetProtocolRoot
184 HRESULT STDMETHODCALLTYPE Abort(HRESULT hrReason, DWORD dwOptions)
185 { return E_NOTIMPL; }
186 HRESULT STDMETHODCALLTYPE Continue(PROTOCOLDATA *pProtocolData)
187 { return S_OK; }
188 HRESULT STDMETHODCALLTYPE Resume() { return S_OK; }
189 HRESULT STDMETHODCALLTYPE Start(LPCWSTR szUrl,
190 IInternetProtocolSink *pOIProtSink,
191 IInternetBindInfo *pOIBindInfo,
192 DWORD grfPI,
193 HANDLE_PTR dwReserved);
194 HRESULT STDMETHODCALLTYPE Suspend() { return S_OK; }
195 HRESULT STDMETHODCALLTYPE Terminate(DWORD dwOptions) { return S_OK; }
196
197 //IInternetProtocol
198 HRESULT STDMETHODCALLTYPE LockRequest(DWORD dwOptions) { return S_OK; }
199 HRESULT STDMETHODCALLTYPE Read(void *pv, ULONG cb, ULONG *pcbRead);
200 HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin,
201 ULARGE_INTEGER* plibNewPosition)
202 { return E_FAIL; }
203 HRESULT STDMETHODCALLTYPE UnlockRequest() { return S_OK; }
204 };
205
206 class ClassFactory : public IClassFactory
207 {
208 private:
209 ULONG m_refCount;
210 public:
211 //IUnknown
212 ULONG STDMETHODCALLTYPE AddRef();
213 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject);
214 ULONG STDMETHODCALLTYPE Release();
215
216 //IClassFactory
217 HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown* pUnkOuter,
218 REFIID riid, void** ppvObject);
219 HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock);
220 };
221
222 #endif // wxUSE_WEBVIEW_IE
223
224 #endif // wxWebViewIE_H