X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ce7fe42e848cc0c9058dae906c3a7bded50681e6..be10c7f969bb460dc79bd8946d59bf54c98ac660:/src/msw/webview_ie.cpp?ds=sidebyside diff --git a/src/msw/webview_ie.cpp b/src/msw/webview_ie.cpp index d52a5ad373..9a3d3ea019 100644 --- a/src/msw/webview_ie.cpp +++ b/src/msw/webview_ie.cpp @@ -2,7 +2,6 @@ // Name: src/msw/webview_ie.cpp // Purpose: wxMSW wxWebViewIE class implementation for web view component // Author: Marianne Gagnon -// Id: $Id$ // Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -670,9 +669,13 @@ long wxWebViewIE::Find(const wxString& text, int flags) ClearSelection(); m_findText = text; m_findFlags = flags; - //find the text and return count. + //find the text and return wxNOT_FOUND if there are no matches. FindInternal(text, flags, wxWEBVIEW_FIND_ADD_POINTERS); - return m_findPointers.empty() ? wxNOT_FOUND : m_findPointers.size(); + if(m_findPointers.empty()) + return wxNOT_FOUND; + + // Or their number if there are. + return m_findPointers.size(); } void wxWebViewIE::SetEditable(bool enable) @@ -940,19 +943,19 @@ wxCOMPtr wxWebViewIE::GetDocument() const return document; } -bool wxWebViewIE::IsElementVisible(IHTMLElement* elm) +bool wxWebViewIE::IsElementVisible(wxCOMPtr elm) { - wxIHTMLCurrentStyle* style; - IHTMLElement *elm1 = elm; - wxIHTMLElement2 *elm2; + wxCOMPtr 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 elm2; if(SUCCEEDED(elm1->QueryInterface(wxIID_IHTMLElement2, (void**) &elm2))) { + wxCOMPtr style; if(SUCCEEDED(elm2->get_currentStyle(&style))) { //Check if the object has the style display:none. @@ -976,7 +979,6 @@ bool wxWebViewIE::IsElementVisible(IHTMLElement* elm) IHTMLElement* parent; if(is_visible && SUCCEEDED(elm1->get_parentElement(&parent))) { - elm1->Release(); elm1 = parent; } else @@ -990,17 +992,17 @@ bool wxWebViewIE::IsElementVisible(IHTMLElement* elm) void wxWebViewIE::FindInternal(const wxString& text, int flags, int internal_flag) { - wxIMarkupServices *pIMS; - wxIMarkupContainer *pIMC; - wxIMarkupPointer *ptrBegin, *ptrEnd; - IHTMLElement* elm; long find_flag = 0; - IHTMLDocument2 *document = GetDocument(); + wxCOMPtr pIMS; + wxCOMPtr document = GetDocument(); + //This function does the acutal work. - if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupServices, (void **)&pIMS))) + if(document && SUCCEEDED(document->QueryInterface(wxIID_IMarkupServices, (void **)&pIMS))) { + wxCOMPtr pIMC; if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupContainer, (void **)&pIMC))) { + wxCOMPtr ptrBegin, ptrEnd; BSTR attr_bstr = SysAllocString(L"style=\"background-color:#ffff00\""); BSTR text_bstr = SysAllocString(text.wc_str()); pIMS->CreateMarkupPointer(&ptrBegin); @@ -1026,6 +1028,7 @@ void wxWebViewIE::FindInternal(const wxString& text, int flags, int internal_fla while(ptrBegin->FindText(text_bstr, find_flag, ptrEnd, NULL) == S_OK) { + wxCOMPtr elm; if(ptrBegin->CurrentScope(&elm) == S_OK) { if(IsElementVisible(elm)) @@ -1054,20 +1057,14 @@ void wxWebViewIE::FindInternal(const wxString& text, int flags, int internal_fla m_findPointers.push_back(wxFindPointers(cptrBegin,cptrEnd)); } } - elm->Release(); } ptrBegin->MoveToPointer(ptrEnd); } //Clean up. SysFreeString(text_bstr); SysFreeString(attr_bstr); - pIMC->Release(); - ptrBegin->Release(); - ptrEnd->Release(); } - pIMS->Release(); } - document->Release(); } long wxWebViewIE::FindNext(int direction) @@ -1111,20 +1108,21 @@ long wxWebViewIE::FindNext(int direction) return wxNOT_FOUND; } } - //some variables to use later on. - IHTMLElement *body_element; - IHTMLBodyElement *body; - wxIHTMLTxtRange *range = NULL; - wxIMarkupServices *pIMS; - IHTMLDocument2 *document = GetDocument(); + + wxCOMPtr document = GetDocument(); + wxCOMPtr body_element; + long ret = -1; //Now try to create a range from the body. - if(SUCCEEDED(document->get_body(&body_element))) + if(document && SUCCEEDED(document->get_body(&body_element))) { + wxCOMPtr body; if(SUCCEEDED(body_element->QueryInterface(IID_IHTMLBodyElement,(void**)&body))) { + wxCOMPtr range; if(SUCCEEDED(body->createTextRange((IHTMLTxtRange**)(&range)))) { + wxCOMPtr pIMS; //So far so good, now we try to position our find pointers. if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupServices,(void **)&pIMS))) { @@ -1133,15 +1131,10 @@ long wxWebViewIE::FindNext(int direction) { ret = m_findPosition; } - pIMS->Release(); } - range->Release(); } - body->Release(); } - body_element->Release(); } - document->Release(); return ret; }