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 // RCS-ID:      $Id: webkit.h 53798 2008-05-28 06:12:34Z RD $
8 // Copyright:   (c) Jethro Grassie / Kevin Ollivier
9 // Licence:     wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11 
12 #ifndef _WX_WEBKIT_H
13 #define _WX_WEBKIT_H
14 
15 #if wxUSE_WEBKIT
16 
17 #if !defined(__WXMAC__) && !defined(__WXCOCOA__)
18 #error "wxWebKitCtrl not implemented for this platform"
19 #endif
20 
21 #include "wx/control.h"
22 
23 // ----------------------------------------------------------------------------
24 // Web Kit Control
25 // ----------------------------------------------------------------------------
26 
27 class wxWebKitCtrl : public wxControl
28 {
29 public:
DECLARE_DYNAMIC_CLASS(wxWebKitCtrl)30     DECLARE_DYNAMIC_CLASS(wxWebKitCtrl)
31 
32     wxWebKitCtrl() {};
33     wxWebKitCtrl(wxWindow *parent,
34                     wxWindowID winID,
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"))
40     {
41         Create(parent, winID, strURL, pos, size, style, validator, name);
42     };
43     bool Create(wxWindow *parent,
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,
49                 const wxString& name = wxT("webkitctrl"));
50     virtual ~wxWebKitCtrl();
51 
52     void LoadURL(const wxString &url);
53 
54     bool CanGoBack();
55     bool CanGoForward();
56     bool GoBack();
57     bool GoForward();
58     void Reload();
59     void Stop();
60     bool CanGetPageSource();
61     wxString GetPageSource();
62     void SetPageSource(const wxString& source, const wxString& baseUrl = wxEmptyString);
GetPageURL()63 	wxString GetPageURL(){ return m_currentURL; }
SetPageTitle(const wxString & title)64     void SetPageTitle(const wxString& title) { m_pageTitle = title; }
GetPageTitle()65 	wxString GetPageTitle(){ return m_pageTitle; }
66 
67     // since these worked in 2.6, add wrappers
SetTitle(const wxString & title)68     void SetTitle(const wxString& title) { SetPageTitle(title); }
GetTitle()69     wxString GetTitle() { return GetPageTitle(); }
70 
71     wxString GetSelection();
72 
73     bool CanIncreaseTextSize();
74     void IncreaseTextSize();
75     bool CanDecreaseTextSize();
76     void DecreaseTextSize();
77 
78     void Print(bool showPrompt=FALSE);
79 
80     void MakeEditable(bool enable=TRUE);
81     bool IsEditable();
82 
83     wxString RunScript(const wxString& javascript);
84 
85     void SetScrollPos(int pos);
86     int GetScrollPos();
87 
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);
92 protected:
93     DECLARE_EVENT_TABLE()
94     void MacVisibilityChanged();
95 
96 private:
97     wxWindow *m_parent;
98     wxWindowID m_windowID;
99     wxString m_currentURL;
100     wxString m_pageTitle;
101 
102     struct objc_object *m_webView;
103 
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.
109 };
110 
111 // ----------------------------------------------------------------------------
112 // Web Kit Events
113 // ----------------------------------------------------------------------------
114 
115 enum {
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
122 };
123 
124 enum {
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
131 
132 };
133 
134 
135 
136 class wxWebKitBeforeLoadEvent : public wxCommandEvent
137 {
DECLARE_DYNAMIC_CLASS(wxWebKitBeforeLoadEvent)138     DECLARE_DYNAMIC_CLASS( wxWebKitBeforeLoadEvent )
139 
140 public:
141     bool IsCancelled() { return m_cancelled; }
142     void Cancel(bool cancel = true) { m_cancelled = cancel; }
GetURL()143     wxString GetURL() { return m_url; }
SetURL(const wxString & url)144     void SetURL(const wxString& url) { m_url = url; }
SetNavigationType(int navType)145     void SetNavigationType(int navType) { m_navType = navType; }
GetNavigationType()146     int GetNavigationType() { return m_navType; }
147 
148     wxWebKitBeforeLoadEvent( wxWindow* win = (wxWindow*) NULL );
Clone(void)149     wxEvent *Clone(void) const { return new wxWebKitBeforeLoadEvent(*this); }
150 
151 protected:
152     bool m_cancelled;
153     wxString m_url;
154     int m_navType;
155 };
156 
157 class wxWebKitStateChangedEvent : public wxCommandEvent
158 {
DECLARE_DYNAMIC_CLASS(wxWebKitStateChangedEvent)159     DECLARE_DYNAMIC_CLASS( wxWebKitStateChangedEvent )
160 
161 public:
162     int GetState() { return m_state; }
SetState(const int state)163     void SetState(const int state) { m_state = state; }
GetURL()164     wxString GetURL() { return m_url; }
SetURL(const wxString & url)165     void SetURL(const wxString& url) { m_url = url; }
166 
167     wxWebKitStateChangedEvent( wxWindow* win = (wxWindow*) NULL );
Clone(void)168     wxEvent *Clone(void) const { return new wxWebKitStateChangedEvent(*this); }
169 
170 protected:
171     int m_state;
172     wxString m_url;
173 };
174 
175 
176 #if wxABI_VERSION >= 20808
177 class wxWebKitNewWindowEvent : public wxCommandEvent
178 {
DECLARE_DYNAMIC_CLASS(wxWebViewNewWindowEvent)179     DECLARE_DYNAMIC_CLASS( wxWebViewNewWindowEvent )
180 public:
181     wxString GetURL() const { return m_url; }
SetURL(const wxString & url)182     void SetURL(const wxString& url) { m_url = url; }
GetTargetName()183     wxString GetTargetName() const { return m_targetName; }
SetTargetName(const wxString & name)184     void SetTargetName(const wxString& name) { m_targetName = name; }
185 
186     wxWebKitNewWindowEvent( wxWindow* win = (wxWindow*)(NULL));
Clone(void)187     wxEvent *Clone(void) const { return new wxWebKitNewWindowEvent(*this); }
188 
189 private:
190     wxString m_url;
191     wxString m_targetName;
192 };
193 #endif
194 
195 typedef void (wxEvtHandler::*wxWebKitStateChangedEventFunction)(wxWebKitStateChangedEvent&);
196 typedef void (wxEvtHandler::*wxWebKitBeforeLoadEventFunction)(wxWebKitBeforeLoadEvent&);
197 typedef void (wxEvtHandler::*wxWebKitNewWindowEventFunction)(wxWebKitNewWindowEvent&);
198 
199 BEGIN_DECLARE_EVENT_TYPES()
200     DECLARE_LOCAL_EVENT_TYPE(wxEVT_WEBKIT_BEFORE_LOAD, wxID_ANY)
201     DECLARE_LOCAL_EVENT_TYPE(wxEVT_WEBKIT_STATE_CHANGED, wxID_ANY)
202     DECLARE_LOCAL_EVENT_TYPE(wxEVT_WEBKIT_NEW_WINDOW, wxID_ANY)
203 END_DECLARE_EVENT_TYPES()
204 
205 #define EVT_WEBKIT_STATE_CHANGED(func) \
206             DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_STATE_CHANGED, \
207                             wxID_ANY, \
208                             wxID_ANY, \
209                             (wxObjectEventFunction)   \
210                             (wxWebKitStateChangedEventFunction) & func, \
211                             (wxObject *) NULL ),
212 
213 #define EVT_WEBKIT_BEFORE_LOAD(func) \
214             DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_BEFORE_LOAD, \
215                             wxID_ANY, \
216                             wxID_ANY, \
217                             (wxObjectEventFunction)   \
218                             (wxWebKitBeforeLoadEventFunction) & func, \
219                             (wxObject *) NULL ),
220 
221 #define EVT_WEBKIT_NEW_WINDOW(func)                              \
222             DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_NEW_WINDOW, \
223                             wxID_ANY, \
224                             wxID_ANY, \
225                             (wxObjectEventFunction)   \
226                             (wxWebKitNewWindowEventFunction) & func, \
227                             (wxObject *) NULL ),
228 #endif // wxUSE_WEBKIT
229 
230 #endif
231     // _WX_WEBKIT_H_
232