m_webBrowser->put_RegisterAsDropTarget(VARIANT_TRUE);
m_uiHandler = new DocHostUIHandler;
- m_uiHandler->AddRef();
m_container = new wxIEContainer(this, IID_IWebBrowser2, m_webBrowser, m_uiHandler);
{
m_factories[i]->Release();
}
-
- m_uiHandler->Release();
}
void wxWebViewIE::LoadURL(const wxString& url)
hr = SafeArrayUnaccessData(psaStrings);
- IHTMLDocument2* document = GetDocument();
+ wxCOMPtr<IHTMLDocument2> document(GetDocument());
if(!document)
return;
document->write(psaStrings);
document->close();
- document->Release();
SafeArrayDestroy(psaStrings);
return;
document->write(psaStrings);
- document->Release();
// SafeArrayDestroy calls SysFreeString for each BSTR
SafeArrayDestroy(psaStrings);
wxString wxWebViewIE::GetPageSource() const
{
- IHTMLDocument2* document = GetDocument();
+ wxCOMPtr<IHTMLDocument2> document(GetDocument());
if(document)
{
- IHTMLElement *bodyTag = NULL;
- IHTMLElement *htmlTag = NULL;
+ wxCOMPtr<IHTMLElement> bodyTag;
+ wxCOMPtr<IHTMLElement> htmlTag;
wxString source;
HRESULT hr = document->get_body(&bodyTag);
if(SUCCEEDED(hr))
BSTR bstr;
htmlTag->get_outerHTML(&bstr);
source = wxString(bstr);
- htmlTag->Release();
}
- bodyTag->Release();
}
-
- document->Release();
return source;
}
else
wxString wxWebViewIE::GetCurrentTitle() const
{
- IHTMLDocument2* document = GetDocument();
+ wxCOMPtr<IHTMLDocument2> document(GetDocument());
if(document)
{
BSTR title;
document->get_nameProp(&title);
- document->Release();
return wxString(title);
}
else
{
return CanExecCommand("Copy");
}
+
bool wxWebViewIE::CanPaste() const
{
return CanExecCommand("Paste");
{
return CanExecCommand("Undo");
}
+
bool wxWebViewIE::CanRedo() const
{
return CanExecCommand("Redo");
void wxWebViewIE::SetEditable(bool enable)
{
- IHTMLDocument2* document = GetDocument();
+ wxCOMPtr<IHTMLDocument2> document(GetDocument());
if(document)
{
else
document->put_designMode(SysAllocString(L"Off"));
- document->Release();
}
}
bool wxWebViewIE::IsEditable() const
{
- IHTMLDocument2* document = GetDocument();
+ wxCOMPtr<IHTMLDocument2> document(GetDocument());
if(document)
{
BSTR mode;
document->get_designMode(&mode);
- document->Release();
if(wxString(mode) == "On")
return true;
else
bool wxWebViewIE::HasSelection() const
{
- IHTMLDocument2* document = GetDocument();
+ wxCOMPtr<IHTMLDocument2> document(GetDocument());
if(document)
{
- IHTMLSelectionObject* selection;
+ wxCOMPtr<IHTMLSelectionObject> selection;
wxString sel;
HRESULT hr = document->get_selection(&selection);
if(SUCCEEDED(hr))
BSTR type;
selection->get_type(&type);
sel = wxString(type);
- selection->Release();
}
- document->Release();
return sel != "None";
}
else
wxString wxWebViewIE::GetSelectedText() const
{
- IHTMLDocument2* document = GetDocument();
+ wxCOMPtr<IHTMLDocument2> document(GetDocument());
if(document)
{
- IHTMLSelectionObject* selection;
+ wxCOMPtr<IHTMLSelectionObject> selection;
wxString selected;
HRESULT hr = document->get_selection(&selection);
if(SUCCEEDED(hr))
{
- IDispatch* disrange;
+ wxCOMPtr<IDispatch> disrange;
hr = selection->createRange(&disrange);
if(SUCCEEDED(hr))
{
- IHTMLTxtRange* range;
+ wxCOMPtr<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;
}
else
wxString wxWebViewIE::GetSelectedSource() const
{
- IHTMLDocument2* document = GetDocument();
+ wxCOMPtr<IHTMLDocument2> document(GetDocument());
if(document)
{
- IHTMLSelectionObject* selection;
+ wxCOMPtr<IHTMLSelectionObject> selection;
wxString selected;
HRESULT hr = document->get_selection(&selection);
if(SUCCEEDED(hr))
{
- IDispatch* disrange;
+ wxCOMPtr<IDispatch> disrange;
hr = selection->createRange(&disrange);
if(SUCCEEDED(hr))
{
- IHTMLTxtRange* range;
+ wxCOMPtr<IHTMLTxtRange> range;
hr = disrange->QueryInterface(IID_IHTMLTxtRange, (void**)&range);
if(SUCCEEDED(hr))
{
BSTR text;
range->get_htmlText(&text);
selected = wxString(text);
- range->Release();
}
- disrange->Release();
}
- selection->Release();
}
- document->Release();
return selected;
}
else
void wxWebViewIE::ClearSelection()
{
- IHTMLDocument2* document = GetDocument();
+ wxCOMPtr<IHTMLDocument2> document(GetDocument());
if(document)
{
- IHTMLSelectionObject* selection;
+ wxCOMPtr<IHTMLSelectionObject> selection;
wxString selected;
HRESULT hr = document->get_selection(&selection);
if(SUCCEEDED(hr))
{
selection->empty();
- selection->Release();
}
- document->Release();
}
}
wxString wxWebViewIE::GetPageText() const
{
- IHTMLDocument2* document = GetDocument();
+ wxCOMPtr<IHTMLDocument2> document(GetDocument());
if(document)
{
wxString text;
- IHTMLElement* body;
+ wxCOMPtr<IHTMLElement> body;
HRESULT hr = document->get_body(&body);
if(SUCCEEDED(hr))
{
BSTR out;
body->get_innerText(&out);
text = wxString(out);
- body->Release();
}
- document->Release();
return text;
}
else
void wxWebViewIE::RunScript(const wxString& javascript)
{
- IHTMLDocument2* document = GetDocument();
+ wxCOMPtr<IHTMLDocument2> document(GetDocument());
if(document)
{
- IHTMLWindow2* window;
+ wxCOMPtr<IHTMLWindow2> window;
wxString language = "javascript";
HRESULT hr = document->get_parentWindow(&window);
if(SUCCEEDED(hr))
SysAllocString(language.wc_str()),
&level);
}
- document->Release();
}
}
bool wxWebViewIE::CanExecCommand(wxString command) const
{
- IHTMLDocument2* document = GetDocument();
+ wxCOMPtr<IHTMLDocument2> document(GetDocument());
if(document)
{
VARIANT_BOOL enabled;
document->queryCommandEnabled(SysAllocString(command.wc_str()), &enabled);
- document->Release();
return (enabled == VARIANT_TRUE);
}
void wxWebViewIE::ExecCommand(wxString command)
{
- IHTMLDocument2* document = GetDocument();
+ wxCOMPtr<IHTMLDocument2> document(GetDocument());
if(document)
{
document->execCommand(SysAllocString(command.wc_str()), VARIANT_FALSE, VARIANT(), NULL);
- document->Release();
}
}
-IHTMLDocument2* wxWebViewIE::GetDocument() const
+wxCOMPtr<IHTMLDocument2> wxWebViewIE::GetDocument() const
{
- IDispatch* dispatch;
+ wxCOMPtr<IDispatch> dispatch;
+ wxCOMPtr<IHTMLDocument2> document;
HRESULT result = m_webBrowser->get_Document(&dispatch);
- if(SUCCEEDED(result))
+ if(dispatch && SUCCEEDED(result))
{
- IHTMLDocument2* document;
- dispatch->QueryInterface(IID_IHTMLDocument2, (void**)&document);
//document is set to null automatically if the interface isn't supported
- return document;
- }
- else
- {
- return NULL;
+ dispatch->QueryInterface(IID_IHTMLDocument2, (void**)&document);
}
+ return document;
}
bool wxWebViewIE::EnableControlFeature(long flag, bool enable)
#if wxUSE_DYNLIB_CLASS
wxDynamicLibrary urlMon(wxT("urlmon.dll"));
- if( urlMon.IsLoaded() &&
- urlMon.HasSymbol("CoInternetSetFeatureEnabled") &&
+ if( urlMon.IsLoaded() &&
+ urlMon.HasSymbol("CoInternetSetFeatureEnabled") &&
urlMon.HasSymbol("CoInternetIsFeatureEnabled"))
{
typedef HRESULT (WINAPI *CoInternetSetFeatureEnabled_t)(DWORD, DWORD, BOOL);
return S_OK;
}
-wxIEContainer::wxIEContainer(wxWindow *parent, REFIID iid, IUnknown *pUnk,
+wxIEContainer::wxIEContainer(wxWindow *parent, REFIID iid, IUnknown *pUnk,
DocHostUIHandler* uiHandler) :
wxActiveXContainer(parent,iid,pUnk)
{
{
}
-bool wxIEContainer::QueryClientSiteInterface(REFIID iid, void **_interface,
+bool wxIEContainer::QueryClientSiteInterface(REFIID iid, void **_interface,
const char *&desc)
{
if (m_uiHandler && IsEqualIID(iid, wxIID_IDocHostUIHandler))
return false;
}
-HRESULT DocHostUIHandler::ShowContextMenu(DWORD dwID, POINT *ppt,
- IUnknown *pcmdtReserved,
+HRESULT DocHostUIHandler::ShowContextMenu(DWORD dwID, POINT *ppt,
+ IUnknown *pcmdtReserved,
IDispatch *pdispReserved)
{
wxUnusedVar(dwID);
HRESULT DocHostUIHandler::GetHostInfo(DOCHOSTUIINFO *pInfo)
{
- //don't show 3d border and ebales themes.
+ //don't show 3d border and enable themes.
pInfo->dwFlags = pInfo->dwFlags | DOCHOSTUIFLAG_NO3DBORDER | DOCHOSTUIFLAG_THEME;
return S_OK;
}
HRESULT DocHostUIHandler::ShowUI(DWORD dwID,
- IOleInPlaceActiveObject *pActiveObject,
+ IOleInPlaceActiveObject *pActiveObject,
IOleCommandTarget *pCommandTarget,
IOleInPlaceFrame *pFrame,
IOleInPlaceUIWindow *pDoc)
return E_NOTIMPL;
}
-HRESULT DocHostUIHandler::ResizeBorder(LPCRECT prcBorder,
+HRESULT DocHostUIHandler::ResizeBorder(LPCRECT prcBorder,
IOleInPlaceUIWindow *pUIWindow,
BOOL fFrameWindow)
{
return E_NOTIMPL;
}
-HRESULT DocHostUIHandler::TranslateAccelerator(LPMSG lpMsg,
+HRESULT DocHostUIHandler::TranslateAccelerator(LPMSG lpMsg,
const GUID *pguidCmdGroup,
DWORD nCmdID)
{
//control is down?
if((GetKeyState(VK_CONTROL) & 0x8000 ))
{
- //skip CTRL-N, CTRL-F and CTRL-P
- if(lpMsg->wParam == 'N' || lpMsg->wParam == 'P' || lpMsg->wParam == 'F')
+ //skip the accelerators used by the control
+ switch(lpMsg->wParam)
{
- return S_OK;
+ case 'F':
+ case 'L':
+ case 'N':
+ case 'O':
+ case 'P':
+ return S_OK;
}
}
//skip F5