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.

440 lines
13 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) 2002 Microsoft Corporation. All rights reserved.
  3. // Copyright (c) 2002 OSR Open Systems Resources, Inc.
  4. //
  5. // LogDisplayOptionDlg.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 "LogSessionInformationDlg.h"
  19. #include "ProviderSetupDlg.h"
  20. #include "LogSessionPropSht.h"
  21. #include "Utils.h"
  22. #include "LogDisplayOptionDlg.h"
  23. CString itemName[MaxLogSessionOptions] = {"State",
  24. "Event Count",
  25. "Events Lost",
  26. "Buffers Read",
  27. "Flags",
  28. "Flush Time (S)",
  29. "Maximum Buffers",
  30. "Minimum Buffers",
  31. "Buffer Size",
  32. "Decay Time (Minutes)",
  33. "Circular Buffer Size (MB)",
  34. "Sequential Buffer Size (MB)",
  35. "Start New File After Buffer Size (MB)",
  36. "Use Global Sequence Numbers",
  37. "Use Local Sequence Numbers",
  38. "Level"};
  39. // CListCtrlDisplay - CListCtrl class only used for CLogDisplayOptionDlg
  40. IMPLEMENT_DYNAMIC(CListCtrlDisplay, CListCtrl)
  41. CListCtrlDisplay::CListCtrlDisplay(CLogSessionPropSht *pPropSheet)
  42. : CListCtrl()
  43. {
  44. m_pPropSheet = pPropSheet;
  45. }
  46. CListCtrlDisplay::~CListCtrlDisplay()
  47. {
  48. }
  49. void CListCtrlDisplay::DoDataExchange(CDataExchange* pDX)
  50. {
  51. CListCtrl::DoDataExchange(pDX);
  52. }
  53. BEGIN_MESSAGE_MAP(CListCtrlDisplay, CListCtrl)
  54. //{{AFX_MSG_MAP(CLogSessionDlg)
  55. ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)
  56. //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58. void CListCtrlDisplay::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
  59. {
  60. LVITEM item;
  61. //
  62. // the structure is actually a NMLVCUSTOMDRAW that
  63. // specifies what the custom draw action is attempting
  64. // to do. We need to cast the generic pNMHDR pointer.
  65. //
  66. LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR;
  67. int iRow = (int)lplvcd->nmcd.dwItemSpec;
  68. switch(lplvcd->nmcd.dwDrawStage) {
  69. case CDDS_PREPAINT:
  70. //
  71. // ask for subitem notifications.
  72. //
  73. *pResult = CDRF_NOTIFYSUBITEMDRAW;
  74. break;
  75. case CDDS_ITEMPREPAINT:
  76. //
  77. // ask for subitem notifications.
  78. //
  79. *pResult = CDRF_NOTIFYSUBITEMDRAW;
  80. break;
  81. case CDDS_ITEMPREPAINT|CDDS_SUBITEM:
  82. //
  83. // recd when CDRF_NOTIFYSUBITEMDRAW is returned in
  84. // response to CDDS_ITEMPREPAINT.
  85. //
  86. *pResult = CDRF_NEWFONT;
  87. //
  88. // Default text is black on white background
  89. //
  90. lplvcd->clrTextBk = RGB(255, 255, 255);
  91. lplvcd->clrText = RGB(0, 0, 0);
  92. if(iRow < MaxLogSessionOptions) {
  93. item.iItem = iRow;
  94. item.state = LVIF_PARAM;
  95. item.mask = LVIF_PARAM;
  96. //
  97. // These fields are always grayed out as they cannot be
  98. // altered directly by the user
  99. //
  100. if((State == iRow) ||
  101. (EventCount == iRow) ||
  102. (LostEvents == iRow) ||
  103. (BuffersRead == iRow)) {
  104. lplvcd->clrTextBk = RGB(255, 255, 255);
  105. lplvcd->clrText = RGB(145, 145, 145);
  106. return;
  107. }
  108. //
  109. // The Flags field should be grayed out for
  110. // NT Kernel Logger sessions
  111. //
  112. if((Flags == iRow) &&
  113. (!_tcscmp(m_pPropSheet->m_displayName, _T("NT Kernel Logger")))) {
  114. lplvcd->clrTextBk = RGB(255, 255, 255);
  115. lplvcd->clrText = RGB(145, 145, 145);
  116. return;
  117. }
  118. }
  119. break;
  120. default:
  121. *pResult = CDRF_DODEFAULT;
  122. }
  123. }
  124. // CLogDisplayOptionDlg dialog
  125. IMPLEMENT_DYNAMIC(CLogDisplayOptionDlg, CPropertyPage)
  126. CLogDisplayOptionDlg::CLogDisplayOptionDlg(CLogSessionPropSht *pPropSheet)
  127. : CPropertyPage(CLogDisplayOptionDlg::IDD),
  128. m_displayOptionList(pPropSheet)
  129. {
  130. m_pPropSheet = pPropSheet;
  131. m_bTraceActive = m_pPropSheet->m_pLogSession->m_bTraceActive;
  132. }
  133. CLogDisplayOptionDlg::~CLogDisplayOptionDlg()
  134. {
  135. }
  136. BOOL CLogDisplayOptionDlg::OnSetActive()
  137. {
  138. m_pPropSheet->SetWizardButtons(PSWIZB_BACK | PSWIZB_FINISH);
  139. m_displayOptionList.SetFocus();
  140. //
  141. // Gray out unsettable items
  142. //
  143. if(m_bTraceActive) {
  144. for(LONG ii = 0; ii < MaxLogSessionOptions; ii++) {
  145. if((ii != FlushTime) &&
  146. (ii != MaximumBuffers) &&
  147. (ii != Flags)) {
  148. m_displayOptionList.SetItemState(ii, LVIS_CUT, LVIS_CUT);
  149. }
  150. }
  151. } else {
  152. for(LONG ii = 0; ii < MaxLogSessionOptions; ii++) {
  153. if((ii == State) ||
  154. (ii == EventCount) ||
  155. (ii == LostEvents) ||
  156. (ii == BuffersRead)) {
  157. m_displayOptionList.SetItemState(ii, LVIS_CUT, LVIS_CUT);
  158. }
  159. }
  160. }
  161. //
  162. // Disable Flags value editing for NT Kernel Logger
  163. //
  164. if(!_tcscmp(m_pPropSheet->m_displayName, _T("NT Kernel Logger"))) {
  165. m_displayOptionList.SetItemState(Flags, LVIS_CUT, LVIS_CUT);
  166. }
  167. m_displayOptionList.RedrawItems(0, MaxLogSessionOptions);
  168. m_displayOptionList.UpdateWindow();
  169. return CPropertyPage::OnSetActive();
  170. }
  171. BOOL CLogDisplayOptionDlg::OnInitDialog()
  172. {
  173. RECT rc;
  174. CString str;
  175. BOOL retVal;
  176. retVal = CDialog::OnInitDialog();
  177. //
  178. // get the dialog dimensions
  179. //
  180. GetParent()->GetClientRect(&rc);
  181. if(!m_displayOptionList.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|LVS_REPORT,
  182. rc,
  183. this,
  184. IDC_LOG_DISPLAY_OPTION_LIST))
  185. {
  186. TRACE(_T("Failed to create log session option list control\n"));
  187. return FALSE;
  188. }
  189. m_displayOptionList.CenterWindow();
  190. m_displayOptionList.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
  191. //
  192. // Insert the columns for the list control
  193. //
  194. m_displayOptionList.InsertColumn(0,
  195. _T("Option"),
  196. LVCFMT_LEFT,
  197. 300);
  198. m_displayOptionList.InsertColumn(1,
  199. _T("Value"),
  200. LVCFMT_LEFT,
  201. rc.right - rc.left - m_displayOptionList.GetColumnWidth(0) - 22);
  202. //
  203. // set the values in the display
  204. //
  205. for(LONG ii = 0; ii < MaxLogSessionOptions; ii++) {
  206. m_displayOptionList.InsertItem(ii, itemName[ii]);
  207. m_displayOptionList.SetItemText(ii, 1, m_pPropSheet->m_logSessionValues[ii]);
  208. }
  209. return retVal;
  210. }
  211. void CLogDisplayOptionDlg::DoDataExchange(CDataExchange* pDX)
  212. {
  213. CPropertyPage::DoDataExchange(pDX);
  214. }
  215. BEGIN_MESSAGE_MAP(CLogDisplayOptionDlg, CPropertyPage)
  216. ON_NOTIFY(NM_CLICK, IDC_LOG_DISPLAY_OPTION_LIST, OnNMClickDisplayList)
  217. ON_MESSAGE(WM_PARAMETER_CHANGED, OnParameterChanged)
  218. END_MESSAGE_MAP()
  219. // CLogDisplayOptionDlg message handlers
  220. void CLogDisplayOptionDlg::OnNMClickDisplayList(NMHDR *pNMHDR, LRESULT *pResult)
  221. {
  222. CString str;
  223. DWORD position;
  224. int listIndex;
  225. LVHITTESTINFO lvhti;
  226. CRect itemRect;
  227. CRect parentRect;
  228. //
  229. // Get the position of the mouse when this
  230. // message posted
  231. //
  232. position = ::GetMessagePos();
  233. //
  234. // Get the position in an easy to use format
  235. //
  236. CPoint point((int) LOWORD (position), (int)HIWORD(position));
  237. //
  238. // Convert to client coordinates
  239. //
  240. ScreenToClient(&point);
  241. lvhti.pt = point;
  242. listIndex = m_displayOptionList.SubItemHitTest(&lvhti);
  243. if(0 == lvhti.iSubItem) {
  244. if(-1 == lvhti.iItem) {
  245. //str.Format(_T("NM Click: Item = %d, Flags = 0x%X\n"), lvhti.iItem, lvhti.flags);
  246. //TRACE(str);
  247. } else {
  248. //str.Format(_T("NM Click: Item = %d\n"), lvhti.iItem);
  249. //TRACE(str);
  250. }
  251. } else if(-1 == lvhti.iItem) {
  252. //str.Format(_T("NM Click: Item = %d, Flags = 0x%X\n"), lvhti.iItem, lvhti.flags);
  253. //TRACE(str);
  254. } else {
  255. //str.Format(_T("NM Click: Item = %d, "), lvhti.iItem);
  256. //TRACE(str);
  257. //str.Format(_T("SubItem = %d\n"), lvhti.iSubItem);
  258. //TRACE(str);
  259. GetClientRect(&parentRect);
  260. m_displayOptionList.GetSubItemRect(lvhti.iItem, lvhti.iSubItem, LVIR_BOUNDS, itemRect);
  261. itemRect.right = m_displayOptionList.GetColumnWidth(0) + parentRect.left + (itemRect.right - itemRect.left);
  262. itemRect.left = m_displayOptionList.GetColumnWidth(0) + parentRect.left;
  263. *pResult = 0;
  264. if(lvhti.iItem == State) {
  265. return;
  266. }
  267. //
  268. // Determine if the user selected a modifiable field. If
  269. // so, pop up the proper edit or combo box to allow the user
  270. // to modify the log session properties.
  271. //
  272. if(((lvhti.iItem == GlobalSequence) ||
  273. (lvhti.iItem == LocalSequence)) &&
  274. (LVIS_CUT != m_displayOptionList.GetItemState(lvhti.iItem, LVIS_CUT))) {
  275. CComboBox *pCombo = new CSubItemCombo(lvhti.iItem,
  276. lvhti.iSubItem,
  277. &m_displayOptionList);
  278. pCombo->Create(WS_BORDER|WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST,
  279. itemRect,
  280. &m_displayOptionList,
  281. 1);
  282. return;
  283. }
  284. if((lvhti.iItem == Circular) &&
  285. (LVIS_CUT != m_displayOptionList.GetItemState(lvhti.iItem, LVIS_CUT))){
  286. CEdit *pEdit = new CSubItemEdit(lvhti.iItem,
  287. lvhti.iSubItem,
  288. &m_displayOptionList);
  289. pEdit->Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP,
  290. itemRect,
  291. this,
  292. 1);
  293. return;
  294. }
  295. if((lvhti.iItem == Sequential) &&
  296. (LVIS_CUT != m_displayOptionList.GetItemState(lvhti.iItem, LVIS_CUT))){
  297. CEdit *pEdit = new CSubItemEdit(lvhti.iItem,
  298. lvhti.iSubItem,
  299. &m_displayOptionList);
  300. pEdit->Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP,
  301. itemRect,
  302. this,
  303. 1);
  304. return;
  305. }
  306. if((lvhti.iItem == NewFile) &&
  307. (LVIS_CUT != m_displayOptionList.GetItemState(lvhti.iItem, LVIS_CUT))){
  308. CEdit *pEdit = new CSubItemEdit(lvhti.iItem,
  309. lvhti.iSubItem,
  310. &m_displayOptionList);
  311. pEdit->Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP,
  312. itemRect,
  313. this,
  314. 1);
  315. return;
  316. }
  317. if(LVIS_CUT != m_displayOptionList.GetItemState(lvhti.iItem, LVIS_CUT)){
  318. CEdit *pEdit = new CSubItemEdit(lvhti.iItem,
  319. lvhti.iSubItem,
  320. &m_displayOptionList);
  321. pEdit->Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP,
  322. itemRect,
  323. this,
  324. 1);
  325. }
  326. }
  327. }
  328. LRESULT CLogDisplayOptionDlg::OnParameterChanged(WPARAM wParam, LPARAM lParam)
  329. {
  330. CString str;
  331. //
  332. // Get the changed text
  333. //
  334. str = m_displayOptionList.GetItemText((int)wParam, (int)lParam);
  335. if(((int)wParam == Circular) &&
  336. !str.IsEmpty()) {
  337. m_displayOptionList.SetItemText(Sequential, (int)lParam, _T(""));
  338. m_displayOptionList.SetItemText(NewFile, (int)lParam, _T(""));
  339. }
  340. if(((int)wParam == Sequential) &&
  341. !str.IsEmpty()) {
  342. m_displayOptionList.SetItemText(Circular, (int)lParam, _T(""));
  343. m_displayOptionList.SetItemText(NewFile, (int)lParam, _T(""));
  344. }
  345. if(((int)wParam == NewFile) &&
  346. !str.IsEmpty()) {
  347. m_displayOptionList.SetItemText(Circular, (int)lParam, _T(""));
  348. m_displayOptionList.SetItemText(Sequential, (int)lParam, _T(""));
  349. }
  350. if(((int)wParam == GlobalSequence) &&
  351. !str.Compare(_T("TRUE"))) {
  352. m_displayOptionList.SetItemText(LocalSequence, (int)lParam, _T("FALSE"));
  353. }
  354. if(((int)wParam == LocalSequence) &&
  355. !str.Compare(_T("TRUE"))) {
  356. m_displayOptionList.SetItemText(GlobalSequence, (int)lParam, _T("FALSE"));
  357. }
  358. return 0;
  359. }