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.

261 lines
5.3 KiB

  1. #include "dataobj.h"
  2. #include <stdlib.h>
  3. CImpIDataObject::CImpIDataObject(
  4. PCDataObject pObj,
  5. LPUNKNOWN pUnkOuter
  6. )
  7. {
  8. m_cRef = 0;
  9. m_pObj = pObj;
  10. m_pUnkOuter = pUnkOuter;
  11. return;
  12. }
  13. CImpIDataObject::~CImpIDataObject(void)
  14. {
  15. return;
  16. }
  17. STDMETHODIMP
  18. CImpIDataObject::QueryInterface(
  19. REFIID riid,
  20. LPLPVOID ppv
  21. )
  22. {
  23. return m_pUnkOuter->QueryInterface(riid, ppv);
  24. }
  25. STDMETHODIMP_(ULONG)
  26. CImpIDataObject::AddRef(void)
  27. {
  28. ++m_cRef;
  29. return m_pUnkOuter->AddRef();
  30. }
  31. STDMETHODIMP_(ULONG)
  32. CImpIDataObject::Release(void)
  33. {
  34. --m_cRef;
  35. return m_pUnkOuter->Release();
  36. }
  37. STDMETHODIMP
  38. CImpIDataObject::GetData(
  39. LPFORMATETC pFE,
  40. LPSTGMEDIUM pSTM
  41. )
  42. {
  43. UINT cf = pFE->cfFormat;
  44. if (!(DVASPECT_CONTENT & pFE->dwAspect))
  45. return ResultFromScode(DATA_E_FORMATETC);
  46. switch (cf)
  47. {
  48. case CF_TEXT:
  49. if (!(TYMED_HGLOBAL & pFE->tymed))
  50. break;
  51. return m_pObj->RenderText(pSTM, TEXT("Getdata"),
  52. FL_MAKE_ITEM | FL_PASS_PUNK);
  53. default:
  54. break;
  55. }
  56. return ResultFromScode(DATA_E_FORMATETC);
  57. }
  58. STDMETHODIMP
  59. CImpIDataObject::GetDataHere(
  60. LPFORMATETC pFE,
  61. LPSTGMEDIUM pSTM
  62. )
  63. {
  64. UINT cf = pFE->cfFormat;
  65. if (!(DVASPECT_CONTENT & pFE->dwAspect))
  66. return ResultFromScode(DATA_E_FORMATETC);
  67. switch (cf)
  68. {
  69. case CF_TEXT:
  70. if (!(TYMED_HGLOBAL & pFE->tymed))
  71. break;
  72. if(TYMED_NULL == pSTM->tymed)
  73. return ResultFromScode(S_OK);
  74. if(TYMED_HGLOBAL != pSTM->tymed)
  75. return ResultFromScode(E_INVALIDARG);
  76. return m_pObj->RenderText(pSTM, TEXT("GetDataHere"), FL_USE_ITEM);
  77. default:
  78. return ResultFromScode( DATA_E_FORMATETC );
  79. }
  80. return ResultFromScode(E_NOTIMPL);
  81. }
  82. STDMETHODIMP
  83. CImpIDataObject::QueryGetData(
  84. LPFORMATETC pFE
  85. )
  86. {
  87. UINT cf = pFE->cfFormat;
  88. BOOL fRet = FALSE;
  89. if (!(DVASPECT_CONTENT & pFE->dwAspect))
  90. return ResultFromScode(DATA_E_FORMATETC);
  91. switch (cf)
  92. {
  93. case CF_TEXT:
  94. fRet = (BOOL) (pFE->tymed & TYMED_HGLOBAL);
  95. break;
  96. default:
  97. fRet = FALSE;
  98. break;
  99. }
  100. return fRet ? NOERROR : ResultFromScode(S_FALSE);
  101. }
  102. STDMETHODIMP
  103. CImpIDataObject::GetCanonicalFormatEtc(
  104. LPFORMATETC pFEIn,
  105. LPFORMATETC pFEOut
  106. )
  107. {
  108. if (NULL==pFEOut)
  109. return ResultFromScode(E_INVALIDARG);
  110. pFEOut->ptd = NULL;
  111. return ResultFromScode(DATA_S_SAMEFORMATETC);
  112. }
  113. STDMETHODIMP
  114. CImpIDataObject::SetData(
  115. LPFORMATETC pFE,
  116. STGMEDIUM FAR *pST,
  117. BOOL fRelease
  118. )
  119. {
  120. UINT cf = pFE->cfFormat;
  121. int iArg;
  122. if (!(DVASPECT_CONTENT & pFE->dwAspect))
  123. return ResultFromScode(DATA_E_FORMATETC);
  124. switch (cf)
  125. {
  126. case CF_TEXT:
  127. if (!(TYMED_HGLOBAL & pFE->tymed))
  128. break;
  129. if(TYMED_HGLOBAL != pST->tymed)
  130. return ResultFromScode(E_INVALIDARG);
  131. LPTSTR psz=(LPTSTR)GlobalLock(pST->hGlobal); // Lock
  132. iArg = *((long*)psz); // Use
  133. GlobalUnlock(pST->hGlobal); // Unlock
  134. if(iArg > 0)
  135. {
  136. m_pObj->m_cDataSize = iArg;
  137. return NOERROR;
  138. }
  139. }
  140. if(-1 == iArg && fRelease)
  141. {
  142. ReleaseStgMedium(pST);
  143. return NOERROR;
  144. }
  145. return ResultFromScode(E_NOTIMPL);
  146. }
  147. STDMETHODIMP
  148. CImpIDataObject::EnumFormatEtc(
  149. DWORD dwDir,
  150. LPENUMFORMATETC FAR *ppEnum
  151. )
  152. {
  153. switch (dwDir)
  154. {
  155. case DATADIR_GET:
  156. *ppEnum = (LPENUMFORMATETC) new CEnumFormatEtc(
  157. m_pUnkOuter,
  158. m_pObj->m_cfeGet,
  159. m_pObj->m_rgfeGet );
  160. break;
  161. case DATADIR_SET:
  162. *ppEnum = NULL;
  163. break;
  164. default:
  165. *ppEnum = NULL;
  166. break;
  167. }
  168. if (NULL == *ppEnum)
  169. return ResultFromScode(E_FAIL);
  170. else
  171. (*ppEnum)->AddRef();
  172. return NOERROR;
  173. }
  174. STDMETHODIMP
  175. CImpIDataObject::DAdvise(
  176. LPFORMATETC pFE,
  177. DWORD dwFlags,
  178. LPADVISESINK pIAdviseSink,
  179. LPDWORD pdwConn
  180. )
  181. {
  182. HRESULT hr;
  183. if (NULL == m_pObj->m_pIDataAdviseHolder)
  184. {
  185. hr = CreateDataAdviseHolder(&m_pObj->m_pIDataAdviseHolder);
  186. if(FAILED(hr))
  187. return ResultFromScode(E_OUTOFMEMORY);
  188. }
  189. hr = m_pObj->m_pIDataAdviseHolder->Advise(
  190. (LPDATAOBJECT)this,
  191. pFE,
  192. dwFlags,
  193. pIAdviseSink,
  194. pdwConn );
  195. return hr;
  196. }
  197. STDMETHODIMP
  198. CImpIDataObject::DUnadvise(
  199. DWORD dwConn
  200. )
  201. {
  202. HRESULT hr;
  203. if (NULL==m_pObj->m_pIDataAdviseHolder)
  204. return ResultFromScode(E_FAIL);
  205. hr = m_pObj->m_pIDataAdviseHolder->Unadvise(dwConn);
  206. return hr;
  207. }
  208. STDMETHODIMP
  209. CImpIDataObject::EnumDAdvise(
  210. LPENUMSTATDATA FAR *ppEnum
  211. )
  212. {
  213. HRESULT hr;
  214. if (NULL==m_pObj->m_pIDataAdviseHolder)
  215. return ResultFromScode(E_FAIL);
  216. hr = m_pObj->m_pIDataAdviseHolder->EnumAdvise(ppEnum);
  217. return hr;
  218. }
  219.