/* File: D:\WACKER\cncttapi\cnfrmdlg.c (Created: 23-Mar-1994) * * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI * All rights reserved * * $Revision: 1.24 $ * $Date: 1995/04/21 16:03:39 $ */ #include #pragma hdrstop #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "cncttapi.hh" #include "cncttapi.h" static void InitConfirmDlg(const HWND hwnd, const HHDRIVER hhDriver); /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- * FUNCTION: * ConfirmDlg * * DESCRIPTION: * Displays dialog confirming user's choices for the requested connect. * Assumes that EnumerateLines() and TranslateAddress() have been called. * * ARGUMENTS: * Standard dialog * * RETURNS: * Standard dialog * */ BOOL CALLBACK ConfirmDlg(HWND hwnd, UINT uMsg, WPARAM wPar, LPARAM lPar) { #define IDC_TF_LOCATION 107 #define CB_LOCATION 108 #define PB_EDIT_NEW 109 #define IDC_TF_PHONE 104 #define TB_PHONE 105 #define TB_CARD 110 #define IDC_TF_CARD 111 #define TB_SESSNAME 103 #define PB_MODIFY 106 int i; long lRet; LRESULT lr; HHDRIVER hhDriver; static DWORD aHlpTable[] = { CB_LOCATION, IDH_TERM_DIAL_LOCATION, IDC_TF_LOCATION, IDH_TERM_DIAL_LOCATION, IDC_TF_PHONE, IDH_TERM_DIAL_PHONENUMBER, TB_PHONE, IDH_TERM_DIAL_PHONENUMBER, TB_CARD, IDH_TERM_DIAL_CALLING_CARD, IDC_TF_CARD, IDH_TERM_DIAL_CALLING_CARD, PB_MODIFY, IDH_TERM_DIAL_MODIFY, PB_EDIT_NEW, IDH_TERM_DIAL_EDITNEW, IDOK, IDH_TERM_DIAL_DIAL, 0,0}; switch (uMsg) { case WM_INITDIALOG: SetWindowLong(hwnd, DWL_USER, lPar); hhDriver = (HHDRIVER)lPar; mscCenterWindowOnWindow(hwnd, sessQueryHwnd(hhDriver->hSession)); if ((lRet = TranslateAddress(hhDriver)) != 0) { if (lRet == LINEERR_INIFILECORRUPT) { PostMessage(hwnd, WM_COMMAND, MAKEWPARAM(PB_EDIT_NEW, BN_CLICKED), (LPARAM)hwnd); } } InitConfirmDlg(hwnd, hhDriver); EnumerateTapiLocations(hhDriver, GetDlgItem(hwnd, CB_LOCATION), GetDlgItem(hwnd, TB_CARD)); break; case WM_CONTEXTMENU: WinHelp((HWND)wPar, glblQueryHelpFileName(), HELP_CONTEXTMENU, (DWORD)(LPSTR)aHlpTable); break; case WM_HELP: WinHelp(((LPHELPINFO)lPar)->hItemHandle, glblQueryHelpFileName(), HELP_WM_HELP, (DWORD)(LPSTR)aHlpTable); break; case WM_COMMAND: switch (LOWORD(wPar)) { case IDOK: hhDriver = (HHDRIVER)GetWindowLong(hwnd, DWL_USER); EndDialog(hwnd, TRUE); break; case IDCANCEL: EndDialog(hwnd, FALSE); break; case PB_EDIT_NEW: hhDriver = (HHDRIVER)GetWindowLong(hwnd, DWL_USER); lineTranslateDialog(hhDriver->hLineApp, hhDriver->dwLine, TAPI_VER, hwnd, hhDriver->achCanonicalDest); EnumerateTapiLocations(hhDriver, GetDlgItem(hwnd, CB_LOCATION), GetDlgItem(hwnd, TB_CARD)); if (TranslateAddress(hhDriver) == 0) InitConfirmDlg(hwnd, hhDriver); break; case PB_MODIFY: hhDriver = (HHDRIVER)GetWindowLong(hwnd, DWL_USER); DoInternalProperties(hhDriver->hSession, sessQueryHwnd(hhDriver->hSession)); SetFocus(GetDlgItem(hwnd, PB_MODIFY)); EnumerateLines(hhDriver, 0); if (TranslateAddress(hhDriver) == 0) InitConfirmDlg(hwnd, hhDriver); break; case CB_LOCATION: if (HIWORD(wPar) == CBN_SELENDOK) { hhDriver = (HHDRIVER)GetWindowLong(hwnd, DWL_USER); if ((i = SendDlgItemMessage(hwnd, CB_LOCATION, CB_GETCURSEL, 0, 0)) != CB_ERR) { lr = SendDlgItemMessage(hwnd, CB_LOCATION, CB_GETITEMDATA, (WPARAM)i, 0); if (lr != CB_ERR) { if (lineSetCurrentLocation(hhDriver->hLineApp, (DWORD)lr) == 0) { // Leave the hwndCB (second paramater) zero. // Otherwise we go into and infinite message loop EnumerateTapiLocations(hhDriver, 0, GetDlgItem(hwnd, TB_CARD)); if (TranslateAddress(hhDriver) == 0) InitConfirmDlg(hwnd, hhDriver); } } } } break; default: return FALSE; } break; default: return FALSE; } return TRUE; } /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- * FUNCTION: * InitConfirmDlg * * DESCRIPTION: * Used to initialize some fields in the Confirmation dialog. * * ARGUMENTS: * hwnd - confirmation dialog * hhDriver - private driver handle. * * RETURNS: * void * */ static void InitConfirmDlg(const HWND hwnd, const HHDRIVER hhDriver) { TCHAR ach[512]; SetDlgItemText(hwnd, TB_PHONE, hhDriver->achDisplayableDest); SendDlgItemMessage(hwnd, 101, STM_SETICON, (WPARAM)sessQueryIcon(hhDriver->hSession), 0); sessQueryName(hhDriver->hSession, ach, sizeof(ach)); mscModifyToFit(GetDlgItem(hwnd, TB_SESSNAME), ach); SetDlgItemText(hwnd, TB_SESSNAME, ach); return; } /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- * FUNCTION: * TranslateAddress * * DESCRIPTION: * Translates the country code, area code, phone number into canonical * format and then lets tapi translate it into the final dialable format. * What is canonical format you say? * * +Country Code SPACE [Area Code] SPACE Subscriber Number * * Assumes EnumerateLines() has been called and a default device was * selected. * * ARGUMENTS: * hhDriver - private connection driver handle * * RETURNS: * 0=OK * */ long TranslateAddress(const HHDRIVER hhDriver) { LONG lRet = 1; DWORD dwSize; TCHAR ach[100]; LPLINECOUNTRYLIST pcl; LPLINECOUNTRYENTRY pce; LINETRANSLATEOUTPUT *pLnTransOutput; if (hhDriver == 0) { assert(FALSE); return -1; } if (CheckHotPhone(hhDriver, hhDriver->dwLine, &hhDriver->fHotPhone) != 0) return -1; // error message displayed already. // Hot Phone is TAPI terminology for Direct Connects // We don't need to do address translation since we // not going to use it. if (hhDriver->fHotPhone) { hhDriver->achDialableDest[0] = TEXT('\0'); hhDriver->achDisplayableDest[0] = TEXT('\0'); return 0; } ach[0] = TEXT('\0'); // initialize the string! // If we not using the country code or area code, we don't want // or need TAPI's line translation. Just copy the destination // as the user entered it in the phonenumber field. // if (hhDriver->fUseCCAC) { /* --- Do lineGetCountry to get extension --- */ if (DoLineGetCountry(hhDriver->dwCountryID, hhDriver->dwAPIVersion, &pcl) != 0) { assert(FALSE); return 2; } if ((pce = (LPLINECOUNTRYENTRY) ((BYTE *)pcl + pcl->dwCountryListOffset)) == 0) { assert(FALSE); return 3; } /* --- Put country code in now --- */ wsprintf(ach, "+%u ", pce->dwCountryCode); free(pcl); /* --- Area code ---*/ #if 0 // mrw:4/20/95 (see phonedlg.c) if (hhDriver->achAreaCode[0]) && fCountryUsesAreaCode(hhDriver->dwCountryID, hhDriver->dwAPIVersion)) #endif if (!fIsStringEmpty(hhDriver->achAreaCode)) { lstrcat(ach, "("); lstrcat(ach, hhDriver->achAreaCode); lstrcat(ach, ") "); } } lstrcat(ach, hhDriver->achDest); /* --- Allocate some space --- */ pLnTransOutput = malloc(sizeof(LINETRANSLATEOUTPUT)); if (pLnTransOutput == 0) { assert (FALSE); return 4; } pLnTransOutput->dwTotalSize = sizeof(LINETRANSLATEOUTPUT); /* --- Now that we've satisifed the clergy, translate it --- */ if ((lRet = TRAP(lineTranslateAddress(hhDriver->hLineApp, hhDriver->dwLine, TAPI_VER, ach, 0, LINETRANSLATEOPTION_CANCELCALLWAITING, pLnTransOutput))) != 0) { free(pLnTransOutput); return lRet; } if (pLnTransOutput->dwTotalSize < pLnTransOutput->dwNeededSize) { dwSize = pLnTransOutput->dwNeededSize; free(pLnTransOutput); if ((pLnTransOutput = malloc(dwSize)) == 0) { assert(FALSE); return 5; } pLnTransOutput->dwTotalSize = dwSize; if ((lRet = TRAP(lineTranslateAddress(hhDriver->hLineApp, hhDriver->dwLine, TAPI_VER, ach, 0, LINETRANSLATEOPTION_CANCELCALLWAITING, pLnTransOutput))) != 0) { assert(FALSE); free(pLnTransOutput); return lRet; } } /* --- At last, some strings to throw at the modem --- */ lstrcpy(hhDriver->achDialableDest, (LPSTR)pLnTransOutput + pLnTransOutput->dwDialableStringOffset); lstrcpy(hhDriver->achDisplayableDest, (LPSTR)pLnTransOutput + pLnTransOutput->dwDisplayableStringOffset); hhDriver->dwCountryCode = pLnTransOutput->dwDestCountry; lstrcpy(hhDriver->achCanonicalDest, ach); free(pLnTransOutput); return 0; } /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- * FUNCTION: * CheckHotPhone * * DESCRIPTION: * Checks to see if the selected line is a hot phone (ie. direct connect * that requires no dialing). * * ARGUMENTS: * hhDriver - private driver handle. * dwLine - line to test * pfHotPhone - result * * RETURNS: * 0=OK * */ int CheckHotPhone(const HHDRIVER hhDriver, const DWORD dwLine, int *pfHotPhone) { DWORD dw; LPLINEADDRESSCAPS pac = 0; if (hhDriver == 0) return -6; /* --- Get Address caps to determine line type --- */ if ((pac = (LPLINEADDRESSCAPS)malloc(sizeof(*pac))) == 0) { return -1; } pac->dwTotalSize = sizeof(*pac); if (lineGetAddressCaps(hhDriver->hLineApp, dwLine, 0, TAPI_VER, 0, pac) != 0) { free(pac); return -2; } if (pac->dwNeededSize > pac->dwTotalSize) { dw = pac->dwNeededSize; free(pac); if ((pac = (LPLINEADDRESSCAPS)malloc(dw)) == 0) { return -3; } pac->dwTotalSize = dw; if (lineGetAddressCaps(hhDriver->hLineApp, dwLine, 0, TAPI_VER, 0, pac) != 0) { free(pac); return -4; } } *pfHotPhone = !(pac->dwAddrCapFlags & LINEADDRCAPFLAGS_DIALED); free(pac); return 0; }