+VirtualProtocol::VirtualProtocol(wxSharedPtr<wxWebViewHandler> handler)
+{
+ m_file = NULL;
+ m_handler = handler;
+}
+
+BEGIN_IID_TABLE(VirtualProtocol)
+ ADD_IID(Unknown)
+ ADD_RAW_IID(wxIID_IInternetProtocolRoot)
+ ADD_RAW_IID(wxIID_IInternetProtocol)
+END_IID_TABLE;
+
+IMPLEMENT_IUNKNOWN_METHODS(VirtualProtocol)
+
+HRESULT VirtualProtocol::Start(LPCWSTR szUrl, wxIInternetProtocolSink *pOIProtSink,
+ wxIInternetBindInfo *pOIBindInfo, DWORD grfPI,
+ HANDLE_PTR dwReserved)
+{
+ wxUnusedVar(szUrl);
+ wxUnusedVar(pOIBindInfo);
+ wxUnusedVar(grfPI);
+ wxUnusedVar(dwReserved);
+ m_protocolSink = pOIProtSink;
+
+ //We get the file itself from the protocol handler
+ m_file = m_handler->GetFile(szUrl);
+
+
+ if(!m_file)
+ return INET_E_RESOURCE_NOT_FOUND;
+
+ //We return the stream length for current and total size as we can always
+ //read the whole file from the stream
+ wxFileOffset length = m_file->GetStream()->GetLength();
+ m_protocolSink->ReportData(wxBSCF_FIRSTDATANOTIFICATION |
+ wxBSCF_DATAFULLYAVAILABLE |
+ wxBSCF_LASTDATANOTIFICATION,
+ length, length);
+ return S_OK;
+}
+
+HRESULT VirtualProtocol::Read(void *pv, ULONG cb, ULONG *pcbRead)
+{
+ //If the file is null we return false to indicte it is finished
+ if(!m_file)
+ return S_FALSE;
+
+ wxStreamError err = m_file->GetStream()->Read(pv, cb).GetLastError();
+ *pcbRead = m_file->GetStream()->LastRead();
+
+ if(err == wxSTREAM_NO_ERROR)
+ {
+ if(*pcbRead < cb)
+ {
+ wxDELETE(m_file);
+ m_protocolSink->ReportResult(S_OK, 0, NULL);
+ }
+ //As we are not eof there is more data
+ return S_OK;
+ }
+ else if(err == wxSTREAM_EOF)
+ {
+ wxDELETE(m_file);
+ m_protocolSink->ReportResult(S_OK, 0, NULL);
+ //We are eof and so finished
+ return S_OK;
+ }
+ else if(err == wxSTREAM_READ_ERROR)
+ {
+ wxDELETE(m_file);
+ return INET_E_DOWNLOAD_FAILURE;
+ }
+ else
+ {
+ //Dummy return to surpress a compiler warning
+ wxFAIL;
+ return INET_E_DOWNLOAD_FAILURE;
+ }
+}
+
+BEGIN_IID_TABLE(ClassFactory)
+ ADD_IID(Unknown)
+ ADD_IID(ClassFactory)
+END_IID_TABLE;
+
+IMPLEMENT_IUNKNOWN_METHODS(ClassFactory)
+
+HRESULT ClassFactory::CreateInstance(IUnknown* pUnkOuter, REFIID riid,
+ void ** ppvObject)
+{
+ if (pUnkOuter)
+ return CLASS_E_NOAGGREGATION;
+ VirtualProtocol* vp = new VirtualProtocol(m_handler);
+ vp->AddRef();
+ HRESULT hr = vp->QueryInterface(riid, ppvObject);
+ vp->Release();
+ return hr;
+
+}
+
+STDMETHODIMP ClassFactory::LockServer(BOOL fLock)
+{
+ wxUnusedVar(fLock);
+ return S_OK;
+}
+
+wxIEContainer::wxIEContainer(wxWindow *parent, REFIID iid, IUnknown *pUnk,
+ DocHostUIHandler* uiHandler) :
+ wxActiveXContainer(parent,iid,pUnk)
+{
+ m_uiHandler = uiHandler;
+}
+
+wxIEContainer::~wxIEContainer()
+{
+}
+
+bool wxIEContainer::QueryClientSiteInterface(REFIID iid, void **_interface,
+ const char *&desc)
+{
+ if (m_uiHandler && IsEqualIID(iid, wxIID_IDocHostUIHandler))
+ {
+ *_interface = (IUnknown *) (wxIDocHostUIHandler *) m_uiHandler;
+ desc = "IDocHostUIHandler";
+ return true;
+ }
+ return false;
+}
+
+HRESULT DocHostUIHandler::ShowContextMenu(DWORD dwID, POINT *ppt,
+ IUnknown *pcmdtReserved,
+ IDispatch *pdispReserved)
+{
+ wxUnusedVar(dwID);
+ wxUnusedVar(ppt);
+ wxUnusedVar(pcmdtReserved);
+ wxUnusedVar(pdispReserved);
+ return E_NOTIMPL;
+}
+
+HRESULT DocHostUIHandler::GetHostInfo(DOCHOSTUIINFO *pInfo)
+{
+ //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,
+ IOleCommandTarget *pCommandTarget,
+ IOleInPlaceFrame *pFrame,
+ IOleInPlaceUIWindow *pDoc)
+{
+ wxUnusedVar(dwID);
+ wxUnusedVar(pActiveObject);
+ wxUnusedVar(pCommandTarget);
+ wxUnusedVar(pFrame);
+ wxUnusedVar(pDoc);
+ return S_FALSE;
+}
+
+HRESULT DocHostUIHandler::HideUI(void)
+{
+ return E_NOTIMPL;
+}
+
+HRESULT DocHostUIHandler::UpdateUI(void)
+{
+ return E_NOTIMPL;
+}
+
+HRESULT DocHostUIHandler::EnableModeless(BOOL fEnable)
+{
+ wxUnusedVar(fEnable);
+ return E_NOTIMPL;
+}
+
+HRESULT DocHostUIHandler::OnDocWindowActivate(BOOL fActivate)
+{
+ wxUnusedVar(fActivate);
+ return E_NOTIMPL;
+}
+
+HRESULT DocHostUIHandler::OnFrameWindowActivate(BOOL fActivate)
+{
+ wxUnusedVar(fActivate);
+ return E_NOTIMPL;
+}
+
+HRESULT DocHostUIHandler::ResizeBorder(LPCRECT prcBorder,
+ IOleInPlaceUIWindow *pUIWindow,
+ BOOL fFrameWindow)
+{
+ wxUnusedVar(prcBorder);
+ wxUnusedVar(pUIWindow);
+ wxUnusedVar(fFrameWindow);
+ return E_NOTIMPL;
+}
+
+HRESULT DocHostUIHandler::TranslateAccelerator(LPMSG lpMsg,
+ const GUID *pguidCmdGroup,
+ DWORD nCmdID)
+{
+ if(lpMsg && lpMsg->message == WM_KEYDOWN)
+ {
+ //control is down?
+ if((GetKeyState(VK_CONTROL) & 0x8000 ))
+ {
+ //skip the accelerators used by the control
+ switch(lpMsg->wParam)
+ {
+ case 'F':
+ case 'L':
+ case 'N':
+ case 'O':
+ case 'P':
+ return S_OK;
+ }
+ }
+ //skip F5
+ if(lpMsg->wParam == VK_F5)
+ {
+ return S_OK;
+ }
+ }
+
+ wxUnusedVar(pguidCmdGroup);
+ wxUnusedVar(nCmdID);
+ return E_NOTIMPL;
+}
+
+HRESULT DocHostUIHandler::GetOptionKeyPath(LPOLESTR *pchKey,DWORD dw)
+{
+ wxUnusedVar(pchKey);
+ wxUnusedVar(dw);
+ return E_NOTIMPL;
+}
+
+HRESULT DocHostUIHandler::GetDropTarget(IDropTarget *pDropTarget,
+ IDropTarget **ppDropTarget)
+{
+ wxUnusedVar(pDropTarget);
+ wxUnusedVar(ppDropTarget);
+ return E_NOTIMPL;
+}
+
+HRESULT DocHostUIHandler::GetExternal(IDispatch **ppDispatch)
+{
+ wxUnusedVar(ppDispatch);
+ return E_NOTIMPL;
+}
+
+HRESULT DocHostUIHandler::TranslateUrl(DWORD dwTranslate,
+ OLECHAR *pchURLIn,
+ OLECHAR **ppchURLOut)
+{
+ wxUnusedVar(dwTranslate);
+ wxUnusedVar(pchURLIn);
+ wxUnusedVar(ppchURLOut);
+ return E_NOTIMPL;
+}
+
+HRESULT DocHostUIHandler::FilterDataObject(IDataObject *pDO, IDataObject **ppDORet)
+{
+ wxUnusedVar(pDO);
+ wxUnusedVar(ppDORet);
+ return E_NOTIMPL;
+}
+
+BEGIN_IID_TABLE(DocHostUIHandler)
+ ADD_IID(Unknown)
+ ADD_RAW_IID(wxIID_IDocHostUIHandler)
+END_IID_TABLE;
+
+IMPLEMENT_IUNKNOWN_METHODS(DocHostUIHandler)
+
+#endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE