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.

160 lines
4.8 KiB

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