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.4 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Behav_STATE.cpp
  5. Abstract:
  6. This file contains the implementation of the CPCHBehavior_STATE 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 WCHAR c_rgFMT[] = L"INTERNAL_%s###%s";
  15. ////////////////////////////////////////////////////////////////////////////////
  16. CPCHBehavior_STATE::CPCHBehavior_STATE()
  17. {
  18. __HCP_FUNC_ENTRY( "CPCHBehavior_STATE::CPCHBehavior_STATE" );
  19. m_lCookie_PERSISTLOAD = 0; // long m_lCookie_PERSISTLOAD;
  20. m_lCookie_PERSISTSAVE = 0; // long m_lCookie_PERSISTSAVE;
  21. // CComBSTR m_bstrIdentity;
  22. }
  23. /////////////////////////////////////////////////////////////////////////////
  24. STDMETHODIMP CPCHBehavior_STATE::Init( /*[in]*/ IElementBehaviorSite* pBehaviorSite )
  25. {
  26. __HCP_FUNC_ENTRY( "CPCHBehavior_STATE::Init" );
  27. HRESULT hr;
  28. CComPtr<IDispatch> pDisp;
  29. __MPC_EXIT_IF_METHOD_FAILS(hr, CPCHBehavior::Init( pBehaviorSite ));
  30. if(!m_fTrusted)
  31. {
  32. __MPC_SET_ERROR_AND_EXIT(hr, E_ACCESSDENIED);
  33. }
  34. //
  35. // Attach to all the events from CPCHEvents.
  36. //
  37. __MPC_EXIT_IF_METHOD_FAILS(hr, AttachToEvent( NULL, (CLASS_METHOD)onPersistLoad, NULL, &pDisp ));
  38. __MPC_EXIT_IF_METHOD_FAILS(hr, m_parent->Events().RegisterEvents( DISPID_PCH_E_PERSISTLOAD, MAXLONG, pDisp, &m_lCookie_PERSISTLOAD ));
  39. pDisp.Release();
  40. __MPC_EXIT_IF_METHOD_FAILS(hr, AttachToEvent( NULL, (CLASS_METHOD)onPersistSave, NULL, &pDisp ));
  41. __MPC_EXIT_IF_METHOD_FAILS(hr, m_parent->Events().RegisterEvents( DISPID_PCH_E_PERSISTSAVE, MINLONG, pDisp, &m_lCookie_PERSISTSAVE ));
  42. pDisp.Release();
  43. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::COMUtil::GetPropertyByName( m_elem, L"identity", m_bstrIdentity ));
  44. hr = S_OK;
  45. __HCP_FUNC_CLEANUP;
  46. __HCP_FUNC_EXIT(hr);
  47. }
  48. STDMETHODIMP CPCHBehavior_STATE::Notify( /*[in]*/ LONG lEvent, /*[in/out]*/ VARIANT* pVar )
  49. {
  50. if(lEvent == BEHAVIOREVENT_CONTENTREADY)
  51. {
  52. m_parent->HelpHost()->ChangeStatus( m_bstrIdentity, true );
  53. }
  54. return S_OK;
  55. }
  56. STDMETHODIMP CPCHBehavior_STATE::Detach()
  57. {
  58. m_parent->HelpHost()->ChangeStatus( m_bstrIdentity, false );
  59. if(m_lCookie_PERSISTLOAD) { (void)m_parent->Events().UnregisterEvents( m_lCookie_PERSISTLOAD ); m_lCookie_PERSISTLOAD = 0; }
  60. if(m_lCookie_PERSISTSAVE) { (void)m_parent->Events().UnregisterEvents( m_lCookie_PERSISTSAVE ); m_lCookie_PERSISTSAVE = 0; }
  61. return CPCHBehavior::Detach();
  62. }
  63. ////////////////////////////////////////////////////////////////////////////////
  64. HRESULT CPCHBehavior_STATE::onPersistLoad( DISPID id, DISPPARAMS* pdispparams, VARIANT* )
  65. {
  66. __HCP_FUNC_ENTRY( "CPCHBehavior_STATE::onPersistLoad" );
  67. HRESULT hr;
  68. VARIANT& v = pdispparams->rgvarg[0];
  69. if(v.vt == VT_DISPATCH)
  70. {
  71. CComQIPtr<IPCHEvent> evCurrent = v.pdispVal;
  72. }
  73. hr = S_OK;
  74. // __HCP_FUNC_CLEANUP;
  75. __HCP_FUNC_EXIT(hr);
  76. }
  77. HRESULT CPCHBehavior_STATE::onPersistSave( DISPID id, DISPPARAMS* pdispparams, VARIANT* )
  78. {
  79. __HCP_FUNC_ENTRY( "CPCHBehavior_STATE::onPersistLoad" );
  80. HRESULT hr;
  81. VARIANT& v = pdispparams->rgvarg[0];
  82. if(v.vt == VT_DISPATCH)
  83. {
  84. CComQIPtr<IPCHEvent> evCurrent = v.pdispVal;
  85. }
  86. hr = S_OK;
  87. // __HCP_FUNC_CLEANUP;
  88. __HCP_FUNC_EXIT(hr);
  89. }
  90. ////////////////////////////////////////////////////////////////////////////////
  91. STDMETHODIMP CPCHBehavior_STATE::get_stateProperty( /*[in]*/ BSTR bstrName, /*[out, retval]*/ VARIANT *pVal )
  92. {
  93. WCHAR rgName[512];
  94. _snwprintf( rgName, MAXSTRLEN(rgName), c_rgFMT, SAFEBSTR( m_bstrIdentity ), SAFEBSTR( bstrName ) );
  95. return m_parent->HelpSession()->Current()->get_Property( rgName, pVal );
  96. }
  97. STDMETHODIMP CPCHBehavior_STATE::put_stateProperty( /*[in]*/ BSTR bstrName, /*[in]*/ VARIANT newVal )
  98. {
  99. WCHAR rgName[512];
  100. _snwprintf( rgName, MAXSTRLEN(rgName), c_rgFMT, SAFEBSTR( m_bstrIdentity ), SAFEBSTR( bstrName ) );
  101. return m_parent->HelpSession()->Current()->put_Property( rgName, newVal );
  102. }