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.

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