2 * @file TestFilterDlg.cpp
4 * @brief Dialog for testing file filters
6 // ID line follows -- this is updated by SVN
10 #include "TestFilterDlg.h"
13 #include "UnicodeString.h"
14 #include "FileFilterMgr.h"
15 #include "DDXHelper.h"
20 static char THIS_FILE[] = __FILE__;
25 * @param [in] pParent Parent window.
26 * @param [in] pFileFilter File filter to test.
27 * @param [in] pFilterMgr File filter manager.
29 CTestFilterDlg::CTestFilterDlg(CWnd* pParent, FileFilter * pFileFilter, FileFilterMgr *pFilterMgr)
30 : CDialog(CTestFilterDlg::IDD, pParent)
31 , m_pFileFilter(pFileFilter)
32 , m_pFileFilterMgr(pFilterMgr)
36 void CTestFilterDlg::DoDataExchange(CDataExchange* pDX)
38 CDialog::DoDataExchange(pDX);
39 //{{AFX_DATA_MAP(CTestFilterDlg)
40 // NOTE: the ClassWizard will add DDX and DDV calls here
45 BEGIN_MESSAGE_MAP(CTestFilterDlg, CDialog)
46 //{{AFX_MSG_MAP(CTestFilterDlg)
47 ON_BN_CLICKED(IDC_TEST_BTN, OnTestBtn)
51 /////////////////////////////////////////////////////////////////////////////
52 // CTestFilterDlg message handlers
55 * @brief Initialize the dialog.
56 * @return FALSE always.
58 BOOL CTestFilterDlg::OnInitDialog()
60 theApp.TranslateDialog(m_hWnd);
61 CDialog::OnInitDialog();
63 GetDlgItem(IDC_TEST_TEXT)->SetFocus();
65 String name = m_pFileFilterMgr->GetFilterName(m_pFileFilter);
66 SetDlgItemText(IDC_HEADER_FILTER_NAME, name.c_str());
68 return FALSE; // return TRUE unless you set the focus to a control
69 // EXCEPTION: OCX Property Pages should return FALSE
72 /** @brief User pressed Text button. */
73 void CTestFilterDlg::OnTestBtn()
76 GetDlgItemText(IDC_TEST_TEXT, PopString(text));
78 bool passed = CheckText(text);
80 String result = (passed ? _T("passed") : _T("failed"));
81 text += _T(": ") + result;
86 /** @brief user pressed <enter> key. */
87 void CTestFilterDlg::OnOK()
89 CWnd *pWnd = GetFocus();
91 if (IDCANCEL == pWnd->GetDlgCtrlID())
102 * @brief Test text against filter.
103 * @param [in] text Text to test.
104 * @return true if text passes the filter, FALSE otherwise.
106 bool CTestFilterDlg::CheckText(String text) const
108 CButton * IsDirButton = (CButton *)GetDlgItem(IDC_IS_DIRECTORY);
109 bool isDir = (IsDirButton->GetCheck() == BST_CHECKED);
112 // Convert any forward slashes to canonical Windows-style backslashes
113 string_replace(text, _T("/"), _T("\\"));
114 return m_pFileFilterMgr->TestDirNameAgainstFilter(m_pFileFilter, text);
118 return m_pFileFilterMgr->TestFileNameAgainstFilter(m_pFileFilter, text);
123 * @brief Add text to end of edit control.
124 * @param [in] edit Edit contror into which the text is added.
125 * @param [in] text Text to add to edit control.
127 void AppendToEditBox(CEdit & edit, const String& text)
129 int len = edit.GetWindowTextLength();
130 edit.SetSel(len, len);
131 edit.ReplaceSel(text.c_str());
135 * @brief Add new result to end of result edit box.
136 * @param [in] result Result text to add.
138 void CTestFilterDlg::AppendResult(String result)
140 CEdit * edit = (CEdit *)GetDlgItem(IDC_RESULTS);
141 if (edit->GetWindowTextLength()>0)
142 result = _T("\r\n") + result;
143 AppendToEditBox(*edit, result);