X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b2b31b87fbac61af6eb96f3f5fa960ee4479bb1d..11e3c6ef36393fb5863ea2f9601d8facd73acb12:/include/wx/webview.h?ds=sidebyside diff --git a/include/wx/webview.h b/include/wx/webview.h index a58fd87f97..c6e8b200cf 100644 --- a/include/wx/webview.h +++ b/include/wx/webview.h @@ -7,10 +7,10 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef _WX_WEB_VIEW_H_ -#define _WX_WEB_VIEW_H_ +#ifndef _WX_WEBVIEW_H_ +#define _WX_WEBVIEW_H_ -#include "wx/setup.h" +#include "wx/defs.h" #if wxUSE_WEBVIEW @@ -20,53 +20,63 @@ #include "wx/sharedptr.h" #include "wx/vector.h" -#include "wx/osx/webviewhistoryitem_webkit.h" -#include "wx/gtk/webviewhistoryitem_webkit.h" -#include "wx/msw/webviewhistoryitem_ie.h" +#if defined(__WXOSX__) + #include "wx/osx/webviewhistoryitem_webkit.h" +#elif defined(__WXGTK__) + #include "wx/gtk/webviewhistoryitem_webkit.h" +#elif defined(__WXMSW__) + #include "wx/msw/webviewhistoryitem_ie.h" +#else + #error "wxWebView not implemented on this platform." +#endif class wxFSFile; class wxFileSystem; +class wxWebView; enum wxWebViewZoom { - wxWEB_VIEW_ZOOM_TINY, - wxWEB_VIEW_ZOOM_SMALL, - wxWEB_VIEW_ZOOM_MEDIUM, - wxWEB_VIEW_ZOOM_LARGE, - wxWEB_VIEW_ZOOM_LARGEST + wxWEBVIEW_ZOOM_TINY, + wxWEBVIEW_ZOOM_SMALL, + wxWEBVIEW_ZOOM_MEDIUM, + wxWEBVIEW_ZOOM_LARGE, + wxWEBVIEW_ZOOM_LARGEST }; enum wxWebViewZoomType { //Scales entire page, including images - wxWEB_VIEW_ZOOM_TYPE_LAYOUT, - wxWEB_VIEW_ZOOM_TYPE_TEXT + wxWEBVIEW_ZOOM_TYPE_LAYOUT, + wxWEBVIEW_ZOOM_TYPE_TEXT }; enum wxWebViewNavigationError { - 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 + wxWEBVIEW_NAV_ERR_CONNECTION, + wxWEBVIEW_NAV_ERR_CERTIFICATE, + wxWEBVIEW_NAV_ERR_AUTH, + wxWEBVIEW_NAV_ERR_SECURITY, + wxWEBVIEW_NAV_ERR_NOT_FOUND, + wxWEBVIEW_NAV_ERR_REQUEST, + wxWEBVIEW_NAV_ERR_USER_CANCELLED, + wxWEBVIEW_NAV_ERR_OTHER }; enum wxWebViewReloadFlags { //Default, may access cache - wxWEB_VIEW_RELOAD_DEFAULT, - wxWEB_VIEW_RELOAD_NO_CACHE + wxWEBVIEW_RELOAD_DEFAULT, + wxWEBVIEW_RELOAD_NO_CACHE }; -enum wxWebViewBackend +enum wxWebViewFindFlags { - wxWEB_VIEW_BACKEND_DEFAULT, - wxWEB_VIEW_BACKEND_WEBKIT, - wxWEB_VIEW_BACKEND_IE + wxWEBVIEW_FIND_WRAP = 0x0001, + wxWEBVIEW_FIND_ENTIRE_WORD = 0x0002, + wxWEBVIEW_FIND_MATCH_CASE = 0x0004, + wxWEBVIEW_FIND_HIGHLIGHT_RESULT = 0x0008, + wxWEBVIEW_FIND_BACKWARDS = 0x0010, + wxWEBVIEW_FIND_DEFAULT = 0 }; //Base class for custom scheme handlers @@ -83,49 +93,86 @@ private: extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewNameStr[]; extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewDefaultURLStr[]; +extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendDefault[]; +extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendIE[]; +extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendWebKit[]; + +class WXDLLIMPEXP_WEBVIEW wxWebViewFactory : public wxObject +{ +public: + virtual wxWebView* Create() = 0; + virtual wxWebView* Create(wxWindow* parent, + wxWindowID id, + const wxString& url = wxWebViewDefaultURLStr, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString& name = wxWebViewNameStr) = 0; +}; + +WX_DECLARE_STRING_HASH_MAP(wxSharedPtr, wxStringWebViewFactoryMap); class WXDLLIMPEXP_WEBVIEW wxWebView : public wxControl { public: + wxWebView() + { + m_showMenu = true; + } - virtual bool Create(wxWindow* parent, - wxWindowID id, - const wxString& url, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) = 0; + virtual ~wxWebView() {} - static wxWebView* New(wxWebViewBackend backend = wxWEB_VIEW_BACKEND_DEFAULT); - static wxWebView* New(wxWindow* parent, + virtual bool Create(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); + const wxString& name = wxWebViewNameStr) = 0; - //General methods + // Factory methods allowing the use of custom factories registered with + // RegisterFactory + static wxWebView* New(const wxString& backend = wxWebViewBackendDefault); + static wxWebView* New(wxWindow* parent, + wxWindowID id, + const wxString& url = wxWebViewDefaultURLStr, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + const wxString& backend = wxWebViewBackendDefault, + long style = 0, + const wxString& name = wxWebViewNameStr); + + static void RegisterFactory(const wxString& backend, + wxSharedPtr factory); + + // General methods + virtual void EnableContextMenu(bool enable = true) + { + m_showMenu = enable; + } 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 IsContextMenuEnabled() const { return m_showMenu; } virtual bool IsEditable() const = 0; virtual void LoadURL(const wxString& url) = 0; virtual void Print() = 0; virtual void RegisterHandler(wxSharedPtr handler) = 0; - virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT) = 0; + virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_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) + void SetPage(const wxString& html, const wxString& baseUrl) + { + DoSetPage(html, baseUrl); + } + void SetPage(wxInputStream& html, wxString baseUrl) { wxStringOutputStream stream; stream.Write(html); - SetPage(stream.GetString(), baseUrl); + DoSetPage(stream.GetString(), baseUrl); } virtual void Stop() = 0; @@ -169,6 +216,21 @@ public: virtual void Undo() = 0; virtual void Redo() = 0; + //Get the pointer to the underlying native engine. + virtual void* GetNativeBackend() const = 0; + //Find function + virtual long Find(const wxString& text, int flags = wxWEBVIEW_FIND_DEFAULT) = 0; + +protected: + virtual void DoSetPage(const wxString& html, const wxString& baseUrl) = 0; + +private: + static void InitFactoryMap(); + static wxStringWebViewFactoryMap::iterator FindFactory(const wxString &backend); + + bool m_showMenu; + static wxStringWebViewFactoryMap m_factoryMap; + wxDECLARE_ABSTRACT_CLASS(wxWebView); }; @@ -193,12 +255,12 @@ private: wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWebViewEvent); }; -wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_NAVIGATING, wxWebViewEvent ); -wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_NAVIGATED, wxWebViewEvent ); -wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_LOADED, wxWebViewEvent ); -wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_ERROR, wxWebViewEvent ); -wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, wxWebViewEvent ); -wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, wxWebViewEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEBVIEW_NAVIGATING, wxWebViewEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEBVIEW_NAVIGATED, wxWebViewEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEBVIEW_LOADED, wxWebViewEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEBVIEW_ERROR, wxWebViewEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEBVIEW_NEWWINDOW, wxWebViewEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEBVIEW_TITLE_CHANGED, wxWebViewEvent ); typedef void (wxEvtHandler::*wxWebViewEventFunction) (wxWebViewEvent&); @@ -206,30 +268,30 @@ typedef void (wxEvtHandler::*wxWebViewEventFunction) #define wxWebViewEventHandler(func) \ wxEVENT_HANDLER_CAST(wxWebViewEventFunction, func) -#define EVT_WEB_VIEW_NAVIGATING(id, fn) \ - wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATING, id, \ +#define EVT_WEBVIEW_NAVIGATING(id, fn) \ + wx__DECLARE_EVT1(wxEVT_COMMAND_WEBVIEW_NAVIGATING, id, \ wxWebViewEventHandler(fn)) -#define EVT_WEB_VIEW_NAVIGATED(id, fn) \ - wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATED, id, \ +#define EVT_WEBVIEW_NAVIGATED(id, fn) \ + wx__DECLARE_EVT1(wxEVT_COMMAND_WEBVIEW_NAVIGATED, id, \ wxWebViewEventHandler(fn)) -#define EVT_WEB_VIEW_LOADED(id, fn) \ - wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_LOADED, id, \ +#define EVT_WEBVIEW_LOADED(id, fn) \ + wx__DECLARE_EVT1(wxEVT_COMMAND_WEBVIEW_LOADED, id, \ wxWebViewEventHandler(fn)) -#define EVT_WEB_VIEW_ERRROR(id, fn) \ - wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_ERROR, id, \ +#define EVT_WEBVIEW_ERROR(id, fn) \ + wx__DECLARE_EVT1(wxEVT_COMMAND_WEBVIEW_ERROR, id, \ wxWebViewEventHandler(fn)) -#define EVT_WEB_VIEW_NEWWINDOW(id, fn) \ - wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, id, \ +#define EVT_WEBVIEW_NEWWINDOW(id, fn) \ + wx__DECLARE_EVT1(wxEVT_COMMAND_WEBVIEW_NEWWINDOW, id, \ wxWebViewEventHandler(fn)) -#define EVT_WEB_VIEW_TITLE_CHANGED(id, fn) \ - wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, id, \ +#define EVT_WEBVIEW_TITLE_CHANGED(id, fn) \ + wx__DECLARE_EVT1(wxEVT_COMMAND_WEBVIEW_TITLE_CHANGED, id, \ wxWebViewEventHandler(fn)) #endif // wxUSE_WEBVIEW -#endif // _WX_WEB_VIEW_H_ +#endif // _WX_WEBVIEW_H_