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.

627 lines
15 KiB

  1. // SplitPaneResultsView.cpp: implementation of the CSplitPaneResultsView class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. // Copyright (c) 2000 Microsoft Corporation
  5. //
  6. // 04/06/00 v-marfin 62935 : Show "OK" Instead of "Reset" in the upper pane only
  7. #include "stdafx.h"
  8. #include "snapin.h"
  9. #include "SplitPaneResultsView.h"
  10. #include "HealthmonResultsPane.h"
  11. #include "HMListViewColumn.h"
  12. #include "HMResultsPaneItem.h"
  13. #include "HMScopeItem.h"
  14. #include "HealthmonScopePane.h"
  15. #include "HMObject.h"
  16. #include "EventManager.h"
  17. #include "HMGraphView.h"
  18. #include "DataElement.h"
  19. #include "Rule.h"
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char THIS_FILE[]=__FILE__;
  23. #define new DEBUG_NEW
  24. #endif
  25. IMPLEMENT_DYNCREATE(CSplitPaneResultsView,CResultsPaneView)
  26. //////////////////////////////////////////////////////////////////////
  27. // Construction/Destruction
  28. //////////////////////////////////////////////////////////////////////
  29. CSplitPaneResultsView::CSplitPaneResultsView()
  30. {
  31. }
  32. CSplitPaneResultsView::~CSplitPaneResultsView()
  33. {
  34. Destroy();
  35. }
  36. //////////////////////////////////////////////////////////////////////
  37. // Create/Destroy
  38. //////////////////////////////////////////////////////////////////////
  39. bool CSplitPaneResultsView::Create(CScopePaneItem* pOwnerItem)
  40. {
  41. TRACEX(_T("CSplitPaneResultsView::Create\n"));
  42. TRACEARGn(pOwnerItem);
  43. if( ! CResultsPaneView::Create(pOwnerItem) )
  44. {
  45. TRACE(_T("FAILED : CResultsPaneView::Create failed.\n"));
  46. return false;
  47. }
  48. return true;
  49. }
  50. //////////////////////////////////////////////////////////////////////
  51. // Results Pane Item Members
  52. //////////////////////////////////////////////////////////////////////
  53. void CSplitPaneResultsView::RemoveItem(int iIndex)
  54. {
  55. TRACEX(_T("CSplitPaneResultsView::RemoveItem\n"));
  56. TRACEARGn(iIndex);
  57. if( iIndex >= m_ResultItems.GetSize() || iIndex < 0 )
  58. {
  59. TRACE(_T("FAILED : iIndex is out of array bounds.\n"));
  60. return;
  61. }
  62. CResultsPaneItem* pItem = m_ResultItems[iIndex];
  63. if( ! GfxCheckObjPtr(pItem,CResultsPaneItem) )
  64. {
  65. TRACE(_T("FAILED : pItem is not a valid results pane item pointer.\n"));
  66. return;
  67. }
  68. // for each pane showing this results view, delete the item from it
  69. for( int i=0; i < m_ResultsPanes.GetSize(); i++ )
  70. {
  71. if( GfxCheckObjPtr(m_ResultsPanes[i],CResultsPane) )
  72. {
  73. pItem->RemoveItem(m_ResultsPanes[i]);
  74. }
  75. }
  76. delete pItem;
  77. m_ResultItems.RemoveAt(iIndex);
  78. }
  79. //////////////////////////////////////////////////////////////////////
  80. // MMC Notify Handlers
  81. //////////////////////////////////////////////////////////////////////
  82. HRESULT CSplitPaneResultsView::OnGetResultViewType(CString& sViewType,long& lViewOptions)
  83. {
  84. TRACEX(_T("CSplitPaneResultsView::OnGetResultViewType\n"));
  85. TRACEARGs(sViewType);
  86. TRACEARGn(lViewOptions);
  87. sViewType = _T("{668E5408-8E05-11D2-8ADA-0000F87A3912}");
  88. lViewOptions = MMC_VIEW_OPTIONS_NOLISTVIEWS;
  89. return S_OK;
  90. }
  91. HRESULT CSplitPaneResultsView::OnShow(CResultsPane* pPane, BOOL bSelecting, HSCOPEITEM hScopeItem)
  92. {
  93. TRACEX(_T("CSplitPaneResultsView::OnShow\n"));
  94. TRACEARGn(pPane);
  95. TRACEARGn(bSelecting);
  96. TRACEARGn(hScopeItem);
  97. if( ! GfxCheckObjPtr(pPane,CHealthmonResultsPane) )
  98. {
  99. TRACE(_T("FAILED : pPane is not a valid pointer.\n"));
  100. return E_FAIL;
  101. }
  102. CHealthmonResultsPane* pHMRP = (CHealthmonResultsPane*)pPane;
  103. // set the description bar text
  104. LPRESULTDATA pIResultData = pHMRP->GetResultDataPtr();
  105. if( pIResultData )
  106. {
  107. CString sDescription;
  108. sDescription.LoadString(IDS_STRING_HEALTHMON_RESULTSPANE);
  109. pIResultData->SetDescBarText((LPTSTR)(LPCTSTR)sDescription);
  110. pIResultData->Release();
  111. }
  112. HRESULT hr = S_OK;
  113. _DHMListView* pUpperList = NULL;
  114. // get upper list control
  115. pUpperList = pHMRP->GetUpperListCtrl();
  116. if( ! pUpperList )
  117. {
  118. TRACE(_T("FAILED : CHealthmonResultsPane::GetUpperListCtrl returned a NULL pointer.\n"));
  119. return E_FAIL;
  120. }
  121. _DHMListView* pLowerList = NULL;
  122. // get lower list control
  123. pLowerList = pHMRP->GetLowerListCtrl();
  124. if( ! pLowerList )
  125. {
  126. TRACE(_T("FAILED : CHealthmonResultsPane::GetLowerListCtrl returned a NULL pointer.\n"));
  127. return E_FAIL;
  128. }
  129. _DHMListView* pStatsList = NULL;
  130. // get stats list control
  131. pStatsList = pHMRP->GetStatsListCtrl();
  132. if( ! pLowerList )
  133. {
  134. TRACE(_T("FAILED : CHealthmonResultsPane::GetLowerListCtrl returned a NULL pointer.\n"));
  135. return E_FAIL;
  136. }
  137. for( int i = 0; i < m_ResultItems.GetSize(); i++ )
  138. {
  139. delete m_ResultItems[i];
  140. }
  141. m_ResultItems.RemoveAll();
  142. pUpperList->DeleteAllItems();
  143. pLowerList->DeleteAllItems();
  144. pStatsList->DeleteAllItems();
  145. CScopePaneItem* pOwnerScopeItem = GetOwnerScopeItem();
  146. if( ! pOwnerScopeItem || ! GfxCheckObjPtr(pOwnerScopeItem,CHMScopeItem) )
  147. {
  148. TRACE(_T("FAILED : CResultsPaneView::GetOwnerScopeItem returns NULL pointer.\n"));
  149. return E_FAIL;
  150. }
  151. CHMObject* pObject = ((CHMScopeItem*)(pOwnerScopeItem))->GetObjectPtr();
  152. if( ! pObject )
  153. {
  154. return E_FAIL;
  155. }
  156. if( bSelecting )
  157. {
  158. CString sText;
  159. sText.Format(IDS_STRING_CHILDREN_OF_FORMAT,pOwnerScopeItem->GetDisplayName());
  160. pUpperList->SetTitle(sText);
  161. // v-marfin 62935 : Show "OK" Instead of "Reset" in the upper pane only
  162. CString sOK;
  163. sOK.LoadString(IDS_STRING_OK);
  164. CString sReset;
  165. sReset.LoadString(IDS_STRING_RESET);
  166. // add the children of the selected scope item to the upper pane
  167. for( int i = 0; i < pOwnerScopeItem->GetChildCount(); i++ )
  168. {
  169. CScopePaneItem* pChildScopeItem = pOwnerScopeItem->GetChild(i);
  170. CHMResultsPaneItem* pItem = new CHMResultsPaneItem;
  171. CStringArray saNames;
  172. saNames.Copy(pChildScopeItem->GetDisplayNames());
  173. // v-marfin 62935 : Show "OK" Instead of "Reset" in the upper pane only
  174. if (saNames.GetSize() > 1)
  175. {
  176. CString sTest = saNames.GetAt(1);
  177. if (saNames.GetAt(1)==sReset)
  178. {
  179. saNames.SetAt(1,sOK);
  180. }
  181. }
  182. CUIntArray iaIconIds;
  183. iaIconIds.Copy(pChildScopeItem->GetIconIds());
  184. if( ! pItem->Create(this,saNames,iaIconIds,pChildScopeItem->GetIconIndex()) )
  185. {
  186. TRACE(_T("FAILED : CHMResultsPaneItem::Create failed.\n"));
  187. return false;
  188. }
  189. pItem->SetToUpperPane();
  190. m_ResultItems.Add(pItem);
  191. }
  192. sText.Format(IDS_STRING_COUNT_OF_FORMAT,pOwnerScopeItem->GetChildCount());
  193. pUpperList->SetDescription(sText);
  194. hr = AddEvents(pHMRP);
  195. if( ! CHECKHRESULT(hr) )
  196. {
  197. TRACE(_T("FAILED : CResultsPaneView::OnShow failed.\n"));
  198. }
  199. hr = CResultsPaneView::OnShow(pPane,bSelecting,hScopeItem);
  200. if( ! CHECKHRESULT(hr) )
  201. {
  202. TRACE(_T("FAILED : CResultsPaneView::OnShow failed.\n"));
  203. }
  204. hr = AddStatistics(pHMRP);
  205. if( ! CHECKHRESULT(hr) )
  206. {
  207. TRACE(_T("FAILED : CResultsPaneView::OnShow failed.\n"));
  208. }
  209. USES_CONVERSION;
  210. CString sOrder = AfxGetApp()->GetProfileString(A2T(pObject->GetRuntimeClass()->m_lpszClassName),_T("UpperColumnOrder"));
  211. if( ! sOrder.IsEmpty() && sOrder != pUpperList->GetColumnOrder() )
  212. {
  213. pUpperList->SetColumnOrder(sOrder);
  214. }
  215. sOrder = AfxGetApp()->GetProfileString(A2T(pObject->GetRuntimeClass()->m_lpszClassName),_T("LowerColumnOrder"));
  216. if( ! sOrder.IsEmpty() && sOrder != pLowerList->GetColumnOrder() )
  217. {
  218. pLowerList->SetColumnOrder(sOrder);
  219. }
  220. }
  221. else
  222. {
  223. hr = CResultsPaneView::OnShow(pPane,bSelecting,hScopeItem);
  224. int iUpperColCount = 0;
  225. int iLowerColCount = 0;
  226. for( int i=0; i < GetColumnCount(); i++ )
  227. {
  228. CHMListViewColumn* pColumn = (CHMListViewColumn*)GetColumn(i);
  229. if( pColumn )
  230. {
  231. if( pColumn->IsUpperPane() )
  232. {
  233. pColumn->SaveWidth(pPane,iUpperColCount++);
  234. }
  235. if( pColumn->IsLowerPane() )
  236. {
  237. pColumn->SaveWidth(pPane,iLowerColCount++);
  238. }
  239. }
  240. }
  241. USES_CONVERSION;
  242. CString sOrder = pUpperList->GetColumnOrder();
  243. AfxGetApp()->WriteProfileString(A2T(pObject->GetRuntimeClass()->m_lpszClassName),_T("UpperColumnOrder"),sOrder);
  244. sOrder.Empty();
  245. sOrder = pLowerList->GetColumnOrder();
  246. AfxGetApp()->WriteProfileString(A2T(pObject->GetRuntimeClass()->m_lpszClassName),_T("LowerColumnOrder"),sOrder);
  247. sOrder.Empty();
  248. for( i = 0; i < GetColumnCount(); i++ )
  249. {
  250. CHMListViewColumn* pColumn = (CHMListViewColumn*)GetColumn(i);
  251. if( pColumn->IsUpperPane() )
  252. {
  253. pUpperList->DeleteColumn(0);
  254. }
  255. if( pColumn->IsLowerPane() )
  256. {
  257. pLowerList->DeleteColumn(0);
  258. }
  259. if( pColumn->IsStatsPane() )
  260. {
  261. pStatsList->DeleteColumn(0);
  262. }
  263. }
  264. // clean up lower list control
  265. pLowerList->DeleteAllItems();
  266. // clean up stats list control
  267. pStatsList->DeleteAllItems();
  268. RemoveStatistics(pHMRP);
  269. }
  270. return S_OK;
  271. }
  272. void CSplitPaneResultsView::AddStatistic(CEventContainer* pContainer, CStatistics* pStatistic, bool bUpdateGraph /*=true*/)
  273. {
  274. TRACEX(_T("CSplitPaneResultsView::AddStatistic\n"));
  275. TRACEARGn(pContainer);
  276. TRACEARGn(pStatistic);
  277. // insert item at top of stats list for this statistic
  278. AddItem(pStatistic->CreateResultsPaneItem(this));
  279. if( bUpdateGraph )
  280. {
  281. CHMScopeItem* pHMItem = (CHMScopeItem*)GetOwnerScopeItem();
  282. if( ! GfxCheckObjPtr(pHMItem,CHMScopeItem) )
  283. {
  284. TRACE(_T("FAILED : pPane is not a valid pointer.\n"));
  285. return;
  286. }
  287. CHMObject* pObject = pHMItem->GetObjectPtr();
  288. if( !pObject || ! GfxCheckObjPtr(pObject,CHMObject) )
  289. {
  290. return;
  291. }
  292. for( int i = 0; i < GetResultsPanesCount(); i++ )
  293. {
  294. CHealthmonResultsPane* pPane = (CHealthmonResultsPane*)GetResultsPane(i);
  295. if( pPane )
  296. {
  297. _DHMGraphView* pGraphView = pPane->GetGraphViewCtrl();
  298. if( pGraphView )
  299. {
  300. pPane->GetGraphViewSink()->SetResultsViewPtr(this);
  301. long lCurrentStyle = pGraphView->GetStyle();
  302. pGraphView->Clear();
  303. if( lCurrentStyle & HMGVS_CURRENT )
  304. {
  305. pGraphView->SetStyle(HMGVS_CURRENT|HMGVS_GROUP);
  306. }
  307. if( lCurrentStyle & HMGVS_HISTORIC )
  308. {
  309. pGraphView->SetStyle(HMGVS_HISTORIC|HMGVS_GROUP);
  310. }
  311. pGraphView->SetName(pObject->GetName());
  312. }
  313. CEventContainer* pContainer = NULL;
  314. EvtGetEventManager()->GetEventContainer(pObject->GetSystemName(),pObject->GetGuid(),pContainer);
  315. if( pContainer )
  316. {
  317. for(int i = 0; i < pContainer->GetStatisticsCount(); i++ )
  318. {
  319. if( i > pContainer->GetStatisticsCount()-10 )
  320. {
  321. CStatistics* pStat = pContainer->GetStatistic(i);
  322. if( pStat )
  323. {
  324. pStat->UpdateGraph(pGraphView);
  325. }
  326. }
  327. }
  328. }
  329. }
  330. }
  331. }
  332. }
  333. inline HRESULT CSplitPaneResultsView::AddEvents(CHealthmonResultsPane* pPane)
  334. {
  335. TRACEX(_T("CSplitPaneResultsView::AddEvents\n"));
  336. CScopePaneItem* pSPI = GetOwnerScopeItem();
  337. if( ! pSPI->IsKindOf(RUNTIME_CLASS(CHMScopeItem)) )
  338. {
  339. return S_FALSE;
  340. }
  341. CHMScopeItem* pHMItem = (CHMScopeItem*)pSPI;
  342. if( ! GfxCheckObjPtr(pPane,CHealthmonResultsPane) )
  343. {
  344. TRACE(_T("FAILED : pPane is not a valid pointer.\n"));
  345. return E_FAIL;
  346. }
  347. CString sText;
  348. sText.Format(IDS_STRING_EVENTS_OF_FORMAT,pSPI->GetDisplayName());
  349. pPane->GetLowerListCtrl()->SetTitle(sText);
  350. CHMObject* pObject = pHMItem->GetObjectPtr();
  351. if( !pObject || ! GfxCheckObjPtr(pObject,CHMObject) )
  352. {
  353. return E_FAIL;
  354. }
  355. CEventContainer* pContainer = NULL;
  356. EvtGetEventManager()->GetEventContainer(pObject->GetSystemName(),pObject->GetGuid(),pContainer);
  357. if( pContainer )
  358. {
  359. for(int i = 0; i < pContainer->GetEventCount(); i++ )
  360. {
  361. CEvent* pEvent = pContainer->GetEvent(i);
  362. if( pEvent )
  363. {
  364. CHMEventResultsPaneItem* pEventItem = pEvent->CreateResultsPaneItem(this);
  365. m_ResultItems.Add(pEventItem);
  366. }
  367. }
  368. }
  369. sText.Format(IDS_STRING_COUNT_OF_FORMAT,pContainer->GetEventCount());
  370. pPane->GetLowerListCtrl()->SetDescription(sText);
  371. return S_OK;
  372. }
  373. inline HRESULT CSplitPaneResultsView::AddStatistics(CHealthmonResultsPane* pPane)
  374. {
  375. TRACEX(_T("CSplitPaneResultsView::AddStatistics\n"));
  376. CScopePaneItem* pSPI = GetOwnerScopeItem();
  377. if( ! pSPI->IsKindOf(RUNTIME_CLASS(CHMScopeItem)) )
  378. {
  379. return S_FALSE;
  380. }
  381. CHMScopeItem* pHMItem = (CHMScopeItem*)pSPI;
  382. if( ! GfxCheckObjPtr(pPane,CHealthmonResultsPane) )
  383. {
  384. TRACE(_T("FAILED : pPane is not a valid pointer.\n"));
  385. return E_FAIL;
  386. }
  387. CString sText;
  388. sText.Format(IDS_STRING_STATISTICS_FOR,pSPI->GetDisplayName());
  389. pPane->GetStatsListCtrl()->SetTitle(sText);
  390. CHMObject* pObject = pHMItem->GetObjectPtr();
  391. if( !pObject || ! GfxCheckObjPtr(pObject,CHMObject) )
  392. {
  393. return E_FAIL;
  394. }
  395. _DHMGraphView* pGraphView = pPane->GetGraphViewCtrl();
  396. if( pGraphView )
  397. {
  398. pPane->GetGraphViewSink()->SetResultsViewPtr(this);
  399. long lCurrentStyle = pGraphView->GetStyle();
  400. pGraphView->Clear();
  401. if( lCurrentStyle & HMGVS_CURRENT )
  402. {
  403. pGraphView->SetStyle(HMGVS_CURRENT|HMGVS_GROUP);
  404. }
  405. if( lCurrentStyle & HMGVS_HISTORIC )
  406. {
  407. pGraphView->SetStyle(HMGVS_HISTORIC|HMGVS_GROUP);
  408. }
  409. pGraphView->SetName(pObject->GetName());
  410. }
  411. CEventContainer* pContainer = NULL;
  412. EvtGetEventManager()->GetEventContainer(pObject->GetSystemName(),pObject->GetGuid(),pContainer);
  413. if( pContainer )
  414. {
  415. for(int i = 0; i < pContainer->GetStatisticsCount(); i++ )
  416. {
  417. if( i > pContainer->GetStatisticsCount()-10 )
  418. {
  419. CStatistics* pStat = pContainer->GetStatistic(i);
  420. if( pStat )
  421. {
  422. AddStatistic(pContainer,pStat,i==pContainer->GetStatisticsCount()-1);
  423. }
  424. }
  425. }
  426. }
  427. sText.Format(IDS_STRING_COUNT_OF_FORMAT,pContainer->GetStatisticsCount());
  428. pPane->GetStatsListCtrl()->SetDescription(sText);
  429. return S_OK;
  430. }
  431. inline HRESULT CSplitPaneResultsView::RemoveStatistics(CHealthmonResultsPane* pPane)
  432. {
  433. TRACEX(_T("CSplitPaneResultsView::RemoveStatistics\n"));
  434. CScopePaneItem* pSPI = GetOwnerScopeItem();
  435. if( ! pSPI->IsKindOf(RUNTIME_CLASS(CHMScopeItem)) )
  436. {
  437. return S_FALSE;
  438. }
  439. CHMScopeItem* pHMItem = (CHMScopeItem*)pSPI;
  440. if( ! GfxCheckObjPtr(pPane,CHealthmonResultsPane) )
  441. {
  442. TRACE(_T("FAILED : pPane is not a valid pointer.\n"));
  443. return E_FAIL;
  444. }
  445. CHMObject* pObject = pHMItem->GetObjectPtr();
  446. if( !pObject || ! GfxCheckObjPtr(pObject,CHMObject) )
  447. {
  448. return E_FAIL;
  449. }
  450. pPane->GetGraphViewSink()->SetResultsViewPtr(NULL);
  451. if(pPane->GetGraphViewCtrl())
  452. {
  453. pPane->GetGraphViewCtrl()->Clear();
  454. }
  455. CString sWaiting;
  456. sWaiting.LoadString(IDS_STRING_WAITING);
  457. pPane->GetStatsListCtrl()->SetTitle(sWaiting);
  458. return S_OK;
  459. }
  460. //////////////////////////////////////////////////////////////////////
  461. // GraphView Events Members
  462. //////////////////////////////////////////////////////////////////////
  463. void CSplitPaneResultsView::OnGraphViewStyleChange(_DHMGraphView* pGraphView)
  464. {
  465. if( ! pGraphView )
  466. {
  467. ASSERT(FALSE);
  468. return;
  469. }
  470. CScopePaneItem* pSPI = GetOwnerScopeItem();
  471. if( ! pSPI->IsKindOf(RUNTIME_CLASS(CHMScopeItem)) )
  472. {
  473. return;
  474. }
  475. CHMScopeItem* pHMItem = (CHMScopeItem*)pSPI;
  476. CHMObject* pObject = pHMItem->GetObjectPtr();
  477. if( !pObject || ! GfxCheckObjPtr(pObject,CHMObject) )
  478. {
  479. return;
  480. }
  481. pGraphView->SetName(pObject->GetName());
  482. CEventContainer* pContainer = NULL;
  483. EvtGetEventManager()->GetEventContainer(pObject->GetSystemName(),pObject->GetGuid(),pContainer);
  484. if( pContainer )
  485. {
  486. for(int i = 0; i < pContainer->GetStatisticsCount(); i++ )
  487. {
  488. if( i > pContainer->GetStatisticsCount()-10 )
  489. {
  490. CStatistics* pStat = pContainer->GetStatistic(i);
  491. if( pStat )
  492. {
  493. AddStatistic(pContainer,pStat);
  494. }
  495. }
  496. }
  497. }
  498. }