webkit.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/html/webkit.h
  3. // Purpose: wxWebKitCtrl - embeddable web kit control
  4. // Author: Jethro Grassie / Kevin Ollivier
  5. // Modified by:
  6. // Created: 2004-4-16
  7. // Copyright: (c) Jethro Grassie / Kevin Ollivier
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_WEBKIT_H
  11. #define _WX_WEBKIT_H
  12. #if wxUSE_WEBKIT
  13. #if !defined(__WXMAC__) && !defined(__WXCOCOA__)
  14. #error "wxWebKitCtrl not implemented for this platform"
  15. #endif
  16. #include "wx/control.h"
  17. DECLARE_WXCOCOA_OBJC_CLASS(WebView);
  18. // ----------------------------------------------------------------------------
  19. // Web Kit Control
  20. // ----------------------------------------------------------------------------
  21. extern WXDLLIMPEXP_DATA_CORE(const char) wxWebKitCtrlNameStr[];
  22. class WXDLLIMPEXP_CORE wxWebKitCtrl : public wxControl
  23. {
  24. public:
  25. DECLARE_DYNAMIC_CLASS(wxWebKitCtrl)
  26. wxWebKitCtrl() {}
  27. wxWebKitCtrl(wxWindow *parent,
  28. wxWindowID winID,
  29. const wxString& strURL,
  30. const wxPoint& pos = wxDefaultPosition,
  31. const wxSize& size = wxDefaultSize, long style = 0,
  32. const wxValidator& validator = wxDefaultValidator,
  33. const wxString& name = wxWebKitCtrlNameStr)
  34. {
  35. Create(parent, winID, strURL, pos, size, style, validator, name);
  36. }
  37. bool Create(wxWindow *parent,
  38. wxWindowID winID,
  39. const wxString& strURL,
  40. const wxPoint& pos = wxDefaultPosition,
  41. const wxSize& size = wxDefaultSize, long style = 0,
  42. const wxValidator& validator = wxDefaultValidator,
  43. const wxString& name = wxWebKitCtrlNameStr);
  44. virtual ~wxWebKitCtrl();
  45. void LoadURL(const wxString &url);
  46. bool CanGoBack();
  47. bool CanGoForward();
  48. bool GoBack();
  49. bool GoForward();
  50. void Reload();
  51. void Stop();
  52. bool CanGetPageSource();
  53. wxString GetPageSource();
  54. void SetPageSource(const wxString& source, const wxString& baseUrl = wxEmptyString);
  55. wxString GetPageURL(){ return m_currentURL; }
  56. void SetPageTitle(const wxString& title) { m_pageTitle = title; }
  57. wxString GetPageTitle(){ return m_pageTitle; }
  58. // since these worked in 2.6, add wrappers
  59. void SetTitle(const wxString& title) { SetPageTitle(title); }
  60. wxString GetTitle() { return GetPageTitle(); }
  61. wxString GetSelection();
  62. bool CanIncreaseTextSize();
  63. void IncreaseTextSize();
  64. bool CanDecreaseTextSize();
  65. void DecreaseTextSize();
  66. void Print(bool showPrompt = false);
  67. void MakeEditable(bool enable = true);
  68. bool IsEditable();
  69. wxString RunScript(const wxString& javascript);
  70. void SetScrollPos(int pos);
  71. int GetScrollPos();
  72. // don't hide base class virtuals
  73. virtual void SetScrollPos( int orient, int pos, bool refresh = true )
  74. { return wxControl::SetScrollPos(orient, pos, refresh); }
  75. virtual int GetScrollPos( int orient ) const
  76. { return wxControl::GetScrollPos(orient); }
  77. //we need to resize the webview when the control size changes
  78. void OnSize(wxSizeEvent &event);
  79. void OnMove(wxMoveEvent &event);
  80. void OnMouseEvents(wxMouseEvent &event);
  81. protected:
  82. DECLARE_EVENT_TABLE()
  83. void MacVisibilityChanged();
  84. private:
  85. wxWindow *m_parent;
  86. wxWindowID m_windowID;
  87. wxString m_currentURL;
  88. wxString m_pageTitle;
  89. WX_WebView m_webView;
  90. // we may use this later to setup our own mouse events,
  91. // so leave it in for now.
  92. void* m_webKitCtrlEventHandler;
  93. };
  94. // ----------------------------------------------------------------------------
  95. // Web Kit Events
  96. // ----------------------------------------------------------------------------
  97. enum {
  98. wxWEBKIT_STATE_START = 1,
  99. wxWEBKIT_STATE_NEGOTIATING = 2,
  100. wxWEBKIT_STATE_REDIRECTING = 4,
  101. wxWEBKIT_STATE_TRANSFERRING = 8,
  102. wxWEBKIT_STATE_STOP = 16,
  103. wxWEBKIT_STATE_FAILED = 32
  104. };
  105. enum {
  106. wxWEBKIT_NAV_LINK_CLICKED = 1,
  107. wxWEBKIT_NAV_BACK_NEXT = 2,
  108. wxWEBKIT_NAV_FORM_SUBMITTED = 4,
  109. wxWEBKIT_NAV_RELOAD = 8,
  110. wxWEBKIT_NAV_FORM_RESUBMITTED = 16,
  111. wxWEBKIT_NAV_OTHER = 32
  112. };
  113. class WXDLLIMPEXP_CORE wxWebKitBeforeLoadEvent : public wxCommandEvent
  114. {
  115. DECLARE_DYNAMIC_CLASS( wxWebKitBeforeLoadEvent )
  116. public:
  117. bool IsCancelled() { return m_cancelled; }
  118. void Cancel(bool cancel = true) { m_cancelled = cancel; }
  119. wxString GetURL() { return m_url; }
  120. void SetURL(const wxString& url) { m_url = url; }
  121. void SetNavigationType(int navType) { m_navType = navType; }
  122. int GetNavigationType() { return m_navType; }
  123. wxWebKitBeforeLoadEvent( wxWindow* win = NULL );
  124. wxEvent *Clone(void) const { return new wxWebKitBeforeLoadEvent(*this); }
  125. protected:
  126. bool m_cancelled;
  127. wxString m_url;
  128. int m_navType;
  129. };
  130. class WXDLLIMPEXP_CORE wxWebKitStateChangedEvent : public wxCommandEvent
  131. {
  132. DECLARE_DYNAMIC_CLASS( wxWebKitStateChangedEvent )
  133. public:
  134. int GetState() { return m_state; }
  135. void SetState(const int state) { m_state = state; }
  136. wxString GetURL() { return m_url; }
  137. void SetURL(const wxString& url) { m_url = url; }
  138. wxWebKitStateChangedEvent( wxWindow* win = NULL );
  139. wxEvent *Clone(void) const { return new wxWebKitStateChangedEvent(*this); }
  140. protected:
  141. int m_state;
  142. wxString m_url;
  143. };
  144. class WXDLLIMPEXP_CORE wxWebKitNewWindowEvent : public wxCommandEvent
  145. {
  146. DECLARE_DYNAMIC_CLASS( wxWebKitNewWindowEvent )
  147. public:
  148. wxString GetURL() const { return m_url; }
  149. void SetURL(const wxString& url) { m_url = url; }
  150. wxString GetTargetName() const { return m_targetName; }
  151. void SetTargetName(const wxString& name) { m_targetName = name; }
  152. wxWebKitNewWindowEvent( wxWindow* win = (wxWindow*)(NULL));
  153. wxEvent *Clone(void) const { return new wxWebKitNewWindowEvent(*this); }
  154. private:
  155. wxString m_url;
  156. wxString m_targetName;
  157. };
  158. typedef void (wxEvtHandler::*wxWebKitStateChangedEventFunction)(wxWebKitStateChangedEvent&);
  159. typedef void (wxEvtHandler::*wxWebKitBeforeLoadEventFunction)(wxWebKitBeforeLoadEvent&);
  160. typedef void (wxEvtHandler::*wxWebKitNewWindowEventFunction)(wxWebKitNewWindowEvent&);
  161. #define wxWebKitStateChangedEventHandler( func ) \
  162. wxEVENT_HANDLER_CAST( wxWebKitStateChangedEventFunction, func )
  163. #define wxWebKitBeforeLoadEventHandler( func ) \
  164. wxEVENT_HANDLER_CAST( wxWebKitBeforeLoadEventFunction, func )
  165. #define wxWebKitNewWindowEventHandler( func ) \
  166. wxEVENT_HANDLER_CAST( wxWebKitNewWindowEventFunction, func )
  167. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_WEBKIT_STATE_CHANGED, wxWebKitStateChangedEvent );
  168. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_WEBKIT_BEFORE_LOAD, wxWebKitBeforeLoadEvent );
  169. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_WEBKIT_NEW_WINDOW, wxWebKitNewWindowEvent );
  170. #define EVT_WEBKIT_STATE_CHANGED(func) \
  171. wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_STATE_CHANGED, \
  172. wxID_ANY, \
  173. wxID_ANY, \
  174. wxWebKitStateChangedEventHandler( func ), \
  175. NULL ),
  176. #define EVT_WEBKIT_BEFORE_LOAD(func) \
  177. wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_BEFORE_LOAD, \
  178. wxID_ANY, \
  179. wxID_ANY, \
  180. wxWebKitBeforeLoadEventHandler( func ), \
  181. NULL ),
  182. #define EVT_WEBKIT_NEW_WINDOW(func) \
  183. wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_NEW_WINDOW, \
  184. wxID_ANY, \
  185. wxID_ANY, \
  186. wxWebKitNewWindowEventHandler( func ), \
  187. NULL ),
  188. #endif // wxUSE_WEBKIT
  189. #endif
  190. // _WX_WEBKIT_H_