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.

448 lines
15 KiB

  1. #ifndef _INC_DSKQUOTA_SNAPIN_H
  2. #define _INC_DSKQUOTA_SNAPIN_H
  3. ///////////////////////////////////////////////////////////////////////////////
  4. /* File: snapin.h
  5. Description: Declares classes used in the disk quota policy MMC snapin.
  6. Indentation indicates inheritance.
  7. Classes:
  8. CSnapInComp - implements IComponent.
  9. CSnapInCompData - implements IComponentData.
  10. CDataObject
  11. CSnapInItem - abstract base class for scope/result items.
  12. CScopeItem - MMC scope pane item
  13. CResultItem - MMC result pane item
  14. Revision History:
  15. Date Description Programmer
  16. -------- --------------------------------------------------- ----------
  17. 02/14/98 Initial creation. BrianAu
  18. 06/25/98 Disabled snapin code with #ifdef POLICY_MMC_SNAPIN. BrianAu
  19. Switching to ADM-file approach to entering policy
  20. data. Keeping snapin code available in case
  21. we decide to switch back at a later time.
  22. */
  23. ///////////////////////////////////////////////////////////////////////////////
  24. #ifdef POLICY_MMC_SNAPIN
  25. #ifndef __mmc_h__
  26. # include <mmc.h>
  27. #endif
  28. #ifndef _GPEDIT_H_
  29. # include <gpedit.h>
  30. #endif
  31. #ifndef _INC_DSKQUOTA_STRCLASS_H
  32. # include "strclass.h"
  33. #endif
  34. #ifndef _INC_DSKQUOTA_CARRAY_H
  35. # include "carray.h"
  36. #endif
  37. //
  38. // This CSnapInItem hierarchy represents the relationships between scope-pane
  39. // items and result-pane items. CSnapInItem contains data common to both
  40. // types of items. It also allows us to give the node mgr CSnapInItem ptrs
  41. // and use virtual functions to retrieve the proper type-specific data
  42. // when required.
  43. //
  44. // CSnapInItem (pure virtual)
  45. // |
  46. // is a
  47. // +--------------+---------------+
  48. // | |
  49. // | |
  50. // | |
  51. // CScopeItem ----- contains ---->> CResultItem
  52. //
  53. //
  54. class CSnapInCompData; // fwd decl.
  55. class CResultItem; // fwd decl.
  56. //
  57. // Pure virtual base class for snap-in scope items and result items.
  58. //
  59. class CSnapInItem
  60. {
  61. public:
  62. CSnapInItem(LPCTSTR pszDisplayName, int iImage)
  63. : m_strDisplayName(pszDisplayName),
  64. m_iImage(iImage)
  65. { DBGTRACE((DM_SNAPIN, DL_MID, TEXT("CSnapInItem::CSnapInItem"))); }
  66. virtual ~CSnapInItem(void)
  67. { DBGTRACE((DM_SNAPIN, DL_MID, TEXT("CSnapInItem::~CSnapInItem"))); }
  68. int ImageIndex(void) const
  69. { return m_iImage; }
  70. const CString& DisplayName(void) const
  71. { return m_strDisplayName; }
  72. //
  73. // All derived types must provide implementations for
  74. // NodeType and RenderData.
  75. //
  76. virtual const GUID& NodeType(void) const = 0;
  77. virtual HRESULT RenderData(UINT cf, LPSTGMEDIUM pMedium) const = 0;
  78. protected:
  79. //
  80. // Helper functions for rendering data.
  81. //
  82. static void GUIDToString(const GUID& guid, CString *pstr);
  83. static HRESULT RenderData(LPVOID pvData, int cbData, LPSTGMEDIUM pMedium);
  84. private:
  85. int m_iImage; // Index of image in imagelist.
  86. CString m_strDisplayName; // Item's display name string.
  87. //
  88. // Prevent copy.
  89. //
  90. CSnapInItem(const CSnapInItem& rhs);
  91. CSnapInItem& operator = (const CSnapInItem& rhs);
  92. };
  93. //
  94. // An item in the MMC scope pane.
  95. //
  96. class CScopeItem : public CSnapInItem
  97. {
  98. public:
  99. CScopeItem(const GUID& NodeType,
  100. const CSnapInCompData& cd,
  101. CScopeItem *pParent,
  102. LPCTSTR pszDisplayName,
  103. int iImage,
  104. int iImageOpen)
  105. : CSnapInItem(pszDisplayName, iImage),
  106. m_idType(NodeType),
  107. m_pParent(pParent),
  108. m_cd(cd),
  109. m_iOpenImage(iImageOpen)
  110. { DBGTRACE((DM_SNAPIN, DL_MID, TEXT("CScopeItem::CScopeItem"))); }
  111. virtual ~CScopeItem(void);
  112. int OpenImageIndex(void) const
  113. { return m_iOpenImage; }
  114. int NumChildren(void) const
  115. { return m_rgpChildren.Count(); }
  116. void AddChild(CScopeItem *pNode)
  117. { m_rgpChildren.Append(pNode); }
  118. CScopeItem *Child(int iChild) const
  119. { return m_rgpChildren[iChild]; }
  120. int NumResultItems(void) const
  121. { return m_rgpResultItems.Count(); }
  122. CResultItem *ResultItem(int iItem) const
  123. { return m_rgpResultItems[iItem]; }
  124. void AddResultItem(CResultItem *pItem)
  125. { m_rgpResultItems.Append(pItem); }
  126. virtual const GUID& NodeType(void) const
  127. { return m_idType; }
  128. virtual HRESULT RenderData(UINT cf, LPSTGMEDIUM pMedium) const;
  129. private:
  130. const GUID& m_idType; // Node type GUID.
  131. const CSnapInCompData& m_cd; // Snapin's component data.
  132. int m_iOpenImage; // Index of "open" image.
  133. CScopeItem *m_pParent; // Parent scope pane item.
  134. CArray<CScopeItem *> m_rgpChildren; // Scope pane children.
  135. CArray<CResultItem *> m_rgpResultItems; // Result items.
  136. //
  137. // Standard clipboard formats required by MMC.
  138. //
  139. static UINT m_cfNodeType;
  140. static UINT m_cfNodeTypeString;
  141. static UINT m_cfDisplayName;
  142. static UINT m_cfCoClass;
  143. //
  144. // Prevent copy.
  145. //
  146. CScopeItem(const CScopeItem& rhs);
  147. CScopeItem& operator = (const CScopeItem& rhs);
  148. };
  149. //
  150. // An item in the MMC result pane.
  151. //
  152. class CResultItem : public CSnapInItem
  153. {
  154. public:
  155. CResultItem(LPCTSTR pszDisplayName, int iImage, CScopeItem& si)
  156. : CSnapInItem(pszDisplayName, iImage),
  157. m_scopeItem(si)
  158. { DBGTRACE((DM_SNAPIN, DL_MID, TEXT("CResultItem::CResultItem"))); }
  159. virtual ~CResultItem(void)
  160. { DBGTRACE((DM_SNAPIN, DL_MID, TEXT("CResultItem::~CResultItem"))); }
  161. CScopeItem& ScopeItem(void) const
  162. { return m_scopeItem; }
  163. virtual const GUID& NodeType(void) const
  164. { return m_scopeItem.NodeType(); }
  165. virtual HRESULT RenderData(UINT cf, LPSTGMEDIUM pMedium) const
  166. { return m_scopeItem.RenderData(cf, pMedium); }
  167. private:
  168. CScopeItem& m_scopeItem; // Item's "owner" in scope pane.
  169. //
  170. // Prevent copy.
  171. //
  172. CResultItem(const CResultItem& rhs);
  173. CResultItem& operator = (const CResultItem& rhs);
  174. };
  175. //
  176. // Required implementation for IComponent.
  177. //
  178. class CSnapInComp : public IComponent,
  179. public IExtendContextMenu
  180. {
  181. public:
  182. CSnapInComp(HINSTANCE hInstance, CSnapInCompData& cd);
  183. ~CSnapInComp(void);
  184. HRESULT GetScopeItem(HSCOPEITEM hItem, CScopeItem **ppsi) const;
  185. //
  186. // IUnknown methods.
  187. //
  188. STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  189. STDMETHODIMP_(ULONG) AddRef(VOID);
  190. STDMETHODIMP_(ULONG) Release(VOID);
  191. //
  192. // IComponent methods.
  193. //
  194. STDMETHODIMP Initialize(LPCONSOLE lpConsole);
  195. STDMETHODIMP Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, long arg, long param);
  196. STDMETHODIMP Destroy(LONG cookie);
  197. STDMETHODIMP QueryDataObject(long cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT *ppDataObject);
  198. STDMETHODIMP GetResultViewType(long cookie, LPOLESTR *ppViewType, long *pViewOptions);
  199. STDMETHODIMP GetDisplayInfo(RESULTDATAITEM *pResultDataItem);
  200. STDMETHODIMP CompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  201. //
  202. // IExtendContextMenu methods.
  203. //
  204. STDMETHODIMP AddMenuItems(LPDATAOBJECT pDataObject, LPCONTEXTMENUCALLBACK piCallback, long *pInsertionAllowed);
  205. STDMETHODIMP Command(long lCommandID, LPDATAOBJECT pDataObject);
  206. private:
  207. LONG m_cRef; // COM ref count.
  208. HINSTANCE m_hInstance; // For getting resources.
  209. CSnapInCompData& m_cd; // Component's ComponentData
  210. LPCONSOLE m_pConsole; // The MMC console.
  211. LPRESULTDATA m_pResult; // The result pane.
  212. LPHEADERCTRL m_pHeader; // The result pane header ctrl.
  213. LPIMAGELIST m_pImageResult; // The result pane imagelist.
  214. CString m_strColumn; // Column header title.
  215. int m_cxColumn; // Column header width.
  216. long m_lViewMode; // Result pane view mode.
  217. //
  218. // Prevent copy.
  219. //
  220. CSnapInComp(const CSnapInComp& rhs);
  221. CSnapInComp& operator = (const CSnapInComp& rhs);
  222. };
  223. //
  224. // Custom interface for data object. Primary purpose is to distinguish
  225. // our data object from any other data object. This is done by calling
  226. // QI for IQuotaDataObject. If it succeeds, it's ours.
  227. //
  228. #undef INTERFACE
  229. #define INTERFACE IQuotaDataObject
  230. DECLARE_INTERFACE_(IQuotaDataObject, IUnknown)
  231. {
  232. // *** IUnknown methods ***
  233. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID * ppvObj) PURE;
  234. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  235. STDMETHOD_(ULONG,Release) (THIS) PURE;
  236. // *** IQuotaDataObject methods ***
  237. STDMETHOD(SetType) (THIS_ DATA_OBJECT_TYPES type) PURE;
  238. STDMETHOD(GetType) (THIS_ DATA_OBJECT_TYPES *type) PURE;
  239. STDMETHOD(SetItem) (THIS_ CSnapInItem *pItem) PURE;
  240. STDMETHOD(GetItem) (THIS_ CSnapInItem **pItem) PURE;
  241. };
  242. typedef IQuotaDataObject *LPQUOTADATAOBJECT;
  243. //
  244. // The snap-in's data object.
  245. //
  246. class CDataObject : public IDataObject,
  247. public IQuotaDataObject
  248. {
  249. public:
  250. CDataObject(CSnapInCompData& cd);
  251. ~CDataObject(void);
  252. //
  253. // IUnknown methods.
  254. //
  255. STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  256. STDMETHODIMP_(ULONG) AddRef(VOID);
  257. STDMETHODIMP_(ULONG) Release(VOID);
  258. //
  259. // IDataObject. All but GetDataHere are unimplemented.
  260. //
  261. STDMETHODIMP GetDataHere(FORMATETC *pFormatetc, STGMEDIUM *pmedium);
  262. STDMETHODIMP GetData(FORMATETC *pFormatetc, STGMEDIUM *pmedium)
  263. { return E_NOTIMPL; }
  264. STDMETHODIMP QueryGetData(FORMATETC *pFormatetc)
  265. { return E_NOTIMPL; }
  266. STDMETHODIMP GetCanonicalFormatEtc(FORMATETC *pFormatetcIn, FORMATETC *pFormatetcOut)
  267. { return E_NOTIMPL; }
  268. STDMETHODIMP SetData(FORMATETC *pFormatetc, STGMEDIUM *pmedium, BOOL fRelease)
  269. { return E_NOTIMPL; }
  270. STDMETHODIMP EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC **ppenumFormatetc)
  271. { return E_NOTIMPL; }
  272. STDMETHODIMP DAdvise(FORMATETC *pFormatetc, DWORD advf, IAdviseSink *pAdvSink, DWORD * pdwConnection)
  273. { return E_NOTIMPL; }
  274. STDMETHODIMP DUnadvise(DWORD dwConnection)
  275. { return E_NOTIMPL; }
  276. STDMETHODIMP EnumDAdvise(IEnumSTATDATA **ppenumAdvise)
  277. { return E_NOTIMPL; }
  278. //
  279. // IQuotaDataObject.
  280. //
  281. STDMETHODIMP SetType(DATA_OBJECT_TYPES type)
  282. { m_type = type; return S_OK; }
  283. STDMETHODIMP GetType(DATA_OBJECT_TYPES *type)
  284. { *type = m_type; return S_OK; }
  285. STDMETHODIMP SetItem(CSnapInItem *pItem)
  286. { m_pItem = pItem; return S_OK; }
  287. STDMETHODIMP GetItem(CSnapInItem **ppItem)
  288. { *ppItem = m_pItem; return S_OK; }
  289. private:
  290. LONG m_cRef; // COM ref count.
  291. CSnapInCompData& m_cd; // Related component data object.
  292. DATA_OBJECT_TYPES m_type; // Type defined by MMC.
  293. CSnapInItem *m_pItem; // Related snapin item.
  294. //
  295. // Prevent copy.
  296. //
  297. CDataObject(const CDataObject& rhs);
  298. CDataObject& operator = (const CDataObject& rhs);
  299. };
  300. //
  301. // Required implementation for IComponentData.
  302. //
  303. class CSnapInCompData : public IComponentData,
  304. public IPersistStreamInit,
  305. public IExtendContextMenu
  306. {
  307. public:
  308. //
  309. // Icon indexes in scope image list.
  310. //
  311. enum { iICON_QUOTA = 0,
  312. iICON_QUOTA_OPEN };
  313. CSnapInCompData(HINSTANCE hInstance, LPCTSTR pszDisplayName, const GUID& idClass);
  314. ~CSnapInCompData(void);
  315. const CString& DisplayName(void) const
  316. { return m_strDisplayName; }
  317. const GUID& ClassId(void) const
  318. { return m_idClass; }
  319. HRESULT OpenVolumeQuotaProperties(void);
  320. //
  321. // IUnknown methods.
  322. //
  323. STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  324. STDMETHODIMP_(ULONG) AddRef(VOID);
  325. STDMETHODIMP_(ULONG) Release(VOID);
  326. //
  327. // IComponentData methods.
  328. //
  329. STDMETHODIMP Initialize(LPUNKNOWN pUnknown);
  330. STDMETHODIMP CreateComponent (LPCOMPONENT *ppComponent);
  331. STDMETHODIMP Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, long arg, long param);
  332. STDMETHODIMP Destroy(void);
  333. STDMETHODIMP GetDisplayInfo(SCOPEDATAITEM *pScopeDataItem);
  334. STDMETHODIMP CompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  335. STDMETHODIMP QueryDataObject(long cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT *ppDataObject);
  336. //
  337. // IPersistStreamInit methods.
  338. //
  339. STDMETHODIMP GetClassID(CLSID *pClassID);
  340. STDMETHODIMP IsDirty(void);
  341. STDMETHODIMP Load(IStream *pStm);
  342. STDMETHODIMP Save(IStream *pStm, BOOL fClearDirty);
  343. STDMETHODIMP GetSizeMax(ULARGE_INTEGER *pcbSize);
  344. STDMETHODIMP InitNew(void);
  345. //
  346. // IExtendContextMenu methods.
  347. //
  348. STDMETHODIMP AddMenuItems(LPDATAOBJECT pDataObject, LPCONTEXTMENUCALLBACK piCallback, long *pInsertionAllowed);
  349. STDMETHODIMP Command(long lCommandID, LPDATAOBJECT pDataObject);
  350. private:
  351. LONG m_cRef; // obj ref counter.
  352. HINSTANCE m_hInstance; // for getting resources.
  353. CString m_strDisplayName; // Component's display name.
  354. const GUID& m_idClass; // Component's class ID.
  355. LPCONSOLE m_pConsole; // SnapIn mgr's console interface.
  356. LPCONSOLENAMESPACE m_pScope; // SnapIn mgr's scope interface.
  357. CScopeItem *m_pRootScopeItem; // Scope pane node tree root.
  358. HSCOPEITEM m_hRoot; // Root of extension's namespace
  359. LPGPEINFORMATION m_pGPEInformation;
  360. HRESULT EnumerateScopePane(HSCOPEITEM hParent);
  361. static BOOL CALLBACK AddPropSheetPage(HPROPSHEETPAGE hpage, LPARAM lParam);
  362. static DWORD PropPageThreadProc(LPVOID pvParam);
  363. //
  364. // Prevent copy.
  365. //
  366. CSnapInCompData(const CSnapInCompData& rhs);
  367. CSnapInCompData& operator = (const CSnapInCompData& rhs);
  368. friend class CSnapInComp;
  369. };
  370. #endif // POLICY_MMC_SNAPIN
  371. #endif // _INC_DSKQUOTA_SNAPIN_H