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.

298 lines
7.2 KiB

  1. //
  2. // sdo.cpp
  3. //
  4. #include "private.h"
  5. #include "tsdo.h"
  6. #include "helpers.h"
  7. //////////////////////////////////////////////////////////////////////////////
  8. //
  9. // CTFDataObject
  10. //
  11. //////////////////////////////////////////////////////////////////////////////
  12. //+---------------------------------------------------------------------------
  13. //
  14. // IUnknown
  15. //
  16. //----------------------------------------------------------------------------
  17. STDAPI CTFDataObject::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) CTFDataObject::AddRef()
  33. {
  34. return ++_cRef;
  35. }
  36. STDAPI_(ULONG) CTFDataObject::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. CTFDataObject::CTFDataObject()
  53. {
  54. Dbg_MemSetThisName(TEXT("CTFDataObject"));
  55. memset(&_fe, 0, sizeof(_fe));
  56. memset(&_sm, 0, sizeof(_sm));
  57. _cRef = 1;
  58. }
  59. //+---------------------------------------------------------------------------
  60. //
  61. // dtor
  62. //
  63. //----------------------------------------------------------------------------
  64. CTFDataObject::~CTFDataObject()
  65. {
  66. ReleaseStgMedium(&_sm);
  67. }
  68. //+---------------------------------------------------------------------------
  69. //
  70. // GetData
  71. //
  72. //----------------------------------------------------------------------------
  73. STDAPI CTFDataObject::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. if (pch)
  98. {
  99. cch = wcslen(pch) + 1; // include the '\0'
  100. if ((psm->hGlobal = GlobalAlloc(GMEM_FIXED, cch*sizeof(WCHAR))) == NULL)
  101. {
  102. GlobalUnlock(_sm.hGlobal);
  103. return STG_E_MEDIUMFULL;
  104. }
  105. memcpy(psm->hGlobal, pch, cch*sizeof(WCHAR));
  106. GlobalUnlock(_sm.hGlobal);
  107. }
  108. psm->tymed = TYMED_HGLOBAL;
  109. psm->pUnkForRelease = NULL; // caller must GlobalFree
  110. break;
  111. default:
  112. Assert(0); // shouldn't have let anyone SetData with something we can't handle
  113. break;
  114. }
  115. }
  116. else
  117. {
  118. Assert(0); // shouldn't have let anyone SetData with something we can't handle
  119. }
  120. return S_OK;
  121. }
  122. //+---------------------------------------------------------------------------
  123. //
  124. // GetDataHere
  125. //
  126. //----------------------------------------------------------------------------
  127. STDAPI CTFDataObject::GetDataHere(FORMATETC *pfe, STGMEDIUM *psm)
  128. {
  129. return E_NOTIMPL;
  130. }
  131. //+---------------------------------------------------------------------------
  132. //
  133. // QueryGetData
  134. //
  135. //----------------------------------------------------------------------------
  136. STDAPI CTFDataObject::QueryGetData(FORMATETC *pfe)
  137. {
  138. if (pfe == NULL)
  139. return E_INVALIDARG;
  140. // verify the formatetc
  141. if (pfe->cfFormat != _fe.cfFormat)
  142. return DV_E_FORMATETC;
  143. // Issue: ignoring ptd
  144. if (pfe->dwAspect != _fe.dwAspect)
  145. return DV_E_DVASPECT;
  146. if (pfe->lindex != _fe.lindex)
  147. return DV_E_LINDEX;
  148. if (!(pfe->tymed & _fe.lindex))
  149. return DV_E_TYMED;
  150. return S_OK;
  151. }
  152. //+---------------------------------------------------------------------------
  153. //
  154. // GetCanonicalFormatEtc
  155. //
  156. //----------------------------------------------------------------------------
  157. STDAPI CTFDataObject::GetCanonicalFormatEtc(FORMATETC *pfeIn, FORMATETC *pfeOut)
  158. {
  159. return E_NOTIMPL;
  160. }
  161. //+---------------------------------------------------------------------------
  162. //
  163. // SetData
  164. //
  165. //----------------------------------------------------------------------------
  166. STDAPI CTFDataObject::SetData(FORMATETC *pfe, STGMEDIUM *psm, BOOL fRelease)
  167. {
  168. Assert(fRelease == TRUE); // bogus, but for now we don't support copying
  169. if (pfe == NULL || psm == NULL)
  170. return E_INVALIDARG;
  171. if (pfe->tymed != psm->tymed)
  172. return E_INVALIDARG;
  173. // free up any storage
  174. ReleaseStgMedium(&_sm);
  175. // copy the new stuff
  176. _fe = *pfe;
  177. _sm = *psm;
  178. return S_OK;
  179. }
  180. //+---------------------------------------------------------------------------
  181. //
  182. // EnumFormatEtc
  183. //
  184. //----------------------------------------------------------------------------
  185. STDAPI CTFDataObject::EnumFormatEtc(DWORD dwDir, IEnumFORMATETC **ppefe)
  186. {
  187. return E_NOTIMPL;
  188. }
  189. //+---------------------------------------------------------------------------
  190. //
  191. // DAdvise
  192. //
  193. //----------------------------------------------------------------------------
  194. STDAPI CTFDataObject::DAdvise(FORMATETC *pfe, DWORD advf, IAdviseSink *pas, DWORD *pdwCookie)
  195. {
  196. return E_NOTIMPL;
  197. }
  198. //+---------------------------------------------------------------------------
  199. //
  200. // DUnadvise
  201. //
  202. //----------------------------------------------------------------------------
  203. STDAPI CTFDataObject::DUnadvise(DWORD dwCookie)
  204. {
  205. return E_NOTIMPL;
  206. }
  207. //+---------------------------------------------------------------------------
  208. //
  209. // EnumDAdvise
  210. //
  211. //----------------------------------------------------------------------------
  212. STDAPI CTFDataObject::EnumDAdvise(IEnumSTATDATA **ppesd)
  213. {
  214. return E_NOTIMPL;
  215. }
  216. //+---------------------------------------------------------------------------
  217. //
  218. // _SetData
  219. //
  220. //----------------------------------------------------------------------------
  221. HRESULT CTFDataObject::_SetData(const WCHAR *pch, ULONG cch)
  222. {
  223. FORMATETC fe;
  224. STGMEDIUM sm;
  225. fe.cfFormat = CF_UNICODETEXT;
  226. fe.ptd = NULL;
  227. fe.dwAspect = DVASPECT_CONTENT;
  228. fe.lindex = -1;
  229. fe.tymed = TYMED_HGLOBAL;
  230. sm.tymed = TYMED_HGLOBAL;
  231. sm.hGlobal = NULL;
  232. sm.pUnkForRelease = NULL;
  233. sm.hGlobal = GlobalAlloc(GMEM_FIXED, (cch+1)*sizeof(WCHAR));
  234. if (sm.hGlobal == NULL)
  235. return E_OUTOFMEMORY;
  236. memcpy(sm.hGlobal, pch, cch*sizeof(WCHAR));
  237. ((WCHAR *)sm.hGlobal)[cch] = '\0';
  238. return SetData(&fe, &sm, TRUE);
  239. }