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