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.

370 lines
8.0 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. faxdataobj.cpp
  5. Abstract:
  6. This file contains my implementation of IDataObject.
  7. Environment:
  8. WIN32 User Mode
  9. Author:
  10. Darwin Ouyang (t-darouy) 30-Sept-1997
  11. --*/
  12. // FaxDataObj.cpp : Implementation of CFaxDataObject
  13. #include "stdafx.h"
  14. #include "faxadmin.h"
  15. #include "faxdataobj.h"
  16. #include "faxstrt.h"
  17. #include "inode.h"
  18. #pragma hdrstop
  19. //
  20. // This is the minimum set of clipboard formats we must implement.
  21. // MMC uses these to get necessary information from our snapin about
  22. // our nodes.
  23. //
  24. UINT CFaxDataObject::s_cfInternal = 0;
  25. UINT CFaxDataObject::s_cfDisplayName = 0;
  26. UINT CFaxDataObject::s_cfNodeType = 0;
  27. UINT CFaxDataObject::s_cfSnapinClsid = 0;
  28. #ifdef DEBUG
  29. // DataObject Count
  30. long CFaxDataObject::DataObjectCount = 0;
  31. #endif
  32. #define CF_SNAPIN_INTERNAL L"MMC_SNAPIN_INTERNAL"
  33. ////////////////////////////////////////////////////////////////////////////////////////////////////
  34. ////////////////////////////////////////////////////////////////////////////////////////////////////
  35. ////////////////////////////////////////////////////////////////////////////////////////////////////
  36. ////////////////////////////////////////////////////////////////////////////////////////////////////
  37. //
  38. //
  39. // Constructor and destructor
  40. //
  41. //
  42. CFaxDataObject::CFaxDataObject()
  43. /*++
  44. Routine Description:
  45. Constructor.
  46. Arguments:
  47. None.
  48. Return Value:
  49. None.
  50. --*/
  51. {
  52. // DebugPrint(( TEXT("Trace: CFaxDataObject::CFaxDataObject") ));
  53. m_ulCookie = 0;
  54. m_Context = CCT_UNINITIALIZED;
  55. pOwner = NULL;
  56. #ifdef DEBUG
  57. InterlockedIncrement( &DataObjectCount );
  58. // DebugPrint(( TEXT("FaxDataObject %d created."), DataObjectCount ));
  59. #endif
  60. // These are the clipboard formats that we must supply at a minimum.
  61. // mmc.h actually defined these. We can make up our own to use for
  62. // other reasons. We don't need any others at this time.
  63. s_cfInternal = RegisterClipboardFormat(CF_SNAPIN_INTERNAL);
  64. s_cfDisplayName = RegisterClipboardFormat(CCF_DISPLAY_NAME);
  65. s_cfNodeType = RegisterClipboardFormat(CCF_NODETYPE);
  66. s_cfSnapinClsid = RegisterClipboardFormat(CCF_SNAPIN_CLASSID);
  67. }
  68. CFaxDataObject::~CFaxDataObject()
  69. /*++
  70. Routine Description:
  71. Destructor.
  72. Arguments:
  73. None.
  74. Return Value:
  75. None.
  76. --*/
  77. {
  78. // DebugPrint(( TEXT("Trace: CFaxDataObject::~CFaxDataObject") ));
  79. #ifdef DEBUG
  80. if( DataObjectCount <= 1 ) {
  81. // DebugPrint(( TEXT(" ** All FaxDataObjects destroyed"), DataObjectCount ));
  82. }
  83. InterlockedDecrement( &DataObjectCount );
  84. #endif
  85. }
  86. ////////////////////////////////////////////////////////////////////////////////////////////////////
  87. ////////////////////////////////////////////////////////////////////////////////////////////////////
  88. ////////////////////////////////////////////////////////////////////////////////////////////////////
  89. ////////////////////////////////////////////////////////////////////////////////////////////////////
  90. //
  91. //
  92. // CFaxDataObject - IDataObject implementation
  93. //
  94. //
  95. HRESULT
  96. STDMETHODCALLTYPE
  97. CFaxDataObject::GetDataHere(
  98. /* [unique] */ IN FORMATETC __RPC_FAR *pFormatEtc,
  99. IN OUT STGMEDIUM __RPC_FAR *pMedium)
  100. /*++
  101. Routine Description:
  102. Writes the requested data to the specified medium, also dispatches
  103. the data request to the owning node's getdatahere for custom formats.
  104. Arguments:
  105. pFormatEtc - the format
  106. pMedium - the medium
  107. Return Value:
  108. HRESULT indicating SUCCEEDED() or FAILED()
  109. --*/
  110. {
  111. // DebugPrint(( TEXT("Trace: CFaxDataObject::GetDataHere") ));
  112. HRESULT hr = S_OK;
  113. const CLIPFORMAT cf = pFormatEtc->cfFormat;
  114. IStream *pstm = NULL;
  115. assert(pOwner != NULL );
  116. pMedium->pUnkForRelease = NULL; // by OLE spec
  117. do {
  118. hr = CreateStreamOnHGlobal(pMedium->hGlobal, FALSE, &pstm);
  119. if( FAILED( hr ) ) {
  120. break;
  121. }
  122. if(cf == s_cfDisplayName) {
  123. //DebugPrint(( TEXT("Trace: CFaxDataObject Format DisplayName") ));
  124. hr = _WriteDisplayName(pstm);
  125. } else if(cf == s_cfInternal) {
  126. //DebugPrint(( TEXT("Trace: CFaxDataObject Format Internal") ));
  127. hr = _WriteInternal(pstm);
  128. } else if(cf == s_cfNodeType) {
  129. //DebugPrint(( TEXT("Trace: CFaxDataObject Format Node Type UUID") ));
  130. hr = _WriteNodeType(pstm);
  131. } else if(cf == s_cfSnapinClsid) {
  132. //DebugPrint(( TEXT("Trace: CFaxDataObject Format Snapin CLSID") ));
  133. hr = _WriteClsid(pstm);
  134. } else {
  135. // if we're attached to a node
  136. if(pOwner != NULL ) {
  137. // this is a node specific dataobject - handle node specific data formats
  138. hr = pOwner->DataObjectGetDataHere( pFormatEtc, pstm );
  139. // not a known data type!
  140. if( FAILED(hr) ) {
  141. assert( FALSE );
  142. break;
  143. }
  144. } else {
  145. // this is a snapin data object
  146. // we don't support this clipboard format
  147. assert( FALSE );
  148. hr = DV_E_FORMATETC;
  149. }
  150. }
  151. } while(0);
  152. if(pstm) {
  153. pstm->Release();
  154. }
  155. return hr;
  156. }
  157. ////////////////////////////////////////////////////////////////////////////////////////////////////
  158. ////////////////////////////////////////////////////////////////////////////////////////////////////
  159. ////////////////////////////////////////////////////////////////////////////////////////////////////
  160. ////////////////////////////////////////////////////////////////////////////////////////////////////
  161. //
  162. //
  163. // Member Functions
  164. //
  165. //
  166. void
  167. CFaxDataObject::SetOwner(
  168. CInternalNode* pO )
  169. /*++
  170. Routine Description:
  171. Initialization function to set the owner of the dataobject and
  172. register additional clipboard formats
  173. Arguments:
  174. pO - owner node
  175. Return Value:
  176. None.
  177. --*/
  178. {
  179. assert( pO != NULL );
  180. pOwner = pO;
  181. // register node specific data types now
  182. if( pOwner != NULL ) {
  183. pOwner->DataObjectRegisterFormats();
  184. }
  185. }
  186. HRESULT
  187. CFaxDataObject::_WriteNodeType(
  188. IStream *pstm)
  189. /*++
  190. Routine Description:
  191. Write this node's GUID type to the stream [pstm].
  192. Arguments:
  193. pstm - the target stream
  194. Return Value:
  195. None.
  196. --*/
  197. {
  198. HRESULT hr;
  199. const GUID *pguid = NULL;
  200. assert( pOwner != NULL );
  201. if( pOwner == NULL ) {
  202. return E_UNEXPECTED;
  203. }
  204. pguid = pOwner->GetNodeGUID();
  205. hr = pstm->Write((PVOID) pguid, sizeof(GUID), NULL);
  206. return hr;
  207. }
  208. HRESULT
  209. CFaxDataObject::_WriteDisplayName(
  210. IStream *pstm)
  211. /*++
  212. Routine Description:
  213. Write this node's display name to the stream [pstm].
  214. Arguments:
  215. pstm - the target stream
  216. Return Value:
  217. None.
  218. --*/
  219. {
  220. HRESULT hr = S_OK;
  221. LPWSTR pwszName;
  222. assert( pOwner != NULL );
  223. if( pOwner == NULL ) {
  224. return E_UNEXPECTED;
  225. }
  226. pwszName = pOwner->GetNodeDisplayName();
  227. ULONG ulSizeofName = lstrlen(pwszName);
  228. ulSizeofName++; // count null
  229. ulSizeofName *= sizeof(WCHAR);
  230. hr = pstm->Write(pwszName, ulSizeofName, NULL);
  231. return hr;
  232. }
  233. HRESULT
  234. CFaxDataObject::_WriteInternal(
  235. IStream *pstm)
  236. /*++
  237. Routine Description:
  238. Write this object's data in the private clipboard format
  239. to the stream [pstm].
  240. Arguments:
  241. pstm - the target stream
  242. Return Value:
  243. None.
  244. --*/
  245. {
  246. HRESULT hr;
  247. CFaxDataObject *pThis = this;
  248. hr = pstm->Write(&pThis, sizeof (CFaxDataObject *), NULL);
  249. return hr;
  250. }
  251. HRESULT
  252. CFaxDataObject::_WriteClsid(
  253. IStream *pstm)
  254. /*++
  255. Routine Description:
  256. Write the snapin's CLSID
  257. to the stream [pstm].
  258. Arguments:
  259. pstm - the target stream
  260. Return Value:
  261. None.
  262. --*/
  263. {
  264. HRESULT hr;
  265. hr = pstm->Write(&CLSID_FaxSnapin, sizeof CLSID_FaxSnapin, NULL);
  266. return hr;
  267. }