Source code of Windows XP (NT5)
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.

1275 lines
28 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. recvopts.c
  5. Abstract:
  6. Functions for handling events in the "Receive Options" tab of
  7. the fax server configuration property sheet
  8. Environment:
  9. Fax configuration applet
  10. Revision History:
  11. 03/13/96 -davidx-
  12. Created it.
  13. mm/dd/yy -author-
  14. description
  15. --*/
  16. #include "faxcpl.h"
  17. //
  18. // Information about the fax device list view on "Receive Options" page
  19. //
  20. static COLUMNINFO faxDeviceListViewColumnInfo[] = {
  21. { COLUMN_DEVICE_NAME, 2 },
  22. { COLUMN_CSID, 1 },
  23. { 0, 0 },
  24. };
  25. VOID
  26. EnumMapiProfiles(
  27. HWND hwnd
  28. )
  29. /*++
  30. Routine Description:
  31. Put the mapi profiles in the combo box
  32. Arguments:
  33. hwnd - window handle to mapi profiles combo box
  34. Return Value:
  35. NONE
  36. --*/
  37. {
  38. LPTSTR MapiProfiles;
  39. MapiProfiles = gConfigData->pMapiProfiles;
  40. while (MapiProfiles && *MapiProfiles) {
  41. SendMessage(
  42. hwnd,
  43. CB_ADDSTRING,
  44. 0,
  45. (LPARAM) MapiProfiles
  46. );
  47. MapiProfiles += _tcslen(MapiProfiles) + 1;
  48. }
  49. }
  50. VOID
  51. DoInitRecvOptions(
  52. HWND hDlg
  53. )
  54. /*++
  55. Routine Description:
  56. Perform one-time initialization of "Receive Options" property page
  57. Arguments:
  58. hDlg - Window handle to the "Receive Options" property page
  59. Return Value:
  60. NONE
  61. --*/
  62. {
  63. HWND hwnd;
  64. TCHAR buffer[MAX_STRING_LEN];
  65. //
  66. // Maximum length for various text fields in the dialog
  67. //
  68. static INT textLimits[] = {
  69. IDC_CSID, 21,
  70. IDC_DEST_DIRPATH, MAX_ARCHIVE_DIR,
  71. IDC_DEST_RINGS, 3,
  72. 0,
  73. };
  74. GetMapiProfiles();
  75. LimitTextFields(hDlg, textLimits);
  76. if (gConfigData->pMapiProfiles && (hwnd = GetDlgItem(hDlg, IDC_DEST_PROFILENAME))){
  77. EnumMapiProfiles(hwnd);
  78. LoadString(ghInstance, IDS_DEFAULT_PROFILE, buffer, MAX_STRING_LEN);
  79. SendMessage(hwnd, CB_INSERTSTRING, 0, (LPARAM) buffer);
  80. }
  81. //
  82. // Initialize the list of destination printers
  83. //
  84. if (hwnd = GetDlgItem(hDlg, IDC_DEST_PRINTERLIST)) {
  85. PPRINTER_INFO_2 pPrinterInfo2, pSaved;
  86. DWORD cPrinters, dwFlags;
  87. dwFlags = gConfigData->pServerName ?
  88. PRINTER_ENUM_NAME :
  89. (PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS);
  90. pPrinterInfo2 = MyEnumPrinters(gConfigData->pServerName, 2, &cPrinters, dwFlags);
  91. if (pSaved = pPrinterInfo2) {
  92. //
  93. // Filtering out fax printers from the list
  94. //
  95. for ( ; cPrinters--; pPrinterInfo2++) {
  96. if (_tcsicmp(pPrinterInfo2->pDriverName, FAX_DRIVER_NAME) != EQUAL_STRING)
  97. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM) pPrinterInfo2->pPrinterName);
  98. }
  99. MemFree(pSaved);
  100. }
  101. //
  102. // The first choice is always the system default printer
  103. //
  104. LoadString(ghInstance, IDS_DEFAULT_PRINTER, buffer, MAX_STRING_LEN);
  105. SendMessage(hwnd, CB_INSERTSTRING, 0, (LPARAM) buffer);
  106. }
  107. //
  108. // Connect to the fax service and retrieve the list of fax devices
  109. //
  110. GetFaxDeviceAndConfigInfo();
  111. }
  112. //
  113. // Data structure and constants used for comparing two fax devices
  114. //
  115. typedef struct {
  116. PCONFIG_PORT_INFO_2 pDevInfo;
  117. DWORD match;
  118. } MATCHINFO, *PMATCHINFO;
  119. #define MATCH_DEST_PRINTER 0x0001
  120. #define MATCH_DEST_DIR 0x0002
  121. #define MATCH_DEST_EMAIL 0x0004
  122. #define MATCH_DEST_MAILBOX 0x0008
  123. #define MATCH_DEST_PRINTERNAME 0x0010
  124. #define MATCH_DEST_DIRPATH 0x0020
  125. #define MATCH_DEST_PROFILENAME 0x0040
  126. #define MATCH_DEST_CSID 0x0080
  127. #define MATCH_DEST_RINGS 0x0100
  128. #define MATCH_ALL 0x0FFF
  129. VOID
  130. MatchFaxDevInfo(
  131. PMATCHINFO pMatchInfo,
  132. PCONFIG_PORT_INFO_2 pDevInfo
  133. )
  134. /*++
  135. Routine Description:
  136. Compare a fax device with another one and
  137. figure out what attributes they have in common
  138. Arguments:
  139. pMatchInfo - Points to a MATCHINFO structure
  140. pDevInfo - Specifies the fax device to match
  141. Return Value:
  142. NONE
  143. --*/
  144. #define MatchRoutingOption(matchFlag, routingFlag) { \
  145. if ((pMatchInfo->match & (matchFlag)) && \
  146. (pRefInfo->Mask & (routingFlag)) != (pDevInfo->Mask & (routingFlag))) \
  147. { \
  148. pMatchInfo->match &= ~(matchFlag); \
  149. } \
  150. }
  151. #define MatchDWORDField(matchFlag, FieldName) { \
  152. if ((pMatchInfo->match & (matchFlag)) && \
  153. (pRefInfo->FieldName != pDevInfo->FieldName)) \
  154. { \
  155. pMatchInfo->match &= ~(matchFlag); \
  156. } \
  157. }
  158. #define MatchTextField(matchFlag, pFieldName) { \
  159. if ((pMatchInfo->match & (matchFlag)) && \
  160. (! pRefInfo->pFieldName || \
  161. ! pDevInfo->pFieldName || \
  162. _tcsicmp(pRefInfo->pFieldName, pDevInfo->pFieldName) != EQUAL_STRING)) \
  163. { \
  164. pMatchInfo->match &= ~(matchFlag); \
  165. } \
  166. }
  167. {
  168. PCONFIG_PORT_INFO_2 pRefInfo;
  169. //
  170. // Remember the first fax device as the reference
  171. //
  172. if ((pRefInfo = pMatchInfo->pDevInfo) == NULL) {
  173. pMatchInfo->pDevInfo = pDevInfo;
  174. pMatchInfo->match = MATCH_ALL;
  175. return;
  176. }
  177. //
  178. // Match each attribute in turn
  179. //
  180. MatchRoutingOption(MATCH_DEST_PRINTER, LR_PRINT);
  181. MatchRoutingOption(MATCH_DEST_EMAIL, LR_EMAIL);
  182. MatchRoutingOption(MATCH_DEST_DIR, LR_STORE);
  183. MatchRoutingOption(MATCH_DEST_MAILBOX, LR_INBOX);
  184. MatchTextField(MATCH_DEST_PRINTERNAME, PrinterName);
  185. MatchTextField(MATCH_DEST_DIRPATH, DirStore);
  186. MatchTextField(MATCH_DEST_PROFILENAME, ProfileName);
  187. MatchTextField(MATCH_DEST_CSID, CSID);
  188. MatchDWORDField(MATCH_DEST_RINGS, Rings);
  189. }
  190. VOID
  191. DoChangeRecvDeviceSel(
  192. HWND hDlg,
  193. HWND hwndLV
  194. )
  195. /*++
  196. Routine Description:
  197. Process selection change events in the fax device list
  198. Arguments:
  199. hDlg - Window handle to the "Receive Options" property page
  200. hwndLV - Handle to the fax device list
  201. Return Value:
  202. NONE
  203. --*/
  204. #define SetMatchedCheckBox(matchFlag, routingFlag, itemId) \
  205. CheckDlgButton(hDlg, itemId, \
  206. (match & (matchFlag)) ? \
  207. ((pDevInfo->Mask & (routingFlag)) ? BST_CHECKED : BST_UNCHECKED) : \
  208. BST_INDETERMINATE)
  209. #define SetMatchedTextField(matchFlag, itemId, pFieldName) \
  210. SetDlgItemText(hDlg, itemId, \
  211. ((match & (matchFlag)) && pDevInfo->pFieldName) ? \
  212. pDevInfo->pFieldName : TEXT(""))
  213. #define SetMatchedDWORDField(matchFlag, itemId, pFieldName) \
  214. SetDlgItemInt(hDlg, itemId, \
  215. (match & matchFlag) ? pDevInfo->pFieldName : 0, FALSE)
  216. {
  217. MATCHINFO matchInfo = { NULL, 0 };
  218. INT index = -1;
  219. DWORD match;
  220. HWND hwndList;
  221. PCONFIG_PORT_INFO_2 pDevInfo;
  222. //
  223. // Find the common attributes shared by selected devices
  224. //
  225. while ((index = ListView_GetNextItem(hwndLV, index, LVNI_ALL|LVNI_SELECTED)) != -1) {
  226. Assert(index < gConfigData->cDevices);
  227. MatchFaxDevInfo(&matchInfo, gConfigData->pDevInfo + index);
  228. }
  229. if ((pDevInfo = matchInfo.pDevInfo) == NULL)
  230. return;
  231. //
  232. // Display the shared attributes at the bottom of the page
  233. //
  234. match = matchInfo.match;
  235. SetMatchedCheckBox(MATCH_DEST_PRINTER, LR_PRINT, IDC_DEST_PRINTER);
  236. SetMatchedCheckBox(MATCH_DEST_EMAIL, LR_EMAIL, IDC_DEST_EMAIL);
  237. SetMatchedCheckBox(MATCH_DEST_DIR, LR_STORE, IDC_DEST_DIR);
  238. SetMatchedCheckBox(MATCH_DEST_MAILBOX, LR_INBOX, IDC_DEST_MAILBOX);
  239. if (hwndList = GetDlgItem(hDlg, IDC_DEST_PRINTERLIST)) {
  240. if ((match & MATCH_DEST_PRINTERNAME) && pDevInfo->PrinterName) {
  241. if (IsEmptyString(pDevInfo->PrinterName))
  242. SendMessage(hwndList, CB_SETCURSEL, 0, 0);
  243. else if (SendMessage(hwndList,
  244. CB_SELECTSTRING,
  245. (WPARAM) -1,
  246. (LPARAM) pDevInfo->PrinterName) == CB_ERR)
  247. {
  248. DisplayMessageDialog(hDlg,
  249. 0,
  250. IDS_WARNING_DLGTITLE,
  251. IDS_NONEXISTENT_PRINTER,
  252. pDevInfo->PrinterName);
  253. }
  254. } else
  255. SendMessage(hwndList, CB_SETCURSEL, (WPARAM) -1, 0);
  256. }
  257. if (hwndList = GetDlgItem(hDlg, IDC_DEST_PROFILENAME)) {
  258. if ((match & MATCH_DEST_PROFILENAME) && pDevInfo->ProfileName) {
  259. if (IsEmptyString(pDevInfo->ProfileName) ||
  260. ! SendMessage(hwndList,
  261. CB_SELECTSTRING,
  262. (WPARAM) -1,
  263. (LPARAM) pDevInfo->ProfileName))
  264. {
  265. SendMessage(hwndList, CB_SETCURSEL, 0, 0);
  266. }
  267. } else
  268. SendMessage(hwndList, CB_SETCURSEL, (WPARAM) -1, 0);
  269. }
  270. //
  271. // This is a real kluge. But we have no other way of telling whether
  272. // EN_CHANGE message is caused by user action or was caused by
  273. // us calling SetDlgItemText.
  274. //
  275. insideSetDlgItemText = TRUE;
  276. SetMatchedTextField(MATCH_DEST_DIRPATH, IDC_DEST_DIRPATH, DirStore);
  277. SetMatchedTextField(MATCH_DEST_CSID, IDC_CSID, CSID);
  278. SetMatchedDWORDField(MATCH_DEST_RINGS, IDC_DEST_RINGS, Rings);
  279. insideSetDlgItemText = FALSE;
  280. }
  281. BOOL
  282. ValidateReceiveOptions(
  283. HWND hDlg,
  284. INT index
  285. )
  286. /*++
  287. Routine Description:
  288. Check the receive options for the specified fax device
  289. Arguments:
  290. hDlg - Window handle to the "Receive Options" property page
  291. index - Specifies the index of the interested fax device
  292. Return Value:
  293. TRUE if successful, FALSE if there is an error
  294. --*/
  295. {
  296. PCONFIG_PORT_INFO_2 pDevInfo;
  297. INT errorId = 0;
  298. //
  299. // Sanity check
  300. //
  301. if (index >= gConfigData->cDevices || gConfigData->pDevInfo == NULL) {
  302. Assert(FALSE);
  303. return TRUE;
  304. }
  305. //
  306. // Check if the specified device is not enabled for receiving fax
  307. //
  308. pDevInfo = gConfigData->pDevInfo + index;
  309. if (! (pDevInfo->Flags & FPF_RECEIVE))
  310. return TRUE;
  311. if ((pDevInfo->Mask & (LR_PRINT|LR_STORE|LR_EMAIL|LR_INBOX)) == 0) {
  312. //
  313. // At least one inbound routing option must be selected
  314. //
  315. errorId = IDS_NO_INBOUND_ROUTING;
  316. } else if ((pDevInfo->Mask & LR_STORE) &&
  317. (pDevInfo->DirStore == NULL || *(pDevInfo->DirStore) == NUL))
  318. {
  319. //
  320. // If the "Store In Directory" option is selected,
  321. // a directory path must be specified.
  322. //
  323. errorId = IDS_MISSING_INBOUND_DIR;
  324. }
  325. //
  326. // Display an error message the receive options are invalid
  327. //
  328. if (errorId != 0) {
  329. DisplayMessageDialog(hDlg,
  330. 0,
  331. IDS_INVALID_INBOUND_OPTIONS,
  332. errorId,
  333. pDevInfo->DeviceName);
  334. }
  335. return (errorId == 0);
  336. }
  337. BOOL
  338. ValidateReceiveOptionsForSelectedDevices(
  339. HWND hDlg,
  340. HWND hwndLV
  341. )
  342. /*++
  343. Routine Description:
  344. Check if the receive options for the selected fax devices are valid
  345. Arguments:
  346. hDlg - Window handle to the "Receive Options" property page
  347. hwndLV - Handle to the fax device list
  348. Return Value:
  349. TRUE if successful, FALSE otherwise
  350. --*/
  351. {
  352. INT index = -1;
  353. //
  354. // Check the receive options for each selected device
  355. //
  356. while ((index = ListView_GetNextItem(hwndLV, index, LVNI_ALL|LVNI_SELECTED)) != -1) {
  357. if (! ValidateReceiveOptions(hDlg, index))
  358. return FALSE;
  359. }
  360. return TRUE;
  361. }
  362. VOID
  363. ToggleFaxDeviceForReceive(
  364. HWND hwndLV,
  365. INT index
  366. )
  367. /*++
  368. Routine Description:
  369. Toggle a fax device for receiving
  370. Arguments:
  371. hwndLV - Handle to the fax device list view
  372. index - Specifies the fax device to be toggled
  373. Return Value:
  374. NONE
  375. --*/
  376. {
  377. Assert(index < gConfigData->cDevices);
  378. if (IsListViewItemChecked(hwndLV, index)) {
  379. UncheckListViewItem(hwndLV, index);
  380. gConfigData->pDevInfo[index].Flags &= ~FPF_RECEIVE;
  381. } else {
  382. CheckListViewItem(hwndLV, index);
  383. gConfigData->pDevInfo[index].Flags |= FPF_RECEIVE;
  384. }
  385. }
  386. VOID
  387. UpdateReceiveOptionControls(
  388. HWND hDlg
  389. )
  390. /*++
  391. Routine Description:
  392. Enable/disable receive option controls
  393. Arguments:
  394. hDlg - Window handle to the "Receive Options" property page
  395. Return Value:
  396. NONE
  397. --*/
  398. {
  399. HWND hwndLV;
  400. //
  401. // Check if something is selected in the fax device list view
  402. //
  403. if ((hwndLV = GetDlgItem(hDlg, IDC_FAX_DEVICE_LIST)) == NULL ||
  404. ListView_GetNextItem(hwndLV, -1, LVNI_ALL|LVNI_SELECTED) == -1)
  405. {
  406. insideSetDlgItemText = TRUE;
  407. SetDlgItemText(hDlg, IDC_DEST_DIRPATH, TEXT(""));
  408. SetDlgItemText(hDlg, IDC_CSID, TEXT(""));
  409. SetDlgItemInt(hDlg, IDC_DEST_RINGS, 0, FALSE);
  410. insideSetDlgItemText = FALSE;
  411. SendDlgItemMessage(hDlg, IDC_DEST_PRINTERLIST, CB_SETCURSEL, (WPARAM) -1, 0);
  412. SendDlgItemMessage(hDlg, IDC_DEST_PROFILENAME, CB_SETCURSEL, (WPARAM) -1, 0);
  413. EnableWindow(GetDlgItem(hDlg, IDC_DEST_RINGS), FALSE);
  414. EnableWindow(GetDlgItem(hDlg, IDC_CSID), FALSE);
  415. EnableWindow(GetDlgItem(hDlg, IDC_DEST_PRINTER), FALSE);
  416. EnableWindow(GetDlgItem(hDlg, IDC_DEST_EMAIL), FALSE);
  417. EnableWindow(GetDlgItem(hDlg, IDC_DEST_DIR), FALSE);
  418. EnableWindow(GetDlgItem(hDlg, IDC_DEST_MAILBOX), FALSE);
  419. CheckDlgButton(hDlg, IDC_DEST_PRINTER, BST_UNCHECKED);
  420. CheckDlgButton(hDlg, IDC_DEST_EMAIL, BST_UNCHECKED);
  421. CheckDlgButton(hDlg, IDC_DEST_DIR, BST_UNCHECKED);
  422. CheckDlgButton(hDlg, IDC_DEST_MAILBOX, BST_UNCHECKED);
  423. } else {
  424. EnableWindow(GetDlgItem(hDlg, IDC_CSID), TRUE);
  425. EnableWindow(GetDlgItem(hDlg, IDC_DEST_PRINTER), TRUE);
  426. EnableWindow(GetDlgItem(hDlg, IDC_DEST_DIR), TRUE);
  427. EnableWindow(GetDlgItem(hDlg, IDC_DEST_EMAIL), TRUE);
  428. EnableWindow(GetDlgItem(hDlg, IDC_DEST_MAILBOX), gConfigData->pMapiProfiles != NULL);
  429. if (!GetDlgItemInt(hDlg, IDC_DEST_RINGS, NULL, FALSE)) {
  430. EnableWindow(GetDlgItem(hDlg, IDC_DEST_RINGS), FALSE);
  431. } else {
  432. EnableWindow(GetDlgItem(hDlg, IDC_DEST_RINGS), TRUE);
  433. }
  434. }
  435. EnableWindow(GetDlgItem(hDlg, IDC_DEST_PRINTERLIST),
  436. IsDlgButtonChecked(hDlg, IDC_DEST_PRINTER) == BST_CHECKED);
  437. EnableWindow(GetDlgItem(hDlg, IDC_DEST_DIRPATH),
  438. IsDlgButtonChecked(hDlg, IDC_DEST_DIR) == BST_CHECKED);
  439. EnableWindow(GetDlgItem(hDlg, IDC_BROWSE_DIR),
  440. IsDlgButtonChecked(hDlg, IDC_DEST_DIR) == BST_CHECKED &&
  441. gConfigData->pServerName == NULL);
  442. if (gConfigData->pMapiProfiles && IsDlgButtonChecked(hDlg, IDC_DEST_MAILBOX) == BST_CHECKED) {
  443. EnableWindow(GetDlgItem(hDlg, IDCSTATIC_PROFILE_NAME), TRUE);
  444. EnableWindow(GetDlgItem(hDlg, IDC_DEST_PROFILENAME), TRUE);
  445. } else {
  446. if (gConfigData->pMapiProfiles == NULL)
  447. CheckDlgButton(hDlg, IDC_DEST_MAILBOX, BST_UNCHECKED);
  448. EnableWindow(GetDlgItem(hDlg, IDCSTATIC_PROFILE_NAME), FALSE);
  449. EnableWindow(GetDlgItem(hDlg, IDC_DEST_PROFILENAME), FALSE);
  450. }
  451. }
  452. BOOL
  453. HandleRecvListViewMessage(
  454. HWND hDlg,
  455. LPNMHDR pNMHdr
  456. )
  457. /*++
  458. Routine Description:
  459. Handle notification events from the fax device list
  460. Arguments:
  461. hDlg - Window handle to the "Receive Options" property page
  462. pNMHdr - Points to an NMHDR structure
  463. Return Value:
  464. FALSE if there is no device assigned to the current printer
  465. TRUE otherwise
  466. --*/
  467. {
  468. LV_HITTESTINFO hitTestInfo;
  469. DWORD msgPos;
  470. INT index;
  471. NM_LISTVIEW *pnmlv;
  472. HWND hwndLV = pNMHdr->hwndFrom;
  473. switch (pNMHdr->code) {
  474. case NM_CLICK:
  475. //
  476. // Figure out which item (if any) was clicked on
  477. //
  478. msgPos = GetMessagePos();
  479. hitTestInfo.pt.x = LOWORD(msgPos);
  480. hitTestInfo.pt.y = HIWORD(msgPos);
  481. MapWindowPoints(HWND_DESKTOP, hwndLV, &hitTestInfo.pt, 1 );
  482. index = ListView_HitTest(hwndLV, &hitTestInfo);
  483. if (index == -1 || ! (hitTestInfo.flags & LVHT_ONITEMSTATEICON))
  484. return FALSE;
  485. //
  486. // Toggle between checked and unchecked state
  487. //
  488. ToggleFaxDeviceForReceive(hwndLV, index);
  489. return TRUE;
  490. case LVN_KEYDOWN:
  491. //
  492. // Use space key to toggle check boxes
  493. //
  494. if (((LV_KEYDOWN *) pNMHdr)->wVKey == VK_SPACE) {
  495. index = ListView_GetNextItem(hwndLV, -1, LVNI_ALL|LVNI_SELECTED);
  496. if (index != -1) {
  497. ToggleFaxDeviceForReceive(hwndLV, index);
  498. return TRUE;
  499. }
  500. }
  501. break;
  502. case LVN_ITEMCHANGING:
  503. //
  504. // Validate receive options before switch to another device
  505. //
  506. pnmlv = (NM_LISTVIEW *) pNMHdr;
  507. if ((pnmlv->uChanged & LVIF_STATE) != 0 &&
  508. (pnmlv->uOldState & LVIS_SELECTED) != (pnmlv->uNewState & LVIS_SELECTED) &&
  509. ! ValidateReceiveOptionsForSelectedDevices(hDlg, hwndLV))
  510. {
  511. return TRUE;
  512. }
  513. break;
  514. case LVN_ITEMCHANGED:
  515. //
  516. // Update the contents at the bottom of the page
  517. // when there is a selection change
  518. //
  519. pnmlv = (NM_LISTVIEW *) pNMHdr;
  520. if ((pnmlv->uChanged & LVIF_STATE) != 0 &&
  521. (pnmlv->uOldState & LVIS_SELECTED) != (pnmlv->uNewState & LVIS_SELECTED))
  522. {
  523. Verbose(("Selection change: %d\n", pnmlv->iItem));
  524. DoChangeRecvDeviceSel(hDlg, hwndLV);
  525. UpdateReceiveOptionControls(hDlg);
  526. }
  527. break;
  528. }
  529. return FALSE;
  530. }
  531. VOID
  532. DoActivateRecvOptions(
  533. HWND hDlg
  534. )
  535. /*++
  536. Routine Description:
  537. Called when the "Receive Options" property page is activated
  538. Arguments:
  539. hDlg - Window handle to the "Receive Options" property page
  540. Return Value:
  541. NONE
  542. --*/
  543. {
  544. HWND hwndLV;
  545. INT index;
  546. //
  547. // Reinitialize the fax device list view if necessary
  548. //
  549. if (!IsFaxDeviceListInSync(RECEIVE_OPTIONS_PAGE) &&
  550. (hwndLV = GetDlgItem(hDlg, IDC_FAX_DEVICE_LIST)))
  551. {
  552. InitFaxDeviceListView(hwndLV, LV_HASCHECKBOX, faxDeviceListViewColumnInfo);
  553. for (index=0; index < gConfigData->cDevices; index++) {
  554. if (gConfigData->pDevInfo[index].Flags & FPF_RECEIVE) {
  555. CheckListViewItem(hwndLV, index);
  556. }
  557. }
  558. }
  559. SetFaxDeviceListInSync(RECEIVE_OPTIONS_PAGE);
  560. if (gConfigData->configType & FAXCONFIG_WORKSTATION) {
  561. HideWindow( GetDlgItem( hDlg, IDC_DEST_EMAIL ) );
  562. }
  563. }
  564. BOOL
  565. DoSaveRecvOptions(
  566. HWND hDlg
  567. )
  568. /*++
  569. Routine Description:
  570. Save the information on the "Receive Options" property page
  571. Arguments:
  572. hDlg - Handle to the "Receive Options" property page
  573. Return Value:
  574. TRUE if successful, FALSE if there is an error
  575. --*/
  576. {
  577. INT index;
  578. //
  579. // Check if anything on this page was changed
  580. //
  581. Verbose(("Saving 'Receive Options' page ...\n"));
  582. if (! GetChangedFlag(RECEIVE_OPTIONS_PAGE))
  583. return TRUE;
  584. //
  585. // Validate the inbound routing options for all fax devics
  586. //
  587. for (index=0; index < gConfigData->cDevices; index++) {
  588. if (! ValidateReceiveOptions(hDlg, index))
  589. return FALSE;
  590. }
  591. //
  592. // Save the fax device information if this is the last modified page
  593. //
  594. return SaveFaxDeviceAndConfigInfo(hDlg, RECEIVE_OPTIONS_PAGE);
  595. }
  596. BOOL
  597. GetDestPrinterName(
  598. HWND hwndList,
  599. LPTSTR pBuffer,
  600. INT cch
  601. )
  602. /*++
  603. Routine Description:
  604. Retrieve the name of the currently selected inbound destination printer.
  605. Also used to get the mapi profile name.
  606. Arguments:
  607. hwndList - Specifies the inbound destination printer list box
  608. pBuffer - Specifies a buffer for storing the selected printer name
  609. cch - Size of the buffer in characters
  610. Return Value:
  611. TRUE if successful
  612. FALSE if there is no selection or if there is an error
  613. --*/
  614. {
  615. INT sel, length;
  616. pBuffer[0] = NUL;
  617. if (hwndList && (sel = SendMessage(hwndList, CB_GETCURSEL, 0, 0)) != CB_ERR) {
  618. //
  619. // Get the current selection index. The first item is special:
  620. // It means to use the sytem default printer and not a specific printer name.
  621. //
  622. if ((sel == 0) ||
  623. (length = SendMessage(hwndList, CB_GETLBTEXTLEN, sel, 0)) != CB_ERR &&
  624. (length < cch) &&
  625. SendMessage(hwndList, CB_GETLBTEXT, sel, (LPARAM) pBuffer) != CB_ERR)
  626. {
  627. return TRUE;
  628. }
  629. }
  630. return FALSE;
  631. }
  632. VOID
  633. DoChangeInboundRouting(
  634. HWND hDlg,
  635. INT itemId
  636. )
  637. /*++
  638. Routine Description:
  639. Called when the user changes any inbound routing options
  640. Arguments:
  641. hDlg - Handle to the "Receive Options" property page
  642. itemId - Specifies which inbound routing option is changed
  643. Return Value:
  644. NONE
  645. --*/
  646. {
  647. TCHAR buffer[MAX_STRING_LEN];
  648. DWORD dwValue;
  649. DWORD routing, routingMask = 0;
  650. INT index;
  651. HWND hwndLV;
  652. if (! (hwndLV = GetDlgItem(hDlg, IDC_FAX_DEVICE_LIST)))
  653. return;
  654. //
  655. // Figure out the new setting of the changing item
  656. //
  657. switch (itemId) {
  658. case IDC_DEST_PRINTER:
  659. routingMask = LR_PRINT;
  660. break;
  661. case IDC_DEST_DIR:
  662. routingMask = LR_STORE;
  663. break;
  664. case IDC_DEST_EMAIL:
  665. routingMask = LR_EMAIL;
  666. break;
  667. case IDC_DEST_PRINTERLIST:
  668. if (! GetDestPrinterName(GetDlgItem(hDlg, IDC_DEST_PRINTERLIST), buffer, MAX_STRING_LEN))
  669. return;
  670. break;
  671. case IDC_DEST_MAILBOX:
  672. routingMask = LR_INBOX;
  673. break;
  674. case IDC_DEST_PROFILENAME:
  675. if (! GetDestPrinterName(GetDlgItem(hDlg, IDC_DEST_PROFILENAME), buffer, MAX_STRING_LEN))
  676. return;
  677. break;
  678. case IDC_DEST_DIRPATH:
  679. case IDC_CSID:
  680. if (! GetDlgItemText(hDlg, itemId, buffer, MAX_STRING_LEN))
  681. buffer[0] = NUL;
  682. break;
  683. case IDC_DEST_RINGS:
  684. dwValue = GetDlgItemInt( hDlg, itemId, NULL, FALSE );
  685. break;
  686. default:
  687. Assert(FALSE);
  688. return;
  689. }
  690. if (routingMask != 0)
  691. routing = IsDlgButtonChecked(hDlg, itemId) ? routingMask : 0;
  692. //
  693. // Apply the change to selected fax device(s)
  694. //
  695. index = -1;
  696. while ((index = ListView_GetNextItem(hwndLV, index, LVNI_ALL|LVNI_SELECTED)) != -1) {
  697. PCONFIG_PORT_INFO_2 pDevInfo;
  698. Assert(index < gConfigData->cDevices);
  699. pDevInfo = gConfigData->pDevInfo + index;
  700. if (routingMask) {
  701. pDevInfo->Mask &= ~routingMask;
  702. pDevInfo->Mask |= routing;
  703. } else if (itemId == IDC_DEST_RINGS) {
  704. pDevInfo->Rings = dwValue;
  705. } else {
  706. LPTSTR *ppStr;
  707. switch (itemId) {
  708. case IDC_DEST_PRINTERLIST:
  709. ppStr = &pDevInfo->PrinterName;
  710. break;
  711. case IDC_DEST_DIRPATH:
  712. ppStr = &pDevInfo->DirStore;
  713. break;
  714. case IDC_DEST_PROFILENAME:
  715. ppStr = &pDevInfo->ProfileName;
  716. break;
  717. case IDC_CSID:
  718. ppStr = &pDevInfo->CSID;
  719. break;
  720. default:
  721. Assert(FALSE);
  722. return;
  723. }
  724. MemFree(*ppStr);
  725. *ppStr = DuplicateString(buffer);
  726. }
  727. }
  728. }
  729. BOOL
  730. ReceiveOptionsProc(
  731. HWND hDlg,
  732. UINT message,
  733. UINT wParam,
  734. LONG lParam
  735. )
  736. /*++
  737. Routine Description:
  738. Procedure for handling the "Receive Options" tab
  739. Arguments:
  740. hDlg - Identifies the property sheet page
  741. message - Specifies the message
  742. wParam - Specifies additional message-specific information
  743. lParam - Specifies additional message-specific information
  744. Return Value:
  745. Depends on the value of message parameter
  746. --*/
  747. {
  748. INT cmdId;
  749. LPNMHDR pNMHdr;
  750. switch (message) {
  751. case WM_INITDIALOG:
  752. DoInitRecvOptions(hDlg);
  753. return TRUE;
  754. case WM_COMMAND:
  755. switch (cmdId = GET_WM_COMMAND_ID(wParam, lParam)) {
  756. case IDC_DEST_PRINTER:
  757. case IDC_DEST_DIR:
  758. case IDC_DEST_EMAIL:
  759. case IDC_DEST_MAILBOX:
  760. if (GET_WM_COMMAND_CMD(wParam, lParam) != BN_CLICKED)
  761. return FALSE;
  762. CheckDlgButton(hDlg, cmdId,
  763. (IsDlgButtonChecked(hDlg, cmdId) == BST_CHECKED) ? BST_UNCHECKED : BST_CHECKED);
  764. UpdateReceiveOptionControls(hDlg);
  765. break;
  766. case IDC_BROWSE_DIR:
  767. if (! DoBrowseForDirectory(hDlg, IDC_DEST_DIRPATH, IDS_INBOUND_DIR))
  768. return TRUE;
  769. cmdId = IDC_DEST_DIRPATH;
  770. break;
  771. case IDC_DEST_PROFILENAME:
  772. case IDC_DEST_PRINTERLIST:
  773. if (GET_WM_COMMAND_CMD(wParam, lParam) != CBN_SELCHANGE)
  774. return TRUE;
  775. break;
  776. case IDC_DEST_DIRPATH:
  777. case IDC_DEST_RINGS:
  778. //
  779. // We would like to change our internal data only after EN_KILLFOCUS.
  780. // But the list view control gets selection change message before
  781. // the edit controls get kill focus message.
  782. //
  783. //
  784. if (insideSetDlgItemText) {
  785. return TRUE;
  786. }
  787. if (cmdId == IDC_DEST_RINGS && GET_WM_COMMAND_CMD(wParam, lParam) == EN_UPDATE) {
  788. BOOL Rslt; DWORD Value;
  789. Value = GetDlgItemInt(hDlg, IDC_DEST_RINGS, &Rslt, FALSE);
  790. if (Rslt && Value == 0) {
  791. SetDlgItemText(hDlg, IDC_DEST_RINGS, TEXT("") );
  792. MessageBeep(0);
  793. return TRUE;
  794. }
  795. }
  796. if (GET_WM_COMMAND_CMD(wParam, lParam) != EN_CHANGE) {
  797. return TRUE;
  798. }
  799. break;
  800. case IDC_CSID:
  801. switch (GET_WM_COMMAND_CMD(wParam, lParam)) {
  802. case EN_CHANGE:
  803. if (insideSetDlgItemText)
  804. return TRUE;
  805. break;
  806. case EN_KILLFOCUS:
  807. UpdateFaxDeviceListViewColumns(GetDlgItem(hDlg, IDC_FAX_DEVICE_LIST),
  808. faxDeviceListViewColumnInfo,
  809. 1);
  810. default:
  811. return TRUE;
  812. }
  813. break;
  814. default:
  815. return FALSE;
  816. }
  817. DoChangeInboundRouting(hDlg, cmdId);
  818. SetChangedFlag(hDlg, RECEIVE_OPTIONS_PAGE, TRUE);
  819. return TRUE;
  820. case WM_NOTIFY:
  821. pNMHdr = (NMHDR *) lParam;
  822. if (pNMHdr->hwndFrom == GetDlgItem(hDlg, IDC_FAX_DEVICE_LIST)) {
  823. if (HandleRecvListViewMessage(hDlg, pNMHdr))
  824. SetChangedFlag(hDlg, RECEIVE_OPTIONS_PAGE, TRUE);
  825. } else switch (pNMHdr->code) {
  826. case PSN_SETACTIVE:
  827. DoActivateRecvOptions(hDlg);
  828. break;
  829. case PSN_APPLY:
  830. //
  831. // User pressed OK or Apply - validate inputs and save changes
  832. //
  833. if (! DoSaveRecvOptions(hDlg)) {
  834. SetWindowLong(hDlg, DWL_MSGRESULT, -1);
  835. return PSNRET_INVALID_NOCHANGEPAGE;
  836. } else {
  837. SetChangedFlag(hDlg, RECEIVE_OPTIONS_PAGE, FALSE);
  838. return PSNRET_NOERROR;
  839. }
  840. }
  841. break;
  842. case WM_HELP:
  843. case WM_CONTEXTMENU:
  844. return HandleHelpPopup(hDlg, message, wParam, lParam, RECEIVE_OPTIONS_PAGE);
  845. }
  846. return FALSE;
  847. }