Fix various GCC warnings in wxWebView.
[wxWidgets.git] / include / wx / msw / webview_ie.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/msw/webviewie.h
3 // Purpose: wxMSW IE wxWebView backend
4 // Author: Marianne Gagnon
5 // Id: $Id$
6 // Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef wxWebViewIE_H
11 #define wxWebViewIE_H
12
13 #include "wx/setup.h"
14
15 #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
16
17 #include "wx/control.h"
18 #include "wx/webview.h"
19 #include "wx/msw/ole/automtn.h"
20 #include "wx/msw/ole/activex.h"
21 #include "wx/msw/missing.h"
22 #include "wx/sharedptr.h"
23 #include "wx/vector.h"
24
25 struct IHTMLDocument2;
26 class wxFSFile;
27 class ClassFactory;
28
29 class WXDLLIMPEXP_WEBVIEW wxWebViewIE : public wxWebView
30 {
31 public:
32
33 wxWebViewIE() {}
34
35 wxWebViewIE(wxWindow* parent,
36 wxWindowID id,
37 const wxString& url = wxWebViewDefaultURLStr,
38 const wxPoint& pos = wxDefaultPosition,
39 const wxSize& size = wxDefaultSize,
40 long style = 0,
41 const wxString& name = wxWebViewNameStr)
42 {
43 Create(parent, id, url, pos, size, style, name);
44 }
45
46 ~wxWebViewIE();
47
48 bool Create(wxWindow* parent,
49 wxWindowID id,
50 const wxString& url = wxWebViewDefaultURLStr,
51 const wxPoint& pos = wxDefaultPosition,
52 const wxSize& size = wxDefaultSize,
53 long style = 0,
54 const wxString& name = wxWebViewNameStr);
55
56 virtual void LoadURL(const wxString& url);
57 virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item);
58 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory();
59 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory();
60
61 virtual bool CanGoForward() const;
62 virtual bool CanGoBack() const;
63 virtual void GoBack();
64 virtual void GoForward();
65 virtual void ClearHistory();
66 virtual void EnableHistory(bool enable = true);
67 virtual void Stop();
68 virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT);
69
70 virtual wxString GetPageSource() const;
71 virtual wxString GetPageText() const;
72
73 virtual bool IsBusy() const;
74 virtual wxString GetCurrentURL() const;
75 virtual wxString GetCurrentTitle() const;
76
77 virtual void SetZoomType(wxWebViewZoomType);
78 virtual wxWebViewZoomType GetZoomType() const;
79 virtual bool CanSetZoomType(wxWebViewZoomType) const;
80
81 virtual void Print();
82
83 virtual void SetPage(const wxString& html, const wxString& baseUrl);
84
85 virtual wxWebViewZoom GetZoom() const;
86 virtual void SetZoom(wxWebViewZoom zoom);
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 SelectAll();
108 virtual bool HasSelection() const;
109 virtual void DeleteSelection();
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
119 // ---- IE-specific methods
120
121 // FIXME: I seem to be able to access remote webpages even in offline mode...
122 bool IsOfflineMode();
123 void SetOfflineMode(bool offline);
124
125 wxWebViewZoom GetIETextZoom() const;
126 void SetIETextZoom(wxWebViewZoom level);
127
128 wxWebViewZoom GetIEOpticalZoom() const;
129 void SetIEOpticalZoom(wxWebViewZoom level);
130
131 void onActiveXEvent(wxActiveXEvent& evt);
132 void onEraseBg(wxEraseEvent&) {}
133
134 DECLARE_EVENT_TABLE();
135
136 private:
137 wxActiveXContainer* m_container;
138 wxAutomationObject m_ie;
139 IWebBrowser2* m_webBrowser;
140 DWORD m_dwCookie;
141
142 //We store the current zoom type;
143 wxWebViewZoomType m_zoomType;
144
145 /** The "Busy" property of IWebBrowser2 does not always return busy when
146 * we'd want it to; this variable may be set to true in cases where the
147 * Busy property is false but should be true.
148 */
149 bool m_isBusy;
150 //We manage our own history, the history list contains the history items
151 //which are added as documentcomplete events arrive, unless we are loading
152 //an item from the history. The position is stored as an int, and reflects
153 //where we are in the history list.
154 wxVector<wxSharedPtr<wxWebViewHistoryItem> > m_historyList;
155 wxVector<ClassFactory*> m_factories;
156 int m_historyPosition;
157 bool m_historyLoadingFromList;
158 bool m_historyEnabled;
159
160 //Generic helper functions for IHtmlDocument commands
161 bool CanExecCommand(wxString command) const;
162 void ExecCommand(wxString command);
163 IHTMLDocument2* GetDocument() const;
164
165 wxDECLARE_DYNAMIC_CLASS(wxWebViewIE);
166 };
167
168 class VirtualProtocol : public IInternetProtocol
169 {
170 protected:
171 ULONG m_refCount;
172 IInternetProtocolSink* m_protocolSink;
173 wxString m_html;
174 VOID * fileP;
175
176 wxFSFile* m_file;
177 wxSharedPtr<wxWebViewHandler> m_handler;
178
179 public:
180 VirtualProtocol(wxSharedPtr<wxWebViewHandler> handler);
181 ~VirtualProtocol();
182
183 //IUnknown
184 ULONG STDMETHODCALLTYPE AddRef();
185 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject);
186 ULONG STDMETHODCALLTYPE Release();
187
188 //IInternetProtocolRoot
189 HRESULT STDMETHODCALLTYPE Abort(HRESULT WXUNUSED(hrReason),
190 DWORD WXUNUSED(dwOptions))
191 { return E_NOTIMPL; }
192 HRESULT STDMETHODCALLTYPE Continue(PROTOCOLDATA *WXUNUSED(pProtocolData))
193 { return S_OK; }
194 HRESULT STDMETHODCALLTYPE Resume() { return S_OK; }
195 HRESULT STDMETHODCALLTYPE Start(LPCWSTR szUrl,
196 IInternetProtocolSink *pOIProtSink,
197 IInternetBindInfo *pOIBindInfo,
198 DWORD grfPI,
199 HANDLE_PTR dwReserved);
200 HRESULT STDMETHODCALLTYPE Suspend() { return S_OK; }
201 HRESULT STDMETHODCALLTYPE Terminate(DWORD WXUNUSED(dwOptions)) { return S_OK; }
202
203 //IInternetProtocol
204 HRESULT STDMETHODCALLTYPE LockRequest(DWORD WXUNUSED(dwOptions))
205 { return S_OK; }
206 HRESULT STDMETHODCALLTYPE Read(void *pv, ULONG cb, ULONG *pcbRead);
207 HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER WXUNUSED(dlibMove),
208 DWORD WXUNUSED(dwOrigin),
209 ULARGE_INTEGER* WXUNUSED(plibNewPosition))
210 { return E_FAIL; }
211 HRESULT STDMETHODCALLTYPE UnlockRequest() { return S_OK; }
212 };
213
214 class ClassFactory : public IClassFactory
215 {
216 public:
217 ClassFactory(wxSharedPtr<wxWebViewHandler> handler) : m_refCount(0), m_handler(handler) {}
218 //IUnknown
219 ULONG STDMETHODCALLTYPE AddRef();
220 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject);
221 ULONG STDMETHODCALLTYPE Release();
222
223 //IClassFactory
224 HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown* pUnkOuter,
225 REFIID riid, void** ppvObject);
226 HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock);
227 private:
228 ULONG m_refCount;
229 wxSharedPtr<wxWebViewHandler> m_handler;
230 };
231
232 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
233
234 #endif // wxWebViewIE_H