+ //A little speed-up to avoid to re-alloc in the positions vector.
+ if(text.Len() < 3 && m_findPointers.capacity() < 500)
+ {
+ m_findPointers.reserve(text.Len() == 1 ? 1000 : 500);
+ }
+
+ while(ptrBegin->FindText(text_bstr, find_flag, ptrEnd, NULL) == S_OK)
+ {
+ wxCOMPtr<IHTMLElement> elm;
+ if(ptrBegin->CurrentScope(&elm) == S_OK)
+ {
+ if(IsElementVisible(elm))
+ {
+ //Highlight the word if the flag was set.
+ if(flags & wxWEBVIEW_FIND_HIGHLIGHT_RESULT)
+ {
+ IHTMLElement* pFontEl;
+ pIMS->CreateElement(wxTAGID_FONT, attr_bstr, &pFontEl);
+ pIMS->InsertElement(pFontEl, ptrBegin, ptrEnd);
+ }
+ if(internal_flag & wxWEBVIEW_FIND_REMOVE_HIGHLIGHT)
+ {
+ IHTMLElement* pFontEl;
+ ptrBegin->CurrentScope(&pFontEl);
+ pIMS->RemoveElement(pFontEl);
+ pFontEl->Release();
+ }
+ if(internal_flag & wxWEBVIEW_FIND_ADD_POINTERS)
+ {
+ wxIMarkupPointer *cptrBegin, *cptrEnd;
+ pIMS->CreateMarkupPointer(&cptrBegin);
+ pIMS->CreateMarkupPointer(&cptrEnd);
+ cptrBegin->MoveToPointer(ptrBegin);
+ cptrEnd->MoveToPointer(ptrEnd);
+ m_findPointers.push_back(wxFindPointers(cptrBegin,cptrEnd));
+ }
+ }
+ }
+ ptrBegin->MoveToPointer(ptrEnd);
+ }
+ //Clean up.
+ SysFreeString(text_bstr);
+ SysFreeString(attr_bstr);
+ }
+ }
+}
+
+long wxWebViewIE::FindNext(int direction)
+{
+ //Don't bother if we have no pointers set.
+ if(m_findPointers.empty())
+ {
+ return wxNOT_FOUND;
+ }
+ //Manage the find position and do some checks.
+ if(direction > 0)
+ {
+ m_findPosition++;
+ }
+ else
+ {
+ m_findPosition--;
+ }
+
+ if(m_findPosition >= (signed)m_findPointers.size())
+ {
+ if(m_findFlags & wxWEBVIEW_FIND_WRAP)
+ {
+ m_findPosition = 0;
+ }
+ else
+ {
+ m_findPosition--;
+ return wxNOT_FOUND;
+ }
+ }
+ else if(m_findPosition < 0)
+ {
+ if(m_findFlags & wxWEBVIEW_FIND_WRAP)
+ {
+ m_findPosition = m_findPointers.size()-1;
+ }
+ else
+ {
+ m_findPosition++;
+ return wxNOT_FOUND;
+ }
+ }
+
+ wxCOMPtr<IHTMLDocument2> document = GetDocument();
+ wxCOMPtr<IHTMLElement> body_element;
+
+ long ret = -1;
+ //Now try to create a range from the body.
+ if(document && SUCCEEDED(document->get_body(&body_element)))
+ {
+ wxCOMPtr<IHTMLBodyElement> body;
+ if(SUCCEEDED(body_element->QueryInterface(IID_IHTMLBodyElement,(void**)&body)))
+ {
+ wxCOMPtr<wxIHTMLTxtRange> range;
+ if(SUCCEEDED(body->createTextRange((IHTMLTxtRange**)(&range))))
+ {
+ wxCOMPtr<wxIMarkupServices> pIMS;
+ //So far so good, now we try to position our find pointers.
+ if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupServices,(void **)&pIMS)))
+ {
+ wxIMarkupPointer *begin = m_findPointers[m_findPosition].begin, *end = m_findPointers[m_findPosition].end;
+ if(pIMS->MoveRangeToPointers(begin,end,range) == S_OK && range->select() == S_OK)
+ {
+ ret = m_findPosition;
+ }
+ }
+ }
+ }
+ }
+ return ret;
+}
+
+void wxWebViewIE::FindClear()
+{
+ //Reset find variables.
+ m_findText.Empty();
+ m_findFlags = wxWEBVIEW_FIND_DEFAULT;
+ m_findPosition = -1;
+
+ //The m_findPointers contains pointers for the found text.
+ //Since it uses ref counting we call release on the pointers first
+ //before we remove them from the vector. In other words do not just
+ //remove elements from m_findPointers without calling release first
+ //or you will get a memory leak.
+ size_t count = m_findPointers.size();
+ for(size_t i = 0; i < count; i++)
+ {
+ m_findPointers[i].begin->Release();
+ m_findPointers[i].end->Release();
+ }
+ m_findPointers.clear();
+}
+
+bool wxWebViewIE::EnableControlFeature(long flag, bool enable)
+{
+#if wxUSE_DYNLIB_CLASS
+
+ wxDynamicLibrary urlMon(wxT("urlmon.dll"));
+ if( urlMon.IsLoaded() &&
+ urlMon.HasSymbol("CoInternetSetFeatureEnabled") &&
+ urlMon.HasSymbol("CoInternetIsFeatureEnabled"))
+ {
+ typedef HRESULT (WINAPI *CoInternetSetFeatureEnabled_t)(DWORD, DWORD, BOOL);
+ typedef HRESULT (WINAPI *CoInternetIsFeatureEnabled_t)(DWORD, DWORD);
+
+ wxDYNLIB_FUNCTION(CoInternetSetFeatureEnabled_t, CoInternetSetFeatureEnabled, urlMon);
+ wxDYNLIB_FUNCTION(CoInternetIsFeatureEnabled_t, CoInternetIsFeatureEnabled, urlMon);
+
+ HRESULT hr = (*pfnCoInternetIsFeatureEnabled)(flag,
+ 0x2 /* SET_FEATURE_ON_PROCESS */);
+ if((hr == S_OK && enable) || (hr == S_FALSE && !enable))
+ return true;
+
+ hr = (*pfnCoInternetSetFeatureEnabled)(flag,
+ 0x2/* SET_FEATURE_ON_PROCESS */,
+ (enable ? TRUE : FALSE));
+ if ( FAILED(hr) )
+ {
+ wxLogApiError(wxT("CoInternetSetFeatureEnabled"), hr);
+ return false;
+ }
+ return true;
+ }
+ return false;
+#else
+ wxUnusedVar(flag);
+ wxUnusedVar(enable);
+ return false;
+#endif // wxUSE_DYNLIB_CLASS/!wxUSE_DYNLIB_CLASS