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 extern WXDLLIMPEXP_DATA_CORE(const char) wxWebKitCtrlNameStr
[];
29 class WXDLLIMPEXP_CORE wxWebKitCtrl
: public wxControl
32 DECLARE_DYNAMIC_CLASS(wxWebKitCtrl
)
35 wxWebKitCtrl(wxWindow
*parent
,
37 const wxString
& strURL
,
38 const wxPoint
& pos
= wxDefaultPosition
,
39 const wxSize
& size
= wxDefaultSize
, long style
= 0,
40 const wxValidator
& validator
= wxDefaultValidator
,
41 const wxString
& name
= wxWebKitCtrlNameStr
)
43 Create(parent
, winID
, strURL
, pos
, size
, style
, validator
, name
);
45 bool Create(wxWindow
*parent
,
47 const wxString
& strURL
,
48 const wxPoint
& pos
= wxDefaultPosition
,
49 const wxSize
& size
= wxDefaultSize
, long style
= 0,
50 const wxValidator
& validator
= wxDefaultValidator
,
51 const wxString
& name
= wxWebKitCtrlNameStr
);
52 virtual ~wxWebKitCtrl();
54 void LoadURL(const wxString
&url
);
62 bool CanGetPageSource();
63 wxString
GetPageSource();
64 void SetPageSource(const wxString
& source
, const wxString
& baseUrl
= wxEmptyString
);
65 wxString
GetPageURL(){ return m_currentURL
; }
66 void SetPageTitle(const wxString
& title
) { m_pageTitle
= title
; }
67 wxString
GetPageTitle(){ return m_pageTitle
; }
69 // since these worked in 2.6, add wrappers
70 void SetTitle(const wxString
& title
) { SetPageTitle(title
); }
71 wxString
GetTitle() { return GetPageTitle(); }
73 wxString
GetSelection();
75 bool CanIncreaseTextSize();
76 void IncreaseTextSize();
77 bool CanDecreaseTextSize();
78 void DecreaseTextSize();
80 void Print(bool showPrompt
= false);
82 void MakeEditable(bool enable
= true);
85 wxString
RunScript(const wxString
& javascript
);
87 void SetScrollPos(int pos
);
90 // don't hide base class virtuals
91 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= true )
92 { return wxControl::SetScrollPos(orient
, pos
, refresh
); }
93 virtual int GetScrollPos( int orient
) const
94 { return wxControl::GetScrollPos(orient
); }
96 //we need to resize the webview when the control size changes
97 void OnSize(wxSizeEvent
&event
);
98 void OnMove(wxMoveEvent
&event
);
99 void OnMouseEvents(wxMouseEvent
&event
);
101 DECLARE_EVENT_TABLE()
102 void MacVisibilityChanged();
106 wxWindowID m_windowID
;
107 wxString m_currentURL
;
108 wxString m_pageTitle
;
110 struct objc_object
*m_webView
;
112 // we may use this later to setup our own mouse events,
113 // so leave it in for now.
114 void* m_webKitCtrlEventHandler
;
115 //It should be WebView*, but WebView is an Objective-C class
116 //TODO: look into using DECLARE_WXCOCOA_OBJC_CLASS rather than this.
119 // ----------------------------------------------------------------------------
121 // ----------------------------------------------------------------------------
124 wxWEBKIT_STATE_START
= 1,
125 wxWEBKIT_STATE_NEGOTIATING
= 2,
126 wxWEBKIT_STATE_REDIRECTING
= 4,
127 wxWEBKIT_STATE_TRANSFERRING
= 8,
128 wxWEBKIT_STATE_STOP
= 16,
129 wxWEBKIT_STATE_FAILED
= 32
133 wxWEBKIT_NAV_LINK_CLICKED
= 1,
134 wxWEBKIT_NAV_BACK_NEXT
= 2,
135 wxWEBKIT_NAV_FORM_SUBMITTED
= 4,
136 wxWEBKIT_NAV_RELOAD
= 8,
137 wxWEBKIT_NAV_FORM_RESUBMITTED
= 16,
138 wxWEBKIT_NAV_OTHER
= 32
144 class WXDLLIMPEXP_CORE wxWebKitBeforeLoadEvent
: public wxCommandEvent
146 DECLARE_DYNAMIC_CLASS( wxWebKitBeforeLoadEvent
)
149 bool IsCancelled() { return m_cancelled
; }
150 void Cancel(bool cancel
= true) { m_cancelled
= cancel
; }
151 wxString
GetURL() { return m_url
; }
152 void SetURL(const wxString
& url
) { m_url
= url
; }
153 void SetNavigationType(int navType
) { m_navType
= navType
; }
154 int GetNavigationType() { return m_navType
; }
156 wxWebKitBeforeLoadEvent( wxWindow
* win
= NULL
);
157 wxEvent
*Clone(void) const { return new wxWebKitBeforeLoadEvent(*this); }
165 class WXDLLIMPEXP_CORE wxWebKitStateChangedEvent
: public wxCommandEvent
167 DECLARE_DYNAMIC_CLASS( wxWebKitStateChangedEvent
)
170 int GetState() { return m_state
; }
171 void SetState(const int state
) { m_state
= state
; }
172 wxString
GetURL() { return m_url
; }
173 void SetURL(const wxString
& url
) { m_url
= url
; }
175 wxWebKitStateChangedEvent( wxWindow
* win
= NULL
);
176 wxEvent
*Clone(void) const { return new wxWebKitStateChangedEvent(*this); }
184 class WXDLLIMPEXP_CORE wxWebKitNewWindowEvent
: public wxCommandEvent
186 DECLARE_DYNAMIC_CLASS( wxWebKitNewWindowEvent
)
188 wxString
GetURL() const { return m_url
; }
189 void SetURL(const wxString
& url
) { m_url
= url
; }
190 wxString
GetTargetName() const { return m_targetName
; }
191 void SetTargetName(const wxString
& name
) { m_targetName
= name
; }
193 wxWebKitNewWindowEvent( wxWindow
* win
= (wxWindow
*)(NULL
));
194 wxEvent
*Clone(void) const { return new wxWebKitNewWindowEvent(*this); }
198 wxString m_targetName
;
201 typedef void (wxEvtHandler::*wxWebKitStateChangedEventFunction
)(wxWebKitStateChangedEvent
&);
202 typedef void (wxEvtHandler::*wxWebKitBeforeLoadEventFunction
)(wxWebKitBeforeLoadEvent
&);
203 typedef void (wxEvtHandler::*wxWebKitNewWindowEventFunction
)(wxWebKitNewWindowEvent
&);
205 #define wxWebKitStateChangedEventHandler( func ) \
206 wxEVENT_HANDLER_CAST( wxWebKitStateChangedEventFunction, func )
208 #define wxWebKitBeforeLoadEventHandler( func ) \
209 wxEVENT_HANDLER_CAST( wxWebKitBeforeLoadEventFunction, func )
211 #define wxWebKitNewWindowEventHandler( func ) \
212 wxEVENT_HANDLER_CAST( wxWebKitNewWindowEventFunction, func )
214 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_WEBKIT_STATE_CHANGED
, wxWebKitStateChangedEvent
);
215 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_WEBKIT_BEFORE_LOAD
, wxWebKitBeforeLoadEvent
);
216 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_WEBKIT_NEW_WINDOW
, wxWebKitNewWindowEvent
);
218 #define EVT_WEBKIT_STATE_CHANGED(func) \
219 wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_STATE_CHANGED, \
222 wxWebKitStateChangedEventHandler( func ), \
225 #define EVT_WEBKIT_BEFORE_LOAD(func) \
226 wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_BEFORE_LOAD, \
229 wxWebKitBeforeLoadEventHandler( func ), \
232 #define EVT_WEBKIT_NEW_WINDOW(func) \
233 wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_NEW_WINDOW, \
236 wxWebKitNewWindowEventFunction( func ), \
238 #endif // wxUSE_WEBKIT