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.

257 lines
8.1 KiB

  1. // DataObj.h : Internal data object structure for transfering clipboard formats.
  2. //
  3. // Copyright (c) 1998-1999 Microsoft Corporation
  4. #pragma once // MSINFO_DATAOBJ_H
  5. #define MSINFO_DATAOBJ_H
  6. #ifdef MSINFO_COMPDATA_H
  7. #error "DataObj.h must be included _before_ CompData.h"
  8. #endif // MSINFO_COMPDATA_H
  9. // This hack is required because we may be building in an environment
  10. // which doesn't have a late enough version of rpcndr.h
  11. #if __RPCNDR_H_VERSION__ < 440
  12. #define __RPCNDR_H_VERSION__ 440
  13. #define MIDL_INTERFACE(x) interface
  14. #endif
  15. #ifndef __mmc_h__
  16. #include <mmc.h>
  17. #endif // __mmc_h__
  18. #include "StdAfx.h"
  19. // Forward declaration.
  20. class CDataObject;
  21. #include "CompData.h"
  22. /*
  23. * CDataObject - The public interface for a unit of data.
  24. */
  25. class CDataObject : public IDataObject, public CComObjectRoot
  26. {
  27. DECLARE_NOT_AGGREGATABLE(CDataObject)
  28. BEGIN_COM_MAP(CDataObject)
  29. COM_INTERFACE_ENTRY(IDataObject)
  30. END_COM_MAP()
  31. friend class CSystemInfoScope;
  32. friend class CSystemInfo;
  33. public:
  34. CDataObject();
  35. virtual ~CDataObject();
  36. // Clipboard formats required by IConsole.
  37. public:
  38. static unsigned int m_cfNodeType;
  39. static unsigned int m_cfNodeTypeString;
  40. static unsigned int m_cfDisplayName;
  41. static unsigned int m_cfCoClass;
  42. static unsigned int m_cfMultiSel;
  43. static unsigned int m_cfMachineName;
  44. static unsigned int m_cfInternalObject;
  45. static unsigned int m_cfSnapinPreloads;
  46. // Internal clipboard formats?
  47. // static unsigned int m_cfInternal;
  48. // IDataObject interface implentation
  49. public:
  50. STDMETHOD(GetData)(LPFORMATETC lpFormatetc, LPSTGMEDIUM lpMedium);
  51. STDMETHOD(GetDataHere)(LPFORMATETC lpFormatetc, LPSTGMEDIUM lpMedium);
  52. STDMETHOD(EnumFormatEtc)(DWORD dwDirection, LPENUMFORMATETC *ppEnumFormatEtc);
  53. STDMETHOD(QueryGetData)(LPFORMATETC lpFormatetc);
  54. STDMETHOD(GetCanonicalFormatEtc)(LPFORMATETC lpFormatetcIn, LPFORMATETC lpFormatetcOut);
  55. STDMETHOD(SetData)(LPFORMATETC lpFormatetc, LPSTGMEDIUM lpMedium, BOOL bRelease);
  56. STDMETHOD(DAdvise)(LPFORMATETC lpFormatetc, DWORD advf, LPADVISESINK pAdvSink, LPDWORD pdwConnection);
  57. STDMETHOD(DUnadvise)(DWORD dwConnection);
  58. STDMETHOD(EnumDAdvise)(LPENUMSTATDATA *ppEnumAdvise);
  59. // Data Member Access Functions
  60. public:
  61. virtual CFolder *Category() const = 0;
  62. DATA_OBJECT_TYPES Context() const { return m_internal.m_type; }
  63. LPTSTR String() const { return m_internal.m_string; }
  64. MMC_COOKIE Cookie() const { return m_internal.m_cookie; }
  65. CLSID ClassID() const { return pComponentData()->GetCoClassID(); }
  66. CSystemInfoScope *pComponentData() const { ASSERT(m_pComponentData); return m_pComponentData; }
  67. void SetContext(DATA_OBJECT_TYPES type)
  68. { ASSERT(m_internal.m_type == CCT_UNINITIALIZED); m_internal.m_type = type; }
  69. void SetString(LPTSTR lpString) { m_internal.m_string = lpString; }
  70. void SetCookie(MMC_COOKIE cookie) { m_internal.m_cookie = cookie; }
  71. void SetComponentData(CSystemInfoScope *pCCD)
  72. {
  73. ASSERT(m_pComponentData == NULL && pCCD != NULL); m_pComponentData = pCCD;
  74. }
  75. CSystemInfoScope *m_pComponentData;
  76. protected:
  77. struct { MMC_COOKIE m_cookie; LPTSTR m_string; DATA_OBJECT_TYPES m_type; } m_internal;
  78. CDataSource *pSource() { return pComponentData()->pSource(); }
  79. // Internal helper functions.
  80. protected:
  81. static HRESULT CompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  82. // The function which returns a DataObject based on the context
  83. // information
  84. static HRESULT CreateDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  85. CSystemInfoScope *pScope, LPDATAOBJECT *ppDataObject);
  86. // The generic Create function which puts the appropriate amount of
  87. // lpMedium data into the pBuffer
  88. static HRESULT Create(const void *pBuffer, int size, LPSTGMEDIUM pMedium);
  89. // The specific functions which take the named member out of the
  90. // specified lpMedium.
  91. virtual HRESULT CreateCoClassID(LPSTGMEDIUM lpMedium);
  92. virtual HRESULT CreateDisplayName(LPSTGMEDIUM lpMedium) = 0;
  93. virtual HRESULT CreateNodeTypeData(LPSTGMEDIUM lpMedium) = 0;
  94. virtual HRESULT CreateNodeTypeStringData(LPSTGMEDIUM lpMedium) = 0;
  95. virtual HRESULT CreateSnapinPreloads(LPSTGMEDIUM lpMedium);
  96. virtual HRESULT CreateMachineName(LPSTGMEDIUM lpMedium);
  97. virtual HRESULT CreateInternalObject(LPSTGMEDIUM lpMedium);
  98. HRESULT CreateMultiSelData(LPSTGMEDIUM lpMedium);
  99. // Multiple selection data.
  100. protected:
  101. BYTE *m_pbMultiSelData;
  102. UINT m_cbMultiSelData;
  103. BOOL m_bMultiSelDobj;
  104. };
  105. /*
  106. * CScopeDataObject - The data object for scope items.
  107. *
  108. * History: a-jsari 9/25/97
  109. */
  110. class CScopeDataObject : public CDataObject {
  111. public:
  112. virtual CFolder *Category() const
  113. { return reinterpret_cast<CViewObject *>(Cookie())->Category(); }
  114. private:
  115. virtual HRESULT CreateDisplayName(LPSTGMEDIUM lpMedium);
  116. virtual HRESULT CreateNodeTypeData(LPSTGMEDIUM lpMedium);
  117. virtual HRESULT CreateNodeTypeStringData(LPSTGMEDIUM lpMedium);
  118. };
  119. /*
  120. * CResultDataObject - The DataObject for result items.
  121. *
  122. * History: a-jsari 9/25/97
  123. */
  124. class CResultDataObject : public CDataObject {
  125. public:
  126. virtual CFolder *Category() const { ASSERT(FALSE); return NULL; }
  127. private:
  128. virtual HRESULT CreateDisplayName(LPSTGMEDIUM lpMedium);
  129. virtual HRESULT CreateNodeTypeData(LPSTGMEDIUM lpMedium);
  130. virtual HRESULT CreateNodeTypeStringData(LPSTGMEDIUM lpMedium);
  131. };
  132. /*
  133. * CManagerDataObject - The DataObject for SNAPIN_MANAGER items.
  134. *
  135. * History: a-jsari 9/25/97
  136. */
  137. class CManagerDataObject : public CDataObject {
  138. public:
  139. virtual CFolder *Category() const
  140. { ASSERT(pComponentData()); return pComponentData()->pRootCategory(); }
  141. private:
  142. virtual HRESULT CreateDisplayName(LPSTGMEDIUM lpMedium);
  143. virtual HRESULT CreateNodeTypeData(LPSTGMEDIUM lpMedium);
  144. virtual HRESULT CreateNodeTypeStringData(LPSTGMEDIUM lpMedium);
  145. };
  146. /*
  147. * GetInternalFromDataObject - Return the CDataObject pointer represented by
  148. * the lpDataObject
  149. *
  150. * History: a-jsari 9/25/97 Initial version
  151. *
  152. * Note: It is essential that this pointer not be freed by the calling
  153. * function as it points to an existing DataObject.
  154. */
  155. inline CDataObject *GetInternalFromDataObject(LPDATAOBJECT lpDataObject)
  156. {
  157. ASSERT(lpDataObject != NULL);
  158. FORMATETC fetcInternal = {
  159. (unsigned short)CDataObject::m_cfInternalObject,
  160. NULL,
  161. DVASPECT_CONTENT,
  162. -1, /* All Data */
  163. TYMED_HGLOBAL
  164. };
  165. STGMEDIUM stgmInternal = { TYMED_HGLOBAL, NULL };
  166. CDataObject *cdoReturn = NULL;
  167. // CHECK: Make sure this gets propertly freed.
  168. stgmInternal.hGlobal = ::GlobalAlloc(GMEM_SHARE, sizeof(CDataObject **));
  169. do {
  170. HRESULT hr = lpDataObject->GetDataHere(&fetcInternal, &stgmInternal);
  171. ASSERT(stgmInternal.pUnkForRelease == NULL);
  172. if (hr != S_OK) break;
  173. cdoReturn = *(reinterpret_cast<CDataObject **>(::GlobalLock(stgmInternal.hGlobal)));
  174. ::GlobalUnlock(stgmInternal.hGlobal);
  175. // cdoReturn = *(reinterpret_cast<CDataObject **>(stgmInternal.hGlobal));
  176. } while (0);
  177. ::GlobalFree(stgmInternal.hGlobal);
  178. return cdoReturn;
  179. }
  180. /*
  181. * GetCookieFromDataObject - Returns the cookie contained by the object
  182. * represented by the lpDataObject interface.
  183. *
  184. * History: a-jsari 9/25/97
  185. */
  186. inline MMC_COOKIE GetCookieFromDataObject(LPDATAOBJECT lpDataObject)
  187. {
  188. CDataObject *cdoTemp = GetInternalFromDataObject(lpDataObject);
  189. // Root node for an extension snap-in.
  190. if (cdoTemp == NULL) return 0;
  191. return cdoTemp->Cookie();
  192. }
  193. /*
  194. * IsValidRegisteredClipboardFormat - Return a Boolean value telling whether
  195. * uFormatID is a valid clipboard format or not.
  196. *
  197. * History: a-jsari 9/25/97
  198. */
  199. inline bool IsValidRegisteredClipboardFormat(UINT uFormatID)
  200. {
  201. // return (uFormatID >= 0xc000 && uFormatID <= 0xffff);
  202. return (uFormatID != 0);
  203. }
  204. #if 0
  205. /*
  206. * IsMMCMultiSelectDataObject - Return a flag telling whether our data object refers
  207. * to a multiple item selection.
  208. *
  209. * History: a-jsari 9/25/97
  210. */
  211. inline BOOL IsMMCMultiSelectDataObject(LPDATAOBJECT lpDataObject)
  212. {
  213. static unsigned int m_cfMultiSelData = 0;
  214. if (m_cfMultiSelData == 0) {
  215. USES_CONVERSION;
  216. m_cfMultiSelData = RegisterClipboardFormat(W2T(CCF_MMC_MULTISELECT_DATAOBJECT));
  217. ASSERT(IsValidRegisteredClipboardFormat(m_cfMultiSelData));
  218. }
  219. /* const */ FORMATETC fmt = { (unsigned short) m_cfMultiSelData,
  220. NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  221. return lpDataObject->QueryGetData(&fmt) == S_OK;
  222. }
  223. #endif