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.

469 lines
11 KiB

  1. // HMEventResultsPaneItem.cpp: implementation of the CHMEventResultsPaneItem class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "snapin.h"
  6. #include "HMEventResultsPaneItem.h"
  7. #include "HealthmonResultsPane.h"
  8. #include "ScopePaneItem.h"
  9. #include "ResultsPaneView.h"
  10. #include "AlertPage.h"
  11. #ifdef _DEBUG
  12. #undef THIS_FILE
  13. static char THIS_FILE[]=__FILE__;
  14. #define new DEBUG_NEW
  15. #endif
  16. IMPLEMENT_DYNCREATE(CHMEventResultsPaneItem,CHMResultsPaneItem)
  17. //////////////////////////////////////////////////////////////////////
  18. // Construction/Destruction
  19. //////////////////////////////////////////////////////////////////////
  20. CHMEventResultsPaneItem::CHMEventResultsPaneItem()
  21. {
  22. ZeroMemory(&m_st,sizeof(SYSTEMTIME));
  23. m_iState = HMS_UNKNOWN;
  24. m_iDateTimeColumn = -1;
  25. }
  26. CHMEventResultsPaneItem::~CHMEventResultsPaneItem()
  27. {
  28. Destroy();
  29. m_iState = -1;
  30. m_iDateTimeColumn = -1;
  31. }
  32. /////////////////////////////////////////////////////////////////////////////
  33. // Display Names Members
  34. CString CHMEventResultsPaneItem::GetDisplayName(int nIndex /* = 0*/)
  35. {
  36. TRACEX(_T("CResultsPaneItem::GetDisplayName\n"));
  37. TRACEARGn(nIndex);
  38. if( nIndex >= m_saDisplayNames.GetSize() || nIndex < 0 )
  39. {
  40. TRACE(_T("FAILED : nIndex is out of array bounds.\n"));
  41. return _T("");
  42. }
  43. if( nIndex == GetDateTimeColumn() )
  44. {
  45. CString sTime;
  46. CString sDate;
  47. int iLen = GetTimeFormat(LOCALE_USER_DEFAULT,0L,&m_st,NULL,NULL,0);
  48. iLen = GetTimeFormat(LOCALE_USER_DEFAULT,0L,&m_st,NULL,sTime.GetBuffer(iLen+(sizeof(TCHAR)*1)),iLen);
  49. sTime.ReleaseBuffer();
  50. iLen = GetDateFormat(LOCALE_USER_DEFAULT,0L,&m_st,NULL,NULL,0);
  51. iLen = GetDateFormat(LOCALE_USER_DEFAULT,0L,&m_st,NULL,sDate.GetBuffer(iLen+(sizeof(TCHAR)*1)),iLen);
  52. sDate.ReleaseBuffer();
  53. return sDate + _T(" ") + sTime;
  54. }
  55. return m_saDisplayNames[nIndex];
  56. }
  57. /////////////////////////////////////////////////////////////////////////////
  58. // MMC-Related Members
  59. int CHMEventResultsPaneItem::CompareItem(CResultsPaneItem* pItem, int iColumn /*= 0*/ )
  60. {
  61. TRACEX(_T("CResultsPaneItem::CompareItem\n"));
  62. TRACEARGn(pItem);
  63. TRACEARGn(iColumn);
  64. CHMEventResultsPaneItem* pEventItem = (CHMEventResultsPaneItem*)pItem;
  65. if( ! GfxCheckObjPtr(pEventItem,CHMEventResultsPaneItem) )
  66. {
  67. return CResultsPaneItem::CompareItem(pItem,iColumn);
  68. }
  69. if( iColumn == GetDateTimeColumn() )
  70. {
  71. CTime time1(m_st);
  72. CTime time2(pEventItem->m_st);
  73. if( time1 == time2 )
  74. return 0;
  75. if( time1 < time2 )
  76. return 1;
  77. if( time1 > time2 )
  78. return -1;
  79. }
  80. if( iColumn == 0 && IsLowerPane() )
  81. {
  82. if( m_iState == pEventItem->m_iState )
  83. return 0;
  84. if( m_iState < pEventItem->m_iState )
  85. return 1;
  86. if( m_iState > pEventItem->m_iState )
  87. return -1;
  88. }
  89. return CResultsPaneItem::CompareItem(pItem,iColumn);
  90. }
  91. HRESULT CHMEventResultsPaneItem::WriteExtensionData(LPSTREAM pStream)
  92. {
  93. TRACEX(_T("CHMEventResultsPaneItem::WriteExtensionData\n"));
  94. TRACEARGn(pStream);
  95. HRESULT hr = S_OK;
  96. ULONG ulSize = GetDisplayName(3).GetLength() + 1;
  97. ulSize *= sizeof(TCHAR);
  98. if( ! CHECKHRESULT(hr = pStream->Write(GetDisplayName(3), ulSize, NULL)) )
  99. {
  100. return hr;
  101. }
  102. CString sType = IDS_STRING_MOF_HMR_STATUS;
  103. ulSize = sType.GetLength() + 1;
  104. ulSize *= sizeof(TCHAR);
  105. if( ! CHECKHRESULT(hr = pStream->Write(sType, ulSize, NULL)) )
  106. {
  107. return hr;
  108. }
  109. ulSize = m_sGuid.GetLength() + 1;
  110. ulSize *= sizeof(TCHAR);
  111. if( ! CHECKHRESULT(hr = pStream->Write(m_sGuid, ulSize, NULL)) )
  112. {
  113. return hr;
  114. }
  115. return S_OK;
  116. }
  117. /////////////////////////////////////////////////////////////////////////////
  118. // MMC Notify Handlers
  119. /////////////////////////////////////////////////////////////////////////////
  120. HRESULT CHMEventResultsPaneItem::OnAddMenuItems(LPCONTEXTMENUCALLBACK piCallback,long __RPC_FAR *pInsertionAllowed)
  121. {
  122. TRACEX(_T("CHMEventResultsPaneItem::OnAddMenuItems\n"));
  123. TRACEARGn(piCallback);
  124. TRACEARGn(pInsertionAllowed);
  125. HRESULT hr = S_OK;
  126. // Add New Menu Items
  127. if( CCM_INSERTIONALLOWED_NEW & *pInsertionAllowed )
  128. {
  129. // TODO: Add any context menu items for the New Menu here
  130. }
  131. // Add Task Menu Items
  132. if( CCM_INSERTIONALLOWED_TASK & *pInsertionAllowed )
  133. {
  134. // TODO: Add any context menu items for the Task Menu here
  135. }
  136. // Add Top Menu Items
  137. if( CCM_INSERTIONALLOWED_TOP & *pInsertionAllowed )
  138. {
  139. CONTEXTMENUITEM cmi;
  140. CString sResString;
  141. CString sResString2;
  142. // Copy
  143. sResString.LoadString(IDS_STRING_COPY);
  144. cmi.strName = LPTSTR(LPCTSTR(sResString));
  145. cmi.strStatusBarText = NULL;
  146. cmi.lCommandID = IDM_COPY;
  147. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  148. cmi.fFlags = 0;
  149. cmi.fSpecialFlags = 0;
  150. hr = piCallback->AddItem(&cmi);
  151. if( !SUCCEEDED(hr) )
  152. {
  153. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  154. return hr;
  155. }
  156. if( ! IsStatsPane() )
  157. {
  158. // Delete
  159. sResString.LoadString(IDS_STRING_CLEAR);
  160. cmi.strName = LPTSTR(LPCTSTR(sResString));
  161. cmi.strStatusBarText = NULL;
  162. cmi.lCommandID = IDM_DELETE;
  163. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  164. cmi.fFlags = 0;
  165. cmi.fSpecialFlags = 0;
  166. hr = piCallback->AddItem(&cmi);
  167. if( !SUCCEEDED(hr) )
  168. {
  169. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  170. return hr;
  171. }
  172. // Refresh
  173. sResString.LoadString(IDS_STRING_REFRESH);
  174. cmi.strName = LPTSTR(LPCTSTR(sResString));
  175. cmi.strStatusBarText = NULL;
  176. cmi.lCommandID = IDM_REFRESH;
  177. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  178. cmi.fFlags = 0;
  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. if( ! IsUpperPane() )
  187. {
  188. cmi.strName = NULL;
  189. cmi.strStatusBarText = NULL;
  190. cmi.lCommandID = 0;
  191. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  192. cmi.fFlags = MF_SEPARATOR;
  193. cmi.fSpecialFlags = 0;
  194. hr = piCallback->AddItem(&cmi);
  195. if( !SUCCEEDED(hr) )
  196. {
  197. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  198. return hr;
  199. }
  200. // Properties
  201. sResString.LoadString(IDS_STRING_ALERT_PROPERTIES);
  202. cmi.strName = LPTSTR(LPCTSTR(sResString));
  203. cmi.strStatusBarText = NULL;
  204. cmi.lCommandID = IDM_PROPERTIES;
  205. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  206. cmi.fFlags = 0;
  207. cmi.fSpecialFlags = 0;
  208. hr = piCallback->AddItem(&cmi);
  209. if( !SUCCEEDED(hr) )
  210. {
  211. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  212. return hr;
  213. }
  214. cmi.strName = NULL;
  215. cmi.strStatusBarText = NULL;
  216. cmi.lCommandID = 0;
  217. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  218. cmi.fFlags = MF_SEPARATOR;
  219. cmi.fSpecialFlags = 0;
  220. hr = piCallback->AddItem(&cmi);
  221. if( !SUCCEEDED(hr) )
  222. {
  223. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  224. return hr;
  225. }
  226. }
  227. // Help
  228. sResString.LoadString(IDS_STRING_HELP);
  229. cmi.strName = LPTSTR(LPCTSTR(sResString));
  230. cmi.strStatusBarText = NULL;
  231. cmi.lCommandID = IDM_HELP;
  232. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  233. cmi.fFlags = 0;
  234. cmi.fSpecialFlags = 0;
  235. hr = piCallback->AddItem(&cmi);
  236. if( !SUCCEEDED(hr) )
  237. {
  238. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  239. return hr;
  240. }
  241. }
  242. }
  243. return S_OK;
  244. }
  245. HRESULT CHMEventResultsPaneItem::OnCommand(CResultsPane* pPane, long lCommandID)
  246. {
  247. TRACEX(_T("CHMEventResultsPaneItem::OnCommand\n"));
  248. TRACEARGn(pPane);
  249. TRACEARGn(lCommandID);
  250. CHealthmonResultsPane* pHMRP = (CHealthmonResultsPane*)pPane;
  251. if( ! GfxCheckObjPtr(pHMRP,CHealthmonResultsPane) )
  252. {
  253. return E_FAIL;
  254. }
  255. HRESULT hr = S_OK;
  256. switch( lCommandID )
  257. {
  258. case IDM_CUT:
  259. {
  260. }
  261. break;
  262. case IDM_COPY:
  263. {
  264. _DHMListView* pListView = IsStatsPane() ? pHMRP->GetStatsListCtrl() : pHMRP->GetLowerListCtrl();
  265. if( ! pListView )
  266. {
  267. return E_FAIL;
  268. }
  269. CTypedPtrArray<CObArray,CHMEventResultsPaneItem*> Items;
  270. int iIndex = pListView->GetNextItem(-1,LVNI_SELECTED);
  271. while( iIndex != -1 )
  272. {
  273. LPARAM lParam = pListView->GetItem(iIndex);
  274. CHMEventResultsPaneItem* pItem = (CHMEventResultsPaneItem*)lParam;
  275. if( GfxCheckObjPtr(pItem,CHMEventResultsPaneItem) )
  276. {
  277. Items.Add(pItem);
  278. }
  279. int iNextIndex = pListView->GetNextItem(iIndex,LVNI_SELECTED|LVNI_BELOW);
  280. if( iNextIndex == iIndex )
  281. {
  282. break;
  283. }
  284. else
  285. {
  286. iIndex = iNextIndex;
  287. }
  288. }
  289. CString sData;
  290. for( int i = 0; i < Items.GetSize(); i++ )
  291. {
  292. CHMEventResultsPaneItem* pItem = Items[i];
  293. if( IsStatsPane() )
  294. {
  295. for( int l = 0; l < pItem->GetDisplayNameCount(); l++ )
  296. {
  297. sData += pItem->m_saDisplayNames[l] + _T("\t");
  298. }
  299. }
  300. else
  301. {
  302. for( int l = 0; l < pItem->GetDisplayNameCount(); l++ )
  303. {
  304. sData += pItem->GetDisplayName(l) + _T("\t");
  305. }
  306. }
  307. sData.TrimRight(_T("\t"));
  308. sData += _T("\r\n");
  309. }
  310. COleDataSource* pDataSource = new COleDataSource;
  311. // Allocate memory for the stream
  312. HGLOBAL hGlobal = GlobalAlloc( GMEM_SHARE, (sData.GetLength()+1)*sizeof(TCHAR) );
  313. if( ! hGlobal )
  314. {
  315. hr = E_OUTOFMEMORY;
  316. TRACE(_T("FAILED : Out of Memory.\n"));
  317. return hr;
  318. }
  319. LPVOID lpGlobal = GlobalLock(hGlobal);
  320. CopyMemory(lpGlobal,(LPCTSTR)sData,(sData.GetLength()+1)*sizeof(TCHAR));
  321. GlobalUnlock(hGlobal);
  322. pDataSource->CacheGlobalData(CF_UNICODETEXT,hGlobal);
  323. pDataSource->SetClipboard();
  324. }
  325. break;
  326. case IDM_DELETE:
  327. {
  328. CHMListViewEventSink* pSink = pHMRP->GetLowerListSink();
  329. pSink->OnDelete();
  330. }
  331. break;
  332. case IDM_PROPERTIES:
  333. {
  334. _DHMListView* pListView = IsStatsPane() ? pHMRP->GetStatsListCtrl() : pHMRP->GetLowerListCtrl();
  335. CPropertySheet sheet(IDS_STRING_PROPERTIES_OF_ALERT);
  336. sheet.m_psh.dwFlags |= PSH_HASHELP;
  337. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  338. CAlertPage page;
  339. page.m_psp.dwFlags |= PSP_HASHELP;
  340. sheet.AddPage(&page);
  341. page.m_sSeverity = GetDisplayName(0);
  342. page.m_sID = GetDisplayName(1);
  343. page.m_sDTime = GetDisplayName(2);
  344. page.m_sDataCollector = GetDisplayName(3);
  345. page.m_sComputer = GetDisplayName(4);
  346. page.m_sAlert = GetDisplayName(5);
  347. page.m_pScopePane = pHMRP->GetOwnerScopePane();
  348. page.m_pListView = pListView;
  349. #ifndef IA64
  350. page.m_iIndex = pListView->FindItemByLParam((LPARAM)this); // Needs ptr fixing
  351. #endif // IA64
  352. sheet.DoModal();
  353. }
  354. break;
  355. case IDM_REFRESH:
  356. {
  357. CResultsPaneView* pView = GetOwnerResultsView();
  358. if( pView )
  359. {
  360. CScopePaneItem* pSPI = pView->GetOwnerScopeItem();
  361. if( GfxCheckObjPtr(pSPI,CScopePaneItem) )
  362. {
  363. pSPI->OnRefresh();
  364. }
  365. }
  366. }
  367. break;
  368. case IDM_HELP:
  369. {
  370. CResultsPaneView* pView = GetOwnerResultsView();
  371. if( pView )
  372. {
  373. CScopePaneItem* pSPI = pView->GetOwnerScopeItem();
  374. if( GfxCheckObjPtr(pSPI,CScopePaneItem) )
  375. {
  376. pSPI->OnContextHelp();
  377. }
  378. }
  379. }
  380. break;
  381. }
  382. return S_OK;
  383. }