]>
Commit | Line | Data |
---|---|---|
2c990ba6 KO |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: 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$ | |
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 | ||
21 | #ifdef __WXCOCOA | |
22 | #include <WebKit/WebKit.h> | |
23 | #endif | |
24 | #include "wx/control.h" | |
25 | ||
26 | // ---------------------------------------------------------------------------- | |
27 | // Web Kit Control | |
28 | // ---------------------------------------------------------------------------- | |
29 | ||
30 | class wxWebKitCtrl : public wxControl | |
31 | { | |
32 | public: | |
3ca7ba74 | 33 | DECLARE_DYNAMIC_CLASS(wxWebKitCtrl) |
2c990ba6 | 34 | |
3ca7ba74 | 35 | wxWebKitCtrl() {}; |
2c990ba6 | 36 | wxWebKitCtrl(wxWindow *parent, |
3ca7ba74 | 37 | wxWindowID winID, |
2c990ba6 KO |
38 | const wxString& strURL, |
39 | const wxPoint& pos = wxDefaultPosition, | |
3ca7ba74 RD |
40 | const wxSize& size = wxDefaultSize, long style = 0, |
41 | const wxValidator& validator = wxDefaultValidator, | |
42 | const wxString& name = wxT("webkitctrl")) | |
2c990ba6 KO |
43 | { |
44 | Create(parent, winID, strURL, pos, size, style, validator, name); | |
45 | }; | |
3ca7ba74 | 46 | bool Create(wxWindow *parent, |
2c990ba6 KO |
47 | wxWindowID winID, |
48 | const wxString& strURL, | |
49 | const wxPoint& pos = wxDefaultPosition, | |
50 | const wxSize& size = wxDefaultSize, long style = 0, | |
51 | const wxValidator& validator = wxDefaultValidator, | |
7eb8c6ee | 52 | const wxString& name = wxT("webkitctrl")); |
3ca7ba74 | 53 | virtual ~wxWebKitCtrl(); |
6953da00 | 54 | |
2c990ba6 | 55 | void LoadURL(const wxString &url); |
6953da00 | 56 | |
2c990ba6 KO |
57 | bool CanGoBack(); |
58 | bool CanGoForward(); | |
59 | bool GoBack(); | |
60 | bool GoForward(); | |
6953da00 | 61 | void Reload(); |
2c990ba6 KO |
62 | void Stop(); |
63 | bool CanGetPageSource(); | |
64 | wxString GetPageSource(); | |
7eb8c6ee | 65 | void SetPageSource(wxString& source, const wxString& baseUrl = wxEmptyString); |
b4fd164d KO |
66 | wxString GetPageURL(){ return m_currentURL; } |
67 | wxString GetPageTitle(){ return m_pageTitle; } | |
8f3b30d5 | 68 | |
2c990ba6 | 69 | //we need to resize the webview when the control size changes |
005198fa | 70 | void OnSize(wxSizeEvent &event); |
2c990ba6 | 71 | protected: |
3ca7ba74 | 72 | DECLARE_EVENT_TABLE() |
14f21d6d | 73 | void MacVisibilityChanged(); |
2c990ba6 KO |
74 | |
75 | private: | |
76 | wxWindow *m_parent; | |
77 | wxWindowID m_windowID; | |
78 | wxString m_currentURL; | |
79 | wxString m_pageTitle; | |
696e9331 DE |
80 | struct objc_object *m_webView; |
81 | //It should be WebView*, but WebView is an Objective-C class | |
82 | //TODO: look into using DECLARE_WXCOCOA_OBJC_CLASS rather than this. | |
2c990ba6 KO |
83 | }; |
84 | ||
85 | // ---------------------------------------------------------------------------- | |
86 | // Web Kit Events | |
87 | // ---------------------------------------------------------------------------- | |
88 | ||
89 | enum { | |
3ca7ba74 RD |
90 | wxWEBKIT_STATE_START = 1, |
91 | wxWEBKIT_STATE_NEGOTIATING = 2, | |
92 | wxWEBKIT_STATE_REDIRECTING = 4, | |
93 | wxWEBKIT_STATE_TRANSFERRING = 8, | |
94 | wxWEBKIT_STATE_STOP = 16, | |
2c990ba6 KO |
95 | wxWEBKIT_STATE_FAILED = 32 |
96 | }; | |
97 | ||
98 | class wxWebKitStateChangedEvent : public wxCommandEvent | |
99 | { | |
100 | DECLARE_DYNAMIC_CLASS( wxWebKitStateChangedEvent ) | |
101 | ||
102 | public: | |
3ca7ba74 RD |
103 | int GetState() { return m_state; } |
104 | void SetState(const int state) { m_state = state; } | |
105 | wxString GetURL() { return m_url; } | |
106 | void SetURL(const wxString& url) { m_url = url; } | |
2c990ba6 KO |
107 | |
108 | wxWebKitStateChangedEvent( wxWindow* win = (wxWindow*) NULL ); | |
3ca7ba74 | 109 | wxEvent *Clone(void) const { return new wxWebKitStateChangedEvent(*this); } |
2c990ba6 KO |
110 | |
111 | protected: | |
3ca7ba74 RD |
112 | int m_state; |
113 | wxString m_url; | |
2c990ba6 KO |
114 | }; |
115 | ||
116 | typedef void (wxEvtHandler::*wxWebKitStateChangedEventFunction)(wxWebKitStateChangedEvent&); | |
117 | ||
118 | BEGIN_DECLARE_EVENT_TYPES() | |
6953da00 | 119 | DECLARE_LOCAL_EVENT_TYPE(wxEVT_WEBKIT_STATE_CHANGED, wxID_ANY) |
2c990ba6 KO |
120 | END_DECLARE_EVENT_TYPES() |
121 | ||
122 | #define EVT_WEBKIT_STATE_CHANGED(func) \ | |
123 | DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_STATE_CHANGED, \ | |
6953da00 WS |
124 | wxID_ANY, \ |
125 | wxID_ANY, \ | |
2c990ba6 KO |
126 | (wxObjectEventFunction) \ |
127 | (wxWebKitStateChangedEventFunction) & func, \ | |
128 | (wxObject *) NULL ), | |
129 | ||
5b8f917c KO |
130 | #endif // wxUSE_WEBKIT |
131 | ||
2c990ba6 | 132 | #endif // _WX_WEBKIT_H_ |