home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / viewhtml.cpp < prev    next >
C/C++ Source or Header  |  1998-06-16  |  20KB  |  829 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef AFX_HTML_SEG
  14. #pragma code_seg(AFX_HTML_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CHtmlView
  25.  
  26. BEGIN_MESSAGE_MAP(CHtmlView, CFormView)
  27.     //{{AFX_MSG_MAP(CHtmlView)
  28.     ON_WM_SIZE()
  29.     ON_WM_PAINT()
  30.     ON_WM_DESTROY()
  31.     //}}AFX_MSG_MAP
  32.     // Standard printing commands
  33.     ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
  34. END_MESSAGE_MAP()
  35.  
  36. BEGIN_EVENTSINK_MAP(CHtmlView, CFormView)
  37.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 102 /* StatusTextChange */, OnStatusTextChange, VTS_BSTR)
  38.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 108 /* ProgressChange */, OnProgressChange, VTS_I4 VTS_I4)
  39.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 105 /* CommandStateChange */, OnCommandStateChange, VTS_I4 VTS_BOOL)
  40.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 106 /* DownloadBegin */, OnDownloadBegin, VTS_NONE)
  41.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 104 /* DownloadComplete */, OnDownloadComplete, VTS_NONE)
  42.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 113 /* TitleChange */, OnTitleChange, VTS_BSTR)
  43.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 252 /* NavigateComplete2 */, NavigateComplete2, VTS_DISPATCH VTS_PVARIANT)
  44.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 250 /* BeforeNavigate2 */, BeforeNavigate2, VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
  45.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 112 /* PropertyChange */, OnPropertyChange, VTS_BSTR)
  46.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 251 /* NewWindow2 */, OnNewWindow2, VTS_PDISPATCH VTS_PBOOL)
  47.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 259 /* DocumentComplete */, DocumentComplete, VTS_DISPATCH VTS_PVARIANT)
  48.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 253 /* OnQuit */, OnQuit, VTS_NONE)
  49.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 254 /* OnVisible */, OnVisible, VTS_BOOL)
  50.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 255 /* OnToolBar */, OnToolBar, VTS_BOOL)
  51.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 256 /* OnMenuBar */, OnMenuBar, VTS_BOOL)
  52.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 257 /* OnStatusBar */, OnStatusBar, VTS_BOOL)
  53.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 258 /* OnFullScreen */, OnFullScreen, VTS_BOOL)
  54.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 260 /* OnTheaterMode */, OnTheaterMode, VTS_BOOL)
  55. END_EVENTSINK_MAP()
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CHtmlView construction/destruction
  59.  
  60. CHtmlView::CHtmlView()
  61.     : CFormView((LPCTSTR) NULL)
  62. {
  63.     m_pBrowserApp = NULL;
  64. }
  65.  
  66. CHtmlView::~CHtmlView()
  67. {
  68.     if (m_pBrowserApp != NULL)
  69.         m_pBrowserApp->Release();
  70. }
  71.  
  72.  
  73. /////////////////////////////////////////////////////////////////////////////
  74. // CHtmlView drawing
  75.  
  76. void CHtmlView::OnDraw(CDC* /* pDC */)
  77. {
  78.     // this class should never do its own drawing;
  79.     // the browser control should handle everything
  80.  
  81.     ASSERT(FALSE);
  82. }
  83.  
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CHtmlView printing
  86.  
  87. void CHtmlView::OnFilePrint()
  88. {
  89.     // get the HTMLDocument
  90.  
  91.     if (m_pBrowserApp != NULL)
  92.     {
  93.         LPOLECOMMANDTARGET lpTarget = NULL;
  94.         LPDISPATCH lpDisp = GetHtmlDocument();
  95.  
  96.         if (lpDisp != NULL)
  97.         {
  98.             // the control will handle all printing UI
  99.  
  100.             if (SUCCEEDED(lpDisp->QueryInterface(IID_IOleCommandTarget,
  101.                     (LPVOID*) &lpTarget)))
  102.             {
  103.                 lpTarget->Exec(NULL, OLECMDID_PRINT, 0, NULL, NULL);
  104.                 lpTarget->Release();
  105.             }
  106.             lpDisp->Release();
  107.         }
  108.     }
  109. }
  110.  
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CHtmlView diagnostics
  113.  
  114. #ifdef _DEBUG
  115. void CHtmlView::AssertValid() const
  116. {
  117.     CFormView::AssertValid();
  118. }
  119.  
  120. void CHtmlView::Dump(CDumpContext& dc) const
  121. {
  122.     CFormView::Dump(dc);
  123. }
  124. #endif //_DEBUG
  125.  
  126. /////////////////////////////////////////////////////////////////////////////
  127. // CHtmlView message handlers
  128.  
  129. void CHtmlView::OnDestroy()
  130. {
  131.     RELEASE(m_pBrowserApp);
  132. }
  133.  
  134. void CHtmlView::OnSize(UINT nType, int cx, int cy)
  135. {
  136.     CFormView::OnSize(nType, cx, cy);
  137.  
  138.     if (::IsWindow(m_wndBrowser.m_hWnd))
  139.     {
  140.         // need to push non-client borders out of the client area
  141.         CRect rect;
  142.         GetClientRect(rect);
  143.         ::AdjustWindowRectEx(rect,
  144.             m_wndBrowser.GetStyle(), FALSE, WS_EX_CLIENTEDGE);
  145.         m_wndBrowser.SetWindowPos(NULL, rect.left, rect.top,
  146.             rect.Width(), rect.Height(), SWP_NOACTIVATE | SWP_NOZORDER);
  147.     }
  148. }
  149.  
  150. void CHtmlView::OnPaint()
  151. {
  152.     Default();
  153. }
  154.  
  155. /////////////////////////////////////////////////////////////////////////////
  156. // CHtmlView operations
  157.  
  158. BOOL CHtmlView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName,
  159.                         DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
  160.                         UINT nID, CCreateContext* pContext)
  161. {
  162.     // create the view window itself
  163.     m_pCreateContext = pContext;
  164.     if (!CView::Create(lpszClassName, lpszWindowName,
  165.                 dwStyle, rect, pParentWnd,  nID, pContext))
  166.     {
  167.         return FALSE;
  168.     }
  169.  
  170.     AfxEnableControlContainer();
  171.  
  172.     RECT rectClient;
  173.     GetClientRect(&rectClient);
  174.  
  175.     // create the control window
  176.     // AFX_IDW_PANE_FIRST is a safe but arbitrary ID
  177.     if (!m_wndBrowser.CreateControl(CLSID_WebBrowser, lpszWindowName,
  178.                 WS_VISIBLE | WS_CHILD, rectClient, this, AFX_IDW_PANE_FIRST))
  179.     {
  180.         DestroyWindow();
  181.         return FALSE;
  182.     }
  183.  
  184.     LPUNKNOWN lpUnk = m_wndBrowser.GetControlUnknown();
  185.     HRESULT hr = lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowserApp);
  186.     if (!SUCCEEDED(hr))
  187.     {
  188.         m_pBrowserApp = NULL;
  189.         m_wndBrowser.DestroyWindow();
  190.         DestroyWindow();
  191.         return FALSE;
  192.     }
  193.  
  194.     return TRUE;
  195. }
  196.  
  197. /////////////////////////////////////////////////////////////////////////////
  198. // CHtmlView properties
  199.  
  200. CString CHtmlView::GetType() const
  201. {
  202.     ASSERT(m_pBrowserApp != NULL);
  203.  
  204.     BSTR bstr;
  205.     m_pBrowserApp->get_Type(&bstr);
  206.     CString retVal(bstr);
  207.     return retVal;
  208. }
  209.  
  210. long CHtmlView::GetLeft() const
  211. {
  212.     ASSERT(m_pBrowserApp != NULL);
  213.  
  214.     long result;
  215.     m_pBrowserApp->get_Left(&result);
  216.     return result;
  217. }
  218.  
  219.  
  220. long CHtmlView::GetTop() const
  221. {
  222.     ASSERT(m_pBrowserApp != NULL);
  223.     long result;
  224.     m_pBrowserApp->get_Top(&result);
  225.     return result;
  226. }
  227.  
  228. int CHtmlView::GetToolBar() const
  229. {
  230.     ASSERT(m_pBrowserApp != NULL);
  231.     int result;
  232.     m_pBrowserApp->get_ToolBar(&result);
  233.     return result;
  234. }
  235.  
  236. long CHtmlView::GetHeight() const
  237. {
  238.     ASSERT(m_pBrowserApp != NULL);
  239.     long result;
  240.     m_pBrowserApp->get_Height(&result);
  241.     return result;
  242. }
  243.  
  244. BOOL CHtmlView::GetVisible() const
  245. {
  246.     ASSERT(m_pBrowserApp != NULL);
  247.  
  248.     VARIANT_BOOL result;
  249.     m_pBrowserApp->get_Visible(&result);
  250.     return result;
  251. }
  252.  
  253. CString CHtmlView::GetLocationName() const
  254. {
  255.     ASSERT(m_pBrowserApp != NULL);
  256.  
  257.     BSTR bstr;
  258.     m_pBrowserApp->get_LocationName(&bstr);
  259.     CString retVal(bstr);
  260.     return retVal;
  261. }
  262.  
  263. CString CHtmlView::GetLocationURL() const
  264. {
  265.     ASSERT(m_pBrowserApp != NULL);
  266.  
  267.     BSTR bstr;
  268.     m_pBrowserApp->get_LocationURL(&bstr);
  269.     CString retVal(bstr);
  270.     return retVal;
  271. }
  272.  
  273. BOOL CHtmlView::GetBusy() const
  274. {
  275.     ASSERT(m_pBrowserApp != NULL);
  276.  
  277.     VARIANT_BOOL result;
  278.     m_pBrowserApp->get_Busy(&result);
  279.     return result;
  280. }
  281.  
  282. READYSTATE CHtmlView::GetReadyState() const
  283. {
  284.     ASSERT(m_pBrowserApp != NULL);
  285.  
  286.     READYSTATE result;
  287.     m_pBrowserApp->get_ReadyState(&result);
  288.     return result;
  289. }
  290.  
  291. BOOL CHtmlView::GetOffline() const
  292. {
  293.     ASSERT(m_pBrowserApp != NULL);
  294.  
  295.     VARIANT_BOOL result;
  296.     m_pBrowserApp->get_Offline(&result);
  297.     return result;
  298. }
  299.  
  300. BOOL CHtmlView::GetSilent() const
  301. {
  302.     ASSERT(m_pBrowserApp != NULL);
  303.  
  304.     VARIANT_BOOL result;
  305.     m_pBrowserApp->get_Silent(&result);
  306.     return result;
  307. }
  308.  
  309. LPDISPATCH CHtmlView::GetApplication() const
  310. {
  311.     ASSERT(m_pBrowserApp != NULL);
  312.  
  313.     LPDISPATCH result;
  314.     m_pBrowserApp->get_Application(&result);
  315.     return result;
  316. }
  317.  
  318.  
  319. LPDISPATCH CHtmlView::GetParentBrowser() const
  320. {
  321.     ASSERT(m_pBrowserApp != NULL);
  322.  
  323.     LPDISPATCH result;
  324.     m_pBrowserApp->get_Parent(&result);
  325.     return result;
  326. }
  327.  
  328. LPDISPATCH CHtmlView::GetContainer() const
  329. {
  330.     ASSERT(m_pBrowserApp != NULL);
  331.  
  332.     LPDISPATCH result;
  333.     m_pBrowserApp->get_Container(&result);
  334.     return result;
  335. }
  336.  
  337. LPDISPATCH CHtmlView::GetHtmlDocument() const
  338. {
  339.     ASSERT(m_pBrowserApp != NULL);
  340.  
  341.     LPDISPATCH result;
  342.     m_pBrowserApp->get_Document(&result);
  343.     return result;
  344. }
  345.  
  346. BOOL CHtmlView::GetTopLevelContainer() const
  347. {
  348.     ASSERT(m_pBrowserApp != NULL);
  349.  
  350.     VARIANT_BOOL result;
  351.     m_pBrowserApp->get_TopLevelContainer(&result);
  352.     return result;
  353. }
  354.  
  355. BOOL CHtmlView::GetMenuBar() const
  356. {
  357.     ASSERT(m_pBrowserApp != NULL);
  358.  
  359.     VARIANT_BOOL result;
  360.     m_pBrowserApp->get_MenuBar(&result);
  361.     return result;
  362. }
  363.  
  364. BOOL CHtmlView::GetFullScreen() const
  365. {
  366.     ASSERT(m_pBrowserApp != NULL);
  367.  
  368.     VARIANT_BOOL result;
  369.     m_pBrowserApp->get_FullScreen(&result);
  370.     return result;
  371. }
  372.  
  373. BOOL CHtmlView::GetStatusBar() const
  374. {
  375.     ASSERT(m_pBrowserApp != NULL);
  376.  
  377.     VARIANT_BOOL result;
  378.     m_pBrowserApp->get_StatusBar(&result);
  379.     return result;
  380. }
  381.  
  382. OLECMDF CHtmlView::QueryStatusWB(OLECMDID cmdID) const
  383. {
  384.     ASSERT(m_pBrowserApp != NULL);
  385.  
  386.     OLECMDF result;
  387.     m_pBrowserApp->QueryStatusWB(cmdID, &result);
  388.     return result;
  389. }
  390.  
  391. void CHtmlView::ExecWB(OLECMDID cmdID, OLECMDEXECOPT cmdexecopt,
  392.     VARIANT* pvaIn, VARIANT* pvaOut)
  393. {
  394.     ASSERT(m_pBrowserApp != NULL);
  395.  
  396.     m_pBrowserApp->ExecWB(cmdID, cmdexecopt, pvaIn, pvaOut);
  397. }
  398.  
  399. BOOL CHtmlView::GetRegisterAsBrowser() const
  400. {
  401.     ASSERT(m_pBrowserApp != NULL);
  402.  
  403.     VARIANT_BOOL result;
  404.     m_pBrowserApp->get_RegisterAsBrowser(&result);
  405.     return result;
  406. }
  407.  
  408. BOOL CHtmlView::GetRegisterAsDropTarget() const
  409. {
  410.     ASSERT(m_pBrowserApp != NULL);
  411.  
  412.     VARIANT_BOOL result;
  413.     m_pBrowserApp->get_RegisterAsDropTarget(&result);
  414.     return result;
  415. }
  416.  
  417. BOOL CHtmlView::GetTheaterMode() const
  418. {
  419.     ASSERT(m_pBrowserApp != NULL);
  420.  
  421.     VARIANT_BOOL result;
  422.     m_pBrowserApp->get_TheaterMode(&result);
  423.     return result;
  424. }
  425.  
  426. BOOL CHtmlView::GetAddressBar() const
  427. {
  428.     ASSERT(m_pBrowserApp != NULL);
  429.  
  430.     VARIANT_BOOL result;
  431.     m_pBrowserApp->get_AddressBar(&result);
  432.     return result;
  433. }
  434.  
  435. /////////////////////////////////////////////////////////////////////////////
  436. // CHtmlView operations
  437.  
  438. BOOL CHtmlView::LoadFromResource(LPCTSTR lpszResource)
  439. {
  440.     HINSTANCE hInstance = AfxGetResourceHandle();
  441.     ASSERT(hInstance != NULL);
  442.  
  443.     CString strResourceURL;
  444.     BOOL bRetVal = TRUE;
  445.     LPTSTR lpszModule = new TCHAR[_MAX_PATH];
  446.  
  447.     if (GetModuleFileName(hInstance, lpszModule, _MAX_PATH))
  448.     {
  449.         strResourceURL.Format(_T("res://%s/%s"), lpszModule, lpszResource);
  450.         Navigate(strResourceURL, 0, 0, 0);
  451.     }
  452.     else
  453.         bRetVal = FALSE;
  454.  
  455.     delete [] lpszModule;
  456.     return bRetVal;
  457. }
  458.  
  459. BOOL CHtmlView::LoadFromResource(UINT nRes)
  460. {
  461.     HINSTANCE hInstance = AfxGetResourceHandle();
  462.     ASSERT(hInstance != NULL);
  463.  
  464.     CString strResourceURL;
  465.     BOOL bRetVal = TRUE;
  466.     LPTSTR lpszModule = new TCHAR[_MAX_PATH];
  467.  
  468.     if (GetModuleFileName(hInstance, lpszModule, _MAX_PATH))
  469.     {
  470.         strResourceURL.Format(_T("res://%s/%d"), lpszModule, nRes);
  471.         Navigate(strResourceURL, 0, 0, 0);
  472.     }
  473.     else
  474.         bRetVal = FALSE;
  475.  
  476.     delete [] lpszModule;
  477.     return bRetVal;
  478. }
  479.  
  480. void CHtmlView::Navigate(LPCTSTR lpszURL, DWORD dwFlags /* = 0 */,
  481.     LPCTSTR lpszTargetFrameName /* = NULL */ ,
  482.     LPCTSTR lpszHeaders /* = NULL */, LPVOID lpvPostData /* = NULL */,
  483.     DWORD dwPostDataLen /* = 0 */)
  484. {
  485.     CString strURL(lpszURL);
  486.     BSTR bstrURL = strURL.AllocSysString();
  487.  
  488.     COleSafeArray vPostData;
  489.     if (lpvPostData != NULL)
  490.     {
  491.         if (dwPostDataLen == 0)
  492.             dwPostDataLen = lstrlen((LPCTSTR) lpvPostData);
  493.  
  494.         vPostData.CreateOneDim(VT_UI1, dwPostDataLen, lpvPostData);
  495.     }
  496.  
  497.     m_pBrowserApp->Navigate(bstrURL,
  498.         COleVariant((long) dwFlags, VT_I4),
  499.         COleVariant(lpszTargetFrameName, VT_BSTR),
  500.         vPostData,
  501.         COleVariant(lpszHeaders, VT_BSTR));
  502. }
  503.  
  504. void CHtmlView::Navigate2(LPITEMIDLIST pIDL, DWORD dwFlags /* = 0 */,
  505.     LPCTSTR lpszTargetFrameName /* = NULL */)
  506. {
  507.     ASSERT(m_pBrowserApp != NULL);
  508.  
  509.     COleVariant vPIDL(pIDL);
  510.     COleVariant empty;
  511.  
  512.     m_pBrowserApp->Navigate2(vPIDL,
  513.         COleVariant((long) dwFlags, VT_I4),
  514.         COleVariant(lpszTargetFrameName, VT_BSTR),
  515.         empty, empty);
  516. }
  517.  
  518. void CHtmlView::Navigate2(LPCTSTR lpszURL, DWORD dwFlags /* = 0 */,
  519.     LPCTSTR lpszTargetFrameName /* = NULL */,
  520.     LPCTSTR lpszHeaders /* = NULL */,
  521.     LPVOID lpvPostData /* = NULL */, DWORD dwPostDataLen /* = 0 */)
  522. {
  523.     ASSERT(m_pBrowserApp != NULL);
  524.  
  525.     COleSafeArray vPostData;
  526.     if (lpvPostData != NULL)
  527.     {
  528.         if (dwPostDataLen == 0)
  529.             dwPostDataLen = lstrlen((LPCTSTR) lpvPostData);
  530.  
  531.         vPostData.CreateOneDim(VT_UI1, dwPostDataLen, lpvPostData);
  532.     }
  533.  
  534.     COleVariant vURL(lpszURL, VT_BSTR);
  535.     COleVariant vHeaders(lpszHeaders, VT_BSTR);
  536.     COleVariant vTargetFrameName(lpszTargetFrameName, VT_BSTR);
  537.     COleVariant vFlags((long) dwFlags, VT_I4);
  538.  
  539.     m_pBrowserApp->Navigate2(vURL,
  540.         vFlags, vTargetFrameName, vPostData, vHeaders);
  541. }
  542.  
  543. void CHtmlView::Navigate2(LPCTSTR lpszURL, DWORD dwFlags,
  544.     CByteArray& baPostData, LPCTSTR lpszTargetFrameName /* = NULL */,
  545.     LPCTSTR lpszHeaders /* = NULL */)
  546. {
  547.     ASSERT(m_pBrowserApp != NULL);
  548.  
  549.     COleVariant vPostData = baPostData;
  550.     COleVariant vURL(lpszURL, VT_BSTR);
  551.     COleVariant vHeaders(lpszHeaders, VT_BSTR);
  552.     COleVariant vTargetFrameName(lpszTargetFrameName, VT_BSTR);
  553.     COleVariant vFlags((long) dwFlags, VT_I4);
  554.  
  555.     ASSERT(m_pBrowserApp != NULL);
  556.  
  557.     m_pBrowserApp->Navigate2(vURL, vFlags, vTargetFrameName,
  558.         vPostData, vHeaders);
  559. }
  560.  
  561. void CHtmlView::PutProperty(LPCTSTR lpszProperty, const VARIANT& vtValue)
  562. {
  563.     ASSERT(m_pBrowserApp != NULL);
  564.  
  565.     CString strProp(lpszProperty);
  566.     BSTR bstrProp = strProp.AllocSysString();
  567.     m_pBrowserApp->PutProperty(bstrProp, vtValue);
  568.     ::SysFreeString(bstrProp);
  569. }
  570.  
  571. BOOL CHtmlView::GetProperty(LPCTSTR lpszProperty, CString& strValue)
  572. {
  573.     ASSERT(m_pBrowserApp != NULL);
  574.  
  575.     CString strProperty(lpszProperty);
  576.     BSTR bstrProperty = strProperty.AllocSysString();
  577.  
  578.     BOOL bResult = FALSE;
  579.     VARIANT vReturn;
  580.     vReturn.vt = VT_BSTR;
  581.     vReturn.bstrVal = NULL;
  582.     HRESULT hr = m_pBrowserApp->GetProperty(bstrProperty, &vReturn);
  583.  
  584.     if (SUCCEEDED(hr))
  585.     {
  586.         strValue = CString(vReturn.bstrVal);
  587.         bResult = TRUE;
  588.     }
  589.  
  590.     ::SysFreeString(bstrProperty);
  591.     return bResult;
  592. }
  593.  
  594. COleVariant CHtmlView::GetProperty(LPCTSTR lpszProperty)
  595. {
  596.     COleVariant result;
  597.  
  598.     static BYTE parms[] =
  599.         VTS_BSTR;
  600.     m_wndBrowser.InvokeHelper(0x12f, DISPATCH_METHOD,
  601.         VT_VARIANT, (void*)&result, parms, lpszProperty);
  602.  
  603.     return result;
  604. }
  605.  
  606. CString CHtmlView::GetFullName() const
  607. {
  608.     ASSERT(m_pBrowserApp != NULL);
  609.  
  610.     BSTR bstr;
  611.     m_pBrowserApp->get_FullName(&bstr);
  612.     CString retVal(bstr);
  613.     return retVal;
  614. }
  615.  
  616. /////////////////////////////////////////////////////////////////////////////
  617. // CHtmlView event reflectors
  618.  
  619. void CHtmlView::NavigateComplete2(LPDISPATCH /* pDisp */, VARIANT* URL)
  620. {
  621.     ASSERT(V_VT(URL) == VT_BSTR);
  622.  
  623.     USES_CONVERSION;
  624.  
  625.     CString str = OLE2T(V_BSTR(URL));
  626.     OnNavigateComplete2(str);
  627. }
  628.  
  629. void CHtmlView::BeforeNavigate2(LPDISPATCH /* pDisp */, VARIANT* URL,
  630.         VARIANT* Flags, VARIANT* TargetFrameName,
  631.         VARIANT* PostData, VARIANT* Headers, BOOL* Cancel)
  632. {
  633.     ASSERT(V_VT(URL) == VT_BSTR);
  634.     ASSERT(V_VT(TargetFrameName) == VT_BSTR);
  635.     ASSERT(V_VT(PostData) == (VT_VARIANT | VT_BYREF));
  636.     ASSERT(V_VT(Headers) == VT_BSTR);
  637.     ASSERT(Cancel != NULL);
  638.  
  639.     USES_CONVERSION;
  640.  
  641.     VARIANT* vtPostedData = V_VARIANTREF(PostData);
  642.     CByteArray array;
  643.     if (V_VT(vtPostedData) & VT_ARRAY)
  644.     {
  645.         // must be a vector of bytes
  646.         ASSERT(vtPostedData->parray->cDims == 1 && vtPostedData->parray->cbElements == 1);
  647.  
  648.         vtPostedData->vt |= VT_UI1;
  649.         COleSafeArray safe(vtPostedData);
  650.  
  651.         DWORD dwSize = safe.GetOneDimSize();
  652.         LPVOID pVoid;
  653.         safe.AccessData(&pVoid);
  654.  
  655.         array.SetSize(dwSize);
  656.         LPBYTE lpByte = array.GetData();
  657.  
  658.         memcpy(lpByte, pVoid, dwSize);
  659.         safe.UnaccessData();
  660.     }
  661.     // make real parameters out of the notification
  662.  
  663.     CString strTargetFrameName(V_BSTR(TargetFrameName));
  664.     CString strURL = V_BSTR(URL);
  665.     CString strHeaders = V_BSTR(Headers);
  666.     DWORD nFlags = V_I4(Flags);
  667.  
  668.     // notify the user's class
  669.     OnBeforeNavigate2(strURL, nFlags, strTargetFrameName,
  670.         array, strHeaders, Cancel);
  671. }
  672.  
  673. void CHtmlView::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
  674. {
  675.     UNUSED_ALWAYS(pDisp);
  676.     ASSERT(V_VT(URL) == VT_BSTR);
  677.  
  678.     CString str(V_BSTR(URL));
  679.     OnDocumentComplete(str);
  680. }
  681.  
  682. /////////////////////////////////////////////////////////////////////////////
  683. // CHtmlView Events
  684.  
  685. void CHtmlView::OnProgressChange(long lProgress, long lProgressMax)
  686. {
  687.     // user will override to handle this notification
  688.     UNUSED_ALWAYS(lProgress);
  689.     UNUSED_ALWAYS(lProgressMax);
  690. }
  691.  
  692. void CHtmlView::OnCommandStateChange(long lCommand, BOOL bEnable)
  693. {
  694.     // user will override to handle this notification
  695.     UNUSED_ALWAYS(lCommand);
  696.     UNUSED_ALWAYS(bEnable);
  697. }
  698.  
  699. void CHtmlView::OnDownloadBegin()
  700. {
  701.     // user will override to handle this notification
  702. }
  703.  
  704. void CHtmlView::OnDownloadComplete()
  705. {
  706.     // user will override to handle this notification
  707. }
  708.  
  709. void CHtmlView::OnTitleChange(LPCTSTR lpszText)
  710. {
  711.     // user will override to handle this notification
  712.     UNUSED_ALWAYS(lpszText);
  713. }
  714.  
  715. void CHtmlView::OnPropertyChange(LPCTSTR lpszProperty)
  716. {
  717.     // user will override to handle this notification
  718.     UNUSED_ALWAYS(lpszProperty);
  719. }
  720.  
  721. void CHtmlView::OnNewWindow2(LPDISPATCH* ppDisp, BOOL* bCancel)
  722. {
  723.     // default to continuing
  724.     bCancel = FALSE;
  725.  
  726.     // user will override to handle this notification
  727.     UNUSED_ALWAYS(ppDisp);
  728. }
  729.  
  730. void CHtmlView::OnDocumentComplete(LPCTSTR lpszURL)
  731. {
  732.     // user will override to handle this notification
  733.     UNUSED_ALWAYS(lpszURL);
  734. }
  735.  
  736. void CHtmlView::OnQuit()
  737. {
  738.     // user will override to handle this notification
  739. }
  740.  
  741. void CHtmlView::OnVisible(BOOL bVisible)
  742. {
  743.     // user will override to handle this notification
  744.     UNUSED_ALWAYS(bVisible);
  745. }
  746.  
  747. void CHtmlView::OnToolBar(BOOL bToolBar)
  748. {
  749.     // user will override to handle this notification
  750.     UNUSED_ALWAYS(bToolBar);
  751. }
  752.  
  753. void CHtmlView::OnMenuBar(BOOL bMenuBar)
  754. {
  755.     // user will override to handle this notification
  756.     UNUSED_ALWAYS(bMenuBar);
  757. }
  758.  
  759. void CHtmlView::OnStatusBar(BOOL bStatusBar)
  760. {
  761.     // user will override to handle this notification
  762.     UNUSED_ALWAYS(bStatusBar);
  763. }
  764.  
  765. void CHtmlView::OnFullScreen(BOOL bFullScreen)
  766. {
  767.     // user will override to handle this notification
  768.     UNUSED_ALWAYS(bFullScreen);
  769. }
  770.  
  771. void CHtmlView::OnTheaterMode(BOOL bTheaterMode)
  772. {
  773.     // user will override to handle this notification
  774.     UNUSED_ALWAYS(bTheaterMode);
  775. }
  776.  
  777. void CHtmlView::OnNavigateComplete2(LPCTSTR lpszURL)
  778. {
  779.     // user will override to handle this notification
  780.     UNUSED_ALWAYS(lpszURL);
  781. }
  782.  
  783. void CHtmlView::OnBeforeNavigate2(LPCTSTR lpszURL, DWORD nFlags,
  784.     LPCTSTR lpszTargetFrameName, CByteArray& baPostData,
  785.     LPCTSTR lpszHeaders, BOOL* bCancel)
  786. {
  787.     // default to continuing
  788.     bCancel = FALSE;
  789.  
  790.     // user will override to handle this notification
  791.     UNUSED_ALWAYS(lpszURL);
  792.     UNUSED_ALWAYS(nFlags);
  793.     UNUSED_ALWAYS(lpszTargetFrameName);
  794.     UNUSED_ALWAYS(baPostData);
  795.     UNUSED_ALWAYS(lpszHeaders);
  796. }
  797.  
  798. void CHtmlView::OnStatusTextChange(LPCTSTR pszText)
  799. {
  800.     // try to set the status bar text via the frame
  801.  
  802.     CFrameWnd* pFrame = GetParentFrame();
  803.     if (pFrame != NULL)
  804.         pFrame->SetMessageText(pszText);
  805. }
  806.  
  807. /////////////////////////////////////////////////////////////////////////////
  808. // Inline function declarations expanded out-of-line
  809.  
  810. #ifndef _AFX_ENABLE_INLINES
  811.  
  812. // expand inlines for Html functions
  813. static char _szAfxHtmlInl[] = "afxhtml.inl";
  814. #undef THIS_FILE
  815. #define THIS_FILE _szAfxHtmlInl
  816. #define _AFXHTML_INLINE
  817. #include "afxhtml.inl"
  818.  
  819. #endif //!_AFX_ENABLE_INLINES
  820.  
  821. /////////////////////////////////////////////////////////////////////////////
  822. // Pre-startup code
  823.  
  824. #ifdef AFX_INIT_SEG
  825. #pragma code_seg(AFX_INIT_SEG)
  826. #endif
  827.  
  828. IMPLEMENT_DYNCREATE(CHtmlView, CFormView)
  829.