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.

365 lines
10 KiB

  1. //-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: D L G O P T. C P P
  7. //
  8. // Contents: Implementation for CTcpOptionsPage
  9. //
  10. // Notes: CTcpOptionsPage is the Tcpip options page,
  11. // The other classes are pop-up dislogs for each option
  12. // on this page.
  13. //
  14. // Author: tongl 29 Nov 1997
  15. //-----------------------------------------------------------------------
  16. //
  17. // CTcpOptionsPage
  18. //
  19. #include "pch.h"
  20. #pragma hdrstop
  21. #include "tcpipobj.h"
  22. #include "ncstl.h"
  23. #include "resource.h"
  24. #include "tcpconst.h"
  25. #include "tcputil.h"
  26. #include "dlgopt.h"
  27. #include "dlgaddr.h"
  28. #include "tcphelp.h"
  29. //Whistler bug 123164, we remove the ipsec from the connection UI
  30. const int c_rgsLanOptions[] = { c_iIpFilter };
  31. //
  32. // CTcpOptionsPage
  33. //
  34. CTcpOptionsPage::CTcpOptionsPage(CTcpAddrPage * pTcpAddrPage,
  35. ADAPTER_INFO * pAdapterDlg,
  36. GLOBAL_INFO * pGlbDlg,
  37. const DWORD * adwHelpIDs)
  38. {
  39. Assert(pTcpAddrPage);
  40. Assert(pAdapterDlg);
  41. Assert(pGlbDlg);
  42. m_pParentDlg = pTcpAddrPage;
  43. m_pAdapterInfo = pAdapterDlg;
  44. m_pGlbInfo = pGlbDlg;
  45. m_adwHelpIDs = adwHelpIDs;
  46. m_fModified = FALSE;
  47. m_fPropDlgModified = FALSE;
  48. //IPSec is removed from connection UI
  49. //m_fIpsecPolicySet = FALSE;
  50. }
  51. CTcpOptionsPage::~CTcpOptionsPage()
  52. {
  53. }
  54. // message map functions
  55. LRESULT CTcpOptionsPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& fHandled)
  56. {
  57. // Initialize the list view
  58. HWND hwndList = GetDlgItem(IDC_LVW_OPTIONS);
  59. RECT rc;
  60. LV_COLUMN lvc = {0};
  61. ::GetClientRect(hwndList, &rc);
  62. lvc.mask = LVCF_FMT | LVCF_WIDTH;
  63. lvc.fmt = LVCFMT_LEFT;
  64. lvc.cx = rc.right - GetSystemMetrics(SM_CXVSCROLL);
  65. ListView_InsertColumn(GetDlgItem(IDC_LVW_OPTIONS), 0, &lvc);
  66. // Insert options and description text
  67. LV_ITEM lvi = {0};
  68. lvi.mask = LVIF_TEXT | LVIF_PARAM;
  69. int iMaxOptions = 0;
  70. const int * pOptions = NULL;
  71. // RAS connections don't have option tab at all
  72. ASSERT(!m_pAdapterInfo->m_fIsRasFakeAdapter);
  73. if (!m_pAdapterInfo->m_fIsRasFakeAdapter)
  74. {
  75. iMaxOptions = celems(c_rgsLanOptions);
  76. pOptions = c_rgsLanOptions;
  77. }
  78. for (int i = 0; i < iMaxOptions; i++)
  79. {
  80. lvi.iItem = i;
  81. OPTION_ITEM_DATA * pItemData = new OPTION_ITEM_DATA;
  82. if (NULL == pItemData)
  83. continue;
  84. ASSERT(pOptions);
  85. switch (pOptions[i])
  86. {
  87. case c_iIpFilter:
  88. pItemData->iOptionId = c_iIpFilter;
  89. pItemData->szName = (PWSTR) SzLoadIds(IDS_IP_FILTERING);
  90. pItemData->szDesc = (PWSTR) SzLoadIds(IDS_IP_FILTERING_DESC);
  91. break;
  92. default:
  93. AssertSz(FALSE, "Invalid option");
  94. }
  95. lvi.lParam = reinterpret_cast<LPARAM>(pItemData);
  96. lvi.pszText = pItemData->szName;
  97. INT ret;
  98. ret = ListView_InsertItem(hwndList, &lvi);
  99. }
  100. // set the top item as the current selection
  101. ListView_SetItemState(hwndList, 0, LVIS_SELECTED, LVIS_SELECTED);
  102. //this is a ras connection and a non-admin user, disable all the controls
  103. //for globl settings
  104. if (m_pAdapterInfo->m_fIsRasFakeAdapter && m_pParentDlg->m_fRasNotAdmin)
  105. {
  106. ::EnableWindow(GetDlgItem(IDC_OPT_PROPERTIES), FALSE);
  107. }
  108. return 0;
  109. }
  110. LRESULT CTcpOptionsPage::OnContextMenu(UINT uMsg, WPARAM wParam,
  111. LPARAM lParam, BOOL& fHandled)
  112. {
  113. ShowContextHelp(m_hWnd, HELP_CONTEXTMENU, m_adwHelpIDs);
  114. return 0;
  115. }
  116. LRESULT CTcpOptionsPage::OnHelp(UINT uMsg, WPARAM wParam,
  117. LPARAM lParam, BOOL& fHandled)
  118. {
  119. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  120. Assert(lphi);
  121. if (HELPINFO_WINDOW == lphi->iContextType)
  122. {
  123. ShowContextHelp(static_cast<HWND>(lphi->hItemHandle), HELP_WM_HELP,
  124. m_adwHelpIDs);
  125. }
  126. return 0;
  127. }
  128. // notify handlers for the property page
  129. LRESULT CTcpOptionsPage::OnApply(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  130. {
  131. BOOL nResult = PSNRET_NOERROR;
  132. if (!IsModified())
  133. {
  134. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, nResult);
  135. return nResult;
  136. }
  137. // pass the info back to its parent dialog
  138. m_pParentDlg->m_fPropShtOk = TRUE;
  139. if(!m_pParentDlg->m_fPropShtModified)
  140. m_pParentDlg->m_fPropShtModified = IsModified();
  141. //IPSec is removed from connection UI
  142. //if (!m_pParentDlg->m_fIpsecPolicySet)
  143. // m_pParentDlg->m_fIpsecPolicySet = m_fIpsecPolicySet;
  144. // reset status
  145. SetModifiedTo(FALSE); // this page is no longer modified
  146. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, nResult);
  147. return nResult;
  148. }
  149. LRESULT CTcpOptionsPage::OnKillActive(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  150. {
  151. return 0;
  152. }
  153. LRESULT CTcpOptionsPage::OnActive(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  154. {
  155. return 0;
  156. }
  157. LRESULT CTcpOptionsPage::OnCancel(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  158. {
  159. return 0;
  160. }
  161. LRESULT CTcpOptionsPage::OnQueryCancel(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  162. {
  163. return 0;
  164. }
  165. LRESULT CTcpOptionsPage::OnProperties(WORD wNotifyCode, WORD wID,
  166. HWND hWndCtl, BOOL& fHandled)
  167. {
  168. HWND hwndList = GetDlgItem(IDC_LVW_OPTIONS);
  169. Assert(hwndList);
  170. LvProperties(hwndList);
  171. return 0;
  172. }
  173. LRESULT CTcpOptionsPage::OnItemChanged(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  174. {
  175. NM_LISTVIEW * pnmlv = reinterpret_cast<NM_LISTVIEW *>(pnmh);
  176. HWND hwndList = GetDlgItem(IDC_LVW_OPTIONS);
  177. Assert(pnmlv);
  178. // Check if selection changed
  179. if ((pnmlv->uNewState & LVIS_SELECTED) &&
  180. (!(pnmlv->uOldState & LVIS_SELECTED)))
  181. {
  182. // enable Property button if valid and update description text
  183. INT iSelected = ListView_GetNextItem(hwndList, -1, LVNI_SELECTED);
  184. if (iSelected == -1) // Nothing selected or list empty
  185. {
  186. // if list is empty
  187. ::EnableWindow(GetDlgItem(IDC_OPT_PROPERTIES), FALSE);
  188. ::SetWindowText(GetDlgItem(IDC_OPT_DESC), c_szEmpty);
  189. }
  190. else
  191. {
  192. LV_ITEM lvItem;
  193. lvItem.mask = LVIF_PARAM;
  194. lvItem.iItem = iSelected;
  195. lvItem.iSubItem = 0;
  196. if (ListView_GetItem(hwndList, &lvItem))
  197. {
  198. OPTION_ITEM_DATA * pItemData = NULL;
  199. pItemData = reinterpret_cast<OPTION_ITEM_DATA *>(lvItem.lParam);
  200. if (pItemData)
  201. {
  202. //this is a ras connection and a non-admin user, Dont enable the
  203. // "properties" button
  204. if (!(m_pAdapterInfo->m_fIsRasFakeAdapter && m_pParentDlg->m_fRasNotAdmin))
  205. {
  206. ::EnableWindow(GetDlgItem(IDC_OPT_PROPERTIES), TRUE);
  207. }
  208. ::SetWindowText(GetDlgItem(IDC_OPT_DESC), (PCWSTR)pItemData->szDesc);
  209. }
  210. }
  211. }
  212. }
  213. return 0;
  214. }
  215. LRESULT CTcpOptionsPage::OnDbClick(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  216. {
  217. INT iItem;
  218. DWORD dwpts;
  219. RECT rc;
  220. LV_HITTESTINFO lvhti;
  221. //don't bring up the propeties of the selected option if the user is not admin
  222. if (m_pAdapterInfo->m_fIsRasFakeAdapter && m_pParentDlg->m_fRasNotAdmin)
  223. return 0;
  224. HWND hwndList = GetDlgItem(IDC_LVW_OPTIONS);
  225. // we have the location
  226. dwpts = GetMessagePos();
  227. // translate it relative to the listview
  228. ::GetWindowRect( hwndList, &rc );
  229. lvhti.pt.x = LOWORD( dwpts ) - rc.left;
  230. lvhti.pt.y = HIWORD( dwpts ) - rc.top;
  231. // get currently selected item
  232. iItem = ListView_HitTest( hwndList, &lvhti );
  233. // if valid selection
  234. if (-1 != iItem)
  235. {
  236. LvProperties(hwndList);
  237. }
  238. return 0;
  239. }
  240. void CTcpOptionsPage::LvProperties(HWND hwndList)
  241. {
  242. INT iSelected = ListView_GetNextItem(hwndList, -1, LVNI_SELECTED);
  243. if (iSelected != -1)
  244. {
  245. LV_ITEM lvItem = {0};
  246. lvItem.mask = LVIF_PARAM;
  247. lvItem.iItem = iSelected;
  248. if (ListView_GetItem(hwndList, &lvItem))
  249. {
  250. OPTION_ITEM_DATA * pItemData = NULL;
  251. pItemData = reinterpret_cast<OPTION_ITEM_DATA *>(lvItem.lParam);
  252. if (pItemData)
  253. {
  254. // bring up the proper dialog
  255. switch(pItemData->iOptionId)
  256. {
  257. case c_iIpFilter:
  258. {
  259. // make a copy of the global and adapter info & pass to the filter dialog
  260. GLOBAL_INFO glbInfo;
  261. glbInfo = *m_pGlbInfo;
  262. ADAPTER_INFO adapterInfo;
  263. adapterInfo = *m_pAdapterInfo;
  264. CFilterDialog * pDlgFilter = new CFilterDialog(this,
  265. &glbInfo,
  266. &adapterInfo,
  267. g_aHelpIDs_IDD_FILTER);
  268. if (NULL == pDlgFilter)
  269. return;
  270. if (pDlgFilter->DoModal() == IDOK)
  271. {
  272. if (m_fPropDlgModified)
  273. {
  274. // Something changed,
  275. // so copy the changes and mark the page as modified
  276. *m_pGlbInfo = glbInfo;
  277. *m_pAdapterInfo = adapterInfo;
  278. PageModified();
  279. m_fPropDlgModified = FALSE;
  280. }
  281. }
  282. delete pDlgFilter;
  283. }
  284. break;
  285. default:
  286. AssertSz(FALSE, "Invalid option");
  287. break;
  288. }
  289. }
  290. }
  291. }
  292. }