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.

772 lines
28 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: addsnpin.h
  8. //
  9. //--------------------------------------------------------------------------
  10. // AddSnpIn.h : header file
  11. //
  12. /*
  13. * CSnapinInfo:
  14. * This object represents a snapin entry in the registry. So if same snapin
  15. * is added several times to a console they will all refer to same instance
  16. * of this object. This object has a linked list of extensions.
  17. *
  18. * CExtensionLink:
  19. * This object represents an extension snapin. So if an extension extends
  20. * two different snapins then there are two instances of this object for
  21. * each extension. Each CExtensionLink refers to underlying snapin through
  22. * CSnapinInfo. So for the two extensions there will be two CExtensionLink
  23. * objects but only one CSnapinInfo object.
  24. *
  25. * CSnapinManager:
  26. * Has a SnapinInfoCache, standalone & extension pages, policy objects.
  27. * It can initialize by populating snapininfo cache, loading mtnode tree
  28. * And update the snapin-info cache if there are any changes.
  29. *
  30. */
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CSnapinManager dialog
  33. #ifndef __ADDSNPIN_H__
  34. #define __ADDSNPIN_H__
  35. #include "dlgs.h"
  36. #include "ccomboex.h"
  37. #include "regutil.h" // need HashKey(GUID&) function
  38. #include "about.h"
  39. #define BMP_EXTENSION 0
  40. #define BMP_DIRECTORY 0
  41. #define ADDSNP_ROOTFOLDER 1
  42. #define ADDSNP_SNAPIN 2
  43. #define ADDSNP_EXTENSIONUI 3
  44. #define ADDSNP_EXTENSION 4
  45. #define ADDSNP_STATICNODE 5
  46. #define MSG_LOADABOUT_REQUEST (WM_USER + 100)
  47. #define MSG_LOADABOUT_COMPLETE (WM_USER + 101)
  48. class CSnapinManager;
  49. class CSnapinStandAlonePage;
  50. class CSnapinExtensionPage;
  51. class CSnapinManagerAdd;
  52. class CSnapinInfo;
  53. class CSnapinInfoCache;
  54. class CNewTreeNode;
  55. class CManagerNode;
  56. class CExtensionLink;
  57. class CPolicy;
  58. class CAboutInfoThread;
  59. //-----------------------------------------------------
  60. // CCheckList class
  61. //
  62. // Helper class for listview with checkboxes
  63. //-----------------------------------------------------
  64. class CCheckList : public MMC_ATL::CWindowImpl<CCheckList, WTL::CListViewCtrl>
  65. {
  66. public:
  67. DECLARE_WND_SUPERCLASS (NULL, WTL::CListViewCtrl::GetWndClassName())
  68. BEGIN_MSG_MAP(CCheckList)
  69. MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
  70. MESSAGE_HANDLER(WM_LBUTTONDBLCLK, OnLButtonDblClk )
  71. MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown )
  72. END_MSG_MAP()
  73. LRESULT OnKeyDown( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled );
  74. LRESULT OnLButtonDblClk( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled );
  75. LRESULT OnLButtonDown( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled );
  76. public:
  77. enum
  78. {
  79. CHECKOFF_STATE = INDEXTOSTATEIMAGEMASK(1),
  80. CHECKON_STATE = INDEXTOSTATEIMAGEMASK(2),
  81. DISABLEOFF_STATE = INDEXTOSTATEIMAGEMASK(3),
  82. DISABLEON_STATE = INDEXTOSTATEIMAGEMASK(4)
  83. };
  84. BOOL GetItemCheck(int iItem, BOOL* pbEnable = NULL)
  85. {
  86. ASSERT(::IsWindow(m_hWnd));
  87. ASSERT(iItem >= 0 && iItem < GetItemCount());
  88. int iState = GetItemState(iItem, LVIS_STATEIMAGEMASK);
  89. if (pbEnable != NULL)
  90. *pbEnable = (iState <= CHECKON_STATE);
  91. return (iState == CHECKON_STATE || iState == DISABLEON_STATE);
  92. }
  93. void SetItemCheck(int iItem, BOOL bState, BOOL bEnable = TRUE)
  94. {
  95. ASSERT(::IsWindow(m_hWnd));
  96. ASSERT(iItem >= 0 && iItem < GetItemCount());
  97. int iState = bState ? CHECKON_STATE : CHECKOFF_STATE;
  98. if (!bEnable)
  99. iState += (DISABLEOFF_STATE - CHECKOFF_STATE);
  100. SetItemState(iItem, iState, LVIS_STATEIMAGEMASK);
  101. }
  102. void ToggleItemCheck(int iItem)
  103. {
  104. ASSERT(::IsWindow(m_hWnd));
  105. ASSERT(iItem >= 0 && iItem < GetItemCount());
  106. SetItemState(iItem, GetItemState(iItem, LVIS_STATEIMAGEMASK)^(CHECKON_STATE^CHECKOFF_STATE), LVIS_STATEIMAGEMASK);
  107. }
  108. };
  109. //-----------------------------------------------------
  110. // CAboutInfoThread
  111. //
  112. // This class handles the creation/deletion of the
  113. // AboutInfo thread. One static instance of this class
  114. // must be defined in addsnpin.cpp.
  115. //-----------------------------------------------------
  116. class CAboutInfoThread
  117. {
  118. public:
  119. CAboutInfoThread()
  120. {
  121. DEBUG_INCREMENT_INSTANCE_COUNTER(CAboutInfoThread);
  122. m_hThread = NULL;
  123. m_hEvent = NULL;
  124. m_uThreadID = 0;
  125. }
  126. ~CAboutInfoThread();
  127. BOOL StartThread();
  128. BOOL PostRequest(CSnapinInfo* pSnapInfo, HWND hWndNotify);
  129. private:
  130. static unsigned _stdcall ThreadProc(void* pVoid);
  131. HANDLE m_hThread; // thread handle
  132. HANDLE m_hEvent; // start event
  133. unsigned m_uThreadID; // thread ID
  134. };
  135. //-----------------------------------------------------
  136. // CSnapinInfo class
  137. //
  138. // Contains the registry information for a snapin.
  139. // Also provides access to the ISnapinAbout information.
  140. //-----------------------------------------------------
  141. typedef CSnapinInfo* PSNAPININFO;
  142. class CSnapinInfo : public CSnapinAbout
  143. {
  144. friend class CSnapinInfoCache;
  145. public:
  146. // Constructor/Destructor
  147. CSnapinInfo (Properties* pInitProps = NULL) :
  148. m_lRefCnt (0),
  149. m_nUseCnt (0),
  150. m_iImage (-1),
  151. m_iOpenImage (-1),
  152. m_spSnapin (NULL),
  153. m_pExtensions (NULL),
  154. m_spInitProps (pInitProps),
  155. m_bAboutValid (false),
  156. m_bStandAlone (false),
  157. m_bExtendable (false),
  158. m_bExtensionsLoaded (false),
  159. m_bEnableAllExts (false),
  160. m_bInstalled (false),
  161. m_bPolicyPermission (false)
  162. {
  163. DEBUG_INCREMENT_INSTANCE_COUNTER(CSnapinInfo);
  164. }
  165. ~CSnapinInfo();
  166. private:
  167. // Attributes
  168. long m_lRefCnt; // COM-type ref count (controls lifetime)
  169. int m_nUseCnt; // Number of node and extension references
  170. GUID m_clsid; // snapin CLSID
  171. GUID m_clsidAbout; // About CLSID
  172. int m_iImage; // small icon image index
  173. int m_iOpenImage; // index of open image
  174. CSnapInPtr m_spSnapin; // ptr to CSnapIn (if snapin in use prior
  175. // to this manager session)
  176. CExtensionLink* m_pExtensions; // linked list of extensions
  177. PropertiesPtr m_spInitProps; // properties to initialize with
  178. bool m_bAboutValid : 1; // TRUE if About CLSID is valid
  179. bool m_bStandAlone : 1; // TRUE if snapin is standalone
  180. bool m_bExtendable : 1; // TRUE if snapin can be extended
  181. bool m_bExtensionsLoaded : 1; // Available extensions loaded
  182. bool m_bEnableAllExts : 1; // TRUE if all extensions enabled
  183. bool m_bInstalled : 1; // TRUE if snap-in is installed locally
  184. bool m_bPolicyPermission : 1; // Says if current user can use the snapin
  185. public:
  186. // Operations
  187. BOOL InitFromMMCReg(GUID& clsid, CRegKeyEx& regkey, BOOL bPermitted);
  188. BOOL InitFromComponentReg(GUID& clsid, LPCTSTR pszName, BOOL bStandAlone, BOOL bPermitted);
  189. ULONG AddRef(void)
  190. {
  191. return InterlockedIncrement(&m_lRefCnt);
  192. }
  193. ULONG Release(void)
  194. {
  195. LONG lRet = InterlockedDecrement(&m_lRefCnt);
  196. ASSERT(lRet >= 0);
  197. if (lRet == 0)
  198. delete this;
  199. return static_cast<ULONG>(lRet);
  200. }
  201. void AddUseRef(void);
  202. void DeleteUseRef(void);
  203. GUID& GetCLSID(void) { return m_clsid; }
  204. void LoadImages( WTL::CImageList iml );
  205. int GetImage(void) { return m_iImage; }
  206. int GetOpenImage(void) { return m_iOpenImage; }
  207. BOOL IsStandAlone(void) { return m_bStandAlone; }
  208. BOOL IsExtendable(void) { return m_bExtendable; }
  209. BOOL IsUsed(void) { return (m_nUseCnt != 0); }
  210. BOOL AreAllExtensionsEnabled(void) { return m_bEnableAllExts; }
  211. BOOL IsInstalled(void) { return m_bInstalled; }
  212. CSnapIn* GetSnapIn(void) { return m_spSnapin; }
  213. void SetSnapIn(CSnapIn* pSnapIn) { m_spSnapin = pSnapIn; }
  214. void AttachSnapIn(CSnapIn* pSnapIn, CSnapinInfoCache& InfoCache);
  215. void DetachSnapIn() { m_spSnapin = NULL; }
  216. void SetEnableAllExtensions(BOOL bState) { m_bEnableAllExts = bState; }
  217. SC ScInstall(CLSID* pclsidPrimary);
  218. BOOL HasAbout(void) { return m_bAboutValid; }
  219. // const LPOLESTR GetDescription(void);
  220. void ShowAboutPages(HWND hWndParent);
  221. BOOL IsPermittedByPolicy() { return m_bPolicyPermission; }
  222. BOOL LoadAboutInfo()
  223. {
  224. if (m_bAboutValid && !HasInformation())
  225. {
  226. BOOL bStat = GetSnapinInformation(m_clsidAbout);
  227. // if failure, About object is not really valid
  228. if (!bStat)
  229. m_bAboutValid = FALSE;
  230. }
  231. return HasInformation();
  232. }
  233. void ResetAboutInfo() { m_bAboutValid = TRUE; }
  234. CExtensionLink* GetExtensions(void) { return m_pExtensions; }
  235. CExtensionLink* FindExtension(CLSID& ExtCLSID);
  236. CExtensionLink* GetAvailableExtensions(CSnapinInfoCache* pInfoCache, CPolicy *pMMCPolicy);
  237. Properties* GetInitProperties() const {return m_spInitProps; }
  238. void SetInitProperties(Properties *pInitProps) { m_spInitProps = pInitProps;}
  239. };
  240. // CMap for holding all CSnapinInfo objects indexed by CLSID
  241. class CSnapinInfoCache : public CMap<GUID, const GUID&, PSNAPININFO, PSNAPININFO>
  242. {
  243. public:
  244. // Constructor
  245. CSnapinInfoCache(void)
  246. {
  247. DEBUG_INCREMENT_INSTANCE_COUNTER(CSnapinInfoCache);
  248. InitHashTable(31);
  249. }
  250. ~CSnapinInfoCache()
  251. {
  252. DEBUG_DECREMENT_INSTANCE_COUNTER(CSnapinInfoCache);
  253. }
  254. // Operators
  255. void AddEntry(CSnapinInfo* pSnapInfo)
  256. {
  257. SetAt(pSnapInfo->m_clsid, pSnapInfo);
  258. pSnapInfo->AddRef();
  259. }
  260. CSnapinInfo* FindEntry( const GUID& clsid);
  261. #ifdef DBG
  262. void Dump(void);
  263. #else
  264. void Dump(void) {}
  265. #endif
  266. };
  267. inline CSnapinInfo* CSnapinInfoCache::FindEntry(const GUID& rclsid)
  268. {
  269. CSnapinInfo* pSnapInfo = NULL;
  270. Lookup(rclsid, pSnapInfo);
  271. return pSnapInfo;
  272. }
  273. template<>
  274. inline UINT HashKey(const GUID& guid)
  275. {
  276. unsigned short* Values = (unsigned short *)&guid;
  277. return (Values[0] ^ Values[1] ^ Values[2] ^ Values[3] ^
  278. Values[4] ^ Values[5] ^ Values[6] ^ Values[7]);
  279. }
  280. //-----------------------------------------------------
  281. // CExtensionLink class
  282. //
  283. // Represents one link from a snapin to an extension.
  284. // Each CSnapinInfo object maintains a list of these.
  285. //-----------------------------------------------------
  286. typedef CExtensionLink* PEXTENSIONLINK;
  287. class CExtensionLink
  288. {
  289. public:
  290. typedef enum _EXTENSION_STATE
  291. {
  292. EXTEN_OFF,
  293. EXTEN_READY,
  294. EXTEN_ON
  295. } EXTENSION_STATE;
  296. // Constructor/Destructor
  297. CExtensionLink(CSnapinInfo* pSnapInfo) :
  298. m_pSnapInfo(pSnapInfo), m_pNext(NULL), m_iExtTypes(0),
  299. m_eOrigState(EXTEN_OFF), m_bRequired(FALSE), m_eCurState(EXTEN_OFF) {}
  300. private:
  301. // Attributes
  302. EXTENSION_STATE m_eOrigState; // Original state of link
  303. EXTENSION_STATE m_eCurState; // Current state
  304. BOOL m_bRequired; // Is a required extension
  305. int m_iExtTypes; // Extension type flags (from class CExtSI)
  306. CSnapinInfo* m_pSnapInfo; // ptr to extension snapin info
  307. PEXTENSIONLINK m_pNext; // ptr to next extension link
  308. public:
  309. // Operations
  310. void SetInitialState(EXTENSION_STATE eState) { m_eOrigState = eState; }
  311. void SetState(EXTENSION_STATE eState);
  312. void SetExtTypes(int iExtTypes) { m_iExtTypes = iExtTypes; }
  313. int GetExtTypes() { return m_iExtTypes; }
  314. void SetNext(CExtensionLink* pExtNext) { m_pNext = pExtNext; }
  315. EXTENSION_STATE GetState(void) { return m_eCurState; }
  316. CSnapinInfo* GetSnapinInfo(void) { return m_pSnapInfo; }
  317. BOOL IsChanged(void)
  318. { return (m_eOrigState == EXTEN_ON && m_eCurState != EXTEN_ON) ||
  319. (m_eOrigState != EXTEN_ON && m_eCurState == EXTEN_ON);
  320. }
  321. BOOL IsRequired(void) { return m_bRequired; }
  322. void SetRequired(BOOL bState = TRUE) { m_bRequired = bState; }
  323. PEXTENSIONLINK Next(void) { return m_pNext; }
  324. };
  325. //-----------------------------------------------------
  326. // CNewTreeNode class
  327. //
  328. // Holds information for a new node created by the
  329. // snapin manager. The objects are kept in a NewNodeList
  330. // owned by the CSnapinManager. The list is passed to
  331. // the scope tree handler to create the real nodes.
  332. //-----------------------------------------------------
  333. class CNewTreeNode
  334. {
  335. public:
  336. // Contructor / Destructor
  337. CNewTreeNode() : m_pmtNode(NULL), m_pNext(NULL),
  338. m_pChild(NULL), m_pParent(NULL), m_pmtNewNode(NULL),
  339. m_pmtNewSnapInNode(NULL)
  340. {};
  341. ~CNewTreeNode() { if (m_pmtNewNode) m_pmtNewNode->Release(); delete Child(); delete Next(); }
  342. public:
  343. // Operators
  344. PNEWTREENODE Next() { return m_pNext; }
  345. PNEWTREENODE Child() { return m_pChild; }
  346. PNEWTREENODE Parent() { return m_pParent;}
  347. CMTNode* GetMTNode() {return m_pmtNode;}
  348. VOID AddChild(PNEWTREENODE pntNode);
  349. VOID RemoveChild(PNEWTREENODE pntNode);
  350. public:
  351. // Attributes
  352. CMTNode* m_pmtNode; // pointer to parent MTNode (NULL if child of new node)
  353. PNEWTREENODE m_pNext; // pointer to next sibling
  354. PNEWTREENODE m_pChild; // pointer to first child
  355. PNEWTREENODE m_pParent; // pointer to new node parent (NULL if child of MTNode)
  356. //Specific node data
  357. IComponentDataPtr m_spIComponentData; // pointer to the snapin's IComponentData (if snapin)
  358. CLSID m_clsidSnapIn; // snapin CLSID (if snapin)
  359. CMTNode* m_pmtNewNode; // Pointer to new node (if not snapin node)
  360. PropertiesPtr m_spSnapinProps; // pointer to the snap-in's properties
  361. CMTSnapInNode* m_pmtNewSnapInNode; // new snap-in node
  362. };
  363. //------------------------------------------------------
  364. // CManagerNode class
  365. //
  366. // Primary object that node manager handles. Each object
  367. // represents one static standalone node. The objects
  368. // are linked in a tree structure owned by the
  369. // CSnapinManager class.
  370. //------------------------------------------------------
  371. typedef CManagerNode* PMANAGERNODE;
  372. typedef CList <PMANAGERNODE, PMANAGERNODE> ManagerNodeList;
  373. class CManagerNode
  374. {
  375. public:
  376. // Constructor / Destructor
  377. CManagerNode(): m_nType(0), m_pmtNode(NULL),
  378. m_pSnapInfo(NULL), m_pNewNode(NULL) {}
  379. ~CManagerNode();
  380. public:
  381. // Attributes
  382. PMANAGERNODE m_pmgnParent; // pointer to parent node
  383. ManagerNodeList m_ChildList; // Child node list
  384. CStr m_strValue; // Display name string
  385. int m_nType; // node type (ADDNSP_SNAPIN or ADDSNP_STATICNODE)
  386. CMTNode* m_pmtNode; // pointer to MTNode (for existing node only)
  387. PNEWTREENODE m_pNewNode; // pointer to new tree node (for new nodes only)
  388. PSNAPININFO m_pSnapInfo; // pointer Snapin information
  389. int m_iImage; // image list indices
  390. int m_iOpenImage;
  391. int m_iIndent; // indentation level for tree view
  392. // Operators
  393. VOID AddChild(PMANAGERNODE pmgnNode);
  394. VOID RemoveChild(PMANAGERNODE pmgnNode);
  395. PSNAPININFO GetSnapinInfo(void) { return m_pSnapInfo; }
  396. BOOL HasAboutInfo(void) { return (m_pSnapInfo && m_pSnapInfo->HasAbout()); }
  397. };
  398. /*+-------------------------------------------------------------------------*
  399. * class CSnapinManagerAdd
  400. *
  401. *
  402. * PURPOSE: Dialog for selecting type of snapin to add. Called by
  403. * CSnapinStandAlonePage to enable the user to select a page. When the user
  404. * selects a snapin, calls back into the CSnapinStandAlonePage to add
  405. * the snapin.
  406. *
  407. * NOTE: This object does not know about where in the tree the snapin will
  408. * be added. That is handled by the CSnapinStandalone page.
  409. ************************************************************************/
  410. class CSnapinManagerAdd : public CDialogImpl<CSnapinManagerAdd>
  411. {
  412. // Constructor/Destrcutor
  413. public:
  414. CSnapinManagerAdd(CSnapinManager* pManager, CSnapinStandAlonePage* pStandAlonePage);
  415. ~CSnapinManagerAdd();
  416. //MSGMAP
  417. public:
  418. BEGIN_MSG_MAP(CSnapinManagerAdd)
  419. // MESSAGE_HANDLER(WM_SHOWWINDOW, OnShowWindow)
  420. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  421. MESSAGE_HANDLER(WM_COMMAND, OnCommand)
  422. MESSAGE_HANDLER(WM_SYSCOMMAND, OnSysCommand);
  423. CONTEXT_HELP_HANDLER()
  424. MESSAGE_HANDLER(MSG_LOADABOUT_COMPLETE, OnLoadAboutComplete)
  425. NOTIFY_HANDLER(IDC_SNAPIN_LV, LVN_ITEMCHANGED, OnItemChanged)
  426. NOTIFY_HANDLER(IDC_SNAPIN_LV, LVN_GETDISPINFO, OnGetDispInfo)
  427. NOTIFY_HANDLER(IDC_SNAPIN_LV, NM_DBLCLK, OnListDblClick)
  428. END_MSG_MAP()
  429. IMPLEMENT_CONTEXT_HELP(g_aHelpIDs_IDD_SNAPIN_MANAGER_ADD);
  430. // Operators
  431. PSNAPININFO SelectedInfo() { return m_pInfoSelected; }
  432. public:
  433. // Operators
  434. enum { IDD = IDD_SNAPIN_MANAGER_ADD };
  435. // Generated message map functions
  436. protected:
  437. LRESULT OnShowWindow(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  438. LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  439. LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  440. LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  441. LRESULT OnItemChanged(int idCtrl, LPNMHDR pNMHDR, BOOL& bHandled);
  442. LRESULT OnGetDispInfo(int idCtrl, LPNMHDR pNMHDR, BOOL& bHandled);
  443. LRESULT OnListDblClick(int idCtrl, LPNMHDR pNMHDR, BOOL& bHandled);
  444. LRESULT OnLoadAboutComplete(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  445. void BuildSnapinList();
  446. // Attributes
  447. CSnapinManager* m_pManager; // Pointer to owning manager
  448. CSnapinStandAlonePage* m_pStandAlonePage; // Pointer to calling page
  449. WTL::CListViewCtrl* m_pListCtrl; // snapin listview
  450. BOOL m_bDoOnce; // TRUE first time through ShowWindow
  451. PSNAPININFO m_pInfoSelected; // Selected snapin info
  452. int m_iGetInfoIndex; // index of snapin with pending About info
  453. CStr m_strNotInstalled; // string to display for uninstalled snap-ins
  454. };
  455. //------------------------------------------------------
  456. // CSnapinStandAlonePage class
  457. //
  458. // The property page for adding/removing standalone
  459. // snapin nodes.
  460. //------------------------------------------------------
  461. class CSnapinStandAlonePage : public WTL::CPropertyPageImpl<CSnapinStandAlonePage>
  462. {
  463. public:
  464. typedef WTL::CPropertyPageImpl<CSnapinStandAlonePage> BC;
  465. // Constructor/destructor
  466. CSnapinStandAlonePage(CSnapinManager* pManager);
  467. ~CSnapinStandAlonePage();
  468. enum { IDD = IDD_SNAPIN_STANDALONE_PROPP };
  469. private:
  470. CSnapinManagerAdd& GetAddDialog() {return m_dlgAdd;}
  471. private:
  472. // attributes
  473. CSnapinManager* m_pManager; // pointer to owning snapin manager
  474. CSnapinManagerAdd m_dlgAdd; // pointer to add dialog
  475. WTL::CListViewCtrl m_snpListCtrl; // listview for displaying child nodes
  476. CComboBoxEx2 m_snpComboBox; // combobox for selecting parent node
  477. WTL::CToolBarCtrl m_ToolbarCtrl; // toolbar for folder-up button
  478. PMANAGERNODE m_pmgnParent; // currently selcted parent node
  479. PMANAGERNODE m_pmgnChild; // currently selcted child node
  480. protected:
  481. BEGIN_MSG_MAP( CSnapinStandAlonePage )
  482. COMMAND_HANDLER(IDC_SNAPIN_COMBOEX, CBN_SELENDOK, OnTreeItemSelect)
  483. NOTIFY_HANDLER(IDC_SNAPIN_ADDED_LIST, LVN_ITEMCHANGED, OnListItemChanged)
  484. NOTIFY_HANDLER(IDC_SNAPIN_ADDED_LIST, LVN_KEYDOWN, OnListKeyDown)
  485. NOTIFY_HANDLER(IDC_SNAPIN_ADDED_LIST, NM_DBLCLK, OnListItemDblClick)
  486. COMMAND_ID_HANDLER(ID_SNP_UP, OnTreeUp)
  487. COMMAND_ID_HANDLER(IDC_SNAPIN_MANAGER_ADD, OnAddSnapin)
  488. COMMAND_ID_HANDLER(IDC_SNAPIN_MANAGER_DELETE, OnDeleteSnapin)
  489. COMMAND_ID_HANDLER(IDC_SNAPIN_ABOUT, OnAboutSnapin)
  490. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  491. CONTEXT_HELP_HANDLER()
  492. CHAIN_MSG_MAP(BC)
  493. END_MSG_MAP()
  494. IMPLEMENT_CONTEXT_HELP(g_aHelpIDs_IDD_SNAPIN_STANDALONE_PROPP);
  495. // operations
  496. LRESULT OnTreeItemSelect( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );
  497. LRESULT OnListItemChanged( int idCtrl, LPNMHDR pnmh, BOOL& bHandled );
  498. LRESULT OnListKeyDown( int idCtrl, LPNMHDR pnmh, BOOL& bHandled );
  499. LRESULT OnListItemDblClick( int idCtrl, LPNMHDR pnmh, BOOL& bHandled );
  500. LRESULT OnTreeUp( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );
  501. LRESULT OnAddSnapin( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );
  502. LRESULT OnDeleteSnapin( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );
  503. LRESULT OnAboutSnapin( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );
  504. LRESULT OnInitDialog( UINT mMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled );
  505. VOID AddNodeListToTree(ManagerNodeList& NodeList);
  506. int AddChildToTree(PMANAGERNODE pMgrNode);
  507. VOID DisplayChildList(ManagerNodeList& NodeList);
  508. int AddChildToList(PMANAGERNODE pMgrNode, int iIndex = -1);
  509. VOID SelectParentNodeItem(PMANAGERNODE pMgrNode);
  510. VOID SetupParentNode(PMANAGERNODE pMgrNode, bool bVisible = true);
  511. VOID SetupChildNode(PMANAGERNODE pMgrNode);
  512. SC ScRunSnapinWizard (const CLSID& clsid, HWND hwndParent,
  513. Properties* pInitProps,
  514. IComponentData*& rpComponentData,
  515. Properties*& rpSnapinProps);
  516. public:
  517. HRESULT AddOneSnapin(CSnapinInfo* pSnapInfo, bool bVisible = true);
  518. SC ScAddOneSnapin(PMANAGERNODE pmgNodeParent, PSNAPININFO pSnapInfo);
  519. SC ScRemoveOneSnapin(PMANAGERNODE pmgNodeTobeRemoved, int iItem, bool bVisible = true);
  520. };
  521. //------------------------------------------------------
  522. // CSnapinExtensionPage class
  523. //
  524. // The property page configuring snapin extensions.
  525. //------------------------------------------------------
  526. class CSnapinExtensionPage : public WTL::CPropertyPageImpl<CSnapinExtensionPage>
  527. {
  528. public:
  529. typedef WTL::CPropertyPageImpl<CSnapinExtensionPage> BC;
  530. // Constructor/destructor
  531. CSnapinExtensionPage(CSnapinManager* pManager) :
  532. m_pManager(pManager), m_pCurSnapInfo(NULL), m_pExtLink(NULL) {}
  533. ~CSnapinExtensionPage();
  534. enum { IDD = IDD_SNAPIN_EXTENSION_PROPP };
  535. private:
  536. // Attributes
  537. CSnapinManager* m_pManager; // ptr to owning manager
  538. CComboBoxEx2 m_SnapComboBox; // combobox for selecting snapin
  539. CCheckList m_ExtListCtrl; // list of extensions
  540. PSNAPININFO m_pCurSnapInfo; // currently selected snapin
  541. PEXTENSIONLINK m_pExtLink; // currently selected extension
  542. BOOL m_bUpdateSnapinList; // TRUE if snapin list may have changed
  543. WTL::CImageList m_ilCheckbox; // checkbox image list
  544. protected:
  545. BEGIN_MSG_MAP(CSnapinExtensPage)
  546. COMMAND_HANDLER( IDC_SNAPIN_COMBOEX, CBN_SELENDOK, OnSnapinSelect )
  547. COMMAND_HANDLER( IDC_SNAPIN_COMBOEX, CBN_DROPDOWN, OnSnapinDropDown )
  548. COMMAND_HANDLER( IDC_SNAPIN_ENABLEALL, BN_CLICKED, OnEnableAllChanged )
  549. COMMAND_ID_HANDLER( IDC_SNAPIN_ABOUT, OnAboutSnapin )
  550. COMMAND_ID_HANDLER( IDC_SNAPIN_DOWNLOAD, OnDownloadSnapin )
  551. NOTIFY_HANDLER( IDC_EXTENSION_LIST, LVN_ITEMCHANGED, OnExtensionChanged )
  552. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  553. CONTEXT_HELP_HANDLER()
  554. CHAIN_MSG_MAP(BC)
  555. END_MSG_MAP()
  556. IMPLEMENT_CONTEXT_HELP(g_aHelpIDs_IDD_SNAPIN_EXTENSION_PROPP);
  557. // Operations
  558. LRESULT OnSnapinSelect( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );
  559. LRESULT OnExtensionChanged( int idCtrl, LPNMHDR pnmh, BOOL& bHandled );
  560. LRESULT OnEnableAllChanged( WORD wNotifyCode, WORD wID, HWND hWndCtrl, BOOL& bHandled );
  561. LRESULT OnSnapinDropDown( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );
  562. LRESULT OnAboutSnapin( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );
  563. LRESULT OnDownloadSnapin( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );
  564. LRESULT OnInitDialog( UINT mMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled );
  565. BOOL OnSetActive(void);
  566. void BuildSnapinList(void);
  567. void BuildExtensionList(PSNAPININFO pSnapInfo);
  568. };
  569. //------------------------------------------------------
  570. // CSnapinManager class
  571. //
  572. // Top level mannger object.
  573. //------------------------------------------------------
  574. typedef CList<CMTNode*, CMTNode*> MTNodesList;
  575. class CSnapinManager : public WTL::CPropertySheet
  576. {
  577. friend class CSnapinStandAlonePage;
  578. friend class CSnapinExtensionPage;
  579. friend class CSnapinManagerAdd;
  580. DECLARE_NOT_COPIABLE (CSnapinManager)
  581. DECLARE_NOT_ASSIGNABLE (CSnapinManager)
  582. public:
  583. // Constructor/Destructor
  584. CSnapinManager(CMTNode *pmtNode);
  585. ~CSnapinManager();
  586. // Attributes
  587. typedef CList<CSnapIn*, CSnapIn*> SNPList; // TEMP TEMP
  588. SNPList m_snpSnapinChangedList; // List of modified snapins
  589. MTNodesList m_mtnDeletedNodesList; // List of delted MT ndoes
  590. NewNodeList m_NewNodesList; // Tree of added nodes
  591. // Operators
  592. virtual int DoModal(void);
  593. MTNodesList* GetDeletedNodesList(void) { return &m_mtnDeletedNodesList; }
  594. NewNodeList* GetNewNodes(void) { return &m_NewNodesList; }
  595. SNPList* GetSnapinChangedList(void) { return &m_snpSnapinChangedList; }
  596. HRESULT LoadAboutInfoAsync(PSNAPININFO pSnapInfo, HWND hWndNotify);
  597. CSnapinInfoCache &GetSnapinInfoCache() {return m_SnapinInfoCache;}
  598. SC ScInitialize();
  599. public:
  600. // object method operations
  601. SC ScAddSnapin(LPCWSTR szSnapinNameOrCLSIDOrProgID, SnapIn* pParentSnapinNode, Properties *pProperties);
  602. SC ScRemoveSnapin(CMTNode *pMTNode);
  603. SC ScEnableAllExtensions(const CLSID& clsidSnapin, BOOL bEnable);
  604. SC ScEnableExtension(const CLSID& clsidPrimarySnapin, const CLSID& clsidExtension, bool bEnable);
  605. protected:
  606. // Operations
  607. BOOL LoadMTNodeTree(PMANAGERNODE pmgnParent, CMTNode* pMTNode);
  608. SC ScLoadSnapinInfo(void);
  609. void UpdateSnapInCache();
  610. PMANAGERNODE FindManagerNode(const ManagerNodeList& mgNodeList, CMTNode *pMTNode);
  611. SC ScGetSnapinInfo(LPCWSTR szSnapinNameOrCLSIDOrProgID, CSnapinInfo **ppSnapinInfo);
  612. // Attributes
  613. WTL::CImageList m_iml; // imagelist shared by all controls
  614. CMTNode* m_pmtNode; // Root node of master tree
  615. ManagerNodeList m_mgNodeList; // List of manager nodes
  616. CSnapinInfoCache m_SnapinInfoCache; // Cache of snapin info objects
  617. CAboutInfoThread m_AboutInfoThread; // Worker thread class
  618. bool m_bInitialized : 1; // Should initialize only once.
  619. private:
  620. // Attributes
  621. CSnapinStandAlonePage m_proppStandAlone; // Standalone property page
  622. CSnapinExtensionPage m_proppExtension; // Extensions property page
  623. CPolicy *m_pMMCPolicy;
  624. };
  625. int CALLBACK _ListViewCompareFunc(LPARAM lParam1,LPARAM lParam2,LPARAM lParamSort);
  626. #endif // __ADDSNPIN_H__