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.

546 lines
14 KiB

  1. //-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: P V C D L G . C P P
  7. //
  8. // Contents: PVC main dialog message handler implementation
  9. //
  10. // Notes:
  11. //
  12. // Author: tongl 23 Feb, 1998
  13. //
  14. //-----------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "auniobj.h"
  18. #include "atmutil.h"
  19. #include "aunidlg.h"
  20. #include "atmcommon.h"
  21. #include "pvcdata.h"
  22. #include "ncatlui.h"
  23. #include "ncstl.h"
  24. #include "ncui.h"
  25. #include "atmhelp.h"
  26. CPVCMainDialog::CPVCMainDialog( CUniPage * pUniPage,
  27. CPvcInfo * pPvcInfo,
  28. const DWORD* adwHelpIDs)
  29. {
  30. Assert(pUniPage);
  31. Assert(pPvcInfo);
  32. m_pParentDlg = pUniPage;
  33. m_pPvcInfo = pPvcInfo;
  34. m_adwHelpIDs = adwHelpIDs;
  35. m_fDialogModified = FALSE;
  36. m_fPropShtOk = FALSE;
  37. m_fPropShtModified = FALSE;
  38. m_pQosPage = NULL;
  39. m_pLocalPage = NULL;
  40. m_pDestPage = NULL;
  41. }
  42. CPVCMainDialog::~CPVCMainDialog()
  43. {
  44. if (m_pQosPage != NULL)
  45. {
  46. delete (m_pQosPage);
  47. }
  48. if (m_pLocalPage != NULL)
  49. {
  50. delete (m_pLocalPage);
  51. }
  52. if (m_pDestPage != NULL)
  53. {
  54. delete (m_pDestPage);
  55. }
  56. }
  57. LRESULT CPVCMainDialog::OnInitDialog(UINT uMsg, WPARAM wParam,
  58. LPARAM lParam, BOOL& fHandled)
  59. {
  60. m_CurType = m_pPvcInfo->m_dwPVCType;
  61. InitInfo();
  62. SetInfo();
  63. return 0;
  64. }
  65. LRESULT CPVCMainDialog::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 CPVCMainDialog::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. LRESULT CPVCMainDialog::OnOk(WORD wNotifyCode, WORD wID,
  84. HWND hWndCtl, BOOL& fHandled)
  85. {
  86. // load the info from the controls to memory structure
  87. UpdateInfo();
  88. // make sure vpi, vci are in their range
  89. if (m_pPvcInfo->m_dwVpi > MAX_VPI)
  90. {
  91. // we pop up a message box and set focus to the vpi edit box
  92. NcMsgBox(m_hWnd, IDS_MSFT_UNI_TEXT, IDS_INVALID_VPI,
  93. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  94. ::SetFocus(GetDlgItem(IDC_EDT_PVC_VPI));
  95. return 0;
  96. }
  97. if ((m_pPvcInfo->m_dwVci<MIN_VCI) || (m_pPvcInfo->m_dwVci>MAX_VCI))
  98. {
  99. // we pop up a message box and set focus to the vpi edit box
  100. NcMsgBox(m_hWnd, IDS_MSFT_UNI_TEXT, IDS_INVALID_VCI,
  101. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  102. ::SetFocus(GetDlgItem(IDC_EDT_PVC_VCI));
  103. return 0;
  104. }
  105. // make sure calling and called atm addresses are correct in format
  106. int i, nId;
  107. if (m_pPvcInfo->m_strCallingAddr != c_szEmpty)
  108. {
  109. if (!FIsValidAtmAddress((PWSTR)m_pPvcInfo->m_strCallingAddr.c_str(), &i, &nId))
  110. {
  111. // we pop up a message box and set focus to the calling address edit box
  112. NcMsgBox(m_hWnd, IDS_MSFT_UNI_TEXT, IDS_INVALID_Calling_Address,
  113. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  114. ::SetFocus(GetDlgItem(IDC_EDT_PVC_AnswerAddr));
  115. return 0;
  116. }
  117. }
  118. if (m_pPvcInfo->m_strCalledAddr != c_szEmpty)
  119. {
  120. if (!FIsValidAtmAddress((PWSTR)m_pPvcInfo->m_strCalledAddr.c_str(), &i, &nId))
  121. {
  122. // we pop up a message box and set focus to the calling address edit box
  123. NcMsgBox(m_hWnd, IDS_MSFT_UNI_TEXT, IDS_INVALID_Called_Address,
  124. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  125. ::SetFocus(GetDlgItem(IDC_EDT_PVC_CallAddr));
  126. return 0;
  127. }
  128. }
  129. // set the modified bit
  130. if (!m_fDialogModified)
  131. {
  132. if ((m_pPvcInfo->m_dwVpi != m_pPvcInfo->m_dwOldVpi) ||
  133. (m_pPvcInfo->m_dwVci != m_pPvcInfo->m_dwOldVci) ||
  134. (m_pPvcInfo->m_dwAAL != m_pPvcInfo->m_dwOldAAL) ||
  135. (m_pPvcInfo->m_strCallingAddr != m_pPvcInfo->m_strCallingAddr) ||
  136. (m_pPvcInfo->m_strCalledAddr != m_pPvcInfo->m_strOldCalledAddr)
  137. )
  138. {
  139. m_fDialogModified = TRUE;
  140. }
  141. }
  142. EndDialog(IDOK);
  143. return 0;
  144. }
  145. LRESULT CPVCMainDialog::OnCancel(WORD wNotifyCode, WORD wID,
  146. HWND hWndCtl, BOOL& fHandled)
  147. {
  148. EndDialog(IDCANCEL);
  149. return 0;
  150. }
  151. LRESULT CPVCMainDialog::OnType(WORD wNotifyCode, WORD wID,
  152. HWND hWndCtl, BOOL& fHandled)
  153. {
  154. // $REVIEW(tongl 2/27/98): confirmed this behaviour with ArvindM
  155. // When type changes, we reset all the type related defaults
  156. // to match the new type ...
  157. // get the new selection
  158. int idx = SendDlgItemMessage(IDC_CMB_PVC_Type, CB_GETCURSEL, (LPARAM)(0), 0);
  159. if (idx != CB_ERR)
  160. {
  161. if (idx != m_CurType-1) // type has changed
  162. {
  163. UpdateInfo();
  164. m_CurType = (PVCType)(idx+1);
  165. m_pPvcInfo->SetTypeDefaults(m_CurType);
  166. // update the UI
  167. SetInfo();
  168. }
  169. }
  170. return 0;
  171. }
  172. LRESULT CPVCMainDialog::OnSpecifyCallAddr(WORD wNotifyCode, WORD wID,
  173. HWND hWndCtl, BOOL& fHandled)
  174. {
  175. if (IsDlgButtonChecked(IDC_CHK_PVC_CallAddr))
  176. {
  177. // enable the calling address control
  178. ::EnableWindow(GetDlgItem(IDC_EDT_PVC_CallAddr), TRUE);
  179. }
  180. else
  181. {
  182. // disable the control
  183. ::EnableWindow(GetDlgItem(IDC_EDT_PVC_CallAddr), FALSE);
  184. }
  185. return 0;
  186. }
  187. LRESULT CPVCMainDialog::OnSpecifyAnswerAddr(WORD wNotifyCode, WORD wID,
  188. HWND hWndCtl, BOOL& fHandled)
  189. {
  190. if (IsDlgButtonChecked(IDC_CHK_PVC_AnswerAddr))
  191. {
  192. // enable the calling address control
  193. ::EnableWindow(GetDlgItem(IDC_EDT_PVC_AnswerAddr), TRUE);
  194. }
  195. else
  196. {
  197. // disable the control
  198. ::EnableWindow(GetDlgItem(IDC_EDT_PVC_AnswerAddr), FALSE);
  199. }
  200. return 0;
  201. }
  202. LRESULT CPVCMainDialog::OnAdvanced(WORD wNotifyCode, WORD wID,
  203. HWND hWndCtl, BOOL& fHandled)
  204. {
  205. switch (wNotifyCode)
  206. {
  207. case BN_CLICKED:
  208. case BN_DOUBLECLICKED:
  209. // Make a copy of the current PVC info and pass to the
  210. // advanced property sheet pages
  211. // get what's in the main UI to in memory structure
  212. UpdateInfo();
  213. CPvcInfo * pPvcInfoDlg = new CPvcInfo(m_pPvcInfo->m_strPvcId.c_str());
  214. if (pPvcInfoDlg)
  215. {
  216. *pPvcInfoDlg = *m_pPvcInfo;
  217. // Bring up the advanced PVC property sheet
  218. HRESULT hr = HrDoPvcPropertySheet(pPvcInfoDlg);
  219. if (S_OK == hr)
  220. {
  221. if (m_fPropShtOk && m_fPropShtModified)
  222. {
  223. // Something changed, so mark the page as modified
  224. m_fDialogModified = TRUE;
  225. // Reset values
  226. m_fPropShtOk = FALSE;
  227. m_fPropShtModified = FALSE;
  228. // Update second memory info structure
  229. *m_pPvcInfo = *pPvcInfoDlg;
  230. }
  231. }
  232. delete pPvcInfoDlg;
  233. }
  234. break;
  235. }
  236. return 0;
  237. }
  238. HRESULT CPVCMainDialog::HrDoPvcPropertySheet(CPvcInfo * pPvcInfoDlg)
  239. {
  240. Assert(pPvcInfoDlg);
  241. HRESULT hr = S_OK;
  242. HPROPSHEETPAGE *ahpsp = NULL;
  243. int cPages = 0;
  244. // Create property pages
  245. hr = HrSetupPropPages(pPvcInfoDlg, &ahpsp, &cPages);
  246. if (SUCCEEDED(hr))
  247. {
  248. // Show the property sheet
  249. PROPSHEETHEADER psh = {0};
  250. psh.dwSize = sizeof(PROPSHEETHEADER);
  251. psh.dwFlags = PSH_NOAPPLYNOW;
  252. psh.hwndParent = ::GetActiveWindow();
  253. psh.hInstance = _Module.GetModuleInstance();
  254. psh.pszIcon = NULL;
  255. psh.pszCaption = (PWSTR)SzLoadIds(IDS_ADV_PVC_HEADER);
  256. psh.nPages = cPages;
  257. psh.phpage = ahpsp;
  258. int iRet = PropertySheet(&psh);
  259. if (-1 == iRet)
  260. {
  261. hr = HrFromLastWin32Error();
  262. }
  263. CoTaskMemFree(ahpsp);
  264. }
  265. TraceError("CPVCMainDialog::DoPropertySheet", hr);
  266. return hr;
  267. }
  268. HRESULT CPVCMainDialog::HrSetupPropPages( CPvcInfo * pPvcInfoDlg,
  269. HPROPSHEETPAGE ** pahpsp,
  270. INT * pcPages)
  271. {
  272. HRESULT hr = S_OK;
  273. *pahpsp = NULL;
  274. *pcPages = 0;
  275. int cPages = 0;
  276. HPROPSHEETPAGE *ahpsp = NULL;
  277. delete (m_pQosPage);
  278. m_pQosPage = NULL;
  279. delete (m_pLocalPage);
  280. m_pLocalPage = NULL;
  281. delete (m_pDestPage);
  282. m_pDestPage = NULL;
  283. // Set up the property pages
  284. m_pQosPage = new CPvcQosPage(this, pPvcInfoDlg, g_aHelpIDs_IDD_PVC_Traffic);
  285. if (!m_pQosPage)
  286. {
  287. return E_OUTOFMEMORY;
  288. }
  289. cPages = 1;
  290. if (m_pPvcInfo->m_dwPVCType == PVC_CUSTOM)
  291. {
  292. m_pLocalPage = new CPvcLocalPage(this, pPvcInfoDlg, g_aHelpIDs_IDD_PVC_Local);
  293. if (!m_pLocalPage)
  294. {
  295. return E_OUTOFMEMORY;
  296. }
  297. m_pDestPage = new CPvcDestPage(this, pPvcInfoDlg, g_aHelpIDs_IDD_PVC_Dest);
  298. if (!m_pDestPage)
  299. {
  300. return E_OUTOFMEMORY;
  301. }
  302. cPages = 3;
  303. }
  304. // Allocate a buffer large enough to hold the handles to all of our
  305. // property pages.
  306. ahpsp = (HPROPSHEETPAGE *)CoTaskMemAlloc(sizeof(HPROPSHEETPAGE)* cPages);
  307. if (!ahpsp)
  308. {
  309. return E_OUTOFMEMORY;
  310. }
  311. cPages =0;
  312. ahpsp[cPages++] = m_pQosPage->CreatePage(IDD_PVC_Traffic, 0);
  313. if (m_pPvcInfo->m_dwPVCType == PVC_CUSTOM)
  314. {
  315. ahpsp[cPages++] = m_pLocalPage->CreatePage(IDD_PVC_Local, 0);
  316. ahpsp[cPages++] = m_pDestPage->CreatePage(IDD_PVC_Dest, 0);
  317. }
  318. *pahpsp = ahpsp;
  319. *pcPages = cPages;
  320. return hr;
  321. }
  322. void CPVCMainDialog::InitInfo()
  323. {
  324. // set limits & selections to the controls
  325. // PVC name
  326. ::SendMessage(GetDlgItem(IDC_EDT_PVC_Name), EM_SETLIMITTEXT, MAX_PATH, 0);
  327. // VPI
  328. // length limit
  329. ::SendMessage(GetDlgItem(IDC_EDT_PVC_VPI), EM_SETLIMITTEXT, MAX_VPI_LENGTH, 0);
  330. // VCI
  331. // length limit
  332. ::SendMessage(GetDlgItem(IDC_EDT_PVC_VCI), EM_SETLIMITTEXT, MAX_VCI_LENGTH, 0);
  333. // AAL TYpe
  334. // $REVIEW(tongl 2/24/98): per ArvindM, only AAL5 is supported in NT5
  335. SendDlgItemMessage(IDC_CMB_PVC_AAL,
  336. CB_ADDSTRING, 0, (LPARAM)((PWSTR) SzLoadIds(IDS_PVC_AAL5)));
  337. // PVC_TYPE
  338. SendDlgItemMessage(IDC_CMB_PVC_Type,
  339. CB_ADDSTRING, 0, (LPARAM)((PWSTR) SzLoadIds(IDS_PVC_ATMARP)));
  340. SendDlgItemMessage(IDC_CMB_PVC_Type,
  341. CB_ADDSTRING, 0, (LPARAM)((PWSTR) SzLoadIds(IDS_PVC_PPP_ATM_CLIENT)));
  342. SendDlgItemMessage(IDC_CMB_PVC_Type,
  343. CB_ADDSTRING, 0, (LPARAM)((PWSTR) SzLoadIds(IDS_PVC_PPP_ATM_SERVER)));
  344. SendDlgItemMessage(IDC_CMB_PVC_Type,
  345. CB_ADDSTRING, 0, (LPARAM)((PWSTR) SzLoadIds(IDS_PVC_CUSTOM)));
  346. }
  347. void CPVCMainDialog::SetInfo()
  348. {
  349. // Name
  350. SetDlgItemText(IDC_EDT_PVC_Name, m_pPvcInfo->m_strName.c_str());
  351. // VPI
  352. WCHAR szVpi[MAX_VPI_LENGTH+1];
  353. wsprintfW(szVpi, c_szItoa, m_pPvcInfo->m_dwVpi);
  354. SetDlgItemText(IDC_EDT_PVC_VPI, szVpi);
  355. // VCI
  356. if (FIELD_UNSET != m_pPvcInfo->m_dwVci)
  357. {
  358. WCHAR szVci[MAX_VCI_LENGTH+1];
  359. wsprintfW(szVci, c_szItoa, m_pPvcInfo->m_dwVci);
  360. SetDlgItemText(IDC_EDT_PVC_VCI, szVci);
  361. }
  362. // AAL TYpe
  363. SendDlgItemMessage(IDC_CMB_PVC_AAL,
  364. CB_SETCURSEL, (LPARAM)(0), 0);
  365. // PVC_TYPE
  366. SendDlgItemMessage(IDC_CMB_PVC_Type,
  367. CB_SETCURSEL, (LPARAM)(m_pPvcInfo->m_dwPVCType-1), 0);
  368. // calling addresses
  369. BOOL fAddrSpecified = (m_pPvcInfo->m_strCalledAddr != c_szEmpty);
  370. ::EnableWindow(GetDlgItem(IDC_CHK_PVC_CallAddr), TRUE);
  371. CheckDlgButton(IDC_CHK_PVC_CallAddr, fAddrSpecified);
  372. ::EnableWindow(GetDlgItem(IDC_EDT_PVC_CallAddr), fAddrSpecified);
  373. if (fAddrSpecified)
  374. {
  375. SetDlgItemText(IDC_EDT_PVC_CallAddr, m_pPvcInfo->m_strCalledAddr.c_str());
  376. }
  377. // answering address
  378. fAddrSpecified = (m_pPvcInfo->m_strCallingAddr != c_szEmpty);
  379. ::EnableWindow(GetDlgItem(IDC_CHK_PVC_AnswerAddr), TRUE);
  380. CheckDlgButton(IDC_CHK_PVC_AnswerAddr, fAddrSpecified);
  381. ::EnableWindow(GetDlgItem(IDC_EDT_PVC_AnswerAddr), fAddrSpecified);
  382. if (fAddrSpecified)
  383. {
  384. SetDlgItemText(IDC_EDT_PVC_AnswerAddr, m_pPvcInfo->m_strCallingAddr.c_str());
  385. }
  386. // disable the calling address\answer address controls if the type is ATMARP
  387. // Bug #179335
  388. if (m_pPvcInfo->m_dwPVCType == PVC_ATMARP)
  389. {
  390. // disable all controls on this doalog
  391. static const int nrgIdc[] = {IDC_CHK_PVC_CallAddr,
  392. IDC_EDT_PVC_CallAddr,
  393. IDC_CHK_PVC_AnswerAddr,
  394. IDC_EDT_PVC_AnswerAddr};
  395. EnableOrDisableDialogControls(m_hWnd, celems(nrgIdc), nrgIdc, FALSE);
  396. }
  397. }
  398. // Update the in memory structure with what's in the dialog
  399. void CPVCMainDialog::UpdateInfo()
  400. {
  401. WCHAR szBuf[MAX_PATH];
  402. // Name
  403. GetDlgItemText(IDC_EDT_PVC_Name, szBuf, MAX_PATH);
  404. m_pPvcInfo->m_strName = szBuf;
  405. // VPI
  406. GetDlgItemText(IDC_EDT_PVC_VPI, szBuf, MAX_VPI_LENGTH+1);
  407. m_pPvcInfo->m_dwVpi = _wtoi(szBuf);
  408. // VCI
  409. GetDlgItemText(IDC_EDT_PVC_VCI, szBuf, MAX_VCI_LENGTH+1);
  410. if (*szBuf ==0) // empty string
  411. {
  412. m_pPvcInfo->m_dwVci = FIELD_UNSET;
  413. }
  414. else
  415. {
  416. m_pPvcInfo->m_dwVci = _wtoi(szBuf);
  417. }
  418. // current selection
  419. int idx = SendDlgItemMessage(IDC_CMB_PVC_Type, CB_GETCURSEL, (LPARAM)(0), 0);
  420. if (idx != CB_ERR)
  421. {
  422. m_pPvcInfo->m_dwPVCType = (PVCType)(idx+1);
  423. }
  424. // calling addresses
  425. if (!IsDlgButtonChecked(IDC_CHK_PVC_CallAddr))
  426. {
  427. m_pPvcInfo->m_strCalledAddr = c_szEmpty;
  428. }
  429. else
  430. {
  431. GetDlgItemText(IDC_EDT_PVC_CallAddr, szBuf, MAX_ATM_ADDRESS_LENGTH+1);
  432. m_pPvcInfo->m_strCalledAddr = szBuf;
  433. }
  434. // answering address
  435. if (!IsDlgButtonChecked(IDC_CHK_PVC_AnswerAddr))
  436. {
  437. m_pPvcInfo->m_strCallingAddr = c_szEmpty;
  438. }
  439. else
  440. {
  441. GetDlgItemText(IDC_EDT_PVC_AnswerAddr, szBuf, MAX_ATM_ADDRESS_LENGTH+1);
  442. m_pPvcInfo->m_strCallingAddr = szBuf;
  443. }
  444. }