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.

431 lines
7.2 KiB

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