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.

150 lines
4.5 KiB

  1. #include "privcpp.h"
  2. CPackage_IAdviseSink::CPackage_IAdviseSink(CPackage *pPackage) :
  3. _pPackage(pPackage)
  4. {
  5. ASSERT(_cRef == 0);
  6. }
  7. CPackage_IAdviseSink::~CPackage_IAdviseSink()
  8. {
  9. DebugMsg(DM_TRACE,"CPackage_IAdviseSink destroyed with ref count %d",_cRef);
  10. }
  11. //////////////////////////////////
  12. //
  13. // IUnknown Methods...
  14. //
  15. HRESULT CPackage_IAdviseSink::QueryInterface(REFIID iid, void ** ppv)
  16. {
  17. return _pPackage->QueryInterface(iid,ppv);
  18. }
  19. ULONG CPackage_IAdviseSink::AddRef(void)
  20. {
  21. _cRef++; // interface ref count for debugging
  22. return _pPackage->AddRef();
  23. }
  24. ULONG CPackage_IAdviseSink::Release(void)
  25. {
  26. _cRef--; // interface ref count for debugging
  27. return _pPackage->Release();
  28. }
  29. //////////////////////////////////
  30. //
  31. // IAdviseSink Methods...
  32. //
  33. void CPackage_IAdviseSink::OnDataChange(LPFORMATETC, LPSTGMEDIUM)
  34. {
  35. // NOTE: currently, we never set up a data advise connection with
  36. // anyone, but if we ever do, we'll want to set our dirty flag
  37. // when we get a datachange notificaiton.
  38. DebugMsg(DM_TRACE, "pack as - OnDataChange() called.");
  39. // when we get a data change notification, set our dirty flag
  40. _pPackage->_fIsDirty = TRUE;
  41. return;
  42. }
  43. void CPackage_IAdviseSink::OnViewChange(DWORD, LONG)
  44. {
  45. DebugMsg(DM_TRACE, "pack as - OnViewChange() called.");
  46. //
  47. // there's nothing to do here....we don't care about view changes.
  48. // we are always viewed as an icon and that can't be changed by the server
  49. // which is run when the contents are activated. the icon can
  50. // only be changed through the edit package verb
  51. //
  52. return;
  53. }
  54. void CPackage_IAdviseSink::OnRename(LPMONIKER)
  55. {
  56. DebugMsg(DM_TRACE, "pack as - OnRename() called.");
  57. //
  58. // once again, nothing to do here...if the user for some unknown reason
  59. // tries to save the packaged file by a different name when he's done
  60. // editing the contents then we'll just give not receive those changes.
  61. // why would anyone want to rename a temporary file, anyway?
  62. //
  63. return;
  64. }
  65. void CPackage_IAdviseSink::OnSave(void)
  66. {
  67. DebugMsg(DM_TRACE, "pack as - OnSave() called.");
  68. // if the contents have been saved, then our storage is out of date,
  69. // so set our dirty flag, then the container can choose to save us or not
  70. _pPackage->_fIsDirty = TRUE;
  71. // NOTE: even though Word sends us OnSave, it doesn't actually save
  72. // the file. Getting IPersistFile here and calling Save
  73. // fails with RPC_E_CANTCALLOUT_INASYNCCALL. W2K didn't pick
  74. // up Word's save either...
  75. // we just notifiy our own container that we've been saved and it
  76. // can do whatever it wants to.
  77. if (_pPackage->_pIOleAdviseHolder)
  78. _pPackage->_pIOleAdviseHolder->SendOnSave();
  79. }
  80. void CPackage_IAdviseSink::OnClose(void)
  81. {
  82. DebugMsg(DM_TRACE, "pack as - OnClose() called.");
  83. switch(_pPackage->_panetype)
  84. {
  85. case PEMBED:
  86. // get rid of advsiory connnection
  87. _pPackage->_pEmbed->poo->Unadvise(_pPackage->_dwCookie);
  88. _pPackage->_pEmbed->poo->Release();
  89. _pPackage->_pEmbed->poo = NULL;
  90. // this updates the size of the packaged file in our _pPackage->_pEmbed
  91. if (FAILED(_pPackage->EmbedInitFromFile(_pPackage->_pEmbed->pszTempName, FALSE)))
  92. {
  93. ShellMessageBox(g_hinst,
  94. NULL,
  95. MAKEINTRESOURCE(IDS_UPDATE_ERROR),
  96. MAKEINTRESOURCE(IDS_APP_TITLE),
  97. MB_TASKMODAL | MB_ICONERROR | MB_OK);
  98. }
  99. if (FAILED(_pPackage->_pIOleClientSite->SaveObject()))
  100. {
  101. ShellMessageBox(g_hinst,
  102. NULL,
  103. MAKEINTRESOURCE(IDS_UPDATE_ERROR),
  104. MAKEINTRESOURCE(IDS_APP_TITLE),
  105. MB_TASKMODAL | MB_ICONERROR | MB_OK);
  106. }
  107. if (_pPackage->_pIOleAdviseHolder)
  108. _pPackage->_pIOleAdviseHolder->SendOnSave();
  109. if (!_pPackage->_fNoIOleClientSiteCalls)
  110. _pPackage->_pIOleClientSite->OnShowWindow(FALSE);
  111. // we just notify out own container that we've been closed and let
  112. // it do whatever it wants to.
  113. if (_pPackage->_pIOleAdviseHolder)
  114. _pPackage->_pIOleAdviseHolder->SendOnClose();
  115. break;
  116. case CMDLINK:
  117. // there shouldn't be anything to do here, since a CMDLINK is always
  118. // executed using ShellExecute and never through OLE, so who would be
  119. // setting up an advisory connection with the package?
  120. break;
  121. }
  122. }