]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/webview.h
Added a parameter to PrintBuffer and PrintFile to allow silent or prompted printing.
[wxWidgets.git] / include / wx / webview.h
... / ...
CommitLineData
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
33class wxFSFile;
34class wxFileSystem;
35
36enum 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
45enum wxWebViewZoomType
46{
47 //Scales entire page, including images
48 wxWEB_VIEW_ZOOM_TYPE_LAYOUT,
49 wxWEB_VIEW_ZOOM_TYPE_TEXT
50};
51
52enum 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
64enum wxWebViewReloadFlags
65{
66 //Default, may access cache
67 wxWEB_VIEW_RELOAD_DEFAULT,
68 wxWEB_VIEW_RELOAD_NO_CACHE
69};
70
71enum wxWebViewBackend
72{
73 wxWEB_VIEW_BACKEND_DEFAULT,
74 wxWEB_VIEW_BACKEND_WEBKIT,
75 wxWEB_VIEW_BACKEND_IE
76};
77
78//Base class for custom scheme handlers
79class WXDLLIMPEXP_WEBVIEW wxWebViewHandler
80{
81public:
82 wxWebViewHandler(const wxString& scheme) : m_scheme(scheme) {}
83 virtual ~wxWebViewHandler() {}
84 virtual wxString GetName() const { return m_scheme; }
85 virtual wxFSFile* GetFile(const wxString &uri) = 0;
86private:
87 wxString m_scheme;
88};
89
90extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewNameStr[];
91extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewDefaultURLStr[];
92
93class WXDLLIMPEXP_WEBVIEW wxWebView : public wxControl
94{
95public:
96 virtual ~wxWebView() {}
97
98 virtual bool Create(wxWindow* parent,
99 wxWindowID id,
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;
105
106 static wxWebView* New(wxWebViewBackend backend = wxWEB_VIEW_BACKEND_DEFAULT);
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
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;
124 virtual void LoadURL(const wxString& url) = 0;
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;
130 virtual void SetPage(const wxString& html, const wxString& baseUrl) = 0;
131 virtual void SetPage(wxInputStream& html, wxString baseUrl)
132 {
133 wxStringOutputStream stream;
134 stream.Write(html);
135 SetPage(stream.GetString(), baseUrl);
136 }
137 virtual void Stop() = 0;
138
139 //History
140 virtual bool CanGoBack() const = 0;
141 virtual bool CanGoForward() const = 0;
142 virtual void GoBack() = 0;
143 virtual void GoForward() = 0;
144 virtual void ClearHistory() = 0;
145 virtual void EnableHistory(bool enable = true) = 0;
146 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory() = 0;
147 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory() = 0;
148 virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item) = 0;
149
150 //Zoom
151 virtual bool CanSetZoomType(wxWebViewZoomType type) const = 0;
152 virtual wxWebViewZoom GetZoom() const = 0;
153 virtual wxWebViewZoomType GetZoomType() const = 0;
154 virtual void SetZoom(wxWebViewZoom zoom) = 0;
155 virtual void SetZoomType(wxWebViewZoomType zoomType) = 0;
156
157 //Selection
158 virtual void SelectAll() = 0;
159 virtual bool HasSelection() const = 0;
160 virtual void DeleteSelection() = 0;
161 virtual wxString GetSelectedText() const = 0;
162 virtual wxString GetSelectedSource() const = 0;
163 virtual void ClearSelection() = 0;
164
165 //Clipboard functions
166 virtual bool CanCut() const = 0;
167 virtual bool CanCopy() const = 0;
168 virtual bool CanPaste() const = 0;
169 virtual void Cut() = 0;
170 virtual void Copy() = 0;
171 virtual void Paste() = 0;
172
173 //Undo / redo functionality
174 virtual bool CanUndo() const = 0;
175 virtual bool CanRedo() const = 0;
176 virtual void Undo() = 0;
177 virtual void Redo() = 0;
178
179 wxDECLARE_ABSTRACT_CLASS(wxWebView);
180};
181
182class WXDLLIMPEXP_WEBVIEW wxWebViewEvent : public wxNotifyEvent
183{
184public:
185 wxWebViewEvent() {}
186 wxWebViewEvent(wxEventType type, int id, const wxString url,
187 const wxString target)
188 : wxNotifyEvent(type, id), m_url(url), m_target(target)
189 {}
190
191
192 const wxString& GetURL() const { return m_url; }
193 const wxString& GetTarget() const { return m_target; }
194
195 virtual wxEvent* Clone() const { return new wxWebViewEvent(*this); }
196private:
197 wxString m_url;
198 wxString m_target;
199
200 wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWebViewEvent);
201};
202
203wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_NAVIGATING, wxWebViewEvent );
204wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_NAVIGATED, wxWebViewEvent );
205wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_LOADED, wxWebViewEvent );
206wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_ERROR, wxWebViewEvent );
207wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, wxWebViewEvent );
208wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, wxWebViewEvent );
209
210typedef void (wxEvtHandler::*wxWebViewEventFunction)
211 (wxWebViewEvent&);
212
213#define wxWebViewEventHandler(func) \
214 wxEVENT_HANDLER_CAST(wxWebViewEventFunction, func)
215
216#define EVT_WEB_VIEW_NAVIGATING(id, fn) \
217 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATING, id, \
218 wxWebViewEventHandler(fn))
219
220#define EVT_WEB_VIEW_NAVIGATED(id, fn) \
221 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATED, id, \
222 wxWebViewEventHandler(fn))
223
224#define EVT_WEB_VIEW_LOADED(id, fn) \
225 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_LOADED, id, \
226 wxWebViewEventHandler(fn))
227
228#define EVT_WEB_VIEW_ERROR(id, fn) \
229 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_ERROR, id, \
230 wxWebViewEventHandler(fn))
231
232#define EVT_WEB_VIEW_NEWWINDOW(id, fn) \
233 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, id, \
234 wxWebViewEventHandler(fn))
235
236#define EVT_WEB_VIEW_TITLE_CHANGED(id, fn) \
237 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, id, \
238 wxWebViewEventHandler(fn))
239
240#endif // wxUSE_WEBVIEW
241
242#endif // _WX_WEB_VIEW_H_