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.

1145 lines
30 KiB

  1. //-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: A R P S D L G . C P P
  7. //
  8. // Contents: CArpsPage declaration
  9. //
  10. // Notes:
  11. //
  12. // Author: tongl 2 Feb 1998
  13. //
  14. //-----------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "arpsobj.h"
  18. #include "arpsdlg.h"
  19. #include "ncatlui.h"
  20. #include "ncstl.h"
  21. //#include "ncui.h"
  22. //#include "resource.h"
  23. #include "atmcommon.h"
  24. #include "atmhelp.h"
  25. //
  26. // CArpsPage
  27. //
  28. CArpsPage::CArpsPage(CArpsCfg * pArpscfg, const DWORD * adwHelpIDs)
  29. {
  30. Assert(pArpscfg);
  31. m_pArpscfg = pArpscfg;
  32. m_adwHelpIDs = adwHelpIDs;
  33. m_pAdapterInfo = pArpscfg->GetSecondMemoryAdapterInfo();
  34. m_fEditState = FALSE;
  35. m_fModified = FALSE;
  36. }
  37. CArpsPage::~CArpsPage()
  38. {
  39. }
  40. LRESULT CArpsPage::OnInitDialog(UINT uMsg, WPARAM wParam,
  41. LPARAM lParam, BOOL& fHandled)
  42. {
  43. RECT rect;
  44. LV_COLUMN lvCol = {0}; // list view column structure
  45. // initialize registered atm address list view
  46. ::GetClientRect(GetDlgItem(IDC_LVW_ARPS_REG_ADDR), &rect);
  47. lvCol.mask = LVCF_FMT | LVCF_WIDTH;
  48. lvCol.fmt = LVCFMT_LEFT;
  49. lvCol.cx = rect.right;
  50. ListView_InsertColumn(GetDlgItem(IDC_LVW_ARPS_REG_ADDR), 0, &lvCol);
  51. // initialize report view of multicast address list view
  52. int index, iNewItem;
  53. // Calculate column width
  54. ::GetClientRect(GetDlgItem(IDC_LVW_ARPS_MUL_ADDR), &rect);
  55. int colWidth = (rect.right/c_nColumns);
  56. // The mask specifies that the fmt, width and pszText members
  57. // of the structure are valid
  58. lvCol.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT ;
  59. lvCol.fmt = LVCFMT_LEFT; // left-align column
  60. lvCol.cx = colWidth; // width of column in pixels
  61. // Add the two columns and header text.
  62. for (index = 0; index < c_nColumns; index++)
  63. {
  64. // column header text
  65. if (0 == index) // first column
  66. {
  67. lvCol.pszText = (PWSTR) SzLoadIds(IDS_IPADDRESS_FROM);
  68. }
  69. else
  70. {
  71. lvCol.pszText = (PWSTR) SzLoadIds(IDS_IPADDRESS_TO);
  72. }
  73. iNewItem = ListView_InsertColumn(GetDlgItem(IDC_LVW_ARPS_MUL_ADDR),
  74. index, &lvCol);
  75. AssertSz((iNewItem == index), "Invalid item inserted to list view !");
  76. }
  77. m_hRegAddrs.m_hListView = GetDlgItem(IDC_LVW_ARPS_REG_ADDR);
  78. m_hRegAddrs.m_hAdd = GetDlgItem(IDC_PSH_ARPS_REG_ADD);
  79. m_hRegAddrs.m_hEdit = GetDlgItem(IDC_PSH_ARPS_REG_EDT);
  80. m_hRegAddrs.m_hRemove = GetDlgItem(IDC_PSH_ARPS_REG_RMV);
  81. m_hMulAddrs.m_hListView = GetDlgItem(IDC_LVW_ARPS_MUL_ADDR);
  82. m_hMulAddrs.m_hAdd = GetDlgItem(IDC_PSH_ARPS_MUL_ADD);
  83. m_hMulAddrs.m_hEdit = GetDlgItem(IDC_PSH_ARPS_MUL_EDT);
  84. m_hMulAddrs.m_hRemove = GetDlgItem(IDC_PSH_ARPS_MUL_RMV);
  85. // do this last
  86. SetRegisteredAtmAddrInfo();
  87. SetMulticastIpAddrInfo();
  88. return 0;
  89. }
  90. LRESULT CArpsPage::OnContextMenu(UINT uMsg, WPARAM wParam,
  91. LPARAM lParam, BOOL& fHandled)
  92. {
  93. ShowContextHelp(m_hWnd, HELP_CONTEXTMENU, m_adwHelpIDs);
  94. return 0;
  95. }
  96. LRESULT CArpsPage::OnHelp(UINT uMsg, WPARAM wParam,
  97. LPARAM lParam, BOOL& fHandled)
  98. {
  99. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  100. Assert(lphi);
  101. if (HELPINFO_WINDOW == lphi->iContextType)
  102. {
  103. ShowContextHelp(static_cast<HWND>(lphi->hItemHandle), HELP_WM_HELP,
  104. m_adwHelpIDs);
  105. }
  106. return 0;
  107. }
  108. LRESULT CArpsPage::OnActive(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  109. {
  110. return 0;
  111. }
  112. LRESULT CArpsPage::OnKillActive(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  113. {
  114. BOOL err = FALSE;
  115. // Update the in memory with what's in the UI
  116. UpdateInfo();
  117. // Check duplicate ATM address
  118. int iDupRegAddr = CheckDupRegAddr();
  119. if (iDupRegAddr >=0)
  120. {
  121. NcMsgBox(m_hWnd, IDS_MSFT_ARPS_TEXT, IDS_DUPLICATE_REG_ADDR,
  122. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  123. ListView_SetItemState(GetDlgItem(IDC_LVW_ARPS_REG_ADDR), iDupRegAddr,
  124. LVIS_SELECTED, LVIS_SELECTED);
  125. err = TRUE;
  126. }
  127. // Check overlapped IP address range
  128. if (!err)
  129. {
  130. int iOverlappedIpRange = CheckOverlappedIpRange();
  131. if (iOverlappedIpRange >=0)
  132. {
  133. NcMsgBox(m_hWnd, IDS_MSFT_ARPS_TEXT, IDS_OVERLAP_MUL_ADDR,
  134. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  135. ListView_SetItemState(GetDlgItem(IDC_LVW_ARPS_MUL_ADDR), iOverlappedIpRange,
  136. LVIS_SELECTED, LVIS_SELECTED);
  137. err = TRUE;
  138. }
  139. }
  140. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, err);
  141. return err;
  142. }
  143. LRESULT CArpsPage::OnItemChanged(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  144. {
  145. NM_LISTVIEW * pnmlv = reinterpret_cast<NM_LISTVIEW *>(pnmh);
  146. Assert(pnmlv);
  147. // Reset the buttons based on the changed selection
  148. if (idCtrl == IDC_LVW_ARPS_REG_ADDR)
  149. {
  150. SetButtons(m_hRegAddrs);
  151. }
  152. else if (idCtrl == IDC_LVW_ARPS_MUL_ADDR)
  153. {
  154. SetButtons(m_hMulAddrs);
  155. }
  156. return 0;
  157. }
  158. int CArpsPage::CheckDupRegAddr()
  159. {
  160. int ret = -1;
  161. int idx = 0;
  162. for(VECSTR::iterator iterAtmAddr = m_pAdapterInfo->m_vstrRegisteredAtmAddrs.begin();
  163. iterAtmAddr != m_pAdapterInfo->m_vstrRegisteredAtmAddrs.end();
  164. iterAtmAddr ++)
  165. {
  166. VECSTR::iterator iterAtmAddrComp = iterAtmAddr;
  167. iterAtmAddrComp ++;
  168. while (iterAtmAddrComp != m_pAdapterInfo->m_vstrRegisteredAtmAddrs.end())
  169. {
  170. if (**iterAtmAddr == **iterAtmAddrComp)
  171. {
  172. // we find a duplicate address
  173. ret = idx;
  174. break;
  175. }
  176. iterAtmAddrComp++;
  177. }
  178. // duplicate address found
  179. if (ret >=0 )
  180. {
  181. break;
  182. }
  183. // move next
  184. idx ++;
  185. }
  186. return ret;
  187. }
  188. int CArpsPage::CheckOverlappedIpRange()
  189. {
  190. int ret = -1;
  191. int idx = 0;
  192. for(VECSTR::iterator iterIpRange = m_pAdapterInfo->m_vstrMulticastIpAddrs.begin();
  193. iterIpRange != m_pAdapterInfo->m_vstrMulticastIpAddrs.end();
  194. iterIpRange ++)
  195. {
  196. tstring strUpperIp;
  197. GetUpperIp( **iterIpRange, &strUpperIp);
  198. VECSTR::iterator iterIpRangeComp = iterIpRange;
  199. iterIpRangeComp ++;
  200. while (iterIpRangeComp != m_pAdapterInfo->m_vstrMulticastIpAddrs.end())
  201. {
  202. tstring strLowerIpComp;
  203. GetLowerIp( **iterIpRangeComp, &strLowerIpComp);
  204. if (strUpperIp >= strLowerIpComp)
  205. {
  206. // we find an overlapped range
  207. ret = idx;
  208. break;
  209. }
  210. iterIpRangeComp++;
  211. }
  212. // duplicate address found
  213. if (ret >=0 )
  214. {
  215. break;
  216. }
  217. // move next
  218. idx ++;
  219. }
  220. return ret;
  221. }
  222. LRESULT CArpsPage::OnApply(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  223. {
  224. BOOL nResult = PSNRET_NOERROR;
  225. if (!IsModified())
  226. {
  227. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, nResult);
  228. return nResult;
  229. }
  230. m_pArpscfg->SetSecondMemoryModified();
  231. SetModifiedTo(FALSE); // this page is no longer modified
  232. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, nResult);
  233. return nResult;
  234. }
  235. LRESULT CArpsPage::OnCancel(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  236. {
  237. return 0;
  238. }
  239. LRESULT CArpsPage::OnAddRegisteredAddr(WORD wNotifyCode, WORD wID,
  240. HWND hWndCtl, BOOL& fHandled)
  241. {
  242. m_fEditState = FALSE;
  243. CAtmAddrDlg * pDlgAddr = new CAtmAddrDlg(this, g_aHelpIDs_IDD_ARPS_REG_ADDR);
  244. if (pDlgAddr == NULL)
  245. {
  246. return(ERROR_NOT_ENOUGH_MEMORY);
  247. }
  248. pDlgAddr->m_strNewAtmAddr = m_strRemovedAtmAddr;
  249. // See if the address is added
  250. if (pDlgAddr->DoModal() == IDOK)
  251. {
  252. int nCount = ListView_GetItemCount(GetDlgItem(IDC_LVW_ARPS_REG_ADDR));
  253. // insert the new item at the end of list
  254. LV_ITEM lvItem;
  255. lvItem.mask = LVIF_TEXT;
  256. lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  257. lvItem.state = 0;
  258. lvItem.iItem=nCount;
  259. lvItem.iSubItem=0;
  260. lvItem.pszText= (PWSTR)(m_strRemovedAtmAddr.c_str());
  261. int ret = ListView_InsertItem(GetDlgItem(IDC_LVW_ARPS_REG_ADDR), &lvItem);
  262. // empty strings, this removes the saved address from RemoveAtmAddr
  263. m_strRemovedAtmAddr = c_szEmpty;
  264. SetButtons(m_hRegAddrs);
  265. PageModified();
  266. }
  267. delete pDlgAddr;
  268. return 0;
  269. }
  270. LRESULT CArpsPage::OnEditRegisteredAddr(WORD wNotifyCode, WORD wID,
  271. HWND hWndCtl, BOOL& fHandled)
  272. {
  273. m_fEditState = TRUE;
  274. CAtmAddrDlg * pDlgAddr = new CAtmAddrDlg(this, g_aHelpIDs_IDD_ARPS_REG_ADDR);
  275. if (pDlgAddr == NULL)
  276. {
  277. return(ERROR_NOT_ENOUGH_MEMORY);
  278. }
  279. // get the user selection
  280. int itemSelected = ListView_GetNextItem(GetDlgItem(IDC_LVW_ARPS_REG_ADDR),
  281. -1, LVNI_SELECTED);
  282. if (itemSelected != -1)
  283. {
  284. WCHAR buf[MAX_ATM_ADDRESS_LENGTH+1];
  285. // save off the removed address
  286. LV_ITEM lvItem;
  287. lvItem.mask = LVIF_TEXT;
  288. lvItem.iItem = itemSelected;
  289. lvItem.iSubItem = 0;
  290. lvItem.pszText = buf;
  291. lvItem.cchTextMax = celems(buf);
  292. ListView_GetItem(GetDlgItem(IDC_LVW_ARPS_REG_ADDR), &lvItem);
  293. pDlgAddr->m_strNewAtmAddr = buf;
  294. // See if the address is edited & address changed
  295. if ((pDlgAddr->DoModal() == IDOK) && (m_strRemovedAtmAddr != buf))
  296. {
  297. // delete the old address
  298. ListView_DeleteItem(GetDlgItem(IDC_LVW_ARPS_REG_ADDR), itemSelected);
  299. // replace the item with the new address
  300. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  301. lvItem.lParam =0;
  302. lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  303. lvItem.state = 0;
  304. lvItem.iItem=itemSelected;
  305. lvItem.iSubItem=0;
  306. lvItem.pszText= (PWSTR)(m_strRemovedAtmAddr.c_str());
  307. ListView_InsertItem(GetDlgItem(IDC_LVW_ARPS_REG_ADDR), &lvItem);
  308. PageModified();
  309. }
  310. }
  311. else // no current selection
  312. {
  313. NcMsgBox(::GetActiveWindow(), IDS_MSFT_ARPS_TEXT, IDS_NO_ITEM_SELECTED,
  314. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  315. }
  316. // don't save this registered address
  317. m_strRemovedAtmAddr = c_szEmpty;
  318. delete pDlgAddr;
  319. return 0;
  320. }
  321. LRESULT CArpsPage::OnRemoveRegisteredAddr(WORD wNotifyCode, WORD wID,
  322. HWND hWndCtl, BOOL& fHandled)
  323. {
  324. // get the current selected item and remove it
  325. int itemSelected = ListView_GetNextItem(GetDlgItem(IDC_LVW_ARPS_REG_ADDR), -1,
  326. LVNI_SELECTED);
  327. if (itemSelected != -1)
  328. {
  329. WCHAR buf[MAX_ATM_ADDRESS_LENGTH+1];
  330. LV_ITEM lvItem;
  331. lvItem.mask = LVIF_TEXT;
  332. lvItem.pszText = buf;
  333. lvItem.cchTextMax = celems(buf);
  334. // save off the removed address and delete it from the listview
  335. lvItem.iItem = itemSelected;
  336. lvItem.iSubItem = 0;
  337. ListView_GetItem(GetDlgItem(IDC_LVW_ARPS_REG_ADDR), &lvItem);
  338. m_strRemovedAtmAddr = buf;
  339. ListView_DeleteItem(GetDlgItem(IDC_LVW_ARPS_REG_ADDR), itemSelected);
  340. SetButtons(m_hRegAddrs);
  341. PageModified();
  342. }
  343. else
  344. {
  345. NcMsgBox(::GetActiveWindow(), IDS_MSFT_ARPS_TEXT,
  346. IDS_NO_ITEM_SELECTED,
  347. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  348. }
  349. return 0;
  350. }
  351. LRESULT CArpsPage::OnAddMulticastAddr(WORD wNotifyCode, WORD wID,
  352. HWND hWndCtl, BOOL& fHandled)
  353. {
  354. m_fEditState = FALSE;
  355. CIpAddrRangeDlg * pDlgAddr = new CIpAddrRangeDlg(this, g_aHelpIDs_IDD_ARPS_MUL_ADDR);
  356. if (pDlgAddr == NULL)
  357. {
  358. return(ERROR_NOT_ENOUGH_MEMORY);
  359. }
  360. pDlgAddr->m_strNewIpRange = m_strRemovedIpRange;
  361. // See if the address is added
  362. if (pDlgAddr->DoModal() == IDOK)
  363. {
  364. LvInsertIpRangeInOrder(pDlgAddr->m_strNewIpRange);
  365. // empty strings, this removes the saved address from RemoveIP
  366. pDlgAddr->m_strNewIpRange = c_szEmpty;
  367. SetButtons(m_hMulAddrs);
  368. PageModified();
  369. }
  370. m_strRemovedIpRange = pDlgAddr->m_strNewIpRange;
  371. delete pDlgAddr;
  372. return 0;
  373. }
  374. LRESULT CArpsPage::OnEditMulticastAddr(WORD wNotifyCode, WORD wID,
  375. HWND hWndCtl, BOOL& fHandled)
  376. {
  377. m_fEditState = TRUE;
  378. CIpAddrRangeDlg * pDlgAddr = new CIpAddrRangeDlg(this, g_aHelpIDs_IDD_ARPS_MUL_ADDR);
  379. if (pDlgAddr == NULL)
  380. {
  381. return(ERROR_NOT_ENOUGH_MEMORY);
  382. }
  383. // get the user selection
  384. int itemSelected = ListView_GetNextItem(GetDlgItem(IDC_LVW_ARPS_MUL_ADDR),
  385. -1, LVNI_SELECTED);
  386. if (itemSelected != -1)
  387. {
  388. WCHAR szBuf[IPRANGE_LIMIT];
  389. // save off the removed address and delete it from the listview
  390. LV_ITEM lvItem;
  391. lvItem.mask = LVIF_TEXT;
  392. // lower ip
  393. lvItem.iItem = itemSelected;
  394. lvItem.iSubItem = 0;
  395. lvItem.pszText = szBuf;
  396. lvItem.cchTextMax = celems(szBuf);
  397. ListView_GetItem(GetDlgItem(IDC_LVW_ARPS_MUL_ADDR), &lvItem);
  398. pDlgAddr->m_strNewIpRange = szBuf;
  399. pDlgAddr->m_strNewIpRange += c_chSeparator;
  400. // upper ip
  401. lvItem.iItem = itemSelected;
  402. lvItem.iSubItem = 1;
  403. lvItem.pszText = szBuf;
  404. lvItem.cchTextMax = celems(szBuf);
  405. ListView_GetItem(GetDlgItem(IDC_LVW_ARPS_MUL_ADDR), &lvItem);
  406. pDlgAddr->m_strNewIpRange += szBuf;
  407. // See if the address is edited & address changed
  408. if ((pDlgAddr->DoModal() == IDOK) && (pDlgAddr->m_strNewIpRange != szBuf))
  409. {
  410. // delete the old address
  411. ListView_DeleteItem(GetDlgItem(IDC_LVW_ARPS_MUL_ADDR), itemSelected);
  412. // insert new one
  413. LvInsertIpRangeInOrder(pDlgAddr->m_strNewIpRange);
  414. // empty strings, this removes the saved address from RemoveIP
  415. pDlgAddr->m_strNewIpRange = c_szEmpty;
  416. PageModified();
  417. }
  418. }
  419. else // no current selection
  420. {
  421. NcMsgBox(::GetActiveWindow(), IDS_MSFT_ARPS_TEXT,
  422. IDS_NO_ITEM_SELECTED,
  423. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  424. }
  425. // don't save this IP range
  426. m_strRemovedIpRange = c_szEmpty;
  427. delete pDlgAddr;
  428. return 0;
  429. }
  430. void CArpsPage::LvInsertIpRangeInOrder(tstring& strNewIpRange)
  431. {
  432. tstring strLowerIp;
  433. GetLowerIp(strNewIpRange, &strLowerIp);
  434. int nCount = ListView_GetItemCount(GetDlgItem(IDC_LVW_ARPS_MUL_ADDR));
  435. // find the index to insert the new item
  436. LV_ITEM lvItem;
  437. lvItem.mask = LVIF_TEXT;
  438. WCHAR buf[IPRANGE_LIMIT];
  439. lvItem.pszText = buf;
  440. lvItem.cchTextMax = celems(buf);
  441. for (int iItem =0; iItem <nCount; iItem++)
  442. {
  443. lvItem.iItem = iItem;
  444. lvItem.iSubItem = 0;
  445. ListView_GetItem(GetDlgItem(IDC_LVW_ARPS_MUL_ADDR), &lvItem);
  446. Assert(buf);
  447. if (strLowerIp < buf)
  448. {
  449. break;
  450. }
  451. }
  452. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  453. lvItem.lParam =0;
  454. lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  455. lvItem.state = 0;
  456. // lower IP address
  457. lvItem.iItem=iItem;
  458. lvItem.iSubItem=0;
  459. lvItem.pszText= (PWSTR)(strLowerIp.c_str());
  460. SendDlgItemMessage(IDC_LVW_ARPS_MUL_ADDR, LVM_INSERTITEM, 0, (LPARAM)&lvItem);
  461. // upper IP address
  462. tstring strUpperIp;
  463. GetUpperIp(strNewIpRange, &strUpperIp);
  464. lvItem.iItem=iItem;
  465. lvItem.iSubItem=1;
  466. lvItem.pszText= (PWSTR)(strUpperIp.c_str());
  467. SendDlgItemMessage(IDC_LVW_ARPS_MUL_ADDR, LVM_SETITEMTEXT, iItem, (LPARAM)&lvItem);
  468. }
  469. LRESULT CArpsPage::OnRemoveMulticastAddr(WORD wNotifyCode, WORD wID,
  470. HWND hWndCtl, BOOL& fHandled)
  471. {
  472. // get the current selected item and remove it
  473. int itemSelected = ListView_GetNextItem(GetDlgItem(IDC_LVW_ARPS_MUL_ADDR), -1,
  474. LVNI_SELECTED);
  475. if (itemSelected != -1)
  476. {
  477. WCHAR szBuf[IPRANGE_LIMIT];
  478. LV_ITEM lvItem;
  479. lvItem.mask = LVIF_TEXT;
  480. lvItem.pszText = szBuf;
  481. lvItem.cchTextMax = celems(szBuf);
  482. // save off the removed address
  483. // lower ip
  484. lvItem.iItem = itemSelected;
  485. lvItem.iSubItem = 0;
  486. lvItem.cchTextMax = celems(szBuf);
  487. ListView_GetItem(GetDlgItem(IDC_LVW_ARPS_MUL_ADDR), &lvItem);
  488. m_strRemovedIpRange = szBuf;
  489. m_strRemovedIpRange += c_chSeparator;
  490. // upper ip
  491. lvItem.iItem = itemSelected;
  492. lvItem.iSubItem = 1;
  493. lvItem.pszText = szBuf;
  494. lvItem.cchTextMax = celems(szBuf);
  495. ListView_GetItem(GetDlgItem(IDC_LVW_ARPS_MUL_ADDR), &lvItem);
  496. m_strRemovedIpRange += szBuf;
  497. // delete it from the list view
  498. ListView_DeleteItem(GetDlgItem(IDC_LVW_ARPS_MUL_ADDR), itemSelected);
  499. SetButtons(m_hMulAddrs);
  500. PageModified();
  501. }
  502. else
  503. {
  504. NcMsgBox(::GetActiveWindow(), IDS_MSFT_ARPS_TEXT,
  505. IDS_NO_ITEM_SELECTED,
  506. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  507. }
  508. return 0;
  509. }
  510. void CArpsPage::SetRegisteredAtmAddrInfo()
  511. {
  512. BOOL ret = ListView_DeleteAllItems(GetDlgItem(IDC_LVW_ARPS_REG_ADDR));
  513. Assert(ret);
  514. LV_ITEM lvItem;
  515. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  516. lvItem.lParam =0;
  517. lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  518. lvItem.state = 0;
  519. int iItem =0;
  520. for (VECSTR::iterator iterAtmAddr = m_pAdapterInfo->m_vstrRegisteredAtmAddrs.begin();
  521. iterAtmAddr != m_pAdapterInfo->m_vstrRegisteredAtmAddrs.end();
  522. iterAtmAddr ++)
  523. {
  524. if ((**iterAtmAddr) == c_szEmpty)
  525. {
  526. continue;
  527. }
  528. lvItem.iItem=iItem;
  529. lvItem.iSubItem=0;
  530. lvItem.pszText=(PWSTR)((*iterAtmAddr)->c_str());
  531. lvItem.cchTextMax = celems((*iterAtmAddr)->c_str());
  532. int ret = ListView_InsertItem(GetDlgItem(IDC_LVW_ARPS_REG_ADDR), &lvItem);
  533. iItem++;
  534. }
  535. // now set the button states
  536. SetButtons(m_hRegAddrs);
  537. }
  538. void CArpsPage::SetMulticastIpAddrInfo()
  539. {
  540. BOOL ret = ListView_DeleteAllItems(GetDlgItem(IDC_LVW_ARPS_MUL_ADDR));
  541. Assert(ret);
  542. LV_ITEM lvItem;
  543. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  544. lvItem.lParam =0;
  545. lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  546. lvItem.state = 0;
  547. int iItem =0;
  548. tstring strIpLower;
  549. tstring strIpUpper;
  550. for (VECSTR::iterator iterIpAddrRange = m_pAdapterInfo->m_vstrMulticastIpAddrs.begin();
  551. iterIpAddrRange != m_pAdapterInfo->m_vstrMulticastIpAddrs.end();
  552. iterIpAddrRange ++)
  553. {
  554. if ((**iterIpAddrRange) == c_szEmpty)
  555. {
  556. continue;
  557. }
  558. GetLowerIp((**iterIpAddrRange), &strIpLower);
  559. GetUpperIp((**iterIpAddrRange), &strIpUpper);
  560. // Add the lower IP address
  561. lvItem.iItem=iItem;
  562. lvItem.iSubItem=0;
  563. lvItem.pszText=(PWSTR)(strIpLower.c_str());
  564. SendDlgItemMessage(IDC_LVW_ARPS_MUL_ADDR, LVM_INSERTITEM, iItem, (LPARAM)&lvItem);
  565. // Add the upper IP address
  566. lvItem.iItem=iItem;
  567. lvItem.iSubItem=1;
  568. lvItem.pszText=(PWSTR)(strIpUpper.c_str());
  569. // sub-item can not be inserted by ListView_InsertItem
  570. SendDlgItemMessage(IDC_LVW_ARPS_MUL_ADDR, LVM_SETITEMTEXT, iItem, (LPARAM)&lvItem);
  571. iItem++;
  572. }
  573. SetButtons(m_hMulAddrs);
  574. }
  575. void CArpsPage::SetButtons(HandleGroup& handles)
  576. {
  577. INT iSelected = ListView_GetNextItem(handles.m_hListView, -1, LVNI_SELECTED);
  578. if (iSelected == -1) // Nothing selected or list empty
  579. {
  580. ::EnableWindow(handles.m_hEdit, FALSE);
  581. ::EnableWindow(handles.m_hRemove, FALSE);
  582. ::SetFocus(handles.m_hListView);
  583. }
  584. else
  585. {
  586. ::EnableWindow(handles.m_hEdit, TRUE);
  587. ::EnableWindow(handles.m_hRemove, TRUE);
  588. }
  589. }
  590. void CArpsPage::UpdateInfo()
  591. {
  592. int i;
  593. // Update Registered ATM address
  594. FreeCollectionAndItem(m_pAdapterInfo->m_vstrRegisteredAtmAddrs);
  595. int nCount = ListView_GetItemCount(GetDlgItem(IDC_LVW_ARPS_REG_ADDR));
  596. WCHAR szAtmAddr[MAX_ATM_ADDRESS_LENGTH+1];
  597. LV_ITEM lvItem;
  598. lvItem.mask = LVIF_TEXT;
  599. for (i=0; i< nCount; i++)
  600. {
  601. lvItem.iItem = i;
  602. lvItem.iSubItem = 0;
  603. lvItem.pszText = szAtmAddr;
  604. lvItem.cchTextMax = celems(szAtmAddr);
  605. ListView_GetItem(GetDlgItem(IDC_LVW_ARPS_REG_ADDR), &lvItem);
  606. m_pAdapterInfo->m_vstrRegisteredAtmAddrs.push_back(new tstring(szAtmAddr));
  607. }
  608. // Update Multicast IP address
  609. FreeCollectionAndItem(m_pAdapterInfo->m_vstrMulticastIpAddrs);
  610. nCount = ListView_GetItemCount(GetDlgItem(IDC_LVW_ARPS_MUL_ADDR));
  611. WCHAR szBuf[IPRANGE_LIMIT];
  612. tstring strIpRange;
  613. for (i=0; i< nCount; i++)
  614. {
  615. LV_ITEM lvItem;
  616. lvItem.mask = LVIF_TEXT;
  617. // lower ip
  618. lvItem.iItem = i;
  619. lvItem.iSubItem = 0;
  620. lvItem.pszText = szBuf;
  621. lvItem.cchTextMax = celems(szBuf);
  622. ListView_GetItem(GetDlgItem(IDC_LVW_ARPS_MUL_ADDR), &lvItem);
  623. strIpRange = szBuf;
  624. strIpRange += c_chSeparator;
  625. // upper ip
  626. lvItem.iItem = i;
  627. lvItem.iSubItem = 1;
  628. lvItem.pszText = szBuf;
  629. lvItem.cchTextMax = celems(szBuf);
  630. ListView_GetItem(GetDlgItem(IDC_LVW_ARPS_MUL_ADDR), &lvItem);
  631. strIpRange += szBuf;
  632. m_pAdapterInfo->m_vstrMulticastIpAddrs.push_back(new tstring(strIpRange.c_str()));
  633. }
  634. }
  635. //
  636. // CAtmAddrDlg
  637. //
  638. CAtmAddrDlg::CAtmAddrDlg(CArpsPage * pAtmArpsPage, const DWORD* adwHelpIDs)
  639. {
  640. m_pParentDlg = pAtmArpsPage;
  641. m_adwHelpIDs = adwHelpIDs;
  642. m_hOkButton = 0;
  643. }
  644. LRESULT CAtmAddrDlg::OnInitDialog(UINT uMsg, WPARAM wParam,
  645. LPARAM lParam, BOOL& fHandled)
  646. {
  647. // change the "Ok" button to "Add" if we are not editing
  648. if (FALSE == m_pParentDlg->m_fEditState)
  649. {
  650. SetDlgItemText(IDOK, L"Add");
  651. }
  652. // Set the position of the pop up dialog to be right over the listbox
  653. // on parent dialog
  654. RECT rect;
  655. HWND hwndList = m_pParentDlg->m_hRegAddrs.m_hListView;
  656. Assert(hwndList);
  657. ::GetWindowRect(hwndList, &rect);
  658. SetWindowPos(NULL, rect.left, rect.top, 0,0,
  659. SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE);
  660. // Save handles to the "Ok" button and the edit box
  661. m_hOkButton = GetDlgItem(IDOK);
  662. m_hEditBox = GetDlgItem(IDC_EDT_ARPS_REG_Address);
  663. // ATM addresses have a 40 character limit + separaters
  664. ::SendMessage(m_hEditBox, EM_SETLIMITTEXT,
  665. MAX_ATM_ADDRESS_LENGTH + (MAX_ATM_ADDRESS_LENGTH / 2), 0);
  666. // add the address that was just removed
  667. if (m_strNewAtmAddr.size())
  668. {
  669. ::SetWindowText(m_hEditBox, m_strNewAtmAddr.c_str());
  670. ::SendMessage(m_hEditBox, EM_SETSEL, 0, -1);
  671. ::EnableWindow(m_hOkButton, TRUE);
  672. }
  673. else
  674. {
  675. ::EnableWindow(m_hOkButton, FALSE);
  676. }
  677. ::SetFocus(m_hEditBox);
  678. return 0;
  679. }
  680. LRESULT CAtmAddrDlg::OnContextMenu(UINT uMsg, WPARAM wParam,
  681. LPARAM lParam, BOOL& fHandled)
  682. {
  683. ShowContextHelp(m_hWnd, HELP_CONTEXTMENU, m_adwHelpIDs);
  684. return 0;
  685. }
  686. LRESULT CAtmAddrDlg::OnHelp(UINT uMsg, WPARAM wParam,
  687. LPARAM lParam, BOOL& fHandled)
  688. {
  689. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  690. Assert(lphi);
  691. if (HELPINFO_WINDOW == lphi->iContextType)
  692. {
  693. ShowContextHelp(static_cast<HWND>(lphi->hItemHandle), HELP_WM_HELP,
  694. m_adwHelpIDs);
  695. }
  696. return 0;
  697. }
  698. LRESULT CAtmAddrDlg::OnOk(WORD wNotifyCode, WORD wID,
  699. HWND hWndCtl, BOOL& fHandled)
  700. {
  701. WCHAR szAtmAddress[MAX_ATM_ADDRESS_LENGTH+1];
  702. // Get the current address from the control and
  703. // add them to the adapter if valid
  704. ::GetWindowText(m_hEditBox, szAtmAddress, MAX_ATM_ADDRESS_LENGTH+1);
  705. int i, nId;
  706. if (! FIsValidAtmAddress(szAtmAddress, &i, &nId))
  707. { // If invalid ATM address, we pop up a message box and set focus
  708. // back to the edit box
  709. // REVIEW(tongl): report first invalid character in mesg box
  710. NcMsgBox(m_hWnd, IDS_MSFT_ARPS_TEXT, IDS_INVALID_ATM_ADDRESS,
  711. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  712. ::SetFocus(GetDlgItem(IDC_EDT_ARPS_REG_Address));
  713. return 0;
  714. }
  715. if (m_pParentDlg->m_fEditState == FALSE) // Add new address
  716. {
  717. m_pParentDlg->m_strRemovedAtmAddr = szAtmAddress;
  718. }
  719. else // if edit, see if string is having a diferent value now
  720. {
  721. if (m_pParentDlg->m_strRemovedAtmAddr != szAtmAddress)
  722. {
  723. m_pParentDlg->m_strRemovedAtmAddr = szAtmAddress; // update save addresses
  724. }
  725. else
  726. {
  727. EndDialog(IDCANCEL);
  728. }
  729. }
  730. EndDialog(IDOK);
  731. return 0;
  732. }
  733. LRESULT CAtmAddrDlg::OnCancel(WORD wNotifyCode, WORD wID,
  734. HWND hWndCtl, BOOL& fHandled)
  735. {
  736. EndDialog(IDCANCEL);
  737. return 0;
  738. }
  739. LRESULT CAtmAddrDlg::OnChange(WORD wNotifyCode, WORD wID,
  740. HWND hWndCtl, BOOL& fHandled)
  741. {
  742. WCHAR buf[2];
  743. // Enable or disable the "Ok" button
  744. // based on whether the edit box is empty
  745. if (::GetWindowText(m_hEditBox, buf, celems(buf)) == 0)
  746. {
  747. ::EnableWindow(m_hOkButton, FALSE);
  748. }
  749. else
  750. {
  751. ::EnableWindow(m_hOkButton, TRUE);
  752. }
  753. return 0;
  754. }
  755. //
  756. // CIpAddrRangeDlg
  757. //
  758. CIpAddrRangeDlg::CIpAddrRangeDlg( CArpsPage * pAtmArpsPage, const DWORD* adwHelpIDs)
  759. {
  760. m_pParentDlg = pAtmArpsPage;
  761. m_hOkButton = 0;
  762. m_adwHelpIDs = adwHelpIDs;
  763. }
  764. LRESULT CIpAddrRangeDlg::OnInitDialog(UINT uMsg, WPARAM wParam,
  765. LPARAM lParam, BOOL& fHandled)
  766. {
  767. // change the ok button to add if we are not editing
  768. if (FALSE == m_pParentDlg->m_fEditState)
  769. {
  770. SetDlgItemText(IDOK, L"Add");
  771. }
  772. // Set the position of the pop up dialog to be right over the listbox
  773. // on parent dialog
  774. RECT rect;
  775. HWND hwndList = m_pParentDlg->m_hMulAddrs.m_hListView;
  776. Assert(hwndList);
  777. ::GetWindowRect(hwndList, &rect);
  778. SetWindowPos(NULL, rect.left, rect.top, 0,0,
  779. SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE);
  780. // Save handles to the "Ok" button and the edit box
  781. m_hOkButton = GetDlgItem(IDOK);
  782. // create ip controls
  783. m_ipLower.Create(m_hWnd,IDC_ARPS_MUL_LOWER_IP);
  784. m_ipUpper.Create(m_hWnd,IDC_ARPS_MUL_UPPER_IP);
  785. // add the address that was just removed
  786. if (m_strNewIpRange.size())
  787. {
  788. GetLowerIp(m_strNewIpRange, &m_strNewIpLower);
  789. GetUpperIp(m_strNewIpRange, &m_strNewIpUpper);
  790. Assert(m_strNewIpLower.size()>0);
  791. Assert(m_strNewIpUpper.size()>0);
  792. m_ipLower.SetAddress(m_strNewIpLower.c_str());
  793. m_ipUpper.SetAddress(m_strNewIpUpper.c_str());
  794. ::EnableWindow(m_hOkButton, TRUE);
  795. }
  796. else
  797. {
  798. m_strNewIpLower = c_szEmpty;
  799. m_strNewIpUpper = c_szEmpty;
  800. // the ip and subnet are blank, so there's nothing to save
  801. ::EnableWindow(m_hOkButton, FALSE);
  802. }
  803. return 0;
  804. }
  805. LRESULT CIpAddrRangeDlg::OnContextMenu(UINT uMsg, WPARAM wParam,
  806. LPARAM lParam, BOOL& fHandled)
  807. {
  808. ShowContextHelp(m_hWnd, HELP_CONTEXTMENU, m_adwHelpIDs);
  809. return 0;
  810. }
  811. LRESULT CIpAddrRangeDlg::OnHelp(UINT uMsg, WPARAM wParam,
  812. LPARAM lParam, BOOL& fHandled)
  813. {
  814. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  815. Assert(lphi);
  816. if (HELPINFO_WINDOW == lphi->iContextType)
  817. {
  818. ShowContextHelp(static_cast<HWND>(lphi->hItemHandle), HELP_WM_HELP,
  819. m_adwHelpIDs);
  820. }
  821. return 0;
  822. }
  823. LRESULT CIpAddrRangeDlg::OnOk(WORD wNotifyCode, WORD wID,
  824. HWND hWndCtl, BOOL& fHandled)
  825. {
  826. tstring strIpLower;
  827. tstring strIpUpper;
  828. // Get the current address from the control and add them to the adapter if valid
  829. m_ipLower.GetAddress(&strIpLower);
  830. m_ipUpper.GetAddress(&strIpUpper);
  831. if (!IsValidIpRange(strIpLower, strIpUpper))
  832. {
  833. NcMsgBox(::GetActiveWindow(),
  834. IDS_MSFT_ARPS_TEXT,
  835. IDS_INCORRECT_IPRANGE,
  836. MB_APPLMODAL | MB_ICONSTOP | MB_OK);
  837. ::SetFocus(m_ipLower);
  838. return 0;
  839. }
  840. if (m_pParentDlg->m_fEditState == FALSE) // when adding a new range
  841. {
  842. // Get the current address from the control and add them to the adapter if valid
  843. MakeIpRange(strIpLower, strIpUpper, &m_strNewIpRange);
  844. EndDialog(IDOK);
  845. }
  846. else // if editing an existing range
  847. {
  848. if ((strIpLower != m_strNewIpLower)||(strIpUpper != m_strNewIpUpper))
  849. {
  850. MakeIpRange(strIpLower, strIpUpper, &m_strNewIpRange);
  851. EndDialog(IDOK);
  852. }
  853. else
  854. {
  855. // no change
  856. EndDialog(IDCANCEL);
  857. }
  858. }
  859. EndDialog(IDOK);
  860. return 0;
  861. }
  862. LRESULT CIpAddrRangeDlg::OnCancel(WORD wNotifyCode, WORD wID,
  863. HWND hWndCtl, BOOL& fHandled)
  864. {
  865. EndDialog(IDCANCEL);
  866. return 0;
  867. }
  868. LRESULT CIpAddrRangeDlg::OnChangeLowerIp(WORD wNotifyCode, WORD wID,
  869. HWND hWndCtl, BOOL& fHandled)
  870. {
  871. switch(wNotifyCode)
  872. {
  873. case EN_CHANGE:
  874. if (m_ipLower.IsBlank() || m_ipUpper.IsBlank())
  875. {
  876. ::EnableWindow(m_hOkButton, FALSE);
  877. }
  878. else
  879. {
  880. ::EnableWindow(m_hOkButton, TRUE);
  881. }
  882. break;
  883. default:
  884. break;
  885. }
  886. return 0;
  887. }
  888. LRESULT CIpAddrRangeDlg::OnChangeUpperIp(WORD wNotifyCode, WORD wID,
  889. HWND hWndCtl, BOOL& fHandled)
  890. {
  891. switch(wNotifyCode)
  892. {
  893. case EN_CHANGE:
  894. if (m_ipLower.IsBlank() || m_ipUpper.IsBlank())
  895. {
  896. ::EnableWindow(m_hOkButton, FALSE);
  897. }
  898. else
  899. {
  900. ::EnableWindow(m_hOkButton, TRUE);
  901. }
  902. break;
  903. default:
  904. break;
  905. }
  906. return 0;
  907. }
  908. LRESULT CIpAddrRangeDlg::OnIpFieldChange(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  909. {
  910. return 0;
  911. }