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.

127 lines
2.8 KiB

  1. #include "priv.h"
  2. #include "evtsink.h"
  3. #include "mshtml.h"
  4. #include "mshtmdid.h"
  5. #include "dispex.h"
  6. CDispatchEventSink::CDispatchEventSink() : m_cRef(1)
  7. {
  8. }
  9. CDispatchEventSink::~CDispatchEventSink()
  10. {
  11. }
  12. STDMETHODIMP CDispatchEventSink::QueryInterface(REFIID riid, void **ppv)
  13. {
  14. if (riid == IID_IUnknown || riid == IID_IDispatch) {
  15. *ppv = SAFECAST(this, IDispatch*);
  16. } else {
  17. *ppv = NULL;
  18. return E_NOINTERFACE;
  19. }
  20. AddRef();
  21. return S_OK;
  22. }
  23. STDMETHODIMP_(ULONG) CDispatchEventSink::AddRef(void)
  24. {
  25. m_cRef += 1;
  26. return m_cRef;
  27. }
  28. STDMETHODIMP_(ULONG) CDispatchEventSink::Release(void)
  29. {
  30. m_cRef -= 1;
  31. if (m_cRef != 0) {
  32. return m_cRef;
  33. }
  34. delete this;
  35. return 0;
  36. }
  37. STDMETHODIMP CDispatchEventSink::GetTypeInfoCount(UINT *pctInfo)
  38. {
  39. *pctInfo = 0;
  40. return NOERROR;
  41. }
  42. STDMETHODIMP CDispatchEventSink::GetTypeInfo(UINT iTInfo, LCID lcid,
  43. ITypeInfo **pptInfo)
  44. {
  45. *pptInfo = NULL;
  46. return E_NOTIMPL;
  47. }
  48. STDMETHODIMP CDispatchEventSink::GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames,
  49. UINT cNames, LCID lcid, DISPID *rgDispId)
  50. {
  51. if (riid != IID_NULL) {
  52. return DISP_E_UNKNOWNINTERFACE;
  53. }
  54. return DISP_E_UNKNOWNNAME;
  55. }
  56. /////////////////////////////////////////////////////////////////////////////
  57. // Window event sink helpers
  58. HRESULT ConnectHtmlEvents(IDispatch *pdispSink, CComPtr<IOleClientSite> &spClientSite, IDispatch **ppdispWindow,
  59. DWORD *pdwCookie)
  60. {
  61. HRESULT hr;
  62. CComPtr<IOleContainer> spContainer;
  63. CComPtr<IHTMLDocument2> spHTMLDoc;
  64. CComPtr<IHTMLWindow2> spWindow;
  65. *ppdispWindow = NULL;
  66. //
  67. // Get the browser window object
  68. //
  69. IfFailRet(spClientSite->GetContainer(&spContainer));
  70. IfFailRet(spContainer->QueryInterface(IID_IHTMLDocument2, (void **)&spHTMLDoc));
  71. IfFailRet(spHTMLDoc->get_parentWindow(&spWindow));
  72. IfFailRet(spWindow->QueryInterface(IID_IDispatch, (void **)ppdispWindow));
  73. //
  74. // Connect the event sink
  75. //
  76. if (FAILED(AtlAdvise(*ppdispWindow, pdispSink, IID_IDispatch,
  77. pdwCookie)))
  78. ATOMICRELEASE(*ppdispWindow);
  79. return S_OK;
  80. }
  81. HRESULT DisconnectHtmlEvents(IDispatch * pdispWindow, DWORD dwCookie)
  82. {
  83. HRESULT hr;
  84. //
  85. // Get the browser window object
  86. //
  87. if (pdispWindow == NULL) {
  88. return S_OK; // Nothing to cleanup
  89. }
  90. //
  91. // Disconnect the event sink
  92. //
  93. hr = AtlUnadvise(pdispWindow, IID_IDispatch, dwCookie);
  94. //
  95. // Release the HTML window dispatch
  96. //
  97. ATOMICRELEASE(pdispWindow);
  98. return hr;
  99. }