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.

157 lines
4.6 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Behav_EVENT.cpp
  5. Abstract:
  6. This file contains the implementation of the CPCHBehavior_EVENT class,
  7. that dictates how hyperlinks work in the help center.
  8. Revision History:
  9. Davide Massarenti (dmassare) 06/06/2000
  10. created
  11. ******************************************************************************/
  12. #include "stdafx.h"
  13. ////////////////////////////////////////////////////////////////////////////////
  14. static const int c_NumOfEvents = DISPID_PCH_E_LASTEVENT - DISPID_PCH_E_FIRSTEVENT;
  15. ////////////////////////////////////////////////////////////////////////////////
  16. CPCHBehavior_EVENT::CPCHBehavior_EVENT()
  17. {
  18. __HCP_FUNC_ENTRY( "CPCHBehavior_EVENT::CPCHBehavior_EVENT" );
  19. m_lCookieIN = 0; // long m_lCookieIN;
  20. m_lCookieOUT = NULL; // LONG* m_lCookieOUT;
  21. //
  22. // CComQIPtr<IPCHEvent> m_evCurrent;
  23. }
  24. CPCHBehavior_EVENT::~CPCHBehavior_EVENT()
  25. {
  26. Detach();
  27. }
  28. /////////////////////////////////////////////////////////////////////////////
  29. STDMETHODIMP CPCHBehavior_EVENT::Init( /*[in]*/ IElementBehaviorSite* pBehaviorSite )
  30. {
  31. __HCP_FUNC_ENTRY( "CPCHBehavior_EVENT::Init" );
  32. HRESULT hr;
  33. CComVariant vPriority;
  34. long lPriority = 0;
  35. __MPC_EXIT_IF_METHOD_FAILS(hr, CPCHBehavior::Init( pBehaviorSite ));
  36. __MPC_EXIT_IF_ALLOC_FAILS(hr, m_lCookieOUT, new LONG[c_NumOfEvents]);
  37. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::COMUtil::GetPropertyByName( m_elem, L"priority", vPriority ));
  38. if(SUCCEEDED(vPriority.ChangeType( VT_I4 )))
  39. {
  40. lPriority = vPriority.lVal;
  41. }
  42. if(m_fTrusted)
  43. {
  44. CComPtr<IDispatch> pDisp;
  45. //
  46. // Attach to all the events from CPCHEvents.
  47. //
  48. __MPC_EXIT_IF_METHOD_FAILS(hr, AttachToEvent( NULL, (CLASS_METHOD)onFire, NULL, &pDisp ));
  49. __MPC_EXIT_IF_METHOD_FAILS(hr, m_parent->Events().RegisterEvents( -1, lPriority, pDisp, &m_lCookieIN ));
  50. //
  51. // Register all the custom events.
  52. //
  53. for(int i=0; i<c_NumOfEvents; i++)
  54. {
  55. __MPC_EXIT_IF_METHOD_FAILS(hr, CreateEvent( CComBSTR( CPCHEvents::ReverseLookup( i + DISPID_PCH_E_FIRSTEVENT ) ), m_lCookieOUT[i] ));
  56. }
  57. }
  58. hr = S_OK;
  59. __HCP_FUNC_CLEANUP;
  60. __HCP_FUNC_EXIT(hr);
  61. }
  62. STDMETHODIMP CPCHBehavior_EVENT::Detach()
  63. {
  64. if(m_lCookieIN)
  65. {
  66. (void)m_parent->Events().UnregisterEvents( m_lCookieIN );
  67. m_lCookieIN = 0;
  68. }
  69. if(m_lCookieOUT)
  70. {
  71. delete [] m_lCookieOUT;
  72. m_lCookieOUT = NULL;
  73. }
  74. return CPCHBehavior::Detach();
  75. }
  76. ////////////////////////////////////////////////////////////////////////////////
  77. STDMETHODIMP CPCHBehavior_EVENT::get_data ( /*[out, retval]*/ VARIANT *pVal ) { return GetAsVARIANT ( m_evCurrent, pVal ); }
  78. STDMETHODIMP CPCHBehavior_EVENT::get_element( /*[out, retval]*/ IDispatch* *pVal ) { return GetAsIDISPATCH( NULL , pVal ); }
  79. STDMETHODIMP CPCHBehavior_EVENT::Load ( /*[in ]*/ BSTR newVal ) { return S_FALSE; }
  80. STDMETHODIMP CPCHBehavior_EVENT::Save ( /*[out, retval]*/ BSTR *pVal ) { if(pVal) *pVal = NULL; return S_FALSE; }
  81. STDMETHODIMP CPCHBehavior_EVENT::Locate ( /*[in]*/ BSTR bstrKey, /*[out, retval]*/ VARIANT *pVal ) { return S_FALSE; }
  82. STDMETHODIMP CPCHBehavior_EVENT::Unselect( ) { return S_FALSE; }
  83. ////////////////////////////////////////////////////////////////////////////////
  84. HRESULT CPCHBehavior_EVENT::onFire( DISPID id, DISPPARAMS* pdispparams, VARIANT* )
  85. {
  86. __HCP_FUNC_ENTRY( "CPCHBehavior_EVENT::onFire" );
  87. AddRef(); // Protect against early deletion during event firing...
  88. HRESULT hr;
  89. VARIANT& v = pdispparams->rgvarg[0];
  90. CComPtr<IPCHEvent> evPrevious = m_evCurrent;
  91. if(v.vt == VT_DISPATCH)
  92. {
  93. m_evCurrent = v.pdispVal;
  94. }
  95. for(int i=0; i<c_NumOfEvents; i++)
  96. {
  97. if((i + DISPID_PCH_E_FIRSTEVENT) == id)
  98. {
  99. __MPC_EXIT_IF_METHOD_FAILS(hr, FireEvent( m_lCookieOUT[i] ));
  100. break;
  101. }
  102. }
  103. hr = S_OK;
  104. __HCP_FUNC_CLEANUP;
  105. m_evCurrent = evPrevious;
  106. Release(); // Revert protection against early deletion during event firing...
  107. __HCP_FUNC_EXIT(hr);
  108. }