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.

346 lines
8.6 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. edituser.h
  7. Edit user dialog implementation file
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "mdlsdlg.h"
  12. #include "SrchMFlt.h"
  13. #include "spdutil.h"
  14. #include "ncglobal.h" // network console global defines
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CSearchMMFilters dialog
  22. CSearchMMFilters::CSearchMMFilters(ISpdInfo * pSpdInfo)
  23. : CModelessDlg()
  24. {
  25. //{{AFX_DATA_INIT(CSearchMMFilters)
  26. // NOTE: the ClassWizard will add member initialization here
  27. //}}AFX_DATA_INIT
  28. m_spSpdInfo.Set(pSpdInfo);
  29. }
  30. void CSearchMMFilters::DoDataExchange(CDataExchange* pDX)
  31. {
  32. CBaseDialog::DoDataExchange(pDX);
  33. //{{AFX_DATA_MAP(CSearchMMFilters)
  34. DDX_Control(pDX, IDC_MM_SRCH_LIST, m_listResult);
  35. //}}AFX_DATA_MAP
  36. }
  37. BEGIN_MESSAGE_MAP(CSearchMMFilters, CBaseDialog)
  38. //{{AFX_MSG_MAP(CSearchMMFilters)
  39. ON_BN_CLICKED(IDC_MM_SEARCH, OnButtonSearch)
  40. ON_BN_CLICKED(IDC_MM_SRCH_SRC_ANY, OnSrcOptionClicked)
  41. ON_BN_CLICKED(IDC_MM_SRCH_SRC_SPEC, OnSrcOptionClicked)
  42. ON_BN_CLICKED(IDC_MM_SRCH_DEST_ANY, OnDestOptionClicked)
  43. ON_BN_CLICKED(IDC_MM_SRCH_DEST_SPEC, OnDestOptionClicked)
  44. //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46. //To manually create the IP control and disable mirroring if the parent dialog is mirrored
  47. //
  48. //Arguments:
  49. // uID [IN] the control that the new IP control should overwrite
  50. // uIDIpCtr [IN] the ID of the IP control to create
  51. //
  52. //Note: $REVIEW (nsun) this should be removed after the snapin is themed since IP controls
  53. // in comctl v6 will handle the mirroring by itself
  54. //
  55. HWND CSearchMMFilters::CreateIPControl(UINT uID, UINT uIDIpCtl)
  56. {
  57. HWND hwndIPControl = NULL;
  58. RECT rcClient; // client area of parent window
  59. CWnd* pWnd = GetDlgItem(uID);
  60. if (pWnd)
  61. {
  62. // get pos info from our template static and then make sure it is hidden
  63. pWnd->GetWindowRect(&rcClient);
  64. pWnd->ShowWindow (SW_HIDE);
  65. ScreenToClient (&rcClient);
  66. //$REVIEW WS_EX_NOINHERITLAYOUT is to fix the mirroring problem of IP control
  67. //See WinXP bug 261926. We should remove that we switch the comctl32 v6
  68. LONG lExStyles = 0;
  69. LONG lExStyles0 = 0;
  70. if (m_hWnd)
  71. {
  72. lExStyles0 = lExStyles = GetWindowLong(m_hWnd, GWL_EXSTYLE);
  73. if (lExStyles & WS_EX_LAYOUTRTL)
  74. {
  75. lExStyles |= WS_EX_NOINHERITLAYOUT;
  76. SetWindowLong(m_hWnd, GWL_EXSTYLE, lExStyles);
  77. }
  78. }
  79. // create the new edit control
  80. hwndIPControl = ::CreateWindowEx(WS_EX_NOINHERITLAYOUT, WC_IPADDRESS, NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER,
  81. rcClient.left,
  82. rcClient.top,
  83. rcClient.right - rcClient.left,
  84. rcClient.bottom - rcClient.top,
  85. GetSafeHwnd(),
  86. (HMENU) IntToPtr(uIDIpCtl),
  87. AfxGetInstanceHandle (), //g_hinst,
  88. NULL);
  89. if (lExStyles0 != lExStyles && m_hWnd)
  90. {
  91. SetWindowLong(m_hWnd, GWL_EXSTYLE, lExStyles0);
  92. }
  93. // move the control directly behind the pWnd in the Z order
  94. if (hwndIPControl)
  95. {
  96. ::SetWindowPos (hwndIPControl, pWnd->GetSafeHwnd(), 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  97. }
  98. }
  99. return hwndIPControl;
  100. }
  101. /////////////////////////////////////////////////////////////////////////////
  102. // CSearchMMFilters message handlers
  103. BOOL CSearchMMFilters::OnInitDialog()
  104. {
  105. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  106. HWND hIpCtrl = CreateIPControl(IDC_MM_SRCH_SRC_IP_TEXT, IDC_MM_SRCH_SRC_IP);
  107. m_ipSrc.Create(hIpCtrl);
  108. hIpCtrl = CreateIPControl(IDC_MM_SRCH_DEST_IP_TEXT, IDC_MM_SRCH_DEST_IP);
  109. m_ipDest.Create(hIpCtrl);
  110. m_ipSrc.SetFieldRange(0, 1, 223);
  111. m_ipDest.SetFieldRange(0, 1, 223);
  112. CBaseDialog::OnInitDialog();
  113. CString st;
  114. CheckDlgButton(IDC_MM_SRCH_SRC_ANY, BST_CHECKED);
  115. OnSrcOptionClicked();
  116. CheckDlgButton(IDC_MM_SRCH_DEST_ANY, BST_CHECKED);
  117. OnDestOptionClicked();
  118. CheckDlgButton(IDC_MM_SRCH_INBOUND, BST_CHECKED);
  119. CheckDlgButton(IDC_MM_SRCH_OUTBOUND, BST_CHECKED);
  120. CheckDlgButton(IDC_MM_SRCH_RADIO_BEST, BST_CHECKED);
  121. int nWidth;
  122. nWidth = m_listResult.GetStringWidth(_T("555.555.555.555 - "));
  123. st.LoadString(IDS_COL_FLTR_SRC);
  124. m_listResult.InsertColumn(0, st, LVCFMT_LEFT, nWidth);
  125. nWidth = m_listResult.GetStringWidth(_T("555.555.555.555 - "));
  126. st.LoadString(IDS_COL_FLTR_DEST);
  127. m_listResult.InsertColumn(1, st, LVCFMT_LEFT, nWidth);
  128. st.LoadString(IDS_FLTR_DIR_OUT);
  129. nWidth = m_listResult.GetStringWidth((LPCTSTR)st) + 20;
  130. st.LoadString(IDS_FILTER_PP_COL_DIRECTION);
  131. m_listResult.InsertColumn(2, st, LVCFMT_LEFT, nWidth);
  132. st.LoadString(IDS_FILTER_PP_COL_WEIGHT);
  133. nWidth = m_listResult.GetStringWidth((LPCTSTR)st) + 20;
  134. m_listResult.InsertColumn(3, st, LVCFMT_LEFT, nWidth);
  135. st.LoadString(IDS_FLTER_PP_COL_IKE_POL);
  136. nWidth = m_listResult.GetStringWidth((LPCTSTR)st) + 20;
  137. m_listResult.InsertColumn(4, st, LVCFMT_LEFT, nWidth);
  138. st.LoadString(IDS_FLTER_PP_COL_MM_AUTH);
  139. nWidth = m_listResult.GetStringWidth((LPCTSTR)st) + 20;
  140. m_listResult.InsertColumn(5, st, LVCFMT_LEFT, nWidth);
  141. return TRUE; // return TRUE unless you set the focus to a control
  142. // EXCEPTION: OCX Property Pages should return FALSE
  143. }
  144. void CSearchMMFilters::OnButtonSearch()
  145. {
  146. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  147. CMmFilterInfo fltr;
  148. CMmFilterInfoArray arrMatchFltrs;
  149. if (!LoadConditionInfoFromControls(&fltr))
  150. return;
  151. DWORD dwNum = 1000; //TODO BUGBUG, should change to 0 to mean search all matches
  152. if(IsDlgButtonChecked(IDC_MM_SRCH_RADIO_BEST))
  153. {
  154. dwNum = 1;
  155. }
  156. m_spSpdInfo->GetMatchMMFilters(&fltr, dwNum, &arrMatchFltrs);
  157. PopulateFilterListToControl(&arrMatchFltrs);
  158. FreeItemsAndEmptyArray(arrMatchFltrs);
  159. }
  160. BOOL CSearchMMFilters::LoadConditionInfoFromControls(CMmFilterInfo * pFltr)
  161. {
  162. CString st;
  163. if (IsDlgButtonChecked(IDC_MM_SRCH_SRC_ANY))
  164. {
  165. pFltr->m_SrcAddr.AddrType = IP_ADDR_SUBNET;
  166. pFltr->m_SrcAddr.uIpAddr = 0;
  167. pFltr->m_SrcAddr.uSubNetMask = 0;
  168. }
  169. else
  170. {
  171. USES_CONVERSION;
  172. pFltr->m_SrcAddr.AddrType = IP_ADDR_UNIQUE;
  173. m_ipSrc.GetAddress(st);
  174. pFltr->m_SrcAddr.uIpAddr = inet_addr(T2A((LPCTSTR)st));
  175. pFltr->m_SrcAddr.uSubNetMask = 0xFFFFFFFF;
  176. }
  177. if (IsDlgButtonChecked(IDC_MM_SRCH_DEST_ANY))
  178. {
  179. pFltr->m_DesAddr.AddrType = IP_ADDR_SUBNET;
  180. pFltr->m_DesAddr.uIpAddr = 0;
  181. pFltr->m_DesAddr.uSubNetMask = 0;
  182. }
  183. else
  184. {
  185. USES_CONVERSION;
  186. pFltr->m_DesAddr.AddrType = IP_ADDR_UNIQUE;
  187. m_ipDest.GetAddress(st);
  188. pFltr->m_DesAddr.uIpAddr = inet_addr(T2A((LPCTSTR)st));
  189. pFltr->m_DesAddr.uSubNetMask = 0xFFFFFFFF;
  190. }
  191. if (IsDlgButtonChecked(IDC_MM_SRCH_INBOUND))
  192. {
  193. //if both inbound and outbound are chosen, then
  194. //set the driection valude as 0
  195. if (IsDlgButtonChecked(IDC_MM_SRCH_OUTBOUND))
  196. {
  197. pFltr->m_dwDirection = 0;
  198. }
  199. else
  200. {
  201. pFltr->m_dwDirection = FILTER_DIRECTION_INBOUND;
  202. }
  203. }
  204. else if (IsDlgButtonChecked(IDC_MM_SRCH_OUTBOUND))
  205. {
  206. pFltr->m_dwDirection = FILTER_DIRECTION_OUTBOUND;
  207. }
  208. else
  209. {
  210. ::AfxMessageBox(IDS_ERR_NO_DIRECTION);
  211. return FALSE;
  212. }
  213. return TRUE;
  214. }
  215. void CSearchMMFilters::PopulateFilterListToControl(CMmFilterInfoArray * parrFltrs)
  216. {
  217. CString st;
  218. m_listResult.DeleteAllItems();
  219. int nRows = -1;
  220. for (int i = 0; i < parrFltrs->GetSize(); i++)
  221. {
  222. nRows++;
  223. nRows = m_listResult.InsertItem(nRows, _T(""));
  224. if (-1 != nRows)
  225. {
  226. AddressToString((*parrFltrs)[i]->m_SrcAddr, &st);
  227. m_listResult.SetItemText(nRows, 0, st);
  228. AddressToString((*parrFltrs)[i]->m_DesAddr, &st);
  229. m_listResult.SetItemText(nRows, 1, st);
  230. DirectionToString((*parrFltrs)[i]->m_dwDirection, &st);
  231. m_listResult.SetItemText(nRows, 2, st);
  232. st.Format(_T("%d"), (*parrFltrs)[i]->m_dwWeight);
  233. m_listResult.SetItemText(nRows, 3, st);
  234. m_listResult.SetItemText(nRows, 4, (*parrFltrs)[i]->m_stPolicyName);
  235. m_listResult.SetItemText(nRows, 5, (*parrFltrs)[i]->m_stAuthDescription);
  236. m_listResult.SetItemData(nRows, i);
  237. }
  238. }
  239. }
  240. void CSearchMMFilters::OnSrcOptionClicked()
  241. {
  242. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  243. BOOL fAny = IsDlgButtonChecked(IDC_MM_SRCH_SRC_ANY);
  244. if (fAny)
  245. {
  246. m_ipSrc.ClearAddress();
  247. }
  248. if (m_ipSrc.m_hIPaddr)
  249. {
  250. ::EnableWindow(m_ipSrc.m_hIPaddr, !fAny);
  251. }
  252. }
  253. void CSearchMMFilters::OnDestOptionClicked()
  254. {
  255. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  256. BOOL fAny = IsDlgButtonChecked(IDC_MM_SRCH_DEST_ANY);
  257. if (fAny)
  258. {
  259. m_ipDest.ClearAddress();
  260. }
  261. if (m_ipDest.m_hIPaddr)
  262. {
  263. ::EnableWindow(m_ipDest.m_hIPaddr, !fAny);
  264. }
  265. }
  266. void CSearchMMFilters::OnOK()
  267. {
  268. //Since this is a modelless dialog, need to call DestroyWindow
  269. DestroyWindow();
  270. }