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.

295 lines
7.1 KiB

  1. //
  2. // sdo.cpp
  3. //
  4. #include "private.h"
  5. #include "sdo.h"
  6. #include "helpers.h"
  7. //////////////////////////////////////////////////////////////////////////////
  8. //
  9. // CDataObject
  10. //
  11. //////////////////////////////////////////////////////////////////////////////
  12. //+---------------------------------------------------------------------------
  13. //
  14. // IUnknown
  15. //
  16. //----------------------------------------------------------------------------
  17. STDAPI CDataObject::QueryInterface(REFIID riid, void **ppvObj)
  18. {
  19. *ppvObj = NULL;
  20. if (IsEqualIID(riid, IID_IUnknown) ||
  21. IsEqualIID(riid, IID_IDataObject))
  22. {
  23. *ppvObj = SAFECAST(this, IDataObject *);
  24. }
  25. if (*ppvObj)
  26. {
  27. AddRef();
  28. return S_OK;
  29. }
  30. return E_NOINTERFACE;
  31. }
  32. STDAPI_(ULONG) CDataObject::AddRef()
  33. {
  34. return ++_cRef;
  35. }
  36. STDAPI_(ULONG) CDataObject::Release()
  37. {
  38. long cr;
  39. cr = --_cRef;
  40. Assert(cr >= 0);
  41. if (cr == 0)
  42. {
  43. delete this;
  44. }
  45. return cr;
  46. }
  47. //+---------------------------------------------------------------------------
  48. //
  49. // ctor
  50. //
  51. //----------------------------------------------------------------------------
  52. CDataObject::CDataObject()
  53. {
  54. Dbg_MemSetThisName(TEXT("CDataObject"));
  55. memset(&_fe, 0, sizeof(_fe));
  56. memset(&_sm, 0, sizeof(_sm));
  57. _cRef = 1;
  58. }
  59. //+---------------------------------------------------------------------------
  60. //
  61. // dtor
  62. //
  63. //----------------------------------------------------------------------------
  64. CDataObject::~CDataObject()
  65. {
  66. ReleaseStgMedium(&_sm);
  67. }
  68. //+---------------------------------------------------------------------------
  69. //
  70. // GetData
  71. //
  72. //----------------------------------------------------------------------------
  73. STDAPI CDataObject::GetData(FORMATETC *pfe, STGMEDIUM *psm)
  74. {
  75. WCHAR *pch;
  76. ULONG cch;
  77. if (pfe == NULL || psm == NULL)
  78. return E_INVALIDARG;
  79. // verify the formatetc -- Issue: use QueryGetData
  80. if (pfe->cfFormat != _fe.cfFormat)
  81. return DV_E_FORMATETC;
  82. // Issue: ignoring ptd
  83. if (pfe->dwAspect != _fe.dwAspect)
  84. return DV_E_DVASPECT;
  85. if (pfe->lindex != _fe.lindex)
  86. return DV_E_LINDEX;
  87. if (!(pfe->tymed & _fe.lindex))
  88. return DV_E_TYMED;
  89. Assert(_fe.tymed == _sm.tymed);
  90. // allocate the medium
  91. if ((pfe->tymed & _fe.lindex) == TYMED_HGLOBAL)
  92. {
  93. switch (pfe->cfFormat)
  94. {
  95. case CF_UNICODETEXT:
  96. pch = (WCHAR *)GlobalLock(_sm.hGlobal);
  97. cch = wcslen(pch) + 1; // include the '\0'
  98. if ((psm->hGlobal = GlobalAlloc(GMEM_FIXED, cch*sizeof(WCHAR))) == NULL)
  99. {
  100. GlobalUnlock(_sm.hGlobal);
  101. return STG_E_MEDIUMFULL;
  102. }
  103. memcpy(psm->hGlobal, pch, cch*sizeof(WCHAR));
  104. GlobalUnlock(_sm.hGlobal);
  105. psm->tymed = TYMED_HGLOBAL;
  106. psm->pUnkForRelease = NULL; // caller must GlobalFree
  107. break;
  108. default:
  109. Assert(0); // shouldn't have let anyone SetData with something we can't handle
  110. break;
  111. }
  112. }
  113. else
  114. {
  115. Assert(0); // shouldn't have let anyone SetData with something we can't handle
  116. }
  117. return S_OK;
  118. }
  119. //+---------------------------------------------------------------------------
  120. //
  121. // GetDataHere
  122. //
  123. //----------------------------------------------------------------------------
  124. STDAPI CDataObject::GetDataHere(FORMATETC *pfe, STGMEDIUM *psm)
  125. {
  126. return E_NOTIMPL;
  127. }
  128. //+---------------------------------------------------------------------------
  129. //
  130. // QueryGetData
  131. //
  132. //----------------------------------------------------------------------------
  133. STDAPI CDataObject::QueryGetData(FORMATETC *pfe)
  134. {
  135. if (pfe == NULL)
  136. return E_INVALIDARG;
  137. // verify the formatetc
  138. if (pfe->cfFormat != _fe.cfFormat)
  139. return DV_E_FORMATETC;
  140. // Issue: ignoring ptd
  141. if (pfe->dwAspect != _fe.dwAspect)
  142. return DV_E_DVASPECT;
  143. if (pfe->lindex != _fe.lindex)
  144. return DV_E_LINDEX;
  145. if (!(pfe->tymed & _fe.lindex))
  146. return DV_E_TYMED;
  147. return S_OK;
  148. }
  149. //+---------------------------------------------------------------------------
  150. //
  151. // GetCanonicalFormatEtc
  152. //
  153. //----------------------------------------------------------------------------
  154. STDAPI CDataObject::GetCanonicalFormatEtc(FORMATETC *pfeIn, FORMATETC *pfeOut)
  155. {
  156. return E_NOTIMPL; // Issue: may not be legal to leave this unimpl
  157. }
  158. //+---------------------------------------------------------------------------
  159. //
  160. // SetData
  161. //
  162. //----------------------------------------------------------------------------
  163. STDAPI CDataObject::SetData(FORMATETC *pfe, STGMEDIUM *psm, BOOL fRelease)
  164. {
  165. Assert(fRelease == TRUE); // bogus, but for now we don't support copying
  166. if (pfe == NULL || psm == NULL)
  167. return E_INVALIDARG;
  168. if (pfe->tymed != psm->tymed)
  169. return E_INVALIDARG;
  170. // free up any storage
  171. ReleaseStgMedium(&_sm);
  172. // copy the new stuff
  173. _fe = *pfe;
  174. _sm = *psm;
  175. return S_OK;
  176. }
  177. //+---------------------------------------------------------------------------
  178. //
  179. // EnumFormatEtc
  180. //
  181. //----------------------------------------------------------------------------
  182. STDAPI CDataObject::EnumFormatEtc(DWORD dwDir, IEnumFORMATETC **ppefe)
  183. {
  184. return E_NOTIMPL;
  185. }
  186. //+---------------------------------------------------------------------------
  187. //
  188. // DAdvise
  189. //
  190. //----------------------------------------------------------------------------
  191. STDAPI CDataObject::DAdvise(FORMATETC *pfe, DWORD advf, IAdviseSink *pas, DWORD *pdwCookie)
  192. {
  193. return E_NOTIMPL;
  194. }
  195. //+---------------------------------------------------------------------------
  196. //
  197. // DUnadvise
  198. //
  199. //----------------------------------------------------------------------------
  200. STDAPI CDataObject::DUnadvise(DWORD dwCookie)
  201. {
  202. return E_NOTIMPL;
  203. }
  204. //+---------------------------------------------------------------------------
  205. //
  206. // EnumDAdvise
  207. //
  208. //----------------------------------------------------------------------------
  209. STDAPI CDataObject::EnumDAdvise(IEnumSTATDATA **ppesd)
  210. {
  211. return E_NOTIMPL;
  212. }
  213. //+---------------------------------------------------------------------------
  214. //
  215. // _SetData
  216. //
  217. //----------------------------------------------------------------------------
  218. HRESULT CDataObject::_SetData(const WCHAR *pch, ULONG cch)
  219. {
  220. FORMATETC fe;
  221. STGMEDIUM sm;
  222. fe.cfFormat = CF_UNICODETEXT;
  223. fe.ptd = NULL;
  224. fe.dwAspect = DVASPECT_CONTENT;
  225. fe.lindex = -1;
  226. fe.tymed = TYMED_HGLOBAL;
  227. sm.tymed = TYMED_HGLOBAL;
  228. sm.hGlobal = NULL;
  229. sm.pUnkForRelease = NULL;
  230. sm.hGlobal = GlobalAlloc(GMEM_FIXED, (cch+1)*sizeof(WCHAR));
  231. if (sm.hGlobal == NULL)
  232. return E_OUTOFMEMORY;
  233. memcpy(sm.hGlobal, pch, cch*sizeof(WCHAR));
  234. ((WCHAR *)sm.hGlobal)[cch] = '\0';
  235. return SetData(&fe, &sm, TRUE);
  236. }