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.

584 lines
15 KiB

  1. //***********************************************************************
  2. // evntprop.cpp
  3. //
  4. // This file contains the implementation of the event properties dialog.
  5. //
  6. // Author: SEA
  7. //
  8. // History:
  9. // 20-Febuary-1996 Larry A. French
  10. // Made various changes to this code. However, much of it is
  11. // legacy code and in dire need of being rewritten.
  12. //
  13. //
  14. // Copyright (C) 1995, 1996 Microsoft Corporation. All rights reserved.
  15. //
  16. //************************************************************************
  17. #include "stdafx.h"
  18. #include "resource.h"
  19. #include "eventrap.h"
  20. #include "evntprop.h"
  21. #include "trapreg.h"
  22. #include "globals.h"
  23. #ifdef _DEBUG
  24. #undef THIS_FILE
  25. static char BASED_CODE THIS_FILE[] = __FILE__;
  26. #endif
  27. #define MAX_EVENT_COUNT 32767
  28. #define MAX_TIME_INTERVAL 32767
  29. #define IsWithinRange(value, lower, upper) (((value) >= (lower)) && ((value) <= (upper)))
  30. void RangeError(int iLower, int iUpper)
  31. {
  32. TCHAR szBuffer[1024];
  33. CString sFormat;
  34. sFormat.LoadString(IDS_ERR_RANGE);
  35. _stprintf(szBuffer, (LPCTSTR) sFormat, iLower, iUpper);
  36. AfxMessageBox(szBuffer);
  37. }
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CEventPropertiesDlg dialog
  40. CEventPropertiesDlg::CEventPropertiesDlg(CWnd* pParent /*=NULL*/)
  41. : CDialog(CEventPropertiesDlg::IDD, pParent)
  42. {
  43. //{{AFX_DATA_INIT(CEventPropertiesDlg)
  44. m_sDescription = _T("");
  45. m_sSource = _T("");
  46. m_sEventId = _T("");
  47. m_sLog = _T("");
  48. m_sSourceOID = _T("");
  49. m_sFullEventID = _T("");
  50. //}}AFX_DATA_INIT
  51. }
  52. BOOL CEventPropertiesDlg::OnInitDialog()
  53. {
  54. CDialog::OnInitDialog();
  55. m_spinEventCount.SetRange(1, MAX_EVENT_COUNT);
  56. if (m_iEventCount==0) {
  57. m_spinEventCount.SetPos(1);
  58. } else {
  59. m_spinEventCount.SetPos(m_iEventCount);
  60. }
  61. if (m_iTimeInterval == 0) {
  62. m_btnWithinTime.SetCheck(0);
  63. m_spinTimeInterval.SetRange(0, MAX_TIME_INTERVAL);
  64. }
  65. else {
  66. m_btnWithinTime.SetCheck(1);
  67. m_spinTimeInterval.SetRange(1, MAX_TIME_INTERVAL);
  68. }
  69. m_spinTimeInterval.SetPos(m_iTimeInterval);
  70. m_edtTimeInterval.EnableWindow(m_btnWithinTime.GetCheck() == 1);
  71. m_spinTimeInterval.EnableWindow(m_btnWithinTime.GetCheck() == 1);
  72. // If this is not a custom configuration, do not let the user
  73. // modify the configuration.
  74. if ((g_reg.GetConfigType() != CONFIG_TYPE_CUSTOM) || (g_reg.m_bRegIsReadOnly)) {
  75. m_btnOK.EnableWindow(FALSE);
  76. }
  77. m_bDidEditEventCount = FALSE;
  78. OnWithintime();
  79. return TRUE; // return TRUE unless you set the focus to a control
  80. // EXCEPTION: OCX Property Pages should return FALSE
  81. }
  82. void CEventPropertiesDlg::DoDataExchange(CDataExchange* pDX)
  83. {
  84. CDialog::DoDataExchange(pDX);
  85. //{{AFX_DATA_MAP(CEventPropertiesDlg)
  86. DDX_Control(pDX, IDC_WITHINTIME, m_btnWithinTime);
  87. DDX_Control(pDX, IDC_EVENTCOUNTSPN, m_spinEventCount);
  88. DDX_Control(pDX, IDC_TIMEINTRVLSPN, m_spinTimeInterval);
  89. DDX_Control(pDX, IDC_TIMEINTERVAL, m_edtTimeInterval);
  90. DDX_Control(pDX, IDC_EVENTCOUNT, m_edtEventCount);
  91. DDX_Control(pDX, IDOK, m_btnOK);
  92. DDX_Text(pDX, IDC_DESCRIPTION, m_sDescription);
  93. DDV_MaxChars(pDX, m_sDescription, 2048);
  94. DDX_Text(pDX, ID_STAT_SOURCE, m_sSource);
  95. DDV_MaxChars(pDX, m_sSource, 256);
  96. DDX_Text(pDX, ID_STAT_EVENTID, m_sEventId);
  97. DDX_Text(pDX, ID_STAT_LOG, m_sLog);
  98. DDX_Text(pDX, IDC_EDIT_ENTERPRISEOID, m_sSourceOID);
  99. DDX_Text(pDX, IDC_EDIT_FULL_EVENT_ID, m_sFullEventID);
  100. //}}AFX_DATA_MAP
  101. }
  102. BEGIN_MESSAGE_MAP(CEventPropertiesDlg, CDialog)
  103. //{{AFX_MSG_MAP(CEventPropertiesDlg)
  104. ON_BN_CLICKED(IDC_WITHINTIME, OnWithintime)
  105. ON_COMMAND(ID_HELP, OnHelp)
  106. ON_WM_HELPINFO()
  107. ON_WM_CONTEXTMENU()
  108. //}}AFX_MSG_MAP
  109. END_MESSAGE_MAP()
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CEventPropertiesDlg message handlers
  112. void CEventPropertiesDlg::OnOK()
  113. {
  114. // TODO: Add extra validation here
  115. int iLower, iUpper;
  116. CString sText;
  117. m_spinEventCount.GetRange(iLower, iUpper);
  118. // Validate the event count edit item and set m_iEventCount
  119. m_edtEventCount.GetWindowText(sText);
  120. if (!IsDecimalInteger(sText)) {
  121. RangeError(iLower, iUpper);
  122. m_edtEventCount.SetSel(0, -1);
  123. m_edtEventCount.SetFocus();
  124. return;
  125. }
  126. m_iEventCount = _ttoi(sText);
  127. if (!IsWithinRange(m_iEventCount, iLower, iUpper)) {
  128. RangeError(iLower, iUpper);
  129. sText.Format(_T("%u"), m_iEventCount);
  130. m_edtEventCount.SetWindowText(sText);
  131. m_edtEventCount.SetSel(0, -1);
  132. m_edtEventCount.SetFocus();
  133. return;
  134. }
  135. // Validate the time interval and set m_iTimeInterval
  136. m_spinTimeInterval.GetRange(iLower, iUpper);
  137. m_edtTimeInterval.GetWindowText(sText);
  138. if (!IsDecimalInteger(sText)) {
  139. RangeError(iLower, iUpper);
  140. m_edtTimeInterval.SetSel(0, -1);
  141. m_edtTimeInterval.SetFocus();
  142. return;
  143. }
  144. m_iTimeInterval = _ttoi(sText);
  145. if (m_btnWithinTime.GetCheck() == 1) {
  146. if (m_iEventCount < 2) {
  147. AfxMessageBox(IDS_ERR_PROP_TIME1);
  148. m_edtEventCount.SetSel(0, -1);
  149. m_edtEventCount.SetFocus();
  150. return;
  151. }
  152. if (m_iTimeInterval < 1) {
  153. AfxMessageBox(IDS_ERR_PROP_TIME2);
  154. sText.Format(_T("%u"), m_iTimeInterval);
  155. m_edtTimeInterval.SetWindowText(sText);
  156. m_edtTimeInterval.SetSel(0, -1);
  157. m_edtTimeInterval.SetFocus();
  158. return;
  159. }
  160. if (!IsWithinRange(m_iTimeInterval, iLower, iUpper)) {
  161. RangeError(iLower, iUpper);
  162. sText.Format(_T("%u"), m_iTimeInterval);
  163. m_edtTimeInterval.SetWindowText(sText);
  164. m_edtTimeInterval.SetSel(0, -1);
  165. m_edtTimeInterval.SetFocus();
  166. return;
  167. }
  168. }
  169. else if (m_iEventCount < 1) {
  170. AfxMessageBox(IDS_ERR_PROP_TIME_LESS_THAN_TWO);
  171. m_edtEventCount.SetSel(0, -1);
  172. return;
  173. }
  174. CDialog::OnOK();
  175. // We don't set the g_reg.m_bIsDirty flag here because we want to see if the
  176. // user actually changed the current settings. This check is made in
  177. // CEventPropertiesDlg::EditEventProperties on a per-event basis.
  178. }
  179. void CEventPropertiesDlg::OnWithintime()
  180. {
  181. // The WithinTime checkbox was clicked.
  182. // Enable/disable the TimeInterval control.
  183. // Check to see if the count field has been edited. If it has been edited,
  184. // mark the field as being dirty.
  185. if (m_edtEventCount.IsDirty() || m_spinEventCount.IsDirty()) {
  186. m_bDidEditEventCount = TRUE;
  187. }
  188. int iEventCount;
  189. int iTemp;
  190. SCODE sc = m_edtEventCount.GetValue(iEventCount);
  191. if (FAILED(sc)) {
  192. m_spinEventCount.GetRange(iEventCount, iTemp);
  193. m_spinEventCount.SetPos(iEventCount);
  194. m_bDidEditEventCount = FALSE;
  195. }
  196. if (m_btnWithinTime.GetCheck() == 1) {
  197. m_edtTimeInterval.EnableWindow(TRUE);
  198. m_spinTimeInterval.EnableWindow(TRUE);
  199. if (iEventCount < 2) {
  200. // If the event count is less than two, it will flip to two when the spin button's
  201. // range is set. In this event, we make it appear as if the user never edited the
  202. // value so that it will flip back when the check box is unchecked.
  203. m_bDidEditEventCount = FALSE;
  204. m_bDidFlipEventCount = TRUE;
  205. m_edtEventCount.ClearDirty();
  206. m_spinEventCount.ClearDirty();
  207. m_spinEventCount.SetPos(2);
  208. }
  209. m_spinEventCount.SetRange(2, MAX_EVENT_COUNT);
  210. m_spinTimeInterval.SetRange(1, MAX_TIME_INTERVAL);
  211. }
  212. else {
  213. m_edtTimeInterval.EnableWindow(FALSE);
  214. m_spinTimeInterval.EnableWindow(FALSE);
  215. m_spinEventCount.SetRange(1, MAX_EVENT_COUNT);
  216. m_spinEventCount.SetPos(iEventCount);
  217. m_spinTimeInterval.SetRange(0, MAX_TIME_INTERVAL);
  218. m_spinTimeInterval.SetPos(0);
  219. // If the initial event count was one and we flipped it to two when the "within time"
  220. // button was clicked, then flip it back to one now if it was not edited.
  221. if (m_bDidFlipEventCount) {
  222. if (!m_bDidEditEventCount) {
  223. m_spinEventCount.SetPos(1);
  224. }
  225. m_bDidFlipEventCount = FALSE;
  226. }
  227. }
  228. m_spinTimeInterval.SetRedraw();
  229. }
  230. //***************************************************************************
  231. //
  232. // CEventPropertiesDlg::MakeLabelsBold
  233. //
  234. // This method makes the static labels bold to enhance the appearance of
  235. // the dialog.
  236. //
  237. // This method should be called after CDIalog::InitDialog.
  238. //
  239. // Parameters:
  240. // None.
  241. //
  242. // Returns:
  243. // Nothing.
  244. //
  245. // Status:
  246. // The MFC2.0 library makes the labels invisible when an attempt
  247. // is made to change the font of a static item. I've tried this with
  248. // MFC4.0 and it works.
  249. //
  250. //***************************************************************************
  251. void CEventPropertiesDlg::MakeLabelsBold()
  252. {
  253. #if 0
  254. CFont* pfontDefault;
  255. LOGFONT lf;
  256. // Get the LOGFONT for the default static item font and then
  257. // switch the logfont weight to bold.
  258. pfontDefault = m_statSource.GetFont();
  259. pfontDefault->GetObject(sizeof(lf), &lf);
  260. lf.lfWeight = FW_BOLD;
  261. // Create a bold font with all other characteristics the same as the
  262. // default font. Then switch all labels to a bold font.
  263. CFont fontNew;
  264. if (fontNew.CreateFontIndirect(&lf)) {
  265. m_statSource.SetFont(&fontNew, TRUE);
  266. m_statLog.SetFont(&fontNew, TRUE);
  267. m_statEventID.SetFont(&fontNew, TRUE);
  268. m_statEnterpriseOID.SetFont(&fontNew, TRUE);
  269. }
  270. #endif //0
  271. }
  272. //********************************************************************
  273. // CEventPropertiesDlg::EditEventProperties
  274. //
  275. // Edit the properties of a number of events.
  276. //
  277. // Parameters:
  278. // CEventArray& aEvents
  279. // An array of CEvent pointers. These are the events that
  280. // are to be edited.
  281. //
  282. // Returns:
  283. // BOOL
  284. // TRUE if the user clicked OK and the events were edited.
  285. // FALSE if the user clicked Cancel and the events were not
  286. // edited.
  287. //
  288. //******************************************************************
  289. BOOL CEventPropertiesDlg::EditEventProperties(CXEventArray& aEvents)
  290. {
  291. LONG nEvents = aEvents.GetSize();
  292. if (nEvents == 0) {
  293. return TRUE;
  294. }
  295. // The first event is taken as a representative of the other
  296. // events. Copy the appropriate data from this event to the
  297. // dialog.
  298. CString sText;
  299. CXEvent* pEvent = aEvents[0];
  300. CXEventSource* pEventSource = pEvent->m_pEventSource;
  301. CXEventLog* pEventLog = pEventSource->m_pEventLog;
  302. LONG iEvent;
  303. BOOL bMultipleSources = FALSE;
  304. BOOL bMultipleLogs = FALSE;
  305. for (iEvent=0; iEvent < nEvents; ++iEvent) {
  306. pEvent = aEvents[iEvent];
  307. if (pEvent->m_pEventSource != pEventSource) {
  308. bMultipleSources = TRUE;
  309. }
  310. if (pEvent->m_pEventSource->m_pEventLog != pEventLog) {
  311. bMultipleLogs = TRUE;
  312. }
  313. }
  314. if (bMultipleSources) {
  315. m_sSource.LoadString(IDS_MULTIPLE_SEL);
  316. m_sSourceOID.LoadString(IDS_MULTIPLE_SEL);
  317. }
  318. else {
  319. m_sSource = pEventSource->m_sName;
  320. pEventSource->GetEnterpriseOID(m_sSourceOID, TRUE);
  321. }
  322. if (bMultipleLogs) {
  323. m_sLog.LoadString(IDS_MULTIPLE_SEL);
  324. }
  325. else {
  326. m_sLog = pEventSource->m_pEventLog->m_sName;
  327. }
  328. // Copy the initial values.
  329. m_iTimeInterval = (int) pEvent->m_dwTimeInterval;
  330. m_iEventCount = pEvent->m_dwCount;
  331. m_bDidFlipEventCount = FALSE;
  332. // m_bWithinTime = (m_iTimeInterval != 0);
  333. if (nEvents > 1) {
  334. m_sEventId.LoadString(IDS_MULTIPLE_SEL);
  335. m_sDescription.LoadString(IDS_MULTIPLE_SEL);
  336. m_sFullEventID.LoadString(IDS_MULTIPLE_SEL);
  337. }
  338. else {
  339. pEvent->m_message.GetShortId(m_sEventId);
  340. m_sDescription = pEvent->m_message.m_sText;
  341. DecString(m_sFullEventID, pEvent->m_message.m_dwId);
  342. }
  343. // Put up the dialog and let the user edit the data.
  344. BOOL bDidCancel = (DoModal() == IDCANCEL);
  345. if (bDidCancel) {
  346. // The user canceled the dialog, so do nothing.
  347. return FALSE;
  348. }
  349. // Control comes here if the user clicked OK. Now we need to copy the
  350. // user's settings to each event that we are editing and mark the registry
  351. // as dirty if any of the settings changed.
  352. for (iEvent=0; iEvent < nEvents; ++iEvent) {
  353. pEvent = aEvents[iEvent];
  354. if (pEvent->m_dwTimeInterval != (DWORD) m_iTimeInterval) {
  355. g_reg.SetDirty(TRUE);
  356. pEvent->m_dwTimeInterval = (DWORD) m_iTimeInterval;
  357. }
  358. if (pEvent->m_dwCount != (DWORD) m_iEventCount) {
  359. g_reg.SetDirty(TRUE);
  360. pEvent->m_dwCount = m_iEventCount;
  361. }
  362. }
  363. return TRUE;
  364. }
  365. /////////////////////////////////////////////////////////////////////////////
  366. // CEditField
  367. CEditField::CEditField()
  368. {
  369. m_bIsDirty = FALSE;
  370. }
  371. CEditField::~CEditField()
  372. {
  373. }
  374. BEGIN_MESSAGE_MAP(CEditField, CEdit)
  375. //{{AFX_MSG_MAP(CEditField)
  376. ON_WM_CHAR()
  377. //}}AFX_MSG_MAP
  378. END_MESSAGE_MAP()
  379. /////////////////////////////////////////////////////////////////////////////
  380. // CEditField message handlers
  381. void CEditField::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  382. {
  383. // TODO: Add your message handler code here and/or call default
  384. CEdit::OnChar(nChar, nRepCnt, nFlags);
  385. m_bIsDirty = TRUE;
  386. }
  387. SCODE CEditField::GetValue(int& iValue)
  388. {
  389. CString sValue;
  390. GetWindowText(sValue);
  391. if (!IsDecimalInteger(sValue)) {
  392. return E_FAIL;
  393. }
  394. iValue = _ttoi(sValue);
  395. return S_OK;
  396. }
  397. /////////////////////////////////////////////////////////////////////////////
  398. // CEditSpin
  399. CEditSpin::CEditSpin()
  400. {
  401. m_bIsDirty = FALSE;
  402. m_iSetPos = 0;
  403. }
  404. CEditSpin::~CEditSpin()
  405. {
  406. }
  407. BEGIN_MESSAGE_MAP(CEditSpin, CSpinButtonCtrl)
  408. //{{AFX_MSG_MAP(CEditSpin)
  409. ON_WM_LBUTTONUP()
  410. //}}AFX_MSG_MAP
  411. END_MESSAGE_MAP()
  412. /////////////////////////////////////////////////////////////////////////////
  413. // CEditSpin message handlers
  414. void CEditSpin::OnLButtonUp(UINT nFlags, CPoint point)
  415. {
  416. // TODO: Add your message handler code here and/or call default
  417. CSpinButtonCtrl::OnLButtonUp(nFlags, point);
  418. if (GetPos() != m_iSetPos) {
  419. m_bIsDirty = TRUE;
  420. }
  421. }
  422. int CEditSpin::SetPos(int iPos)
  423. {
  424. int iResult = CSpinButtonCtrl::SetPos(iPos);
  425. m_iSetPos = GetPos();
  426. m_bIsDirty = FALSE;
  427. return iResult;
  428. }
  429. void CEditSpin::SetRange(int iLower, int iUpper)
  430. {
  431. int iPos = GetPos();
  432. CSpinButtonCtrl::SetRange(iLower, iUpper);
  433. if (iPos < iLower) {
  434. iPos = iLower;
  435. }
  436. if (iPos > iUpper) {
  437. iPos = iUpper;
  438. }
  439. SetPos(iPos);
  440. SetRedraw();
  441. m_iSetPos = iLower;
  442. m_bIsDirty = FALSE;
  443. }
  444. BOOL CEditSpin::IsDirty()
  445. {
  446. int iCurPos = GetPos();
  447. return (m_bIsDirty || (m_iSetPos != iCurPos));
  448. }
  449. BOOL CEventPropertiesDlg::OnHelpInfo(HELPINFO *pHelpInfo)
  450. {
  451. if (pHelpInfo->iContextType == HELPINFO_WINDOW &&
  452. pHelpInfo->iCtrlId != IDD_NULL)
  453. {
  454. ::WinHelp ((HWND)pHelpInfo->hItemHandle,
  455. AfxGetApp()->m_pszHelpFilePath,
  456. HELP_WM_HELP,
  457. (ULONG_PTR)g_aHelpIDs_IDD_PROPERTIESDLG);
  458. }
  459. return TRUE;
  460. }
  461. void CEventPropertiesDlg::OnContextMenu(CWnd* pWnd, CPoint point)
  462. {
  463. if (pWnd == this)
  464. return;
  465. ::WinHelp (pWnd->m_hWnd,
  466. AfxGetApp()->m_pszHelpFilePath,
  467. HELP_CONTEXTMENU,
  468. (ULONG_PTR)g_aHelpIDs_IDD_PROPERTIESDLG);
  469. }