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.

617 lines
16 KiB

  1. /*++
  2. Copyright (c) 1999 - 2000 Microsoft Corporation
  3. Module Name:
  4. recvwzrd.c
  5. Abstract:
  6. Fax wizard pages for receiving configuration
  7. Environment:
  8. Fax configuration wizard
  9. Revision History:
  10. 03/13/00 -taoyuan-
  11. Created it.
  12. mm/dd/yy -author-
  13. description
  14. --*/
  15. #include "faxcfgwz.h"
  16. // functions which will be used only in this file
  17. VOID DoInitRecvDeviceList(HWND);
  18. VOID DoShowRecvDevices(HWND);
  19. VOID DoSaveRecvDevices(HWND);
  20. VOID CheckAnswerOptions(HWND);
  21. VOID
  22. DoShowRecvDevices(
  23. HWND hDlg
  24. )
  25. /*++
  26. Routine Description:
  27. Load the device information into the list view control
  28. Arguments:
  29. hDlg - Handle to the Device Send Options property sheet page
  30. Return Value:
  31. TRUE if successful, FALSE if failed.
  32. --*/
  33. {
  34. LV_ITEM item = {0};
  35. INT iItem = 0;
  36. INT iIndex;
  37. DWORD dw;
  38. HWND hwndLv;
  39. DEBUG_FUNCTION_NAME(TEXT("DoShowRecvDevices()"));
  40. hwndLv = GetDlgItem(hDlg, IDC_RECV_DEVICE_LIST);
  41. ListView_DeleteAllItems(hwndLv);
  42. //
  43. // Fill the list of devices and select the first item.
  44. //
  45. item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
  46. item.iImage = DI_Modem;
  47. for (dw = 0; dw < g_wizData.dwDeviceCount; ++dw)
  48. {
  49. if(!(g_wizData.pDevInfo[dw].bSelected))
  50. {
  51. //
  52. // skip unselected device
  53. //
  54. continue;
  55. }
  56. item.iItem = iItem++;
  57. item.pszText = g_wizData.pDevInfo[dw].szDeviceName;
  58. item.lParam = dw;
  59. iIndex = ListView_InsertItem(hwndLv, &item );
  60. ListView_SetCheckState(hwndLv,
  61. iIndex,
  62. (FAX_DEVICE_RECEIVE_MODE_OFF != g_wizData.pDevInfo[dw].ReceiveMode));
  63. }
  64. //
  65. // Select the first item.
  66. //
  67. ListView_SetItemState(hwndLv, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  68. ListView_SetColumnWidth(hwndLv, 0, LVSCW_AUTOSIZE_USEHEADER );
  69. }
  70. VOID
  71. DoSaveRecvDevices(
  72. HWND hDlg
  73. )
  74. /*++
  75. Routine Description:
  76. Save the user's choice for fax receiving devices
  77. Arguments:
  78. hDlg - Handle to the "Receive Device" page
  79. Return Value:
  80. TRUE -- if at least one device is selected or confirms for not selecting any receive
  81. FALSE -- if no device is selected but user chooses to go back.
  82. --*/
  83. {
  84. DWORD dw;
  85. DWORD dwDevInx;
  86. DWORD dwDeviceCount;
  87. HWND hwndLv;
  88. LVITEM lv = {0};
  89. DEBUG_FUNCTION_NAME(TEXT("DoSaveRecvDevices()"));
  90. lv.mask = LVIF_PARAM;
  91. hwndLv = GetDlgItem(hDlg, IDC_RECV_DEVICE_LIST);
  92. dwDeviceCount = ListView_GetItemCount(hwndLv);
  93. //
  94. // check selected devices
  95. //
  96. for(dw = 0; dw < dwDeviceCount; ++dw)
  97. {
  98. //
  99. // Get device index
  100. //
  101. lv.iItem = dw;
  102. ListView_GetItem(hwndLv, &lv);
  103. dwDevInx = (DWORD)lv.lParam;
  104. g_wizData.pDevInfo[dwDevInx].ReceiveMode = FAX_DEVICE_RECEIVE_MODE_OFF;
  105. if(ListView_GetCheckState(hwndLv, dw))
  106. {
  107. if(IsDlgButtonChecked(hDlg,IDC_MANUAL_ANSWER) == BST_CHECKED)
  108. {
  109. g_wizData.pDevInfo[dwDevInx].ReceiveMode = FAX_DEVICE_RECEIVE_MODE_MANUAL;
  110. }
  111. else
  112. {
  113. g_wizData.pDevInfo[dwDevInx].ReceiveMode = FAX_DEVICE_RECEIVE_MODE_AUTO;
  114. }
  115. }
  116. }
  117. }
  118. VOID
  119. CheckAnswerOptions(
  120. HWND hDlg
  121. )
  122. /*++
  123. Routine Description:
  124. Enable/disable the manual and auto answer radio button depending on the device
  125. number to receive faxes
  126. Arguments:
  127. hDlg - Handle to the "Receive Device" page
  128. Return Value:
  129. None
  130. --*/
  131. {
  132. HWND hwndLv; // list view windows
  133. DWORD dwDeviceIndex;
  134. DWORD dwDeviceCount;
  135. DWORD dwSelectNum=0; // number of the selected devices
  136. BOOL bManualAnswer = FALSE;
  137. BOOL bAllowManualAnswer = TRUE;
  138. BOOL bAllVirtual = TRUE; // Are all device virtual
  139. DEBUG_FUNCTION_NAME(TEXT("CheckAnswerOptions()"));
  140. hwndLv = GetDlgItem(hDlg, IDC_RECV_DEVICE_LIST);
  141. dwDeviceCount = ListView_GetItemCount(hwndLv);
  142. if(dwDeviceCount < 1) // if there isn't device in the list.
  143. {
  144. goto exit;
  145. }
  146. Assert (g_hFaxSvcHandle);
  147. for(dwDeviceIndex = 0; dwDeviceIndex < dwDeviceCount; ++dwDeviceIndex)
  148. {
  149. if(ListView_GetCheckState(hwndLv, dwDeviceIndex))
  150. {
  151. DWORD dwRes;
  152. BOOL bVirtual;
  153. dwRes = IsDeviceVirtual (g_hFaxSvcHandle, g_wizData.pDevInfo[dwDeviceIndex].dwDeviceId, &bVirtual);
  154. if (ERROR_SUCCESS != dwRes)
  155. {
  156. //
  157. // Assume device is virtual
  158. //
  159. bVirtual = TRUE;
  160. }
  161. if (!bVirtual)
  162. {
  163. bAllVirtual = FALSE;
  164. }
  165. ++dwSelectNum;
  166. if(FAX_DEVICE_RECEIVE_MODE_MANUAL == g_wizData.pDevInfo[dwDeviceIndex].ReceiveMode)
  167. {
  168. Assert(!bManualAnswer);
  169. bManualAnswer = TRUE;
  170. }
  171. }
  172. }
  173. if(dwSelectNum != 1)
  174. {
  175. bAllowManualAnswer = FALSE;
  176. }
  177. if (bAllVirtual && dwSelectNum)
  178. {
  179. //
  180. // Virtual devices don't support manual-answer mode
  181. //
  182. bAllowManualAnswer = FALSE;
  183. //
  184. // Virtual devices always answer after one ring
  185. //
  186. SetDlgItemInt (hDlg, IDC_RING_COUNT, 1, FALSE);
  187. }
  188. if(IsDlgButtonChecked(hDlg,IDC_MANUAL_ANSWER) == BST_CHECKED)
  189. {
  190. if (!bAllowManualAnswer)
  191. {
  192. //
  193. // Manual-answer is not a valid option, yet, it is selected.
  194. // Change to auto-answer mode.
  195. //
  196. CheckDlgButton (hDlg, IDC_MANUAL_ANSWER, FALSE);
  197. CheckDlgButton (hDlg, IDC_AUTO_ANSWER, TRUE);
  198. bManualAnswer = FALSE;
  199. }
  200. else
  201. {
  202. bManualAnswer = TRUE;
  203. }
  204. }
  205. exit:
  206. // Show/hide answer mode controls
  207. EnableWindow(GetDlgItem(hDlg, IDC_MANUAL_ANSWER), !bAllVirtual && (dwSelectNum == 1));
  208. EnableWindow(GetDlgItem(hDlg, IDC_AUTO_ANSWER), (dwSelectNum > 0));
  209. EnableWindow(GetDlgItem(hDlg, IDCSTATIC_RINGS), (dwSelectNum > 0));
  210. CheckDlgButton (hDlg, IDC_MANUAL_ANSWER, bManualAnswer ? BST_CHECKED : BST_UNCHECKED);
  211. CheckDlgButton (hDlg, IDC_AUTO_ANSWER, (!bManualAnswer && (dwSelectNum > 0)) ? BST_CHECKED : BST_UNCHECKED);
  212. EnableWindow(GetDlgItem(hDlg, IDC_RING_COUNT), !bAllVirtual && (dwSelectNum > 0) && IsDlgButtonChecked(hDlg, IDC_AUTO_ANSWER));
  213. EnableWindow(GetDlgItem(hDlg, IDC_SPIN_RING_COUNT), !bAllVirtual && (dwSelectNum > 0) && IsDlgButtonChecked(hDlg, IDC_AUTO_ANSWER));
  214. ShowWindow(GetDlgItem(hDlg, IDCSTATIC_NO_RECV_DEVICE), (dwSelectNum > 0) ? SW_HIDE : SW_SHOW);
  215. ShowWindow(GetDlgItem(hDlg, IDCSTATIC_NO_DEVICE_ERR), (dwSelectNum > 0) ? SW_HIDE : SW_SHOW);
  216. return;
  217. } // CheckAnswerOptions
  218. INT_PTR
  219. CALLBACK
  220. RecvDeviceDlgProc (
  221. HWND hDlg,
  222. UINT uMsg,
  223. WPARAM wParam,
  224. LPARAM lParam
  225. )
  226. /*++
  227. Routine Description:
  228. Procedure for handling the "Receive Device" page
  229. Arguments:
  230. hDlg - Identifies the property sheet page
  231. uMsg - Specifies the message
  232. wParam - Specifies additional message-specific information
  233. lParam - Specifies additional message-specific information
  234. Return Value:
  235. Depends on the value of message parameter
  236. --*/
  237. {
  238. switch (uMsg)
  239. {
  240. case WM_INITDIALOG :
  241. {
  242. //
  243. // Maximum length for various text fields in the dialog
  244. //
  245. static INT textLimits[] =
  246. {
  247. IDC_RING_COUNT, FXS_RINGS_LENGTH+1,
  248. 0,
  249. };
  250. LimitTextFields(hDlg, textLimits);
  251. //
  252. // Initiate the spin control.
  253. //
  254. SendDlgItemMessage(hDlg, IDC_SPIN_RING_COUNT, UDM_SETRANGE32,
  255. (WPARAM)FXS_RINGS_LOWER, (LPARAM)FXS_RINGS_UPPER);
  256. if(g_wizData.dwRingCount > FXS_RINGS_UPPER || (int)(g_wizData.dwRingCount) < FXS_RINGS_LOWER)
  257. {
  258. SetDlgItemInt(hDlg, IDC_RING_COUNT, FXS_RINGS_DEFAULT, FALSE);
  259. }
  260. else
  261. {
  262. SetDlgItemInt(hDlg, IDC_RING_COUNT, g_wizData.dwRingCount, FALSE);
  263. }
  264. //
  265. // init the list view and load device info
  266. //
  267. InitDeviceList(hDlg, IDC_RECV_DEVICE_LIST);
  268. DoShowRecvDevices(hDlg);
  269. CheckAnswerOptions(hDlg);
  270. return TRUE;
  271. }
  272. case WM_COMMAND:
  273. switch(LOWORD(wParam))
  274. {
  275. case IDC_MANUAL_ANSWER:
  276. case IDC_AUTO_ANSWER:
  277. // at this time, they must be enabled
  278. EnableWindow(GetDlgItem(hDlg, IDC_RING_COUNT),
  279. LOWORD(wParam)==IDC_AUTO_ANSWER);
  280. EnableWindow(GetDlgItem(hDlg, IDC_SPIN_RING_COUNT),
  281. LOWORD(wParam)==IDC_AUTO_ANSWER);
  282. break;
  283. default:
  284. break;
  285. }
  286. break;
  287. case WM_NOTIFY :
  288. {
  289. LPNMHDR lpnm = (LPNMHDR) lParam;
  290. switch (lpnm->code)
  291. {
  292. case PSN_SETACTIVE :
  293. DoShowRecvDevices(hDlg);
  294. // Enable the Back and Finish button
  295. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_NEXT);
  296. break;
  297. case PSN_WIZBACK :
  298. {
  299. //
  300. // Handle a Back button click here
  301. //
  302. DoSaveRecvDevices(hDlg);
  303. if(RemoveLastPage(hDlg))
  304. {
  305. return TRUE;
  306. }
  307. break;
  308. }
  309. case PSN_WIZNEXT :
  310. {
  311. BOOL bRes;
  312. //
  313. // Handle a Next button click, if necessary
  314. //
  315. DoSaveRecvDevices(hDlg);
  316. if(IsReceiveEnable() &&
  317. (IsDlgButtonChecked(hDlg,IDC_AUTO_ANSWER) == BST_CHECKED) &&
  318. (SendDlgItemMessage(hDlg, IDC_RING_COUNT, WM_GETTEXTLENGTH, 0, 0) == 0))
  319. {
  320. //
  321. // If the rings field is empty
  322. // go back to this page
  323. //
  324. DisplayMessageDialog(hDlg, MB_OK | MB_ICONSTOP, 0, IDS_ERR_NO_RINGS);
  325. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, -1);
  326. return TRUE;
  327. }
  328. g_wizData.dwRingCount = GetDlgItemInt(hDlg, IDC_RING_COUNT, &bRes, FALSE);
  329. if(!bRes)
  330. {
  331. DEBUG_FUNCTION_NAME(TEXT("RecvDeviceDlgProc()"));
  332. DebugPrintEx(DEBUG_ERR, TEXT("GetDlgItemInt failed: %d."), GetLastError());
  333. }
  334. if(!IsReceiveEnable())
  335. {
  336. //
  337. // go to the completion page
  338. //
  339. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, IDD_WIZARD_COMPLETE);
  340. SetLastPage(IDD_WIZARD_RECV_SELECT_DEVICES);
  341. return TRUE;
  342. }
  343. SetLastPage(IDD_WIZARD_RECV_SELECT_DEVICES);
  344. break;
  345. }
  346. case PSN_RESET :
  347. {
  348. // Handle a Cancel button click, if necessary
  349. break;
  350. }
  351. case LVN_ITEMCHANGED:
  352. {
  353. CheckAnswerOptions(hDlg);
  354. break;
  355. }
  356. case NM_DBLCLK:
  357. {
  358. INT iItem;
  359. HWND hwndLv;
  360. iItem = ((LPNMITEMACTIVATE)lParam)->iItem;
  361. hwndLv = GetDlgItem(hDlg, IDC_RECV_DEVICE_LIST);
  362. ListView_SetCheckState(hwndLv, iItem,
  363. !ListView_GetCheckState(hwndLv, iItem));
  364. // we don't have break here because we'll go through NM_CLICK
  365. }
  366. case NM_CLICK:
  367. break;
  368. default :
  369. break;
  370. }
  371. } // end of case WM_NOTIFY
  372. break;
  373. default:
  374. break;
  375. } // end of switch (uMsg)
  376. return FALSE;
  377. }
  378. INT_PTR
  379. CALLBACK
  380. RecvCsidDlgProc (
  381. HWND hDlg,
  382. UINT uMsg,
  383. WPARAM wParam,
  384. LPARAM lParam
  385. )
  386. /*++
  387. Routine Description:
  388. Procedure for handling the "CSID" page
  389. Arguments:
  390. hDlg - Identifies the property sheet page
  391. uMsg - Specifies the message
  392. wParam - Specifies additional message-specific information
  393. lParam - Specifies additional message-specific information
  394. Return Value:
  395. Depends on the value of message parameter
  396. --*/
  397. {
  398. switch (uMsg)
  399. {
  400. case WM_INITDIALOG :
  401. {
  402. //
  403. // Maximum length for various text fields in the dialog
  404. //
  405. static INT textLimits[] = {
  406. IDC_CSID, FXS_TSID_CSID_MAX_LENGTH + 1,
  407. 0,
  408. };
  409. LimitTextFields(hDlg, textLimits);
  410. if(g_wizData.szCsid)
  411. {
  412. SetDlgItemText(hDlg, IDC_CSID, g_wizData.szCsid);
  413. }
  414. return TRUE;
  415. }
  416. case WM_NOTIFY :
  417. {
  418. LPNMHDR lpnm = (LPNMHDR) lParam;
  419. switch (lpnm->code)
  420. {
  421. case PSN_SETACTIVE : //Enable the Back and Finish button
  422. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_NEXT);
  423. break;
  424. case PSN_WIZBACK :
  425. {
  426. //
  427. // Handle a Back button click here
  428. //
  429. if(RemoveLastPage(hDlg))
  430. {
  431. return TRUE;
  432. }
  433. break;
  434. }
  435. case PSN_WIZNEXT :
  436. {
  437. //Handle a Next button click, if necessary
  438. LPTSTR pCsid = NULL;
  439. pCsid = (LPTSTR)MemAlloc((FXS_TSID_CSID_MAX_LENGTH + 1) * sizeof(TCHAR));
  440. Assert(pCsid);
  441. if(pCsid)
  442. {
  443. pCsid[0] = '\0';
  444. GetDlgItemText(hDlg, IDC_CSID, pCsid, FXS_TSID_CSID_MAX_LENGTH + 1);
  445. MemFree(g_wizData.szCsid);
  446. g_wizData.szCsid = NULL;
  447. }
  448. else
  449. {
  450. LPCTSTR faxDbgFunction = TEXT("RecvCsidDlgProc()");
  451. DebugPrintEx(DEBUG_ERR, TEXT("Can't allocate memory for CSID.") );
  452. }
  453. g_wizData.szCsid = pCsid;
  454. SetLastPage(IDD_WIZARD_RECV_CSID);
  455. break;
  456. }
  457. case PSN_RESET :
  458. {
  459. // Handle a Cancel button click, if necessary
  460. break;
  461. }
  462. default :
  463. break;
  464. }
  465. }
  466. break;
  467. default:
  468. break;
  469. }
  470. return FALSE;
  471. }