X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c7cbe308f6273245493ee0da52dc80385805cb40..3dffc2aea2597a2df3c3faee052ca232635ab69d:/src/msw/webview_ie.cpp diff --git a/src/msw/webview_ie.cpp b/src/msw/webview_ie.cpp index 2d04aba3e4..2e4e7a2e75 100644 --- a/src/msw/webview_ie.cpp +++ b/src/msw/webview_ie.cpp @@ -122,14 +122,10 @@ bool wxWebViewIE::Create(wxWindow* parent, void wxWebViewIE::LoadUrl(const wxString& url) { - wxVariant out = m_ie.CallMethod("Navigate", (BSTR) url.wc_str(), - NULL, NULL, NULL, NULL); - - // FIXME: why is out value null?? - //(HRESULT)(out.GetLong()) == S_OK; + m_ie.CallMethod("Navigate", (BSTR) url.wc_str(), NULL, NULL, NULL, NULL); } -void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl) +void wxWebViewIE::SetPage(const wxString& html, const wxString&) { LoadUrl("about:blank"); @@ -170,22 +166,20 @@ wxString wxWebViewIE::GetPageSource() IHTMLDocument2* document = GetDocument(); IHTMLElement *bodyTag = NULL; IHTMLElement *htmlTag = NULL; - document->get_body(&bodyTag); - wxASSERT(bodyTag != NULL); + BSTR bstr; + HRESULT hr = document->get_body(&bodyTag); + if(SUCCEEDED(hr)) + { + hr = bodyTag->get_parentElement(&htmlTag); + if(SUCCEEDED(hr)) + { + htmlTag->get_outerHTML(&bstr); + htmlTag->Release(); + } + bodyTag->Release(); + } document->Release(); - bodyTag->get_parentElement(&htmlTag); - wxASSERT(htmlTag != NULL); - - BSTR bstr; - htmlTag->get_outerHTML(&bstr); - - bodyTag->Release(); - htmlTag->Release(); - - //wxMessageBox(wxString(bstr)); - - // TODO: check encoding return wxString(bstr); } @@ -271,7 +265,6 @@ int wxWebViewIE::GetIETextZoom() wxASSERT (result == S_OK); int zoom = V_I4(&zoomVariant); - // wxMessageBox(wxString::Format("Zoom : %i", zoom)); VariantClear (&zoomVariant); return zoom; @@ -353,7 +346,7 @@ bool wxWebViewIE::CanGoBack() bool wxWebViewIE::CanGoForward() { if(m_historyEnabled) - return m_historyPosition != m_historyList.size() - 1; + return m_historyPosition != static_cast(m_historyList.size()) - 1; else return false; } @@ -367,7 +360,8 @@ void wxWebViewIE::LoadHistoryItem(wxSharedPtr item) if(m_historyList[i].get() == item.get()) pos = i; } - wxASSERT_MSG(pos != m_historyList.size(), "invalid history item"); + wxASSERT_MSG(pos != static_cast(m_historyList.size()), + "invalid history item"); m_historyLoadingFromList = true; LoadUrl(item->GetUrl()); m_historyPosition = pos; @@ -390,7 +384,7 @@ wxVector > wxWebViewIE::GetForwardHistory() wxVector > forwardhist; //As we don't have std::copy or an iterator constructor in the wxwidgets //native vector we construct it by hand - for(int i = m_historyPosition + 1; i < m_historyList.size(); i++) + for(int i = m_historyPosition + 1; i < static_cast(m_historyList.size()); i++) { forwardhist.push_back(m_historyList[i]); } @@ -409,10 +403,7 @@ void wxWebViewIE::GoForward() void wxWebViewIE::Stop() { - wxVariant out = m_ie.CallMethod("Stop"); - - // FIXME: why is out value null?? - //return (HRESULT)(out.GetLong()) == S_OK; + m_ie.CallMethod("Stop"); } void wxWebViewIE::ClearHistory() @@ -490,9 +481,10 @@ wxString wxWebViewIE::GetCurrentURL() wxString wxWebViewIE::GetCurrentTitle() { IHTMLDocument2* document = GetDocument(); - BSTR title; + document->get_nameProp(&title); + document->Release(); return wxString(title); } @@ -551,6 +543,8 @@ void wxWebViewIE::SetEditable(bool enable) document->put_designMode(SysAllocString(L"On")); else document->put_designMode(SysAllocString(L"Off")); + + document->Release(); } bool wxWebViewIE::IsEditable() @@ -562,14 +556,71 @@ bool wxWebViewIE::IsEditable() return true; else return false; + + document->Release(); } -bool wxWebViewIE::CanExecCommand(wxString command) +void wxWebViewIE::SelectAll() +{ + ExecCommand("SelectAll"); +} + +bool wxWebViewIE::HasSelection() { IHTMLDocument2* document = GetDocument(); + IHTMLSelectionObject* selection; + BSTR type; + HRESULT hr = document->get_selection(&selection); + if(SUCCEEDED(hr)) + { + selection->get_type(&type); + selection->Release(); + } + document->Release(); + return wxString(type) != "None"; +} + +void wxWebViewIE::DeleteSelection() +{ + ExecCommand("Delete"); +} + +wxString wxWebViewIE::GetSelectedText() +{ + IHTMLDocument2* document = GetDocument(); + IHTMLSelectionObject* selection; + wxString selected; + HRESULT hr = document->get_selection(&selection); + if(SUCCEEDED(hr)) + { + IDispatch* disrange; + hr = selection->createRange(&disrange); + if(SUCCEEDED(hr)) + { + IHTMLTxtRange* range; + hr = disrange->QueryInterface(IID_IHTMLTxtRange, (void**)&range); + if(SUCCEEDED(hr)) + { + BSTR text; + range->get_text(&text); + selected = wxString(text); + range->Release(); + } + disrange->Release(); + } + selection->Release(); + } + document->Release(); + return selected; +} +bool wxWebViewIE::CanExecCommand(wxString command) +{ + IHTMLDocument2* document = GetDocument(); VARIANT_BOOL enabled; + document->queryCommandEnabled(SysAllocString(command.wc_str()), &enabled); + document->Release(); return (enabled == VARIANT_TRUE); } @@ -578,6 +629,7 @@ void wxWebViewIE::ExecCommand(wxString command) { IHTMLDocument2* document = GetDocument(); document->execCommand(SysAllocString(command.wc_str()), VARIANT_FALSE, VARIANT(), NULL); + document->Release(); } IHTMLDocument2* wxWebViewIE::GetDocument() @@ -659,7 +711,7 @@ void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt) { //If we are not at the end of the list, then erase everything //between us and the end before adding the new page - if(m_historyPosition != m_historyList.size() - 1) + if(m_historyPosition != static_cast(m_historyList.size()) - 1) { m_historyList.erase(m_historyList.begin() + m_historyPosition + 1, m_historyList.end());