]>
Commit | Line | Data |
---|---|---|
61b98a2d SL |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: webview.h | |
3 | // Purpose: Common interface and events for web view component | |
4 | // Author: Marianne Gagnon | |
5 | // Id: $Id$ | |
153530af | 6 | // Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton |
61b98a2d SL |
7 | // Licence: wxWindows licence |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifndef _WX_WEB_VIEW_H_ | |
11 | #define _WX_WEB_VIEW_H_ | |
12 | ||
99644bf1 | 13 | #include "wx/defs.h" |
9c805dec | 14 | |
88cc66f7 | 15 | #if wxUSE_WEBVIEW |
9c805dec | 16 | |
407f2162 SC |
17 | #include "wx/control.h" |
18 | #include "wx/event.h" | |
19 | #include "wx/sstream.h" | |
5cbda74b | 20 | #include "wx/sharedptr.h" |
ae26e17b | 21 | #include "wx/vector.h" |
5cbda74b | 22 | |
37bea8d2 VZ |
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 | |
eafdb19c | 32 | |
29365629 | 33 | class wxFSFile; |
eff8f795 | 34 | class wxFileSystem; |
29365629 | 35 | |
61b98a2d SL |
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 | ||
61b98a2d SL |
45 | enum wxWebViewZoomType |
46 | { | |
9af51222 | 47 | //Scales entire page, including images |
61b98a2d | 48 | wxWEB_VIEW_ZOOM_TYPE_LAYOUT, |
61b98a2d SL |
49 | wxWEB_VIEW_ZOOM_TYPE_TEXT |
50 | }; | |
51 | ||
04fa04d8 | 52 | enum wxWebViewNavigationError |
61b98a2d | 53 | { |
70554c32 | 54 | wxWEB_NAV_ERR_CONNECTION, |
70554c32 | 55 | wxWEB_NAV_ERR_CERTIFICATE, |
70554c32 | 56 | wxWEB_NAV_ERR_AUTH, |
70554c32 | 57 | wxWEB_NAV_ERR_SECURITY, |
70554c32 | 58 | wxWEB_NAV_ERR_NOT_FOUND, |
70554c32 | 59 | wxWEB_NAV_ERR_REQUEST, |
70554c32 | 60 | wxWEB_NAV_ERR_USER_CANCELLED, |
70554c32 | 61 | wxWEB_NAV_ERR_OTHER |
61b98a2d SL |
62 | }; |
63 | ||
61b98a2d SL |
64 | enum wxWebViewReloadFlags |
65 | { | |
9af51222 | 66 | //Default, may access cache |
70554c32 | 67 | wxWEB_VIEW_RELOAD_DEFAULT, |
34326da7 | 68 | wxWEB_VIEW_RELOAD_NO_CACHE |
61b98a2d SL |
69 | }; |
70 | ||
61b98a2d SL |
71 | enum wxWebViewBackend |
72 | { | |
61b98a2d | 73 | wxWEB_VIEW_BACKEND_DEFAULT, |
9df97be2 | 74 | wxWEB_VIEW_BACKEND_WEBKIT, |
61b98a2d SL |
75 | wxWEB_VIEW_BACKEND_IE |
76 | }; | |
77 | ||
9e3d4a32 | 78 | //Base class for custom scheme handlers |
467d261e | 79 | class WXDLLIMPEXP_WEBVIEW wxWebViewHandler |
29365629 SL |
80 | { |
81 | public: | |
7d8d6163 | 82 | wxWebViewHandler(const wxString& scheme) : m_scheme(scheme) {} |
5b91ac06 | 83 | virtual ~wxWebViewHandler() {} |
7d8d6163 | 84 | virtual wxString GetName() const { return m_scheme; } |
29365629 | 85 | virtual wxFSFile* GetFile(const wxString &uri) = 0; |
7d8d6163 SL |
86 | private: |
87 | wxString m_scheme; | |
29365629 SL |
88 | }; |
89 | ||
467d261e SL |
90 | extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewNameStr[]; |
91 | extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewDefaultURLStr[]; | |
61b98a2d | 92 | |
467d261e | 93 | class WXDLLIMPEXP_WEBVIEW wxWebView : public wxControl |
61b98a2d SL |
94 | { |
95 | public: | |
39498710 | 96 | virtual ~wxWebView() {} |
61b98a2d | 97 | |
61b98a2d SL |
98 | virtual bool Create(wxWindow* parent, |
99 | wxWindowID id, | |
cce10ca0 RD |
100 | const wxString& url = wxWebViewDefaultURLStr, |
101 | const wxPoint& pos = wxDefaultPosition, | |
102 | const wxSize& size = wxDefaultSize, | |
103 | long style = 0, | |
104 | const wxString& name = wxWebViewNameStr) = 0; | |
61b98a2d | 105 | |
61b98a2d | 106 | static wxWebView* New(wxWebViewBackend backend = wxWEB_VIEW_BACKEND_DEFAULT); |
61b98a2d SL |
107 | static wxWebView* New(wxWindow* parent, |
108 | wxWindowID id, | |
109 | const wxString& url = wxWebViewDefaultURLStr, | |
110 | const wxPoint& pos = wxDefaultPosition, | |
111 | const wxSize& size = wxDefaultSize, | |
112 | wxWebViewBackend backend = wxWEB_VIEW_BACKEND_DEFAULT, | |
113 | long style = 0, | |
114 | const wxString& name = wxWebViewNameStr); | |
115 | ||
9af51222 SL |
116 | //General methods |
117 | virtual wxString GetCurrentTitle() const = 0; | |
118 | virtual wxString GetCurrentURL() const = 0; | |
119 | // TODO: handle choosing a frame when calling GetPageSource()? | |
120 | virtual wxString GetPageSource() const = 0; | |
121 | virtual wxString GetPageText() const = 0; | |
122 | virtual bool IsBusy() const = 0; | |
123 | virtual bool IsEditable() const = 0; | |
4d0dddc7 | 124 | virtual void LoadURL(const wxString& url) = 0; |
9af51222 SL |
125 | virtual void Print() = 0; |
126 | virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) = 0; | |
127 | virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT) = 0; | |
128 | virtual void RunScript(const wxString& javascript) = 0; | |
129 | virtual void SetEditable(bool enable = true) = 0; | |
a977376a VZ |
130 | void SetPage(const wxString& html, const wxString& baseUrl) |
131 | { | |
132 | DoSetPage(html, baseUrl); | |
133 | } | |
134 | void SetPage(wxInputStream& html, wxString baseUrl) | |
9af51222 SL |
135 | { |
136 | wxStringOutputStream stream; | |
137 | stream.Write(html); | |
a977376a | 138 | DoSetPage(stream.GetString(), baseUrl); |
9af51222 SL |
139 | } |
140 | virtual void Stop() = 0; | |
61b98a2d | 141 | |
9af51222 | 142 | //History |
e669ddde | 143 | virtual bool CanGoBack() const = 0; |
e669ddde | 144 | virtual bool CanGoForward() const = 0; |
61b98a2d | 145 | virtual void GoBack() = 0; |
61b98a2d | 146 | virtual void GoForward() = 0; |
152a5808 SL |
147 | virtual void ClearHistory() = 0; |
148 | virtual void EnableHistory(bool enable = true) = 0; | |
c13d6ac1 SL |
149 | virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory() = 0; |
150 | virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory() = 0; | |
151 | virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item) = 0; | |
152a5808 | 152 | |
9af51222 SL |
153 | //Zoom |
154 | virtual bool CanSetZoomType(wxWebViewZoomType type) const = 0; | |
e669ddde | 155 | virtual wxWebViewZoom GetZoom() const = 0; |
9af51222 | 156 | virtual wxWebViewZoomType GetZoomType() const = 0; |
61b98a2d | 157 | virtual void SetZoom(wxWebViewZoom zoom) = 0; |
61b98a2d SL |
158 | virtual void SetZoomType(wxWebViewZoomType zoomType) = 0; |
159 | ||
9af51222 | 160 | //Selection |
63a65070 | 161 | virtual void SelectAll() = 0; |
e669ddde | 162 | virtual bool HasSelection() const = 0; |
63a65070 | 163 | virtual void DeleteSelection() = 0; |
e669ddde SL |
164 | virtual wxString GetSelectedText() const = 0; |
165 | virtual wxString GetSelectedSource() const = 0; | |
41933aa5 | 166 | virtual void ClearSelection() = 0; |
63a65070 | 167 | |
4681a3ea | 168 | //Clipboard functions |
e669ddde SL |
169 | virtual bool CanCut() const = 0; |
170 | virtual bool CanCopy() const = 0; | |
171 | virtual bool CanPaste() const = 0; | |
4681a3ea SL |
172 | virtual void Cut() = 0; |
173 | virtual void Copy() = 0; | |
174 | virtual void Paste() = 0; | |
97e49559 SL |
175 | |
176 | //Undo / redo functionality | |
e669ddde SL |
177 | virtual bool CanUndo() const = 0; |
178 | virtual bool CanRedo() const = 0; | |
97e49559 SL |
179 | virtual void Undo() = 0; |
180 | virtual void Redo() = 0; | |
eff8f795 | 181 | |
a977376a VZ |
182 | protected: |
183 | virtual void DoSetPage(const wxString& html, const wxString& baseUrl) = 0; | |
184 | ||
cddf4541 | 185 | wxDECLARE_ABSTRACT_CLASS(wxWebView); |
61b98a2d SL |
186 | }; |
187 | ||
467d261e | 188 | class WXDLLIMPEXP_WEBVIEW wxWebViewEvent : public wxNotifyEvent |
61b98a2d SL |
189 | { |
190 | public: | |
04fa04d8 SL |
191 | wxWebViewEvent() {} |
192 | wxWebViewEvent(wxEventType type, int id, const wxString url, | |
3225a4b8 SL |
193 | const wxString target) |
194 | : wxNotifyEvent(type, id), m_url(url), m_target(target) | |
195 | {} | |
61b98a2d | 196 | |
61b98a2d | 197 | |
9af51222 | 198 | const wxString& GetURL() const { return m_url; } |
61b98a2d SL |
199 | const wxString& GetTarget() const { return m_target; } |
200 | ||
04fa04d8 | 201 | virtual wxEvent* Clone() const { return new wxWebViewEvent(*this); } |
61b98a2d | 202 | private: |
e40741b9 | 203 | wxString m_url; |
61b98a2d | 204 | wxString m_target; |
61b98a2d | 205 | |
04fa04d8 | 206 | wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWebViewEvent); |
61b98a2d SL |
207 | }; |
208 | ||
467d261e SL |
209 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_NAVIGATING, wxWebViewEvent ); |
210 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_NAVIGATED, wxWebViewEvent ); | |
211 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_LOADED, wxWebViewEvent ); | |
212 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_ERROR, wxWebViewEvent ); | |
213 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, wxWebViewEvent ); | |
214 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, wxWebViewEvent ); | |
61b98a2d | 215 | |
04fa04d8 SL |
216 | typedef void (wxEvtHandler::*wxWebViewEventFunction) |
217 | (wxWebViewEvent&); | |
61b98a2d | 218 | |
04fa04d8 SL |
219 | #define wxWebViewEventHandler(func) \ |
220 | wxEVENT_HANDLER_CAST(wxWebViewEventFunction, func) | |
61b98a2d SL |
221 | |
222 | #define EVT_WEB_VIEW_NAVIGATING(id, fn) \ | |
384b8d9f | 223 | wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATING, id, \ |
04fa04d8 | 224 | wxWebViewEventHandler(fn)) |
61b98a2d SL |
225 | |
226 | #define EVT_WEB_VIEW_NAVIGATED(id, fn) \ | |
384b8d9f | 227 | wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATED, id, \ |
04fa04d8 | 228 | wxWebViewEventHandler(fn)) |
61b98a2d SL |
229 | |
230 | #define EVT_WEB_VIEW_LOADED(id, fn) \ | |
384b8d9f | 231 | wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_LOADED, id, \ |
04fa04d8 | 232 | wxWebViewEventHandler(fn)) |
61b98a2d | 233 | |
ecc610f1 | 234 | #define EVT_WEB_VIEW_ERROR(id, fn) \ |
384b8d9f | 235 | wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_ERROR, id, \ |
04fa04d8 | 236 | wxWebViewEventHandler(fn)) |
61b98a2d | 237 | |
853b6cd0 SL |
238 | #define EVT_WEB_VIEW_NEWWINDOW(id, fn) \ |
239 | wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, id, \ | |
04fa04d8 | 240 | wxWebViewEventHandler(fn)) |
853b6cd0 | 241 | |
153530af SL |
242 | #define EVT_WEB_VIEW_TITLE_CHANGED(id, fn) \ |
243 | wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, id, \ | |
04fa04d8 | 244 | wxWebViewEventHandler(fn)) |
153530af | 245 | |
88cc66f7 | 246 | #endif // wxUSE_WEBVIEW |
9c805dec SL |
247 | |
248 | #endif // _WX_WEB_VIEW_H_ |