Fix crash on wxWebViewWebKit window destruction.
[wxWidgets.git] / include / wx / gtk / webview_webkit.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/gtk/wx/webview.h
3 // Purpose: GTK webkit backend for web view component
4 // Author: Robert Roebling, Marianne Gagnon
5 // Id: $Id$
6 // Copyright: (c) 2010 Marianne Gagnon, 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_GTK_WEBKITCTRL_H_
11 #define _WX_GTK_WEBKITCTRL_H_
12
13 #include "wx/setup.h"
14
15 #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && defined(__WXGTK__)
16
17 #include "wx/sharedptr.h"
18 #include "wx/webview.h"
19
20 typedef struct _WebKitWebView WebKitWebView;
21
22 //-----------------------------------------------------------------------------
23 // wxWebViewWebKit
24 //-----------------------------------------------------------------------------
25
26 class WXDLLIMPEXP_WEBVIEW wxWebViewWebKit : public wxWebView
27 {
28 public:
29 wxWebViewWebKit() { Init(); }
30
31 wxWebViewWebKit(wxWindow *parent,
32 wxWindowID id = wxID_ANY,
33 const wxString& url = wxWebViewDefaultURLStr,
34 const wxPoint& pos = wxDefaultPosition,
35 const wxSize& size = wxDefaultSize, long style = 0,
36 const wxString& name = wxWebViewNameStr)
37 {
38 Init();
39
40 Create(parent, id, url, pos, size, style, name);
41 }
42
43 virtual bool Create(wxWindow *parent,
44 wxWindowID id = wxID_ANY,
45 const wxString& url = wxWebViewDefaultURLStr,
46 const wxPoint& pos = wxDefaultPosition,
47 const wxSize& size = wxDefaultSize, long style = 0,
48 const wxString& name = wxWebViewNameStr);
49
50 virtual ~wxWebViewWebKit();
51
52 virtual bool Enable( bool enable = true );
53
54 // implementation
55 // --------------
56
57 static wxVisualAttributes
58 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
59
60 virtual void Stop();
61 virtual void LoadURL(const wxString& url);
62 virtual void GoBack();
63 virtual void GoForward();
64 virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT);
65 virtual bool CanGoBack() const;
66 virtual bool CanGoForward() const;
67 virtual void ClearHistory();
68 virtual void EnableHistory(bool enable = true);
69 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory();
70 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory();
71 virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item);
72 virtual wxString GetCurrentURL() const;
73 virtual wxString GetCurrentTitle() const;
74 virtual wxString GetPageSource() const;
75 virtual wxString GetPageText() const;
76 //We do not want to hide the other overloads
77 using wxWebView::SetPage;
78 virtual void SetPage(const wxString& html, const wxString& baseUrl);
79 virtual void Print();
80 virtual bool IsBusy() const;
81
82 void SetZoomType(wxWebViewZoomType);
83 wxWebViewZoomType GetZoomType() const;
84 bool CanSetZoomType(wxWebViewZoomType) const;
85 virtual wxWebViewZoom GetZoom() const;
86 virtual void SetZoom(wxWebViewZoom);
87
88 //Clipboard functions
89 virtual bool CanCut() const;
90 virtual bool CanCopy() const;
91 virtual bool CanPaste() const;
92 virtual void Cut();
93 virtual void Copy();
94 virtual void Paste();
95
96 //Undo / redo functionality
97 virtual bool CanUndo() const;
98 virtual bool CanRedo() const;
99 virtual void Undo();
100 virtual void Redo();
101
102 //Editing functions
103 virtual void SetEditable(bool enable = true);
104 virtual bool IsEditable() const;
105
106 //Selection
107 virtual void DeleteSelection();
108 virtual bool HasSelection() const;
109 virtual void SelectAll();
110 virtual wxString GetSelectedText() const;
111 virtual wxString GetSelectedSource() const;
112 virtual void ClearSelection();
113
114 virtual void RunScript(const wxString& javascript);
115
116 //Virtual Filesystem Support
117 virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler);
118 virtual wxVector<wxSharedPtr<wxWebViewHandler> > GetHandlers() { return m_handlerList; }
119
120 /** TODO: check if this can be made private
121 * The native control has a getter to check for busy state, but except in
122 * very recent versions of webkit this getter doesn't say everything we need
123 * (namely it seems to stay indefinitely busy when loading is cancelled by
124 * user)
125 */
126 bool m_busy;
127
128 wxString m_vfsurl;
129
130 //We use this flag to stop recursion when we load a page from the navigation
131 //callback, mainly when loading a VFS page
132 bool m_guard;
133
134 protected:
135
136 virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
137
138 private:
139
140 void ZoomIn();
141 void ZoomOut();
142 void SetWebkitZoom(float level);
143 float GetWebkitZoom() const;
144
145 // focus event handler: calls GTKUpdateBitmap()
146 void GTKOnFocus(wxFocusEvent& event);
147
148 WebKitWebView *m_web_view;
149 int m_historyLimit;
150
151 wxVector<wxSharedPtr<wxWebViewHandler> > m_handlerList;
152
153 wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit);
154 };
155
156 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && defined(__WXGTK__)
157
158 #endif