1
0

viewhtml.cpp 20 KB

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