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.

488 lines
11 KiB

  1. // HMResultsPaneItem.cpp: implementation of the CHMResultsPaneItem class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. //
  5. // Copyright (c) 2000 Microsoft Corporation
  6. //
  7. // 04/06/00 v-marfin 62935 : Show "OK" Instead of "Reset" in the upper pane only
  8. //
  9. //
  10. //
  11. //
  12. #include "stdafx.h"
  13. #include "snapin.h"
  14. #include "HMResultsPaneItem.h"
  15. #include "HealthmonResultsPane.h"
  16. #include "..\HMListView\HMList.h"
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[]=__FILE__;
  20. #define new DEBUG_NEW
  21. #endif
  22. IMPLEMENT_DYNCREATE(CHMResultsPaneItem,CResultsPaneItem)
  23. //////////////////////////////////////////////////////////////////////
  24. // Construction/Destruction
  25. //////////////////////////////////////////////////////////////////////
  26. CHMResultsPaneItem::CHMResultsPaneItem()
  27. {
  28. }
  29. CHMResultsPaneItem::~CHMResultsPaneItem()
  30. {
  31. Destroy();
  32. }
  33. /////////////////////////////////////////////////////////////////////////////
  34. // MMC-Related Members
  35. bool CHMResultsPaneItem::InsertItem(CResultsPane* pPane, int nIndex, bool bResizeColumns /*= false*/)
  36. {
  37. TRACEX(_T("CHMResultsPaneItem::InsertItem\n"));
  38. TRACEARGn(pPane);
  39. TRACEARGn(nIndex);
  40. TRACEARGn(bResizeColumns);
  41. if( ! GfxCheckObjPtr(pPane,CHealthmonResultsPane) )
  42. {
  43. TRACE(_T("FAILED : pPane is not a valid pointer.\n"));
  44. return false;
  45. }
  46. CHealthmonResultsPane* pHMRP = (CHealthmonResultsPane*)pPane;
  47. _DHMListView* pList = NULL;
  48. if( IsUpperPane() )
  49. {
  50. pList = pHMRP->GetUpperListCtrl();
  51. }
  52. else if( IsLowerPane() )
  53. {
  54. pList = pHMRP->GetLowerListCtrl();
  55. }
  56. else if( IsStatsPane() )
  57. {
  58. pList = pHMRP->GetStatsListCtrl();
  59. }
  60. else
  61. {
  62. TRACE(_T("WARNING : Column has not been assigned to a results pane in the split view.\n"));
  63. ASSERT(FALSE);
  64. }
  65. if( ! pList )
  66. {
  67. TRACE(_T("FAILED : Results Pane's list control has not been intialized.\n"));
  68. return false;
  69. }
  70. #ifndef IA64
  71. if( pList->FindItemByLParam((long)this) >= 0 ) // needs ptr fixing
  72. {
  73. return true;
  74. }
  75. #endif // IA64
  76. if( IsLowerPane() )
  77. {
  78. // check filters
  79. CStringArray saFilters;
  80. CDWordArray dwaFilterTypes;
  81. CString sFilter;
  82. BSTR bsFilter = NULL;
  83. long lType = -1L;
  84. long lColumnCount = pList->GetColumnCount();
  85. for( long l = 0L; l < lColumnCount; l++ )
  86. {
  87. pList->GetColumnFilter(l,&bsFilter,&lType);
  88. sFilter = bsFilter;
  89. saFilters.Add(sFilter);
  90. dwaFilterTypes.Add(lType);
  91. SysFreeString(bsFilter);
  92. }
  93. bool bItemPassed = true;
  94. for( l = 0L; l < lColumnCount; l++ )
  95. {
  96. if( dwaFilterTypes[l] == HDFS_CONTAINS )
  97. {
  98. if( saFilters[l] != _T("") && GetDisplayName(l).Find(saFilters[l]) == -1 )
  99. {
  100. bItemPassed = false;
  101. break;
  102. }
  103. }
  104. else if( dwaFilterTypes[l] == HDFS_DOES_NOT_CONTAIN )
  105. {
  106. if( saFilters[l] != _T("") && GetDisplayName(l).Find(saFilters[l]) != -1 )
  107. {
  108. bItemPassed = false;
  109. break;
  110. }
  111. }
  112. else if( dwaFilterTypes[l] == HDFS_STARTS_WITH )
  113. {
  114. if( saFilters[l] != _T("") && GetDisplayName(l).Find(saFilters[l]) != 0 )
  115. {
  116. bItemPassed = false;
  117. break;
  118. }
  119. }
  120. else if( dwaFilterTypes[l] == HDFS_ENDS_WITH )
  121. {
  122. if( saFilters[l] != _T("") && GetDisplayName(l).Find(saFilters[l]) != GetDisplayName(l).GetLength() - saFilters[l].GetLength() )
  123. {
  124. bItemPassed = false;
  125. break;
  126. }
  127. }
  128. else if( dwaFilterTypes[l] == HDFS_IS )
  129. {
  130. if( saFilters[l] != _T("") && GetDisplayName(l) != saFilters[l] )
  131. {
  132. bItemPassed = false;
  133. break;
  134. }
  135. }
  136. else if( dwaFilterTypes[l] == HDFS_IS_NOT )
  137. {
  138. if( saFilters[l] != _T("") && GetDisplayName(l) == saFilters[l] )
  139. {
  140. bItemPassed = false;
  141. break;
  142. }
  143. }
  144. }
  145. if( ! bItemPassed )
  146. {
  147. return true;
  148. }
  149. }
  150. // insert the item
  151. DWORD dwlvif = LVIF_TEXT|LVIF_PARAM;
  152. int iIconIndex = -1;
  153. if( m_IconResIds.GetSize() > 0 )
  154. {
  155. dwlvif |= LVIF_IMAGE;
  156. iIconIndex = pHMRP->GetIconIndex(GetIconId(),m_Pane);
  157. }
  158. int iResult=0;
  159. #ifndef IA64
  160. iResult = pList->InsertItem(dwlvif,
  161. IsUpperPane() ? nIndex : 0,
  162. (LPCTSTR)GetDisplayName(),
  163. -1L,
  164. -1L,
  165. iIconIndex,
  166. (long)this);
  167. #endif // IA64
  168. // insert the subitems
  169. for(int i = 1; i < m_saDisplayNames.GetSize(); i++ )
  170. {
  171. #ifndef IA64
  172. iResult = pList->SetItem(IsUpperPane() ? nIndex : 0,
  173. i,
  174. LVIF_TEXT,
  175. (LPCTSTR)GetDisplayName(i),
  176. -1L,
  177. -1L,
  178. -1L,
  179. (long)this);
  180. #endif // IA64
  181. if( iResult == -1 )
  182. {
  183. TRACE(_T("FAILED : CHMListCtrl::InsertItem failed.\n"));
  184. }
  185. if( GetDisplayName(i).IsEmpty() && bResizeColumns )
  186. {
  187. pList->SetColumnWidth(i,LVSCW_AUTOSIZE_USEHEADER);
  188. }
  189. }
  190. if( iResult == -1 )
  191. {
  192. TRACE(_T("FAILED : CHMListCtrl::InsertItem failed.\n"));
  193. return false;
  194. }
  195. if( bResizeColumns )
  196. {
  197. /*
  198. int iColWidth = 0;
  199. int iStrWidth = 0;
  200. // set the widths of the columns for this item
  201. for( int i = 0; i < m_saDisplayNames.GetSize(); i++ )
  202. {
  203. // get the width in pixels of the item
  204. iStrWidth = pList->GetStringWidth((LPCTSTR)m_saDisplayNames[i]) + 16;
  205. iColWidth = pList->GetColumnWidth(i);
  206. if( iStrWidth > iColWidth && iStrWidth > 10 )
  207. pList->SetColumnWidth(i,iStrWidth);
  208. }
  209. */
  210. }
  211. return true;
  212. }
  213. bool CHMResultsPaneItem::SetItem(CResultsPane* pPane)
  214. {
  215. TRACEX(_T("CHMResultsPaneItem::SetItem\n"));
  216. TRACEARGn(pPane);
  217. if( ! GfxCheckObjPtr(pPane,CHealthmonResultsPane) )
  218. {
  219. TRACE(_T("FAILED : pPane is not a valid pointer.\n"));
  220. return false;
  221. }
  222. CHealthmonResultsPane* pHMRP = (CHealthmonResultsPane*)pPane;
  223. _DHMListView* pList = NULL;
  224. BOOL bUpperPane = FALSE; // 62935 : Show "OK" Instead of "Reset" in the upper pane only
  225. int iIndex = -1;
  226. if( IsUpperPane() )
  227. {
  228. pList = pHMRP->GetUpperListCtrl();
  229. bUpperPane=TRUE; // 62935 : Show "OK" Instead of "Reset" in the upper pane only
  230. }
  231. else if( IsLowerPane() )
  232. {
  233. pList = pHMRP->GetLowerListCtrl();
  234. }
  235. else if( IsStatsPane() )
  236. {
  237. pList = pHMRP->GetStatsListCtrl();
  238. }
  239. else
  240. {
  241. TRACE(_T("WARNING : Column has not been assigned to a results pane in the split view.\n"));
  242. ASSERT(FALSE);
  243. }
  244. if( ! pList )
  245. {
  246. TRACE(_T("FAILED : Results Pane's list control has not been intialized.\n"));
  247. return false;
  248. }
  249. #ifndef IA64
  250. iIndex = pList->FindItemByLParam((long)this);
  251. #endif // IA64
  252. // set the item
  253. DWORD dwlvif = LVIF_TEXT;
  254. int iIconIndex = -1;
  255. if( m_IconResIds.GetSize() > 0 )
  256. {
  257. dwlvif |= LVIF_IMAGE;
  258. iIconIndex = pHMRP->GetIconIndex(GetIconId(),m_Pane);
  259. }
  260. int iResult=0;
  261. #ifndef IA64
  262. iResult = pList->SetItem(iIndex,
  263. 0,
  264. dwlvif,
  265. (LPCTSTR)GetDisplayName(),
  266. iIconIndex,
  267. -1L,
  268. -1L,
  269. (long)this);
  270. #endif // IA64
  271. // 62935 : Show "OK" Instead of "Reset" in the upper pane only
  272. CString sOK;
  273. sOK.LoadString(IDS_STRING_OK);
  274. CString sReset;
  275. sReset.LoadString(IDS_STRING_RESET);
  276. // insert the subitems
  277. for(int i = 1; i < m_saDisplayNames.GetSize(); i++ )
  278. {
  279. CString sTest = GetDisplayName(i);
  280. #ifndef IA64
  281. iResult = pList->SetItem(iIndex,
  282. i,
  283. LVIF_TEXT,
  284. //(LPCTSTR)GetDisplayName(i), // 62935
  285. (i==1 && bUpperPane && GetDisplayName(i) == sReset) ? (LPCTSTR)sOK : (LPCTSTR)GetDisplayName(i), // 62935 -1L,
  286. -1L,
  287. -1L,
  288. -1L,
  289. (long)this);
  290. #endif // IA64
  291. if( iResult == -1 )
  292. {
  293. TRACE(_T("FAILED : CHMListCtrl::InsertItem failed.\n"));
  294. }
  295. }
  296. if( iResult == -1 )
  297. {
  298. TRACE(_T("FAILED : CHMListCtrl::InsertItem failed.\n"));
  299. return false;
  300. }
  301. return true;
  302. }
  303. bool CHMResultsPaneItem::RemoveItem(CResultsPane* pPane)
  304. {
  305. TRACEX(_T("CHMResultsPaneItem::RemoveItem\n"));
  306. TRACEARGn(pPane);
  307. if( ! GfxCheckObjPtr(pPane,CHealthmonResultsPane) )
  308. {
  309. TRACE(_T("FAILED : pPane is an invalid pointer.\n"));
  310. return false;
  311. }
  312. if( ! GfxCheckObjPtr(pPane,CHealthmonResultsPane) )
  313. {
  314. TRACE(_T("FAILED : pPane is not a valid pointer.\n"));
  315. return false;
  316. }
  317. CHealthmonResultsPane* pHMRP = (CHealthmonResultsPane*)pPane;
  318. _DHMListView* pList = NULL;
  319. int iIndex = -1;
  320. if( IsUpperPane() )
  321. {
  322. pList = pHMRP->GetUpperListCtrl();
  323. }
  324. else if( IsLowerPane() )
  325. {
  326. pList = pHMRP->GetLowerListCtrl();
  327. }
  328. else if( IsStatsPane() )
  329. {
  330. pList = pHMRP->GetStatsListCtrl();
  331. }
  332. else
  333. {
  334. TRACE(_T("WARNING : Column has not been assigned to a results pane in the split view.\n"));
  335. ASSERT(FALSE);
  336. }
  337. if( ! pList )
  338. {
  339. TRACE(_T("FAILED : Results Pane's list control has not been intialized.\n"));
  340. return false;
  341. }
  342. #ifndef IA64
  343. iIndex = pList->FindItemByLParam((long)this);
  344. #endif // IA64
  345. if( iIndex == -1 )
  346. {
  347. return false;
  348. }
  349. return pList->DeleteItem(iIndex) ? TRUE : FALSE;
  350. }
  351. /////////////////////////////////////////////////////////////////////////////
  352. // MMC Notify Handlers
  353. /////////////////////////////////////////////////////////////////////////////
  354. HRESULT CHMResultsPaneItem::OnAddMenuItems(LPCONTEXTMENUCALLBACK piCallback,long __RPC_FAR *pInsertionAllowed)
  355. {
  356. TRACEX(_T("CHMResultsPaneItem::OnAddMenuItems\n"));
  357. TRACEARGn(piCallback);
  358. TRACEARGn(pInsertionAllowed);
  359. HRESULT hr = S_OK;
  360. // Add New Menu Items
  361. if( CCM_INSERTIONALLOWED_NEW & *pInsertionAllowed )
  362. {
  363. // TODO: Add any context menu items for the New Menu here
  364. }
  365. // Add Task Menu Items
  366. if( CCM_INSERTIONALLOWED_TASK & *pInsertionAllowed )
  367. {
  368. // TODO: Add any context menu items for the Task Menu here
  369. }
  370. // Add Top Menu Items
  371. if( CCM_INSERTIONALLOWED_TOP & *pInsertionAllowed )
  372. {
  373. CONTEXTMENUITEM cmi;
  374. CString sResString;
  375. CString sResString2;
  376. // Cut
  377. sResString.LoadString(IDS_STRING_CUT);
  378. cmi.strName = LPTSTR(LPCTSTR(sResString));
  379. cmi.strStatusBarText = NULL;
  380. cmi.lCommandID = IDM_CUT;
  381. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  382. cmi.fFlags = 0;
  383. cmi.fSpecialFlags = 0;
  384. hr = piCallback->AddItem(&cmi);
  385. if( !SUCCEEDED(hr) )
  386. {
  387. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  388. return hr;
  389. }
  390. // Copy
  391. sResString.LoadString(IDS_STRING_COPY);
  392. cmi.strName = LPTSTR(LPCTSTR(sResString));
  393. cmi.strStatusBarText = NULL;
  394. cmi.lCommandID = IDM_COPY;
  395. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  396. cmi.fFlags = 0;
  397. cmi.fSpecialFlags = 0;
  398. hr = piCallback->AddItem(&cmi);
  399. if( !SUCCEEDED(hr) )
  400. {
  401. TRACE(_T("FAILED : IContextMenuCallback::AddItem failed.\n"));
  402. return hr;
  403. }
  404. }
  405. return S_OK;
  406. }
  407. HRESULT CHMResultsPaneItem::OnCommand(CResultsPane* pPane, long lCommandID)
  408. {
  409. TRACEX(_T("CHMResultsPaneItem::OnCommand\n"));
  410. TRACEARGn(lCommandID);
  411. return S_OK;
  412. }