]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/webview_webkit.h
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / include / wx / osx / webview_webkit.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/osx/webkit.h
3 // Purpose: wxWebViewWebKit - embeddable web kit control,
4 // OS X implementation of web view component
5 // Author: Jethro Grassie / Kevin Ollivier / Marianne Gagnon
6 // Modified by:
7 // Created: 2004-4-16
8 // Copyright: (c) Jethro Grassie / Kevin Ollivier / Marianne Gagnon
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WEBKIT_H
13 #define _WX_WEBKIT_H
14
15 #include "wx/setup.h"
16
17 #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && (defined(__WXOSX_COCOA__) \
18 || defined(__WXOSX_CARBON__))
19
20 #include "wx/control.h"
21 #include "wx/webview.h"
22
23 #include "wx/osx/core/objcid.h"
24
25 // ----------------------------------------------------------------------------
26 // Web Kit Control
27 // ----------------------------------------------------------------------------
28
29 class WXDLLIMPEXP_WEBVIEW wxWebViewWebKit : public wxWebView
30 {
31 public:
32 wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit);
33
34 wxWebViewWebKit() {}
35 wxWebViewWebKit(wxWindow *parent,
36 wxWindowID winID = wxID_ANY,
37 const wxString& strURL = wxWebViewDefaultURLStr,
38 const wxPoint& pos = wxDefaultPosition,
39 const wxSize& size = wxDefaultSize, long style = 0,
40 const wxString& name = wxWebViewNameStr)
41 {
42 Create(parent, winID, strURL, pos, size, style, name);
43 }
44 bool Create(wxWindow *parent,
45 wxWindowID winID = wxID_ANY,
46 const wxString& strURL = wxWebViewDefaultURLStr,
47 const wxPoint& pos = wxDefaultPosition,
48 const wxSize& size = wxDefaultSize, long style = 0,
49 const wxString& name = wxWebViewNameStr);
50 virtual ~wxWebViewWebKit();
51
52 virtual bool CanGoBack() const;
53 virtual bool CanGoForward() const;
54 virtual void GoBack();
55 virtual void GoForward();
56 virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT);
57 virtual void Stop();
58 virtual wxString GetPageSource() const;
59 virtual wxString GetPageText() const;
60
61 virtual void Print();
62
63 virtual void LoadURL(const wxString& url);
64 virtual wxString GetCurrentURL() const;
65 virtual wxString GetCurrentTitle() const;
66 virtual wxWebViewZoom GetZoom() const;
67 virtual void SetZoom(wxWebViewZoom zoom);
68
69 virtual void SetZoomType(wxWebViewZoomType zoomType);
70 virtual wxWebViewZoomType GetZoomType() const;
71 virtual bool CanSetZoomType(wxWebViewZoomType type) const;
72
73 virtual bool IsBusy() const { return m_busy; }
74
75 //History functions
76 virtual void ClearHistory();
77 virtual void EnableHistory(bool enable = true);
78 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory();
79 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory();
80 virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item);
81
82 //Undo / redo functionality
83 virtual bool CanUndo() const;
84 virtual bool CanRedo() const;
85 virtual void Undo();
86 virtual void Redo();
87
88 //Find function
89 virtual long Find(const wxString& text, int flags = wxWEBVIEW_FIND_DEFAULT)
90 {
91 wxUnusedVar(text);
92 wxUnusedVar(flags);
93 return wxNOT_FOUND;
94 }
95
96 //Clipboard functions
97 virtual bool CanCut() const { return true; }
98 virtual bool CanCopy() const { return true; }
99 virtual bool CanPaste() const { return true; }
100 virtual void Cut();
101 virtual void Copy();
102 virtual void Paste();
103
104 //Editing functions
105 virtual void SetEditable(bool enable = true);
106 virtual bool IsEditable() const;
107
108 //Selection
109 virtual void DeleteSelection();
110 virtual bool HasSelection() const;
111 virtual void SelectAll();
112 virtual wxString GetSelectedText() const;
113 virtual wxString GetSelectedSource() const;
114 virtual void ClearSelection();
115
116 void RunScript(const wxString& javascript);
117
118 //Virtual Filesystem Support
119 virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler);
120
121 virtual void* GetNativeBackend() const { return m_webView; }
122
123 // ---- methods not from the parent (common) interface
124 bool CanGetPageSource() const;
125
126 void SetScrollPos(int pos);
127 int GetScrollPos();
128
129 bool CanIncreaseTextSize() const;
130 void IncreaseTextSize();
131 bool CanDecreaseTextSize() const;
132 void DecreaseTextSize();
133
134 float GetWebkitZoom() const;
135 void SetWebkitZoom(float zoom);
136
137 // don't hide base class virtuals
138 virtual void SetScrollPos( int orient, int pos, bool refresh = true )
139 { return wxControl::SetScrollPos(orient, pos, refresh); }
140 virtual int GetScrollPos( int orient ) const
141 { return wxControl::GetScrollPos(orient); }
142
143 //we need to resize the webview when the control size changes
144 void OnSize(wxSizeEvent &event);
145 void OnMove(wxMoveEvent &event);
146 void OnMouseEvents(wxMouseEvent &event);
147
148 bool m_busy;
149
150 protected:
151 virtual void DoSetPage(const wxString& html, const wxString& baseUrl);
152
153 DECLARE_EVENT_TABLE()
154 void MacVisibilityChanged();
155
156 private:
157 wxWindow *m_parent;
158 wxWindowID m_windowID;
159 wxString m_pageTitle;
160
161 wxObjCID m_webView;
162
163 // we may use this later to setup our own mouse events,
164 // so leave it in for now.
165 void* m_webKitCtrlEventHandler;
166 //It should be WebView*, but WebView is an Objective-C class
167 //TODO: look into using DECLARE_WXCOCOA_OBJC_CLASS rather than this.
168 };
169
170 class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryWebKit : public wxWebViewFactory
171 {
172 public:
173 virtual wxWebView* Create() { return new wxWebViewWebKit; }
174 virtual wxWebView* Create(wxWindow* parent,
175 wxWindowID id,
176 const wxString& url = wxWebViewDefaultURLStr,
177 const wxPoint& pos = wxDefaultPosition,
178 const wxSize& size = wxDefaultSize,
179 long style = 0,
180 const wxString& name = wxWebViewNameStr)
181 { return new wxWebViewWebKit(parent, id, url, pos, size, style, name); }
182 };
183
184 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT
185
186 #endif // _WX_WEBKIT_H_