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
= wxWEB_VIEW_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
= wxWEB_VIEW_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 VirtualProtocol
: public wxIInternetProtocol
201 wxIInternetProtocolSink
* m_protocolSink
;
206 wxSharedPtr
<wxWebViewHandler
> m_handler
;
209 VirtualProtocol(wxSharedPtr
<wxWebViewHandler
> handler
);
210 ~VirtualProtocol() {}
213 DECLARE_IUNKNOWN_METHODS
;
215 //IInternetProtocolRoot
216 HRESULT STDMETHODCALLTYPE
Abort(HRESULT
WXUNUSED(hrReason
),
217 DWORD
WXUNUSED(dwOptions
))
218 { return E_NOTIMPL
; }
219 HRESULT STDMETHODCALLTYPE
Continue(wxPROTOCOLDATA
*WXUNUSED(pProtocolData
))
221 HRESULT STDMETHODCALLTYPE
Resume() { return S_OK
; }
222 HRESULT STDMETHODCALLTYPE
Start(LPCWSTR szUrl
,
223 wxIInternetProtocolSink
*pOIProtSink
,
224 wxIInternetBindInfo
*pOIBindInfo
,
226 HANDLE_PTR dwReserved
);
227 HRESULT STDMETHODCALLTYPE
Suspend() { return S_OK
; }
228 HRESULT STDMETHODCALLTYPE
Terminate(DWORD
WXUNUSED(dwOptions
)) { return S_OK
; }
231 HRESULT STDMETHODCALLTYPE
LockRequest(DWORD
WXUNUSED(dwOptions
))
233 HRESULT STDMETHODCALLTYPE
Read(void *pv
, ULONG cb
, ULONG
*pcbRead
);
234 HRESULT STDMETHODCALLTYPE
Seek(LARGE_INTEGER
WXUNUSED(dlibMove
),
235 DWORD
WXUNUSED(dwOrigin
),
236 ULARGE_INTEGER
* WXUNUSED(plibNewPosition
))
238 HRESULT STDMETHODCALLTYPE
UnlockRequest() { return S_OK
; }
241 class ClassFactory
: public IClassFactory
244 ClassFactory(wxSharedPtr
<wxWebViewHandler
> handler
) : m_handler(handler
) {}
247 HRESULT STDMETHODCALLTYPE
CreateInstance(IUnknown
* pUnkOuter
,
248 REFIID riid
, void** ppvObject
);
249 HRESULT STDMETHODCALLTYPE
LockServer(BOOL fLock
);
252 DECLARE_IUNKNOWN_METHODS
;
255 wxSharedPtr
<wxWebViewHandler
> m_handler
;
258 class wxIEContainer
: public wxActiveXContainer
261 wxIEContainer(wxWindow
*parent
, REFIID iid
, IUnknown
*pUnk
, DocHostUIHandler
* uiHandler
= NULL
);
262 virtual ~wxIEContainer();
263 virtual bool QueryClientSiteInterface(REFIID iid
, void **_interface
, const char *&desc
);
265 DocHostUIHandler
* m_uiHandler
;
268 class DocHostUIHandler
: public wxIDocHostUIHandler
271 DocHostUIHandler() {};
272 ~DocHostUIHandler() {};
273 virtual HRESULT wxSTDCALL
ShowContextMenu(DWORD dwID
, POINT
*ppt
,
274 IUnknown
*pcmdtReserved
,
275 IDispatch
*pdispReserved
);
277 virtual HRESULT wxSTDCALL
GetHostInfo(DOCHOSTUIINFO
*pInfo
);
279 virtual HRESULT wxSTDCALL
ShowUI(DWORD dwID
,
280 IOleInPlaceActiveObject
*pActiveObject
,
281 IOleCommandTarget
*pCommandTarget
,
282 IOleInPlaceFrame
*pFrame
,
283 IOleInPlaceUIWindow
*pDoc
);
285 virtual HRESULT wxSTDCALL
HideUI(void);
287 virtual HRESULT wxSTDCALL
UpdateUI(void);
289 virtual HRESULT wxSTDCALL
EnableModeless(BOOL fEnable
);
291 virtual HRESULT wxSTDCALL
OnDocWindowActivate(BOOL fActivate
);
293 virtual HRESULT wxSTDCALL
OnFrameWindowActivate(BOOL fActivate
);
295 virtual HRESULT wxSTDCALL
ResizeBorder(LPCRECT prcBorder
,
296 IOleInPlaceUIWindow
*pUIWindow
,
299 virtual HRESULT wxSTDCALL
TranslateAccelerator(LPMSG lpMsg
,
300 const GUID
*pguidCmdGroup
,
303 virtual HRESULT wxSTDCALL
GetOptionKeyPath(LPOLESTR
*pchKey
,
306 virtual HRESULT wxSTDCALL
GetDropTarget(IDropTarget
*pDropTarget
,
307 IDropTarget
**ppDropTarget
);
309 virtual HRESULT wxSTDCALL
GetExternal(IDispatch
**ppDispatch
);
311 virtual HRESULT wxSTDCALL
TranslateUrl(DWORD dwTranslate
,
313 OLECHAR
**ppchURLOut
);
315 virtual HRESULT wxSTDCALL
FilterDataObject(IDataObject
*pDO
,
316 IDataObject
**ppDORet
);
318 DECLARE_IUNKNOWN_METHODS
;
324 wxFindPointers(wxIMarkupPointer
*ptrBegin
, wxIMarkupPointer
*ptrEnd
)
329 //The two markup pointers.
330 wxIMarkupPointer
*begin
, *end
;
333 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
335 #endif // wxWebViewIE_H