]>
Commit | Line | Data |
---|---|---|
2c990ba6 | 1 | ///////////////////////////////////////////////////////////////////////////// |
1b88201f | 2 | // Name: wx/html/webkit.h |
2c990ba6 KO |
3 | // Purpose: wxWebKitCtrl - embeddable web kit control |
4 | // Author: Jethro Grassie / Kevin Ollivier | |
5 | // Modified by: | |
6 | // Created: 2004-4-16 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Jethro Grassie / Kevin Ollivier | |
65571936 | 9 | // Licence: wxWindows licence |
2c990ba6 KO |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_WEBKIT_H | |
13 | #define _WX_WEBKIT_H | |
14 | ||
5b8f917c KO |
15 | #if wxUSE_WEBKIT |
16 | ||
2c990ba6 KO |
17 | #if !defined(__WXMAC__) && !defined(__WXCOCOA__) |
18 | #error "wxWebKitCtrl not implemented for this platform" | |
19 | #endif | |
20 | ||
2c990ba6 KO |
21 | #include "wx/control.h" |
22 | ||
23 | // ---------------------------------------------------------------------------- | |
24 | // Web Kit Control | |
25 | // ---------------------------------------------------------------------------- | |
26 | ||
29391f32 | 27 | class WXDLLIMPEXP_CORE wxWebKitCtrl : public wxControl |
2c990ba6 KO |
28 | { |
29 | public: | |
3ca7ba74 | 30 | DECLARE_DYNAMIC_CLASS(wxWebKitCtrl) |
2c990ba6 | 31 | |
3ca7ba74 | 32 | wxWebKitCtrl() {}; |
2c990ba6 | 33 | wxWebKitCtrl(wxWindow *parent, |
3ca7ba74 | 34 | wxWindowID winID, |
2c990ba6 KO |
35 | const wxString& strURL, |
36 | const wxPoint& pos = wxDefaultPosition, | |
3ca7ba74 RD |
37 | const wxSize& size = wxDefaultSize, long style = 0, |
38 | const wxValidator& validator = wxDefaultValidator, | |
39 | const wxString& name = wxT("webkitctrl")) | |
2c990ba6 KO |
40 | { |
41 | Create(parent, winID, strURL, pos, size, style, validator, name); | |
42 | }; | |
3ca7ba74 | 43 | bool Create(wxWindow *parent, |
2c990ba6 KO |
44 | wxWindowID winID, |
45 | const wxString& strURL, | |
46 | const wxPoint& pos = wxDefaultPosition, | |
47 | const wxSize& size = wxDefaultSize, long style = 0, | |
48 | const wxValidator& validator = wxDefaultValidator, | |
7eb8c6ee | 49 | const wxString& name = wxT("webkitctrl")); |
3ca7ba74 | 50 | virtual ~wxWebKitCtrl(); |
6953da00 | 51 | |
2c990ba6 | 52 | void LoadURL(const wxString &url); |
6953da00 | 53 | |
2c990ba6 KO |
54 | bool CanGoBack(); |
55 | bool CanGoForward(); | |
56 | bool GoBack(); | |
57 | bool GoForward(); | |
6953da00 | 58 | void Reload(); |
2c990ba6 KO |
59 | void Stop(); |
60 | bool CanGetPageSource(); | |
61 | wxString GetPageSource(); | |
448f8f12 | 62 | void SetPageSource(const wxString& source, const wxString& baseUrl = wxEmptyString); |
2c6dbc21 | 63 | wxString GetPageURL(){ return m_currentURL; } |
448f8f12 | 64 | void SetPageTitle(const wxString& title) { m_pageTitle = title; } |
2c6dbc21 | 65 | wxString GetPageTitle(){ return m_pageTitle; } |
c058cafa | 66 | |
448f8f12 KO |
67 | // since these worked in 2.6, add wrappers |
68 | void SetTitle(const wxString& title) { SetPageTitle(title); } | |
69 | wxString GetTitle() { return GetPageTitle(); } | |
c058cafa | 70 | |
448f8f12 | 71 | wxString GetSelection(); |
c058cafa | 72 | |
448f8f12 KO |
73 | bool CanIncreaseTextSize(); |
74 | void IncreaseTextSize(); | |
75 | bool CanDecreaseTextSize(); | |
76 | void DecreaseTextSize(); | |
c058cafa | 77 | |
8e6efd1f | 78 | void Print(bool showPrompt = false); |
c058cafa | 79 | |
8e6efd1f | 80 | void MakeEditable(bool enable = true); |
448f8f12 | 81 | bool IsEditable(); |
c058cafa | 82 | |
448f8f12 | 83 | wxString RunScript(const wxString& javascript); |
c058cafa | 84 | |
448f8f12 KO |
85 | void SetScrollPos(int pos); |
86 | int GetScrollPos(); | |
8f3b30d5 | 87 | |
8a28bf76 VZ |
88 | // don't hide base class virtuals |
89 | virtual void SetScrollPos( int orient, int pos, bool refresh = true ) | |
90 | { return wxControl::SetScrollPos(orient, pos, refresh); } | |
91 | virtual int GetScrollPos( int orient ) const | |
92 | { return wxControl::GetScrollPos(orient); } | |
93 | ||
2c990ba6 | 94 | //we need to resize the webview when the control size changes |
005198fa | 95 | void OnSize(wxSizeEvent &event); |
448f8f12 KO |
96 | void OnMove(wxMoveEvent &event); |
97 | void OnMouseEvents(wxMouseEvent &event); | |
2c990ba6 | 98 | protected: |
3ca7ba74 | 99 | DECLARE_EVENT_TABLE() |
14f21d6d | 100 | void MacVisibilityChanged(); |
2c990ba6 KO |
101 | |
102 | private: | |
103 | wxWindow *m_parent; | |
104 | wxWindowID m_windowID; | |
105 | wxString m_currentURL; | |
106 | wxString m_pageTitle; | |
c058cafa | 107 | |
696e9331 | 108 | struct objc_object *m_webView; |
c058cafa | 109 | |
448f8f12 KO |
110 | // we may use this later to setup our own mouse events, |
111 | // so leave it in for now. | |
112 | void* m_webKitCtrlEventHandler; | |
696e9331 DE |
113 | //It should be WebView*, but WebView is an Objective-C class |
114 | //TODO: look into using DECLARE_WXCOCOA_OBJC_CLASS rather than this. | |
2c990ba6 KO |
115 | }; |
116 | ||
117 | // ---------------------------------------------------------------------------- | |
118 | // Web Kit Events | |
119 | // ---------------------------------------------------------------------------- | |
120 | ||
121 | enum { | |
3ca7ba74 RD |
122 | wxWEBKIT_STATE_START = 1, |
123 | wxWEBKIT_STATE_NEGOTIATING = 2, | |
124 | wxWEBKIT_STATE_REDIRECTING = 4, | |
125 | wxWEBKIT_STATE_TRANSFERRING = 8, | |
126 | wxWEBKIT_STATE_STOP = 16, | |
2c990ba6 KO |
127 | wxWEBKIT_STATE_FAILED = 32 |
128 | }; | |
129 | ||
448f8f12 KO |
130 | enum { |
131 | wxWEBKIT_NAV_LINK_CLICKED = 1, | |
132 | wxWEBKIT_NAV_BACK_NEXT = 2, | |
133 | wxWEBKIT_NAV_FORM_SUBMITTED = 4, | |
134 | wxWEBKIT_NAV_RELOAD = 8, | |
135 | wxWEBKIT_NAV_FORM_RESUBMITTED = 16, | |
136 | wxWEBKIT_NAV_OTHER = 32 | |
137 | ||
138 | }; | |
139 | ||
140 | ||
141 | ||
29391f32 | 142 | class WXDLLIMPEXP_CORE wxWebKitBeforeLoadEvent : public wxCommandEvent |
448f8f12 KO |
143 | { |
144 | DECLARE_DYNAMIC_CLASS( wxWebKitBeforeLoadEvent ) | |
c058cafa | 145 | |
448f8f12 KO |
146 | public: |
147 | bool IsCancelled() { return m_cancelled; } | |
148 | void Cancel(bool cancel = true) { m_cancelled = cancel; } | |
149 | wxString GetURL() { return m_url; } | |
150 | void SetURL(const wxString& url) { m_url = url; } | |
151 | void SetNavigationType(int navType) { m_navType = navType; } | |
152 | int GetNavigationType() { return m_navType; } | |
153 | ||
d3b9f782 | 154 | wxWebKitBeforeLoadEvent( wxWindow* win = NULL ); |
448f8f12 KO |
155 | wxEvent *Clone(void) const { return new wxWebKitBeforeLoadEvent(*this); } |
156 | ||
157 | protected: | |
158 | bool m_cancelled; | |
159 | wxString m_url; | |
160 | int m_navType; | |
161 | }; | |
162 | ||
29391f32 | 163 | class WXDLLIMPEXP_CORE wxWebKitStateChangedEvent : public wxCommandEvent |
2c990ba6 KO |
164 | { |
165 | DECLARE_DYNAMIC_CLASS( wxWebKitStateChangedEvent ) | |
166 | ||
167 | public: | |
3ca7ba74 RD |
168 | int GetState() { return m_state; } |
169 | void SetState(const int state) { m_state = state; } | |
170 | wxString GetURL() { return m_url; } | |
171 | void SetURL(const wxString& url) { m_url = url; } | |
2c990ba6 | 172 | |
d3b9f782 | 173 | wxWebKitStateChangedEvent( wxWindow* win = NULL ); |
3ca7ba74 | 174 | wxEvent *Clone(void) const { return new wxWebKitStateChangedEvent(*this); } |
2c990ba6 KO |
175 | |
176 | protected: | |
3ca7ba74 RD |
177 | int m_state; |
178 | wxString m_url; | |
2c990ba6 KO |
179 | }; |
180 | ||
fa34bc53 | 181 | |
29391f32 | 182 | class WXDLLIMPEXP_CORE wxWebKitNewWindowEvent : public wxCommandEvent |
fa34bc53 RD |
183 | { |
184 | DECLARE_DYNAMIC_CLASS( wxWebViewNewWindowEvent ) | |
185 | public: | |
186 | wxString GetURL() const { return m_url; } | |
187 | void SetURL(const wxString& url) { m_url = url; } | |
188 | wxString GetTargetName() const { return m_targetName; } | |
189 | void SetTargetName(const wxString& name) { m_targetName = name; } | |
190 | ||
191 | wxWebKitNewWindowEvent( wxWindow* win = (wxWindow*)(NULL)); | |
192 | wxEvent *Clone(void) const { return new wxWebKitNewWindowEvent(*this); } | |
193 | ||
194 | private: | |
195 | wxString m_url; | |
196 | wxString m_targetName; | |
197 | }; | |
198 | ||
2c990ba6 | 199 | typedef void (wxEvtHandler::*wxWebKitStateChangedEventFunction)(wxWebKitStateChangedEvent&); |
448f8f12 | 200 | typedef void (wxEvtHandler::*wxWebKitBeforeLoadEventFunction)(wxWebKitBeforeLoadEvent&); |
fa34bc53 | 201 | typedef void (wxEvtHandler::*wxWebKitNewWindowEventFunction)(wxWebKitNewWindowEvent&); |
2c990ba6 | 202 | |
3c778901 VZ |
203 | #define wxWebKitStateChangedEventHandler( func ) \ |
204 | wxEVENT_HANDLER_CAST( wxWebKitStateChangedEventFunction, func ) | |
205 | ||
206 | #define wxWebKitBeforeLoadEventHandler( func ) \ | |
207 | wxEVENT_HANDLER_CAST( wxWebKitBeforeLoadEventFunction, func ) | |
208 | ||
209 | #define wxWebKitNewWindowEventHandler( func ) \ | |
210 | wxEVENT_HANDLER_CAST( wxWebKitNewWindowEventFunction, func ) | |
211 | ||
9b11752c VZ |
212 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_WEBKIT_STATE_CHANGED, wxWebKitStateChangedEvent ); |
213 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_WEBKIT_BEFORE_LOAD, wxWebKitBeforeLoadEvent ); | |
214 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_WEBKIT_NEW_WINDOW, wxWebKitNewWindowEvent ); | |
2c990ba6 KO |
215 | |
216 | #define EVT_WEBKIT_STATE_CHANGED(func) \ | |
217 | DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_STATE_CHANGED, \ | |
6953da00 WS |
218 | wxID_ANY, \ |
219 | wxID_ANY, \ | |
3c778901 | 220 | wxWebKitStateChangedEventHandler( func ), \ |
d3b9f782 | 221 | NULL ), |
c058cafa | 222 | |
448f8f12 KO |
223 | #define EVT_WEBKIT_BEFORE_LOAD(func) \ |
224 | DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_BEFORE_LOAD, \ | |
225 | wxID_ANY, \ | |
226 | wxID_ANY, \ | |
3c778901 | 227 | wxWebKitBeforeLoadEventHandler( func ), \ |
d3b9f782 | 228 | NULL ), |
2c990ba6 | 229 | |
fa34bc53 RD |
230 | #define EVT_WEBKIT_NEW_WINDOW(func) \ |
231 | DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_NEW_WINDOW, \ | |
232 | wxID_ANY, \ | |
233 | wxID_ANY, \ | |
3c778901 | 234 | wxWebKitNewWindowEventFunction( func ), \ |
d3b9f782 | 235 | NULL ), |
5b8f917c KO |
236 | #endif // wxUSE_WEBKIT |
237 | ||
1b88201f WS |
238 | #endif |
239 | // _WX_WEBKIT_H_ |