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.

416 lines
10 KiB

  1. /*
  2. * DataObj.cpp - IDataObject implementation.
  3. *
  4. * Taken from URL code - very similar to DavidDi's original code
  5. *
  6. * Created: ChrisPi 9-11-95
  7. *
  8. */
  9. #include "precomp.h"
  10. #include "clrefcnt.hpp"
  11. #include "clenumft.hpp"
  12. #include "clCnfLnk.hpp"
  13. /* Global Variables
  14. *******************/
  15. /* registered clipboard formats */
  16. UINT g_cfConfLink = 0;
  17. UINT g_cfFileGroupDescriptor = 0;
  18. UINT g_cfFileContents = 0;
  19. /* Module Variables
  20. *******************/
  21. #pragma data_seg(DATA_SEG_READ_ONLY)
  22. char s_szConfLinkCF[] = "ConferenceLink";
  23. char s_szFileGroupDescriptorCF[] = CFSTR_FILEDESCRIPTOR;
  24. char s_szFileContentsCF[] = CFSTR_FILECONTENTS;
  25. #pragma data_seg()
  26. /***************************** Private Functions *****************************/
  27. BOOL InitDataObjectModule(void)
  28. {
  29. g_cfConfLink = RegisterClipboardFormat(s_szConfLinkCF);
  30. g_cfFileGroupDescriptor = RegisterClipboardFormat(s_szFileGroupDescriptorCF);
  31. g_cfFileContents = RegisterClipboardFormat(s_szFileContentsCF);
  32. return( g_cfConfLink &&
  33. g_cfFileGroupDescriptor &&
  34. g_cfFileContents);
  35. }
  36. /********************************** Methods **********************************/
  37. HRESULT STDMETHODCALLTYPE CConfLink::GetData( PFORMATETC pfmtetc,
  38. PSTGMEDIUM pstgmed)
  39. {
  40. HRESULT hr;
  41. DebugEntry(CConfLink::GetData);
  42. ASSERT(IS_VALID_STRUCT_PTR(this, CConfLink));
  43. ASSERT(IS_VALID_STRUCT_PTR(pfmtetc, CFORMATETC));
  44. ASSERT(IS_VALID_WRITE_PTR(pstgmed, STGMEDIUM));
  45. // Ignore pfmtetc.ptd. All supported data formats are device-independent.
  46. ZeroMemory(pstgmed, sizeof(*pstgmed));
  47. if (pfmtetc->dwAspect == DVASPECT_CONTENT)
  48. {
  49. #ifdef DEBUG
  50. if ((pfmtetc->lindex == -1) &&
  51. ( (pfmtetc->cfFormat == g_cfConfLink) ||
  52. (pfmtetc->cfFormat == CF_TEXT) ||
  53. (pfmtetc->cfFormat == g_cfFileGroupDescriptor)) )
  54. {
  55. ERROR_OUT(("CConfLink::GetData - unsupported cfFormat"));
  56. }
  57. #endif /* DEBUG */
  58. #if 0
  59. if (pfmtetc->cfFormat == g_cfConfLink)
  60. {
  61. hr = (pfmtetc->lindex == -1) ?
  62. TransferConfLink(pfmtetc, pstgmed) : DV_E_LINDEX;
  63. }
  64. else if (pfmtetc->cfFormat == CF_TEXT)
  65. {
  66. hr = (pfmtetc->lindex == -1) ?
  67. TransferText(pfmtetc, pstgmed) : DV_E_LINDEX;
  68. }
  69. else if (pfmtetc->cfFormat == g_cfFileGroupDescriptor)
  70. {
  71. hr = (pfmtetc->lindex == -1) ?
  72. TransferFileGroupDescriptor(pfmtetc, pstgmed) : DV_E_LINDEX;
  73. }
  74. else
  75. #endif // 0
  76. if (pfmtetc->cfFormat == g_cfFileContents)
  77. {
  78. hr = (! pfmtetc->lindex) ?
  79. TransferFileContents(pfmtetc, pstgmed) : DV_E_LINDEX;
  80. }
  81. else
  82. {
  83. hr = DV_E_FORMATETC;
  84. }
  85. }
  86. else
  87. {
  88. hr = DV_E_DVASPECT;
  89. }
  90. if (hr == S_OK)
  91. {
  92. TRACE_OUT(("CConfLink::GetData(): Returning clipboard format %s.",
  93. GetClipboardFormatNameString(pfmtetc->cfFormat)));
  94. }
  95. else
  96. {
  97. TRACE_OUT(("CConfLink::GetData(): Failed to return clipboard format %s.",
  98. GetClipboardFormatNameString(pfmtetc->cfFormat)));
  99. }
  100. ASSERT(IS_VALID_STRUCT_PTR(this, CConfLink));
  101. ASSERT(FAILED(hr) || IS_VALID_STRUCT_PTR(pstgmed, CSTGMEDIUM));
  102. DebugExitHRESULT(CConfLink::GetData, hr);
  103. return(hr);
  104. }
  105. // #pragma warning(disable:4100) /* "unreferenced formal parameter" warning */
  106. HRESULT STDMETHODCALLTYPE CConfLink::GetDataHere( PFORMATETC pfmtetc,
  107. PSTGMEDIUM pstgpmed)
  108. {
  109. HRESULT hr;
  110. DebugEntry(CConfLink::GetDataHere);
  111. ASSERT(IS_VALID_STRUCT_PTR(pfmtetc, CFORMATETC));
  112. ASSERT(IS_VALID_STRUCT_PTR(pstgpmed, CSTGMEDIUM));
  113. ASSERT(IS_VALID_STRUCT_PTR(this, CConfLink));
  114. TRACE_OUT(("CConfLink::GetDataHere(): Failed to return clipboard format %s.",
  115. GetClipboardFormatNameString(pfmtetc->cfFormat)));
  116. hr = DV_E_FORMATETC;
  117. ASSERT(IS_VALID_STRUCT_PTR(this, CConfLink));
  118. ASSERT(IS_VALID_STRUCT_PTR(pstgpmed, CSTGMEDIUM));
  119. DebugExitHRESULT(CConfLink::GetDataHere, hr);
  120. return(hr);
  121. }
  122. // #pragma warning(default:4100) /* "unreferenced formal parameter" warning */
  123. HRESULT STDMETHODCALLTYPE CConfLink::QueryGetData(PFORMATETC pfmtetc)
  124. {
  125. HRESULT hr;
  126. DebugEntry(CConfLink::QueryGetData);
  127. ASSERT(IS_VALID_STRUCT_PTR(this, CConfLink));
  128. ASSERT(IS_VALID_STRUCT_PTR(pfmtetc, CFORMATETC));
  129. TRACE_OUT(("CConfLink::QueryGetData(): Asked for clipboard format %s.",
  130. GetClipboardFormatNameString(pfmtetc->cfFormat)));
  131. // Ignore pfmtetc.ptd. All supported data formats are device-independent.
  132. if (pfmtetc->dwAspect == DVASPECT_CONTENT)
  133. {
  134. if (IS_FLAG_SET(pfmtetc->tymed, TYMED_HGLOBAL))
  135. {
  136. if (pfmtetc->cfFormat == g_cfConfLink)
  137. hr = (pfmtetc->lindex == -1) ? S_OK : DV_E_LINDEX;
  138. else if (pfmtetc->cfFormat == CF_TEXT)
  139. hr = (pfmtetc->lindex == -1) ? S_OK : DV_E_LINDEX;
  140. else if (pfmtetc->cfFormat == g_cfFileGroupDescriptor)
  141. hr = (pfmtetc->lindex == -1) ? S_OK : DV_E_LINDEX;
  142. else if (pfmtetc->cfFormat == g_cfFileContents)
  143. hr = (! pfmtetc->lindex) ? S_OK : DV_E_LINDEX;
  144. else
  145. hr = DV_E_FORMATETC;
  146. }
  147. else
  148. hr = DV_E_TYMED;
  149. }
  150. else
  151. {
  152. hr = DV_E_DVASPECT;
  153. }
  154. if (hr == S_OK)
  155. {
  156. TRACE_OUT(("CConfLink::QueryGetData(): Clipboard format %s supported.",
  157. GetClipboardFormatNameString(pfmtetc->cfFormat)));
  158. }
  159. else
  160. {
  161. TRACE_OUT(("CConfLink::QueryGetData(): Clipboard format %s not supported.",
  162. GetClipboardFormatNameString(pfmtetc->cfFormat)));
  163. }
  164. ASSERT(IS_VALID_STRUCT_PTR(this, CConfLink));
  165. DebugExitHRESULT(CConfLink::QueryGetData, hr);
  166. return(hr);
  167. }
  168. HRESULT STDMETHODCALLTYPE CConfLink::GetCanonicalFormatEtc( PFORMATETC pfmtetcIn,
  169. PFORMATETC pfmtetcOut)
  170. {
  171. HRESULT hr;
  172. DebugEntry(CConfLink::GetCanonicalFormatEtc);
  173. ASSERT(IS_VALID_STRUCT_PTR(this, CConfLink));
  174. ASSERT(IS_VALID_STRUCT_PTR(pfmtetcIn, CFORMATETC));
  175. ASSERT(IS_VALID_WRITE_PTR(pfmtetcOut, FORMATETC));
  176. hr = QueryGetData(pfmtetcIn);
  177. if (hr == S_OK)
  178. {
  179. *pfmtetcOut = *pfmtetcIn;
  180. if (pfmtetcIn->ptd == NULL)
  181. {
  182. hr = DATA_S_SAMEFORMATETC;
  183. }
  184. else
  185. {
  186. pfmtetcIn->ptd = NULL;
  187. ASSERT(hr == S_OK);
  188. }
  189. }
  190. else
  191. {
  192. ZeroMemory(pfmtetcOut, sizeof(*pfmtetcOut));
  193. }
  194. ASSERT(IS_VALID_STRUCT_PTR(this, CConfLink));
  195. ASSERT(FAILED(hr) ||
  196. IS_VALID_STRUCT_PTR(pfmtetcOut, CFORMATETC));
  197. DebugExitHRESULT(CConfLink::GetCanonicalFormatEtc, hr);
  198. return(hr);
  199. }
  200. // #pragma warning(disable:4100) /* "unreferenced formal parameter" warning */
  201. HRESULT STDMETHODCALLTYPE CConfLink::SetData( PFORMATETC pfmtetc,
  202. PSTGMEDIUM pstgmed,
  203. BOOL bRelease)
  204. {
  205. HRESULT hr;
  206. DebugEntry(CConfLink::SetData);
  207. // bRelease may be any value.
  208. ASSERT(IS_VALID_STRUCT_PTR(this, CConfLink));
  209. ASSERT(IS_VALID_STRUCT_PTR(pfmtetc, CFORMATETC));
  210. ASSERT(IS_VALID_STRUCT_PTR(pstgmed, CSTGMEDIUM));
  211. hr = DV_E_FORMATETC;
  212. ASSERT(IS_VALID_STRUCT_PTR(this, CConfLink));
  213. DebugExitHRESULT(CConfLink::SetData, hr);
  214. return(hr);
  215. }
  216. // #pragma warning(default:4100) /* "unreferenced formal parameter" warning */
  217. HRESULT STDMETHODCALLTYPE CConfLink::EnumFormatEtc( DWORD dwDirFlags,
  218. PIEnumFORMATETC *ppiefe)
  219. {
  220. HRESULT hr;
  221. DebugEntry(CConfLink::EnumFormatEtc);
  222. ASSERT(IS_VALID_STRUCT_PTR(this, CConfLink));
  223. ASSERT(FLAGS_ARE_VALID(dwDirFlags, ALL_DATADIR_FLAGS));
  224. ASSERT(IS_VALID_WRITE_PTR(ppiefe, PIEnumFORMATETC));
  225. *ppiefe = NULL;
  226. if (dwDirFlags == DATADIR_GET)
  227. {
  228. FORMATETC rgfmtetc[] =
  229. {
  230. { 0, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL },
  231. { 0, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL },
  232. { 0, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL },
  233. { 0, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL },
  234. };
  235. PEnumFormatEtc pefe;
  236. rgfmtetc[0].cfFormat = (CLIPFORMAT)g_cfConfLink;
  237. rgfmtetc[1].cfFormat = CF_TEXT;
  238. rgfmtetc[2].cfFormat = (CLIPFORMAT)g_cfFileGroupDescriptor;
  239. rgfmtetc[3].cfFormat = (CLIPFORMAT)g_cfFileContents;
  240. pefe = new ::EnumFormatEtc(rgfmtetc, ARRAY_ELEMENTS(rgfmtetc));
  241. if (pefe)
  242. {
  243. hr = pefe->Status();
  244. if (hr == S_OK)
  245. {
  246. *ppiefe = pefe;
  247. }
  248. else
  249. {
  250. delete pefe;
  251. pefe = NULL;
  252. }
  253. }
  254. else
  255. {
  256. hr = E_OUTOFMEMORY;
  257. }
  258. }
  259. else
  260. {
  261. // BUGBUG: Implement IDataObject::SetData() and add support for
  262. // DATADIR_SET here.
  263. hr = E_NOTIMPL;
  264. }
  265. ASSERT(IS_VALID_STRUCT_PTR(this, CConfLink));
  266. ASSERT((hr == S_OK &&
  267. IS_VALID_INTERFACE_PTR(*ppiefe, IEnumFORMATETC)) || (FAILED(hr) && ! *ppiefe));
  268. DebugExitHRESULT(CConfLink::EnumFormatEtc, hr);
  269. return(hr);
  270. }
  271. // #pragma warning(disable:4100) /* "unreferenced formal parameter" warning */
  272. HRESULT STDMETHODCALLTYPE CConfLink::DAdvise( PFORMATETC pfmtetc,
  273. DWORD dwAdviseFlags,
  274. PIAdviseSink piadvsink,
  275. PDWORD pdwConnection)
  276. {
  277. HRESULT hr;
  278. DebugEntry(CConfLink::DAdvise);
  279. ASSERT(IS_VALID_STRUCT_PTR(this, CConfLink));
  280. ASSERT(IS_VALID_STRUCT_PTR(pfmtetc, CFORMATETC));
  281. ASSERT(FLAGS_ARE_VALID(dwAdviseFlags, ALL_ADVISE_FLAGS));
  282. ASSERT(IS_VALID_INTERFACE_PTR(piadvsink, IAdviseSink));
  283. ASSERT(IS_VALID_WRITE_PTR(pdwConnection, DWORD));
  284. *pdwConnection = 0;
  285. hr = OLE_E_ADVISENOTSUPPORTED;
  286. ASSERT(IS_VALID_STRUCT_PTR(this, CConfLink));
  287. ASSERT((hr == S_OK && *pdwConnection) ||
  288. (FAILED(hr) && ! *pdwConnection));
  289. DebugExitHRESULT(CConfLink::DAdvise, hr);
  290. return(hr);
  291. }
  292. HRESULT STDMETHODCALLTYPE CConfLink::DUnadvise(DWORD dwConnection)
  293. {
  294. HRESULT hr;
  295. DebugEntry(CConfLink::DUnadvise);
  296. ASSERT(IS_VALID_STRUCT_PTR(this, CConfLink));
  297. ASSERT(dwConnection);
  298. hr = OLE_E_ADVISENOTSUPPORTED;
  299. ASSERT(IS_VALID_STRUCT_PTR(this, CConfLink));
  300. DebugExitHRESULT(CConfLink::DUnadvise, hr);
  301. return(hr);
  302. }
  303. // #pragma warning(default:4100) /* "unreferenced formal parameter" warning */
  304. HRESULT STDMETHODCALLTYPE CConfLink::EnumDAdvise(PIEnumSTATDATA *ppiesd)
  305. {
  306. HRESULT hr;
  307. DebugEntry(CConfLink::EnumDAdvise);
  308. ASSERT(IS_VALID_STRUCT_PTR(this, CConfLink));
  309. ASSERT(IS_VALID_WRITE_PTR(ppiesd, PIEnumSTATDATA));
  310. *ppiesd = NULL;
  311. hr = OLE_E_ADVISENOTSUPPORTED;
  312. ASSERT(IS_VALID_STRUCT_PTR(this, CConfLink));
  313. ASSERT((hr == S_OK && IS_VALID_INTERFACE_PTR(*ppiesd, IEnumSTATDATA)) ||
  314. (FAILED(hr) && ! *ppiesd));
  315. DebugExitHRESULT(CConfLink::EnumDAdvise, hr);
  316. return(hr);
  317. }