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.

412 lines
6.7 KiB

  1. /*++
  2. Copyright (c) 1994-1998 Microsoft Corporation
  3. Module Name :
  4. fltdlg.cpp
  5. Abstract:
  6. WWW Filters Property Dialog
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. --*/
  13. //
  14. // Include Files
  15. //
  16. #include "stdafx.h"
  17. #include "w3scfg.h"
  18. #include "fltdlg.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. CFilterDlg::CFilterDlg(
  25. IN OUT CIISFilter & flt,
  26. IN CIISFilterList * & pFilters,
  27. IN BOOL fLocal,
  28. IN CWnd * pParent OPTIONAL
  29. )
  30. /*++
  31. Routine Description:
  32. Filter properties dialog constructor
  33. Arguments:
  34. CIISFilter & flt : Filter being edited
  35. CFilters * & pFilters : List of filters that exist
  36. BOOL fLocal : TRUE on the local system
  37. CWnd * pParent OPTIONAL : Optional parent window
  38. Return Value:
  39. N/A
  40. --*/
  41. : CDialog(CFilterDlg::IDD, pParent),
  42. m_fLocal(fLocal),
  43. m_pFilters(pFilters),
  44. m_fEditMode(FALSE),
  45. m_flt(flt)
  46. {
  47. //{{AFX_DATA_INIT(CFilterDlg)
  48. m_strExecutable = m_flt.m_strExecutable;
  49. m_strFilterName = m_flt.m_strName;
  50. //}}AFX_DATA_INIT
  51. //
  52. // Map priority to string ID
  53. //
  54. m_strPriority.LoadString(IDS_HIGH + 3 - m_flt.m_nPriority);
  55. }
  56. void
  57. CFilterDlg::DoDataExchange(
  58. IN CDataExchange * pDX
  59. )
  60. /*++
  61. Routine Description:
  62. Initialise/Store control data
  63. Arguments:
  64. CDataExchange * pDX - DDX/DDV control structure
  65. Return Value:
  66. None
  67. --*/
  68. {
  69. CDialog::DoDataExchange(pDX);
  70. //{{AFX_DATA_MAP(CFilterDlg)
  71. DDX_Control(pDX, IDC_STATIC_PRIORITY_VALUE, m_static_Priority);
  72. DDX_Control(pDX, IDC_STATIC_PRIORITY, m_static_PriorityPrompt);
  73. DDX_Control(pDX, IDOK, m_button_Ok);
  74. DDX_Control(pDX, IDC_EDIT_FILTERNAME, m_edit_FilterName);
  75. DDX_Control(pDX, IDC_EDIT_EXECUTABLE, m_edit_Executable);
  76. DDX_Control(pDX, IDC_BUTTON_BROWSE, m_button_Browse);
  77. DDX_Text(pDX, IDC_EDIT_FILTERNAME, m_strFilterName);
  78. DDX_Text(pDX, IDC_STATIC_PRIORITY_VALUE, m_strPriority);
  79. //}}AFX_DATA_MAP
  80. DDX_Text(pDX, IDC_EDIT_EXECUTABLE, m_strExecutable);
  81. DDV_MaxChars(pDX, m_strExecutable, 255);
  82. if (pDX->m_bSaveAndValidate)
  83. {
  84. //
  85. // Validate executable
  86. //
  87. if (!::IsFullyQualifiedPath(m_strExecutable))
  88. {
  89. ::AfxMessageBox(IDS_ERR_BAD_PATH);
  90. pDX->Fail();
  91. }
  92. if (m_fLocal &&
  93. (::GetFileAttributes(m_strExecutable) & FILE_ATTRIBUTE_DIRECTORY))
  94. {
  95. ::AfxMessageBox(IDS_ERR_FILE_NOT_FOUND);
  96. pDX->Fail();
  97. }
  98. }
  99. }
  100. //
  101. // Message Map
  102. //
  103. BEGIN_MESSAGE_MAP(CFilterDlg, CDialog)
  104. //{{AFX_MSG_MAP(CFilterDlg)
  105. ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
  106. ON_EN_CHANGE(IDC_EDIT_EXECUTABLE, OnExecutableChanged)
  107. //}}AFX_MSG_MAP
  108. ON_EN_CHANGE(IDC_EDIT_FILTERNAME, OnItemChanged)
  109. END_MESSAGE_MAP()
  110. //
  111. // Message Handlers
  112. //
  113. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  114. BOOL
  115. CFilterDlg::OnInitDialog()
  116. /*++
  117. Routine Description:
  118. WM_INITDIALOG handler. Initialize the dialog.
  119. Arguments:
  120. None.
  121. Return Value:
  122. TRUE if no focus is to be set automatically, FALSE if the focus
  123. is already set.
  124. --*/
  125. {
  126. CDialog::OnInitDialog();
  127. //
  128. // Available on local connections only
  129. //
  130. m_button_Browse.EnableWindow(m_fLocal);
  131. if ((m_fEditMode = m_edit_FilterName.GetWindowTextLength() > 0))
  132. {
  133. m_edit_FilterName.SetReadOnly();
  134. }
  135. SetControlStates();
  136. return TRUE;
  137. }
  138. void
  139. CFilterDlg::OnButtonBrowse()
  140. /*++
  141. Routine Description:
  142. Browse button handler
  143. Arguments:
  144. None
  145. Return Value:
  146. None
  147. --*/
  148. {
  149. ASSERT(m_fLocal);
  150. CString strFilterMask((LPCTSTR)IDS_FILTER_MASK);
  151. //
  152. // CODEWORK: Derive a class from CFileDialog that allows
  153. // the setting of the initial path
  154. //
  155. //CString strPath;
  156. //m_edit_Executable.GetWindowText(strPath);
  157. CFileDialog dlgBrowse(
  158. TRUE,
  159. NULL,
  160. NULL,
  161. OFN_HIDEREADONLY,
  162. strFilterMask,
  163. this
  164. );
  165. if (dlgBrowse.DoModal() == IDOK)
  166. {
  167. m_edit_Executable.SetWindowText(dlgBrowse.GetPathName());
  168. }
  169. OnItemChanged();
  170. }
  171. void
  172. CFilterDlg::SetControlStates()
  173. /*++
  174. Routine Description:
  175. Set the states of the dialog control depending on its current
  176. values.
  177. Arguments:
  178. BOOL fAllowAnonymous : If TRUE, 'allow anonymous' is on.
  179. Return Value:
  180. None
  181. --*/
  182. {
  183. m_button_Ok.EnableWindow(
  184. m_edit_FilterName.GetWindowTextLength() > 0
  185. && m_edit_Executable.GetWindowTextLength() > 0);
  186. ActivateControl(m_static_PriorityPrompt, m_flt.m_nPriority != FLTR_PR_INVALID);
  187. ActivateControl(m_static_Priority, m_flt.m_nPriority != FLTR_PR_INVALID);
  188. }
  189. void
  190. CFilterDlg::OnItemChanged()
  191. /*++
  192. Routine Description:
  193. Register a change in control value on this page. Mark the page as dirty.
  194. All change messages map to this function
  195. Arguments:
  196. None
  197. Return Value:
  198. None
  199. --*/
  200. {
  201. SetControlStates();
  202. }
  203. void
  204. CFilterDlg::OnExecutableChanged()
  205. /*++
  206. Routine Description:
  207. Handle change in executable edit box. Remove priority as this
  208. is no longer valid
  209. Arguments:
  210. None
  211. Return Value:
  212. None
  213. --*/
  214. {
  215. //
  216. // Priority no longer makes sense.
  217. //
  218. m_flt.m_nPriority = FLTR_PR_INVALID;
  219. OnItemChanged();
  220. }
  221. BOOL
  222. CFilterDlg::FilterNameExists(
  223. IN LPCTSTR lpName
  224. )
  225. /*++
  226. Routine Description:
  227. Look for a given filter name in the list
  228. Arguments:
  229. LPCTSTR lpName : Filter name to look for
  230. Return Value:
  231. TRUE if the name already existed in the list
  232. --*/
  233. {
  234. m_pFilters->ResetEnumerator();
  235. while(m_pFilters->MoreFilters())
  236. {
  237. CIISFilter * pFilter = m_pFilters->GetNextFilter();
  238. ASSERT(pFilter != NULL);
  239. if (!pFilter->IsFlaggedForDeletion())
  240. {
  241. if (!pFilter->m_strName.CompareNoCase(lpName))
  242. {
  243. return TRUE;
  244. }
  245. }
  246. }
  247. return FALSE;
  248. }
  249. void
  250. CFilterDlg::OnOK()
  251. /*++
  252. Routine Description:
  253. OK button handler. Save data
  254. Arguments:
  255. None
  256. Return Value:
  257. None
  258. --*/
  259. {
  260. if (UpdateData(TRUE))
  261. {
  262. //
  263. // Make sure the filter name is unique
  264. //
  265. if (!m_fEditMode && FilterNameExists(m_strFilterName))
  266. {
  267. ::AfxMessageBox(IDS_ERR_DUP_FILTER);
  268. return;
  269. }
  270. m_flt.m_strExecutable = m_strExecutable;
  271. m_flt.m_strName = m_strFilterName;
  272. //
  273. // Anyway to load this from the DLL?
  274. //
  275. //m_flt.m_nPriority = FLTR_PR_MEDIUM;
  276. CDialog::OnOK();
  277. }
  278. //
  279. // Don't dismiss the dialog
  280. //
  281. }