]>
Commit | Line | Data |
---|---|---|
61b98a2d | 1 | ///////////////////////////////////////////////////////////////////////////// |
8290e3cd | 2 | // Name: src/msw/webview_ie.cpp |
61b98a2d SL |
3 | // Purpose: wxMSW wxWebViewIE class implementation for web view component |
4 | // Author: Marianne Gagnon | |
5 | // Id: $Id$ | |
153530af | 6 | // Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton |
61b98a2d SL |
7 | // Licence: wxWindows licence |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
384b8d9f SL |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #if defined(__BORLANDC__) | |
14 | #pragma hdrstop | |
15 | #endif | |
16 | ||
8290e3cd | 17 | #include "wx/msw/webview_ie.h" |
61b98a2d | 18 | |
9d2f31db | 19 | #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE |
61b98a2d SL |
20 | |
21 | #include <olectl.h> | |
22 | #include <oleidl.h> | |
23 | #include <exdispid.h> | |
24 | #include <exdisp.h> | |
25 | #include <mshtml.h> | |
cd4e4673 | 26 | #include "wx/msw/registry.h" |
1d7d04d7 | 27 | #include "wx/msw/missing.h" |
7d3f6b4d | 28 | #include "wx/filesys.h" |
e924e848 | 29 | #include "wx/dynlib.h" |
f559d1a2 | 30 | #include <initguid.h> |
c1381581 | 31 | #include <wininet.h> |
f559d1a2 VZ |
32 | |
33 | /* These GUID definitions are our own implementation to support interfaces | |
34 | * normally in urlmon.h. See include/wx/msw/webview_ie.h | |
35 | */ | |
36 | ||
37 | namespace { | |
38 | ||
39 | DEFINE_GUID(wxIID_IInternetProtocolRoot,0x79eac9e3,0xbaf9,0x11ce,0x8c,0x82,0,0xaa,0,0x4b,0xa9,0xb); | |
40 | DEFINE_GUID(wxIID_IInternetProtocol,0x79eac9e4,0xbaf9,0x11ce,0x8c,0x82,0,0xaa,0,0x4b,0xa9,0xb); | |
accc94d5 | 41 | DEFINE_GUID(wxIID_IDocHostUIHandler, 0xbd3f23c0, 0xd43e, 0x11cf, 0x89, 0x3b, 0x00, 0xaa, 0x00, 0xbd, 0xce, 0x1a); |
e52aec97 SL |
42 | DEFINE_GUID(wxIID_IHTMLElement2,0x3050f434,0x98b5,0x11cf,0xbb,0x82,0,0xaa,0,0xbd,0xce,0x0b); |
43 | DEFINE_GUID(wxIID_IMarkupServices,0x3050f4a0,0x98b5,0x11cf,0xbb,0x82,0,0xaa,0,0xbd,0xce,0x0b); | |
44 | DEFINE_GUID(wxIID_IMarkupContainer,0x3050f5f9,0x98b5,0x11cf,0xbb,0x82,0,0xaa,0,0xbd,0xce,0x0b); | |
f559d1a2 | 45 | |
66ac0400 SL |
46 | enum //Internal find flags |
47 | { | |
236cff73 SL |
48 | wxWEBVIEW_FIND_ADD_POINTERS = 0x0001, |
49 | wxWEBVIEW_FIND_REMOVE_HIGHLIGHT = 0x0002 | |
66ac0400 SL |
50 | }; |
51 | ||
f559d1a2 | 52 | } |
7d3f6b4d | 53 | |
c1381581 SL |
54 | //Convenience function for error conversion |
55 | #define WX_ERROR_CASE(error, wxerror) \ | |
56 | case error: \ | |
57 | event.SetString(#error); \ | |
58 | event.SetInt(wxerror); \ | |
59 | break; | |
60 | ||
cddf4541 SL |
61 | wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewIE, wxWebView); |
62 | ||
61b98a2d | 63 | BEGIN_EVENT_TABLE(wxWebViewIE, wxControl) |
97ad1425 SL |
64 | EVT_ACTIVEX(wxID_ANY, wxWebViewIE::onActiveXEvent) |
65 | EVT_ERASE_BACKGROUND(wxWebViewIE::onEraseBg) | |
61b98a2d SL |
66 | END_EVENT_TABLE() |
67 | ||
68 | bool wxWebViewIE::Create(wxWindow* parent, | |
69 | wxWindowID id, | |
70 | const wxString& url, | |
71 | const wxPoint& pos, | |
72 | const wxSize& size, | |
73 | long style, | |
74 | const wxString& name) | |
75 | { | |
76 | if (!wxControl::Create(parent, id, pos, size, style, | |
77 | wxDefaultValidator, name)) | |
78 | { | |
79 | return false; | |
80 | } | |
81 | ||
82 | m_webBrowser = NULL; | |
61b98a2d | 83 | m_isBusy = false; |
74af0b13 SL |
84 | m_historyLoadingFromList = false; |
85 | m_historyEnabled = true; | |
86 | m_historyPosition = -1; | |
236cff73 | 87 | m_zoomType = wxWEBVIEW_ZOOM_TYPE_TEXT; |
66ac0400 | 88 | FindClear(); |
61b98a2d SL |
89 | |
90 | if (::CoCreateInstance(CLSID_WebBrowser, NULL, | |
91 | CLSCTX_INPROC_SERVER, // CLSCTX_INPROC, | |
92 | IID_IWebBrowser2 , (void**)&m_webBrowser) != 0) | |
93 | { | |
94 | wxLogError("Failed to initialize IE, CoCreateInstance returned an error"); | |
95 | return false; | |
96 | } | |
97 | ||
98 | m_ie.SetDispatchPtr(m_webBrowser); // wxAutomationObject will release itself | |
99 | ||
100 | m_webBrowser->put_RegisterAsBrowser(VARIANT_TRUE); | |
101 | m_webBrowser->put_RegisterAsDropTarget(VARIANT_TRUE); | |
61b98a2d | 102 | |
c420d57b | 103 | m_uiHandler = new DocHostUIHandler(this); |
accc94d5 SL |
104 | |
105 | m_container = new wxIEContainer(this, IID_IWebBrowser2, m_webBrowser, m_uiHandler); | |
61b98a2d | 106 | |
9447a0d6 SL |
107 | EnableControlFeature(21 /* FEATURE_DISABLE_NAVIGATION_SOUNDS */); |
108 | ||
4d0dddc7 | 109 | LoadURL(url); |
61b98a2d SL |
110 | return true; |
111 | } | |
112 | ||
39498710 SL |
113 | wxWebViewIE::~wxWebViewIE() |
114 | { | |
8626e0b7 SL |
115 | wxDynamicLibrary urlMon(wxT("urlmon.dll")); |
116 | if(urlMon.HasSymbol(wxT("CoInternetGetSession"))) | |
39498710 | 117 | { |
8626e0b7 SL |
118 | typedef HRESULT (WINAPI *CoInternetGetSession_t)(DWORD, |
119 | wxIInternetSession**, | |
120 | DWORD); | |
121 | wxDYNLIB_FUNCTION(CoInternetGetSession_t, CoInternetGetSession, urlMon); | |
122 | ||
123 | wxIInternetSession* session; | |
124 | HRESULT res = (*pfnCoInternetGetSession)(0, &session, 0); | |
125 | if(FAILED(res)) | |
126 | { | |
127 | wxFAIL_MSG("Could not retrive internet session"); | |
128 | } | |
129 | ||
130 | for(unsigned int i = 0; i < m_factories.size(); i++) | |
131 | { | |
132 | session->UnregisterNameSpace(m_factories[i], | |
133 | (m_factories[i]->GetName()).wc_str()); | |
134 | m_factories[i]->Release(); | |
135 | } | |
39498710 | 136 | } |
66ac0400 | 137 | FindClear(); |
39498710 | 138 | } |
61b98a2d | 139 | |
4d0dddc7 | 140 | void wxWebViewIE::LoadURL(const wxString& url) |
61b98a2d | 141 | { |
e8d243a9 | 142 | m_ie.CallMethod("Navigate", wxConvertStringToOle(url)); |
61b98a2d SL |
143 | } |
144 | ||
a977376a | 145 | void wxWebViewIE::DoSetPage(const wxString& html, const wxString& baseUrl) |
61b98a2d | 146 | { |
7f98bdd6 | 147 | BSTR bstr = SysAllocString(OLESTR("")); |
61b98a2d SL |
148 | SAFEARRAY *psaStrings = SafeArrayCreateVector(VT_VARIANT, 0, 1); |
149 | if (psaStrings != NULL) | |
150 | { | |
151 | VARIANT *param; | |
152 | HRESULT hr = SafeArrayAccessData(psaStrings, (LPVOID*)¶m); | |
153 | param->vt = VT_BSTR; | |
154 | param->bstrVal = bstr; | |
442262d4 | 155 | |
7f98bdd6 | 156 | hr = SafeArrayUnaccessData(psaStrings); |
accc94d5 | 157 | |
f40f8e17 | 158 | wxCOMPtr<IHTMLDocument2> document(GetDocument()); |
e81ef297 SL |
159 | |
160 | if(!document) | |
161 | return; | |
162 | ||
61b98a2d | 163 | document->write(psaStrings); |
7f98bdd6 | 164 | document->close(); |
61b98a2d | 165 | |
61b98a2d | 166 | SafeArrayDestroy(psaStrings); |
442262d4 | 167 | |
7f98bdd6 SL |
168 | bstr = SysAllocString(html.wc_str()); |
169 | ||
170 | // Creates a new one-dimensional array | |
171 | psaStrings = SafeArrayCreateVector(VT_VARIANT, 0, 1); | |
172 | if (psaStrings != NULL) | |
173 | { | |
174 | hr = SafeArrayAccessData(psaStrings, (LPVOID*)¶m); | |
175 | param->vt = VT_BSTR; | |
176 | param->bstrVal = bstr; | |
177 | hr = SafeArrayUnaccessData(psaStrings); | |
178 | ||
179 | document = GetDocument(); | |
e81ef297 SL |
180 | |
181 | if(!document) | |
182 | return; | |
183 | ||
7f98bdd6 | 184 | document->write(psaStrings); |
7f98bdd6 SL |
185 | |
186 | // SafeArrayDestroy calls SysFreeString for each BSTR | |
187 | SafeArrayDestroy(psaStrings); | |
188 | ||
189 | //We send the events when we are done to mimic webkit | |
190 | //Navigated event | |
ce7fe42e | 191 | wxWebViewEvent event(wxEVT_WEBVIEW_NAVIGATED, |
7f98bdd6 SL |
192 | GetId(), baseUrl, ""); |
193 | event.SetEventObject(this); | |
194 | HandleWindowEvent(event); | |
195 | ||
196 | //Document complete event | |
ce7fe42e | 197 | event.SetEventType(wxEVT_WEBVIEW_LOADED); |
7f98bdd6 SL |
198 | event.SetEventObject(this); |
199 | HandleWindowEvent(event); | |
200 | } | |
201 | else | |
202 | { | |
203 | wxLogError("wxWebViewIE::SetPage() : psaStrings is NULL"); | |
204 | } | |
61b98a2d SL |
205 | } |
206 | else | |
207 | { | |
7f98bdd6 | 208 | wxLogError("wxWebViewIE::SetPage() : psaStrings is NULL during clear"); |
61b98a2d | 209 | } |
61b98a2d SL |
210 | } |
211 | ||
e669ddde | 212 | wxString wxWebViewIE::GetPageSource() const |
61b98a2d | 213 | { |
f40f8e17 | 214 | wxCOMPtr<IHTMLDocument2> document(GetDocument()); |
e81ef297 SL |
215 | |
216 | if(document) | |
7fbc727b | 217 | { |
f40f8e17 SL |
218 | wxCOMPtr<IHTMLElement> bodyTag; |
219 | wxCOMPtr<IHTMLElement> htmlTag; | |
e81ef297 SL |
220 | wxString source; |
221 | HRESULT hr = document->get_body(&bodyTag); | |
7fbc727b SL |
222 | if(SUCCEEDED(hr)) |
223 | { | |
e81ef297 SL |
224 | hr = bodyTag->get_parentElement(&htmlTag); |
225 | if(SUCCEEDED(hr)) | |
226 | { | |
227 | BSTR bstr; | |
228 | htmlTag->get_outerHTML(&bstr); | |
229 | source = wxString(bstr); | |
e81ef297 | 230 | } |
7fbc727b | 231 | } |
e81ef297 SL |
232 | return source; |
233 | } | |
234 | else | |
235 | { | |
236 | return ""; | |
237 | } | |
61b98a2d SL |
238 | } |
239 | ||
e669ddde | 240 | wxWebViewZoom wxWebViewIE::GetZoom() const |
61b98a2d | 241 | { |
8acbf08b SL |
242 | switch( m_zoomType ) |
243 | { | |
236cff73 | 244 | case wxWEBVIEW_ZOOM_TYPE_LAYOUT: |
8acbf08b | 245 | return GetIEOpticalZoom(); |
236cff73 | 246 | case wxWEBVIEW_ZOOM_TYPE_TEXT: |
8acbf08b SL |
247 | return GetIETextZoom(); |
248 | default: | |
249 | wxFAIL; | |
250 | } | |
423adfde SL |
251 | |
252 | //Dummy return to stop compiler warnings | |
236cff73 | 253 | return wxWEBVIEW_ZOOM_MEDIUM; |
1d7d04d7 | 254 | |
61b98a2d | 255 | } |
c5f417cb | 256 | |
61b98a2d SL |
257 | void wxWebViewIE::SetZoom(wxWebViewZoom zoom) |
258 | { | |
8acbf08b SL |
259 | switch( m_zoomType ) |
260 | { | |
236cff73 | 261 | case wxWEBVIEW_ZOOM_TYPE_LAYOUT: |
8acbf08b SL |
262 | SetIEOpticalZoom(zoom); |
263 | break; | |
236cff73 | 264 | case wxWEBVIEW_ZOOM_TYPE_TEXT: |
8acbf08b SL |
265 | SetIETextZoom(zoom); |
266 | break; | |
267 | default: | |
268 | wxFAIL; | |
269 | } | |
61b98a2d SL |
270 | } |
271 | ||
c5f417cb | 272 | void wxWebViewIE::SetIETextZoom(wxWebViewZoom level) |
61b98a2d | 273 | { |
1d7d04d7 | 274 | //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range |
c5f417cb SL |
275 | //is 0 to 4 so the check is unnecessary, these match exactly with the |
276 | //enum values | |
61b98a2d SL |
277 | VARIANT zoomVariant; |
278 | VariantInit (&zoomVariant); | |
279 | V_VT(&zoomVariant) = VT_I4; | |
280 | V_I4(&zoomVariant) = level; | |
281 | ||
8acbf08b SL |
282 | #if wxDEBUG_LEVEL |
283 | HRESULT result = | |
284 | #endif | |
285 | m_webBrowser->ExecWB(OLECMDID_ZOOM, | |
286 | OLECMDEXECOPT_DONTPROMPTUSER, | |
287 | &zoomVariant, NULL); | |
c5f417cb | 288 | wxASSERT(result == S_OK); |
61b98a2d SL |
289 | } |
290 | ||
e669ddde | 291 | wxWebViewZoom wxWebViewIE::GetIETextZoom() const |
61b98a2d SL |
292 | { |
293 | VARIANT zoomVariant; | |
294 | VariantInit (&zoomVariant); | |
295 | V_VT(&zoomVariant) = VT_I4; | |
61b98a2d | 296 | |
8acbf08b SL |
297 | #if wxDEBUG_LEVEL |
298 | HRESULT result = | |
299 | #endif | |
300 | m_webBrowser->ExecWB(OLECMDID_ZOOM, | |
301 | OLECMDEXECOPT_DONTPROMPTUSER, | |
302 | NULL, &zoomVariant); | |
c5f417cb | 303 | wxASSERT(result == S_OK); |
61b98a2d | 304 | |
c5f417cb SL |
305 | //We can safely cast here as we know that the range matches our enum |
306 | return static_cast<wxWebViewZoom>(V_I4(&zoomVariant)); | |
61b98a2d SL |
307 | } |
308 | ||
c5f417cb | 309 | void wxWebViewIE::SetIEOpticalZoom(wxWebViewZoom level) |
61b98a2d | 310 | { |
1d7d04d7 | 311 | //We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range |
c5f417cb | 312 | //is 10 to 1000 so the check is unnecessary |
61b98a2d SL |
313 | VARIANT zoomVariant; |
314 | VariantInit (&zoomVariant); | |
315 | V_VT(&zoomVariant) = VT_I4; | |
c5f417cb SL |
316 | |
317 | //We make a somewhat arbitray map here, taken from values used by webkit | |
318 | switch(level) | |
319 | { | |
236cff73 | 320 | case wxWEBVIEW_ZOOM_TINY: |
c5f417cb SL |
321 | V_I4(&zoomVariant) = 60; |
322 | break; | |
236cff73 | 323 | case wxWEBVIEW_ZOOM_SMALL: |
c5f417cb SL |
324 | V_I4(&zoomVariant) = 80; |
325 | break; | |
236cff73 | 326 | case wxWEBVIEW_ZOOM_MEDIUM: |
c5f417cb SL |
327 | V_I4(&zoomVariant) = 100; |
328 | break; | |
236cff73 | 329 | case wxWEBVIEW_ZOOM_LARGE: |
c5f417cb SL |
330 | V_I4(&zoomVariant) = 130; |
331 | break; | |
236cff73 | 332 | case wxWEBVIEW_ZOOM_LARGEST: |
c5f417cb SL |
333 | V_I4(&zoomVariant) = 160; |
334 | break; | |
335 | default: | |
336 | wxFAIL; | |
337 | } | |
61b98a2d | 338 | |
8acbf08b SL |
339 | #if wxDEBUG_LEVEL |
340 | HRESULT result = | |
341 | #endif | |
342 | m_webBrowser->ExecWB((OLECMDID)63 /*OLECMDID_OPTICAL_ZOOM*/, | |
343 | OLECMDEXECOPT_DODEFAULT, | |
344 | &zoomVariant, | |
345 | NULL); | |
c5f417cb | 346 | wxASSERT(result == S_OK); |
61b98a2d SL |
347 | } |
348 | ||
e669ddde | 349 | wxWebViewZoom wxWebViewIE::GetIEOpticalZoom() const |
61b98a2d | 350 | { |
61b98a2d SL |
351 | VARIANT zoomVariant; |
352 | VariantInit (&zoomVariant); | |
353 | V_VT(&zoomVariant) = VT_I4; | |
61b98a2d | 354 | |
8acbf08b SL |
355 | #if wxDEBUG_LEVEL |
356 | HRESULT result = | |
357 | #endif | |
358 | m_webBrowser->ExecWB((OLECMDID)63 /*OLECMDID_OPTICAL_ZOOM*/, | |
359 | OLECMDEXECOPT_DODEFAULT, NULL, | |
360 | &zoomVariant); | |
c5f417cb | 361 | wxASSERT(result == S_OK); |
61b98a2d SL |
362 | |
363 | const int zoom = V_I4(&zoomVariant); | |
61b98a2d | 364 | |
c5f417cb SL |
365 | //We make a somewhat arbitray map here, taken from values used by webkit |
366 | if (zoom <= 65) | |
367 | { | |
236cff73 | 368 | return wxWEBVIEW_ZOOM_TINY; |
c5f417cb SL |
369 | } |
370 | else if (zoom > 65 && zoom <= 90) | |
371 | { | |
236cff73 | 372 | return wxWEBVIEW_ZOOM_SMALL; |
c5f417cb SL |
373 | } |
374 | else if (zoom > 90 && zoom <= 115) | |
375 | { | |
236cff73 | 376 | return wxWEBVIEW_ZOOM_MEDIUM; |
c5f417cb SL |
377 | } |
378 | else if (zoom > 115 && zoom <= 145) | |
379 | { | |
236cff73 | 380 | return wxWEBVIEW_ZOOM_LARGE; |
c5f417cb | 381 | } |
423adfde | 382 | else /*if (zoom > 145) */ //Using else removes a compiler warning |
c5f417cb | 383 | { |
236cff73 | 384 | return wxWEBVIEW_ZOOM_LARGEST; |
c5f417cb | 385 | } |
61b98a2d SL |
386 | } |
387 | ||
c5f417cb | 388 | void wxWebViewIE::SetZoomType(wxWebViewZoomType type) |
61b98a2d | 389 | { |
c5f417cb | 390 | m_zoomType = type; |
61b98a2d SL |
391 | } |
392 | ||
393 | wxWebViewZoomType wxWebViewIE::GetZoomType() const | |
394 | { | |
c5f417cb | 395 | return m_zoomType; |
61b98a2d SL |
396 | } |
397 | ||
cd4e4673 | 398 | bool wxWebViewIE::CanSetZoomType(wxWebViewZoomType type) const |
61b98a2d | 399 | { |
cd4e4673 SL |
400 | //IE 6 and below only support text zoom, so check the registry to see what |
401 | //version we actually have | |
402 | wxRegKey key(wxRegKey::HKLM, "Software\\Microsoft\\Internet Explorer"); | |
403 | wxString value; | |
404 | key.QueryValue("Version", value); | |
405 | ||
406 | long version = wxAtoi(value.Left(1)); | |
236cff73 | 407 | if(version <= 6 && type == wxWEBVIEW_ZOOM_TYPE_LAYOUT) |
cd4e4673 SL |
408 | return false; |
409 | else | |
410 | return true; | |
61b98a2d SL |
411 | } |
412 | ||
413 | void wxWebViewIE::Print() | |
414 | { | |
415 | m_webBrowser->ExecWB(OLECMDID_PRINTPREVIEW, | |
416 | OLECMDEXECOPT_DODEFAULT, NULL, NULL); | |
417 | } | |
418 | ||
e669ddde | 419 | bool wxWebViewIE::CanGoBack() const |
61b98a2d | 420 | { |
74af0b13 SL |
421 | if(m_historyEnabled) |
422 | return m_historyPosition > 0; | |
423 | else | |
424 | return false; | |
425 | } | |
61b98a2d | 426 | |
e669ddde | 427 | bool wxWebViewIE::CanGoForward() const |
74af0b13 SL |
428 | { |
429 | if(m_historyEnabled) | |
22ca10fa | 430 | return m_historyPosition != static_cast<int>(m_historyList.size()) - 1; |
74af0b13 SL |
431 | else |
432 | return false; | |
61b98a2d SL |
433 | } |
434 | ||
c13d6ac1 | 435 | void wxWebViewIE::LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item) |
61b98a2d | 436 | { |
74af0b13 SL |
437 | int pos = -1; |
438 | for(unsigned int i = 0; i < m_historyList.size(); i++) | |
439 | { | |
3e7968c2 SL |
440 | //We compare the actual pointers to find the correct item |
441 | if(m_historyList[i].get() == item.get()) | |
74af0b13 SL |
442 | pos = i; |
443 | } | |
1d7d04d7 | 444 | wxASSERT_MSG(pos != static_cast<int>(m_historyList.size()), |
22ca10fa | 445 | "invalid history item"); |
74af0b13 | 446 | m_historyLoadingFromList = true; |
4d0dddc7 | 447 | LoadURL(item->GetUrl()); |
74af0b13 SL |
448 | m_historyPosition = pos; |
449 | } | |
61b98a2d | 450 | |
c13d6ac1 | 451 | wxVector<wxSharedPtr<wxWebViewHistoryItem> > wxWebViewIE::GetBackwardHistory() |
5cbda74b | 452 | { |
c13d6ac1 | 453 | wxVector<wxSharedPtr<wxWebViewHistoryItem> > backhist; |
5cbda74b SL |
454 | //As we don't have std::copy or an iterator constructor in the wxwidgets |
455 | //native vector we construct it by hand | |
456 | for(int i = 0; i < m_historyPosition; i++) | |
457 | { | |
458 | backhist.push_back(m_historyList[i]); | |
459 | } | |
460 | return backhist; | |
461 | } | |
462 | ||
c13d6ac1 | 463 | wxVector<wxSharedPtr<wxWebViewHistoryItem> > wxWebViewIE::GetForwardHistory() |
5cbda74b | 464 | { |
c13d6ac1 | 465 | wxVector<wxSharedPtr<wxWebViewHistoryItem> > forwardhist; |
5cbda74b SL |
466 | //As we don't have std::copy or an iterator constructor in the wxwidgets |
467 | //native vector we construct it by hand | |
22ca10fa | 468 | for(int i = m_historyPosition + 1; i < static_cast<int>(m_historyList.size()); i++) |
5cbda74b SL |
469 | { |
470 | forwardhist.push_back(m_historyList[i]); | |
471 | } | |
472 | return forwardhist; | |
473 | } | |
474 | ||
74af0b13 SL |
475 | void wxWebViewIE::GoBack() |
476 | { | |
3e7968c2 | 477 | LoadHistoryItem(m_historyList[m_historyPosition - 1]); |
74af0b13 SL |
478 | } |
479 | ||
480 | void wxWebViewIE::GoForward() | |
481 | { | |
3e7968c2 | 482 | LoadHistoryItem(m_historyList[m_historyPosition + 1]); |
61b98a2d SL |
483 | } |
484 | ||
485 | void wxWebViewIE::Stop() | |
486 | { | |
7fbc727b | 487 | m_ie.CallMethod("Stop"); |
61b98a2d SL |
488 | } |
489 | ||
74af0b13 SL |
490 | void wxWebViewIE::ClearHistory() |
491 | { | |
492 | m_historyList.clear(); | |
493 | m_historyPosition = -1; | |
494 | } | |
495 | ||
496 | void wxWebViewIE::EnableHistory(bool enable) | |
497 | { | |
498 | m_historyEnabled = enable; | |
499 | m_historyList.clear(); | |
500 | m_historyPosition = -1; | |
501 | } | |
61b98a2d SL |
502 | |
503 | void wxWebViewIE::Reload(wxWebViewReloadFlags flags) | |
504 | { | |
7aa18fc7 SL |
505 | VARIANTARG level; |
506 | VariantInit(&level); | |
507 | V_VT(&level) = VT_I2; | |
61b98a2d | 508 | |
7aa18fc7 | 509 | switch(flags) |
61b98a2d | 510 | { |
236cff73 | 511 | case wxWEBVIEW_RELOAD_DEFAULT: |
7aa18fc7 SL |
512 | V_I2(&level) = REFRESH_NORMAL; |
513 | break; | |
236cff73 | 514 | case wxWEBVIEW_RELOAD_NO_CACHE: |
7aa18fc7 SL |
515 | V_I2(&level) = REFRESH_COMPLETELY; |
516 | break; | |
517 | default: | |
518 | wxFAIL_MSG("Unexpected reload type"); | |
61b98a2d SL |
519 | } |
520 | ||
7aa18fc7 | 521 | m_webBrowser->Refresh2(&level); |
61b98a2d SL |
522 | } |
523 | ||
524 | bool wxWebViewIE::IsOfflineMode() | |
525 | { | |
526 | wxVariant out = m_ie.GetProperty("Offline"); | |
527 | ||
528 | wxASSERT(out.GetType() == "bool"); | |
529 | ||
530 | return out.GetBool(); | |
531 | } | |
532 | ||
533 | void wxWebViewIE::SetOfflineMode(bool offline) | |
534 | { | |
535 | // FIXME: the wxWidgets docs do not really document what the return | |
536 | // parameter of PutProperty is | |
8acbf08b SL |
537 | #if wxDEBUG_LEVEL |
538 | const bool success = | |
539 | #endif | |
540 | m_ie.PutProperty("Offline", (offline ? | |
541 | VARIANT_TRUE : | |
542 | VARIANT_FALSE)); | |
61b98a2d SL |
543 | wxASSERT(success); |
544 | } | |
545 | ||
e669ddde | 546 | bool wxWebViewIE::IsBusy() const |
60eabdbe | 547 | { |
61b98a2d SL |
548 | if (m_isBusy) return true; |
549 | ||
550 | wxVariant out = m_ie.GetProperty("Busy"); | |
551 | ||
552 | wxASSERT(out.GetType() == "bool"); | |
553 | ||
554 | return out.GetBool(); | |
555 | } | |
556 | ||
e669ddde | 557 | wxString wxWebViewIE::GetCurrentURL() const |
61b98a2d SL |
558 | { |
559 | wxVariant out = m_ie.GetProperty("LocationURL"); | |
560 | ||
561 | wxASSERT(out.GetType() == "string"); | |
562 | return out.GetString(); | |
563 | } | |
564 | ||
e669ddde | 565 | wxString wxWebViewIE::GetCurrentTitle() const |
61b98a2d | 566 | { |
f40f8e17 | 567 | wxCOMPtr<IHTMLDocument2> document(GetDocument()); |
7fbc727b | 568 | |
e81ef297 SL |
569 | if(document) |
570 | { | |
571 | BSTR title; | |
572 | document->get_nameProp(&title); | |
e81ef297 SL |
573 | return wxString(title); |
574 | } | |
575 | else | |
576 | { | |
577 | return ""; | |
578 | } | |
61b98a2d SL |
579 | } |
580 | ||
e669ddde | 581 | bool wxWebViewIE::CanCut() const |
4681a3ea SL |
582 | { |
583 | return CanExecCommand("Cut"); | |
584 | } | |
585 | ||
e669ddde | 586 | bool wxWebViewIE::CanCopy() const |
4681a3ea SL |
587 | { |
588 | return CanExecCommand("Copy"); | |
589 | } | |
34326da7 | 590 | |
e669ddde | 591 | bool wxWebViewIE::CanPaste() const |
4681a3ea SL |
592 | { |
593 | return CanExecCommand("Paste"); | |
594 | } | |
595 | ||
596 | void wxWebViewIE::Cut() | |
597 | { | |
598 | ExecCommand("Cut"); | |
599 | } | |
600 | ||
601 | void wxWebViewIE::Copy() | |
602 | { | |
603 | ExecCommand("Copy"); | |
604 | } | |
605 | ||
606 | void wxWebViewIE::Paste() | |
607 | { | |
608 | ExecCommand("Paste"); | |
609 | } | |
610 | ||
e669ddde | 611 | bool wxWebViewIE::CanUndo() const |
97e49559 SL |
612 | { |
613 | return CanExecCommand("Undo"); | |
614 | } | |
34326da7 | 615 | |
e669ddde | 616 | bool wxWebViewIE::CanRedo() const |
97e49559 SL |
617 | { |
618 | return CanExecCommand("Redo"); | |
619 | } | |
620 | ||
621 | void wxWebViewIE::Undo() | |
622 | { | |
623 | ExecCommand("Undo"); | |
624 | } | |
625 | ||
626 | void wxWebViewIE::Redo() | |
627 | { | |
628 | ExecCommand("Redo"); | |
629 | } | |
630 | ||
66ac0400 SL |
631 | long wxWebViewIE::Find(const wxString& text, int flags) |
632 | { | |
633 | //If the text is empty then we clear. | |
634 | if(text.IsEmpty()) | |
635 | { | |
636 | ClearSelection(); | |
236cff73 | 637 | if(m_findFlags & wxWEBVIEW_FIND_HIGHLIGHT_RESULT) |
66ac0400 | 638 | { |
236cff73 | 639 | FindInternal(m_findText, (m_findFlags &~ wxWEBVIEW_FIND_HIGHLIGHT_RESULT), wxWEBVIEW_FIND_REMOVE_HIGHLIGHT); |
66ac0400 SL |
640 | } |
641 | FindClear(); | |
642 | return wxNOT_FOUND; | |
643 | } | |
644 | //Have we done this search before? | |
645 | if(m_findText == text) | |
646 | { | |
647 | //Just do a highlight? | |
236cff73 | 648 | if((flags & wxWEBVIEW_FIND_HIGHLIGHT_RESULT) != (m_findFlags & wxWEBVIEW_FIND_HIGHLIGHT_RESULT)) |
66ac0400 SL |
649 | { |
650 | m_findFlags = flags; | |
651 | if(!m_findPointers.empty()) | |
652 | { | |
236cff73 | 653 | FindInternal(m_findText, m_findFlags, ((flags & wxWEBVIEW_FIND_HIGHLIGHT_RESULT) == 0 ? wxWEBVIEW_FIND_REMOVE_HIGHLIGHT : 0)); |
66ac0400 SL |
654 | } |
655 | return m_findPosition; | |
656 | } | |
236cff73 | 657 | else if(((m_findFlags & wxWEBVIEW_FIND_ENTIRE_WORD) == (flags & wxWEBVIEW_FIND_ENTIRE_WORD)) && ((m_findFlags & wxWEBVIEW_FIND_MATCH_CASE) == (flags&wxWEBVIEW_FIND_MATCH_CASE))) |
66ac0400 SL |
658 | { |
659 | m_findFlags = flags; | |
236cff73 | 660 | return FindNext(((flags & wxWEBVIEW_FIND_BACKWARDS) ? -1 : 1)); |
66ac0400 SL |
661 | } |
662 | } | |
663 | //Remove old highlight if any. | |
236cff73 | 664 | if(m_findFlags & wxWEBVIEW_FIND_HIGHLIGHT_RESULT) |
66ac0400 | 665 | { |
236cff73 | 666 | FindInternal(m_findText, (m_findFlags &~ wxWEBVIEW_FIND_HIGHLIGHT_RESULT), wxWEBVIEW_FIND_REMOVE_HIGHLIGHT); |
66ac0400 SL |
667 | } |
668 | //Reset find variables. | |
669 | FindClear(); | |
670 | ClearSelection(); | |
671 | m_findText = text; | |
672 | m_findFlags = flags; | |
673 | //find the text and return count. | |
236cff73 | 674 | FindInternal(text, flags, wxWEBVIEW_FIND_ADD_POINTERS); |
66ac0400 SL |
675 | return m_findPointers.empty() ? wxNOT_FOUND : m_findPointers.size(); |
676 | } | |
677 | ||
c7cbe308 SL |
678 | void wxWebViewIE::SetEditable(bool enable) |
679 | { | |
f40f8e17 | 680 | wxCOMPtr<IHTMLDocument2> document(GetDocument()); |
7fbc727b | 681 | |
e81ef297 SL |
682 | if(document) |
683 | { | |
684 | if( enable ) | |
685 | document->put_designMode(SysAllocString(L"On")); | |
686 | else | |
687 | document->put_designMode(SysAllocString(L"Off")); | |
688 | ||
e81ef297 | 689 | } |
c7cbe308 SL |
690 | } |
691 | ||
e669ddde | 692 | bool wxWebViewIE::IsEditable() const |
c7cbe308 | 693 | { |
f40f8e17 | 694 | wxCOMPtr<IHTMLDocument2> document(GetDocument()); |
e81ef297 SL |
695 | |
696 | if(document) | |
697 | { | |
698 | BSTR mode; | |
699 | document->get_designMode(&mode); | |
e81ef297 SL |
700 | if(wxString(mode) == "On") |
701 | return true; | |
702 | else | |
703 | return false; | |
704 | } | |
c7cbe308 | 705 | else |
e81ef297 | 706 | { |
c7cbe308 | 707 | return false; |
e81ef297 | 708 | } |
c7cbe308 SL |
709 | } |
710 | ||
63a65070 SL |
711 | void wxWebViewIE::SelectAll() |
712 | { | |
713 | ExecCommand("SelectAll"); | |
714 | } | |
715 | ||
e669ddde | 716 | bool wxWebViewIE::HasSelection() const |
63a65070 | 717 | { |
f40f8e17 | 718 | wxCOMPtr<IHTMLDocument2> document(GetDocument()); |
e81ef297 SL |
719 | |
720 | if(document) | |
7fbc727b | 721 | { |
f40f8e17 | 722 | wxCOMPtr<IHTMLSelectionObject> selection; |
e81ef297 SL |
723 | wxString sel; |
724 | HRESULT hr = document->get_selection(&selection); | |
725 | if(SUCCEEDED(hr)) | |
726 | { | |
727 | BSTR type; | |
728 | selection->get_type(&type); | |
729 | sel = wxString(type); | |
e81ef297 | 730 | } |
e81ef297 SL |
731 | return sel != "None"; |
732 | } | |
733 | else | |
734 | { | |
735 | return false; | |
7fbc727b | 736 | } |
63a65070 SL |
737 | } |
738 | ||
739 | void wxWebViewIE::DeleteSelection() | |
740 | { | |
741 | ExecCommand("Delete"); | |
742 | } | |
743 | ||
e669ddde | 744 | wxString wxWebViewIE::GetSelectedText() const |
c9355a3d | 745 | { |
f40f8e17 | 746 | wxCOMPtr<IHTMLDocument2> document(GetDocument()); |
e81ef297 SL |
747 | |
748 | if(document) | |
c9355a3d | 749 | { |
f40f8e17 | 750 | wxCOMPtr<IHTMLSelectionObject> selection; |
e81ef297 SL |
751 | wxString selected; |
752 | HRESULT hr = document->get_selection(&selection); | |
c9355a3d SL |
753 | if(SUCCEEDED(hr)) |
754 | { | |
f40f8e17 | 755 | wxCOMPtr<IDispatch> disrange; |
e81ef297 | 756 | hr = selection->createRange(&disrange); |
c9355a3d SL |
757 | if(SUCCEEDED(hr)) |
758 | { | |
f40f8e17 | 759 | wxCOMPtr<IHTMLTxtRange> range; |
e81ef297 SL |
760 | hr = disrange->QueryInterface(IID_IHTMLTxtRange, (void**)&range); |
761 | if(SUCCEEDED(hr)) | |
762 | { | |
763 | BSTR text; | |
764 | range->get_text(&text); | |
765 | selected = wxString(text); | |
e81ef297 | 766 | } |
c9355a3d | 767 | } |
c9355a3d | 768 | } |
e81ef297 SL |
769 | return selected; |
770 | } | |
771 | else | |
772 | { | |
773 | return ""; | |
c9355a3d | 774 | } |
c9355a3d SL |
775 | } |
776 | ||
e669ddde | 777 | wxString wxWebViewIE::GetSelectedSource() const |
0fe8a1b6 | 778 | { |
f40f8e17 | 779 | wxCOMPtr<IHTMLDocument2> document(GetDocument()); |
e81ef297 SL |
780 | |
781 | if(document) | |
0fe8a1b6 | 782 | { |
f40f8e17 | 783 | wxCOMPtr<IHTMLSelectionObject> selection; |
e81ef297 SL |
784 | wxString selected; |
785 | HRESULT hr = document->get_selection(&selection); | |
0fe8a1b6 SL |
786 | if(SUCCEEDED(hr)) |
787 | { | |
f40f8e17 | 788 | wxCOMPtr<IDispatch> disrange; |
e81ef297 | 789 | hr = selection->createRange(&disrange); |
0fe8a1b6 SL |
790 | if(SUCCEEDED(hr)) |
791 | { | |
f40f8e17 | 792 | wxCOMPtr<IHTMLTxtRange> range; |
e81ef297 SL |
793 | hr = disrange->QueryInterface(IID_IHTMLTxtRange, (void**)&range); |
794 | if(SUCCEEDED(hr)) | |
795 | { | |
796 | BSTR text; | |
797 | range->get_htmlText(&text); | |
798 | selected = wxString(text); | |
e81ef297 | 799 | } |
0fe8a1b6 | 800 | } |
0fe8a1b6 | 801 | } |
e81ef297 SL |
802 | return selected; |
803 | } | |
804 | else | |
805 | { | |
806 | return ""; | |
0fe8a1b6 | 807 | } |
0fe8a1b6 SL |
808 | } |
809 | ||
41933aa5 SL |
810 | void wxWebViewIE::ClearSelection() |
811 | { | |
f40f8e17 | 812 | wxCOMPtr<IHTMLDocument2> document(GetDocument()); |
e81ef297 SL |
813 | |
814 | if(document) | |
41933aa5 | 815 | { |
f40f8e17 | 816 | wxCOMPtr<IHTMLSelectionObject> selection; |
e81ef297 SL |
817 | wxString selected; |
818 | HRESULT hr = document->get_selection(&selection); | |
819 | if(SUCCEEDED(hr)) | |
820 | { | |
821 | selection->empty(); | |
e81ef297 | 822 | } |
41933aa5 | 823 | } |
41933aa5 SL |
824 | } |
825 | ||
e669ddde | 826 | wxString wxWebViewIE::GetPageText() const |
241b769f | 827 | { |
f40f8e17 | 828 | wxCOMPtr<IHTMLDocument2> document(GetDocument()); |
e81ef297 SL |
829 | |
830 | if(document) | |
241b769f | 831 | { |
e81ef297 | 832 | wxString text; |
f40f8e17 | 833 | wxCOMPtr<IHTMLElement> body; |
e81ef297 SL |
834 | HRESULT hr = document->get_body(&body); |
835 | if(SUCCEEDED(hr)) | |
836 | { | |
837 | BSTR out; | |
838 | body->get_innerText(&out); | |
839 | text = wxString(out); | |
e81ef297 | 840 | } |
e81ef297 SL |
841 | return text; |
842 | } | |
843 | else | |
844 | { | |
845 | return ""; | |
241b769f | 846 | } |
241b769f SL |
847 | } |
848 | ||
c9ccc09c SL |
849 | void wxWebViewIE::RunScript(const wxString& javascript) |
850 | { | |
f40f8e17 | 851 | wxCOMPtr<IHTMLDocument2> document(GetDocument()); |
e81ef297 SL |
852 | |
853 | if(document) | |
c9ccc09c | 854 | { |
f40f8e17 | 855 | wxCOMPtr<IHTMLWindow2> window; |
e81ef297 SL |
856 | wxString language = "javascript"; |
857 | HRESULT hr = document->get_parentWindow(&window); | |
858 | if(SUCCEEDED(hr)) | |
859 | { | |
860 | VARIANT level; | |
861 | VariantInit(&level); | |
862 | V_VT(&level) = VT_EMPTY; | |
863 | window->execScript(SysAllocString(javascript.wc_str()), | |
864 | SysAllocString(language.wc_str()), | |
865 | &level); | |
866 | } | |
c9ccc09c | 867 | } |
c9ccc09c SL |
868 | } |
869 | ||
7d8d6163 | 870 | void wxWebViewIE::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) |
29365629 | 871 | { |
e924e848 SL |
872 | wxDynamicLibrary urlMon(wxT("urlmon.dll")); |
873 | if(urlMon.HasSymbol(wxT("CoInternetGetSession"))) | |
29365629 | 874 | { |
f559d1a2 | 875 | typedef HRESULT (WINAPI *CoInternetGetSession_t)(DWORD, wxIInternetSession**, DWORD); |
e924e848 SL |
876 | wxDYNLIB_FUNCTION(CoInternetGetSession_t, CoInternetGetSession, urlMon); |
877 | ||
878 | ClassFactory* cf = new ClassFactory(handler); | |
f559d1a2 | 879 | wxIInternetSession* session; |
e924e848 SL |
880 | HRESULT res = (*pfnCoInternetGetSession)(0, &session, 0); |
881 | if(FAILED(res)) | |
882 | { | |
883 | wxFAIL_MSG("Could not retrive internet session"); | |
884 | } | |
29365629 | 885 | |
c9a828e7 VZ |
886 | HRESULT hr = session->RegisterNameSpace(cf, CLSID_FileProtocol, |
887 | handler->GetName().wc_str(), | |
888 | 0, NULL, 0); | |
e924e848 SL |
889 | if(FAILED(hr)) |
890 | { | |
891 | wxFAIL_MSG("Could not register protocol"); | |
892 | } | |
39498710 | 893 | m_factories.push_back(cf); |
e924e848 SL |
894 | } |
895 | else | |
29365629 | 896 | { |
e924e848 | 897 | wxFAIL_MSG("urlmon does not contain CoInternetGetSession"); |
29365629 SL |
898 | } |
899 | } | |
900 | ||
e669ddde | 901 | bool wxWebViewIE::CanExecCommand(wxString command) const |
4681a3ea | 902 | { |
f40f8e17 | 903 | wxCOMPtr<IHTMLDocument2> document(GetDocument()); |
7fbc727b | 904 | |
e81ef297 SL |
905 | if(document) |
906 | { | |
907 | VARIANT_BOOL enabled; | |
908 | ||
909 | document->queryCommandEnabled(SysAllocString(command.wc_str()), &enabled); | |
e81ef297 SL |
910 | |
911 | return (enabled == VARIANT_TRUE); | |
912 | } | |
913 | else | |
914 | { | |
915 | return false; | |
916 | } | |
4681a3ea | 917 | |
4681a3ea SL |
918 | } |
919 | ||
920 | void wxWebViewIE::ExecCommand(wxString command) | |
921 | { | |
f40f8e17 | 922 | wxCOMPtr<IHTMLDocument2> document(GetDocument()); |
e81ef297 SL |
923 | |
924 | if(document) | |
925 | { | |
926 | document->execCommand(SysAllocString(command.wc_str()), VARIANT_FALSE, VARIANT(), NULL); | |
e81ef297 | 927 | } |
617227c3 | 928 | } |
4681a3ea | 929 | |
f40f8e17 | 930 | wxCOMPtr<IHTMLDocument2> wxWebViewIE::GetDocument() const |
617227c3 | 931 | { |
f40f8e17 SL |
932 | wxCOMPtr<IDispatch> dispatch; |
933 | wxCOMPtr<IHTMLDocument2> document; | |
e81ef297 | 934 | HRESULT result = m_webBrowser->get_Document(&dispatch); |
601d0ba7 | 935 | if(dispatch && SUCCEEDED(result)) |
e81ef297 | 936 | { |
e81ef297 | 937 | //document is set to null automatically if the interface isn't supported |
f40f8e17 | 938 | dispatch->QueryInterface(IID_IHTMLDocument2, (void**)&document); |
e81ef297 | 939 | } |
f40f8e17 | 940 | return document; |
4681a3ea SL |
941 | } |
942 | ||
938506b1 | 943 | bool wxWebViewIE::IsElementVisible(wxCOMPtr<IHTMLElement> elm) |
66ac0400 | 944 | { |
938506b1 | 945 | wxCOMPtr<IHTMLElement> elm1 = elm; |
66ac0400 SL |
946 | BSTR tmp_bstr; |
947 | bool is_visible = true; | |
948 | //This method is not perfect but it does discover most of the hidden elements. | |
949 | //so if a better solution is found, then please do improve. | |
950 | while(elm1) | |
951 | { | |
938506b1 | 952 | wxCOMPtr<wxIHTMLElement2> elm2; |
e52aec97 | 953 | if(SUCCEEDED(elm1->QueryInterface(wxIID_IHTMLElement2, (void**) &elm2))) |
66ac0400 | 954 | { |
938506b1 | 955 | wxCOMPtr<wxIHTMLCurrentStyle> style; |
66ac0400 SL |
956 | if(SUCCEEDED(elm2->get_currentStyle(&style))) |
957 | { | |
958 | //Check if the object has the style display:none. | |
959 | if((style->get_display(&tmp_bstr) != S_OK) || | |
960 | (tmp_bstr != NULL && (_wcsicmp(tmp_bstr, L"none") == 0))) | |
961 | { | |
962 | is_visible = false; | |
963 | } | |
964 | //Check if the object has the style visibility:hidden. | |
79fdb1d1 | 965 | if((is_visible && (style->get_visibility(&tmp_bstr) != S_OK)) || |
66ac0400 SL |
966 | (tmp_bstr != NULL && _wcsicmp(tmp_bstr, L"hidden") == 0)) |
967 | { | |
968 | is_visible = false; | |
969 | } | |
970 | style->Release(); | |
971 | } | |
972 | elm2->Release(); | |
973 | } | |
974 | ||
975 | //Lets check the object's parent element. | |
976 | IHTMLElement* parent; | |
977 | if(is_visible && SUCCEEDED(elm1->get_parentElement(&parent))) | |
978 | { | |
66ac0400 SL |
979 | elm1 = parent; |
980 | } | |
981 | else | |
982 | { | |
983 | elm1->Release(); | |
984 | break; | |
985 | } | |
986 | } | |
987 | return is_visible; | |
988 | } | |
989 | ||
990 | void wxWebViewIE::FindInternal(const wxString& text, int flags, int internal_flag) | |
991 | { | |
66ac0400 | 992 | long find_flag = 0; |
938506b1 SL |
993 | wxCOMPtr<wxIMarkupServices> pIMS; |
994 | wxCOMPtr<IHTMLDocument2> document = GetDocument(); | |
995 | ||
66ac0400 | 996 | //This function does the acutal work. |
938506b1 | 997 | if(document && SUCCEEDED(document->QueryInterface(wxIID_IMarkupServices, (void **)&pIMS))) |
66ac0400 | 998 | { |
938506b1 | 999 | wxCOMPtr<wxIMarkupContainer> pIMC; |
e52aec97 | 1000 | if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupContainer, (void **)&pIMC))) |
66ac0400 | 1001 | { |
938506b1 | 1002 | wxCOMPtr<wxIMarkupPointer> ptrBegin, ptrEnd; |
66ac0400 SL |
1003 | BSTR attr_bstr = SysAllocString(L"style=\"background-color:#ffff00\""); |
1004 | BSTR text_bstr = SysAllocString(text.wc_str()); | |
1005 | pIMS->CreateMarkupPointer(&ptrBegin); | |
1006 | pIMS->CreateMarkupPointer(&ptrEnd); | |
1007 | ||
a8da90b8 | 1008 | ptrBegin->SetGravity(wxPOINTER_GRAVITY_Right); |
66ac0400 SL |
1009 | ptrBegin->MoveToContainer(pIMC, TRUE); |
1010 | //Create the find flag from the wx one. | |
236cff73 | 1011 | if(flags & wxWEBVIEW_FIND_ENTIRE_WORD) |
66ac0400 | 1012 | { |
a8da90b8 | 1013 | find_flag |= wxFINDTEXT_WHOLEWORD; |
66ac0400 | 1014 | } |
236cff73 | 1015 | if(flags & wxWEBVIEW_FIND_MATCH_CASE) |
66ac0400 | 1016 | { |
a8da90b8 | 1017 | find_flag |= wxFINDTEXT_MATCHCASE; |
66ac0400 SL |
1018 | } |
1019 | ||
1020 | //A little speed-up to avoid to re-alloc in the positions vector. | |
1021 | if(text.Len() < 3 && m_findPointers.capacity() < 500) | |
1022 | { | |
1023 | m_findPointers.reserve(text.Len() == 1 ? 1000 : 500); | |
1024 | } | |
1025 | ||
1026 | while(ptrBegin->FindText(text_bstr, find_flag, ptrEnd, NULL) == S_OK) | |
1027 | { | |
938506b1 | 1028 | wxCOMPtr<IHTMLElement> elm; |
66ac0400 SL |
1029 | if(ptrBegin->CurrentScope(&elm) == S_OK) |
1030 | { | |
1031 | if(IsElementVisible(elm)) | |
1032 | { | |
1033 | //Highlight the word if the flag was set. | |
236cff73 | 1034 | if(flags & wxWEBVIEW_FIND_HIGHLIGHT_RESULT) |
66ac0400 SL |
1035 | { |
1036 | IHTMLElement* pFontEl; | |
a8da90b8 | 1037 | pIMS->CreateElement(wxTAGID_FONT, attr_bstr, &pFontEl); |
66ac0400 SL |
1038 | pIMS->InsertElement(pFontEl, ptrBegin, ptrEnd); |
1039 | } | |
236cff73 | 1040 | if(internal_flag & wxWEBVIEW_FIND_REMOVE_HIGHLIGHT) |
66ac0400 SL |
1041 | { |
1042 | IHTMLElement* pFontEl; | |
1043 | ptrBegin->CurrentScope(&pFontEl); | |
1044 | pIMS->RemoveElement(pFontEl); | |
1045 | pFontEl->Release(); | |
1046 | } | |
236cff73 | 1047 | if(internal_flag & wxWEBVIEW_FIND_ADD_POINTERS) |
66ac0400 | 1048 | { |
e52aec97 | 1049 | wxIMarkupPointer *cptrBegin, *cptrEnd; |
66ac0400 SL |
1050 | pIMS->CreateMarkupPointer(&cptrBegin); |
1051 | pIMS->CreateMarkupPointer(&cptrEnd); | |
1052 | cptrBegin->MoveToPointer(ptrBegin); | |
1053 | cptrEnd->MoveToPointer(ptrEnd); | |
1054 | m_findPointers.push_back(wxFindPointers(cptrBegin,cptrEnd)); | |
1055 | } | |
1056 | } | |
66ac0400 SL |
1057 | } |
1058 | ptrBegin->MoveToPointer(ptrEnd); | |
1059 | } | |
1060 | //Clean up. | |
1061 | SysFreeString(text_bstr); | |
1062 | SysFreeString(attr_bstr); | |
66ac0400 | 1063 | } |
66ac0400 | 1064 | } |
66ac0400 SL |
1065 | } |
1066 | ||
1067 | long wxWebViewIE::FindNext(int direction) | |
1068 | { | |
1069 | //Don't bother if we have no pointers set. | |
1070 | if(m_findPointers.empty()) | |
1071 | { | |
1072 | return wxNOT_FOUND; | |
1073 | } | |
1074 | //Manage the find position and do some checks. | |
1075 | if(direction > 0) | |
1076 | { | |
1077 | m_findPosition++; | |
1078 | } | |
1079 | else | |
1080 | { | |
1081 | m_findPosition--; | |
1082 | } | |
1083 | ||
1084 | if(m_findPosition >= (signed)m_findPointers.size()) | |
1085 | { | |
236cff73 | 1086 | if(m_findFlags & wxWEBVIEW_FIND_WRAP) |
66ac0400 SL |
1087 | { |
1088 | m_findPosition = 0; | |
1089 | } | |
1090 | else | |
1091 | { | |
1092 | m_findPosition--; | |
1093 | return wxNOT_FOUND; | |
1094 | } | |
1095 | } | |
1096 | else if(m_findPosition < 0) | |
1097 | { | |
236cff73 | 1098 | if(m_findFlags & wxWEBVIEW_FIND_WRAP) |
66ac0400 SL |
1099 | { |
1100 | m_findPosition = m_findPointers.size()-1; | |
1101 | } | |
1102 | else | |
1103 | { | |
1104 | m_findPosition++; | |
1105 | return wxNOT_FOUND; | |
1106 | } | |
1107 | } | |
938506b1 SL |
1108 | |
1109 | wxCOMPtr<IHTMLDocument2> document = GetDocument(); | |
1110 | wxCOMPtr<IHTMLElement> body_element; | |
1111 | ||
66ac0400 SL |
1112 | long ret = -1; |
1113 | //Now try to create a range from the body. | |
938506b1 | 1114 | if(document && SUCCEEDED(document->get_body(&body_element))) |
66ac0400 | 1115 | { |
938506b1 | 1116 | wxCOMPtr<IHTMLBodyElement> body; |
66ac0400 SL |
1117 | if(SUCCEEDED(body_element->QueryInterface(IID_IHTMLBodyElement,(void**)&body))) |
1118 | { | |
938506b1 | 1119 | wxCOMPtr<wxIHTMLTxtRange> range; |
e52aec97 | 1120 | if(SUCCEEDED(body->createTextRange((IHTMLTxtRange**)(&range)))) |
66ac0400 | 1121 | { |
938506b1 | 1122 | wxCOMPtr<wxIMarkupServices> pIMS; |
66ac0400 | 1123 | //So far so good, now we try to position our find pointers. |
e52aec97 | 1124 | if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupServices,(void **)&pIMS))) |
66ac0400 | 1125 | { |
e52aec97 | 1126 | wxIMarkupPointer *begin = m_findPointers[m_findPosition].begin, *end = m_findPointers[m_findPosition].end; |
66ac0400 SL |
1127 | if(pIMS->MoveRangeToPointers(begin,end,range) == S_OK && range->select() == S_OK) |
1128 | { | |
1129 | ret = m_findPosition; | |
1130 | } | |
66ac0400 | 1131 | } |
66ac0400 | 1132 | } |
66ac0400 | 1133 | } |
66ac0400 | 1134 | } |
66ac0400 SL |
1135 | return ret; |
1136 | } | |
1137 | ||
1138 | void wxWebViewIE::FindClear() | |
1139 | { | |
1140 | //Reset find variables. | |
1141 | m_findText.Empty(); | |
236cff73 | 1142 | m_findFlags = wxWEBVIEW_FIND_DEFAULT; |
66ac0400 SL |
1143 | m_findPosition = -1; |
1144 | ||
1145 | //The m_findPointers contains pointers for the found text. | |
1146 | //Since it uses ref counting we call release on the pointers first | |
1147 | //before we remove them from the vector. In other words do not just | |
1148 | //remove elements from m_findPointers without calling release first | |
1149 | //or you will get a memory leak. | |
1150 | size_t count = m_findPointers.size(); | |
1151 | for(size_t i = 0; i < count; i++) | |
1152 | { | |
1153 | m_findPointers[i].begin->Release(); | |
1154 | m_findPointers[i].end->Release(); | |
1155 | } | |
1156 | m_findPointers.clear(); | |
1157 | } | |
1158 | ||
9447a0d6 SL |
1159 | bool wxWebViewIE::EnableControlFeature(long flag, bool enable) |
1160 | { | |
1161 | #if wxUSE_DYNLIB_CLASS | |
1162 | ||
1163 | wxDynamicLibrary urlMon(wxT("urlmon.dll")); | |
34326da7 SL |
1164 | if( urlMon.IsLoaded() && |
1165 | urlMon.HasSymbol("CoInternetSetFeatureEnabled") && | |
9447a0d6 SL |
1166 | urlMon.HasSymbol("CoInternetIsFeatureEnabled")) |
1167 | { | |
1168 | typedef HRESULT (WINAPI *CoInternetSetFeatureEnabled_t)(DWORD, DWORD, BOOL); | |
1169 | typedef HRESULT (WINAPI *CoInternetIsFeatureEnabled_t)(DWORD, DWORD); | |
1170 | ||
1171 | wxDYNLIB_FUNCTION(CoInternetSetFeatureEnabled_t, CoInternetSetFeatureEnabled, urlMon); | |
1172 | wxDYNLIB_FUNCTION(CoInternetIsFeatureEnabled_t, CoInternetIsFeatureEnabled, urlMon); | |
1173 | ||
1174 | HRESULT hr = (*pfnCoInternetIsFeatureEnabled)(flag, | |
1175 | 0x2 /* SET_FEATURE_ON_PROCESS */); | |
1176 | if((hr == S_OK && enable) || (hr == S_FALSE && !enable)) | |
1177 | return true; | |
1178 | ||
1179 | hr = (*pfnCoInternetSetFeatureEnabled)(flag, | |
1180 | 0x2/* SET_FEATURE_ON_PROCESS */, | |
1181 | (enable ? TRUE : FALSE)); | |
1182 | if ( FAILED(hr) ) | |
1183 | { | |
1184 | wxLogApiError(wxT("CoInternetSetFeatureEnabled"), hr); | |
1185 | return false; | |
1186 | } | |
1187 | return true; | |
1188 | } | |
1189 | return false; | |
1190 | #else | |
1191 | wxUnusedVar(flag); | |
1192 | wxUnusedVar(enable); | |
1193 | return false; | |
1194 | #endif // wxUSE_DYNLIB_CLASS/!wxUSE_DYNLIB_CLASS | |
1195 | } | |
1196 | ||
61b98a2d SL |
1197 | void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt) |
1198 | { | |
1199 | if (m_webBrowser == NULL) return; | |
1200 | ||
1201 | switch (evt.GetDispatchId()) | |
1202 | { | |
1203 | case DISPID_BEFORENAVIGATE2: | |
1204 | { | |
1205 | m_isBusy = true; | |
1206 | ||
1207 | wxString url = evt[1].GetString(); | |
1208 | wxString target = evt[3].GetString(); | |
1209 | ||
ce7fe42e | 1210 | wxWebViewEvent event(wxEVT_WEBVIEW_NAVIGATING, |
3225a4b8 | 1211 | GetId(), url, target); |
e11b9a6b SL |
1212 | |
1213 | //skip empty javascript events. | |
1214 | if(url == "javascript:\"\"" && target.IsEmpty()) | |
1215 | { | |
1216 | event.Veto(); | |
1217 | } | |
1218 | else | |
1219 | { | |
1220 | event.SetEventObject(this); | |
1221 | HandleWindowEvent(event); | |
1222 | } | |
61b98a2d | 1223 | |
3225a4b8 | 1224 | if (!event.IsAllowed()) |
61b98a2d SL |
1225 | { |
1226 | wxActiveXEventNativeMSW* nativeParams = | |
1227 | evt.GetNativeParameters(); | |
1228 | *V_BOOLREF(&nativeParams->pDispParams->rgvarg[0]) = VARIANT_TRUE; | |
1229 | } | |
1230 | ||
1231 | // at this point, either the navigation event has been cancelled | |
1232 | // and we're not busy, either it was accepted and IWebBrowser2's | |
1233 | // Busy property will be true; so we don't need our override | |
1234 | // flag anymore. | |
1235 | m_isBusy = false; | |
1236 | ||
1237 | break; | |
1238 | } | |
1239 | ||
1240 | case DISPID_NAVIGATECOMPLETE2: | |
1241 | { | |
1242 | wxString url = evt[1].GetString(); | |
1243 | // TODO: set target parameter if possible | |
1244 | wxString target = wxEmptyString; | |
ce7fe42e | 1245 | wxWebViewEvent event(wxEVT_WEBVIEW_NAVIGATED, |
3225a4b8 | 1246 | GetId(), url, target); |
61b98a2d SL |
1247 | event.SetEventObject(this); |
1248 | HandleWindowEvent(event); | |
1249 | break; | |
1250 | } | |
1251 | ||
1252 | case DISPID_PROGRESSCHANGE: | |
1253 | { | |
1254 | // download progress | |
1255 | break; | |
1256 | } | |
1257 | ||
1258 | case DISPID_DOCUMENTCOMPLETE: | |
1259 | { | |
3ee442ff SL |
1260 | //Only send a complete even if we are actually finished, this brings |
1261 | //the event in to line with webkit | |
1262 | READYSTATE rs; | |
1263 | m_webBrowser->get_ReadyState( &rs ); | |
1264 | if(rs != READYSTATE_COMPLETE) | |
1265 | break; | |
1266 | ||
61b98a2d | 1267 | wxString url = evt[1].GetString(); |
113e0a92 SL |
1268 | |
1269 | //As we are complete we also add to the history list, but not if the | |
1270 | //page is not the main page, ie it is a subframe | |
60eabdbe | 1271 | //We also have to check if we are loading a file:// url, if so we |
f239a200 SL |
1272 | //need to change the comparison as ie passes back a different style |
1273 | //of url | |
60eabdbe VZ |
1274 | if(m_historyEnabled && !m_historyLoadingFromList && |
1275 | (url == GetCurrentURL() || | |
1276 | (GetCurrentURL().substr(0, 4) == "file" && | |
f239a200 | 1277 | wxFileSystem::URLToFileName(GetCurrentURL()).GetFullPath() == url))) |
74af0b13 SL |
1278 | { |
1279 | //If we are not at the end of the list, then erase everything | |
1280 | //between us and the end before adding the new page | |
22ca10fa | 1281 | if(m_historyPosition != static_cast<int>(m_historyList.size()) - 1) |
74af0b13 SL |
1282 | { |
1283 | m_historyList.erase(m_historyList.begin() + m_historyPosition + 1, | |
1284 | m_historyList.end()); | |
1285 | } | |
c13d6ac1 | 1286 | wxSharedPtr<wxWebViewHistoryItem> item(new wxWebViewHistoryItem(url, GetCurrentTitle())); |
74af0b13 SL |
1287 | m_historyList.push_back(item); |
1288 | m_historyPosition++; | |
1289 | } | |
1290 | //Reset as we are done now | |
1291 | m_historyLoadingFromList = false; | |
66ac0400 SL |
1292 | //Reset the find values. |
1293 | FindClear(); | |
61b98a2d SL |
1294 | // TODO: set target parameter if possible |
1295 | wxString target = wxEmptyString; | |
ce7fe42e | 1296 | wxWebViewEvent event(wxEVT_WEBVIEW_LOADED, GetId(), |
3225a4b8 | 1297 | url, target); |
61b98a2d SL |
1298 | event.SetEventObject(this); |
1299 | HandleWindowEvent(event); | |
1300 | break; | |
1301 | } | |
1302 | ||
1303 | case DISPID_STATUSTEXTCHANGE: | |
1304 | { | |
1305 | break; | |
1306 | } | |
1307 | ||
1308 | case DISPID_TITLECHANGE: | |
1309 | { | |
153530af SL |
1310 | wxString title = evt[0].GetString(); |
1311 | ||
ce7fe42e | 1312 | wxWebViewEvent event(wxEVT_WEBVIEW_TITLE_CHANGED, |
3225a4b8 | 1313 | GetId(), GetCurrentURL(), ""); |
153530af SL |
1314 | event.SetString(title); |
1315 | event.SetEventObject(this); | |
1316 | HandleWindowEvent(event); | |
61b98a2d SL |
1317 | break; |
1318 | } | |
1319 | ||
1320 | case DISPID_NAVIGATEERROR: | |
1321 | { | |
ce7fe42e | 1322 | wxWebViewEvent event(wxEVT_WEBVIEW_ERROR, GetId(), |
c1381581 SL |
1323 | evt[1].GetString(), evt[2].GetString()); |
1324 | event.SetEventObject(this); | |
1325 | ||
61b98a2d SL |
1326 | switch (evt[3].GetLong()) |
1327 | { | |
c1381581 | 1328 | // 400 Error codes |
236cff73 SL |
1329 | WX_ERROR_CASE(HTTP_STATUS_BAD_REQUEST, wxWEBVIEW_NAV_ERR_REQUEST) |
1330 | WX_ERROR_CASE(HTTP_STATUS_DENIED, wxWEBVIEW_NAV_ERR_AUTH) | |
1331 | WX_ERROR_CASE(HTTP_STATUS_PAYMENT_REQ, wxWEBVIEW_NAV_ERR_OTHER) | |
1332 | WX_ERROR_CASE(HTTP_STATUS_FORBIDDEN, wxWEBVIEW_NAV_ERR_AUTH) | |
1333 | WX_ERROR_CASE(HTTP_STATUS_NOT_FOUND, wxWEBVIEW_NAV_ERR_NOT_FOUND) | |
1334 | WX_ERROR_CASE(HTTP_STATUS_BAD_METHOD, wxWEBVIEW_NAV_ERR_REQUEST) | |
1335 | WX_ERROR_CASE(HTTP_STATUS_NONE_ACCEPTABLE, wxWEBVIEW_NAV_ERR_OTHER) | |
1336 | WX_ERROR_CASE(HTTP_STATUS_PROXY_AUTH_REQ, wxWEBVIEW_NAV_ERR_AUTH) | |
1337 | WX_ERROR_CASE(HTTP_STATUS_REQUEST_TIMEOUT, wxWEBVIEW_NAV_ERR_CONNECTION) | |
1338 | WX_ERROR_CASE(HTTP_STATUS_CONFLICT, wxWEBVIEW_NAV_ERR_REQUEST) | |
1339 | WX_ERROR_CASE(HTTP_STATUS_GONE, wxWEBVIEW_NAV_ERR_NOT_FOUND) | |
1340 | WX_ERROR_CASE(HTTP_STATUS_LENGTH_REQUIRED, wxWEBVIEW_NAV_ERR_REQUEST) | |
1341 | WX_ERROR_CASE(HTTP_STATUS_PRECOND_FAILED, wxWEBVIEW_NAV_ERR_REQUEST) | |
1342 | WX_ERROR_CASE(HTTP_STATUS_REQUEST_TOO_LARGE, wxWEBVIEW_NAV_ERR_REQUEST) | |
1343 | WX_ERROR_CASE(HTTP_STATUS_URI_TOO_LONG, wxWEBVIEW_NAV_ERR_REQUEST) | |
1344 | WX_ERROR_CASE(HTTP_STATUS_UNSUPPORTED_MEDIA, wxWEBVIEW_NAV_ERR_REQUEST) | |
1345 | WX_ERROR_CASE(HTTP_STATUS_RETRY_WITH, wxWEBVIEW_NAV_ERR_OTHER) | |
c1381581 SL |
1346 | |
1347 | // 500 - Error codes | |
236cff73 SL |
1348 | WX_ERROR_CASE(HTTP_STATUS_SERVER_ERROR, wxWEBVIEW_NAV_ERR_CONNECTION) |
1349 | WX_ERROR_CASE(HTTP_STATUS_NOT_SUPPORTED, wxWEBVIEW_NAV_ERR_CONNECTION) | |
1350 | WX_ERROR_CASE(HTTP_STATUS_BAD_GATEWAY, wxWEBVIEW_NAV_ERR_CONNECTION) | |
1351 | WX_ERROR_CASE(HTTP_STATUS_SERVICE_UNAVAIL, wxWEBVIEW_NAV_ERR_CONNECTION) | |
1352 | WX_ERROR_CASE(HTTP_STATUS_GATEWAY_TIMEOUT, wxWEBVIEW_NAV_ERR_CONNECTION) | |
1353 | WX_ERROR_CASE(HTTP_STATUS_VERSION_NOT_SUP, wxWEBVIEW_NAV_ERR_REQUEST) | |
c1381581 SL |
1354 | |
1355 | // URL Moniker error codes | |
236cff73 SL |
1356 | WX_ERROR_CASE(INET_E_INVALID_URL, wxWEBVIEW_NAV_ERR_REQUEST) |
1357 | WX_ERROR_CASE(INET_E_NO_SESSION, wxWEBVIEW_NAV_ERR_CONNECTION) | |
1358 | WX_ERROR_CASE(INET_E_CANNOT_CONNECT, wxWEBVIEW_NAV_ERR_CONNECTION) | |
1359 | WX_ERROR_CASE(INET_E_RESOURCE_NOT_FOUND, wxWEBVIEW_NAV_ERR_NOT_FOUND) | |
1360 | WX_ERROR_CASE(INET_E_OBJECT_NOT_FOUND, wxWEBVIEW_NAV_ERR_NOT_FOUND) | |
1361 | WX_ERROR_CASE(INET_E_DATA_NOT_AVAILABLE, wxWEBVIEW_NAV_ERR_NOT_FOUND) | |
1362 | WX_ERROR_CASE(INET_E_DOWNLOAD_FAILURE, wxWEBVIEW_NAV_ERR_CONNECTION) | |
1363 | WX_ERROR_CASE(INET_E_AUTHENTICATION_REQUIRED, wxWEBVIEW_NAV_ERR_AUTH) | |
1364 | WX_ERROR_CASE(INET_E_NO_VALID_MEDIA, wxWEBVIEW_NAV_ERR_REQUEST) | |
1365 | WX_ERROR_CASE(INET_E_CONNECTION_TIMEOUT, wxWEBVIEW_NAV_ERR_CONNECTION) | |
1366 | WX_ERROR_CASE(INET_E_INVALID_REQUEST, wxWEBVIEW_NAV_ERR_REQUEST) | |
1367 | WX_ERROR_CASE(INET_E_UNKNOWN_PROTOCOL, wxWEBVIEW_NAV_ERR_REQUEST) | |
1368 | WX_ERROR_CASE(INET_E_SECURITY_PROBLEM, wxWEBVIEW_NAV_ERR_SECURITY) | |
1369 | WX_ERROR_CASE(INET_E_CANNOT_LOAD_DATA, wxWEBVIEW_NAV_ERR_OTHER) | |
1370 | WX_ERROR_CASE(INET_E_REDIRECT_FAILED, wxWEBVIEW_NAV_ERR_OTHER) | |
1371 | WX_ERROR_CASE(INET_E_REDIRECT_TO_DIR, wxWEBVIEW_NAV_ERR_REQUEST) | |
1372 | WX_ERROR_CASE(INET_E_CANNOT_LOCK_REQUEST, wxWEBVIEW_NAV_ERR_OTHER) | |
1373 | WX_ERROR_CASE(INET_E_USE_EXTEND_BINDING, wxWEBVIEW_NAV_ERR_OTHER) | |
1374 | WX_ERROR_CASE(INET_E_TERMINATED_BIND, wxWEBVIEW_NAV_ERR_OTHER) | |
1375 | WX_ERROR_CASE(INET_E_INVALID_CERTIFICATE, wxWEBVIEW_NAV_ERR_CERTIFICATE) | |
1376 | WX_ERROR_CASE(INET_E_CODE_DOWNLOAD_DECLINED, wxWEBVIEW_NAV_ERR_USER_CANCELLED) | |
1377 | WX_ERROR_CASE(INET_E_RESULT_DISPATCHED, wxWEBVIEW_NAV_ERR_OTHER) | |
1378 | WX_ERROR_CASE(INET_E_CANNOT_REPLACE_SFP_FILE, wxWEBVIEW_NAV_ERR_SECURITY) | |
1379 | WX_ERROR_CASE(INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY, wxWEBVIEW_NAV_ERR_SECURITY) | |
1380 | WX_ERROR_CASE(INET_E_CODE_INSTALL_SUPPRESSED, wxWEBVIEW_NAV_ERR_SECURITY) | |
61b98a2d | 1381 | } |
61b98a2d SL |
1382 | HandleWindowEvent(event); |
1383 | break; | |
1384 | } | |
853b6cd0 | 1385 | case DISPID_NEWWINDOW3: |
61b98a2d | 1386 | { |
853b6cd0 SL |
1387 | wxString url = evt[4].GetString(); |
1388 | ||
ce7fe42e | 1389 | wxWebViewEvent event(wxEVT_WEBVIEW_NEWWINDOW, |
3225a4b8 | 1390 | GetId(), url, wxEmptyString); |
853b6cd0 SL |
1391 | event.SetEventObject(this); |
1392 | HandleWindowEvent(event); | |
1393 | ||
d676fb21 SL |
1394 | //We always cancel this event otherwise an Internet Exporer window |
1395 | //is opened for the url | |
1396 | wxActiveXEventNativeMSW* nativeParams = evt.GetNativeParameters(); | |
1397 | *V_BOOLREF(&nativeParams->pDispParams->rgvarg[3]) = VARIANT_TRUE; | |
be19c556 SL |
1398 | break; |
1399 | } | |
61b98a2d SL |
1400 | } |
1401 | ||
1402 | evt.Skip(); | |
1403 | } | |
1404 | ||
7d8d6163 | 1405 | VirtualProtocol::VirtualProtocol(wxSharedPtr<wxWebViewHandler> handler) |
7d3f6b4d | 1406 | { |
7d3f6b4d | 1407 | m_file = NULL; |
29365629 | 1408 | m_handler = handler; |
7d3f6b4d SL |
1409 | } |
1410 | ||
9f194b9d SL |
1411 | BEGIN_IID_TABLE(VirtualProtocol) |
1412 | ADD_IID(Unknown) | |
1413 | ADD_RAW_IID(wxIID_IInternetProtocolRoot) | |
1414 | ADD_RAW_IID(wxIID_IInternetProtocol) | |
1415 | END_IID_TABLE; | |
7d3f6b4d | 1416 | |
9f194b9d | 1417 | IMPLEMENT_IUNKNOWN_METHODS(VirtualProtocol) |
7d3f6b4d | 1418 | |
a9c5eac9 | 1419 | HRESULT STDMETHODCALLTYPE VirtualProtocol::Start(LPCWSTR szUrl, wxIInternetProtocolSink *pOIProtSink, |
f559d1a2 | 1420 | wxIInternetBindInfo *pOIBindInfo, DWORD grfPI, |
0995b9dc | 1421 | HANDLE_PTR dwReserved) |
7d3f6b4d | 1422 | { |
0995b9dc SL |
1423 | wxUnusedVar(szUrl); |
1424 | wxUnusedVar(pOIBindInfo); | |
1425 | wxUnusedVar(grfPI); | |
1426 | wxUnusedVar(dwReserved); | |
7d3f6b4d | 1427 | m_protocolSink = pOIProtSink; |
60eabdbe | 1428 | |
29365629 SL |
1429 | //We get the file itself from the protocol handler |
1430 | m_file = m_handler->GetFile(szUrl); | |
1431 | ||
7d3f6b4d SL |
1432 | |
1433 | if(!m_file) | |
1434 | return INET_E_RESOURCE_NOT_FOUND; | |
1435 | ||
1436 | //We return the stream length for current and total size as we can always | |
1437 | //read the whole file from the stream | |
666f73c4 | 1438 | wxFileOffset length = m_file->GetStream()->GetLength(); |
f559d1a2 VZ |
1439 | m_protocolSink->ReportData(wxBSCF_FIRSTDATANOTIFICATION | |
1440 | wxBSCF_DATAFULLYAVAILABLE | | |
1441 | wxBSCF_LASTDATANOTIFICATION, | |
666f73c4 | 1442 | length, length); |
60eabdbe | 1443 | return S_OK; |
7d3f6b4d SL |
1444 | } |
1445 | ||
a9c5eac9 | 1446 | HRESULT STDMETHODCALLTYPE VirtualProtocol::Read(void *pv, ULONG cb, ULONG *pcbRead) |
7d3f6b4d SL |
1447 | { |
1448 | //If the file is null we return false to indicte it is finished | |
60eabdbe | 1449 | if(!m_file) |
7d3f6b4d SL |
1450 | return S_FALSE; |
1451 | ||
1452 | wxStreamError err = m_file->GetStream()->Read(pv, cb).GetLastError(); | |
1453 | *pcbRead = m_file->GetStream()->LastRead(); | |
1454 | ||
1455 | if(err == wxSTREAM_NO_ERROR) | |
1456 | { | |
1457 | if(*pcbRead < cb) | |
1458 | { | |
1459 | wxDELETE(m_file); | |
1460 | m_protocolSink->ReportResult(S_OK, 0, NULL); | |
1461 | } | |
1462 | //As we are not eof there is more data | |
1463 | return S_OK; | |
1464 | } | |
1465 | else if(err == wxSTREAM_EOF) | |
1466 | { | |
1467 | wxDELETE(m_file); | |
1468 | m_protocolSink->ReportResult(S_OK, 0, NULL); | |
1469 | //We are eof and so finished | |
1470 | return S_OK; | |
1471 | } | |
1472 | else if(err == wxSTREAM_READ_ERROR) | |
1473 | { | |
1474 | wxDELETE(m_file); | |
1475 | return INET_E_DOWNLOAD_FAILURE; | |
1476 | } | |
0995b9dc SL |
1477 | else |
1478 | { | |
070d6391 | 1479 | //Dummy return to suppress a compiler warning |
0995b9dc SL |
1480 | wxFAIL; |
1481 | return INET_E_DOWNLOAD_FAILURE; | |
1482 | } | |
7d3f6b4d SL |
1483 | } |
1484 | ||
9f194b9d SL |
1485 | BEGIN_IID_TABLE(ClassFactory) |
1486 | ADD_IID(Unknown) | |
1487 | ADD_IID(ClassFactory) | |
1488 | END_IID_TABLE; | |
1489 | ||
1490 | IMPLEMENT_IUNKNOWN_METHODS(ClassFactory) | |
1491 | ||
a9c5eac9 | 1492 | HRESULT STDMETHODCALLTYPE ClassFactory::CreateInstance(IUnknown* pUnkOuter, REFIID riid, |
7d3f6b4d SL |
1493 | void ** ppvObject) |
1494 | { | |
60eabdbe | 1495 | if (pUnkOuter) |
7d3f6b4d | 1496 | return CLASS_E_NOAGGREGATION; |
29365629 | 1497 | VirtualProtocol* vp = new VirtualProtocol(m_handler); |
7d3f6b4d SL |
1498 | vp->AddRef(); |
1499 | HRESULT hr = vp->QueryInterface(riid, ppvObject); | |
1500 | vp->Release(); | |
1501 | return hr; | |
1502 | ||
60eabdbe | 1503 | } |
7d3f6b4d SL |
1504 | |
1505 | STDMETHODIMP ClassFactory::LockServer(BOOL fLock) | |
1506 | { | |
0995b9dc SL |
1507 | wxUnusedVar(fLock); |
1508 | return S_OK; | |
7d3f6b4d SL |
1509 | } |
1510 | ||
34326da7 | 1511 | wxIEContainer::wxIEContainer(wxWindow *parent, REFIID iid, IUnknown *pUnk, |
accc94d5 SL |
1512 | DocHostUIHandler* uiHandler) : |
1513 | wxActiveXContainer(parent,iid,pUnk) | |
1514 | { | |
1515 | m_uiHandler = uiHandler; | |
1516 | } | |
1517 | ||
1518 | wxIEContainer::~wxIEContainer() | |
1519 | { | |
1520 | } | |
1521 | ||
34326da7 | 1522 | bool wxIEContainer::QueryClientSiteInterface(REFIID iid, void **_interface, |
accc94d5 SL |
1523 | const char *&desc) |
1524 | { | |
1525 | if (m_uiHandler && IsEqualIID(iid, wxIID_IDocHostUIHandler)) | |
1526 | { | |
1527 | *_interface = (IUnknown *) (wxIDocHostUIHandler *) m_uiHandler; | |
1528 | desc = "IDocHostUIHandler"; | |
1529 | return true; | |
1530 | } | |
1531 | return false; | |
1532 | } | |
1533 | ||
a9c5eac9 | 1534 | HRESULT wxSTDCALL DocHostUIHandler::ShowContextMenu(DWORD dwID, POINT *ppt, |
34326da7 | 1535 | IUnknown *pcmdtReserved, |
accc94d5 SL |
1536 | IDispatch *pdispReserved) |
1537 | { | |
1538 | wxUnusedVar(dwID); | |
1539 | wxUnusedVar(ppt); | |
1540 | wxUnusedVar(pcmdtReserved); | |
1541 | wxUnusedVar(pdispReserved); | |
c420d57b SL |
1542 | if(m_browser->IsContextMenuEnabled()) |
1543 | return E_NOTIMPL; | |
1544 | else | |
1545 | return S_OK; | |
accc94d5 SL |
1546 | } |
1547 | ||
a9c5eac9 | 1548 | HRESULT wxSTDCALL DocHostUIHandler::GetHostInfo(DOCHOSTUIINFO *pInfo) |
accc94d5 | 1549 | { |
34326da7 | 1550 | //don't show 3d border and enable themes. |
accc94d5 SL |
1551 | pInfo->dwFlags = pInfo->dwFlags | DOCHOSTUIFLAG_NO3DBORDER | DOCHOSTUIFLAG_THEME; |
1552 | return S_OK; | |
1553 | } | |
1554 | ||
a9c5eac9 | 1555 | HRESULT wxSTDCALL DocHostUIHandler::ShowUI(DWORD dwID, |
34326da7 | 1556 | IOleInPlaceActiveObject *pActiveObject, |
accc94d5 SL |
1557 | IOleCommandTarget *pCommandTarget, |
1558 | IOleInPlaceFrame *pFrame, | |
1559 | IOleInPlaceUIWindow *pDoc) | |
1560 | { | |
1561 | wxUnusedVar(dwID); | |
1562 | wxUnusedVar(pActiveObject); | |
1563 | wxUnusedVar(pCommandTarget); | |
1564 | wxUnusedVar(pFrame); | |
1565 | wxUnusedVar(pDoc); | |
1566 | return S_FALSE; | |
1567 | } | |
1568 | ||
a9c5eac9 | 1569 | HRESULT wxSTDCALL DocHostUIHandler::HideUI(void) |
accc94d5 SL |
1570 | { |
1571 | return E_NOTIMPL; | |
1572 | } | |
1573 | ||
a9c5eac9 | 1574 | HRESULT wxSTDCALL DocHostUIHandler::UpdateUI(void) |
accc94d5 SL |
1575 | { |
1576 | return E_NOTIMPL; | |
1577 | } | |
1578 | ||
a9c5eac9 | 1579 | HRESULT wxSTDCALL DocHostUIHandler::EnableModeless(BOOL fEnable) |
accc94d5 SL |
1580 | { |
1581 | wxUnusedVar(fEnable); | |
1582 | return E_NOTIMPL; | |
1583 | } | |
1584 | ||
a9c5eac9 | 1585 | HRESULT wxSTDCALL DocHostUIHandler::OnDocWindowActivate(BOOL fActivate) |
accc94d5 SL |
1586 | { |
1587 | wxUnusedVar(fActivate); | |
1588 | return E_NOTIMPL; | |
1589 | } | |
1590 | ||
a9c5eac9 | 1591 | HRESULT wxSTDCALL DocHostUIHandler::OnFrameWindowActivate(BOOL fActivate) |
accc94d5 SL |
1592 | { |
1593 | wxUnusedVar(fActivate); | |
1594 | return E_NOTIMPL; | |
1595 | } | |
1596 | ||
a9c5eac9 | 1597 | HRESULT wxSTDCALL DocHostUIHandler::ResizeBorder(LPCRECT prcBorder, |
accc94d5 SL |
1598 | IOleInPlaceUIWindow *pUIWindow, |
1599 | BOOL fFrameWindow) | |
1600 | { | |
1601 | wxUnusedVar(prcBorder); | |
1602 | wxUnusedVar(pUIWindow); | |
1603 | wxUnusedVar(fFrameWindow); | |
1604 | return E_NOTIMPL; | |
1605 | } | |
1606 | ||
a9c5eac9 | 1607 | HRESULT wxSTDCALL DocHostUIHandler::TranslateAccelerator(LPMSG lpMsg, |
accc94d5 SL |
1608 | const GUID *pguidCmdGroup, |
1609 | DWORD nCmdID) | |
1610 | { | |
1611 | if(lpMsg && lpMsg->message == WM_KEYDOWN) | |
1612 | { | |
4ed85025 SL |
1613 | // check control is down but that it isn't right-alt which is mapped to |
1614 | // alt + ctrl | |
1615 | if(GetKeyState(VK_CONTROL) & 0x8000 && | |
1616 | !(GetKeyState(VK_MENU) & 0x8000)) | |
accc94d5 | 1617 | { |
e5f9b4ae VZ |
1618 | //skip the accelerators used by the control |
1619 | switch(lpMsg->wParam) | |
accc94d5 | 1620 | { |
e5f9b4ae VZ |
1621 | case 'F': |
1622 | case 'L': | |
1623 | case 'N': | |
1624 | case 'O': | |
1625 | case 'P': | |
1626 | return S_OK; | |
accc94d5 SL |
1627 | } |
1628 | } | |
1629 | //skip F5 | |
1630 | if(lpMsg->wParam == VK_F5) | |
1631 | { | |
1632 | return S_OK; | |
1633 | } | |
1634 | } | |
1635 | ||
1636 | wxUnusedVar(pguidCmdGroup); | |
1637 | wxUnusedVar(nCmdID); | |
1638 | return E_NOTIMPL; | |
1639 | } | |
1640 | ||
a9c5eac9 | 1641 | HRESULT wxSTDCALL DocHostUIHandler::GetOptionKeyPath(LPOLESTR *pchKey,DWORD dw) |
accc94d5 SL |
1642 | { |
1643 | wxUnusedVar(pchKey); | |
1644 | wxUnusedVar(dw); | |
1645 | return E_NOTIMPL; | |
1646 | } | |
1647 | ||
a9c5eac9 | 1648 | HRESULT wxSTDCALL DocHostUIHandler::GetDropTarget(IDropTarget *pDropTarget, |
accc94d5 SL |
1649 | IDropTarget **ppDropTarget) |
1650 | { | |
1651 | wxUnusedVar(pDropTarget); | |
1652 | wxUnusedVar(ppDropTarget); | |
1653 | return E_NOTIMPL; | |
1654 | } | |
1655 | ||
a9c5eac9 | 1656 | HRESULT wxSTDCALL DocHostUIHandler::GetExternal(IDispatch **ppDispatch) |
accc94d5 SL |
1657 | { |
1658 | wxUnusedVar(ppDispatch); | |
1659 | return E_NOTIMPL; | |
1660 | } | |
1661 | ||
a9c5eac9 | 1662 | HRESULT wxSTDCALL DocHostUIHandler::TranslateUrl(DWORD dwTranslate, |
accc94d5 SL |
1663 | OLECHAR *pchURLIn, |
1664 | OLECHAR **ppchURLOut) | |
1665 | { | |
1666 | wxUnusedVar(dwTranslate); | |
1667 | wxUnusedVar(pchURLIn); | |
1668 | wxUnusedVar(ppchURLOut); | |
1669 | return E_NOTIMPL; | |
1670 | } | |
1671 | ||
a9c5eac9 | 1672 | HRESULT wxSTDCALL DocHostUIHandler::FilterDataObject(IDataObject *pDO, IDataObject **ppDORet) |
accc94d5 SL |
1673 | { |
1674 | wxUnusedVar(pDO); | |
1675 | wxUnusedVar(ppDORet); | |
1676 | return E_NOTIMPL; | |
1677 | } | |
1678 | ||
1679 | BEGIN_IID_TABLE(DocHostUIHandler) | |
1680 | ADD_IID(Unknown) | |
1681 | ADD_RAW_IID(wxIID_IDocHostUIHandler) | |
1682 | END_IID_TABLE; | |
1683 | ||
1684 | IMPLEMENT_IUNKNOWN_METHODS(DocHostUIHandler) | |
1685 | ||
9d2f31db | 1686 | #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE |