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.

326 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. CFolder* GetVirtualFolder();
  170. CFolder* GetParentFolder(INTERNAL* pInternal);
  171. // Interface pointers
  172. protected:
  173. LPCONSOLE2 m_pConsole; // Console's IFrame interface
  174. LPHEADERCTRL m_pHeader; // Result pane's header control interface
  175. LPCOMPONENTDATA m_pComponentData;
  176. LPRESULTDATA m_pResult; // My interface pointer to the result pane
  177. LPIMAGELIST m_pImageResult; // My interface pointer to the result pane image list
  178. LPCONTROLBAR m_pControlbar; // control bar to hold my tool bars
  179. LPCONSOLEVERB m_pConsoleVerb; // pointer the console verb
  180. #ifdef INSERT_DEBUG_FOLDERS
  181. LPMENUBUTTON m_pMenuButton1; // Menu Button for view
  182. #endif // INSERT_DEBUG_FOLDERS
  183. LPTOOLBAR m_pSvrMgrToolbar1; // Toolbar for view
  184. CBitmap* m_pbmpSvrMgrToolbar1; // Imagelist for the toolbar
  185. CFolder* m_pCurrentlySelectedScopeFolder; // keep track of who has focus
  186. private:
  187. BOOL m_bIsDirty;
  188. CUSTOM_VIEW_ID m_CustomViewID;
  189. BOOL m_bVirtualView;
  190. DWORD m_dwVirtualSortOptions;
  191. void SetDirty(BOOL b = TRUE) { m_bIsDirty = b; }
  192. void ClearDirty() { m_bIsDirty = FALSE; }
  193. BOOL ThisIsDirty() { return m_bIsDirty; }
  194. };
  195. inline void CSnapin::SetIComponentData(CComponentDataImpl* pData)
  196. {
  197. ASSERT(pData);
  198. ASSERT(m_pComponentData == NULL);
  199. LPUNKNOWN pUnk = pData->GetUnknown();
  200. HRESULT hr;
  201. hr = pUnk->QueryInterface(IID_IComponentData, reinterpret_cast<void**>(&m_pComponentData));
  202. ASSERT(hr == S_OK);
  203. }
  204. class CCertTypeAboutImpl :
  205. public ISnapinAbout,
  206. public CComObjectRoot,
  207. public CComCoClass<CCertTypeAboutImpl, &CLSID_CertTypeAbout>
  208. {
  209. public:
  210. CCertTypeAboutImpl();
  211. ~CCertTypeAboutImpl();
  212. public:
  213. DECLARE_REGISTRY(CSnapin, _T("Snapin.PolicySettingsAbout.1"), _T("Snapin.PolicySettingsAbout"), IDS_SNAPIN_DESC, THREADFLAGS_BOTH)
  214. BEGIN_COM_MAP(CCertTypeAboutImpl)
  215. COM_INTERFACE_ENTRY(ISnapinAbout)
  216. END_COM_MAP()
  217. public:
  218. STDMETHOD(GetSnapinDescription)(LPOLESTR* lpDescription);
  219. STDMETHOD(GetProvider)(LPOLESTR* lpName);
  220. STDMETHOD(GetSnapinVersion)(LPOLESTR* lpVersion);
  221. STDMETHOD(GetSnapinImage)(HICON* hAppIcon);
  222. STDMETHOD(GetStaticFolderImage)(HBITMAP* hSmallImage,
  223. HBITMAP* hSmallImageOpen,
  224. HBITMAP* hLargeImage,
  225. COLORREF* cLargeMask);
  226. // Internal functions
  227. private:
  228. HRESULT AboutHelper(UINT nID, LPOLESTR* lpPtr);
  229. HRESULT AboutHelper2(LPSTR str, LPOLESTR* lpPtr);
  230. };
  231. class CCAPolicyAboutImpl :
  232. public ISnapinAbout,
  233. public CComObjectRoot,
  234. public CComCoClass<CCAPolicyAboutImpl, &CLSID_CAPolicyAbout>
  235. {
  236. public:
  237. CCAPolicyAboutImpl();
  238. ~CCAPolicyAboutImpl();
  239. public:
  240. DECLARE_REGISTRY(CSnapin, _T("Snapin.PolicySettingsAbout.1"), _T("Snapin.PolicySettingsAbout"), IDS_SNAPIN_DESC, THREADFLAGS_BOTH)
  241. BEGIN_COM_MAP(CCAPolicyAboutImpl)
  242. COM_INTERFACE_ENTRY(ISnapinAbout)
  243. END_COM_MAP()
  244. public:
  245. STDMETHOD(GetSnapinDescription)(LPOLESTR* lpDescription);
  246. STDMETHOD(GetProvider)(LPOLESTR* lpName);
  247. STDMETHOD(GetSnapinVersion)(LPOLESTR* lpVersion);
  248. STDMETHOD(GetSnapinImage)(HICON* hAppIcon);
  249. STDMETHOD(GetStaticFolderImage)(HBITMAP* hSmallImage,
  250. HBITMAP* hSmallImageOpen,
  251. HBITMAP* hLargeImage,
  252. COLORREF* cLargeMask);
  253. // Internal functions
  254. private:
  255. HRESULT AboutHelper(UINT nID, LPOLESTR* lpPtr);
  256. HRESULT AboutHelper2(LPSTR str, LPOLESTR* lpPtr);
  257. };
  258. #define FREE_DATA(pData) \
  259. ASSERT(pData != NULL); \
  260. do { if (pData != NULL) \
  261. GlobalFree(pData); } \
  262. while(0);
  263. #endif // #define _CSNAPIN_H_