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.

553 lines
13 KiB

  1. /* File: D:\WACKER\cncttapi\cnfrmdlg.c (Created: 23-Mar-1994)
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 16 $
  7. * $Date: 7/08/02 6:30p $
  8. */
  9. #define TAPI_CURRENT_VERSION 0x00010004 // cab:11/14/96 - required!
  10. #include <tapi.h>
  11. #pragma hdrstop
  12. #include <prsht.h>
  13. #include <time.h>
  14. #include <tdll\stdtyp.h>
  15. #include <tdll\session.h>
  16. #include <tdll\tdll.h>
  17. #include <tdll\misc.h>
  18. #include <tdll\mc.h>
  19. #include <tdll\assert.h>
  20. #include <tdll\errorbox.h>
  21. #include <tdll\cnct.h>
  22. #include <tdll\hlptable.h>
  23. #include <tdll\globals.h>
  24. #include <tdll\property.h>
  25. #include <term\res.h>
  26. #include <tdll\statusbr.h>
  27. #include <tdll\htchar.h>
  28. #include "cncttapi.hh"
  29. #include "cncttapi.h"
  30. static void InitConfirmDlg(const HWND hwnd, const HHDRIVER hhDriver);
  31. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  32. * FUNCTION:
  33. * ConfirmDlg
  34. *
  35. * DESCRIPTION:
  36. * Displays dialog confirming user's choices for the requested connect.
  37. * Assumes that EnumerateLines() and TranslateAddress() have been called.
  38. *
  39. * ARGUMENTS:
  40. * Standard dialog
  41. *
  42. * RETURNS:
  43. * Standard dialog
  44. *
  45. */
  46. INT_PTR CALLBACK ConfirmDlg(HWND hwnd, UINT uMsg, WPARAM wPar, LPARAM lPar)
  47. {
  48. #define IDC_TF_LOCATION 107
  49. #define CB_LOCATION 108
  50. #define PB_EDIT_NEW 109
  51. #define IDI_ICON 102
  52. #define IDC_TF_PHONE 104
  53. #define TB_PHONE 105
  54. #define TB_CARD 110
  55. #define IDC_TF_CARD 111
  56. #define TB_SESSNAME 103
  57. #define PB_MODIFY 106
  58. #define PB_DIAL 117
  59. TCHAR ach[128];
  60. int i;
  61. long lRet;
  62. LRESULT lr;
  63. HHDRIVER hhDriver;
  64. static DWORD aHlpTable[] = { CB_LOCATION, IDH_TERM_DIAL_LOCATION,
  65. IDC_TF_LOCATION, IDH_TERM_DIAL_LOCATION,
  66. IDC_TF_PHONE, IDH_TERM_DIAL_PHONENUMBER,
  67. TB_PHONE, IDH_TERM_DIAL_PHONENUMBER,
  68. TB_CARD, IDH_TERM_DIAL_CALLING_CARD,
  69. IDC_TF_CARD, IDH_TERM_DIAL_CALLING_CARD,
  70. PB_MODIFY, IDH_TERM_DIAL_MODIFY,
  71. PB_EDIT_NEW, IDH_TERM_DIAL_EDITNEW,
  72. PB_DIAL, IDH_TERM_DIAL_DIAL,
  73. IDCANCEL, IDH_CANCEL,
  74. 0,0};
  75. switch (uMsg)
  76. {
  77. case WM_INITDIALOG:
  78. SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)lPar);
  79. hhDriver = (HHDRIVER)lPar;
  80. mscCenterWindowOnWindow(hwnd, sessQueryHwnd(hhDriver->hSession));
  81. if ((lRet = TranslateAddress(hhDriver)) != 0)
  82. {
  83. if (lRet == LINEERR_INIFILECORRUPT)
  84. {
  85. PostMessage(hwnd, WM_COMMAND,
  86. MAKEWPARAM(PB_EDIT_NEW, BN_CLICKED), (LPARAM)hwnd);
  87. }
  88. }
  89. InitConfirmDlg(hwnd, hhDriver);
  90. EnumerateTapiLocations(hhDriver, GetDlgItem(hwnd, CB_LOCATION),
  91. GetDlgItem(hwnd, TB_CARD));
  92. break;
  93. case WM_CONTEXTMENU:
  94. doContextHelp(aHlpTable, wPar, lPar, TRUE, TRUE);
  95. break;
  96. case WM_HELP:
  97. doContextHelp(aHlpTable, wPar, lPar, FALSE, FALSE);
  98. break;
  99. case WM_COMMAND:
  100. switch (LOWORD(wPar))
  101. {
  102. case PB_DIAL:
  103. GetDlgItemText(hwnd, TB_PHONE, ach, sizeof(ach)/sizeof(TCHAR));
  104. if (strcmp(ach, TEXT("")) != 0)
  105. {
  106. hhDriver = (HHDRIVER)GetWindowLongPtr(hwnd, DWLP_USER);
  107. if (hhDriver->achDialableDest[0] != TEXT('\0') &&
  108. hhDriver->achCanonicalDest[0] != TEXT('\0') )
  109. {
  110. EndDialog(hwnd, TRUE);
  111. }
  112. else
  113. {
  114. LoadString(glblQueryDllHinst(), IDS_ER_CNCT_BADADDRESS,
  115. ach, sizeof(ach)/sizeof(TCHAR));
  116. MessageBox(hwnd, ach, NULL, MB_OK);
  117. }
  118. }
  119. else
  120. {
  121. LoadString(glblQueryDllHinst(), 40808, ach,
  122. sizeof(ach)/sizeof(TCHAR));
  123. MessageBox(hwnd, ach, NULL, MB_OK);
  124. }
  125. break;
  126. case IDCANCEL:
  127. EndDialog(hwnd, FALSE);
  128. break;
  129. case PB_EDIT_NEW:
  130. hhDriver = (HHDRIVER)GetWindowLongPtr(hwnd, DWLP_USER);
  131. lineTranslateDialog(hhDriver->hLineApp, hhDriver->dwLine,
  132. TAPI_VER, hwnd, hhDriver->achCanonicalDest);
  133. EnumerateTapiLocations(hhDriver, GetDlgItem(hwnd, CB_LOCATION),
  134. GetDlgItem(hwnd, TB_CARD));
  135. if (TranslateAddress(hhDriver) == 0)
  136. InitConfirmDlg(hwnd, hhDriver);
  137. break;
  138. case PB_MODIFY:
  139. hhDriver = (HHDRIVER)GetWindowLongPtr(hwnd, DWLP_USER);
  140. EnableWindow(GetDlgItem(hwnd, PB_MODIFY), FALSE);
  141. DoInternalProperties(hhDriver->hSession,
  142. hwnd);
  143. // Fix for the statusbar was not updating when the
  144. // session's properties were modified when the
  145. // Dial Confirm dialog. We now update the statusbar
  146. // when we return from DoInternalProperties() so that
  147. // the status bar is correct. REV: 11/08/2000
  148. //
  149. PostMessage(sessQueryHwndStatusbar(hhDriver->hSession), SBR_NTFY_REFRESH,
  150. (WPARAM)SBR_ALL_PARTS, 0);
  151. if ( IsNT() )
  152. {
  153. EnumerateLinesNT(hhDriver, 0);
  154. }
  155. else
  156. {
  157. EnumerateLines(hhDriver, 0);
  158. }
  159. lRet = TranslateAddress(hhDriver);
  160. if (lRet == 0 || lRet == LINEERR_INVALADDRESS)
  161. {
  162. InitConfirmDlg(hwnd, hhDriver);
  163. }
  164. EnableWindow(GetDlgItem(hwnd, PB_MODIFY), TRUE);
  165. SetFocus(GetDlgItem(hwnd, PB_MODIFY));
  166. break;
  167. case CB_LOCATION:
  168. if (HIWORD(wPar) == CBN_SELENDOK)
  169. {
  170. hhDriver = (HHDRIVER)GetWindowLongPtr(hwnd, DWLP_USER);
  171. if ((i = (int)SendDlgItemMessage(hwnd, CB_LOCATION, CB_GETCURSEL,
  172. 0, 0)) != CB_ERR)
  173. {
  174. lr = SendDlgItemMessage(hwnd, CB_LOCATION, CB_GETITEMDATA,
  175. (WPARAM)i, 0);
  176. if (lr != CB_ERR)
  177. {
  178. if (lineSetCurrentLocation(hhDriver->hLineApp,
  179. (DWORD)lr) == 0)
  180. {
  181. // Leave the hwndCB (second paramater) zero.
  182. // Otherwise we go into and infinite message loop
  183. EnumerateTapiLocations(hhDriver, 0,
  184. GetDlgItem(hwnd, TB_CARD));
  185. if (TranslateAddress(hhDriver) == 0)
  186. InitConfirmDlg(hwnd, hhDriver);
  187. }
  188. }
  189. }
  190. }
  191. break;
  192. default:
  193. return FALSE;
  194. }
  195. break;
  196. default:
  197. return FALSE;
  198. }
  199. return TRUE;
  200. }
  201. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  202. * FUNCTION:
  203. * InitConfirmDlg
  204. *
  205. * DESCRIPTION:
  206. * Used to initialize some fields in the Confirmation dialog.
  207. *
  208. * ARGUMENTS:
  209. * hwnd - confirmation dialog
  210. * hhDriver - private driver handle.
  211. *
  212. * RETURNS:
  213. * void
  214. *
  215. */
  216. static void InitConfirmDlg(const HWND hwnd, const HHDRIVER hhDriver)
  217. {
  218. TCHAR ach[512];
  219. SendDlgItemMessage(hwnd, 101, STM_SETICON,
  220. (WPARAM)sessQueryIcon(hhDriver->hSession), 0);
  221. sessQueryName(hhDriver->hSession, ach, sizeof(ach));
  222. mscModifyToFit(GetDlgItem(hwnd, TB_SESSNAME), ach, SS_WORDELLIPSIS);
  223. SetDlgItemText(hwnd, TB_SESSNAME, ach);
  224. if (hhDriver->achDialableDest[0] == TEXT('\0'))
  225. {
  226. // We need to disable the Dial button here if there is not
  227. // a valid dialable destination. REV: 10/23/2000
  228. //
  229. EnableDial(hwnd, FALSE);
  230. LoadString(glblQueryDllHinst(), IDS_ER_CNCT_BADADDRESS2, ach,
  231. sizeof(ach)/sizeof(TCHAR));
  232. SetDlgItemText(hwnd, TB_PHONE, ach);
  233. }
  234. else
  235. {
  236. EnableDial(hwnd, TRUE);
  237. SetDlgItemText(hwnd, TB_PHONE, hhDriver->achDisplayableDest);
  238. }
  239. return;
  240. }
  241. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  242. * FUNCTION:
  243. * TranslateAddress
  244. *
  245. * DESCRIPTION:
  246. * Translates the country code, area code, phone number into canonical
  247. * format and then lets tapi translate it into the final dialable format.
  248. * What is canonical format you say?
  249. *
  250. * +Country Code SPACE [Area Code] SPACE Subscriber Number
  251. *
  252. * Assumes EnumerateLines() has been called and a default device was
  253. * selected.
  254. *
  255. * ARGUMENTS:
  256. * hhDriver - private connection driver handle
  257. *
  258. * RETURNS:
  259. * 0=OK
  260. *
  261. */
  262. long TranslateAddress(const HHDRIVER hhDriver)
  263. {
  264. LONG lRet = 1;
  265. DWORD dwSize;
  266. TCHAR ach[100];
  267. LPLINECOUNTRYLIST pcl=NULL;
  268. LPLINECOUNTRYENTRY pce;
  269. LINETRANSLATEOUTPUT *pLnTransOutput;
  270. if (hhDriver == 0)
  271. {
  272. assert(FALSE);
  273. return -1;
  274. }
  275. if (CheckHotPhone(hhDriver, hhDriver->dwLine, &hhDriver->fHotPhone) != 0)
  276. return -1; // error message displayed already.
  277. // Hot Phone is TAPI terminology for Direct Connects
  278. // We don't need to do address translation since we
  279. // not going to use it.
  280. if (hhDriver->fHotPhone)
  281. {
  282. hhDriver->achDialableDest[0] = TEXT('\0');
  283. hhDriver->achDisplayableDest[0] = TEXT('\0');
  284. return 0;
  285. }
  286. ach[0] = TEXT('\0'); // initialize the string!
  287. // If we not using the country code or area code, we don't want
  288. // or need TAPI's line translation. Just copy the destination
  289. // as the user entered it in the phonenumber field.
  290. //
  291. if (hhDriver->fUseCCAC)
  292. {
  293. /* --- Do lineGetCountry to get extension --- */
  294. if (DoLineGetCountry(hhDriver->dwCountryID, hhDriver->dwAPIVersion,
  295. &pcl) != 0)
  296. {
  297. assert(FALSE);
  298. return 2;
  299. }
  300. if ((pce = (LPLINECOUNTRYENTRY)
  301. ((BYTE *)pcl + pcl->dwCountryListOffset)) == 0)
  302. {
  303. assert(FALSE);
  304. return 3;
  305. }
  306. /* --- Put country code in now --- */
  307. wsprintf(ach, "+%u ", pce->dwCountryCode);
  308. free(pcl);
  309. pcl = NULL;
  310. /* --- Area code ---*/
  311. #if defined(DEADWOOD) // mrw:4/20/95 (see phonedlg.c)
  312. if (hhDriver->achAreaCode[0]) &&
  313. fCountryUsesAreaCode(hhDriver->dwCountryID,
  314. hhDriver->dwAPIVersion))
  315. #endif // defined(DEADWOOD)
  316. if (!fIsStringEmpty(hhDriver->achAreaCode))
  317. {
  318. StrCharCat(ach, TEXT("("));
  319. StrCharCat(ach, hhDriver->achAreaCode);
  320. StrCharCat(ach, TEXT(") "));
  321. }
  322. }
  323. StrCharCat(ach, hhDriver->achDest);
  324. /* --- Allocate some space --- */
  325. pLnTransOutput = malloc(sizeof(LINETRANSLATEOUTPUT));
  326. if (pLnTransOutput == 0)
  327. {
  328. assert (FALSE);
  329. return 4;
  330. }
  331. pLnTransOutput->dwTotalSize = sizeof(LINETRANSLATEOUTPUT);
  332. /* --- Now that we've got the line address, translate it --- */
  333. if ((lRet = TRAP(lineTranslateAddress(hhDriver->hLineApp,
  334. hhDriver->dwLine, TAPI_VER, ach, 0,
  335. LINETRANSLATEOPTION_CANCELCALLWAITING,
  336. pLnTransOutput))) != 0)
  337. {
  338. free(pLnTransOutput);
  339. pLnTransOutput = NULL;
  340. return lRet;
  341. }
  342. if (pLnTransOutput->dwTotalSize < pLnTransOutput->dwNeededSize)
  343. {
  344. dwSize = pLnTransOutput->dwNeededSize;
  345. free(pLnTransOutput);
  346. pLnTransOutput = NULL;
  347. if ((pLnTransOutput = malloc(dwSize)) == 0)
  348. {
  349. assert(FALSE);
  350. return 5;
  351. }
  352. pLnTransOutput->dwTotalSize = dwSize;
  353. if ((lRet = TRAP(lineTranslateAddress(hhDriver->hLineApp,
  354. hhDriver->dwLine, TAPI_VER, ach, 0,
  355. LINETRANSLATEOPTION_CANCELCALLWAITING,
  356. pLnTransOutput))) != 0)
  357. {
  358. assert(FALSE);
  359. free(pLnTransOutput);
  360. pLnTransOutput = NULL;
  361. return lRet;
  362. }
  363. }
  364. /* --- At last, some strings to throw at the modem --- */
  365. StrCharCopyN(hhDriver->achDialableDest,
  366. (LPSTR)pLnTransOutput + pLnTransOutput->dwDialableStringOffset,
  367. TAPIMAXDESTADDRESSSIZE+1);
  368. StrCharCopyN(hhDriver->achDisplayableDest,
  369. (LPSTR)pLnTransOutput + pLnTransOutput->dwDisplayableStringOffset,
  370. TAPIMAXDESTADDRESSSIZE+1);
  371. hhDriver->dwCountryCode = pLnTransOutput->dwDestCountry;
  372. StrCharCopyN(hhDriver->achCanonicalDest, ach, TAPIMAXDESTADDRESSSIZE+1);
  373. free(pLnTransOutput);
  374. pLnTransOutput = NULL;
  375. return 0;
  376. }
  377. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  378. * FUNCTION:
  379. * CheckHotPhone
  380. *
  381. * DESCRIPTION:
  382. * Checks to see if the selected line is a hot phone (ie. direct connect
  383. * that requires no dialing).
  384. *
  385. * ARGUMENTS:
  386. * hhDriver - private driver handle.
  387. * dwLine - line to test
  388. * pfHotPhone - result
  389. *
  390. * RETURNS:
  391. * 0=OK
  392. *
  393. */
  394. int CheckHotPhone(const HHDRIVER hhDriver, const DWORD dwLine, int *pfHotPhone)
  395. {
  396. DWORD dw;
  397. LPLINEADDRESSCAPS pac = 0;
  398. if (hhDriver == 0)
  399. return -6;
  400. /* --- Get Address caps to determine line type --- */
  401. if ((pac = (LPLINEADDRESSCAPS)malloc(sizeof(*pac))) == 0)
  402. {
  403. return -1;
  404. }
  405. pac->dwTotalSize = sizeof(*pac);
  406. if (lineGetAddressCaps(hhDriver->hLineApp, dwLine, 0, TAPI_VER, 0,
  407. pac) != 0)
  408. {
  409. free(pac);
  410. pac = NULL;
  411. return -2;
  412. }
  413. if (pac->dwNeededSize > pac->dwTotalSize)
  414. {
  415. dw = pac->dwNeededSize;
  416. free(pac);
  417. pac = NULL;
  418. if ((pac = (LPLINEADDRESSCAPS)malloc(dw)) == 0)
  419. {
  420. return -3;
  421. }
  422. pac->dwTotalSize = dw;
  423. if (lineGetAddressCaps(hhDriver->hLineApp, dwLine,
  424. 0, TAPI_VER, 0, pac) != 0)
  425. {
  426. free(pac);
  427. pac = NULL;
  428. return -4;
  429. }
  430. }
  431. *pfHotPhone = !(pac->dwAddrCapFlags & LINEADDRCAPFLAGS_DIALED);
  432. free(pac);
  433. pac = NULL;
  434. return 0;
  435. }
  436. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  437. * FUNCTION:
  438. * EnableDial
  439. *
  440. * DESCRIPTION:
  441. * Enables/Disables Dial button.
  442. *
  443. * ARGUMENTS:
  444. * hwndDlg - dial dialog window handle
  445. * fEnable - TRUE/FALSE
  446. *
  447. * RETURNS:
  448. * void
  449. *
  450. */
  451. void EnableDial(const HWND hwndDlg, const BOOL fEnable)
  452. {
  453. if (IsWindow(hwndDlg))
  454. {
  455. EnableWindow(GetDlgItem(hwndDlg, PB_DIAL), fEnable);
  456. if (fEnable == FALSE)
  457. {
  458. SetFocus(GetDlgItem(hwndDlg,PB_MODIFY));
  459. }
  460. else
  461. {
  462. SetFocus(GetDlgItem(hwndDlg, PB_DIAL));
  463. }
  464. }
  465. return;
  466. }