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.

433 lines
12 KiB

  1. // RuleScopeItem.cpp: implementation of the CRuleScopeItem class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. //
  5. // History
  6. //
  7. // 03/04/00 v-marfin bug 59643 Make Expression page the 1st page displayed
  8. // 03/31/00 v-marfin bug 62644 Removed "Reset Status" from the Threshold context menu.
  9. // 04/02/00 v-marfin bug 59643b : Make General Page the first page, but set
  10. // details page as the focus on a new item.
  11. //
  12. //
  13. #include "stdafx.h"
  14. #include "snapin.h"
  15. #include "Rule.h"
  16. #include "RuleScopeItem.h"
  17. #include "RuleResultsView.h"
  18. #include "HealthmonScopePane.h"
  19. #include "THGeneralPage.h"
  20. #include "THExpressionPage.h"
  21. #include "THPolicyPage.h"
  22. #include "THSchedulePage.h"
  23. #include "THMessagePage.h"
  24. #include "ActionAssociationPage.h"
  25. #ifdef _DEBUG
  26. #undef THIS_FILE
  27. static char THIS_FILE[]=__FILE__;
  28. #define new DEBUG_NEW
  29. #endif
  30. // {DFB09C0F-C9E7-11d2-BD8D-0000F87A3912}
  31. static GUID GUID_Rule =
  32. { 0xdfb09c0f, 0xc9e7, 0x11d2, { 0xbd, 0x8d, 0x0, 0x0, 0xf8, 0x7a, 0x39, 0x12 } };
  33. IMPLEMENT_DYNCREATE(CRuleScopeItem,CHMScopeItem)
  34. // icon table - associates state to icons
  35. static UINT _Icons[HMS_MAX_STATES] =
  36. {
  37. IDI_ICON_THRESHOLD,
  38. IDI_ICON_THRESHOLD_DISABLED,
  39. IDI_ICON_THRESHOLD_OUTAGE,
  40. IDI_ICON_THRESHOLD_UNKNOWN,
  41. IDI_ICON_THRESHOLD_NO_CONNECT,
  42. IDI_ICON_THRESHOLD_WARNING,
  43. IDI_ICON_THRESHOLD_CRITICAL
  44. };
  45. //////////////////////////////////////////////////////////////////////
  46. // Construction/Destruction
  47. //////////////////////////////////////////////////////////////////////
  48. CRuleScopeItem::CRuleScopeItem()
  49. {
  50. m_lpguidItemType = &GUID_Rule;
  51. }
  52. CRuleScopeItem::~CRuleScopeItem()
  53. {
  54. Destroy();
  55. }
  56. //////////////////////////////////////////////////////////////////////
  57. // Creation Members
  58. //////////////////////////////////////////////////////////////////////
  59. bool CRuleScopeItem::Create(CScopePane* pScopePane, CScopePaneItem* pParentItem)
  60. {
  61. TRACEX(_T("CRuleScopeItem::Create\n"));
  62. TRACEARGn(pScopePane);
  63. TRACEARGn(pParentItem);
  64. // call base class Create method
  65. if( ! CHMScopeItem::Create(pScopePane,pParentItem) )
  66. {
  67. TRACE(_T("CHMScopeItem::Create failed.\n"));
  68. return false;
  69. }
  70. for( int i = 0; i < HMS_MAX_STATES; i++ )
  71. {
  72. UINT nId = _Icons[i];
  73. m_IconResIds.Add(nId);
  74. m_OpenIconResIds.Add(nId);
  75. }
  76. SetIconIndex(HMS_NORMAL);
  77. SetOpenIconIndex(HMS_NORMAL);
  78. return true;
  79. }
  80. //////////////////////////////////////////////////////////////////////
  81. // Results Pane View Members
  82. //////////////////////////////////////////////////////////////////////
  83. CResultsPaneView* CRuleScopeItem::CreateResultsPaneView()
  84. {
  85. TRACEX(_T("CRuleScopeItem::CreateResultsPaneView\n"));
  86. return new CRuleResultsView;
  87. }
  88. //////////////////////////////////////////////////////////////////////
  89. // MMC Notify Handlers
  90. //////////////////////////////////////////////////////////////////////
  91. HRESULT CRuleScopeItem::OnAddMenuItems(LPCONTEXTMENUCALLBACK piCallback,long __RPC_FAR *pInsertionAllowed)
  92. {
  93. TRACEX(_T("CRuleScopeItem::OnAddMenuItems\n"));
  94. TRACEARGn(piCallback);
  95. TRACEARGn(pInsertionAllowed);
  96. HRESULT hr = S_OK;
  97. // Add Task Menu Items
  98. if( CCM_INSERTIONALLOWED_TASK & *pInsertionAllowed )
  99. {
  100. CONTEXTMENUITEM cmi;
  101. CString sResString;
  102. CString sResString2;
  103. sResString.LoadString(IDS_STRING_CLEAR_EVENTS);
  104. cmi.strName = LPTSTR(LPCTSTR(sResString));
  105. sResString2.LoadString(IDS_STRING_CLEAR_EVENTS_DESCRIPTION);
  106. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  107. cmi.lCommandID = IDM_CLEAR_EVENTS;
  108. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  109. cmi.fFlags = 0;
  110. cmi.fSpecialFlags = 0;
  111. hr = piCallback->AddItem(&cmi);
  112. if( !SUCCEEDED(hr) )
  113. {
  114. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  115. return hr;
  116. }
  117. /* v-marfin 62644 : Remove "Reset Status" from the Threshold context menu
  118. sResString.LoadString(IDS_STRING_RESET_STATUS);
  119. cmi.strName = LPTSTR(LPCTSTR(sResString));
  120. sResString2.LoadString(IDS_STRING_RESET_STATUS_DESCRIPTION);
  121. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  122. cmi.lCommandID = IDM_RESET_STATUS;
  123. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  124. cmi.fFlags = 0;
  125. cmi.fSpecialFlags = 0;
  126. hr = piCallback->AddItem(&cmi);
  127. if( !SUCCEEDED(hr) )
  128. {
  129. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  130. return hr;
  131. }*/
  132. // Enable All Thresholds
  133. sResString.LoadString(IDS_STRING_ENABLE_ALL_THRESHOLDS);
  134. cmi.strName = LPTSTR(LPCTSTR(sResString));
  135. sResString2.LoadString(IDS_STRING_ENABLE_ALL_THRESHOLDS_DESCRIPTION);
  136. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  137. cmi.lCommandID = IDM_DISABLE_MONITORING;
  138. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  139. CHMObject* pObject = GetObjectPtr();
  140. CHMScopeItem* pParentItem = (CHMScopeItem*)GetParent();
  141. // disable menu item if null object ptr or parent is disabled
  142. if( ! pObject || (pParentItem && pParentItem->GetObjectPtr()
  143. && !pParentItem->GetObjectPtr()->IsEnabled()) )
  144. {
  145. cmi.fFlags = MF_DISABLED|MF_GRAYED;
  146. }
  147. else
  148. {
  149. int iState = pObject->IsEnabled();
  150. if( iState == -1 )
  151. {
  152. cmi.fFlags = MF_DISABLED|MF_GRAYED;
  153. }
  154. else if( iState == 0 )
  155. {
  156. cmi.fFlags = MF_CHECKED;
  157. }
  158. else if( iState == 1 )
  159. {
  160. cmi.fFlags = MF_UNCHECKED;
  161. }
  162. }
  163. cmi.fSpecialFlags = 0;
  164. hr = piCallback->AddItem(&cmi);
  165. if( !SUCCEEDED(hr) )
  166. {
  167. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  168. return hr;
  169. }
  170. /*
  171. // Export
  172. sResString.LoadString(IDS_STRING_EXPORT);
  173. cmi.strName = LPTSTR(LPCTSTR(sResString));
  174. cmi.strStatusBarText = NULL;
  175. cmi.lCommandID = IDM_EXPORT;
  176. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  177. cmi.fFlags = 0;
  178. cmi.fSpecialFlags = 0;
  179. hr = piCallback->AddItem(&cmi);
  180. if( !SUCCEEDED(hr) )
  181. {
  182. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  183. return hr;
  184. }
  185. */
  186. // separator
  187. cmi.strName = NULL;
  188. cmi.strStatusBarText = NULL;
  189. cmi.lCommandID = NULL;
  190. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  191. cmi.fFlags = MF_SEPARATOR;
  192. cmi.fSpecialFlags = 0;
  193. hr = piCallback->AddItem(&cmi);
  194. if( !SUCCEEDED(hr) )
  195. {
  196. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  197. return hr;
  198. }
  199. }
  200. // Add View Menu Items
  201. if( CCM_INSERTIONALLOWED_VIEW & *pInsertionAllowed )
  202. {
  203. CONTEXTMENUITEM cmi;
  204. CString sResString;
  205. CString sResString2;
  206. sResString.LoadString(IDS_STRING_STATUS_ONLY);
  207. cmi.strName = LPTSTR(LPCTSTR(sResString));
  208. sResString2.LoadString(IDS_STRING_STATUS_ONLY_DESCRIPTION);
  209. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  210. cmi.lCommandID = IDM_STATUS_ONLY;
  211. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_VIEW;
  212. cmi.fFlags = MF_UNCHECKED;
  213. cmi.fSpecialFlags = 0;
  214. hr = piCallback->AddItem(&cmi);
  215. if( !SUCCEEDED(hr) )
  216. {
  217. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  218. return hr;
  219. }
  220. sResString.LoadString(IDS_STRING_AUTO_FILTER);
  221. cmi.strName = LPTSTR(LPCTSTR(sResString));
  222. sResString2.LoadString(IDS_STRING_AUTO_FILTER_DESCRIPTION);
  223. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  224. cmi.lCommandID = IDM_AUTO_FILTER;
  225. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_VIEW;
  226. cmi.fFlags = MF_CHECKED;
  227. cmi.fSpecialFlags = 0;
  228. hr = piCallback->AddItem(&cmi);
  229. if( !SUCCEEDED(hr) )
  230. {
  231. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  232. return hr;
  233. }
  234. // icon legend
  235. sResString.LoadString(IDS_STRING_ICON_LEGEND);
  236. cmi.strName = LPTSTR(LPCTSTR(sResString));
  237. sResString2.LoadString(IDS_STRING_ICON_LEGEND_DESCRIPTION);
  238. cmi.strStatusBarText = LPTSTR(LPCTSTR(sResString2));
  239. cmi.lCommandID = IDM_ICON_LEGEND;
  240. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_VIEW;
  241. cmi.fFlags = 0;
  242. cmi.fSpecialFlags = 0;
  243. hr = piCallback->AddItem(&cmi);
  244. if( !SUCCEEDED(hr) )
  245. {
  246. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  247. return hr;
  248. }
  249. }
  250. return hr;
  251. }
  252. HRESULT CRuleScopeItem::OnCommand(long lCommandID)
  253. {
  254. TRACEX(_T("CRuleScopeItem::OnCommand\n"));
  255. TRACEARGn(lCommandID);
  256. HRESULT hr = S_OK;
  257. switch(lCommandID)
  258. {
  259. case IDM_EXPORT:
  260. {
  261. CString sFilter;
  262. sFilter.LoadString(IDS_STRING_MOF_FILTER);
  263. CFileDialog fd(FALSE,_T("MOF"),NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,sFilter);
  264. if( fd.DoModal() == IDOK )
  265. {
  266. CFile file;
  267. if( ! file.Open(fd.GetPathName(),CFile::modeCreate|CFile::modeWrite|CFile::shareExclusive) )
  268. {
  269. return S_OK;
  270. }
  271. CArchive ar(&file,CArchive::store);
  272. CHMObject* pObject = GetObjectPtr();
  273. if( pObject )
  274. {
  275. pObject->ExportMofFile(ar);
  276. }
  277. }
  278. }
  279. break;
  280. default:
  281. {
  282. hr = CHMScopeItem::OnCommand(lCommandID);
  283. }
  284. }
  285. return hr;
  286. }
  287. HRESULT CRuleScopeItem::OnCreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider, INT_PTR handle)
  288. {
  289. TRACEX(_T("CRuleScopeItem::OnCreatePropertyPages\n"));
  290. TRACEARGn(lpProvider);
  291. TRACEARGn(handle);
  292. if( m_pScopePane == NULL )
  293. {
  294. return S_FALSE;
  295. }
  296. CRule* pRule = (CRule*)GetObjectPtr();
  297. if( ! GfxCheckObjPtr(pRule,CRule) )
  298. {
  299. return E_FAIL;
  300. }
  301. HRESULT hr = S_OK;
  302. // v-marfin bug 59643b - Make general page the first page but make the
  303. // details page the focus on new items.
  304. CTHGeneralPage* pPage1 = new CTHGeneralPage;
  305. pPage1->SetObjectPtr(pRule);
  306. HPROPSHEETPAGE hPage1 = CreatePropertySheetPage( reinterpret_cast<LPCPROPSHEETPAGE>(&pPage1->m_psp) );
  307. hr = lpProvider->AddPage(hPage1);
  308. CTHExpressionPage* pPage2 = new CTHExpressionPage;
  309. pPage2->SetObjectPtr(pRule);
  310. HPROPSHEETPAGE hPage2 = CreatePropertySheetPage( reinterpret_cast<LPCPROPSHEETPAGE>(&pPage2->m_psp) );
  311. hr = lpProvider->AddPage(hPage2);
  312. CTHMessagePage* pPage3 = new CTHMessagePage;
  313. pPage3->SetObjectPtr(pRule);
  314. HPROPSHEETPAGE hPage3 = CreatePropertySheetPage( reinterpret_cast<LPCPROPSHEETPAGE>(&pPage3->m_psp) );
  315. hr = lpProvider->AddPage(hPage3);
  316. CActionAssociationPage* pPage4 = new CActionAssociationPage;
  317. pPage4->SetObjectPtr(GetObjectPtr());
  318. HPROPSHEETPAGE hPage4 = CreatePropertySheetPage( reinterpret_cast<LPCPROPSHEETPAGE>(&pPage4->m_psp) );
  319. hr = lpProvider->AddPage(hPage4);
  320. /*
  321. CTHSchedulePage* pPage5 = new CTHSchedulePage;
  322. pPage5->SetObjectPtr(pRule);
  323. HPROPSHEETPAGE hPage5 = CreatePropertySheetPage( reinterpret_cast<LPCPROPSHEETPAGE>(&pPage5->m_psp) );
  324. hr = lpProvider->AddPage(hPage5);
  325. */
  326. return hr;
  327. }
  328. HRESULT CRuleScopeItem::OnSelect(CResultsPane* pPane, BOOL bSelected)
  329. {
  330. TRACEX(_T("CRuleScopeItem::OnSelect\n"));
  331. TRACEARGn(pPane);
  332. TRACEARGn(bSelected);
  333. if( ! CHECKHRESULT(CHMScopeItem::OnSelect(pPane,bSelected)) )
  334. {
  335. TRACE(_T("FAILED : CHMScopeItem::OnSelect returns failure.\n"));
  336. return E_FAIL;
  337. }
  338. if( ! bSelected ) // we are being de-selected so do not do anything
  339. {
  340. return S_OK;
  341. }
  342. LPCONSOLEVERB lpConsoleVerb = pPane->GetConsoleVerbPtr();
  343. HRESULT hr = lpConsoleVerb->SetVerbState( MMC_VERB_PROPERTIES, ENABLED, TRUE );
  344. if( ! CHECKHRESULT(hr) )
  345. {
  346. TRACE(_T("FAILED : IConsoleVerb::SetVerbState failed.\n"));
  347. lpConsoleVerb->Release();
  348. return hr;
  349. }
  350. hr = lpConsoleVerb->SetVerbState( MMC_VERB_RENAME, ENABLED, TRUE );
  351. if( ! CHECKHRESULT(hr) )
  352. {
  353. TRACE(_T("FAILED : IConsoleVerb::SetVerbState failed.\n"));
  354. lpConsoleVerb->Release();
  355. return hr;
  356. }
  357. hr = lpConsoleVerb->SetVerbState( MMC_VERB_DELETE, ENABLED, TRUE );
  358. if( ! CHECKHRESULT(hr) )
  359. {
  360. TRACE(_T("FAILED : IConsoleVerb::SetVerbState failed.\n"));
  361. lpConsoleVerb->Release();
  362. return hr;
  363. }
  364. lpConsoleVerb->Release();
  365. return hr;
  366. }