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.

485 lines
12 KiB

  1. #include "faxcfgwz.h"
  2. DWORD
  3. GetSelectedDevIndex(
  4. HWND hDlg
  5. )
  6. /*++
  7. Routine Description:
  8. Get selected device index in WIZARDDATA.pDevInfo array
  9. Arguments:
  10. hDlg - Handle to the "One device limit" page
  11. Return Value:
  12. Device index in WIZARDDATA.pDevInfo array
  13. --*/
  14. {
  15. DWORD dwIndex = 0;
  16. DWORD dwDeviceId = 0;
  17. DWORD dwDevIndex = 0;
  18. HWND hComboModem = NULL;
  19. DEBUG_FUNCTION_NAME(TEXT("GetSelectedDevIndex()"));
  20. hComboModem = GetDlgItem(hDlg, IDC_COMBO_MODEM);
  21. if(!hComboModem)
  22. {
  23. Assert(FALSE);
  24. DebugPrintEx(DEBUG_ERR, TEXT("GetDlgItem(hDlg, IDC_COMBO_MODEM) failed, ec = %d."), GetLastError());
  25. return dwDevIndex;
  26. }
  27. dwIndex = (DWORD)SendMessage(hComboModem, CB_GETCURSEL,0,0);
  28. if(CB_ERR == dwIndex)
  29. {
  30. DebugPrintEx(DEBUG_ERR, TEXT("SendMessage(hComboModem, CB_GETCURSEL,0,0) failed."));
  31. return dwDevIndex;
  32. }
  33. dwDevIndex = (DWORD)SendMessage(hComboModem, CB_GETITEMDATA, dwIndex, 0);
  34. if(CB_ERR == dwDevIndex)
  35. {
  36. DebugPrintEx(DEBUG_ERR, TEXT("SendMessage(hComboModem, CB_GETITEMDATA, dwIndex, 0) failed."));
  37. return dwDevIndex;
  38. }
  39. return dwDevIndex;
  40. }
  41. void
  42. OnReceiveEnable(
  43. HWND hDlg
  44. )
  45. /*++
  46. Routine Description:
  47. Handle "Receive Enable" check button
  48. Arguments:
  49. hDlg - Handle to the "One device limit" page
  50. Return Value:
  51. None
  52. --*/
  53. {
  54. BOOL bRcvEnable;
  55. BOOL bAutoAnswer;
  56. DEBUG_FUNCTION_NAME(TEXT("OnReceiveEnable()"));
  57. bRcvEnable = IsDlgButtonChecked(hDlg, IDC_RECEIVE_ENABLE) == BST_CHECKED;
  58. if(bRcvEnable &&
  59. IsDlgButtonChecked(hDlg, IDC_MANUAL_ANSWER) != BST_CHECKED &&
  60. IsDlgButtonChecked(hDlg, IDC_AUTO_ANSWER) != BST_CHECKED)
  61. {
  62. //
  63. // Auto answer is the default
  64. //
  65. CheckDlgButton(hDlg, IDC_AUTO_ANSWER, BST_CHECKED);
  66. }
  67. if (bRcvEnable)
  68. {
  69. //
  70. // Let's see if the device is virtual
  71. //
  72. DWORD dwDevIndex = GetSelectedDevIndex(hDlg);
  73. DWORD dwRes;
  74. BOOL bVirtual = FALSE;
  75. dwRes = IsDeviceVirtual (g_hFaxSvcHandle, g_wizData.pDevInfo[dwDevIndex].dwDeviceId, &bVirtual);
  76. if (ERROR_SUCCESS != dwRes)
  77. {
  78. //
  79. // Assume device is virtual
  80. //
  81. bVirtual = TRUE;
  82. }
  83. if (bVirtual)
  84. {
  85. //
  86. // A virtual device is set to receive.
  87. // Enable ONLY auto-answer and set rings to 1.
  88. //
  89. EnableWindow (GetDlgItem(hDlg, IDC_MANUAL_ANSWER), FALSE);
  90. EnableWindow (GetDlgItem(hDlg, IDC_AUTO_ANSWER), TRUE);
  91. EnableWindow(GetDlgItem(hDlg, IDCSTATIC_RINGS), TRUE);
  92. EnableWindow(GetDlgItem(hDlg, IDC_RING_COUNT), FALSE);
  93. EnableWindow(GetDlgItem(hDlg, IDC_SPIN_RING_COUNT), FALSE);
  94. SetDlgItemInt(hDlg, IDC_RING_COUNT, 1, FALSE);
  95. return;
  96. }
  97. }
  98. bAutoAnswer = IsDlgButtonChecked(hDlg, IDC_AUTO_ANSWER) == BST_CHECKED;
  99. EnableWindow(GetDlgItem(hDlg, IDC_MANUAL_ANSWER), bRcvEnable);
  100. EnableWindow(GetDlgItem(hDlg, IDC_AUTO_ANSWER), bRcvEnable);
  101. EnableWindow(GetDlgItem(hDlg, IDCSTATIC_RINGS), bRcvEnable);
  102. EnableWindow(GetDlgItem(hDlg, IDC_RING_COUNT), bRcvEnable && bAutoAnswer);
  103. EnableWindow(GetDlgItem(hDlg, IDC_SPIN_RING_COUNT), bRcvEnable && bAutoAnswer);
  104. } // OnReceiveEnable
  105. void
  106. OnDevSelectChanged(
  107. HWND hDlg
  108. )
  109. /*++
  110. Routine Description:
  111. Handle device selection change
  112. Arguments:
  113. hDlg - Handle to the "One device limit" page
  114. Return Value:
  115. None
  116. --*/
  117. {
  118. DWORD dwDevIndex;
  119. DEBUG_FUNCTION_NAME(TEXT("OnDevSelectChanged()"));
  120. dwDevIndex = GetSelectedDevIndex(hDlg);
  121. CheckDlgButton(hDlg, IDC_SEND_ENABLE, g_wizData.pDevInfo[dwDevIndex].bSend ? BST_CHECKED : BST_UNCHECKED);
  122. CheckDlgButton(hDlg,
  123. IDC_RECEIVE_ENABLE,
  124. (FAX_DEVICE_RECEIVE_MODE_OFF != g_wizData.pDevInfo[dwDevIndex].ReceiveMode) ? BST_CHECKED : BST_UNCHECKED);
  125. if(FAX_DEVICE_RECEIVE_MODE_MANUAL == g_wizData.pDevInfo[dwDevIndex].ReceiveMode)
  126. {
  127. CheckDlgButton(hDlg, IDC_MANUAL_ANSWER, BST_CHECKED);
  128. CheckDlgButton(hDlg, IDC_AUTO_ANSWER, BST_UNCHECKED);
  129. }
  130. else if(FAX_DEVICE_RECEIVE_MODE_AUTO == g_wizData.pDevInfo[dwDevIndex].ReceiveMode)
  131. {
  132. CheckDlgButton(hDlg, IDC_MANUAL_ANSWER, BST_UNCHECKED);
  133. CheckDlgButton(hDlg, IDC_AUTO_ANSWER, BST_CHECKED);
  134. }
  135. else
  136. {
  137. //
  138. // No answer mode
  139. //
  140. CheckDlgButton(hDlg, IDC_MANUAL_ANSWER, BST_UNCHECKED);
  141. CheckDlgButton(hDlg, IDC_AUTO_ANSWER, BST_UNCHECKED);
  142. }
  143. OnReceiveEnable(hDlg);
  144. }
  145. VOID
  146. DoInitOneDevLimitDlg(
  147. HWND hDlg
  148. )
  149. /*++
  150. Routine Description:
  151. Init the "One device limit" page
  152. Arguments:
  153. hDlg - Handle to the "One device limit" page
  154. Return Value:
  155. None
  156. --*/
  157. {
  158. DWORD dw;
  159. DWORD dwItem;
  160. DWORD dwSelectedItem=0;
  161. HWND hComboModem;
  162. DEBUG_FUNCTION_NAME(TEXT("DoInitOneDevLimitDlg()"));
  163. hComboModem = GetDlgItem(hDlg, IDC_COMBO_MODEM);
  164. if(!hComboModem)
  165. {
  166. Assert(FALSE);
  167. return;
  168. }
  169. for(dw=0; dw < g_wizData.dwDeviceCount; ++dw)
  170. {
  171. dwItem = (DWORD)SendMessage(hComboModem, CB_ADDSTRING, 0, (LPARAM)(g_wizData.pDevInfo[dw].szDeviceName));
  172. if(CB_ERR != dwItem && CB_ERRSPACE != dwItem)
  173. {
  174. SendMessage(hComboModem, CB_SETITEMDATA, dwItem, dw);
  175. if(g_wizData.pDevInfo[dw].bSend ||
  176. (FAX_DEVICE_RECEIVE_MODE_OFF != g_wizData.pDevInfo[dw].ReceiveMode))
  177. {
  178. dwSelectedItem = dwItem;
  179. }
  180. }
  181. else
  182. {
  183. DebugPrintEx(DEBUG_ERR, TEXT("SendMessage(hComboModem, CB_ADDSTRING) failed."));
  184. }
  185. }
  186. SendDlgItemMessage(hDlg,
  187. IDC_SPIN_RING_COUNT,
  188. UDM_SETRANGE32,
  189. (WPARAM)FXS_RINGS_LOWER,
  190. (LPARAM)FXS_RINGS_UPPER);
  191. SendDlgItemMessage(hDlg, IDC_RING_COUNT, EM_SETLIMITTEXT, FXS_RINGS_LENGTH, 0);
  192. if(!SetDlgItemInt(hDlg, IDC_RING_COUNT, g_wizData.dwRingCount, FALSE))
  193. {
  194. DebugPrintEx(DEBUG_ERR, TEXT("SetDlgItemInt(IDC_RING_COUNT) failed with %d."), GetLastError());
  195. }
  196. SendMessage(hComboModem, CB_SETCURSEL, dwSelectedItem, 0);
  197. OnDevSelectChanged(hDlg);
  198. }
  199. void
  200. DoSaveOneDevLimit(
  201. HWND hDlg
  202. )
  203. /*++
  204. Routine Description:
  205. Save the user's choice for devices
  206. Arguments:
  207. hDlg - Handle to the "One device limit" page
  208. Return Value:
  209. None
  210. --*/
  211. {
  212. DWORD dw;
  213. BOOL bRes;
  214. DWORD dwRes;
  215. DWORD dwDevIndex;
  216. DEBUG_FUNCTION_NAME(TEXT("DoSaveOneDevLimit()"));
  217. dwDevIndex = GetSelectedDevIndex(hDlg);
  218. //
  219. // disable all devices
  220. //
  221. for(dw=0; dw < g_wizData.dwDeviceCount; ++dw)
  222. {
  223. g_wizData.pDevInfo[dw].bSend = FALSE;
  224. g_wizData.pDevInfo[dw].ReceiveMode = FAX_DEVICE_RECEIVE_MODE_OFF;
  225. g_wizData.pDevInfo[dw].bSelected = FALSE;
  226. }
  227. //
  228. // save "Send enable"
  229. //
  230. if(IsDlgButtonChecked(hDlg, IDC_SEND_ENABLE) == BST_CHECKED)
  231. {
  232. g_wizData.pDevInfo[dwDevIndex].bSend = TRUE;
  233. }
  234. //
  235. // save receive options
  236. //
  237. if(IsDlgButtonChecked(hDlg, IDC_RECEIVE_ENABLE) != BST_CHECKED)
  238. {
  239. return;
  240. }
  241. if(IsDlgButtonChecked(hDlg, IDC_MANUAL_ANSWER) == BST_CHECKED)
  242. {
  243. g_wizData.pDevInfo[dwDevIndex].ReceiveMode = FAX_DEVICE_RECEIVE_MODE_MANUAL;
  244. return;
  245. }
  246. //
  247. // auto answer
  248. //
  249. g_wizData.pDevInfo[dwDevIndex].ReceiveMode = FAX_DEVICE_RECEIVE_MODE_AUTO;
  250. //
  251. // get ring count
  252. //
  253. dwRes = GetDlgItemInt(hDlg, IDC_RING_COUNT, &bRes, FALSE);
  254. if(!bRes)
  255. {
  256. DebugPrintEx(DEBUG_ERR, TEXT("GetDlgItemInt(IDC_RING_COUNT) failed with %d."), GetLastError());
  257. }
  258. else
  259. {
  260. g_wizData.dwRingCount = dwRes;
  261. }
  262. }
  263. INT_PTR
  264. CALLBACK
  265. OneDevLimitDlgProc (
  266. HWND hDlg,
  267. UINT uMsg,
  268. WPARAM wParam,
  269. LPARAM lParam
  270. )
  271. /*++
  272. Routine Description:
  273. Procedure for handling the "One device limit" page
  274. Arguments:
  275. hDlg - Identifies the property sheet page
  276. uMsg - Specifies the message
  277. wParam - Specifies additional message-specific information
  278. lParam - Specifies additional message-specific information
  279. Return Value:
  280. Depends on the value of message parameter
  281. --*/
  282. {
  283. switch (uMsg)
  284. {
  285. case WM_INITDIALOG :
  286. {
  287. DoInitOneDevLimitDlg(hDlg);
  288. return TRUE;
  289. }
  290. case WM_COMMAND:
  291. switch(LOWORD(wParam))
  292. {
  293. case IDC_COMBO_MODEM:
  294. if(HIWORD(wParam) == CBN_SELCHANGE)
  295. {
  296. OnDevSelectChanged(hDlg);
  297. }
  298. break;
  299. case IDC_MANUAL_ANSWER:
  300. case IDC_AUTO_ANSWER:
  301. case IDC_RECEIVE_ENABLE:
  302. OnReceiveEnable(hDlg);
  303. break;
  304. }
  305. break;
  306. case WM_NOTIFY :
  307. {
  308. LPNMHDR lpnm = (LPNMHDR) lParam;
  309. switch (lpnm->code)
  310. {
  311. case PSN_SETACTIVE :
  312. // Enable the Back and Finish button
  313. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_NEXT);
  314. break;
  315. case PSN_WIZBACK :
  316. {
  317. //
  318. // Handle a Back button click here
  319. //
  320. if(RemoveLastPage(hDlg))
  321. {
  322. return TRUE;
  323. }
  324. break;
  325. }
  326. case PSN_WIZNEXT :
  327. //
  328. // Handle a Next button click, if necessary
  329. //
  330. if((IsDlgButtonChecked(hDlg, IDC_RECEIVE_ENABLE) == BST_CHECKED) &&
  331. (IsDlgButtonChecked(hDlg, IDC_AUTO_ANSWER) == BST_CHECKED) &&
  332. (SendDlgItemMessage(hDlg, IDC_RING_COUNT, WM_GETTEXTLENGTH, 0, 0) == 0))
  333. {
  334. //
  335. // If the rings field is empty
  336. // go back to this page
  337. //
  338. DisplayMessageDialog(hDlg, MB_OK | MB_ICONSTOP, 0, IDS_ERR_NO_RINGS);
  339. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, -1);
  340. return TRUE;
  341. }
  342. DoSaveOneDevLimit(hDlg);
  343. SetLastPage(IDD_ONE_DEVICE_LIMIT);
  344. if(!IsSendEnable())
  345. {
  346. if(IsReceiveEnable())
  347. {
  348. //
  349. // go to the CSID page
  350. //
  351. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, IDD_WIZARD_RECV_CSID);
  352. return TRUE;
  353. }
  354. else
  355. {
  356. //
  357. // go to the completion page
  358. //
  359. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, IDD_WIZARD_COMPLETE);
  360. return TRUE;
  361. }
  362. }
  363. break;
  364. case PSN_RESET :
  365. {
  366. // Handle a Cancel button click, if necessary
  367. break;
  368. }
  369. default :
  370. break;
  371. }
  372. }
  373. break;
  374. default:
  375. break;
  376. }
  377. return FALSE;
  378. }