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.

866 lines
24 KiB

  1. //-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: D L G A T M . C P P
  7. //
  8. // Contents: CTcpArpcPage and CATMAddressDialog implementation
  9. //
  10. // Notes: The "ARP Client" page and dialog
  11. //
  12. // Author: tongl 1 July 1997 Created
  13. //
  14. //-----------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "tcpipobj.h"
  18. #include "ncatlui.h"
  19. #include "ncstl.h"
  20. #include "tcpconst.h"
  21. #include "tcpmacro.h"
  22. #include "tcputil.h"
  23. #include "tcphelp.h"
  24. #include "atmcommon.h"
  25. #include "dlgatm.h"
  26. #include "dlgaddr.h"
  27. /////////////////////////////////////////////////////////////////
  28. //
  29. // CAtmArpcPage
  30. //
  31. /////////////////////////////////////////////////////////////////
  32. // Message map functions
  33. LRESULT CAtmArpcPage::OnInitDialog(UINT uMsg, WPARAM wParam,
  34. LPARAM lParam, BOOL& fHandled)
  35. {
  36. m_hMTUEditBox = GetDlgItem(IDC_EDT_ATM_MaxTU);
  37. Assert(m_hMTUEditBox);
  38. // ARP Server
  39. m_hArps.m_hList = GetDlgItem(IDC_LBX_ATM_ArpsAddrs);
  40. m_hArps.m_hAdd = GetDlgItem(IDC_PSB_ATM_ArpsAdd);
  41. m_hArps.m_hEdit = GetDlgItem(IDC_PSB_ATM_ArpsEdt);
  42. m_hArps.m_hRemove = GetDlgItem(IDC_PSB_ATM_ArpsRmv);
  43. m_hArps.m_hUp = GetDlgItem(IDC_PSB_ATM_ArpsUp);
  44. m_hArps.m_hDown = GetDlgItem(IDC_PSB_ATM_ArpsDown);
  45. // MAR Server
  46. m_hMars.m_hList = GetDlgItem(IDC_LBX_ATM_MarsAddrs);
  47. m_hMars.m_hAdd = GetDlgItem(IDC_PSB_ATM_MarsAdd);
  48. m_hMars.m_hEdit = GetDlgItem(IDC_PSB_ATM_MarsEdt);
  49. m_hMars.m_hRemove = GetDlgItem(IDC_PSB_ATM_MarsRmv);
  50. m_hMars.m_hUp = GetDlgItem(IDC_PSB_ATM_MarsUp);
  51. m_hMars.m_hDown = GetDlgItem(IDC_PSB_ATM_MarsDown);
  52. // Set the up\down arrow icons
  53. SendDlgItemMessage(IDC_PSB_ATM_ArpsUp, BM_SETIMAGE, IMAGE_ICON,
  54. reinterpret_cast<LPARAM>(g_hiconUpArrow));
  55. SendDlgItemMessage(IDC_PSB_ATM_ArpsDown, BM_SETIMAGE, IMAGE_ICON,
  56. reinterpret_cast<LPARAM>(g_hiconDownArrow));
  57. SendDlgItemMessage(IDC_PSB_ATM_MarsUp, BM_SETIMAGE, IMAGE_ICON,
  58. reinterpret_cast<LPARAM>(g_hiconUpArrow));
  59. SendDlgItemMessage(IDC_PSB_ATM_MarsDown, BM_SETIMAGE, IMAGE_ICON,
  60. reinterpret_cast<LPARAM>(g_hiconDownArrow));
  61. // Set MTU edit box length
  62. ::SendMessage(m_hMTUEditBox, EM_SETLIMITTEXT, MAX_MTU_LENGTH, 0);
  63. return 0;
  64. }
  65. LRESULT CAtmArpcPage::OnContextMenu(UINT uMsg, WPARAM wParam,
  66. LPARAM lParam, BOOL& fHandled)
  67. {
  68. ShowContextHelp(m_hWnd, HELP_CONTEXTMENU, m_adwHelpIDs);
  69. return 0;
  70. }
  71. LRESULT CAtmArpcPage::OnHelp(UINT uMsg, WPARAM wParam,
  72. LPARAM lParam, BOOL& fHandled)
  73. {
  74. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  75. Assert(lphi);
  76. if (HELPINFO_WINDOW == lphi->iContextType)
  77. {
  78. ShowContextHelp(static_cast<HWND>(lphi->hItemHandle), HELP_WM_HELP,
  79. m_adwHelpIDs);
  80. }
  81. return 0;
  82. }
  83. // Notify handlers for the property page
  84. LRESULT CAtmArpcPage::OnActive(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  85. {
  86. SetInfo();
  87. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, 0);
  88. return 0;
  89. }
  90. LRESULT CAtmArpcPage::OnKillActive(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  91. {
  92. // All error values are loaded and then checked here
  93. // while all non-error values are checked in OnApply
  94. BOOL err = FALSE; // Allow page to lose active status
  95. // In non-PVC only mode, if either of the list boxes (ARPS or MARS)
  96. // is empty for any bound atm card, we can't leave the page.
  97. if (BST_UNCHECKED == IsDlgButtonChecked(IDC_CHK_ATM_PVCONLY))
  98. {
  99. int nArps = Tcp_ListBox_GetCount(m_hArps.m_hList);
  100. int nMars = Tcp_ListBox_GetCount(m_hMars.m_hList);
  101. if ((nArps==0) || (nMars ==0))
  102. {
  103. NcMsgBox(m_hWnd, IDS_MSFT_TCP_TEXT, IDS_INVALID_ATMSERVERLIST,
  104. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  105. err = TRUE;
  106. }
  107. }
  108. // MTU value
  109. WCHAR szData[MAX_MTU_LENGTH+1];
  110. szData[0]= 0;
  111. ::GetWindowText(GetDlgItem(IDC_EDT_ATM_MaxTU), szData, MAX_MTU_LENGTH+1);
  112. // check the range of the number
  113. PWSTR pStr;
  114. unsigned long num = wcstoul(szData, &pStr, 10);
  115. int nId = IDS_MTU_RANGE_WORD;
  116. if (num < MIN_MTU || num > MAX_MTU)
  117. {
  118. NcMsgBox(::GetActiveWindow(),
  119. IDS_MSFT_TCP_TEXT,
  120. nId,
  121. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  122. ::SetFocus(m_hMTUEditBox);
  123. err = TRUE;
  124. }
  125. if (!err)
  126. {
  127. UpdateInfo();
  128. }
  129. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, err);
  130. return err;
  131. }
  132. LRESULT CAtmArpcPage::OnApply(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  133. {
  134. BOOL nResult = PSNRET_NOERROR;
  135. if (!IsModified())
  136. {
  137. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, nResult);
  138. return nResult;
  139. }
  140. UpdateInfo();
  141. // pass the info back to its parent dialog
  142. m_pParentDlg->m_fPropShtOk = TRUE;
  143. if(!m_pParentDlg->m_fPropShtModified)
  144. m_pParentDlg->m_fPropShtModified = IsModified();
  145. // reset status
  146. SetModifiedTo(FALSE); // this page is no longer modified
  147. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, nResult);
  148. return nResult;
  149. }
  150. LRESULT CAtmArpcPage::OnCancel(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  151. {
  152. return 0;
  153. }
  154. LRESULT CAtmArpcPage::OnQueryCancel(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  155. {
  156. return 0;
  157. }
  158. // Control message handlers
  159. // PVC Only
  160. LRESULT CAtmArpcPage::OnPVCOnly(WORD wNotifyCode, WORD wID,
  161. HWND hWndCtl, BOOL& fHandled)
  162. {
  163. BOOL fChecked = (BST_CHECKED == IsDlgButtonChecked(IDC_CHK_ATM_PVCONLY));
  164. if (fChecked != m_pAdapterInfo->m_fPVCOnly)
  165. {
  166. PageModified();
  167. }
  168. EnableGroup(!fChecked);
  169. return 0;
  170. }
  171. // ARP server controls
  172. LRESULT CAtmArpcPage::OnArpServer(WORD wNotifyCode, WORD wID,
  173. HWND hWndCtl, BOOL& fHandled)
  174. {
  175. switch (wNotifyCode)
  176. {
  177. case LBN_SELCHANGE:
  178. SetButtons(m_hArps, NUM_ATMSERVER_LIMIT);
  179. break;
  180. default:
  181. break;
  182. }
  183. return 0;
  184. }
  185. LRESULT CAtmArpcPage::OnAddArps(WORD wNotifyCode, WORD wID,
  186. HWND hWndCtl, BOOL& fHandled)
  187. {
  188. m_hAddressList = m_hArps.m_hList;
  189. OnServerAdd(m_hArps, c_szArpServer);
  190. return 0;
  191. }
  192. LRESULT CAtmArpcPage::OnEditArps(WORD wNotifyCode, WORD wID,
  193. HWND hWndCtl, BOOL& fHandled)
  194. {
  195. m_hAddressList = m_hArps.m_hList;
  196. OnServerEdit(m_hArps, c_szArpServer);
  197. return 0;
  198. }
  199. LRESULT CAtmArpcPage::OnRemoveArps(WORD wNotifyCode, WORD wID,
  200. HWND hWndCtl, BOOL& fHandled)
  201. {
  202. BOOL fRemoveArps = TRUE;
  203. OnServerRemove(m_hArps, fRemoveArps);
  204. return 0;
  205. }
  206. LRESULT CAtmArpcPage::OnArpsUp(WORD wNotifyCode, WORD wID,
  207. HWND hWndCtl, BOOL& fHandled)
  208. {
  209. OnServerUp(m_hArps);
  210. return 0;
  211. }
  212. LRESULT CAtmArpcPage::OnArpsDown(WORD wNotifyCode, WORD wID,
  213. HWND hWndCtl, BOOL& fHandled)
  214. {
  215. OnServerDown(m_hArps);
  216. return 0;
  217. }
  218. // MAR server controls
  219. LRESULT CAtmArpcPage::OnMarServer(WORD wNotifyCode, WORD wID,
  220. HWND hWndCtl, BOOL& fHandled)
  221. {
  222. switch (wNotifyCode)
  223. {
  224. case LBN_SELCHANGE:
  225. SetButtons(m_hMars, NUM_ATMSERVER_LIMIT);
  226. break;
  227. default:
  228. break;
  229. }
  230. return 0;
  231. }
  232. LRESULT CAtmArpcPage::OnAddMars(WORD wNotifyCode, WORD wID,
  233. HWND hWndCtl, BOOL& fHandled)
  234. {
  235. m_hAddressList = m_hMars.m_hList;
  236. OnServerAdd(m_hMars, c_szMarServer);
  237. return 0;
  238. }
  239. LRESULT CAtmArpcPage::OnEditMars(WORD wNotifyCode, WORD wID,
  240. HWND hWndCtl, BOOL& fHandled)
  241. {
  242. m_hAddressList = m_hMars.m_hList;
  243. OnServerEdit(m_hMars, c_szMarServer);
  244. return 0;
  245. }
  246. LRESULT CAtmArpcPage::OnRemoveMars(WORD wNotifyCode, WORD wID,
  247. HWND hWndCtl, BOOL& fHandled)
  248. {
  249. BOOL fRemoveArps = FALSE;
  250. OnServerRemove(m_hMars, fRemoveArps);
  251. return 0;
  252. }
  253. LRESULT CAtmArpcPage::OnMarsUp(WORD wNotifyCode, WORD wID,
  254. HWND hWndCtl, BOOL& fHandled)
  255. {
  256. OnServerUp(m_hMars);
  257. return 0;
  258. }
  259. LRESULT CAtmArpcPage::OnMarsDown(WORD wNotifyCode, WORD wID,
  260. HWND hWndCtl, BOOL& fHandled)
  261. {
  262. OnServerDown(m_hMars);
  263. return 0;
  264. }
  265. LRESULT CAtmArpcPage::OnMaxTU(WORD wNotifyCode, WORD wID,
  266. HWND hWndCtl, BOOL& fHandled)
  267. {
  268. switch(wNotifyCode)
  269. {
  270. case EN_CHANGE:
  271. PageModified();
  272. break;
  273. }
  274. return 0;
  275. }
  276. //
  277. // Helper functions
  278. //
  279. // Update the server addresses and MTU of the deselected card
  280. void CAtmArpcPage::UpdateInfo()
  281. {
  282. // PVC Only
  283. m_pAdapterInfo->m_fPVCOnly =
  284. (BST_CHECKED == IsDlgButtonChecked(IDC_CHK_ATM_PVCONLY));
  285. // Update ARP server address
  286. FreeCollectionAndItem(m_pAdapterInfo->m_vstrARPServerList);
  287. int nCount = Tcp_ListBox_GetCount(m_hArps.m_hList);
  288. WCHAR szARPS[MAX_ATM_ADDRESS_LENGTH+1];
  289. for (int i=0; i< nCount; i++)
  290. {
  291. Tcp_ListBox_GetText(m_hArps.m_hList, i, szARPS);
  292. m_pAdapterInfo->m_vstrARPServerList.push_back(new tstring(szARPS));
  293. }
  294. // Update MAR server address
  295. FreeCollectionAndItem(m_pAdapterInfo->m_vstrMARServerList);
  296. nCount = Tcp_ListBox_GetCount(m_hMars.m_hList);
  297. WCHAR szMARS[MAX_ATM_ADDRESS_LENGTH+1];
  298. for (i=0; i< nCount; i++)
  299. {
  300. Tcp_ListBox_GetText(m_hMars.m_hList, i, szMARS);
  301. m_pAdapterInfo->m_vstrMARServerList.push_back(new tstring(szMARS));
  302. }
  303. // MTU
  304. WCHAR szMTU[MAX_MTU_LENGTH+1];
  305. GetDlgItemText(IDC_EDT_ATM_MaxTU, szMTU, MAX_MTU_LENGTH+1);
  306. m_pAdapterInfo->m_dwMTU = _wtoi(szMTU);
  307. }
  308. // Set the other controls according to the current adapter
  309. void CAtmArpcPage::SetInfo()
  310. {
  311. Assert(m_pAdapterInfo);
  312. if (m_pAdapterInfo != NULL)
  313. {
  314. Assert (m_pAdapterInfo->m_fIsAtmAdapter);
  315. if (m_pAdapterInfo->m_fIsAtmAdapter)
  316. {
  317. // ARP server IDC_LBX_ATM_ArpsAddrs
  318. int nResult;
  319. Tcp_ListBox_ResetContent(m_hArps.m_hList);
  320. for(VSTR_ITER iterARPServer = m_pAdapterInfo->m_vstrARPServerList.begin();
  321. iterARPServer != m_pAdapterInfo->m_vstrARPServerList.end() ;
  322. ++iterARPServer)
  323. {
  324. nResult = Tcp_ListBox_InsertString(m_hArps.m_hList, -1,
  325. (*iterARPServer)->c_str());
  326. }
  327. // set slection to first item
  328. if (nResult >= 0)
  329. Tcp_ListBox_SetCurSel(m_hArps.m_hList, 0);
  330. // MAR server IDC_LBX_ATM_MarsAddrs
  331. Tcp_ListBox_ResetContent(m_hMars.m_hList);
  332. for(VSTR_ITER iterMARServer = m_pAdapterInfo->m_vstrMARServerList.begin();
  333. iterMARServer != m_pAdapterInfo->m_vstrMARServerList.end() ;
  334. ++iterMARServer)
  335. {
  336. nResult = Tcp_ListBox_InsertString(m_hMars.m_hList, -1,
  337. (*iterMARServer)->c_str());
  338. }
  339. // set slection to first item
  340. if (nResult >= 0)
  341. Tcp_ListBox_SetCurSel(m_hMars.m_hList, 0);
  342. // MTU
  343. WCHAR szBuf[MAX_MTU_LENGTH];
  344. wsprintfW(szBuf, c_szItoa, m_pAdapterInfo->m_dwMTU);
  345. SetDlgItemText(IDC_EDT_ATM_MaxTU, szBuf);
  346. // Set push buttons state
  347. SetButtons(m_hArps, NUM_ATMSERVER_LIMIT);
  348. SetButtons(m_hMars, NUM_ATMSERVER_LIMIT);
  349. // Set PVC Only check box
  350. CheckDlgButton(IDC_CHK_ATM_PVCONLY, m_pAdapterInfo->m_fPVCOnly);
  351. if(m_pAdapterInfo->m_fPVCOnly)
  352. {
  353. EnableGroup(FALSE);
  354. }
  355. }
  356. }
  357. return;
  358. }
  359. void CAtmArpcPage::EnableGroup(BOOL fEnable)
  360. {
  361. ::EnableWindow(GetDlgItem(IDC_LBX_ATM_ArpsAddrs), fEnable);
  362. ::EnableWindow(GetDlgItem(IDC_PSB_ATM_ArpsAdd), fEnable);
  363. ::EnableWindow(GetDlgItem(IDC_PSB_ATM_ArpsEdt), fEnable);
  364. ::EnableWindow(GetDlgItem(IDC_PSB_ATM_ArpsRmv), fEnable);
  365. ::EnableWindow(GetDlgItem(IDC_PSB_ATM_ArpsUp), fEnable);
  366. ::EnableWindow(GetDlgItem(IDC_PSB_ATM_ArpsDown), fEnable);
  367. ::EnableWindow(GetDlgItem(IDC_LBX_ATM_MarsAddrs), fEnable);
  368. ::EnableWindow(GetDlgItem(IDC_PSB_ATM_MarsAdd), fEnable);
  369. ::EnableWindow(GetDlgItem(IDC_PSB_ATM_MarsEdt), fEnable);
  370. ::EnableWindow(GetDlgItem(IDC_PSB_ATM_MarsRmv), fEnable);
  371. ::EnableWindow(GetDlgItem(IDC_PSB_ATM_MarsUp), fEnable);
  372. ::EnableWindow(GetDlgItem(IDC_PSB_ATM_MarsDown), fEnable);
  373. if (fEnable)
  374. {
  375. // Set push buttons state
  376. SetButtons(m_hArps, NUM_ATMSERVER_LIMIT);
  377. SetButtons(m_hMars, NUM_ATMSERVER_LIMIT);
  378. }
  379. }
  380. void CAtmArpcPage::OnServerAdd(HANDLES hGroup, PCTSTR pszTitle)
  381. {
  382. m_fEditState = FALSE;
  383. CAtmAddressDialog * pDlgSrv = new CAtmAddressDialog(this, g_aHelpIDs_IDD_ATM_ADDR);
  384. pDlgSrv->SetTitle(pszTitle);
  385. if (pDlgSrv->DoModal() == IDOK)
  386. {
  387. tstring strNewAddress;
  388. if (!lstrcmpW(pszTitle, c_szArpServer))
  389. {
  390. strNewAddress = m_strNewArpsAddress;
  391. // empty strings, this removes the saved address
  392. m_strNewArpsAddress = c_szEmpty;
  393. }
  394. else
  395. {
  396. Assert(!lstrcmpW(pszTitle, c_szMarServer));
  397. strNewAddress = m_strNewMarsAddress;
  398. // empty strings, this removes the saved address
  399. m_strNewMarsAddress = c_szEmpty;
  400. }
  401. int idx = Tcp_ListBox_InsertString(hGroup.m_hList,
  402. -1,
  403. strNewAddress.c_str());
  404. PageModified();
  405. Assert(idx >= 0);
  406. if (idx >= 0)
  407. {
  408. Tcp_ListBox_SetCurSel(hGroup.m_hList, idx);
  409. SetButtons(hGroup, NUM_ATMSERVER_LIMIT);
  410. }
  411. }
  412. // release dialog object
  413. delete pDlgSrv;
  414. }
  415. void CAtmArpcPage::OnServerEdit(HANDLES hGroup, PCWSTR pszTitle)
  416. {
  417. m_fEditState = TRUE;
  418. Assert(Tcp_ListBox_GetCount(hGroup.m_hList));
  419. int idx = Tcp_ListBox_GetCurSel(hGroup.m_hList);
  420. Assert(idx >= 0);
  421. // save off the removed address and delete it from the listview
  422. if (idx >= 0)
  423. {
  424. WCHAR buf[MAX_ATM_ADDRESS_LENGTH+1];
  425. Assert(Tcp_ListBox_GetTextLen(hGroup.m_hList, idx) <= celems(buf));
  426. Tcp_ListBox_GetText(hGroup.m_hList, idx, buf);
  427. BOOL fEditArps = !lstrcmpW(pszTitle, c_szArpServer);
  428. // used by dialog to display what to edit
  429. if (fEditArps)
  430. {
  431. m_strNewArpsAddress = buf;
  432. }
  433. else
  434. {
  435. m_strNewMarsAddress = buf;
  436. }
  437. CAtmAddressDialog * pDlgSrv = new CAtmAddressDialog(this, g_aHelpIDs_IDD_ATM_ADDR);
  438. pDlgSrv->SetTitle(pszTitle);
  439. if (pDlgSrv->DoModal() == IDOK)
  440. {
  441. // replace the item in the listview with the new information
  442. Tcp_ListBox_DeleteString(hGroup.m_hList, idx);
  443. PageModified();
  444. if (fEditArps)
  445. {
  446. m_strMovingEntry = m_strNewArpsAddress;
  447. // restore the original removed address
  448. m_strNewArpsAddress = buf;
  449. }
  450. else
  451. {
  452. m_strMovingEntry = m_strNewMarsAddress;
  453. // restore the original removed address
  454. m_strNewMarsAddress = buf;
  455. }
  456. ListBoxInsertAfter(hGroup.m_hList, idx, m_strMovingEntry.c_str());
  457. Tcp_ListBox_SetCurSel(hGroup.m_hList, idx);
  458. }
  459. else
  460. {
  461. // empty strings, this removes the saved address
  462. if (fEditArps)
  463. {
  464. m_strNewArpsAddress = c_szEmpty;
  465. }
  466. else
  467. {
  468. m_strNewMarsAddress = c_szEmpty;
  469. }
  470. }
  471. delete pDlgSrv;
  472. }
  473. }
  474. void CAtmArpcPage::OnServerRemove(HANDLES hGroup, BOOL fRemoveArps)
  475. {
  476. int idx = Tcp_ListBox_GetCurSel(hGroup.m_hList);
  477. Assert(idx >=0);
  478. if (idx >=0)
  479. {
  480. WCHAR buf[MAX_ATM_ADDRESS_LENGTH+1];
  481. Assert(Tcp_ListBox_GetTextLen(hGroup.m_hList, idx) <= celems(buf));
  482. Tcp_ListBox_GetText(hGroup.m_hList, idx, buf);
  483. if (fRemoveArps)
  484. {
  485. m_strNewArpsAddress = buf;
  486. }
  487. else
  488. {
  489. m_strNewMarsAddress = buf;
  490. }
  491. Tcp_ListBox_DeleteString(hGroup.m_hList, idx);
  492. PageModified();
  493. // select a new item
  494. int nCount;
  495. if ((nCount = Tcp_ListBox_GetCount(hGroup.m_hList)) != LB_ERR)
  496. {
  497. // select the previous item in the list
  498. if (idx)
  499. --idx;
  500. Tcp_ListBox_SetCurSel(hGroup.m_hList, idx);
  501. }
  502. SetButtons(hGroup, NUM_ATMSERVER_LIMIT);
  503. }
  504. }
  505. void CAtmArpcPage::OnServerUp(HANDLES hGroup)
  506. {
  507. Assert(m_hArps.m_hList);
  508. int nCount = Tcp_ListBox_GetCount(hGroup.m_hList);
  509. Assert(nCount);
  510. int idx = Tcp_ListBox_GetCurSel(hGroup.m_hList);
  511. Assert(idx != 0);
  512. if (ListBoxRemoveAt(hGroup.m_hList, idx, &m_strMovingEntry) == FALSE)
  513. {
  514. Assert(FALSE);
  515. return;
  516. }
  517. --idx;
  518. PageModified();
  519. ListBoxInsertAfter(hGroup.m_hList, idx, m_strMovingEntry.c_str());
  520. Tcp_ListBox_SetCurSel(hGroup.m_hList, idx);
  521. SetButtons(hGroup, NUM_ATMSERVER_LIMIT);
  522. }
  523. void CAtmArpcPage::OnServerDown(HANDLES hGroup)
  524. {
  525. Assert(hGroup.m_hList);
  526. int nCount = Tcp_ListBox_GetCount(hGroup.m_hList);
  527. Assert(nCount);
  528. int idx = Tcp_ListBox_GetCurSel(hGroup.m_hList);
  529. --nCount;
  530. Assert(idx != nCount);
  531. if (ListBoxRemoveAt(hGroup.m_hList, idx, &m_strMovingEntry) == FALSE)
  532. {
  533. Assert(FALSE);
  534. return;
  535. }
  536. ++idx;
  537. PageModified();
  538. ListBoxInsertAfter(hGroup.m_hList, idx, m_strMovingEntry.c_str());
  539. Tcp_ListBox_SetCurSel(hGroup.m_hList, idx);
  540. SetButtons(hGroup, NUM_ATMSERVER_LIMIT);
  541. }
  542. /////////////////////////////////////////////////////////////////
  543. //
  544. // CAtmAddressDialog
  545. //
  546. /////////////////////////////////////////////////////////////////
  547. CAtmAddressDialog::CAtmAddressDialog(CAtmArpcPage * pAtmArpcPage, const DWORD* adwHelpIDs)
  548. {
  549. m_pParentDlg = pAtmArpcPage;
  550. m_adwHelpIDs = adwHelpIDs;
  551. m_hOkButton = 0;
  552. };
  553. CAtmAddressDialog::~CAtmAddressDialog(){};
  554. LRESULT CAtmAddressDialog::OnInitDialog(UINT uMsg, WPARAM wParam,
  555. LPARAM lParam, BOOL& fHandled)
  556. {
  557. // set title
  558. SetDlgItemText(IDCST_ATM_AddrName, m_szTitle);
  559. BOOL fEditArps = !lstrcmpW(m_szTitle, c_szArpServer);
  560. // change the "Ok" button to "Add" if we are not editing
  561. if (FALSE == m_pParentDlg->m_fEditState)
  562. SetDlgItemText(IDOK, L"Add");
  563. // Set the position of the pop up dialog to be right over the listbox
  564. // on parent dialog
  565. RECT rect;
  566. Assert(m_pParentDlg->m_hAddressList);
  567. ::GetWindowRect(m_pParentDlg->m_hAddressList, &rect);
  568. SetWindowPos(NULL, rect.left, rect.top, 0,0,
  569. SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE);
  570. // Save handles to the "Ok" button and the edit box
  571. m_hOkButton = GetDlgItem(IDOK);
  572. m_hEditBox = GetDlgItem(IDC_EDT_ATM_Address);
  573. // ATM addresses have a 40 character limit + separaters
  574. ::SendMessage(m_hEditBox, EM_SETLIMITTEXT, MAX_ATM_ADDRESS_LENGTH*1.5, 0);
  575. // add the address that was just removed
  576. tstring strNewAddress = fEditArps ? m_pParentDlg->m_strNewArpsAddress : m_pParentDlg->m_strNewMarsAddress;
  577. if (strNewAddress.size())
  578. {
  579. ::SetWindowText(m_hEditBox, strNewAddress.c_str());
  580. ::SendMessage(m_hEditBox, EM_SETSEL, 0, -1);
  581. ::EnableWindow(m_hOkButton, TRUE);
  582. }
  583. else
  584. {
  585. if (fEditArps)
  586. {
  587. m_pParentDlg->m_strNewArpsAddress = c_szEmpty;
  588. }
  589. else
  590. {
  591. m_pParentDlg->m_strNewMarsAddress = c_szEmpty;
  592. }
  593. ::EnableWindow(m_hOkButton, FALSE);
  594. }
  595. ::SetFocus(m_hEditBox);
  596. return 0;
  597. }
  598. LRESULT CAtmAddressDialog::OnContextMenu(UINT uMsg, WPARAM wParam,
  599. LPARAM lParam, BOOL& fHandled)
  600. {
  601. ShowContextHelp(m_hWnd, HELP_CONTEXTMENU, m_adwHelpIDs);
  602. return 0;
  603. }
  604. LRESULT CAtmAddressDialog::OnHelp(UINT uMsg, WPARAM wParam,
  605. LPARAM lParam, BOOL& fHandled)
  606. {
  607. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  608. Assert(lphi);
  609. if (HELPINFO_WINDOW == lphi->iContextType)
  610. {
  611. ShowContextHelp(static_cast<HWND>(lphi->hItemHandle), HELP_WM_HELP,
  612. m_adwHelpIDs);
  613. }
  614. return 0;
  615. }
  616. // If the "Ok button is pushed
  617. LRESULT CAtmAddressDialog::OnOk(WORD wNotifyCode, WORD wID,
  618. HWND hWndCtl, BOOL& fHandled)
  619. {
  620. WCHAR szAtmAddress[MAX_ATM_ADDRESS_LENGTH+1];
  621. int i =0;
  622. int nId =0;
  623. // Get the current address from the control and
  624. // add them to the adapter if valid
  625. ::GetWindowText(m_hEditBox, szAtmAddress, MAX_ATM_ADDRESS_LENGTH+1);
  626. if (! FIsValidAtmAddress(szAtmAddress, &i, &nId))
  627. { // If invalid ATM address, we pop up a message box and set focus
  628. // back to the edit box
  629. // REVIEW(tongl): report first invalid character in mesg box
  630. NcMsgBox(m_hWnd, IDS_MSFT_TCP_TEXT, IDS_INCORRECT_ATM_ADDRESS,
  631. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  632. ::SetFocus(GetDlgItem(IDC_EDT_ATM_Address));
  633. return 0;
  634. }
  635. // We check if the newly added or modified string is already in the list,
  636. // if so, we do not add a duplicate address
  637. // m_hCurrentAddressList is the handle to either ARPS list or MARS list
  638. int nCount = Tcp_ListBox_GetCount(m_pParentDlg->m_hAddressList);
  639. if (nCount) // if the list is not empty
  640. {
  641. int i;
  642. WCHAR szBuff[MAX_ATM_ADDRESS_LENGTH+1];
  643. for (i=0; i<nCount; i++)
  644. {
  645. Tcp_ListBox_GetText(m_pParentDlg->m_hAddressList, i, szBuff);
  646. if (lstrcmpW(szAtmAddress, szBuff) ==0) // If string is already on the list
  647. {
  648. EndDialog(IDCANCEL);
  649. }
  650. }
  651. }
  652. BOOL fArpsDialog = !lstrcmpW(m_szTitle, c_szArpServer);
  653. if (m_pParentDlg->m_fEditState == FALSE) // Add new address
  654. {
  655. if (fArpsDialog)
  656. {
  657. m_pParentDlg->m_strNewArpsAddress = szAtmAddress;
  658. }
  659. else
  660. {
  661. m_pParentDlg->m_strNewMarsAddress = szAtmAddress;
  662. }
  663. }
  664. else // if edit, see if string is having a diferent value now
  665. {
  666. if (fArpsDialog)
  667. {
  668. if(m_pParentDlg->m_strNewArpsAddress != szAtmAddress)
  669. m_pParentDlg->m_strNewArpsAddress = szAtmAddress; // update save addresses
  670. else
  671. EndDialog(IDCANCEL);
  672. }
  673. else
  674. {
  675. if(m_pParentDlg->m_strNewMarsAddress != szAtmAddress)
  676. m_pParentDlg->m_strNewMarsAddress = szAtmAddress; // update save addresses
  677. else
  678. EndDialog(IDCANCEL);
  679. }
  680. }
  681. EndDialog(IDOK);
  682. return 0;
  683. }
  684. // If the "Cancel" button is pushed
  685. LRESULT CAtmAddressDialog::OnCancel(WORD wNotifyCode, WORD wID,
  686. HWND hWndCtl, BOOL& fHandled)
  687. {
  688. EndDialog(IDCANCEL);
  689. return 0;
  690. }
  691. // If the edit box contents is changed
  692. LRESULT CAtmAddressDialog::OnChange(WORD wNotifyCode, WORD wID,
  693. HWND hWndCtl, BOOL& fHandled)
  694. {
  695. WCHAR buf[2];
  696. // Enable or disable the "Ok" button
  697. // based on whether the edit box is empty
  698. if (::GetWindowText(m_hEditBox, buf, celems(buf)) == 0)
  699. ::EnableWindow(m_hOkButton, FALSE);
  700. else
  701. ::EnableWindow(m_hOkButton, TRUE);
  702. return 0;
  703. }
  704. void CAtmAddressDialog::SetTitle(PCWSTR pszTitle)
  705. {
  706. Assert(pszTitle);
  707. lstrcpyW(m_szTitle, pszTitle);
  708. }