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.

320 lines
7.8 KiB

  1. // This is a part of the Microsoft Management Console.
  2. // Copyright (C) 1995-1996 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Management Console and related
  7. // electronic documentation provided with the interfaces.
  8. #ifndef _DATAOBJ_H
  9. #define _DATAOBJ_H
  10. ///////////////////////////////////////////////////////////////////////////////
  11. // MACROS
  12. #define BYTE_MEM_LEN_W(s) ((wcslen(s)+1) * sizeof(wchar_t))
  13. ///////////////////////////////////////////////////////////////////////////////
  14. // FORWARD DECLARATIONS
  15. class CTreeNode;
  16. class CRootData;
  17. class CComponentDataObject;
  18. class CNodeList;
  19. ///////////////////////////////////////////////////////////////////////////////
  20. // DATA STRUCTURES
  21. // New Clipboard format that has the Type and Cookie
  22. extern const wchar_t* CCF_DNS_SNAPIN_INTERNAL;
  23. struct INTERNAL
  24. {
  25. INTERNAL()
  26. {
  27. m_type = CCT_UNINITIALIZED;
  28. m_p_cookies = NULL;
  29. m_pString = NULL;
  30. m_cookie_count = 0;
  31. };
  32. ~INTERNAL()
  33. {
  34. free(m_p_cookies);
  35. delete m_pString;
  36. }
  37. DATA_OBJECT_TYPES m_type; // What context is the data object.
  38. CTreeNode** m_p_cookies; // What object the cookie represents
  39. LPTSTR m_pString; // internal pointer
  40. DWORD m_cookie_count;
  41. INTERNAL & operator=(const INTERNAL& rhs)
  42. {
  43. m_type = rhs.m_type;
  44. m_p_cookies = rhs.m_p_cookies;
  45. m_cookie_count = rhs.m_cookie_count;
  46. return *this;
  47. }
  48. };
  49. //////////////////////////////////////////////////////////////////////////////
  50. // CInternalFormatCracker
  51. class CInternalFormatCracker
  52. {
  53. public:
  54. CInternalFormatCracker() : m_pInternal(NULL) {}
  55. CInternalFormatCracker(INTERNAL* pInternal) : m_pInternal(pInternal) {}
  56. ~CInternalFormatCracker()
  57. {
  58. _Free();
  59. }
  60. DWORD GetCookieCount()
  61. {
  62. if (m_pInternal == NULL)
  63. {
  64. return 0;
  65. }
  66. return m_pInternal->m_cookie_count;
  67. }
  68. DATA_OBJECT_TYPES GetCookieType()
  69. {
  70. ASSERT(m_pInternal != NULL);
  71. return m_pInternal->m_type;
  72. }
  73. CTreeNode* GetCookieAt(DWORD idx)
  74. {
  75. if(m_pInternal == NULL)
  76. {
  77. return NULL;
  78. }
  79. if (idx < m_pInternal->m_cookie_count)
  80. {
  81. return m_pInternal->m_p_cookies[idx];
  82. }
  83. return NULL;
  84. }
  85. HRESULT Extract(LPDATAOBJECT lpDataObject);
  86. void GetCookieList(CNodeList& list);
  87. private:
  88. INTERNAL* m_pInternal;
  89. void _Free()
  90. {
  91. if (m_pInternal != NULL)
  92. {
  93. ::GlobalFree(m_pInternal);
  94. m_pInternal = NULL;
  95. }
  96. }
  97. };
  98. ///////////////////////////////////////////////////////////////////////////////
  99. // CDataObject
  100. class CDataObject : public IDataObject, public CComObjectRoot
  101. {
  102. // ATL Maps
  103. DECLARE_NOT_AGGREGATABLE(CDataObject)
  104. BEGIN_COM_MAP(CDataObject)
  105. COM_INTERFACE_ENTRY(IDataObject)
  106. END_COM_MAP()
  107. // Construction/Destruction
  108. CDataObject()
  109. {
  110. #ifdef _DEBUG_REFCOUNT
  111. dbg_cRef = 0;
  112. ++m_nOustandingObjects;
  113. TRACE(_T("CDataObject(), count = %d\n"),m_nOustandingObjects);
  114. #endif // _DEBUG_REFCOUNT
  115. m_pUnkComponentData = NULL;
  116. }
  117. ~CDataObject()
  118. {
  119. #ifdef _DEBUG_REFCOUNT
  120. --m_nOustandingObjects;
  121. TRACE(_T("~CDataObject(), count = %d\n"),m_nOustandingObjects);
  122. #endif // _DEBUG_REFCOUNT
  123. if (m_pUnkComponentData != NULL)
  124. {
  125. m_pUnkComponentData->Release();
  126. m_pUnkComponentData = NULL;
  127. #ifdef _DEBUG_REFCOUNT
  128. TRACE(_T("~CDataObject() released m_pUnkComponentData\n"));
  129. #endif // _DEBUG_REFCOUNT
  130. }
  131. }
  132. #ifdef _DEBUG_REFCOUNT
  133. static unsigned int m_nOustandingObjects; // # of objects created
  134. int dbg_cRef;
  135. ULONG InternalAddRef()
  136. {
  137. ++dbg_cRef;
  138. return CComObjectRoot::InternalAddRef();
  139. }
  140. ULONG InternalRelease()
  141. {
  142. --dbg_cRef;
  143. return CComObjectRoot::InternalRelease();
  144. }
  145. #endif // _DEBUG_REFCOUNT
  146. // Clipboard formats that are required by the console
  147. public:
  148. static CLIPFORMAT m_cfNodeType; // Required by the console
  149. static CLIPFORMAT m_cfNodeTypeString; // Required by the console
  150. static CLIPFORMAT m_cfDisplayName; // Required by the console
  151. static CLIPFORMAT m_cfCoClass; // Required by the console
  152. static CLIPFORMAT m_cfColumnID; // Option for column identification
  153. static CLIPFORMAT m_cfInternal;
  154. static CLIPFORMAT m_cfMultiSel;
  155. static CLIPFORMAT m_cfMultiObjTypes;
  156. // Standard IDataObject methods
  157. public:
  158. // Implemented
  159. STDMETHOD(GetData)(LPFORMATETC lpFormatetcIn, LPSTGMEDIUM lpMedium);
  160. STDMETHOD(GetDataHere)(LPFORMATETC lpFormatetc, LPSTGMEDIUM lpMedium);
  161. STDMETHOD(EnumFormatEtc)(DWORD dwDirection, LPENUMFORMATETC* ppEnumFormatEtc);
  162. // Not Implemented
  163. private:
  164. STDMETHOD(QueryGetData)(LPFORMATETC)
  165. { return E_NOTIMPL; };
  166. STDMETHOD(GetCanonicalFormatEtc)(LPFORMATETC, LPFORMATETC)
  167. { return E_NOTIMPL; };
  168. STDMETHOD(SetData)(LPFORMATETC, LPSTGMEDIUM, BOOL)
  169. { return E_NOTIMPL; };
  170. STDMETHOD(DAdvise)(LPFORMATETC, DWORD,
  171. LPADVISESINK, LPDWORD)
  172. { return E_NOTIMPL; };
  173. STDMETHOD(DUnadvise)(DWORD)
  174. { return E_NOTIMPL; };
  175. STDMETHOD(EnumDAdvise)(LPENUMSTATDATA*)
  176. { return E_NOTIMPL; };
  177. // Implementation
  178. public:
  179. void SetType(DATA_OBJECT_TYPES type) // Step 3
  180. {
  181. ASSERT(m_internal.m_type == CCT_UNINITIALIZED);
  182. m_internal.m_type = type;
  183. }
  184. DATA_OBJECT_TYPES GetType()
  185. {
  186. ASSERT(m_internal.m_type != CCT_UNINITIALIZED);
  187. return m_internal.m_type;
  188. }
  189. void AddCookie(CTreeNode* cookie);
  190. void SetString(LPTSTR lpString) { m_internal.m_pString = lpString; }
  191. HRESULT Create(const void* pBuffer, size_t len, LPSTGMEDIUM lpMedium);
  192. private:
  193. HRESULT CreateColumnID(LPSTGMEDIUM lpMedium); // Optional for column identification
  194. HRESULT CreateNodeTypeData(LPSTGMEDIUM lpMedium); // Required by the console
  195. HRESULT CreateNodeTypeStringData(LPSTGMEDIUM lpMedium); // Required by the console
  196. HRESULT CreateDisplayName(LPSTGMEDIUM lpMedium); // Required by the console
  197. HRESULT CreateCoClassID(LPSTGMEDIUM lpMedium); // Required by the console
  198. HRESULT CreateMultiSelectObject(LPSTGMEDIUM lpMedium);
  199. HRESULT CreateInternal(LPSTGMEDIUM lpMedium);
  200. INTERNAL m_internal;
  201. // pointer to the ComponentDataObject
  202. private:
  203. IUnknown* m_pUnkComponentData;
  204. HRESULT SetComponentData(IUnknown* pUnkComponentData)
  205. {
  206. if (m_pUnkComponentData != NULL)
  207. {
  208. m_pUnkComponentData->Release();
  209. }
  210. m_pUnkComponentData = pUnkComponentData;
  211. if (m_pUnkComponentData != NULL)
  212. {
  213. m_pUnkComponentData->AddRef();
  214. }
  215. return S_OK;
  216. }
  217. HRESULT GetComponentData(IUnknown** ppUnkComponentData)
  218. {
  219. ASSERT(FALSE); // never called??? find out!
  220. if (ppUnkComponentData == NULL)
  221. {
  222. return E_POINTER;
  223. }
  224. *ppUnkComponentData = m_pUnkComponentData;
  225. if (m_pUnkComponentData != NULL)
  226. {
  227. m_pUnkComponentData->AddRef();
  228. }
  229. return S_OK;
  230. }
  231. CRootData* GetDataFromComponentDataObject();
  232. CTreeNode* GetTreeNodeFromCookie();
  233. friend class CComponentDataObject;
  234. };
  235. ///////////////////////////////////////////////////////////////////////////////
  236. // CDummyDataObject
  237. class CDummyDataObject : public IDataObject, public CComObjectRoot
  238. {
  239. // ATL Maps
  240. DECLARE_NOT_AGGREGATABLE(CDummyDataObject)
  241. BEGIN_COM_MAP(CDummyDataObject)
  242. COM_INTERFACE_ENTRY(IDataObject)
  243. END_COM_MAP()
  244. // Standard IDataObject methods
  245. public:
  246. STDMETHOD(GetData)(LPFORMATETC, LPSTGMEDIUM)
  247. { return E_NOTIMPL; };
  248. STDMETHOD(GetDataHere)(LPFORMATETC, LPSTGMEDIUM)
  249. { return E_NOTIMPL; };
  250. STDMETHOD(EnumFormatEtc)(DWORD, LPENUMFORMATETC*)
  251. { return E_NOTIMPL; };
  252. STDMETHOD(QueryGetData)(LPFORMATETC)
  253. { return E_NOTIMPL; };
  254. STDMETHOD(GetCanonicalFormatEtc)(LPFORMATETC, LPFORMATETC)
  255. { return E_NOTIMPL; };
  256. STDMETHOD(SetData)(LPFORMATETC, LPSTGMEDIUM, BOOL)
  257. { return E_NOTIMPL; };
  258. STDMETHOD(DAdvise)(LPFORMATETC, DWORD, LPADVISESINK, LPDWORD)
  259. { return E_NOTIMPL; };
  260. STDMETHOD(DUnadvise)(DWORD)
  261. { return E_NOTIMPL; };
  262. STDMETHOD(EnumDAdvise)(LPENUMSTATDATA*)
  263. { return E_NOTIMPL; };
  264. };
  265. #endif // _DATAOBJ_H