]> git.saurik.com Git - wxWidgets.git/blob - include/wx/webview.h
don't use deprecated wxMouseState functions
[wxWidgets.git] / include / wx / webview.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: webview.h
3 // Purpose: Common interface and events for web view component
4 // Author: Marianne Gagnon
5 // Id: $Id$
6 // Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_WEB_VIEW_H_
11 #define _WX_WEB_VIEW_H_
12
13 #include "wx/defs.h"
14
15 #if wxUSE_WEBVIEW
16
17 #include "wx/control.h"
18 #include "wx/event.h"
19 #include "wx/sstream.h"
20 #include "wx/sharedptr.h"
21 #include "wx/vector.h"
22
23 #if defined(__WXOSX__)
24 #include "wx/osx/webviewhistoryitem_webkit.h"
25 #elif defined(__WXGTK__)
26 #include "wx/gtk/webviewhistoryitem_webkit.h"
27 #elif defined(__WXMSW__)
28 #include "wx/msw/webviewhistoryitem_ie.h"
29 #else
30 #error "wxWebView not implemented on this platform."
31 #endif
32
33 class wxFSFile;
34 class wxFileSystem;
35
36 enum wxWebViewZoom
37 {
38 wxWEB_VIEW_ZOOM_TINY,
39 wxWEB_VIEW_ZOOM_SMALL,
40 wxWEB_VIEW_ZOOM_MEDIUM,
41 wxWEB_VIEW_ZOOM_LARGE,
42 wxWEB_VIEW_ZOOM_LARGEST
43 };
44
45 enum wxWebViewZoomType
46 {
47 //Scales entire page, including images
48 wxWEB_VIEW_ZOOM_TYPE_LAYOUT,
49 wxWEB_VIEW_ZOOM_TYPE_TEXT
50 };
51
52 enum wxWebViewNavigationError
53 {
54 wxWEB_NAV_ERR_CONNECTION,
55 wxWEB_NAV_ERR_CERTIFICATE,
56 wxWEB_NAV_ERR_AUTH,
57 wxWEB_NAV_ERR_SECURITY,
58 wxWEB_NAV_ERR_NOT_FOUND,
59 wxWEB_NAV_ERR_REQUEST,
60 wxWEB_NAV_ERR_USER_CANCELLED,
61 wxWEB_NAV_ERR_OTHER
62 };
63
64 enum wxWebViewReloadFlags
65 {
66 //Default, may access cache
67 wxWEB_VIEW_RELOAD_DEFAULT,
68 wxWEB_VIEW_RELOAD_NO_CACHE
69 };
70
71 enum wxWebViewFindFlags
72 {
73 wxWEB_VIEW_FIND_WRAP = 0x0001,
74 wxWEB_VIEW_FIND_ENTIRE_WORD = 0x0002,
75 wxWEB_VIEW_FIND_MATCH_CASE = 0x0004,
76 wxWEB_VIEW_FIND_HIGHLIGHT_RESULT = 0x0008,
77 wxWEB_VIEW_FIND_BACKWARDS = 0x0010,
78 wxWEB_VIEW_FIND_DEFAULT = 0
79 };
80
81 enum wxWebViewBackend
82 {
83 wxWEB_VIEW_BACKEND_DEFAULT,
84 wxWEB_VIEW_BACKEND_WEBKIT,
85 wxWEB_VIEW_BACKEND_IE
86 };
87
88 //Base class for custom scheme handlers
89 class WXDLLIMPEXP_WEBVIEW wxWebViewHandler
90 {
91 public:
92 wxWebViewHandler(const wxString& scheme) : m_scheme(scheme) {}
93 virtual ~wxWebViewHandler() {}
94 virtual wxString GetName() const { return m_scheme; }
95 virtual wxFSFile* GetFile(const wxString &uri) = 0;
96 private:
97 wxString m_scheme;
98 };
99
100 extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewNameStr[];
101 extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewDefaultURLStr[];
102
103 class WXDLLIMPEXP_WEBVIEW wxWebView : public wxControl
104 {
105 public:
106 wxWebView()
107 {
108 m_showMenu = true;
109 }
110
111 virtual ~wxWebView() {}
112
113 virtual bool Create(wxWindow* parent,
114 wxWindowID id,
115 const wxString& url = wxWebViewDefaultURLStr,
116 const wxPoint& pos = wxDefaultPosition,
117 const wxSize& size = wxDefaultSize,
118 long style = 0,
119 const wxString& name = wxWebViewNameStr) = 0;
120
121 static wxWebView* New(wxWebViewBackend backend = wxWEB_VIEW_BACKEND_DEFAULT);
122 static wxWebView* New(wxWindow* parent,
123 wxWindowID id,
124 const wxString& url = wxWebViewDefaultURLStr,
125 const wxPoint& pos = wxDefaultPosition,
126 const wxSize& size = wxDefaultSize,
127 wxWebViewBackend backend = wxWEB_VIEW_BACKEND_DEFAULT,
128 long style = 0,
129 const wxString& name = wxWebViewNameStr);
130
131 //General methods
132 virtual void EnableContextMenu(bool enable = true)
133 {
134 m_showMenu = enable;
135 }
136 virtual wxString GetCurrentTitle() const = 0;
137 virtual wxString GetCurrentURL() const = 0;
138 // TODO: handle choosing a frame when calling GetPageSource()?
139 virtual wxString GetPageSource() const = 0;
140 virtual wxString GetPageText() const = 0;
141 virtual bool IsBusy() const = 0;
142 virtual bool IsContextMenuEnabled() const { return m_showMenu; }
143 virtual bool IsEditable() const = 0;
144 virtual void LoadURL(const wxString& url) = 0;
145 virtual void Print() = 0;
146 virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) = 0;
147 virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT) = 0;
148 virtual void RunScript(const wxString& javascript) = 0;
149 virtual void SetEditable(bool enable = true) = 0;
150 void SetPage(const wxString& html, const wxString& baseUrl)
151 {
152 DoSetPage(html, baseUrl);
153 }
154 void SetPage(wxInputStream& html, wxString baseUrl)
155 {
156 wxStringOutputStream stream;
157 stream.Write(html);
158 DoSetPage(stream.GetString(), baseUrl);
159 }
160 virtual void Stop() = 0;
161
162 //History
163 virtual bool CanGoBack() const = 0;
164 virtual bool CanGoForward() const = 0;
165 virtual void GoBack() = 0;
166 virtual void GoForward() = 0;
167 virtual void ClearHistory() = 0;
168 virtual void EnableHistory(bool enable = true) = 0;
169 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory() = 0;
170 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory() = 0;
171 virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item) = 0;
172
173 //Zoom
174 virtual bool CanSetZoomType(wxWebViewZoomType type) const = 0;
175 virtual wxWebViewZoom GetZoom() const = 0;
176 virtual wxWebViewZoomType GetZoomType() const = 0;
177 virtual void SetZoom(wxWebViewZoom zoom) = 0;
178 virtual void SetZoomType(wxWebViewZoomType zoomType) = 0;
179
180 //Selection
181 virtual void SelectAll() = 0;
182 virtual bool HasSelection() const = 0;
183 virtual void DeleteSelection() = 0;
184 virtual wxString GetSelectedText() const = 0;
185 virtual wxString GetSelectedSource() const = 0;
186 virtual void ClearSelection() = 0;
187
188 //Clipboard functions
189 virtual bool CanCut() const = 0;
190 virtual bool CanCopy() const = 0;
191 virtual bool CanPaste() const = 0;
192 virtual void Cut() = 0;
193 virtual void Copy() = 0;
194 virtual void Paste() = 0;
195
196 //Undo / redo functionality
197 virtual bool CanUndo() const = 0;
198 virtual bool CanRedo() const = 0;
199 virtual void Undo() = 0;
200 virtual void Redo() = 0;
201
202 //Get the pointer to the underlying native engine.
203 virtual void* GetNativeBackend() const = 0;
204 //Find function
205 virtual long Find(const wxString& text, int flags = wxWEB_VIEW_FIND_DEFAULT) = 0;
206
207 protected:
208 virtual void DoSetPage(const wxString& html, const wxString& baseUrl) = 0;
209
210 private:
211 bool m_showMenu;
212
213 wxDECLARE_ABSTRACT_CLASS(wxWebView);
214 };
215
216 class WXDLLIMPEXP_WEBVIEW wxWebViewEvent : public wxNotifyEvent
217 {
218 public:
219 wxWebViewEvent() {}
220 wxWebViewEvent(wxEventType type, int id, const wxString url,
221 const wxString target)
222 : wxNotifyEvent(type, id), m_url(url), m_target(target)
223 {}
224
225
226 const wxString& GetURL() const { return m_url; }
227 const wxString& GetTarget() const { return m_target; }
228
229 virtual wxEvent* Clone() const { return new wxWebViewEvent(*this); }
230 private:
231 wxString m_url;
232 wxString m_target;
233
234 wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWebViewEvent);
235 };
236
237 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_NAVIGATING, wxWebViewEvent );
238 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_NAVIGATED, wxWebViewEvent );
239 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_LOADED, wxWebViewEvent );
240 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_ERROR, wxWebViewEvent );
241 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, wxWebViewEvent );
242 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, wxWebViewEvent );
243
244 typedef void (wxEvtHandler::*wxWebViewEventFunction)
245 (wxWebViewEvent&);
246
247 #define wxWebViewEventHandler(func) \
248 wxEVENT_HANDLER_CAST(wxWebViewEventFunction, func)
249
250 #define EVT_WEB_VIEW_NAVIGATING(id, fn) \
251 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATING, id, \
252 wxWebViewEventHandler(fn))
253
254 #define EVT_WEB_VIEW_NAVIGATED(id, fn) \
255 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATED, id, \
256 wxWebViewEventHandler(fn))
257
258 #define EVT_WEB_VIEW_LOADED(id, fn) \
259 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_LOADED, id, \
260 wxWebViewEventHandler(fn))
261
262 #define EVT_WEB_VIEW_ERROR(id, fn) \
263 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_ERROR, id, \
264 wxWebViewEventHandler(fn))
265
266 #define EVT_WEB_VIEW_NEWWINDOW(id, fn) \
267 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, id, \
268 wxWebViewEventHandler(fn))
269
270 #define EVT_WEB_VIEW_TITLE_CHANGED(id, fn) \
271 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, id, \
272 wxWebViewEventHandler(fn))
273
274 #endif // wxUSE_WEBVIEW
275
276 #endif // _WX_WEB_VIEW_H_