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.

233 lines
9.6 KiB

  1. /*
  2. * componentdata.hxx
  3. *
  4. *
  5. * Copyright (c) 1998-1999 Microsoft Corporation
  6. *
  7. * PURPOSE: Defines the CComponentData class
  8. *
  9. *
  10. * OWNER: ptousig
  11. */
  12. #pragma once
  13. // -----------------------------------------------------------------------------
  14. // -----------------------------------------------------------------------------
  15. // -----------------------------------------------------------------------------
  16. // CComponentData
  17. //
  18. // This is the "document" of a snapin. In the case of a standalone snapin, one
  19. // of these is created for each root added under "Console Root".
  20. // For extension snapins, things are not quite that simple. In fact, there is
  21. // no rule as to when a ComponentData get constructed. MMC may change the
  22. // behavior at any time, so it is best not to make any assumption.
  23. //
  24. // This class is not the direct COM object, CComponentDataTemplate is the
  25. // actual COM object.
  26. //
  27. // $REVIEW (ptousig) For now, this is also the object MMC creates for a
  28. // context menu extension (or property sheet extension).
  29. // Creating a seperate class for these would mess up the
  30. // DECLARE_SNAPIN macros. The advantage of doing this would
  31. // not be worth the effort at this time.
  32. //
  33. class CComponentData : public IComponentData2,
  34. public IExtendContextMenu,
  35. public IExtendPropertySheet,
  36. public IResultDataCompareEx,
  37. public IPersistStreamInit,
  38. public ISnapinHelp,
  39. public CComObjectRoot
  40. {
  41. public:
  42. CComponentData(CBaseSnapin *psnapin);
  43. virtual ~CComponentData(void);
  44. public:
  45. //
  46. // Accessors
  47. //
  48. inline CBaseSnapin * Psnapin(void) { return m_psnapin;}
  49. inline IResultData * IpResultData(void) { return m_ipResultData;}
  50. inline IConsole * IpConsole(void) { return m_ipConsole;}
  51. inline IConsoleNameSpace * IpConsoleNameSpace(void) { return m_ipConsoleNameSpace;}
  52. inline IPropertySheetProvider *IpPropertySheetProvider(void) { return m_ipPropertySheetProvider;}
  53. inline BOOL FIsRealComponentData(void) { return m_fIsRealComponentData;}
  54. inline CBaseSnapinItem * PitemStandaloneRoot(void) { return m_pitemStandaloneRoot;}
  55. inline void SetPitemStandaloneRoot(CBaseSnapinItem *pitem) { m_pitemStandaloneRoot = pitem;}
  56. //
  57. // Shortcuts
  58. //
  59. CBaseSnapinItem * Pitem(LPDATAOBJECT lpDataObject = NULL, HSCOPEITEM hscopeitem = 0, long cookie = 0);
  60. inline const tstring& StrSnapinClassName(void) { return Psnapin()->StrClassName();}
  61. //
  62. // Other stuff
  63. //
  64. virtual SC ScCreateComponent(LPCOMPONENT * ppComponent) = 0;
  65. virtual SC ScOnDocumentChangeInsertItem(CBaseSnapinItem *pitemNew);
  66. virtual SC ScWasExpandedOnce(CBaseSnapinItem *pitem, BOOL *pfWasExpanded);
  67. virtual SC ScRegister(BOOL fRegister);
  68. static HRESULT WINAPI UpdateRegistry(BOOL fRegister) { return S_OK;} // needed by ATL
  69. public:
  70. //
  71. // "Sc" version of IComponentData2 interface
  72. //
  73. virtual SC ScInitialize(LPUNKNOWN pUnknown);
  74. virtual SC ScNotify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, long arg, long param);
  75. virtual SC ScDestroy(void);
  76. virtual SC ScGetDisplayInfo(LPSCOPEDATAITEM pScopeItem);
  77. virtual SC ScQueryDataObject(long cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject);
  78. virtual SC ScQueryDispatch(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDISPATCH* ppDispatch);
  79. //
  80. // "Sc" version of IExtendContextMenu interface
  81. //
  82. virtual SC ScCommand(long nCommandID, LPDATAOBJECT pDataObject);
  83. //
  84. // "Sc" version of IExtendPropertySheet interface
  85. //
  86. virtual SC ScCreatePropertyPages(LPPROPERTYSHEETCALLBACK ipPropertySheetCallback, long handle, LPDATAOBJECT pDataObject);
  87. virtual SC ScQueryPagesFor(LPDATAOBJECT lpDataObject);
  88. //
  89. // "Sc" version of IPersistStreamInit interface
  90. //
  91. virtual SC ScLoad(IStream *pstream);
  92. virtual SC ScSave(IStream *pstream, BOOL fClearDirty);
  93. virtual SC ScIsDirty(void);
  94. //
  95. // Notifications
  96. //
  97. virtual SC ScOnExpand(LPDATAOBJECT lpDataObject, BOOL fExpand, HSCOPEITEM hscopeitem);
  98. virtual SC ScOnExpandSync(LPDATAOBJECT lpDataObject, MMC_EXPANDSYNC_STRUCT *pmes);
  99. virtual SC ScOnRemoveChildren(LPDATAOBJECT lpDataObject, HSCOPEITEM hscopeitem);
  100. virtual SC ScOnDelete(LPDATAOBJECT lpDataObject);
  101. virtual SC ScOnButtonClick(LPDATAOBJECT lpDataObject, MMC_CONSOLE_VERB mcvVerb);
  102. public:
  103. //
  104. // IComponentData2 interface
  105. //
  106. STDMETHOD(CompareObjects) (LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  107. STDMETHOD(GetDisplayInfo) (LPSCOPEDATAITEM pItem);
  108. STDMETHOD(QueryDataObject) (long cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT * ppDataObject);
  109. STDMETHOD(Notify) (LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, long arg, long param);
  110. STDMETHOD(CreateComponent) (LPCOMPONENT * ppComponent);
  111. STDMETHOD(Initialize) (LPUNKNOWN pUnknown);
  112. STDMETHOD(Destroy) (void);
  113. STDMETHOD(QueryDispatch) (MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDISPATCH* ppDispatch);
  114. //
  115. // IExtendContextMenu interface
  116. //
  117. STDMETHOD(AddMenuItems) (LPDATAOBJECT pDataObject, LPCONTEXTMENUCALLBACK ipContextMenuCallback, long *pInsertionAllowed);
  118. STDMETHOD(Command) (long nCommandID, LPDATAOBJECT pDataObject);
  119. //
  120. // IExtendPropertySheet interface
  121. //
  122. STDMETHOD(CreatePropertyPages) (LPPROPERTYSHEETCALLBACK lpProvider, long handle, LPDATAOBJECT lpDataObject);
  123. STDMETHOD(QueryPagesFor) (LPDATAOBJECT lpDataObject);
  124. //
  125. // IResultDataCompareEx interface
  126. //
  127. STDMETHOD(Compare) (RDCOMPARE * prdc, int * pnResult);
  128. //
  129. // IPersistStreamInit interface
  130. //
  131. STDMETHOD(GetClassID) (CLSID *pclsid);
  132. STDMETHOD(IsDirty) (void);
  133. STDMETHOD(Load) (IStream *pstream);
  134. STDMETHOD(Save) (IStream *pstream, BOOL fClearDirty);
  135. STDMETHOD(GetSizeMax) (ULARGE_INTEGER *pcbSize);
  136. STDMETHOD(InitNew) (void);
  137. //
  138. // ISnapinHelp interface
  139. //
  140. STDMETHOD(GetHelpTopic) (LPOLESTR *lpCompiledHelpFile);
  141. private:
  142. CBaseSnapin * m_psnapin;
  143. // The component data keep track of their own standalone
  144. // root item.
  145. CBaseSnapinItem * m_pitemStandaloneRoot;
  146. // This will be set to FALSE until IComponentData::Initialize
  147. // is called. Context menu extensions will always be FALSE.
  148. BOOL m_fIsRealComponentData;
  149. // Interface pointers
  150. IConsolePtr m_ipConsole;
  151. IConsoleNameSpacePtr m_ipConsoleNameSpace;
  152. IPropertySheetProviderPtr m_ipPropertySheetProvider;
  153. IResultDataPtr m_ipResultData;
  154. };
  155. // -----------------------------------------------------------------------------
  156. // -----------------------------------------------------------------------------
  157. // -----------------------------------------------------------------------------
  158. // CComponentDataTemplate
  159. //
  160. // This template class is used to make the link between the ComponentData and
  161. // the CBaseSnapin.
  162. //
  163. // Parameters:
  164. // TSnapin The CBaseSnapin-derived class.
  165. // TComponent The CComponent-derived class.
  166. // pclsid Needed by CComCoClass
  167. //
  168. // The TComponent parameter will always be CComponent at the moment. In the
  169. // future, individual snapins might provide their own CComponent-derived classes.
  170. //
  171. template <class TSnapin, class TComponent, const CLSID* pclsid>
  172. class CComponentDataTemplate : public CComponentData,
  173. public CComCoClass< CComponentDataTemplate<TSnapin, TComponent, pclsid>, pclsid >
  174. {
  175. typedef CComponentDataTemplate<TSnapin, TComponent, pclsid> t_self;
  176. BEGIN_COM_MAP(t_self)
  177. COM_INTERFACE_ENTRY(IComponentData)
  178. COM_INTERFACE_ENTRY(IComponentData2)
  179. COM_INTERFACE_ENTRY(IExtendContextMenu)
  180. COM_INTERFACE_ENTRY(IExtendPropertySheet)
  181. COM_INTERFACE_ENTRY(IResultDataCompareEx)
  182. COM_INTERFACE_ENTRY(IPersistStreamInit)
  183. COM_INTERFACE_ENTRY(ISnapinHelp)
  184. END_COM_MAP()
  185. DECLARE_NOT_AGGREGATABLE(t_self);
  186. public:
  187. //
  188. // Construct the base class with the CBaseSnapin * stored in the static
  189. // variable s_snapin of the individual snapin.
  190. //
  191. CComponentDataTemplate(void) : CComponentData(&TSnapin::s_snapin)
  192. {
  193. }
  194. //
  195. // This is where we create new instances of CComponent.
  196. //
  197. virtual SC ScCreateComponent(LPCOMPONENT *ppComponent)
  198. {
  199. typedef CComObject<TComponent> t_ComponentInstance;
  200. SC sc = S_OK;
  201. t_ComponentInstance *pComponent = NULL;
  202. t_ComponentInstance::CreateInstance(&pComponent);
  203. pComponent->SetComponentData(this);
  204. sc = pComponent->QueryInterface(IID_IComponent, reinterpret_cast<void**>(ppComponent));
  205. return sc;
  206. }
  207. };