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.

222 lines
6.3 KiB

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