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.

474 lines
13 KiB

  1. // SystemGroupScopeItem.cpp: implementation of the CSystemGroupScopeItem class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Snapin.h"
  6. #include "HealthmonScopePane.h"
  7. #include "SystemGroupScopeItem.h"
  8. #include "SystemGroupResultsView.h"
  9. #include "NewsystemShortcutDlg.h"
  10. #include "SystemGroup.h"
  11. #include "System.h"
  12. #include "GroupGeneralPage.h"
  13. #ifdef _DEBUG
  14. #undef THIS_FILE
  15. static char THIS_FILE[]=__FILE__;
  16. #define new DEBUG_NEW
  17. #endif
  18. // {F768EEC3-BA00-11d2-BD76-0000F87A3912}
  19. static GUID GUID_Group =
  20. { 0xf768eec3, 0xba00, 0x11d2, { 0xbd, 0x76, 0x0, 0x0, 0xf8, 0x7a, 0x39, 0x12 } };
  21. IMPLEMENT_DYNCREATE(CSystemGroupScopeItem,CHMScopeItem)
  22. // icon table - associates state to icons
  23. static UINT _Icons[HMS_MAX_STATES] =
  24. {
  25. IDI_ICON_SYSTEMS,
  26. IDI_ICON_SYSTEMS_DISABLED,
  27. IDI_ICON_SYSTEMS_OUTAGE,
  28. IDI_ICON_SYSTEMS_UNKNOWN,
  29. IDI_ICON_SYSTEMS_NO_CONNECT,
  30. IDI_ICON_SYSTEMS_WARNING,
  31. IDI_ICON_SYSTEMS_CRITICAL
  32. };
  33. //////////////////////////////////////////////////////////////////////
  34. // Construction/Destruction
  35. //////////////////////////////////////////////////////////////////////
  36. CSystemGroupScopeItem::CSystemGroupScopeItem()
  37. {
  38. m_lpguidItemType = &GUID_Group;
  39. }
  40. CSystemGroupScopeItem::~CSystemGroupScopeItem()
  41. {
  42. Destroy();
  43. }
  44. //////////////////////////////////////////////////////////////////////
  45. // Creation Members
  46. //////////////////////////////////////////////////////////////////////
  47. bool CSystemGroupScopeItem::Create(CScopePane* pScopePane, CScopePaneItem* pParentItem)
  48. {
  49. TRACEX(_T("CSystemGroupScopeItem::Create\n"));
  50. TRACEARGn(pScopePane);
  51. TRACEARGn(pParentItem);
  52. // set up all the icons first
  53. for( int i = 0; i < HMS_MAX_STATES; i++ )
  54. {
  55. UINT nId = _Icons[i];
  56. m_IconResIds.Add(nId);
  57. m_OpenIconResIds.Add(nId);
  58. }
  59. SetIconIndex(HMS_NORMAL);
  60. SetOpenIconIndex(HMS_NORMAL);
  61. // call base class Create method
  62. if( ! CHMScopeItem::Create(pScopePane,pParentItem) )
  63. {
  64. TRACE(_T("CHMScopeItem::Create failed.\n"));
  65. return false;
  66. }
  67. // set display name to untitled
  68. CString sName;
  69. sName.LoadString(IDS_STRING_UNTITLED);
  70. SetDisplayName(0,sName);
  71. return true;
  72. }
  73. //////////////////////////////////////////////////////////////////////
  74. // Results Pane View Members
  75. //////////////////////////////////////////////////////////////////////
  76. CResultsPaneView* CSystemGroupScopeItem::CreateResultsPaneView()
  77. {
  78. TRACEX(_T("CSystemGroupScopeItem::CreateResultsPaneView\n"));
  79. return new CSystemGroupResultsView;
  80. }
  81. //////////////////////////////////////////////////////////////////////
  82. // MMC Notify Handlers
  83. //////////////////////////////////////////////////////////////////////
  84. HRESULT CSystemGroupScopeItem::OnAddMenuItems(LPCONTEXTMENUCALLBACK piCallback,long __RPC_FAR *pInsertionAllowed)
  85. {
  86. TRACEX(_T("CSystemGroupScopeItem::OnAddMenuItems\n"));
  87. TRACEARGn(piCallback);
  88. TRACEARGn(pInsertionAllowed);
  89. HRESULT hr = S_OK;
  90. // Add New Menu Items
  91. if( CCM_INSERTIONALLOWED_NEW & *pInsertionAllowed )
  92. {
  93. CONTEXTMENUITEM cmi;
  94. CString sResString;
  95. CString sResString2;
  96. sResString.LoadString(IDS_STRING_NEW_SYSTEMS_GROUP);
  97. cmi.strName = LPTSTR(LPCTSTR(sResString));
  98. sResString2.LoadString(IDS_STRING_NEW_SYSTEMS_GROUP_DESCRIPTION);
  99. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  100. cmi.lCommandID = IDM_NEW_GROUP;
  101. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_NEW;
  102. cmi.fFlags = 0;
  103. cmi.fSpecialFlags = 0;
  104. hr = piCallback->AddItem(&cmi);
  105. if( !SUCCEEDED(hr) )
  106. {
  107. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  108. return hr;
  109. }
  110. sResString.LoadString(IDS_STRING_NEW_SYSTEM_SHORTCUT);
  111. cmi.strName = LPTSTR(LPCTSTR(sResString));
  112. sResString2.LoadString(IDS_STRING_NEW_SYSTEM_SHORTCUT_DESCRIPTION);
  113. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  114. cmi.lCommandID = IDM_NEW_SYSTEM;
  115. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_NEW;
  116. cmi.fFlags = 0;
  117. cmi.fSpecialFlags = 0;
  118. hr = piCallback->AddItem(&cmi);
  119. if( !SUCCEEDED(hr) )
  120. {
  121. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  122. return hr;
  123. }
  124. }
  125. // Add Task Menu Items
  126. if( CCM_INSERTIONALLOWED_TASK & *pInsertionAllowed )
  127. {
  128. CONTEXTMENUITEM cmi;
  129. CString sResString;
  130. CString sResString2;
  131. sResString.LoadString(IDS_STRING_MODIFY_SYSTEM_SHORTCUT);
  132. cmi.strName = LPTSTR(LPCTSTR(sResString));
  133. sResString2.LoadString(IDS_STRING_CLEAR_EVENTS_DESCRIPTION);
  134. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  135. cmi.lCommandID = IDM_NEW_SYSTEM;
  136. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  137. cmi.fFlags = 0;
  138. cmi.fSpecialFlags = 0;
  139. hr = piCallback->AddItem(&cmi);
  140. if( !SUCCEEDED(hr) )
  141. {
  142. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  143. return hr;
  144. }
  145. sResString.LoadString(IDS_STRING_CLEAR_EVENTS);
  146. cmi.strName = LPTSTR(LPCTSTR(sResString));
  147. sResString2.LoadString(IDS_STRING_CLEAR_EVENTS_DESCRIPTION);
  148. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  149. cmi.lCommandID = IDM_CLEAR_EVENTS;
  150. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  151. cmi.fFlags = 0;
  152. cmi.fSpecialFlags = 0;
  153. hr = piCallback->AddItem(&cmi);
  154. if( !SUCCEEDED(hr) )
  155. {
  156. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  157. return hr;
  158. }
  159. sResString.LoadString(IDS_STRING_RESET_STATUS);
  160. cmi.strName = LPTSTR(LPCTSTR(sResString));
  161. sResString2.LoadString(IDS_STRING_RESET_STATUS_DESCRIPTION);
  162. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  163. cmi.lCommandID = IDM_RESET_STATUS;
  164. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  165. cmi.fFlags = 0;
  166. cmi.fSpecialFlags = 0;
  167. hr = piCallback->AddItem(&cmi);
  168. if( !SUCCEEDED(hr) )
  169. {
  170. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  171. return hr;
  172. }
  173. // separator
  174. cmi.strName = NULL;
  175. cmi.strStatusBarText = NULL;
  176. cmi.lCommandID = NULL;
  177. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  178. cmi.fFlags = MF_SEPARATOR;
  179. cmi.fSpecialFlags = 0;
  180. hr = piCallback->AddItem(&cmi);
  181. if( !SUCCEEDED(hr) )
  182. {
  183. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  184. return hr;
  185. }
  186. }
  187. // Add View Menu Items
  188. if( CCM_INSERTIONALLOWED_VIEW & *pInsertionAllowed )
  189. {
  190. CONTEXTMENUITEM cmi;
  191. CString sResString;
  192. CString sResString2;
  193. sResString.LoadString(IDS_STRING_STATUS_ONLY);
  194. cmi.strName = LPTSTR(LPCTSTR(sResString));
  195. sResString2.LoadString(IDS_STRING_STATUS_ONLY_DESCRIPTION);
  196. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  197. cmi.lCommandID = IDM_STATUS_ONLY;
  198. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_VIEW;
  199. cmi.fFlags = MF_UNCHECKED;
  200. cmi.fSpecialFlags = 0;
  201. hr = piCallback->AddItem(&cmi);
  202. if( !SUCCEEDED(hr) )
  203. {
  204. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  205. return hr;
  206. }
  207. sResString.LoadString(IDS_STRING_AUTO_FILTER);
  208. cmi.strName = LPTSTR(LPCTSTR(sResString));
  209. sResString2.LoadString(IDS_STRING_AUTO_FILTER_DESCRIPTION);
  210. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  211. cmi.lCommandID = IDM_AUTO_FILTER;
  212. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_VIEW;
  213. cmi.fFlags = MF_CHECKED;
  214. cmi.fSpecialFlags = 0;
  215. hr = piCallback->AddItem(&cmi);
  216. if( !SUCCEEDED(hr) )
  217. {
  218. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  219. return hr;
  220. }
  221. // icon legend
  222. sResString.LoadString(IDS_STRING_ICON_LEGEND);
  223. cmi.strName = LPTSTR(LPCTSTR(sResString));
  224. sResString2.LoadString(IDS_STRING_ICON_LEGEND_DESCRIPTION);
  225. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  226. cmi.lCommandID = IDM_ICON_LEGEND;
  227. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_VIEW;
  228. cmi.fFlags = 0;
  229. cmi.fSpecialFlags = 0;
  230. hr = piCallback->AddItem(&cmi);
  231. if( !SUCCEEDED(hr) )
  232. {
  233. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  234. return hr;
  235. }
  236. }
  237. return hr;
  238. }
  239. HRESULT CSystemGroupScopeItem::OnCommand(long lCommandID)
  240. {
  241. TRACEX(_T("CSystemGroupScopeItem::OnCommand\n"));
  242. TRACEARGn(lCommandID);
  243. HRESULT hr = S_OK;
  244. switch(lCommandID)
  245. {
  246. case IDM_NEW_GROUP:
  247. {
  248. CHealthmonScopePane* pPane = (CHealthmonScopePane*)GetScopePane();
  249. if( ! GfxCheckObjPtr(pPane,CHealthmonScopePane) )
  250. {
  251. TRACE(_T("FAILED : CGroupScopeItem::GetScopePane returns an invalid pointer.\n"));
  252. return E_FAIL;
  253. }
  254. CSystemGroup* pSG = (CSystemGroup*)GetObjectPtr();
  255. pSG->CreateNewChildSystemGroup();
  256. }
  257. break;
  258. case IDM_NEW_SYSTEM:
  259. {
  260. CHealthmonScopePane* pPane = (CHealthmonScopePane*)GetScopePane();
  261. if( ! GfxCheckObjPtr(pPane,CHealthmonScopePane) )
  262. {
  263. TRACE(_T("FAILED : CGroupScopeItem::GetScopePane returns an invalid pointer.\n"));
  264. return E_FAIL;
  265. }
  266. CSystemGroup* pGroup = (CSystemGroup*)GetObjectPtr();
  267. if( ! GfxCheckObjPtr(pGroup,CSystemGroup) )
  268. {
  269. TRACE(_T("FAILED : CGroupScopeItem::GetObjectPtr returns an invalid pointer.\n"));
  270. return E_FAIL;
  271. }
  272. CSystemGroup* pASG = pPane->GetAllSystemsGroup();
  273. CNewSystemShortcutDlg dlg;
  274. dlg.m_sGroupName = pGroup->GetName();
  275. for( int i = 0; i < pASG->GetChildCount(); i++ )
  276. {
  277. CString sName = pASG->GetChild(i)->GetName();
  278. dlg.m_saSystems.Add(sName);
  279. if( pGroup->GetShortcut(sName) )
  280. {
  281. dlg.m_uaIncludeFlags.Add(1);
  282. }
  283. else
  284. {
  285. dlg.m_uaIncludeFlags.Add(0);
  286. }
  287. }
  288. if( dlg.DoModal() == IDOK )
  289. {
  290. for( int i = 0; i < dlg.m_saSystems.GetSize(); i++ )
  291. {
  292. if( dlg.m_uaIncludeFlags[i] == 1 && ! pGroup->GetShortcut(dlg.m_saSystems[i]) )
  293. {
  294. CSystem* pSystem = (CSystem*)pASG->GetChild(dlg.m_saSystems[i]);
  295. pGroup->AddShortcut(pSystem);
  296. }
  297. else
  298. {
  299. if( dlg.m_uaIncludeFlags[i] == 0 )
  300. {
  301. for( int z = 0; z < GetChildCount(); z++ )
  302. {
  303. if( GetChild(z) && GetChild(z)->GetDisplayName().CompareNoCase(dlg.m_saSystems[i]) == 0 )
  304. {
  305. GetChild(z)->OnDelete();
  306. }
  307. }
  308. CSystem* pSystem = (CSystem*)pGroup->GetShortcut(dlg.m_saSystems[i]);
  309. pGroup->RemoveShortcut(pSystem);
  310. }
  311. }
  312. }
  313. }
  314. }
  315. break;
  316. default:
  317. {
  318. hr = CHMScopeItem::OnCommand(lCommandID);
  319. }
  320. }
  321. return hr;
  322. }
  323. HRESULT CSystemGroupScopeItem::OnCreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider, INT_PTR handle)
  324. {
  325. TRACEX(_T("CSystemGroupScopeItem::OnCreatePropertyPages\n"));
  326. TRACEARGn(lpProvider);
  327. TRACEARGn(handle);
  328. if( m_pScopePane == NULL )
  329. {
  330. return S_FALSE;
  331. }
  332. HRESULT hr = S_OK;
  333. CGroupGeneralPage* pPage1 = new CGroupGeneralPage;
  334. pPage1->SetObjectPtr(GetObjectPtr());
  335. HPROPSHEETPAGE hPage1 = CreatePropertySheetPage( reinterpret_cast<LPCPROPSHEETPAGE>(&pPage1->m_psp) );
  336. hr = lpProvider->AddPage(hPage1);
  337. return hr;
  338. }
  339. HRESULT CSystemGroupScopeItem::OnSelect(CResultsPane* pPane, BOOL bSelected)
  340. {
  341. TRACEX(_T("CSystemGroupScopeItem::OnSelect\n"));
  342. TRACEARGn(pPane);
  343. TRACEARGn(bSelected);
  344. if( ! CHECKHRESULT(CHMScopeItem::OnSelect(pPane,bSelected)) )
  345. {
  346. TRACE(_T("FAILED : CHMScopeItem::OnSelect returns failure.\n"));
  347. return E_FAIL;
  348. }
  349. if( ! bSelected ) // we are being de-selected so do not do anything
  350. {
  351. return S_OK;
  352. }
  353. LPCONSOLEVERB lpConsoleVerb = pPane->GetConsoleVerbPtr();
  354. HRESULT hr = lpConsoleVerb->SetVerbState( MMC_VERB_PROPERTIES, ENABLED, TRUE );
  355. if( ! CHECKHRESULT(hr) )
  356. {
  357. TRACE(_T("FAILED : IConsoleVerb::SetVerbState failed.\n"));
  358. lpConsoleVerb->Release();
  359. return hr;
  360. }
  361. hr = lpConsoleVerb->SetVerbState( MMC_VERB_RENAME, ENABLED, TRUE );
  362. if( ! CHECKHRESULT(hr) )
  363. {
  364. TRACE(_T("FAILED : IConsoleVerb::SetVerbState failed.\n"));
  365. lpConsoleVerb->Release();
  366. return hr;
  367. }
  368. hr = lpConsoleVerb->SetVerbState( MMC_VERB_CUT, ENABLED, TRUE );
  369. if( ! CHECKHRESULT(hr) )
  370. {
  371. TRACE(_T("FAILED : IConsoleVerb::SetVerbState failed.\n"));
  372. lpConsoleVerb->Release();
  373. return hr;
  374. }
  375. hr = lpConsoleVerb->SetVerbState( MMC_VERB_COPY, ENABLED, TRUE );
  376. if( ! CHECKHRESULT(hr) )
  377. {
  378. TRACE(_T("FAILED : IConsoleVerb::SetVerbState failed.\n"));
  379. lpConsoleVerb->Release();
  380. return hr;
  381. }
  382. hr = lpConsoleVerb->SetVerbState( MMC_VERB_PASTE, ENABLED, TRUE );
  383. if( ! CHECKHRESULT(hr) )
  384. {
  385. TRACE(_T("FAILED : IConsoleVerb::SetVerbState failed.\n"));
  386. lpConsoleVerb->Release();
  387. return hr;
  388. }
  389. hr = lpConsoleVerb->SetVerbState( MMC_VERB_DELETE, ENABLED, TRUE );
  390. if( ! CHECKHRESULT(hr) )
  391. {
  392. TRACE(_T("FAILED : IConsoleVerb::SetVerbState failed.\n"));
  393. lpConsoleVerb->Release();
  394. return hr;
  395. }
  396. lpConsoleVerb->Release();
  397. return hr;
  398. }