2011-05-04 14:24:30 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: webview.h
|
|
|
|
// Purpose: Common interface and events for web view component
|
|
|
|
// Author: Marianne Gagnon
|
|
|
|
// Id: $Id$
|
2011-07-30 07:26:55 -04:00
|
|
|
// Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
|
2011-05-04 14:24:30 -04:00
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_WEB_VIEW_H_
|
|
|
|
#define _WX_WEB_VIEW_H_
|
|
|
|
|
2011-06-23 16:44:19 -04:00
|
|
|
#include "wx/setup.h"
|
2011-05-05 16:30:51 -04:00
|
|
|
|
|
|
|
#if wxUSE_WEB
|
|
|
|
|
2011-08-11 04:43:13 -04:00
|
|
|
#include "wx/control.h"
|
|
|
|
#include "wx/event.h"
|
|
|
|
#include "wx/sstream.h"
|
2011-07-01 06:57:37 -04:00
|
|
|
#include "wx/sharedptr.h"
|
2011-07-02 10:32:02 -04:00
|
|
|
#include "wx/vector.h"
|
2011-07-01 06:57:37 -04:00
|
|
|
|
2011-08-15 08:31:31 -04:00
|
|
|
#include "wx/osx/webviewhistoryitem_webkit.h"
|
|
|
|
#include "wx/gtk/webviewhistoryitem_webkit.h"
|
|
|
|
#include "wx/msw/webviewhistoryitem_ie.h"
|
2011-07-31 10:06:33 -04:00
|
|
|
|
2011-07-28 12:08:59 -04:00
|
|
|
class wxFSFile;
|
2011-07-28 12:49:48 -04:00
|
|
|
class wxFileSystem;
|
2011-07-28 12:08:59 -04:00
|
|
|
|
2011-05-04 14:24:30 -04:00
|
|
|
enum wxWebViewZoom
|
|
|
|
{
|
|
|
|
wxWEB_VIEW_ZOOM_TINY,
|
|
|
|
wxWEB_VIEW_ZOOM_SMALL,
|
|
|
|
wxWEB_VIEW_ZOOM_MEDIUM,
|
|
|
|
wxWEB_VIEW_ZOOM_LARGE,
|
|
|
|
wxWEB_VIEW_ZOOM_LARGEST
|
|
|
|
};
|
|
|
|
|
|
|
|
enum wxWebViewZoomType
|
|
|
|
{
|
2011-08-17 06:49:17 -04:00
|
|
|
//Scales entire page, including images
|
2011-05-04 14:24:30 -04:00
|
|
|
wxWEB_VIEW_ZOOM_TYPE_LAYOUT,
|
|
|
|
wxWEB_VIEW_ZOOM_TYPE_TEXT
|
|
|
|
};
|
|
|
|
|
2011-08-15 07:03:26 -04:00
|
|
|
enum wxWebViewNavigationError
|
2011-05-04 14:24:30 -04:00
|
|
|
{
|
2011-05-19 15:42:01 -04:00
|
|
|
wxWEB_NAV_ERR_CONNECTION,
|
|
|
|
wxWEB_NAV_ERR_CERTIFICATE,
|
|
|
|
wxWEB_NAV_ERR_AUTH,
|
|
|
|
wxWEB_NAV_ERR_SECURITY,
|
|
|
|
wxWEB_NAV_ERR_NOT_FOUND,
|
|
|
|
wxWEB_NAV_ERR_REQUEST,
|
|
|
|
wxWEB_NAV_ERR_USER_CANCELLED,
|
|
|
|
wxWEB_NAV_ERR_OTHER
|
2011-05-04 14:24:30 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
enum wxWebViewReloadFlags
|
|
|
|
{
|
2011-08-17 06:49:17 -04:00
|
|
|
//Default, may access cache
|
2011-05-19 15:42:01 -04:00
|
|
|
wxWEB_VIEW_RELOAD_DEFAULT,
|
2011-05-06 09:37:01 -04:00
|
|
|
wxWEB_VIEW_RELOAD_NO_CACHE
|
2011-05-04 14:24:30 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
enum wxWebViewBackend
|
|
|
|
{
|
|
|
|
wxWEB_VIEW_BACKEND_DEFAULT,
|
2011-07-05 11:33:42 -04:00
|
|
|
wxWEB_VIEW_BACKEND_WEBKIT,
|
2011-05-04 14:24:30 -04:00
|
|
|
wxWEB_VIEW_BACKEND_IE
|
|
|
|
};
|
|
|
|
|
2011-07-30 10:22:15 -04:00
|
|
|
//Base class for custom scheme handlers
|
2011-08-14 08:15:34 -04:00
|
|
|
class WXDLLIMPEXP_WEB wxWebViewHandler
|
2011-07-28 12:08:59 -04:00
|
|
|
{
|
|
|
|
public:
|
2011-08-14 08:15:34 -04:00
|
|
|
wxWebViewHandler(const wxString& scheme) : m_scheme(scheme) {}
|
|
|
|
virtual wxString GetName() const { return m_scheme; }
|
2011-07-28 12:08:59 -04:00
|
|
|
virtual wxFSFile* GetFile(const wxString &uri) = 0;
|
2011-08-14 08:15:34 -04:00
|
|
|
private:
|
|
|
|
wxString m_scheme;
|
2011-07-28 12:08:59 -04:00
|
|
|
};
|
|
|
|
|
2011-05-06 07:00:45 -04:00
|
|
|
extern WXDLLIMPEXP_DATA_WEB(const char) wxWebViewNameStr[];
|
|
|
|
extern WXDLLIMPEXP_DATA_WEB(const char) wxWebViewDefaultURLStr[];
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2011-05-06 07:00:45 -04:00
|
|
|
class WXDLLIMPEXP_WEB wxWebView : public wxControl
|
2011-05-04 14:24:30 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual bool Create(wxWindow* parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxString& url,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
|
|
|
long style,
|
|
|
|
const wxString& name) = 0;
|
|
|
|
|
|
|
|
static wxWebView* New(wxWebViewBackend backend = wxWEB_VIEW_BACKEND_DEFAULT);
|
|
|
|
static wxWebView* New(wxWindow* parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxString& url = wxWebViewDefaultURLStr,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
wxWebViewBackend backend = wxWEB_VIEW_BACKEND_DEFAULT,
|
|
|
|
long style = 0,
|
|
|
|
const wxString& name = wxWebViewNameStr);
|
|
|
|
|
2011-08-17 06:49:17 -04:00
|
|
|
//General methods
|
|
|
|
virtual wxString GetCurrentTitle() const = 0;
|
|
|
|
virtual wxString GetCurrentURL() const = 0;
|
|
|
|
// TODO: handle choosing a frame when calling GetPageSource()?
|
|
|
|
virtual wxString GetPageSource() const = 0;
|
|
|
|
virtual wxString GetPageText() const = 0;
|
|
|
|
virtual bool IsBusy() const = 0;
|
|
|
|
virtual bool IsEditable() const = 0;
|
|
|
|
virtual void LoadUrl(const wxString& url) = 0;
|
|
|
|
virtual void Print() = 0;
|
|
|
|
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) = 0;
|
|
|
|
virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT) = 0;
|
|
|
|
virtual void RunScript(const wxString& javascript) = 0;
|
|
|
|
virtual void SetEditable(bool enable = true) = 0;
|
|
|
|
virtual void SetPage(const wxString& html, const wxString& baseUrl) = 0;
|
|
|
|
virtual void SetPage(wxInputStream& html, wxString baseUrl)
|
|
|
|
{
|
|
|
|
wxStringOutputStream stream;
|
|
|
|
stream.Write(html);
|
|
|
|
SetPage(stream.GetString(), baseUrl);
|
|
|
|
}
|
|
|
|
virtual void Stop() = 0;
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2011-08-17 06:49:17 -04:00
|
|
|
//History
|
2011-08-17 06:26:09 -04:00
|
|
|
virtual bool CanGoBack() const = 0;
|
|
|
|
virtual bool CanGoForward() const = 0;
|
2011-05-04 14:24:30 -04:00
|
|
|
virtual void GoBack() = 0;
|
|
|
|
virtual void GoForward() = 0;
|
2011-06-30 06:03:25 -04:00
|
|
|
virtual void ClearHistory() = 0;
|
|
|
|
virtual void EnableHistory(bool enable = true) = 0;
|
2011-08-15 08:31:31 -04:00
|
|
|
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory() = 0;
|
|
|
|
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory() = 0;
|
|
|
|
virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item) = 0;
|
2011-06-30 06:03:25 -04:00
|
|
|
|
2011-08-17 06:49:17 -04:00
|
|
|
//Zoom
|
|
|
|
virtual bool CanSetZoomType(wxWebViewZoomType type) const = 0;
|
2011-08-17 06:26:09 -04:00
|
|
|
virtual wxWebViewZoom GetZoom() const = 0;
|
2011-08-17 06:49:17 -04:00
|
|
|
virtual wxWebViewZoomType GetZoomType() const = 0;
|
2011-05-04 14:24:30 -04:00
|
|
|
virtual void SetZoom(wxWebViewZoom zoom) = 0;
|
|
|
|
virtual void SetZoomType(wxWebViewZoomType zoomType) = 0;
|
|
|
|
|
2011-08-17 06:49:17 -04:00
|
|
|
//Selection
|
2011-07-09 10:31:29 -04:00
|
|
|
virtual void SelectAll() = 0;
|
2011-08-17 06:26:09 -04:00
|
|
|
virtual bool HasSelection() const = 0;
|
2011-07-09 10:31:29 -04:00
|
|
|
virtual void DeleteSelection() = 0;
|
2011-08-17 06:26:09 -04:00
|
|
|
virtual wxString GetSelectedText() const = 0;
|
|
|
|
virtual wxString GetSelectedSource() const = 0;
|
2011-07-15 05:36:08 -04:00
|
|
|
virtual void ClearSelection() = 0;
|
2011-07-09 10:31:29 -04:00
|
|
|
|
2011-07-02 07:45:19 -04:00
|
|
|
//Clipboard functions
|
2011-08-17 06:26:09 -04:00
|
|
|
virtual bool CanCut() const = 0;
|
|
|
|
virtual bool CanCopy() const = 0;
|
|
|
|
virtual bool CanPaste() const = 0;
|
2011-07-02 07:45:19 -04:00
|
|
|
virtual void Cut() = 0;
|
|
|
|
virtual void Copy() = 0;
|
|
|
|
virtual void Paste() = 0;
|
2011-07-02 11:07:46 -04:00
|
|
|
|
|
|
|
//Undo / redo functionality
|
2011-08-17 06:26:09 -04:00
|
|
|
virtual bool CanUndo() const = 0;
|
|
|
|
virtual bool CanRedo() const = 0;
|
2011-07-02 11:07:46 -04:00
|
|
|
virtual void Undo() = 0;
|
|
|
|
virtual void Redo() = 0;
|
2011-07-28 12:49:48 -04:00
|
|
|
|
2011-08-01 11:49:05 -04:00
|
|
|
wxDECLARE_ABSTRACT_CLASS(wxWebView);
|
2011-05-04 14:24:30 -04:00
|
|
|
};
|
|
|
|
|
2011-08-15 07:03:26 -04:00
|
|
|
class WXDLLIMPEXP_WEB wxWebViewEvent : public wxCommandEvent
|
2011-05-04 14:24:30 -04:00
|
|
|
{
|
|
|
|
public:
|
2011-08-15 07:03:26 -04:00
|
|
|
wxWebViewEvent() {}
|
|
|
|
wxWebViewEvent(wxEventType type, int id, const wxString url,
|
|
|
|
const wxString target, bool canVeto)
|
2011-05-04 14:24:30 -04:00
|
|
|
: wxCommandEvent(type, id)
|
|
|
|
{
|
2011-07-25 10:30:07 -04:00
|
|
|
m_url = url;
|
2011-05-04 14:24:30 -04:00
|
|
|
m_target = target;
|
|
|
|
m_vetoed = false;
|
|
|
|
m_canVeto = canVeto;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-17 06:49:17 -04:00
|
|
|
const wxString& GetURL() const { return m_url; }
|
2011-05-04 14:24:30 -04:00
|
|
|
const wxString& GetTarget() const { return m_target; }
|
|
|
|
|
2011-08-15 07:03:26 -04:00
|
|
|
virtual wxEvent* Clone() const { return new wxWebViewEvent(*this); }
|
2011-05-04 14:24:30 -04:00
|
|
|
|
|
|
|
bool CanVeto() const { return m_canVeto; }
|
|
|
|
bool IsVetoed() const { return m_vetoed; }
|
|
|
|
|
|
|
|
void Veto() { wxASSERT(m_canVeto); m_vetoed = true; }
|
|
|
|
|
|
|
|
private:
|
2011-07-25 10:30:07 -04:00
|
|
|
wxString m_url;
|
2011-05-04 14:24:30 -04:00
|
|
|
wxString m_target;
|
|
|
|
bool m_canVeto;
|
|
|
|
bool m_vetoed;
|
|
|
|
|
2011-08-15 07:03:26 -04:00
|
|
|
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWebViewEvent);
|
2011-05-04 14:24:30 -04:00
|
|
|
};
|
|
|
|
|
2011-08-15 07:03:26 -04:00
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_NAVIGATING, wxWebViewEvent );
|
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_NAVIGATED, wxWebViewEvent );
|
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_LOADED, wxWebViewEvent );
|
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_ERROR, wxWebViewEvent );
|
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, wxWebViewEvent );
|
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, wxWebViewEvent );
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2011-08-15 07:03:26 -04:00
|
|
|
typedef void (wxEvtHandler::*wxWebViewEventFunction)
|
|
|
|
(wxWebViewEvent&);
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2011-08-15 07:03:26 -04:00
|
|
|
#define wxWebViewEventHandler(func) \
|
|
|
|
wxEVENT_HANDLER_CAST(wxWebViewEventFunction, func)
|
2011-05-04 14:24:30 -04:00
|
|
|
|
|
|
|
#define EVT_WEB_VIEW_NAVIGATING(id, fn) \
|
2011-05-05 09:01:54 -04:00
|
|
|
wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATING, id, \
|
2011-08-15 07:03:26 -04:00
|
|
|
wxWebViewEventHandler(fn))
|
2011-05-04 14:24:30 -04:00
|
|
|
|
|
|
|
#define EVT_WEB_VIEW_NAVIGATED(id, fn) \
|
2011-05-05 09:01:54 -04:00
|
|
|
wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATED, id, \
|
2011-08-15 07:03:26 -04:00
|
|
|
wxWebViewEventHandler(fn))
|
2011-05-04 14:24:30 -04:00
|
|
|
|
|
|
|
#define EVT_WEB_VIEW_LOADED(id, fn) \
|
2011-05-05 09:01:54 -04:00
|
|
|
wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_LOADED, id, \
|
2011-08-15 07:03:26 -04:00
|
|
|
wxWebViewEventHandler(fn))
|
2011-05-04 14:24:30 -04:00
|
|
|
|
|
|
|
#define EVT_WEB_VIEW_ERRROR(id, fn) \
|
2011-05-05 09:01:54 -04:00
|
|
|
wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_ERROR, id, \
|
2011-08-15 07:03:26 -04:00
|
|
|
wxWebViewEventHandler(fn))
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2011-05-26 14:43:18 -04:00
|
|
|
#define EVT_WEB_VIEW_NEWWINDOW(id, fn) \
|
|
|
|
wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, id, \
|
2011-08-15 07:03:26 -04:00
|
|
|
wxWebViewEventHandler(fn))
|
2011-05-26 14:43:18 -04:00
|
|
|
|
2011-07-30 07:26:55 -04:00
|
|
|
#define EVT_WEB_VIEW_TITLE_CHANGED(id, fn) \
|
|
|
|
wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, id, \
|
2011-08-15 07:03:26 -04:00
|
|
|
wxWebViewEventHandler(fn))
|
2011-07-30 07:26:55 -04:00
|
|
|
|
2011-05-05 16:30:51 -04:00
|
|
|
#endif // wxUSE_WEB
|
|
|
|
|
|
|
|
#endif // _WX_WEB_VIEW_H_
|