]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/webview_ie.h
Somehow, setting a tint color makes gauge work :/.
[wxWidgets.git] / include / wx / msw / webview_ie.h
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 /////////////////////////////////////////////////////////////////////////////
8
9 #ifndef wxWebViewIE_H
10 #define wxWebViewIE_H
11
12 #include "wx/setup.h"
13
14 #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
15
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"
27
28 struct IHTMLDocument2;
29 struct IHTMLElement;
30 struct IMarkupPointer;
31 class wxFSFile;
32 class ClassFactory;
33 class wxIEContainer;
34 class DocHostUIHandler;
35 class wxFindPointers;
36 class wxIInternetProtocol;
37
38 class WXDLLIMPEXP_WEBVIEW wxWebViewIE : public wxWebView
39 {
40 public:
41
42 wxWebViewIE() {}
43
44 wxWebViewIE(wxWindow* parent,
45 wxWindowID id,
46 const wxString& url = wxWebViewDefaultURLStr,
47 const wxPoint& pos = wxDefaultPosition,
48 const wxSize& size = wxDefaultSize,
49 long style = 0,
50 const wxString& name = wxWebViewNameStr)
51 {
52 Create(parent, id, url, pos, size, style, name);
53 }
54
55 ~wxWebViewIE();
56
57 bool Create(wxWindow* parent,
58 wxWindowID id,
59 const wxString& url = wxWebViewDefaultURLStr,
60 const wxPoint& pos = wxDefaultPosition,
61 const wxSize& size = wxDefaultSize,
62 long style = 0,
63 const wxString& name = wxWebViewNameStr);
64
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();
69
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);
76 virtual void Stop();
77 virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT);
78
79 virtual wxString GetPageSource() const;
80 virtual wxString GetPageText() const;
81
82 virtual bool IsBusy() const;
83 virtual wxString GetCurrentURL() const;
84 virtual wxString GetCurrentTitle() const;
85
86 virtual void SetZoomType(wxWebViewZoomType);
87 virtual wxWebViewZoomType GetZoomType() const;
88 virtual bool CanSetZoomType(wxWebViewZoomType) const;
89
90 virtual void Print();
91
92 virtual wxWebViewZoom GetZoom() const;
93 virtual void SetZoom(wxWebViewZoom zoom);
94
95 //Clipboard functions
96 virtual bool CanCut() const;
97 virtual bool CanCopy() const;
98 virtual bool CanPaste() const;
99 virtual void Cut();
100 virtual void Copy();
101 virtual void Paste();
102
103 //Undo / redo functionality
104 virtual bool CanUndo() const;
105 virtual bool CanRedo() const;
106 virtual void Undo();
107 virtual void Redo();
108
109 //Find function
110 virtual long Find(const wxString& text, int flags = wxWEBVIEW_FIND_DEFAULT);
111
112 //Editing functions
113 virtual void SetEditable(bool enable = true);
114 virtual bool IsEditable() const;
115
116 //Selection
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();
123
124 virtual void RunScript(const wxString& javascript);
125
126 //Virtual Filesystem Support
127 virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler);
128
129 virtual void* GetNativeBackend() const { return m_webBrowser; }
130
131 // ---- IE-specific methods
132
133 // FIXME: I seem to be able to access remote webpages even in offline mode...
134 bool IsOfflineMode();
135 void SetOfflineMode(bool offline);
136
137 wxWebViewZoom GetIETextZoom() const;
138 void SetIETextZoom(wxWebViewZoom level);
139
140 wxWebViewZoom GetIEOpticalZoom() const;
141 void SetIEOpticalZoom(wxWebViewZoom level);
142
143 void onActiveXEvent(wxActiveXEvent& evt);
144 void onEraseBg(wxEraseEvent&) {}
145
146 DECLARE_EVENT_TABLE();
147
148 protected:
149 virtual void DoSetPage(const wxString& html, const wxString& baseUrl);
150
151 private:
152 wxIEContainer* m_container;
153 wxAutomationObject m_ie;
154 IWebBrowser2* m_webBrowser;
155 DWORD m_dwCookie;
156 wxCOMPtr<DocHostUIHandler> m_uiHandler;
157
158 //We store the current zoom type;
159 wxWebViewZoomType m_zoomType;
160
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.
164 */
165 bool m_isBusy;
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;
175
176 //We store find flag, results and position.
177 wxVector<wxFindPointers> m_findPointers;
178 int m_findFlags;
179 wxString m_findText;
180 int m_findPosition;
181
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);
190 void FindClear();
191 //Toggles control features see INTERNETFEATURELIST for values.
192 bool EnableControlFeature(long flag, bool enable = true);
193
194 wxDECLARE_DYNAMIC_CLASS(wxWebViewIE);
195 };
196
197 class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryIE : public wxWebViewFactory
198 {
199 public:
200 virtual wxWebView* Create() { return new wxWebViewIE; }
201 virtual wxWebView* Create(wxWindow* parent,
202 wxWindowID id,
203 const wxString& url = wxWebViewDefaultURLStr,
204 const wxPoint& pos = wxDefaultPosition,
205 const wxSize& size = wxDefaultSize,
206 long style = 0,
207 const wxString& name = wxWebViewNameStr)
208 { return new wxWebViewIE(parent, id, url, pos, size, style, name); }
209 };
210
211 class VirtualProtocol : public wxIInternetProtocol
212 {
213 protected:
214 wxIInternetProtocolSink* m_protocolSink;
215 wxString m_html;
216 VOID * fileP;
217
218 wxFSFile* m_file;
219 wxSharedPtr<wxWebViewHandler> m_handler;
220
221 public:
222 VirtualProtocol(wxSharedPtr<wxWebViewHandler> handler);
223 virtual ~VirtualProtocol() {}
224
225 //IUnknown
226 DECLARE_IUNKNOWN_METHODS;
227
228 //IInternetProtocolRoot
229 HRESULT STDMETHODCALLTYPE Abort(HRESULT WXUNUSED(hrReason),
230 DWORD WXUNUSED(dwOptions))
231 { return E_NOTIMPL; }
232 HRESULT STDMETHODCALLTYPE Continue(wxPROTOCOLDATA *WXUNUSED(pProtocolData))
233 { return S_OK; }
234 HRESULT STDMETHODCALLTYPE Resume() { return S_OK; }
235 HRESULT STDMETHODCALLTYPE Start(LPCWSTR szUrl,
236 wxIInternetProtocolSink *pOIProtSink,
237 wxIInternetBindInfo *pOIBindInfo,
238 DWORD grfPI,
239 HANDLE_PTR dwReserved);
240 HRESULT STDMETHODCALLTYPE Suspend() { return S_OK; }
241 HRESULT STDMETHODCALLTYPE Terminate(DWORD WXUNUSED(dwOptions)) { return S_OK; }
242
243 //IInternetProtocol
244 HRESULT STDMETHODCALLTYPE LockRequest(DWORD WXUNUSED(dwOptions))
245 { return S_OK; }
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))
250 { return E_FAIL; }
251 HRESULT STDMETHODCALLTYPE UnlockRequest() { return S_OK; }
252 };
253
254 class ClassFactory : public IClassFactory
255 {
256 public:
257 ClassFactory(wxSharedPtr<wxWebViewHandler> handler) : m_handler(handler)
258 { AddRef(); }
259 virtual ~ClassFactory() {}
260
261 wxString GetName() { return m_handler->GetName(); }
262
263 //IClassFactory
264 HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown* pUnkOuter,
265 REFIID riid, void** ppvObject);
266 HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock);
267
268 //IUnknown
269 DECLARE_IUNKNOWN_METHODS;
270
271 private:
272 wxSharedPtr<wxWebViewHandler> m_handler;
273 };
274
275 class wxIEContainer : public wxActiveXContainer
276 {
277 public:
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);
281 private:
282 DocHostUIHandler* m_uiHandler;
283 };
284
285 class DocHostUIHandler : public wxIDocHostUIHandler
286 {
287 public:
288 DocHostUIHandler(wxWebView* browser) { m_browser = browser; }
289 virtual ~DocHostUIHandler() {}
290
291 virtual HRESULT wxSTDCALL ShowContextMenu(DWORD dwID, POINT *ppt,
292 IUnknown *pcmdtReserved,
293 IDispatch *pdispReserved);
294
295 virtual HRESULT wxSTDCALL GetHostInfo(DOCHOSTUIINFO *pInfo);
296
297 virtual HRESULT wxSTDCALL ShowUI(DWORD dwID,
298 IOleInPlaceActiveObject *pActiveObject,
299 IOleCommandTarget *pCommandTarget,
300 IOleInPlaceFrame *pFrame,
301 IOleInPlaceUIWindow *pDoc);
302
303 virtual HRESULT wxSTDCALL HideUI(void);
304
305 virtual HRESULT wxSTDCALL UpdateUI(void);
306
307 virtual HRESULT wxSTDCALL EnableModeless(BOOL fEnable);
308
309 virtual HRESULT wxSTDCALL OnDocWindowActivate(BOOL fActivate);
310
311 virtual HRESULT wxSTDCALL OnFrameWindowActivate(BOOL fActivate);
312
313 virtual HRESULT wxSTDCALL ResizeBorder(LPCRECT prcBorder,
314 IOleInPlaceUIWindow *pUIWindow,
315 BOOL fRameWindow);
316
317 virtual HRESULT wxSTDCALL TranslateAccelerator(LPMSG lpMsg,
318 const GUID *pguidCmdGroup,
319 DWORD nCmdID);
320
321 virtual HRESULT wxSTDCALL GetOptionKeyPath(LPOLESTR *pchKey,
322 DWORD dw);
323
324 virtual HRESULT wxSTDCALL GetDropTarget(IDropTarget *pDropTarget,
325 IDropTarget **ppDropTarget);
326
327 virtual HRESULT wxSTDCALL GetExternal(IDispatch **ppDispatch);
328
329 virtual HRESULT wxSTDCALL TranslateUrl(DWORD dwTranslate,
330 OLECHAR *pchURLIn,
331 OLECHAR **ppchURLOut);
332
333 virtual HRESULT wxSTDCALL FilterDataObject(IDataObject *pDO,
334 IDataObject **ppDORet);
335 //IUnknown
336 DECLARE_IUNKNOWN_METHODS;
337
338 private:
339 wxWebView* m_browser;
340 };
341
342 class wxFindPointers
343 {
344 public:
345 wxFindPointers(wxIMarkupPointer *ptrBegin, wxIMarkupPointer *ptrEnd)
346 {
347 begin = ptrBegin;
348 end = ptrEnd;
349 }
350 //The two markup pointers.
351 wxIMarkupPointer *begin, *end;
352 };
353
354 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)
355
356 #endif // wxWebViewIE_H