1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/msw/webview_ie.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/ole/oleutils.h"
22 #include "wx/msw/private/comptr.h"
23 #include "wx/msw/wrapwin.h"
24 #include "wx/msw/missing.h"
25 #include "wx/msw/webview_missing.h"
26 #include "wx/sharedptr.h"
27 #include "wx/vector.h"
29 struct IHTMLDocument2
;
31 struct IMarkupPointer
;
35 class DocHostUIHandler
;
37 class wxIInternetProtocol
;
39 class WXDLLIMPEXP_WEBVIEW wxWebViewIE
: public wxWebView
45 wxWebViewIE(wxWindow
* parent
,
47 const wxString
& url
= wxWebViewDefaultURLStr
,
48 const wxPoint
& pos
= wxDefaultPosition
,
49 const wxSize
& size
= wxDefaultSize
,
51 const wxString
& name
= wxWebViewNameStr
)
53 Create(parent
, id
, url
, pos
, size
, style
, name
);
58 bool Create(wxWindow
* parent
,
60 const wxString
& url
= wxWebViewDefaultURLStr
,
61 const wxPoint
& pos
= wxDefaultPosition
,
62 const wxSize
& size
= wxDefaultSize
,
64 const wxString
& name
= wxWebViewNameStr
);
66 virtual void LoadURL(const wxString
& url
);
67 virtual void LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
);
68 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetBackwardHistory();
69 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetForwardHistory();
71 virtual bool CanGoForward() const;
72 virtual bool CanGoBack() const;
73 virtual void GoBack();
74 virtual void GoForward();
75 virtual void ClearHistory();
76 virtual void EnableHistory(bool enable
= true);
78 virtual void Reload(wxWebViewReloadFlags flags
= wxWEBVIEW_RELOAD_DEFAULT
);
80 virtual wxString
GetPageSource() const;
81 virtual wxString
GetPageText() const;
83 virtual bool IsBusy() const;
84 virtual wxString
GetCurrentURL() const;
85 virtual wxString
GetCurrentTitle() const;
87 virtual void SetZoomType(wxWebViewZoomType
);
88 virtual wxWebViewZoomType
GetZoomType() const;
89 virtual bool CanSetZoomType(wxWebViewZoomType
) const;
93 virtual wxWebViewZoom
GetZoom() const;
94 virtual void SetZoom(wxWebViewZoom zoom
);
97 virtual bool CanCut() const;
98 virtual bool CanCopy() const;
99 virtual bool CanPaste() const;
102 virtual void Paste();
104 //Undo / redo functionality
105 virtual bool CanUndo() const;
106 virtual bool CanRedo() const;
111 virtual long Find(const wxString
& text
, int flags
= wxWEBVIEW_FIND_DEFAULT
);
114 virtual void SetEditable(bool enable
= true);
115 virtual bool IsEditable() const;
118 virtual void SelectAll();
119 virtual bool HasSelection() const;
120 virtual void DeleteSelection();
121 virtual wxString
GetSelectedText() const;
122 virtual wxString
GetSelectedSource() const;
123 virtual void ClearSelection();
125 virtual void RunScript(const wxString
& javascript
);
127 //Virtual Filesystem Support
128 virtual void RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
);
130 virtual void* GetNativeBackend() const { return m_webBrowser
; }
132 // ---- IE-specific methods
134 // FIXME: I seem to be able to access remote webpages even in offline mode...
135 bool IsOfflineMode();
136 void SetOfflineMode(bool offline
);
138 wxWebViewZoom
GetIETextZoom() const;
139 void SetIETextZoom(wxWebViewZoom level
);
141 wxWebViewZoom
GetIEOpticalZoom() const;
142 void SetIEOpticalZoom(wxWebViewZoom level
);
144 void onActiveXEvent(wxActiveXEvent
& evt
);
145 void onEraseBg(wxEraseEvent
&) {}
147 DECLARE_EVENT_TABLE();
150 virtual void DoSetPage(const wxString
& html
, const wxString
& baseUrl
);
153 wxIEContainer
* m_container
;
154 wxAutomationObject m_ie
;
155 IWebBrowser2
* m_webBrowser
;
157 wxCOMPtr
<DocHostUIHandler
> m_uiHandler
;
159 //We store the current zoom type;
160 wxWebViewZoomType m_zoomType
;
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.
167 //We manage our own history, the history list contains the history items
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.
171 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > m_historyList
;
172 wxVector
<ClassFactory
*> m_factories
;
173 int m_historyPosition
;
174 bool m_historyLoadingFromList
;
175 bool m_historyEnabled
;
177 //We store find flag, results and position.
178 wxVector
<wxFindPointers
> m_findPointers
;
183 //Generic helper functions
184 bool CanExecCommand(wxString command
) const;
185 void ExecCommand(wxString command
);
186 wxCOMPtr
<IHTMLDocument2
> GetDocument() const;
187 bool IsElementVisible(IHTMLElement
* elm
);
188 //Find helper functions.
189 void FindInternal(const wxString
& text
, int flags
, int internal_flag
);
190 long FindNext(int direction
= 1);
192 //Toggles control features see INTERNETFEATURELIST for values.
193 bool EnableControlFeature(long flag
, bool enable
= true);
195 wxDECLARE_DYNAMIC_CLASS(wxWebViewIE
);
198 class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryIE
: public wxWebViewFactory
201 virtual wxWebView
* Create() { return new wxWebViewIE
; }
202 virtual wxWebView
* Create(wxWindow
* parent
,
204 const wxString
& url
= wxWebViewDefaultURLStr
,
205 const wxPoint
& pos
= wxDefaultPosition
,
206 const wxSize
& size
= wxDefaultSize
,
208 const wxString
& name
= wxWebViewNameStr
)
209 { return new wxWebViewIE(parent
, id
, url
, pos
, size
, style
, name
); }
212 class VirtualProtocol
: public wxIInternetProtocol
215 wxIInternetProtocolSink
* m_protocolSink
;
220 wxSharedPtr
<wxWebViewHandler
> m_handler
;
223 VirtualProtocol(wxSharedPtr
<wxWebViewHandler
> handler
);
224 ~VirtualProtocol() {}
227 DECLARE_IUNKNOWN_METHODS
;
229 //IInternetProtocolRoot
230 HRESULT STDMETHODCALLTYPE
Abort(HRESULT
WXUNUSED(hrReason
),
231 DWORD
WXUNUSED(dwOptions
))
232 { return E_NOTIMPL
; }
233 HRESULT STDMETHODCALLTYPE
Continue(wxPROTOCOLDATA
*WXUNUSED(pProtocolData
))
235 HRESULT STDMETHODCALLTYPE
Resume() { return S_OK
; }
236 HRESULT STDMETHODCALLTYPE
Start(LPCWSTR szUrl
,
237 wxIInternetProtocolSink
*pOIProtSink
,
238 wxIInternetBindInfo
*pOIBindInfo
,
240 HANDLE_PTR dwReserved
);
241 HRESULT STDMETHODCALLTYPE
Suspend() { return S_OK
; }
242 HRESULT STDMETHODCALLTYPE
Terminate(DWORD
WXUNUSED(dwOptions
)) { return S_OK
; }
245 HRESULT STDMETHODCALLTYPE
LockRequest(DWORD
WXUNUSED(dwOptions
))
247 HRESULT STDMETHODCALLTYPE
Read(void *pv
, ULONG cb
, ULONG
*pcbRead
);
248 HRESULT STDMETHODCALLTYPE
Seek(LARGE_INTEGER
WXUNUSED(dlibMove
),
249 DWORD
WXUNUSED(dwOrigin
),
250 ULARGE_INTEGER
* WXUNUSED(plibNewPosition
))
252 HRESULT STDMETHODCALLTYPE
UnlockRequest() { return S_OK
; }
255 class ClassFactory
: public IClassFactory
258 ClassFactory(wxSharedPtr
<wxWebViewHandler
> handler
) : m_handler(handler
)
261 wxString
GetName() { return m_handler
->GetName(); }
264 HRESULT STDMETHODCALLTYPE
CreateInstance(IUnknown
* pUnkOuter
,
265 REFIID riid
, void** ppvObject
);
266 HRESULT STDMETHODCALLTYPE
LockServer(BOOL fLock
);
269 DECLARE_IUNKNOWN_METHODS
;
272 wxSharedPtr
<wxWebViewHandler
> m_handler
;
275 class wxIEContainer
: public wxActiveXContainer
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
);
282 DocHostUIHandler
* m_uiHandler
;
285 class DocHostUIHandler
: public wxIDocHostUIHandler
288 DocHostUIHandler(wxWebView
* browser
) { m_browser
= browser
; }
289 ~DocHostUIHandler() {};
291 virtual HRESULT wxSTDCALL
ShowContextMenu(DWORD dwID
, POINT
*ppt
,
292 IUnknown
*pcmdtReserved
,
293 IDispatch
*pdispReserved
);
295 virtual HRESULT wxSTDCALL
GetHostInfo(DOCHOSTUIINFO
*pInfo
);
297 virtual HRESULT wxSTDCALL
ShowUI(DWORD dwID
,
298 IOleInPlaceActiveObject
*pActiveObject
,
299 IOleCommandTarget
*pCommandTarget
,
300 IOleInPlaceFrame
*pFrame
,
301 IOleInPlaceUIWindow
*pDoc
);
303 virtual HRESULT wxSTDCALL
HideUI(void);
305 virtual HRESULT wxSTDCALL
UpdateUI(void);
307 virtual HRESULT wxSTDCALL
EnableModeless(BOOL fEnable
);
309 virtual HRESULT wxSTDCALL
OnDocWindowActivate(BOOL fActivate
);
311 virtual HRESULT wxSTDCALL
OnFrameWindowActivate(BOOL fActivate
);
313 virtual HRESULT wxSTDCALL
ResizeBorder(LPCRECT prcBorder
,
314 IOleInPlaceUIWindow
*pUIWindow
,
317 virtual HRESULT wxSTDCALL
TranslateAccelerator(LPMSG lpMsg
,
318 const GUID
*pguidCmdGroup
,
321 virtual HRESULT wxSTDCALL
GetOptionKeyPath(LPOLESTR
*pchKey
,
324 virtual HRESULT wxSTDCALL
GetDropTarget(IDropTarget
*pDropTarget
,
325 IDropTarget
**ppDropTarget
);
327 virtual HRESULT wxSTDCALL
GetExternal(IDispatch
**ppDispatch
);
329 virtual HRESULT wxSTDCALL
TranslateUrl(DWORD dwTranslate
,
331 OLECHAR
**ppchURLOut
);
333 virtual HRESULT wxSTDCALL
FilterDataObject(IDataObject
*pDO
,
334 IDataObject
**ppDORet
);
336 DECLARE_IUNKNOWN_METHODS
;
339 wxWebView
* m_browser
;
345 wxFindPointers(wxIMarkupPointer
*ptrBegin
, wxIMarkupPointer
*ptrEnd
)
350 //The two markup pointers.
351 wxIMarkupPointer
*begin
, *end
;
354 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
356 #endif // wxWebViewIE_H