1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/msw/webview_ie.h
3 // Purpose: wxMSW IE wxWebView backend
4 // Author: Marianne Gagnon
5 // Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
14 #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
16 #include "wx/control.h"
17 #include "wx/webview.h"
18 #include "wx/msw/ole/automtn.h"
19 #include "wx/msw/ole/activex.h"
20 #include "wx/msw/ole/oleutils.h"
21 #include "wx/msw/private/comptr.h"
22 #include "wx/msw/wrapwin.h"
23 #include "wx/msw/missing.h"
24 #include "wx/msw/webview_missing.h"
25 #include "wx/sharedptr.h"
26 #include "wx/vector.h"
28 struct IHTMLDocument2
;
30 struct IMarkupPointer
;
34 class DocHostUIHandler
;
36 class wxIInternetProtocol
;
38 class WXDLLIMPEXP_WEBVIEW wxWebViewIE
: public wxWebView
44 wxWebViewIE(wxWindow
* parent
,
46 const wxString
& url
= wxWebViewDefaultURLStr
,
47 const wxPoint
& pos
= wxDefaultPosition
,
48 const wxSize
& size
= wxDefaultSize
,
50 const wxString
& name
= wxWebViewNameStr
)
52 Create(parent
, id
, url
, pos
, size
, style
, name
);
57 bool Create(wxWindow
* parent
,
59 const wxString
& url
= wxWebViewDefaultURLStr
,
60 const wxPoint
& pos
= wxDefaultPosition
,
61 const wxSize
& size
= wxDefaultSize
,
63 const wxString
& name
= wxWebViewNameStr
);
65 virtual void LoadURL(const wxString
& url
);
66 virtual void LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
);
67 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetBackwardHistory();
68 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetForwardHistory();
70 virtual bool CanGoForward() const;
71 virtual bool CanGoBack() const;
72 virtual void GoBack();
73 virtual void GoForward();
74 virtual void ClearHistory();
75 virtual void EnableHistory(bool enable
= true);
77 virtual void Reload(wxWebViewReloadFlags flags
= wxWEBVIEW_RELOAD_DEFAULT
);
79 virtual wxString
GetPageSource() const;
80 virtual wxString
GetPageText() const;
82 virtual bool IsBusy() const;
83 virtual wxString
GetCurrentURL() const;
84 virtual wxString
GetCurrentTitle() const;
86 virtual void SetZoomType(wxWebViewZoomType
);
87 virtual wxWebViewZoomType
GetZoomType() const;
88 virtual bool CanSetZoomType(wxWebViewZoomType
) const;
92 virtual wxWebViewZoom
GetZoom() const;
93 virtual void SetZoom(wxWebViewZoom zoom
);
96 virtual bool CanCut() const;
97 virtual bool CanCopy() const;
98 virtual bool CanPaste() const;
101 virtual void Paste();
103 //Undo / redo functionality
104 virtual bool CanUndo() const;
105 virtual bool CanRedo() const;
110 virtual long Find(const wxString
& text
, int flags
= wxWEBVIEW_FIND_DEFAULT
);
113 virtual void SetEditable(bool enable
= true);
114 virtual bool IsEditable() const;
117 virtual void SelectAll();
118 virtual bool HasSelection() const;
119 virtual void DeleteSelection();
120 virtual wxString
GetSelectedText() const;
121 virtual wxString
GetSelectedSource() const;
122 virtual void ClearSelection();
124 virtual void RunScript(const wxString
& javascript
);
126 //Virtual Filesystem Support
127 virtual void RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
);
129 virtual void* GetNativeBackend() const { return m_webBrowser
; }
131 // ---- IE-specific methods
133 // FIXME: I seem to be able to access remote webpages even in offline mode...
134 bool IsOfflineMode();
135 void SetOfflineMode(bool offline
);
137 wxWebViewZoom
GetIETextZoom() const;
138 void SetIETextZoom(wxWebViewZoom level
);
140 wxWebViewZoom
GetIEOpticalZoom() const;
141 void SetIEOpticalZoom(wxWebViewZoom level
);
143 void onActiveXEvent(wxActiveXEvent
& evt
);
144 void onEraseBg(wxEraseEvent
&) {}
146 DECLARE_EVENT_TABLE();
149 virtual void DoSetPage(const wxString
& html
, const wxString
& baseUrl
);
152 wxIEContainer
* m_container
;
153 wxAutomationObject m_ie
;
154 IWebBrowser2
* m_webBrowser
;
156 wxCOMPtr
<DocHostUIHandler
> m_uiHandler
;
158 //We store the current zoom type;
159 wxWebViewZoomType m_zoomType
;
161 /** The "Busy" property of IWebBrowser2 does not always return busy when
162 * we'd want it to; this variable may be set to true in cases where the
163 * Busy property is false but should be true.
166 //We manage our own history, the history list contains the history items
167 //which are added as documentcomplete events arrive, unless we are loading
168 //an item from the history. The position is stored as an int, and reflects
169 //where we are in the history list.
170 wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > m_historyList
;
171 wxVector
<ClassFactory
*> m_factories
;
172 int m_historyPosition
;
173 bool m_historyLoadingFromList
;
174 bool m_historyEnabled
;
176 //We store find flag, results and position.
177 wxVector
<wxFindPointers
> m_findPointers
;
182 //Generic helper functions
183 bool CanExecCommand(wxString command
) const;
184 void ExecCommand(wxString command
);
185 wxCOMPtr
<IHTMLDocument2
> GetDocument() const;
186 bool IsElementVisible(wxCOMPtr
<IHTMLElement
> elm
);
187 //Find helper functions.
188 void FindInternal(const wxString
& text
, int flags
, int internal_flag
);
189 long FindNext(int direction
= 1);
191 //Toggles control features see INTERNETFEATURELIST for values.
192 bool EnableControlFeature(long flag
, bool enable
= true);
194 wxDECLARE_DYNAMIC_CLASS(wxWebViewIE
);
197 class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryIE
: public wxWebViewFactory
200 virtual wxWebView
* Create() { return new wxWebViewIE
; }
201 virtual wxWebView
* Create(wxWindow
* parent
,
203 const wxString
& url
= wxWebViewDefaultURLStr
,
204 const wxPoint
& pos
= wxDefaultPosition
,
205 const wxSize
& size
= wxDefaultSize
,
207 const wxString
& name
= wxWebViewNameStr
)
208 { return new wxWebViewIE(parent
, id
, url
, pos
, size
, style
, name
); }
211 class VirtualProtocol
: public wxIInternetProtocol
214 wxIInternetProtocolSink
* m_protocolSink
;
219 wxSharedPtr
<wxWebViewHandler
> m_handler
;
222 VirtualProtocol(wxSharedPtr
<wxWebViewHandler
> handler
);
223 virtual ~VirtualProtocol() {}
226 DECLARE_IUNKNOWN_METHODS
;
228 //IInternetProtocolRoot
229 HRESULT STDMETHODCALLTYPE
Abort(HRESULT
WXUNUSED(hrReason
),
230 DWORD
WXUNUSED(dwOptions
))
231 { return E_NOTIMPL
; }
232 HRESULT STDMETHODCALLTYPE
Continue(wxPROTOCOLDATA
*WXUNUSED(pProtocolData
))
234 HRESULT STDMETHODCALLTYPE
Resume() { return S_OK
; }
235 HRESULT STDMETHODCALLTYPE
Start(LPCWSTR szUrl
,
236 wxIInternetProtocolSink
*pOIProtSink
,
237 wxIInternetBindInfo
*pOIBindInfo
,
239 HANDLE_PTR dwReserved
);
240 HRESULT STDMETHODCALLTYPE
Suspend() { return S_OK
; }
241 HRESULT STDMETHODCALLTYPE
Terminate(DWORD
WXUNUSED(dwOptions
)) { return S_OK
; }
244 HRESULT STDMETHODCALLTYPE
LockRequest(DWORD
WXUNUSED(dwOptions
))
246 HRESULT STDMETHODCALLTYPE
Read(void *pv
, ULONG cb
, ULONG
*pcbRead
);
247 HRESULT STDMETHODCALLTYPE
Seek(LARGE_INTEGER
WXUNUSED(dlibMove
),
248 DWORD
WXUNUSED(dwOrigin
),
249 ULARGE_INTEGER
* WXUNUSED(plibNewPosition
))
251 HRESULT STDMETHODCALLTYPE
UnlockRequest() { return S_OK
; }
254 class ClassFactory
: public IClassFactory
257 ClassFactory(wxSharedPtr
<wxWebViewHandler
> handler
) : m_handler(handler
)
259 virtual ~ClassFactory() {}
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 virtual ~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