]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/webview_ie.h
Don't create multiple parent-less top level frames in layout sample.
[wxWidgets.git] / include / wx / msw / webview_ie.h
CommitLineData
61b98a2d 1/////////////////////////////////////////////////////////////////////////////
e52aec97 2// Name: include/wx/msw/webview_ie.h
61b98a2d
SL
3// Purpose: wxMSW IE wxWebView backend
4// Author: Marianne Gagnon
5// Id: $Id$
153530af 6// Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
61b98a2d
SL
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifndef wxWebViewIE_H
11#define wxWebViewIE_H
12
13#include "wx/setup.h"
14
9d2f31db 15#if wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
61b98a2d
SL
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"
9f194b9d 21#include "wx/msw/ole/oleutils.h"
f40f8e17 22#include "wx/msw/private/comptr.h"
97aa7b99 23#include "wx/msw/wrapwin.h"
e924e848 24#include "wx/msw/missing.h"
e52aec97 25#include "wx/msw/webview_missing.h"
74af0b13 26#include "wx/sharedptr.h"
5cbda74b 27#include "wx/vector.h"
61b98a2d 28
22ca10fa 29struct IHTMLDocument2;
66ac0400
SL
30struct IHTMLElement;
31struct IMarkupPointer;
7d3f6b4d 32class wxFSFile;
39498710 33class ClassFactory;
accc94d5
SL
34class wxIEContainer;
35class DocHostUIHandler;
66ac0400 36class wxFindPointers;
e52aec97 37class wxIInternetProtocol;
29365629 38
467d261e 39class WXDLLIMPEXP_WEBVIEW wxWebViewIE : public wxWebView
61b98a2d
SL
40{
41public:
42
43 wxWebViewIE() {}
44
45 wxWebViewIE(wxWindow* parent,
46 wxWindowID id,
47 const wxString& url = wxWebViewDefaultURLStr,
48 const wxPoint& pos = wxDefaultPosition,
49 const wxSize& size = wxDefaultSize,
50 long style = 0,
51 const wxString& name = wxWebViewNameStr)
52 {
53 Create(parent, id, url, pos, size, style, name);
54 }
55
39498710
SL
56 ~wxWebViewIE();
57
61b98a2d
SL
58 bool Create(wxWindow* parent,
59 wxWindowID id,
60 const wxString& url = wxWebViewDefaultURLStr,
61 const wxPoint& pos = wxDefaultPosition,
62 const wxSize& size = wxDefaultSize,
63 long style = 0,
64 const wxString& name = wxWebViewNameStr);
65
4d0dddc7 66 virtual void LoadURL(const wxString& url);
c13d6ac1
SL
67 virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item);
68 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory();
69 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory();
61b98a2d 70
e669ddde
SL
71 virtual bool CanGoForward() const;
72 virtual bool CanGoBack() const;
61b98a2d
SL
73 virtual void GoBack();
74 virtual void GoForward();
74af0b13
SL
75 virtual void ClearHistory();
76 virtual void EnableHistory(bool enable = true);
61b98a2d 77 virtual void Stop();
236cff73 78 virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT);
61b98a2d 79
e669ddde
SL
80 virtual wxString GetPageSource() const;
81 virtual wxString GetPageText() const;
61b98a2d 82
e669ddde
SL
83 virtual bool IsBusy() const;
84 virtual wxString GetCurrentURL() const;
85 virtual wxString GetCurrentTitle() const;
61b98a2d
SL
86
87 virtual void SetZoomType(wxWebViewZoomType);
88 virtual wxWebViewZoomType GetZoomType() const;
89 virtual bool CanSetZoomType(wxWebViewZoomType) const;
90
91 virtual void Print();
92
e669ddde 93 virtual wxWebViewZoom GetZoom() const;
61b98a2d
SL
94 virtual void SetZoom(wxWebViewZoom zoom);
95
4681a3ea 96 //Clipboard functions
e669ddde
SL
97 virtual bool CanCut() const;
98 virtual bool CanCopy() const;
99 virtual bool CanPaste() const;
4681a3ea
SL
100 virtual void Cut();
101 virtual void Copy();
102 virtual void Paste();
103
97e49559 104 //Undo / redo functionality
e669ddde
SL
105 virtual bool CanUndo() const;
106 virtual bool CanRedo() const;
97e49559
SL
107 virtual void Undo();
108 virtual void Redo();
109
66ac0400 110 //Find function
236cff73 111 virtual long Find(const wxString& text, int flags = wxWEBVIEW_FIND_DEFAULT);
66ac0400 112
c7cbe308
SL
113 //Editing functions
114 virtual void SetEditable(bool enable = true);
e669ddde 115 virtual bool IsEditable() const;
c7cbe308 116
63a65070
SL
117 //Selection
118 virtual void SelectAll();
e669ddde 119 virtual bool HasSelection() const;
63a65070 120 virtual void DeleteSelection();
e669ddde
SL
121 virtual wxString GetSelectedText() const;
122 virtual wxString GetSelectedSource() const;
41933aa5 123 virtual void ClearSelection();
63a65070 124
c9ccc09c 125 virtual void RunScript(const wxString& javascript);
63a65070 126
29365629 127 //Virtual Filesystem Support
7d8d6163 128 virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler);
29365629 129
b6a49c2b
VZ
130 virtual void* GetNativeBackend() const { return m_webBrowser; }
131
61b98a2d
SL
132 // ---- IE-specific methods
133
134 // FIXME: I seem to be able to access remote webpages even in offline mode...
135 bool IsOfflineMode();
136 void SetOfflineMode(bool offline);
137
e669ddde 138 wxWebViewZoom GetIETextZoom() const;
c5f417cb 139 void SetIETextZoom(wxWebViewZoom level);
61b98a2d 140
e669ddde 141 wxWebViewZoom GetIEOpticalZoom() const;
c5f417cb 142 void SetIEOpticalZoom(wxWebViewZoom level);
61b98a2d
SL
143
144 void onActiveXEvent(wxActiveXEvent& evt);
22ca10fa 145 void onEraseBg(wxEraseEvent&) {}
61b98a2d
SL
146
147 DECLARE_EVENT_TABLE();
148
a977376a
VZ
149protected:
150 virtual void DoSetPage(const wxString& html, const wxString& baseUrl);
151
61b98a2d 152private:
accc94d5 153 wxIEContainer* m_container;
61b98a2d
SL
154 wxAutomationObject m_ie;
155 IWebBrowser2* m_webBrowser;
156 DWORD m_dwCookie;
f40f8e17 157 wxCOMPtr<DocHostUIHandler> m_uiHandler;
61b98a2d 158
c5f417cb
SL
159 //We store the current zoom type;
160 wxWebViewZoomType m_zoomType;
161
61b98a2d
SL
162 /** The "Busy" property of IWebBrowser2 does not always return busy when
163 * we'd want it to; this variable may be set to true in cases where the
164 * Busy property is false but should be true.
165 */
166 bool m_isBusy;
60eabdbe 167 //We manage our own history, the history list contains the history items
3e7968c2
SL
168 //which are added as documentcomplete events arrive, unless we are loading
169 //an item from the history. The position is stored as an int, and reflects
170 //where we are in the history list.
c13d6ac1 171 wxVector<wxSharedPtr<wxWebViewHistoryItem> > m_historyList;
39498710 172 wxVector<ClassFactory*> m_factories;
74af0b13
SL
173 int m_historyPosition;
174 bool m_historyLoadingFromList;
175 bool m_historyEnabled;
176
66ac0400
SL
177 //We store find flag, results and position.
178 wxVector<wxFindPointers> m_findPointers;
179 int m_findFlags;
180 wxString m_findText;
181 int m_findPosition;
182
183 //Generic helper functions
e669ddde 184 bool CanExecCommand(wxString command) const;
4681a3ea 185 void ExecCommand(wxString command);
f40f8e17 186 wxCOMPtr<IHTMLDocument2> GetDocument() const;
938506b1 187 bool IsElementVisible(wxCOMPtr<IHTMLElement> elm);
66ac0400
SL
188 //Find helper functions.
189 void FindInternal(const wxString& text, int flags, int internal_flag);
190 long FindNext(int direction = 1);
191 void FindClear();
9447a0d6
SL
192 //Toggles control features see INTERNETFEATURELIST for values.
193 bool EnableControlFeature(long flag, bool enable = true);
4681a3ea 194
cddf4541 195 wxDECLARE_DYNAMIC_CLASS(wxWebViewIE);
61b98a2d
SL
196};
197
4c687fff
SL
198class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryIE : public wxWebViewFactory
199{
200public:
201 virtual wxWebView* Create() { return new wxWebViewIE; }
202 virtual wxWebView* Create(wxWindow* parent,
203 wxWindowID id,
204 const wxString& url = wxWebViewDefaultURLStr,
205 const wxPoint& pos = wxDefaultPosition,
206 const wxSize& size = wxDefaultSize,
207 long style = 0,
208 const wxString& name = wxWebViewNameStr)
209 { return new wxWebViewIE(parent, id, url, pos, size, style, name); }
210};
211
f559d1a2 212class VirtualProtocol : public wxIInternetProtocol
7d3f6b4d
SL
213{
214protected:
f559d1a2 215 wxIInternetProtocolSink* m_protocolSink;
7d3f6b4d
SL
216 wxString m_html;
217 VOID * fileP;
218
219 wxFSFile* m_file;
7d8d6163 220 wxSharedPtr<wxWebViewHandler> m_handler;
7d3f6b4d
SL
221
222public:
7d8d6163 223 VirtualProtocol(wxSharedPtr<wxWebViewHandler> handler);
6dd0883d 224 ~VirtualProtocol() {}
7d3f6b4d
SL
225
226 //IUnknown
9f194b9d 227 DECLARE_IUNKNOWN_METHODS;
7d3f6b4d
SL
228
229 //IInternetProtocolRoot
60eabdbe 230 HRESULT STDMETHODCALLTYPE Abort(HRESULT WXUNUSED(hrReason),
0995b9dc 231 DWORD WXUNUSED(dwOptions))
7d3f6b4d 232 { return E_NOTIMPL; }
f559d1a2 233 HRESULT STDMETHODCALLTYPE Continue(wxPROTOCOLDATA *WXUNUSED(pProtocolData))
7d3f6b4d
SL
234 { return S_OK; }
235 HRESULT STDMETHODCALLTYPE Resume() { return S_OK; }
60eabdbe 236 HRESULT STDMETHODCALLTYPE Start(LPCWSTR szUrl,
f559d1a2
VZ
237 wxIInternetProtocolSink *pOIProtSink,
238 wxIInternetBindInfo *pOIBindInfo,
60eabdbe 239 DWORD grfPI,
7d3f6b4d
SL
240 HANDLE_PTR dwReserved);
241 HRESULT STDMETHODCALLTYPE Suspend() { return S_OK; }
0995b9dc 242 HRESULT STDMETHODCALLTYPE Terminate(DWORD WXUNUSED(dwOptions)) { return S_OK; }
7d3f6b4d
SL
243
244 //IInternetProtocol
60eabdbe 245 HRESULT STDMETHODCALLTYPE LockRequest(DWORD WXUNUSED(dwOptions))
0995b9dc 246 { return S_OK; }
7d3f6b4d 247 HRESULT STDMETHODCALLTYPE Read(void *pv, ULONG cb, ULONG *pcbRead);
60eabdbe
VZ
248 HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER WXUNUSED(dlibMove),
249 DWORD WXUNUSED(dwOrigin),
250 ULARGE_INTEGER* WXUNUSED(plibNewPosition))
7d3f6b4d
SL
251 { return E_FAIL; }
252 HRESULT STDMETHODCALLTYPE UnlockRequest() { return S_OK; }
253};
254
255class ClassFactory : public IClassFactory
256{
7d3f6b4d 257public:
8626e0b7
SL
258 ClassFactory(wxSharedPtr<wxWebViewHandler> handler) : m_handler(handler)
259 { AddRef(); }
260
261 wxString GetName() { return m_handler->GetName(); }
7d3f6b4d
SL
262
263 //IClassFactory
60eabdbe 264 HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown* pUnkOuter,
7d3f6b4d
SL
265 REFIID riid, void** ppvObject);
266 HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock);
9f194b9d
SL
267
268 //IUnknown
269 DECLARE_IUNKNOWN_METHODS;
270
29365629 271private:
7d8d6163 272 wxSharedPtr<wxWebViewHandler> m_handler;
7d3f6b4d
SL
273};
274
accc94d5
SL
275class wxIEContainer : public wxActiveXContainer
276{
277public:
278 wxIEContainer(wxWindow *parent, REFIID iid, IUnknown *pUnk, DocHostUIHandler* uiHandler = NULL);
279 virtual ~wxIEContainer();
280 virtual bool QueryClientSiteInterface(REFIID iid, void **_interface, const char *&desc);
281private:
282 DocHostUIHandler* m_uiHandler;
283};
284
285class DocHostUIHandler : public wxIDocHostUIHandler
286{
287public:
c420d57b 288 DocHostUIHandler(wxWebView* browser) { m_browser = browser; }
accc94d5 289 ~DocHostUIHandler() {};
c420d57b 290
accc94d5
SL
291 virtual HRESULT wxSTDCALL ShowContextMenu(DWORD dwID, POINT *ppt,
292 IUnknown *pcmdtReserved,
293 IDispatch *pdispReserved);
34326da7 294
accc94d5
SL
295 virtual HRESULT wxSTDCALL GetHostInfo(DOCHOSTUIINFO *pInfo);
296
297 virtual HRESULT wxSTDCALL ShowUI(DWORD dwID,
298 IOleInPlaceActiveObject *pActiveObject,
299 IOleCommandTarget *pCommandTarget,
300 IOleInPlaceFrame *pFrame,
301 IOleInPlaceUIWindow *pDoc);
302
303 virtual HRESULT wxSTDCALL HideUI(void);
304
305 virtual HRESULT wxSTDCALL UpdateUI(void);
306
307 virtual HRESULT wxSTDCALL EnableModeless(BOOL fEnable);
308
309 virtual HRESULT wxSTDCALL OnDocWindowActivate(BOOL fActivate);
310
311 virtual HRESULT wxSTDCALL OnFrameWindowActivate(BOOL fActivate);
312
313 virtual HRESULT wxSTDCALL ResizeBorder(LPCRECT prcBorder,
314 IOleInPlaceUIWindow *pUIWindow,
315 BOOL fRameWindow);
316
317 virtual HRESULT wxSTDCALL TranslateAccelerator(LPMSG lpMsg,
318 const GUID *pguidCmdGroup,
319 DWORD nCmdID);
320
34326da7 321 virtual HRESULT wxSTDCALL GetOptionKeyPath(LPOLESTR *pchKey,
accc94d5
SL
322 DWORD dw);
323
324 virtual HRESULT wxSTDCALL GetDropTarget(IDropTarget *pDropTarget,
325 IDropTarget **ppDropTarget);
326
327 virtual HRESULT wxSTDCALL GetExternal(IDispatch **ppDispatch);
328
329 virtual HRESULT wxSTDCALL TranslateUrl(DWORD dwTranslate,
96457e67
SL
330 OLECHAR *pchURLIn,
331 OLECHAR **ppchURLOut);
accc94d5
SL
332
333 virtual HRESULT wxSTDCALL FilterDataObject(IDataObject *pDO,
334 IDataObject **ppDORet);
335 //IUnknown
336 DECLARE_IUNKNOWN_METHODS;
c420d57b
SL
337
338private:
339 wxWebView* m_browser;
accc94d5
SL
340};
341
66ac0400
SL
342class wxFindPointers
343{
344public:
e52aec97 345 wxFindPointers(wxIMarkupPointer *ptrBegin, wxIMarkupPointer *ptrEnd)
66ac0400
SL
346 {
347 begin = ptrBegin;
348 end = ptrEnd;
349 }
350 //The two markup pointers.
e52aec97 351 wxIMarkupPointer *begin, *end;
66ac0400
SL
352};
353
9d2f31db 354#endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
61b98a2d
SL
355
356#endif // wxWebViewIE_H