Leaked source code of windows server 2003
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.

441 lines
15 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) 2002 Microsoft Corporation. All rights reserved.
  3. // Copyright (c) 2002 OSR Open Systems Resources, Inc.
  4. //
  5. // ListCtrlEx.cpp : implementation file
  6. //////////////////////////////////////////////////////////////////////////////
  7. #include "stdafx.h"
  8. #include <tchar.h>
  9. #include <wmistr.h>
  10. #include <initguid.h>
  11. extern "C" {
  12. #include <evntrace.h>
  13. }
  14. #include <traceprt.h>
  15. #include "TraceView.h"
  16. #include "LogSession.h"
  17. #include "DisplayDlg.h"
  18. #include "ListCtrlEx.h"
  19. #include "LogSessionDlg.h"
  20. // CListCtrlEx
  21. IMPLEMENT_DYNAMIC(CListCtrlEx, CListCtrl)
  22. CListCtrlEx::CListCtrlEx()
  23. : CListCtrl()
  24. {
  25. //
  26. // Initialize flag for suspending list control updates
  27. // See SuspendUpdates() function
  28. //
  29. m_bSuspendUpdates = FALSE;
  30. }
  31. CListCtrlEx::~CListCtrlEx()
  32. {
  33. }
  34. void CListCtrlEx::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CListCtrl::DoDataExchange(pDX);
  37. }
  38. BEGIN_MESSAGE_MAP(CListCtrlEx, CListCtrl)
  39. //{{AFX_MSG_MAP(CLogSessionDlg)
  40. ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)
  41. //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43. void CListCtrlEx::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
  44. {
  45. CLogSession *pLogSession = NULL;
  46. CLogSessionDlg *pDialog = NULL;
  47. CDisplayDlg *pDisplayDlg = NULL;
  48. LVITEM item;
  49. //
  50. // the structure is actually a NMLVCUSTOMDRAW that
  51. // specifies what the custom draw action is attempting
  52. // to do. We need to cast the generic pNMHDR pointer.
  53. //
  54. LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR;
  55. int iCol = lplvcd->iSubItem;
  56. int iRow = (int)lplvcd->nmcd.dwItemSpec;
  57. switch(lplvcd->nmcd.dwDrawStage) {
  58. case CDDS_PREPAINT:
  59. //
  60. // ask for subitem notifications.
  61. //
  62. *pResult = CDRF_NOTIFYSUBITEMDRAW;
  63. break;
  64. case CDDS_ITEMPREPAINT:
  65. //
  66. // ask for subitem notifications.
  67. //
  68. *pResult = CDRF_NOTIFYSUBITEMDRAW;
  69. break;
  70. case CDDS_ITEMPREPAINT|CDDS_SUBITEM:
  71. //
  72. // recd when CDRF_NOTIFYSUBITEMDRAW is returned in
  73. // response to CDDS_ITEMPREPAINT.
  74. //
  75. *pResult = CDRF_NEWFONT;
  76. //
  77. // Default text is black on white background
  78. //
  79. lplvcd->clrTextBk = RGB(255, 255, 255);
  80. lplvcd->clrText = RGB(0, 0, 0);
  81. if((iCol == 0) && (iRow < GetItemCount())) {
  82. item.iItem = iRow;
  83. item.state = LVIF_PARAM;
  84. item.mask = LVIF_PARAM;
  85. CListCtrl::GetItem(&item);
  86. pLogSession = (CLogSession *)item.lParam;
  87. //
  88. // Go with the default if no session found
  89. //
  90. if(NULL == pLogSession) {
  91. return;
  92. }
  93. //
  94. // Set the text color
  95. //
  96. lplvcd->clrText = pLogSession->m_titleTextColor;
  97. lplvcd->clrTextBk = pLogSession->m_titleBackgroundColor;
  98. return;
  99. } else if(iRow < GetItemCount()) {
  100. item.iItem = iRow;
  101. item.state = LVIF_PARAM;
  102. item.mask = LVIF_PARAM;
  103. CListCtrl::GetItem(&item);
  104. pLogSession = (CLogSession *)item.lParam;
  105. //
  106. // Go with the default if no session found
  107. //
  108. if(NULL == pLogSession) {
  109. return;
  110. }
  111. //
  112. // These fields are always grayed out as they cannot be
  113. // altered directly by the user
  114. //
  115. pDialog = (CLogSessionDlg *)GetParent();
  116. if(pDialog == NULL) {
  117. return;
  118. }
  119. if(State == pDialog->m_retrievalArray[iCol]) {
  120. lplvcd->clrTextBk = RGB(255, 255, 255);
  121. lplvcd->clrText = RGB(145, 145, 145);
  122. //
  123. // Update the state text whenever we get here
  124. //
  125. if(pLogSession->m_logSessionValues[pDialog->m_retrievalArray[iCol]].Compare(CListCtrl::GetItemText(iRow, iCol))) {
  126. CListCtrl::SetItemText(iRow, iCol, pLogSession->m_logSessionValues[pDialog->m_retrievalArray[iCol]]);
  127. }
  128. return;
  129. }
  130. if(EventCount == pDialog->m_retrievalArray[iCol]) {
  131. lplvcd->clrTextBk = RGB(255, 255, 255);
  132. lplvcd->clrText = RGB(145, 145, 145);
  133. pDisplayDlg = pLogSession->GetDisplayWnd();
  134. if(NULL == pDisplayDlg) {
  135. return;
  136. }
  137. //
  138. // Update the event count text whenever we get here
  139. //
  140. pLogSession->m_logSessionValues[EventCount].Format(_T("%d"), pDisplayDlg->m_totalEventCount);
  141. if(pLogSession->m_logSessionValues[EventCount].Compare(CListCtrl::GetItemText(iRow, iCol))) {
  142. CListCtrl::SetItemText(iRow, iCol, pLogSession->m_logSessionValues[EventCount]);
  143. }
  144. return;
  145. }
  146. if(LostEvents == pDialog->m_retrievalArray[iCol]) {
  147. lplvcd->clrTextBk = RGB(255, 255, 255);
  148. lplvcd->clrText = RGB(145, 145, 145);
  149. pDisplayDlg = pLogSession->GetDisplayWnd();
  150. if(NULL == pDisplayDlg) {
  151. return;
  152. }
  153. //
  154. // Update the event count text whenever we get here
  155. //
  156. pLogSession->m_logSessionValues[LostEvents].Format(_T("%d"), pDisplayDlg->m_totalEventsLost);
  157. if(pLogSession->m_logSessionValues[LostEvents].Compare(CListCtrl::GetItemText(iRow, iCol))) {
  158. CListCtrl::SetItemText(iRow, iCol, pLogSession->m_logSessionValues[LostEvents]);
  159. }
  160. return;
  161. }
  162. if(BuffersRead == pDialog->m_retrievalArray[iCol]) {
  163. lplvcd->clrTextBk = RGB(255, 255, 255);
  164. lplvcd->clrText = RGB(145, 145, 145);
  165. pDisplayDlg = pLogSession->GetDisplayWnd();
  166. if(NULL == pDisplayDlg) {
  167. return;
  168. }
  169. //
  170. // Update the event count text whenever we get here
  171. //
  172. pLogSession->m_logSessionValues[BuffersRead].Format(_T("%d"), pDisplayDlg->m_totalBuffersRead);
  173. if(pLogSession->m_logSessionValues[BuffersRead].Compare(CListCtrl::GetItemText(iRow, iCol))) {
  174. CListCtrl::SetItemText(iRow, iCol, pLogSession->m_logSessionValues[BuffersRead]);
  175. }
  176. return;
  177. }
  178. //
  179. // Update all log session parameters if necessary
  180. //
  181. //
  182. // Flags
  183. //
  184. if(Flags == pDialog->m_retrievalArray[iCol]) {
  185. if(pLogSession->m_logSessionValues[Flags].Compare(CListCtrl::GetItemText(iRow, iCol))) {
  186. CListCtrl::SetItemText(iRow, iCol, pLogSession->m_logSessionValues[Flags]);
  187. }
  188. }
  189. //
  190. // FlushTime
  191. //
  192. if(FlushTime == pDialog->m_retrievalArray[iCol]) {
  193. if(pLogSession->m_logSessionValues[FlushTime].Compare(CListCtrl::GetItemText(iRow, iCol))) {
  194. CListCtrl::SetItemText(iRow, iCol, pLogSession->m_logSessionValues[FlushTime]);
  195. }
  196. }
  197. //
  198. // MaximumBuffers
  199. //
  200. if(MaximumBuffers == pDialog->m_retrievalArray[iCol]) {
  201. if(pLogSession->m_logSessionValues[MaximumBuffers].Compare(CListCtrl::GetItemText(iRow, iCol))) {
  202. CListCtrl::SetItemText(iRow, iCol, pLogSession->m_logSessionValues[MaximumBuffers]);
  203. }
  204. }
  205. //
  206. // MinimumBuffers
  207. //
  208. if(MinimumBuffers == pDialog->m_retrievalArray[iCol]) {
  209. if(pLogSession->m_logSessionValues[MinimumBuffers].Compare(CListCtrl::GetItemText(iRow, iCol))) {
  210. CListCtrl::SetItemText(iRow, iCol, pLogSession->m_logSessionValues[MinimumBuffers]);
  211. }
  212. }
  213. //
  214. // BufferSize
  215. //
  216. if(BufferSize == pDialog->m_retrievalArray[iCol]) {
  217. if(pLogSession->m_logSessionValues[BufferSize].Compare(CListCtrl::GetItemText(iRow, iCol))) {
  218. CListCtrl::SetItemText(iRow, iCol, pLogSession->m_logSessionValues[BufferSize]);
  219. }
  220. }
  221. //
  222. // DecayTime
  223. //
  224. if(DecayTime == pDialog->m_retrievalArray[iCol]) {
  225. if(pLogSession->m_logSessionValues[DecayTime].Compare(CListCtrl::GetItemText(iRow, iCol))) {
  226. CListCtrl::SetItemText(iRow, iCol, pLogSession->m_logSessionValues[DecayTime]);
  227. }
  228. }
  229. //
  230. // Circular
  231. //
  232. if(Circular == pDialog->m_retrievalArray[iCol]) {
  233. if(pLogSession->m_logSessionValues[Circular].Compare(CListCtrl::GetItemText(iRow, iCol))) {
  234. CListCtrl::SetItemText(iRow, iCol, pLogSession->m_logSessionValues[Circular]);
  235. }
  236. }
  237. //
  238. // Sequential
  239. //
  240. if(Sequential == pDialog->m_retrievalArray[iCol]) {
  241. if(pLogSession->m_logSessionValues[Sequential].Compare(CListCtrl::GetItemText(iRow, iCol))) {
  242. CListCtrl::SetItemText(iRow, iCol, pLogSession->m_logSessionValues[Sequential]);
  243. }
  244. }
  245. //
  246. // NewFile
  247. //
  248. if(NewFile == pDialog->m_retrievalArray[iCol]) {
  249. if(pLogSession->m_logSessionValues[NewFile].Compare(CListCtrl::GetItemText(iRow, iCol))) {
  250. CListCtrl::SetItemText(iRow, iCol, pLogSession->m_logSessionValues[NewFile]);
  251. }
  252. }
  253. //
  254. // GlobalSequence
  255. //
  256. if(GlobalSequence == pDialog->m_retrievalArray[iCol]) {
  257. if(pLogSession->m_logSessionValues[GlobalSequence].Compare(CListCtrl::GetItemText(iRow, iCol))) {
  258. CListCtrl::SetItemText(iRow, iCol, pLogSession->m_logSessionValues[GlobalSequence]);
  259. }
  260. }
  261. //
  262. // LocalSequence
  263. //
  264. if(LocalSequence == pDialog->m_retrievalArray[iCol]) {
  265. if(pLogSession->m_logSessionValues[LocalSequence].Compare(CListCtrl::GetItemText(iRow, iCol))) {
  266. CListCtrl::SetItemText(iRow, iCol, pLogSession->m_logSessionValues[LocalSequence]);
  267. }
  268. }
  269. //
  270. // Level
  271. //
  272. if(Level == pDialog->m_retrievalArray[iCol]) {
  273. if(pLogSession->m_logSessionValues[Level].Compare(CListCtrl::GetItemText(iRow, iCol))) {
  274. CListCtrl::SetItemText(iRow, iCol, pLogSession->m_logSessionValues[Level]);
  275. }
  276. }
  277. //
  278. // If this is a kernel logger session, then gray out
  279. // the flags field
  280. //
  281. if((Flags == pDialog->m_retrievalArray[iCol]) &&
  282. (!_tcscmp(pLogSession->GetDisplayName(), _T("NT Kernel Logger")))) {
  283. lplvcd->clrTextBk = RGB(255, 255, 255);
  284. lplvcd->clrText = RGB(145, 145, 145);
  285. return;
  286. }
  287. //
  288. // If the trace session is not active all fields are
  289. // shown with default
  290. //
  291. if(!pLogSession->m_bTraceActive) {
  292. return;
  293. }
  294. //
  295. // For existing logfile trace sessions we opt
  296. // for default
  297. //
  298. if(pLogSession->m_bDisplayExistingLogFileOnly) {
  299. return;
  300. }
  301. //
  302. // If the trace session is active, we gray out
  303. // any fields that cannot be updated while active.
  304. //
  305. if((Flags != pDialog->m_retrievalArray[iCol]) &&
  306. (MaximumBuffers != pDialog->m_retrievalArray[iCol]) &&
  307. (FlushTime != pDialog->m_retrievalArray[iCol])) {
  308. lplvcd->clrTextBk = RGB(255, 255, 255);
  309. lplvcd->clrText = RGB(145, 145, 145);
  310. return;
  311. }
  312. }
  313. //
  314. // Default text is black on white background
  315. //
  316. lplvcd->clrTextBk = RGB(255, 255, 255);
  317. lplvcd->clrText = RGB(0, 0, 0);
  318. break;
  319. default:
  320. *pResult = CDRF_DODEFAULT;
  321. }
  322. }
  323. int CListCtrlEx::InsertItem(int nItem, LPCTSTR lpszItem, CLogSession *pLogSession)
  324. {
  325. //
  326. // We don't allow NULL item data
  327. //
  328. if(pLogSession == NULL) {
  329. return 0;
  330. }
  331. //
  332. // Insert the item into the list with
  333. // the log session as item data
  334. //
  335. return CListCtrl::InsertItem(LVIF_TEXT | LVIF_PARAM,
  336. nItem,
  337. lpszItem,
  338. LVIF_TEXT | LVIF_PARAM,
  339. 0,
  340. 0,
  341. (LPARAM)pLogSession);
  342. }
  343. BOOL CListCtrlEx::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  344. {
  345. LPNMHDR pNH = (LPNMHDR) lParam;
  346. //
  347. // wParam is zero for Header ctrl
  348. //
  349. if(wParam == 0 && pNH->code == NM_RCLICK) {
  350. NMLISTVIEW NMListView;
  351. NMListView.hdr.code = HDN_ITEMRCLICK;
  352. NMListView.hdr.hwndFrom = m_hWnd;
  353. NMListView.hdr.idFrom = GetDlgCtrlID();
  354. CWnd* pWnd = GetParent();
  355. pWnd->SendMessage(WM_NOTIFY,
  356. GetDlgCtrlID(),
  357. (LPARAM)&NMListView);
  358. return TRUE;
  359. }
  360. return CListCtrl::OnNotify(wParam, lParam, pResult);
  361. }
  362. BOOL CListCtrlEx::RedrawItems(int nFirst, int nLast)
  363. {
  364. if(!m_bSuspendUpdates) {
  365. return CListCtrl::RedrawItems(nFirst, nLast);
  366. }
  367. return FALSE;
  368. }
  369. void CListCtrlEx::UpdateWindow()
  370. {
  371. if(!m_bSuspendUpdates) {
  372. CListCtrl::UpdateWindow();
  373. }
  374. }