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.

251 lines
6.8 KiB

  1. #include "privcpp.h"
  2. CPackage_IDataObject::CPackage_IDataObject(CPackage *pPackage) :
  3. _pPackage(pPackage)
  4. {
  5. ASSERT(_cRef == 0);
  6. }
  7. CPackage_IDataObject::~CPackage_IDataObject()
  8. {
  9. DebugMsg(DM_TRACE,"CPackage_IDataObject destroyed with ref count %d",_cRef);
  10. }
  11. //////////////////////////////////
  12. //
  13. // IUnknown Methods...
  14. //
  15. HRESULT CPackage_IDataObject::QueryInterface(REFIID iid, void ** ppv)
  16. {
  17. return _pPackage->QueryInterface(iid,ppv);
  18. }
  19. ULONG CPackage_IDataObject::AddRef(void)
  20. {
  21. _cRef++; // interface ref count for debugging
  22. return _pPackage->AddRef();
  23. }
  24. ULONG CPackage_IDataObject::Release(void)
  25. {
  26. _cRef--; // interface ref count for debugging
  27. return _pPackage->Release();
  28. }
  29. //////////////////////////////////
  30. //
  31. // IDataObject Methods...
  32. //
  33. HRESULT CPackage_IDataObject::GetData(LPFORMATETC pFEIn, LPSTGMEDIUM pSTM)
  34. {
  35. UINT cf = pFEIn->cfFormat;
  36. DebugMsg(DM_TRACE, "pack do - GetData() called.");
  37. // Check the aspects we support
  38. if (!(pFEIn->dwAspect & DVASPECT_CONTENT)) {
  39. DebugMsg(DM_TRACE, " Invalid Aspect! dwAspect=%d",pFEIn->dwAspect);
  40. return DATA_E_FORMATETC;
  41. }
  42. // we set this to NULL so we aren't responsible for freeing memory
  43. pSTM->pUnkForRelease = NULL;
  44. // Go render the appropriate data for the format.
  45. if (cf == CF_FILEDESCRIPTOR)
  46. return _pPackage->GetFileDescriptor(pFEIn,pSTM);
  47. else if (cf == CF_FILECONTENTS)
  48. return _pPackage->GetFileContents(pFEIn,pSTM);
  49. else if (cf == CF_METAFILEPICT)
  50. return _pPackage->GetMetafilePict(pFEIn,pSTM);
  51. else if (cf == CF_ENHMETAFILE)
  52. return _pPackage->GetEnhMetafile(pFEIn,pSTM);
  53. else if (cf == CF_OBJECTDESCRIPTOR)
  54. return _pPackage->GetObjectDescriptor(pFEIn,pSTM);
  55. #ifdef DEBUG
  56. else {
  57. TCHAR szFormat[80];
  58. GetClipboardFormatName(cf, szFormat, ARRAYSIZE(szFormat));
  59. DebugMsg(DM_TRACE," unknown format: %s",szFormat);
  60. return DATA_E_FORMATETC;
  61. }
  62. #endif
  63. return DATA_E_FORMATETC;
  64. }
  65. HRESULT CPackage_IDataObject::GetDataHere(LPFORMATETC pFE, LPSTGMEDIUM pSTM)
  66. {
  67. DebugMsg(DM_TRACE, "pack do - GetDataHere() called.");
  68. HRESULT hr;
  69. // The only reasonable time this is called is for CFSTR_EMEDSOURCE and
  70. // TYMED_ISTORAGE. This means the same as IPersistStorage::Save
  71. // Aspect is unimportant to us here, as is lindex and ptd.
  72. if (pFE->cfFormat == CF_EMBEDSOURCE && (pFE->tymed & TYMED_ISTORAGE)) {
  73. // we have an IStorage we can write into.
  74. pSTM->tymed = TYMED_ISTORAGE;
  75. pSTM->pUnkForRelease = NULL;
  76. hr = _pPackage->_pIPersistStorage->Save(pSTM->pstg, FALSE);
  77. _pPackage->_pIPersistStorage->SaveCompleted(NULL);
  78. return hr;
  79. }
  80. return DATA_E_FORMATETC;
  81. }
  82. HRESULT CPackage_IDataObject::QueryGetData(LPFORMATETC pFE)
  83. {
  84. UINT cf = pFE->cfFormat;
  85. BOOL fRet = FALSE;
  86. DebugMsg(DM_TRACE, "pack do - QueryGetData() called.");
  87. if (!(pFE->dwAspect & DVASPECT_CONTENT))
  88. return S_FALSE;
  89. if (cf == CF_FILEDESCRIPTOR) {
  90. DebugMsg(DM_TRACE," Getting File Descriptor");
  91. fRet = (BOOL)(pFE->tymed & TYMED_HGLOBAL);
  92. }
  93. else if (cf == CF_FILECONTENTS) {
  94. DebugMsg(DM_TRACE," Getting File Contents");
  95. fRet = (BOOL)(pFE->tymed & (TYMED_HGLOBAL|TYMED_ISTREAM));
  96. }
  97. else if (cf == CF_EMBEDSOURCE) {
  98. DebugMsg(DM_TRACE," Getting Embed Source");
  99. fRet = (BOOL)(pFE->tymed & TYMED_ISTORAGE);
  100. }
  101. else if (cf == CF_OBJECTDESCRIPTOR) {
  102. DebugMsg(DM_TRACE," Getting Object Descriptor");
  103. fRet = (BOOL)(pFE->tymed & TYMED_HGLOBAL);
  104. }
  105. else if (cf == CF_METAFILEPICT) {
  106. DebugMsg(DM_TRACE," Getting MetafilePict");
  107. fRet = (BOOL)(pFE->tymed & TYMED_MFPICT);
  108. }
  109. else if (cf == CF_ENHMETAFILE) {
  110. DebugMsg(DM_TRACE," Getting EnhancedMetafile");
  111. fRet = (BOOL)(pFE->tymed & TYMED_ENHMF);
  112. }
  113. #ifdef DEBUG
  114. else {
  115. TCHAR szFormat[255];
  116. GetClipboardFormatName(cf, szFormat, ARRAYSIZE(szFormat));
  117. DebugMsg(DM_TRACE," unknown format: %s",szFormat);
  118. fRet = FALSE;
  119. }
  120. #endif
  121. DebugMsg(DM_TRACE, " fRet == %s",fRet ? TEXT("TRUE") : TEXT("FALSE"));
  122. return fRet ? S_OK : S_FALSE;
  123. }
  124. HRESULT CPackage_IDataObject::GetCanonicalFormatEtc(LPFORMATETC pFEIn,
  125. LPFORMATETC pFEOut)
  126. {
  127. DebugMsg(DM_TRACE, "pack do - GetCanonicalFormatEtc() called.");
  128. if (!pFEOut)
  129. return E_INVALIDARG;
  130. pFEOut->ptd = NULL;
  131. return DATA_S_SAMEFORMATETC;
  132. }
  133. HRESULT CPackage_IDataObject::SetData(LPFORMATETC pFE, LPSTGMEDIUM pSTM,
  134. BOOL fRelease)
  135. {
  136. HRESULT hr;
  137. DebugMsg(DM_TRACE, "pack do - SetData() called.");
  138. if ((pFE->cfFormat == CF_FILENAMEW) && (pFE->tymed & (TYMED_HGLOBAL|TYMED_FILE)))
  139. {
  140. LPWSTR pwsz = pSTM->tymed == TYMED_HGLOBAL ? (LPWSTR)pSTM->hGlobal : pSTM->lpszFileName;
  141. #ifdef UNICODE
  142. hr = _pPackage->CmlInitFromFile(pwsz, TRUE, CMDLINK);
  143. #else
  144. CHAR szPath[MAX_PATH];
  145. WideCharToMultiByte(CP_ACP, 0, pwsz, -1, szPath, ARRAYSIZE(szPath), NULL, NULL);
  146. hr = _pPackage->CmlInitFromFile(szPath, TRUE, CMDLINK);
  147. #endif // UNICODE
  148. _pPackage->_pCml->fCmdIsLink = TRUE;
  149. }
  150. return DATA_E_FORMATETC;
  151. }
  152. HRESULT CPackage_IDataObject::EnumFormatEtc(DWORD dwDirection,
  153. LPENUMFORMATETC *ppEnum)
  154. {
  155. DebugMsg(DM_TRACE, "pack do - EnumFormatEtc() called.");
  156. // NOTE: This means that we'll have to put the appropriate entries in
  157. // the registry for this to work.
  158. //
  159. return OleRegEnumFormatEtc(CLSID_CPackage, dwDirection, ppEnum);
  160. }
  161. HRESULT CPackage_IDataObject::DAdvise(LPFORMATETC pFE, DWORD grfAdv,
  162. LPADVISESINK pAdvSink, LPDWORD pdwConnection)
  163. {
  164. HRESULT hr;
  165. DebugMsg(DM_TRACE, "pack do - DAdvise() called.");
  166. if (_pPackage->_pIDataAdviseHolder == NULL) {
  167. hr = CreateDataAdviseHolder(&_pPackage->_pIDataAdviseHolder);
  168. if (FAILED(hr))
  169. return E_OUTOFMEMORY;
  170. }
  171. return _pPackage->_pIDataAdviseHolder->Advise(this, pFE, grfAdv, pAdvSink,
  172. pdwConnection);
  173. }
  174. HRESULT CPackage_IDataObject::DUnadvise(DWORD dwConnection)
  175. {
  176. DebugMsg(DM_TRACE, "pack do - DUnadvise() called.");
  177. if (_pPackage->_pIDataAdviseHolder == NULL)
  178. return E_UNEXPECTED;
  179. return _pPackage->_pIDataAdviseHolder->Unadvise(dwConnection);
  180. }
  181. HRESULT CPackage_IDataObject::EnumDAdvise(LPENUMSTATDATA *ppEnum)
  182. {
  183. DebugMsg(DM_TRACE, "pack do - EnumAdvise() called.");
  184. if (_pPackage->_pIDataAdviseHolder == NULL)
  185. return E_UNEXPECTED;
  186. return _pPackage->_pIDataAdviseHolder->EnumAdvise(ppEnum);
  187. }