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