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.

544 lines
13 KiB

  1. //**********************************************************************
  2. // File name: IDO.CPP
  3. //
  4. // Implementation file for the CDataObject Class
  5. //
  6. // Functions:
  7. //
  8. // See ido.h for a list of member functions.
  9. //
  10. // Copyright (c) 1993 Microsoft Corporation. All rights reserved.
  11. //**********************************************************************
  12. #include "pre.h"
  13. #include "obj.h"
  14. #include "ido.h"
  15. #include "app.h"
  16. #include "doc.h"
  17. //**********************************************************************
  18. //
  19. // CDataObject::QueryInterface
  20. //
  21. // Purpose:
  22. //
  23. //
  24. // Parameters:
  25. //
  26. // REFIID riid - Interface being queried for.
  27. //
  28. // LPVOID FAR *ppvObj - Out pointer for the interface.
  29. //
  30. // Return Value:
  31. //
  32. // S_OK - Success
  33. // E_NOINTERFACE - Failure
  34. //
  35. // Function Calls:
  36. // Function Location
  37. //
  38. // CSimpSvrObj::QueryInterface OBJ.CPP
  39. //
  40. // Comments:
  41. //
  42. //
  43. //********************************************************************
  44. STDMETHODIMP CDataObject::QueryInterface ( REFIID riid, LPVOID FAR* ppvObj)
  45. {
  46. TestDebugOut("In CDataObject::QueryInterface\r\n");
  47. return m_lpObj->QueryInterface(riid, ppvObj);
  48. };
  49. //**********************************************************************
  50. //
  51. // CDataObject::AddRef
  52. //
  53. // Purpose:
  54. //
  55. // Increments the reference count on CClassFactory and the application
  56. // object.
  57. //
  58. // Parameters:
  59. //
  60. // None
  61. //
  62. // Return Value:
  63. //
  64. // The Reference count on CDataObject
  65. //
  66. // Function Calls:
  67. // Function Location
  68. //
  69. // OuputDebugString Windows API
  70. // CSimpSvrObj::AddRef OBJ.CPP
  71. //
  72. // Comments:
  73. //
  74. //
  75. //********************************************************************
  76. STDMETHODIMP_(ULONG) CDataObject::AddRef ()
  77. {
  78. TestDebugOut("In CDataObject::AddRef\r\n");
  79. ++m_nCount;
  80. return m_lpObj->AddRef();
  81. };
  82. //**********************************************************************
  83. //
  84. // CDataObject::Release
  85. //
  86. // Purpose:
  87. //
  88. // Decrements the reference count of CDataObject
  89. //
  90. // Parameters:
  91. //
  92. // None
  93. //
  94. // Return Value:
  95. //
  96. // The new reference count
  97. //
  98. // Function Calls:
  99. // Function Location
  100. //
  101. // TestDebugOut Windows API
  102. // CSimpSvrObj::Release OBJ.CPP
  103. //
  104. // Comments:
  105. //
  106. //
  107. //********************************************************************
  108. STDMETHODIMP_(ULONG) CDataObject::Release ()
  109. {
  110. TestDebugOut("In CDataObject::Release\r\n");
  111. --m_nCount;
  112. return m_lpObj->Release();
  113. };
  114. //**********************************************************************
  115. //
  116. // CDataObject::QueryGetData
  117. //
  118. // Purpose:
  119. //
  120. // Called to determine if our object supports a particular
  121. // FORMATETC.
  122. //
  123. // Parameters:
  124. //
  125. // LPFORMATETC pformatetc - Pointer to the FORMATETC being queried for.
  126. //
  127. // Return Value:
  128. //
  129. // DATA_E_FORMATETC - The FORMATETC is not supported
  130. // S_OK - The FORMATETC is supported.
  131. //
  132. //
  133. // Function Calls:
  134. // Function Location
  135. //
  136. // TestDebugOut Windows API
  137. // ResultFromScode OLE API
  138. //
  139. // Comments:
  140. //
  141. //
  142. //********************************************************************
  143. STDMETHODIMP CDataObject::QueryGetData ( LPFORMATETC pformatetc )
  144. {
  145. SCODE sc = DATA_E_FORMATETC;
  146. TestDebugOut("In CDataObject::QueryGetData\r\n");
  147. // check the validity of the formatetc.
  148. if ( (pformatetc->cfFormat == CF_METAFILEPICT) &&
  149. (pformatetc->dwAspect == DVASPECT_CONTENT) &&
  150. (pformatetc->tymed == TYMED_MFPICT) )
  151. sc = S_OK;
  152. return ResultFromScode(sc);
  153. };
  154. //**********************************************************************
  155. //
  156. // CDataObject::DAdvise
  157. //
  158. // Purpose:
  159. //
  160. // Called by the container when it would like to be notified of
  161. // changes in the object data.
  162. //
  163. // Parameters:
  164. //
  165. // FORMATETC FAR* pFormatetc - The format the container is interested in.
  166. //
  167. // DWORD advf - The type of advise to be set up.
  168. //
  169. // LPADVISESINK pAdvSink - Pointer to the containers IAdviseSink
  170. //
  171. // DWORD FAR* pdwConnection - Out parameter to return a unique connection id.
  172. //
  173. // Return Value:
  174. //
  175. // passed on from IDataAdviseHolder
  176. //
  177. // Function Calls:
  178. // Function Location
  179. //
  180. // TestDebugOut Windows API
  181. // CreateDataAdviseHolder OLE API
  182. // IDataAdviseHolder::Advise OLE API
  183. //
  184. // Comments:
  185. //
  186. //
  187. //********************************************************************
  188. STDMETHODIMP CDataObject::DAdvise ( FORMATETC FAR* pFormatetc, DWORD advf,
  189. LPADVISESINK pAdvSink, DWORD FAR* pdwConnection)
  190. {
  191. TestDebugOut("In CDataObject::DAdvise\r\n");
  192. // if no DataAdviseHolder has been created, then create one.
  193. if (!m_lpObj->m_lpDataAdviseHolder)
  194. CreateDataAdviseHolder(&m_lpObj->m_lpDataAdviseHolder);
  195. // pass on to the DataAdviseHolder
  196. return m_lpObj->m_lpDataAdviseHolder->Advise( this, pFormatetc, advf,
  197. pAdvSink, pdwConnection);
  198. }
  199. //**********************************************************************
  200. //
  201. // CDataObject::GetData
  202. //
  203. // Purpose:
  204. //
  205. // Returns the data in the format specified in pformatetcIn.
  206. //
  207. // Parameters:
  208. //
  209. // LPFORMATETC pformatetcIn - The format requested by the caller
  210. //
  211. // LPSTGMEDIUM pmedium - The medium requested by the caller
  212. //
  213. // Return Value:
  214. //
  215. // DATA_E_FORMATETC - Format not supported
  216. // S_OK - Success
  217. //
  218. // Function Calls:
  219. // Function Location
  220. //
  221. // TestDebugOut Windows API
  222. // CSimpSvrObj::GetMetaFilePict() OBJ.CPP
  223. // ResultFromScode OLE API
  224. //
  225. // Comments:
  226. //
  227. //
  228. //********************************************************************
  229. STDMETHODIMP CDataObject::GetData ( LPFORMATETC pformatetcIn, LPSTGMEDIUM pmedium )
  230. {
  231. SCODE sc = DATA_E_FORMATETC;
  232. TestDebugOut("In CDataObject::GetData\r\n");
  233. // Check to the FORMATETC and fill pmedium if valid.
  234. if ( (pformatetcIn->cfFormat == CF_METAFILEPICT) &&
  235. (pformatetcIn->dwAspect == DVASPECT_CONTENT) &&
  236. (pformatetcIn->tymed & TYMED_MFPICT) )
  237. {
  238. HANDLE hmfPict = m_lpObj->GetMetaFilePict();
  239. pmedium->tymed = TYMED_MFPICT;
  240. pmedium->hGlobal = hmfPict;
  241. pmedium->pUnkForRelease = NULL;
  242. sc = S_OK;
  243. }
  244. return ResultFromScode( sc );
  245. };
  246. //**********************************************************************
  247. //
  248. // CDataObject::DUnadvise
  249. //
  250. // Purpose:
  251. //
  252. // Breaks down an Advise connection.
  253. //
  254. // Parameters:
  255. //
  256. // DWORD dwConnection - Advise connection ID.
  257. //
  258. // Return Value:
  259. //
  260. // Returned from the DataAdviseHolder.
  261. //
  262. // Function Calls:
  263. // Function Location
  264. //
  265. // TestDebugOut Windows API
  266. // IDataAdviseHolder::Unadvise OLE
  267. //
  268. // Comments:
  269. //
  270. //
  271. //********************************************************************
  272. STDMETHODIMP CDataObject::DUnadvise ( DWORD dwConnection)
  273. {
  274. TestDebugOut("In CDataObject::DUnadvise\r\n");
  275. if (m_lpObj != NULL && m_lpObj->m_lpDataAdviseHolder != NULL)
  276. {
  277. return m_lpObj->m_lpDataAdviseHolder->Unadvise(dwConnection);
  278. }
  279. return ResultFromScode( E_UNEXPECTED);
  280. };
  281. //**********************************************************************
  282. //
  283. // CDataObject::GetDataHere
  284. //
  285. // Purpose:
  286. //
  287. // Called to get a data format in a caller supplied location
  288. //
  289. // Parameters:
  290. //
  291. // LPFORMATETC pformatetc - FORMATETC requested
  292. //
  293. // LPSTGMEDIUM pmedium - Medium to return the data
  294. //
  295. // Return Value:
  296. //
  297. // DATA_E_FORMATETC - We don't support the requested format
  298. //
  299. // Function Calls:
  300. // Function Location
  301. //
  302. // TestDebugOut Windows API
  303. //
  304. // Comments:
  305. //
  306. // In this simple implementation, we don't really support this
  307. // method, we just always return DATA_E_FORMATETC.
  308. //
  309. //********************************************************************
  310. STDMETHODIMP CDataObject::GetDataHere ( LPFORMATETC pformatetc,
  311. LPSTGMEDIUM pmedium )
  312. {
  313. TestDebugOut("In CDataObject::GetDataHere\r\n");
  314. return ResultFromScode( DATA_E_FORMATETC);
  315. };
  316. //**********************************************************************
  317. //
  318. // CDataObject::GetCanonicalFormatEtc
  319. //
  320. // Purpose:
  321. //
  322. // Returns a FORMATETC that is equivalent to the one passed in.
  323. //
  324. // Parameters:
  325. //
  326. // LPFORMATETC pformatetc - FORMATETC to be tested.
  327. //
  328. // LPFORMATETC pformatetcOut - Out ptr for returned FORMATETC.
  329. //
  330. // Return Value:
  331. //
  332. // DATA_S_SAMEFORMATETC - Use the same formatetc as was passed.
  333. //
  334. // Function Calls:
  335. // Function Location
  336. //
  337. // TestDebugOut Windows API
  338. // CoGetMalloc OLE API
  339. // IMalloc::Alloc OLE
  340. // IMalloc::Release OLE
  341. // _fmemcpy C run-time
  342. //
  343. // Comments:
  344. //
  345. //
  346. //********************************************************************
  347. STDMETHODIMP CDataObject::GetCanonicalFormatEtc ( LPFORMATETC pformatetc,
  348. LPFORMATETC pformatetcOut)
  349. {
  350. HRESULT hresult;
  351. TestDebugOut("In CDataObject::GetCanonicalFormatEtc\r\n");
  352. if (!pformatetcOut)
  353. return ResultFromScode(E_INVALIDARG);
  354. /* OLE2NOTE: we must make sure to set all out parameters to NULL. */
  355. pformatetcOut->ptd = NULL;
  356. if (!pformatetc)
  357. return ResultFromScode(E_INVALIDARG);
  358. // OLE2NOTE: we must validate that the format requested is supported
  359. if ((hresult = QueryGetData(pformatetc)) != NOERROR)
  360. return hresult;
  361. /* OLE2NOTE: an app that is insensitive to target device (as
  362. ** SimpSvr is) should fill in the lpformatOut parameter
  363. ** but NULL out the "ptd" field; it should return NOERROR if the
  364. ** input formatetc->ptd what non-NULL. this tells the caller
  365. ** that it is NOT necessary to maintain a separate screen
  366. ** rendering and printer rendering. if should return
  367. ** DATA_S_SAMEFORMATETC if the input and output formatetc's are
  368. ** identical.
  369. */
  370. *pformatetcOut = *pformatetc;
  371. if (pformatetc->ptd == NULL)
  372. return ResultFromScode(DATA_S_SAMEFORMATETC);
  373. else
  374. {
  375. pformatetcOut->ptd = NULL;
  376. return NOERROR;
  377. }
  378. };
  379. //**********************************************************************
  380. //
  381. // CDataObject::SetData
  382. //
  383. // Purpose:
  384. //
  385. // Called to set the data for the object.
  386. //
  387. // Parameters:
  388. //
  389. // LPFORMATETC pformatetc - the format of the data being passed
  390. //
  391. // STGMEDIUM FAR * pmedium - the location of the data.
  392. //
  393. // BOOL fRelease - Defines the ownership of the medium
  394. //
  395. // Return Value:
  396. //
  397. // DATA_E_FORMATETC - Not a valid FORMATETC for this object
  398. //
  399. // Function Calls:
  400. // Function Location
  401. //
  402. // TestDebugOut Windows API
  403. //
  404. // Comments:
  405. //
  406. // This simple object does not support having its data set, so an
  407. // error value is always returned.
  408. //
  409. //********************************************************************
  410. STDMETHODIMP CDataObject::SetData ( LPFORMATETC pformatetc, STGMEDIUM FAR * pmedium,
  411. BOOL fRelease)
  412. {
  413. TestDebugOut("In CDataObject::SetData\r\n");
  414. return ResultFromScode( DATA_E_FORMATETC );
  415. };
  416. //**********************************************************************
  417. //
  418. // CDataObject::EnumFormatEtc
  419. //
  420. // Purpose:
  421. //
  422. // Enumerates the formats supported by this object.
  423. //
  424. // Parameters:
  425. //
  426. // DWORD dwDirection - Order of enumeration.
  427. //
  428. // LPENUMFORMATETC FAR* ppenumFormatEtc - Place to return a pointer
  429. // to the enumerator.
  430. //
  431. // Return Value:
  432. //
  433. // OLE_S_USEREG - Indicates that OLE should consult the REG DB
  434. // to enumerate the formats.
  435. //
  436. // Function Calls:
  437. // Function Location
  438. //
  439. // TestDebugOut Windows API
  440. //
  441. // Comments:
  442. //
  443. //
  444. //********************************************************************
  445. STDMETHODIMP CDataObject::EnumFormatEtc ( DWORD dwDirection,
  446. LPENUMFORMATETC FAR* ppenumFormatEtc)
  447. {
  448. TestDebugOut("In CDataObject::EnumFormatEtc\r\n");
  449. // need to NULL the out parameter
  450. *ppenumFormatEtc = NULL;
  451. return ResultFromScode( OLE_S_USEREG );
  452. };
  453. //**********************************************************************
  454. //
  455. // CDataObject::EnumDAdvise
  456. //
  457. // Purpose:
  458. //
  459. // Returns an enumerator that enumerates all of the advises
  460. // set up on this data object.
  461. //
  462. // Parameters:
  463. //
  464. // LPENUMSTATDATA FAR* ppenumAdvise - An out ptr in which to
  465. // return the enumerator.
  466. //
  467. // Return Value:
  468. //
  469. // Passed back from IDataAdviseHolder::EnumAdvise
  470. //
  471. // Function Calls:
  472. // Function Location
  473. //
  474. // TestDebugOut Windows API
  475. // IDAtaAdviseHolder::EnumAdvise OLE
  476. //
  477. // Comments:
  478. //
  479. // This just delegates to the DataAdviseHolder.
  480. //
  481. //********************************************************************
  482. STDMETHODIMP CDataObject::EnumDAdvise ( LPENUMSTATDATA FAR* ppenumAdvise)
  483. {
  484. TestDebugOut("In CDataObject::EnumDAdvise\r\n");
  485. // need to NULL the out parameter
  486. *ppenumAdvise = NULL;
  487. return m_lpObj->m_lpDataAdviseHolder->EnumAdvise(ppenumAdvise);
  488. };