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.

771 lines
27 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. inline UINT HashKey(const GUID& guid)
  274. {
  275. unsigned short* Values = (unsigned short *)&guid;
  276. return (Values[0] ^ Values[1] ^ Values[2] ^ Values[3] ^
  277. Values[4] ^ Values[5] ^ Values[6] ^ Values[7]);
  278. }
  279. //-----------------------------------------------------
  280. // CExtensionLink class
  281. //
  282. // Represents one link from a snapin to an extension.
  283. // Each CSnapinInfo object maintains a list of these.
  284. //-----------------------------------------------------
  285. typedef CExtensionLink* PEXTENSIONLINK;
  286. class CExtensionLink
  287. {
  288. public:
  289. typedef enum _EXTENSION_STATE
  290. {
  291. EXTEN_OFF,
  292. EXTEN_READY,
  293. EXTEN_ON
  294. } EXTENSION_STATE;
  295. // Constructor/Destructor
  296. CExtensionLink(CSnapinInfo* pSnapInfo) :
  297. m_pSnapInfo(pSnapInfo), m_pNext(NULL), m_iExtTypes(0),
  298. m_eOrigState(EXTEN_OFF), m_bRequired(FALSE), m_eCurState(EXTEN_OFF) {}
  299. private:
  300. // Attributes
  301. EXTENSION_STATE m_eOrigState; // Original state of link
  302. EXTENSION_STATE m_eCurState; // Current state
  303. BOOL m_bRequired; // Is a required extension
  304. int m_iExtTypes; // Extension type flags (from class CExtSI)
  305. CSnapinInfo* m_pSnapInfo; // ptr to extension snapin info
  306. PEXTENSIONLINK m_pNext; // ptr to next extension link
  307. public:
  308. // Operations
  309. void SetInitialState(EXTENSION_STATE eState) { m_eOrigState = eState; }
  310. void SetState(EXTENSION_STATE eState);
  311. void SetExtTypes(int iExtTypes) { m_iExtTypes = iExtTypes; }
  312. int GetExtTypes() { return m_iExtTypes; }
  313. void SetNext(CExtensionLink* pExtNext) { m_pNext = pExtNext; }
  314. EXTENSION_STATE GetState(void) { return m_eCurState; }
  315. CSnapinInfo* GetSnapinInfo(void) { return m_pSnapInfo; }
  316. BOOL IsChanged(void)
  317. { return (m_eOrigState == EXTEN_ON && m_eCurState != EXTEN_ON) ||
  318. (m_eOrigState != EXTEN_ON && m_eCurState == EXTEN_ON);
  319. }
  320. BOOL IsRequired(void) { return m_bRequired; }
  321. void SetRequired(BOOL bState = TRUE) { m_bRequired = bState; }
  322. PEXTENSIONLINK Next(void) { return m_pNext; }
  323. };
  324. //-----------------------------------------------------
  325. // CNewTreeNode class
  326. //
  327. // Holds information for a new node created by the
  328. // snapin manager. The objects are kept in a NewNodeList
  329. // owned by the CSnapinManager. The list is passed to
  330. // the scope tree handler to create the real nodes.
  331. //-----------------------------------------------------
  332. class CNewTreeNode
  333. {
  334. public:
  335. // Contructor / Destructor
  336. CNewTreeNode() : m_pmtNode(NULL), m_pNext(NULL),
  337. m_pChild(NULL), m_pParent(NULL), m_pmtNewNode(NULL),
  338. m_pmtNewSnapInNode(NULL)
  339. {};
  340. ~CNewTreeNode() { if (m_pmtNewNode) m_pmtNewNode->Release(); delete Child(); delete Next(); }
  341. public:
  342. // Operators
  343. PNEWTREENODE Next() { return m_pNext; }
  344. PNEWTREENODE Child() { return m_pChild; }
  345. PNEWTREENODE Parent() { return m_pParent;}
  346. CMTNode* GetMTNode() {return m_pmtNode;}
  347. VOID AddChild(PNEWTREENODE pntNode);
  348. VOID RemoveChild(PNEWTREENODE pntNode);
  349. public:
  350. // Attributes
  351. CMTNode* m_pmtNode; // pointer to parent MTNode (NULL if child of new node)
  352. PNEWTREENODE m_pNext; // pointer to next sibling
  353. PNEWTREENODE m_pChild; // pointer to first child
  354. PNEWTREENODE m_pParent; // pointer to new node parent (NULL if child of MTNode)
  355. //Specific node data
  356. IComponentDataPtr m_spIComponentData; // pointer to the snapin's IComponentData (if snapin)
  357. CLSID m_clsidSnapIn; // snapin CLSID (if snapin)
  358. CMTNode* m_pmtNewNode; // Pointer to new node (if not snapin node)
  359. PropertiesPtr m_spSnapinProps; // pointer to the snap-in's properties
  360. CMTSnapInNode* m_pmtNewSnapInNode; // new snap-in node
  361. };
  362. //------------------------------------------------------
  363. // CManagerNode class
  364. //
  365. // Primary object that node manager handles. Each object
  366. // represents one static standalone node. The objects
  367. // are linked in a tree structure owned by the
  368. // CSnapinManager class.
  369. //------------------------------------------------------
  370. typedef CManagerNode* PMANAGERNODE;
  371. typedef CList <PMANAGERNODE, PMANAGERNODE> ManagerNodeList;
  372. class CManagerNode
  373. {
  374. public:
  375. // Constructor / Destructor
  376. CManagerNode(): m_nType(0), m_pmtNode(NULL),
  377. m_pSnapInfo(NULL), m_pNewNode(NULL) {}
  378. ~CManagerNode();
  379. public:
  380. // Attributes
  381. PMANAGERNODE m_pmgnParent; // pointer to parent node
  382. ManagerNodeList m_ChildList; // Child node list
  383. CStr m_strValue; // Display name string
  384. int m_nType; // node type (ADDNSP_SNAPIN or ADDSNP_STATICNODE)
  385. CMTNode* m_pmtNode; // pointer to MTNode (for existing node only)
  386. PNEWTREENODE m_pNewNode; // pointer to new tree node (for new nodes only)
  387. PSNAPININFO m_pSnapInfo; // pointer Snapin information
  388. int m_iImage; // image list indices
  389. int m_iOpenImage;
  390. int m_iIndent; // indentation level for tree view
  391. // Operators
  392. VOID AddChild(PMANAGERNODE pmgnNode);
  393. VOID RemoveChild(PMANAGERNODE pmgnNode);
  394. PSNAPININFO GetSnapinInfo(void) { return m_pSnapInfo; }
  395. BOOL HasAboutInfo(void) { return (m_pSnapInfo && m_pSnapInfo->HasAbout()); }
  396. };
  397. /*+-------------------------------------------------------------------------*
  398. * class CSnapinManagerAdd
  399. *
  400. *
  401. * PURPOSE: Dialog for selecting type of snapin to add. Called by
  402. * CSnapinStandAlonePage to enable the user to select a page. When the user
  403. * selects a snapin, calls back into the CSnapinStandAlonePage to add
  404. * the snapin.
  405. *
  406. * NOTE: This object does not know about where in the tree the snapin will
  407. * be added. That is handled by the CSnapinStandalone page.
  408. ************************************************************************/
  409. class CSnapinManagerAdd : public CDialogImpl<CSnapinManagerAdd>
  410. {
  411. // Constructor/Destrcutor
  412. public:
  413. CSnapinManagerAdd(CSnapinManager* pManager, CSnapinStandAlonePage* pStandAlonePage);
  414. ~CSnapinManagerAdd();
  415. //MSGMAP
  416. public:
  417. BEGIN_MSG_MAP(CSnapinManagerAdd)
  418. // MESSAGE_HANDLER(WM_SHOWWINDOW, OnShowWindow)
  419. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  420. MESSAGE_HANDLER(WM_COMMAND, OnCommand)
  421. MESSAGE_HANDLER(WM_SYSCOMMAND, OnSysCommand);
  422. CONTEXT_HELP_HANDLER()
  423. MESSAGE_HANDLER(MSG_LOADABOUT_COMPLETE, OnLoadAboutComplete)
  424. NOTIFY_HANDLER(IDC_SNAPIN_LV, LVN_ITEMCHANGED, OnItemChanged)
  425. NOTIFY_HANDLER(IDC_SNAPIN_LV, LVN_GETDISPINFO, OnGetDispInfo)
  426. NOTIFY_HANDLER(IDC_SNAPIN_LV, NM_DBLCLK, OnListDblClick)
  427. END_MSG_MAP()
  428. IMPLEMENT_CONTEXT_HELP(g_aHelpIDs_IDD_SNAPIN_MANAGER_ADD);
  429. // Operators
  430. PSNAPININFO SelectedInfo() { return m_pInfoSelected; }
  431. public:
  432. // Operators
  433. enum { IDD = IDD_SNAPIN_MANAGER_ADD };
  434. // Generated message map functions
  435. protected:
  436. LRESULT OnShowWindow(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  437. LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  438. LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  439. LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  440. LRESULT OnItemChanged(int idCtrl, LPNMHDR pNMHDR, BOOL& bHandled);
  441. LRESULT OnGetDispInfo(int idCtrl, LPNMHDR pNMHDR, BOOL& bHandled);
  442. LRESULT OnListDblClick(int idCtrl, LPNMHDR pNMHDR, BOOL& bHandled);
  443. LRESULT OnLoadAboutComplete(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  444. void BuildSnapinList();
  445. // Attributes
  446. CSnapinManager* m_pManager; // Pointer to owning manager
  447. CSnapinStandAlonePage* m_pStandAlonePage; // Pointer to calling page
  448. WTL::CListViewCtrl* m_pListCtrl; // snapin listview
  449. BOOL m_bDoOnce; // TRUE first time through ShowWindow
  450. PSNAPININFO m_pInfoSelected; // Selected snapin info
  451. int m_iGetInfoIndex; // index of snapin with pending About info
  452. CStr m_strNotInstalled; // string to display for uninstalled snap-ins
  453. };
  454. //------------------------------------------------------
  455. // CSnapinStandAlonePage class
  456. //
  457. // The property page for adding/removing standalone
  458. // snapin nodes.
  459. //------------------------------------------------------
  460. class CSnapinStandAlonePage : public WTL::CPropertyPageImpl<CSnapinStandAlonePage>
  461. {
  462. public:
  463. typedef WTL::CPropertyPageImpl<CSnapinStandAlonePage> BC;
  464. // Constructor/destructor
  465. CSnapinStandAlonePage(CSnapinManager* pManager);
  466. ~CSnapinStandAlonePage();
  467. enum { IDD = IDD_SNAPIN_STANDALONE_PROPP };
  468. private:
  469. CSnapinManagerAdd& GetAddDialog() {return m_dlgAdd;}
  470. private:
  471. // attributes
  472. CSnapinManager* m_pManager; // pointer to owning snapin manager
  473. CSnapinManagerAdd m_dlgAdd; // pointer to add dialog
  474. WTL::CListViewCtrl m_snpListCtrl; // listview for displaying child nodes
  475. CComboBoxEx2 m_snpComboBox; // combobox for selecting parent node
  476. WTL::CToolBarCtrl m_ToolbarCtrl; // toolbar for folder-up button
  477. PMANAGERNODE m_pmgnParent; // currently selcted parent node
  478. PMANAGERNODE m_pmgnChild; // currently selcted child node
  479. protected:
  480. BEGIN_MSG_MAP( CSnapinStandAlonePage )
  481. COMMAND_HANDLER(IDC_SNAPIN_COMBOEX, CBN_SELENDOK, OnTreeItemSelect)
  482. NOTIFY_HANDLER(IDC_SNAPIN_ADDED_LIST, LVN_ITEMCHANGED, OnListItemChanged)
  483. NOTIFY_HANDLER(IDC_SNAPIN_ADDED_LIST, LVN_KEYDOWN, OnListKeyDown)
  484. NOTIFY_HANDLER(IDC_SNAPIN_ADDED_LIST, NM_DBLCLK, OnListItemDblClick)
  485. COMMAND_ID_HANDLER(ID_SNP_UP, OnTreeUp)
  486. COMMAND_ID_HANDLER(IDC_SNAPIN_MANAGER_ADD, OnAddSnapin)
  487. COMMAND_ID_HANDLER(IDC_SNAPIN_MANAGER_DELETE, OnDeleteSnapin)
  488. COMMAND_ID_HANDLER(IDC_SNAPIN_ABOUT, OnAboutSnapin)
  489. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  490. CONTEXT_HELP_HANDLER()
  491. CHAIN_MSG_MAP(BC)
  492. END_MSG_MAP()
  493. IMPLEMENT_CONTEXT_HELP(g_aHelpIDs_IDD_SNAPIN_STANDALONE_PROPP);
  494. // operations
  495. LRESULT OnTreeItemSelect( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );
  496. LRESULT OnListItemChanged( int idCtrl, LPNMHDR pnmh, BOOL& bHandled );
  497. LRESULT OnListKeyDown( int idCtrl, LPNMHDR pnmh, BOOL& bHandled );
  498. LRESULT OnListItemDblClick( int idCtrl, LPNMHDR pnmh, BOOL& bHandled );
  499. LRESULT OnTreeUp( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );
  500. LRESULT OnAddSnapin( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );
  501. LRESULT OnDeleteSnapin( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );
  502. LRESULT OnAboutSnapin( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );
  503. LRESULT OnInitDialog( UINT mMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled );
  504. VOID AddNodeListToTree(ManagerNodeList& NodeList);
  505. int AddChildToTree(PMANAGERNODE pMgrNode);
  506. VOID DisplayChildList(ManagerNodeList& NodeList);
  507. int AddChildToList(PMANAGERNODE pMgrNode, int iIndex = -1);
  508. VOID SelectParentNodeItem(PMANAGERNODE pMgrNode);
  509. VOID SetupParentNode(PMANAGERNODE pMgrNode, bool bVisible = true);
  510. VOID SetupChildNode(PMANAGERNODE pMgrNode);
  511. SC ScRunSnapinWizard (const CLSID& clsid, HWND hwndParent,
  512. Properties* pInitProps,
  513. IComponentData*& rpComponentData,
  514. Properties*& rpSnapinProps);
  515. public:
  516. HRESULT AddOneSnapin(CSnapinInfo* pSnapInfo, bool bVisible = true);
  517. SC ScAddOneSnapin(PMANAGERNODE pmgNodeParent, PSNAPININFO pSnapInfo);
  518. SC ScRemoveOneSnapin(PMANAGERNODE pmgNodeTobeRemoved, int iItem, bool bVisible = true);
  519. };
  520. //------------------------------------------------------
  521. // CSnapinExtensionPage class
  522. //
  523. // The property page configuring snapin extensions.
  524. //------------------------------------------------------
  525. class CSnapinExtensionPage : public WTL::CPropertyPageImpl<CSnapinExtensionPage>
  526. {
  527. public:
  528. typedef WTL::CPropertyPageImpl<CSnapinExtensionPage> BC;
  529. // Constructor/destructor
  530. CSnapinExtensionPage(CSnapinManager* pManager) :
  531. m_pManager(pManager), m_pCurSnapInfo(NULL), m_pExtLink(NULL) {}
  532. ~CSnapinExtensionPage();
  533. enum { IDD = IDD_SNAPIN_EXTENSION_PROPP };
  534. private:
  535. // Attributes
  536. CSnapinManager* m_pManager; // ptr to owning manager
  537. CComboBoxEx2 m_SnapComboBox; // combobox for selecting snapin
  538. CCheckList m_ExtListCtrl; // list of extensions
  539. PSNAPININFO m_pCurSnapInfo; // currently selected snapin
  540. PEXTENSIONLINK m_pExtLink; // currently selected extension
  541. BOOL m_bUpdateSnapinList; // TRUE if snapin list may have changed
  542. WTL::CImageList m_ilCheckbox; // checkbox image list
  543. protected:
  544. BEGIN_MSG_MAP(CSnapinExtensPage)
  545. COMMAND_HANDLER( IDC_SNAPIN_COMBOEX, CBN_SELENDOK, OnSnapinSelect )
  546. COMMAND_HANDLER( IDC_SNAPIN_COMBOEX, CBN_DROPDOWN, OnSnapinDropDown )
  547. COMMAND_HANDLER( IDC_SNAPIN_ENABLEALL, BN_CLICKED, OnEnableAllChanged )
  548. COMMAND_ID_HANDLER( IDC_SNAPIN_ABOUT, OnAboutSnapin )
  549. COMMAND_ID_HANDLER( IDC_SNAPIN_DOWNLOAD, OnDownloadSnapin )
  550. NOTIFY_HANDLER( IDC_EXTENSION_LIST, LVN_ITEMCHANGED, OnExtensionChanged )
  551. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  552. CONTEXT_HELP_HANDLER()
  553. CHAIN_MSG_MAP(BC)
  554. END_MSG_MAP()
  555. IMPLEMENT_CONTEXT_HELP(g_aHelpIDs_IDD_SNAPIN_EXTENSION_PROPP);
  556. // Operations
  557. LRESULT OnSnapinSelect( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );
  558. LRESULT OnExtensionChanged( int idCtrl, LPNMHDR pnmh, BOOL& bHandled );
  559. LRESULT OnEnableAllChanged( WORD wNotifyCode, WORD wID, HWND hWndCtrl, BOOL& bHandled );
  560. LRESULT OnSnapinDropDown( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );
  561. LRESULT OnAboutSnapin( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );
  562. LRESULT OnDownloadSnapin( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );
  563. LRESULT OnInitDialog( UINT mMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled );
  564. BOOL OnSetActive(void);
  565. void BuildSnapinList(void);
  566. void BuildExtensionList(PSNAPININFO pSnapInfo);
  567. };
  568. //------------------------------------------------------
  569. // CSnapinManager class
  570. //
  571. // Top level mannger object.
  572. //------------------------------------------------------
  573. typedef CList<CMTNode*, CMTNode*> MTNodesList;
  574. class CSnapinManager : public WTL::CPropertySheet
  575. {
  576. friend class CSnapinStandAlonePage;
  577. friend class CSnapinExtensionPage;
  578. friend class CSnapinManagerAdd;
  579. DECLARE_NOT_COPIABLE (CSnapinManager)
  580. DECLARE_NOT_ASSIGNABLE (CSnapinManager)
  581. public:
  582. // Constructor/Destructor
  583. CSnapinManager(CMTNode *pmtNode);
  584. ~CSnapinManager();
  585. // Attributes
  586. typedef CList<CSnapIn*, CSnapIn*> SNPList; // TEMP TEMP
  587. SNPList m_snpSnapinChangedList; // List of modified snapins
  588. MTNodesList m_mtnDeletedNodesList; // List of delted MT ndoes
  589. NewNodeList m_NewNodesList; // Tree of added nodes
  590. // Operators
  591. virtual int DoModal(void);
  592. MTNodesList* GetDeletedNodesList(void) { return &m_mtnDeletedNodesList; }
  593. NewNodeList* GetNewNodes(void) { return &m_NewNodesList; }
  594. SNPList* GetSnapinChangedList(void) { return &m_snpSnapinChangedList; }
  595. HRESULT LoadAboutInfoAsync(PSNAPININFO pSnapInfo, HWND hWndNotify);
  596. CSnapinInfoCache &GetSnapinInfoCache() {return m_SnapinInfoCache;}
  597. SC ScInitialize();
  598. public:
  599. // object method operations
  600. SC ScAddSnapin(LPCWSTR szSnapinNameOrCLSIDOrProgID, SnapIn* pParentSnapinNode, Properties *pProperties);
  601. SC ScRemoveSnapin(CMTNode *pMTNode);
  602. SC ScEnableAllExtensions(const CLSID& clsidSnapin, BOOL bEnable);
  603. SC ScEnableExtension(const CLSID& clsidPrimarySnapin, const CLSID& clsidExtension, bool bEnable);
  604. protected:
  605. // Operations
  606. BOOL LoadMTNodeTree(PMANAGERNODE pmgnParent, CMTNode* pMTNode);
  607. SC ScLoadSnapinInfo(void);
  608. void UpdateSnapInCache();
  609. PMANAGERNODE FindManagerNode(const ManagerNodeList& mgNodeList, CMTNode *pMTNode);
  610. SC ScGetSnapinInfo(LPCWSTR szSnapinNameOrCLSIDOrProgID, CSnapinInfo **ppSnapinInfo);
  611. // Attributes
  612. WTL::CImageList m_iml; // imagelist shared by all controls
  613. CMTNode* m_pmtNode; // Root node of master tree
  614. ManagerNodeList m_mgNodeList; // List of manager nodes
  615. CSnapinInfoCache m_SnapinInfoCache; // Cache of snapin info objects
  616. CAboutInfoThread m_AboutInfoThread; // Worker thread class
  617. bool m_bInitialized : 1; // Should initialize only once.
  618. private:
  619. // Attributes
  620. CSnapinStandAlonePage m_proppStandAlone; // Standalone property page
  621. CSnapinExtensionPage m_proppExtension; // Extensions property page
  622. CPolicy *m_pMMCPolicy;
  623. };
  624. int CALLBACK _ListViewCompareFunc(LPARAM lParam1,LPARAM lParam2,LPARAM lParamSort);
  625. #endif // __ADDSNPIN_H__