]> git.saurik.com Git - wxWidgets.git/blame - include/wx/webview.h
Add wx/datetimectrl.h to the wxAdv files list.
[wxWidgets.git] / include / wx / webview.h
CommitLineData
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
726cc869 13#include "wx/setup.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
c13d6ac1
SL
23#include "wx/osx/webviewhistoryitem_webkit.h"
24#include "wx/gtk/webviewhistoryitem_webkit.h"
25#include "wx/msw/webviewhistoryitem_ie.h"
eafdb19c 26
29365629 27class wxFSFile;
eff8f795 28class wxFileSystem;
29365629 29
61b98a2d
SL
30enum wxWebViewZoom
31{
32 wxWEB_VIEW_ZOOM_TINY,
33 wxWEB_VIEW_ZOOM_SMALL,
34 wxWEB_VIEW_ZOOM_MEDIUM,
35 wxWEB_VIEW_ZOOM_LARGE,
36 wxWEB_VIEW_ZOOM_LARGEST
37};
38
61b98a2d
SL
39enum wxWebViewZoomType
40{
9af51222 41 //Scales entire page, including images
61b98a2d 42 wxWEB_VIEW_ZOOM_TYPE_LAYOUT,
61b98a2d
SL
43 wxWEB_VIEW_ZOOM_TYPE_TEXT
44};
45
04fa04d8 46enum wxWebViewNavigationError
61b98a2d 47{
70554c32 48 wxWEB_NAV_ERR_CONNECTION,
70554c32 49 wxWEB_NAV_ERR_CERTIFICATE,
70554c32 50 wxWEB_NAV_ERR_AUTH,
70554c32 51 wxWEB_NAV_ERR_SECURITY,
70554c32 52 wxWEB_NAV_ERR_NOT_FOUND,
70554c32 53 wxWEB_NAV_ERR_REQUEST,
70554c32 54 wxWEB_NAV_ERR_USER_CANCELLED,
70554c32 55 wxWEB_NAV_ERR_OTHER
61b98a2d
SL
56};
57
61b98a2d
SL
58enum wxWebViewReloadFlags
59{
9af51222 60 //Default, may access cache
70554c32 61 wxWEB_VIEW_RELOAD_DEFAULT,
a703012a 62 wxWEB_VIEW_RELOAD_NO_CACHE
61b98a2d
SL
63};
64
61b98a2d
SL
65enum wxWebViewBackend
66{
61b98a2d 67 wxWEB_VIEW_BACKEND_DEFAULT,
9df97be2 68 wxWEB_VIEW_BACKEND_WEBKIT,
61b98a2d
SL
69 wxWEB_VIEW_BACKEND_IE
70};
71
9e3d4a32 72//Base class for custom scheme handlers
467d261e 73class WXDLLIMPEXP_WEBVIEW wxWebViewHandler
29365629
SL
74{
75public:
7d8d6163 76 wxWebViewHandler(const wxString& scheme) : m_scheme(scheme) {}
5b91ac06 77 virtual ~wxWebViewHandler() {}
7d8d6163 78 virtual wxString GetName() const { return m_scheme; }
29365629 79 virtual wxFSFile* GetFile(const wxString &uri) = 0;
7d8d6163
SL
80private:
81 wxString m_scheme;
29365629
SL
82};
83
467d261e
SL
84extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewNameStr[];
85extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewDefaultURLStr[];
61b98a2d 86
467d261e 87class WXDLLIMPEXP_WEBVIEW wxWebView : public wxControl
61b98a2d
SL
88{
89public:
39498710 90 virtual ~wxWebView() {}
61b98a2d 91
61b98a2d
SL
92 virtual bool Create(wxWindow* parent,
93 wxWindowID id,
94 const wxString& url,
95 const wxPoint& pos,
96 const wxSize& size,
97 long style,
98 const wxString& name) = 0;
99
61b98a2d 100 static wxWebView* New(wxWebViewBackend backend = wxWEB_VIEW_BACKEND_DEFAULT);
61b98a2d
SL
101 static wxWebView* New(wxWindow* parent,
102 wxWindowID id,
103 const wxString& url = wxWebViewDefaultURLStr,
104 const wxPoint& pos = wxDefaultPosition,
105 const wxSize& size = wxDefaultSize,
106 wxWebViewBackend backend = wxWEB_VIEW_BACKEND_DEFAULT,
107 long style = 0,
108 const wxString& name = wxWebViewNameStr);
109
9af51222
SL
110 //General methods
111 virtual wxString GetCurrentTitle() const = 0;
112 virtual wxString GetCurrentURL() const = 0;
113 // TODO: handle choosing a frame when calling GetPageSource()?
114 virtual wxString GetPageSource() const = 0;
115 virtual wxString GetPageText() const = 0;
116 virtual bool IsBusy() const = 0;
117 virtual bool IsEditable() const = 0;
4d0dddc7 118 virtual void LoadURL(const wxString& url) = 0;
9af51222
SL
119 virtual void Print() = 0;
120 virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) = 0;
121 virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT) = 0;
122 virtual void RunScript(const wxString& javascript) = 0;
123 virtual void SetEditable(bool enable = true) = 0;
124 virtual void SetPage(const wxString& html, const wxString& baseUrl) = 0;
125 virtual void SetPage(wxInputStream& html, wxString baseUrl)
126 {
127 wxStringOutputStream stream;
128 stream.Write(html);
129 SetPage(stream.GetString(), baseUrl);
130 }
131 virtual void Stop() = 0;
61b98a2d 132
9af51222 133 //History
e669ddde 134 virtual bool CanGoBack() const = 0;
e669ddde 135 virtual bool CanGoForward() const = 0;
61b98a2d 136 virtual void GoBack() = 0;
61b98a2d 137 virtual void GoForward() = 0;
152a5808
SL
138 virtual void ClearHistory() = 0;
139 virtual void EnableHistory(bool enable = true) = 0;
c13d6ac1
SL
140 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory() = 0;
141 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory() = 0;
142 virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item) = 0;
152a5808 143
9af51222
SL
144 //Zoom
145 virtual bool CanSetZoomType(wxWebViewZoomType type) const = 0;
e669ddde 146 virtual wxWebViewZoom GetZoom() const = 0;
9af51222 147 virtual wxWebViewZoomType GetZoomType() const = 0;
61b98a2d 148 virtual void SetZoom(wxWebViewZoom zoom) = 0;
61b98a2d
SL
149 virtual void SetZoomType(wxWebViewZoomType zoomType) = 0;
150
9af51222 151 //Selection
63a65070 152 virtual void SelectAll() = 0;
e669ddde 153 virtual bool HasSelection() const = 0;
63a65070 154 virtual void DeleteSelection() = 0;
e669ddde
SL
155 virtual wxString GetSelectedText() const = 0;
156 virtual wxString GetSelectedSource() const = 0;
41933aa5 157 virtual void ClearSelection() = 0;
63a65070 158
4681a3ea 159 //Clipboard functions
e669ddde
SL
160 virtual bool CanCut() const = 0;
161 virtual bool CanCopy() const = 0;
162 virtual bool CanPaste() const = 0;
4681a3ea
SL
163 virtual void Cut() = 0;
164 virtual void Copy() = 0;
165 virtual void Paste() = 0;
97e49559
SL
166
167 //Undo / redo functionality
e669ddde
SL
168 virtual bool CanUndo() const = 0;
169 virtual bool CanRedo() const = 0;
97e49559
SL
170 virtual void Undo() = 0;
171 virtual void Redo() = 0;
eff8f795 172
cddf4541 173 wxDECLARE_ABSTRACT_CLASS(wxWebView);
61b98a2d
SL
174};
175
467d261e 176class WXDLLIMPEXP_WEBVIEW wxWebViewEvent : public wxNotifyEvent
61b98a2d
SL
177{
178public:
04fa04d8
SL
179 wxWebViewEvent() {}
180 wxWebViewEvent(wxEventType type, int id, const wxString url,
3225a4b8
SL
181 const wxString target)
182 : wxNotifyEvent(type, id), m_url(url), m_target(target)
183 {}
61b98a2d 184
61b98a2d 185
9af51222 186 const wxString& GetURL() const { return m_url; }
61b98a2d
SL
187 const wxString& GetTarget() const { return m_target; }
188
04fa04d8 189 virtual wxEvent* Clone() const { return new wxWebViewEvent(*this); }
61b98a2d 190private:
e40741b9 191 wxString m_url;
61b98a2d 192 wxString m_target;
61b98a2d 193
04fa04d8 194 wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWebViewEvent);
61b98a2d
SL
195};
196
467d261e
SL
197wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_NAVIGATING, wxWebViewEvent );
198wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_NAVIGATED, wxWebViewEvent );
199wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_LOADED, wxWebViewEvent );
200wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_ERROR, wxWebViewEvent );
201wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, wxWebViewEvent );
202wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, wxWebViewEvent );
61b98a2d 203
04fa04d8
SL
204typedef void (wxEvtHandler::*wxWebViewEventFunction)
205 (wxWebViewEvent&);
61b98a2d 206
04fa04d8
SL
207#define wxWebViewEventHandler(func) \
208 wxEVENT_HANDLER_CAST(wxWebViewEventFunction, func)
61b98a2d
SL
209
210#define EVT_WEB_VIEW_NAVIGATING(id, fn) \
384b8d9f 211 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATING, id, \
04fa04d8 212 wxWebViewEventHandler(fn))
61b98a2d
SL
213
214#define EVT_WEB_VIEW_NAVIGATED(id, fn) \
384b8d9f 215 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATED, id, \
04fa04d8 216 wxWebViewEventHandler(fn))
61b98a2d
SL
217
218#define EVT_WEB_VIEW_LOADED(id, fn) \
384b8d9f 219 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_LOADED, id, \
04fa04d8 220 wxWebViewEventHandler(fn))
61b98a2d
SL
221
222#define EVT_WEB_VIEW_ERRROR(id, fn) \
384b8d9f 223 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_ERROR, id, \
04fa04d8 224 wxWebViewEventHandler(fn))
61b98a2d 225
853b6cd0
SL
226#define EVT_WEB_VIEW_NEWWINDOW(id, fn) \
227 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, id, \
04fa04d8 228 wxWebViewEventHandler(fn))
853b6cd0 229
153530af
SL
230#define EVT_WEB_VIEW_TITLE_CHANGED(id, fn) \
231 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, id, \
04fa04d8 232 wxWebViewEventHandler(fn))
153530af 233
88cc66f7 234#endif // wxUSE_WEBVIEW
9c805dec
SL
235
236#endif // _WX_WEB_VIEW_H_