Source code of Windows XP (NT5)
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.

402 lines
11 KiB

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