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 wxString
GetName() { return m_handler
->GetName(); }
250 HRESULT STDMETHODCALLTYPE
CreateInstance(IUnknown
* pUnkOuter
,
251 REFIID riid
, void** ppvObject
);
252 HRESULT STDMETHODCALLTYPE
LockServer(BOOL fLock
);
255 DECLARE_IUNKNOWN_METHODS
;
258 wxSharedPtr
<wxWebViewHandler
> m_handler
;
261 class wxIEContainer
: public wxActiveXContainer
264 wxIEContainer(wxWindow
*parent
, REFIID iid
, IUnknown
*pUnk
, DocHostUIHandler
* uiHandler
= NULL
);
265 virtual ~wxIEContainer();
266 virtual bool QueryClientSiteInterface(REFIID iid
, void **_interface
, const char *&desc
);
268 DocHostUIHandler
* m_uiHandler
;
271 class DocHostUIHandler
: public wxIDocHostUIHandler
274 DocHostUIHandler() {};
275 ~DocHostUIHandler() {};
276 virtual HRESULT wxSTDCALL
ShowContextMenu(DWORD dwID
, POINT
*ppt
,
277 IUnknown
*pcmdtReserved
,
278 IDispatch
*pdispReserved
);
280 virtual HRESULT wxSTDCALL
GetHostInfo(DOCHOSTUIINFO
*pInfo
);
282 virtual HRESULT wxSTDCALL
ShowUI(DWORD dwID
,
283 IOleInPlaceActiveObject
*pActiveObject
,
284 IOleCommandTarget
*pCommandTarget
,
285 IOleInPlaceFrame
*pFrame
,
286 IOleInPlaceUIWindow
*pDoc
);
288 virtual HRESULT wxSTDCALL
HideUI(void);
290 virtual HRESULT wxSTDCALL
UpdateUI(void);
292 virtual HRESULT wxSTDCALL
EnableModeless(BOOL fEnable
);
294 virtual HRESULT wxSTDCALL
OnDocWindowActivate(BOOL fActivate
);
296 virtual HRESULT wxSTDCALL
OnFrameWindowActivate(BOOL fActivate
);
298 virtual HRESULT wxSTDCALL
ResizeBorder(LPCRECT prcBorder
,
299 IOleInPlaceUIWindow
*pUIWindow
,
302 virtual HRESULT wxSTDCALL
TranslateAccelerator(LPMSG lpMsg
,
303 const GUID
*pguidCmdGroup
,
306 virtual HRESULT wxSTDCALL
GetOptionKeyPath(LPOLESTR
*pchKey
,
309 virtual HRESULT wxSTDCALL
GetDropTarget(IDropTarget
*pDropTarget
,
310 IDropTarget
**ppDropTarget
);
312 virtual HRESULT wxSTDCALL
GetExternal(IDispatch
**ppDispatch
);
314 virtual HRESULT wxSTDCALL
TranslateUrl(DWORD dwTranslate
,
316 OLECHAR
**ppchURLOut
);
318 virtual HRESULT wxSTDCALL
FilterDataObject(IDataObject
*pDO
,
319 IDataObject
**ppDORet
);
321 DECLARE_IUNKNOWN_METHODS
;
327 wxFindPointers(wxIMarkupPointer
*ptrBegin
, wxIMarkupPointer
*ptrEnd
)
332 //The two markup pointers.
333 wxIMarkupPointer
*begin
, *end
;
336 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
338 #endif // wxWebViewIE_H