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.

227 lines
5.3 KiB

  1. // evntfind.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "eventrap.h"
  5. #include "evntfind.h"
  6. #include "source.h"
  7. #include "globals.h"
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char BASED_CODE THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CEventFindDlg dialog
  14. CEventFindDlg::CEventFindDlg(CWnd* pParent)
  15. : CDialog(CEventFindDlg::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CEventFindDlg)
  18. m_sFindWhat = _T("");
  19. m_bMatchWholeWord = FALSE;
  20. m_bMatchCase = FALSE;
  21. //}}AFX_DATA_INIT
  22. m_pSource = NULL;
  23. m_bSearchInTree = TRUE;
  24. m_bMatchCase = FALSE;
  25. m_bMatchWholeWord = FALSE;
  26. m_iFoundWhere = I_FOUND_NOTHING;
  27. }
  28. CEventFindDlg::~CEventFindDlg()
  29. {
  30. m_pSource->m_pdlgFind = NULL;
  31. }
  32. BOOL CEventFindDlg::Create(CSource* pSource, UINT nIDTemplate, CWnd* pParentWnd)
  33. {
  34. m_pSource = pSource;
  35. return CDialog::Create(nIDTemplate, pParentWnd);
  36. }
  37. void CEventFindDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CEventFindDlg)
  41. DDX_Text(pDX, IDC_EDIT_FIND_WHAT, m_sFindWhat);
  42. DDX_Check(pDX, IDC_CHECK_MATCH_WHOLEWORD, m_bMatchWholeWord);
  43. DDX_Check(pDX, IDC_CHECK_MATCH_CASE, m_bMatchCase);
  44. //}}AFX_DATA_MAP
  45. }
  46. BEGIN_MESSAGE_MAP(CEventFindDlg, CDialog)
  47. //{{AFX_MSG_MAP(CEventFindDlg)
  48. ON_BN_CLICKED(IDC_CHECK_MATCH_WHOLEWORD, OnCheckMatchWholeword)
  49. ON_BN_CLICKED(IDC_CHECK_MATCH_CASE, OnCheckMatchCase)
  50. ON_EN_CHANGE(IDC_EDIT_FIND_WHAT, OnChangeEditFindWhat)
  51. ON_BN_CLICKED(IDC_RADIO_SEARCH_DESCRIPTIONS, OnRadioSearchDescriptions)
  52. ON_BN_CLICKED(IDC_RADIO_SEARCH_SOURCES, OnRadioSearchSources)
  53. ON_WM_HELPINFO()
  54. ON_WM_CONTEXTMENU()
  55. ON_BN_CLICKED(IDC_FIND_OK, OnOK)
  56. ON_BN_CLICKED(IDC_FIND_CANCEL, OnCancel)
  57. //}}AFX_MSG_MAP
  58. END_MESSAGE_MAP()
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CEventFindDlg message handlers
  61. void CEventFindDlg::OnCheckMatchWholeword()
  62. {
  63. CButton *pButton = (CButton*)GetDlgItem(IDC_CHECK_MATCH_WHOLEWORD);
  64. if (pButton != NULL)
  65. m_bMatchWholeWord = pButton->GetCheck() != 0;
  66. }
  67. void CEventFindDlg::OnCheckMatchCase()
  68. {
  69. CButton *pButton = (CButton*)GetDlgItem(IDC_CHECK_MATCH_CASE);
  70. if (pButton != NULL)
  71. m_bMatchCase = pButton->GetCheck() != 0;
  72. }
  73. void CEventFindDlg::OnCancel()
  74. {
  75. CDialog::OnCancel();
  76. delete this;
  77. }
  78. void CEventFindDlg::OnChangeEditFindWhat()
  79. {
  80. CWnd* pwndEdit = GetDlgItem(IDC_EDIT_FIND_WHAT);
  81. CButton* pbtnWholeWord = (CButton*) GetDlgItem(IDC_CHECK_MATCH_WHOLEWORD);
  82. CString sText;
  83. // Get the search string and check to see if it contains any spaces.
  84. pwndEdit->GetWindowText(sText);
  85. if (sText.Find(_T(' ')) ==-1) {
  86. // It does not contain a space. Enable the window.
  87. if (!pbtnWholeWord->IsWindowEnabled()) {
  88. pbtnWholeWord->EnableWindow();
  89. }
  90. }
  91. else {
  92. // The search string contained a space, disable the whole-word button
  93. // and uncheck it if necessary.
  94. if (pbtnWholeWord->IsWindowEnabled()) {
  95. if (pbtnWholeWord->GetCheck() == 1) {
  96. // The "whole word" button was checked, so uncheck it and
  97. // disable the button.
  98. pbtnWholeWord->SetCheck(0);
  99. }
  100. pbtnWholeWord->EnableWindow(FALSE);
  101. }
  102. }
  103. }
  104. BOOL CEventFindDlg::OnInitDialog()
  105. {
  106. CDialog::OnInitDialog();
  107. // TODO: Add extra initialization here
  108. int idButton = m_bSearchInTree ? IDC_RADIO_SEARCH_SOURCES : IDC_RADIO_SEARCH_DESCRIPTIONS;
  109. CButton *pButton = (CButton*)GetDlgItem(idButton);
  110. if (pButton != NULL)
  111. pButton->SetCheck(1);
  112. return TRUE; // return TRUE unless you set the focus to a control
  113. // EXCEPTION: OCX Property Pages should return FALSE
  114. }
  115. void CEventFindDlg::OnRadioSearchDescriptions()
  116. {
  117. m_bSearchInTree = FALSE;
  118. }
  119. void CEventFindDlg::OnRadioSearchSources()
  120. {
  121. m_bSearchInTree = TRUE;
  122. }
  123. BOOL CEventFindDlg::OnCommand(WPARAM wParam, LPARAM lParam)
  124. {
  125. // TODO: Add your specialized code here and/or call the base class
  126. return CDialog::OnCommand(wParam, lParam);
  127. }
  128. void CEventFindDlg::OnOK()
  129. {
  130. // Get the Find What text.
  131. CEdit* pEdit = (CEdit*) GetDlgItem(IDC_EDIT_FIND_WHAT);
  132. if (pEdit == NULL)
  133. return; // Can't do anything.
  134. // Empty Find What string; nothing to do.
  135. pEdit->GetWindowText(m_sFindWhat);
  136. if (m_sFindWhat.IsEmpty())
  137. return;
  138. pEdit->SetSel(0, -1);
  139. BOOL bFound = m_pSource->Find(m_bSearchInTree, m_sFindWhat, m_bMatchWholeWord, m_bMatchCase);
  140. SetFocus();
  141. // Put the focus on the parent window.
  142. if (bFound) {
  143. if (m_bSearchInTree) {
  144. m_iFoundWhere = I_FOUND_IN_TREE;
  145. }
  146. else {
  147. m_iFoundWhere = I_FOUND_IN_LIST;
  148. }
  149. }
  150. else {
  151. CString sMsg;
  152. sMsg.LoadString(IDS_MSG_TEXTNOTFOUND);
  153. MessageBox(sMsg, NULL, MB_OK | MB_ICONINFORMATION);
  154. }
  155. }
  156. FOUND_WHERE CEventFindDlg::Find(CSource* pSource)
  157. {
  158. m_pSource = pSource;
  159. DoModal();
  160. return m_iFoundWhere;
  161. }
  162. BOOL CEventFindDlg::OnHelpInfo(HELPINFO* pHelpInfo)
  163. {
  164. if (pHelpInfo->iContextType == HELPINFO_WINDOW)
  165. {
  166. ::WinHelp ((HWND)pHelpInfo->hItemHandle,
  167. AfxGetApp()->m_pszHelpFilePath,
  168. HELP_WM_HELP,
  169. (ULONG_PTR)g_aHelpIDs_IDD_EVENTFINDDLG);
  170. }
  171. return TRUE;
  172. }
  173. void CEventFindDlg::OnContextMenu(CWnd* pWnd, CPoint point)
  174. {
  175. if (this == pWnd)
  176. return;
  177. ::WinHelp (pWnd->m_hWnd,
  178. AfxGetApp()->m_pszHelpFilePath,
  179. HELP_CONTEXTMENU,
  180. (ULONG_PTR)g_aHelpIDs_IDD_EVENTFINDDLG);
  181. }