XTHtmlView.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:23k
- // XTHtmlView.cpp : implementation of the CXTHtmlView class.
- //
- // This file is a part of the XTREME CONTROLS MFC class library.
- // (c)1998-2008 Codejock Software, All Rights Reserved.
- //
- // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
- // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
- // CONSENT OF CODEJOCK SOFTWARE.
- //
- // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
- // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
- // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
- // SINGLE COMPUTER.
- //
- // CONTACT INFORMATION:
- // support@codejock.com
- // http://www.codejock.com
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Common/XTPVC80Helpers.h" // Visual Studio 2005 helper functions
- #include "Common/XTPColorManager.h"
- #include "Common/XTPDrawHelpers.h"
- #include "XTGlobal.h"
- #include "XTHtmlView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CXTHtmlView
- /////////////////////////////////////////////////////////////////////////////
- CXTHtmlView::CXTHtmlView() : CFormView((LPCTSTR) NULL)
- {
- m_bLoading = true;
- m_strLoading = _T("Loading...");
- m_bLoadingMessage = false;
- m_pBrowserApp = NULL;
- }
- CXTHtmlView::~CXTHtmlView()
- {
- if (m_pBrowserApp != NULL)
- m_pBrowserApp->Release();
- }
- IMPLEMENT_DYNCREATE(CXTHtmlView, CFormView)
- BEGIN_MESSAGE_MAP(CXTHtmlView, CFormView)
- //{{AFX_MSG_MAP(CXTHtmlView)
- ON_WM_SIZE()
- ON_WM_DESTROY()
- ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
- ON_WM_ERASEBKGND()
- ON_WM_PAINT()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- BEGIN_EVENTSINK_MAP(CXTHtmlView, CFormView)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 102 /* StatusTextChange */, OnStatusTextChange, VTS_BSTR)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 108 /* ProgressChange */, OnProgressChange, VTS_I4 VTS_I4)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 105 /* CommandStateChange */, OnCommandStateChange, VTS_I4 VTS_BOOL)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 106 /* DownloadBegin */, OnDownloadBegin, VTS_NONE)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 104 /* DownloadComplete */, OnDownloadComplete, VTS_NONE)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 113 /* TitleChange */, OnTitleChange, VTS_BSTR)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 252 /* NavigateComplete2 */, NavigateComplete2, VTS_DISPATCH VTS_PVARIANT)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 250 /* BeforeNavigate2 */, BeforeNavigate2, VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 112 /* PropertyChange */, OnPropertyChange, VTS_BSTR)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 251 /* NewWindow2 */, OnNewWindow2, VTS_PDISPATCH VTS_PBOOL)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 259 /* DocumentComplete */, DocumentComplete, VTS_DISPATCH VTS_PVARIANT)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 271, /* NavigateError */ NavigateError, VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 253 /* OnQuit */, OnQuit, VTS_NONE)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 254 /* OnVisible */, OnVisible, VTS_BOOL)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 255 /* OnToolBar */, OnToolBar, VTS_BOOL)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 256 /* OnMenuBar */, OnMenuBar, VTS_BOOL)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 257 /* OnStatusBar */, OnStatusBar, VTS_BOOL)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 258 /* OnFullScreen */, OnFullScreen, VTS_BOOL)
- ON_EVENT(CXTHtmlView, AFX_IDW_PANE_FIRST, 260 /* OnTheaterMode */, OnTheaterMode, VTS_BOOL)
- END_EVENTSINK_MAP()
- void CXTHtmlView::OnDraw(CDC* /* pDC */)
- {
- // this class should never do its own drawing;
- // the browser control should handle everything
- ASSERT(FALSE);
- }
- void CXTHtmlView::OnFilePrint()
- {
- // get the HTMLDocument
- if (m_pBrowserApp != NULL)
- {
- LPOLECOMMANDTARGET lpTarget = NULL;
- LPDISPATCH lpDisp = GetHtmlDocument();
- if (lpDisp != NULL)
- {
- // the control will handle all printing UI
- if (SUCCEEDED(lpDisp->QueryInterface(IID_IOleCommandTarget,
- (LPVOID*) &lpTarget)))
- {
- lpTarget->Exec(NULL, OLECMDID_PRINT, 0, NULL, NULL);
- lpTarget->Release();
- }
- lpDisp->Release();
- }
- }
- }
- #ifdef _DEBUG
- void CXTHtmlView::AssertValid() const
- {
- CFormView::AssertValid();
- }
- void CXTHtmlView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
- #endif //_DEBUG
- void CXTHtmlView::OnDestroy()
- {
- if (m_pBrowserApp)
- {
- m_pBrowserApp->Release();
- m_pBrowserApp = 0;
- }
- }
- void CXTHtmlView::OnSize(UINT nType, int cx, int cy)
- {
- CFormView::OnSize(nType, cx, cy);
- if (::IsWindow(m_wndBrowser.m_hWnd))
- {
- // need to push non-client borders out of the client area
- int icx = ::GetSystemMetrics (SM_CXEDGE);
- int icy = ::GetSystemMetrics (SM_CYEDGE);
- m_wndBrowser.SetWindowPos(NULL, -icx, -icy,
- cx+(icx * 2), cy+(icy * 2), SWP_NOACTIVATE | SWP_NOZORDER);
- }
- }
- BOOL CXTHtmlView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName,
- DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
- UINT nID, CCreateContext* pContext)
- {
- // create the view window itself
- m_pCreateContext = pContext;
- if (!CView::Create(lpszClassName, lpszWindowName,
- dwStyle, rect, pParentWnd, nID, pContext))
- {
- return FALSE;
- }
- AfxEnableControlContainer();
- RECT rectClient;
- GetClientRect(&rectClient);
- // create the control window
- // AFX_IDW_PANE_FIRST is a safe but arbitrary ID
- if (!m_wndBrowser.CreateControl(CLSID_WebBrowser, lpszWindowName,
- WS_VISIBLE | WS_CHILD, rectClient, this, AFX_IDW_PANE_FIRST))
- {
- DestroyWindow();
- return FALSE;
- }
- LPUNKNOWN lpUnk = m_wndBrowser.GetControlUnknown();
- HRESULT hr = lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowserApp);
- if (!SUCCEEDED(hr))
- {
- m_pBrowserApp = NULL;
- m_wndBrowser.DestroyWindow();
- DestroyWindow();
- return FALSE;
- }
- return TRUE;
- }
- CString CXTHtmlView::GetType() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return _T("");
- BSTR bstr;
- m_pBrowserApp->get_Type(&bstr);
- CString retVal(bstr);
- return retVal;
- }
- long CXTHtmlView::GetLeft() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return 0;
- long result;
- m_pBrowserApp->get_Left(&result);
- return result;
- }
- long CXTHtmlView::GetTop() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return 0;
- long result;
- m_pBrowserApp->get_Top(&result);
- return result;
- }
- int CXTHtmlView::GetToolBar() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return 0;
- int result;
- m_pBrowserApp->get_ToolBar(&result);
- return result;
- }
- long CXTHtmlView::GetHeight() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return 0;
- long result;
- m_pBrowserApp->get_Height(&result);
- return result;
- }
- BOOL CXTHtmlView::GetVisible() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return FALSE;
- VARIANT_BOOL result;
- m_pBrowserApp->get_Visible(&result);
- return result;
- }
- CString CXTHtmlView::GetLocationName() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return _T("");
- BSTR bstr;
- m_pBrowserApp->get_LocationName(&bstr);
- CString retVal(bstr);
- return retVal;
- }
- CString CXTHtmlView::GetLocationURL() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return _T("");
- BSTR bstr;
- m_pBrowserApp->get_LocationURL(&bstr);
- CString retVal(bstr);
- return retVal;
- }
- BOOL CXTHtmlView::GetBusy() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return FALSE;
- VARIANT_BOOL result;
- m_pBrowserApp->get_Busy(&result);
- return result;
- }
- READYSTATE CXTHtmlView::GetReadyState() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return READYSTATE_UNINITIALIZED;
- READYSTATE result;
- m_pBrowserApp->get_ReadyState(&result);
- return result;
- }
- BOOL CXTHtmlView::GetOffline() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return FALSE;
- VARIANT_BOOL result;
- m_pBrowserApp->get_Offline(&result);
- return result;
- }
- BOOL CXTHtmlView::GetSilent() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return FALSE;
- VARIANT_BOOL result;
- m_pBrowserApp->get_Silent(&result);
- return result;
- }
- LPDISPATCH CXTHtmlView::GetApplication() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return 0;
- LPDISPATCH result;
- m_pBrowserApp->get_Application(&result);
- return result;
- }
- LPDISPATCH CXTHtmlView::GetParentBrowser() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return 0;
- LPDISPATCH result;
- m_pBrowserApp->get_Parent(&result);
- return result;
- }
- LPDISPATCH CXTHtmlView::GetContainer() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return 0;
- LPDISPATCH result;
- m_pBrowserApp->get_Container(&result);
- return result;
- }
- LPDISPATCH CXTHtmlView::GetHtmlDocument() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return 0;
- LPDISPATCH result;
- m_pBrowserApp->get_Document(&result);
- return result;
- }
- BOOL CXTHtmlView::GetTopLevelContainer() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return FALSE;
- VARIANT_BOOL result;
- m_pBrowserApp->get_TopLevelContainer(&result);
- return result;
- }
- BOOL CXTHtmlView::GetMenuBar() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return FALSE;
- VARIANT_BOOL result;
- m_pBrowserApp->get_MenuBar(&result);
- return result;
- }
- BOOL CXTHtmlView::GetFullScreen() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return FALSE;
- VARIANT_BOOL result;
- m_pBrowserApp->get_FullScreen(&result);
- return result;
- }
- BOOL CXTHtmlView::GetStatusBar() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return FALSE;
- VARIANT_BOOL result;
- m_pBrowserApp->get_StatusBar(&result);
- return result;
- }
- OLECMDF CXTHtmlView::QueryStatusWB(OLECMDID cmdID) const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return (OLECMDF)0;
- OLECMDF result;
- m_pBrowserApp->QueryStatusWB(cmdID, &result);
- return result;
- }
- void CXTHtmlView::ExecWB(OLECMDID cmdID, OLECMDEXECOPT cmdexecopt,
- VARIANT* pvaIn, VARIANT* pvaOut)
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return;
- m_pBrowserApp->ExecWB(cmdID, cmdexecopt, pvaIn, pvaOut);
- }
- BOOL CXTHtmlView::GetRegisterAsBrowser() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return FALSE;
- VARIANT_BOOL result;
- m_pBrowserApp->get_RegisterAsBrowser(&result);
- return result;
- }
- BOOL CXTHtmlView::GetRegisterAsDropTarget() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return FALSE;
- VARIANT_BOOL result;
- m_pBrowserApp->get_RegisterAsDropTarget(&result);
- return result;
- }
- BOOL CXTHtmlView::GetTheaterMode() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return FALSE;
- VARIANT_BOOL result;
- m_pBrowserApp->get_TheaterMode(&result);
- return result;
- }
- BOOL CXTHtmlView::GetAddressBar() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return FALSE;
- VARIANT_BOOL result;
- m_pBrowserApp->get_AddressBar(&result);
- return result;
- }
- BOOL CXTHtmlView::LoadFromResource(LPCTSTR lpszResource)
- {
- HINSTANCE hInstance = AfxGetResourceHandle();
- ASSERT(hInstance != NULL);
- CString strResourceURL;
- BOOL bRetVal = TRUE;
- LPTSTR lpszModule = new TCHAR[_MAX_PATH];
- if (GetModuleFileName(hInstance, lpszModule, _MAX_PATH))
- {
- strResourceURL.Format(_T("res://%s/%s"), lpszModule, lpszResource);
- Navigate(strResourceURL, 0, 0, 0);
- }
- else
- bRetVal = FALSE;
- delete[] lpszModule;
- return bRetVal;
- }
- BOOL CXTHtmlView::LoadFromResource(UINT nRes)
- {
- HINSTANCE hInstance = AfxGetResourceHandle();
- ASSERT(hInstance != NULL);
- CString strResourceURL;
- BOOL bRetVal = TRUE;
- LPTSTR lpszModule = new TCHAR[_MAX_PATH];
- if (GetModuleFileName(hInstance, lpszModule, _MAX_PATH))
- {
- strResourceURL.Format(_T("res://%s/%d"), lpszModule, nRes);
- Navigate(strResourceURL, 0, 0, 0);
- }
- else
- bRetVal = FALSE;
- delete[] lpszModule;
- return bRetVal;
- }
- void CXTHtmlView::Navigate(LPCTSTR lpszURL, DWORD dwFlags /* = 0 */,
- LPCTSTR lpszTargetFrameName /* = NULL */ ,
- LPCTSTR lpszHeaders /* = NULL */, LPVOID lpvPostData /* = NULL */,
- DWORD dwPostDataLen /* = 0 */)
- {
- CString strURL(lpszURL);
- BSTR bstrURL = strURL.AllocSysString();
- COleSafeArray vPostData;
- if (lpvPostData != NULL)
- {
- if (dwPostDataLen == 0)
- dwPostDataLen = lstrlen((LPCTSTR) lpvPostData);
- vPostData.CreateOneDim(VT_UI1, dwPostDataLen, lpvPostData);
- }
- m_pBrowserApp->Navigate(bstrURL,
- COleVariant((long) dwFlags, VT_I4),
- COleVariant(lpszTargetFrameName, VT_BSTR),
- vPostData,
- COleVariant(lpszHeaders, VT_BSTR));
- SysFreeString(bstrURL);
- }
- void CXTHtmlView::Navigate2(LPITEMIDLIST pIDL, DWORD dwFlags, LPCTSTR lpszTargetFrameName)
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return;
- #if (_MSC_VER <= 1100) // Using Visual C++ 5.0
- COleVariant vPIDL;
- AfxVariantInit(&vPIDL);
- if (pIDL != NULL)
- {
- // walk through entries in the list and accumulate their size
- UINT cbTotal = 0;
- SAFEARRAY *psa = NULL;
- LPCITEMIDLIST pidlWalker = pIDL;
- while (pidlWalker->mkid.cb)
- {
- cbTotal += pidlWalker->mkid.cb;
- pidlWalker = (LPCITEMIDLIST)
- (((LPBYTE)pidlWalker) + pidlWalker->mkid.cb);
- }
- // add the base structure size
- cbTotal += sizeof(ITEMIDLIST);
- // get a safe array for them
- psa = SafeArrayCreateVector(VT_UI1, 0, cbTotal);
- // copy it and set members
- if (psa != NULL)
- {
- memcpy(psa->pvData, (LPBYTE) pIDL, cbTotal);
- vPIDL.vt = VT_ARRAY | VT_UI1;
- vPIDL.parray = psa;
- }
- }
- #else
- COleVariant vPIDL(pIDL);
- #endif
- COleVariant empty;
- m_pBrowserApp->Navigate2(vPIDL,
- COleVariant((long) dwFlags, VT_I4),
- COleVariant(lpszTargetFrameName, VT_BSTR),
- empty, empty);
- }
- void CXTHtmlView::Navigate2(LPCTSTR lpszURL, DWORD dwFlags /* = 0 */,
- LPCTSTR lpszTargetFrameName /* = NULL */,
- LPCTSTR lpszHeaders /* = NULL */,
- LPVOID lpvPostData /* = NULL */, DWORD dwPostDataLen /* = 0 */)
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return;
- COleSafeArray vPostData;
- if (lpvPostData != NULL)
- {
- if (dwPostDataLen == 0)
- dwPostDataLen = lstrlen((LPCTSTR) lpvPostData);
- vPostData.CreateOneDim(VT_UI1, dwPostDataLen, lpvPostData);
- }
- COleVariant vURL(lpszURL, VT_BSTR);
- COleVariant vHeaders(lpszHeaders, VT_BSTR);
- COleVariant vTargetFrameName(lpszTargetFrameName, VT_BSTR);
- COleVariant vFlags((long) dwFlags, VT_I4);
- m_pBrowserApp->Navigate2(vURL,
- vFlags, vTargetFrameName, vPostData, vHeaders);
- }
- void CXTHtmlView::Navigate2(LPCTSTR lpszURL, DWORD dwFlags,
- CByteArray& baPostData, LPCTSTR lpszTargetFrameName /* = NULL */,
- LPCTSTR lpszHeaders /* = NULL */)
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return;
- COleVariant vPostData = baPostData;
- COleVariant vURL(lpszURL, VT_BSTR);
- COleVariant vHeaders(lpszHeaders, VT_BSTR);
- COleVariant vTargetFrameName(lpszTargetFrameName, VT_BSTR);
- COleVariant vFlags((long) dwFlags, VT_I4);
- ASSERT(m_pBrowserApp != NULL);
- m_pBrowserApp->Navigate2(vURL, vFlags, vTargetFrameName,
- vPostData, vHeaders);
- }
- void CXTHtmlView::PutProperty(LPCTSTR lpszProperty, const VARIANT& vtValue)
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return;
- CString strProp(lpszProperty);
- BSTR bstrProp = strProp.AllocSysString();
- m_pBrowserApp->PutProperty(bstrProp, vtValue);
- ::SysFreeString(bstrProp);
- }
- BOOL CXTHtmlView::GetProperty(LPCTSTR lpszProperty, CString& strValue)
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return FALSE;
- CString strProperty(lpszProperty);
- BSTR bstrProperty = strProperty.AllocSysString();
- BOOL bResult = FALSE;
- VARIANT vReturn;
- vReturn.vt = VT_BSTR;
- vReturn.bstrVal = NULL;
- HRESULT hr = m_pBrowserApp->GetProperty(bstrProperty, &vReturn);
- if (SUCCEEDED(hr))
- {
- strValue = CString(vReturn.bstrVal);
- bResult = TRUE;
- }
- ::SysFreeString(bstrProperty);
- return bResult;
- }
- COleVariant CXTHtmlView::GetProperty(LPCTSTR lpszProperty)
- {
- COleVariant result;
- static BYTE parms[] =
- VTS_BSTR;
- m_wndBrowser.InvokeHelper(0x12f, DISPATCH_METHOD,
- VT_VARIANT, (void*)&result, parms, lpszProperty);
- return result;
- }
- CString CXTHtmlView::GetFullName() const
- {
- ASSERT(m_pBrowserApp != NULL);
- if (!m_pBrowserApp)
- return _T("");
- BSTR bstr;
- m_pBrowserApp->get_FullName(&bstr);
- CString retVal(bstr);
- return retVal;
- }
- void CXTHtmlView::NavigateComplete2(LPDISPATCH /* pDisp */, VARIANT* URL)
- {
- ASSERT(V_VT(URL) == VT_BSTR);
- CString str(V_BSTR(URL));
- OnNavigateComplete2(str);
- }
- void CXTHtmlView::BeforeNavigate2(LPDISPATCH /* pDisp */, VARIANT* URL,
- VARIANT* Flags, VARIANT* TargetFrameName,
- VARIANT* PostData, VARIANT* Headers, BOOL* Cancel)
- {
- ASSERT(V_VT(URL) == VT_BSTR);
- ASSERT(V_VT(TargetFrameName) == VT_BSTR);
- ASSERT(V_VT(PostData) == (VT_VARIANT | VT_BYREF));
- ASSERT(V_VT(Headers) == VT_BSTR);
- ASSERT(Cancel != NULL);
- VARIANT* vtPostedData = V_VARIANTREF(PostData);
- CByteArray array;
- if (V_VT(vtPostedData) & VT_ARRAY)
- {
- // must be a vector of bytes
- ASSERT(vtPostedData->parray->cDims == 1 && vtPostedData->parray->cbElements == 1);
- vtPostedData->vt |= VT_UI1;
- COleSafeArray safe(vtPostedData);
- DWORD dwSize = safe.GetOneDimSize();
- LPVOID pVoid;
- safe.AccessData(&pVoid);
- array.SetSize(dwSize);
- LPBYTE lpByte = array.GetData();
- MEMCPY_S(lpByte, pVoid, dwSize);
- safe.UnaccessData();
- }
- // make real parameters out of the notification
- CString strTargetFrameName(V_BSTR(TargetFrameName));
- CString strURL(V_BSTR(URL));
- CString strHeaders(V_BSTR(Headers));
- DWORD nFlags = V_I4(Flags);
- // notify the user's class
- OnBeforeNavigate2(strURL, nFlags, strTargetFrameName,
- array, strHeaders, Cancel);
- }
- void CXTHtmlView::DocumentComplete(LPDISPATCH /*pDisp*/, VARIANT* URL)
- {
- ASSERT(V_VT(URL) == VT_BSTR);
- CString str(V_BSTR(URL));
- OnDocumentComplete(str);
- }
- void CXTHtmlView::NavigateError(LPDISPATCH /*pDisp*/, VARIANT* pvURL,
- VARIANT* pvFrame, VARIANT* pvStatusCode, VARIANT_BOOL* pvbCancel)
- {
- ASSERT(pvURL != NULL);
- ASSERT(pvStatusCode != NULL);
- ASSERT(pvbCancel != NULL);
- if (!pvURL || !pvStatusCode || !pvbCancel)
- return;
- ASSERT(V_VT(pvURL) == VT_BSTR);
- ASSERT(pvFrame == NULL || V_VT(pvFrame) == VT_BSTR);
- CString strURL(V_BSTR(pvURL));
- CString strFrame(pvFrame ? V_BSTR(pvFrame) : NULL);
- DWORD dwError = V_I4(pvStatusCode);
- BOOL bCancel = FALSE;
- // notify the user's class
- OnNavigateError(strURL, strFrame, dwError, &bCancel);
- if (pvbCancel)
- *pvbCancel = bCancel ? (VARIANT_BOOL)AFX_OLE_TRUE : (VARIANT_BOOL)AFX_OLE_FALSE;
- }
- void CXTHtmlView::OnProgressChange(long /*lProgress*/, long /*lProgressMax*/)
- {
- // user will override to handle this notification
- }
- void CXTHtmlView::OnCommandStateChange(long /*lCommand*/, BOOL /*bEnable*/)
- {
- // user will override to handle this notification
- }
- void CXTHtmlView::OnDownloadBegin()
- {
- // user will override to handle this notification
- }
- void CXTHtmlView::OnDownloadComplete()
- {
- // user will override to handle this notification
- }
- void CXTHtmlView::OnTitleChange(LPCTSTR /*lpszText*/)
- {
- // user will override to handle this notification
- }
- void CXTHtmlView::OnPropertyChange(LPCTSTR /*lpszProperty*/)
- {
- // user will override to handle this notification
- }
- void CXTHtmlView::OnNewWindow2(LPDISPATCH* /*ppDisp*/, BOOL* bCancel)
- {
- // default to continuing
- *bCancel = FALSE;
- // user will override to handle this notification
- }
- void CXTHtmlView::OnDocumentComplete(LPCTSTR /*lpszURL*/)
- {
- // user will override to handle this notification
- }
- void CXTHtmlView::OnQuit()
- {
- // user will override to handle this notification
- }
- void CXTHtmlView::OnVisible(BOOL /*bVisible*/)
- {
- // user will override to handle this notification
- }
- void CXTHtmlView::OnToolBar(BOOL /*bToolBar*/)
- {
- // user will override to handle this notification
- }
- void CXTHtmlView::OnMenuBar(BOOL /*bMenuBar*/)
- {
- // user will override to handle this notification
- }
- void CXTHtmlView::OnStatusBar(BOOL /*bStatusBar*/)
- {
- // user will override to handle this notification
- }
- void CXTHtmlView::OnFullScreen(BOOL /*bFullScreen*/)
- {
- // user will override to handle this notification
- }
- void CXTHtmlView::OnTheaterMode(BOOL /*bTheaterMode*/)
- {
- // user will override to handle this notification
- }
- void CXTHtmlView::OnNavigateComplete2(LPCTSTR /*lpszURL*/)
- {
- // user will override to handle this notification
- }
- void CXTHtmlView::OnBeforeNavigate2(LPCTSTR /*lpszURL*/, DWORD /*nFlags*/,
- LPCTSTR /*lpszTargetFrameName*/, CByteArray& /*baPostData*/,
- LPCTSTR /*lpszHeaders*/, BOOL* pbCancel)
- {
- // default to continuing
- if (pbCancel)
- {
- *pbCancel = FALSE;
- }
- // user will override to handle this notification
- }
- void CXTHtmlView::OnStatusTextChange(LPCTSTR pszText)
- {
- // try to set the status bar text via the frame
- CFrameWnd* pFrame = GetParentFrame();
- if (pFrame != NULL)
- pFrame->SetMessageText(pszText);
- }
- void CXTHtmlView::OnNavigateError(LPCTSTR /*lpszURL*/, LPCTSTR /*lpszFrame*/, DWORD dwError, BOOL* pbCancel)
- {
- // default to continuing
- *pbCancel = FALSE;
- // user will override to handle this notification
- dwError;
- TRACE1("OnNavigateError called with status scode = 0x%Xn", dwError);
- }
- BOOL CXTHtmlView::OnEraseBkgnd(CDC* pDC)
- {
- if (m_bLoading == true)
- {
- // Get the client rect.
- CRect r;
- GetClientRect(&r);
- CXTPBufferDC memDC(*pDC, r);
- memDC.FillSolidRect(r, GetXtremeColor(COLOR_WINDOW));
- if (m_bLoadingMessage)
- {
- int iSavedDC = memDC.SaveDC();
- memDC.SelectObject(&XTAuxData().font);
- memDC.SetTextColor(GetXtremeColor(COLOR_GRAYTEXT));
- memDC.DrawText(m_strLoading, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.RestoreDC(iSavedDC);
- }
- m_bLoading = false;
- }
- return TRUE;
- }
- void CXTHtmlView::OnPaint()
- {
- // background is already filled in gray
- CPaintDC dc(this);
- // Get the client rect.
- CRect r;
- GetClientRect(&r);
- // Exclude it from painting, this will eliminate
- // screen flicker when view is resized, since we
- // actually don't draw the HTML page that is
- // displayed.
- dc.ExcludeClipRect(&r);
- // Paint to a memory device context to help
- // eliminate screen flicker.
- CXTPBufferDC memDC(dc);
- memDC.FillSolidRect(r, GetXtremeColor(COLOR_WINDOW));
- // Now let the window do its default painting...
- CWnd::DefWindowProc(WM_PAINT, (WPARAM)memDC.m_hDC, 0);
- }