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.

726 lines
19 KiB

  1. // SystemScopeItem.cpp: implementation of the CSystemScopeItem class.
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // 03/22/00 v-marfin 59675 : Rearranged data group menu items.
  6. // 03/30/00 v-marfin 62696 : Help link fix
  7. // 04/05/00 v-marfin 62903 : Ensure SystemCopeItem's OnDestory is called when
  8. // disconnecting a computer from the scope pane.
  9. #include "stdafx.h"
  10. #include "snapin.h"
  11. #include "SystemScopeItem.h"
  12. #include "SystemResultsView.h"
  13. #include "HealthmonScopePane.h"
  14. #include "ResultsPane.h"
  15. #include "RemoveSystemDlg.h"
  16. #include "System.h"
  17. #include "SysGeneralPage.h"
  18. #include "ActionAssociationPage.h"
  19. #include "SystemGroupScopeItem.h"
  20. #include "AllSystemsScopeItem.h"
  21. #include "SystemGroup.h"
  22. #include "RootScopeItem.h"
  23. #include "RemovesystemDlg.h"
  24. #include "ActionPolicyScopeItem.h"
  25. #include "EventManager.h"
  26. #ifdef _DEBUG
  27. #undef THIS_FILE
  28. static char THIS_FILE[]=__FILE__;
  29. #define new DEBUG_NEW
  30. #endif
  31. IMPLEMENT_DYNCREATE(CSystemScopeItem,CHMScopeItem)
  32. // {D5D74613-BA11-11d2-BD76-0000F87A3912}
  33. static GUID GUID_System =
  34. { 0xd5d74613, 0xba11, 0x11d2, { 0xbd, 0x76, 0x0, 0x0, 0xf8, 0x7a, 0x39, 0x12 } };
  35. // icon table - associates state to icons
  36. static UINT _Icons[HMS_MAX_STATES] =
  37. {
  38. IDI_ICON_SYSTEM,
  39. IDI_ICON_SYSTEM_DISABLED,
  40. IDI_ICON_SYSTEM_OUTAGE,
  41. IDI_ICON_SYSTEM_UNKNOWN,
  42. IDI_ICON_SYSTEM_NO_CONNECT,
  43. IDI_ICON_SYSTEM_WARNING,
  44. IDI_ICON_SYSTEM_CRITICAL
  45. };
  46. // icon table - associates state to icons
  47. static UINT _ShortcutIcons[HMS_MAX_STATES] =
  48. {
  49. IDI_ICON_SYSTEM_SHORTCUT,
  50. IDI_ICON_SYSTEM_SHORTCUT_DISABLED,
  51. IDI_ICON_SYSTEM_SHORTCUT_OUTAGE,
  52. IDI_ICON_SYSTEM_SHORTCUT_UNKNOWN,
  53. IDI_ICON_SYSTEM_SHORTCUT_NO_CONNECT,
  54. IDI_ICON_SYSTEM_SHORTCUT_WARNING,
  55. IDI_ICON_SYSTEM_SHORTCUT_CRITICAL
  56. };
  57. //////////////////////////////////////////////////////////////////////
  58. // Construction/Destruction
  59. //////////////////////////////////////////////////////////////////////
  60. CSystemScopeItem::CSystemScopeItem()
  61. {
  62. m_lpguidItemType = &GUID_System;
  63. }
  64. CSystemScopeItem::~CSystemScopeItem()
  65. {
  66. Destroy();
  67. }
  68. //////////////////////////////////////////////////////////////////////
  69. // Creation Members
  70. //////////////////////////////////////////////////////////////////////
  71. bool CSystemScopeItem::Create(CScopePane* pScopePane, CScopePaneItem* pParentItem)
  72. {
  73. TRACEX(_T("CSystemScopeItem::Create\n"));
  74. TRACEARGn(pScopePane);
  75. TRACEARGn(pParentItem);
  76. // set up all the icons first
  77. for( int i = 0; i < HMS_MAX_STATES; i++ )
  78. {
  79. UINT nId = 0L;
  80. if( pParentItem->GetRuntimeClass()->m_lpszClassName == CString(_T("CAllSystemsScopeItem")) )
  81. {
  82. nId = _Icons[i];
  83. }
  84. else
  85. {
  86. nId = _ShortcutIcons[i];
  87. }
  88. m_IconResIds.Add(nId);
  89. m_OpenIconResIds.Add(nId);
  90. }
  91. SetIconIndex(HMS_NORMAL);
  92. SetOpenIconIndex(HMS_NORMAL);
  93. // call base class Create method
  94. if( ! CHMScopeItem::Create(pScopePane,pParentItem) )
  95. {
  96. TRACE(_T("CHMScopeItem::Create failed.\n"));
  97. return false;
  98. }
  99. // set display names
  100. CString sName;
  101. sName.LoadString(IDS_STRING_UNTITLED);
  102. SetDisplayName(0,sName);
  103. return true;
  104. }
  105. //////////////////////////////////////////////////////////////////////
  106. // Results Pane View Members
  107. //////////////////////////////////////////////////////////////////////
  108. CResultsPaneView* CSystemScopeItem::CreateResultsPaneView()
  109. {
  110. TRACEX(_T("CSystemScopeItem::CreateResultsPaneView\n"));
  111. return new CSystemResultsView;
  112. }
  113. //////////////////////////////////////////////////////////////////////
  114. // MMC Notify Handlers
  115. //////////////////////////////////////////////////////////////////////
  116. HRESULT CSystemScopeItem::OnAddMenuItems(LPCONTEXTMENUCALLBACK piCallback,long __RPC_FAR *pInsertionAllowed)
  117. {
  118. TRACEX(_T("CSystemScopeItem::OnAddMenuItems\n"));
  119. TRACEARGn(piCallback);
  120. TRACEARGn(pInsertionAllowed);
  121. HRESULT hr = S_OK;
  122. // Add New Menu Items
  123. if( CCM_INSERTIONALLOWED_NEW & *pInsertionAllowed )
  124. {
  125. CONTEXTMENUITEM cmi;
  126. CString sResString;
  127. CString sResString2;
  128. // Component...
  129. sResString.LoadString(IDS_STRING_NEW_COMPONENT);
  130. cmi.strName = LPTSTR(LPCTSTR(sResString));
  131. sResString2.LoadString(IDS_STRING_NEW_COMPONENT_DESCRIPTION);
  132. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  133. cmi.lCommandID = IDM_NEW_DATA_GROUP;
  134. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_NEW;
  135. cmi.fFlags = 0;
  136. cmi.fSpecialFlags = 0;
  137. hr = piCallback->AddItem(&cmi);
  138. if( !SUCCEEDED(hr) )
  139. {
  140. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  141. return hr;
  142. }
  143. }
  144. // Add Task Menu Items
  145. if( CCM_INSERTIONALLOWED_TASK & *pInsertionAllowed )
  146. {
  147. CONTEXTMENUITEM cmi;
  148. CString sResString;
  149. CString sResString2;
  150. // Disconnect
  151. if( GfxCheckObjPtr(GetParent(),CAllSystemsScopeItem) ) // it is not a shortcut
  152. {
  153. sResString.LoadString(IDS_STRING_DISCONNECT);
  154. cmi.strName = LPTSTR(LPCTSTR(sResString));
  155. cmi.strStatusBarText = NULL;
  156. cmi.lCommandID = IDM_DISCONNECT;
  157. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  158. cmi.fFlags = 0;
  159. cmi.fSpecialFlags = 0;
  160. hr = piCallback->AddItem(&cmi);
  161. if( !SUCCEEDED(hr) )
  162. {
  163. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  164. return hr;
  165. }
  166. }
  167. // v-marfin 59675 : rearrange menu items
  168. // separator
  169. cmi.strName = NULL;
  170. cmi.strStatusBarText = NULL;
  171. cmi.lCommandID = NULL;
  172. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  173. cmi.fFlags = MF_SEPARATOR;
  174. cmi.fSpecialFlags = 0;
  175. hr = piCallback->AddItem(&cmi);
  176. if( !SUCCEEDED(hr) )
  177. {
  178. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  179. return hr;
  180. }
  181. // clear events
  182. sResString.LoadString(IDS_STRING_CLEAR_EVENTS);
  183. cmi.strName = LPTSTR(LPCTSTR(sResString));
  184. sResString2.LoadString(IDS_STRING_CLEAR_EVENTS_DESCRIPTION);
  185. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  186. cmi.lCommandID = IDM_CLEAR_EVENTS;
  187. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  188. cmi.fFlags = 0;
  189. cmi.fSpecialFlags = 0;
  190. hr = piCallback->AddItem(&cmi);
  191. if( !SUCCEEDED(hr) )
  192. {
  193. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  194. return hr;
  195. }
  196. // Reset Statistics
  197. sResString.LoadString(IDS_STRING_RESET_STATISTICS);
  198. cmi.strName = LPTSTR(LPCTSTR(sResString));
  199. sResString2.LoadString(IDS_STRING_RESET_STATISTICS_DESC);
  200. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  201. cmi.lCommandID = IDM_RESET_STATISTICS;
  202. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  203. cmi.fFlags = 0;
  204. cmi.fSpecialFlags = 0;
  205. hr = piCallback->AddItem(&cmi);
  206. if( !SUCCEEDED(hr) )
  207. {
  208. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  209. return hr;
  210. }
  211. // separator
  212. cmi.strName = NULL;
  213. cmi.strStatusBarText = NULL;
  214. cmi.lCommandID = NULL;
  215. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  216. cmi.fFlags = MF_SEPARATOR;
  217. cmi.fSpecialFlags = 0;
  218. hr = piCallback->AddItem(&cmi);
  219. if( !SUCCEEDED(hr) )
  220. {
  221. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  222. return hr;
  223. }
  224. // reset status
  225. sResString.LoadString(IDS_STRING_RESET_STATUS);
  226. cmi.strName = LPTSTR(LPCTSTR(sResString));
  227. sResString2.LoadString(IDS_STRING_RESET_STATUS_DESCRIPTION);
  228. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  229. cmi.lCommandID = IDM_RESET_STATUS;
  230. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  231. cmi.fFlags = 0;
  232. cmi.fSpecialFlags = 0;
  233. hr = piCallback->AddItem(&cmi);
  234. if( !SUCCEEDED(hr) )
  235. {
  236. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  237. return hr;
  238. }
  239. // check now
  240. sResString.LoadString(IDS_STRING_CHECK_NOW);
  241. cmi.strName = LPTSTR(LPCTSTR(sResString));
  242. sResString2.LoadString(IDS_STRING_CHECK_NOW_DESC);
  243. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  244. cmi.lCommandID = IDM_CHECK_NOW;
  245. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  246. cmi.fFlags = 0;
  247. cmi.fSpecialFlags = 0;
  248. hr = piCallback->AddItem(&cmi);
  249. if( !SUCCEEDED(hr) )
  250. {
  251. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  252. return hr;
  253. }
  254. // separator
  255. cmi.strName = NULL;
  256. cmi.strStatusBarText = NULL;
  257. cmi.lCommandID = NULL;
  258. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  259. cmi.fFlags = MF_SEPARATOR;
  260. cmi.fSpecialFlags = 0;
  261. hr = piCallback->AddItem(&cmi);
  262. if( !SUCCEEDED(hr) )
  263. {
  264. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  265. return hr;
  266. }
  267. // disable monitoring
  268. sResString.LoadString(IDS_STRING_ENABLE_ALL_THRESHOLDS);
  269. cmi.strName = LPTSTR(LPCTSTR(sResString));
  270. sResString2.LoadString(IDS_STRING_ENABLE_ALL_THRESHOLDS_DESCRIPTION);
  271. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  272. cmi.lCommandID = IDM_DISABLE_MONITORING;
  273. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  274. CHMObject* pObject = GetObjectPtr();
  275. CHMScopeItem* pParentItem = (CHMScopeItem*)GetParent();
  276. // disable menu item if null object ptr or parent is disabled
  277. if( ! pObject || (pParentItem && pParentItem->GetObjectPtr()
  278. && !pParentItem->GetObjectPtr()->IsEnabled()) )
  279. {
  280. cmi.fFlags = MF_DISABLED|MF_GRAYED;
  281. }
  282. else
  283. {
  284. int iState = pObject->IsEnabled();
  285. if( iState == -1 )
  286. {
  287. cmi.fFlags = MF_DISABLED|MF_GRAYED;
  288. }
  289. else if( iState == 0 )
  290. {
  291. cmi.fFlags = MF_CHECKED;
  292. }
  293. else if( iState == 1 )
  294. {
  295. cmi.fFlags = MF_UNCHECKED;
  296. }
  297. }
  298. cmi.fSpecialFlags = 0;
  299. hr = piCallback->AddItem(&cmi);
  300. if( !SUCCEEDED(hr) )
  301. {
  302. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  303. return hr;
  304. }
  305. }
  306. // Add View Menu Items
  307. if( CCM_INSERTIONALLOWED_VIEW & *pInsertionAllowed )
  308. {
  309. CONTEXTMENUITEM cmi;
  310. CString sResString;
  311. CString sResString2;
  312. sResString.LoadString(IDS_STRING_STATUS_ONLY);
  313. cmi.strName = LPTSTR(LPCTSTR(sResString));
  314. sResString2.LoadString(IDS_STRING_STATUS_ONLY_DESCRIPTION);
  315. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  316. cmi.lCommandID = IDM_STATUS_ONLY;
  317. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_VIEW;
  318. cmi.fFlags = MF_UNCHECKED;
  319. cmi.fSpecialFlags = 0;
  320. hr = piCallback->AddItem(&cmi);
  321. if( !SUCCEEDED(hr) )
  322. {
  323. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  324. return hr;
  325. }
  326. sResString.LoadString(IDS_STRING_AUTO_FILTER);
  327. cmi.strName = LPTSTR(LPCTSTR(sResString));
  328. sResString2.LoadString(IDS_STRING_AUTO_FILTER_DESCRIPTION);
  329. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  330. cmi.lCommandID = IDM_AUTO_FILTER;
  331. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_VIEW;
  332. cmi.fFlags = MF_CHECKED;
  333. cmi.fSpecialFlags = 0;
  334. hr = piCallback->AddItem(&cmi);
  335. if( !SUCCEEDED(hr) )
  336. {
  337. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  338. return hr;
  339. }
  340. // icon legend
  341. sResString.LoadString(IDS_STRING_ICON_LEGEND);
  342. cmi.strName = LPTSTR(LPCTSTR(sResString));
  343. sResString2.LoadString(IDS_STRING_ICON_LEGEND_DESCRIPTION);
  344. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  345. cmi.lCommandID = IDM_ICON_LEGEND;
  346. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_VIEW;
  347. cmi.fFlags = 0;
  348. cmi.fSpecialFlags = 0;
  349. hr = piCallback->AddItem(&cmi);
  350. if( !SUCCEEDED(hr) )
  351. {
  352. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  353. return hr;
  354. }
  355. }
  356. return hr;
  357. }
  358. HRESULT CSystemScopeItem::OnCommand(long lCommandID)
  359. {
  360. TRACEX(_T("CSystemScopeItem::OnCommand\n"));
  361. TRACEARGn(lCommandID);
  362. HRESULT hr = S_OK;
  363. switch(lCommandID)
  364. {
  365. case IDM_NEW_DATA_GROUP:
  366. {
  367. CSystem* pSystem = (CSystem*)GetObjectPtr();
  368. if( ! GfxCheckObjPtr(pSystem,CSystem) )
  369. {
  370. return E_FAIL;
  371. }
  372. pSystem->CreateNewChildDataGroup();
  373. }
  374. break;
  375. case IDM_DISCONNECT:
  376. {
  377. OnDelete();
  378. }
  379. break;
  380. case IDM_EXPORT:
  381. {
  382. CString sFilter;
  383. sFilter.LoadString(IDS_STRING_MOF_FILTER);
  384. CFileDialog fd(FALSE,_T("MOF"),NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,sFilter);
  385. if( fd.DoModal() == IDOK )
  386. {
  387. CFile file;
  388. if( ! file.Open(fd.GetPathName(),CFile::modeCreate|CFile::modeWrite|CFile::shareExclusive) )
  389. {
  390. return S_OK;
  391. }
  392. CArchive ar(&file,CArchive::store);
  393. CHMObject* pObject = GetObjectPtr();
  394. if( pObject )
  395. {
  396. pObject->ExportMofFile(ar);
  397. }
  398. }
  399. }
  400. break;
  401. default:
  402. {
  403. hr = CHMScopeItem::OnCommand(lCommandID);
  404. }
  405. }
  406. return hr;
  407. }
  408. HRESULT CSystemScopeItem::OnCreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider, INT_PTR handle)
  409. {
  410. TRACEX(_T("CSystemScopeItem::OnCreatePropertyPages\n"));
  411. TRACEARGn(lpProvider);
  412. TRACEARGn(handle);
  413. if( m_pScopePane == NULL )
  414. {
  415. return S_FALSE;
  416. }
  417. HRESULT hr = S_OK;
  418. // create the pages
  419. CSysGeneralPage* pPage1 = new CSysGeneralPage;
  420. pPage1->SetObjectPtr(GetObjectPtr());
  421. HPROPSHEETPAGE hPage1 = CreatePropertySheetPage( reinterpret_cast<LPCPROPSHEETPAGE>(&pPage1->m_psp) );
  422. hr = lpProvider->AddPage(hPage1);
  423. CActionAssociationPage* pPage2 = new CActionAssociationPage;
  424. //---------------------------------------------------------------------------------------------
  425. // v-marfin 62192 : by default the action property page will load its threshold action help.
  426. // so we will override since this is a data group being shown properties, not
  427. // a threshold.
  428. pPage2->m_sHelpTopic = _T("HMon21.chm::/dmcact.htm"); // v-marfin 62696 :dmcact.htm
  429. //----------------------------------------------------------------------------------------------
  430. pPage2->SetObjectPtr(GetObjectPtr());
  431. HPROPSHEETPAGE hPage2 = CreatePropertySheetPage( reinterpret_cast<LPCPROPSHEETPAGE>(&pPage2->m_psp) );
  432. hr = lpProvider->AddPage(hPage2);
  433. return hr;
  434. }
  435. HRESULT CSystemScopeItem::OnDelete(BOOL bConfirm) // v-marfin 62903
  436. {
  437. TRACEX(_T("CSystemScopeItem::OnDelete\n"));
  438. CHMObject* pObject = GetObjectPtr();
  439. if( ! GfxCheckObjPtr(pObject,CSystem) )
  440. {
  441. return E_FAIL;
  442. }
  443. if( ! GetParent() )
  444. {
  445. return E_FAIL;
  446. }
  447. CScopePaneItem* pItemToSelect = NULL;
  448. if( GetScopePane() && GetScopePane()->GetSelectedScopeItem() == this )
  449. {
  450. pItemToSelect = GetParent();
  451. }
  452. if( GfxCheckObjPtr(GetParent(),CAllSystemsScopeItem) ) // it is not a shortcut
  453. {
  454. CRemoveSystemDlg dlg;
  455. if( dlg.DoModal() == IDCANCEL )
  456. {
  457. return S_FALSE;
  458. }
  459. // first query all the scope items and see if any have open property sheets
  460. for( int i = 0; i < pObject->GetScopeItemCount(); i++ )
  461. {
  462. if( pObject->GetScopeItem(i)->IsPropertySheetOpen(true) )
  463. {
  464. AfxMessageBox(IDS_STRING_WARN_PROPPAGE_OPEN);
  465. return S_OK;
  466. }
  467. }
  468. CHealthmonScopePane* pPane = (CHealthmonScopePane*)GetScopePane();
  469. if( ! GfxCheckObjPtr(pPane,CHealthmonScopePane) )
  470. {
  471. return E_FAIL;
  472. }
  473. CSystemGroup* pRootGroup = pPane->GetRootGroup();
  474. if( ! pRootGroup )
  475. {
  476. return E_FAIL;
  477. }
  478. EvtGetEventManager()->RemoveSystemContainer(pObject->GetSystemName());
  479. for( i = pObject->GetScopeItemCount() - 1; i >= 0; i-- )
  480. {
  481. CHMScopeItem* pParentItem = (CHMScopeItem*)pObject->GetScopeItem(i)->GetParent();
  482. if( pParentItem && GfxCheckObjPtr(pParentItem,CHMScopeItem) )
  483. {
  484. CHMObject* pParentObject = pParentItem->GetObjectPtr();
  485. if( pParentObject->IsKindOf(RUNTIME_CLASS(CAllSystemsGroup)) )
  486. {
  487. pParentItem->DestroyChild(this);
  488. pParentObject->RemoveChild(pObject);
  489. }
  490. else
  491. {
  492. ((CSystemGroup*)pParentObject)->RemoveShortcut(pObject);
  493. }
  494. pParentItem->OnChangeChildState(HMS_NORMAL);
  495. }
  496. }
  497. pObject->Destroy(false);
  498. delete pObject;
  499. return S_OK;
  500. }
  501. else // this is a shortcut
  502. {
  503. // first query the scope item and see if it has any open property sheets
  504. if( IsPropertySheetOpen() )
  505. {
  506. AfxMessageBox(IDS_STRING_WARN_PROPPAGE_OPEN);
  507. return S_OK;
  508. }
  509. CHMScopeItem* pGroupItem = (CHMScopeItem*)GetParent();
  510. if( ! pGroupItem )
  511. {
  512. return S_FALSE;
  513. }
  514. CHMScopeItem* pTopmostParentItem = pGroupItem;
  515. while( pTopmostParentItem->GetParent() && ! pTopmostParentItem->GetParent()->IsKindOf(RUNTIME_CLASS(CRootScopeItem)) )
  516. {
  517. pTopmostParentItem = (CHMScopeItem*)pTopmostParentItem->GetParent();
  518. }
  519. CSystemGroup* pGroup = (CSystemGroup*)pGroupItem->GetObjectPtr();
  520. CSystemGroup* pTopmostGroup = (CSystemGroup*)pTopmostParentItem->GetObjectPtr();
  521. if( pGroup )
  522. {
  523. pGroup->RemoveShortcut(GetObjectPtr());
  524. }
  525. pGroupItem->OnChangeChildState(HMS_NORMAL);
  526. pGroupItem->SelectItem();
  527. }
  528. if( pItemToSelect )
  529. {
  530. pItemToSelect->SelectItem();
  531. }
  532. return S_OK;
  533. }
  534. HRESULT CSystemScopeItem::OnExpand(BOOL bExpand)
  535. {
  536. TRACEX(_T("CSystemScopeItem::OnExpand\n"));
  537. TRACEARGn(bExpand);
  538. if( ! GetObjectPtr() )
  539. {
  540. return E_FAIL;
  541. }
  542. if( GetChildCount() == 1 )
  543. {
  544. m_pObject->EnumerateChildren();
  545. }
  546. return CScopePaneItem::OnExpand(bExpand);
  547. }
  548. HRESULT CSystemScopeItem::OnSelect(CResultsPane* pPane, BOOL bSelected)
  549. {
  550. TRACEX(_T("CSystemScopeItem::OnSelect\n"));
  551. TRACEARGn(pPane);
  552. TRACEARGn(bSelected);
  553. if( ! CHECKHRESULT(CHMScopeItem::OnSelect(pPane,bSelected)) )
  554. {
  555. TRACE(_T("FAILED : CHMScopeItem::OnSelect returns failure.\n"));
  556. return E_FAIL;
  557. }
  558. if( ! bSelected ) // we are being de-selected so do not do anything
  559. {
  560. return S_OK;
  561. }
  562. LPCONSOLEVERB lpConsoleVerb = pPane->GetConsoleVerbPtr();
  563. HRESULT hr = lpConsoleVerb->SetVerbState( MMC_VERB_PROPERTIES, ENABLED, TRUE );
  564. if( ! CHECKHRESULT(hr) )
  565. {
  566. TRACE(_T("FAILED : IConsoleVerb::SetVerbState failed.\n"));
  567. lpConsoleVerb->Release();
  568. return hr;
  569. }
  570. lpConsoleVerb->Release();
  571. hr = lpConsoleVerb->SetVerbState( MMC_VERB_CUT, ENABLED, TRUE );
  572. if( ! CHECKHRESULT(hr) )
  573. {
  574. TRACE(_T("FAILED : IConsoleVerb::SetVerbState failed.\n"));
  575. lpConsoleVerb->Release();
  576. return hr;
  577. }
  578. hr = lpConsoleVerb->SetVerbState( MMC_VERB_COPY, ENABLED, TRUE );
  579. if( ! CHECKHRESULT(hr) )
  580. {
  581. TRACE(_T("FAILED : IConsoleVerb::SetVerbState failed.\n"));
  582. lpConsoleVerb->Release();
  583. return hr;
  584. }
  585. hr = lpConsoleVerb->SetVerbState( MMC_VERB_PASTE, ENABLED, TRUE );
  586. if( ! CHECKHRESULT(hr) )
  587. {
  588. TRACE(_T("FAILED : IConsoleVerb::SetVerbState failed.\n"));
  589. lpConsoleVerb->Release();
  590. return hr;
  591. }
  592. hr = lpConsoleVerb->SetVerbState( MMC_VERB_DELETE, ENABLED, TRUE );
  593. if( ! CHECKHRESULT(hr) )
  594. {
  595. TRACE(_T("FAILED : IConsoleVerb::SetVerbState failed.\n"));
  596. lpConsoleVerb->Release();
  597. return hr;
  598. }
  599. return hr;
  600. }