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_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/sharedptr.h"
22 #include "wx/vector.h"
24 struct IHTMLDocument2
;
27 class WXDLLIMPEXP_WEB wxWebViewIE
: public wxWebView
33 wxWebViewIE(wxWindow
* parent
,
35 const wxString
& url
= wxWebViewDefaultURLStr
,
36 const wxPoint
& pos
= wxDefaultPosition
,
37 const wxSize
& size
= wxDefaultSize
,
39 const wxString
& name
= wxWebViewNameStr
)
41 Create(parent
, id
, url
, pos
, size
, style
, name
);
44 bool Create(wxWindow
* parent
,
46 const wxString
& url
= wxWebViewDefaultURLStr
,
47 const wxPoint
& pos
= wxDefaultPosition
,
48 const wxSize
& size
= wxDefaultSize
,
50 const wxString
& name
= wxWebViewNameStr
);
52 virtual void LoadURL(const wxString
& url
);
53 virtual void LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
);
54 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetBackwardHistory();
55 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetForwardHistory();
57 virtual bool CanGoForward() const;
58 virtual bool CanGoBack() const;
59 virtual void GoBack();
60 virtual void GoForward();
61 virtual void ClearHistory();
62 virtual void EnableHistory(bool enable
= true);
64 virtual void Reload(wxWebViewReloadFlags flags
= wxWEB_VIEW_RELOAD_DEFAULT
);
66 virtual wxString
GetPageSource() const;
67 virtual wxString
GetPageText() const;
69 virtual bool IsBusy() const;
70 virtual wxString
GetCurrentURL() const;
71 virtual wxString
GetCurrentTitle() const;
73 virtual void SetZoomType(wxWebViewZoomType
);
74 virtual wxWebViewZoomType
GetZoomType() const;
75 virtual bool CanSetZoomType(wxWebViewZoomType
) const;
79 virtual void SetPage(const wxString
& html
, const wxString
& baseUrl
);
81 virtual wxWebViewZoom
GetZoom() const;
82 virtual void SetZoom(wxWebViewZoom zoom
);
85 virtual bool CanCut() const;
86 virtual bool CanCopy() const;
87 virtual bool CanPaste() const;
92 //Undo / redo functionality
93 virtual bool CanUndo() const;
94 virtual bool CanRedo() const;
99 virtual void SetEditable(bool enable
= true);
100 virtual bool IsEditable() const;
103 virtual void SelectAll();
104 virtual bool HasSelection() const;
105 virtual void DeleteSelection();
106 virtual wxString
GetSelectedText() const;
107 virtual wxString
GetSelectedSource() const;
108 virtual void ClearSelection();
110 virtual void RunScript(const wxString
& javascript
);
112 //Virtual Filesystem Support
113 virtual void RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
);
115 // ---- IE-specific methods
117 // FIXME: I seem to be able to access remote webpages even in offline mode...
118 bool IsOfflineMode();
119 void SetOfflineMode(bool offline
);
121 wxWebViewZoom
GetIETextZoom() const;
122 void SetIETextZoom(wxWebViewZoom level
);
124 wxWebViewZoom
GetIEOpticalZoom() const;
125 void SetIEOpticalZoom(wxWebViewZoom level
);
127 void onActiveXEvent(wxActiveXEvent
& evt
);
128 void onEraseBg(wxEraseEvent
&) {}
130 DECLARE_EVENT_TABLE();
133 wxActiveXContainer
* m_container
;
134 wxAutomationObject m_ie
;
135 IWebBrowser2
* m_webBrowser
;
138 //We store the current zoom type;
139 wxWebViewZoomType m_zoomType
;
141 /** The "Busy" property of IWebBrowser2 does not always return busy when
142 * we'd want it to; this variable may be set to true in cases where the
143 * Busy property is false but should be true.
146 //We manage our own history, the history list contains the history items
147 //which are added as documentcomplete events arrive, unless we are loading
148 //an item from the history. The position is stored as an int, and reflects
149 //where we are in the history list.
150 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > m_historyList
;
151 int m_historyPosition
;
152 bool m_historyLoadingFromList
;
153 bool m_historyEnabled
;
155 //Generic helper functions for IHtmlDocument commands
156 bool CanExecCommand(wxString command
) const;
157 void ExecCommand(wxString command
);
158 IHTMLDocument2
* GetDocument() const;
160 wxDECLARE_DYNAMIC_CLASS(wxWebViewIE
);
163 class VirtualProtocol
: public IInternetProtocol
167 IInternetProtocolSink
* m_protocolSink
;
172 wxSharedPtr
<wxWebViewHandler
> m_handler
;
175 VirtualProtocol(wxSharedPtr
<wxWebViewHandler
> handler
);
179 ULONG STDMETHODCALLTYPE
AddRef();
180 HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID riid
, void **ppvObject
);
181 ULONG STDMETHODCALLTYPE
Release();
183 //IInternetProtocolRoot
184 HRESULT STDMETHODCALLTYPE
Abort(HRESULT
WXUNUSED(hrReason
),
185 DWORD
WXUNUSED(dwOptions
))
186 { return E_NOTIMPL
; }
187 HRESULT STDMETHODCALLTYPE
Continue(PROTOCOLDATA
*WXUNUSED(pProtocolData
))
189 HRESULT STDMETHODCALLTYPE
Resume() { return S_OK
; }
190 HRESULT STDMETHODCALLTYPE
Start(LPCWSTR szUrl
,
191 IInternetProtocolSink
*pOIProtSink
,
192 IInternetBindInfo
*pOIBindInfo
,
194 HANDLE_PTR dwReserved
);
195 HRESULT STDMETHODCALLTYPE
Suspend() { return S_OK
; }
196 HRESULT STDMETHODCALLTYPE
Terminate(DWORD
WXUNUSED(dwOptions
)) { return S_OK
; }
199 HRESULT STDMETHODCALLTYPE
LockRequest(DWORD
WXUNUSED(dwOptions
))
201 HRESULT STDMETHODCALLTYPE
Read(void *pv
, ULONG cb
, ULONG
*pcbRead
);
202 HRESULT STDMETHODCALLTYPE
Seek(LARGE_INTEGER
WXUNUSED(dlibMove
),
203 DWORD
WXUNUSED(dwOrigin
),
204 ULARGE_INTEGER
* WXUNUSED(plibNewPosition
))
206 HRESULT STDMETHODCALLTYPE
UnlockRequest() { return S_OK
; }
209 class ClassFactory
: public IClassFactory
214 ClassFactory(wxSharedPtr
<wxWebViewHandler
> handler
) : m_handler(handler
) {}
216 ULONG STDMETHODCALLTYPE
AddRef();
217 HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID riid
, void **ppvObject
);
218 ULONG STDMETHODCALLTYPE
Release();
221 HRESULT STDMETHODCALLTYPE
CreateInstance(IUnknown
* pUnkOuter
,
222 REFIID riid
, void** ppvObject
);
223 HRESULT STDMETHODCALLTYPE
LockServer(BOOL fLock
);
225 wxSharedPtr
<wxWebViewHandler
> m_handler
;
228 #endif // wxUSE_WEBVIEW_IE && defined(__WXMSW__)
230 #endif // wxWebViewIE_H