1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/msw/webviewie.h
3 // Purpose: wxMSW IE wxWebView backend
4 // Author: Marianne Gagnon
6 // Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
15 #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
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"
25 struct IHTMLDocument2
;
29 class WXDLLIMPEXP_WEBVIEW wxWebViewIE
: public wxWebView
35 wxWebViewIE(wxWindow
* parent
,
37 const wxString
& url
= wxWebViewDefaultURLStr
,
38 const wxPoint
& pos
= wxDefaultPosition
,
39 const wxSize
& size
= wxDefaultSize
,
41 const wxString
& name
= wxWebViewNameStr
)
43 Create(parent
, id
, url
, pos
, size
, style
, name
);
48 bool Create(wxWindow
* parent
,
50 const wxString
& url
= wxWebViewDefaultURLStr
,
51 const wxPoint
& pos
= wxDefaultPosition
,
52 const wxSize
& size
= wxDefaultSize
,
54 const wxString
& name
= wxWebViewNameStr
);
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();
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);
68 virtual void Reload(wxWebViewReloadFlags flags
= wxWEB_VIEW_RELOAD_DEFAULT
);
70 virtual wxString
GetPageSource() const;
71 virtual wxString
GetPageText() const;
73 virtual bool IsBusy() const;
74 virtual wxString
GetCurrentURL() const;
75 virtual wxString
GetCurrentTitle() const;
77 virtual void SetZoomType(wxWebViewZoomType
);
78 virtual wxWebViewZoomType
GetZoomType() const;
79 virtual bool CanSetZoomType(wxWebViewZoomType
) const;
83 virtual void SetPage(const wxString
& html
, const wxString
& baseUrl
);
85 virtual wxWebViewZoom
GetZoom() const;
86 virtual void SetZoom(wxWebViewZoom zoom
);
89 virtual bool CanCut() const;
90 virtual bool CanCopy() const;
91 virtual bool CanPaste() const;
96 //Undo / redo functionality
97 virtual bool CanUndo() const;
98 virtual bool CanRedo() const;
103 virtual void SetEditable(bool enable
= true);
104 virtual bool IsEditable() const;
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();
114 virtual void RunScript(const wxString
& javascript
);
116 //Virtual Filesystem Support
117 virtual void RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
);
119 // ---- IE-specific methods
121 // FIXME: I seem to be able to access remote webpages even in offline mode...
122 bool IsOfflineMode();
123 void SetOfflineMode(bool offline
);
125 wxWebViewZoom
GetIETextZoom() const;
126 void SetIETextZoom(wxWebViewZoom level
);
128 wxWebViewZoom
GetIEOpticalZoom() const;
129 void SetIEOpticalZoom(wxWebViewZoom level
);
131 void onActiveXEvent(wxActiveXEvent
& evt
);
132 void onEraseBg(wxEraseEvent
&) {}
134 DECLARE_EVENT_TABLE();
137 wxActiveXContainer
* m_container
;
138 wxAutomationObject m_ie
;
139 IWebBrowser2
* m_webBrowser
;
142 //We store the current zoom type;
143 wxWebViewZoomType m_zoomType
;
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.
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
;
160 //Generic helper functions for IHtmlDocument commands
161 bool CanExecCommand(wxString command
) const;
162 void ExecCommand(wxString command
);
163 IHTMLDocument2
* GetDocument() const;
165 wxDECLARE_DYNAMIC_CLASS(wxWebViewIE
);
168 class VirtualProtocol
: public IInternetProtocol
172 IInternetProtocolSink
* m_protocolSink
;
177 wxSharedPtr
<wxWebViewHandler
> m_handler
;
180 VirtualProtocol(wxSharedPtr
<wxWebViewHandler
> handler
);
184 ULONG STDMETHODCALLTYPE
AddRef();
185 HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID riid
, void **ppvObject
);
186 ULONG STDMETHODCALLTYPE
Release();
188 //IInternetProtocolRoot
189 HRESULT STDMETHODCALLTYPE
Abort(HRESULT
WXUNUSED(hrReason
),
190 DWORD
WXUNUSED(dwOptions
))
191 { return E_NOTIMPL
; }
192 HRESULT STDMETHODCALLTYPE
Continue(PROTOCOLDATA
*WXUNUSED(pProtocolData
))
194 HRESULT STDMETHODCALLTYPE
Resume() { return S_OK
; }
195 HRESULT STDMETHODCALLTYPE
Start(LPCWSTR szUrl
,
196 IInternetProtocolSink
*pOIProtSink
,
197 IInternetBindInfo
*pOIBindInfo
,
199 HANDLE_PTR dwReserved
);
200 HRESULT STDMETHODCALLTYPE
Suspend() { return S_OK
; }
201 HRESULT STDMETHODCALLTYPE
Terminate(DWORD
WXUNUSED(dwOptions
)) { return S_OK
; }
204 HRESULT STDMETHODCALLTYPE
LockRequest(DWORD
WXUNUSED(dwOptions
))
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
))
211 HRESULT STDMETHODCALLTYPE
UnlockRequest() { return S_OK
; }
214 class ClassFactory
: public IClassFactory
217 ClassFactory(wxSharedPtr
<wxWebViewHandler
> handler
) : m_refCount(0), m_handler(handler
) {}
219 ULONG STDMETHODCALLTYPE
AddRef();
220 HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID riid
, void **ppvObject
);
221 ULONG STDMETHODCALLTYPE
Release();
224 HRESULT STDMETHODCALLTYPE
CreateInstance(IUnknown
* pUnkOuter
,
225 REFIID riid
, void** ppvObject
);
226 HRESULT STDMETHODCALLTYPE
LockServer(BOOL fLock
);
229 wxSharedPtr
<wxWebViewHandler
> m_handler
;
232 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
234 #endif // wxWebViewIE_H