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.

321 lines
10 KiB

  1. // This is a part of the Microsoft Management Console.
  2. // Copyright (C) Microsoft Corporation, 1995 - 1999
  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. // CSnapin.h : Declaration of the CSnapin
  9. #ifndef _CSNAPIN_H_
  10. #define _CSNAPIN_H_
  11. #include "resource.h" // main symbols
  12. #ifndef __mmc_h__
  13. #include <mmc.h>
  14. #endif
  15. using namespace CertSrv;
  16. enum
  17. {
  18. // Identifiers for each of the commands/views to be inserted into the context menu.
  19. IDM_COMMAND1,
  20. IDM_COMMAND2,
  21. IDM_SAMPLE_OCX_VIEW,
  22. IDM_SAMPLE_WEB_VIEW
  23. };
  24. template <class TYPE>
  25. TYPE* Extract(LPDATAOBJECT lpDataObject, CLIPFORMAT cf);
  26. BOOL IsMMCMultiSelectDataObject(IDataObject* pDataObject);
  27. CLSID* ExtractClassID(LPDATAOBJECT lpDataObject);
  28. GUID* ExtractNodeType(LPDATAOBJECT lpDataObject);
  29. wchar_t* ExtractWorkstation(LPDATAOBJECT lpDataObject);
  30. INTERNAL* ExtractInternalFormat(LPDATAOBJECT lpDataObject);
  31. HRESULT _QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  32. CComponentDataImpl* pImpl, LPDATAOBJECT* ppDataObject);
  33. DWORD GetItemType(MMC_COOKIE cookie);
  34. /////////////////////////////////////////////////////////////////////////////
  35. // Snapin
  36. //
  37. // helper methods extracting data from data object
  38. //
  39. INTERNAL * ExtractInternalFormat(LPDATAOBJECT lpDataObject);
  40. wchar_t * ExtractWorkstation(LPDATAOBJECT lpDataObject);
  41. GUID * ExtractNodeType(LPDATAOBJECT lpDataObject);
  42. CLSID * ExtractClassID(LPDATAOBJECT lpDataObject);
  43. enum CUSTOM_VIEW_ID
  44. {
  45. VIEW_DEFAULT_LV = 0,
  46. VIEW_ERROR_OCX = 1,
  47. };
  48. class CSnapin :
  49. public IComponent,
  50. public IExtendContextMenu, // Step 3
  51. public IExtendControlbar,
  52. public IExtendPropertySheet,
  53. public IResultDataCompare,
  54. public IPersistStream,
  55. public CComObjectRoot
  56. {
  57. public:
  58. CSnapin();
  59. ~CSnapin();
  60. BEGIN_COM_MAP(CSnapin)
  61. COM_INTERFACE_ENTRY(IComponent)
  62. COM_INTERFACE_ENTRY(IExtendContextMenu) // Step 3
  63. COM_INTERFACE_ENTRY(IExtendControlbar)
  64. COM_INTERFACE_ENTRY(IExtendPropertySheet)
  65. COM_INTERFACE_ENTRY(IResultDataCompare)
  66. COM_INTERFACE_ENTRY(IPersistStream)
  67. END_COM_MAP()
  68. friend class CDataObject;
  69. static long lDataObjectRefCount;
  70. // IComponent interface members
  71. public:
  72. STDMETHOD(Initialize)(LPCONSOLE lpConsole);
  73. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  74. STDMETHOD(Destroy)(MMC_COOKIE cookie);
  75. STDMETHOD(GetResultViewType)(MMC_COOKIE cookie, LPOLESTR* ppViewType, long* pViewOptions);
  76. STDMETHOD(QueryDataObject)(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  77. LPDATAOBJECT* ppDataObject);
  78. STDMETHOD(GetDisplayInfo)(RESULTDATAITEM* pResultDataItem);
  79. STDMETHOD(CompareObjects)(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  80. // IResultDataCompare
  81. STDMETHOD(Compare)(LPARAM lUserParam, MMC_COOKIE cookieA, MMC_COOKIE cookieB, int* pnResult);
  82. // IExtendControlbar
  83. STDMETHOD(SetControlbar)(LPCONTROLBAR pControlbar);
  84. STDMETHOD(ControlbarNotify)(MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  85. // IExtendPropertySheet interface
  86. public:
  87. STDMETHOD(CreatePropertyPages)(LPPROPERTYSHEETCALLBACK lpProvider,
  88. LONG_PTR handle,
  89. LPDATAOBJECT lpIDataObject);
  90. STDMETHOD(QueryPagesFor)(LPDATAOBJECT lpDataObject);
  91. public:
  92. // IPersistStream interface members
  93. STDMETHOD(GetClassID)(CLSID *pClassID);
  94. STDMETHOD(IsDirty)();
  95. STDMETHOD(Load)(IStream *pStm);
  96. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty);
  97. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize);
  98. // Only for debug purpose
  99. bool m_bInitializedC;
  100. bool m_bLoadedC;
  101. bool m_bDestroyedC;
  102. // Helpers for CSnapin
  103. public:
  104. void SetIComponentData(CComponentDataImpl* pData);
  105. void GetItemName(LPDATAOBJECT lpDataObject, LPWSTR pszName, DWORD *pcName);
  106. BOOL IsPrimaryImpl()
  107. {
  108. CComponentDataImpl* pData =
  109. dynamic_cast<CComponentDataImpl*>(m_pComponentData);
  110. ASSERT(pData != NULL);
  111. if (pData != NULL)
  112. return pData->IsPrimaryImpl();
  113. return FALSE;
  114. }
  115. #if DBG==1
  116. public:
  117. int dbg_cRef;
  118. ULONG InternalAddRef()
  119. {
  120. ++dbg_cRef;
  121. return CComObjectRoot::InternalAddRef();
  122. }
  123. ULONG InternalRelease()
  124. {
  125. --dbg_cRef;
  126. return CComObjectRoot::InternalRelease();
  127. }
  128. #endif // DBG==1
  129. // Notify event handlers
  130. protected:
  131. HRESULT OnFolder(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  132. HRESULT OnAddImages(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  133. HRESULT OnShow(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  134. HRESULT OnDelete(LPDATAOBJECT lpDataObject, LPARAM arg, LPARAM param);
  135. HRESULT OnActivate(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  136. HRESULT OnMinimize(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  137. HRESULT OnPropertyChange(LPDATAOBJECT lpDataObject); // Step 3
  138. HRESULT OnUpdateView(LPDATAOBJECT lpDataObject);
  139. HRESULT OnResultItemClk(DATA_OBJECT_TYPES type, MMC_COOKIE cookie);
  140. HRESULT OnContextHelp(LPDATAOBJECT lpDataObject);
  141. void OnButtonClick(LPDATAOBJECT pdtobj, int idBtn);
  142. HRESULT QueryMultiSelectDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  143. LPDATAOBJECT* ppDataObject);
  144. // IExtendContextMenu
  145. public:
  146. STDMETHOD(AddMenuItems)(LPDATAOBJECT pDataObject, LPCONTEXTMENUCALLBACK pCallbackUnknown,
  147. long *pInsertionAllowed);
  148. STDMETHOD(Command)(long nCommandID, LPDATAOBJECT pDataObject);
  149. // End step 3
  150. // Helper functions
  151. protected:
  152. void Construct();
  153. void LoadResources();
  154. HRESULT InitializeHeaders(MMC_COOKIE cookie);
  155. HRESULT Enumerate(MMC_COOKIE cookie, HSCOPEITEM pParent);
  156. HRESULT EnumerateResultPane(MMC_COOKIE cookie);
  157. // Result pane helpers
  158. void RemoveResultItems(MMC_COOKIE cookie);
  159. void AddUser(CFolder* pFolder);
  160. void AddExtUser(CFolder* pFolder);
  161. void AddVirtual();
  162. HRESULT AddCACertTypesToResults(CFolder* pParentFolder);
  163. RESULT_DATA* GetVirtualResultItem(int iIndex);
  164. // UI Helpers
  165. void HandleStandardVerbs(bool bDeselectAll, LPARAM arg, LPDATAOBJECT lpDataObject);
  166. void HandleExtToolbars(bool bDeselectAll, LPARAM arg, LPARAM param);
  167. void HandleExtMenus(LPARAM arg, LPARAM param);
  168. void _OnRefresh(LPDATAOBJECT pDataObject);
  169. // Interface pointers
  170. protected:
  171. LPCONSOLE2 m_pConsole; // Console's IFrame interface
  172. LPHEADERCTRL m_pHeader; // Result pane's header control interface
  173. LPCOMPONENTDATA m_pComponentData;
  174. LPRESULTDATA m_pResult; // My interface pointer to the result pane
  175. LPIMAGELIST m_pImageResult; // My interface pointer to the result pane image list
  176. LPCONTROLBAR m_pControlbar; // control bar to hold my tool bars
  177. LPCONSOLEVERB m_pConsoleVerb; // pointer the console verb
  178. #ifdef INSERT_DEBUG_FOLDERS
  179. LPMENUBUTTON m_pMenuButton1; // Menu Button for view
  180. #endif // INSERT_DEBUG_FOLDERS
  181. LPTOOLBAR m_pSvrMgrToolbar1; // Toolbar for view
  182. CBitmap* m_pbmpSvrMgrToolbar1; // Imagelist for the toolbar
  183. CFolder* m_pCurrentlySelectedScopeFolder; // keep track of who has focus
  184. private:
  185. BOOL m_bIsDirty;
  186. CUSTOM_VIEW_ID m_CustomViewID;
  187. BOOL m_bVirtualView;
  188. DWORD m_dwVirtualSortOptions;
  189. void SetDirty(BOOL b = TRUE) { m_bIsDirty = b; }
  190. void ClearDirty() { m_bIsDirty = FALSE; }
  191. BOOL ThisIsDirty() { return m_bIsDirty; }
  192. };
  193. inline void CSnapin::SetIComponentData(CComponentDataImpl* pData)
  194. {
  195. ASSERT(pData);
  196. ASSERT(m_pComponentData == NULL);
  197. LPUNKNOWN pUnk = pData->GetUnknown();
  198. HRESULT hr;
  199. hr = pUnk->QueryInterface(IID_IComponentData, reinterpret_cast<void**>(&m_pComponentData));
  200. ASSERT(hr == S_OK);
  201. }
  202. class CCertTypeAboutImpl :
  203. public ISnapinAbout,
  204. public CComObjectRoot,
  205. public CComCoClass<CCertTypeAboutImpl, &CLSID_CertTypeAbout>
  206. {
  207. public:
  208. CCertTypeAboutImpl();
  209. ~CCertTypeAboutImpl();
  210. public:
  211. DECLARE_REGISTRY(CSnapin, _T("Snapin.PolicySettingsAbout.1"), _T("Snapin.PolicySettingsAbout"), IDS_SNAPIN_DESC, THREADFLAGS_BOTH)
  212. BEGIN_COM_MAP(CCertTypeAboutImpl)
  213. COM_INTERFACE_ENTRY(ISnapinAbout)
  214. END_COM_MAP()
  215. public:
  216. STDMETHOD(GetSnapinDescription)(LPOLESTR* lpDescription);
  217. STDMETHOD(GetProvider)(LPOLESTR* lpName);
  218. STDMETHOD(GetSnapinVersion)(LPOLESTR* lpVersion);
  219. STDMETHOD(GetSnapinImage)(HICON* hAppIcon);
  220. STDMETHOD(GetStaticFolderImage)(HBITMAP* hSmallImage,
  221. HBITMAP* hSmallImageOpen,
  222. HBITMAP* hLargeImage,
  223. COLORREF* cLargeMask);
  224. // Internal functions
  225. private:
  226. HRESULT AboutHelper(UINT nID, LPOLESTR* lpPtr);
  227. };
  228. class CCAPolicyAboutImpl :
  229. public ISnapinAbout,
  230. public CComObjectRoot,
  231. public CComCoClass<CCAPolicyAboutImpl, &CLSID_CAPolicyAbout>
  232. {
  233. public:
  234. CCAPolicyAboutImpl();
  235. ~CCAPolicyAboutImpl();
  236. public:
  237. DECLARE_REGISTRY(CSnapin, _T("Snapin.PolicySettingsAbout.1"), _T("Snapin.PolicySettingsAbout"), IDS_SNAPIN_DESC, THREADFLAGS_BOTH)
  238. BEGIN_COM_MAP(CCAPolicyAboutImpl)
  239. COM_INTERFACE_ENTRY(ISnapinAbout)
  240. END_COM_MAP()
  241. public:
  242. STDMETHOD(GetSnapinDescription)(LPOLESTR* lpDescription);
  243. STDMETHOD(GetProvider)(LPOLESTR* lpName);
  244. STDMETHOD(GetSnapinVersion)(LPOLESTR* lpVersion);
  245. STDMETHOD(GetSnapinImage)(HICON* hAppIcon);
  246. STDMETHOD(GetStaticFolderImage)(HBITMAP* hSmallImage,
  247. HBITMAP* hSmallImageOpen,
  248. HBITMAP* hLargeImage,
  249. COLORREF* cLargeMask);
  250. // Internal functions
  251. private:
  252. HRESULT AboutHelper(UINT nID, LPOLESTR* lpPtr);
  253. };
  254. #define FREE_DATA(pData) \
  255. ASSERT(pData != NULL); \
  256. do { if (pData != NULL) \
  257. GlobalFree(pData); } \
  258. while(0);
  259. #endif // #define _CSNAPIN_H_