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"
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
27 class WXDLLIMPEXP_CORE wxWebKitCtrl
: public wxControl
30 DECLARE_DYNAMIC_CLASS(wxWebKitCtrl
)
33 wxWebKitCtrl(wxWindow
*parent
,
35 const wxString
& strURL
,
36 const wxPoint
& pos
= wxDefaultPosition
,
37 const wxSize
& size
= wxDefaultSize
, long style
= 0,
38 const wxValidator
& validator
= wxDefaultValidator
,
39 const wxString
& name
= wxT("webkitctrl"))
41 Create(parent
, winID
, strURL
, pos
, size
, style
, validator
, name
);
43 bool Create(wxWindow
*parent
,
45 const wxString
& strURL
,
46 const wxPoint
& pos
= wxDefaultPosition
,
47 const wxSize
& size
= wxDefaultSize
, long style
= 0,
48 const wxValidator
& validator
= wxDefaultValidator
,
49 const wxString
& name
= wxT("webkitctrl"));
50 virtual ~wxWebKitCtrl();
52 void LoadURL(const wxString
&url
);
60 bool CanGetPageSource();
61 wxString
GetPageSource();
62 void SetPageSource(const wxString
& source
, const wxString
& baseUrl
= wxEmptyString
);
63 wxString
GetPageURL(){ return m_currentURL
; }
64 void SetPageTitle(const wxString
& title
) { m_pageTitle
= title
; }
65 wxString
GetPageTitle(){ return m_pageTitle
; }
67 // since these worked in 2.6, add wrappers
68 void SetTitle(const wxString
& title
) { SetPageTitle(title
); }
69 wxString
GetTitle() { return GetPageTitle(); }
71 wxString
GetSelection();
73 bool CanIncreaseTextSize();
74 void IncreaseTextSize();
75 bool CanDecreaseTextSize();
76 void DecreaseTextSize();
78 void Print(bool showPrompt
=FALSE
);
80 void MakeEditable(bool enable
=TRUE
);
83 wxString
RunScript(const wxString
& javascript
);
85 void SetScrollPos(int pos
);
88 //we need to resize the webview when the control size changes
89 void OnSize(wxSizeEvent
&event
);
90 void OnMove(wxMoveEvent
&event
);
91 void OnMouseEvents(wxMouseEvent
&event
);
94 void MacVisibilityChanged();
98 wxWindowID m_windowID
;
99 wxString m_currentURL
;
100 wxString m_pageTitle
;
102 struct objc_object
*m_webView
;
104 // we may use this later to setup our own mouse events,
105 // so leave it in for now.
106 void* m_webKitCtrlEventHandler
;
107 //It should be WebView*, but WebView is an Objective-C class
108 //TODO: look into using DECLARE_WXCOCOA_OBJC_CLASS rather than this.
111 // ----------------------------------------------------------------------------
113 // ----------------------------------------------------------------------------
116 wxWEBKIT_STATE_START
= 1,
117 wxWEBKIT_STATE_NEGOTIATING
= 2,
118 wxWEBKIT_STATE_REDIRECTING
= 4,
119 wxWEBKIT_STATE_TRANSFERRING
= 8,
120 wxWEBKIT_STATE_STOP
= 16,
121 wxWEBKIT_STATE_FAILED
= 32
125 wxWEBKIT_NAV_LINK_CLICKED
= 1,
126 wxWEBKIT_NAV_BACK_NEXT
= 2,
127 wxWEBKIT_NAV_FORM_SUBMITTED
= 4,
128 wxWEBKIT_NAV_RELOAD
= 8,
129 wxWEBKIT_NAV_FORM_RESUBMITTED
= 16,
130 wxWEBKIT_NAV_OTHER
= 32
136 class WXDLLIMPEXP_CORE wxWebKitBeforeLoadEvent
: public wxCommandEvent
138 DECLARE_DYNAMIC_CLASS( wxWebKitBeforeLoadEvent
)
141 bool IsCancelled() { return m_cancelled
; }
142 void Cancel(bool cancel
= true) { m_cancelled
= cancel
; }
143 wxString
GetURL() { return m_url
; }
144 void SetURL(const wxString
& url
) { m_url
= url
; }
145 void SetNavigationType(int navType
) { m_navType
= navType
; }
146 int GetNavigationType() { return m_navType
; }
148 wxWebKitBeforeLoadEvent( wxWindow
* win
= NULL
);
149 wxEvent
*Clone(void) const { return new wxWebKitBeforeLoadEvent(*this); }
157 class WXDLLIMPEXP_CORE wxWebKitStateChangedEvent
: public wxCommandEvent
159 DECLARE_DYNAMIC_CLASS( wxWebKitStateChangedEvent
)
162 int GetState() { return m_state
; }
163 void SetState(const int state
) { m_state
= state
; }
164 wxString
GetURL() { return m_url
; }
165 void SetURL(const wxString
& url
) { m_url
= url
; }
167 wxWebKitStateChangedEvent( wxWindow
* win
= NULL
);
168 wxEvent
*Clone(void) const { return new wxWebKitStateChangedEvent(*this); }
176 class WXDLLIMPEXP_CORE wxWebKitNewWindowEvent
: public wxCommandEvent
178 DECLARE_DYNAMIC_CLASS( wxWebViewNewWindowEvent
)
180 wxString
GetURL() const { return m_url
; }
181 void SetURL(const wxString
& url
) { m_url
= url
; }
182 wxString
GetTargetName() const { return m_targetName
; }
183 void SetTargetName(const wxString
& name
) { m_targetName
= name
; }
185 wxWebKitNewWindowEvent( wxWindow
* win
= (wxWindow
*)(NULL
));
186 wxEvent
*Clone(void) const { return new wxWebKitNewWindowEvent(*this); }
190 wxString m_targetName
;
193 typedef void (wxEvtHandler::*wxWebKitStateChangedEventFunction
)(wxWebKitStateChangedEvent
&);
194 typedef void (wxEvtHandler::*wxWebKitBeforeLoadEventFunction
)(wxWebKitBeforeLoadEvent
&);
195 typedef void (wxEvtHandler::*wxWebKitNewWindowEventFunction
)(wxWebKitNewWindowEvent
&);
197 #define wxWebKitStateChangedEventHandler( func ) \
198 wxEVENT_HANDLER_CAST( wxWebKitStateChangedEventFunction, func )
200 #define wxWebKitBeforeLoadEventHandler( func ) \
201 wxEVENT_HANDLER_CAST( wxWebKitBeforeLoadEventFunction, func )
203 #define wxWebKitNewWindowEventHandler( func ) \
204 wxEVENT_HANDLER_CAST( wxWebKitNewWindowEventFunction, func )
206 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_WEBKIT_STATE_CHANGED
, wxWebKitStateChangedEvent
);
207 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_WEBKIT_BEFORE_LOAD
, wxWebKitBeforeLoadEvent
);
208 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_WEBKIT_NEW_WINDOW
, wxWebKitNewWindowEvent
);
210 #define EVT_WEBKIT_STATE_CHANGED(func) \
211 DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_STATE_CHANGED, \
214 wxWebKitStateChangedEventHandler( func ), \
217 #define EVT_WEBKIT_BEFORE_LOAD(func) \
218 DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_BEFORE_LOAD, \
221 wxWebKitBeforeLoadEventHandler( func ), \
224 #define EVT_WEBKIT_NEW_WINDOW(func) \
225 DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_NEW_WINDOW, \
228 wxWebKitNewWindowEventFunction( func ), \
230 #endif // wxUSE_WEBKIT