Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

501 lines
14 KiB

  1. // wvcoord.cpp : Implementation of CWebViewCoord
  2. #include "priv.h"
  3. #include "wvcoord.h"
  4. const CLSID CLSID_WebViewOld = {0x7a707490,0x260a,0x11d1,{0x83,0xdf,0x00,0xa0,0xc9,0x0d,0xc8,0x49}}; // retired from service, so made private
  5. /////////////////////////////////////////////////////////////////////////////
  6. // CWebViewCoord
  7. /////////////////////////////////////////////////////////////////////////////
  8. CWebViewCoord::CWebViewCoord()
  9. {
  10. m_pFileListWrapper = NULL;
  11. m_pThumbNailWrapper = NULL;
  12. m_pdispWindow = NULL;
  13. m_dwFileListAdviseCookie = 0;
  14. m_dwThumbNailAdviseCookie = 0;
  15. m_dwHtmlWindowAdviseCookie = 0;
  16. m_dwCSCHotTrackCookie = 0;
  17. }
  18. CWebViewCoord::~CWebViewCoord()
  19. {
  20. ReleaseFolderObjects();
  21. }
  22. STDMETHODIMP CWebViewCoord::Invoke(DISPID dispidMember, REFIID riid, LCID lcid,
  23. WORD wFlags, DISPPARAMS *pDispParams,
  24. VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
  25. UINT *puArgErr)
  26. {
  27. HRESULT hr = S_OK;
  28. switch (dispidMember)
  29. {
  30. case DISPID_HTMLWINDOWEVENTS_ONLOAD:
  31. hr = OnWindowLoad();
  32. break;
  33. case DISPID_HTMLWINDOWEVENTS_ONUNLOAD:
  34. hr = OnWindowUnLoad();
  35. break;
  36. case DISPID_HTMLWINDOWEVENTS_ONRESIZE:
  37. hr = OnFixSize();
  38. break;
  39. case DISPID_EVMETH_ONMOUSEOVER:
  40. hr = OnCSCMouseOver();
  41. break;
  42. case DISPID_EVMETH_ONMOUSEOUT:
  43. hr = OnCSCMouseOut();
  44. break;
  45. case DISPID_EVMETH_ONKEYPRESS:
  46. case DISPID_EVMETH_ONCLICK:
  47. hr = OnCSCClick();
  48. break;
  49. default:
  50. hr = IDispatchImpl<IWebView, &IID_IWebView, &LIBID_WEBVWLib>::
  51. Invoke(dispidMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
  52. break;
  53. }
  54. return hr;
  55. }
  56. STDMETHODIMP CWebViewCoord::OnCSCClick()
  57. {
  58. HRESULT hres = S_OK;
  59. if (S_OK != _IsSafe())
  60. {
  61. hres = E_ACCESSDENIED;
  62. }
  63. else
  64. {
  65. if (m_pFileListWrapper)
  66. {
  67. hres = m_pFileListWrapper->OnCSCClick();
  68. }
  69. }
  70. return hres;
  71. }
  72. STDMETHODIMP CWebViewCoord::OnCSCMouseOver()
  73. {
  74. HRESULT hres = S_OK;
  75. if (S_OK != _IsSafe())
  76. {
  77. hres = E_ACCESSDENIED;
  78. }
  79. else
  80. {
  81. if (m_pFileListWrapper)
  82. {
  83. hres = m_pFileListWrapper->OnCSCMouseOnOff(TRUE);
  84. }
  85. }
  86. return hres;
  87. }
  88. STDMETHODIMP CWebViewCoord::OnCSCMouseOut()
  89. {
  90. HRESULT hres = S_OK;
  91. if (S_OK != _IsSafe())
  92. {
  93. hres = E_ACCESSDENIED;
  94. }
  95. else
  96. {
  97. if (m_pFileListWrapper)
  98. {
  99. hres = m_pFileListWrapper->OnCSCMouseOnOff(FALSE);
  100. }
  101. }
  102. return hres;
  103. }
  104. STDMETHODIMP CWebViewCoord::CSCSynchronize()
  105. {
  106. HRESULT hres = S_OK;
  107. if (S_OK != _IsSafe())
  108. {
  109. hres = E_ACCESSDENIED;
  110. }
  111. else
  112. {
  113. if (m_pFileListWrapper)
  114. {
  115. hres = m_pFileListWrapper->CSCSynchronize();
  116. }
  117. }
  118. return hres;
  119. }
  120. STDMETHODIMP CWebViewCoord::SetSite(IUnknown *punkSite)
  121. {
  122. HRESULT hr;
  123. if (punkSite == NULL && m_pdispWindow)
  124. {
  125. DisconnectHtmlEvents(m_pdispWindow, m_dwHtmlWindowAdviseCookie);
  126. m_dwHtmlWindowAdviseCookie = 0;
  127. }
  128. hr = IObjectWithSiteImpl<CWebViewCoord>::SetSite(punkSite);
  129. m_spClientSite = NULL; // Release client site pointer
  130. ReleaseFolderObjects();
  131. if (punkSite != NULL && SUCCEEDED(hr))
  132. {
  133. hr = punkSite->QueryInterface(IID_IOleClientSite, (void **)&m_spClientSite);
  134. if (SUCCEEDED(hr))
  135. {
  136. hr = ConnectHtmlEvents(this, m_spClientSite, &m_pdispWindow, &m_dwHtmlWindowAdviseCookie);
  137. }
  138. }
  139. return hr;
  140. }
  141. HRESULT CWebViewCoord::InitFolderObjects()
  142. {
  143. HRESULT hr;
  144. CComPtr<IOleContainer> spContainer;
  145. CComPtr<IDispatch> spdispItem;
  146. CComVariant vEmpty;
  147. CComPtr<IThumbCtl> spThumbNail;
  148. CComPtr<IHTMLElement> spElement;
  149. CComPtr<IHTMLElement> spInfo;
  150. CComPtr<IHTMLElement> spLinks;
  151. CComPtr<IHTMLElement> spMediaPlayerSpan;
  152. CComPtr<IShellFolderViewDual> spFileList;
  153. CComPtr<IHTMLElement> spCSCPlusMin;
  154. CComPtr<IHTMLElement> spCSCText;
  155. CComPtr<IHTMLElement> spCSCDetail;
  156. CComPtr<IHTMLElement> spCSCButton;
  157. CComPtr<IHTMLStyle> spCSCStyle;
  158. CComPtr<IHTMLStyle> spCSCDetailStyle;
  159. CComPtr<IHTMLStyle> spCSCButtonStyle;
  160. CComPtr<IHTMLWindow2> spWindow;
  161. // Get some document level objects
  162. IfFailRet(m_spClientSite->GetContainer(&spContainer));
  163. IfFailRet(spContainer->QueryInterface(IID_IHTMLDocument2, (void **)&m_spDocument));
  164. IfFailRet(IUnknown_QueryService(m_spClientSite, SID_SHTMLWindow, IID_IHTMLWindow2, (LPVOID*)&spWindow));
  165. IfFailRet(m_spDocument->get_all(&m_spDocAll));
  166. hr = m_spDocument->get_body(&spElement);
  167. if (SUCCEEDED(hr))
  168. {
  169. spElement->QueryInterface(IID_IHTMLControlElement, (void **)&m_spDocBody);
  170. }
  171. //
  172. // Init Info
  173. //
  174. if (SUCCEEDED(m_spDocAll->item(CComVariant(OLESTR("Info")), vEmpty, &spdispItem)) && spdispItem)
  175. {
  176. spdispItem->QueryInterface(IID_IHTMLElement, (void **)&spInfo);
  177. spdispItem = NULL;
  178. }
  179. if (SUCCEEDED(m_spDocAll->item(CComVariant(OLESTR("Links")), vEmpty, &spdispItem)) && spdispItem)
  180. {
  181. spdispItem->QueryInterface(IID_IHTMLElement, (void **)&spLinks);
  182. spdispItem = NULL;
  183. }
  184. if (SUCCEEDED(m_spDocAll->item(CComVariant(OLESTR("MediaPlayerSpan")), vEmpty, &spdispItem)) && spdispItem)
  185. {
  186. spdispItem->QueryInterface(IID_IHTMLElement, (void **)&spMediaPlayerSpan);
  187. spdispItem = NULL;
  188. }
  189. if (SUCCEEDED(m_spDocAll->item(CComVariant(OLESTR("panel")), vEmpty, &spdispItem)) && spdispItem)
  190. {
  191. FindObjectStyle(spdispItem, m_spPanelStyle);
  192. spdispItem = NULL;
  193. }
  194. if (SUCCEEDED(m_spDocAll->item(CComVariant(OLESTR("CSC")), vEmpty, &spdispItem)) && spdispItem)
  195. {
  196. FindObjectStyle(spdispItem, spCSCStyle);
  197. spdispItem = NULL;
  198. }
  199. if (SUCCEEDED(m_spDocAll->item(CComVariant(OLESTR("CSCHotTrack")), vEmpty, &spdispItem)) && spdispItem)
  200. {
  201. //
  202. // Set up sink for CSC UI notifications to implement hot tracking and expand/collapse
  203. //
  204. AtlAdvise(spdispItem, GetUnknown(), IID_IDispatch, &m_dwCSCHotTrackCookie);
  205. spdispItem = NULL;
  206. }
  207. if (SUCCEEDED(m_spDocAll->item(CComVariant(OLESTR("CSCPlusMin")), vEmpty, &spdispItem)) && spdispItem)
  208. {
  209. spdispItem->QueryInterface(IID_IHTMLElement, (void **)&spCSCPlusMin);
  210. spdispItem = NULL;
  211. }
  212. if (SUCCEEDED(m_spDocAll->item(CComVariant(OLESTR("CSCText")), vEmpty, &spdispItem)) && spdispItem)
  213. {
  214. spdispItem->QueryInterface(IID_IHTMLElement, (void **)&spCSCText);
  215. spdispItem = NULL;
  216. }
  217. if (SUCCEEDED(m_spDocAll->item(CComVariant(OLESTR("CSCDetail")), vEmpty, &spdispItem)) && spdispItem)
  218. {
  219. spdispItem->QueryInterface(IID_IHTMLElement, (void **)&spCSCDetail);
  220. FindObjectStyle(spdispItem, spCSCDetailStyle);
  221. spdispItem = NULL;
  222. }
  223. if (SUCCEEDED(m_spDocAll->item(CComVariant(OLESTR("CSCButton")), vEmpty, &spdispItem)) && spdispItem)
  224. {
  225. spdispItem->QueryInterface(IID_IHTMLElement, (void **)&spCSCButton);
  226. FindObjectStyle(spdispItem, spCSCButtonStyle);
  227. spdispItem = NULL;
  228. }
  229. //
  230. // Init the thumbnail wrapper object
  231. //
  232. if (SUCCEEDED(m_spDocAll->item(CComVariant(OLESTR("ThumbNail")), vEmpty, &spdispItem)) && spdispItem)
  233. {
  234. if (SUCCEEDED(spdispItem->QueryInterface(IID_IThumbCtl, (void **)&spThumbNail)))
  235. {
  236. m_pThumbNailWrapper = new CThumbNailWrapper;
  237. if (m_pThumbNailWrapper == NULL)
  238. {
  239. return E_OUTOFMEMORY;
  240. }
  241. CComPtr<IDispatch> spdispItem2;
  242. CComPtr<IHTMLElement> spThumbnailLabel;
  243. if (SUCCEEDED(m_spDocAll->item(CComVariant(OLESTR("ThumbnailLabel")), vEmpty, &spdispItem2)) && spdispItem2)
  244. {
  245. spdispItem2->QueryInterface(IID_IHTMLElement, (void **)&spThumbnailLabel);
  246. spdispItem2 = NULL;
  247. }
  248. m_pThumbNailWrapper->Init(spThumbNail, spThumbnailLabel);
  249. AtlAdvise(spdispItem, m_pThumbNailWrapper, IID_IDispatch, &m_dwThumbNailAdviseCookie);
  250. }
  251. spdispItem = NULL;
  252. }
  253. //
  254. // Init the file list object
  255. //
  256. if (SUCCEEDED(m_spDocAll->item(CComVariant(OLESTR("Filelist")), vEmpty, &spdispItem)) && spdispItem)
  257. {
  258. if (SUCCEEDED(spdispItem->QueryInterface(IID_IShellFolderViewDual, (void **)&spFileList)))
  259. {
  260. m_pFileListWrapper = new CFileListWrapper;
  261. if (m_pFileListWrapper == NULL)
  262. {
  263. AtlUnadvise(spdispItem, IID_IDispatch, m_dwThumbNailAdviseCookie);
  264. m_dwThumbNailAdviseCookie = 0;
  265. delete m_pThumbNailWrapper;
  266. return E_OUTOFMEMORY;
  267. }
  268. m_pFileListWrapper->Init(spFileList, spInfo, spLinks, m_spPanelStyle, spMediaPlayerSpan,
  269. spCSCPlusMin, spCSCText, spCSCDetail, spCSCButton, spCSCStyle,
  270. spCSCDetailStyle, spCSCButtonStyle, m_spDocument, spWindow, m_pThumbNailWrapper);
  271. AtlAdvise(spdispItem, m_pFileListWrapper, IID_IDispatch,
  272. &m_dwFileListAdviseCookie);
  273. }
  274. spdispItem = NULL;
  275. }
  276. //
  277. // Init onsize properties
  278. //
  279. if (SUCCEEDED(m_spDocAll->item(CComVariant(OLESTR("Banner")), vEmpty, &spdispItem)) && spdispItem)
  280. {
  281. spdispItem->QueryInterface(IID_IHTMLElement, (void **)&m_spHeading);
  282. FindObjectStyle(spdispItem, m_spHeadingStyle);
  283. spdispItem = NULL;
  284. }
  285. m_bRTLDocument = IsRTLDocument(m_spDocument);
  286. if (!m_bRTLDocument && m_spPanelStyle)
  287. {
  288. m_spPanelStyle->put_overflow(OLESTR("auto"));
  289. }
  290. if (SUCCEEDED(m_spDocAll->item(CComVariant(OLESTR("FileList")), vEmpty, &spdispItem)) && spdispItem)
  291. {
  292. FindObjectStyle(spdispItem, m_spFileListStyle);
  293. spdispItem = NULL;
  294. }
  295. if (SUCCEEDED(m_spDocAll->item(CComVariant(OLESTR("rule")), vEmpty, &spdispItem)) && spdispItem)
  296. {
  297. FindObjectStyle(spdispItem, m_spRuleStyle);
  298. spdispItem = NULL;
  299. }
  300. return S_OK;
  301. }
  302. HRESULT CWebViewCoord::ReleaseFolderObjects()
  303. {
  304. CComPtr<IDispatch> spdisp;
  305. //
  306. // Do the unadvise
  307. //
  308. if (m_dwCSCHotTrackCookie)
  309. {
  310. CComVariant vEmpty;
  311. if (SUCCEEDED(m_spDocAll->item(CComVariant(OLESTR("CSCHotTrack")), vEmpty, &spdisp)) && spdisp)
  312. {
  313. AtlUnadvise(spdisp, IID_IDispatch, m_dwCSCHotTrackCookie);
  314. m_dwCSCHotTrackCookie = 0;
  315. spdisp = NULL;
  316. }
  317. }
  318. if (m_dwFileListAdviseCookie != 0) {
  319. spdisp = m_pFileListWrapper->Control();
  320. if (spdisp != NULL) {
  321. AtlUnadvise(spdisp, IID_IDispatch, m_dwFileListAdviseCookie);
  322. m_dwFileListAdviseCookie = 0;
  323. spdisp = NULL;
  324. }
  325. }
  326. if (m_dwThumbNailAdviseCookie != 0) {
  327. spdisp = (IThumbCtl *)(m_pThumbNailWrapper->Control());
  328. if (spdisp != NULL) {
  329. AtlUnadvise(spdisp, IID_IDispatch, m_dwThumbNailAdviseCookie);
  330. m_dwThumbNailAdviseCookie = 0;
  331. spdisp = NULL;
  332. }
  333. }
  334. //
  335. // Free the file list wrapper
  336. //
  337. if (m_pFileListWrapper != NULL) {
  338. // Need to unadvise from WV links before releasing
  339. m_pFileListWrapper->AdviseWebviewLinks( FALSE );
  340. m_pFileListWrapper->Release();
  341. m_pFileListWrapper = NULL;
  342. }
  343. if (m_pThumbNailWrapper != NULL) {
  344. m_pThumbNailWrapper->Release();
  345. m_pThumbNailWrapper = NULL;
  346. }
  347. //
  348. // Free any references we may have
  349. //
  350. m_spDocAll = NULL;
  351. m_spDocBody = NULL;
  352. m_spDocument = NULL;
  353. m_spFileListStyle = NULL;
  354. m_spHeading = NULL;
  355. m_spHeadingStyle = NULL;
  356. m_spPanelStyle = NULL;
  357. m_spRuleStyle = NULL;
  358. return S_OK;
  359. }
  360. HRESULT CWebViewCoord::OnWindowLoad()
  361. {
  362. HRESULT hr;
  363. ReleaseFolderObjects();
  364. InitFolderObjects();
  365. hr = OnFixSize();
  366. return hr;
  367. }
  368. HRESULT CWebViewCoord::OnWindowUnLoad()
  369. {
  370. return ReleaseFolderObjects();
  371. }
  372. HRESULT CWebViewCoord::OnFixSize()
  373. {
  374. HRESULT hr = S_OK;
  375. LONG lClientWidth;
  376. if (m_spFileListStyle && m_spDocBody && SUCCEEDED(m_spDocBody->get_clientWidth(&lClientWidth)))
  377. {
  378. LONG lPanelWidth;
  379. if (!m_spPanelStyle || FAILED(m_spPanelStyle->get_pixelWidth(&lPanelWidth)))
  380. {
  381. lPanelWidth = 0;
  382. }
  383. CComBSTR bstrPanelVisibility;
  384. LONG lFileListLeft, lFileListWidth = -1;
  385. if (lClientWidth < (lPanelWidth * 2))
  386. {
  387. bstrPanelVisibility = OLESTR("hidden");
  388. lFileListLeft = 0;
  389. }
  390. else
  391. {
  392. bstrPanelVisibility = OLESTR("visible");
  393. if (m_bRTLDocument)
  394. {
  395. lFileListLeft = 0;
  396. lFileListWidth = lClientWidth - lPanelWidth;
  397. if (m_spPanelStyle)
  398. {
  399. m_spPanelStyle->put_pixelLeft(lClientWidth - lPanelWidth);
  400. }
  401. }
  402. else
  403. {
  404. lFileListLeft = lPanelWidth;
  405. }
  406. }
  407. if (m_spPanelStyle)
  408. {
  409. m_spPanelStyle->put_visibility(bstrPanelVisibility);
  410. }
  411. m_spFileListStyle->put_pixelLeft(lFileListLeft);
  412. m_spFileListStyle->put_pixelWidth((lFileListWidth == -1) ?
  413. (lClientWidth - lFileListLeft) : lFileListWidth);
  414. }
  415. return hr;
  416. }