+ wxCOMPtr<IHTMLDocument2> document(GetDocument());
+
+ if(document)
+ {
+ document->execCommand(SysAllocString(command.wc_str()), VARIANT_FALSE, VARIANT(), NULL);
+ }
+}
+
+wxCOMPtr<IHTMLDocument2> wxWebViewIE::GetDocument() const
+{
+ wxCOMPtr<IDispatch> dispatch;
+ wxCOMPtr<IHTMLDocument2> document;
+ HRESULT result = m_webBrowser->get_Document(&dispatch);
+ if(dispatch && SUCCEEDED(result))
+ {
+ //document is set to null automatically if the interface isn't supported
+ dispatch->QueryInterface(IID_IHTMLDocument2, (void**)&document);
+ }
+ return document;
+}
+
+bool wxWebViewIE::IsElementVisible(wxCOMPtr<IHTMLElement> elm)
+{
+ wxCOMPtr<IHTMLElement> elm1 = elm;
+ BSTR tmp_bstr;
+ bool is_visible = true;
+ //This method is not perfect but it does discover most of the hidden elements.
+ //so if a better solution is found, then please do improve.
+ while(elm1)
+ {
+ wxCOMPtr<wxIHTMLElement2> elm2;
+ if(SUCCEEDED(elm1->QueryInterface(wxIID_IHTMLElement2, (void**) &elm2)))
+ {
+ wxCOMPtr<wxIHTMLCurrentStyle> style;
+ if(SUCCEEDED(elm2->get_currentStyle(&style)))
+ {
+ //Check if the object has the style display:none.
+ if((style->get_display(&tmp_bstr) != S_OK) ||
+ (tmp_bstr != NULL && (_wcsicmp(tmp_bstr, L"none") == 0)))
+ {
+ is_visible = false;
+ }
+ //Check if the object has the style visibility:hidden.
+ if((is_visible && (style->get_visibility(&tmp_bstr) != S_OK)) ||
+ (tmp_bstr != NULL && _wcsicmp(tmp_bstr, L"hidden") == 0))
+ {
+ is_visible = false;
+ }
+ style->Release();
+ }
+ elm2->Release();
+ }
+
+ //Lets check the object's parent element.
+ IHTMLElement* parent;
+ if(is_visible && SUCCEEDED(elm1->get_parentElement(&parent)))
+ {
+ elm1 = parent;
+ }
+ else
+ {
+ elm1->Release();
+ break;
+ }
+ }
+ return is_visible;
+}
+
+void wxWebViewIE::FindInternal(const wxString& text, int flags, int internal_flag)
+{
+ long find_flag = 0;
+ wxCOMPtr<wxIMarkupServices> pIMS;
+ wxCOMPtr<IHTMLDocument2> document = GetDocument();
+
+ //This function does the acutal work.
+ if(document && SUCCEEDED(document->QueryInterface(wxIID_IMarkupServices, (void **)&pIMS)))
+ {
+ wxCOMPtr<wxIMarkupContainer> pIMC;
+ if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupContainer, (void **)&pIMC)))
+ {
+ wxCOMPtr<wxIMarkupPointer> ptrBegin, ptrEnd;
+ BSTR attr_bstr = SysAllocString(L"style=\"background-color:#ffff00\"");
+ BSTR text_bstr = SysAllocString(text.wc_str());
+ pIMS->CreateMarkupPointer(&ptrBegin);
+ pIMS->CreateMarkupPointer(&ptrEnd);
+
+ ptrBegin->SetGravity(wxPOINTER_GRAVITY_Right);
+ ptrBegin->MoveToContainer(pIMC, TRUE);
+ //Create the find flag from the wx one.
+ if(flags & wxWEBVIEW_FIND_ENTIRE_WORD)
+ {
+ find_flag |= wxFINDTEXT_WHOLEWORD;
+ }
+ if(flags & wxWEBVIEW_FIND_MATCH_CASE)
+ {
+ find_flag |= wxFINDTEXT_MATCHCASE;
+ }
+
+ //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);