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.

675 lines
16 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: I S D N P A G E . C P P
  7. //
  8. // Contents: Contains the isdn page for enumerated net class devices
  9. //
  10. // Notes:
  11. //
  12. // Author: BillBe 9 Sep 1997
  13. //
  14. //---------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "isdnpage.h"
  18. #include "isdnshts.h"
  19. #include "ncreg.h"
  20. #include "ncsetup.h"
  21. #include "ncui.h"
  22. CIsdnPage::CIsdnPage()
  23. : m_fDirty(FALSE),
  24. m_hkeyDriver(NULL),
  25. m_hdi(NULL),
  26. m_pdeid(NULL),
  27. m_pisdnci(NULL)
  28. {
  29. }
  30. CIsdnPage::~CIsdnPage()
  31. {
  32. if (m_pisdnci)
  33. {
  34. // Free the structure. This was allocated by
  35. // HrReadIsdnPropertiesInfo.
  36. //
  37. FreeIsdnPropertiesInfo(m_pisdnci);
  38. }
  39. RegSafeCloseKey(m_hkeyDriver);
  40. }
  41. //+--------------------------------------------------------------------------
  42. //
  43. // Member: CIsdnPage::CreatePage
  44. //
  45. // Purpose: Creates the Isdn page only if there the device is an isdn
  46. // adapter
  47. //
  48. // Arguments:
  49. // hdi [in] SetupApi HDEVINFO for device
  50. // pdeid [in] SetupApi PSP_DEVINFO_DATA for device
  51. //
  52. // Returns: HPROPSHEETPAGE
  53. //
  54. // Author: billbe 9 Sep 1997
  55. //
  56. // Notes:
  57. //
  58. HPROPSHEETPAGE
  59. CIsdnPage::CreatePage(HDEVINFO hdi, PSP_DEVINFO_DATA pdeid)
  60. {
  61. Assert(INVALID_HANDLE_VALUE != hdi);
  62. Assert(hdi);
  63. Assert(pdeid);
  64. HPROPSHEETPAGE hpsp = NULL;
  65. // Open the device's instance key
  66. HRESULT hr = HrSetupDiOpenDevRegKey(hdi, pdeid,
  67. DICS_FLAG_GLOBAL, 0, DIREG_DRV, KEY_ALL_ACCESS,
  68. &m_hkeyDriver);
  69. // If the key was opened and this adapter is ISDN
  70. if (SUCCEEDED(hr) && FShowIsdnPages(m_hkeyDriver))
  71. {
  72. // read the adapter's properties from the registry
  73. hr = HrReadIsdnPropertiesInfo(m_hkeyDriver, hdi, pdeid, &m_pisdnci);
  74. if (SUCCEEDED(hr))
  75. {
  76. m_hdi = hdi;
  77. m_pdeid = pdeid;
  78. hpsp = CPropSheetPage::CreatePage(IDP_ISDN_SWITCH_TYPE, 0);
  79. }
  80. }
  81. return hpsp;
  82. }
  83. //+--------------------------------------------------------------------------
  84. //
  85. // Member: CIsdnPage::OnInitDialog
  86. //
  87. // Purpose: Handler for the WM_INITDIALOG window message. Initializes
  88. // the dialog window.
  89. //
  90. // Author: BillBe 09 Sep 1997
  91. //
  92. // Notes:
  93. //
  94. //
  95. LRESULT
  96. CIsdnPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam,
  97. BOOL& bHandled)
  98. {
  99. // Populate the switch types from the multi-sz that we read
  100. PopulateIsdnSwitchTypes(m_hWnd, IDC_CMB_SwitchType, m_pisdnci);
  101. SetSwitchType(m_hWnd, IDC_CMB_SwitchType, m_pisdnci->dwCurSwitchType);
  102. // Note the current selections
  103. //
  104. m_pisdnci->nOldBChannel = SendDlgItemMessage(IDC_LBX_Variant,
  105. LB_GETCURSEL, 0, 0);
  106. m_pisdnci->nOldDChannel = SendDlgItemMessage(IDC_LBX_Line,
  107. LB_GETCURSEL, 0, 0);
  108. return 0;
  109. }
  110. LRESULT
  111. CIsdnPage::OnSwitchType(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  112. BOOL& bHandled)
  113. {
  114. if (wNotifyCode == CBN_SELCHANGE)
  115. {
  116. m_fDirty = TRUE;
  117. SetChangedFlag();
  118. }
  119. return 0;
  120. }
  121. //+--------------------------------------------------------------------------
  122. //
  123. // Member: CIsdnPage::OnApply
  124. //
  125. // Purpose: Handler for the PSN_APPLY message
  126. //
  127. // Author: BillBe 10 Sep 1997
  128. //
  129. // Notes:
  130. //
  131. //
  132. LRESULT
  133. CIsdnPage::OnApply(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  134. {
  135. // only do something if data has changed.
  136. if (m_fDirty)
  137. {
  138. // Update the switch type
  139. m_pisdnci->dwCurSwitchType = DwGetSwitchType(m_hWnd, m_pisdnci,
  140. IDC_CMB_SwitchType);
  141. // Write the parameters back out into the registry.
  142. (void) HrWriteIsdnPropertiesInfo(m_hkeyDriver, m_pisdnci);
  143. // Notify the UI that its display might need updating
  144. //
  145. SP_DEVINSTALL_PARAMS deip;
  146. // Try to get the current params
  147. (void) HrSetupDiGetDeviceInstallParams(m_hdi, m_pdeid, &deip);
  148. deip.FlagsEx |= DI_FLAGSEX_PROPCHANGE_PENDING;
  149. // Try to set the new params. If it fails, it is not
  150. // catastrophic so we ignore return values
  151. (void) HrSetupDiSetDeviceInstallParams(m_hdi, m_pdeid, &deip);
  152. // Changes have been applied so clear our dirty flag
  153. m_fDirty = FALSE;
  154. }
  155. return 0;
  156. }
  157. LRESULT
  158. CIsdnPage::OnConfigure(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  159. BOOL& bHandled)
  160. {
  161. DWORD dwSwitchType;
  162. dwSwitchType = DwGetSwitchType(m_hWnd, m_pisdnci, IDC_CMB_SwitchType);
  163. switch (dwSwitchType)
  164. {
  165. case ISDN_SWITCH_ATT:
  166. case ISDN_SWITCH_NI1:
  167. case ISDN_SWITCH_NI2:
  168. case ISDN_SWITCH_NTI:
  169. if (m_pisdnci->fIsPri)
  170. {
  171. // PRI adapters use the EAZ page instead
  172. DoEazDlg();
  173. }
  174. else
  175. {
  176. DoSpidsDlg();
  177. }
  178. break;
  179. case ISDN_SWITCH_INS64:
  180. DoJapanDlg();
  181. break;
  182. case ISDN_SWITCH_1TR6:
  183. case ISDN_SWITCH_AUTO:
  184. DoEazDlg();
  185. break;
  186. case ISDN_SWITCH_VN3:
  187. case ISDN_SWITCH_DSS1:
  188. case ISDN_SWITCH_AUS:
  189. case ISDN_SWITCH_BEL:
  190. case ISDN_SWITCH_VN4:
  191. case ISDN_SWITCH_SWE:
  192. case ISDN_SWITCH_ITA:
  193. case ISDN_SWITCH_TWN:
  194. DoMsnDlg();
  195. break;
  196. default:
  197. AssertSz(FALSE, "Where do we go from here.. now that all of our "
  198. "children are growin' up?");
  199. break;
  200. }
  201. return 0;
  202. }
  203. VOID CIsdnPage::DoSpidsDlg()
  204. {
  205. CSpidsDlg dlg(m_pisdnci);
  206. INT nRet;
  207. m_pisdnci->idd = dlg.IDD;
  208. nRet = dlg.DoModal(m_hWnd);
  209. if (nRet)
  210. {
  211. m_fDirty = TRUE;
  212. SetChangedFlag();
  213. }
  214. }
  215. VOID CIsdnPage::DoJapanDlg()
  216. {
  217. CJapanDlg dlg(m_pisdnci);
  218. INT nRet;
  219. m_pisdnci->idd = dlg.IDD;
  220. nRet = dlg.DoModal(m_hWnd);
  221. if (nRet)
  222. {
  223. m_fDirty = TRUE;
  224. SetChangedFlag();
  225. }
  226. }
  227. VOID CIsdnPage::DoEazDlg()
  228. {
  229. CEazDlg dlg(m_pisdnci);
  230. INT nRet;
  231. m_pisdnci->idd = dlg.IDD;
  232. nRet = dlg.DoModal(m_hWnd);
  233. if (nRet)
  234. {
  235. m_fDirty = TRUE;
  236. SetChangedFlag();
  237. }
  238. }
  239. VOID CIsdnPage::DoMsnDlg()
  240. {
  241. CMsnDlg dlg(m_pisdnci);
  242. INT nRet;
  243. m_pisdnci->idd = dlg.IDD;
  244. nRet = dlg.DoModal(m_hWnd);
  245. if (nRet)
  246. {
  247. m_fDirty = TRUE;
  248. SetChangedFlag();
  249. }
  250. }
  251. static const CONTEXTIDMAP c_adwContextIdMap[] =
  252. {
  253. { IDC_LBX_Line, 2003230, 2003230 },
  254. { IDC_LBX_Variant, 2003240, 2003240 },
  255. { IDC_EDT_PhoneNumber, 2003250, 2003255 },
  256. { IDC_EDT_SPID, 2003265, 2003260 },
  257. { IDC_EDT_MSN, 2003270, 2003270 },
  258. { IDC_PSB_ADD, 2003280, 2003280 },
  259. { IDC_LBX_MSN, 2003290, 2003290 },
  260. { IDC_PSB_REMOVE, 2003300, 2003300 },
  261. { IDC_CMB_SwitchType, 2003310, 2003310 },
  262. { IDC_PSB_Configure, 2003320, 2003320 },
  263. { 0, 0, 0 }, // end marker
  264. };
  265. LRESULT CIsdnPage::OnHelp(UINT uMsg, WPARAM wParam, LPARAM lParam,
  266. BOOL& bHandled)
  267. {
  268. OnHelpGeneric(m_hWnd, (LPHELPINFO)lParam, c_adwContextIdMap, m_pisdnci->idd == IDD_ISDN_JAPAN, c_szIsdnHelpFile);
  269. return TRUE;
  270. }
  271. LRESULT CIsdnPage::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam,
  272. BOOL& bHandled)
  273. {
  274. HELPINFO hi;
  275. HMENU h = CreatePopupMenu();
  276. POINT pScreen;
  277. TCHAR szWhat[MAX_PATH];
  278. if (h == NULL)
  279. {
  280. return FALSE;
  281. }
  282. LoadString(_Module.GetResourceInstance(), IDS_ISDN_WHATS_THIS, szWhat, MAX_PATH);
  283. InsertMenu(h, -1, MF_BYPOSITION, 777, szWhat);
  284. pScreen.x = ((int)(short)LOWORD(lParam));
  285. pScreen.y = ((int)(short)HIWORD(lParam));
  286. int n;
  287. switch(n = TrackPopupMenu(h, TPM_NONOTIFY | TPM_RETURNCMD, pScreen.x, pScreen.y, 0, m_hWnd, NULL))
  288. {
  289. case 777:
  290. hi.iContextType = HELPINFO_WINDOW;
  291. hi.iCtrlId = ::GetWindowLong((HWND)wParam, GWL_ID);
  292. OnHelpGeneric(m_hWnd, &hi, c_adwContextIdMap, m_pisdnci->idd == IDD_ISDN_JAPAN, c_szIsdnHelpFile);
  293. break;
  294. }
  295. DestroyMenu(h);
  296. return TRUE;
  297. }
  298. //+---------------------------------------------------------------------------
  299. //
  300. // Function: HrGetIsdnPage
  301. //
  302. // Purpose: Creates the Isdn page for enumerated net devices.
  303. // This function is called by the NetPropPageProvider fcn.
  304. //
  305. // Arguments:
  306. // hdi [in] See SetupApi for info
  307. // pdeid [in] See SetupApi for for info
  308. // phpsp [out] Pointer to the handle to the isdn property page
  309. //
  310. // Returns:
  311. //
  312. // Author: billbe 9 Sep 1997
  313. //
  314. // Notes:
  315. //
  316. HRESULT
  317. HrGetIsdnPage(HDEVINFO hdi, PSP_DEVINFO_DATA pdeid,
  318. HPROPSHEETPAGE* phpsp)
  319. {
  320. Assert(hdi);
  321. Assert(pdeid);
  322. Assert(phpsp);
  323. HRESULT hr;
  324. HPROPSHEETPAGE hpsp;
  325. CIsdnPage* pisdn = new CIsdnPage();
  326. if (pisdn == NULL)
  327. {
  328. return(ERROR_NOT_ENOUGH_MEMORY);
  329. }
  330. // create the isdn page
  331. hpsp = pisdn->CreatePage(hdi, pdeid);
  332. // if successful, set the out param
  333. if (hpsp)
  334. {
  335. *phpsp = hpsp;
  336. hr = S_OK;
  337. }
  338. else
  339. {
  340. // Either there is no isdn page to display or there
  341. // was an error.
  342. hr = E_FAIL;
  343. *phpsp = NULL;
  344. delete pisdn;
  345. }
  346. TraceErrorOptional("HrGetIsdnPage", hr, E_FAIL == hr);
  347. return (hr);
  348. }
  349. LRESULT CSpidsDlg::OnOk(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  350. BOOL& bHandled)
  351. {
  352. OnIsdnInfoPageTransition(m_hWnd, m_pisdnci);
  353. EndDialog(TRUE);
  354. return 0;
  355. }
  356. LRESULT CSpidsDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  357. BOOL& bHandled)
  358. {
  359. EndDialog(FALSE);
  360. return 0;
  361. }
  362. LRESULT CSpidsDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam,
  363. BOOL& bHandled)
  364. {
  365. // Populate the channels from the array of B-Channels stored in our
  366. // config info for the first D-Channel
  367. //
  368. PopulateIsdnChannels(m_hWnd, IDC_EDT_SPID, IDC_EDT_PhoneNumber,
  369. IDC_LBX_Line, IDC_LBX_Variant, m_pisdnci);
  370. ::SetFocus(GetDlgItem(IDC_EDT_PhoneNumber));
  371. // Note the current selections
  372. //
  373. m_pisdnci->nOldBChannel = SendDlgItemMessage(IDC_LBX_Variant,
  374. LB_GETCURSEL, 0, 0);
  375. m_pisdnci->nOldDChannel = SendDlgItemMessage(IDC_LBX_Line,
  376. LB_GETCURSEL, 0, 0);
  377. SendDlgItemMessage(IDC_EDT_SPID, EM_LIMITTEXT, c_cchMaxSpid, 0);
  378. SendDlgItemMessage(IDC_EDT_PhoneNumber, EM_LIMITTEXT, c_cchMaxOther, 0);
  379. return FALSE;
  380. }
  381. LRESULT CSpidsDlg::OnSelChange(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  382. BOOL& bHandled)
  383. {
  384. if (wNotifyCode == LBN_SELCHANGE)
  385. {
  386. OnIsdnInfoPageSelChange(m_hWnd, m_pisdnci);
  387. }
  388. return 0;
  389. }
  390. LRESULT CSpidsDlg::OnHelp(UINT uMsg, WPARAM wParam, LPARAM lParam,
  391. BOOL& bHandled)
  392. {
  393. OnHelpGeneric(m_hWnd, (LPHELPINFO)lParam, c_adwContextIdMap, m_pisdnci->idd == IDD_ISDN_JAPAN, c_szIsdnHelpFile);
  394. return TRUE;
  395. }
  396. //
  397. // CEazDlg Implementation
  398. //
  399. LRESULT CEazDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam,
  400. BOOL& bHandled)
  401. {
  402. // Populate the channels from the array of B-Channels stored in our
  403. // config info for the first D-Channel
  404. //
  405. PopulateIsdnChannels(m_hWnd, IDC_EDT_SPID, IDC_EDT_PhoneNumber,
  406. IDC_LBX_Line, IDC_LBX_Variant, m_pisdnci);
  407. ::SetFocus(GetDlgItem(IDC_EDT_PhoneNumber));
  408. // Note the current selections
  409. //
  410. m_pisdnci->nOldBChannel = SendDlgItemMessage(IDC_LBX_Variant,
  411. LB_GETCURSEL, 0, 0);
  412. m_pisdnci->nOldDChannel = SendDlgItemMessage(IDC_LBX_Line,
  413. LB_GETCURSEL, 0, 0);
  414. SendDlgItemMessage(IDC_EDT_PhoneNumber, EM_LIMITTEXT, c_cchMaxOther, 0);
  415. return FALSE;
  416. }
  417. LRESULT CEazDlg::OnOk(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  418. BOOL& bHandled)
  419. {
  420. OnIsdnInfoPageTransition(m_hWnd, m_pisdnci);
  421. EndDialog(TRUE);
  422. return 0;
  423. }
  424. LRESULT CEazDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  425. BOOL& bHandled)
  426. {
  427. EndDialog(FALSE);
  428. return 0;
  429. }
  430. LRESULT CEazDlg::OnSelChange(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  431. BOOL& bHandled)
  432. {
  433. if (wNotifyCode == LBN_SELCHANGE)
  434. {
  435. OnIsdnInfoPageSelChange(m_hWnd, m_pisdnci);
  436. }
  437. return 0;
  438. }
  439. LRESULT CEazDlg::OnHelp(UINT uMsg, WPARAM wParam, LPARAM lParam,
  440. BOOL& bHandled)
  441. {
  442. OnHelpGeneric(m_hWnd, (LPHELPINFO)lParam, c_adwContextIdMap, m_pisdnci->idd == IDD_ISDN_JAPAN, c_szIsdnHelpFile);
  443. return TRUE;
  444. }
  445. //
  446. // CMsnDlg Implementation
  447. //
  448. LRESULT CMsnDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam,
  449. BOOL& bHandled)
  450. {
  451. OnMsnPageInitDialog(m_hWnd, m_pisdnci);
  452. // Note the current selections
  453. //
  454. m_pisdnci->nOldDChannel = SendDlgItemMessage(IDC_LBX_Line,
  455. LB_GETCURSEL, 0, 0);
  456. SendDlgItemMessage(IDC_EDT_MSN, EM_LIMITTEXT, c_cchMaxOther, 0);
  457. return FALSE;
  458. }
  459. LRESULT CMsnDlg::OnOk(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  460. BOOL& bHandled)
  461. {
  462. INT iCurSel;
  463. iCurSel = SendDlgItemMessage(IDC_LBX_Line, LB_GETCURSEL, 0, 0);
  464. if (iCurSel != LB_ERR)
  465. {
  466. GetDataFromListBox(iCurSel, m_hWnd, m_pisdnci);
  467. }
  468. EndDialog(TRUE);
  469. return 0;
  470. }
  471. LRESULT CMsnDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  472. BOOL& bHandled)
  473. {
  474. EndDialog(FALSE);
  475. return 0;
  476. }
  477. LRESULT CMsnDlg::OnAdd(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  478. BOOL& bHandled)
  479. {
  480. OnMsnPageAdd(m_hWnd, m_pisdnci);
  481. return 0;
  482. }
  483. LRESULT CMsnDlg::OnRemove(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  484. BOOL& bHandled)
  485. {
  486. OnMsnPageRemove(m_hWnd, m_pisdnci);
  487. return 0;
  488. }
  489. LRESULT CMsnDlg::OnChange(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  490. BOOL& bHandled)
  491. {
  492. OnMsnPageEditSelChange(m_hWnd, m_pisdnci);
  493. return 0;
  494. }
  495. LRESULT CMsnDlg::OnSelChange(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  496. BOOL& bHandled)
  497. {
  498. if (wNotifyCode == LBN_SELCHANGE)
  499. {
  500. OnMsnPageSelChange(m_hWnd, m_pisdnci);
  501. }
  502. return 0;
  503. }
  504. LRESULT CMsnDlg::OnHelp(UINT uMsg, WPARAM wParam, LPARAM lParam,
  505. BOOL& bHandled)
  506. {
  507. OnHelpGeneric(m_hWnd, (LPHELPINFO)lParam, c_adwContextIdMap, m_pisdnci->idd == IDD_ISDN_JAPAN, c_szIsdnHelpFile);
  508. return TRUE;
  509. }
  510. //
  511. // CJapanDlg Implementation
  512. //
  513. LRESULT CJapanDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam,
  514. BOOL& bHandled)
  515. {
  516. // Populate the channels from the array of B-Channels stored in our
  517. // config info for the first D-Channel
  518. //
  519. PopulateIsdnChannels(m_hWnd, IDC_EDT_SPID, IDC_EDT_PhoneNumber,
  520. IDC_LBX_Line, IDC_LBX_Variant, m_pisdnci);
  521. ::SetFocus(GetDlgItem(IDC_EDT_PhoneNumber));
  522. // Note the current selections
  523. //
  524. m_pisdnci->nOldBChannel = SendDlgItemMessage(IDC_LBX_Variant,
  525. LB_GETCURSEL, 0, 0);
  526. m_pisdnci->nOldDChannel = SendDlgItemMessage(IDC_LBX_Line,
  527. LB_GETCURSEL, 0, 0);
  528. SendDlgItemMessage(IDC_EDT_PhoneNumber, EM_LIMITTEXT, c_cchMaxOther, 0);
  529. SendDlgItemMessage(IDC_EDT_SPID, EM_LIMITTEXT, c_cchMaxOther, 0);
  530. return FALSE;
  531. }
  532. LRESULT CJapanDlg::OnOk(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  533. BOOL& bHandled)
  534. {
  535. OnIsdnInfoPageTransition(m_hWnd, m_pisdnci);
  536. EndDialog(TRUE);
  537. return 0;
  538. }
  539. LRESULT CJapanDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  540. BOOL& bHandled)
  541. {
  542. EndDialog(FALSE);
  543. return 0;
  544. }
  545. LRESULT CJapanDlg::OnSelChange(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  546. BOOL& bHandled)
  547. {
  548. if (wNotifyCode == LBN_SELCHANGE)
  549. {
  550. OnIsdnInfoPageSelChange(m_hWnd, m_pisdnci);
  551. }
  552. return 0;
  553. }
  554. LRESULT CJapanDlg::OnHelp(UINT uMsg, WPARAM wParam, LPARAM lParam,
  555. BOOL& bHandled)
  556. {
  557. OnHelpGeneric(m_hWnd, (LPHELPINFO)lParam, c_adwContextIdMap, m_pisdnci->idd == IDD_ISDN_JAPAN, c_szIsdnHelpFile);
  558. return TRUE;
  559. }