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.

715 lines
17 KiB

  1. /*++
  2. Copyright (c) 1999 - 2000 Microsoft Corporation
  3. Module Name:
  4. sendwzrd.c
  5. Abstract:
  6. Fax wizard pages for sending configuration
  7. plus the welcome and complete page for the wizard.
  8. Environment:
  9. Fax configuration wizard
  10. Revision History:
  11. 03/13/00 -taoyuan-
  12. Created it.
  13. mm/dd/yy -author-
  14. description
  15. --*/
  16. #include "faxcfgwz.h"
  17. //
  18. // functions which will be used only in this file
  19. //
  20. VOID DoInitSendDeviceList(HWND);
  21. BOOL DoShowSendDevices(HWND);
  22. VOID DoSaveSendDevices(HWND);
  23. BOOL ValidateControl(HWND, INT);
  24. BOOL ChangePriority(HWND, BOOL);
  25. VOID CheckSendDevices(HWND hDlg);
  26. BOOL
  27. DoShowSendDevices(
  28. HWND hDlg
  29. )
  30. /*++
  31. Routine Description:
  32. Load the device information into the list view control
  33. Arguments:
  34. hDlg - Handle to the "Send Device" page
  35. Return Value:
  36. NONE
  37. --*/
  38. {
  39. LV_ITEM item;
  40. INT iItem = 0;
  41. INT iIndex;
  42. DWORD dw;
  43. int nDevInx;
  44. HWND hwndLv;
  45. DEBUG_FUNCTION_NAME(TEXT("DoShowSendDevices()"));
  46. hwndLv = GetDlgItem(hDlg, IDC_SEND_DEVICE_LIST);
  47. ListView_DeleteAllItems(hwndLv );
  48. //
  49. // Fill the list of devices and select the first item.
  50. //
  51. for (dw = 0; dw < g_wizData.dwDeviceCount; ++dw)
  52. {
  53. nDevInx = GetDevIndexByDevId(g_wizData.pdwSendDevOrder[dw]);
  54. if(nDevInx < 0)
  55. {
  56. Assert(FALSE);
  57. continue;
  58. }
  59. if(!(g_wizData.pDevInfo[nDevInx].bSelected))
  60. {
  61. //
  62. // skip unselected device
  63. //
  64. continue;
  65. }
  66. ZeroMemory( &item, sizeof(item) );
  67. item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
  68. item.iItem = iItem++;
  69. item.pszText = g_wizData.pDevInfo[nDevInx].szDeviceName;
  70. //
  71. // we only support modem icon right now, if we can distinguish
  72. // the type of a specific, add code here
  73. //
  74. item.iImage = DI_Modem;
  75. item.lParam = nDevInx;
  76. iIndex = ListView_InsertItem(hwndLv, &item );
  77. ListView_SetCheckState(hwndLv,
  78. iIndex,
  79. g_wizData.pDevInfo[nDevInx].bSend);
  80. }
  81. //
  82. // Select the first item and validate the buttons
  83. //
  84. ListView_SetItemState(hwndLv, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  85. ListView_SetColumnWidth(hwndLv, 0, LVSCW_AUTOSIZE_USEHEADER );
  86. ValidateControl(hDlg, 0);
  87. return TRUE;
  88. }
  89. VOID
  90. DoSaveSendDevices(
  91. HWND hDlg
  92. )
  93. /*++
  94. Routine Description:
  95. Save the user's choice for fax sending devices
  96. Arguments:
  97. hDlg - Handle to the "Send Device" page
  98. Return Value:
  99. TRUE -- if at least one device is selected or confirms for disable send
  100. FALSE -- if no device is selected but user chooses to go back.
  101. --*/
  102. {
  103. DWORD dw;
  104. DWORD dwOrder;
  105. LVITEM lv = {0}; // for getting info of device Id
  106. DWORD dwDevInx;
  107. DWORD dwDeviceCount;
  108. HWND hwndLv;
  109. DEBUG_FUNCTION_NAME(TEXT("DoSaveSendDevices()"));
  110. hwndLv = GetDlgItem(hDlg, IDC_SEND_DEVICE_LIST);
  111. dwDeviceCount = ListView_GetItemCount(hwndLv);
  112. lv.mask = LVIF_PARAM;
  113. //
  114. // check selected devices
  115. //
  116. for(dwOrder = 0; dwOrder < dwDeviceCount; ++dwOrder)
  117. {
  118. //
  119. // Get device index
  120. //
  121. lv.iItem = dwOrder;
  122. ListView_GetItem(hwndLv, &lv);
  123. dwDevInx = (DWORD)lv.lParam;
  124. //
  125. // get device selection
  126. //
  127. g_wizData.pDevInfo[dwDevInx].bSend = ListView_GetCheckState(hwndLv, dwOrder);
  128. //
  129. // save order info
  130. //
  131. g_wizData.pdwSendDevOrder[dwOrder] = g_wizData.pDevInfo[dwDevInx].dwDeviceId;
  132. }
  133. //
  134. // Store unselected device order
  135. //
  136. for (dw=0; dw < g_wizData.dwDeviceCount && dwOrder < g_wizData.dwDeviceCount; ++dw)
  137. {
  138. if(!(g_wizData.pDevInfo[dw].bSelected))
  139. {
  140. g_wizData.pdwSendDevOrder[dwOrder] = g_wizData.pDevInfo[dw].dwDeviceId;
  141. ++dwOrder;
  142. }
  143. }
  144. Assert(dwOrder == g_wizData.dwDeviceCount);
  145. }
  146. BOOL
  147. ValidateControl(
  148. HWND hDlg,
  149. INT iItem
  150. )
  151. /*++
  152. Routine Description:
  153. Validate the up and down button in the device select page
  154. Arguments:
  155. hDlg - Handle to the Device Send Options property sheet page
  156. iItem - index of the item being selected
  157. Return Value:
  158. TRUE -- if no error
  159. FALSE -- if error
  160. --*/
  161. {
  162. DWORD dwDeviceCount = ListView_GetItemCount(GetDlgItem(hDlg, IDC_SEND_DEVICE_LIST));
  163. //
  164. // if there is only one device or we don't click on any item
  165. // up and down buttons are disabled
  166. //
  167. if(dwDeviceCount < 2 || iItem == -1)
  168. {
  169. EnableWindow(GetDlgItem(hDlg, IDC_SENDPRI_UP), FALSE);
  170. EnableWindow(GetDlgItem(hDlg, IDC_SENDPRI_DOWN), FALSE);
  171. return TRUE;
  172. }
  173. EnableWindow(GetDlgItem(hDlg, IDC_SENDPRI_UP), iItem > 0); // not the top one
  174. EnableWindow(GetDlgItem(hDlg, IDC_SENDPRI_DOWN), iItem < (INT)dwDeviceCount - 1 ); // not the last one
  175. if (!IsWindowEnabled (GetFocus()))
  176. {
  177. //
  178. // The currently selected control turned disabled - select the list control
  179. //
  180. SetFocus (GetDlgItem (hDlg, IDC_SEND_DEVICE_LIST));
  181. }
  182. return TRUE;
  183. }
  184. BOOL
  185. ChangePriority(
  186. HWND hDlg,
  187. BOOL bMoveUp
  188. )
  189. /*++
  190. Routine Description:
  191. Validate the up and down button in the device select page
  192. Arguments:
  193. hDlg - Handle to the Device Send Options property sheet page
  194. bMoveUp -- TRUE for moving up, FALSE for moving down
  195. Return Value:
  196. TRUE -- if no error
  197. FALSE -- if error
  198. --*/
  199. {
  200. INT iItem;
  201. BOOL rslt;
  202. LVITEM lv={0};
  203. HWND hwndLv;
  204. BOOL bChecked;
  205. TCHAR pszText[MAX_DEVICE_NAME];
  206. DEBUG_FUNCTION_NAME(TEXT("ChangePriority()"));
  207. hwndLv = GetDlgItem(hDlg, IDC_SEND_DEVICE_LIST);
  208. iItem = ListView_GetNextItem(hwndLv, -1, LVNI_ALL | LVNI_SELECTED);
  209. if(iItem == -1)
  210. {
  211. return FALSE;
  212. }
  213. //
  214. // get selected item information and then remove it
  215. //
  216. lv.iItem = iItem;
  217. lv.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
  218. lv.stateMask = LVIS_SELECTED;
  219. lv.pszText = pszText;
  220. lv.cchTextMax = MAX_DEVICE_NAME;
  221. ListView_GetItem(hwndLv, &lv);
  222. bChecked = ListView_GetCheckState(hwndLv, iItem);
  223. rslt = ListView_DeleteItem(hwndLv, iItem);
  224. //
  225. // recalculate the item index;
  226. //
  227. if(bMoveUp)
  228. {
  229. lv.iItem--;
  230. }
  231. else
  232. {
  233. lv.iItem++;
  234. }
  235. //
  236. // reinsert the item and validate button state
  237. //
  238. iItem = ListView_InsertItem(hwndLv, &lv);
  239. ListView_SetCheckState(hwndLv, iItem, bChecked);
  240. ListView_SetItemState(hwndLv, iItem, LVIS_SELECTED, LVIS_SELECTED);
  241. ValidateControl(hDlg, iItem);
  242. return TRUE;
  243. }
  244. VOID
  245. CheckSendDevices(
  246. HWND hDlg
  247. )
  248. /*++
  249. Routine Description:
  250. Display a warning if no device is selected
  251. Arguments:
  252. hDlg - Handle to the "Send Device" page
  253. Return Value:
  254. None
  255. --*/
  256. {
  257. HWND hwndLv; // list view windows
  258. DWORD dwDeviceIndex;
  259. DWORD dwDeviceCount;
  260. BOOL bDeviceSelect = FALSE; // indicate whether we have at least one device selected.
  261. DEBUG_FUNCTION_NAME(TEXT("CheckSendDevices()"));
  262. hwndLv = GetDlgItem(hDlg, IDC_SEND_DEVICE_LIST);
  263. dwDeviceCount = ListView_GetItemCount(hwndLv);
  264. if(dwDeviceCount < 1) // if there isn't device in the list.
  265. {
  266. goto exit;
  267. }
  268. for(dwDeviceIndex = 0; dwDeviceIndex < dwDeviceCount; dwDeviceIndex++)
  269. {
  270. if(ListView_GetCheckState(hwndLv, dwDeviceIndex))
  271. {
  272. bDeviceSelect = TRUE;
  273. break;
  274. }
  275. }
  276. exit:
  277. ShowWindow(GetDlgItem(hDlg, IDCSTATIC_NO_SEND_DEVICE), bDeviceSelect ? SW_HIDE : SW_SHOW);
  278. ShowWindow(GetDlgItem(hDlg, IDCSTATIC_NO_DEVICE_ERR), bDeviceSelect ? SW_HIDE : SW_SHOW);
  279. return;
  280. }
  281. INT_PTR
  282. CALLBACK
  283. SendDeviceDlgProc (
  284. HWND hDlg,
  285. UINT uMsg,
  286. WPARAM wParam,
  287. LPARAM lParam
  288. )
  289. /*++
  290. Routine Description:
  291. Procedure for handling the "Send Device" page
  292. Arguments:
  293. hDlg - Identifies the property sheet page
  294. uMsg - Specifies the message
  295. wParam - Specifies additional message-specific information
  296. lParam - Specifies additional message-specific information
  297. Return Value:
  298. Depends on the value of message parameter
  299. --*/
  300. {
  301. switch (uMsg)
  302. {
  303. case WM_INITDIALOG :
  304. {
  305. // icon handles for up and down arrows.
  306. HICON hIconUp, hIconDown;
  307. hIconUp = LoadIcon(g_hResource, MAKEINTRESOURCE(IDI_Up));
  308. hIconDown = LoadIcon(g_hResource, MAKEINTRESOURCE(IDI_Down));
  309. SendDlgItemMessage(hDlg, IDC_SENDPRI_UP, BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)hIconUp);
  310. SendDlgItemMessage(hDlg, IDC_SENDPRI_DOWN, BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)hIconDown);
  311. //
  312. // load device info
  313. //
  314. InitDeviceList(hDlg, IDC_SEND_DEVICE_LIST);
  315. DoShowSendDevices(hDlg);
  316. CheckSendDevices(hDlg);
  317. return TRUE;
  318. }
  319. case WM_COMMAND:
  320. switch(LOWORD(wParam))
  321. {
  322. case IDC_SENDPRI_UP:
  323. ChangePriority(hDlg, TRUE);
  324. break;
  325. case IDC_SENDPRI_DOWN:
  326. ChangePriority(hDlg, FALSE);
  327. break;
  328. default:
  329. break;
  330. }
  331. break;
  332. case WM_NOTIFY :
  333. {
  334. LPNMHDR lpnm = (LPNMHDR) lParam;
  335. switch (lpnm->code)
  336. {
  337. case PSN_SETACTIVE :
  338. DoShowSendDevices(hDlg);
  339. // Enable the Back and Finish button
  340. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_NEXT);
  341. break;
  342. case PSN_WIZBACK :
  343. {
  344. //
  345. // Handle a Back button click here
  346. //
  347. DoSaveSendDevices(hDlg);
  348. if(RemoveLastPage(hDlg))
  349. {
  350. return TRUE;
  351. }
  352. break;
  353. }
  354. case PSN_WIZNEXT :
  355. //
  356. // Handle a Next button click, if necessary
  357. //
  358. DoSaveSendDevices(hDlg);
  359. //
  360. // switch to appropriate page
  361. //
  362. if(!IsSendEnable())
  363. {
  364. //
  365. // go to the receive configuration or completion page
  366. //
  367. if(g_bShowDevicePages)
  368. {
  369. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, IDD_WIZARD_RECV_SELECT_DEVICES);
  370. }
  371. else
  372. {
  373. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, IDD_WIZARD_COMPLETE);
  374. }
  375. SetLastPage(IDD_WIZARD_SEND_SELECT_DEVICES);
  376. return TRUE;
  377. }
  378. SetLastPage(IDD_WIZARD_SEND_SELECT_DEVICES);
  379. break;
  380. case PSN_RESET :
  381. {
  382. // Handle a Cancel button click, if necessary
  383. break;
  384. }
  385. case LVN_ITEMCHANGED:
  386. {
  387. //
  388. // need to validate the control after changing selection by keyboard
  389. //
  390. LPNMLISTVIEW pnmv;
  391. pnmv = (LPNMLISTVIEW) lParam;
  392. ValidateControl(hDlg, pnmv->iItem);
  393. CheckSendDevices(hDlg);
  394. break;
  395. }
  396. case NM_DBLCLK:
  397. {
  398. //
  399. // Handle a double click event
  400. //
  401. INT iItem;
  402. HWND hwndLv;
  403. hwndLv = GetDlgItem(hDlg, IDC_SEND_DEVICE_LIST);
  404. iItem = ((LPNMITEMACTIVATE) lParam)->iItem;
  405. ListView_SetCheckState(hwndLv, iItem, !ListView_GetCheckState(hwndLv, iItem));
  406. // we don't have break here because we'll go through NM_CLICK
  407. }
  408. case NM_CLICK:
  409. {
  410. //
  411. // Handle a Click event
  412. //
  413. HWND hwndLv;
  414. LPNMITEMACTIVATE lpnmitem;
  415. lpnmitem = (LPNMITEMACTIVATE)lParam;
  416. hwndLv = GetDlgItem(hDlg, IDC_SEND_DEVICE_LIST);
  417. ListView_SetItemState(hwndLv, lpnmitem->iItem, LVIS_SELECTED, LVIS_SELECTED);
  418. ValidateControl(hDlg, lpnmitem->iItem);
  419. CheckSendDevices(hDlg);
  420. break;
  421. }
  422. default :
  423. break;
  424. }
  425. }
  426. break;
  427. default:
  428. break;
  429. }
  430. return FALSE;
  431. }
  432. INT_PTR CALLBACK
  433. SendTsidDlgProc (
  434. HWND hDlg,
  435. UINT uMsg,
  436. WPARAM wParam,
  437. LPARAM lParam
  438. )
  439. /*++
  440. Routine Description:
  441. Procedure for handling the "TSID" page
  442. Arguments:
  443. hDlg - Identifies the property sheet page
  444. uMsg - Specifies the message
  445. wParam - Specifies additional message-specific information
  446. lParam - Specifies additional message-specific information
  447. Return Value:
  448. Depends on the value of message parameter
  449. --*/
  450. {
  451. switch (uMsg)
  452. {
  453. case WM_INITDIALOG :
  454. {
  455. //
  456. // Maximum length for various text fields in the dialog
  457. //
  458. static INT textLimits[] =
  459. {
  460. IDC_TSID, FXS_TSID_CSID_MAX_LENGTH + 1,
  461. 0,
  462. };
  463. LimitTextFields(hDlg, textLimits);
  464. if(g_wizData.szTsid)
  465. {
  466. SetDlgItemText(hDlg, IDC_TSID, g_wizData.szTsid);
  467. }
  468. return TRUE;
  469. }
  470. case WM_NOTIFY :
  471. {
  472. LPNMHDR lpnm = (LPNMHDR) lParam;
  473. switch (lpnm->code)
  474. {
  475. case PSN_SETACTIVE : //Enable the Back and Finish button
  476. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_NEXT);
  477. break;
  478. case PSN_WIZBACK :
  479. {
  480. //
  481. // Handle a Back button click here
  482. //
  483. if(RemoveLastPage(hDlg))
  484. {
  485. return TRUE;
  486. }
  487. break;
  488. }
  489. case PSN_WIZNEXT :
  490. {
  491. // Handle a Next button click, if necessary
  492. LPTSTR pTsid;
  493. pTsid = (LPTSTR)MemAlloc((FXS_TSID_CSID_MAX_LENGTH + 1) * sizeof(TCHAR));
  494. Assert(pTsid);
  495. if(pTsid)
  496. {
  497. pTsid[0] = '\0';
  498. GetDlgItemText(hDlg, IDC_TSID, pTsid, FXS_TSID_CSID_MAX_LENGTH + 1);
  499. MemFree(g_wizData.szTsid);
  500. g_wizData.szTsid = NULL;
  501. }
  502. else
  503. {
  504. LPCTSTR faxDbgFunction = TEXT("SendTsidDlgProc()");
  505. DebugPrintEx(DEBUG_ERR, TEXT("Can't allocate memory for TSID."));
  506. }
  507. g_wizData.szTsid = pTsid;
  508. if(1 == g_wizData.dwDeviceLimit && !IsReceiveEnable())
  509. {
  510. //
  511. // go to the completion page
  512. //
  513. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, IDD_WIZARD_COMPLETE);
  514. SetLastPage(IDD_WIZARD_SEND_TSID);
  515. return TRUE;
  516. }
  517. SetLastPage(IDD_WIZARD_SEND_TSID);
  518. break;
  519. }
  520. case PSN_RESET :
  521. {
  522. // Handle a Cancel button click, if necessary
  523. break;
  524. }
  525. default :
  526. break;
  527. }
  528. break;
  529. } // WM_NOTIFY
  530. default:
  531. break;
  532. }
  533. return FALSE;
  534. }