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.

332 lines
11 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. typedef struct _MY_MMCBUTTON
  16. {
  17. MMCBUTTON item;
  18. UINT uiString1;
  19. UINT uiString2;
  20. WCHAR szString1[MAX_RESOURCE_STRLEN];
  21. WCHAR szString2[MAX_RESOURCE_STRLEN];
  22. } MY_MMCBUTTON, *PMY_MMCBUTTON;
  23. MY_MMCBUTTON SvrMgrToolbar1Buttons[];
  24. // File Versions
  25. // current version
  26. #define VER_CSNAPIN_SAVE_STREAM_3 0x03
  27. // includes m_dwViewID, m_RowEnum
  28. // version written through Win2000 beta 3
  29. #define VER_CSNAPIN_SAVE_STREAM_2 0x02
  30. /////////////////////////////
  31. template <class TYPE>
  32. TYPE* Extract(LPDATAOBJECT lpDataObject, CLIPFORMAT cf);
  33. CLSID* ExtractClassID(LPDATAOBJECT lpDataObject);
  34. GUID* ExtractNodeType(LPDATAOBJECT lpDataObject);
  35. INTERNAL* ExtractInternalFormat(LPDATAOBJECT lpDataObject);
  36. BOOL IsMMCMultiSelectDataObject(IDataObject* pDataObject);
  37. HRESULT _QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, DWORD dwViewID,
  38. CComponentDataImpl* pImpl, LPDATAOBJECT* ppDataObject);
  39. CFolder* GetParentFolder(INTERNAL* pInternal);
  40. /////////////////////////////////////////////////////////////////////////////
  41. // Snapin
  42. //
  43. // helper methods extracting data from data object
  44. //
  45. INTERNAL * ExtractInternalFormat(LPDATAOBJECT lpDataObject);
  46. wchar_t * ExtractWorkstation(LPDATAOBJECT lpDataObject);
  47. GUID * ExtractNodeType(LPDATAOBJECT lpDataObject);
  48. CLSID * ExtractClassID(LPDATAOBJECT lpDataObject);
  49. #define g_szEmptyHeader L" "
  50. enum CUSTOM_VIEW_ID
  51. {
  52. VIEW_DEFAULT_LV = 0,
  53. VIEW_MICROSOFT_URL = 2,
  54. };
  55. class CSnapin :
  56. public IComponent,
  57. public IExtendPropertySheet,
  58. public IExtendContextMenu,
  59. public IExtendControlbar,
  60. public IResultDataCompare,
  61. public IResultOwnerData,
  62. public IPersistStream,
  63. public CComObjectRoot
  64. {
  65. public:
  66. CSnapin();
  67. virtual ~CSnapin();
  68. BEGIN_COM_MAP(CSnapin)
  69. COM_INTERFACE_ENTRY(IComponent)
  70. COM_INTERFACE_ENTRY(IExtendPropertySheet)
  71. COM_INTERFACE_ENTRY(IExtendContextMenu)
  72. COM_INTERFACE_ENTRY(IExtendControlbar)
  73. COM_INTERFACE_ENTRY(IResultDataCompare)
  74. COM_INTERFACE_ENTRY(IResultOwnerData)
  75. COM_INTERFACE_ENTRY(IPersistStream)
  76. END_COM_MAP()
  77. // IComponent interface members
  78. public:
  79. STDMETHOD(Initialize)(LPCONSOLE lpConsole);
  80. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  81. STDMETHOD(Destroy)(MMC_COOKIE cookie);
  82. STDMETHOD(GetResultViewType)(MMC_COOKIE cookie, LPOLESTR* ppViewType, LONG* pViewOptions);
  83. STDMETHOD(QueryDataObject)(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  84. LPDATAOBJECT* ppDataObject);
  85. STDMETHOD(GetDisplayInfo)(RESULTDATAITEM* pResultDataItem);
  86. STDMETHOD(CompareObjects)(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  87. // IResultDataCompare
  88. STDMETHOD(Compare)(LPARAM lUserParam, MMC_COOKIE cookieA, MMC_COOKIE cookieB, int* pnResult);
  89. // IResultOwnerData
  90. STDMETHOD(FindItem)(LPRESULTFINDINFO pFindInfo, int* pnFoundIndex);
  91. STDMETHOD(CacheHint)(int nStartIndex, int nEndIndex);
  92. STDMETHOD(SortItems)(int nColumn, DWORD dwSortOptions, LPARAM lUserParam);
  93. // IExtendPropertySheet interface
  94. public:
  95. STDMETHOD(CreatePropertyPages)(LPPROPERTYSHEETCALLBACK lpProvider,
  96. LONG_PTR handle,
  97. LPDATAOBJECT lpIDataObject);
  98. STDMETHOD(QueryPagesFor)(LPDATAOBJECT lpDataObject);
  99. // IExtendControlbar
  100. STDMETHOD(SetControlbar)(LPCONTROLBAR pControlbar);
  101. STDMETHOD(ControlbarNotify)(MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  102. public:
  103. // IPersistStream interface members
  104. STDMETHOD(GetClassID)(CLSID *pClassID);
  105. STDMETHOD(IsDirty)();
  106. STDMETHOD(Load)(IStream *pStm);
  107. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty);
  108. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize);
  109. // Only for debug purpose
  110. bool m_bInitializedC;
  111. bool m_bLoadedC;
  112. bool m_bDestroyedC;
  113. // Helpers for CSnapin
  114. public:
  115. void SmartEnableServiceControlButtons();
  116. void SetIComponentData(CComponentDataImpl* pData);
  117. // void RefreshFolder(CFolder* pFolder);
  118. CFolder* GetVirtualFolder();
  119. CFolder* GetParentFolder(INTERNAL* pInternal);
  120. BOOL IsPrimaryImpl()
  121. {
  122. CComponentDataImpl* pData =
  123. dynamic_cast<CComponentDataImpl*>(m_pComponentData);
  124. ASSERT(pData != NULL);
  125. if (pData != NULL)
  126. return pData->IsPrimaryImpl();
  127. return FALSE;
  128. }
  129. void SetViewID(DWORD id) { m_dwViewID = id; }
  130. #if DBG
  131. public:
  132. int dbg_cRef;
  133. ULONG InternalAddRef()
  134. {
  135. ++dbg_cRef;
  136. return CComObjectRoot::InternalAddRef();
  137. }
  138. ULONG InternalRelease()
  139. {
  140. --dbg_cRef;
  141. return CComObjectRoot::InternalRelease();
  142. }
  143. #endif // DBG
  144. // Notify event handlers
  145. protected:
  146. HRESULT OnAddImages(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  147. HRESULT OnShow(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  148. HRESULT OnUpdateView(LPDATAOBJECT lpDataObject, LPARAM arg);
  149. HRESULT OnContextHelp(LPDATAOBJECT lpDataObject);
  150. void OnButtonClick(LPDATAOBJECT pdtobj, int idBtn);
  151. HRESULT QueryMultiSelectDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  152. LPDATAOBJECT* ppDataObject);
  153. // IExtendContextMenu
  154. public:
  155. STDMETHOD(AddMenuItems)(LPDATAOBJECT pDataObject,
  156. LPCONTEXTMENUCALLBACK pCallbackUnknown,
  157. LONG *pInsertionAllowed);
  158. STDMETHOD(Command)(LONG nCommandID, LPDATAOBJECT pDataObject);
  159. // Helper functions
  160. protected:
  161. BOOL IsEnumerating(LPDATAOBJECT lpDataObject);
  162. void Construct();
  163. HRESULT GetColumnSetData(MMC_COOKIE cookie, MMC_COLUMN_SET_DATA** ppColSetData);
  164. HRESULT GetColumnSortData(MMC_COOKIE cookie, int* piColSortIdx, BOOL* pfAscending);
  165. HRESULT BuildTemplateDisplayName(
  166. LPCWSTR pcwszFriendlyName,
  167. LPCWSTR pcwszTemplateName,
  168. VARIANT& varDisplayName);
  169. HRESULT InitializeHeaders(MMC_COOKIE cookie);
  170. HRESULT InsertAllColumns(MMC_COOKIE cookie, CertViewRowEnum* pCertViewRowEnum);
  171. HRESULT DoInsertAllColumns(MMC_COLUMN_SET_DATA* pCols);
  172. HRESULT SynchColumns(MMC_COOKIE cookie);
  173. // Result Helpers
  174. HRESULT GetRowColContents(CFolder* pFolder, LONG idxRow, LPCWSTR szColHead, PBYTE* ppbData, DWORD* pcbData, BOOL fStringFmt=FALSE);
  175. HRESULT GetCellContents(CertViewRowEnum* pCRowEnum, CertSvrCA* pCA, LONG idxRow, LONG idxCol, PBYTE pbData, DWORD* pcbData, BOOL fStringFmt);
  176. // UI Helpers
  177. void HandleStandardVerbs(bool bDeselectAll, LPARAM arg, LPDATAOBJECT lpDataObject);
  178. void HandleExtToolbars(bool bDeselectAll, LPARAM arg, LPARAM param);
  179. void HandleExtMenus(LPARAM arg, LPARAM param);
  180. void OnRefresh(LPDATAOBJECT pDataObject);
  181. // Interface pointers
  182. protected:
  183. LPCONSOLE2 m_pConsole; // Console's IFrame interface
  184. LPHEADERCTRL m_pHeader; // Result pane's header control interface
  185. LPCOMPONENTDATA m_pComponentData;
  186. LPRESULTDATA m_pResult; // My interface pointer to the result pane
  187. LPIMAGELIST m_pImageResult; // My interface pointer to the result pane image list
  188. LPCONTROLBAR m_pControlbar; // control bar to hold my tool bars
  189. LPCONSOLEVERB m_pConsoleVerb; // pointer the console verb
  190. LPTOOLBAR m_pSvrMgrToolbar1; // Toolbar for view
  191. LPCOLUMNDATA m_pViewData; // info on our columns
  192. CFolder* m_pCurrentlySelectedScopeFolder; // keep track of who has focus
  193. // all interesting view data here
  194. CertViewRowEnum m_RowEnum;
  195. private:
  196. BOOL m_bIsDirty;
  197. CUSTOM_VIEW_ID m_CustomViewID;
  198. BOOL m_bVirtualView;
  199. // HACK HACK
  200. // used to override the sort order on MMCN_CLICK notifications --
  201. // the view data isn't set early enough in the process for us to use it
  202. // This must remain with view, there might be multiple near-simultaneous clicks happening
  203. typedef struct _COLCLICK_SORT_OVERRIDE
  204. {
  205. BOOL fClickOverride;
  206. int colIdx;
  207. DWORD dwOptions;
  208. } COLCLICK_SORT_OVERRIDE;
  209. COLCLICK_SORT_OVERRIDE m_ColSortOverride;
  210. // HACK HACK
  211. // used to override the column selection on MMCN_COLUMNS_CHANGED notifications --
  212. // the view data isn't set early enough in the process for us to use it
  213. // This must remain with view, there might be multiple near-simultaneous insertions happening
  214. typedef struct _COLCLICK_SET_OVERRIDE
  215. {
  216. BOOL fClickOverride;
  217. MMC_COLUMN_SET_DATA* pColSetData;
  218. } COLCLICK_SET_OVERRIDE;
  219. COLCLICK_SET_OVERRIDE m_ColSetOverride;
  220. // result row flag
  221. DWORD m_dwKnownResultRows;
  222. DWORD KnownResultRows() { return m_dwKnownResultRows; };
  223. void SetKnowResultRows(DWORD dwRows) { m_dwKnownResultRows = dwRows; };
  224. void ResetKnowResultRows() { m_dwKnownResultRows = 1; m_dwViewErrorMsg = S_OK; };
  225. DWORD m_dwViewErrorMsg;
  226. CString m_cstrViewErrorMsg;
  227. // keeps our col views seperate
  228. DWORD m_dwViewID;
  229. // counter used to protect from reentrancy in ICertView (bug 339811)
  230. LONG m_cViewCalls;
  231. void SetDirty(BOOL b = TRUE) { m_bIsDirty = b; }
  232. void ClearDirty() { m_bIsDirty = FALSE; }
  233. BOOL ThisIsDirty() { return m_bIsDirty; }
  234. };
  235. class CSnapinAboutImpl :
  236. public ISnapinAbout,
  237. public CComObjectRoot,
  238. public CComCoClass<CSnapinAboutImpl, &CLSID_About>
  239. {
  240. public:
  241. CSnapinAboutImpl();
  242. ~CSnapinAboutImpl();
  243. public:
  244. DECLARE_REGISTRY(CSnapin, _T("Snapin.About.1"), _T("Snapin.About"), IDS_SNAPIN_DESC, THREADFLAGS_BOTH)
  245. BEGIN_COM_MAP(CSnapinAboutImpl)
  246. COM_INTERFACE_ENTRY(ISnapinAbout)
  247. END_COM_MAP()
  248. public:
  249. STDMETHOD(GetSnapinDescription)(LPOLESTR* lpDescription);
  250. STDMETHOD(GetProvider)(LPOLESTR* lpName);
  251. STDMETHOD(GetSnapinVersion)(LPOLESTR* lpVersion);
  252. STDMETHOD(GetSnapinImage)(HICON* hAppIcon);
  253. STDMETHOD(GetStaticFolderImage)(HBITMAP* hSmallImage,
  254. HBITMAP* hSmallImageOpen,
  255. HBITMAP* hLargeImage,
  256. COLORREF* cLargeMask);
  257. // Internal functions
  258. private:
  259. HRESULT AboutHelper(UINT nID, LPOLESTR* lpPtr);
  260. };
  261. #endif // #define _CSNAPIN_H_