1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/html/webkit.h
3 // Purpose: wxWebKitCtrl - embeddable web kit control
4 // Author: Jethro Grassie / Kevin Ollivier
8 // Copyright: (c) Jethro Grassie / Kevin Ollivier
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
17 #if !defined(__WXMAC__) && !defined(__WXCOCOA__)
18 #error "wxWebKitCtrl not implemented for this platform"
21 #include "wx/control.h"
22 DECLARE_WXCOCOA_OBJC_CLASS(WebView
);
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
28 extern WXDLLIMPEXP_DATA_CORE(const char) wxWebKitCtrlNameStr
[];
30 class WXDLLIMPEXP_CORE wxWebKitCtrl
: public wxControl
33 DECLARE_DYNAMIC_CLASS(wxWebKitCtrl
)
36 wxWebKitCtrl(wxWindow
*parent
,
38 const wxString
& strURL
,
39 const wxPoint
& pos
= wxDefaultPosition
,
40 const wxSize
& size
= wxDefaultSize
, long style
= 0,
41 const wxValidator
& validator
= wxDefaultValidator
,
42 const wxString
& name
= wxWebKitCtrlNameStr
)
44 Create(parent
, winID
, strURL
, pos
, size
, style
, validator
, name
);
46 bool Create(wxWindow
*parent
,
48 const wxString
& strURL
,
49 const wxPoint
& pos
= wxDefaultPosition
,
50 const wxSize
& size
= wxDefaultSize
, long style
= 0,
51 const wxValidator
& validator
= wxDefaultValidator
,
52 const wxString
& name
= wxWebKitCtrlNameStr
);
53 virtual ~wxWebKitCtrl();
55 void LoadURL(const wxString
&url
);
63 bool CanGetPageSource();
64 wxString
GetPageSource();
65 void SetPageSource(const wxString
& source
, const wxString
& baseUrl
= wxEmptyString
);
66 wxString
GetPageURL(){ return m_currentURL
; }
67 void SetPageTitle(const wxString
& title
) { m_pageTitle
= title
; }
68 wxString
GetPageTitle(){ return m_pageTitle
; }
70 // since these worked in 2.6, add wrappers
71 void SetTitle(const wxString
& title
) { SetPageTitle(title
); }
72 wxString
GetTitle() { return GetPageTitle(); }
74 wxString
GetSelection();
76 bool CanIncreaseTextSize();
77 void IncreaseTextSize();
78 bool CanDecreaseTextSize();
79 void DecreaseTextSize();
81 void Print(bool showPrompt
= false);
83 void MakeEditable(bool enable
= true);
86 wxString
RunScript(const wxString
& javascript
);
88 void SetScrollPos(int pos
);
91 // don't hide base class virtuals
92 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= true )
93 { return wxControl::SetScrollPos(orient
, pos
, refresh
); }
94 virtual int GetScrollPos( int orient
) const
95 { return wxControl::GetScrollPos(orient
); }
97 //we need to resize the webview when the control size changes
98 void OnSize(wxSizeEvent
&event
);
99 void OnMove(wxMoveEvent
&event
);
100 void OnMouseEvents(wxMouseEvent
&event
);
102 DECLARE_EVENT_TABLE()
103 void MacVisibilityChanged();
107 wxWindowID m_windowID
;
108 wxString m_currentURL
;
109 wxString m_pageTitle
;
111 WX_WebView m_webView
;
113 // we may use this later to setup our own mouse events,
114 // so leave it in for now.
115 void* m_webKitCtrlEventHandler
;
118 // ----------------------------------------------------------------------------
120 // ----------------------------------------------------------------------------
123 wxWEBKIT_STATE_START
= 1,
124 wxWEBKIT_STATE_NEGOTIATING
= 2,
125 wxWEBKIT_STATE_REDIRECTING
= 4,
126 wxWEBKIT_STATE_TRANSFERRING
= 8,
127 wxWEBKIT_STATE_STOP
= 16,
128 wxWEBKIT_STATE_FAILED
= 32
132 wxWEBKIT_NAV_LINK_CLICKED
= 1,
133 wxWEBKIT_NAV_BACK_NEXT
= 2,
134 wxWEBKIT_NAV_FORM_SUBMITTED
= 4,
135 wxWEBKIT_NAV_RELOAD
= 8,
136 wxWEBKIT_NAV_FORM_RESUBMITTED
= 16,
137 wxWEBKIT_NAV_OTHER
= 32
143 class WXDLLIMPEXP_CORE wxWebKitBeforeLoadEvent
: public wxCommandEvent
145 DECLARE_DYNAMIC_CLASS( wxWebKitBeforeLoadEvent
)
148 bool IsCancelled() { return m_cancelled
; }
149 void Cancel(bool cancel
= true) { m_cancelled
= cancel
; }
150 wxString
GetURL() { return m_url
; }
151 void SetURL(const wxString
& url
) { m_url
= url
; }
152 void SetNavigationType(int navType
) { m_navType
= navType
; }
153 int GetNavigationType() { return m_navType
; }
155 wxWebKitBeforeLoadEvent( wxWindow
* win
= NULL
);
156 wxEvent
*Clone(void) const { return new wxWebKitBeforeLoadEvent(*this); }
164 class WXDLLIMPEXP_CORE wxWebKitStateChangedEvent
: public wxCommandEvent
166 DECLARE_DYNAMIC_CLASS( wxWebKitStateChangedEvent
)
169 int GetState() { return m_state
; }
170 void SetState(const int state
) { m_state
= state
; }
171 wxString
GetURL() { return m_url
; }
172 void SetURL(const wxString
& url
) { m_url
= url
; }
174 wxWebKitStateChangedEvent( wxWindow
* win
= NULL
);
175 wxEvent
*Clone(void) const { return new wxWebKitStateChangedEvent(*this); }
183 class WXDLLIMPEXP_CORE wxWebKitNewWindowEvent
: public wxCommandEvent
185 DECLARE_DYNAMIC_CLASS( wxWebKitNewWindowEvent
)
187 wxString
GetURL() const { return m_url
; }
188 void SetURL(const wxString
& url
) { m_url
= url
; }
189 wxString
GetTargetName() const { return m_targetName
; }
190 void SetTargetName(const wxString
& name
) { m_targetName
= name
; }
192 wxWebKitNewWindowEvent( wxWindow
* win
= (wxWindow
*)(NULL
));
193 wxEvent
*Clone(void) const { return new wxWebKitNewWindowEvent(*this); }
197 wxString m_targetName
;
200 typedef void (wxEvtHandler::*wxWebKitStateChangedEventFunction
)(wxWebKitStateChangedEvent
&);
201 typedef void (wxEvtHandler::*wxWebKitBeforeLoadEventFunction
)(wxWebKitBeforeLoadEvent
&);
202 typedef void (wxEvtHandler::*wxWebKitNewWindowEventFunction
)(wxWebKitNewWindowEvent
&);
204 #define wxWebKitStateChangedEventHandler( func ) \
205 wxEVENT_HANDLER_CAST( wxWebKitStateChangedEventFunction, func )
207 #define wxWebKitBeforeLoadEventHandler( func ) \
208 wxEVENT_HANDLER_CAST( wxWebKitBeforeLoadEventFunction, func )
210 #define wxWebKitNewWindowEventHandler( func ) \
211 wxEVENT_HANDLER_CAST( wxWebKitNewWindowEventFunction, func )
213 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_WEBKIT_STATE_CHANGED
, wxWebKitStateChangedEvent
);
214 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_WEBKIT_BEFORE_LOAD
, wxWebKitBeforeLoadEvent
);
215 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_WEBKIT_NEW_WINDOW
, wxWebKitNewWindowEvent
);
217 #define EVT_WEBKIT_STATE_CHANGED(func) \
218 wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_STATE_CHANGED, \
221 wxWebKitStateChangedEventHandler( func ), \
224 #define EVT_WEBKIT_BEFORE_LOAD(func) \
225 wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_BEFORE_LOAD, \
228 wxWebKitBeforeLoadEventHandler( func ), \
231 #define EVT_WEBKIT_NEW_WINDOW(func) \
232 wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_NEW_WINDOW, \
235 wxWebKitNewWindowEventHandler( func ), \
237 #endif // wxUSE_WEBKIT