Leaked source code of windows server 2003
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.

1869 lines
47 KiB

  1. /* File: D:\WACKER\cncttapi\phonedlg.c (Created: 23-Mar-1994)
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 40 $
  7. * $Date: 7/12/02 8:08a $
  8. */
  9. #define TAPI_CURRENT_VERSION 0x00010004 // cab:11/14/96 - required!
  10. #undef MODEM_NEGOTIATED_DCE_RATE
  11. #include <tapi.h>
  12. #include <unimodem.h>
  13. #pragma hdrstop
  14. #include <prsht.h>
  15. #include <shlobj.h>
  16. #include <time.h>
  17. #include <limits.h>
  18. #include <tdll\stdtyp.h>
  19. #include <tdll\session.h>
  20. #include <tdll\tdll.h>
  21. #include <tdll\misc.h>
  22. #include <tdll\mc.h>
  23. #include <tdll\com.h>
  24. #include <tdll\assert.h>
  25. #include <tdll\errorbox.h>
  26. #include <tdll\cnct.h>
  27. #include <tdll\hlptable.h>
  28. #include <tdll\globals.h>
  29. #include <tdll\property.h>
  30. #include <tdll\htchar.h>
  31. #include <term\res.h>
  32. #if defined(INCL_MINITEL)
  33. #include "emu\emu.h"
  34. #endif // INCL_MINITEL
  35. #include "cncttapi.hh"
  36. #include "cncttapi.h"
  37. STATIC_FUNC int tapi_SAVE_NEWPHONENUM(HWND hwnd);
  38. STATIC_FUNC LRESULT tapi_WM_NOTIFY(const HWND hwnd, const int nId);
  39. STATIC_FUNC void EnableCCAC(const HWND hwnd);
  40. STATIC_FUNC void ModemCheck(const HWND hwnd);
  41. static int ValidatePhoneDlg(const HWND hwnd);
  42. static int CheckWindow(const HWND hwnd, const int id, const UINT iErrMsg);
  43. static int VerifyAddress(const HWND hwnd);
  44. #if defined(INCL_WINSOCK)
  45. static int VerifyHost(const HWND hwnd);
  46. #endif //INCL_WINSOCK
  47. STATIC_FUNC int wsck_SAVE_NEWIPADDR(HWND hwnd);
  48. // Local structure...
  49. // Put in whatever else you might need to access later
  50. //
  51. typedef struct SDS
  52. {
  53. HSESSION hSession;
  54. HDRIVER hDriver;
  55. // Store these so that we can restore the values if the user cancels
  56. // the property sheet.
  57. //
  58. TCHAR acSessNameCopy[256];
  59. int nIconID;
  60. HICON hIcon;
  61. //HICON hLittleIcon;
  62. } SDS, *pSDS;
  63. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  64. * FUNCTION:
  65. * NewPhoneDlg
  66. *
  67. * DESCRIPTION:
  68. * Displays dialog for getting new connection phone number and info.
  69. *
  70. * NOTE: Since this dialog proc is also called by the property sheet's
  71. * phone number tab dialog it has to assume that the lPar contains the
  72. * LPPROPSHEETPAGE.
  73. *
  74. * ARGUMENTS:
  75. * Standard dialog
  76. *
  77. * RETURNS:
  78. * Standard dialog
  79. *
  80. */
  81. INT_PTR CALLBACK NewPhoneDlg(HWND hwnd, UINT uMsg, WPARAM wPar, LPARAM lPar)
  82. {
  83. /*
  84. * NOTE: these defines must match the templates in both places, here and
  85. * int term\dialogs.rc
  86. */
  87. #define IDC_TF_CNTRYCODES 113
  88. #define IDC_TF_AREACODES 106
  89. #define IDC_TF_MODEMS 110
  90. #define IDC_TF_PHONENUM 108
  91. #define IDC_IC_ICON 101
  92. #define IDC_CB_CNTRYCODES 114
  93. #define IDC_EB_AREACODE 107
  94. #define IDC_EB_PHONENUM 109
  95. #define IDC_CB_MODEMS 111
  96. #define IDC_TB_NAME 103
  97. #define IDC_PB_EDITICON 117
  98. #define IDC_PB_CONFIGURE 115
  99. #define IDC_XB_USECCAC 116
  100. #define IDC_XB_REDIAL 119
  101. #define IDC_XB_CDPROMPT 120
  102. #define IDC_EB_HOSTADDR 214
  103. #define IDC_TF_PHONEDETAILS 105
  104. #define IDC_TF_TCPIPDETAILS 205
  105. #define IDC_TF_HOSTADDR 213
  106. #define IDC_TF_PORTNUM 206
  107. #define IDC_EB_PORTNUM 207
  108. #define IDC_TF_ACPROMPT 118
  109. HWND hWindow;
  110. HHDRIVER hhDriver;
  111. TCHAR ach[256];
  112. TCHAR acNameCopy[256];
  113. int i;
  114. PSTLINEIDS pstLineIds = NULL;
  115. TCHAR achSettings[100];
  116. static DWORD aHlpTable[] = {IDC_CB_CNTRYCODES, IDH_TERM_NEWPHONE_COUNTRY,
  117. IDC_TF_CNTRYCODES, IDH_TERM_NEWPHONE_COUNTRY,
  118. IDC_EB_AREACODE, IDH_TERM_NEWPHONE_AREA,
  119. IDC_TF_AREACODES, IDH_TERM_NEWPHONE_AREA,
  120. IDC_EB_PHONENUM, IDH_TERM_NEWPHONE_NUMBER,
  121. IDC_TF_PHONENUM, IDH_TERM_NEWPHONE_NUMBER,
  122. IDC_PB_CONFIGURE, IDH_TERM_NEWPHONE_CONFIGURE,
  123. IDC_TF_MODEMS, IDH_TERM_NEWPHONE_DEVICE,
  124. IDC_CB_MODEMS, IDH_TERM_NEWPHONE_DEVICE,
  125. IDC_PB_EDITICON, IDH_TERM_PHONEPROP_CHANGEICON,
  126. IDC_XB_USECCAC, IDH_TERM_NEWPHONE_USECCAC,
  127. IDC_XB_REDIAL, IDH_TERM_NEWPHONE_REDIAL,
  128. IDC_EB_HOSTADDR, IDH_TERM_NEWPHONE_HOSTADDRESS,
  129. IDC_TF_HOSTADDR, IDH_TERM_NEWPHONE_HOSTADDRESS,
  130. IDC_EB_PORTNUM, IDH_TERM_NEWPHONE_PORTNUMBER,
  131. IDC_TF_PORTNUM, IDH_TERM_NEWPHONE_PORTNUMBER,
  132. IDC_XB_CDPROMPT, IDH_TERM_NEWPHONE_CARRIERDETECT,
  133. IDCANCEL, IDH_CANCEL,
  134. IDOK, IDH_OK,
  135. 0,0,
  136. };
  137. pSDS pS = NULL;
  138. switch (uMsg)
  139. {
  140. case WM_INITDIALOG:
  141. pS = (SDS *)malloc(sizeof(SDS));
  142. if (pS == (SDS *)0)
  143. {
  144. assert(FALSE);
  145. EndDialog(hwnd, FALSE);
  146. break;
  147. }
  148. // In the effort to keep the internal driver handle internal
  149. // we are passing the session handle from the property sheet tab
  150. // dialog.
  151. //
  152. pS->hSession = (HSESSION)(((LPPROPSHEETPAGE)lPar)->lParam);
  153. pS->hDriver = cnctQueryDriverHdl(sessQueryCnctHdl(pS->hSession));
  154. hhDriver = (HHDRIVER)(pS->hDriver);
  155. SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)pS);
  156. // In order to center the property sheet we need to center the parent
  157. // of the hwnd on top of the session window.
  158. // If the parent of hwnd is the session window then this dialog has
  159. // not been called from the property sheet.
  160. //
  161. hWindow = GetParent(hwnd);
  162. if (hWindow != sessQueryHwnd(pS->hSession))
  163. {
  164. mscCenterWindowOnWindow(hWindow, sessQueryHwnd(pS->hSession));
  165. }
  166. else
  167. {
  168. mscCenterWindowOnWindow(hwnd, sessQueryHwnd(pS->hSession));
  169. }
  170. // Display the session icon...
  171. //
  172. pS->nIconID = sessQueryIconID(hhDriver->hSession);
  173. pS->hIcon = sessQueryIcon(hhDriver->hSession);
  174. //pS->hLittleIcon = sessQueryLittleIcon(hhDriver->hSession);
  175. SendDlgItemMessage(hwnd, IDC_IC_ICON, STM_SETICON,
  176. (WPARAM)pS->hIcon, 0);
  177. /* --- Need to initialize TAPI if not already done --- */
  178. if (hhDriver->hLineApp == 0)
  179. {
  180. extern const TCHAR *g_achApp;
  181. if (lineInitialize(&hhDriver->hLineApp, glblQueryDllHinst(),
  182. lineCallbackFunc, g_achApp, &hhDriver->dwLineCnt))
  183. {
  184. assert(FALSE);
  185. }
  186. }
  187. SendDlgItemMessage(hwnd, IDC_EB_PHONENUM, EM_SETLIMITTEXT,
  188. sizeof(hhDriver->achDest)-1, 0);
  189. SendDlgItemMessage(hwnd, IDC_EB_AREACODE, EM_SETLIMITTEXT,
  190. sizeof(hhDriver->achAreaCode)-1, 0);
  191. if (hhDriver->achDest[0])
  192. SetDlgItemText(hwnd, IDC_EB_PHONENUM, hhDriver->achDest);
  193. #if defined(INCL_WINSOCK)
  194. SendDlgItemMessage(hwnd, IDC_EB_HOSTADDR, EM_SETLIMITTEXT,
  195. sizeof(hhDriver->achDestAddr)-1, 0);
  196. if (hhDriver->achDestAddr[0])
  197. SetDlgItemText(hwnd, IDC_EB_HOSTADDR, hhDriver->achDestAddr);
  198. SetDlgItemInt(hwnd, IDC_EB_PORTNUM, hhDriver->iPort, FALSE);
  199. //
  200. // Since the port must be numeric currently and the max size is
  201. // USHRT_MAX, we only need 5 characters here.
  202. //
  203. SendDlgItemMessage(hwnd, IDC_EB_PORTNUM, EM_LIMITTEXT, 5, 0);
  204. #endif
  205. TCHAR_Fill(pS->acSessNameCopy, TEXT('\0'),
  206. sizeof(pS->acSessNameCopy) / sizeof(TCHAR));
  207. sessQueryName(hhDriver->hSession, pS->acSessNameCopy,
  208. sizeof(pS->acSessNameCopy));
  209. TCHAR_Fill(ach, TEXT('\0'), sizeof(ach) / sizeof(TCHAR));
  210. StrCharCopyN(ach, pS->acSessNameCopy, sizeof(ach) / sizeof(TCHAR));
  211. mscModifyToFit(GetDlgItem(hwnd, IDC_TB_NAME), ach, SS_WORDELLIPSIS);
  212. SetDlgItemText(hwnd, IDC_TB_NAME, ach);
  213. EnumerateCountryCodes(hhDriver, GetDlgItem(hwnd, IDC_CB_CNTRYCODES));
  214. EnumerateAreaCodes(hhDriver, GetDlgItem(hwnd, IDC_EB_AREACODE));
  215. hWindow = GetDlgItem(hwnd, IDC_CB_MODEMS);
  216. if (hWindow)
  217. {
  218. if ( IsNT() )
  219. {
  220. EnumerateLinesNT(hhDriver, hWindow);
  221. }
  222. else
  223. {
  224. EnumerateLines(hhDriver, hWindow);
  225. }
  226. //mpt 6-23-98 disable the port list drop-down if we are connected
  227. EnableWindow(hWindow, cnctdrvQueryStatus(hhDriver) == CNCT_STATUS_FALSE);
  228. //
  229. // Set Extended UI functionality for the "Connect Using:"
  230. // dropdown list. REV: 2/1/2002
  231. //
  232. SendMessage(hWindow, CB_SETEXTENDEDUI, TRUE, 0);
  233. //
  234. // Set the width of the dropdown list for the "Connect Using:"
  235. // dropdown list. TODO:REV: 2/1/2002
  236. //
  237. }
  238. if (hhDriver->fUseCCAC) // Use country code and area code?
  239. {
  240. CheckDlgButton(hwnd, IDC_XB_USECCAC, TRUE);
  241. SetFocus(GetDlgItem(hwnd, IDC_EB_PHONENUM));
  242. }
  243. #if defined(INCL_REDIAL_ON_BUSY)
  244. if (hhDriver->fRedialOnBusy)
  245. {
  246. CheckDlgButton(hwnd, IDC_XB_REDIAL, TRUE);
  247. SetFocus(GetDlgItem(hwnd, IDC_EB_PHONENUM));
  248. }
  249. #endif
  250. if (hhDriver->fCarrierDetect)
  251. {
  252. CheckDlgButton(hwnd, IDC_XB_CDPROMPT, TRUE);
  253. }
  254. // Call after Use CCAC checkbox checked or unchecked.
  255. //
  256. EnableCCAC(hwnd);
  257. #if DEADWOOD //This is now done in ModemCheck(). REV: 11/9/2001
  258. /* --- Pick which control to give focus too --- */
  259. if (hhDriver->fUseCCAC) // Use country code and area code?
  260. {
  261. if (SendDlgItemMessage(hwnd, IDC_CB_CNTRYCODES, CB_GETCURSEL,
  262. 0, 0) == CB_ERR)
  263. {
  264. SetFocus(GetDlgItem(hwnd, IDC_CB_CNTRYCODES));
  265. }
  266. else if (GetDlgItemText(hwnd, IDC_EB_AREACODE, ach,
  267. sizeof(ach) / sizeof(TCHAR)) == 0)
  268. {
  269. SetFocus(GetDlgItem(hwnd, IDC_EB_AREACODE));
  270. }
  271. }
  272. #endif // DEADWOOD
  273. // If we have an old session and we have not matched our stored
  274. // permanent line id, then pop-up a message saying the TAPI
  275. // configuration has changed.
  276. //
  277. if (hhDriver->fMatchedPermanentLineID == FALSE &&
  278. hhDriver->dwPermanentLineId != (DWORD)-1 &&
  279. hhDriver->dwPermanentLineId != DIRECT_COMWINSOCK)
  280. {
  281. LoadString(glblQueryDllHinst(), IDS_ER_TAPI_CONFIG,
  282. ach, sizeof(ach) / sizeof(TCHAR));
  283. TimedMessageBox(hwnd, ach, NULL, MB_OK | MB_ICONHAND, 0);
  284. }
  285. else if (hhDriver->fMatchedPermanentLineID == FALSE)
  286. {
  287. LRESULT lr;
  288. #if defined(INCL_WINSOCK)
  289. if (hhDriver->dwPermanentLineId == DIRECT_COMWINSOCK)
  290. {
  291. if (LoadString(glblQueryDllHinst(), IDS_WINSOCK_SETTINGS_STR,
  292. ach, sizeof(ach) / sizeof(TCHAR)) == 0)
  293. {
  294. assert(FALSE);
  295. // The loading of the string has failed from the resource,
  296. // so add the non-localized string here (I don't believe
  297. // this string is ever translated). REV 8/13/99
  298. //
  299. StrCharCopyN(ach, TEXT("TCP/IP (Winsock)"),
  300. sizeof(ach) / sizeof(TCHAR));
  301. }
  302. lr = SendMessage(GetDlgItem(hwnd, IDC_CB_MODEMS),
  303. CB_FINDSTRING, (WPARAM) -1,
  304. (LPARAM) ach);
  305. //
  306. // The existing permanent line id TCP/IP (WinSock),
  307. // so set the combobox to the TCP/IP (WinSock) item
  308. // or the first item in the list if TCP/IP (WinSock)
  309. // is not found. REV: 11/1/2001
  310. //
  311. lr = SendMessage(GetDlgItem(hwnd, IDC_CB_MODEMS),
  312. CB_SETCURSEL, (lr == CB_ERR) ? 0 : lr,
  313. (LPARAM)0);
  314. }
  315. else
  316. #endif //defined(INCL_WINSOCK)
  317. {
  318. //
  319. // No existing permanent line id has been located, so set the
  320. // combobox to the first item in the list. REV: 10/31/2001
  321. //
  322. lr = SendMessage(GetDlgItem(hwnd, IDC_CB_MODEMS),
  323. CB_SETCURSEL, (WPARAM)0, (LPARAM)0);
  324. }
  325. }
  326. ModemCheck(hwnd);
  327. return 0;
  328. case WM_CONTEXTMENU:
  329. doContextHelp(aHlpTable, wPar, lPar, TRUE, TRUE);
  330. break;
  331. case WM_HELP:
  332. doContextHelp(aHlpTable, wPar, lPar, FALSE, FALSE);
  333. break;
  334. case WM_DESTROY:
  335. // OK, now we know that we are actually leaving the dialog for good, so
  336. // free the storage...
  337. //
  338. pS = (pSDS)GetWindowLongPtr(hwnd, DWLP_USER);
  339. if (pS)
  340. {
  341. free(pS);
  342. pS = NULL;
  343. }
  344. mscResetComboBox(GetDlgItem(hwnd, IDC_CB_MODEMS));
  345. break;
  346. case WM_NOTIFY:
  347. //
  348. // Property sheet messages are being channeled through here...
  349. //
  350. return tapi_WM_NOTIFY(hwnd, (int)((NMHDR *)lPar)->code);
  351. case WM_COMMAND:
  352. switch (LOWORD(wPar))
  353. {
  354. case IDC_CB_CNTRYCODES:
  355. if (HIWORD(wPar) == CBN_SELENDOK)
  356. {
  357. EnableCCAC(hwnd);
  358. }
  359. break;
  360. case IDC_CB_MODEMS:
  361. {
  362. INT message = HIWORD(wPar);
  363. if (message == CBN_SELENDOK ||
  364. message == CBN_KILLFOCUS ||
  365. message == CBN_CLOSEUP)
  366. {
  367. ModemCheck(hwnd);
  368. }
  369. }
  370. break;
  371. //
  372. // Property sheet's TAB_PHONENUMBER dialog is using this dialog proc
  373. // also, the following two buttons appear only in this tabbed dialog
  374. // template.
  375. //
  376. case IDC_PB_EDITICON:
  377. {
  378. pS = (pSDS)GetWindowLongPtr(hwnd, DWLP_USER);
  379. sessQueryName(pS->hSession, acNameCopy, sizeof(acNameCopy));
  380. if (DialogBoxParam(glblQueryDllHinst(),
  381. MAKEINTRESOURCE(IDD_NEWCONNECTION),
  382. hwnd, NewConnectionDlg,
  383. (LPARAM)pS->hSession) == FALSE)
  384. {
  385. return 0;
  386. }
  387. SetFocus(GetDlgItem(hwnd, IDC_PB_EDITICON));
  388. ach[0] = TEXT('\0');
  389. sessQueryName(pS->hSession, ach, sizeof(ach));
  390. mscModifyToFit(GetDlgItem(hwnd, IDC_TB_NAME), ach, SS_WORDELLIPSIS);
  391. SetDlgItemText(hwnd, IDC_TB_NAME, ach);
  392. SendDlgItemMessage(hwnd, IDC_IC_ICON, STM_SETICON,
  393. (WPARAM)sessQueryIcon(pS->hSession), 0);
  394. // The user may have changed the name of the session.
  395. // The new name should be reflected in the property sheet title
  396. // and in the app title.
  397. //
  398. propUpdateTitle(pS->hSession, hwnd, acNameCopy);
  399. }
  400. break;
  401. case IDC_PB_CONFIGURE:
  402. pS = (pSDS)GetWindowLongPtr(hwnd, DWLP_USER);
  403. hhDriver = (HHDRIVER)(pS->hDriver);
  404. if ((i = (int)SendDlgItemMessage(hwnd, IDC_CB_MODEMS, CB_GETCURSEL,
  405. 0, 0)) != CB_ERR)
  406. {
  407. if (((LRESULT)pstLineIds = SendDlgItemMessage(hwnd,
  408. IDC_CB_MODEMS, CB_GETITEMDATA, (WPARAM)i, 0))
  409. != CB_ERR)
  410. {
  411. if (pstLineIds != NULL &&
  412. (LRESULT)pstLineIds != CB_ERR)
  413. {
  414. BOOL fIsSerialPort = FALSE;
  415. // I've "reserved" 4 permanent line ids to indentify
  416. // the direct to com port lines.
  417. //
  418. if (IN_RANGE(pstLineIds->dwPermanentLineId,
  419. DIRECT_COM1, DIRECT_COM4))
  420. {
  421. if (pstLineIds != NULL)
  422. {
  423. wsprintf(ach, TEXT("COM%d"),
  424. pstLineIds->dwPermanentLineId - DIRECT_COM1 + 1);
  425. }
  426. fIsSerialPort = TRUE;
  427. }
  428. else if ( IsNT() && pstLineIds->dwPermanentLineId == DIRECT_COM_DEVICE)
  429. {
  430. // Get device from combobox... mrw:6/5/96
  431. //
  432. SendDlgItemMessage(hwnd, IDC_CB_MODEMS,
  433. CB_GETLBTEXT, (WPARAM)i,(LPARAM)ach);
  434. fIsSerialPort = TRUE;
  435. }
  436. if (fIsSerialPort == TRUE)
  437. {
  438. HCOM hCom = sessQueryComHdl(pS->hSession);
  439. TCHAR szPortName[MAX_PATH];
  440. ComGetPortName(hCom, szPortName, MAX_PATH);
  441. if (StrCharCmp(szPortName, ach) != 0 )
  442. {
  443. ComSetPortName(hCom, ach);
  444. // mrw: 2/20/96 - Set AutoDetect off if user clicks
  445. // OK in this dialog.
  446. //
  447. if (ComDriverSpecial(hCom, "GET Defaults", NULL, 0) != COM_OK)
  448. {
  449. assert(FALSE);
  450. }
  451. ComSetAutoDetect(hCom, FALSE);
  452. ComConfigurePort(hCom);
  453. ComSetPortName(sessQueryComHdl(pS->hSession), ach);
  454. }
  455. }
  456. // mrw: 2/20/96 - Set AutoDetect off if user clicks
  457. // OK in this dialog.
  458. //
  459. if (fIsSerialPort == TRUE &&
  460. ComDeviceDialog(sessQueryComHdl(pS->hSession), hwnd) == COM_OK)
  461. {
  462. ComSetAutoDetect(sessQueryComHdl(pS->hSession), FALSE);
  463. ComConfigurePort(sessQueryComHdl(pS->hSession));
  464. }
  465. else
  466. {
  467. #if RESET_DEVICE_SETTINGS
  468. LPVARSTRING pvs = NULL;
  469. int lReturn;
  470. LPVOID pv = NULL;
  471. lReturn = cncttapiGetLineConfig( pstLineIds->dwLineId, (VOID **) &pvs );
  472. if (lReturn != 0)
  473. {
  474. if (pvs != NULL)
  475. {
  476. free(pvs);
  477. pvs = NULL;
  478. }
  479. return FALSE;
  480. }
  481. #endif
  482. //
  483. // Get the current settings.
  484. //
  485. cncttapiGetCOMSettings(pstLineIds->dwLineId,
  486. ach,
  487. sizeof(ach) / sizeof(TCHAR));
  488. //
  489. // rev: 11/30/00 - Set AutoDetect off if user clicks
  490. // OK in this dialog.
  491. //
  492. lineConfigDialog(pstLineIds->dwLineId,
  493. hwnd, DEVCLASS);
  494. //
  495. // Get the new settings.
  496. //
  497. cncttapiGetCOMSettings(pstLineIds->dwLineId,
  498. achSettings,
  499. sizeof(achSettings) / sizeof(TCHAR));
  500. #if RESET_DEVICE_SETTINGS
  501. //
  502. // Return the settings back to what they were before our dialog was displayed.
  503. //
  504. if (pvs != NULL)
  505. {
  506. pv = (BYTE *)pvs + pvs->dwStringOffset;
  507. lReturn = lineSetDevConfig(pstLineIds->dwLineId, pv,
  508. pvs->dwStringSize, DEVCLASS);
  509. free(pvs);
  510. pvs = NULL;
  511. if (lReturn != 0)
  512. {
  513. assert(FALSE);
  514. return FALSE;
  515. }
  516. }
  517. #endif
  518. //
  519. // See if the settings have changed. If so, then turn off
  520. // AutoDetect. REV: 12/01/2000
  521. //
  522. if (StrCharCmpi(ach, achSettings) != 0)
  523. {
  524. ComSetAutoDetect(sessQueryComHdl(pS->hSession), FALSE);
  525. }
  526. }
  527. }
  528. }
  529. }
  530. else
  531. {
  532. mscMessageBeep(MB_ICONHAND);
  533. }
  534. break;
  535. case IDC_XB_USECCAC:
  536. EnableCCAC(hwnd);
  537. break;
  538. case IDOK:
  539. if (ValidatePhoneDlg(hwnd) == 0 &&
  540. tapi_SAVE_NEWPHONENUM(hwnd) == 0)
  541. {
  542. EndDialog(hwnd, TRUE);
  543. }
  544. break;
  545. case IDCANCEL:
  546. EndDialog(hwnd, FALSE);
  547. break;
  548. default:
  549. return FALSE;
  550. }
  551. break;
  552. default:
  553. return FALSE;
  554. }
  555. return TRUE;
  556. }
  557. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  558. * FUNCTION:
  559. * tapi_WM_NOTIFY
  560. *
  561. * DESCRIPTION:
  562. * Process Property Sheet Notification messages.
  563. *
  564. * ARGUMENTS:
  565. *
  566. * RETURNS:
  567. *
  568. */
  569. STATIC_FUNC LRESULT tapi_WM_NOTIFY(const HWND hDlg, const int nId)
  570. {
  571. pSDS pS;
  572. LRESULT lReturn = FALSE;
  573. switch (nId)
  574. {
  575. default:
  576. break;
  577. case PSN_APPLY:
  578. pS = (pSDS)GetWindowLongPtr(hDlg, DWLP_USER);
  579. if (pS)
  580. {
  581. //
  582. // Do whatever saving is necessary
  583. //
  584. if (ValidatePhoneDlg(hDlg) != 0 || tapi_SAVE_NEWPHONENUM(hDlg) != 0)
  585. {
  586. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, (LONG_PTR)TRUE);
  587. lReturn = TRUE;
  588. }
  589. }
  590. break;
  591. case PSN_RESET:
  592. pS = (pSDS)GetWindowLongPtr(hDlg, DWLP_USER);
  593. if (pS)
  594. {
  595. //
  596. // If the user cancels make sure the old session name and its
  597. // icon are restored.
  598. //
  599. sessSetName(pS->hSession, pS->acSessNameCopy);
  600. sessSetIconID(pS->hSession, pS->nIconID);
  601. sessUpdateAppTitle(pS->hSession);
  602. SendMessage(sessQueryHwnd(pS->hSession), WM_SETICON,
  603. (WPARAM)TRUE, (LPARAM)pS->hIcon);
  604. }
  605. break;
  606. #if 0
  607. case PSN_HASHELP:
  608. // For now gray the help button...
  609. //
  610. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, (LONG_PTR)FALSE);
  611. break;
  612. #endif
  613. case PSN_HELP:
  614. // Display help in whatever way is appropriate
  615. break;
  616. }
  617. return lReturn;
  618. }
  619. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  620. * FUNCTION:
  621. * tapi_SAVE_NEWPHONENUM
  622. *
  623. * DESCRIPTION:
  624. *
  625. * ARGUMENTS:
  626. *
  627. * RETURNS:
  628. *
  629. */
  630. STATIC_FUNC int tapi_SAVE_NEWPHONENUM(HWND hwnd)
  631. {
  632. pSDS pS;
  633. HHDRIVER hhDriver;
  634. LRESULT lr, lrx;
  635. PSTLINEIDS pstLineIds = NULL;
  636. #if defined(INCL_MINITEL)
  637. HCOM hCom;
  638. BOOL fAutoDetect = FALSE;
  639. #endif // INCL_MINITEL
  640. pS = (pSDS)GetWindowLongPtr(hwnd, DWLP_USER);
  641. hhDriver = (HHDRIVER)(pS->hDriver);
  642. /* --- Get selected modem --- */
  643. lrx = SendDlgItemMessage(hwnd, IDC_CB_MODEMS, CB_GETCURSEL, 0, 0);
  644. if (lrx != CB_ERR)
  645. {
  646. lr = SendDlgItemMessage(hwnd, IDC_CB_MODEMS, CB_GETLBTEXT, (WPARAM)lrx,
  647. (LPARAM)hhDriver->achLineName);
  648. if (lr != CB_ERR)
  649. {
  650. pstLineIds = (PSTLINEIDS)SendDlgItemMessage(hwnd, IDC_CB_MODEMS,
  651. CB_GETITEMDATA, (WPARAM)lrx, 0);
  652. if ((LRESULT)pstLineIds != CB_ERR)
  653. {
  654. hhDriver->dwPermanentLineId = pstLineIds->dwPermanentLineId;
  655. hhDriver->dwLine = pstLineIds->dwLineId;
  656. if ( IsNT() )
  657. {
  658. if (hhDriver->dwPermanentLineId == DIRECT_COM_DEVICE)
  659. {
  660. SendDlgItemMessage(hwnd, IDC_CB_MODEMS,
  661. CB_GETLBTEXT, (WPARAM)lrx,
  662. (LPARAM)hhDriver->achComDeviceName);
  663. }
  664. }
  665. }
  666. else
  667. {
  668. assert(FALSE);
  669. }
  670. }
  671. else
  672. {
  673. assert(FALSE);
  674. }
  675. }
  676. else
  677. {
  678. //
  679. // Invalid port number.
  680. //
  681. TCHAR acBuffer[256];
  682. TCHAR acFormat[256];
  683. //
  684. // Display an error message.
  685. //
  686. if (LoadString(glblQueryDllHinst(), IDS_ER_TAPI_CONFIG, acFormat, 256) == 0)
  687. {
  688. acBuffer[0] = TEXT('\0');
  689. }
  690. //
  691. // Set the focus to the invalid control and display an error.
  692. //
  693. SetFocus(GetDlgItem(hwnd, IDC_CB_MODEMS));
  694. TimedMessageBox(hwnd, acBuffer, NULL, MB_OK | MB_ICONEXCLAMATION, 0);
  695. return 1;
  696. }
  697. /* --- Get Country Code --- */
  698. if (IsWindowEnabled(GetDlgItem(hwnd, IDC_CB_CNTRYCODES)))
  699. {
  700. lr = SendDlgItemMessage(hwnd, IDC_CB_CNTRYCODES, CB_GETCURSEL, 0, 0);
  701. if (lr != CB_ERR)
  702. {
  703. lr = SendDlgItemMessage(hwnd, IDC_CB_CNTRYCODES, CB_GETITEMDATA,
  704. (WPARAM)lr, 0);
  705. if (lr != CB_ERR)
  706. {
  707. hhDriver->dwCountryID = (DWORD)lr;
  708. }
  709. else
  710. {
  711. assert(FALSE);
  712. }
  713. }
  714. }
  715. /* --- Get area code --- */
  716. if (IsWindowEnabled(GetDlgItem(hwnd, IDC_EB_AREACODE)))
  717. {
  718. GetDlgItemText(hwnd, IDC_EB_AREACODE, hhDriver->achAreaCode,
  719. sizeof(hhDriver->achAreaCode) / sizeof(TCHAR));
  720. }
  721. /* --- Get phone number --- */
  722. if (IsWindowEnabled(GetDlgItem(hwnd, IDC_EB_PHONENUM)))
  723. {
  724. GetDlgItemText(hwnd, IDC_EB_PHONENUM, hhDriver->achDest,
  725. sizeof(hhDriver->achDest) / sizeof(TCHAR));
  726. }
  727. #if defined(INCL_WINSOCK)
  728. if (IsWindowEnabled(GetDlgItem(hwnd, IDC_EB_HOSTADDR)))
  729. {
  730. GetDlgItemText(hwnd, IDC_EB_HOSTADDR, hhDriver->achDestAddr,
  731. sizeof(hhDriver->achDestAddr) / sizeof(TCHAR));
  732. }
  733. if (IsWindowEnabled(GetDlgItem(hwnd, IDC_EB_PORTNUM)))
  734. {
  735. BOOL fTranslated = FALSE;
  736. int nValue = GetDlgItemInt(hwnd, IDC_EB_PORTNUM, &fTranslated, TRUE);
  737. //
  738. // NOTE: The values for the port must is set based upon the
  739. // struct sockaddr_in sin_port (which is defined as unsigned short)
  740. // and values accepted by connect(). REV: 4/11/2002
  741. //
  742. if (fTranslated && nValue <= USHRT_MAX)
  743. {
  744. hhDriver->iPort = nValue;
  745. }
  746. else
  747. {
  748. //
  749. // Invalid port number.
  750. //
  751. TCHAR acBuffer[256];
  752. TCHAR acFormat[256];
  753. //
  754. // Display an error message.
  755. //
  756. if (LoadString(glblQueryDllHinst(), IDS_ER_INVALID_PORT, acFormat, 256) == 0)
  757. {
  758. StrCharCopyN(acFormat,
  759. TEXT("Invalid port number. Port number must be between %d and %d."),
  760. 256);
  761. }
  762. //
  763. // The port must be between 0 and USHRT_MAX.
  764. //
  765. wsprintf(acBuffer, acFormat, 0, USHRT_MAX);
  766. //
  767. // Set the focus to the invalid control and display an error.
  768. //
  769. SetFocus(GetDlgItem(hwnd, IDC_EB_PORTNUM));
  770. TimedMessageBox(hwnd, acBuffer, NULL, MB_OK | MB_ICONEXCLAMATION, 0);
  771. return 1;
  772. }
  773. }
  774. #endif // defined(INCL_WINSOCK)
  775. /* --- Get Use country code, area code info --- */
  776. if (IsWindowEnabled(GetDlgItem(hwnd, IDC_XB_USECCAC)))
  777. {
  778. hhDriver->fUseCCAC = (IsDlgButtonChecked(hwnd, IDC_XB_USECCAC) == BST_CHECKED);
  779. }
  780. #if defined(INCL_REDIAL_ON_BUSY)
  781. /* --- Get Redial on Busy setting --- */
  782. if (IsWindowEnabled(GetDlgItem(hwnd, IDC_XB_REDIAL)))
  783. {
  784. hhDriver->fRedialOnBusy =
  785. (IsDlgButtonChecked(hwnd, IDC_XB_REDIAL) == BST_CHECKED);
  786. }
  787. #endif
  788. if (IsWindowEnabled(GetDlgItem(hwnd, IDC_XB_CDPROMPT)))
  789. {
  790. hhDriver->fCarrierDetect = (IsDlgButtonChecked(hwnd, IDC_XB_CDPROMPT) == BST_CHECKED);
  791. if (!hhDriver->fCarrierDetect)
  792. {
  793. hhDriver->stCallPar.dwBearerMode = 0;
  794. }
  795. else if (cnctdrvQueryStatus(hhDriver) != CNCT_STATUS_FALSE)
  796. {
  797. NotifyClient(hhDriver->hSession, EVENT_LOST_CONNECTION,
  798. CNCT_LOSTCARRIER | (sessQueryExit(hhDriver->hSession) ? DISCNCT_EXIT : 0 ));
  799. }
  800. }
  801. #if defined (INCL_MINITEL)
  802. hCom = sessQueryComHdl(pS->hSession);
  803. if (hCom && ComValidHandle(hCom) &&
  804. ComGetAutoDetect(hCom, &fAutoDetect) == COM_OK &&
  805. fAutoDetect == TRUE)
  806. {
  807. HEMU hEmu = sessQueryEmuHdl(pS->hSession);
  808. if (hEmu && emuQueryEmulatorId(hEmu) == EMU_MINI)
  809. {
  810. //
  811. // Set to seven bit, even parity, and 1 stop bit (7E1),
  812. // This is only done when the Minitel emulator is selected.
  813. // The user can change the COM settings manually after this
  814. // point.
  815. //
  816. ComSetDataBits(hCom, 7);
  817. ComSetParity(hCom, EVENPARITY);
  818. ComSetStopBits(hCom, ONESTOPBIT);
  819. ComSetAutoDetect(hCom, FALSE);
  820. cncttapiSetLineConfig(hhDriver->dwLine, hCom);
  821. }
  822. }
  823. #endif //INCL_MINITEL
  824. return 0;
  825. }
  826. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  827. * FUNCTION:
  828. * EnableCCAC
  829. *
  830. * DESCRIPTION:
  831. * Enables/disables controls associated with the Use Country Code,
  832. * Area Code control
  833. *
  834. * ARGUMENTS:
  835. * hwnd - dialog window
  836. *
  837. * RETURNS:
  838. * void
  839. *
  840. */
  841. STATIC_FUNC void EnableCCAC(const HWND hwnd)
  842. {
  843. BOOL fUseCCAC = TRUE;
  844. BOOL fUseAC = TRUE;
  845. DWORD dwCountryId;
  846. pSDS pS;
  847. HHDRIVER hhDriver;
  848. LRESULT lr;
  849. // Different templates use this same dialog proc. If this window
  850. // is not there, don't do the work. Also, selection of the direct
  851. // connect stuff can disable the control.
  852. if (IsWindowEnabled(GetDlgItem(hwnd, IDC_XB_USECCAC)))
  853. {
  854. fUseCCAC = (IsDlgButtonChecked(hwnd, IDC_XB_USECCAC) == BST_CHECKED);
  855. EnableWindow(GetDlgItem(hwnd, IDC_CB_CNTRYCODES), fUseCCAC);
  856. }
  857. // We want to enable the area code only if both the use Country
  858. // code, Area code checkbox is checked and the country in
  859. // question uses area codes. - mrw, 2/12/95
  860. //
  861. pS = (pSDS)GetWindowLongPtr(hwnd, DWLP_USER);
  862. hhDriver = (HHDRIVER)(pS->hDriver);
  863. // Country code from dialog
  864. //
  865. lr = SendDlgItemMessage(hwnd, IDC_CB_CNTRYCODES, CB_GETCURSEL, 0, 0);
  866. if (lr != CB_ERR)
  867. {
  868. lr = SendDlgItemMessage(hwnd, IDC_CB_CNTRYCODES, CB_GETITEMDATA,
  869. (WPARAM)lr, 0);
  870. if (lr != CB_ERR)
  871. dwCountryId = (DWORD)lr;
  872. #if defined(DEADWOOD)
  873. fUseAC = fCountryUsesAreaCode(dwCountryId, hhDriver->dwAPIVersion);
  874. #else // defined(DEADWOOD)
  875. fUseAC = TRUE; // Microsoft changed its mind on this one -mrw:4/20/95
  876. #endif // defined(DEADWOOD)
  877. }
  878. EnableWindow(GetDlgItem(hwnd, IDC_EB_AREACODE), fUseCCAC && fUseAC);
  879. return;
  880. }
  881. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  882. * FUNCTION:
  883. * ModemCheck
  884. *
  885. * DESCRIPTION:
  886. * Checks if the currently selected "modem" is one of the Direct to Com?
  887. * selections. If it is, it disables the country code, area code, phone
  888. * number, and Use country code area code check box.
  889. *
  890. * ARGUMENTS:
  891. * hwnd - dialog window handle
  892. *
  893. * RETURNS:
  894. * void
  895. *
  896. */
  897. STATIC_FUNC void ModemCheck(const HWND hwnd)
  898. {
  899. int fModem;
  900. int fHotPhone;
  901. int fWinSock;
  902. LRESULT lr;
  903. PSTLINEIDS pstLineIds = NULL;
  904. HHDRIVER hhDriver;
  905. const pSDS pS = (pSDS)GetWindowLongPtr(hwnd, DWLP_USER);
  906. const HWND hwndCB = GetDlgItem(hwnd, IDC_CB_MODEMS);
  907. HWND hwndTmp;
  908. if (!IsWindow(hwndCB))
  909. return;
  910. if ((lr = SendMessage(hwndCB, CB_GETCURSEL, 0, 0)) != CB_ERR)
  911. {
  912. pstLineIds = (PSTLINEIDS)SendMessage(hwndCB, CB_GETITEMDATA, lr, 0);
  913. if ((LRESULT)pstLineIds != CB_ERR)
  914. {
  915. fModem = TRUE;
  916. fWinSock = FALSE;
  917. if ((IN_RANGE(pstLineIds->dwPermanentLineId,
  918. DIRECT_COM1, DIRECT_COM4)) ||
  919. (IsNT() &&
  920. pstLineIds->dwPermanentLineId == DIRECT_COM_DEVICE))
  921. {
  922. fModem = FALSE;
  923. }
  924. #if defined(INCL_WINSOCK)
  925. else if (pstLineIds->dwPermanentLineId == DIRECT_COMWINSOCK)
  926. {
  927. fModem = FALSE;
  928. fWinSock = TRUE;
  929. }
  930. #endif
  931. // Also check if we have a hotphone
  932. //
  933. if (fModem == TRUE && pS)
  934. {
  935. hhDriver = (HHDRIVER)(pS->hDriver);
  936. if (hhDriver)
  937. {
  938. if (CheckHotPhone(hhDriver, pstLineIds->dwLineId,
  939. &fHotPhone) == 0)
  940. {
  941. fModem = !fHotPhone;
  942. }
  943. }
  944. }
  945. // Swap between phone number and host address prompts
  946. if ((hwndTmp = GetDlgItem(hwnd, IDC_TF_PHONEDETAILS)))
  947. {
  948. ShowWindow(hwndTmp, fWinSock ? SW_HIDE : SW_SHOW);
  949. EnableWindow(hwndTmp, fModem);
  950. }
  951. if ((hwndTmp = GetDlgItem(hwnd, IDC_TF_TCPIPDETAILS)))
  952. {
  953. ShowWindow(hwndTmp, fWinSock ? SW_SHOW : SW_HIDE);
  954. }
  955. if ((hwndTmp = GetDlgItem(hwnd, IDC_TF_ACPROMPT)))
  956. {
  957. ShowWindow(hwndTmp, fWinSock ? SW_HIDE : SW_SHOW);
  958. EnableWindow(hwndTmp, fModem);
  959. }
  960. // Swap between Country code and Host address static text
  961. if (hwndTmp = GetDlgItem(hwnd, IDC_TF_CNTRYCODES))
  962. {
  963. ShowWindow(hwndTmp, fWinSock ? SW_HIDE : SW_SHOW);
  964. //
  965. // Changed from ! fWinSock to fModem. REV: 11/7/2001
  966. //
  967. EnableWindow(hwndTmp, fModem);
  968. }
  969. if (hwndTmp = GetDlgItem(hwnd, IDC_TF_HOSTADDR))
  970. {
  971. ShowWindow(hwndTmp, fWinSock ? SW_SHOW : SW_HIDE);
  972. EnableWindow(hwndTmp, fWinSock || fModem);
  973. }
  974. // Swap between country code and host address edit boxes
  975. if (hwndTmp = GetDlgItem(hwnd, IDC_CB_CNTRYCODES))
  976. {
  977. ShowWindow(hwndTmp, fWinSock ? SW_HIDE : SW_SHOW);
  978. EnableWindow(hwndTmp, fModem);
  979. }
  980. if (hwndTmp = GetDlgItem(hwnd, IDC_EB_HOSTADDR))
  981. {
  982. ShowWindow(hwndTmp, fWinSock ? SW_SHOW : SW_HIDE);
  983. EnableWindow(hwndTmp, fWinSock);
  984. }
  985. // Swap between area code and port number static text
  986. if (hwndTmp = GetDlgItem(hwnd, IDC_TF_AREACODES))
  987. {
  988. ShowWindow(hwndTmp, fWinSock ? SW_HIDE : SW_SHOW);
  989. //
  990. // Changed from ! fWinSock to fModem. REV: 11/7/2001
  991. //
  992. EnableWindow(hwndTmp, fModem);
  993. }
  994. if (hwndTmp = GetDlgItem(hwnd, IDC_TF_PORTNUM))
  995. {
  996. ShowWindow(hwndTmp, fWinSock ? SW_SHOW : SW_HIDE);
  997. EnableWindow(hwndTmp, fWinSock);
  998. }
  999. // Swap between area code and port number edit boxes
  1000. if (hwndTmp = GetDlgItem(hwnd, IDC_EB_AREACODE))
  1001. {
  1002. ShowWindow(hwndTmp, fWinSock ? SW_HIDE : SW_SHOW);
  1003. EnableWindow(hwndTmp, fModem);
  1004. }
  1005. if (hwndTmp = GetDlgItem(hwnd, IDC_EB_PORTNUM))
  1006. {
  1007. ShowWindow(hwndTmp, fWinSock ? SW_SHOW : SW_HIDE);
  1008. EnableWindow(hwndTmp, fWinSock);
  1009. }
  1010. if (hwndTmp = GetDlgItem(hwnd, IDC_TF_PHONENUM))
  1011. {
  1012. ShowWindow(hwndTmp, ! fWinSock);
  1013. //
  1014. // Changed from ! fWinSock to fModem. REV: 11/7/2001
  1015. //
  1016. EnableWindow(hwndTmp, fModem);
  1017. }
  1018. if (hwndTmp = GetDlgItem(hwnd, IDC_EB_PHONENUM))
  1019. {
  1020. ShowWindow(hwndTmp, ! fWinSock);
  1021. EnableWindow(hwndTmp, fModem);
  1022. }
  1023. if ((hwndTmp = GetDlgItem(hwnd, IDC_XB_USECCAC)))
  1024. {
  1025. ShowWindow(hwndTmp, ! fWinSock);
  1026. EnableWindow(hwndTmp, fModem);
  1027. }
  1028. if ((hwndTmp = GetDlgItem(hwnd, IDC_PB_CONFIGURE)))
  1029. {
  1030. ShowWindow(hwndTmp, !fWinSock);
  1031. EnableWindow(hwndTmp, !fWinSock);
  1032. if (pS)
  1033. {
  1034. EnableWindow(hwndTmp, cnctdrvQueryStatus((HHDRIVER)(pS->hDriver)) == CNCT_STATUS_FALSE);
  1035. }
  1036. }
  1037. if ((hwndTmp = GetDlgItem(hwnd, IDC_XB_CDPROMPT)))
  1038. {
  1039. ShowWindow(hwndTmp, !fWinSock);
  1040. EnableWindow(hwndTmp, !fWinSock);
  1041. }
  1042. // Set focus to modem combo when direct connect selected.
  1043. // mrw:11/3/95
  1044. //
  1045. if (fWinSock == TRUE)
  1046. {
  1047. hwndTmp = GetDlgItem(hwnd,IDC_EB_HOSTADDR);
  1048. }
  1049. else if (fModem == TRUE)
  1050. {
  1051. hwndTmp = GetDlgItem(hwnd, IDC_EB_PHONENUM);
  1052. }
  1053. else
  1054. {
  1055. hwndTmp = GetDlgItem(hwnd, IDC_PB_CONFIGURE);
  1056. }
  1057. SetFocus(hwndTmp ? hwndTmp : hwndCB);
  1058. #if defined(INCL_REDIAL_ON_BUSY)
  1059. if ((hwndTmp = GetDlgItem(hwnd, IDC_XB_REDIAL)))
  1060. {
  1061. ShowWindow(hwndTmp, ! fWinSock);
  1062. EnableWindow(hwndTmp, fModem);
  1063. }
  1064. #endif
  1065. if (fModem == TRUE)
  1066. {
  1067. EnableCCAC(hwnd);
  1068. }
  1069. }
  1070. }
  1071. return;
  1072. }
  1073. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1074. * FUNCTION:
  1075. * ValidatePhoneDlg
  1076. *
  1077. * DESCRIPTION:
  1078. * Checks phone dialog entries for proper values. This mostly means
  1079. * checking for blank entry fields.
  1080. *
  1081. * ARGUMENTS:
  1082. * hwnd - phone dialog
  1083. *
  1084. * RETURNS:
  1085. * 0=OK,else error
  1086. *
  1087. */
  1088. static int ValidatePhoneDlg(const HWND hwnd)
  1089. {
  1090. int return_value = 0;
  1091. if (CheckWindow(hwnd, IDC_CB_CNTRYCODES, IDS_GNRL_NEED_COUNTRYCODE) != 0)
  1092. {
  1093. return_value = -1;
  1094. }
  1095. #if DEADWOOD //- mrw:4/20/95
  1096. else if (CheckWindow(hwnd, IDC_EB_AREACODE, IDS_GNRL_NEED_AREACODE) != 0)
  1097. {
  1098. return_value = -2;
  1099. }
  1100. #endif // DEADWOOD
  1101. #if DEADWOOD // Removed per MHG discussions - MPT 12/21/95
  1102. else if (CheckWindow(hwnd, IDC_EB_PHONENUM, IDS_GNRL_NEED_PHONENUMBER) != 0)
  1103. {
  1104. return_value = -3;
  1105. }
  1106. #endif // DEADWOOD
  1107. else if (CheckWindow(hwnd, IDC_CB_MODEMS, IDS_GNRL_NEED_CONNECTIONTYPE) != 0)
  1108. {
  1109. return_value = -4;
  1110. }
  1111. else if (VerifyAddress(hwnd) != 0)
  1112. {
  1113. return_value = -5;
  1114. }
  1115. #if defined(INCL_WINSOCK)
  1116. else if (VerifyHost(hwnd) != 0)
  1117. {
  1118. return_value = -6;
  1119. }
  1120. #endif //INCL_WINSOCK
  1121. return return_value;
  1122. }
  1123. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1124. * FUNCTION:
  1125. * CheckWindow
  1126. *
  1127. * DESCRIPTION:
  1128. * Since the dialog only enables windows that require entries, it just
  1129. * needs to check if an enabled window has text. This function sets
  1130. * the focus to the offending field and beeps.
  1131. *
  1132. * ARGUMENTS:
  1133. * hwnd - dialog window
  1134. * id - control id
  1135. * iErrMsg - id of error message to display if field is empty
  1136. *
  1137. * RETURNS:
  1138. * 0=OK, else not ok.
  1139. *
  1140. */
  1141. static int CheckWindow(const HWND hwnd, const int id, const UINT iErrMsg)
  1142. {
  1143. TCHAR ach[256];
  1144. if (IsWindowEnabled(GetDlgItem(hwnd, id)))
  1145. {
  1146. if (GetDlgItemText(hwnd, id, ach, 256) == 0)
  1147. {
  1148. if (iErrMsg != 0)
  1149. {
  1150. //
  1151. // Added the warning dlg with a warning instead of just
  1152. // a warning. rde 31 Oct 01
  1153. //
  1154. LoadString(glblQueryDllHinst(), iErrMsg, ach, 256);
  1155. TimedMessageBox(hwnd, ach, NULL, MB_OK | MB_ICONHAND, 0);
  1156. }
  1157. SetFocus(GetDlgItem(hwnd, id));
  1158. return -1;
  1159. }
  1160. }
  1161. return 0;
  1162. }
  1163. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1164. * FUNCTION:
  1165. * VerifyAddress
  1166. *
  1167. * DESCRIPTION:
  1168. * I can't believe how much code it takes to verify a stinking address.
  1169. *
  1170. * ARGUMENTS:
  1171. * hwnd - dialog window handle.
  1172. *
  1173. * RETURNS:
  1174. * 0=OK
  1175. *
  1176. */
  1177. static int VerifyAddress(const HWND hwnd)
  1178. {
  1179. pSDS pS;
  1180. HHDRIVER hhDriver;
  1181. LRESULT lr, lrx;
  1182. PSTLINEIDS pstLineIds = NULL;
  1183. int fHotPhone;
  1184. int fUseCCAC;
  1185. long lRet;
  1186. DWORD dwSize;
  1187. DWORD dwLine;
  1188. DWORD dwCountryID;
  1189. DWORD dwPermanentLineId;
  1190. TCHAR achAreaCode[10];
  1191. TCHAR achDest[(TAPIMAXDESTADDRESSSIZE/2)+1];
  1192. TCHAR ach[256];
  1193. LPLINECOUNTRYLIST pcl;
  1194. LPLINECOUNTRYENTRY pce;
  1195. LINETRANSLATEOUTPUT *pLnTransOutput;
  1196. pS = (pSDS)GetWindowLongPtr(hwnd, DWLP_USER);
  1197. hhDriver = (HHDRIVER)(pS->hDriver);
  1198. /* --- Get selected modem --- */
  1199. lrx = SendDlgItemMessage(hwnd, IDC_CB_MODEMS, CB_GETCURSEL, 0, 0);
  1200. if (lrx != CB_ERR)
  1201. {
  1202. pstLineIds = (PSTLINEIDS)SendDlgItemMessage(hwnd, IDC_CB_MODEMS,
  1203. CB_GETITEMDATA, (WPARAM)lrx, 0);
  1204. if ((LRESULT)pstLineIds != CB_ERR)
  1205. {
  1206. dwPermanentLineId = pstLineIds->dwPermanentLineId;
  1207. dwLine = pstLineIds->dwLineId;
  1208. }
  1209. }
  1210. else
  1211. {
  1212. return 0;
  1213. }
  1214. /* --- Get Country Code --- */
  1215. if (IsWindowEnabled(GetDlgItem(hwnd, IDC_CB_CNTRYCODES)))
  1216. {
  1217. lr = SendDlgItemMessage(hwnd, IDC_CB_CNTRYCODES, CB_GETCURSEL, 0, 0);
  1218. if (lr != CB_ERR)
  1219. {
  1220. lr = SendDlgItemMessage(hwnd, IDC_CB_CNTRYCODES, CB_GETITEMDATA,
  1221. (WPARAM)lr, 0);
  1222. if (lr != CB_ERR)
  1223. dwCountryID = (DWORD)lr;
  1224. }
  1225. }
  1226. else
  1227. {
  1228. return 0;
  1229. }
  1230. /* --- Get area code --- */
  1231. achAreaCode[0] = TEXT('\0');
  1232. GetDlgItemText(hwnd, IDC_EB_AREACODE, achAreaCode,
  1233. sizeof(achAreaCode) / sizeof(TCHAR));
  1234. /* --- Get phone number --- */
  1235. achDest[0] = TEXT('\0');
  1236. GetDlgItemText(hwnd, IDC_EB_PHONENUM, achDest,
  1237. sizeof(achDest) / sizeof(TCHAR));
  1238. /* --- Get Use country code, area code info --- */
  1239. fUseCCAC = TRUE;
  1240. if (IsWindowEnabled(GetDlgItem(hwnd, IDC_XB_USECCAC)))
  1241. fUseCCAC = (IsDlgButtonChecked(hwnd, IDC_XB_USECCAC) == BST_CHECKED);
  1242. /* --- Try to translate --- */
  1243. if (CheckHotPhone(hhDriver, dwLine, &fHotPhone) != 0)
  1244. {
  1245. assert(0);
  1246. return 0; // error message displayed already.
  1247. }
  1248. // Hot Phone is TAPI terminology for Direct Connects
  1249. // We don't need to do address translation since we
  1250. // not going to use it.
  1251. if (fHotPhone)
  1252. {
  1253. return 0;
  1254. }
  1255. ach[0] = TEXT('\0');
  1256. // If we not using the country code or area code, we still need to
  1257. // pass a dialable string format to TAPI so that we get the
  1258. // pulse/tone dialing modifiers in the dialable string.
  1259. //
  1260. if (fUseCCAC)
  1261. {
  1262. /* --- Do lineGetCountry to get extension --- */
  1263. if (DoLineGetCountry(dwCountryID, TAPI_VER, &pcl) != 0)
  1264. {
  1265. assert(FALSE);
  1266. return 0;
  1267. }
  1268. if ((pce = (LPLINECOUNTRYENTRY)
  1269. ((BYTE *)pcl + pcl->dwCountryListOffset)) == 0)
  1270. {
  1271. assert(FALSE);
  1272. return 0;
  1273. }
  1274. /* --- Put country code in now --- */
  1275. wsprintf(ach, "+%u ", pce->dwCountryCode);
  1276. free(pcl);
  1277. pcl = NULL;
  1278. if (!fIsStringEmpty(achAreaCode))
  1279. {
  1280. StrCharCat(ach, "(");
  1281. StrCharCat(ach, achAreaCode);
  1282. StrCharCat(ach, ") ");
  1283. }
  1284. }
  1285. StrCharCat(ach, achDest);
  1286. /* --- Allocate some space --- */
  1287. pLnTransOutput = malloc(sizeof(LINETRANSLATEOUTPUT));
  1288. if (pLnTransOutput == 0)
  1289. {
  1290. assert(FALSE);
  1291. return 0;
  1292. }
  1293. pLnTransOutput->dwTotalSize = sizeof(LINETRANSLATEOUTPUT);
  1294. /* --- Now that we've satisifed the clergy, translate it --- */
  1295. if (TRAP(lRet = lineTranslateAddress(hhDriver->hLineApp,
  1296. dwLine, TAPI_VER, ach, 0,
  1297. LINETRANSLATEOPTION_CANCELCALLWAITING,
  1298. pLnTransOutput)) != 0)
  1299. {
  1300. free(pLnTransOutput);
  1301. pLnTransOutput = NULL;
  1302. if (lRet == LINEERR_INVALADDRESS)
  1303. {
  1304. goto MSG_EXIT;
  1305. }
  1306. return 0;
  1307. }
  1308. if (pLnTransOutput->dwTotalSize < pLnTransOutput->dwNeededSize)
  1309. {
  1310. dwSize = pLnTransOutput->dwNeededSize;
  1311. free(pLnTransOutput);
  1312. pLnTransOutput = NULL;
  1313. if ((pLnTransOutput = malloc(dwSize)) == 0)
  1314. {
  1315. assert(FALSE);
  1316. return 0;
  1317. }
  1318. pLnTransOutput->dwTotalSize = dwSize;
  1319. if ((lRet = lineTranslateAddress(hhDriver->hLineApp,
  1320. dwLine, TAPI_VER, ach, 0,
  1321. LINETRANSLATEOPTION_CANCELCALLWAITING,
  1322. pLnTransOutput)) != 0)
  1323. {
  1324. assert(FALSE);
  1325. free(pLnTransOutput);
  1326. pLnTransOutput = NULL;
  1327. if (lRet == LINEERR_INVALADDRESS)
  1328. {
  1329. goto MSG_EXIT;
  1330. }
  1331. }
  1332. }
  1333. free(pLnTransOutput);
  1334. pLnTransOutput = NULL;
  1335. return 0;
  1336. MSG_EXIT:
  1337. hhDriver->achDialableDest[0] = TEXT('\0');
  1338. hhDriver->achDisplayableDest[0] = TEXT('\0');
  1339. hhDriver->achCanonicalDest[0] = TEXT('\0');
  1340. LoadString(glblQueryDllHinst(), IDS_ER_CNCT_BADADDRESS, ach,
  1341. sizeof(ach) / sizeof(TCHAR));
  1342. TimedMessageBox(hwnd, ach, NULL, MB_OK | MB_ICONINFORMATION, 0);
  1343. #if defined (NT_EDITION)
  1344. //
  1345. // TODO:REV 5/17/2002 If we want to not exit the property page when
  1346. // there is an error with the phone number, then we should change the
  1347. // LINEERR_INVALADDRESS to 0 in the line below.
  1348. //
  1349. if (lRet != LINEERR_INVALADDRESS)
  1350. {
  1351. return -2;
  1352. }
  1353. #endif
  1354. // per MHG discussion - MPT 12/21/95
  1355. return 0;
  1356. }
  1357. #if defined(INCL_WINSOCK)
  1358. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1359. * FUNCTION:
  1360. * VerifyHost
  1361. *
  1362. * DESCRIPTION:
  1363. * Verify the Host Address is valid.
  1364. *
  1365. * ARGUMENTS:
  1366. * hwnd - dialog window handle.
  1367. *
  1368. * RETURNS:
  1369. * 0=OK
  1370. *
  1371. */
  1372. static int VerifyHost(const HWND hwnd)
  1373. {
  1374. int return_value = 0;
  1375. if (CheckWindow(hwnd, IDC_EB_HOSTADDR, IDS_ER_TCPIP_MISSING_ADDR) != 0)
  1376. {
  1377. return_value = -1;
  1378. }
  1379. else if (CheckWindow(hwnd, IDC_EB_PORTNUM, IDS_ER_TCPIP_MISSING_PORT) != 0)
  1380. {
  1381. return_value = -2;
  1382. }
  1383. return return_value;
  1384. }
  1385. #endif // INCL_WINSOCK
  1386. #if defined(DEADWOOD)
  1387. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1388. * FUNCTION:
  1389. * fCountryUsesAreaCode
  1390. *
  1391. * DESCRIPTION:
  1392. * Checks if the specified country uses area codes.
  1393. *
  1394. * ARGUMENTS:
  1395. * hwnd - window handle of dialog.
  1396. *
  1397. * RETURNS:
  1398. * TRUE/FALSE, <0=error
  1399. *
  1400. * AUTHOR: Mike Ward, 26-Jan-1995
  1401. */
  1402. int fCountryUsesAreaCode(const DWORD dwCountryID, const DWORD dwAPIVersion)
  1403. {
  1404. LPTSTR pachLongDistDialRule;
  1405. LPLINECOUNTRYLIST pcl;
  1406. LPLINECOUNTRYENTRY pce;
  1407. // Get country information
  1408. //
  1409. if (DoLineGetCountry(dwCountryID, TAPI_VER, &pcl) != 0)
  1410. {
  1411. assert(0);
  1412. return -1;
  1413. }
  1414. // Find offset to country info.
  1415. //
  1416. if ((pce = (LPLINECOUNTRYENTRY)
  1417. ((BYTE *)pcl + pcl->dwCountryListOffset)) == 0)
  1418. {
  1419. assert(0);
  1420. return -1;
  1421. }
  1422. // Get long distance dialing rule
  1423. //
  1424. pachLongDistDialRule = (BYTE *)pcl + pce->dwLongDistanceRuleOffset;
  1425. // If dial rule has an 'F', we need the area code.
  1426. //
  1427. if (strchr(pachLongDistDialRule, TEXT('F')))
  1428. return TRUE;
  1429. return FALSE;
  1430. }
  1431. #endif // defined(DEADWOOD)
  1432. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1433. * FUNCTION:
  1434. * fIsStringEmpty
  1435. *
  1436. * DESCRIPTION:
  1437. * Used for checking if areacode is just blanks. lineTranslateAddress
  1438. * pukes badly if you give it a string of blanks for the area code.
  1439. *
  1440. * ARGUMENTS:
  1441. * ach - areacode string (can be NULL)
  1442. *
  1443. * RETURNS:
  1444. * 1=emtpy, 0=not empty
  1445. *
  1446. * AUTHOR: Mike Ward, 20-Apr-1995
  1447. */
  1448. int fIsStringEmpty(LPTSTR ach)
  1449. {
  1450. int i;
  1451. if (ach == 0)
  1452. return 1;
  1453. if (ach[0] == TEXT('\0'))
  1454. return 1;
  1455. for (i = lstrlen(ach) - 1 ; i >= 0 ; --i)
  1456. {
  1457. if (ach[i] != TEXT(' '))
  1458. return 0;
  1459. }
  1460. return 1;
  1461. }
  1462. int cncttapiGetCOMSettings( const DWORD dwLineId, LPTSTR pachStr, const size_t cb )
  1463. {
  1464. static CHAR acParity[] = "NOEMS"; // see com.h
  1465. static CHAR *pachStop[] = {"1", "1.5", "2"};
  1466. TCHAR ach[100];
  1467. DWORD dwSize;
  1468. LPVARSTRING pvs;
  1469. int fAutoDetect = FALSE;
  1470. long lBaud = 0;
  1471. int iDataBits = 0;
  1472. int iParity = 0;
  1473. int iStopBits = 0;
  1474. int lReturn = 0;
  1475. LPCOMMPROP pComProp = 0;
  1476. #if defined(MODEM_NEGOTIATED_DCE_RATE) // TODO:REV 5/29/2002
  1477. long lNegBaud = 0;
  1478. #endif // defined(MODEM_NEGOTIATED_DCE_RATE)
  1479. // Check the parameters
  1480. //
  1481. if (pachStr == 0 || cb == 0)
  1482. {
  1483. assert(0);
  1484. return -2;
  1485. }
  1486. ach[0] = TEXT('\0');
  1487. if ((pvs = malloc(sizeof(VARSTRING))) == 0)
  1488. {
  1489. assert(FALSE);
  1490. return -3;
  1491. }
  1492. memset(pvs, 0, sizeof(VARSTRING));
  1493. pvs->dwTotalSize = sizeof(VARSTRING);
  1494. pvs->dwNeededSize = 0;
  1495. if (lineGetDevConfig(dwLineId, pvs, DEVCLASS) != 0)
  1496. {
  1497. assert(FALSE);
  1498. free(pvs);
  1499. pvs = NULL;
  1500. return -4;
  1501. }
  1502. if (pvs->dwNeededSize > pvs->dwTotalSize)
  1503. {
  1504. dwSize = pvs->dwNeededSize;
  1505. free(pvs);
  1506. pvs = NULL;
  1507. if ((pvs = malloc(dwSize)) == 0)
  1508. {
  1509. assert(FALSE);
  1510. return -5;
  1511. }
  1512. memset(pvs, 0, dwSize);
  1513. pvs->dwTotalSize = dwSize;
  1514. if (lineGetDevConfig(dwLineId, pvs, DEVCLASS) != 0)
  1515. {
  1516. assert(FALSE);
  1517. free(pvs);
  1518. pvs = NULL;
  1519. return -6;
  1520. }
  1521. }
  1522. // The structure of the DevConfig block is as follows
  1523. //
  1524. // VARSTRING
  1525. // UMDEVCFGHDR
  1526. // COMMCONFIG
  1527. // MODEMSETTINGS
  1528. //
  1529. // The UMDEVCFG structure used below is defined in the
  1530. // UNIMODEM.H provided in the platform SDK (in the nih
  1531. // directory for HTPE). REV: 12/01/2000
  1532. //
  1533. {
  1534. PUMDEVCFG pDevCfg = NULL;
  1535. pDevCfg = (UMDEVCFG *)((BYTE *)pvs + pvs->dwStringOffset);
  1536. if (pDevCfg)
  1537. {
  1538. // commconfig struct has a DCB structure we dereference for the
  1539. // com settings.
  1540. //
  1541. lBaud = pDevCfg->commconfig.dcb.BaudRate;
  1542. iDataBits = pDevCfg->commconfig.dcb.ByteSize;
  1543. iParity = pDevCfg->commconfig.dcb.Parity;
  1544. iStopBits = pDevCfg->commconfig.dcb.StopBits;
  1545. #if defined(MODEM_NEGOTIATED_DCE_RATE) // TODO:REV 5/29/2002
  1546. //
  1547. // See if this is a modem connection and connected, then get
  1548. // the negotiated baud rate instead of the default max rate
  1549. // the modem is set up for. -- REV: 5/29/2002
  1550. //
  1551. if (pDevCfg->commconfig.dwProviderSubType == PST_MODEM)
  1552. {
  1553. MODEMSETTINGS * pModemSettings = (MODEMSETTINGS *)pDevCfg->commconfig.wcProviderData;
  1554. if (pModemSettings)
  1555. {
  1556. lNegBaud = pModemSettings->dwNegotiatedDCERate;
  1557. }
  1558. }
  1559. #endif // defined(MODEM_NEGOTIATED_DCE_RATE)
  1560. }
  1561. #if defined(MODEM_NEGOTIATED_DCE_RATE) // TODO:REV 5/29/2002
  1562. if (lNegBaud > 0)
  1563. {
  1564. wsprintf(ach, "%ld %d-%c-%s", lNegBaud, iDataBits,
  1565. acParity[iParity], pachStop[iStopBits]);
  1566. }
  1567. else
  1568. {
  1569. wsprintf(ach, "%ld %d-%c-%s", lBaud, iDataBits,
  1570. acParity[iParity], pachStop[iStopBits]);
  1571. }
  1572. #else // defined(MODEM_NEGOTIATED_DCE_RATE)
  1573. wsprintf(ach, "%ld %d-%c-%s", lBaud, iDataBits,
  1574. acParity[iParity], pachStop[iStopBits]);
  1575. #endif //defined(MODEM_NEGOTIATED_DCE_RATE)
  1576. #if 0 //DEADWOOD:jkh 9/9/98
  1577. wsprintf(ach, "%u %d-%c-%s", pDevCfg->commconfig.dcb.BaudRate,
  1578. pDevCfg->commconfig.dcb.ByteSize,
  1579. acParity[pDevCfg->commconfig.dcb.Parity],
  1580. pachStop[pDevCfg->commconfig.dcb.StopBits]);
  1581. #endif
  1582. }
  1583. StrCharCopyN(pachStr, ach, cb);
  1584. pachStr[cb-1] = TEXT('\0');
  1585. free(pvs);
  1586. pvs = NULL;
  1587. return 0;
  1588. }