Source code of Windows XP (NT5)
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.

1410 lines
41 KiB

  1. #include "priv.h"
  2. #include "basesb.h"
  3. #define DISPID_ONTRANSITIONFINISH 1
  4. const GUID DIID_ICSSTransitionEvents = {0x8E64AA50L,0xDC42,0x11D0,0x99,0x49,0x00,0xA0,0xC9,0x0A,0x8F,0xF2};
  5. //
  6. // Notes:
  7. // - CTransitionSite object is always contained in a CBaseBrowser object,
  8. // therefore, it does not have its own reference count.
  9. // - The macro CONTAINERMAP maps the pointer to this object up to the
  10. // containing object.
  11. // - CTransitionSite is a friend class of CBaseBrowser class.
  12. //
  13. // Notes:
  14. // - Having anything be a friend of CBaseBrowser is not good.
  15. // - This object is completely contained by it's parent object,
  16. // so to avoid a reference loop we keep our pContainer pointer
  17. // with no reference. Do not QI off it or we will leak!
  18. //
  19. #define TF_TRSITE 0
  20. #define TF_TRDRAW TF_ALWAYS
  21. #define TF_TREXTDRAW 0
  22. #define TF_TRLIFE 0
  23. #define TF_ADDREFRELEASE 0
  24. #define TF_TRSPB 0
  25. #define TF_DEBUGQI 0
  26. /////////////////////////////////////////////////////////////////////////////
  27. // Design constants
  28. /////////////////////////////////////////////////////////////////////////////
  29. #define MIN_TRANSITION_DURATION 0.0
  30. #define MAX_TRANSITION_DURATION 100.0
  31. #define MIN_ONVIEWCHANGE_DURATION 1500 // ms
  32. #define TSPB_CREATE_INCR 4
  33. // CTransitionSitePropertyBag property list create size
  34. /////////////////////////////////////////////////////////////////////////////
  35. // Module variables
  36. /////////////////////////////////////////////////////////////////////////////
  37. static const TCHAR c_szTransitionsKey[] = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CSSFilters");
  38. static const OLECHAR c_szDurationProp[] = OLESTR("Duration");
  39. static OLECHAR * s_szApplyMethod = OLESTR("Apply");
  40. static OLECHAR * s_szPlayMethod = OLESTR("Play");
  41. static OLECHAR * s_szStopMethod = OLESTR("Stop");
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CTransitionSite
  44. /////////////////////////////////////////////////////////////////////////////
  45. #undef THISCLASS
  46. CTransitionSite::CTransitionSite
  47. (
  48. IShellBrowser * pcont
  49. ) : _pContainer(pcont) // DO NOT ADDREF
  50. {
  51. TraceMsg(TF_TRLIFE, "TRS::ctor called");
  52. ASSERT(pcont != NULL);
  53. _uState = TRSTATE_NONE;
  54. _ptiCurrent = NULL;
  55. }
  56. CTransitionSite::~CTransitionSite
  57. (
  58. )
  59. {
  60. TraceMsg(TF_TRLIFE, "TRS::dtor called");
  61. #ifdef DEBUG
  62. ASSERT(_pSite == NULL);
  63. ASSERT(_psvNew == NULL);
  64. ASSERT(_pvoNew == NULL);
  65. ASSERT(_hwndViewNew == NULL);
  66. ASSERT(_pTransition == NULL);
  67. ASSERT(_pDispTransition == NULL);
  68. ASSERT(_dwTransitionSink == NULL);
  69. #endif // DEBUG
  70. for (int te = teFirstEvent; te < teNumEvents; te++)
  71. SAFERELEASE(_tiEventInfo[te].pPropBag);
  72. }
  73. /////////////////////////////////////////////////////////////////////////////
  74. // CTransitionSite::_ApplyTransition
  75. /////////////////////////////////////////////////////////////////////////////
  76. HRESULT CTransitionSite::_ApplyTransition
  77. (
  78. BOOL bSiteChanging
  79. )
  80. {
  81. HRESULT hrResult = S_OK;
  82. TraceMsg(TF_TRSITE, "TRS::_ApplyTransition(%d) called", bSiteChanging);
  83. if (_ptiCurrent != NULL)
  84. _OnComplete();
  85. ASSERT(_ptiCurrent == NULL);
  86. if (bSiteChanging && (_tiEventInfo[teSiteEnter].clsid != CLSID_NULL))
  87. _ptiCurrent = &_tiEventInfo[teSiteEnter];
  88. else if (_tiEventInfo[tePageEnter].clsid != CLSID_NULL)
  89. _ptiCurrent = &_tiEventInfo[tePageEnter];
  90. else
  91. _ptiCurrent = NULL;
  92. // Allow the contatiner a chance to set a transition if we don't have one.
  93. if (_ptiCurrent == NULL)
  94. {
  95. // vaIn.vt = VT_BOOL; vaIn.boolVal = Site is changing;
  96. VARIANTARG vaIn = { VT_BOOL, bSiteChanging };
  97. // vaOut[0].vt = VT_I4; vaOut[0].lVal = TransitionEvent
  98. // vaOut[1].vt = VT_BSTR; vaOut[1].bstrVal = Transition String.
  99. VARIANTARG vaOut[2] = { 0 };
  100. if (SUCCEEDED(hrResult = IUnknown_Exec(_pContainer,
  101. &CGID_ShellDocView,
  102. SHDVID_GETTRANSITION,
  103. OLECMDEXECOPT_DODEFAULT,
  104. &vaIn,
  105. vaOut)))
  106. {
  107. TRANSITIONINFO ti = { 0 };
  108. if (
  109. (vaOut[0].vt == VT_I4)
  110. &&
  111. ((vaOut[0].lVal >= teFirstEvent) && (vaOut[0].lVal < teNumEvents))
  112. &&
  113. (vaOut[1].vt == VT_BSTR)
  114. &&
  115. (vaOut[1].bstrVal != NULL)
  116. &&
  117. ParseTransitionInfo((LPWSTR)vaOut[1].bstrVal, &ti)
  118. )
  119. {
  120. hrResult = _SetTransitionInfo((TransitionEvent)vaOut[0].lVal, &ti);
  121. _ptiCurrent = &_tiEventInfo[vaOut[0].lVal];
  122. }
  123. else
  124. hrResult = E_UNEXPECTED;
  125. SAFERELEASE(ti.pPropBag);
  126. }
  127. TraceMsg(TF_TRSITE, "hrResult = 0x%.8X after _pContainer->Exec()", hrResult);
  128. VariantClear(&vaOut[0]);
  129. VariantClear(&vaOut[1]);
  130. }
  131. if (SUCCEEDED(hrResult))
  132. {
  133. if (SUCCEEDED(hrResult = _LoadTransition()))
  134. {
  135. ASSERT(_hwndViewNew != NULL);
  136. // We need to hide the view window to draw on our own DC.
  137. _fViewIsVisible = ::IsWindowVisible(_hwndViewNew);
  138. if (_fViewIsVisible)
  139. ::ShowWindow(_hwndViewNew, SW_HIDE);
  140. _pContainer->EnableModelessSB(FALSE);
  141. }
  142. }
  143. else
  144. {
  145. // Make sure we don't fiddle with the window visibility
  146. // in _OnComplete if we didn't succeed.
  147. _hwndViewNew = NULL;
  148. _OnComplete();
  149. }
  150. return hrResult;
  151. }
  152. /////////////////////////////////////////////////////////////////////////////
  153. // CTransitionSite::_LoadTransition
  154. /////////////////////////////////////////////////////////////////////////////
  155. HRESULT CTransitionSite::_LoadTransition
  156. (
  157. )
  158. {
  159. HRESULT hrResult;
  160. TraceMsg(TF_TRSITE, "TRS::_LoadTransition called");
  161. if ((_ptiCurrent == NULL) || (_ptiCurrent->clsid == CLSID_NULL))
  162. return E_INVALIDARG;
  163. // Create the transition.
  164. for (;;)
  165. {
  166. ASSERT(_pTransition == NULL);
  167. if (FAILED(hrResult = CoCreateInstance( _ptiCurrent->clsid,
  168. NULL,
  169. CLSCTX_INPROC_SERVER,
  170. IID_IHTMLViewFilter,
  171. (void **)&_pTransition)))
  172. {
  173. TraceMsg(TF_ERROR, "TRS::_LoadTransition CoCreateInstance failed 0x%X", hrResult);
  174. break;
  175. }
  176. ASSERT(_pDispTransition == NULL);
  177. if (FAILED(hrResult = _pTransition->QueryInterface( IID_IDispatch,
  178. (void **)&_pDispTransition)))
  179. {
  180. TraceMsg(TF_ERROR, "TRS::_LoadTransition QI::IDispatch failed 0x%X", hrResult);
  181. break;
  182. }
  183. ASSERT(_dwTransitionSink == 0);
  184. if (FAILED(hrResult = ConnectToConnectionPoint( SAFECAST(this, IDispatch *),
  185. DIID_ICSSTransitionEvents,
  186. TRUE,
  187. _pTransition,
  188. &_dwTransitionSink,
  189. NULL)))
  190. {
  191. TraceMsg(TF_ERROR, "TRS::_LoadTransition ConnectToConnectionPoint failed 0x%X", hrResult);
  192. break;
  193. }
  194. // Supply the property bag to the transition (if needed)
  195. IPersistPropertyBag * pPersistPropBag;
  196. if (
  197. (_ptiCurrent->pPropBag != NULL)
  198. &&
  199. SUCCEEDED(_pTransition->QueryInterface(IID_IPersistPropertyBag, (void **)&pPersistPropBag))
  200. )
  201. {
  202. EVAL(SUCCEEDED(pPersistPropBag->InitNew()));
  203. EVAL(SUCCEEDED(pPersistPropBag->Load(SAFECAST(_ptiCurrent->pPropBag, IPropertyBag *), NULL)));
  204. ATOMICRELEASE(pPersistPropBag);
  205. }
  206. if (FAILED(hrResult = _pTransition->SetSite(SAFECAST(this, IHTMLViewFilterSite *))))
  207. {
  208. TraceMsg(TF_ERROR, "TRS::_LoadTransition _pT->SetSite failed 0x%X", hrResult);
  209. break;
  210. }
  211. if (FAILED(hrResult = _pTransition->SetSource(SAFECAST(this, IHTMLViewFilter *))))
  212. {
  213. TraceMsg(TF_ERROR, "TRS::_LoadTransition _pT->SetSource failed 0x%X", hrResult);
  214. break;
  215. }
  216. if (FAILED(hrResult = _InitWait()))
  217. {
  218. TraceMsg(TF_ERROR, "TRS::_LoadTransition _InitWait failed 0x%X", hrResult);
  219. break;
  220. }
  221. hrResult = S_OK;
  222. break;
  223. }
  224. if (FAILED(hrResult))
  225. _OnComplete();
  226. return hrResult;
  227. }
  228. /////////////////////////////////////////////////////////////////////////////
  229. // CTransitionSite::_SetTransitionInfo
  230. /////////////////////////////////////////////////////////////////////////////
  231. HRESULT CTransitionSite::_SetTransitionInfo
  232. (
  233. TransitionEvent te,
  234. TRANSITIONINFO * pti
  235. )
  236. {
  237. TraceMsg(TF_TRSITE, "TRS::_SetTransitionInfo(%d)", te);
  238. ASSERT((te >= teFirstEvent) && (te < teNumEvents));
  239. SAFERELEASE(_tiEventInfo[te].pPropBag);
  240. _tiEventInfo[te] = *pti;
  241. if (_tiEventInfo[te].pPropBag != NULL)
  242. _tiEventInfo[te].pPropBag->AddRef();
  243. return S_OK;
  244. }
  245. /////////////////////////////////////////////////////////////////////////////
  246. // CTransitionSite::_InitWait
  247. /////////////////////////////////////////////////////////////////////////////
  248. HRESULT CTransitionSite::_InitWait()
  249. {
  250. HRESULT hrResult;
  251. TraceMsg(TF_TRSITE, "TRS::_InitWait called");
  252. ASSERT(_pTransition != NULL);
  253. ASSERT(_pDispTransition != NULL);
  254. ASSERT(_uState == TRSTATE_NONE);
  255. for (;;)
  256. {
  257. RECT rc;
  258. IBrowserService2 *pbs2;
  259. if (SUCCEEDED(_pContainer->QueryInterface(IID_IBrowserService2, (void **)&pbs2)))
  260. {
  261. pbs2->GetViewRect(&rc);
  262. pbs2->Release();
  263. }
  264. EVAL(SUCCEEDED(hrResult = _pTransition->SetPosition(&rc)));
  265. TraceMsg(TF_TRSITE, "TRS::_InitWait called _pTransition->SetPosition 0x%X", hrResult);
  266. DISPID dispid;
  267. if (FAILED(hrResult = _pDispTransition->GetIDsOfNames( IID_NULL,
  268. &s_szApplyMethod,
  269. 1,
  270. LOCALE_USER_DEFAULT,
  271. &dispid)))
  272. {
  273. TraceMsg(TF_ERROR, "TRS::_InitWait _pDispTransition->GetIDsOfNames(Apply) failed 0x%X", hrResult);
  274. break;
  275. }
  276. unsigned int uArgError = (unsigned int)-1;
  277. DISPPARAMS dispparamsNoArgs = { NULL, NULL, 0, 0 };
  278. if (FAILED(hrResult = _pDispTransition->Invoke( dispid,
  279. IID_NULL,
  280. LOCALE_USER_DEFAULT,
  281. DISPATCH_METHOD,
  282. &dispparamsNoArgs,
  283. NULL,
  284. NULL,
  285. &uArgError)))
  286. {
  287. TraceMsg(TF_ERROR, "TRS::_InitWait _pDispTransition->Invoke(Apply) failed 0x%X", hrResult);
  288. break;
  289. }
  290. break;
  291. }
  292. if (SUCCEEDED(hrResult))
  293. _uState = TRSTATE_INITIALIZING;
  294. return hrResult;
  295. }
  296. /////////////////////////////////////////////////////////////////////////////
  297. // CTransitionSite::_StartTransition
  298. /////////////////////////////////////////////////////////////////////////////
  299. HRESULT CTransitionSite::_StartTransition
  300. (
  301. )
  302. {
  303. HRESULT hrResult;
  304. TraceMsg(TF_TRSITE, "TRS::_StartTransition");
  305. ASSERT(_uState == TRSTATE_INITIALIZING);
  306. for (;;)
  307. {
  308. if (_pDispTransition == NULL)
  309. {
  310. hrResult = E_UNEXPECTED;
  311. break;
  312. }
  313. if (
  314. FAILED(hrResult = _psvNew->QueryInterface(IID_IViewObject, (void **)&_pvoNew))
  315. ||
  316. FAILED(hrResult = _pvoNew->SetAdvise( DVASPECT_CONTENT,
  317. 0,
  318. SAFECAST(this, IAdviseSink *)))
  319. )
  320. {
  321. TraceMsg(TF_ERROR, "TRS::_StartTransition QI for IViewObject failed 0x%X", hrResult);
  322. break;
  323. }
  324. _uState = TRSTATE_STARTPAINTING;
  325. DISPID dispid;
  326. if (FAILED(hrResult = _pDispTransition->GetIDsOfNames( IID_NULL,
  327. &s_szPlayMethod,
  328. 1,
  329. LOCALE_USER_DEFAULT,
  330. &dispid)))
  331. {
  332. TraceMsg(TF_ERROR, "TRS::_StartTransition _pDispTransition->GetIDsOfNames(Play) failed 0x%X", hrResult);
  333. break;
  334. }
  335. unsigned int uArgError = (unsigned int)-1;
  336. DISPPARAMS dispparamsNoArgs = { NULL, NULL, 0, 0 };
  337. if (FAILED(hrResult = _pDispTransition->Invoke( dispid,
  338. IID_NULL,
  339. LOCALE_USER_DEFAULT,
  340. DISPATCH_METHOD,
  341. &dispparamsNoArgs,
  342. NULL,
  343. NULL,
  344. &uArgError)))
  345. {
  346. TraceMsg(TF_ERROR, "TRS::_StartTransition _pDispTransition->Invoke(Play) failed 0x%X", hrResult);
  347. break;
  348. }
  349. _uState = TRSTATE_PAINTING;
  350. break;
  351. }
  352. if (FAILED(hrResult))
  353. _OnComplete();
  354. return hrResult;
  355. }
  356. /////////////////////////////////////////////////////////////////////////////
  357. // CTransitionSite::_StopTransition
  358. /////////////////////////////////////////////////////////////////////////////
  359. HRESULT CTransitionSite::_StopTransition
  360. (
  361. )
  362. {
  363. HRESULT hrResult;
  364. for (;;)
  365. {
  366. if (_pDispTransition == NULL)
  367. {
  368. hrResult = E_UNEXPECTED;
  369. break;
  370. }
  371. DISPID dispid;
  372. if (FAILED(hrResult = _pDispTransition->GetIDsOfNames( IID_NULL,
  373. &s_szStopMethod,
  374. 1,
  375. LOCALE_USER_DEFAULT,
  376. &dispid)))
  377. {
  378. TraceMsg(TF_ERROR, "TRS::_StopTransition _pDispTransition->GetIDsOfNames(Stop) failed 0x%X", hrResult);
  379. break;
  380. }
  381. unsigned int uArgError = (unsigned int)-1;
  382. DISPPARAMS dispparamsNoArgs = { NULL, NULL, 0, 0 };
  383. if (FAILED(hrResult = _pDispTransition->Invoke( dispid,
  384. IID_NULL,
  385. LOCALE_USER_DEFAULT,
  386. DISPATCH_METHOD,
  387. &dispparamsNoArgs,
  388. NULL,
  389. NULL,
  390. &uArgError)))
  391. {
  392. TraceMsg(TF_ERROR, "TRS::_StopTransition _pDispTransition->Invoke(Stop) failed 0x%X", hrResult);
  393. break;
  394. }
  395. break;
  396. }
  397. _OnComplete();
  398. return hrResult;
  399. }
  400. /////////////////////////////////////////////////////////////////////////////
  401. // CTransitionSite::_UpdateEventList
  402. /////////////////////////////////////////////////////////////////////////////
  403. HRESULT CTransitionSite::_UpdateEventList
  404. (
  405. )
  406. {
  407. SAFERELEASE(_tiEventInfo[teSiteEnter].pPropBag);
  408. _tiEventInfo[teSiteEnter] = _tiEventInfo[teSiteExit];
  409. _tiEventInfo[teSiteExit].clsid = CLSID_NULL;
  410. _tiEventInfo[teSiteExit].pPropBag = NULL;
  411. SAFERELEASE(_tiEventInfo[tePageEnter].pPropBag);
  412. _tiEventInfo[tePageEnter] = _tiEventInfo[tePageExit];
  413. _tiEventInfo[tePageExit].clsid = CLSID_NULL;
  414. _tiEventInfo[tePageExit].pPropBag = NULL;
  415. _uState = TRSTATE_NONE;
  416. _ptiCurrent = NULL;
  417. return S_OK;
  418. }
  419. /////////////////////////////////////////////////////////////////////////////
  420. // CTransitionSite::_OnComplete
  421. /////////////////////////////////////////////////////////////////////////////
  422. HRESULT CTransitionSite::_OnComplete
  423. (
  424. )
  425. {
  426. TraceMsg(TF_TRSITE, "TRS::_OnComplete() called");
  427. if (_dwTransitionSink != 0)
  428. {
  429. EVAL(SUCCEEDED(ConnectToConnectionPoint(SAFECAST(this, IDispatch *),
  430. DIID_ICSSTransitionEvents,
  431. FALSE,
  432. _pTransition,
  433. &_dwTransitionSink,
  434. NULL)));
  435. _dwTransitionSink = 0;
  436. }
  437. if (_pvoNew != NULL)
  438. {
  439. _pvoNew->SetAdvise(DVASPECT_CONTENT, 0, 0);
  440. ATOMICRELEASE(_pvoNew);
  441. }
  442. ATOMICRELEASE(_pDispTransition);
  443. if (_pTransition != NULL)
  444. {
  445. _pTransition->SetSource(NULL);
  446. _pTransition->SetSite(NULL);
  447. ASSERT(_pSite == NULL);
  448. ATOMICRELEASE(_pTransition);
  449. }
  450. if (_hwndViewNew != NULL)
  451. {
  452. if (_fViewIsVisible)
  453. ::ShowWindow(_hwndViewNew, SW_SHOW);
  454. _pContainer->EnableModelessSB(TRUE);
  455. }
  456. ATOMICRELEASE(_psvNew);
  457. _hwndViewNew = NULL;
  458. return _UpdateEventList();
  459. }
  460. /////////////////////////////////////////////////////////////////////////////
  461. // IUnknown interface
  462. /////////////////////////////////////////////////////////////////////////////
  463. HRESULT CTransitionSite::QueryInterface(REFIID riid, void **ppvObj)
  464. {
  465. if (IsEqualIID(riid, IID_IUnknown) ||
  466. IsEqualIID(riid, IID_IHTMLViewFilter))
  467. {
  468. *ppvObj = SAFECAST(this, IHTMLViewFilter *);
  469. }
  470. else if (IsEqualIID(riid, IID_IHTMLViewFilterSite))
  471. {
  472. *ppvObj = SAFECAST(this, IHTMLViewFilterSite *);
  473. }
  474. else if (IsEqualIID(riid, DIID_ICSSTransitionEvents) ||
  475. IsEqualIID(riid, IID_IDispatch))
  476. {
  477. *ppvObj = SAFECAST(this, IDispatch *);
  478. }
  479. else if (IsEqualIID(riid, IID_IServiceProvider))
  480. {
  481. return _pContainer->QueryInterface(IID_IServiceProvider, ppvObj);
  482. }
  483. else
  484. {
  485. *ppvObj = NULL;
  486. return E_NOINTERFACE;
  487. }
  488. AddRef();
  489. return S_OK;
  490. }
  491. ULONG CTransitionSite::AddRef()
  492. {
  493. TraceMsg(TF_ADDREFRELEASE, "TRS::AddRef()");
  494. return _pContainer->AddRef();
  495. }
  496. ULONG CTransitionSite::Release()
  497. {
  498. TraceMsg(TF_ADDREFRELEASE, "TRS::Release()");
  499. return _pContainer->Release();
  500. }
  501. /////////////////////////////////////////////////////////////////////////////
  502. // IHTMLViewFilter interface
  503. /////////////////////////////////////////////////////////////////////////////
  504. HRESULT CTransitionSite::SetSource(IHTMLViewFilter * pFilter)
  505. {
  506. ASSERT(0);
  507. return E_FAIL;
  508. }
  509. HRESULT CTransitionSite::GetSource
  510. (
  511. IHTMLViewFilter ** ppFilter
  512. )
  513. {
  514. ASSERT(0);
  515. return E_FAIL;
  516. }
  517. HRESULT CTransitionSite::SetSite
  518. (
  519. IHTMLViewFilterSite * pFilterSite
  520. )
  521. {
  522. TraceMsg(TF_TRSITE, "TRS::SetSite called with %x", pFilterSite);
  523. ATOMICRELEASE(_pSite);
  524. _pSite = pFilterSite;
  525. if (pFilterSite != NULL)
  526. pFilterSite->AddRef();
  527. return S_OK;
  528. }
  529. /////////////////////////////////////////////////////////////////////////////
  530. // CTransitionSite::GetSite
  531. /////////////////////////////////////////////////////////////////////////////
  532. HRESULT CTransitionSite::GetSite
  533. (
  534. IHTMLViewFilterSite ** ppFilterSite
  535. )
  536. {
  537. TraceMsg(TF_TRSITE, "TRS::GetSite called _pSite=%x", _pSite);
  538. *ppFilterSite = _pSite;
  539. if (_pSite != NULL)
  540. {
  541. _pSite->AddRef();
  542. return S_OK;
  543. }
  544. return S_FALSE;
  545. }
  546. /////////////////////////////////////////////////////////////////////////////
  547. // CTransitionSite::SetPosition
  548. /////////////////////////////////////////////////////////////////////////////
  549. HRESULT CTransitionSite::SetPosition
  550. (
  551. LPCRECT prc
  552. )
  553. {
  554. return S_OK;
  555. }
  556. /////////////////////////////////////////////////////////////////////////////
  557. // CTransitionSite::Draw
  558. /////////////////////////////////////////////////////////////////////////////
  559. HRESULT CTransitionSite::Draw
  560. (
  561. HDC hDC,
  562. LPCRECT prc
  563. )
  564. {
  565. HRESULT hrResult;
  566. HWND hwndView = NULL; // init to suppress bogus C4701 warning
  567. TraceMsg(TF_TREXTDRAW,
  568. "TRS::Draw called with hdc=%x (%d,%d)-(%d,%d)",
  569. hDC, prc->left, prc->top, prc->right, prc->bottom);
  570. if ((_uState == TRSTATE_STARTPAINTING) || (_uState == TRSTATE_PAINTING))
  571. {
  572. ASSERT(_pvoNew != NULL);
  573. RECTL rcl = { prc->left, prc->top, prc->right, prc->bottom };
  574. if (FAILED(hrResult = _pvoNew->Draw(DVASPECT_CONTENT,
  575. -1,
  576. NULL,
  577. NULL,
  578. NULL,
  579. hDC,
  580. &rcl,
  581. NULL,
  582. NULL,
  583. 0)))
  584. {
  585. TraceMsg(TF_ERROR, "TRS::Draw IVO::Draw failed 0x%X", hrResult);
  586. hwndView = _hwndViewNew;
  587. }
  588. }
  589. else
  590. {
  591. IShellView * psv;
  592. hrResult = _pContainer->QueryActiveShellView(&psv);
  593. if (SUCCEEDED(hrResult))
  594. {
  595. hrResult = OleDraw(psv, DVASPECT_CONTENT, hDC, prc);
  596. psv->Release();
  597. }
  598. if (FAILED(hrResult))
  599. {
  600. IBrowserService2 *pbs;
  601. TraceMsg(TF_WARNING, "TRS:Draw OleDraw failed 0x%X", hrResult);
  602. if (SUCCEEDED(_pContainer->QueryInterface(IID_IBrowserService2, (void **)&pbs)))
  603. {
  604. pbs->GetViewWindow(&hwndView);
  605. pbs->Release();
  606. }
  607. }
  608. }
  609. // As a last resort, if IViewObject::Draw fails, try WM_PRINT
  610. if (FAILED(hrResult))
  611. {
  612. ASSERT((hwndView != NULL) && IsWindow(hwndView));
  613. // DrawEdge(..., EDGE_SUNKEN, BF_ADJUST|BF_RECT|BF_SOFT);
  614. ::SendMessage(hwndView, WM_PRINT, (WPARAM)hDC, PRF_NONCLIENT | PRF_CLIENT | PRF_CHILDREN | PRF_ERASEBKGND);
  615. hrResult = S_OK;
  616. }
  617. return hrResult;
  618. }
  619. /////////////////////////////////////////////////////////////////////////////
  620. // CTransitionSite::GetStatusBits
  621. /////////////////////////////////////////////////////////////////////////////
  622. HRESULT CTransitionSite::GetStatusBits
  623. (
  624. DWORD * pdwFlags
  625. )
  626. {
  627. *pdwFlags = FILTER_STATUS_OPAQUE;
  628. return S_OK;
  629. }
  630. /////////////////////////////////////////////////////////////////////////////
  631. // IHTMLViewFilterSite interface
  632. /////////////////////////////////////////////////////////////////////////////
  633. /////////////////////////////////////////////////////////////////////////////
  634. // CTransitionSite::GetDC
  635. /////////////////////////////////////////////////////////////////////////////
  636. HRESULT CTransitionSite::GetDC
  637. (
  638. LPCRECT prc,
  639. DWORD dwFlags,
  640. HDC * phDC
  641. )
  642. {
  643. HWND hwnd;
  644. _pContainer->GetWindow(&hwnd);
  645. *phDC = ::GetDC(hwnd);
  646. TraceMsg(TF_TRSITE, "TRS::GetDC returning *phDC=%x", *phDC);
  647. return ((*phDC != NULL) ? S_OK : E_FAIL);
  648. }
  649. /////////////////////////////////////////////////////////////////////////////
  650. // CTransitionSite::ReleaseDC
  651. /////////////////////////////////////////////////////////////////////////////
  652. HRESULT CTransitionSite::ReleaseDC
  653. (
  654. HDC hDC
  655. )
  656. {
  657. TraceMsg(TF_TRSITE, "TRS::ReleaseDC called with %x", hDC);
  658. HWND hwnd;
  659. _pContainer->GetWindow(&hwnd);
  660. ::ReleaseDC(hwnd, hDC);
  661. return S_OK;
  662. }
  663. /////////////////////////////////////////////////////////////////////////////
  664. // CTransitionSite::InvalidateRect
  665. /////////////////////////////////////////////////////////////////////////////
  666. HRESULT CTransitionSite::InvalidateRect
  667. (
  668. LPCRECT prc,
  669. BOOL fErase
  670. )
  671. {
  672. #ifdef DEBUG
  673. if (prc) {
  674. TraceMsg(TF_TREXTDRAW, "TRS::InvalidateRect called with (%x, %x)-(%x, %x) fErase=%d",
  675. prc->left, prc->top, prc->right, prc->bottom, fErase);
  676. } else {
  677. TraceMsg(TF_TREXTDRAW, "TRS::InvalidateRect called prc=NULL, fErase=%d", fErase);
  678. }
  679. #endif
  680. DWORD dwFlags = RDW_INVALIDATE | RDW_UPDATENOW;
  681. dwFlags |= (fErase ? RDW_ERASE : 0);
  682. HWND hwnd;
  683. _pContainer->GetWindow(&hwnd);
  684. ::RedrawWindow(hwnd, prc, NULL, dwFlags);
  685. return S_OK;
  686. }
  687. /////////////////////////////////////////////////////////////////////////////
  688. // CTransitionSite::InvalidateRgn
  689. /////////////////////////////////////////////////////////////////////////////
  690. HRESULT CTransitionSite::InvalidateRgn
  691. (
  692. HRGN hrgn,
  693. BOOL fErase
  694. )
  695. {
  696. TraceMsg(TF_TRSITE, "TRS::InvalidateRgn called");
  697. DWORD dwFlags = RDW_INVALIDATE | RDW_UPDATENOW;
  698. dwFlags |= (fErase ? RDW_ERASE : 0);
  699. HWND hwnd;
  700. _pContainer->GetWindow(&hwnd);
  701. ::RedrawWindow(hwnd, NULL, hrgn, dwFlags);
  702. return S_OK;
  703. }
  704. /////////////////////////////////////////////////////////////////////////////
  705. // CTransitionSite::OnStatusBitsChange
  706. /////////////////////////////////////////////////////////////////////////////
  707. HRESULT CTransitionSite::OnStatusBitsChange
  708. (
  709. DWORD dwFlags
  710. )
  711. {
  712. return S_OK;
  713. }
  714. /////////////////////////////////////////////////////////////////////////////
  715. // IAdviseSink interface
  716. /////////////////////////////////////////////////////////////////////////////
  717. /////////////////////////////////////////////////////////////////////////////
  718. // CTransitionSite::OnViewChange
  719. /////////////////////////////////////////////////////////////////////////////
  720. STDMETHODIMP_(void) CTransitionSite::OnViewChange(DWORD dwAspect, LONG lindex)
  721. {
  722. static DWORD dwLastUpdate = 0;
  723. if (
  724. ((GetTickCount() - dwLastUpdate) > MIN_ONVIEWCHANGE_DURATION)
  725. &&
  726. (_uState == TRSTATE_PAINTING)
  727. &&
  728. (dwAspect & DVASPECT_CONTENT)
  729. )
  730. {
  731. TraceMsg(TF_TRDRAW, "TRS::OnViewChange(%d)", lindex);
  732. _pSite->InvalidateRect(NULL, FALSE);
  733. }
  734. dwLastUpdate = GetTickCount();
  735. }
  736. /////////////////////////////////////////////////////////////////////////////
  737. // IDispatch interface
  738. /////////////////////////////////////////////////////////////////////////////
  739. /////////////////////////////////////////////////////////////////////////////
  740. // CTransitionSite::Invoke
  741. /////////////////////////////////////////////////////////////////////////////
  742. HRESULT CTransitionSite::Invoke
  743. (
  744. DISPID dispidMember,
  745. REFIID riid,
  746. LCID lcid,
  747. WORD wFlags,
  748. DISPPARAMS * pdispparams,
  749. VARIANT * pvarResult,
  750. EXCEPINFO * pexcepinfo,
  751. UINT * puArgErr
  752. )
  753. {
  754. ASSERT(pdispparams != NULL);
  755. if (pdispparams == NULL)
  756. return E_INVALIDARG;
  757. if (!(wFlags & DISPATCH_METHOD))
  758. return E_INVALIDARG;
  759. switch(dispidMember)
  760. {
  761. case DISPID_ONTRANSITIONFINISH:
  762. {
  763. _OnComplete();
  764. break;
  765. }
  766. default:
  767. return E_INVALIDARG;
  768. }
  769. return S_OK;
  770. }
  771. /////////////////////////////////////////////////////////////////////////////
  772. // CTransitionSitePropertyBag
  773. /////////////////////////////////////////////////////////////////////////////
  774. #undef CTransitionSite
  775. CTransitionSitePropertyBag::CTransitionSitePropertyBag
  776. (
  777. ) : _cRef(1)
  778. {
  779. TraceMsg(TF_TRLIFE, "TRSPropBag::ctor called");
  780. // Implicit: _hdpaProperties = NULL;
  781. }
  782. CTransitionSitePropertyBag::~CTransitionSitePropertyBag()
  783. {
  784. TraceMsg(TF_TRLIFE, "TRSPropBag::dtor called");
  785. if (_hdpaProperties != NULL)
  786. {
  787. DPA_DestroyCallback(_hdpaProperties, _DPA_FreeProperties, 0);
  788. _hdpaProperties = NULL;
  789. }
  790. }
  791. /////////////////////////////////////////////////////////////////////////////
  792. // _DPA_FreeProperties
  793. /////////////////////////////////////////////////////////////////////////////
  794. int CTransitionSitePropertyBag::_DPA_FreeProperties(void *pv, void *pData)
  795. {
  796. NAMEVALUE * pnv = (NAMEVALUE *)pv;
  797. ASSERT(pnv != NULL);
  798. ASSERT(pnv->pwszName != NULL);
  799. LocalFree(pnv->pwszName);
  800. pnv->pwszName = NULL;
  801. VariantClear(&pnv->varValue);
  802. LocalFree(pnv);
  803. pnv = NULL;
  804. return 1;
  805. }
  806. /////////////////////////////////////////////////////////////////////////////
  807. // _AddProperty
  808. /////////////////////////////////////////////////////////////////////////////
  809. HRESULT CTransitionSitePropertyBag::_AddProperty(WCHAR *wszPropName, VARIANT *pvarValue)
  810. {
  811. NAMEVALUE * pnv = NULL;
  812. HRESULT hrResult = E_FAIL;
  813. // Create the list if needed
  814. if (_hdpaProperties == NULL)
  815. _hdpaProperties = DPA_Create(TSPB_CREATE_INCR);
  816. for (;;)
  817. {
  818. if (_hdpaProperties == NULL)
  819. break;
  820. // Alloc a new name value pair
  821. pnv = (NAMEVALUE *)LocalAlloc(LPTR, SIZEOF(NAMEVALUE));
  822. if (pnv == NULL)
  823. {
  824. TraceMsg(TF_WARNING, "TRSPB Unable to alloc memory for property");
  825. break;
  826. }
  827. // Copy the name
  828. UINT cb = (lstrlenW(wszPropName)+1) * SIZEOF(wszPropName[0]);
  829. pnv->pwszName = (LPWSTR)LocalAlloc(LPTR, cb);
  830. if (pnv->pwszName == NULL)
  831. {
  832. TraceMsg(TF_WARNING, "TRSPB Unable to alloc memory for property");
  833. break;
  834. }
  835. StrCpyNW(pnv->pwszName, wszPropName, cb / sizeof(wszPropName[0]));
  836. // Copy the value
  837. if (FAILED(hrResult = VariantCopy(&pnv->varValue, pvarValue)))
  838. {
  839. TraceMsg(TF_WARNING, "TRSPB VariantCopy failed");
  840. break;
  841. }
  842. // Add the name value pair to the list
  843. if (DPA_AppendPtr(_hdpaProperties, pnv) == DPA_ERR)
  844. break;
  845. #ifdef DEBUG
  846. TCHAR szPropName[80];
  847. SHUnicodeToTChar(wszPropName, szPropName, SIZEOF(szPropName));
  848. VARIANT vVal = { 0 };
  849. TCHAR szPropVal[80];
  850. EVAL(SUCCEEDED(VariantChangeType(&vVal, pvarValue, 0, VT_BSTR)));
  851. SHUnicodeToTChar(V_BSTR(&vVal), szPropVal, SIZEOF(szPropVal));
  852. EVAL(SUCCEEDED(VariantClear(&vVal)));
  853. TraceMsg(TF_TRSPB, "TRSPB::_AddProperty added '%s = %s'", szPropName, szPropVal);
  854. #endif // DEBUG
  855. hrResult = S_OK;
  856. break;
  857. }
  858. // Cleanup on error
  859. if (FAILED(hrResult))
  860. {
  861. if (pnv != NULL)
  862. {
  863. if (pnv->pwszName != NULL)
  864. {
  865. LocalFree(pnv->pwszName);
  866. pnv->pwszName = NULL;
  867. }
  868. VariantClear(&pnv->varValue);
  869. LocalFree(pnv);
  870. pnv = NULL;
  871. }
  872. }
  873. return hrResult;
  874. }
  875. ULONG CTransitionSitePropertyBag::AddRef()
  876. {
  877. _cRef++;
  878. return _cRef;
  879. }
  880. ULONG CTransitionSitePropertyBag::Release()
  881. {
  882. ASSERT(_cRef > 0);
  883. _cRef--;
  884. if (_cRef > 0)
  885. return _cRef;
  886. delete this;
  887. return 0;
  888. }
  889. HRESULT CTransitionSitePropertyBag::QueryInterface(REFIID riid, void **ppvObj)
  890. {
  891. if (IsEqualIID(riid, IID_IUnknown) ||
  892. IsEqualIID(riid, IID_IPropertyBag))
  893. {
  894. *ppvObj = SAFECAST(this, IPropertyBag *);
  895. }
  896. else
  897. {
  898. *ppvObj = NULL;
  899. return E_NOINTERFACE;
  900. }
  901. AddRef();
  902. return S_OK;
  903. }
  904. /////////////////////////////////////////////////////////////////////////////
  905. // IPropertyBag interface
  906. /////////////////////////////////////////////////////////////////////////////
  907. /////////////////////////////////////////////////////////////////////////////
  908. // CTransitionSitePropertyBag::Read
  909. /////////////////////////////////////////////////////////////////////////////
  910. HRESULT CTransitionSitePropertyBag::Read
  911. (
  912. LPCOLESTR pszPropName,
  913. VARIANT * pVar,
  914. IErrorLog * pErrorLog
  915. )
  916. {
  917. HRESULT hrResult = E_INVALIDARG;
  918. if ((pszPropName == NULL) || (pVar == NULL))
  919. return E_POINTER;
  920. #ifdef DEBUG
  921. TCHAR szPropName[80];
  922. SHUnicodeToTChar(pszPropName, szPropName, SIZEOF(szPropName));
  923. TraceMsg(TF_TRSPB, "TRSPB::Read(%s)", szPropName);
  924. #endif // DEBUG
  925. if (_hdpaProperties != NULL)
  926. {
  927. // Search for the property in the list.
  928. for (int i = 0; i < DPA_GetPtrCount(_hdpaProperties); i++)
  929. {
  930. NAMEVALUE * pnv = (NAMEVALUE *)DPA_GetPtr(_hdpaProperties, i);
  931. if (StrCmpIW(pszPropName, pnv->pwszName) == 0)
  932. {
  933. // Copy the variant property.
  934. hrResult = VariantChangeType(pVar, &pnv->varValue, 0, pVar->vt);
  935. break;
  936. }
  937. }
  938. }
  939. return hrResult;
  940. }
  941. /////////////////////////////////////////////////////////////////////////////
  942. // Helper functions
  943. /////////////////////////////////////////////////////////////////////////////
  944. /////////////////////////////////////////////////////////////////////////////
  945. // CLSIDFromTransitionName
  946. /////////////////////////////////////////////////////////////////////////////
  947. HRESULT CLSIDFromTransitionName
  948. (
  949. LPCTSTR pszName,
  950. LPCLSID clsidName
  951. )
  952. {
  953. HKEY hkeyTransitions = NULL;
  954. HRESULT hrResult;
  955. for (;;)
  956. {
  957. // Check for "{...CLSID...}"
  958. if (*pszName == TEXT('{'))
  959. {
  960. hrResult = SHCLSIDFromString(pszName, clsidName);
  961. break;
  962. }
  963. // Check for Transition Name
  964. if (RegCreateKey( HKEY_LOCAL_MACHINE,
  965. c_szTransitionsKey,
  966. &hkeyTransitions) == ERROR_SUCCESS)
  967. {
  968. TCHAR szCLSID[GUIDSTR_MAX];
  969. DWORD cbBytes = SIZEOF(szCLSID);
  970. DWORD dwType;
  971. if (
  972. (RegQueryValueEx( hkeyTransitions,
  973. pszName,
  974. NULL,
  975. &dwType,
  976. (BYTE *)szCLSID,
  977. &cbBytes) == ERROR_SUCCESS)
  978. &&
  979. (dwType == REG_SZ)
  980. )
  981. {
  982. hrResult = SHCLSIDFromString(szCLSID, clsidName);
  983. break;
  984. }
  985. }
  986. hrResult = E_FAIL;
  987. break;
  988. }
  989. if (hkeyTransitions != NULL)
  990. RegCloseKey(hkeyTransitions);
  991. return hrResult;
  992. }
  993. /////////////////////////////////////////////////////////////////////////////
  994. // ParseTransitionInfo
  995. //
  996. // Purpose: Parse <META HTTP-EQUIV...> of the form:
  997. //
  998. // <META
  999. // HTTP-EQUIV = transition-event
  1000. // CONTENT = transition-description
  1001. // >
  1002. //
  1003. // where:
  1004. //
  1005. // transition-event -> PAGE-ENTER
  1006. // | PAGE-EXIT
  1007. // | SITE-ENTER
  1008. // | SITE-EXIT
  1009. //
  1010. // transition-description -> transition-name ( transition-properties )
  1011. //
  1012. // transition-name -> IDENTIFIER
  1013. // | CLSID
  1014. // | PROGID
  1015. //
  1016. // transition-properties -> transition-property , transition-property
  1017. // transition-properties -> transition-property
  1018. //
  1019. // name-value-assignment -> = | :
  1020. //
  1021. // transition-property -> NAME name-value-assignment VALUE
  1022. //
  1023. // examples:
  1024. //
  1025. // <META
  1026. // HTTP-EQUIV = "Page-Enter"
  1027. // CONTENT = "Reveal(duration=500)"
  1028. // >
  1029. //
  1030. // <META
  1031. // HTTP-EQUIV = "Page-Leave"
  1032. // CONTENT = "Reveal(duration=500, type=checkerboard, size=10)"
  1033. // >
  1034. //
  1035. /////////////////////////////////////////////////////////////////////////////
  1036. BOOL ParseTransitionInfo
  1037. (
  1038. WCHAR * pwz,
  1039. TRANSITIONINFO * pti
  1040. )
  1041. {
  1042. enum
  1043. {
  1044. PTE_PARSE_TRANSITION_NAME,
  1045. PTE_PARSE_NAME,
  1046. PTE_PARSE_VALUE,
  1047. PTE_FINISHED
  1048. };
  1049. #define MAX_TRANSITION_NAME_LEN GUIDSTR_MAX
  1050. WCHAR wszTransitionName[MAX_TRANSITION_NAME_LEN];
  1051. WCHAR * pwzTransitionName = wszTransitionName;
  1052. #define MAX_PTINAME_LEN 32
  1053. WCHAR wszName[MAX_PTINAME_LEN];
  1054. WCHAR * pwzName = wszName;
  1055. #define MAX_PTIVALUE_LEN 32
  1056. WCHAR wszValue[MAX_PTIVALUE_LEN];
  1057. WCHAR * pwzValue = wszValue;
  1058. WCHAR wch;
  1059. UINT cch = 0;
  1060. UINT uiState = PTE_PARSE_TRANSITION_NAME;
  1061. BOOL bSucceeded = FALSE;
  1062. ASSERT(pti != NULL);
  1063. do
  1064. {
  1065. wch = *pwz;
  1066. switch (uiState)
  1067. {
  1068. case PTE_PARSE_TRANSITION_NAME:
  1069. {
  1070. if (wch == TEXT('(')) // Open paren
  1071. {
  1072. cch = 0;
  1073. uiState = PTE_PARSE_NAME;
  1074. *pwzTransitionName = '\0';
  1075. pwzTransitionName = wszTransitionName;
  1076. TCHAR szTransitionName[MAX_TRANSITION_NAME_LEN];
  1077. SHUnicodeToTChar(wszTransitionName, szTransitionName, ARRAYSIZE(szTransitionName));
  1078. TraceMsg(DM_TRACE, "ParseTransitionInfo(%s)", szTransitionName);
  1079. // Resolve the Transition Name
  1080. EVAL(SUCCEEDED(CLSIDFromTransitionName(szTransitionName, &(pti->clsid))));
  1081. }
  1082. else if (
  1083. !ISSPACE(wch)
  1084. &&
  1085. (cch++ < (MAX_TRANSITION_NAME_LEN-1))
  1086. )
  1087. {
  1088. *pwzTransitionName++ = wch;
  1089. }
  1090. else
  1091. ; // Ignore
  1092. break;
  1093. }
  1094. case PTE_PARSE_NAME:
  1095. {
  1096. if (
  1097. (wch == TEXT('=')) // Equal
  1098. ||
  1099. (wch == TEXT(':')) // Semicolon
  1100. )
  1101. {
  1102. cch = 0;
  1103. uiState = PTE_PARSE_VALUE;
  1104. *pwzName = '\0';
  1105. pwzName = wszName;
  1106. }
  1107. else if (
  1108. !ISSPACE(wch)
  1109. &&
  1110. (cch++ < (MAX_PTINAME_LEN-1))
  1111. )
  1112. {
  1113. *pwzName++ = wch;
  1114. }
  1115. else
  1116. ; // Ignore
  1117. break;
  1118. }
  1119. case PTE_PARSE_VALUE:
  1120. {
  1121. if (
  1122. (wch == TEXT(',')) // Comma
  1123. ||
  1124. (wch == TEXT(')')) // Close paren
  1125. )
  1126. {
  1127. cch = 0;
  1128. if (wch == TEXT(','))
  1129. uiState = PTE_PARSE_NAME;
  1130. else
  1131. uiState = PTE_FINISHED;
  1132. *pwzValue = '\0';
  1133. pwzValue = wszValue;
  1134. // Initialize the property bag class
  1135. if (pti->pPropBag == NULL)
  1136. pti->pPropBag = new CTransitionSitePropertyBag;
  1137. if (pti->pPropBag)
  1138. {
  1139. VARIANT v;
  1140. if (SUCCEEDED(InitVariantFromStr(&v, wszValue)))
  1141. {
  1142. VARIANT vDuration = { 0 };
  1143. VARIANT* pvarToAdd = &v;
  1144. // Limit the duration of the transition.
  1145. if (StrCmpIW(wszName, c_szDurationProp) == 0)
  1146. {
  1147. if (SUCCEEDED(VariantChangeTypeEx(&vDuration, &v, MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT), 0, VT_R4)))
  1148. {
  1149. ASSERT(V_VT(&vDuration) == VT_R4);
  1150. if (V_R4(&vDuration) < MIN_TRANSITION_DURATION)
  1151. V_R4(&vDuration) = MIN_TRANSITION_DURATION;
  1152. else if (V_R4(&vDuration) > MAX_TRANSITION_DURATION)
  1153. V_R4(&vDuration) = MAX_TRANSITION_DURATION;
  1154. // don't need to VariantClear() vDuration since it's VT_R4 by the above ASSERT
  1155. pvarToAdd = &vDuration;
  1156. }
  1157. }
  1158. // Add the property to the property bag
  1159. pti->pPropBag->_AddProperty(wszName, pvarToAdd);
  1160. VariantClear(&v);
  1161. // vDuration is VT_EMPTY or VT_R4, neither of which nead VariantClear
  1162. }
  1163. }
  1164. }
  1165. else if (
  1166. !ISSPACE(wch)
  1167. &&
  1168. (cch++ < (MAX_PTIVALUE_LEN-1))
  1169. )
  1170. {
  1171. *pwzValue++ = wch;
  1172. }
  1173. else
  1174. ; // Ignore
  1175. break;
  1176. }
  1177. case PTE_FINISHED:
  1178. {
  1179. bSucceeded = TRUE;
  1180. break;
  1181. }
  1182. default:
  1183. break;
  1184. }
  1185. pwz++;
  1186. } while (wch && !bSucceeded);
  1187. return bSucceeded;
  1188. } // ParseTransitionInfo