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.

415 lines
13 KiB

  1. // This is a part of the Microsoft Management Console.
  2. // Copyright 1995 - 1997 Microsoft Corporation
  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. #include "resource.h" // main symbols
  10. #ifndef __mmc_h__
  11. #include <mmc.h>
  12. #endif
  13. class CFolder;
  14. // Note - This is the offset in my image list that represents the folder
  15. const FOLDER_IMAGE_IDX = 0;
  16. const OPEN_FOLDER_IMAGE_IDX = 5;
  17. const USER_IMAGE = 2;
  18. const COMPANY_IMAGE = 3;
  19. const VIRTUAL_IMAGE = 4;
  20. /////////////////////////////////////////////////////////////////////////////
  21. // Snapin
  22. //
  23. // helper methods extracting data from data object
  24. //
  25. INTERNAL * ExtractInternalFormat(LPDATAOBJECT lpDataObject);
  26. wchar_t * ExtractWorkstation(LPDATAOBJECT lpDataObject);
  27. GUID * ExtractNodeType(LPDATAOBJECT lpDataObject);
  28. CLSID * ExtractClassID(LPDATAOBJECT lpDataObject);
  29. class CComponentDataImpl:
  30. public IComponentData,
  31. public IExtendPropertySheet2,
  32. public IExtendContextMenu,
  33. public IPersistStream,
  34. public CComObjectRoot
  35. {
  36. BEGIN_COM_MAP(CComponentDataImpl)
  37. COM_INTERFACE_ENTRY(IComponentData)
  38. COM_INTERFACE_ENTRY(IExtendPropertySheet)
  39. COM_INTERFACE_ENTRY(IExtendPropertySheet2)
  40. COM_INTERFACE_ENTRY(IExtendContextMenu)
  41. COM_INTERFACE_ENTRY(IPersistStream)
  42. END_COM_MAP()
  43. friend class CSnapin;
  44. friend class CDataObject;
  45. CComponentDataImpl();
  46. ~CComponentDataImpl();
  47. public:
  48. virtual const CLSID& GetCoClassID() = 0;
  49. virtual const BOOL IsPrimaryImpl() = 0;
  50. public:
  51. // IComponentData interface members
  52. STDMETHOD(Initialize)(LPUNKNOWN pUnknown);
  53. STDMETHOD(CreateComponent)(LPCOMPONENT* ppComponent);
  54. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  55. STDMETHOD(Destroy)();
  56. STDMETHOD(QueryDataObject)(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject);
  57. STDMETHOD(GetDisplayInfo)(SCOPEDATAITEM* pScopeDataItem);
  58. STDMETHOD(CompareObjects)(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  59. // IExtendPropertySheet2 interface
  60. public:
  61. STDMETHOD(CreatePropertyPages)(LPPROPERTYSHEETCALLBACK lpProvider,
  62. LONG_PTR handle,
  63. LPDATAOBJECT lpIDataObject);
  64. STDMETHOD(QueryPagesFor)(LPDATAOBJECT lpDataObject);
  65. STDMETHOD(GetWatermarks)(LPDATAOBJECT lpIDataObject, HBITMAP* lphWatermark,
  66. HBITMAP* lphHeader, HPALETTE* lphPalette, BOOL* pbStretch);
  67. // IExtendContextMenu
  68. public:
  69. STDMETHOD(AddMenuItems)(LPDATAOBJECT pDataObject, LPCONTEXTMENUCALLBACK pCallbackUnknown,
  70. long *pInsertionAllowed);
  71. STDMETHOD(Command)(long nCommandID, LPDATAOBJECT pDataObject);
  72. public:
  73. // IPersistStream interface members
  74. STDMETHOD(GetClassID)(CLSID *pClassID);
  75. STDMETHOD(IsDirty)();
  76. STDMETHOD(Load)(IStream *pStm);
  77. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty);
  78. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize);
  79. bool m_bInitializedCD;
  80. bool m_bLoadedCD;
  81. bool m_bDestroyedCD;
  82. public:
  83. // Other public methods
  84. void DeleteAndReinsertAll();
  85. // Notify handler declarations
  86. private:
  87. HRESULT OnDelete(MMC_COOKIE cookie);
  88. HRESULT OnRemoveChildren(LPARAM arg);
  89. HRESULT OnRename(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  90. HRESULT OnExpand(LPDATAOBJECT lpDataObject, LPARAM arg, LPARAM param);
  91. HRESULT OnSelect(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  92. HRESULT OnProperties(LPARAM param);
  93. #if DBG==1
  94. public:
  95. ULONG InternalAddRef()
  96. {
  97. return CComObjectRoot::InternalAddRef();
  98. }
  99. ULONG InternalRelease()
  100. {
  101. return CComObjectRoot::InternalRelease();
  102. }
  103. #endif // DBG==1
  104. // Scope item creation helpers
  105. private:
  106. CFolder* FindObject(MMC_COOKIE cookie);
  107. void CreateFolderList(LPDATAOBJECT lpDataObject); // scope item cookie helper
  108. void DeleteList();
  109. void EnumerateScopePane(LPDATAOBJECT lpDataObject, HSCOPEITEM pParent);
  110. BOOL IsScopePaneNode(LPDATAOBJECT lpDataObject);
  111. HRESULT DoInsertWizard(LPPROPERTYSHEETCALLBACK lpProvider);
  112. private:
  113. LPCONSOLENAMESPACE m_pScope; // My interface pointer to the scope pane
  114. LPCONSOLE m_pConsole; // My interface pointer to the console
  115. HSCOPEITEM m_pStaticRoot;
  116. BOOL m_bIsDirty;
  117. void SetDirty(BOOL b = TRUE) { m_bIsDirty = b; }
  118. void ClearDirty() { m_bIsDirty = FALSE; }
  119. BOOL ThisIsDirty() { return m_bIsDirty; }
  120. void AddScopeItemToResultPane(MMC_COOKIE cookie);
  121. private:
  122. CList<CFolder*, CFolder*> m_scopeItemList;
  123. #ifdef _DEBUG
  124. friend class CDataObject;
  125. int m_cDataObjects;
  126. #endif
  127. };
  128. class CComponentDataPrimaryImpl : public CComponentDataImpl,
  129. public CComCoClass<CComponentDataPrimaryImpl, &CLSID_Snapin>
  130. {
  131. public:
  132. DECLARE_REGISTRY(CSnapin, _T("Snapin.Snapin.1"), _T("Snapin.Snapin"), IDS_SNAPIN_DESC, THREADFLAGS_APARTMENT)
  133. virtual const CLSID & GetCoClassID() { return CLSID_Snapin; }
  134. virtual const BOOL IsPrimaryImpl() { return TRUE; }
  135. };
  136. class CComponentDataExtensionImpl : public CComponentDataImpl,
  137. public CComCoClass<CComponentDataExtensionImpl, &CLSID_Extension>
  138. {
  139. public:
  140. DECLARE_REGISTRY(CSnapin, _T("Extension.Extension.1"), _T("Extension.Extension"), IDS_SNAPIN_DESC, THREADFLAGS_APARTMENT)
  141. virtual const CLSID & GetCoClassID(){ return CLSID_Extension; }
  142. virtual const BOOL IsPrimaryImpl() { return FALSE; }
  143. };
  144. enum CUSTOM_VIEW_ID
  145. {
  146. VIEW_DEFAULT_LV = 0,
  147. VIEW_CALENDAR_OCX = 1,
  148. VIEW_MICROSOFT_URL = 2,
  149. VIEW_DEFAULT_MESSAGE_VIEW = 3,
  150. };
  151. class CSnapin :
  152. public IComponent,
  153. public IExtendContextMenu, // Step 3
  154. public IExtendControlbar,
  155. public IResultDataCompare,
  156. public IResultOwnerData,
  157. public IPersistStream,
  158. public CComObjectRoot
  159. {
  160. public:
  161. CSnapin();
  162. ~CSnapin();
  163. BEGIN_COM_MAP(CSnapin)
  164. COM_INTERFACE_ENTRY(IComponent)
  165. COM_INTERFACE_ENTRY(IExtendContextMenu) // Step 3
  166. COM_INTERFACE_ENTRY(IExtendControlbar)
  167. COM_INTERFACE_ENTRY(IResultDataCompare)
  168. COM_INTERFACE_ENTRY(IResultOwnerData)
  169. COM_INTERFACE_ENTRY(IPersistStream)
  170. END_COM_MAP()
  171. friend class CDataObject;
  172. static long lDataObjectRefCount;
  173. // IComponent interface members
  174. public:
  175. STDMETHOD(Initialize)(LPCONSOLE lpConsole);
  176. STDMETHOD(Notify)(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  177. STDMETHOD(Destroy)(MMC_COOKIE cookie);
  178. STDMETHOD(GetResultViewType)(MMC_COOKIE cookie, LPOLESTR* ppViewType, long* pViewOptions);
  179. STDMETHOD(QueryDataObject)(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  180. LPDATAOBJECT* ppDataObject);
  181. STDMETHOD(GetDisplayInfo)(RESULTDATAITEM* pResultDataItem);
  182. STDMETHOD(CompareObjects)(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB);
  183. // IResultDataCompare
  184. STDMETHOD(Compare)(LPARAM lUserParam, MMC_COOKIE cookieA, MMC_COOKIE cookieB, int* pnResult);
  185. // IResultOwnerData
  186. STDMETHOD(FindItem)(LPRESULTFINDINFO pFindInfo, int* pnFoundIndex);
  187. STDMETHOD(CacheHint)(int nStartIndex, int nEndIndex);
  188. STDMETHOD(SortItems)(int nColumn, DWORD dwSortOptions, LPARAM lUserParam);
  189. // IExtendControlbar
  190. STDMETHOD(SetControlbar)(LPCONTROLBAR pControlbar);
  191. STDMETHOD(ControlbarNotify)(MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  192. public:
  193. // IPersistStream interface members
  194. STDMETHOD(GetClassID)(CLSID *pClassID);
  195. STDMETHOD(IsDirty)();
  196. STDMETHOD(Load)(IStream *pStm);
  197. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty);
  198. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize);
  199. // Only for debug purpose
  200. bool m_bInitializedC;
  201. bool m_bLoadedC;
  202. bool m_bDestroyedC;
  203. // Helpers for CSnapin
  204. public:
  205. void SetIComponentData(CComponentDataImpl* pData);
  206. void GetItemName(LPDATAOBJECT lpDataObject, LPTSTR pszName);
  207. BOOL IsPrimaryImpl()
  208. {
  209. CComponentDataImpl* pData =
  210. dynamic_cast<CComponentDataImpl*>(m_pComponentData);
  211. ASSERT(pData != NULL);
  212. if (pData != NULL)
  213. return pData->IsPrimaryImpl();
  214. return FALSE;
  215. }
  216. #if DBG==1
  217. public:
  218. int dbg_cRef;
  219. ULONG InternalAddRef()
  220. {
  221. ++dbg_cRef;
  222. return CComObjectRoot::InternalAddRef();
  223. }
  224. ULONG InternalRelease()
  225. {
  226. --dbg_cRef;
  227. return CComObjectRoot::InternalRelease();
  228. }
  229. #endif // DBG==1
  230. // Notify event handlers
  231. protected:
  232. HRESULT OnFolder(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  233. HRESULT OnAddImages(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  234. HRESULT OnShow(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  235. HRESULT OnActivate(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  236. HRESULT OnMinimize(MMC_COOKIE cookie, LPARAM arg, LPARAM param);
  237. HRESULT OnPropertyChange(LPDATAOBJECT lpDataObject); // Step 3
  238. HRESULT OnUpdateView(LPDATAOBJECT lpDataObject);
  239. HRESULT OnResultItemClk(DATA_OBJECT_TYPES type, MMC_COOKIE cookie);
  240. HRESULT OnContextHelp(LPDATAOBJECT lpDataObject);
  241. void OnButtonClick(LPDATAOBJECT pdtobj, LONG_PTR idBtn);
  242. HRESULT QueryMultiSelectDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  243. LPDATAOBJECT* ppDataObject);
  244. // IExtendContextMenu
  245. public:
  246. STDMETHOD(AddMenuItems)(LPDATAOBJECT pDataObject, LPCONTEXTMENUCALLBACK pCallbackUnknown,
  247. long *pInsertionAllowed);
  248. STDMETHOD(Command)(long nCommandID, LPDATAOBJECT pDataObject);
  249. // End step 3
  250. // Helper functions
  251. protected:
  252. BOOL IsEnumerating(LPDATAOBJECT lpDataObject);
  253. void Construct();
  254. void LoadResources();
  255. HRESULT InitializeHeaders(MMC_COOKIE cookie);
  256. void Enumerate(MMC_COOKIE cookie, HSCOPEITEM pParent);
  257. void EnumerateResultPane(MMC_COOKIE cookie);
  258. void PopulateMessageView (MMC_COOKIE cookie);
  259. // Result pane helpers
  260. void AddResultItems(RESULT_DATA* pData, int nCount, int imageIndex);
  261. void AddUser();
  262. void AddCompany();
  263. void AddExtUser();
  264. void AddExtCompany();
  265. void AddVirtual();
  266. RESULT_DATA* GetVirtualResultItem(int iIndex);
  267. HRESULT InitializeBitmaps(MMC_COOKIE cookie);
  268. // UI Helpers
  269. void HandleStandardVerbs(bool bDeselectAll, LPARAM arg, LPDATAOBJECT lpDataObject);
  270. void HandleExtToolbars(bool bDeselectAll, LPARAM arg, LPARAM param);
  271. void HandleExtMenus(LPARAM arg, LPARAM param);
  272. void _OnRefresh(LPDATAOBJECT pDataObject);
  273. // Interface pointers
  274. protected:
  275. LPCONSOLE m_pConsole; // Console's IFrame interface
  276. LPHEADERCTRL m_pHeader; // Result pane's header control interface
  277. LPCOMPONENTDATA m_pComponentData;
  278. LPRESULTDATA m_pResult; // My interface pointer to the result pane
  279. LPIMAGELIST m_pImageResult; // My interface pointer to the result pane image list
  280. LPTOOLBAR m_pToolbar1; // Toolbar for view
  281. LPTOOLBAR m_pToolbar2; // Toolbar for view
  282. LPCONTROLBAR m_pControlbar; // control bar to hold my tool bars
  283. LPCONSOLEVERB m_pConsoleVerb; // pointer the console verb
  284. LPMENUBUTTON m_pMenuButton1; // Menu Button for view
  285. ::CBitmap* m_pbmpToolbar1; // Imagelist for the first toolbar
  286. ::CBitmap* m_pbmpToolbar2; // Imagelist for the first toolbar
  287. // Header titles for each nodetype(s)
  288. protected:
  289. CString m_column1; // Name
  290. CString m_column2; // Size
  291. CString m_column3; // Type
  292. private:
  293. BOOL m_bIsDirty;
  294. CUSTOM_VIEW_ID m_CustomViewID;
  295. BOOL m_bVirtualView;
  296. DWORD m_dwVirtualSortOptions;
  297. void SetDirty(BOOL b = TRUE) { m_bIsDirty = b; }
  298. void ClearDirty() { m_bIsDirty = FALSE; }
  299. BOOL ThisIsDirty() { return m_bIsDirty; }
  300. };
  301. inline void CSnapin::SetIComponentData(CComponentDataImpl* pData)
  302. {
  303. ASSERT(pData);
  304. ASSERT(m_pComponentData == NULL);
  305. LPUNKNOWN pUnk = pData->GetUnknown();
  306. HRESULT hr;
  307. hr = pUnk->QueryInterface(IID_IComponentData, reinterpret_cast<void**>(&m_pComponentData));
  308. ASSERT(hr == S_OK);
  309. }
  310. class CSnapinAboutImpl :
  311. public ISnapinAbout,
  312. public CComObjectRoot,
  313. public CComCoClass<CSnapinAboutImpl, &CLSID_About>
  314. {
  315. public:
  316. CSnapinAboutImpl();
  317. ~CSnapinAboutImpl();
  318. public:
  319. DECLARE_REGISTRY(CSnapin, _T("Snapin.About.1"), _T("Snapin.About"), IDS_SNAPIN_DESC, THREADFLAGS_BOTH)
  320. BEGIN_COM_MAP(CSnapinAboutImpl)
  321. COM_INTERFACE_ENTRY(ISnapinAbout)
  322. END_COM_MAP()
  323. public:
  324. STDMETHOD(GetSnapinDescription)(LPOLESTR* lpDescription);
  325. STDMETHOD(GetProvider)(LPOLESTR* lpName);
  326. STDMETHOD(GetSnapinVersion)(LPOLESTR* lpVersion);
  327. STDMETHOD(GetSnapinImage)(HICON* hAppIcon);
  328. STDMETHOD(GetStaticFolderImage)(HBITMAP* hSmallImage,
  329. HBITMAP* hSmallImageOpen,
  330. HBITMAP* hLargeImage,
  331. COLORREF* cLargeMask);
  332. // Internal functions
  333. private:
  334. HRESULT AboutHelper(UINT nID, LPOLESTR* lpPtr);
  335. };
  336. #define FREE_DATA(pData) \
  337. ASSERT(pData != NULL); \
  338. do { if (pData != NULL) \
  339. GlobalFree(pData); } \
  340. while(0);
  341. #define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0]))