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.

1792 lines
53 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. devinfo.c
  5. Abstract:
  6. Property sheet handler for "Device" page
  7. Environment:
  8. Fax driver user interface
  9. Revision History:
  10. 04/09/00 -taoyuan-
  11. Created it.
  12. mm/dd/yy -author-
  13. description
  14. --*/
  15. #include <stdio.h>
  16. #include "faxui.h"
  17. #include "resource.h"
  18. #include "faxuiconstants.h"
  19. //
  20. // List of controls displayes for desktop SKUs only
  21. //
  22. DWORD
  23. g_dwDesktopControls[] =
  24. {
  25. IDC_BRANDING_CHECK,
  26. IDC_RETRIES_STATIC,
  27. IDC_RETRIES_EDIT,
  28. IDC_RETRIES_SPIN,
  29. IDC_OUTB_RETRYDELAY_STATIC,
  30. IDC_RETRYDELAY_EDIT,
  31. IDC_RETRYDELAY_SPIN,
  32. IDC_OUTB_MINUTES_STATIC,
  33. IDC_OUTB_DIS_START_STATIC,
  34. IDC_DISCOUNT_START_TIME,
  35. IDC_OUTB_DIS_STOP_STATIC,
  36. IDC_DISCOUNT_STOP_TIME,
  37. 0
  38. };
  39. static BOOL
  40. SaveSendChanges(IN HWND hDlg);
  41. PPRINTER_NAMES g_pPrinterNames = NULL;
  42. DWORD g_dwNumPrinters = 0;
  43. BOOL
  44. ValidateSend(
  45. HWND hDlg
  46. )
  47. /*++
  48. Routine Description:
  49. Validate the check box and controls for send
  50. Arguments:
  51. hDlg - Handle to the property sheet page
  52. Return Value:
  53. TRUE -- if no error
  54. FALSE -- if error
  55. --*/
  56. {
  57. BOOL bEnabled;
  58. if(g_bUserCanChangeSettings)
  59. {
  60. bEnabled = IsDlgButtonChecked(hDlg, IDC_DEVICE_PROP_SEND) == BST_CHECKED;
  61. //
  62. // Enable/disable controls according to "Enable Send" check box
  63. //
  64. PageEnable(hDlg, bEnabled);
  65. if(!bEnabled)
  66. {
  67. //
  68. // Enable "Enable Send" check box
  69. //
  70. EnableWindow(GetDlgItem(hDlg, IDC_DEVICE_PROP_SEND), TRUE);
  71. SetFocus(GetDlgItem(hDlg, IDC_DEVICE_PROP_SEND));
  72. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_SEND_ICON), TRUE);
  73. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_SEND_OPTIONS), TRUE);
  74. ShowWindow (GetDlgItem(hDlg, IDC_ICON_STORE_IN_FOLDER), SW_HIDE);
  75. ShowWindow (GetDlgItem(hDlg, IDC_STATIC_STORE_IN_FOLDER), SW_HIDE);
  76. }
  77. else
  78. {
  79. ShowWindow (GetDlgItem(hDlg, IDC_ICON_STORE_IN_FOLDER), SW_SHOW);
  80. ShowWindow (GetDlgItem(hDlg, IDC_STATIC_STORE_IN_FOLDER), SW_SHOW);
  81. }
  82. }
  83. else
  84. {
  85. PageEnable(hDlg, FALSE);
  86. ShowWindow (GetDlgItem(hDlg, IDC_ICON_STORE_IN_FOLDER), SW_HIDE);
  87. ShowWindow (GetDlgItem(hDlg, IDC_STATIC_STORE_IN_FOLDER), SW_HIDE);
  88. }
  89. return TRUE;
  90. }
  91. INT_PTR
  92. CALLBACK
  93. DevSendDlgProc(
  94. IN HWND hDlg,
  95. IN UINT message,
  96. IN WPARAM wParam,
  97. IN LPARAM lParam
  98. )
  99. /*++
  100. Routine Description:
  101. Dialog procedure for send settings
  102. Arguments:
  103. hDlg - Identifies the property sheet page
  104. message - Specifies the message
  105. wParam - Specifies additional message-specific information
  106. lParam - Specifies additional message-specific information
  107. Return Value:
  108. Depending on specific message
  109. --*/
  110. {
  111. BOOL fRet = FALSE;
  112. PFAX_PORT_INFO_EX pFaxPortInfo = NULL; // receive port information
  113. DWORD dwDeviceId;
  114. switch( message )
  115. {
  116. case WM_INITDIALOG:
  117. {
  118. SYSTEMTIME sTime = {0};
  119. PFAX_OUTBOX_CONFIG pOutboxConfig = NULL;
  120. TCHAR tszSecondsFreeTimeFormat[MAX_PATH];
  121. //
  122. //Get the shared data from PROPSHEETPAGE lParam value
  123. //and load it into GWL_USERDATA
  124. //
  125. dwDeviceId = (DWORD)((LPPROPSHEETPAGE)lParam)->lParam;
  126. SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)dwDeviceId);
  127. SendDlgItemMessage(hDlg, IDC_DEVICE_PROP_TSID, EM_SETLIMITTEXT, TSID_LIMIT, 0);
  128. pFaxPortInfo = FindPortInfo(dwDeviceId);
  129. if(!pFaxPortInfo)
  130. {
  131. Error(("FindPortInfo() failed.\n"));
  132. Assert(FALSE);
  133. fRet = TRUE;
  134. break;
  135. }
  136. CheckDlgButton(hDlg, IDC_DEVICE_PROP_SEND, pFaxPortInfo->bSend ? BST_CHECKED : BST_UNCHECKED);
  137. SetDlgItemText(hDlg, IDC_DEVICE_PROP_TSID, pFaxPortInfo->lptstrTsid);
  138. if(!IsDesktopSKU())
  139. {
  140. //
  141. // Hide desktop controls for non desktop platform
  142. //
  143. DWORD dw;
  144. for(dw=0; g_dwDesktopControls[dw] != 0; ++dw)
  145. {
  146. ShowWindow(GetDlgItem(hDlg, g_dwDesktopControls[dw]), SW_HIDE);
  147. }
  148. goto InitDlgExit;
  149. }
  150. //
  151. // Update desktop controls
  152. //
  153. if(!Connect(hDlg, TRUE))
  154. {
  155. goto InitDlgExit;
  156. }
  157. if(!FaxGetOutboxConfiguration(g_hFaxSvcHandle, &pOutboxConfig))
  158. {
  159. Error(( "FaxGetOutboxConfiguration() failed with %d.\n", GetLastError()));
  160. goto InitDlgExit;
  161. }
  162. //
  163. // Branding
  164. //
  165. CheckDlgButton(hDlg, IDC_BRANDING_CHECK, pOutboxConfig->bBranding ? BST_CHECKED : BST_UNCHECKED);
  166. //
  167. // Retries
  168. //
  169. SendDlgItemMessage(hDlg, IDC_RETRIES_EDIT, EM_SETLIMITTEXT, FXS_RETRIES_LENGTH, 0);
  170. #if FXS_RETRIES_LOWER > 0
  171. if (pOutboxConfig->dwRetries < FXS_RETRIES_LOWER)
  172. {
  173. pOutboxConfig->dwRetries = FXS_RETRIES_LOWER;
  174. }
  175. #endif
  176. if (pOutboxConfig->dwRetries > FXS_RETRIES_UPPER)
  177. {
  178. pOutboxConfig->dwRetries = FXS_RETRIES_UPPER;
  179. }
  180. SendDlgItemMessage(hDlg, IDC_RETRIES_SPIN, UDM_SETRANGE32, FXS_RETRIES_LOWER, FXS_RETRIES_UPPER);
  181. SendDlgItemMessage(hDlg, IDC_RETRIES_SPIN, UDM_SETPOS32, 0, (LPARAM)pOutboxConfig->dwRetries);
  182. SetDlgItemInt(hDlg, IDC_RETRIES_EDIT, pOutboxConfig->dwRetries, FALSE);
  183. //
  184. // Retry Delay
  185. //
  186. SendDlgItemMessage(hDlg, IDC_RETRYDELAY_EDIT, EM_SETLIMITTEXT, FXS_RETRYDELAY_LENGTH, 0);
  187. #if FXS_RETRYDELAY_LOWER > 0
  188. if (pOutboxConfig->dwRetryDelay < FXS_RETRYDELAY_LOWER)
  189. {
  190. pOutboxConfig->dwRetryDelay = FXS_RETRYDELAY_LOWER;
  191. }
  192. #endif
  193. if (pOutboxConfig->dwRetryDelay > FXS_RETRYDELAY_UPPER)
  194. {
  195. pOutboxConfig->dwRetryDelay = FXS_RETRYDELAY_UPPER;
  196. }
  197. SendDlgItemMessage(hDlg, IDC_RETRYDELAY_SPIN, UDM_SETRANGE32, FXS_RETRYDELAY_LOWER, FXS_RETRYDELAY_UPPER);
  198. SendDlgItemMessage(hDlg, IDC_RETRYDELAY_SPIN, UDM_SETPOS32, 0, (LPARAM)pOutboxConfig->dwRetryDelay);
  199. SetDlgItemInt(hDlg, IDC_RETRYDELAY_EDIT, pOutboxConfig->dwRetryDelay, FALSE);
  200. //
  201. // Discount rate start time
  202. //
  203. GetSecondsFreeTimeFormat(tszSecondsFreeTimeFormat, MAX_PATH);
  204. GetLocalTime(&sTime);
  205. sTime.wHour = pOutboxConfig->dtDiscountStart.Hour;
  206. sTime.wMinute = pOutboxConfig->dtDiscountStart.Minute;
  207. SendDlgItemMessage(hDlg, IDC_DISCOUNT_START_TIME, DTM_SETFORMAT, 0, (LPARAM)tszSecondsFreeTimeFormat);
  208. SendDlgItemMessage(hDlg, IDC_DISCOUNT_START_TIME, DTM_SETSYSTEMTIME, (WPARAM)GDT_VALID, (LPARAM)&sTime);
  209. //
  210. // Discount rate stop time
  211. //
  212. sTime.wHour = pOutboxConfig->dtDiscountEnd.Hour;
  213. sTime.wMinute = pOutboxConfig->dtDiscountEnd.Minute;
  214. SendDlgItemMessage(hDlg, IDC_DISCOUNT_STOP_TIME, DTM_SETFORMAT, 0, (LPARAM)tszSecondsFreeTimeFormat);
  215. SendDlgItemMessage(hDlg, IDC_DISCOUNT_STOP_TIME, DTM_SETSYSTEMTIME, (WPARAM)GDT_VALID, (LPARAM)&sTime);
  216. FaxFreeBuffer(pOutboxConfig);
  217. InitDlgExit:
  218. ValidateSend(hDlg);
  219. fRet = TRUE;
  220. break;
  221. }
  222. case WM_COMMAND:
  223. {
  224. // activate apply button
  225. WORD wID = LOWORD( wParam );
  226. switch( wID )
  227. {
  228. case IDC_DEVICE_PROP_TSID:
  229. case IDC_RETRIES_EDIT:
  230. case IDC_RETRYDELAY_EDIT:
  231. case IDC_DISCOUNT_START_TIME:
  232. case IDC_DISCOUNT_STOP_TIME:
  233. if( HIWORD(wParam) == EN_CHANGE )
  234. { // notification code
  235. Notify_Change(hDlg);
  236. }
  237. fRet = TRUE;
  238. break;
  239. case IDC_DEVICE_PROP_SEND:
  240. if ( HIWORD(wParam) == BN_CLICKED )
  241. {
  242. if(IsDlgButtonChecked(hDlg, IDC_DEVICE_PROP_SEND) == BST_CHECKED)
  243. {
  244. dwDeviceId = (DWORD)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  245. if(!IsDeviceInUse(dwDeviceId) &&
  246. GetDeviceLimit() == CountUsedFaxDevices())
  247. {
  248. CheckDlgButton(hDlg, IDC_DEVICE_PROP_SEND, BST_UNCHECKED);
  249. DisplayErrorMessage(hDlg,
  250. MB_OK | MB_ICONSTOP,
  251. FAXUI_ERROR_DEVICE_LIMIT,
  252. GetDeviceLimit());
  253. fRet = TRUE;
  254. break;
  255. }
  256. }
  257. // notification code
  258. ValidateSend(hDlg);
  259. Notify_Change(hDlg);
  260. }
  261. fRet = TRUE;
  262. break;
  263. default:
  264. break;
  265. } // switch
  266. break;
  267. }
  268. case WM_NOTIFY:
  269. {
  270. switch( ((LPNMHDR) lParam)->code )
  271. {
  272. case PSN_APPLY:
  273. SaveSendChanges(hDlg);
  274. fRet = TRUE;
  275. break;
  276. case DTN_DATETIMECHANGE: // Date/time picker has changed
  277. Notify_Change(hDlg);
  278. fRet = TRUE;
  279. break;
  280. default:
  281. break;
  282. }
  283. break;
  284. }
  285. case WM_HELP:
  286. WinHelpContextPopup(((LPHELPINFO)lParam)->dwContextId, hDlg);
  287. return TRUE;
  288. } // switch
  289. return fRet;
  290. }
  291. BOOL
  292. ValidateReceive(
  293. HWND hDlg
  294. )
  295. /*++
  296. Routine Description:
  297. Validate the check box and controls for receive
  298. Arguments:
  299. hDlg - Handle to the property sheet page
  300. Return Value:
  301. TRUE -- if no error
  302. FALSE -- if error
  303. --*/
  304. {
  305. BOOL bEnabled; // enable/disable controls
  306. BOOL bManualAnswer;
  307. BOOL bVirtual; // Is the device virtual?
  308. // if g_bUserCanChangeSettings is FALSE, controls are disabled by default.
  309. if(g_bUserCanChangeSettings)
  310. {
  311. DWORD dwDeviceId;
  312. DWORD dwRes;
  313. dwDeviceId = (DWORD)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  314. Assert (dwDeviceId);
  315. if(!Connect(hDlg, TRUE))
  316. {
  317. return FALSE;
  318. }
  319. dwRes = IsDeviceVirtual (g_hFaxSvcHandle, dwDeviceId, &bVirtual);
  320. if (ERROR_SUCCESS != dwRes)
  321. {
  322. return FALSE;
  323. }
  324. DisConnect ();
  325. bEnabled = IsDlgButtonChecked(hDlg, IDC_DEVICE_PROP_RECEIVE) == BST_CHECKED;
  326. if(bEnabled &&
  327. IsDlgButtonChecked(hDlg, IDC_DEVICE_PROP_AUTO_ANSWER) != BST_CHECKED &&
  328. IsDlgButtonChecked(hDlg, IDC_DEVICE_PROP_MANUAL_ANSWER) != BST_CHECKED)
  329. {
  330. //
  331. // Set default to auto answer
  332. //
  333. CheckDlgButton(hDlg, IDC_DEVICE_PROP_AUTO_ANSWER, BST_CHECKED);
  334. }
  335. EnableWindow(GetDlgItem(hDlg, IDC_DEVICE_PROP_CSID), bEnabled);
  336. EnableWindow(GetDlgItem(hDlg, IDC_DEVICE_PROP_MANUAL_ANSWER), bEnabled && !bVirtual);
  337. EnableWindow(GetDlgItem(hDlg, IDC_DEVICE_PROP_AUTO_ANSWER), bEnabled);
  338. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_RINGS1), bEnabled);
  339. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_CSID1), bEnabled);
  340. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_CSID), bEnabled);
  341. EnableWindow(GetDlgItem(hDlg, IDCSTATIC_ANSWER_MODE), bEnabled);
  342. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_ROUTE), bEnabled);
  343. EnableWindow(GetDlgItem(hDlg, IDCSTATIC_AUTO_ANSWER), bEnabled);
  344. bManualAnswer = IsDlgButtonChecked(hDlg, IDC_DEVICE_PROP_MANUAL_ANSWER);
  345. Assert (!(bVirtual && bManualAnswer));
  346. EnableWindow(GetDlgItem(hDlg, IDC_DEVICE_PROP_RINGS), bEnabled && !bManualAnswer && !bVirtual);
  347. EnableWindow(GetDlgItem(hDlg, IDC_DEVICE_PROP_SPIN_RINGS), bEnabled && !bManualAnswer && !bVirtual);
  348. if (bVirtual)
  349. {
  350. //
  351. // Virtual devices always answer after one ring
  352. //
  353. SetDlgItemInt (hDlg, IDC_DEVICE_PROP_RINGS, 1, FALSE);
  354. }
  355. EnableWindow(GetDlgItem(hDlg, IDC_DEVICE_PROP_PRINT), bEnabled);
  356. EnableWindow(GetDlgItem(hDlg, IDC_DEVICE_PROP_PRINT_TO), bEnabled
  357. && IsDlgButtonChecked(hDlg, IDC_DEVICE_PROP_PRINT));
  358. EnableWindow(GetDlgItem(hDlg, IDC_DEVICE_PROP_SAVE), bEnabled);
  359. EnableWindow(GetDlgItem(hDlg, IDC_DEVICE_PROP_DEST_FOLDER), bEnabled
  360. && IsDlgButtonChecked(hDlg, IDC_DEVICE_PROP_SAVE));
  361. EnableWindow(GetDlgItem(hDlg, IDC_DEVICE_PROP_DEST_FOLDER_BR), bEnabled
  362. && IsDlgButtonChecked(hDlg, IDC_DEVICE_PROP_SAVE));
  363. EnableWindow(GetDlgItem(hDlg, IDC_ICON_STORE_IN_FOLDER), bEnabled);
  364. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_STORE_IN_FOLDER), bEnabled);
  365. ShowWindow (GetDlgItem(hDlg, IDC_ICON_STORE_IN_FOLDER), bEnabled ? SW_SHOW : SW_HIDE);
  366. ShowWindow (GetDlgItem(hDlg, IDC_STATIC_STORE_IN_FOLDER), bEnabled ? SW_SHOW : SW_HIDE);
  367. }
  368. else
  369. {
  370. PageEnable(hDlg, FALSE);
  371. ShowWindow (GetDlgItem(hDlg, IDC_ICON_STORE_IN_FOLDER), SW_HIDE);
  372. ShowWindow (GetDlgItem(hDlg, IDC_STATIC_STORE_IN_FOLDER), SW_HIDE);
  373. }
  374. return TRUE;
  375. }
  376. BOOL
  377. InitReceiveInfo(
  378. HWND hDlg
  379. )
  380. /*++
  381. Routine Description:
  382. Initialize the routing information for specific device
  383. Arguments:
  384. hDlg - the dialog handle of the dialog
  385. Return Value:
  386. TRUE if success, FALSE otherwise
  387. --*/
  388. {
  389. DWORD dwDeviceId;
  390. HWND hControl;
  391. PFAX_PORT_INFO_EX pFaxPortInfo;
  392. LPBYTE pRoutingInfoBuffer;
  393. DWORD dwRoutingInfoBufferSize;
  394. DWORD dwCurrentRM;
  395. BOOL bSuccessed = TRUE;
  396. Verbose(("Entering InitReceiveInfo...\n"));
  397. //
  398. // Get device id from dialog page
  399. //
  400. dwDeviceId = (DWORD)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  401. pFaxPortInfo = FindPortInfo(dwDeviceId);
  402. if(!pFaxPortInfo)
  403. {
  404. Error(("FindPortInfo() failed.\n"));
  405. Assert(FALSE);
  406. return FALSE;
  407. }
  408. // set up the check box
  409. EnableWindow(GetDlgItem(hDlg, IDC_DEVICE_PROP_RECEIVE), g_bUserCanChangeSettings);
  410. CheckDlgButton(hDlg, IDC_DEVICE_PROP_RECEIVE, pFaxPortInfo->ReceiveMode != FAX_DEVICE_RECEIVE_MODE_OFF);
  411. // set up the CSID control
  412. SetDlgItemText(hDlg, IDC_DEVICE_PROP_CSID, pFaxPortInfo->lptstrCsid);
  413. // setup the ring count spinner control
  414. hControl = GetDlgItem(hDlg, IDC_DEVICE_PROP_SPIN_RINGS);
  415. if(MIN_RING_COUNT <= pFaxPortInfo->dwRings && pFaxPortInfo->dwRings <= MAX_RING_COUNT)
  416. {
  417. SetDlgItemInt(hDlg, IDC_DEVICE_PROP_RINGS, pFaxPortInfo->dwRings, FALSE);
  418. SendMessage( hControl, UDM_SETPOS32, 0, (LPARAM) MAKELONG(pFaxPortInfo->dwRings, 0) );
  419. }
  420. else
  421. {
  422. SetDlgItemInt(hDlg, IDC_DEVICE_PROP_RINGS, DEFAULT_RING_COUNT, FALSE);
  423. SendMessage( hControl, UDM_SETPOS32, 0, (LPARAM) MAKELONG(DEFAULT_RING_COUNT, 0) );
  424. }
  425. //
  426. // Answer mode
  427. //
  428. if (FAX_DEVICE_RECEIVE_MODE_MANUAL == pFaxPortInfo->ReceiveMode)
  429. {
  430. CheckDlgButton(hDlg, IDC_DEVICE_PROP_MANUAL_ANSWER, TRUE);
  431. }
  432. else if (FAX_DEVICE_RECEIVE_MODE_AUTO == pFaxPortInfo->ReceiveMode)
  433. {
  434. CheckDlgButton(hDlg, IDC_DEVICE_PROP_AUTO_ANSWER, TRUE);
  435. }
  436. //
  437. // Get the routing info
  438. //
  439. if(!Connect(hDlg, TRUE))
  440. {
  441. return FALSE;
  442. }
  443. for (dwCurrentRM = 0; dwCurrentRM < RM_COUNT; dwCurrentRM++)
  444. {
  445. BOOL Enabled;
  446. Enabled = FaxDeviceEnableRoutingMethod( g_hFaxSvcHandle,
  447. dwDeviceId,
  448. RoutingGuids[dwCurrentRM],
  449. QUERY_STATUS );
  450. //
  451. // Show routing extension data
  452. //
  453. pRoutingInfoBuffer = NULL;
  454. if(!FaxGetExtensionData(g_hFaxSvcHandle,
  455. dwDeviceId,
  456. RoutingGuids[dwCurrentRM],
  457. &pRoutingInfoBuffer,
  458. &dwRoutingInfoBufferSize))
  459. {
  460. Error(("FaxGetExtensionData failed with %ld.\n", GetLastError()));
  461. pRoutingInfoBuffer = NULL;
  462. }
  463. switch (dwCurrentRM)
  464. {
  465. case RM_FOLDER:
  466. CheckDlgButton( hDlg, IDC_DEVICE_PROP_SAVE, Enabled ? BST_CHECKED : BST_UNCHECKED );
  467. // enable controls if the user has "modify" permission
  468. if(g_bUserCanChangeSettings)
  469. {
  470. EnableWindow( GetDlgItem( hDlg, IDC_DEVICE_PROP_DEST_FOLDER ), Enabled );
  471. EnableWindow( GetDlgItem( hDlg, IDC_DEVICE_PROP_DEST_FOLDER_BR ), Enabled );
  472. }
  473. if (pRoutingInfoBuffer && *pRoutingInfoBuffer)
  474. {
  475. SetDlgItemText( hDlg, IDC_DEVICE_PROP_DEST_FOLDER, (LPCTSTR)pRoutingInfoBuffer );
  476. }
  477. break;
  478. case RM_PRINT:
  479. hControl = GetDlgItem( hDlg, IDC_DEVICE_PROP_PRINT_TO );
  480. //
  481. // Now find out if we match the data the server has
  482. //
  483. if (pRoutingInfoBuffer && lstrlen((LPWSTR)pRoutingInfoBuffer))
  484. {
  485. //
  486. // Server has some name for printer
  487. //
  488. LPCWSTR lpcwstrMatchingText = FindPrinterNameFromPath (g_pPrinterNames, g_dwNumPrinters, (LPWSTR)pRoutingInfoBuffer);
  489. if (!lpcwstrMatchingText)
  490. {
  491. //
  492. // No match, just fill in the text we got from the server
  493. //
  494. SendMessage(hControl, CB_SETCURSEL, -1, 0);
  495. SetWindowText(hControl, (LPWSTR)pRoutingInfoBuffer);
  496. }
  497. else
  498. {
  499. SendMessage(hControl, CB_SELECTSTRING, -1, (LPARAM) lpcwstrMatchingText);
  500. }
  501. }
  502. else
  503. {
  504. //
  505. // No server configuation - Select nothing
  506. //
  507. }
  508. CheckDlgButton( hDlg, IDC_DEVICE_PROP_PRINT, Enabled ? BST_CHECKED : BST_UNCHECKED );
  509. //
  510. // Enable controls if the user has "modify" permission
  511. //
  512. if(g_bUserCanChangeSettings)
  513. {
  514. EnableWindow(GetDlgItem(hDlg, IDC_DEVICE_PROP_PRINT), TRUE);
  515. EnableWindow(hControl, Enabled);
  516. }
  517. break;
  518. }
  519. if (pRoutingInfoBuffer)
  520. {
  521. FaxFreeBuffer(pRoutingInfoBuffer);
  522. }
  523. }
  524. DisConnect();
  525. return bSuccessed;
  526. }
  527. BOOL
  528. SaveReceiveInfo(
  529. HWND hDlg
  530. )
  531. /*++
  532. Routine Description:
  533. Save the receive routing info to the system
  534. Arguments:
  535. hDlg - Identifies the property sheet page
  536. Return Value:
  537. TRUE if successful, FALSE if failed
  538. --*/
  539. {
  540. DWORD dwDeviceId;
  541. PFAX_PORT_INFO_EX pFaxPortInfo = NULL;
  542. DWORD dwCurrentRM;
  543. BOOL bSuccessed = TRUE;
  544. HWND hControl;
  545. TCHAR szCsid[CSID_LIMIT + 1] = {0};
  546. BYTE pRouteInfo[RM_COUNT][INFO_SIZE] = {0};
  547. LPTSTR lpCurSel;
  548. LPDWORD Enabled;
  549. DWORD dwRingCount = 0; // default value is an invalid value
  550. DWORD dwRes = 0;
  551. Verbose(("Entering SaveReceiveInfo...\n"));
  552. //
  553. // check the validity of ring count
  554. //
  555. dwRingCount = GetDlgItemInt(hDlg, IDC_DEVICE_PROP_RINGS, &bSuccessed, FALSE);
  556. if( dwRingCount < MIN_RING_COUNT || dwRingCount > MAX_RING_COUNT )
  557. {
  558. hControl = GetDlgItem(hDlg, IDC_DEVICE_PROP_RINGS);
  559. DisplayErrorMessage(hDlg, 0, FAXUI_ERROR_INVALID_RING_COUNT, MIN_RING_COUNT, MAX_RING_COUNT);
  560. SendMessage(hControl, EM_SETSEL, 0, -1);
  561. SetFocus(hControl);
  562. SetActiveWindow(hControl);
  563. bSuccessed = FALSE;
  564. goto Exit;
  565. }
  566. //
  567. // Check the validity first in the loop,
  568. // then save the routing info
  569. //
  570. for (dwCurrentRM = 0; dwCurrentRM < RM_COUNT; dwCurrentRM++)
  571. {
  572. // initialize
  573. lpCurSel = (LPTSTR)(pRouteInfo[dwCurrentRM] + sizeof(DWORD));
  574. Enabled = (LPDWORD) pRouteInfo[dwCurrentRM];
  575. *Enabled = 0;
  576. switch (dwCurrentRM)
  577. {
  578. case RM_PRINT:
  579. *Enabled = (IsDlgButtonChecked( hDlg, IDC_DEVICE_PROP_PRINT ) == BST_CHECKED);
  580. lpCurSel[0] = TEXT('\0');
  581. //
  582. // Just read-in the selected printer display name
  583. //
  584. GetDlgItemText (hDlg, IDC_DEVICE_PROP_PRINT_TO, lpCurSel, MAX_PATH);
  585. hControl = GetDlgItem(hDlg, IDC_DEVICE_PROP_PRINT_TO);
  586. //
  587. // we will check the validity only when this routing method is enabled
  588. // but we will save the select change anyway.
  589. //
  590. if (*Enabled)
  591. {
  592. if (lpCurSel[0] == 0)
  593. {
  594. DisplayErrorMessage(hDlg, 0, FAXUI_ERROR_SELECT_PRINTER);
  595. SetFocus(hControl);
  596. SetActiveWindow(hControl);
  597. bSuccessed = FALSE;
  598. goto Exit;
  599. }
  600. }
  601. break;
  602. case RM_FOLDER:
  603. *Enabled = (IsDlgButtonChecked( hDlg, IDC_DEVICE_PROP_SAVE ) == BST_CHECKED);
  604. hControl = GetDlgItem(hDlg, IDC_DEVICE_PROP_DEST_FOLDER);
  605. //
  606. // we will check the validity only when this routing method is enabled
  607. // but we will save the text change anyway.
  608. //
  609. GetWindowText( hControl, lpCurSel, MAX_PATH - 1 );
  610. if (*Enabled)
  611. {
  612. if((g_pPathIsRelativeW && g_pPathIsRelativeW (lpCurSel)) || !DirectoryExists(lpCurSel))
  613. {
  614. DisplayErrorMessage(hDlg, 0, ERROR_PATH_NOT_FOUND);
  615. SetFocus(hControl);
  616. SetActiveWindow(hControl);
  617. bSuccessed = FALSE;
  618. goto Exit;
  619. }
  620. }
  621. }
  622. }
  623. //
  624. // Now save the device and routing info
  625. // Get device id from dialog page
  626. //
  627. dwDeviceId = (DWORD)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  628. //
  629. // Save routing methods info
  630. //
  631. if(!Connect(hDlg, TRUE))
  632. {
  633. bSuccessed = FALSE;
  634. goto Exit;
  635. }
  636. if(!FaxGetPortEx(g_hFaxSvcHandle, dwDeviceId, &pFaxPortInfo))
  637. {
  638. bSuccessed = FALSE;
  639. dwRes = GetLastError();
  640. Error(("Can't save routing information.\n"));
  641. goto Exit;
  642. }
  643. //
  644. // Save receive settings
  645. //
  646. if(IsDlgButtonChecked(hDlg, IDC_DEVICE_PROP_RECEIVE) == BST_CHECKED)
  647. {
  648. //
  649. // Collect and verify TSID
  650. //
  651. GetDlgItemText(hDlg, IDC_DEVICE_PROP_CSID, szCsid, CSID_LIMIT + 1);
  652. pFaxPortInfo->lptstrCsid = szCsid;
  653. if(IsDlgButtonChecked(hDlg, IDC_DEVICE_PROP_AUTO_ANSWER) == BST_CHECKED)
  654. {
  655. pFaxPortInfo->ReceiveMode = FAX_DEVICE_RECEIVE_MODE_AUTO;
  656. //
  657. // save ring count info
  658. //
  659. pFaxPortInfo->dwRings = dwRingCount;
  660. }
  661. else if(IsDlgButtonChecked(hDlg, IDC_DEVICE_PROP_MANUAL_ANSWER) == BST_CHECKED)
  662. {
  663. //
  664. // Turn off manual-answer for ALL devices.
  665. //
  666. DWORD dw;
  667. for (dw = 0; dw < g_dwPortsNum; dw++)
  668. {
  669. if (FAX_DEVICE_RECEIVE_MODE_MANUAL == g_pFaxPortInfo[dw].ReceiveMode)
  670. {
  671. g_pFaxPortInfo[dw].ReceiveMode = FAX_DEVICE_RECEIVE_MODE_OFF;
  672. }
  673. }
  674. //
  675. // Turn on manual-answer for selected device only.
  676. //
  677. pFaxPortInfo->ReceiveMode = FAX_DEVICE_RECEIVE_MODE_MANUAL;
  678. }
  679. }
  680. else
  681. {
  682. pFaxPortInfo->ReceiveMode = FAX_DEVICE_RECEIVE_MODE_OFF;
  683. }
  684. if(!FaxSetPortEx(g_hFaxSvcHandle, dwDeviceId, pFaxPortInfo))
  685. {
  686. bSuccessed = FALSE;
  687. dwRes = GetLastError();
  688. Error(( "Set port information error in DoSaveDeviceList(), ec = %d.\n", dwRes));
  689. goto Exit;
  690. }
  691. //
  692. // save routing methods
  693. //
  694. for (dwCurrentRM = 0; dwCurrentRM < RM_COUNT; dwCurrentRM++)
  695. {
  696. lpCurSel = (LPTSTR)(pRouteInfo[dwCurrentRM] + sizeof(DWORD));
  697. Enabled = (LPDWORD)pRouteInfo[dwCurrentRM];
  698. if ((RM_PRINT == dwCurrentRM) && *Enabled)
  699. {
  700. //
  701. // Attempt to convert printer display name to printer path before we pass it on to the server
  702. //
  703. LPCWSTR lpcwstrPrinterPath = FindPrinterPathFromName (g_pPrinterNames, g_dwNumPrinters, lpCurSel);
  704. if (lpcwstrPrinterPath)
  705. {
  706. //
  707. // We have a matching path - replace name with path.
  708. //
  709. lstrcpyn (lpCurSel, lpcwstrPrinterPath, MAX_PATH);
  710. }
  711. }
  712. if(!FaxSetExtensionData(g_hFaxSvcHandle,
  713. dwDeviceId,
  714. RoutingGuids[dwCurrentRM],
  715. (LPBYTE)lpCurSel,
  716. sizeof(TCHAR) * MAX_PATH))
  717. {
  718. bSuccessed = FALSE;
  719. dwRes = GetLastError();
  720. Error(("FaxSetExtensionData() failed with %d.\n", dwRes));
  721. goto Exit;
  722. }
  723. if(!FaxDeviceEnableRoutingMethod(g_hFaxSvcHandle,
  724. dwDeviceId,
  725. RoutingGuids[dwCurrentRM],
  726. *Enabled ? STATUS_ENABLE : STATUS_DISABLE ))
  727. {
  728. bSuccessed = FALSE;
  729. dwRes = GetLastError();
  730. Error(("FaxDeviceEnableRoutingMethod() failed with %d.\n", dwRes));
  731. goto Exit;
  732. }
  733. }
  734. bSuccessed = TRUE;
  735. Exit:
  736. FaxFreeBuffer(pFaxPortInfo);
  737. DisConnect();
  738. switch (dwRes)
  739. {
  740. case ERROR_SUCCESS:
  741. //
  742. // Don't do nothing
  743. //
  744. break;
  745. case FAXUI_ERROR_DEVICE_LIMIT:
  746. case FAX_ERR_DEVICE_NUM_LIMIT_EXCEEDED:
  747. //
  748. // Some additional parameters are needed
  749. //
  750. DisplayErrorMessage(hDlg, 0, dwRes, GetDeviceLimit());
  751. break;
  752. default:
  753. DisplayErrorMessage(hDlg, 0, dwRes);
  754. break;
  755. }
  756. return bSuccessed;
  757. }
  758. INT_PTR
  759. CALLBACK
  760. DevRecvDlgProc(
  761. IN HWND hDlg,
  762. IN UINT message,
  763. IN WPARAM wParam,
  764. IN LPARAM lParam
  765. )
  766. /*++
  767. Routine Description:
  768. Dialog procedure for the receive settings
  769. Arguments:
  770. hDlg - Identifies the property sheet page
  771. message - Specifies the message
  772. wParam - Specifies additional message-specific information
  773. lParam - Specifies additional message-specific information
  774. Return Value:
  775. Depending on specific message
  776. --*/
  777. {
  778. BOOL fRet = FALSE;
  779. HWND hControl;
  780. DWORD dwDeviceId;
  781. switch( message )
  782. {
  783. case WM_DESTROY:
  784. if (g_pPrinterNames)
  785. {
  786. ReleasePrinterNames (g_pPrinterNames, g_dwNumPrinters);
  787. g_pPrinterNames = NULL;
  788. }
  789. break;
  790. case WM_INITDIALOG:
  791. {
  792. //
  793. //Get the shared data from PROPSHEETPAGE lParam value
  794. //and load it into GWL_USERDATA
  795. //
  796. dwDeviceId = (DWORD)((LPPROPSHEETPAGE)lParam)->lParam;
  797. SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)dwDeviceId);
  798. //
  799. // Initialize the list of destination printers
  800. //
  801. hControl = GetDlgItem(hDlg, IDC_DEVICE_PROP_PRINT_TO);
  802. SetLTRComboBox(hDlg, IDC_DEVICE_PROP_PRINT_TO);
  803. if (g_pPrinterNames)
  804. {
  805. ReleasePrinterNames (g_pPrinterNames, g_dwNumPrinters);
  806. g_pPrinterNames = NULL;
  807. }
  808. g_pPrinterNames = CollectPrinterNames (&g_dwNumPrinters, TRUE);
  809. if (!g_pPrinterNames)
  810. {
  811. if (ERROR_PRINTER_NOT_FOUND == GetLastError ())
  812. {
  813. //
  814. // No printers
  815. //
  816. }
  817. else
  818. {
  819. //
  820. // Real error
  821. //
  822. }
  823. }
  824. else
  825. {
  826. //
  827. // Success - fill in the combo-box
  828. //
  829. DWORD dw;
  830. for (dw = 0; dw < g_dwNumPrinters; dw++)
  831. {
  832. SendMessage(hControl, CB_ADDSTRING, 0, (LPARAM) g_pPrinterNames[dw].lpcwstrDisplayName);
  833. }
  834. }
  835. //
  836. // We only allow two-digit phone ring answer
  837. //
  838. SendDlgItemMessage(hDlg, IDC_DEVICE_PROP_RINGS, EM_SETLIMITTEXT, 2, 0);
  839. SendDlgItemMessage(hDlg, IDC_DEVICE_PROP_CSID, EM_SETLIMITTEXT, CSID_LIMIT, 0);
  840. SendDlgItemMessage(hDlg, IDC_DEVICE_PROP_DEST_FOLDER, EM_SETLIMITTEXT, MAX_ARCHIVE_DIR - 1, 0);
  841. //
  842. // Initiate the spin control.
  843. //
  844. SendMessage( GetDlgItem(hDlg, IDC_DEVICE_PROP_SPIN_RINGS),
  845. UDM_SETRANGE32, MIN_RING_COUNT, MAX_RING_COUNT );
  846. SetLTREditDirection(hDlg, IDC_DEVICE_PROP_DEST_FOLDER);
  847. if (g_pSHAutoComplete)
  848. {
  849. g_pSHAutoComplete (GetDlgItem(hDlg, IDC_DEVICE_PROP_DEST_FOLDER), SHACF_FILESYSTEM);
  850. }
  851. InitReceiveInfo(hDlg);
  852. ValidateReceive(hDlg);
  853. return TRUE;
  854. }
  855. case WM_COMMAND:
  856. {
  857. // activate apply button
  858. WORD wID = LOWORD( wParam );
  859. switch( wID )
  860. {
  861. case IDC_DEVICE_PROP_RECEIVE:
  862. if ( HIWORD(wParam) == BN_CLICKED ) // notification code
  863. {
  864. if(IsDlgButtonChecked(hDlg, IDC_DEVICE_PROP_RECEIVE) == BST_CHECKED)
  865. {
  866. dwDeviceId = (DWORD)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  867. if(!IsDeviceInUse(dwDeviceId) &&
  868. GetDeviceLimit() <= CountUsedFaxDevices())
  869. {
  870. CheckDlgButton(hDlg, IDC_DEVICE_PROP_RECEIVE, BST_UNCHECKED);
  871. DisplayErrorMessage(hDlg,
  872. MB_OK | MB_ICONSTOP,
  873. FAXUI_ERROR_DEVICE_LIMIT,
  874. GetDeviceLimit());
  875. fRet = TRUE;
  876. break;
  877. }
  878. }
  879. ValidateReceive(hDlg);
  880. Notify_Change(hDlg);
  881. }
  882. break;
  883. case IDC_DEVICE_PROP_CSID:
  884. case IDC_DEVICE_PROP_DEST_FOLDER:
  885. if( HIWORD(wParam) == EN_CHANGE ) // notification code
  886. {
  887. Notify_Change(hDlg);
  888. }
  889. if (IDC_DEVICE_PROP_DEST_FOLDER == wID && HIWORD(wParam) == EN_KILLFOCUS)
  890. {
  891. TCHAR szFolder[MAX_PATH * 2];
  892. TCHAR szResult[MAX_PATH * 2];
  893. //
  894. // Edit control lost its focus
  895. //
  896. GetDlgItemText (hDlg, wID, szFolder, ARR_SIZE(szFolder));
  897. if (lstrlen (szFolder))
  898. {
  899. if (GetFullPathName(szFolder, ARR_SIZE(szResult), szResult, NULL))
  900. {
  901. if (g_pPathMakePrettyW)
  902. {
  903. g_pPathMakePrettyW (szResult);
  904. }
  905. SetDlgItemText (hDlg, wID, szResult);
  906. }
  907. }
  908. }
  909. break;
  910. case IDC_DEVICE_PROP_MANUAL_ANSWER:
  911. case IDC_DEVICE_PROP_AUTO_ANSWER:
  912. if ( HIWORD(wParam) == BN_CLICKED ) // notification code
  913. {
  914. BOOL bEnabled = IsDlgButtonChecked( hDlg, IDC_DEVICE_PROP_AUTO_ANSWER );
  915. EnableWindow( GetDlgItem( hDlg, IDC_DEVICE_PROP_RINGS ), bEnabled );
  916. EnableWindow( GetDlgItem( hDlg, IDC_DEVICE_PROP_SPIN_RINGS ), bEnabled );
  917. Notify_Change(hDlg);
  918. }
  919. break;
  920. case IDC_DEVICE_PROP_PRINT:
  921. if ( HIWORD(wParam) == BN_CLICKED ) // notification code
  922. {
  923. EnableWindow( GetDlgItem( hDlg, IDC_DEVICE_PROP_PRINT_TO ), IsDlgButtonChecked( hDlg, IDC_DEVICE_PROP_PRINT ) );
  924. Notify_Change(hDlg);
  925. }
  926. break;
  927. case IDC_DEVICE_PROP_SAVE:
  928. if ( HIWORD(wParam) == BN_CLICKED ) // notification code
  929. {
  930. EnableWindow( GetDlgItem( hDlg, IDC_DEVICE_PROP_DEST_FOLDER ), IsDlgButtonChecked( hDlg, IDC_DEVICE_PROP_SAVE ) );
  931. EnableWindow( GetDlgItem( hDlg, IDC_DEVICE_PROP_DEST_FOLDER_BR ), IsDlgButtonChecked( hDlg, IDC_DEVICE_PROP_SAVE ) );
  932. Notify_Change(hDlg);
  933. }
  934. break;
  935. case IDC_DEVICE_PROP_DEST_FOLDER_BR:
  936. {
  937. TCHAR szTitle[MAX_TITLE_LEN];
  938. if(!LoadString(g_hResource, IDS_BROWSE_FOLDER, szTitle, MAX_TITLE_LEN))
  939. {
  940. lstrcpy(szTitle, TEXT("Select a folder"));
  941. }
  942. if(BrowseForDirectory(hDlg, IDC_DEVICE_PROP_DEST_FOLDER, MAX_ARCHIVE_DIR, szTitle))
  943. {
  944. Notify_Change(hDlg);
  945. }
  946. break;
  947. }
  948. case IDC_DEVICE_PROP_PRINT_TO:
  949. if ((HIWORD(wParam) == CBN_SELCHANGE) || // notification code
  950. (HIWORD(wParam) == CBN_EDITCHANGE))
  951. {
  952. Notify_Change(hDlg);
  953. }
  954. break;
  955. default:
  956. break;
  957. } // switch
  958. fRet = TRUE;
  959. break;
  960. }
  961. case WM_NOTIFY:
  962. {
  963. switch( ((LPNMHDR) lParam)->code )
  964. {
  965. case PSN_APPLY:
  966. {
  967. // if the user only has read permission, return immediately
  968. if(!g_bUserCanChangeSettings)
  969. {
  970. return TRUE;
  971. }
  972. if(!SaveReceiveInfo(hDlg))
  973. {
  974. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID);
  975. }
  976. else
  977. {
  978. Notify_UnChange(hDlg);
  979. g_bPortInfoChanged = TRUE;
  980. }
  981. return TRUE;
  982. }
  983. } // switch
  984. break;
  985. }
  986. case WM_HELP:
  987. WinHelpContextPopup(((LPHELPINFO)lParam)->dwContextId, hDlg);
  988. return TRUE;
  989. } // switch
  990. return fRet;
  991. } // DevRecvDlgProc
  992. BOOL
  993. InitCleanupInfo(
  994. HWND hDlg
  995. )
  996. /*++
  997. Routine Description:
  998. Initialize the auto-cleanup information for a specific device
  999. Arguments:
  1000. hDlg - the dialog handle of the dialog
  1001. Return Value:
  1002. TRUE if success, FALSE otherwise
  1003. --*/
  1004. {
  1005. PFAX_OUTBOX_CONFIG pOutboxConfig = NULL;
  1006. Verbose(("Entering InitCleanupInfo...\n"));
  1007. if(!Connect(hDlg, TRUE))
  1008. {
  1009. return FALSE;
  1010. }
  1011. if(!FaxGetOutboxConfiguration(g_hFaxSvcHandle, &pOutboxConfig))
  1012. {
  1013. Error(( "FaxGetOutboxConfiguration() failed with %d.\n", GetLastError()));
  1014. return FALSE;
  1015. }
  1016. if (pOutboxConfig->dwAgeLimit)
  1017. {
  1018. if (pOutboxConfig->dwAgeLimit < FXS_DIRTYDAYS_LOWER)
  1019. {
  1020. pOutboxConfig->dwAgeLimit = FXS_DIRTYDAYS_LOWER;
  1021. }
  1022. if (pOutboxConfig->dwAgeLimit > FXS_DIRTYDAYS_UPPER)
  1023. {
  1024. pOutboxConfig->dwAgeLimit = FXS_DIRTYDAYS_UPPER;
  1025. }
  1026. //
  1027. // Age limit is active
  1028. //
  1029. CheckDlgButton(hDlg, IDC_DELETE_CHECK, BST_CHECKED);
  1030. SetDlgItemInt (hDlg, IDC_DAYS_EDIT, pOutboxConfig->dwAgeLimit, FALSE);
  1031. }
  1032. else
  1033. {
  1034. //
  1035. // Age limit is inactive
  1036. //
  1037. CheckDlgButton(hDlg, IDC_DELETE_CHECK, BST_UNCHECKED);
  1038. SetDlgItemInt (hDlg, IDC_DAYS_EDIT, FXS_DIRTYDAYS_LOWER, FALSE);
  1039. }
  1040. DisConnect();
  1041. return TRUE;
  1042. } // InitCleanupInfo
  1043. BOOL
  1044. ValidateCleanup(
  1045. HWND hDlg
  1046. )
  1047. /*++
  1048. Routine Description:
  1049. Validate the check box and controls for cleanup
  1050. Arguments:
  1051. hDlg - Handle to the property sheet page
  1052. Return Value:
  1053. TRUE -- if no error
  1054. FALSE -- if error
  1055. --*/
  1056. {
  1057. BOOL bEnabled;
  1058. if(g_bUserCanChangeSettings)
  1059. {
  1060. bEnabled = IsDlgButtonChecked(hDlg, IDC_DELETE_CHECK) == BST_CHECKED;
  1061. }
  1062. else
  1063. {
  1064. bEnabled = FALSE;
  1065. EnableWindow (GetDlgItem(hDlg, IDC_DELETE_CHECK), bEnabled);
  1066. EnableWindow (GetDlgItem(hDlg, IDC_STATIC_CLEANUP_ICON), bEnabled);
  1067. EnableWindow (GetDlgItem(hDlg, IDC_STATIC_CLEANUP_OPTIONS), bEnabled);
  1068. }
  1069. //
  1070. // Enable/disable controls according to "Enable Send" check box
  1071. //
  1072. EnableWindow (GetDlgItem(hDlg, IDC_DAYS_EDIT), bEnabled);
  1073. EnableWindow (GetDlgItem(hDlg, IDC_DAYS_SPIN), bEnabled);
  1074. EnableWindow (GetDlgItem(hDlg, IDC_DAYS_STATIC), bEnabled);
  1075. return TRUE;
  1076. } // ValidateCleanup
  1077. BOOL
  1078. SaveCleanupInfo(
  1079. IN HWND hDlg)
  1080. /*++
  1081. Routine name : SaveCleanupInfo
  1082. Routine description:
  1083. Process Apply Button
  1084. Author:
  1085. Eran Yraiv (EranY), April, 2001
  1086. Arguments:
  1087. hDlg [IN] - Handle to the Window
  1088. Return Value:
  1089. TRUE if Apply is succeeded, FALSE otherwise.
  1090. --*/
  1091. {
  1092. DWORD dwRes = 0;
  1093. BOOL bErrorDisplayed = FALSE;
  1094. PFAX_OUTBOX_CONFIG pOutboxConfig = NULL;
  1095. //
  1096. // if the user only has read permission, return immediately
  1097. //
  1098. if(!g_bUserCanChangeSettings)
  1099. {
  1100. return TRUE;
  1101. }
  1102. if(!Connect(hDlg, TRUE))
  1103. {
  1104. //
  1105. // Failed to connect to the Fax Service. Connect() showed the Error Message.
  1106. //
  1107. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID);
  1108. return FALSE;
  1109. }
  1110. if(!FaxGetOutboxConfiguration(g_hFaxSvcHandle, &pOutboxConfig))
  1111. {
  1112. //
  1113. // Show Error Message and return FALSE
  1114. //
  1115. dwRes = GetLastError();
  1116. Error(( "FaxGetOutboxConfiguration() failed with %d.\n", dwRes));
  1117. return FALSE;
  1118. }
  1119. Assert(pOutboxConfig);
  1120. if (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_DELETE_CHECK))
  1121. {
  1122. BOOL bRes;
  1123. int iAgeLimit = GetDlgItemInt (hDlg, IDC_DAYS_EDIT, &bRes, FALSE);
  1124. if (!bRes || (iAgeLimit > FXS_DIRTYDAYS_UPPER) || (iAgeLimit < FXS_DIRTYDAYS_LOWER))
  1125. {
  1126. //
  1127. // Bad data or out of range
  1128. //
  1129. HWND hControl = GetDlgItem(hDlg, IDC_DAYS_EDIT);
  1130. dwRes = ERROR_INVALID_DATA;
  1131. SetLastError (ERROR_INVALID_DATA);
  1132. DisplayErrorMessage(hDlg, 0, FAXUI_ERROR_INVALID_DIRTY_DAYS, FXS_DIRTYDAYS_LOWER, FXS_DIRTYDAYS_UPPER);
  1133. SendMessage(hControl, EM_SETSEL, 0, -1);
  1134. SetFocus(hControl);
  1135. SetActiveWindow(hControl);
  1136. bErrorDisplayed = TRUE;
  1137. goto ClearData;
  1138. }
  1139. pOutboxConfig->dwAgeLimit = iAgeLimit;
  1140. }
  1141. else
  1142. {
  1143. //
  1144. // Age limit is disabled
  1145. //
  1146. pOutboxConfig->dwAgeLimit = 0;
  1147. }
  1148. if(!FaxSetOutboxConfiguration(g_hFaxSvcHandle, pOutboxConfig))
  1149. {
  1150. //
  1151. // Show Error Message and return FALSE
  1152. //
  1153. dwRes = GetLastError();
  1154. Error(("FaxSetOutboxConfiguration() failed with %d.\n", dwRes));
  1155. goto ClearData;
  1156. }
  1157. ClearData:
  1158. FaxFreeBuffer(pOutboxConfig);
  1159. DisConnect();
  1160. switch (dwRes)
  1161. {
  1162. case ERROR_SUCCESS:
  1163. //
  1164. // Don't do nothing
  1165. //
  1166. break;
  1167. case FAXUI_ERROR_DEVICE_LIMIT:
  1168. case FAX_ERR_DEVICE_NUM_LIMIT_EXCEEDED:
  1169. //
  1170. // Some additional parameters are needed
  1171. //
  1172. DisplayErrorMessage(hDlg, 0, dwRes, GetDeviceLimit());
  1173. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID);
  1174. break;
  1175. default:
  1176. DisplayErrorMessage(hDlg, 0, dwRes);
  1177. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID);
  1178. break;
  1179. }
  1180. return (dwRes == 0);
  1181. } // SaveCleanupInfo
  1182. INT_PTR
  1183. CALLBACK
  1184. DevCleanupDlgProc(
  1185. IN HWND hDlg,
  1186. IN UINT message,
  1187. IN WPARAM wParam,
  1188. IN LPARAM lParam
  1189. )
  1190. /*++
  1191. Routine Description:
  1192. Dialog procedure for the cleanup settings
  1193. Arguments:
  1194. hDlg - Identifies the property sheet page
  1195. message - Specifies the message
  1196. wParam - Specifies additional message-specific information
  1197. lParam - Specifies additional message-specific information
  1198. Return Value:
  1199. Depending on specific message
  1200. --*/
  1201. {
  1202. BOOL fRet = FALSE;
  1203. switch( message )
  1204. {
  1205. case WM_INITDIALOG:
  1206. //
  1207. // we only allow two-digit days
  1208. //
  1209. SendDlgItemMessage(hDlg,
  1210. IDC_DAYS_EDIT,
  1211. EM_SETLIMITTEXT,
  1212. FXS_DIRTYDAYS_LENGTH,
  1213. 0);
  1214. //
  1215. // Initiate the spin control.
  1216. //
  1217. SendDlgItemMessage(hDlg,
  1218. IDC_DAYS_SPIN,
  1219. UDM_SETRANGE32,
  1220. FXS_DIRTYDAYS_LOWER,
  1221. FXS_DIRTYDAYS_UPPER);
  1222. InitCleanupInfo(hDlg);
  1223. ValidateCleanup(hDlg);
  1224. return TRUE;
  1225. case WM_COMMAND:
  1226. {
  1227. WORD wID = LOWORD( wParam );
  1228. switch( wID )
  1229. {
  1230. case IDC_DELETE_CHECK:
  1231. if (BN_CLICKED == HIWORD(wParam)) // notification code
  1232. {
  1233. //
  1234. // User checked / unchecked the checkbox
  1235. //
  1236. ValidateCleanup(hDlg);
  1237. Notify_Change(hDlg);
  1238. }
  1239. break;
  1240. case IDC_DAYS_EDIT:
  1241. if(EN_CHANGE == HIWORD(wParam)) // notification code
  1242. {
  1243. //
  1244. // User changed something in the edit control
  1245. //
  1246. Notify_Change(hDlg);
  1247. }
  1248. break;
  1249. default:
  1250. break;
  1251. } // switch
  1252. fRet = TRUE;
  1253. break;
  1254. }
  1255. case WM_NOTIFY:
  1256. {
  1257. switch( ((LPNMHDR) lParam)->code )
  1258. {
  1259. case PSN_APPLY:
  1260. {
  1261. // if the user only has read permission, return immediately
  1262. if(!g_bUserCanChangeSettings)
  1263. {
  1264. return TRUE;
  1265. }
  1266. if(!SaveCleanupInfo(hDlg))
  1267. {
  1268. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID);
  1269. }
  1270. else
  1271. {
  1272. Notify_UnChange(hDlg);
  1273. g_bPortInfoChanged = TRUE;
  1274. }
  1275. return TRUE;
  1276. }
  1277. } // switch
  1278. break;
  1279. }
  1280. case WM_HELP:
  1281. WinHelpContextPopup(((LPHELPINFO)lParam)->dwContextId, hDlg);
  1282. return TRUE;
  1283. } // switch
  1284. return fRet;
  1285. } // DevCleanupDlgProc
  1286. BOOL
  1287. SaveSendChanges(
  1288. IN HWND hDlg)
  1289. /*++
  1290. Routine name : SaveSendChanges
  1291. Routine description:
  1292. Process Apply Button
  1293. Author:
  1294. Iv Garber (IvG), Feb, 2001
  1295. Arguments:
  1296. hDlg [TBD] - Handle to the Window
  1297. Return Value:
  1298. TRUE if Apply is succeeded, FALSE otherwise.
  1299. --*/
  1300. {
  1301. DWORD dwDeviceId = 0;
  1302. DWORD dwRes = 0;
  1303. DWORD dwData;
  1304. TCHAR szTsid[TSID_LIMIT + 1] = {0};
  1305. BOOL bRes;
  1306. BOOL bErrorDisplayed = FALSE;
  1307. SYSTEMTIME sTime = {0};
  1308. PFAX_PORT_INFO_EX pFaxPortInfo = NULL; // receive port information
  1309. PFAX_OUTBOX_CONFIG pOutboxConfig = NULL;
  1310. //
  1311. // if the user only has read permission, return immediately
  1312. //
  1313. if(!g_bUserCanChangeSettings)
  1314. {
  1315. return TRUE;
  1316. }
  1317. //
  1318. // apply changes here!!
  1319. //
  1320. dwDeviceId = (DWORD)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  1321. if(!Connect(hDlg, TRUE))
  1322. {
  1323. //
  1324. // Failed to connect to the Fax Service. Connect() showed the Error Message.
  1325. //
  1326. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID);
  1327. return FALSE;
  1328. }
  1329. if(!FaxGetPortEx(g_hFaxSvcHandle, dwDeviceId, &pFaxPortInfo))
  1330. {
  1331. //
  1332. // Show the Error Message and return with FALSE
  1333. //
  1334. dwRes = GetLastError();
  1335. Error(( "FaxGetPortEx() failed with %d.\n", dwRes));
  1336. goto ClearData;
  1337. }
  1338. Assert(pFaxPortInfo);
  1339. //
  1340. // save settings
  1341. //
  1342. pFaxPortInfo->bSend = IsDlgButtonChecked(hDlg, IDC_DEVICE_PROP_SEND) == BST_CHECKED ? TRUE : FALSE;
  1343. if (pFaxPortInfo->bSend)
  1344. {
  1345. //
  1346. // Collect and verify TSID
  1347. //
  1348. GetDlgItemText(hDlg, IDC_DEVICE_PROP_TSID, szTsid, TSID_LIMIT);
  1349. pFaxPortInfo->lptstrTsid = szTsid;
  1350. }
  1351. if(!FaxSetPortEx(g_hFaxSvcHandle, dwDeviceId, pFaxPortInfo))
  1352. {
  1353. //
  1354. // Show the Error Message and return with FALSE
  1355. //
  1356. dwRes = GetLastError();
  1357. Error(( "FaxSetPortEx() failed with %d.\n", dwRes));
  1358. goto ClearData;
  1359. }
  1360. else
  1361. {
  1362. Notify_UnChange(hDlg);
  1363. g_bPortInfoChanged = TRUE;
  1364. }
  1365. if(!IsDesktopSKU())
  1366. {
  1367. goto ClearData;
  1368. }
  1369. //
  1370. // save desktop controls
  1371. //
  1372. if(!FaxGetOutboxConfiguration(g_hFaxSvcHandle, &pOutboxConfig))
  1373. {
  1374. //
  1375. // Show Error Message and return FALSE
  1376. //
  1377. dwRes = GetLastError();
  1378. Error(( "FaxGetOutboxConfiguration() failed with %d.\n", dwRes));
  1379. goto ClearData;
  1380. }
  1381. Assert(pOutboxConfig);
  1382. //
  1383. // Branding
  1384. //
  1385. pOutboxConfig->bBranding = (IsDlgButtonChecked(hDlg, IDC_BRANDING_CHECK) == BST_CHECKED);
  1386. //
  1387. // Retries
  1388. //
  1389. dwData = GetDlgItemInt(hDlg, IDC_RETRIES_EDIT, &bRes, FALSE);
  1390. if (!bRes ||
  1391. #if FXS_RETRIES_LOWER > 0
  1392. (dwData < FXS_RETRIES_LOWER) ||
  1393. #endif
  1394. (dwData > FXS_RETRIES_UPPER))
  1395. {
  1396. //
  1397. // Bad data or out of range
  1398. //
  1399. HWND hControl = GetDlgItem(hDlg, IDC_RETRIES_EDIT);
  1400. dwRes = ERROR_INVALID_DATA;
  1401. SetLastError (ERROR_INVALID_DATA);
  1402. DisplayErrorMessage(hDlg, 0, FAXUI_ERROR_INVALID_RETRIES, FXS_RETRIES_LOWER, FXS_RETRIES_UPPER);
  1403. SendMessage(hControl, EM_SETSEL, 0, -1);
  1404. SetFocus(hControl);
  1405. SetActiveWindow(hControl);
  1406. bErrorDisplayed = TRUE;
  1407. goto ClearData;
  1408. }
  1409. pOutboxConfig->dwRetries = dwData;
  1410. //
  1411. // Retry Delay
  1412. //
  1413. dwData = GetDlgItemInt(hDlg, IDC_RETRYDELAY_EDIT, &bRes, FALSE);
  1414. if (!bRes ||
  1415. #if FXS_RETRYDELAY_LOWER > 0
  1416. (dwData < FXS_RETRYDELAY_LOWER) ||
  1417. #endif
  1418. (dwData > FXS_RETRYDELAY_UPPER))
  1419. {
  1420. //
  1421. // Bad data or out of range
  1422. //
  1423. HWND hControl = GetDlgItem(hDlg, IDC_RETRYDELAY_EDIT);
  1424. dwRes = ERROR_INVALID_DATA;
  1425. SetLastError (ERROR_INVALID_DATA);
  1426. DisplayErrorMessage(hDlg, 0, FAXUI_ERROR_INVALID_RETRY_DELAY, FXS_RETRYDELAY_LOWER, FXS_RETRYDELAY_UPPER);
  1427. SendMessage(hControl, EM_SETSEL, 0, -1);
  1428. SetFocus(hControl);
  1429. SetActiveWindow(hControl);
  1430. bErrorDisplayed = TRUE;
  1431. goto ClearData;
  1432. }
  1433. pOutboxConfig->dwRetryDelay = dwData;
  1434. //
  1435. // Discount rate start time
  1436. //
  1437. SendDlgItemMessage(hDlg, IDC_DISCOUNT_START_TIME, DTM_GETSYSTEMTIME, 0, (LPARAM)&sTime);
  1438. pOutboxConfig->dtDiscountStart.Hour = sTime.wHour;
  1439. pOutboxConfig->dtDiscountStart.Minute = sTime.wMinute;
  1440. //
  1441. // Discount rate stop time
  1442. //
  1443. SendDlgItemMessage(hDlg, IDC_DISCOUNT_STOP_TIME, DTM_GETSYSTEMTIME, 0, (LPARAM)&sTime);
  1444. pOutboxConfig->dtDiscountEnd.Hour = sTime.wHour;
  1445. pOutboxConfig->dtDiscountEnd.Minute = sTime.wMinute;
  1446. if(!FaxSetOutboxConfiguration(g_hFaxSvcHandle, pOutboxConfig))
  1447. {
  1448. //
  1449. // Show Error Message and return FALSE
  1450. //
  1451. dwRes = GetLastError();
  1452. Error(("FaxSetOutboxConfiguration() failed with %d.\n", dwRes));
  1453. goto ClearData;
  1454. }
  1455. ClearData:
  1456. FaxFreeBuffer(pOutboxConfig);
  1457. FaxFreeBuffer(pFaxPortInfo);
  1458. DisConnect();
  1459. switch (dwRes)
  1460. {
  1461. case ERROR_SUCCESS:
  1462. //
  1463. // Don't do nothing
  1464. //
  1465. break;
  1466. case FAXUI_ERROR_DEVICE_LIMIT:
  1467. case FAX_ERR_DEVICE_NUM_LIMIT_EXCEEDED:
  1468. //
  1469. // Some additional parameters are needed
  1470. //
  1471. if (!bErrorDisplayed)
  1472. {
  1473. DisplayErrorMessage(hDlg, 0, dwRes, GetDeviceLimit());
  1474. }
  1475. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID);
  1476. break;
  1477. default:
  1478. if (!bErrorDisplayed)
  1479. {
  1480. DisplayErrorMessage(hDlg, 0, dwRes);
  1481. }
  1482. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID);
  1483. break;
  1484. }
  1485. return (dwRes == 0);
  1486. } // SaveSendChanges