Leaked source code of windows server 2003
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.

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